Initial commit of kernel only
[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;
47         
48         node = VFS_ParsePath(Path, &ret);
49         
50         if(!node)       return NULL;
51         if(node->Close) node->Close(node);
52         
53         return ret;
54 }
55
56 /**
57  * \fn void VFS_GetMemPath(void *Base, Uint Length, char *Dest)
58  * \brief Create a VFS memory pointer path
59  */
60 void VFS_GetMemPath(void *Base, Uint Length, char *Dest)
61 {
62         Log("VFS_GetMemPath: (Base=%p, Length=0x%x, Dest=%p)", Base, Length, Dest);
63         Dest[0] = '$';
64         itoa( &Dest[1], (Uint)Base, 16, BITS/4, '0' );
65         Dest[BITS/4+1] = ':';
66         itoa( &Dest[BITS/4+2], Length, 16, BITS/4, '0' );
67         
68         Log("VFS_GetMemPath: Dest = \"%s\"", Dest);
69 }
70
71 /**
72  * \fn tVFS_Driver *VFS_GetFSByName(char *Name)
73  * \brief Gets a filesystem structure given a name
74  */
75 tVFS_Driver *VFS_GetFSByName(char *Name)
76 {
77         tVFS_Driver     *drv = gVFS_Drivers;
78         
79         for(;drv;drv=drv->Next)
80         {
81                 if(strcmp(drv->Name, Name) == 0)
82                         return drv;
83         }
84         return NULL;
85 }
86
87 /**
88  * \fn int VFS_AddDriver(tVFS_Driver *Info)
89  */
90 int VFS_AddDriver(tVFS_Driver *Info)
91 {
92         if(!Info)       return  -1;
93         
94         LOCK( &siDriverListLock );
95         Info->Next = gVFS_Drivers;
96         gVFS_Drivers = Info;
97         RELEASE( &siDriverListLock );
98         
99         return 0;
100 }

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