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,106 +18,112 @@ ...@@ -18,106 +18,112 @@
#include <linux/security.h> #include <linux/security.h>
#include "fat.h" #include "fat.h"
int fat_generic_ioctl(struct inode *inode, struct file *filp, static int fat_ioctl_get_attributes(struct inode *inode, u32 __user *user_attr)
unsigned int cmd, unsigned long arg)
{ {
u32 attr;
mutex_lock(&inode->i_mutex);
attr = fat_make_attrs(inode);
mutex_unlock(&inode->i_mutex);
return put_user(attr, user_attr);
}
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); struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
u32 __user *user_attr = (u32 __user *)arg; int is_dir = S_ISDIR(inode->i_mode);
u32 attr, oldattr;
struct iattr ia;
int err;
switch (cmd) { err = get_user(attr, user_attr);
case FAT_IOCTL_GET_ATTRIBUTES: if (err)
{ goto out;
u32 attr;
mutex_lock(&inode->i_mutex); mutex_lock(&inode->i_mutex);
attr = fat_make_attrs(inode); err = mnt_want_write(file->f_path.mnt);
mutex_unlock(&inode->i_mutex); if (err)
goto out_unlock_inode;
return put_user(attr, user_attr); /*
* ATTR_VOLUME and ATTR_DIR cannot be changed; this also
* prevents the user from turning us into a VFAT
* longname entry. Also, we obviously can't set
* any of the NTFS attributes in the high 24 bits.
*/
attr &= 0xff & ~(ATTR_VOLUME | ATTR_DIR);
/* Merge in ATTR_VOLUME and ATTR_DIR */
attr |= (MSDOS_I(inode)->i_attrs & ATTR_VOLUME) |
(is_dir ? ATTR_DIR : 0);
oldattr = fat_make_attrs(inode);
/* Equivalent to a chmod() */
ia.ia_valid = ATTR_MODE | ATTR_CTIME;
ia.ia_ctime = current_fs_time(inode->i_sb);
if (is_dir)
ia.ia_mode = fat_make_mode(sbi, attr, S_IRWXUGO);
else {
ia.ia_mode = fat_make_mode(sbi, attr,
S_IRUGO | S_IWUGO | (inode->i_mode & S_IXUGO));
} }
case FAT_IOCTL_SET_ATTRIBUTES:
{
u32 attr, oldattr;
int err, is_dir = S_ISDIR(inode->i_mode);
struct iattr ia;
err = get_user(attr, user_attr); /* The root directory has no attributes */
if (err) if (inode->i_ino == MSDOS_ROOT_INO && attr != ATTR_DIR) {
return err; err = -EINVAL;
goto out_drop_write;
}
mutex_lock(&inode->i_mutex); if (sbi->options.sys_immutable &&
((attr | oldattr) & ATTR_SYS) &&
err = mnt_want_write(filp->f_path.mnt); !capable(CAP_LINUX_IMMUTABLE)) {
if (err) err = -EPERM;
goto up_no_drop_write; goto out_drop_write;
}
/*
* ATTR_VOLUME and ATTR_DIR cannot be changed; this also
* prevents the user from turning us into a VFAT
* longname entry. Also, we obviously can't set
* any of the NTFS attributes in the high 24 bits.
*/
attr &= 0xff & ~(ATTR_VOLUME | ATTR_DIR);
/* Merge in ATTR_VOLUME and ATTR_DIR */
attr |= (MSDOS_I(inode)->i_attrs & ATTR_VOLUME) |
(is_dir ? ATTR_DIR : 0);
oldattr = fat_make_attrs(inode);
/* Equivalent to a chmod() */
ia.ia_valid = ATTR_MODE | ATTR_CTIME;
ia.ia_ctime = current_fs_time(inode->i_sb);
if (is_dir)
ia.ia_mode = fat_make_mode(sbi, attr, S_IRWXUGO);
else {
ia.ia_mode = fat_make_mode(sbi, attr,
S_IRUGO | S_IWUGO | (inode->i_mode & S_IXUGO));
}
/* The root directory has no attributes */ /*
if (inode->i_ino == MSDOS_ROOT_INO && attr != ATTR_DIR) { * The security check is questionable... We single
err = -EINVAL; * out the RO attribute for checking by the security
goto up; * module, just because it maps to a file mode.
} */
err = security_inode_setattr(file->f_path.dentry, &ia);
if (err)
goto out_drop_write;
if (sbi->options.sys_immutable) { /* This MUST be done before doing anything irreversible... */
if ((attr | oldattr) & ATTR_SYS) { err = fat_setattr(file->f_path.dentry, &ia);
if (!capable(CAP_LINUX_IMMUTABLE)) { if (err)
err = -EPERM; goto out_drop_write;
goto up;
} fsnotify_change(file->f_path.dentry, ia.ia_valid);
} if (sbi->options.sys_immutable) {
} if (attr & ATTR_SYS)
inode->i_flags |= S_IMMUTABLE;
else
inode->i_flags &= S_IMMUTABLE;
}
/* fat_save_attrs(inode, attr);
* The security check is questionable... We single mark_inode_dirty(inode);
* out the RO attribute for checking by the security out_drop_write:
* module, just because it maps to a file mode. mnt_drop_write(file->f_path.mnt);
*/ out_unlock_inode:
err = security_inode_setattr(filp->f_path.dentry, &ia); mutex_unlock(&inode->i_mutex);
if (err) out:
goto up; return err;
}
/* This MUST be done before doing anything irreversible... */
err = fat_setattr(filp->f_path.dentry, &ia);
if (err)
goto up;
fsnotify_change(filp->f_path.dentry, ia.ia_valid);
if (sbi->options.sys_immutable) {
if (attr & ATTR_SYS)
inode->i_flags |= S_IMMUTABLE;
else
inode->i_flags &= S_IMMUTABLE;
}
fat_save_attrs(inode, attr); int fat_generic_ioctl(struct inode *inode, struct file *filp,
mark_inode_dirty(inode); unsigned int cmd, unsigned long arg)
up: {
mnt_drop_write(filp->f_path.mnt); u32 __user *user_attr = (u32 __user *)arg;
up_no_drop_write:
mutex_unlock(&inode->i_mutex); switch (cmd) {
return err; 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: default:
return -ENOTTY; /* Inappropriate ioctl for device */ 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