3 Copyright 1996, 1998, 1999, 2000, 2001, 2002, 2008 Red Hat, Inc.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
13 #include <sys/mount.h>
19 static void remove_all_user_mounts ();
21 static const char version[] = "$Revision$";
22 static const char *progname;
24 struct option longopts[] =
26 {"help", no_argument, NULL, 'h' },
27 {"remove-user-mounts", no_argument, NULL, 'U'},
28 {"version", no_argument, NULL, 'v'},
35 usage (FILE *where = stderr)
38 Usage: %s [OPTION] [<posixpath>]\n\
39 Unmount filesystems\n\
41 -h, --help output usage information and exit\n\
42 -U, --remove-user-mounts remove all user mounts\n\
43 -v, --version output version information and exit\n\
45 exit (where == stderr ? 1 : 0);
49 error (const char *path)
51 fprintf (stderr, "%s: %s: %s\n", progname, path, strerror (errno));
58 const char *v = strchr (version, ':');
68 len = strchr (v, ' ') - v;
73 Copyright 1996, 1998, 1999, 2000, 2001, 2002\n\
75 ", progname, len, v, __DATE__);
79 main (int argc, char **argv)
83 int default_flag = MOUNT_SYSTEM;
87 saw_remove_all_user_mounts
90 progname = strrchr (argv[0], '/');
92 progname = strrchr (argv[0], '\\');
101 while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
109 do_what = saw_remove_all_user_mounts;
120 case saw_remove_all_user_mounts:
123 remove_all_user_mounts ();
126 if (optind != argc - 1)
128 if (cygwin_umount (argv[optind], flags | default_flag) != 0)
129 error (argv[optind]);
135 /* remove_all_user_mounts: Unmount all user mounts. */
137 remove_all_user_mounts ()
139 FILE *m = setmntent ("/-not-used-", "r");
142 while ((p = getmntent (m)) != NULL)
144 /* Remove the mount if it's a user mount. */
145 if (strncmp (p->mnt_type, "user", 4) == 0 &&
146 strstr (p->mnt_opts, "noumount") == NULL)
148 if (cygwin_umount (p->mnt_dir, 0))
151 /* We've modified the table so we need to start over. */
153 m = setmntent ("/-not-used-", "r");