X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=cmd%2Fmount_zfs%2Fmount_zfs.c;h=cd2731446684960954df7eeaa52eba55f5a6a617;hb=563103decdca7c06850ca0909e5c8f8b4b0c0fe5;hp=45c291e04ce000ab3d56d84d6da58d4c8d7b1a28;hpb=92e91da20839ee50536223bedf2ba4fb7d2fae71;p=zfs.git diff --git a/cmd/mount_zfs/mount_zfs.c b/cmd/mount_zfs/mount_zfs.c index 45c291e..cd27314 100644 --- a/cmd/mount_zfs/mount_zfs.c +++ b/cmd/mount_zfs/mount_zfs.c @@ -311,8 +311,9 @@ main(int argc, char **argv) char mntopts[MNT_LINE_MAX] = { '\0' }; char badopt[MNT_LINE_MAX] = { '\0' }; char mtabopt[MNT_LINE_MAX] = { '\0' }; - char *dataset, *mntpoint; - unsigned long mntflags = 0, zfsflags = 0, remount_ro = 0; + char mntpoint[PATH_MAX]; + char *dataset; + unsigned long mntflags = 0, zfsflags = 0, remount = 0; int sloppy = 0, fake = 0, verbose = 0, nomtab = 0, zfsutil = 0; int error, c; @@ -367,7 +368,14 @@ main(int argc, char **argv) } dataset = parse_dataset(argv[0]); - mntpoint = argv[1]; + + /* canonicalize the mount point */ + if (realpath(argv[1], mntpoint) == NULL) { + (void) fprintf(stderr, gettext("filesystem '%s' cannot be " + "mounted at '%s' due to canonicalization error %d.\n"), + dataset, argv[1], errno); + return (MOUNT_SYSERR); + } /* validate mount options and set mntflags */ error = parse_options(mntopts, &mntflags, &zfsflags, sloppy, @@ -417,11 +425,10 @@ main(int argc, char **argv) " mountopts: \"%s\"\n mtabopts: \"%s\"\n"), dataset, mntpoint, mntflags, zfsflags, mntopts, mtabopt); - if (mntflags & MS_REMOUNT) + if (mntflags & MS_REMOUNT) { nomtab = 1; - - if ((mntflags & MS_REMOUNT) && (mntflags & MS_RDONLY)) - remount_ro = 1; + remount = 1; + } if (zfsflags & ZS_ZFSUTIL) zfsutil = 1; @@ -454,9 +461,10 @@ main(int argc, char **argv) * we differentiate the two cases using the 'zfsutil' mount option. * This mount option should only be supplied by the 'zfs mount' util. * - * The only exception to the above rule is '-o remount,ro'. This is - * always allowed for non-legacy datasets for rc.sysinit/umountroot - * to safely remount the root filesystem and flush its cache. + * The only exception to the above rule is '-o remount' which is + * always allowed for non-legacy datasets. This is done because when + * using zfs as your root file system both rc.sysinit/umountroot and + * systemd depend on 'mount -o remount ' to work. */ if (zfsutil && !strcmp(legacy, ZFS_MOUNTPOINT_LEGACY)) { (void) fprintf(stderr, gettext( @@ -467,7 +475,8 @@ main(int argc, char **argv) return (MOUNT_USAGE); } - if (!zfsutil && strcmp(legacy, ZFS_MOUNTPOINT_LEGACY) && !remount_ro) { + if (!zfsutil && !(remount || fake) && + strcmp(legacy, ZFS_MOUNTPOINT_LEGACY)) { (void) fprintf(stderr, gettext( "filesystem '%s' cannot be mounted using 'mount'.\n" "Use 'zfs set mountpoint=%s' or 'zfs mount %s'.\n"