X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Fmount_src%2Fmain.c;h=ced39440b4e1198959da4b9f5375a6b7ffbe60ef;hb=b26dd737345421b70f59fcfd1ddd5278876482da;hp=a272214e365fdd86688d48e0f9af8d2e64e7717c;hpb=e4342ad9de52043cb8f820643794dc44076f9bd9;p=tpg%2Facess2.git diff --git a/Usermode/Applications/mount_src/main.c b/Usermode/Applications/mount_src/main.c index a272214e..ced39440 100644 --- a/Usermode/Applications/mount_src/main.c +++ b/Usermode/Applications/mount_src/main.c @@ -22,10 +22,12 @@ 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? @@ -56,7 +58,10 @@ int main(int argc, char *argv[]) { // -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: @@ -82,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]); @@ -91,7 +112,7 @@ 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 // - At this point sDevice could be a device name or a mount point @@ -121,28 +142,32 @@ int main(int argc, char *argv[]) } // 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! 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;