* Copyright (c) 1980, 1989 The Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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
"@(#) Copyright (c) 1980, 1989 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)umount.c 5.16 (Berkeley) 6/3/91";
#include <sys/socketvar.h>
#include <rpc/pmap_clnt.h>
#include <rpc/pmap_prot.h>
int vflag
, all
, errs
, fake
;
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
= (char *)malloc((unsigned)strlen(fs
->fs_file
) + 1);
cp
= (char *)malloc((unsigned)strlen(fs
->fs_type
) + 1);
cp
= (char *)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 (getmntname(name
, MNTFROM
, &type
) != 0)
else if ((mntpt
= getmntname(name
, MNTON
, &type
)) == 0) {
fprintf(stderr
, "%s: not currently mounted\n", name
);
} else if ((stbuf
.st_mode
& S_IFMT
) == S_IFBLK
) {
if ((mntpt
= getmntname(name
, MNTON
, &type
)) == 0) {
fprintf(stderr
, "%s: not currently mounted\n", name
);
} else if ((stbuf
.st_mode
& S_IFMT
) == S_IFDIR
) {
if (getmntname(mntpt
, MNTFROM
, &type
) == 0) {
fprintf(stderr
, "%s: not currently mounted\n", name
);
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
);
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
, "msdos") == 0)
else if (strcmp(fslist
, "isofs") == 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
));