12 extern tVFS_Driver gRootFS_Info;
13 extern tVFS_Driver gDevFS_Info;
18 char *VFS_GetTruePath(const char *Path);
19 void VFS_GetMemPath(char *Dest, void *Base, Uint Length);
20 tVFS_Driver *VFS_GetFSByName(const char *Name);
21 int VFS_AddDriver(tVFS_Driver *Info);
23 void VFS_UpdateDriverFile(void);
26 EXPORT(VFS_AddDriver);
29 tVFS_Node NULLNode = {0};
30 tShortSpinlock slDriverListLock;
31 tVFS_Driver *gVFS_Drivers = NULL;
32 char *gsVFS_DriverFile = NULL;
33 int giVFS_DriverFileID = 0;
35 char *gsVFS_MountFile = NULL;
36 int giVFS_MountFileID = 0;
40 * \fn int VFS_Init(void)
41 * \brief Initialises the VFS for use by the kernel and user
46 gVFS_Drivers = &gRootFS_Info;
47 gVFS_Drivers->Next = &gDevFS_Info;
48 VFS_UpdateDriverFile();
50 // Register with SysFS
51 giVFS_MountFileID = SysFS_RegisterFile("VFS/Mounts", NULL, 0);
52 giVFS_DriverFileID = SysFS_RegisterFile("VFS/Drivers", NULL, 0);
54 if( VFS_Mount("root", "/", "rootfs", "") != 0 ) {
55 Panic("Unable to mount root (Where the **** is rootfs?)");
58 VFS_MkDir("/Devices");
60 VFS_Mount("dev", "/Devices", "devfs", "");
62 CFGINT(CFG_VFS_MAXFILES) = 32;
67 * \fn char *VFS_GetTruePath(const char *Path)
68 * \brief Gets the true path (non-symlink) of a file
70 char *VFS_GetTruePath(const char *Path)
75 tmp = VFS_GetAbsPath(Path);
76 if(tmp == NULL) return NULL;
77 //Log(" VFS_GetTruePath: tmp = '%s'", tmp);
78 node = VFS_ParsePath(tmp, &ret);
80 //Log(" VFS_GetTruePath: node=%p, ret='%s'", node, ret);
82 if(!node) return NULL;
83 if(node->Close) node->Close(node);
89 * \fn void VFS_GetMemPath(char *Dest, void *Base, Uint Length)
90 * \brief Create a VFS memory pointer path
92 void VFS_GetMemPath(char *Dest, void *Base, Uint Length)
95 itoa( &Dest[1], (tVAddr)Base, 16, BITS/4, '0' );
97 itoa( &Dest[BITS/4+2], Length, 16, BITS/4, '0' );
98 Dest[BITS/2+2] = '\0';
102 * \fn tVFS_Driver *VFS_GetFSByName(const char *Name)
103 * \brief Gets a filesystem structure given a name
105 tVFS_Driver *VFS_GetFSByName(const char *Name)
107 tVFS_Driver *drv = gVFS_Drivers;
109 for(;drv;drv=drv->Next)
111 // Log("strcmp('%s' (%p), '%s') == 0?", drv->Name, drv->Name, Name);
112 if(strcmp(drv->Name, Name) == 0)
119 * \fn int VFS_AddDriver(tVFS_Driver *Info)
121 int VFS_AddDriver(tVFS_Driver *Info)
125 SHORTLOCK( &slDriverListLock );
126 Info->Next = gVFS_Drivers;
128 SHORTREL( &slDriverListLock );
130 VFS_UpdateDriverFile();
136 * \fn void VFS_UpdateDriverFile(void)
137 * \brief Updates the driver list file
139 void VFS_UpdateDriverFile(void)
147 for( drv = gVFS_Drivers; drv; drv = drv->Next )
149 len += 1 + strlen(drv->Name);
153 for( drv = gVFS_Drivers; drv; drv = drv->Next )
155 strcpy( &buf[len], drv->Name );
156 len += strlen(drv->Name);
161 SysFS_UpdateFile( giVFS_DriverFileID, buf, len );
162 if(gsVFS_DriverFile) free(gsVFS_DriverFile);
163 gsVFS_DriverFile = buf;