Kernel/VFS - Fixed missuse of strcmp that caused userland compilations to break
[tpg/acess2.git] / KernelLand / Kernel / vfs / open.c
1 /*
2  * Acess2 VFS
3  * - Open, Close and ChDir
4  */
5 #define DEBUG   0
6 #include <acess.h>
7 #include "vfs.h"
8 #include "vfs_int.h"
9 #include "vfs_ext.h"
10 #include <threads.h>
11
12 // === CONSTANTS ===
13 #define OPEN_MOUNT_ROOT 1
14 #define MAX_PATH_SLASHES        256
15 #define MAX_NESTED_LINKS        4
16 #define MAX_PATH_LEN    255
17
18 // === IMPORTS ===
19 extern tVFS_Mount       *gVFS_RootMount;
20 extern int      VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode);
21 extern tVFS_Node        *VFS_MemFile_Create(const char *Path);
22
23 // === PROTOTYPES ===
24  int    VFS_int_CreateHandle( tVFS_Node *Node, tVFS_Mount *Mount, int Mode );
25
26 // === CODE ===
27 /**
28  * \fn char *VFS_GetAbsPath(const char *Path)
29  * \brief Create an absolute path from a relative one
30  */
31 char *VFS_GetAbsPath(const char *Path)
32 {
33         char    *ret;
34          int    pathLen = strlen(Path);
35         char    *pathComps[MAX_PATH_SLASHES];
36         char    *tmpStr;
37         int             iPos = 0;
38         int             iPos2 = 0;
39         const char      *chroot = *Threads_GetChroot();
40          int    chrootLen;
41         const char      *cwd = *Threads_GetCWD();
42          int    cwdLen;
43         
44         ENTER("sPath", Path);
45         
46         // Memory File
47         if(Path[0] == '$') {
48                 ret = malloc(strlen(Path)+1);
49                 if(!ret) {
50                         Log_Warning("VFS", "VFS_GetAbsPath: malloc() returned NULL");
51                         return NULL;
52                 }
53                 strcpy(ret, Path);
54                 LEAVE('p', ret);
55                 return ret;
56         }
57         
58         // - Fetch ChRoot
59         if( chroot == NULL )
60                 chroot = "";
61         chrootLen = strlen(chroot);
62         // Trim trailing slash off chroot
63         if( chrootLen && chroot[chrootLen - 1] == '/' )
64                 chrootLen -= 1;
65         
66         // Check if the path is already absolute
67         if(Path[0] == '/') {
68                 ret = malloc(chrootLen + pathLen + 1);
69                 if(!ret) {
70                         Log_Warning("VFS", "VFS_GetAbsPath: malloc() returned NULL");
71                         return NULL;
72                 }
73                 strcpy(ret + chrootLen, Path);
74         }
75         else {
76                 if(cwd == NULL) {
77                         cwd = "/";
78                         cwdLen = 1;
79                 }
80                 else {
81                         cwdLen = strlen(cwd);
82                 }
83                 // Prepend the current directory
84                 ret = malloc(chrootLen + cwdLen + 1 + pathLen + 1 );
85                 strcpy(ret+chrootLen, cwd);
86                 ret[cwdLen] = '/';
87                 strcpy(ret+chrootLen+cwdLen+1, Path);
88                 //Log("ret = '%s'", ret);
89         }
90         
91         // Parse Path
92         pathComps[iPos++] = tmpStr = ret+chrootLen+1;
93         while(*tmpStr)
94         {
95                 if(*tmpStr++ == '/')
96                 {
97                         pathComps[iPos++] = tmpStr;
98                         if(iPos == MAX_PATH_SLASHES) {
99                                 LOG("Path '%s' has too many elements", Path);
100                                 free(ret);
101                                 LEAVE('n');
102                                 return NULL;
103                         }
104                 }
105         }
106         pathComps[iPos] = NULL;
107         
108         // Cleanup
109         iPos2 = iPos = 0;
110         while(pathComps[iPos])
111         {
112                 tmpStr = pathComps[iPos];
113                 // Always Increment iPos
114                 iPos++;
115                 // ..
116                 if(tmpStr[0] == '.' && tmpStr[1] == '.' && (tmpStr[2] == '/' || tmpStr[2] == '\0') )
117                 {
118                         if(iPos2 != 0)
119                                 iPos2 --;
120                         continue;
121                 }
122                 // .
123                 if(tmpStr[0] == '.' && (tmpStr[1] == '/' || tmpStr[1] == '\0') )
124                 {
125                         continue;
126                 }
127                 // Empty
128                 if(tmpStr[0] == '/' || tmpStr[0] == '\0')
129                 {
130                         continue;
131                 }
132                 
133                 // Set New Position
134                 pathComps[iPos2] = tmpStr;
135                 iPos2++;
136         }
137         pathComps[iPos2] = NULL;
138         
139         // Build New Path
140         iPos2 = chrootLen + 1;  iPos = 0;
141         ret[0] = '/';
142         while(pathComps[iPos])
143         {
144                 tmpStr = pathComps[iPos];
145                 while(*tmpStr && *tmpStr != '/')
146                 {
147                         ret[iPos2++] = *tmpStr;
148                         tmpStr++;
149                 }
150                 ret[iPos2++] = '/';
151                 iPos++;
152         }
153         if(iPos2 > 1)
154                 ret[iPos2-1] = 0;
155         else
156                 ret[iPos2] = 0;
157
158         // Prepend the chroot
159         if(chrootLen)
160                 memcpy( ret, chroot, chrootLen );
161         
162         LEAVE('s', ret);
163 //      Log_Debug("VFS", "VFS_GetAbsPath: RETURN '%s'", ret);
164         return ret;
165 }
166
167 /**
168  * \fn char *VFS_ParsePath(const char *Path, char **TruePath)
169  * \brief Parses a path, resolving sysmlinks and applying permissions
170  */
171 tVFS_Node *VFS_ParsePath(const char *Path, char **TruePath, tVFS_Mount **MountPoint)
172 {
173         tVFS_Mount      *mnt, *longestMount;
174          int    cmp, retLength = 0;
175          int    ofs, nextSlash;
176          int    iNestedLinks = 0;
177         tVFS_Node       *curNode, *tmpNode;
178         char    *tmp;
179         char    path_buffer[MAX_PATH_LEN+1];
180         
181         ENTER("sPath pTruePath", Path, TruePath);
182         
183         // HACK: Memory File
184         if(Threads_GetUID() == 0 && Path[0] == '$') {
185                 if(TruePath) {
186                         *TruePath = malloc(strlen(Path)+1);
187                         strcpy(*TruePath, Path);
188                 }
189                 curNode = VFS_MemFile_Create(Path);
190                 if(MountPoint) {
191                         *MountPoint = NULL;
192                 }
193                 LEAVE('p', curNode);
194                 return curNode;
195         }
196
197 restart_parse:  
198         // For root we always fast return
199         if(Path[0] == '/' && Path[1] == '\0') {
200                 if(TruePath) {
201                         *TruePath = malloc( gVFS_RootMount->MountPointLen+1 );
202                         strcpy(*TruePath, gVFS_RootMount->MountPoint);
203                 }
204                 if(MountPoint)  *MountPoint = gVFS_RootMount;
205                 LEAVE('p', gVFS_RootMount->RootNode);
206                 return gVFS_RootMount->RootNode;
207         }
208         
209         // Check if there is anything mounted
210         if(!gVFS_Mounts) {
211                 Log_Error("VFS", "VFS_ParsePath - No filesystems mounted");
212                 return NULL;
213         }
214         
215         // Find Mountpoint
216         longestMount = gVFS_RootMount;
217         for(mnt = gVFS_Mounts; mnt; mnt = mnt->Next)
218         {
219                 // Quick Check
220                 if( Path[mnt->MountPointLen] != '/' && Path[mnt->MountPointLen] != '\0')
221                         continue;
222                 // Length Check - If the length is smaller than the longest match sofar
223                 if(mnt->MountPointLen < longestMount->MountPointLen)    continue;
224                 // String Compare
225                 cmp = strncmp(Path, mnt->MountPoint, mnt->MountPointLen);
226                 
227                 #if OPEN_MOUNT_ROOT
228                 // Fast Break - Request Mount Root
229                 if(Path[mnt->MountPointLen] == '\0') {
230                         if(TruePath) {
231                                 *TruePath = malloc( mnt->MountPointLen+1 );
232                                 strcpy(*TruePath, mnt->MountPoint);
233                         }
234                         if(MountPoint)
235                                 *MountPoint = mnt;
236                         LEAVE('p', mnt->RootNode);
237                         return mnt->RootNode;
238                 }
239                 #endif
240                 // Not a match, continue
241                 if(cmp != 0)    continue;
242                 longestMount = mnt;
243         }
244         
245         // Save to shorter variable
246         mnt = longestMount;
247         
248         LOG("mnt = {MountPoint:\"%s\"}", mnt->MountPoint);
249         
250         // Initialise String
251         if(TruePath)
252         {
253                 // Assumes that the resultant path (here) will not be > strlen(Path) + 1
254                 *TruePath = malloc( strlen(Path) + 1 );
255                 strcpy(*TruePath, mnt->MountPoint);
256                 retLength = mnt->MountPointLen;
257         }
258         
259         curNode = mnt->RootNode;
260         curNode->ReferenceCount ++;     
261         // Parse Path
262         ofs = mnt->MountPointLen+1;
263         for(; (nextSlash = strpos(&Path[ofs], '/')) != -1; ofs += nextSlash + 1)
264         {
265                 char    pathEle[nextSlash+1];
266                 
267                 // Empty String
268                 if(nextSlash == 0)      continue;
269                 
270                 memcpy(pathEle, &Path[ofs], nextSlash);
271                 pathEle[nextSlash] = 0;
272         
273                 // Check permissions on root of filesystem
274                 if( !VFS_CheckACL(curNode, VFS_PERM_EXECUTE) ) {
275                         LOG("Permissions failure on '%s'", Path);
276                         goto _error;
277                 }
278                 
279                 // Check if the node has a FindDir method
280                 if( !curNode->Type->FindDir )
281                 {
282                         LOG("Finddir failure on '%s'", Path);
283                         goto _error;
284                 }
285                 LOG("FindDir{=%p}(%p, '%s')", curNode->Type->FindDir, curNode, pathEle);
286                 // Get Child Node
287                 tmpNode = curNode->Type->FindDir(curNode, pathEle);
288                 LOG("tmpNode = %p", tmpNode);
289                 _CloseNode( curNode );
290                 curNode = tmpNode;
291                 
292                 // Error Check
293                 if(!curNode) {
294                         LOG("Node '%s' not found in dir '%s'", pathEle, Path);
295                         goto _error;
296                 }
297                 
298                 // Handle Symbolic Links
299                 if(curNode->Flags & VFS_FFLAG_SYMLINK) {
300                         if(TruePath) {
301                                 free(*TruePath);
302                                 *TruePath = NULL;
303                         }
304                         if(!curNode->Type || !curNode->Type->Read) {
305                                 Log_Warning("VFS", "VFS_ParsePath - Read of symlink node %p'%s' is NULL",
306                                         curNode, Path);
307                                 goto _error;
308                         }
309                         
310                         if(iNestedLinks > MAX_NESTED_LINKS) {
311                                 Log_Notice("VFS", "VFS_ParsePath - Nested link limit exceeded");
312                                 goto _error;
313                         }
314                         
315                         // Parse Symlink Path
316                         // - Just update the path variable and restart the function
317                         // > Count nested symlinks and limit to some value (counteracts loops)
318                         {
319                                  int    remlen = strlen(Path) - (ofs + nextSlash);
320                                 if( curNode->Size + remlen > MAX_PATH_LEN ) {
321                                         Log_Warning("VFS", "VFS_ParsePath - Symlinked path too long");
322                                         goto _error;
323                                 }
324                                 curNode->Type->Read( curNode, 0, curNode->Size, path_buffer );
325                                 path_buffer[ curNode->Size ] = '\0';
326                                 LOG("path_buffer = '%s'", path_buffer);
327                                 strcat(path_buffer, Path + ofs+nextSlash);
328                                 
329                                 Path = path_buffer;
330 //                              Log_Debug("VFS", "VFS_ParsePath: Symlink translated to '%s'", Path);
331                                 iNestedLinks ++;
332                         }
333
334                         // EVIL: Goto :)
335                         LOG("Symlink -> '%s', restart", Path);
336                         goto restart_parse;
337                 }
338                 
339                 // Handle Non-Directories
340                 if( !(curNode->Flags & VFS_FFLAG_DIRECTORY) )
341                 {
342                         Log_Warning("VFS", "VFS_ParsePath - Path segment is not a directory");
343                         goto _error;
344                 }
345                 
346                 // Check if path needs extending
347                 if(!TruePath)   continue;
348                 
349                 // Increase buffer space
350                 tmp = realloc( *TruePath, retLength + strlen(pathEle) + 1 + 1 );
351                 // Check if allocation succeeded
352                 if(!tmp) {
353                         Log_Warning("VFS", "VFS_ParsePath - Unable to reallocate true path buffer");
354                         goto _error;
355                 }
356                 *TruePath = tmp;
357                 // Append to path
358                 (*TruePath)[retLength] = '/';
359                 strcpy(*TruePath+retLength+1, pathEle);
360                 
361                 LOG("*TruePath = '%s'", *TruePath);
362                 
363                 // - Extend Path
364                 retLength += nextSlash + 1;
365         }
366
367         // Check final finddir call     
368         if( !curNode->Type || !curNode->Type->FindDir ) {
369                 Log_Warning("VFS", "VFS_ParsePath - FindDir doesn't exist for element of '%s'", Path);
370                 goto _error;
371         }
372         
373         // Get last node
374         LOG("FindDir(%p, '%s')", curNode, &Path[ofs]);
375         tmpNode = curNode->Type->FindDir(curNode, &Path[ofs]);
376         LOG("tmpNode = %p", tmpNode);
377         // Check if file was found
378         if(!tmpNode) {
379                 LOG("Node '%s' not found in dir '%s'", &Path[ofs], Path);
380                 goto _error;
381         }
382         _CloseNode( curNode );
383         
384         if(TruePath)
385         {
386                 // Increase buffer space
387                 tmp = realloc(*TruePath, retLength + strlen(&Path[ofs]) + 1 + 1);
388                 // Check if allocation succeeded
389                 if(!tmp) {
390                         Log_Warning("VFS", "VFS_ParsePath -  Unable to reallocate true path buffer");
391                         goto _error;
392                 }
393                 *TruePath = tmp;
394                 // Append to path
395                 (*TruePath)[retLength] = '/';
396                 strcpy(*TruePath + retLength + 1, &Path[ofs]);
397                 // - Extend Path
398                 //retLength += strlen(tmpNode->Name) + 1;
399         }
400
401         if( MountPoint ) {
402                 *MountPoint = mnt;
403         }
404         
405         LEAVE('p', tmpNode);
406         return tmpNode;
407
408 _error:
409         _CloseNode( curNode );
410         
411         if(TruePath && *TruePath) {
412                 free(*TruePath);
413                 *TruePath = NULL;
414         }
415         LEAVE('n');
416         return NULL;
417 }
418
419 /**
420  * \brief Create and return a handle number for the given node and mode
421  */
422 int VFS_int_CreateHandle( tVFS_Node *Node, tVFS_Mount *Mount, int Mode )
423 {
424          int    i;
425         
426         ENTER("pNode pMount xMode", Node, Mount, Mode);
427
428         i = 0;
429         i |= (Mode & VFS_OPENFLAG_EXEC) ? VFS_PERM_EXECUTE : 0;
430         i |= (Mode & VFS_OPENFLAG_READ) ? VFS_PERM_READ : 0;
431         i |= (Mode & VFS_OPENFLAG_WRITE) ? VFS_PERM_WRITE : 0;
432         
433         LOG("i = 0b%b", i);
434         
435         // Permissions Check
436         if( !VFS_CheckACL(Node, i) ) {
437                 _CloseNode( Node );
438                 Log_Log("VFS", "VFS_int_CreateHandle: Permissions Failed");
439                 errno = EACCES;
440                 LEAVE_RET('i', -1);
441         }
442         
443         i = VFS_AllocHandle( !!(Mode & VFS_OPENFLAG_USER), Node, Mode );
444         if( i < 0 ) {
445                 Log_Notice("VFS", "VFS_int_CreateHandle: Out of handles");
446                 errno = ENFILE;
447                 LEAVE_RET('i', -1);
448         }
449
450         VFS_GetHandle(i)->Mount = Mount;
451
452         LEAVE_RET('x', i);
453 }
454
455 /**
456  * \fn int VFS_Open(const char *Path, Uint Mode)
457  * \brief Open a file
458  */
459 int VFS_Open(const char *Path, Uint Flags)
460 {
461         return VFS_OpenEx(Path, Flags, 0);
462 }
463
464 int VFS_OpenEx(const char *Path, Uint Flags, Uint Mode)
465 {
466         tVFS_Node       *node;
467         tVFS_Mount      *mnt;
468         char    *absPath;
469         
470         ENTER("sPath xFlags oMode", Path, Flags);
471         
472         // Get absolute path
473         absPath = VFS_GetAbsPath(Path);
474         if(absPath == NULL) {
475                 Log_Warning("VFS", "VFS_Open: Path expansion failed '%s'", Path);
476                 LEAVE_RET('i', -1);
477         }
478         LOG("absPath = \"%s\"", absPath);
479         
480         // Parse path and get mount point
481         node = VFS_ParsePath(absPath, NULL, &mnt);
482         
483         // Create file if requested and it doesn't exist
484         if( !node && (Flags & VFS_OPENFLAG_CREATE) )
485         {
486                 // TODO: Translate `Mode` into ACL and node flags
487                 // Get parent, create node
488                 VFS_MkNod(absPath, 0);
489                 node = VFS_ParsePath(absPath, NULL, &mnt);
490         }
491         
492         // Free generated path
493         free(absPath);
494         
495         // Check for error
496         if(!node)
497         {
498                 LOG("Cannot find node");
499                 errno = ENOENT;
500                 LEAVE_RET('i', -1);
501         }
502         
503         // Check for symlinks
504         if( !(Flags & VFS_OPENFLAG_NOLINK) && (node->Flags & VFS_FFLAG_SYMLINK) )
505         {
506                 char    tmppath[node->Size+1];
507                 if( node->Size > MAX_PATH_LEN ) {
508                         Log_Warning("VFS", "VFS_Open - Symlink is too long (%i)", node->Size);
509                         LEAVE_RET('i', -1);
510                 }
511                 if( !node->Type || !node->Type->Read ) {
512                         Log_Warning("VFS", "VFS_Open - No read method on symlink");
513                         LEAVE_RET('i', -1);
514                 }
515                 // Read symlink's path
516                 node->Type->Read( node, 0, node->Size, tmppath );
517                 tmppath[ node->Size ] = '\0';
518                 _CloseNode( node );
519                 // Open the target
520                 node = VFS_ParsePath(tmppath, NULL, &mnt);
521                 if(!node) {
522                         LOG("Cannot find symlink target node (%s)", tmppath);
523                         errno = ENOENT;
524                         LEAVE_RET('i', -1);
525                 }
526         }
527
528         LEAVE_RET('x', VFS_int_CreateHandle(node, mnt, Flags));
529 }
530
531
532 /**
533  * \brief Open a file from an open directory
534  */
535 int VFS_OpenChild(int FD, const char *Name, Uint Mode)
536 {
537         tVFS_Handle     *h;
538         tVFS_Node       *node;
539         
540         ENTER("xFD sName xMode", FD, Name, Mode);
541
542         // Get handle
543         h = VFS_GetHandle(FD);
544         if(h == NULL) {
545                 Log_Warning("VFS", "VFS_OpenChild - Invalid file handle 0x%x", FD);
546                 errno = EINVAL;
547                 LEAVE_RET('i', -1);
548         }
549         
550         // Check for directory
551         if( !(h->Node->Flags & VFS_FFLAG_DIRECTORY) ) {
552                 Log_Warning("VFS", "VFS_OpenChild - Passed handle is not a directory");
553                 errno = ENOTDIR;
554                 LEAVE_RET('i', -1);
555         }
556
557         // Sanity check
558         if( !h->Node->Type || !h->Node->Type->FindDir ) {
559                 Log_Error("VFS", "VFS_OpenChild - Node does not have a type/is missing FindDir");
560                 errno = ENOTDIR;
561                 LEAVE_RET('i', -1);
562         }
563         
564         // Find Child
565         node = h->Node->Type->FindDir(h->Node, Name);
566         if(!node) {
567                 errno = ENOENT;
568                 LEAVE_RET('i', -1);
569         }
570
571         LEAVE_RET('x', VFS_int_CreateHandle(node, h->Mount, Mode));
572 }
573
574 int VFS_OpenInode(Uint32 Mount, Uint64 Inode, int Mode)
575 {
576         tVFS_Mount      *mnt;
577         tVFS_Node       *node;
578
579         ENTER("iMount XInode xMode", Mount, Inode, Mode);
580         
581         // Get mount point
582         mnt = VFS_GetMountByIdent(Mount);
583         if( !mnt ) {
584                 LOG("Mount point ident invalid");
585                 errno = ENOENT;
586                 LEAVE_RET('i', -1);
587         }
588         
589         // Does the filesystem support this?
590         if( !mnt->Filesystem->GetNodeFromINode ) {
591                 LOG("Filesystem does not support inode accesses");
592                 errno = ENOENT;
593                 LEAVE_RET('i', -1);
594         }
595
596         // Get node
597         node = mnt->Filesystem->GetNodeFromINode(mnt->RootNode, Inode);
598         if( !node ) {
599                 LOG("Unable to find inode");
600                 errno = ENOENT;
601                 LEAVE_RET('i', -1);
602         }
603         
604         LEAVE_RET('x', VFS_int_CreateHandle(node, mnt, Mode));
605 }
606
607 /**
608  * \fn void VFS_Close(int FD)
609  * \brief Closes an open file handle
610  */
611 void VFS_Close(int FD)
612 {
613         tVFS_Handle     *h;
614         
615         // Get handle
616         h = VFS_GetHandle(FD);
617         if(h == NULL) {
618                 Log_Warning("VFS", "Invalid file handle passed to VFS_Close, 0x%x", FD);
619                 return;
620         }
621         
622         #if VALIDATE_VFS_FUNCTIPONS
623         if(h->Node->Close && !MM_GetPhysAddr(h->Node->Close)) {
624                 Log_Warning("VFS", "Node %p's ->Close method is invalid (%p)",
625                         h->Node, h->Node->Close);
626                 return ;
627         }
628         #endif
629         
630         _CloseNode(h->Node);
631         
632         h->Node = NULL;
633 }
634
635 /**
636  * \brief Change current working directory
637  */
638 int VFS_ChDir(const char *Dest)
639 {
640         char    *buf;
641          int    fd;
642         tVFS_Handle     *h;
643         
644         // Create Absolute
645         buf = VFS_GetAbsPath(Dest);
646         if(buf == NULL) {
647                 Log_Notice("VFS", "VFS_ChDir: Path expansion failed");
648                 return -1;
649         }
650         
651         // Check if path exists
652         fd = VFS_Open(buf, VFS_OPENFLAG_EXEC);
653         if(fd == -1) {
654                 Log_Notice("VFS", "VFS_ChDir: Path is invalid");
655                 return -1;
656         }
657         
658         // Get node so we can check for directory
659         h = VFS_GetHandle(fd);
660         if( !(h->Node->Flags & VFS_FFLAG_DIRECTORY) ) {
661                 Log("VFS_ChDir: Path is not a directory");
662                 VFS_Close(fd);
663                 return -1;
664         }
665         
666         // Close file
667         VFS_Close(fd);
668         
669         {
670                 char    **cwdptr = Threads_GetCWD();
671                 // Free old working directory
672                 if( *cwdptr )   free( *cwdptr );
673                 // Set new
674                 *cwdptr = buf;
675         }
676         
677         Log("Updated CWD to '%s'", buf);
678         
679         return 1;
680 }
681
682 /**
683  * \fn int VFS_ChRoot(char *New)
684  * \brief Change current root directory
685  */
686 int VFS_ChRoot(const char *New)
687 {
688         char    *buf;
689          int    fd;
690         tVFS_Handle     *h;
691         
692         if(New[0] == '/' && New[1] == '\0')
693                 return 1;       // What a useless thing to ask!
694         
695         // Create Absolute
696         buf = VFS_GetAbsPath(New);
697         if(buf == NULL) {
698                 LOG("Path expansion failed");
699                 return -1;
700         }
701         
702         // Check if path exists
703         fd = VFS_Open(buf, VFS_OPENFLAG_EXEC);
704         if(fd == -1) {
705                 LOG("Path is invalid");
706                 return -1;
707         }
708         
709         // Get node so we can check for directory
710         h = VFS_GetHandle(fd);
711         if( !(h->Node->Flags & VFS_FFLAG_DIRECTORY) ) {
712                 LOG("Path is not a directory");
713                 VFS_Close(fd);
714                 return -1;
715         }
716         
717         // Close file
718         VFS_Close(fd);
719
720         // Update       
721         {
722                 char    **chroot_ptr = Threads_GetChroot();
723                 if( *chroot_ptr )       free( *chroot_ptr );
724                 *chroot_ptr = buf;
725         }
726         
727         LOG("Updated Root to '%s'", buf);
728         
729         return 1;
730 }
731
732 // === EXPORTS ===
733 EXPORT(VFS_Open);
734 EXPORT(VFS_Close);

UCC git Repository :: git.ucc.asn.au