| Always try external mount programs at first, unless '-i' is specified. |
| Try 'mount.<fstype>' first, then 'mount_<fstype>'. |
| |
| diff -ru --exclude-from freebsd-src-diff-exclude-names /var/tmp/freebsd-10.3-src/usr/src/sbin/mount/mount.c freebsd-10.3/usr/src/sbin/mount/mount.c |
| --- /var/tmp/freebsd-10.3-src/usr/src/sbin/mount/mount.c 2016-03-25 09:10:18.000000000 +0800 |
| +++ freebsd-10.3/usr/src/sbin/mount/mount.c 2018-11-08 00:16:15.113636453 +0800 |
| @@ -82,7 +82,7 @@ |
| void mangle(char *, struct cpa *); |
| char *update_options(char *, char *, int); |
| int mountfs(const char *, const char *, const char *, |
| - int, const char *, const char *); |
| + int, const char *, const char *, int); |
| void remopt(char *, const char *); |
| void prmount(struct statfs *); |
| void putfsent(struct statfs *); |
| @@ -168,15 +168,12 @@ |
| switch (pid = fork()) { |
| case -1: /* Error. */ |
| warn("fork"); |
| - exit (1); |
| + exit(1); |
| case 0: /* Child. */ |
| /* Go find an executable. */ |
| execvP(execname, _PATH_SYSPATH, argv); |
| if (errno == ENOENT) { |
| - warn("exec %s not found", execname); |
| - if (execname[0] != '/') { |
| - warnx("in path: %s", _PATH_SYSPATH); |
| - } |
| + exit(127); |
| } |
| exit(1); |
| default: /* Parent. */ |
| @@ -247,14 +244,15 @@ |
| struct statfs *mntbuf; |
| int all, ch, i, init_flags, late, failok, mntsize, rval, have_fstab, ro; |
| int onlylate; |
| + int internal_only; |
| char *cp, *ep, *options; |
| |
| - all = init_flags = late = onlylate = 0; |
| + all = init_flags = late = onlylate = internal_only = 0; |
| ro = 0; |
| options = NULL; |
| vfslist = NULL; |
| vfstype = "ufs"; |
| - while ((ch = getopt(argc, argv, "adF:fLlno:prt:uvw")) != -1) |
| + while ((ch = getopt(argc, argv, "adF:fiLlno:prt:uvw")) != -1) |
| switch (ch) { |
| case 'a': |
| all = 1; |
| @@ -268,6 +266,9 @@ |
| case 'f': |
| init_flags |= MNT_FORCE; |
| break; |
| + case 'i': |
| + internal_only = 1; |
| + break; |
| case 'L': |
| onlylate = 1; |
| late = 1; |
| @@ -351,7 +352,7 @@ |
| mntbuf->f_flags); |
| if (mountfs(fs->fs_vfstype, fs->fs_spec, |
| fs->fs_file, init_flags, options, |
| - fs->fs_mntops) && !failok) |
| + fs->fs_mntops, internal_only) && !failok) |
| rval = 1; |
| } |
| } else if (fstab_style) { |
| @@ -412,7 +413,8 @@ |
| mntbuf->f_flags); |
| } |
| rval = mountfs(mntbuf->f_fstypename, mntfromname, |
| - mntbuf->f_mntonname, init_flags, options, 0); |
| + mntbuf->f_mntonname, init_flags, options, 0, |
| + internal_only); |
| break; |
| } |
| if ((fs = getfsfile(*argv)) == NULL && |
| @@ -423,7 +425,7 @@ |
| errx(1, "%s has unknown file system type", |
| *argv); |
| rval = mountfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file, |
| - init_flags, options, fs->fs_mntops); |
| + init_flags, options, fs->fs_mntops, internal_only); |
| break; |
| case 2: |
| /* |
| @@ -451,8 +453,8 @@ |
| if (cp == ep) |
| vfstype = "nfs"; |
| } |
| - rval = mountfs(vfstype, |
| - argv[0], argv[1], init_flags, options, NULL); |
| + rval = mountfs(vfstype, argv[0], argv[1], init_flags, |
| + options, NULL, internal_only); |
| break; |
| default: |
| usage(); |
| @@ -550,7 +552,7 @@ |
| |
| int |
| mountfs(const char *vfstype, const char *spec, const char *name, int flags, |
| - const char *options, const char *mntopts) |
| + const char *options, const char *mntopts, int internal_only) |
| { |
| struct statfs sf; |
| int i, ret; |
| @@ -591,7 +593,7 @@ |
| } |
| |
| /* Construct the name of the appropriate mount command */ |
| - (void)snprintf(execname, sizeof(execname), "mount_%s", vfstype); |
| + (void)snprintf(execname, sizeof(execname), "mount.%s", vfstype); |
| |
| mnt_argv.c = -1; |
| append_arg(&mnt_argv, execname); |
| @@ -604,8 +606,8 @@ |
| append_arg(&mnt_argv, NULL); |
| |
| if (debug) { |
| - if (use_mountprog(vfstype)) |
| - printf("exec: %s", execname); |
| + if (!internal_only && use_mountprog(vfstype)) |
| + printf("should exec: %s", execname); |
| else |
| printf("mount -t %s", vfstype); |
| for (i = 1; i < mnt_argv.c; i++) |
| @@ -617,10 +619,18 @@ |
| return (0); |
| } |
| |
| - if (use_mountprog(vfstype)) { |
| - ret = exec_mountprog(name, execname, mnt_argv.a); |
| - } else { |
| + if(internal_only) { |
| ret = mount_fs(vfstype, mnt_argv.c, mnt_argv.a); |
| + } else { |
| + ret = exec_mountprog(name, execname, mnt_argv.a); |
| + if(ret == 127) { |
| + snprintf(execname, sizeof(execname), "mount_%s", vfstype); |
| + ret = exec_mountprog(name, execname, mnt_argv.a); |
| + if(ret == 127) { |
| + strcpy(execname, "mount"); |
| + ret = mount_fs(vfstype, mnt_argv.c, mnt_argv.a); |
| + } |
| + } |
| } |
| |
| free(optbuf); |
| @@ -880,9 +890,9 @@ |
| { |
| |
| (void)fprintf(stderr, "%s\n%s\n%s\n", |
| -"usage: mount [-adflpruvw] [-F fstab] [-o options] [-t ufs | external_type]", |
| -" mount [-dfpruvw] special | node", |
| -" mount [-dfpruvw] [-o options] [-t ufs | external_type] special node"); |
| +"usage: mount [-adfilpruvw] [-F fstab] [-o options] [-t ufs | external_type]", |
| +" mount [-dfipruvw] special | node", |
| +" mount [-dfipruvw] [-o options] [-t ufs | external_type] special node"); |
| exit(1); |
| } |
| |