Various Changes
[tpg/acess2.git] / Kernel / vfs / main.c
1 /* 
2  * Acess 2
3  * Virtual File System
4  */
5 #include <common.h>
6 #include "vfs.h"
7 #include "vfs_int.h"
8 #include "vfs_ext.h"
9
10 // === IMPORTS ===
11 extern tVFS_Driver      gRootFS_Info;
12 extern tVFS_Driver      gDevFS_Info;
13
14 // === GLOBALS ===
15 tVFS_Node       NULLNode = {0};
16 static int      siDriverListLock = 0;
17 tVFS_Driver     *gVFS_Drivers = NULL;
18
19 // === CODE ===
20 /**
21  * \fn int VFS_Init()
22  * \brief Initialises the VFS for use by the kernel and user
23  */
24 int VFS_Init()
25 {
26         // Core Drivers
27         gVFS_Drivers = &gRootFS_Info;
28         gVFS_Drivers->Next = &gDevFS_Info;
29         
30         VFS_Mount("root", "/", "rootfs", "");
31         VFS_MkDir("/Devices");
32         VFS_MkDir("/Mount");
33         VFS_Mount("dev", "/Devices", "devfs", "");
34         
35         CFGINT(CFG_VFS_MAXFILES) = 32;
36         return 0;
37 }
38
39 /**
40  * \fn char *VFS_GetTruePath(char *Path)
41  * \brief Gets the true path (non-symlink) of a file
42  */
43 char *VFS_GetTruePath(char *Path)
44 {
45         tVFS_Node       *node;
46         char    *ret, *tmp;
47         
48         tmp = VFS_GetAbsPath(Path);
49         if(tmp == NULL) return NULL;
50         node = VFS_ParsePath(tmp, &ret);
51         free(tmp);
52         
53         if(!node)       return NULL;
54         if(node->Close) node->Close(node);
55         
56         return ret;
57 }
58
59 /**
60  * \fn void VFS_GetMemPath(void *Base, Uint Length, char *Dest)
61  * \brief Create a VFS memory pointer path
62  */
63 void VFS_GetMemPath(void *Base, Uint Length, char *Dest)
64 {
65         Log("VFS_GetMemPath: (Base=%p, Length=0x%x, Dest=%p)", Base, Length, Dest);
66         Dest[0] = '$';
67         itoa( &Dest[1], (Uint)Base, 16, BITS/4, '0' );
68         Dest[BITS/4+1] = ':';
69         itoa( &Dest[BITS/4+2], Length, 16, BITS/4, '0' );
70         
71         Log("VFS_GetMemPath: Dest = \"%s\"", Dest);
72 }
73
74 /**
75  * \fn tVFS_Driver *VFS_GetFSByName(char *Name)
76  * \brief Gets a filesystem structure given a name
77  */
78 tVFS_Driver *VFS_GetFSByName(char *Name)
79 {
80         tVFS_Driver     *drv = gVFS_Drivers;
81         
82         for(;drv;drv=drv->Next)
83         {
84                 if(strcmp(drv->Name, Name) == 0)
85                         return drv;
86         }
87         return NULL;
88 }
89
90 /**
91  * \fn int VFS_AddDriver(tVFS_Driver *Info)
92  */
93 int VFS_AddDriver(tVFS_Driver *Info)
94 {
95         if(!Info)       return  -1;
96         
97         LOCK( &siDriverListLock );
98         Info->Next = gVFS_Drivers;
99         gVFS_Drivers = Info;
100         RELEASE( &siDriverListLock );
101         
102         return 0;
103 }

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