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, NULL);
64 parent = VFS_ParsePath(absPath, NULL, 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 destNode = VFS_ParsePath( _link, &realLink, NULL );
132 // Get true path and node
139 // Check if destination exists
141 Log_Warning("VFS", "File '%s' does not exist, symlink not created", Link);
145 // Derefence the destination
146 if(destNode->Close) destNode->Close(destNode);
149 if( VFS_MkNod(Name, VFS_FFLAG_SYMLINK) != 0 ) {
150 Log_Warning("VFS", "Unable to create link node '%s'", Name);
151 return -2; // Make link node
154 // Write link address
155 fp = VFS_Open(Name, VFS_OPENFLAG_WRITE|VFS_OPENFLAG_NOLINK);
156 VFS_Write(fp, strlen(realLink), realLink);
165 * \fn int VFS_ReadDir(int FD, char *Dest)
166 * \brief Read from a directory
168 int VFS_ReadDir(int FD, char *Dest)
170 tVFS_Handle *h = VFS_GetHandle(FD);
173 //ENTER("ph pDest", h, Dest);
175 if(!h || h->Node->ReadDir == NULL) {
180 if(h->Node->Size != -1 && h->Position >= h->Node->Size) {
186 tmp = h->Node->ReadDir(h->Node, h->Position);
187 if((Uint)tmp < (Uint)VFS_MAXSKIP)
188 h->Position += (Uint)tmp;
191 } while(tmp != NULL && (Uint)tmp < (Uint)VFS_MAXSKIP);
193 //LOG("tmp = '%s'", tmp);