blob: 1b1d2a2dc22f357136c13ee640a40cbf3c970a9d [file] [log] [blame] [raw]
Always try external mount programs at first, unless '-i' is specified or a
type is already fixed from program name.
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
@@ -62,6 +62,8 @@
#include "mntopts.h"
#include "pathnames.h"
+#define DEFAULT_FS_TYPE "ufs"
+
/* `meta' options */
#define MOUNT_META_OPTION_FSTAB "fstab"
#define MOUNT_META_OPTION_CURRENT "current"
@@ -82,7 +84,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 +170,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 +246,27 @@
struct statfs *mntbuf;
int all, ch, i, init_flags, late, failok, mntsize, rval, have_fstab, ro;
int onlylate;
+ int internal_only, fixed_type;
char *cp, *ep, *options;
+ char *argv0;
all = init_flags = late = onlylate = 0;
ro = 0;
options = NULL;
vfslist = NULL;
- vfstype = "ufs";
- while ((ch = getopt(argc, argv, "adF:fLlno:prt:uvw")) != -1)
+ argv0 = strrchr(argv[0], '/');
+ if(argv0) argv0++; else argv0 = argv[0];
+ vfstype = strchr(argv0, '.') ? : strchr(argv0, '_');
+ if(vfstype) {
+ vfstype++;
+ internal_only = 1;
+ fixed_type = 1;
+ } else {
+ vfstype = DEFAULT_FS_TYPE;
+ internal_only = 0;
+ fixed_type = 0;
+ }
+ while ((ch = getopt(argc, argv, "adF:fiLlno:prt:uvw")) != -1)
switch (ch) {
case 'a':
all = 1;
@@ -268,6 +280,9 @@
case 'f':
init_flags |= MNT_FORCE;
break;
+ case 'i':
+ internal_only = 1;
+ break;
case 'L':
onlylate = 1;
late = 1;
@@ -296,6 +311,9 @@
case 't':
if (vfslist != NULL)
errx(1, "only one -t option may be specified");
+ if(fixed_type && strcmp(vfstype, optarg)) {
+ errx(1, "file system type must be '%s'", vfstype);
+ }
vfslist = makevfslist(optarg);
vfstype = optarg;
break;
@@ -351,7 +369,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 +430,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 +442,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 +470,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 +569,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 +610,8 @@
}
/* Construct the name of the appropriate mount command */
- (void)snprintf(execname, sizeof(execname), "mount_%s", vfstype);
+ if(internal_only) strcpy(execname, "mount");
+ else snprintf(execname, sizeof(execname), "mount.%s", vfstype);
mnt_argv.c = -1;
append_arg(&mnt_argv, execname);
@@ -604,8 +624,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 +637,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 +908,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);
}