fixed so that nfs unmounts actually get round to calling the remote mountd.
SCCS-vsn: sbin/umount/umount.c 8.2
#endif /* not lint */
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)umount.c 8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)umount.c 8.2 (Berkeley) %G%";
#endif /* not lint */
#include <sys/param.h>
#endif /* not lint */
#include <sys/param.h>
#include <nfs/rpcv2.h>
#endif
#include <nfs/rpcv2.h>
#endif
#include <fstab.h>
#include <stdio.h>
#include <fstab.h>
#include <stdio.h>
-int xdr_dir();
-char *nfshost;
+char *nfshost;
+int namematch __P((struct hostent *, char *));
+int xdr_dir __P((XDR *, char *));
-int vflag, all, errs, fake;
-int fflag = 0;
-char *getmntname();
-
-#define MNTON 1
-#define MNTFROM 2
-#define MNTTYPE 3
-
-int *typelist, *maketypelist();
-
-char *namelist[] = INITMOUNTNAMES;
+typedef enum { MNTON, MNTFROM } mntwhat;
+int all, errs, fake, vflag;
+int fflag = 0;
+char *namelist[] = INITMOUNTNAMES;
+int *typelist;
+
+int badtype __P((int, int *));
+int fsnametotype __P((char *));
+char *getmntname __P((char *, mntwhat, int *));
+int *maketypelist __P((char *));
+void umountall __P((int *));
+int umountfs __P((char *, int *));
+void usage __P((void));
+
+int
main(argc, argv)
int argc;
char **argv;
{
main(argc, argv)
int argc;
char **argv;
{
- extern char *optarg;
- extern int optind;
int ch;
sync();
while ((ch = getopt(argc, argv, "afFh:t:v")) != EOF)
int ch;
sync();
while ((ch = getopt(argc, argv, "afFh:t:v")) != EOF)
- switch((char)ch) {
- case 'v':
- vflag++;
+ switch (ch) {
+ case 'a':
+ all++;
break;
case 'f':
fflag = MNT_FORCE;
break;
case 'f':
fflag = MNT_FORCE;
- case 'a':
- all++;
- break;
- case 't':
- typelist = maketypelist(optarg);
- break;
#ifdef NFS
case 'h':
/* -h flag implies -a, and "-t nfs" if no -t flag */
#ifdef NFS
case 'h':
/* -h flag implies -a, and "-t nfs" if no -t flag */
typelist = maketypelist("nfs");
break;
#endif /* NFS */
typelist = maketypelist("nfs");
break;
#endif /* NFS */
+ case 't':
+ typelist = maketypelist(optarg);
+ break;
+ case 'v':
+ vflag++;
+ break;
default:
usage();
/* NOTREACHED */
default:
usage();
/* NOTREACHED */
if (argc == 0 && !all)
usage();
if (argc == 0 && !all)
usage();
+
+ if (setfsent() == 0)
+ err(1, "%s", FSTAB);
+
if (all) {
if (argc > 0)
usage();
if (all) {
if (argc > 0)
usage();
- if (setfsent() == 0)
- perror(FSTAB), exit(1);
umountall(typelist);
exit(0);
umountall(typelist);
exit(0);
while (argc > 0) {
if (umountfs(*argv++, 0) == 0)
errs++;
argc--;
}
while (argc > 0) {
if (umountfs(*argv++, 0) == 0)
errs++;
argc--;
}
usage()
{
fprintf(stderr,
usage()
{
fprintf(stderr,
- "%s\n%s\n",
- "Usage: umount [-fv] special | node",
+ "usage:\n%s\n%s\n",
+ " umount [-fv] special | node",
- " or umount -a[fv] [-t fstypelist]"
+ " umount -a[fv] [-t fstypelist]"
- " or umount -a[fv] [-h host] [-t fstypelist]"
+ " umount -a[fv] [-h host] [-t fstypelist]"
- register struct fstab *fs;
while (fs = getfsent()) {
if (badtype(fsnametotype(fs->fs_vfstype), typelist))
while (fs = getfsent()) {
if (badtype(fsnametotype(fs->fs_vfstype), typelist))
strcmp(fs->fs_type, FSTAB_RO) &&
strcmp(fs->fs_type, FSTAB_RQ))
continue;
strcmp(fs->fs_type, FSTAB_RO) &&
strcmp(fs->fs_type, FSTAB_RQ))
continue;
- cp = (char *)malloc((unsigned)strlen(fs->fs_file) + 1);
- if (cp == NULL) {
- fprintf(stderr, "Out of memory.\n");
- exit(2);
- }
+ cp = (char *)malloc((size_t)strlen(fs->fs_file) + 1);
+ if (cp == NULL)
+ err(2, "malloc");
strcpy(cp, fs->fs_file);
umountall(typelist);
break;
strcpy(cp, fs->fs_file);
umountall(typelist);
break;
umountfs(name, typelist)
char *name;
int *typelist;
{
umountfs(name, typelist)
char *name;
int *typelist;
{
- char *mntpt;
- struct stat stbuf;
- int type;
+ enum clnt_stat clnt_stat;
+ CLIENT *clp;
+ char *delimp, *hostp;
struct hostent *hp = 0;
struct sockaddr_in saddr;
struct timeval pertry, try;
struct hostent *hp = 0;
struct sockaddr_in saddr;
struct timeval pertry, try;
- enum clnt_stat clnt_stat;
+ char *mntpt;
+ struct stat stbuf;
+ int type;
+ char rname[MAXPATHLEN];
+
+ if (realpath(name, rname) == NULL) {
+ warn("%s", rname);
+ return (0);
+ }
+
+ name = rname;
if (stat(name, &stbuf) < 0) {
if (stat(name, &stbuf) < 0) {
- if (getmntname(name, MNTFROM, &type) != 0)
- mntpt = name;
- else if ((mntpt = getmntname(name, MNTON, &type)) == 0) {
- fprintf(stderr, "%s: not currently mounted\n", name);
+ if (((mntpt = getmntname(name, MNTFROM, &type)) == 0) &&
+ ((mntpt = getmntname(name, MNTON, &type)) == 0)) {
+ warnx("%s: not currently mounted", name);
return (0);
}
} else if ((stbuf.st_mode & S_IFMT) == S_IFBLK) {
if ((mntpt = getmntname(name, MNTON, &type)) == 0) {
return (0);
}
} else if ((stbuf.st_mode & S_IFMT) == S_IFBLK) {
if ((mntpt = getmntname(name, MNTON, &type)) == 0) {
- fprintf(stderr, "%s: not currently mounted\n", name);
+ warnx("%s: not currently mounted", name);
return (0);
}
} else if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
mntpt = name;
return (0);
}
} else if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
mntpt = name;
- if (getmntname(mntpt, MNTFROM, &type) == 0) {
- fprintf(stderr, "%s: not currently mounted\n", name);
+ if ((name = getmntname(mntpt, MNTFROM, &type)) == 0) {
+ warnx("%s: not currently mounted", mntpt);
- fprintf(stderr, "%s: not a directory or special device\n",
- name);
+ warnx("%s: not a directory or special device", name);
return (0);
}
if (badtype(type, typelist))
return (0);
}
if (badtype(type, typelist))
- if ((delimp = index(name, '@')) != NULL) {
+ if ((delimp = strchr(name, '@')) != NULL) {
hostp = delimp + 1;
*delimp = '\0';
hp = gethostbyname(hostp);
*delimp = '@';
hostp = delimp + 1;
*delimp = '\0';
hp = gethostbyname(hostp);
*delimp = '@';
- } else if ((delimp = index(name, ':')) != NULL) {
+ } else if ((delimp = strchr(name, ':')) != NULL) {
*delimp = '\0';
hostp = name;
hp = gethostbyname(hostp);
*delimp = '\0';
hostp = name;
hp = gethostbyname(hostp);
}
if (!namematch(hp, nfshost))
}
if (!namematch(hp, nfshost))
#endif /* NFS */
if (!fake && unmount(mntpt, fflag) < 0) {
#endif /* NFS */
if (!fake && unmount(mntpt, fflag) < 0) {
- fprintf(stderr, "%s: Unmounted from %s\n", name, mntpt);
+ warnx("%s: unmounted from %s", name, mntpt);
- if (!fake && hp != NULL && (fflag & MNT_FORCE) == 0) {
+ if (!fake && (hp != NULL) && ((fflag & MNT_FORCE) == 0)) {
- bcopy(hp->h_addr,(caddr_t)&saddr.sin_addr,hp->h_length);
+ bzero(&saddr, sizeof(saddr));
saddr.sin_family = AF_INET;
saddr.sin_port = 0;
saddr.sin_family = AF_INET;
saddr.sin_port = 0;
+ bcopy(hp->h_addr, &saddr.sin_addr, hp->h_length);
pertry.tv_sec = 3;
pertry.tv_usec = 0;
if ((clp = clntudp_create(&saddr, RPCPROG_MNT, RPCMNT_VER1,
pertry.tv_sec = 3;
pertry.tv_usec = 0;
if ((clp = clntudp_create(&saddr, RPCPROG_MNT, RPCMNT_VER1,
char *
getmntname(name, what, type)
char *name;
char *
getmntname(name, what, type)
char *name;
struct statfs *mntbuf;
if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
struct statfs *mntbuf;
if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
- perror("umount");
- return (0);
+ warn("getmntinfo");
+ return (NULL);
}
for (i = 0; i < mntsize; i++) {
if (what == MNTON && !strcmp(mntbuf[i].f_mntfromname, name)) {
}
for (i = 0; i < mntsize; i++) {
if (what == MNTON && !strcmp(mntbuf[i].f_mntfromname, name)) {
return (mntbuf[i].f_mntfromname);
}
}
return (mntbuf[i].f_mntfromname);
}
}
badtype(type, typelist)
int type;
int *typelist;
{
if (typelist == 0)
badtype(type, typelist)
int type;
int *typelist;
{
if (typelist == 0)
while (*typelist) {
if (type == *typelist)
while (*typelist) {
if (type == *typelist)
}
int *
maketypelist(fslist)
char *fslist;
{
}
int *
maketypelist(fslist)
char *fslist;
{
- register char *nextcp;
- register int *av, i;
+ char *nextcp;
+ int *av, i;
if (fslist[0] == 'n' && fslist[1] == 'o') {
fslist += 2;
skipvfs = 1;
if (fslist[0] == 'n' && fslist[1] == 'o') {
fslist += 2;
skipvfs = 1;
for (i = 0, nextcp = fslist; *nextcp; nextcp++)
if (*nextcp == ',')
i++;
for (i = 0, nextcp = fslist; *nextcp; nextcp++)
if (*nextcp == ',')
i++;
av = (int *)malloc((i+2) * sizeof(int));
if (av == NULL)
av = (int *)malloc((i+2) * sizeof(int));
if (av == NULL)
for (i = 0; fslist; fslist = nextcp) {
for (i = 0; fslist; fslist = nextcp) {
- if (nextcp = index(fslist, ','))
+ if (nextcp = strchr(fslist, ','))
*nextcp++ = '\0';
av[i++] = fsnametotype(fslist);
}
av[i++] = 0;
*nextcp++ = '\0';
av[i++] = fsnametotype(fslist);
}
av[i++] = 0;
fsnametotype(name)
char *name;
{
fsnametotype(name)
char *name;
{
namematch(hp, nfshost)
struct hostent *hp;
char *nfshost;
{
namematch(hp, nfshost)
struct hostent *hp;
char *nfshost;
{
- register char *cp;
- register char **np;
if (hp == NULL || nfshost == NULL)
if (hp == NULL || nfshost == NULL)
if (strcasecmp(nfshost, hp->h_name) == 0)
if (strcasecmp(nfshost, hp->h_name) == 0)
- return(1);
- if (cp = index(hp->h_name, '.')) {
+ return (1);
+
+ if (cp = strchr(hp->h_name, '.')) {
*cp = '\0';
if (strcasecmp(nfshost, hp->h_name) == 0)
*cp = '\0';
if (strcasecmp(nfshost, hp->h_name) == 0)
}
for (np = hp->h_aliases; *np; np++) {
if (strcasecmp(nfshost, *np) == 0)
}
for (np = hp->h_aliases; *np; np++) {
if (strcasecmp(nfshost, *np) == 0)
- return(1);
- if (cp = index(*np, '.')) {
+ return (1);
+ if (cp = strchr(*np, '.')) {
+
*cp = '\0';
if (strcasecmp(nfshost, *np) == 0)
*cp = '\0';
if (strcasecmp(nfshost, *np) == 0)
}
/*
* xdr routines for mount rpc's
*/
}
/*
* xdr routines for mount rpc's
*/
xdr_dir(xdrsp, dirp)
XDR *xdrsp;
char *dirp;
xdr_dir(xdrsp, dirp)
XDR *xdrsp;
char *dirp;