mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-13 14:24:11 +08:00
bcachefs: support FS_IOC_SETFSLABEL
Implement support for FS_IOC_SETFSLABEL ioctl to set filesystem label. Signed-off-by: Hongbo Li <lihongbo22@huawei.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
81bce3cf2b
commit
7a254053a5
@ -301,6 +301,41 @@ static int bch2_ioc_getlabel(struct bch_fs *c, char __user *user_label)
|
|||||||
return ret ? -EFAULT : 0;
|
return ret ? -EFAULT : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int bch2_ioc_setlabel(struct bch_fs *c,
|
||||||
|
struct file *file,
|
||||||
|
struct bch_inode_info *inode,
|
||||||
|
const char __user *user_label)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
char label[BCH_SB_LABEL_SIZE];
|
||||||
|
|
||||||
|
if (!capable(CAP_SYS_ADMIN))
|
||||||
|
return -EPERM;
|
||||||
|
|
||||||
|
if (copy_from_user(label, user_label, sizeof(label)))
|
||||||
|
return -EFAULT;
|
||||||
|
|
||||||
|
if (strnlen(label, BCH_SB_LABEL_SIZE) == BCH_SB_LABEL_SIZE) {
|
||||||
|
bch_err(c,
|
||||||
|
"unable to set label with more than %d bytes",
|
||||||
|
BCH_SB_LABEL_SIZE - 1);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = mnt_want_write_file(file);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
mutex_lock(&c->sb_lock);
|
||||||
|
strscpy(c->disk_sb.sb->label, label, BCH_SB_LABEL_SIZE);
|
||||||
|
mutex_unlock(&c->sb_lock);
|
||||||
|
|
||||||
|
ret = bch2_write_super(c);
|
||||||
|
|
||||||
|
mnt_drop_write_file(file);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int bch2_ioc_goingdown(struct bch_fs *c, u32 __user *arg)
|
static int bch2_ioc_goingdown(struct bch_fs *c, u32 __user *arg)
|
||||||
{
|
{
|
||||||
u32 flags;
|
u32 flags;
|
||||||
@ -539,6 +574,10 @@ long bch2_fs_file_ioctl(struct file *file, unsigned cmd, unsigned long arg)
|
|||||||
ret = bch2_ioc_getlabel(c, (void __user *) arg);
|
ret = bch2_ioc_getlabel(c, (void __user *) arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case FS_IOC_SETFSLABEL:
|
||||||
|
ret = bch2_ioc_setlabel(c, file, inode, (const void __user *) arg);
|
||||||
|
break;
|
||||||
|
|
||||||
case FS_IOC_GOINGDOWN:
|
case FS_IOC_GOINGDOWN:
|
||||||
ret = bch2_ioc_goingdown(c, (u32 __user *) arg);
|
ret = bch2_ioc_goingdown(c, (u32 __user *) arg);
|
||||||
break;
|
break;
|
||||||
@ -584,6 +623,7 @@ long bch2_compat_fs_ioctl(struct file *file, unsigned cmd, unsigned long arg)
|
|||||||
cmd = FS_IOC_GETVERSION;
|
cmd = FS_IOC_GETVERSION;
|
||||||
break;
|
break;
|
||||||
case FS_IOC_GETFSLABEL:
|
case FS_IOC_GETFSLABEL:
|
||||||
|
case FS_IOC_SETFSLABEL:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -ENOIOCTLCMD;
|
return -ENOIOCTLCMD;
|
||||||
|
Loading…
Reference in New Issue
Block a user