3 * - Directory Management Functions
11 extern tVFS_Mount *gRootMount;
14 int VFS_MkDir(char *Path);
15 int VFS_MkNod(char *Path, Uint Flags);
19 * \fn int VFS_MkDir(char *Path)
20 * \brief Create a new node
21 * \param Path Path of directory to create
23 int VFS_MkDir(char *Path)
25 return VFS_MkNod(Path, VFS_FFLAG_DIRECTORY);
29 * \fn int VFS_MkNod(char *Path, Uint Flags)
30 * \brief Create a new node in a directory
31 * \param Path Path of new node
32 * \param Flags Flags to apply to the node
34 int VFS_MkNod(char *Path, Uint Flags)
37 int pos = 0, oldpos = 0;
42 ENTER("sPath xFlags", Path, Flags);
44 absPath = VFS_GetAbsPath(Path);
45 LOG("absPath = '%s'", absPath);
47 while( (next = strpos(&absPath[pos+1], '/')) != -1 ) {
48 LOG("next = %i", next);
53 absPath[oldpos] = '\0'; // Mutilate path
54 name = &absPath[oldpos+1];
56 LOG("absPath = '%s', name = '%s'", absPath, name);
59 if(absPath[0] == '\0')
60 parent = VFS_ParsePath("/", NULL);
62 parent = VFS_ParsePath(absPath, NULL);
64 if(!parent) return -1; // Error Check
67 if( !VFS_CheckACL(parent, VFS_PERM_EXECUTE|VFS_PERM_WRITE) ) {
68 if(parent->Close) parent->Close( parent );
74 LOG("parent = %p", parent);
76 if(parent->MkNod == NULL) {
77 Warning("VFS_MkNod - Directory has no MkNod method");
83 ret = parent->MkNod(parent, name, Flags);
85 // Free allocated string
89 if(parent->Close) parent->Close( parent );
102 * \fn int VFS_Symlink(char *Name, char *Link)
103 * \brief Creates a symlink called \a Name to \a Link
104 * \param Name Name of symbolic link
105 * \param Link Destination of symbolic link
107 int VFS_Symlink(char *Name, char *Link)
113 //ENTER("sName sLink", Name, Link);
115 // Get absolue path name
116 Link = VFS_GetAbsPath( Link );
118 Warning("Path '%s' is badly formed", Link);
122 // Get true path and node
123 destNode = VFS_ParsePath( Link, &realLink );
126 // Check if destination exists
128 Warning("File '%s' does not exist, symlink not created", Link);
132 // Derefence the destination
133 if(destNode->Close) destNode->Close(destNode);
136 if( VFS_MkNod(Name, VFS_FFLAG_SYMLINK) != 0 ) {
137 Warning("Unable to create link node '%s'", Name);
138 return -2; // Make link node
141 // Write link address
142 fp = VFS_Open(Name, VFS_OPENFLAG_WRITE|VFS_OPENFLAG_NOLINK);
143 VFS_Write(fp, strlen(realLink), realLink);
152 * \fn int VFS_ReadDir(int FD, char *Dest)
153 * \brief Read from a directory
155 int VFS_ReadDir(int FD, char *Dest)
157 tVFS_Handle *h = VFS_GetHandle(FD);
160 //ENTER("ph pDest", h, Dest);
162 if(!h || h->Node->ReadDir == NULL) {
167 if(h->Node->Size != -1 && h->Position >= h->Node->Size) {
173 tmp = h->Node->ReadDir(h->Node, h->Position);
174 if((Uint)tmp < (Uint)VFS_MAXSKIP)
175 h->Position += (Uint)tmp;
178 } while(tmp != NULL && (Uint)tmp < (Uint)VFS_MAXSKIP);
180 //LOG("tmp = '%s'", tmp);