diff options
author | Christopher Faylor <me@cgf.cx> | 2001-04-03 02:41:54 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2001-04-03 02:41:54 +0000 |
commit | be61cf4d0ce1a34c555b96f42809c3f504bafeab (patch) | |
tree | cb877ddee24785e658ca228176635c2841d64956 /winsup/utils/umount.cc | |
parent | c6cd25a033ca01bb71c74edb846c10714a354792 (diff) | |
download | newlib-be61cf4d0ce1a34c555b96f42809c3f504bafeab.zip newlib-be61cf4d0ce1a34c555b96f42809c3f504bafeab.tar.gz newlib-be61cf4d0ce1a34c555b96f42809c3f504bafeab.tar.bz2 |
* mount.cc (main): Use getopt_long for parsing arguments.
(usage): Reformat, show long and short options.
* umount.cc (main): Ditto, all of the above.
Diffstat (limited to 'winsup/utils/umount.cc')
-rw-r--r-- | winsup/utils/umount.cc | 174 |
1 files changed, 88 insertions, 86 deletions
diff --git a/winsup/utils/umount.cc b/winsup/utils/umount.cc index 3c1e5f3..6072411 100644 --- a/winsup/utils/umount.cc +++ b/winsup/utils/umount.cc @@ -14,31 +14,39 @@ details. */ #include <mntent.h> #include <stdlib.h> #include <errno.h> +#include <getopt.h> static void remove_all_mounts (); -static void remove_all_automounts (); static void remove_all_user_mounts (); static void remove_all_system_mounts (); static void remove_cygdrive_prefix (int flags); static const char *progname; +struct option longopts[] = +{ + {"remove-all-mounts", no_argument, NULL, 'A'}, + {"remove-cygdrive-prefix", no_argument, NULL, 'c'}, + {"remove-system-mounts", no_argument, NULL, 'S'}, + {"remove-user-mounts", no_argument, NULL, 'U'}, + {"system", no_argument, NULL, 's'}, + {"user", no_argument, NULL, 'u'}, + {NULL, 0, NULL, 0} +}; + +char opts[] = "RSUsuc"; + static void usage (void) { - fprintf (stderr, "Usage %s [-s] <posixpath>\n", progname); - fprintf (stderr, - "-s = remove mount point from system-wide registry location\n"); - fprintf (stderr, "\n"); - fprintf (stderr, "--remove-all-mounts = remove all mounts\n"); - fprintf (stderr, - "--remove-auto-mounts = remove all automatically mounted mounts\n"); - fprintf (stderr, - "--remove-user-mounts = remove all mounts in the current user mount registry area, including auto mounts\n"); - fprintf (stderr, - "--remove-system-mounts = remove all mounts in the system-wide mount registry area\n"); - fprintf (stderr, - "[-s] --remove-cygdrive-prefix = remove cygdrive path prefix\n"); + fprintf (stderr, "Usage %s [OPTION] [<posixpath>]\n\ + -A, --remove-all-mounts remove all mounts\n\ + -c, --remove-cygdrive-prefix remove cygdrive prefix\n\ + -s, --system remove system mount\n\ + -S, --remove-system-mounts remove all system mounts\n\ + -u, --user remove user mount\n\ + -U, --remove-user-mounts remove all user mounts\n\ +", progname); exit (1); } @@ -55,54 +63,80 @@ main (int argc, char **argv) int i; int flags = 0; progname = argv[0]; + enum do_what + { + nada, + saw_remove_all_mounts, + saw_remove_cygdrive_prefix, + saw_remove_all_system_mounts, + saw_remove_all_user_mounts + } do_what = nada; if (argc == 1) usage (); - for (i = 1; i < argc; ++i) - { - if (argv[i][0] != '-') + while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF) + switch (i) + { + case 'A': + if (do_what != nada) + usage (); + do_what = saw_remove_all_mounts; + break; + case 'c': + if (do_what != nada) + usage (); + do_what = saw_remove_cygdrive_prefix; + break; + case 's': + flags |= MOUNT_SYSTEM; + break; + case 'S': + if (do_what != nada) + usage (); + do_what = saw_remove_all_system_mounts; + break; + case 'u': + flags &= ~MOUNT_SYSTEM; break; + case 'U': + if (do_what != nada) + usage (); + do_what = saw_remove_all_user_mounts; + break; + default: + usage (); + } - if (strcmp (argv[i], "-s") == 0) - { - flags |= MOUNT_SYSTEM; - } - else if (strcmp (argv[i], "--remove-all-mounts") == 0) - { - remove_all_mounts (); - exit (0); - } - else if (strcmp (argv[i], "--remove-user-mounts") == 0) - { - remove_all_user_mounts (); - exit (0); - } - else if (strcmp (argv[i], "--remove-system-mounts") == 0) - { - remove_all_system_mounts (); - exit (0); - } - else if (strcmp (argv[i], "--remove-auto-mounts") == 0) - { - remove_all_automounts (); - exit (0); - } - else if (strcmp (argv[i], "--remove-cygdrive-prefix") == 0) - { - remove_cygdrive_prefix (flags); - exit (0); - } - else + switch (do_what) + { + case saw_remove_all_mounts: + if (optind != argc) + usage (); + remove_all_mounts (); + break; + case saw_remove_cygdrive_prefix: + if (optind != argc) + usage (); + remove_cygdrive_prefix (flags); + break; + case saw_remove_all_system_mounts: + if (optind != argc) + usage (); + remove_all_system_mounts (); + break; + case saw_remove_all_user_mounts: + if (optind != argc) usage (); + remove_all_user_mounts (); + break; + default: + if (optind != argc - 1) + usage (); + if (cygwin_umount (argv[optind], flags) != 0) + error (argv[optind]); } - if ((i + 1) != argc) - usage (); - - if (cygwin_umount (argv[i], flags) != 0) - error (argv[i]); - return 0; } @@ -114,39 +148,6 @@ remove_all_mounts () remove_all_system_mounts (); } -/* remove_all_automounts: Unmount all automounts. */ -static void -remove_all_automounts () -{ - FILE *m = setmntent ("/-not-used-", "r"); - struct mntent *p; - - while ((p = getmntent (m)) != NULL) - { - /* Remove the mount if it's an automount. */ - if (strcmp (p->mnt_type, "user,auto") == 0) - { - if (cygwin_umount (p->mnt_dir, 0)) - error (p->mnt_dir); - - /* We've modified the table so we need to start over. */ - endmntent (m); - m = setmntent ("/-not-used-", "r"); - } - else if (strcmp (p->mnt_type, "system,auto") == 0) - { - if (cygwin_umount (p->mnt_dir, MOUNT_SYSTEM)) - error (p->mnt_dir); - - /* We've modified the table so we need to start over. */ - endmntent (m); - m = setmntent ("/-not-used-", "r"); - } - } - - endmntent (m); -} - /* remove_all_user_mounts: Unmount all user mounts. */ static void remove_all_user_mounts () @@ -202,4 +203,5 @@ remove_cygdrive_prefix (int flags) int res = cygwin_umount (NULL, flags | MOUNT_AUTO); if (res) error ("remove_cygdrive_prefix"); + exit (0); } |