umount.c (91a81678) umount.c (a69497d7)
1/*-
2 * Copyright (c) 1980, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 45 unchanged lines hidden (view full) ---

54
55#include <err.h>
56#include <fstab.h>
57#include <stdio.h>
58#include <stdlib.h>
59#include <string.h>
60#include <unistd.h>
61
1/*-
2 * Copyright (c) 1980, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 45 unchanged lines hidden (view full) ---

54
55#include <err.h>
56#include <fstab.h>
57#include <stdio.h>
58#include <stdlib.h>
59#include <string.h>
60#include <unistd.h>
61
62#include "mounttab.h"
63
62#define ISDOT(x) ((x)[0] == '.' && (x)[1] == '\0')
63#define ISDOTDOT(x) ((x)[0] == '.' && (x)[1] == '.' && (x)[2] == '\0')
64
65typedef enum { MNTON, MNTFROM, NOTHING } mntwhat;
66typedef enum { MARK, UNMARK, NAME, COUNT, FREE } dowhat;
67
64#define ISDOT(x) ((x)[0] == '.' && (x)[1] == '\0')
65#define ISDOTDOT(x) ((x)[0] == '.' && (x)[1] == '.' && (x)[2] == '\0')
66
67typedef enum { MNTON, MNTFROM, NOTHING } mntwhat;
68typedef enum { MARK, UNMARK, NAME, COUNT, FREE } dowhat;
69
70struct mtablist *mtabhead;
68int fflag, vflag;
69char *nfshost;
70
71void checkmntlist (char *, char **, char **, char **);
72int checkvfsname (const char *, char **);
73char *getmntname (const char *, const char *,
74 mntwhat, char **, dowhat);
75char *getrealname(char *, char *resolved_path);
76char **makevfslist (const char *);
77size_t mntinfo (struct statfs **);
78int namematch (struct hostent *);
71int fflag, vflag;
72char *nfshost;
73
74void checkmntlist (char *, char **, char **, char **);
75int checkvfsname (const char *, char **);
76char *getmntname (const char *, const char *,
77 mntwhat, char **, dowhat);
78char *getrealname(char *, char *resolved_path);
79char **makevfslist (const char *);
80size_t mntinfo (struct statfs **);
81int namematch (struct hostent *);
79int selected (int);
80int umountall (char **);
81int umountfs (char *, char **);
82void usage (void);
83int xdr_dir (XDR *, char *);
84
85int
86main(int argc, char *argv[])
87{

--- 147 unchanged lines hidden (view full) ---

235 return (0);
236}
237
238int
239umountfs(char *name, char **typelist)
240{
241 enum clnt_stat clnt_stat;
242 struct hostent *hp;
82int umountall (char **);
83int umountfs (char *, char **);
84void usage (void);
85int xdr_dir (XDR *, char *);
86
87int
88main(int argc, char *argv[])
89{

--- 147 unchanged lines hidden (view full) ---

237 return (0);
238}
239
240int
241umountfs(char *name, char **typelist)
242{
243 enum clnt_stat clnt_stat;
244 struct hostent *hp;
245 struct mtablist *mtab;
243 struct sockaddr_in saddr;
244 struct timeval pertry, try;
245 CLIENT *clp;
246 size_t len;
247 int so, speclen, do_rpc;
248 char *mntonname, *mntfromname;
249 char *mntfromnamerev;
250 char *nfsdirname, *orignfsdirname;
251 char *resolved, realname[MAXPATHLEN];
252 char *type, *delimp, *hostp, *origname;
253
254 len = 0;
246 struct sockaddr_in saddr;
247 struct timeval pertry, try;
248 CLIENT *clp;
249 size_t len;
250 int so, speclen, do_rpc;
251 char *mntonname, *mntfromname;
252 char *mntfromnamerev;
253 char *nfsdirname, *orignfsdirname;
254 char *resolved, realname[MAXPATHLEN];
255 char *type, *delimp, *hostp, *origname;
256
257 len = 0;
258 mtab = NULL;
255 mntfromname = mntonname = delimp = hostp = orignfsdirname = NULL;
256
257 /*
258 * 1. Check if the name exists in the mounttable.
259 */
260 (void)checkmntlist(name, &mntfromname, &mntonname, &type);
261 /*
262 * 2. Remove trailing slashes if there are any. After that

--- 160 unchanged lines hidden (view full) ---

423 try.tv_sec = 20;
424 try.tv_usec = 0;
425 clnt_stat = clnt_call(clp, RPCMNT_UMOUNT, xdr_dir,
426 nfsdirname, xdr_void, (caddr_t)0, try);
427 if (clnt_stat != RPC_SUCCESS) {
428 clnt_perror(clp, "Bad MNT RPC");
429 return (1);
430 }
259 mntfromname = mntonname = delimp = hostp = orignfsdirname = NULL;
260
261 /*
262 * 1. Check if the name exists in the mounttable.
263 */
264 (void)checkmntlist(name, &mntfromname, &mntonname, &type);
265 /*
266 * 2. Remove trailing slashes if there are any. After that

--- 160 unchanged lines hidden (view full) ---

427 try.tv_sec = 20;
428 try.tv_usec = 0;
429 clnt_stat = clnt_call(clp, RPCMNT_UMOUNT, xdr_dir,
430 nfsdirname, xdr_void, (caddr_t)0, try);
431 if (clnt_stat != RPC_SUCCESS) {
432 clnt_perror(clp, "Bad MNT RPC");
433 return (1);
434 }
435 /*
436 * Remove the unmounted entry from /var/db/mounttab.
437 */
438 if (read_mtab(mtab)) {
439 mtab = mtabhead;
440 clean_mtab(hostp, nfsdirname);
441 if(!write_mtab())
442 warnx("cannot remove entry %s:%s",
443 hostp, nfsdirname);
444 free_mtab();
445 }
431 free(orignfsdirname);
432 auth_destroy(clp->cl_auth);
433 clnt_destroy(clp);
434 }
435 return (0);
436}
437
438char *

