Update from 4.4-Lite, with local changes.

This commit is contained in:
mycroft 1994-06-08 19:33:47 +00:00
parent 726a4412d4
commit bab8181299
7 changed files with 393 additions and 330 deletions

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,16 +32,15 @@
*/
#ifndef lint
/* from: static char sccsid[] = "@(#)utilities.c 5.10 (Berkeley) 12/2/92"; */
static char *rcsid = "$Id: utilities.c,v 1.4 1994/02/19 09:07:18 cgd Exp $";
/*static char sccsid[] = "from: @(#)utilities.c 8.2 (Berkeley) 3/25/94";*/
static char *rcsid = "$Id: utilities.c,v 1.5 1994/06/08 19:33:47 mycroft Exp $";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <ufs/dinode.h>
#include <ufs/dir.h>
#include <ufs/fs.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h>
#include <errno.h>
#include <stdio.h>
@ -72,7 +71,7 @@ pathcheck(name)
*cp = '\0';
ep = lookupname(name);
if (ep == NULL) {
/* safe; we know the pathname exists in the dump */
/* Safe; we know the pathname exists in the dump. */
ep = addentry(name, pathsearch(name)->d_ino, NODE);
newnode(ep);
}
@ -327,19 +326,15 @@ flagvalues(ep)
*/
ino_t
dirlookup(name)
char *name;
const char *name;
{
register struct direct *dp;
struct direct *dp;
ino_t ino;
dp = pathsearch(name);
if (dp != NULL)
ino = dp->d_ino;
else
ino = 0;
ino = ((dp = pathsearch(name)) == NULL) ? 0 : dp->d_ino;
if (ino == 0 || TSTINO(ino, dumpmap) == 0)
fprintf(stderr, "%s is not on tape\n", name);
fprintf(stderr, "%s is not on the tape\n", name);
return (ino);
}

View File

@ -1,5 +1,5 @@
# from: @(#)Makefile 5.3 (Berkeley) 5/11/90
# $Id: Makefile,v 1.4 1993/07/31 15:34:30 mycroft Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/5/93
# $Id: Makefile,v 1.5 1994/06/08 19:36:09 mycroft Exp $
PROG= tunefs
MAN8= tunefs.0

View File

