3 * - Directory Management Functions
11 extern tVFS_Mount *gRootMount;
15 int VFS_MkDir(const char *Path);
17 int VFS_MkNod(const char *Path, Uint Flags);
21 * \fn int VFS_MkDir(char *Path)
22 * \brief Create a new node
23 * \param Path Path of directory to create
25 int VFS_MkDir(const char *Path)
27 return VFS_MkNod(Path, VFS_FFLAG_DIRECTORY);
31 * \fn int VFS_MkNod(char *Path, Uint Flags)
32 * \brief Create a new node in a directory
33 * \param Path Path of new node
34 * \param Flags Flags to apply to the node
36 int VFS_MkNod(const char *Path, Uint Flags)
39 int pos = 0, oldpos = 0;
44 ENTER("sPath xFlags", Path, Flags);
46 absPath = VFS_GetAbsPath(Path);
47 LOG("absPath = '%s'", absPath);
49 while( (next = strpos(&absPath[pos+1], '/')) != -1 ) {
50 LOG("next = %i", next);
55 absPath[oldpos] = '\0'; // Mutilate path
56 name = &absPath[oldpos+1];
58 LOG("absPath = '%s', name = '%s'", absPath, name);
61 if(absPath[0] == '\0')
62 parent = VFS_ParsePath("/", NULL);
64 parent = VFS_ParsePath(absPath, NULL);
66 LOG("parent = %p", parent);
70 return -1; // Error Check
74 if( !VFS_CheckACL(parent, VFS_PERM_EXECUTE|VFS_PERM_WRITE) ) {
75 if(parent->Close) parent->Close( parent );
81 LOG("parent = %p", parent);
83 if(parent->MkNod == NULL) {
84 Warning("VFS_MkNod - Directory has no MkNod method");
90 ret = parent->MkNod(parent, name, Flags);
92 // Free allocated string
96 if(parent->Close) parent->Close( parent );
109 * \fn int VFS_Symlink(const char *Name, const char *Link)
110 * \brief Creates a symlink called \a Name to \a Link
111 * \param Name Name of symbolic link
112 * \param Link Destination of symbolic link
114 int VFS_Symlink(const char *Name, const char *Link)
121 //ENTER("sName sLink", Name, Link);
123 // Get absolue path name
124 _link = VFS_GetAbsPath( Link );
126 Log_Warning("VFS", "Path '%s' is badly formed", Link);
130 // Get true path and node
131 destNode = VFS_ParsePath( _link, &realLink );
135 // Check if destination exists
137 Log_Warning("VFS", "File '%s' does not exist, symlink not created", Link);
141 // Derefence the destination
142 if(destNode->Close) destNode->Close(destNode);
145 if( VFS_MkNod(Name, VFS_FFLAG_SYMLINK) != 0 ) {
146 Log_Warning("VFS", "Unable to create link node '%s'", Name);
147 return -2; // Make link node
150 // Write link address
151 fp = VFS_Open(Name, VFS_OPENFLAG_WRITE|VFS_OPENFLAG_NOLINK);
152 VFS_Write(fp, strlen(realLink), realLink);
161 * \fn int VFS_ReadDir(int FD, char *Dest)
162 * \brief Read from a directory
164 int VFS_ReadDir(int FD, char *Dest)
166 tVFS_Handle *h = VFS_GetHandle(FD);
169 //ENTER("ph pDest", h, Dest);
171 if(!h || h->Node->ReadDir == NULL) {
176 if(h->Node->Size != -1 && h->Position >= h->Node->Size) {
182 tmp = h->Node->ReadDir(h->Node, h->Position);
183 if((Uint)tmp < (Uint)VFS_MAXSKIP)
184 h->Position += (Uint)tmp;
187 } while(tmp != NULL && (Uint)tmp < (Uint)VFS_MAXSKIP);
189 //LOG("tmp = '%s'", tmp);