Kernel - SYS_FDCTL
[tpg/acess2.git] / KernelLand / Kernel / vfs / open.c
index e83ace8..067a73a 100644 (file)
 
 // === IMPORTS ===
 extern tVFS_Mount      *gVFS_RootMount;
-extern int     VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode);
 extern tVFS_Node       *VFS_MemFile_Create(const char *Path);
 
 // === PROTOTYPES ===
 void   _ReferenceMount(tVFS_Mount *Mount, const char *DebugTag);
 void   _DereferenceMount(tVFS_Mount *Mount, const char *DebugTag);
- int   VFS_int_CreateHandle( tVFS_Node *Node, tVFS_Mount *Mount, int Mode );
+ int   VFS_int_CreateHandle(tVFS_Node *Node, tVFS_Mount *Mount, int Mode);
 
 // === CODE ===
 void _ReferenceMount(tVFS_Mount *Mount, const char *DebugTag)
@@ -752,6 +751,39 @@ void VFS_Close(int FD)
        h->Node = NULL;
 }
 
+int VFS_DuplicateFD(int SrcFD, int DstFD)
+{
+        int    isUser = !(SrcFD & VFS_KERNEL_FLAG);
+       tVFS_Handle     *src = VFS_GetHandle(SrcFD);
+       if( !src )      return -1;
+       if( DstFD == -1 ) {
+               DstFD = VFS_AllocHandle(isUser, src->Node, src->Mode);
+       }
+       else {
+               // Can't overwrite
+               if( VFS_GetHandle(DstFD) )
+                       return -1;
+               VFS_SetHandle(DstFD, src->Node, src->Mode);
+       }
+       memcpy(VFS_GetHandle(DstFD), src, sizeof(tVFS_Handle));
+       return DstFD;
+}
+
+/*
+ * Update flags on a FD
+ */
+int VFS_SetFDFlags(int FD, int Mask, int Value)
+{
+       tVFS_Handle     *h = VFS_GetHandle(FD);
+       if(!FD) return -1;
+        int    ret = h->Mode;
+       
+       Value &= Mask;
+       h->Mode &= ~Mask;
+       h->Mode |= Value;
+       return ret;
+}
+
 /**
  * \brief Change current working directory
  */

UCC git Repository :: git.ucc.asn.au