add -A option to unmount all mounted filesystems
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Tue, 9 May 1995 08:50:12 +0000 (00:50 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Tue, 9 May 1995 08:50:12 +0000 (00:50 -0800)
SCCS-vsn: sbin/umount/umount.8 8.2
SCCS-vsn: sbin/umount/umount.c 8.8

usr/src/sbin/umount/umount.8
usr/src/sbin/umount/umount.c

index 1680eca..306b123 100644 (file)
@@ -3,23 +3,23 @@
 .\"
 .\" %sccs.include.redist.roff%
 .\"
 .\"
 .\" %sccs.include.redist.roff%
 .\"
-.\"     @(#)umount.8   8.1 (Berkeley) %G%
+.\"     @(#)umount.8   8.2 (Berkeley) %G%
 .\"
 .Dd 
 .Dt UMOUNT 8
 .Os BSD 4
 .Sh NAME
 .Nm umount
 .\"
 .Dd 
 .Dt UMOUNT 8
 .Os BSD 4
 .Sh NAME
 .Nm umount
-.Nd unmount file systems
+.Nd unmount filesystems
 .Sh SYNOPSIS
 .Nm umount
 .Op Fl fv
 .Ar special | node
 .Nm umount
 .Sh SYNOPSIS
 .Nm umount
 .Op Fl fv
 .Ar special | node
 .Nm umount
-.Fl a
+.Fl a | A
 .Op Fl fv
 .Op Fl h Ar host
 .Op Fl fv
 .Op Fl h Ar host
-.Op Fl t Ar ufs | lfs | external_type
+.Op Fl t Ar type
 .Sh DESCRIPTION
 The
 .Nm umount
 .Sh DESCRIPTION
 The
 .Nm umount
@@ -28,7 +28,7 @@ calls the
 .Xr unmount 2
 system call to remove a
 .Ar "special device"
 .Xr unmount 2
 system call to remove a
 .Ar "special device"
-or the remote node (rhost:path) from the file system tree at the point
+or the remote node (rhost:path) from the filesystem tree at the point
 .Ar node .
 If either
 .Ar special
 .Ar node .
 If either
 .Ar special
@@ -41,23 +41,26 @@ file.
 The options are as follows:
 .Bl -tag -width indent
 .It Fl a
 The options are as follows:
 .Bl -tag -width indent
 .It Fl a
-All of the file systems described in
+All the filesystems described in
 .Xr fstab 5
 are unmounted.
 .Xr fstab 5
 are unmounted.
+.It Fl A
+All the currently mounted filesystems except
+the root are unmounted.
 .It Fl f
 .It Fl f
-The file system is forcibly unmounted.
+The filesystem is forcibly unmounted.
 Active special devices continue to work,
 but all other files return errors if further accesses are attempted.
 Active special devices continue to work,
 but all other files return errors if further accesses are attempted.
-The root file system cannot be forcibly unmounted.
+The root filesystem cannot be forcibly unmounted.
 .It Fl h Ar host
 Only filesystems mounted from the specified host will be
 unmounted.
 This option is implies the
 .It Fl h Ar host
 Only filesystems mounted from the specified host will be
 unmounted.
 This option is implies the
-.Fl a
+.Fl A
 option and, unless otherwise specified with the
 .Fl t
 option, will only unmount NFS filesystems.
 option and, unless otherwise specified with the
 .Fl t
 option, will only unmount NFS filesystems.
-.It Fl t Ar "ufs \\*(Ba lfs \\*(Ba external type"
+.It Fl t Ar type
 Is used to indicate the actions should only be taken on
 filesystems of the specified type.
 More than one type may be specified in a comma separated list.
 Is used to indicate the actions should only be taken on
 filesystems of the specified type.
 More than one type may be specified in a comma separated list.
@@ -78,13 +81,13 @@ umounts all filesystems of the type
 and
 .Tn MFS .
 .It Fl v
 and
 .Tn MFS .
 .It Fl v
-Verbose, additional information is printed out as each file system
+Verbose, additional information is printed out as each filesystem
 is unmounted.
 .El
 .Sh FILES
 .Bl -tag -width /etc/fstab -compact
 .It Pa /etc/fstab
 is unmounted.
 .El
 .Sh FILES
 .Bl -tag -width /etc/fstab -compact
 .It Pa /etc/fstab
-file system table
+filesystem table
 .El
 .Sh SEE ALSO
 .Xr unmount 2 ,
 .El
 .Sh SEE ALSO
 .Xr unmount 2 ,
index 7f68ea9..d8b56ef 100644 (file)
@@ -12,7 +12,7 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)umount.c   8.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)umount.c   8.8 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -55,15 +55,19 @@ main(argc, argv)
        int argc;
        char *argv[];
 {
        int argc;
        char *argv[];
 {
-       int all, ch, errs;
+       int all, ch, errs, mnts;
        char **typelist = NULL;
        char **typelist = NULL;
+       struct statfs *mntbuf;
 
        /* Start disks transferring immediately. */
        sync();
 
        all = 0;
 
        /* Start disks transferring immediately. */
        sync();
 
        all = 0;
-       while ((ch = getopt(argc, argv, "aFfh:t:v")) != EOF)
+       while ((ch = getopt(argc, argv, "AaFfh:t:v")) != EOF)
                switch (ch) {
                switch (ch) {
+               case 'A':
+                       all = 2;
+                       break;
                case 'a':
                        all = 1;
                        break;
                case 'a':
                        all = 1;
                        break;
@@ -73,8 +77,8 @@ main(argc, argv)
                case 'f':
                        fflag = MNT_FORCE;
                        break;
                case 'f':
                        fflag = MNT_FORCE;
                        break;
-               case 'h':       /* -h implies -a. */
-                       all = 1;
+               case 'h':       /* -h implies -A. */
+                       all = 2;
                        nfshost = optarg;
                        break;
                case 't':
                        nfshost = optarg;
                        break;
                case 't':
@@ -99,14 +103,31 @@ main(argc, argv)
        if ((nfshost != NULL) && (typelist == NULL))
                typelist = makevfslist("nfs");
                
        if ((nfshost != NULL) && (typelist == NULL))
                typelist = makevfslist("nfs");
                
-       if (all) {
+       switch (all) {
+       case 2:
+               if ((mnts = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
+                       warn("getmntinfo");
+                       errs = 1;
+                       break;
+               }
+               for (errs = 0, mnts--; mnts > 0; mnts--) {
+                       if (checkvfsname(mntbuf[mnts].f_fstypename, typelist))
+                               continue;
+                       if (umountfs(mntbuf[mnts].f_mntonname, typelist) != 0)
+                               errs = 1;
+               }
+               break;
+       case 1:
                if (setfsent() == 0)
                        err(1, "%s", _PATH_FSTAB);
                errs = umountall(typelist);
                if (setfsent() == 0)
                        err(1, "%s", _PATH_FSTAB);
                errs = umountall(typelist);
-       } else
+               break;
+       case 0:
                for (errs = 0; *argv != NULL; ++argv)
                        if (umountfs(*argv, typelist) != 0)
                                errs = 1;
                for (errs = 0; *argv != NULL; ++argv)
                        if (umountfs(*argv, typelist) != 0)
                                errs = 1;
+               break;
+       }
        exit(errs);
 }
 
        exit(errs);
 }
 
@@ -263,10 +284,12 @@ getmntname(name, what, type)
        mntwhat what;
        char **type;
 {
        mntwhat what;
        char **type;
 {
-       struct statfs *mntbuf;
-       int i, mntsize;
+       static struct statfs *mntbuf;
+       static int mntsize;
+       int i;
 
 
-       if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
+       if (mntbuf == NULL &&
+           (mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
                warn("getmntinfo");
                return (NULL);
        }
                warn("getmntinfo");
                return (NULL);
        }