Kernel - Slight reworks to timer code
[tpg/acess2.git] / Kernel / vfs / open.c
index 448f09b..1536d1a 100644 (file)
@@ -7,6 +7,7 @@
 #include "vfs.h"
 #include "vfs_int.h"
 #include "vfs_ext.h"
+#include <threads.h>
 
 // === CONSTANTS ===
 #define        OPEN_MOUNT_ROOT 1
@@ -35,9 +36,9 @@ char *VFS_GetAbsPath(const char *Path)
        char    *tmpStr;
        int             iPos = 0;
        int             iPos2 = 0;
-       const char      *chroot = CFGPTR(CFG_VFS_CHROOT);
+       const char      *chroot = *Threads_GetChroot();
         int    chrootLen;
-       const char      *cwd = CFGPTR(CFG_VFS_CWD);
+       const char      *cwd = *Threads_GetCWD();
         int    cwdLen;
        
        ENTER("sPath", Path);
@@ -452,13 +453,18 @@ int VFS_int_CreateHandle( tVFS_Node *Node, tVFS_Mount *Mount, int Mode )
  * \fn int VFS_Open(const char *Path, Uint Mode)
  * \brief Open a file
  */
-int VFS_Open(const char *Path, Uint Mode)
+int VFS_Open(const char *Path, Uint Flags)
+{
+       return VFS_OpenEx(Path, Flags, 0);
+}
+
+int VFS_OpenEx(const char *Path, Uint Flags, Uint Mode)
 {
        tVFS_Node       *node;
        tVFS_Mount      *mnt;
        char    *absPath;
        
-       ENTER("sPath xMode", Path, Mode);
+       ENTER("sPath xFlags oMode", Path, Flags);
        
        // Get absolute path
        absPath = VFS_GetAbsPath(Path);
@@ -467,19 +473,32 @@ int VFS_Open(const char *Path, Uint Mode)
                LEAVE_RET('i', -1);
        }
        LOG("absPath = \"%s\"", absPath);
+       
        // Parse path and get mount point
        node = VFS_ParsePath(absPath, NULL, &mnt);
+       
+       // Create file if requested and it doesn't exist
+       if( !node && (Flags & VFS_OPENFLAG_CREATE) )
+       {
+               // TODO: Translate `Mode` into ACL and node flags
+               // Get parent, create node
+               VFS_MkNod(absPath, 0);
+               node = VFS_ParsePath(absPath, NULL, &mnt);
+       }
+       
        // Free generated path
        free(absPath);
        
-       if(!node) {
+       // Check for error
+       if(!node)
+       {
                LOG("Cannot find node");
                errno = ENOENT;
                LEAVE_RET('i', -1);
        }
        
        // Check for symlinks
-       if( !(Mode & VFS_OPENFLAG_NOLINK) && (node->Flags & VFS_FFLAG_SYMLINK) )
+       if( !(Flags & VFS_OPENFLAG_NOLINK) && (node->Flags & VFS_FFLAG_SYMLINK) )
        {
                char    tmppath[node->Size+1];
                if( node->Size > MAX_PATH_LEN ) {
@@ -503,7 +522,7 @@ int VFS_Open(const char *Path, Uint Mode)
                }
        }
 
-       LEAVE_RET('x', VFS_int_CreateHandle(node, mnt, Mode));
+       LEAVE_RET('x', VFS_int_CreateHandle(node, mnt, Flags));
 }
 
 
@@ -644,11 +663,13 @@ int VFS_ChDir(const char *Dest)
        // Close file
        VFS_Close(fd);
        
-       // Free old working directory
-       if( CFGPTR(CFG_VFS_CWD) )
-               free( CFGPTR(CFG_VFS_CWD) );
-       // Set new
-       CFGPTR(CFG_VFS_CWD) = buf;
+       {
+               char    **cwdptr = Threads_GetCWD();
+               // Free old working directory
+               if( *cwdptr )   free( *cwdptr );
+               // Set new
+               *cwdptr = buf;
+       }
        
        Log("Updated CWD to '%s'", buf);
        
@@ -692,12 +713,13 @@ int VFS_ChRoot(const char *New)
        
        // Close file
        VFS_Close(fd);
-       
-       // Free old working directory
-       if( CFGPTR(CFG_VFS_CHROOT) )
-               free( CFGPTR(CFG_VFS_CHROOT) );
-       // Set new
-       CFGPTR(CFG_VFS_CHROOT) = buf;
+
+       // Update       
+       {
+               char    **chroot_ptr = Threads_GetChroot();
+               if( *chroot_ptr )       free( *chroot_ptr );
+               *chroot_ptr = buf;
+       }
        
        LOG("Updated Root to '%s'", buf);
        

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