aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2001-04-03 02:41:54 +0000
committerChristopher Faylor <me@cgf.cx>2001-04-03 02:41:54 +0000
commitbe61cf4d0ce1a34c555b96f42809c3f504bafeab (patch)
treecb877ddee24785e658ca228176635c2841d64956
parentc6cd25a033ca01bb71c74edb846c10714a354792 (diff)
downloadnewlib-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.
-rw-r--r--winsup/utils/ChangeLog6
-rw-r--r--winsup/utils/mount.cc182
-rw-r--r--winsup/utils/umount.cc174
3 files changed, 208 insertions, 154 deletions
diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog
index df9416f..fdc626e 100644
--- a/winsup/utils/ChangeLog
+++ b/winsup/utils/ChangeLog
@@ -1,3 +1,9 @@
+Mon Apr 2 22:41:33 2001 Christopher Faylor <cgf@cygnus.com>
+
+ * mount.cc (main): Use getopt_long for parsing arguments.
+ (usage): Reformat, show long and short options.
+ * umount.cc (main): Ditto, all of the above.
+
Mon Apr 2 10:58:26 2001 Christopher Faylor <cgf@cygnus.com>
* mount.cc (show_mounts): Change format string to more closely resemble
diff --git a/winsup/utils/mount.cc b/winsup/utils/mount.cc
index 1a671dd..c9ec96d 100644
--- a/winsup/utils/mount.cc
+++ b/winsup/utils/mount.cc
@@ -15,6 +15,7 @@ details. */
#include <windows.h>
#include <sys/cygwin.h>
#include <stdlib.h>
+#include <getopt.h>
#ifdef errno
#undef errno
@@ -84,32 +85,57 @@ do_mount (const char *dev, const char *where, int flags)
exit (0);
}
+struct option longopts[] =
+{
+ {"binary", no_argument, NULL, 'b'},
+ {"force", no_argument, NULL, 'f'},
+ {"system", no_argument, NULL, 's'},
+ {"text", no_argument, NULL, 't'},
+ {"user", no_argument, NULL, 'u'},
+ {"executable", no_argument, NULL, 'x'},
+ {"change-cygdrive-prefix", no_argument, NULL, 'c'},
+ {"cygwin-executable", no_argument, NULL, 'X'},
+ {"show-cygdrive-prefix", no_argument, NULL, 'p'},
+ {"import-old-mounts", no_argument, NULL, 'i'},
+ {NULL, 0, NULL, 0}
+};
+
+char opts[] = "bfstuxXpic";
+
static void
usage (void)
{
- fprintf (stderr, "usage %s [-bfstux] <win32path> <posixpath>
--b text files are equivalent to binary files (newline = \\n)
--f force mount, don't warn about missing mount point directories
--s add mount point to system-wide registry location
--t text files get \\r\\n line endings (default)
--u add mount point to user registry location (default)
--x treat all files under mount point as executables
-
-[-bs] --change-cygdrive-prefix <posixpath>
- change the cygdrive path prefix to <posixpath>
---show-cygdrive-prefixes
- show user and/or system cygdrive path prefixes
---import-old-mounts
- copy old registry mount table mounts into the current mount areas
+ fprintf (stderr, "Usage: %s [OPTION] [<win32path> <posixpath>]\n\
+ -b, --binary text files are equivalent to binary files\n\
+ (newline = \\n)\n\
+ -c, --change-cygdrive-prefix change the cygdrive path prefix to <posixpath>\n\
+ -f, --force force mount, don't warn about missing mount\n\
+ point directories\n\
+ -i, --import-old-mounts copy old registry mount table mounts into the current\n\
+ mount areas\n\
+ -p, --show-cygdrive-prefix show user and/or system cygdrive path prefix\n\
+ -s, --system add mount point to system-wide registry location\n\
+ -t, --text (default) text files get \\r\\n line endings\n\
+ -u, --user (default) add mount point to user registry location\n\
+ -x, --executable treat all files under mount point as executables\n\
+ -X, --cygwin-executable treat all files under mount point as cygwin\n\
+ executables\n\
", progname);
exit (1);
}
int
-main (int argc, const char **argv)
+main (int argc, char **argv)
{
int i;
int flags = 0;
+ enum do_what
+ {
+ nada,
+ saw_change_cygdrive_prefix,
+ saw_import_old_mounts,
+ saw_show_cygdrive_prefix
+ } do_what = nada;
progname = argv[0];
@@ -119,65 +145,85 @@ main (int argc, const char **argv)
exit (0);
}
- for (i = 1; i < argc; ++i)
- {
- if (argv[i][0] != '-')
- break;
-
- if (strcmp (argv[i], "--change-cygdrive-prefix") == 0)
- {
- if ((i + 2) != argc)
- usage ();
-
- change_cygdrive_prefix (argv[i+1], flags);
- }
- else if (strcmp (argv[i], "--import-old-mounts") == 0)
- {
- if ((i + 1) != argc)
- usage ();
-
- cygwin_internal (CW_READ_V1_MOUNT_TABLES);
- exit (0);
- }
- else if (strcmp (argv[i], "--show-cygdrive-prefixes") == 0)
- {
- if ((i + 1) != argc)
- usage ();
-
- show_cygdrive_info ();
- }
- else if (strcmp (argv[i], "-b") == 0)
+ while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
+ switch (i)
+ {
+ case 'b':
flags |= MOUNT_BINARY;
- else if (strcmp (argv[i], "-t") == 0)
- flags &= ~MOUNT_BINARY;
- else if (strcmp (argv[i], "-X") == 0)
- flags |= MOUNT_CYGWIN_EXEC;
-#if 0
- else if (strcmp (argv[i], "-x") == 0)
- create_missing_dirs = TRUE;
-#endif
- else if (strcmp (argv[i], "-s") == 0)
+ break;
+ case 'c':
+ if (do_what == nada)
+ do_what = saw_change_cygdrive_prefix;
+ else
+ usage ();
+ break;
+ case 'f':
+ force = TRUE;
+ break;
+ case 'i':
+ if (do_what == nada)
+ do_what = saw_import_old_mounts;
+ else
+ usage ();
+ break;
+ case 'p':
+ if (do_what == nada)
+ do_what = saw_show_cygdrive_prefix;
+ else
+ usage ();
+ break;
+ case 's':
flags |= MOUNT_SYSTEM;
- else if (strcmp (argv[i], "-u") == 0)
+ break;
+ case 't':
+ flags &= ~MOUNT_BINARY;
+ break;
+ case 'u':
flags &= ~MOUNT_SYSTEM;
- else if (strcmp (argv[i], "-x") == 0)
+ break;
+ case 'X':
+ flags |= MOUNT_CYGWIN_EXEC;
+ break;
+ case 'x':
flags |= MOUNT_EXEC;
- else if (strcmp (argv[i], "-f") == 0)
- force = TRUE;
- else
+ break;
+ default:
usage ();
- }
+ }
- if ((i + 2) != argc)
- usage ();
-
- if ((force == FALSE) && (mount_already_exists (argv[i + 1], flags)))
+ argc--;
+ switch (do_what)
{
- errno = EBUSY;
- error (argv[i + 1]);
+ case saw_change_cygdrive_prefix:
+ if (optind != argc)
+ usage ();
+ change_cygdrive_prefix (argv[optind], flags);
+ break;
+ case saw_import_old_mounts:
+ if (optind <= argc)
+ usage ();
+ else
+ cygwin_internal (CW_READ_V1_MOUNT_TABLES);
+ break;
+ case saw_show_cygdrive_prefix:
+ if (optind <= argc)
+ usage ();
+ show_cygdrive_info ();
+ break;
+ default:
+ if (optind != (argc - 1))
+ {
+ fprintf (stderr, "%s: too many arguments\n", progname);
+ usage ();
+ }
+ if (force || !mount_already_exists (argv[optind + 1], flags))
+ do_mount (argv[optind], argv[optind + 1], flags);
+ else
+ {
+ errno = EBUSY;
+ error (argv[optind + 1]);
+ }
}
- else
- do_mount (argv[i], argv[i + 1], flags);
/* NOTREACHED */
return 0;
@@ -257,7 +303,7 @@ change_cygdrive_prefix (const char *new_prefix, int flags)
exit (0);
}
-/* show_cygdrive_info: Show the user and/or cygdrive info, i.e., prefixes and
+/* show_cygdrive_info: Show the user and/or cygdrive info, i.e., prefix and
flags.*/
static void
show_cygdrive_info ()
@@ -270,7 +316,7 @@ show_cygdrive_info ()
cygwin_internal (CW_GET_CYGDRIVE_INFO, user, system, user_flags,
system_flags);
- /* Display the user and system cygdrive path prefixes, if necessary
+ /* Display the user and system cygdrive path prefix, if necessary
(ie, not empty) */
const char *format = "%-18s %-11s %s\n";
printf (format, "Prefix", "Type", "Flags");
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);
}