From: John Hodge Date: Wed, 24 Aug 2011 00:01:18 +0000 (+0800) Subject: Kernel/vfs - Fixing OpenInode support X-Git-Tag: rel0.11~128 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=7e5607004c3221d55c7992148b2f0d958cf28533;p=tpg%2Facess2.git Kernel/vfs - Fixing OpenInode support --- diff --git a/Kernel/include/vfs_int.h b/Kernel/include/vfs_int.h index 8ecef3b0..4961f085 100644 --- a/Kernel/include/vfs_int.h +++ b/Kernel/include/vfs_int.h @@ -47,7 +47,7 @@ extern tVFS_Mount *gVFS_Mounts; // === PROTOTYPES === // --- open.c --- extern char *VFS_GetAbsPath(const char *Path); -extern tVFS_Node *VFS_ParsePath(const char *Path, char **TruePath); +extern tVFS_Node *VFS_ParsePath(const char *Path, char **TruePath, tVFS_Mount **MountPoint); extern tVFS_Handle *VFS_GetHandle(int FD); // --- acls.c --- extern int VFS_CheckACL(tVFS_Node *Node, Uint Permissions); diff --git a/Kernel/vfs/dir.c b/Kernel/vfs/dir.c index 64c5d378..8cc3fa84 100644 --- a/Kernel/vfs/dir.c +++ b/Kernel/vfs/dir.c @@ -59,9 +59,9 @@ int VFS_MkNod(const char *Path, Uint Flags) // Check for root if(absPath[0] == '\0') - parent = VFS_ParsePath("/", NULL); + parent = VFS_ParsePath("/", NULL, NULL); else - parent = VFS_ParsePath(absPath, NULL); + parent = VFS_ParsePath(absPath, NULL, NULL); LOG("parent = %p", parent); @@ -127,10 +127,14 @@ int VFS_Symlink(const char *Name, const char *Link) return -1; } + destNode = VFS_ParsePath( _link, &realLink, NULL ); + #if 0 // Get true path and node - destNode = VFS_ParsePath( _link, &realLink ); free(_link); _link = NULL; + #else + realLink = _link; + #endif // Check if destination exists if(!destNode) { diff --git a/Kernel/vfs/io.c b/Kernel/vfs/io.c index 212a7c21..358d7039 100644 --- a/Kernel/vfs/io.c +++ b/Kernel/vfs/io.c @@ -182,7 +182,12 @@ int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs) h = VFS_GetHandle(FD); if(!h) return -1; - + + if( h->Mount ) + Dest->mount = h->Mount->Identifier; + else + Dest->mount = 0; + Dest->inode = h->Node->Inode; Dest->uid = h->Node->UID; Dest->gid = h->Node->GID; Dest->size = h->Node->Size; diff --git a/Kernel/vfs/main.c b/Kernel/vfs/main.c index c0c37e1d..1000df06 100644 --- a/Kernel/vfs/main.c +++ b/Kernel/vfs/main.c @@ -75,7 +75,7 @@ char *VFS_GetTruePath(const char *Path) tmp = VFS_GetAbsPath(Path); if(tmp == NULL) return NULL; //Log(" VFS_GetTruePath: tmp = '%s'", tmp); - node = VFS_ParsePath(tmp, &ret); + node = VFS_ParsePath(tmp, &ret, NULL); free(tmp); //Log(" VFS_GetTruePath: node=%p, ret='%s'", node, ret); diff --git a/Kernel/vfs/mount.c b/Kernel/vfs/mount.c index a42cd09b..1773218a 100644 --- a/Kernel/vfs/mount.c +++ b/Kernel/vfs/mount.c @@ -20,7 +20,7 @@ void VFS_UpdateMountFile(void); tMutex glVFS_MountList; tVFS_Mount *gVFS_Mounts; tVFS_Mount *gVFS_RootMount = NULL; -Uint32 giVFS_NextMountIdent = 0; +Uint32 giVFS_NextMountIdent = 1; // === CODE === /** @@ -82,6 +82,12 @@ int VFS_Mount(const char *Device, const char *MountPoint, const char *Filesystem } mnt->Identifier = giVFS_NextMountIdent++; + #if 0 + // Ensure identifiers don't repeat + // - Only a problem if there have been 4 billion mounts + while( giVFS_NextMountIdent == 0 || VFS_GetMountByIdent(giVFS_NextMountIdent) ) + giVFS_NextMountIdent ++; + #endif // Set root if(!gVFS_RootMount) gVFS_RootMount = mnt; diff --git a/Kernel/vfs/open.c b/Kernel/vfs/open.c index 02f1a7bc..f549d2bd 100644 --- a/Kernel/vfs/open.c +++ b/Kernel/vfs/open.c @@ -20,7 +20,7 @@ extern tVFS_Mount *gVFS_RootMount; extern int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode); // === PROTOTYPES === - int VFS_int_CreateHandle( tVFS_Node *Node, int Mode ); + int VFS_int_CreateHandle( tVFS_Node *Node, tVFS_Mount *Mount, int Mode ); // === CODE === /** @@ -166,7 +166,7 @@ char *VFS_GetAbsPath(const char *Path) * \fn char *VFS_ParsePath(const char *Path, char **TruePath) * \brief Parses a path, resolving sysmlinks and applying permissions */ -tVFS_Node *VFS_ParsePath(const char *Path, char **TruePath) +tVFS_Node *VFS_ParsePath(const char *Path, char **TruePath, tVFS_Mount **MountPoint) { tVFS_Mount *mnt, *longestMount; int cmp, retLength = 0; @@ -185,6 +185,9 @@ tVFS_Node *VFS_ParsePath(const char *Path, char **TruePath) strcpy(*TruePath, Path); } curNode = gVFS_MemRoot.FindDir(&gVFS_MemRoot, Path); + if(MountPoint) { + *MountPoint = NULL; + } LEAVE('p', curNode); return curNode; } @@ -225,6 +228,8 @@ restart_parse: *TruePath = malloc( mnt->MountPointLen+1 ); strcpy(*TruePath, mnt->MountPoint); } + if(MountPoint) + *MountPoint = mnt; LEAVE('p', mnt->RootNode); return mnt->RootNode; } @@ -399,7 +404,7 @@ restart_parse: } // Get last node - LOG("VFS_ParsePath: FindDir(%p, '%s')", curNode, &Path[ofs]); + LOG("FindDir(%p, '%s')", curNode, &Path[ofs]); tmpNode = curNode->FindDir(curNode, &Path[ofs]); LOG("tmpNode = %p", tmpNode); if(curNode->Close) curNode->Close(curNode); @@ -432,6 +437,10 @@ restart_parse: // - Extend Path //retLength += strlen(tmpNode->Name) + 1; } + + if( MountPoint ) { + *MountPoint = mnt; + } LEAVE('p', tmpNode); return tmpNode; @@ -440,7 +449,7 @@ restart_parse: /** * \brief Create and return a handle number for the given node and mode */ -int VFS_int_CreateHandle( tVFS_Node *Node, int Mode ) +int VFS_int_CreateHandle( tVFS_Node *Node, tVFS_Mount *Mount, int Mode ) { int i; i = 0; @@ -465,6 +474,8 @@ int VFS_int_CreateHandle( tVFS_Node *Node, int Mode ) LEAVE_RET('i', -1); } + VFS_GetHandle(i)->Mount = Mount; + LEAVE_RET('x', i); } @@ -475,6 +486,7 @@ int VFS_int_CreateHandle( tVFS_Node *Node, int Mode ) int VFS_Open(const char *Path, Uint Mode) { tVFS_Node *node; + tVFS_Mount *mnt; char *absPath; ENTER("sPath xMode", Path, Mode); @@ -487,7 +499,7 @@ int VFS_Open(const char *Path, Uint Mode) } LOG("absPath = \"%s\"", absPath); // Parse path and get mount point - node = VFS_ParsePath(absPath, NULL); + node = VFS_ParsePath(absPath, NULL, &mnt); // Free generated path free(absPath); @@ -514,7 +526,7 @@ int VFS_Open(const char *Path, Uint Mode) tmppath[ node->Size ] = '\0'; if(node->Close) node->Close( node ); // Open the target - node = VFS_ParsePath(tmppath, NULL); + node = VFS_ParsePath(tmppath, NULL, &mnt); if(!node) { LOG("Cannot find symlink target node (%s)", tmppath); errno = ENOENT; @@ -522,7 +534,7 @@ int VFS_Open(const char *Path, Uint Mode) } } - LEAVE_RET('x', VFS_int_CreateHandle(node, Mode)); + LEAVE_RET('x', VFS_int_CreateHandle(node, mnt, Mode)); } @@ -558,7 +570,7 @@ int VFS_OpenChild(int FD, const char *Name, Uint Mode) LEAVE_RET('i', -1); } - LEAVE_RET('x', VFS_int_CreateHandle(node, Mode)); + LEAVE_RET('x', VFS_int_CreateHandle(node, h->Mount, Mode)); } int VFS_OpenInode(Uint32 Mount, Uint64 Inode, int Mode) @@ -589,7 +601,7 @@ int VFS_OpenInode(Uint32 Mount, Uint64 Inode, int Mode) LEAVE_RET('i', -1); } - LEAVE_RET('x', VFS_int_CreateHandle(node, Mode)); + LEAVE_RET('x', VFS_int_CreateHandle(node, mnt, Mode)); } /**