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;
59 case 'o': sOptions = argv[++i]; break;
61 //TODO: Long Arguments
85 // Check if we even got a device/mountpoint
91 // If no directory was passed (we want to use the mount list)
92 // or we are not root (we need to use the mount list)
93 // Check the mount list
94 if(sDir == NULL || getuid() != 0)
96 // Check if it is defined in the mounts file
97 // - At this point sDevice could be a device name or a mount point
98 if(GetMountDefs(sDevice, &sDevice, &sDir, &sType, &sOptions) == 0)
101 fprintf(stderr, "Unable to find '%s' in '%s'\n",
102 sDevice, MOUNTABLE_FILE
105 fprintf(stderr, "You must be root to mount devices or directories not in '%s'\n",
111 // We need to be root to mount a filesystem, so, let us be elevated!
112 setuid(0); // I hope I have the setuid bit implemented.
116 // Check that we were passed a filesystem type
118 fprintf(stderr, "Please pass a filesystem type\n");
124 fd = open(sDevice, OPENFLAG_READ);
126 printf("Device '%s' cannot be opened for reading\n", sDevice);
132 fd = open(sDir, OPENFLAG_EXEC);
134 printf("Directory '%s' does not exist\n", sDir);
139 // Replace sOptions with an empty string if it is still NULL
140 if(sOptions == NULL) sOptions = "";
143 _SysMount(sDevice, sDir, sType, sOptions);
148 void ShowUsage(char *ProgName)
150 fprintf(stderr, "Usage:\n");
151 fprintf(stderr, " %s [-t <type>] <device> <directory> [-o <options>]\n", ProgName);
152 fprintf(stderr, "or %s <device>\n", ProgName);
153 fprintf(stderr, "or %s <directory>\n", ProgName);
154 fprintf(stderr, "or %s\n", ProgName);
158 * \fn int GetMountDefs(char *Ident, char **spDevice, char **spDir, char **spType, char **spOptions)
159 * \brief Reads the mountable definitions file and returns the corresponding entry
160 * \param spDevice Pointer to a string (pointer) determining the device (also is the input for this function)
163 int GetMountDefs(char *Ident, char **spDevice, char **spDir, char **spType, char **spOptions)
165 // TODO: Read the mounts file (after deciding what it will be)