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;
23 Uint32 giVFS_NextMountIdent = 1;
27 * \brief Mount a device
28 * \param Device Device string to mount
29 * \param MountPoint Destination for the mount
30 * \param Filesystem Filesystem to use for the mount
31 * \param Options Options to be passed to the filesystem
32 * \return -1 on Invalid FS, -2 on No Mem, 0 on success
34 * Mounts the filesystem on \a Device at \a MountPoint using the driver
35 * \a Filesystem. The options in the string \a Options is passed to the
38 int VFS_Mount(const char *Device, const char *MountPoint, const char *Filesystem, const char *Options)
42 int deviceLen = strlen(Device);
43 int mountLen = strlen(MountPoint);
44 int argLen = strlen(Options);
47 fs = VFS_GetFSByName(Filesystem);
49 Log_Warning("VFS", "VFS_Mount - Unknown FS Type '%s'", Filesystem);
53 // Create mount information
54 mnt = malloc( sizeof(tVFS_Mount)+deviceLen+1+mountLen+1+argLen+1 );
59 // HACK: Forces VFS_ParsePath to fall back on root
60 if(mountLen == 1 && MountPoint[0] == '/')
61 mnt->MountPointLen = 0;
63 mnt->MountPointLen = mountLen;
68 mnt->Device = &mnt->StrData[0];
69 memcpy( mnt->Device, Device, deviceLen+1 );
71 mnt->MountPoint = &mnt->StrData[deviceLen+1];
72 memcpy( mnt->MountPoint, MountPoint, mountLen+1 );
74 mnt->Options = &mnt->StrData[deviceLen+1+mountLen+1];
75 memcpy( mnt->Options, Options, argLen+1 );
78 mnt->RootNode = fs->InitDevice(Device, NULL); //&ArgString);
84 mnt->Identifier = giVFS_NextMountIdent++;
86 // Ensure identifiers don't repeat
87 // - Only a problem if there have been 4 billion mounts
88 while( giVFS_NextMountIdent == 0 || VFS_GetMountByIdent(giVFS_NextMountIdent) )
89 giVFS_NextMountIdent ++;
93 if(!gVFS_RootMount) gVFS_RootMount = mnt;
96 Mutex_Acquire( &glVFS_MountList );
101 for( tmp = gVFS_Mounts; tmp->Next; tmp = tmp->Next );
108 Mutex_Release( &glVFS_MountList );
110 Log_Log("VFS", "Mounted '%s' to '%s' ('%s')", Device, MountPoint, Filesystem);
112 VFS_UpdateMountFile();
118 * \brief Gets a mount point given the identifier
120 tVFS_Mount *VFS_GetMountByIdent(Uint32 MountID)
123 for(mnt = gVFS_Mounts; mnt; mnt = mnt->Next)
125 if(mnt->Identifier == MountID)
132 * \brief Updates the mount file buffer
134 * Updates the ProcFS mounts file buffer to match the current mounts list.
136 void VFS_UpdateMountFile(void)
143 // <device>\t<location>\t<type>\t<options>\n
145 for(mnt = gVFS_Mounts; mnt; mnt = mnt->Next)
147 len += 4 + strlen(mnt->Device) + strlen(mnt->MountPoint)
148 + strlen(mnt->Filesystem->Name) + strlen(mnt->Options);
151 buf = malloc( len + 1 );
153 for(mnt = gVFS_Mounts; mnt; mnt = mnt->Next)
155 strcpy( &buf[len], mnt->Device );
156 len += strlen(mnt->Device);
159 strcpy( &buf[len], mnt->MountPoint );
160 len += strlen(mnt->MountPoint);
163 strcpy( &buf[len], mnt->Filesystem->Name );
164 len += strlen(mnt->Filesystem->Name);
167 strcpy( &buf[len], mnt->Options );
168 len += strlen(mnt->Options);
173 SysFS_UpdateFile( giVFS_MountFileID, buf, len );
174 if( gsVFS_MountFile ) free( gsVFS_MountFile );
175 gsVFS_MountFile = buf;