@ -1,5 +1,5 @@
.\" Copyright (c) 1983, 1991 Regents of the University of California.
.\" All rights reserved.
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@ -29,10 +29,10 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" from: @(#)tunefs.8 6.6 (Berkeley) 3/16/91
.\" $Id: tunefs.8,v 1.6 1994/04/20 03:57:07 cgd Exp $
.\" from: @(#)tunefs.8 8.2 (Berkeley) 12/11/93
.\" $Id: tunefs.8,v 1.7 1994/06/08 19:36:12 mycroft Exp $
.\"
.Dd March 16, 1991
.Dd December 11, 1993
.Dt TUNEFS 8
.Os BSD 4.2
.Sh NAME
@ -97,7 +97,7 @@ users will be unable to allocate files until enough files have
been deleted to get under the higher threshold.
.It Fl o Ar optimize_preference
The file system can either try to minimize the time spent
allocating blocks, or it can attempt minimize the space
allocating blocks, or it can attempt to minimize the space
fragmentation on the disk.
If the value of minfree (see above) is less than 10%,
then the file system should optimize for space to avoid
@ -108,6 +108,7 @@ the file system can be optimized for time.
.El
.Sh SEE ALSO
.Xr fs 5 ,
.Xr dumpfs 8 ,
.Xr newfs 8 ,
.Xr mkfs 8
.Rs
@ -120,7 +121,7 @@ the file system can be optimized for time.
.%N 3
.%P pp 181-197
.%D August 1984
.%O "(reprinted in the BSD System Manager's Manual, SMM:14)"
.%O "(reprinted in the BSD System Manager's Manual, SMM:5)"
.Re
.Sh BUGS
This program should work on mounted and active file systems.

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,14 +32,14 @@
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
All rights reserved.\n";
static char copyright[] =
"@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
/*static char sccsid[] = "from: @(#)tunefs.c 5.11 (Berkeley) 6/1/90";*/
static char rcsid[] = "$Id: tunefs.c,v 1.7 1994/04/20 03:57:08 cgd Exp $";
/*static char sccsid[] = "from: @(#)tunefs.c 8.2 (Berkeley) 4/19/94";*/
static char *rcsid = "$Id: tunefs.c,v 1.8 1994/06/08 19:36:13 mycroft Exp $";
#endif /* not lint */
/*
@ -47,7 +47,10 @@ static char rcsid[] = "$Id: tunefs.c,v 1.7 1994/04/20 03:57:08 cgd Exp $";
*/
#include <sys/param.h>
#include <sys/stat.h>
#include <ufs/fs.h>
#include <ufs/ffs/fs.h>
#include <errno.h>
#include <err.h>
#include <fcntl.h>
#include <fstab.h>
@ -56,22 +59,8 @@ static char rcsid[] = "$Id: tunefs.c,v 1.7 1994/04/20 03:57:08 cgd Exp $";
#include <stdlib.h>
#include <unistd.h>
/*
* MINFREE gives the minimum acceptable percentage of file system
* blocks which may be free. If the freelist drops below this level
* only the superuser may continue to allocate blocks. This may
* be set to 0 if no reserve of free blocks is deemed necessary,
* however throughput drops by fifty percent if the file system
* is run at between 90% and 100% full; thus the default value of
* fs_minfree is 10%. With 10% free space, fragmentation is not a
* problem, so we choose to optimize for time.
*
* XXX should be in some header common with newfs; snarfed from there.
*/
#define MINFREE 10
/* the optimization warning string template */
#define OPTWARN "should optimize for %s with minfree %s %d%%"
#define OPTWARN "should optimize for %s with minfree %s %d%%"
union {
struct fs sb;
@ -119,7 +108,7 @@ again:
}
if ((st.st_mode & S_IFMT) != S_IFBLK &&
(st.st_mode & S_IFMT) != S_IFCHR)
errx(1, "%s: not a block or character device", special);
errx(10, "%s: not a block or character device", special);
getsb(&sblock, special);
for (; argc > 0 && argv[0][0] == '-'; argc--, argv++) {
for (cp = &argv[0][1]; *cp; cp++)
@ -132,11 +121,11 @@ again:
case 'a':
name = "maximum contiguous block count";
if (argc < 1)
errx(1, "-a: missing %s", name);
errx(10, "-a: missing %s", name);
argc--, argv++;
i = atoi(*argv);
if (i < 1)
errx(1, "%s must be >= 1 (was %s)",
errx(10, "%s must be >= 1 (was %s)",
name, *argv);
warnx("%s changes from %d to %d",
name, sblock.fs_maxcontig, i);
@ -147,7 +136,7 @@ again:
name =
"rotational delay between contiguous blocks";
if (argc < 1)
errx(1, "-d: missing %s", name);
errx(10, "-d: missing %s", name);
argc--, argv++;
i = atoi(*argv);
warnx("%s changes from %dms to %dms",
@ -159,11 +148,11 @@ again:
name =
"maximum blocks per file in a cylinder group";
if (argc < 1)
errx(1, "-e: missing %s", name);
errx(10, "-e: missing %s", name);
argc--, argv++;
i = atoi(*argv);
if (i < 1)
errx(1, "%s must be >= 1 (was %s)",
errx(10, "%s must be >= 1 (was %s)",
name, *argv);
warnx("%s changes from %d to %d",
name, sblock.fs_maxbpg, i);
@ -173,11 +162,11 @@ again:
case 'm':
name = "minimum percentage of free space";
if (argc < 1)
errx(1, "-m: missing %s", name);
errx(10, "-m: missing %s", name);
argc--, argv++;
i = atoi(*argv);
if (i < 0 || i > 99)
errx(1, "bad %s (%s)", name, *argv);
errx(10, "bad %s (%s)", name, *argv);
warnx("%s changes from %d%% to %d%%",
name, sblock.fs_minfree, i);
sblock.fs_minfree = i;
@ -192,7 +181,7 @@ again:
case 'o':
name = "optimization preference";
if (argc < 1)
errx(1, "-o: missing %s", name);
errx(10, "-o: missing %s", name);
argc--, argv++;
chg[FS_OPTSPACE] = "space";
chg[FS_OPTTIME] = "time";
@ -201,7 +190,7 @@ again:
else if (strcmp(*argv, chg[FS_OPTTIME]) == 0)
i = FS_OPTTIME;
else
errx(1, "bad %s (options are `space' or `time')",
errx(10, "bad %s (options are `space' or `time')",
name);
if (sblock.fs_optim == i) {
warnx("%s remains unchanged as %s",
@ -237,14 +226,15 @@ again:
void
usage()
{
fprintf(stderr, "usage: tunefs tuneup-options special-device\n");
fprintf(stderr, "Usage: tunefs tuneup-options special-device\n");
fprintf(stderr, "where tuneup-options are:\n");
fprintf(stderr, "\t-a maximum contiguous blocks\n");
fprintf(stderr, "\t-d rotational delay between contiguous blocks\n");
fprintf(stderr, "\t-e maximum blocks per file in a cylinder group\n");
fprintf(stderr, "\t-m minimum percentage of free space\n");
fprintf(stderr, "\t-o optimization preference (`space' or `time')\n");
exit(1);
exit(2);
}
void
@ -255,24 +245,25 @@ getsb(fs, file)
fi = open(file, 2);
if (fi < 0)
err(1, "cannot open %s", file);
err(3, "cannot open %s", file);
if (bread((daddr_t)SBOFF, (char *)fs, SBSIZE))
err(1, "%s: bad super block", file);
err(4, "%s: bad super block", file);
if (fs->fs_magic != FS_MAGIC)
err(1, "%s: bad magic number", file);
err(5, "%s: bad magic number", file);
dev_bsize = fs->fs_fsize / fsbtodb(fs, 1);
}
void
bwrite(bno, buf, size)
daddr_t bno;
bwrite(blk, buf, size)
daddr_t blk;
char *buf;
int size;
{
if (lseek(fi, bno * dev_bsize, 0) < 0)
err(1, "FS SEEK");
if (lseek(fi, (off_t)blk * dev_bsize, SEEK_SET) < 0)
err(6, "FS SEEK");
if (write(fi, buf, size) != size)
err(1, "FS WRITE");
err(7, "FS WRITE");
}
int
@ -281,9 +272,9 @@ bread(bno, buf, cnt)
char *buf;
int cnt;
{
register i;
int i;
if (lseek(fi, bno * dev_bsize, 0) < 0)
if (lseek(fi, (off_t)bno * dev_bsize, SEEK_SET) < 0)
return(1);
if ((i = read(fi, buf, cnt)) != cnt) {
for(i=0; i<sblock.fs_bsize; i++)

View File

@ -1,8 +1,6 @@
# from: @(#)Makefile 5.4 (Berkeley) 5/11/90
# $Id: Makefile,v 1.5 1993/10/08 00:51:24 cgd Exp $
# from: @(#)Makefile 8.2 (Berkeley) 2/20/94
# $Id: Makefile,v 1.6 1994/06/08 19:34:37 mycroft Exp $
PROG= umount
CFLAGS+=-DNFS
NOMAN= noman
.include <bsd.prog.mk>

124
sbin/umount/umount.8 Normal file
View File

@ -0,0 +1,124 @@
.\" Copyright (c) 1980, 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" from: @(#)umount.8 8.1 (Berkeley) 2/20/94
.\" $Id: umount.8,v 1.1 1994/06/08 19:34:38 mycroft Exp $
.\"
.Dd February 20, 1994
.Dt UMOUNT 8
.Os BSD 4
.Sh NAME
.Nm umount
.Nd unmount file systems
.Sh SYNOPSIS
.Nm umount
.Op Fl fv
.Ar special | node
.Nm umount
.Fl a
.Op Fl fv
.Op Fl h Ar host
.Op Fl t Ar ufs | lfs | external_type
.Sh DESCRIPTION
The
.Nm umount
command
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
.Ar special
or
.Ar node
are not provided, the appropriate information is taken from the
.Xr fstab 5
file.
.Pp
The options are as follows:
.Bl -tag -width indent
.It Fl a
All of the file systems described in
.Xr fstab 5
are unmounted.
.It Fl f
The file system is forcibly unmounted.
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.
.It Fl h Ar host
Only filesystems mounted from the specified host will be
unmounted.
This option is implies the
.Fl a
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"
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.
The list of filesystem types can be prefixed with
.Dq no
to specify the filesystem types for which action should
.Em not
be taken.
For example, the
.Nm umount
command:
.Bd -literal -offset indent
umount -a -t nfs,mfs
.Ed
.Pp
umounts all filesystems of the type
.Tn NFS
and
.Tn MFS .
.It Fl v
Verbose, additional information is printed out as each file system
is unmounted.
.El
.Sh FILES
.Bl -tag -width /etc/fstab -compact
.It Pa /etc/fstab
file system table
.El
.Sh SEE ALSO
.Xr unmount 2 ,
.Xr fstab 5 ,
.Xr mount 8
.Sh HISTORY
A
.Nm umount
command appeared in
.At v6 .

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 1980, 1989 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1980, 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,101 +32,83 @@
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1980, 1989 The Regents of the University of California.\n\
All rights reserved.\n";
static char copyright[] =
"@(#) Copyright (c) 1980, 1989, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
/*static char sccsid[] = "from: @(#)umount.c 5.16 (Berkeley) 6/3/91";*/
static char rcsid[] = "$Id: umount.c,v 1.6 1994/04/14 03:25:38 cgd Exp $";
/*static char sccsid[] = "from: @(#)umount.c 8.3 (Berkeley) 2/20/94";*/
static char *rcsid = "$Id: umount.c,v 1.7 1994/06/08 19:34:40 mycroft Exp $";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/mount.h>
#ifdef NFS
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <netdb.h>
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
#include <rpc/pmap_prot.h>
#include <nfs/rpcv2.h>
#endif
#include <err.h>
#include <fstab.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef NFS
char *nfshost;
#endif
typedef enum { MNTON, MNTFROM } mntwhat;
int vflag, all, errs, fake;
int fflag = MNT_NOFORCE;
int fake, fflag, vflag;
char **typelist;
char *nfshost;
#define MNTON 1
#define MNTFROM 2
#define MNTTYPE 3
char **typelist;
struct fstab *allocfsent __P((struct fstab *));
int badtype __P((char *, char **));
void freefsent __P((struct fstab *));
char *getmntname __P((char *, int, char *));
char **maketypelist __P((char *));
void umountall __P((char **));
int umountfs __P((char *, char **, int));
void usage __P((void));
#ifdef NFS
int namematch __P((struct hostent *, char *));
int xdr_dir __P((XDR *, char *));
#endif
char *getmntname __P((char *, mntwhat, char *));
void maketypelist __P((char *));
int selected __P((char *));
int namematch __P((struct hostent *));
int umountall __P((void));
int umountfs __P((char *));
void usage __P((void));
int xdr_dir __P((XDR *, char *));
int
main(argc, argv)
int argc;
char **argv;
char *argv[];
{
extern char *optarg;
extern int optind;
int ch;
int all, ch, errs;
/* Start disks transferring immediately. */
sync();
while ((ch = getopt(argc, argv, "afFh:t:v")) != EOF)
switch((char)ch) {
case 'v':
vflag++;
all = 0;
while ((ch = getopt(argc, argv, "aFfh:t:v")) != EOF)
switch (ch) {
case 'a':
all = 1;
break;
case 'F':
fake = 1;
break;
case 'f':
fflag = MNT_FORCE;
break;
case 'F':
fake++;
break;
case 'a':
all++;
case 'h': /* -h implies -a. */
all = 1;
nfshost = optarg;
break;
case 't':
typelist = maketypelist(optarg);
maketypelist(optarg);
break;
#ifdef NFS
case 'h':
/* -h flag implies -a, and "-t nfs" if no -t flag */
nfshost = optarg;
all++;
if (typelist == NULL)
typelist = maketypelist(MOUNT_NFS);
case 'v':
vflag = 1;
break;
#endif /* NFS */
case '?':
default:
usage();
/* NOTREACHED */
@ -134,150 +116,106 @@ main(argc, argv)
argc -= optind;
argv += optind;
if (argc == 0 && !all)
if (argc == 0 && !all || argc != 0 && all)
usage();
/* -h implies "-t nfs" if no -t flag. */
if ((nfshost != NULL) && (typelist == NULL))
maketypelist("nfs");
if (all) {
if (argc > 0)
usage();
if (setfsent() == 0)
err(1, "%s", FSTAB);
umountall(typelist);
exit(0);
err(1, "%s", _PATH_FSTAB);
errs = umountall();
} else
setfsent();
while (argc > 0) {
if (umountfs(*argv++, 0, 0) == 0)
errs++;
argc--;
}
for (errs = 0; *argv != NULL; ++argv)
if (umountfs(*argv) == 0)
errs = 1;
exit(errs);
}
void
usage()
int
umountall()
{
fprintf(stderr,
"%s\n%s\n",
"Usage: umount [-fv] special | node",
#ifndef NFS
" or umount -a[fv] [-t fstypelist]"
#else
" or umount -a[fv] [-h host] [-t fstypelist]"
#endif
);
exit(1);
}
struct fstab *fs;
int rval;
char *cp;
void
umountall(typelist)
char **typelist;
{
register struct fstab *fs;
struct fstab *allocfsent();
while ((fs = getfsent()) != NULL) {
/* Ignore the root. */
if (strcmp(fs->fs_file, "/") == 0)
continue;
/*
* !!!
* Historic practice: ignore unknown FSTAB_* fields.
*/
if (strcmp(fs->fs_type, FSTAB_RW) &&
strcmp(fs->fs_type, FSTAB_RO) &&
strcmp(fs->fs_type, FSTAB_RQ))
continue;
if ((fs = getfsent()) == (struct fstab *)0)
return;
fs = allocfsent(fs);
umountall(typelist);
if (strcmp(fs->fs_file, "/") == 0) {
freefsent(fs);
return;
if (!selected(fs->fs_vfstype))
continue;
/*
* We want to unmount the file systems in the reverse order
* that they were mounted. So, we save off the file name
* in some allocated memory, and then call recursively.
*/
if ((cp = malloc((size_t)strlen(fs->fs_file) + 1)) == NULL)
err(1, NULL);
(void)strcpy(cp, fs->fs_file);
rval = umountall();
return (umountfs(cp) || rval);
}
if (strcmp(fs->fs_type, FSTAB_RW) &&
strcmp(fs->fs_type, FSTAB_RO) &&
strcmp(fs->fs_type, FSTAB_RQ)) {
freefsent(fs);
return;
}
(void) umountfs(fs->fs_file, typelist, 1);
freefsent(fs);
}
struct fstab *
allocfsent(fs)
register struct fstab *fs;
{
register struct fstab *new;
register char *cp;
new = (struct fstab *)malloc((unsigned)sizeof (*fs));
cp = (char *)malloc((unsigned)strlen(fs->fs_file) + 1);
strcpy(cp, fs->fs_file);
new->fs_file = cp;
cp = (char *)malloc((unsigned)strlen(fs->fs_type) + 1);
strcpy(cp, fs->fs_type);
new->fs_type = cp;
cp = (char *)malloc((unsigned)strlen(fs->fs_spec) + 1);
strcpy(cp, fs->fs_spec);
new->fs_spec = cp;
new->fs_passno = fs->fs_passno;
new->fs_freq = fs->fs_freq;
return (new);
}
void
freefsent(fs)
register struct fstab *fs;
{
if (fs->fs_file != NULL)
free(fs->fs_file);
if (fs->fs_spec != NULL)
free(fs->fs_spec);
if (fs->fs_type != NULL)
free(fs->fs_type);
free((char *)fs);
return (0);
}
int
umountfs(name, typelist, all)
umountfs(name)
char *name;
char **typelist;
int all;
{
char *mntpt;
struct stat stbuf;
char type[MFSNAMELEN+1];
#ifdef NFS
register CLIENT *clp;
struct hostent *hp = 0;
struct sockaddr_in saddr;
struct timeval pertry, try;
enum clnt_stat clnt_stat;
int so = RPC_ANYSOCK;
char *hostp, *delimp;
#endif /* NFS */
struct hostent *hp;
struct sockaddr_in saddr;
struct stat sb;
struct timeval pertry, try;
CLIENT *clp;
int so;
char *delimp, *hostp, *mntpt, rname[MAXPATHLEN], type[MFSNAMELEN];
if (stat(name, &stbuf) < 0) {
if (getmntname(name, MNTFROM, type) != 0)
mntpt = name;
else if ((mntpt = getmntname(name, MNTON, type)) == 0) {
if (!all)
warnx("%s: not currently mounted\n", name);
return (0);
}
} else if ((stbuf.st_mode & S_IFMT) == S_IFBLK) {
if ((mntpt = getmntname(name, MNTON, type)) == 0) {
if (!all)
warnx("%s: not currently mounted\n", name);
return (0);
}
} else if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
mntpt = name;
if (getmntname(mntpt, MNTFROM, type) == 0) {
if (!all)
warnx("%s: not currently mounted\n", name);
return (0);
}
} else {
if (!all)
warnx("%s: not a directory or special device\n", name);
if (realpath(name, rname) == NULL) {
warn("%s", rname);
return (0);
}
if (badtype(type, typelist))
return(1);
#ifdef NFS
name = rname;
if (stat(name, &sb) < 0) {
if (((mntpt = getmntname(name, MNTFROM, type)) == NULL) &&
((mntpt = getmntname(name, MNTON, type)) == NULL)) {
warnx("%s: not currently mounted", name);
return (1);
}
} else if (S_ISBLK(sb.st_mode)) {
if ((mntpt = getmntname(name, MNTON, type)) == NULL) {
warnx("%s: not currently mounted", name);
return (1);
}
} else if (S_ISDIR(sb.st_mode)) {
mntpt = name;
if ((name = getmntname(mntpt, MNTFROM, type)) == NULL) {
warnx("%s: not currently mounted", mntpt);
return (1);
}
} else {
warnx("%s: not a directory or special device", name);
return (1);
}
if (!selected(type))
return (0);
if ((delimp = strchr(name, '@')) != NULL) {
hostp = delimp + 1;
*delimp = '\0';
@ -287,39 +225,42 @@ umountfs(name, typelist, all)
*delimp = '\0';
hostp = name;
hp = gethostbyname(hostp);
name = delimp+1;
name = delimp + 1;
*delimp = ':';
}
if (!namematch(hp, nfshost))
return(1);
#endif /* NFS */
if (!fake && unmount(mntpt, fflag) < 0) {
warn("%s", mntpt);
} else
hp = NULL;
if (!namematch(hp))
return (0);
}
if (vflag)
fprintf(stderr, "%s: Unmounted from %s\n", name, mntpt);
#ifdef NFS
if (!fake && hp != NULL && (fflag & MNT_FORCE) == 0) {
if (vflag)
(void)printf("%s: unmount from %s\n", name, mntpt);
if (fake)
return (0);
if (unmount(mntpt, fflag) < 0) {
warn("%s", mntpt);
return (1);
}
if ((hp != NULL) && !(fflag & MNT_FORCE)) {
*delimp = '\0';
bzero((char *)&saddr, sizeof saddr);
bcopy(hp->h_addr,(caddr_t)&saddr.sin_addr,hp->h_length);
memset(&saddr, 0, sizeof(saddr));
saddr.sin_family = AF_INET;
saddr.sin_port = 0;
memmove(&saddr.sin_addr, hp->h_addr, hp->h_length);
pertry.tv_sec = 3;
pertry.tv_usec = 0;
if ((clp = clntudp_create(&saddr, RPCPROG_MNT, RPCMNT_VER1,
pertry, &so)) == NULL) {
so = RPC_ANYSOCK;
if ((clp = clntudp_create(&saddr,
RPCPROG_MNT, RPCMNT_VER1, pertry, &so)) == NULL) {
clnt_pcreateerror("Cannot MNT PRC");
return (1);
}
clp->cl_auth = authunix_create_default();
try.tv_sec = 20;
try.tv_usec = 0;
clnt_stat = clnt_call(clp, RPCMNT_UMOUNT, xdr_dir, name,
xdr_void, (caddr_t)0, try);
clnt_stat = clnt_call(clp,
RPCMNT_UMOUNT, xdr_dir, name, xdr_void, (caddr_t)0, try);
if (clnt_stat != RPC_SUCCESS) {
clnt_perror(clp, "Bad MNT RPC");
return (1);
@ -327,118 +268,122 @@ umountfs(name, typelist, all)
auth_destroy(clp->cl_auth);
clnt_destroy(clp);
}
#endif /* NFS */
return (1);
return (0);
}
char *
getmntname(name, what, type)
char *name;
int what;
mntwhat what;
char *type;
{
int mntsize, i;
struct statfs *mntbuf;
int i, mntsize;
if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
warn("umount");
return (0);
warn("getmntinfo");
return (NULL);
}
for (i = 0; i < mntsize; i++) {
if (what == MNTON && !strcmp(mntbuf[i].f_mntfromname, name)) {
if (type) {
strncpy(type, mntbuf[i].f_fstypename,
MFSNAMELEN);
type[MFSNAMELEN] = '\0';
}
if ((what == MNTON) && !strcmp(mntbuf[i].f_mntfromname, name)) {
if (type)
memcpy(type, mntbuf[i].f_fstypename,
sizeof(mntbuf[i].f_fstypename));
return (mntbuf[i].f_mntonname);
}
if (what == MNTFROM && !strcmp(mntbuf[i].f_mntonname, name)) {
if (type) {
strncpy(type, mntbuf[i].f_fstypename,
MFSNAMELEN);
type[MFSNAMELEN] = '\0';
}
if ((what == MNTFROM) && !strcmp(mntbuf[i].f_mntonname, name)) {
if (type)
memcpy(type, mntbuf[i].f_fstypename,
sizeof(mntbuf[i].f_fstypename));
return (mntbuf[i].f_mntfromname);
}
}
return (0);
return (NULL);
}
static int skipvfs;
static enum { IN_LIST, NOT_IN_LIST } which;
int
badtype(type, typelist)
selected(type)
char *type;
char **typelist;
{
char **av;
/* If no type specified, it's always selected. */
if (typelist == NULL)
return(0);
while (*typelist) {
if (!strcmp(type, *typelist))
return(skipvfs);
typelist++;
}
return(!skipvfs);
return (1);
for (av = typelist; *av != NULL; ++av)
if (!strcmp(type, *av))
return (which == IN_LIST ? 1 : 0);
return (which == IN_LIST ? 0 : 1);
}
char **
void
maketypelist(fslist)
char *fslist;
{
register char *nextcp, **av;
register int i;
int i;
char *nextcp, **av;
if (fslist == NULL)
return(NULL);
if ((fslist == NULL) || (fslist[0] == '\0'))
errx(1, "empty type list");
/*
* XXX
* Note: the syntax is "noxxx,yyy" for no xxx's and
* no yyy's, not the more intuitive "noyyy,noyyy".
*/
if (fslist[0] == 'n' && fslist[1] == 'o') {
fslist += 2;
skipvfs = 1;
which = NOT_IN_LIST;
} else
skipvfs = 0;
for (i = 0, nextcp = fslist; *nextcp; nextcp++)
which = IN_LIST;
/* Count the number of types. */
for (i = 0, nextcp = fslist; *nextcp != NULL; ++nextcp)
if (*nextcp == ',')
i++;
av = (char **)malloc((i+2) * sizeof(int));
if (av == NULL)
return(NULL);
for (i = 0; fslist; fslist = nextcp) {
/* Build an array of that many types. */
if ((av = typelist = malloc((i + 2) * sizeof(char *))) == NULL)
err(1, NULL);
for (i = 0; fslist != NULL; fslist = nextcp, ++i) {
if ((nextcp = strchr(fslist, ',')) != NULL)
*nextcp++ = '\0';
av[i++] = strdup(fslist);
/* Note that we're keeping pointers into the input string. */
av[i] = fslist;
}
av[i++] = 0;
return(av);
/* Terminate the array. */
av[i++] = NULL;
}
#ifdef NFS
int
namematch(hp, nfshost)
namematch(hp)
struct hostent *hp;
char *nfshost;
{
register char *cp;
register char **np;
char *cp, **np;
if ((hp == NULL) || (nfshost == NULL))
return (1);
if (hp == NULL || nfshost == NULL)
return(1);
if (strcasecmp(nfshost, hp->h_name) == 0)
return(1);
return (1);
if ((cp = strchr(hp->h_name, '.')) != NULL) {
*cp = '\0';
if (strcasecmp(nfshost, hp->h_name) == 0)
return(1);
return (1);
}
for (np = hp->h_aliases; *np; np++) {
if (strcasecmp(nfshost, *np) == 0)
return(1);
return (1);
if ((cp = strchr(*np, '.')) != NULL) {
*cp = '\0';
if (strcasecmp(nfshost, *np) == 0)
return(1);
return (1);
}
}
return(0);
return (0);
}
/*
@ -451,4 +396,13 @@ xdr_dir(xdrsp, dirp)
{
return (xdr_string(xdrsp, &dirp, RPCMNT_PATHLEN));
}
#endif /* NFS */
void
usage()
{
(void)fprintf(stderr,
"usage: %s\n %s\n",
"umount [-fv] [-t fstypelist] special | node",
"umount -a[fv] [-h host] [-t fstypelist]");
exit(1);
}