* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)umount.c 5.9 (Berkeley) %G%";
#include <sys/socketvar.h>
#include <rpc/pmap_clnt.h>
#include <rpc/pmap_prot.h>
char *rindex(), *getmntname();
if (argc
> 0 && !strcmp(*argv
, "-v")) {
if (argc
> 0 && !strcmp(*argv
, "-a")) {
fprintf(stderr
, "Usage: umount [ -a ] [ -v ] [ dev ... ]\n");
if (umountfs(*argv
++) == 0)
struct fstab
*fs
, *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
);
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
)) == 0)
} else if ((stbuf
.st_mode
& S_IFMT
) == S_IFBLK
) {
if ((mntpt
= getmntname(name
, MNTON
)) == 0)
} else if ((stbuf
.st_mode
& S_IFMT
) == S_IFDIR
) {
if ((name
= getmntname(mntpt
, MNTFROM
)) == 0)
fprintf(stderr
, "%s: not a directory or special device\n",
if (unmount(mntpt
, MNT_NOFORCE
) < 0) {
fprintf(stderr
, "%s: Unmounted from %s\n", name
, mntpt
);
if ((delimp
= index(name
, '@')) != NULL
) {
if ((hp
= gethostbyname(hostp
)) != NULL
) {
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
);
if ((mntsize
= getmntinfo(&mntbuf
)) == 0) {
for (i
= 0; i
< mntsize
; i
++) {
if (what
== MNTON
&& !strcmp(mntbuf
[i
].f_mntfromname
, name
))
return (mntbuf
[i
].f_mntonname
);
if (what
== MNTFROM
&& !strcmp(mntbuf
[i
].f_mntonname
, name
))
return (mntbuf
[i
].f_mntfromname
);
fprintf(stderr
, "%s: not currently mounted\n", name
);
* xdr routines for mount rpc's
return (xdr_string(xdrsp
, &dirp
, RPCMNT_PATHLEN
));