@@ -1259,6 +1259,10 @@ struct btrfs_ioctl_defrag_range_args {
};
+struct btrfs_ioctl_fs_label_args {
+ char label[BTRFS_LABEL_SIZE];
+};
+
/*
* inode items have the data typically returned from stat and store other
* info about object characteristics. There is one for every file and
dir in
@@ -268,6 +268,40 @@ static int btrfs_ioctl_getversion(struct file
*file, int __user *arg)
return put_user(inode->i_generation, arg);
}
+static int btrfs_ioctl_fs_setlabel(struct btrfs_root *root, void __user
*arg)
+{
+ struct btrfs_super_block *super_block = &(root->fs_info->super_copy);
+ struct btrfs_ioctl_fs_label_args *label_args;
+ struct btrfs_trans_handle *trans;
+ int ret;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ if (btrfs_root_readonly(root))
+ return -EROFS;
+
+ label_args = memdup_user(arg, sizeof(*label_args));
+ if (IS_ERR(label_args))
+ return PTR_ERR(label_args);
+
+ label_args->label[BTRFS_LABEL_SIZE - 1] = '\0';
+
+ mutex_lock(&root->fs_info->volume_mutex);
+ trans = btrfs_start_transaction(root, 0);
+ if (IS_ERR(trans)) {
+ ret = PTR_ERR(trans);
+ goto out_unlock;
+ }
+ strcpy(super_block->label, label_args->label);
+ btrfs_end_transaction(trans, root);
+
+out_unlock:
+ mutex_unlock(&root->fs_info->volume_mutex);
+ kfree(label_args);
+ return 0;
+}
+
static noinline int btrfs_ioctl_fitrim(struct file *file, void __user
*arg)
{
struct btrfs_root *root = fdentry(file)->d_sb->s_fs_info;
@@ -2876,6 +2910,8 @@ long btrfs_ioctl(struct file *file, unsigned int
return btrfs_ioctl_fs_info(root, argp);
case BTRFS_IOC_DEV_INFO:
return btrfs_ioctl_dev_info(root, argp);
+ case BTRFS_IOC_FS_SETLABEL:
+ return btrfs_ioctl_fs_setlabel(root, argp);
case BTRFS_IOC_BALANCE:
return btrfs_balance(root->fs_info->dev_root);
case BTRFS_IOC_CLONE:
@@ -201,6 +201,8 @@ struct btrfs_ioctl_space_args {
struct btrfs_ioctl_vol_args)
#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \
struct btrfs_ioctl_vol_args)
+#define BTRFS_IOC_FS_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 5, \
+ struct btrfs_ioctl_fs_label_args)
/* trans start and trans end are dangerous, and only for
* use by applications that know how to avoid the
* resulting deadlocks
Thanks again for your nice comments! The wiki update is in progress. Btw, is it make sense to improve the "struct btrfs_ioctl_fs_info_args" to retrieve the label info through BTRFS_IOC_FS_INFO? Would you please review the revised version? Signed-off-by: Jie Liu <jeff.liu@oracle.com> --- fs/btrfs/ctree.h | 4 ++++ fs/btrfs/ioctl.c | 36 ++++++++++++++++++++++++++++++++++++ fs/btrfs/ioctl.h | 2 ++ 3 files changed, 42 insertions(+), 0 deletions(-)