Commit 21bea495 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by OGAWA Hirofumi

fat: split fat_generic_ioctl

Split up fat_generic_ioctl and add separate functions for the two
implemented ioctls.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
parent 85c78591
......@@ -18,15 +18,8 @@
#include <linux/security.h>
#include "fat.h"
int fat_generic_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
static int fat_ioctl_get_attributes(struct inode *inode, u32 __user *user_attr)
{
struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
u32 __user *user_attr = (u32 __user *)arg;
switch (cmd) {
case FAT_IOCTL_GET_ATTRIBUTES:
{
u32 attr;
mutex_lock(&inode->i_mutex);
......@@ -34,22 +27,25 @@ int fat_generic_ioctl(struct inode *inode, struct file *filp,
mutex_unlock(&inode->i_mutex);
return put_user(attr, user_attr);
}
case FAT_IOCTL_SET_ATTRIBUTES:
{
}
static int fat_ioctl_set_attributes(struct file *file, u32 __user *user_attr)
{
struct inode *inode = file->f_path.dentry->d_inode;
struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
int is_dir = S_ISDIR(inode->i_mode);
u32 attr, oldattr;
int err, is_dir = S_ISDIR(inode->i_mode);
struct iattr ia;
int err;
err = get_user(attr, user_attr);
if (err)
return err;
goto out;
mutex_lock(&inode->i_mutex);
err = mnt_want_write(filp->f_path.mnt);
err = mnt_want_write(file->f_path.mnt);
if (err)
goto up_no_drop_write;
goto out_unlock_inode;
/*
* ATTR_VOLUME and ATTR_DIR cannot be changed; this also
......@@ -76,16 +72,14 @@ int fat_generic_ioctl(struct inode *inode, struct file *filp,
/* The root directory has no attributes */
if (inode->i_ino == MSDOS_ROOT_INO && attr != ATTR_DIR) {
err = -EINVAL;
goto up;
goto out_drop_write;
}
if (sbi->options.sys_immutable) {
if ((attr | oldattr) & ATTR_SYS) {
if (!capable(CAP_LINUX_IMMUTABLE)) {
if (sbi->options.sys_immutable &&
((attr | oldattr) & ATTR_SYS) &&
!capable(CAP_LINUX_IMMUTABLE)) {
err = -EPERM;
goto up;
}
}
goto out_drop_write;
}
/*
......@@ -93,16 +87,16 @@ int fat_generic_ioctl(struct inode *inode, struct file *filp,
* out the RO attribute for checking by the security
* module, just because it maps to a file mode.
*/
err = security_inode_setattr(filp->f_path.dentry, &ia);
err = security_inode_setattr(file->f_path.dentry, &ia);
if (err)
goto up;
goto out_drop_write;
/* This MUST be done before doing anything irreversible... */
err = fat_setattr(filp->f_path.dentry, &ia);
err = fat_setattr(file->f_path.dentry, &ia);
if (err)
goto up;
goto out_drop_write;
fsnotify_change(filp->f_path.dentry, ia.ia_valid);
fsnotify_change(file->f_path.dentry, ia.ia_valid);
if (sbi->options.sys_immutable) {
if (attr & ATTR_SYS)
inode->i_flags |= S_IMMUTABLE;
......@@ -112,12 +106,24 @@ int fat_generic_ioctl(struct inode *inode, struct file *filp,
fat_save_attrs(inode, attr);
mark_inode_dirty(inode);
up:
mnt_drop_write(filp->f_path.mnt);
up_no_drop_write:
out_drop_write:
mnt_drop_write(file->f_path.mnt);
out_unlock_inode:
mutex_unlock(&inode->i_mutex);
out:
return err;
}
}
int fat_generic_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
{
u32 __user *user_attr = (u32 __user *)arg;
switch (cmd) {
case FAT_IOCTL_GET_ATTRIBUTES:
return fat_ioctl_get_attributes(inode, user_attr);
case FAT_IOCTL_SET_ATTRIBUTES:
return fat_ioctl_set_attributes(filp, user_attr);
default:
return -ENOTTY; /* Inappropriate ioctl for device */
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment