12 extern tVFS_Driver gRootFS_Info;
13 extern tVFS_Driver gDevFS_Info;
17 char *VFS_GetTruePath(char *Path);
18 void VFS_GetMemPath(char *Dest, void *Base, Uint Length);
19 tVFS_Driver *VFS_GetFSByName(char *Name);
20 int VFS_AddDriver(tVFS_Driver *Info);
21 void VFS_UpdateDriverFile(void);
24 EXPORT(VFS_AddDriver);
27 tVFS_Node NULLNode = {0};
28 tShortSpinlock slDriverListLock;
29 tVFS_Driver *gVFS_Drivers = NULL;
30 char *gsVFS_DriverFile = NULL;
31 int giVFS_DriverFileID = 0;
33 char *gsVFS_MountFile = NULL;
34 int giVFS_MountFileID = 0;
38 * \fn int VFS_Init(void)
39 * \brief Initialises the VFS for use by the kernel and user
44 gVFS_Drivers = &gRootFS_Info;
45 gVFS_Drivers->Next = &gDevFS_Info;
46 VFS_UpdateDriverFile();
48 // Register with SysFS
49 giVFS_MountFileID = SysFS_RegisterFile("VFS/Mounts", NULL, 0);
50 giVFS_DriverFileID = SysFS_RegisterFile("VFS/Drivers", NULL, 0);
52 if( VFS_Mount("root", "/", "rootfs", "") != 0 ) {
53 Panic("Unable to mount root (Where the **** is rootfs?)");
56 VFS_MkDir("/Devices");
58 VFS_Mount("dev", "/Devices", "devfs", "");
60 CFGINT(CFG_VFS_MAXFILES) = 32;
65 * \fn char *VFS_GetTruePath(char *Path)
66 * \brief Gets the true path (non-symlink) of a file
68 char *VFS_GetTruePath(char *Path)
73 tmp = VFS_GetAbsPath(Path);
74 if(tmp == NULL) return NULL;
75 //Log(" VFS_GetTruePath: tmp = '%s'", tmp);
76 node = VFS_ParsePath(tmp, &ret);
78 //Log(" VFS_GetTruePath: node=%p, ret='%s'", node, ret);
80 if(!node) return NULL;
81 if(node->Close) node->Close(node);
87 * \fn void VFS_GetMemPath(char *Dest, void *Base, Uint Length)
88 * \brief Create a VFS memory pointer path
90 void VFS_GetMemPath(char *Dest, void *Base, Uint Length)
93 itoa( &Dest[1], (Uint)Base, 16, BITS/4, '0' );
95 itoa( &Dest[BITS/4+2], Length, 16, BITS/4, '0' );
96 Dest[BITS/2+2] = '\0';
100 * \fn tVFS_Driver *VFS_GetFSByName(char *Name)
101 * \brief Gets a filesystem structure given a name
103 tVFS_Driver *VFS_GetFSByName(char *Name)
105 tVFS_Driver *drv = gVFS_Drivers;
107 for(;drv;drv=drv->Next)
109 // Log("strcmp('%s' (%p), '%s') == 0?", drv->Name, drv->Name, Name);
110 if(strcmp(drv->Name, Name) == 0)
117 * \fn int VFS_AddDriver(tVFS_Driver *Info)
119 int VFS_AddDriver(tVFS_Driver *Info)
123 SHORTLOCK( &slDriverListLock );
124 Info->Next = gVFS_Drivers;
126 SHORTREL( &slDriverListLock );
128 VFS_UpdateDriverFile();
134 * \fn void VFS_UpdateDriverFile(void)
135 * \brief Updates the driver list file
137 void VFS_UpdateDriverFile(void)
145 for( drv = gVFS_Drivers; drv; drv = drv->Next )
147 len += 1 + strlen(drv->Name);
151 for( drv = gVFS_Drivers; drv; drv = drv->Next )
153 strcpy( &buf[len], drv->Name );
154 len += strlen(drv->Name);
159 SysFS_UpdateFile( giVFS_DriverFileID, buf, len );
160 if(gsVFS_DriverFile) free(gsVFS_DriverFile);
161 gsVFS_DriverFile = buf;