]> git.proxmox.com Git - mirror_zfs.git/blobdiff - cmd/mount_zfs/mount_zfs.c
cstyle: Resolve C style issues
[mirror_zfs.git] / cmd / mount_zfs / mount_zfs.c
index fd685faaa286574bb901a97d5b3d397578d4c500..82fa67c932d48f14e11fe0456b4e9b607efaaef0 100644 (file)
@@ -61,6 +61,10 @@ static const option_map_t option_map[] = {
        { MNTOPT_SYNC,          MS_SYNCHRONOUS, ZS_COMMENT      },
        { MNTOPT_USER,          MS_USERS,       ZS_COMMENT      },
        { MNTOPT_USERS,         MS_USERS,       ZS_COMMENT      },
+       /* acl flags passed with util-linux-2.24 mount command */
+       { MNTOPT_ACL,           MS_POSIXACL,    ZS_COMMENT      },
+       { MNTOPT_NOACL,         MS_COMMENT,     ZS_COMMENT      },
+       { MNTOPT_POSIXACL,      MS_POSIXACL,    ZS_COMMENT      },
 #ifdef MS_NOATIME
        { MNTOPT_NOATIME,       MS_NOATIME,     ZS_COMMENT      },
 #endif
@@ -211,24 +215,64 @@ out:
 }
 
 /*
- * If a file or directory in your current working directory is named
- * 'dataset' then mount(8) will prepend your current working directory
- * to dataset.  The is no way to prevent this behavior so we simply
- * check for it and strip the prepended patch when it is added.
+ * Return the pool/dataset to mount given the name passed to mount.  This
+ * is expected to be of the form pool/dataset, however may also refer to
+ * a block device if that device contains a valid zfs label.
  */
 static char *
 parse_dataset(char *dataset)
 {
        char cwd[PATH_MAX];
+       struct stat64 statbuf;
+       int error;
        int len;
 
+       /*
+        * We expect a pool/dataset to be provided, however if we're
+        * given a device which is a member of a zpool we attempt to
+        * extract the pool name stored in the label.  Given the pool
+        * name we can mount the root dataset.
+        */
+       error = stat64(dataset, &statbuf);
+       if (error == 0) {
+               nvlist_t *config;
+               char *name;
+               int fd;
+
+               fd = open(dataset, O_RDONLY);
+               if (fd < 0)
+                       goto out;
+
+               error = zpool_read_label(fd, &config);
+               (void) close(fd);
+               if (error)
+                       goto out;
+
+               error = nvlist_lookup_string(config,
+                   ZPOOL_CONFIG_POOL_NAME, &name);
+               if (error) {
+                       nvlist_free(config);
+               } else {
+                       dataset = strdup(name);
+                       nvlist_free(config);
+                       return (dataset);
+               }
+       }
+out:
+       /*
+        * If a file or directory in your current working directory is
+        * named 'dataset' then mount(8) will prepend your current working
+        * directory to the dataset.  There is no way to prevent this
+        * behavior so we simply check for it and strip the prepended
+        * patch when it is added.
+        */
        if (getcwd(cwd, PATH_MAX) == NULL)
                return (dataset);
 
        len = strlen(cwd);
 
        /* Do not add one when cwd already ends in a trailing '/' */
-       if (!strncmp(cwd, dataset, len))
+       if (strncmp(cwd, dataset, len) == 0)
                return (dataset + len + (cwd[len-1] != '/'));
 
        return (dataset);
@@ -380,7 +424,7 @@ main(int argc, char **argv)
                        return (MOUNT_SYSERR);
                case ENOENT:
                        (void) fprintf(stderr, gettext("filesystem '%s' "
-                           "cannot be mounted of due invalid option "
+                           "cannot be mounted due to invalid option "
                            "'%s'.\n"), dataset, badopt);
                        (void) fprintf(stderr, gettext("Use the '-s' option "
                            "to ignore the bad mount option.\n"));
@@ -400,11 +444,11 @@ main(int argc, char **argv)
         * done until zfs is added to the default selinux policy configuration
         * as a known filesystem type which supports xattrs.
         */
-        if (is_selinux_enabled() && !(zfsflags & ZS_NOCONTEXT)) {
-                (void) strlcat(mntopts, ",context=\"system_u:"
-                    "object_r:file_t:s0\"", sizeof (mntopts));
-                (void) strlcat(mtabopt, ",context=\"system_u:"
-                    "object_r:file_t:s0\"", sizeof (mtabopt));
+       if (is_selinux_enabled() && !(zfsflags & ZS_NOCONTEXT)) {
+               (void) strlcat(mntopts, ",context=\"system_u:"
+                   "object_r:file_t:s0\"", sizeof (mntopts));
+               (void) strlcat(mtabopt, ",context=\"system_u:"
+                   "object_r:file_t:s0\"", sizeof (mtabopt));
        }
 #endif /* HAVE_LIBSELINUX */
 
@@ -457,12 +501,12 @@ main(int argc, char **argv)
         * using zfs as your root file system both rc.sysinit/umountroot and
         * systemd depend on 'mount -o remount <mountpoint>' to work.
         */
-       if (zfsutil && !strcmp(legacy, ZFS_MOUNTPOINT_LEGACY)) {
+       if (zfsutil && (strcmp(legacy, ZFS_MOUNTPOINT_LEGACY) == 0)) {
                (void) fprintf(stderr, gettext(
                    "filesystem '%s' cannot be mounted using 'zfs mount'.\n"
                    "Use 'zfs set mountpoint=%s' or 'mount -t zfs %s %s'.\n"
                    "See zfs(8) for more information.\n"),
-                  dataset, mntpoint, dataset, mntpoint);
+                   dataset, mntpoint, dataset, mntpoint);
                return (MOUNT_USAGE);
        }
 
@@ -488,7 +532,7 @@ main(int argc, char **argv)
                        case EBUSY:
                                (void) fprintf(stderr, gettext("filesystem "
                                    "'%s' is already mounted\n"), dataset);
-                               return (MOUNT_SYSERR);
+                               return (MOUNT_BUSY);
                        default:
                                (void) fprintf(stderr, gettext("filesystem "
                                    "'%s' can not be mounted due to error "