--- 89 unchanged lines hidden (view full) ---

528 }
529 if (count <= 1)
530 return (mntbuf[i].f_mntonname);
531 else
532 return (NULL);
533 case FREE:
534 free(mntbuf);
535 free(mntcheck);
446 free(orignfsdirname);
447 auth_destroy(clp->cl_auth);
448 clnt_destroy(clp);
449 }
450 return (0);
451}
452
453char *

--- 89 unchanged lines hidden (view full) ---

543 }
544 if (count <= 1)
545 return (mntbuf[i].f_mntonname);
546 else
547 return (NULL);
548 case FREE:
549 free(mntbuf);
550 free(mntcheck);
551 free(mntcount);
536 return (NULL);
537 default:
538 return (NULL);
539 }
540}
541
542int
543namematch(struct hostent *hp)

--- 38 unchanged lines hidden (view full) ---

582
583size_t
584mntinfo(struct statfs **mntbuf)
585{
586 static struct statfs *origbuf;
587 size_t bufsize;
588 int mntsize;
589
552 return (NULL);
553 default:
554 return (NULL);
555 }
556}
557
558int
559namematch(struct hostent *hp)

--- 38 unchanged lines hidden (view full) ---

598
599size_t
600mntinfo(struct statfs **mntbuf)
601{
602 static struct statfs *origbuf;
603 size_t bufsize;
604 int mntsize;
605
590 mntsize = getfsstat(NULL, 0l, MNT_NOWAIT);
606 mntsize = getfsstat(NULL, 0, MNT_NOWAIT);
591 if (mntsize <= 0)
592 return (0);
593 bufsize = (mntsize + 1) * sizeof(struct statfs);
594 if ((origbuf = malloc(bufsize)) == NULL)
595 err(1, "malloc");
596 mntsize = getfsstat(origbuf, (long)bufsize, MNT_NOWAIT);
597 *mntbuf = origbuf;
598 return (mntsize);

--- 82 unchanged lines hidden ---
607 if (mntsize <= 0)
608 return (0);
609 bufsize = (mntsize + 1) * sizeof(struct statfs);
610 if ((origbuf = malloc(bufsize)) == NULL)
611 err(1, "malloc");
612 mntsize = getfsstat(origbuf, (long)bufsize, MNT_NOWAIT);
613 *mntbuf = origbuf;
614 return (mntsize);

--- 82 unchanged lines hidden ---