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 Log_KernelPanic("VFS", "Unable to mount root (Where the **** is rootfs?)");
58 VFS_MkDir("/Devices");
60 VFS_Mount("dev", "/Devices", "devfs", "");
62 Log_Debug("VFS", "Setting max files");
63 CFGINT(CFG_VFS_MAXFILES) = 32;
68 * \fn char *VFS_GetTruePath(const char *Path)
69 * \brief Gets the true path (non-symlink) of a file
71 char *VFS_GetTruePath(const char *Path)
76 tmp = VFS_GetAbsPath(Path);
77 if(tmp == NULL) return NULL;
78 //Log(" VFS_GetTruePath: tmp = '%s'", tmp);
79 node = VFS_ParsePath(tmp, &ret, NULL);
81 //Log(" VFS_GetTruePath: node=%p, ret='%s'", node, ret);
83 if(!node) return NULL;
84 if(node->Close) node->Close(node);
90 * \fn void VFS_GetMemPath(char *Dest, void *Base, Uint Length)
91 * \brief Create a VFS memory pointer path
93 void VFS_GetMemPath(char *Dest, void *Base, Uint Length)
96 itoa( &Dest[1], (tVAddr)Base, 16, BITS/4, '0' );
98 itoa( &Dest[BITS/4+2], Length, 16, BITS/4, '0' );
99 Dest[BITS/2+2] = '\0';
103 * \fn tVFS_Driver *VFS_GetFSByName(const char *Name)
104 * \brief Gets a filesystem structure given a name
106 tVFS_Driver *VFS_GetFSByName(const char *Name)
108 tVFS_Driver *drv = gVFS_Drivers;
110 for(;drv;drv=drv->Next)
112 // Log("strcmp('%s' (%p), '%s') == 0?", drv->Name, drv->Name, Name);
113 if(strcmp(drv->Name, Name) == 0)
120 * \fn int VFS_AddDriver(tVFS_Driver *Info)
122 int VFS_AddDriver(tVFS_Driver *Info)
126 SHORTLOCK( &slDriverListLock );
127 Info->Next = gVFS_Drivers;
129 SHORTREL( &slDriverListLock );
131 VFS_UpdateDriverFile();
137 * \fn void VFS_UpdateDriverFile(void)
138 * \brief Updates the driver list file
140 void VFS_UpdateDriverFile(void)
148 for( drv = gVFS_Drivers; drv; drv = drv->Next )
150 len += 1 + strlen(drv->Name);
154 for( drv = gVFS_Drivers; drv; drv = drv->Next )
156 strcpy( &buf[len], drv->Name );
157 len += strlen(drv->Name);
162 SysFS_UpdateFile( giVFS_DriverFileID, buf, len );
163 if(gsVFS_DriverFile) free(gsVFS_DriverFile);
164 gsVFS_DriverFile = buf;