c4ab833e36f386a74392eeb5cf5aa2bb339b88f6
[tpg/acess2.git] / Kernel / vfs / mount.c
1 /* 
2  * Acess Micro - VFS Server version 1
3  */
4 #include <common.h>
5 #include <vfs.h>
6 #include <vfs_int.h>
7
8 // === GLOBALS ===
9  int    glVFS_MountList = 0;
10 tVFS_Mount      *gMounts;
11 tVFS_Mount      *gRootMount = NULL;
12
13 // === CODE ===
14 /**
15  * \fn int VFS_Mount(char *Device, char *MountPoint, char *Filesystem, char *ArgString)
16  * \brief Mount a device
17  * \param Device        Device string to mount
18  * \param MountPoint    Destination for the mount
19  * \param Filesystem    Filesystem to use for the mount
20  * \param ArgString             Options to be passed to the filesystem
21  * \return -1 on Invalid FS, -2 on No Mem, 0 on success
22  */
23 int VFS_Mount(char *Device, char *MountPoint, char *Filesystem, char *ArgString)
24 {
25         tVFS_Mount      *mnt;
26         tVFS_Driver     *fs;
27          int    deviceLen = strlen(Device);
28          int    mountLen = strlen(MountPoint);
29          int    argLen = strlen(ArgString);
30         
31         // Get the filesystem
32         fs = VFS_GetFSByName(Filesystem);
33         if(!fs) {
34                 Warning("VFS_Mount - Unknown FS Type '%s'", Filesystem);
35                 return -1;
36         }
37         
38         // Create mount information
39         mnt = malloc( sizeof(tVFS_Mount)+deviceLen+1+mountLen+1+argLen+1 );
40         if(!mnt) {
41                 return -2;
42         }
43         
44         // HACK: Forces VFS_ParsePath to fall back on root  
45         if(mountLen == 1 && MountPoint[0] == '/')
46                 mnt->MountPointLen = 0;
47         else
48                 mnt->MountPointLen = mountLen;
49         
50         // Fill Structure
51         mnt->Filesystem = fs;
52         
53         mnt->Device = &mnt->StrData[0];
54         memcpy( mnt->Device, Device, deviceLen+1 );
55         
56         mnt->MountPoint = &mnt->StrData[deviceLen+1];
57         memcpy( mnt->MountPoint, MountPoint, mountLen+1 );
58         
59         mnt->Options = &mnt->StrData[deviceLen+1+mountLen+1];
60         memcpy( mnt->Options, ArgString, argLen+1 );
61         
62         // Initialise Volume
63         mnt->RootNode = fs->InitDevice(Device, NULL);   //&ArgString);
64         if(!mnt->RootNode) {
65                 free(mnt);
66                 return -2;
67         }
68         
69         // Set root
70         if(!gRootMount) gRootMount = mnt;
71         
72         // Add to mount list
73         LOCK( &glVFS_MountList );
74         mnt->Next = gMounts;
75         gMounts = mnt;
76         RELEASE( &glVFS_MountList );
77         
78         Log("VFS_Mount: Mounted '%s' to '%s' ('%s')", Device, MountPoint, Filesystem);
79         
80         return 0;
81 }

UCC git Repository :: git.ucc.asn.au