2 * Acess Micro - VFS Server version 1
10 extern int giVFS_MountFileID;
11 extern char *gsVFS_MountFile;
15 int VFS_Mount(const char *Device, const char *MountPoint, const char *Filesystem, const char *Options);
17 void VFS_UpdateMountFile(void);
20 tMutex glVFS_MountList;
21 tVFS_Mount *gVFS_Mounts;
22 tVFS_Mount *gVFS_RootMount = NULL;
26 * \brief Mount a device
27 * \param Device Device string to mount
28 * \param MountPoint Destination for the mount
29 * \param Filesystem Filesystem to use for the mount
30 * \param Options Options to be passed to the filesystem
31 * \return -1 on Invalid FS, -2 on No Mem, 0 on success
33 * Mounts the filesystem on \a Device at \a MountPoint using the driver
34 * \a Filesystem. The options in the string \a Options is passed to the
37 int VFS_Mount(const char *Device, const char *MountPoint, const char *Filesystem, const char *Options)
41 int deviceLen = strlen(Device);
42 int mountLen = strlen(MountPoint);
43 int argLen = strlen(Options);
46 fs = VFS_GetFSByName(Filesystem);
48 Log_Warning("VFS", "VFS_Mount - Unknown FS Type '%s'", Filesystem);
52 // Create mount information
53 mnt = malloc( sizeof(tVFS_Mount)+deviceLen+1+mountLen+1+argLen+1 );
58 // HACK: Forces VFS_ParsePath to fall back on root
59 if(mountLen == 1 && MountPoint[0] == '/')
60 mnt->MountPointLen = 0;
62 mnt->MountPointLen = mountLen;
67 mnt->Device = &mnt->StrData[0];
68 memcpy( mnt->Device, Device, deviceLen+1 );
70 mnt->MountPoint = &mnt->StrData[deviceLen+1];
71 memcpy( mnt->MountPoint, MountPoint, mountLen+1 );
73 mnt->Options = &mnt->StrData[deviceLen+1+mountLen+1];
74 memcpy( mnt->Options, Options, argLen+1 );
77 mnt->RootNode = fs->InitDevice(Device, NULL); //&ArgString);
84 if(!gVFS_RootMount) gVFS_RootMount = mnt;
87 Mutex_Acquire( &glVFS_MountList );
92 for( tmp = gVFS_Mounts; tmp->Next; tmp = tmp->Next );
99 Mutex_Release( &glVFS_MountList );
101 Log_Log("VFS", "Mounted '%s' to '%s' ('%s')", Device, MountPoint, Filesystem);
103 VFS_UpdateMountFile();
109 * \brief Updates the mount file buffer
111 * Updates the ProcFS mounts file buffer to match the current mounts list.
113 void VFS_UpdateMountFile(void)
120 // <device>\t<location>\t<type>\t<options>\n
122 for(mnt = gVFS_Mounts; mnt; mnt = mnt->Next)
124 len += 4 + strlen(mnt->Device) + strlen(mnt->MountPoint)
125 + strlen(mnt->Filesystem->Name) + strlen(mnt->Options);
128 buf = malloc( len + 1 );
130 for(mnt = gVFS_Mounts; mnt; mnt = mnt->Next)
132 strcpy( &buf[len], mnt->Device );
133 len += strlen(mnt->Device);
136 strcpy( &buf[len], mnt->MountPoint );
137 len += strlen(mnt->MountPoint);
140 strcpy( &buf[len], mnt->Filesystem->Name );
141 len += strlen(mnt->Filesystem->Name);
144 strcpy( &buf[len], mnt->Options );
145 len += strlen(mnt->Options);
150 SysFS_UpdateFile( giVFS_MountFileID, buf, len );
151 if( gsVFS_MountFile ) free( gsVFS_MountFile );
152 gsVFS_MountFile = buf;