3 * - Directory Management Functions
12 extern tVFS_Mount *gRootMount;
16 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);
23 * \fn int VFS_MkDir(char *Path)
24 * \brief Create a new node
25 * \param Path Path of directory to create
27 int VFS_MkDir(const char *Path)
29 return VFS_MkNod(Path, VFS_FFLAG_DIRECTORY);
33 * \fn int VFS_MkNod(char *Path, Uint Flags)
34 * \brief Create a new node in a directory
35 * \param Path Path of new node
36 * \param Flags Flags to apply to the node
38 int VFS_MkNod(const char *Path, Uint Flags)
42 int pos = 0, oldpos = 0;
47 ENTER("sPath xFlags", Path, Flags);
49 absPath = VFS_GetAbsPath(Path);
50 LOG("absPath = '%s'", absPath);
52 while( (next = strpos(&absPath[pos+1], '/')) != -1 ) {
53 LOG("next = %i", next);
58 absPath[oldpos] = '\0'; // Mutilate path
59 name = &absPath[oldpos+1];
61 LOG("absPath = '%s', name = '%s'", absPath, name);
64 if(absPath[0] == '\0')
65 parent = VFS_ParsePath("/", NULL, &mountpt);
67 parent = VFS_ParsePath(absPath, NULL, &mountpt);
69 LOG("parent = %p", parent);
77 if( !VFS_CheckACL(parent, VFS_PERM_EXECUTE|VFS_PERM_WRITE) ) {
82 LOG("parent = %p", parent);
84 if(!parent->Type || !parent->Type->MkNod) {
85 Log_Warning("VFS", "VFS_MkNod - Directory has no MkNod method");
91 ret = parent->Type->MkNod(parent, name, Flags);
94 // Free allocated string
98 ASSERT(mountpt->OpenHandleCount>0);
99 mountpt->OpenHandleCount --;
102 // Return whatever the driver said
103 LEAVE('i', ret==NULL);
109 ASSERT(mountpt->OpenHandleCount>0);
110 mountpt->OpenHandleCount --;
118 * \fn int VFS_Symlink(const char *Name, const char *Link)
119 * \brief Creates a symlink called \a Name to \a Link
120 * \param Name Name of symbolic link
121 * \param Link Destination of symbolic link
123 int VFS_Symlink(const char *Name, const char *Link)
128 ENTER("sName sLink", Name, Link);
130 // Get absolue path name
131 realLink = VFS_GetAbsPath( Link );
133 Log_Warning("VFS", "Path '%s' is badly formed", Link);
139 LOG("realLink = '%s'", realLink);
142 if( VFS_MkNod(Name, VFS_FFLAG_SYMLINK) != 0 ) {
143 Log_Warning("VFS", "Unable to create link node '%s'", Name);
145 // errno is set by VFS_MkNod
147 return -2; // Make link node
150 // Write link address
151 fp = VFS_Open(Name, VFS_OPENFLAG_WRITE|VFS_OPENFLAG_NOLINK);
153 Log_Warning("VFS", "Unable to open newly created symlink '%s'", Name);
158 VFS_Write(fp, strlen(realLink), realLink);
168 * \fn int VFS_ReadDir(int FD, char *Dest)
169 * \brief Read from a directory
171 int VFS_ReadDir(int FD, char *Dest)
173 tVFS_Handle *h = VFS_GetHandle(FD);
176 //ENTER("ph pDest", h, Dest);
178 if(!h || !h->Node->Type || !h->Node->Type->ReadDir) {
184 if(h->Node->Size != (Uint64)-1 && h->Position >= h->Node->Size) {
191 rv = h->Node->Type->ReadDir(h->Node, h->Position, Dest);