+
+char *
+getmntname(name, what, type)
+ char *name;
+ mntwhat what;
+ int *type;
+{
+ struct statfs *mntbuf;
+ int i, mntsize;
+
+ if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
+ warn("getmntinfo");
+ return (NULL);
+ }
+ for (i = 0; i < mntsize; i++) {
+ if ((what == MNTON) && !strcmp(mntbuf[i].f_mntfromname, name)) {
+ if (type)
+ *type = mntbuf[i].f_type;
+ return (mntbuf[i].f_mntonname);
+ }
+ if ((what == MNTFROM) && !strcmp(mntbuf[i].f_mntonname, name)) {
+ if (type)
+ *type = mntbuf[i].f_type;
+ return (mntbuf[i].f_mntfromname);
+ }
+ }
+ return (NULL);
+}
+
+static enum { IN_LIST, NOT_IN_LIST } which;
+
+int
+selected(type)
+ int type;
+{
+ int *av;
+
+ /* If no type specified, it's always selected. */
+ if (typelist == NULL)
+ return (1);
+ for (av = typelist; *av != NULL; ++av)
+ if (type == *typelist)
+ return (which == IN_LIST ? 1 : 0);
+ return (which == IN_LIST ? 0 : 1);
+}
+
+void
+maketypelist(fslist)
+ char *fslist;
+{
+ int *av, i;
+ char *nextcp;
+
+ if ((fslist == NULL) || (fslist[0] == '\0'))
+ errx(1, "empty type list");
+
+ /*
+ * XXX
+ * Note: the syntax is "noxxx,yyy" for no xxx's and
+ * no yyy's, not the more intuitive "noyyy,noyyy".
+ */
+ if (fslist[0] == 'n' && fslist[1] == 'o') {
+ fslist += 2;
+ which = NOT_IN_LIST;
+ } else
+ which = IN_LIST;
+
+ /* Count the number of types. */
+ for (i = 0, nextcp = fslist; *nextcp != NULL; ++nextcp)
+ if (*nextcp == ',')
+ i++;
+
+ /* Build an array of that many types. */
+ if ((av = typelist = malloc((i + 2) * sizeof(int))) == NULL)
+ err(1, NULL);
+ for (i = 0; fslist != NULL; fslist = nextcp, ++i) {
+ if ((nextcp = strchr(fslist, ',')) != NULL)
+ *nextcp++ = '\0';
+ av[i] = fsnametotype(fslist);
+ if (av[i] == MOUNT_NONE)
+ errx(1, "%s: unknown mount type", fslist);
+ }
+ /* Terminate the array. */
+ av[i++] = MOUNT_NONE;
+}
+
+int
+fsnametotype(name)
+ char *name;
+{
+ static char const *namelist[] = INITMOUNTNAMES;
+ char const **cp;
+
+ for (cp = namelist; *cp; ++cp)
+ if (strcmp(name, *cp) == 0)
+ return (cp - namelist);
+ return (MOUNT_NONE);
+}
+
+int
+namematch(hp)
+ struct hostent *hp;
+{
+ char *cp, **np;
+
+ if ((hp == NULL) || (nfshost == NULL))
+ return (1);
+
+ if (strcasecmp(nfshost, hp->h_name) == 0)
+ return (1);
+
+ if ((cp = strchr(hp->h_name, '.')) != NULL) {
+ *cp = '\0';
+ if (strcasecmp(nfshost, hp->h_name) == 0)
+ return (1);
+ }
+ for (np = hp->h_aliases; *np; np++) {
+ if (strcasecmp(nfshost, *np) == 0)
+ return (1);
+ if ((cp = strchr(*np, '.')) != NULL) {
+ *cp = '\0';
+ if (strcasecmp(nfshost, *np) == 0)
+ return (1);
+ }
+ }
+ return (0);
+}
+
+/*
+ * xdr routines for mount rpc's
+ */
+int
+xdr_dir(xdrsp, dirp)
+ XDR *xdrsp;
+ char *dirp;
+{
+ return (xdr_string(xdrsp, &dirp, RPCMNT_PATHLEN));
+}
+
+void
+usage()
+{
+ (void)fprintf(stderr,
+ "usage: %s\n %s\n",
+ "umount [-fv] [-t fstypelist] special | node",
+ "umount -a[fv] [-h host] [-t fstypelist]");
+ exit(1);
+}