X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fvfs%2Fdir.c;h=d4c153096f6ad94d43ce081a3f0de27f51554875;hb=a2495c6ea4f4cab16b5d339ae511428e92e89e73;hp=5702986cfa83445c070a57d13dddec4786c07682;hpb=f99096106a98f0616662ad05a55991220691151b;p=tpg%2Facess2.git diff --git a/Kernel/vfs/dir.c b/Kernel/vfs/dir.c index 5702986c..d4c15309 100644 --- a/Kernel/vfs/dir.c +++ b/Kernel/vfs/dir.c @@ -1,14 +1,21 @@ /* + * Acess2 VFS + * - Directory Management Functions */ -#include "vfs.h" -#include "vfs_int.h" +#define DEBUG 0 +#include +#include +#include // === IMPORTS === extern tVFS_Mount *gRootMount; // === PROTOTYPES === - int VFS_MkDir(char *Path); - int VFS_MkNod(char *Path, Uint Flags); +#if 0 + int VFS_MkDir(const char *Path); + int VFS_MkNod(const char *Path, Uint Flags); + int VFS_Symlink(const char *Name, const char *Link); +#endif // === CODE === /** @@ -16,7 +23,7 @@ extern tVFS_Mount *gRootMount; * \brief Create a new node * \param Path Path of directory to create */ -int VFS_MkDir(char *Path) +int VFS_MkDir(const char *Path) { return VFS_MkNod(Path, VFS_FFLAG_DIRECTORY); } @@ -27,98 +34,106 @@ int VFS_MkDir(char *Path) * \param Path Path of new node * \param Flags Flags to apply to the node */ -int VFS_MkNod(char *Path, Uint Flags) +int VFS_MkNod(const char *Path, Uint Flags) { char *absPath, *name; - int pos=0, oldpos = 0; + int pos = 0, oldpos = 0; + int next = 0; tVFS_Node *parent; int ret; - Debug_Enter("VFS_MkNod", "sPath xFlags", Path, Flags); + ENTER("sPath xFlags", Path, Flags); absPath = VFS_GetAbsPath(Path); + LOG("absPath = '%s'", absPath); - while( (pos = strpos8(&absPath[pos+1], '/')) != -1 ) oldpos = pos; + while( (next = strpos(&absPath[pos+1], '/')) != -1 ) { + LOG("next = %i", next); + pos += next+1; + LOG("pos = %i", pos); + oldpos = pos; + } absPath[oldpos] = '\0'; // Mutilate path name = &absPath[oldpos+1]; + LOG("absPath = '%s', name = '%s'", absPath, name); + // 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); - if(!parent) return -1; // Error Check + LOG("parent = %p", parent); + + if(!parent) { + LEAVE('i', -1); + return -1; // Error Check + } // Permissions Check if( !VFS_CheckACL(parent, VFS_PERM_EXECUTE|VFS_PERM_WRITE) ) { - if(parent->Close) parent->Close( parent ); + _CloseNode(parent); free(absPath); - Debug_Leave("VFS_MkNod", 'i', -1); + LEAVE('i', -1); return -1; } - Debug_Log("VFS_MkNod", "parent = %p\n", parent); + LOG("parent = %p", parent); - if(parent->MkNod == NULL) { + if(!parent->Type || !parent->Type->MkNod) { Warning("VFS_MkNod - Directory has no MkNod method"); - Debug_Leave("VFS_MkNod", 'i', -1); + LEAVE('i', -1); return -1; } // Create node - ret = parent->MkNod(parent, name, Flags); + ret = parent->Type->MkNod(parent, name, Flags); // Free allocated string free(absPath); // Free Parent - if(parent->Close) parent->Close( parent ); + _CloseNode(parent); // Error Check - if(ret == 0) return -1; + if(ret == 0) { + LEAVE('i', -1); + return -1; + } - Debug_Leave("VFS_MkNod", 'i', 0); + LEAVE('i', 0); return 0; } /** - * \fn int VFS_Symlink(char *Name, char *Link) + * \fn int VFS_Symlink(const char *Name, const char *Link) * \brief Creates a symlink called \a Name to \a Link * \param Name Name of symbolic link * \param Link Destination of symbolic link */ -int VFS_Symlink(char *Name, char *Link) +int VFS_Symlink(const char *Name, const char *Link) { char *realLink; int fp; - tVFS_Node *destNode; - //LogF("vfs_symlink: (name='%s', link='%s')\n", name, link); + ENTER("sName sLink", Name, Link); // Get absolue path name - Link = VFS_GetAbsPath( Link ); - if(!Link) { - Warning("Path '%s' is badly formed", Link); - return -1; - } - - // Get true path and node - destNode = VFS_ParsePath( Link, &realLink ); - free(Link); - - // Check if destination exists - if(!destNode) { - Warning("File '%s' does not exist, symlink not created", Link); + realLink = VFS_GetAbsPath( Link ); + if(!realLink) { + Log_Warning("VFS", "Path '%s' is badly formed", Link); + LEAVE('i', -1); return -1; } - - // Derefence the destination - if(destNode->Close) destNode->Close(destNode); - + + LOG("realLink = '%s'", realLink); + // Make node if( VFS_MkNod(Name, VFS_FFLAG_SYMLINK) != 0 ) { - Warning("Unable to create link node '%s'", Name); + Log_Warning("VFS", "Unable to create link node '%s'", Name); + free(realLink); + LEAVE('i', -2); return -2; // Make link node } @@ -129,6 +144,7 @@ int VFS_Symlink(char *Name, char *Link) free(realLink); + LEAVE('i', 1); return 1; } @@ -141,37 +157,36 @@ int VFS_ReadDir(int FD, char *Dest) tVFS_Handle *h = VFS_GetHandle(FD); char *tmp; - ENTER("ph pDest", h, Dest); + //ENTER("ph pDest", h, Dest); - if(!h || h->Node->ReadDir == NULL) { - LEAVE('i', 0); + if(!h || !h->Node->Type || !h->Node->Type->ReadDir) { + //LEAVE('i', 0); return 0; } if(h->Node->Size != -1 && h->Position >= h->Node->Size) { - LEAVE('i', 0); + //LEAVE('i', 0); return 0; } do { - tmp = h->Node->ReadDir(h->Node, h->Position); + tmp = h->Node->Type->ReadDir(h->Node, h->Position); if((Uint)tmp < (Uint)VFS_MAXSKIP) h->Position += (Uint)tmp; else h->Position ++; } while(tmp != NULL && (Uint)tmp < (Uint)VFS_MAXSKIP); - LOG("tmp = '%s'", tmp); + + //LOG("tmp = '%s'", tmp); if(!tmp) { - LEAVE('i', 0); + //LEAVE('i', 0); return 0; } strcpy(Dest, tmp); + free(tmp); - if((Uint)tmp & 1) - free((void*)( (Uint)tmp & ~1 )); - - LEAVE('i', 1); + //LEAVE('i', 1); return 1; }