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[])
29 char *sOptions = NULL;
32 // List mounted filesystems
33 // - This is cheating, isn't it?
35 // Dump the contents of /Devices/system/VFS/Mounts
36 FILE *fp = fopen(MOUNTED_FILE, "r");
39 while( (len = fread(buf, 1024, 1, fp)) )
40 fwrite(buf, len, 1, stdout);
51 for( i = 1; i < argc; i++ )
59 // -t <driver> :: Filesystem driver to use
60 case 't': sType = argv[++i]; break;
61 // -o option_list :: Options to pass the driver
62 case 'o': sOptions = argv[++i]; break;
64 case 'u': bUnmount = 1; break;
66 //TODO: Long Arguments
92 // TODO: Check for a match in the fstab
95 fprintf(stderr, "`mount -u` takes one argument\n");
99 if( _SysMount(NULL, sDir, NULL, NULL) ) // Unmount (Dev=NULL means unmount)
101 fprintf(stderr, "Unmount failed\n");
106 // Check if we even got a device/mountpoint
107 if(sDevice == NULL) {
112 // If no directory was passed (we want to use the mount list)
113 // or we are not root (we need to use the mount list)
114 // Check the mount list
115 if(sDir == NULL || getuid() != 0)
117 // Check if it is defined in the mounts file
118 // - At this point sDevice could be a device name or a mount point
119 if(GetMountDefs(sDevice, &sDevice, &sDir, &sType, &sOptions) == 0)
122 fprintf(stderr, "Unable to find '%s' in '%s'\n",
123 sDevice, MOUNTABLE_FILE
126 fprintf(stderr, "You must be root to mount devices or directories not in '%s'\n",
132 // We need to be root to mount a filesystem, so, let us be elevated!
133 setuid(0); // I hope I have the setuid bit implemented.
137 // Check that we were passed a filesystem type
138 // if(sType == NULL) {
139 // fprintf(stderr, "Please pass a filesystem type\n");
140 // return EXIT_FAILURE;
145 fd = open(sDevice, OPENFLAG_READ);
147 printf("Device '%s' cannot be opened for reading\n", sDevice);
153 fd = open(sDir, OPENFLAG_EXEC);
155 printf("Directory '%s' does not exist\n", sDir);
160 // Replace sOptions with an empty string if it is still NULL
161 if(sOptions == NULL) sOptions = "";
164 if( _SysMount(sDevice, sDir, sType, sOptions) ) {
165 // perror("_SysMount");
167 fprintf(stderr, "Filesystem autodetection failed, please pass a type\n");
169 fprintf(stderr, "Mount %s:'%s'=>'%s' failed\n", sType, sDevice, sDir);
176 void ShowUsage(char *ProgName)
178 fprintf(stderr, "Usage:\n");
179 fprintf(stderr, " %s [-t <type>] <device> <directory> [-o <options>]\n", ProgName);
180 fprintf(stderr, "or %s <device>\n", ProgName);
181 fprintf(stderr, "or %s <directory>\n", ProgName);
182 fprintf(stderr, "or %s\n", ProgName);
186 * \fn int GetMountDefs(char *Ident, char **spDevice, char **spDir, char **spType, char **spOptions)
187 * \brief Reads the mountable definitions file and returns the corresponding entry
188 * \param spDevice Pointer to a string (pointer) determining the device (also is the input for this function)
191 int GetMountDefs(char *Ident, char **spDevice, char **spDir, char **spType, char **spOptions)
193 // TODO: Read the mounts file (after deciding what it will be)