X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Fmount_src%2Fmain.c;h=ced39440b4e1198959da4b9f5375a6b7ffbe60ef;hb=fd937b134894af540a322ed3de2c66363d0b584d;hp=b84e85f4750e5470800f42e0543addc64f3b6bb9;hpb=466eda7c917791866a29c253c6c22197faf41bf7;p=tpg%2Facess2.git diff --git a/Usermode/Applications/mount_src/main.c b/Usermode/Applications/mount_src/main.c index b84e85f4..ced39440 100644 --- a/Usermode/Applications/mount_src/main.c +++ b/Usermode/Applications/mount_src/main.c @@ -6,11 +6,11 @@ #include #define MOUNTABLE_FILE "/Acess/Conf/Mountable" -#define MOUNTED_FILE "/Acess/Conf/Mounted" +#define MOUNTED_FILE "/Devices/system/VFS/Mounts" // === PROTOTYPES === -void ShowUsage(); - int GetMountDefs(char **spDevice, char **spDir, char **spType, char **spOptions); +void ShowUsage(char *ProgName); + int GetMountDefs(char *Ident, char **spDevice, char **spDir, char **spType, char **spOptions); // === CODE === /** @@ -22,13 +22,28 @@ int main(int argc, char *argv[]) int fd; int i; char *arg; + char *sType = NULL; char *sDevice = NULL; char *sDir = NULL; char *sOptions = NULL; + int bUnmount = 0; + + // List mounted filesystems + // - This is cheating, isn't it? + if(argc == 1) { + // Dump the contents of /Devices/system/VFS/Mounts + FILE *fp = fopen(MOUNTED_FILE, "r"); + char buf[1024]; + int len; + while( (len = fread(buf, 1024, 1, fp)) ) + fwrite(buf, len, 1, stdout); + printf("\n"); + return 0; + } if(argc < 3) { - ShowUsage(); + ShowUsage(argv[0]); return EXIT_FAILURE; } @@ -41,7 +56,12 @@ int main(int argc, char *argv[]) { switch(arg[1]) { + // -t :: Filesystem driver to use case 't': sType = argv[++i]; break; + // -o option_list :: Options to pass the driver + case 'o': sOptions = argv[++i]; break; + // -u :: Unmount + case 'u': bUnmount = 1; break; case '-': //TODO: Long Arguments default: @@ -51,11 +71,13 @@ int main(int argc, char *argv[]) continue; } + // Device? if(sDevice == NULL) { sDevice = arg; continue; } + // Directory? if(sDir == NULL) { sDir = arg; continue; @@ -65,6 +87,22 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } + if( bUnmount ) + { + // TODO: Check for a match in the fstab + + if( sDir ) { + fprintf(stderr, "`mount -u` takes one argument\n"); + } + + sDir = sDevice; + if( _SysMount(NULL, sDir, NULL, NULL) ) // Unmount (Dev=NULL means unmount) + { + fprintf(stderr, "Unmount failed\n"); + } + return EXIT_SUCCESS; + } + // Check if we even got a device/mountpoint if(sDevice == NULL) { ShowUsage(argv[0]); @@ -74,10 +112,11 @@ int main(int argc, char *argv[]) // If no directory was passed (we want to use the mount list) // or we are not root (we need to use the mount list) // Check the mount list - if(sDir == NULL || getuid() != 0) + if(sDir == NULL || _SysGetUID() != 0) { // Check if it is defined in the mounts file - if(GetMountDefs(&sDevice, &sDir, &sType, &sOptions) == 0) + // - At this point sDevice could be a device name or a mount point + if(GetMountDefs(sDevice, &sDevice, &sDir, &sType, &sOptions) == 0) { if(sDir == NULL) fprintf(stderr, "Unable to find '%s' in '%s'\n", @@ -96,52 +135,60 @@ int main(int argc, char *argv[]) else { // Check that we were passed a filesystem type - if(sType == NULL) { - fprintf(stderr, "Please pass a filesystem type\n"); - return EXIT_FAILURE; - } +// if(sType == NULL) { +// fprintf(stderr, "Please pass a filesystem type\n"); +// return EXIT_FAILURE; +// } } // Check Device - fd = open(sDevice, OPENFLAG_READ); + fd = _SysOpen(sDevice, OPENFLAG_READ); if(fd == -1) { printf("Device '%s' cannot be opened for reading\n", sDevice); return EXIT_FAILURE; } - close(fd); + _SysClose(fd); // Check Mount Point - fd = open(sDir, OPENFLAG_EXEC); + fd = _SysOpen(sDir, OPENFLAG_EXEC); if(fd == -1) { printf("Directory '%s' does not exist\n", sDir); return EXIT_FAILURE; } - close(fd); + _SysClose(fd); // Replace sOptions with an empty string if it is still NULL if(sOptions == NULL) sOptions = ""; // Let's Mount! - _SysMount(sDevice, sDir, sType, sOptions); + if( _SysMount(sDevice, sDir, sType, sOptions) ) { +// perror("_SysMount"); + if( !sType ) + fprintf(stderr, "Filesystem autodetection failed, please pass a type\n"); + else { + fprintf(stderr, "Mount %s:'%s'=>'%s' failed\n", sType, sDevice, sDir); + } + } return 0; } void ShowUsage(char *ProgName) { - fprintf(stderr, "Usage:\n", ProgName); - fprintf(stderr, " %s [-t ] \n"); - fprintf(stderr, "or %s \n"); - fprintf(stderr, "or %s \n"); + fprintf(stderr, "Usage:\n"); + fprintf(stderr, " %s [-t ] [-o ]\n", ProgName); + fprintf(stderr, "or %s \n", ProgName); + fprintf(stderr, "or %s \n", ProgName); + fprintf(stderr, "or %s\n", ProgName); } /** - * \fn int GetMountDefs(char **spDevice, char **spDir, char **spType, char **spOptions) + * \fn int GetMountDefs(char *Ident, char **spDevice, char **spDir, char **spType, char **spOptions) * \brief Reads the mountable definitions file and returns the corresponding entry * \param spDevice Pointer to a string (pointer) determining the device (also is the input for this function) * \note STUB */ -int GetMountDefs(char **spDevice, char **spDir, char **spType, char **spOptions) +int GetMountDefs(char *Ident, char **spDevice, char **spDir, char **spType, char **spOptions) { // TODO: Read the mounts file (after deciding what it will be) return 0;