* 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.6 (Berkeley) %G%";
#include <sys/socketvar.h>
#include <rpc/pmap_clnt.h>
#include <rpc/pmap_prot.h>
char *rindex(), *getmntinfo();
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()) == 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(sizeof (*fs
));
cp
= malloc(strlen(fs
->fs_file
) + 1);
cp
= malloc(strlen(fs
->fs_type
) + 1);
cp
= malloc(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
= getmntinfo(name
, MNTON
)) == 0)
} else if ((stbuf
.st_mode
& IFMT
) == IFBLK
) {
if ((mntpt
= getmntinfo(name
, MNTON
)) == 0)
} else if ((stbuf
.st_mode
& IFMT
) == IFDIR
) {
if ((name
= getmntinfo(mntpt
, MNTFROM
)) == 0)
fprintf(stderr
, "%s: not a directory or special device\n");
if (umount(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
);
struct statfs statfsbuf
, *mntbuf
;
if ((mntsize
= getfsstat(0, 0)) < 0) {
i
= (mntsize
+ 1) * sizeof(struct statfs
);
if ((mntbuf
= (struct statfs
*)malloc(i
)) == 0) {
"no space for umount table buffer\n");
if ((mntsize
= getfsstat(mntbuf
, i
)) < 0) {
} while (i
== mntsize
* sizeof(struct statfs
));
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
));