8 #define MOUNTABLE_FILE "/Acess/Conf/Mountable"
9 #define MOUNTED_FILE "/Devices/System/VFS/Mounts"
12 void ShowUsage(char *ProgName);
13 int GetMountDefs(char *Ident, char **spDevice, char **spDir, char **spType, char **spOptions);
17 * \fn int main(int argc, char *argv[])
20 int main(int argc, char *argv[])
28 char *sOptions = NULL;
30 // List mounted filesystems
31 // - This is cheating, isn't it?
33 // Dump the contents of /Devices/system/VFS/Mounts
34 FILE *fp = fopen("/Devices/system/VFS/Mounts", "r");
37 while( (len = fread(buf, 1024, 1, fp)) )
38 fwrite(buf, len, 1, stdout);
49 for( i = 1; i < argc; i++ )
57 // -t <driver> :: Filesystem driver to use
58 case 't': sType = argv[++i]; break;
60 //TODO: Long Arguments
84 // Check if we even got a device/mountpoint
90 // If no directory was passed (we want to use the mount list)
91 // or we are not root (we need to use the mount list)
92 // Check the mount list
93 if(sDir == NULL || getuid() != 0)
95 // Check if it is defined in the mounts file
96 // - At this point sDevice could be a device name or a mount point
97 if(GetMountDefs(sDevice, &sDevice, &sDir, &sType, &sOptions) == 0)
100 fprintf(stderr, "Unable to find '%s' in '%s'\n",
101 sDevice, MOUNTABLE_FILE
104 fprintf(stderr, "You must be root to mount devices or directories not in '%s'\n",
110 // We need to be root to mount a filesystem, so, let us be elevated!
111 setuid(0); // I hope I have the setuid bit implemented.
115 // Check that we were passed a filesystem type
117 fprintf(stderr, "Please pass a filesystem type\n");
123 fd = open(sDevice, OPENFLAG_READ);
125 printf("Device '%s' cannot be opened for reading\n", sDevice);
131 fd = open(sDir, OPENFLAG_EXEC);
133 printf("Directory '%s' does not exist\n", sDir);
138 // Replace sOptions with an empty string if it is still NULL
139 if(sOptions == NULL) sOptions = "";
142 _SysMount(sDevice, sDir, sType, sOptions);
147 void ShowUsage(char *ProgName)
149 fprintf(stderr, "Usage:\n");
150 fprintf(stderr, " %s [-t <type>] <device> <directory>\n", ProgName);
151 fprintf(stderr, "or %s <device>\n", ProgName);
152 fprintf(stderr, "or %s <directory>\n", ProgName);
153 fprintf(stderr, "or %s\n", ProgName);
157 * \fn int GetMountDefs(char *Ident, char **spDevice, char **spDir, char **spType, char **spOptions)
158 * \brief Reads the mountable definitions file and returns the corresponding entry
159 * \param spDevice Pointer to a string (pointer) determining the device (also is the input for this function)
162 int GetMountDefs(char *Ident, char **spDevice, char **spDir, char **spType, char **spOptions)
164 // TODO: Read the mounts file (after deciding what it will be)