* Copyright (c) 1980, 1989 The Regents of the University of California.
* Redistribution and use in source and binary forms is permitted
* provided that all copyright information, including this notice,
* is retained in all such forms, and that any documentation,
* advertising or other materials related to such distribution and
* use acknowledge that the software was
* developed by the University of California, Berkeley. The name
* of the University may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1980, 1989 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)umount.c 5.15 (Berkeley) %G%";
#include <sys/socketvar.h>
#include <rpc/pmap_clnt.h>
#include <rpc/pmap_prot.h>
int vflag
, all
, errs
, fake
;
char *rindex(), *getmntname();
int *typelist
, *maketypelist();
while ((ch
= getopt(argc
, argv
, "afFh:t:v")) != EOF
)
typelist
= maketypelist(optarg
);
/* -h flag implies -a, and "-t nfs" if no -t flag */
typelist
= maketypelist("nfs");
if (umountfs(*argv
++, 0) == 0)
"Usage: umount [-fv] special | node",
" or umount -a[fv] [-t fstypelist]"
" or umount -a[fv] [-h host] [-t fstypelist]"
register struct fstab
*fs
;
struct fstab
*allocfsent();
if ((fs
= getfsent()) == (struct fstab
*)0)
if (strcmp(fs
->fs_file
, "/") == 0) {
if (strcmp(fs
->fs_type
, FSTAB_RW
) &&
strcmp(fs
->fs_type
, FSTAB_RO
) &&
strcmp(fs
->fs_type
, FSTAB_RQ
)) {
(void) umountfs(fs
->fs_file
, typelist
);
register struct fstab
*fs
;
register struct fstab
*new;
new = (struct fstab
*)malloc((unsigned)sizeof (*fs
));
cp
= malloc((unsigned)strlen(fs
->fs_file
) + 1);
cp
= malloc((unsigned)strlen(fs
->fs_type
) + 1);
cp
= malloc((unsigned)strlen(fs
->fs_spec
) + 1);
new->fs_passno
= fs
->fs_passno
;
new->fs_freq
= fs
->fs_freq
;
register struct fstab
*fs
;
struct sockaddr_in saddr
;
struct timeval pertry
, try;
enum clnt_stat clnt_stat
;
if (stat(name
, &stbuf
) < 0) {
if ((mntpt
= getmntname(name
, MNTON
, &type
)) == 0)
} else if ((stbuf
.st_mode
& S_IFMT
) == S_IFBLK
) {
if ((mntpt
= getmntname(name
, MNTON
, &type
)) == 0)
} else if ((stbuf
.st_mode
& S_IFMT
) == S_IFDIR
) {
if ((name
= getmntname(mntpt
, MNTFROM
, &type
)) == 0)
fprintf(stderr
, "%s: not a directory or special device\n",
if (badtype(type
, typelist
))
if ((delimp
= index(name
, '@')) != NULL
) {
hp
= gethostbyname(hostp
);
} else if ((delimp
= index(name
, ':')) != NULL
) {
hp
= gethostbyname(hostp
);
if (!namematch(hp
, nfshost
))
if (!fake
&& unmount(mntpt
, fflag
) < 0) {
fprintf(stderr
, "%s: Unmounted from %s\n", name
, mntpt
);
if (!fake
&& hp
!= NULL
&& (fflag
& MNT_FORCE
) == 0) {
bcopy(hp
->h_addr
,(caddr_t
)&saddr
.sin_addr
,hp
->h_length
);
saddr
.sin_family
= AF_INET
;
if ((clp
= clntudp_create(&saddr
, RPCPROG_MNT
, RPCMNT_VER1
,
clnt_pcreateerror("Cannot MNT PRC");
clp
->cl_auth
= authunix_create_default();
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");
auth_destroy(clp
->cl_auth
);
getmntname(name
, what
, type
)
if ((mntsize
= getmntinfo(&mntbuf
, MNT_NOWAIT
)) == 0) {
for (i
= 0; i
< mntsize
; i
++) {
if (what
== MNTON
&& !strcmp(mntbuf
[i
].f_mntfromname
, name
)) {
*type
= mntbuf
[i
].f_type
;
return (mntbuf
[i
].f_mntonname
);
if (what
== MNTFROM
&& !strcmp(mntbuf
[i
].f_mntonname
, name
)) {
*type
= mntbuf
[i
].f_type
;
return (mntbuf
[i
].f_mntfromname
);
fprintf(stderr
, "%s: not currently mounted\n", name
);
if (fslist
[0] == 'n' && fslist
[1] == 'o') {
for (i
= 0, nextcp
= fslist
; *nextcp
; nextcp
++)
av
= (int *)malloc((i
+2) * sizeof(int));
for (i
= 0; fslist
; fslist
= nextcp
) {
if (nextcp
= index(fslist
, ','))
if (strcmp(fslist
, "ufs") == 0)
else if (strcmp(fslist
, "nfs") == 0)
else if (strcmp(fslist
, "mfs") == 0)
else if (strcmp(fslist
, "pc") == 0)
if (hp
== NULL
|| nfshost
== NULL
)
if (strcasecmp(nfshost
, hp
->h_name
) == 0)
if (cp
= index(hp
->h_name
, '.')) {
if (strcasecmp(nfshost
, hp
->h_name
) == 0)
for (np
= hp
->h_aliases
; *np
; np
++) {
if (strcasecmp(nfshost
, *np
) == 0)
if (cp
= index(*np
, '.')) {
if (strcasecmp(nfshost
, *np
) == 0)
* xdr routines for mount rpc's
return (xdr_string(xdrsp
, &dirp
, RPCMNT_PATHLEN
));