3 * - Directory Management Functions
11 extern tVFS_Mount *gRootMount;
15 int VFS_MkDir(const char *Path);
16 int VFS_MkNod(const char *Path, Uint Flags);
17 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)
41 int pos = 0, oldpos = 0;
46 ENTER("sPath xFlags", Path, Flags);
48 absPath = VFS_GetAbsPath(Path);
49 LOG("absPath = '%s'", absPath);
51 while( (next = strpos(&absPath[pos+1], '/')) != -1 ) {
52 LOG("next = %i", next);
57 absPath[oldpos] = '\0'; // Mutilate path
58 name = &absPath[oldpos+1];
60 LOG("absPath = '%s', name = '%s'", absPath, name);
63 if(absPath[0] == '\0')
64 parent = VFS_ParsePath("/", NULL, &mountpt);
66 parent = VFS_ParsePath(absPath, NULL, &mountpt);
68 LOG("parent = %p", parent);
72 return -1; // Error Check
76 if( !VFS_CheckACL(parent, VFS_PERM_EXECUTE|VFS_PERM_WRITE) ) {
78 mountpt->OpenHandleCount --;
84 LOG("parent = %p", parent);
86 if(!parent->Type || !parent->Type->MkNod) {
87 Log_Warning("VFS", "VFS_MkNod - Directory has no MkNod method");
88 mountpt->OpenHandleCount --;
94 ret = parent->Type->MkNod(parent, name, Flags);
96 // Free allocated string
100 mountpt->OpenHandleCount --;
103 // Return whatever the driver said
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)
119 ENTER("sName sLink", Name, Link);
121 // Get absolue path name
122 realLink = VFS_GetAbsPath( Link );
124 Log_Warning("VFS", "Path '%s' is badly formed", Link);
129 LOG("realLink = '%s'", realLink);
132 if( VFS_MkNod(Name, VFS_FFLAG_SYMLINK) != 0 ) {
133 Log_Warning("VFS", "Unable to create link node '%s'", Name);
136 return -2; // Make link node
139 // Write link address
140 fp = VFS_Open(Name, VFS_OPENFLAG_WRITE|VFS_OPENFLAG_NOLINK);
141 VFS_Write(fp, strlen(realLink), realLink);
151 * \fn int VFS_ReadDir(int FD, char *Dest)
152 * \brief Read from a directory
154 int VFS_ReadDir(int FD, char *Dest)
156 tVFS_Handle *h = VFS_GetHandle(FD);
159 //ENTER("ph pDest", h, Dest);
161 if(!h || !h->Node->Type || !h->Node->Type->ReadDir) {
166 if(h->Node->Size != -1 && h->Position >= h->Node->Size) {
172 tmp = h->Node->Type->ReadDir(h->Node, h->Position);
173 if((Uint)tmp < (Uint)VFS_MAXSKIP)
174 h->Position += (Uint)tmp;
177 } while(tmp != NULL && (Uint)tmp < (Uint)VFS_MAXSKIP);
179 //LOG("tmp = '%s'", tmp);