From a4b09792dd93b75b022f5f6dfcfe632baf8fdee2 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Thu, 23 Aug 2012 13:19:01 +0800 Subject: [PATCH] Usermode/mount - Added 'mount -u' (unmount) support --- Usermode/Applications/mount_src/main.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Usermode/Applications/mount_src/main.c b/Usermode/Applications/mount_src/main.c index a272214e..7c401bd2 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]); @@ -141,8 +162,12 @@ int main(int argc, char *argv[]) // 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; -- 2.20.1