13 extern tVFS_Driver gRootFS_Info;
14 extern tVFS_Driver gDevFS_Info;
19 char *VFS_GetTruePath(const char *Path);
20 void VFS_GetMemPath(char *Dest, void *Base, Uint Length);
21 tVFS_Driver *VFS_GetFSByName(const char *Name);
22 int VFS_AddDriver(tVFS_Driver *Info);
24 void VFS_UpdateDriverFile(void);
27 EXPORT(VFS_AddDriver);
30 tVFS_Node NULLNode = {0};
31 tShortSpinlock slDriverListLock;
32 tVFS_Driver *gVFS_Drivers = NULL;
33 char *gsVFS_DriverFile = NULL;
34 int giVFS_DriverFileID = 0;
36 char *gsVFS_MountFile = NULL;
37 int giVFS_MountFileID = 0;
41 * \fn int VFS_Init(void)
42 * \brief Initialises the VFS for use by the kernel and user
47 gVFS_Drivers = &gRootFS_Info;
48 gVFS_Drivers->Next = &gDevFS_Info;
49 VFS_UpdateDriverFile();
51 // Register with SysFS
52 giVFS_MountFileID = SysFS_RegisterFile("VFS/Mounts", NULL, 0);
53 giVFS_DriverFileID = SysFS_RegisterFile("VFS/Drivers", NULL, 0);
55 if( VFS_Mount("root", "/", "rootfs", "") != 0 ) {
56 Log_KernelPanic("VFS", "Unable to mount root (Where the **** is rootfs?)");
59 VFS_MkDir("/Devices");
61 VFS_Mount("dev", "/Devices", "devfs", "");
63 Log_Debug("VFS", "Setting max files");
64 *Threads_GetMaxFD() = 32;
69 * \fn char *VFS_GetTruePath(const char *Path)
70 * \brief Gets the true path (non-symlink) of a file
72 char *VFS_GetTruePath(const char *Path)
77 tmp = VFS_GetAbsPath(Path);
78 if(tmp == NULL) return NULL;
79 //Log(" VFS_GetTruePath: tmp = '%s'", tmp);
80 node = VFS_ParsePath(tmp, &ret, NULL);
82 //Log(" VFS_GetTruePath: node=%p, ret='%s'", node, ret);
84 if(!node) return NULL;
85 if(node->Type->Close) node->Type->Close(node);
91 * \fn void VFS_GetMemPath(char *Dest, void *Base, Uint Length)
92 * \brief Create a VFS memory pointer path
94 void VFS_GetMemPath(char *Dest, void *Base, Uint Length)
97 itoa( &Dest[1], (tVAddr)Base, 16, BITS/4, '0' );
99 itoa( &Dest[BITS/4+2], Length, 16, BITS/4, '0' );
100 Dest[BITS/2+2] = '\0';
104 * \fn tVFS_Driver *VFS_GetFSByName(const char *Name)
105 * \brief Gets a filesystem structure given a name
107 tVFS_Driver *VFS_GetFSByName(const char *Name)
109 tVFS_Driver *drv = gVFS_Drivers;
111 for(;drv;drv=drv->Next)
113 // Log("strcmp('%s' (%p), '%s') == 0?", drv->Name, drv->Name, Name);
114 if(strcmp(drv->Name, Name) == 0)
121 * \fn int VFS_AddDriver(tVFS_Driver *Info)
123 int VFS_AddDriver(tVFS_Driver *Info)
127 SHORTLOCK( &slDriverListLock );
128 Info->Next = gVFS_Drivers;
130 SHORTREL( &slDriverListLock );
132 VFS_UpdateDriverFile();
138 * \fn void VFS_UpdateDriverFile(void)
139 * \brief Updates the driver list file
141 void VFS_UpdateDriverFile(void)
149 for( drv = gVFS_Drivers; drv; drv = drv->Next )
151 len += 1 + strlen(drv->Name);
155 for( drv = gVFS_Drivers; drv; drv = drv->Next )
157 strcpy( &buf[len], drv->Name );
158 len += strlen(drv->Name);
163 SysFS_UpdateFile( giVFS_DriverFileID, buf, len );
164 if(gsVFS_DriverFile) free(gsVFS_DriverFile);
165 gsVFS_DriverFile = buf;