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);
108 ASSERT(mountpt->OpenHandleCount>0);
109 mountpt->OpenHandleCount --;
116 * \fn int VFS_Symlink(const char *Name, const char *Link)
117 * \brief Creates a symlink called \a Name to \a Link
118 * \param Name Name of symbolic link
119 * \param Link Destination of symbolic link
121 int VFS_Symlink(const char *Name, const char *Link)
126 ENTER("sName sLink", Name, Link);
128 // Get absolue path name
129 realLink = VFS_GetAbsPath( Link );
131 Log_Warning("VFS", "Path '%s' is badly formed", Link);
137 LOG("realLink = '%s'", realLink);
140 if( VFS_MkNod(Name, VFS_FFLAG_SYMLINK) != 0 ) {
141 Log_Warning("VFS", "Unable to create link node '%s'", Name);
143 // errno is set by VFS_MkNod
145 return -2; // Make link node
148 // Write link address
149 fp = VFS_Open(Name, VFS_OPENFLAG_WRITE|VFS_OPENFLAG_NOLINK);
151 Log_Warning("VFS", "Unable to open newly created symlink '%s'", Name);
156 VFS_Write(fp, strlen(realLink), realLink);
166 * \fn int VFS_ReadDir(int FD, char *Dest)
167 * \brief Read from a directory
169 int VFS_ReadDir(int FD, char *Dest)
171 tVFS_Handle *h = VFS_GetHandle(FD);
174 //ENTER("ph pDest", h, Dest);
176 if(!h || !h->Node->Type || !h->Node->Type->ReadDir) {
181 if(h->Node->Size != (Uint64)-1 && h->Position >= h->Node->Size) {
187 rv = h->Node->Type->ReadDir(h->Node, h->Position, Dest);