+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);
+ }
+ _ReferenceMount(src->Mount, "DuplicateFD");
+ _ReferenceNode(src->Node);
+ 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(!h) {
+ errno = EBADF;
+ return -1;
+ }
+ int ret = h->Mode;
+
+ Value &= Mask;
+ h->Mode &= ~Mask;
+ h->Mode |= Value;
+ return ret;
+}
+