From 5502303d772f926e775bfaf06a469b714fcae0cf Mon Sep 17 00:00:00 2001 From: iedowse Date: Fri, 18 Jul 2003 17:43:13 +0000 Subject: When mount(8) is invoked with the `-v' flag, display the filesystem ID for each file system in addition to the normal information. In umount(8), accept filesystem IDs as well as the usual device and path names. This makes it possible to unambiguously specify which file system is to be unmounted even when two or more file systems share the same device and mountpoint names (e.g. NFS mounts from the same export into different chroots). Suggested by: Dan Nelson --- sbin/mount/mount.c | 5 ++++- sbin/umount/umount.8 | 20 +++++++++----------- sbin/umount/umount.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 54 insertions(+), 17 deletions(-) (limited to 'sbin') diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c index bb4579d..6cfe79b 100644 --- a/sbin/mount/mount.c +++ b/sbin/mount/mount.c @@ -508,7 +508,7 @@ void prmount(sfp) struct statfs *sfp; { - int flags; + int flags, i; struct opt *o; struct passwd *pw; @@ -535,6 +535,9 @@ prmount(sfp) if (sfp->f_syncreads != 0 || sfp->f_asyncreads != 0) (void)printf(", reads: sync %ld async %ld", sfp->f_syncreads, sfp->f_asyncreads); + printf(", fsid "); + for (i = 0; i < sizeof(sfp->f_fsid); i++) + printf("%02x", ((u_char *)&sfp->f_fsid)[i]); } (void)printf(")\n"); } diff --git a/sbin/umount/umount.8 b/sbin/umount/umount.8 index 2f7f914..d992c38 100644 --- a/sbin/umount/umount.8 +++ b/sbin/umount/umount.8 @@ -32,7 +32,7 @@ .\" @(#)umount.8 8.2 (Berkeley) 5/8/95 .\" $FreeBSD$ .\" -.Dd April 7, 2003 +.Dd July 18, 2003 .Dt UMOUNT 8 .Os .Sh NAME @@ -41,7 +41,7 @@ .Sh SYNOPSIS .Nm .Op Fl fv -.Ar special \&| node +.Ar special | node | fsid .Nm .Fl a | A .Op Fl F Ar fstab @@ -53,17 +53,15 @@ The .Nm utility calls the .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 -.Ar node . -If either +system call to remove a file system from the file system tree. +The file system can be specified by its .Ar special -or +device or remote node (rhost:path), the path to the mount point .Ar node -are not provided, the appropriate information is taken from the -.Xr fstab 5 -file. +or by the file system ID +.Ar fsid +as reported by +.Dq mount -v . .Pp The options are as follows: .Bl -tag -width indent diff --git a/sbin/umount/umount.c b/sbin/umount/umount.c index 4ed67bf..209808c 100644 --- a/sbin/umount/umount.c +++ b/sbin/umount/umount.c @@ -53,6 +53,7 @@ static const char rcsid[] = #include #include +#include #include #include #include @@ -66,7 +67,7 @@ static const char rcsid[] = #define ISDOT(x) ((x)[0] == '.' && (x)[1] == '\0') #define ISDOTDOT(x) ((x)[0] == '.' && (x)[1] == '.' && (x)[2] == '\0') -typedef enum { MNTON, MNTFROM, NOTHING } mntwhat; +typedef enum { MNTON, MNTFROM, MNTFSID, NOTHING } mntwhat; typedef enum { MARK, UNMARK, NAME, COUNT, FREE } dowhat; struct addrinfo *nfshost_ai = NULL; @@ -465,6 +466,8 @@ getmntentry(const char *fromname, const char *onname, mntwhat what, dowhat mark) static size_t mntsize = 0; static char *mntcheck = NULL; static char *mntcount = NULL; + fsid_t fsid; + char hexbuf[3]; int i, count; if (mntsize <= 0) { @@ -489,10 +492,41 @@ getmntentry(const char *fromname, const char *onname, mntwhat what, dowhat mark) switch (mark) { case NAME: /* Return only the specific name */ + if (fromname == NULL) + return (NULL); + if (what == MNTFSID) { + /* Convert the hex filesystem ID to a fsid_t. */ + if (strlen(fromname) != sizeof(fsid) * 2) + return (NULL); + hexbuf[2] = '\0'; + for (i = 0; i < sizeof(fsid); i++) { + hexbuf[0] = fromname[i * 2]; + hexbuf[1] = fromname[i * 2 + 1]; + if (!isxdigit(hexbuf[0]) || + !isxdigit(hexbuf[1])) + return (NULL); + ((u_char *)&fsid)[i] = strtol(hexbuf, NULL, 16); + } + } for (i = mntsize - 1; i >= 0; i--) { - if (fromname != NULL && !strcmp((what == MNTFROM) ? - mntbuf[i].f_mntfromname : mntbuf[i].f_mntonname, - fromname) && mntcheck[i] != 1) + switch (what) { + case MNTON: + if (strcmp(mntbuf[i].f_mntonname, + fromname) != 0) + continue; + break; + case MNTFROM: + if (strcmp(mntbuf[i].f_mntfromname, + fromname) != 0) + continue; + case MNTFSID: + if (bcmp(&mntbuf[i].f_fsid, &fsid, + sizeof(fsid)) != 0) + continue; + case NOTHING: /* silence compiler warning */ + break; + } + if (mntcheck[i] != 1) return (&mntbuf[i]); } @@ -609,7 +643,9 @@ checkmntlist(char *name) { struct statfs *sfs; - sfs = getmntentry(name, NULL, MNTON, NAME); + sfs = getmntentry(name, NULL, MNTFSID, NAME); + if (sfs == NULL) + sfs = getmntentry(name, NULL, MNTON, NAME); if (sfs == NULL) sfs = getmntentry(name, NULL, MNTFROM, NAME); return (sfs); -- cgit v1.1