X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Fmount_src%2Fmain.c;h=1a1fc7be57fb2cf311a0126e4c71af6ccdd6f3ca;hb=8e1f78107cc9aa137de29e0c9df3a1fccb483b67;hp=602aefd439fd527ce3c8e19fc52e58c3afea5b76;hpb=197e9f66742d9f3e611f8037a38ce222fb878e5e;p=tpg%2Facess2.git diff --git a/Usermode/Applications/mount_src/main.c b/Usermode/Applications/mount_src/main.c index 602aefd4..1a1fc7be 100644 --- a/Usermode/Applications/mount_src/main.c +++ b/Usermode/Applications/mount_src/main.c @@ -6,7 +6,7 @@ #include #define MOUNTABLE_FILE "/Acess/Conf/Mountable" -#define MOUNTED_FILE "/Devices/System/VFS/Mounts" +#define MOUNTED_FILE "/Devices/system/VFS/Mounts" // === PROTOTYPES === void ShowUsage(char *ProgName); @@ -22,16 +22,18 @@ 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("/Devices/system/VFS/Mounts", "r"); + FILE *fp = fopen(MOUNTED_FILE, "r"); char buf[1024]; int len; while( (len = fread(buf, 1024, 1, fp)) ) @@ -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]); @@ -114,33 +135,40 @@ 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; }