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 <dnelson@allantgroup.com>
This commit is contained in:
Ian Dowse 2003-07-18 17:43:13 +00:00
parent 084fb28576
commit 38f102c2f6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=117742
3 changed files with 54 additions and 17 deletions

View File

@ -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");
}

View File

@ -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

View File

@ -53,6 +53,7 @@ static const char rcsid[] =
#include <rpc/rpc.h>
#include <nfs/rpcv2.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <fstab.h>
@ -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);