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);
18 // int VFS_Symlink(const char *Name, const char *Link);
22 * \fn int VFS_MkDir(char *Path)
23 * \brief Create a new node
24 * \param Path Path of directory to create
26 int VFS_MkDir(const char *Path)
28 return VFS_MkNod(Path, VFS_FFLAG_DIRECTORY);
32 * \fn int VFS_MkNod(char *Path, Uint Flags)
33 * \brief Create a new node in a directory
34 * \param Path Path of new node
35 * \param Flags Flags to apply to the node
37 int VFS_MkNod(const char *Path, Uint Flags)
40 int pos = 0, oldpos = 0;
45 ENTER("sPath xFlags", Path, Flags);
47 absPath = VFS_GetAbsPath(Path);
48 LOG("absPath = '%s'", absPath);
50 while( (next = strpos(&absPath[pos+1], '/')) != -1 ) {
51 LOG("next = %i", next);
56 absPath[oldpos] = '\0'; // Mutilate path
57 name = &absPath[oldpos+1];
59 LOG("absPath = '%s', name = '%s'", absPath, name);
62 if(absPath[0] == '\0')
63 parent = VFS_ParsePath("/", NULL, NULL);
65 parent = VFS_ParsePath(absPath, NULL, NULL);
67 LOG("parent = %p", parent);
71 return -1; // Error Check
75 if( !VFS_CheckACL(parent, VFS_PERM_EXECUTE|VFS_PERM_WRITE) ) {
76 if(parent->Close) parent->Close( parent );
82 LOG("parent = %p", parent);
84 if(parent->MkNod == NULL) {
85 Warning("VFS_MkNod - Directory has no MkNod method");
91 ret = parent->MkNod(parent, name, Flags);
93 // Free allocated string
97 if(parent->Close) parent->Close( parent );
110 * \fn int VFS_Symlink(const char *Name, const char *Link)
111 * \brief Creates a symlink called \a Name to \a Link
112 * \param Name Name of symbolic link
113 * \param Link Destination of symbolic link
115 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);
131 LOG("_link = '%s'", _link);
135 tVFS_Node *destNode = VFS_ParsePath( _link, &realLink, NULL );
137 // Get true path and node
144 // Check if destination exists
146 Log_Warning("VFS", "File '%s' does not exist, symlink not created", Link);
150 // Derefence the destination
151 if(destNode->Close) destNode->Close(destNode);
156 LOG("realLink = '%s'", realLink);
159 if( VFS_MkNod(Name, VFS_FFLAG_SYMLINK) != 0 ) {
160 Log_Warning("VFS", "Unable to create link node '%s'", Name);
162 return -2; // Make link node
165 // Write link address
166 fp = VFS_Open(Name, VFS_OPENFLAG_WRITE|VFS_OPENFLAG_NOLINK);
167 VFS_Write(fp, strlen(realLink), realLink);
177 * \fn int VFS_ReadDir(int FD, char *Dest)
178 * \brief Read from a directory
180 int VFS_ReadDir(int FD, char *Dest)
182 tVFS_Handle *h = VFS_GetHandle(FD);
185 //ENTER("ph pDest", h, Dest);
187 if(!h || h->Node->ReadDir == NULL) {
192 if(h->Node->Size != -1 && h->Position >= h->Node->Size) {
198 tmp = h->Node->ReadDir(h->Node, h->Position);
199 if((Uint)tmp < (Uint)VFS_MAXSKIP)
200 h->Position += (Uint)tmp;
203 } while(tmp != NULL && (Uint)tmp < (Uint)VFS_MAXSKIP);
205 //LOG("tmp = '%s'", tmp);