diff options
author | jeff.liu <jeff.liu@oracle.com> | 2013-01-04 21:48:08 -0500 |
---|---|---|
committer | Josef Bacik <jbacik@fusionio.com> | 2013-02-20 12:59:59 -0500 |
commit | a8bfd4abea3da0e28f215e2a2b8c2f1ca27ebe80 (patch) | |
tree | 949b78c187f77101b366ca3f189ea25e3d20c870 /fs/btrfs | |
parent | 867ab667e74377160c4a683375ee5b8bf8801724 (diff) |
Btrfs: set/change the label of a mounted file system
With this new ioctl(2) BTRFS_IOC_SET_FSLABEL, we can set/change the label of a mounted file system.
Signed-off-by: Jie Liu <jeff.liu@oracle.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Miao Xie <miaox@cn.fujitsu.com>
Reviewed-by: Goffredo Baroncelli <kreijack@inwind.it>
Reviewed-by: David Sterba <dsterba@suse.cz>
Reviewed-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/ioctl.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index fcc15a6804a9..0f68729f261e 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -3936,6 +3936,46 @@ static int btrfs_ioctl_get_fslabel(struct file *file, void __user *arg) | |||
3936 | return ret ? -EFAULT : 0; | 3936 | return ret ? -EFAULT : 0; |
3937 | } | 3937 | } |
3938 | 3938 | ||
3939 | static int btrfs_ioctl_set_fslabel(struct file *file, void __user *arg) | ||
3940 | { | ||
3941 | struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root; | ||
3942 | struct btrfs_super_block *super_block = root->fs_info->super_copy; | ||
3943 | struct btrfs_trans_handle *trans; | ||
3944 | char label[BTRFS_LABEL_SIZE]; | ||
3945 | int ret; | ||
3946 | |||
3947 | if (!capable(CAP_SYS_ADMIN)) | ||
3948 | return -EPERM; | ||
3949 | |||
3950 | if (copy_from_user(label, arg, sizeof(label))) | ||
3951 | return -EFAULT; | ||
3952 | |||
3953 | if (strnlen(label, BTRFS_LABEL_SIZE) == BTRFS_LABEL_SIZE) { | ||
3954 | pr_err("btrfs: unable to set label with more than %d bytes\n", | ||
3955 | BTRFS_LABEL_SIZE - 1); | ||
3956 | return -EINVAL; | ||
3957 | } | ||
3958 | |||
3959 | ret = mnt_want_write_file(file); | ||
3960 | if (ret) | ||
3961 | return ret; | ||
3962 | |||
3963 | mutex_lock(&root->fs_info->volume_mutex); | ||
3964 | trans = btrfs_start_transaction(root, 0); | ||
3965 | if (IS_ERR(trans)) { | ||
3966 | ret = PTR_ERR(trans); | ||
3967 | goto out_unlock; | ||
3968 | } | ||
3969 | |||
3970 | strcpy(super_block->label, label); | ||
3971 | ret = btrfs_end_transaction(trans, root); | ||
3972 | |||
3973 | out_unlock: | ||
3974 | mutex_unlock(&root->fs_info->volume_mutex); | ||
3975 | mnt_drop_write_file(file); | ||
3976 | return ret; | ||
3977 | } | ||
3978 | |||
3939 | long btrfs_ioctl(struct file *file, unsigned int | 3979 | long btrfs_ioctl(struct file *file, unsigned int |
3940 | cmd, unsigned long arg) | 3980 | cmd, unsigned long arg) |
3941 | { | 3981 | { |
@@ -4038,6 +4078,8 @@ long btrfs_ioctl(struct file *file, unsigned int | |||
4038 | return btrfs_ioctl_dev_replace(root, argp); | 4078 | return btrfs_ioctl_dev_replace(root, argp); |
4039 | case BTRFS_IOC_GET_FSLABEL: | 4079 | case BTRFS_IOC_GET_FSLABEL: |
4040 | return btrfs_ioctl_get_fslabel(file, argp); | 4080 | return btrfs_ioctl_get_fslabel(file, argp); |
4081 | case BTRFS_IOC_SET_FSLABEL: | ||
4082 | return btrfs_ioctl_set_fslabel(file, argp); | ||
4041 | } | 4083 | } |
4042 | 4084 | ||
4043 | return -ENOTTY; | 4085 | return -ENOTTY; |