+
+ if (argc == 1 && updateflg) {
+ if ((mntbuf = getmntpt(*argv)) == NULL) {
+ fprintf(stderr,
+ "mount: unknown special file or file system %s.\n",
+ *argv);
+ exit(1);
+ }
+ mnttype = mntbuf->f_type;
+ if (!strcmp(mntbuf->f_mntfromname, "root_device")) {
+ fs = getfsfile("/");
+ strcpy(mntbuf->f_mntfromname, fs->fs_spec);
+ }
+ ret = mountfs(mntbuf->f_mntfromname, mntbuf->f_mntonname,
+ updateflg, type, options, (char *)NULL);
+ } else if (argc == 1) {
+ if (!(fs = getfsfile(*argv)) && !(fs = getfsspec(*argv))) {
+ fprintf(stderr,
+ "mount: unknown special file or file system %s.\n",
+ *argv);
+ exit(1);
+ }
+ if (BADTYPE(fs->fs_type)) {
+ fprintf(stderr,
+ "mount: %s has unknown file system type.\n", *argv);
+ exit(1);
+ }
+ mnttype = getmnttype(fs->fs_vfstype);
+ ret = mountfs(fs->fs_spec, fs->fs_file, updateflg,
+ type, options, fs->fs_mntops);
+ } else if (argc != 2) {
+ usage();
+ ret = 1;
+ } else {
+ /*
+ * If -t flag has not been specified, and spec
+ * contains either a ':' or a '@' then assume that
+ * an NFS filesystem is being specified ala Sun.
+ */
+ if (vfslist == (char **)0 &&
+ (index(argv[0], ':') || index(argv[0], '@')))
+ mnttype = MOUNT_NFS;
+ ret = mountfs(argv[0], argv[1], updateflg, type, options,
+ (char *)NULL);
+ }
+ if ((pidfile = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
+ pid = 0;
+ fscanf(pidfile, "%d", &pid);
+ fclose(pidfile);
+ if (pid > 0)
+ kill(pid, SIGHUP);
+ }
+ exit (ret);
+}
+
+mountfs(spec, name, flags, type, options, mntopts)
+ char *spec, *name, *type, *options, *mntopts;
+ int flags;
+{
+ extern int errno;
+ union wait status;
+ pid_t pid;
+ int argc, i;
+ struct ufs_args args;
+ struct nfs_args nfsargs;
+ char *argp, *argv[50];
+ char execname[MAXPATHLEN + 1], flagval[12];
+
+ nfsargs = nfsdefargs;
+ if (mntopts)
+ getstdopts(mntopts, &flags);
+ if (options)
+ getstdopts(options, &flags);
+ if (type)
+ getstdopts(type, &flags);
+ switch (mnttype) {
+ case MOUNT_UFS:
+ if (mntopts)
+ getufsopts(mntopts, &flags);
+ if (options)
+ getufsopts(options, &flags);
+ args.fspec = spec;
+ args.exroot = DEFAULT_ROOTUID;
+ if (flags & MNT_RDONLY)
+ args.exflags = MNT_EXRDONLY;
+ else
+ args.exflags = 0;
+ argp = (caddr_t)&args;
+ break;
+
+#ifdef NFS
+ case MOUNT_NFS:
+ retrycnt = DEF_RETRY;
+ if (mntopts)
+ getnfsopts(mntopts, &nfsargs, &opflags, &retrycnt);
+ if (options)
+ getnfsopts(options, &nfsargs, &opflags, &retrycnt);
+ if (argp = getnfsargs(spec, &nfsargs))
+ break;
+ return (1);
+#endif /* NFS */
+
+ case MOUNT_MFS:
+ default:
+ argv[0] = mntname;
+ argc = 1;
+ if (flags) {
+ argv[argc++] = "-F";
+ sprintf(flagval, "%d", flags);
+ argv[argc++] = flagval;
+ }
+ if (mntopts)
+ argc += getexecopts(mntopts, &argv[argc]);
+ if (options)
+ argc += getexecopts(options, &argv[argc]);
+ argv[argc++] = spec;
+ argv[argc++] = name;
+ argv[argc++] = NULL;
+ sprintf(execname, "%s/mount_%s", _PATH_EXECDIR, mntname);
+ if (verbose) {
+ (void)printf("exec: %s", execname);
+ for (i = 1; i < argc - 1; i++)
+ (void)printf(" %s", argv[i]);
+ (void)printf("\n");
+ }
+ if (fake)
+ break;
+ if (pid = vfork()) {
+ if (pid == -1) {
+ perror("mount: vfork starting file system");
+ return (1);
+ }
+ if (waitpid(pid, &status, 0) != -1 &&
+ WIFEXITED(status) &&
+ WEXITSTATUS(status) != 0)
+ return (WEXITSTATUS(status));
+ spec = mntname;
+ goto out;
+ }
+ execve(execname, argv, envp);
+ fprintf(stderr, "mount: cannot exec %s for %s: ",
+ execname, name);
+ perror((char *)NULL);
+ exit (1);
+ /* NOTREACHED */
+
+ }
+ if (!fake && mount(mnttype, name, flags, argp)) {
+ if (opflags & ISBGRND)
+ exit(1);
+ fprintf(stderr, "%s on %s: ", spec, name);
+ switch (errno) {
+ case EMFILE:
+ fprintf(stderr, "Mount table full\n");
+ break;
+ case EINVAL:
+ if (flags & MNT_UPDATE)
+ fprintf(stderr, "Specified device does %s\n",
+ "not match mounted device");
+ else
+ fprintf(stderr, "Bogus super block\n");
+ break;
+ case EOPNOTSUPP:
+ fprintf(stderr, "Operation not supported\n");
+ break;
+ default:
+ perror((char *)NULL);
+ break;
+ }
+ return(1);
+ }
+
+out:
+ if (verbose)
+ prmount(spec, name, flags);
+
+ if (opflags & ISBGRND)