From: Christoph Hellwig <hch@lst.de>
To: viro@zeniv.linux.org.uk, zippel@linux-m68k.org
Cc: linux-fsdevel@vger.kernel.org
Subject: [PATCH 2/6] hfsplus: split hfsplus_ioctl
Date: Sun, 26 Sep 2010 23:19:46 +0200 [thread overview]
Message-ID: <20100926211946.GB6394@lst.de> (raw)
In-Reply-To: <20100926211920.GA6394@lst.de>
Give each ioctl command a function of it's own.
Signed-off-by: Christoph Hellwig <hch@tuxera.com>
Index: linux-2.6/fs/hfsplus/ioctl.c
===================================================================
--- linux-2.6.orig/fs/hfsplus/ioctl.c 2010-09-26 01:49:16.701790597 +0900
+++ linux-2.6/fs/hfsplus/ioctl.c 2010-09-26 02:01:29.927790059 +0900
@@ -21,78 +21,93 @@
#include <asm/uaccess.h>
#include "hfsplus_fs.h"
-long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+static int hfsplus_ioctl_getflags(struct file *file, int __user *user_flags)
{
- struct inode *inode = filp->f_path.dentry->d_inode;
+ struct inode *inode = file->f_path.dentry->d_inode;
+ unsigned int flags = 0;
+
+ if (HFSPLUS_I(inode).rootflags & HFSPLUS_FLG_IMMUTABLE)
+ flags |= FS_IMMUTABLE_FL;
+ if (HFSPLUS_I(inode).rootflags & HFSPLUS_FLG_APPEND)
+ flags |= FS_APPEND_FL;
+ if (HFSPLUS_I(inode).userflags & HFSPLUS_FLG_NODUMP)
+ flags |= FS_NODUMP_FL;
+
+ return put_user(flags, user_flags);
+}
+
+static int hfsplus_ioctl_setflags(struct file *file, int __user *user_flags)
+{
+ struct inode *inode = file->f_path.dentry->d_inode;
unsigned int flags;
+ int err = 0;
- switch (cmd) {
- case HFSPLUS_IOC_EXT2_GETFLAGS:
- flags = 0;
- if (HFSPLUS_I(inode).rootflags & HFSPLUS_FLG_IMMUTABLE)
- flags |= FS_IMMUTABLE_FL; /* EXT2_IMMUTABLE_FL */
- if (HFSPLUS_I(inode).rootflags & HFSPLUS_FLG_APPEND)
- flags |= FS_APPEND_FL; /* EXT2_APPEND_FL */
- if (HFSPLUS_I(inode).userflags & HFSPLUS_FLG_NODUMP)
- flags |= FS_NODUMP_FL; /* EXT2_NODUMP_FL */
- return put_user(flags, (int __user *)arg);
- case HFSPLUS_IOC_EXT2_SETFLAGS: {
- int err = 0;
-
- lock_kernel();
- err = mnt_want_write(filp->f_path.mnt);
- if (err) {
- unlock_kernel();
- return err;
- }
+ lock_kernel();
+ err = mnt_want_write(file->f_path.mnt);
+ if (err)
+ goto out_unlock_kernel;
+
+ if (!is_owner_or_cap(inode)) {
+ err = -EACCES;
+ goto out_drop_write;
+ }
- if (!is_owner_or_cap(inode)) {
- err = -EACCES;
- goto setflags_out;
- }
- if (get_user(flags, (int __user *)arg)) {
- err = -EFAULT;
- goto setflags_out;
- }
- if (flags & (FS_IMMUTABLE_FL|FS_APPEND_FL) ||
- HFSPLUS_I(inode).rootflags & (HFSPLUS_FLG_IMMUTABLE|HFSPLUS_FLG_APPEND)) {
- if (!capable(CAP_LINUX_IMMUTABLE)) {
- err = -EPERM;
- goto setflags_out;
- }
- }
+ if (get_user(flags, user_flags)) {
+ err = -EFAULT;
+ goto out_drop_write;
+ }
- /* don't silently ignore unsupported ext2 flags */
- if (flags & ~(FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NODUMP_FL)) {
- err = -EOPNOTSUPP;
- goto setflags_out;
+ if (flags & (FS_IMMUTABLE_FL|FS_APPEND_FL) ||
+ HFSPLUS_I(inode).rootflags & (HFSPLUS_FLG_IMMUTABLE|HFSPLUS_FLG_APPEND)) {
+ if (!capable(CAP_LINUX_IMMUTABLE)) {
+ err = -EPERM;
+ goto out_drop_write;
}
- if (flags & FS_IMMUTABLE_FL) { /* EXT2_IMMUTABLE_FL */
- inode->i_flags |= S_IMMUTABLE;
- HFSPLUS_I(inode).rootflags |= HFSPLUS_FLG_IMMUTABLE;
- } else {
- inode->i_flags &= ~S_IMMUTABLE;
- HFSPLUS_I(inode).rootflags &= ~HFSPLUS_FLG_IMMUTABLE;
- }
- if (flags & FS_APPEND_FL) { /* EXT2_APPEND_FL */
- inode->i_flags |= S_APPEND;
- HFSPLUS_I(inode).rootflags |= HFSPLUS_FLG_APPEND;
- } else {
- inode->i_flags &= ~S_APPEND;
- HFSPLUS_I(inode).rootflags &= ~HFSPLUS_FLG_APPEND;
- }
- if (flags & FS_NODUMP_FL) /* EXT2_NODUMP_FL */
- HFSPLUS_I(inode).userflags |= HFSPLUS_FLG_NODUMP;
- else
- HFSPLUS_I(inode).userflags &= ~HFSPLUS_FLG_NODUMP;
-
- inode->i_ctime = CURRENT_TIME_SEC;
- mark_inode_dirty(inode);
-setflags_out:
- mnt_drop_write(filp->f_path.mnt);
- unlock_kernel();
- return err;
}
+
+ /* don't silently ignore unsupported ext2 flags */
+ if (flags & ~(FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NODUMP_FL)) {
+ err = -EOPNOTSUPP;
+ goto out_drop_write;
+ }
+ if (flags & FS_IMMUTABLE_FL) {
+ inode->i_flags |= S_IMMUTABLE;
+ HFSPLUS_I(inode).rootflags |= HFSPLUS_FLG_IMMUTABLE;
+ } else {
+ inode->i_flags &= ~S_IMMUTABLE;
+ HFSPLUS_I(inode).rootflags &= ~HFSPLUS_FLG_IMMUTABLE;
+ }
+ if (flags & FS_APPEND_FL) {
+ inode->i_flags |= S_APPEND;
+ HFSPLUS_I(inode).rootflags |= HFSPLUS_FLG_APPEND;
+ } else {
+ inode->i_flags &= ~S_APPEND;
+ HFSPLUS_I(inode).rootflags &= ~HFSPLUS_FLG_APPEND;
+ }
+ if (flags & FS_NODUMP_FL)
+ HFSPLUS_I(inode).userflags |= HFSPLUS_FLG_NODUMP;
+ else
+ HFSPLUS_I(inode).userflags &= ~HFSPLUS_FLG_NODUMP;
+
+ inode->i_ctime = CURRENT_TIME_SEC;
+ mark_inode_dirty(inode);
+
+out_drop_write:
+ mnt_drop_write(file->f_path.mnt);
+out_unlock_kernel:
+ unlock_kernel();
+ return err;
+}
+
+long hfsplus_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+ void __user *argp = (void __user *)arg;
+
+ switch (cmd) {
+ case HFSPLUS_IOC_EXT2_GETFLAGS:
+ return hfsplus_ioctl_getflags(file, argp);
+ case HFSPLUS_IOC_EXT2_SETFLAGS:
+ return hfsplus_ioctl_setflags(file, argp);
default:
return -ENOTTY;
}
next prev parent reply other threads:[~2010-09-26 21:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-26 21:19 [PATCH 1/6] hfsplus: fix BKL leak in hfsplus_ioctl Christoph Hellwig
2010-09-26 21:19 ` Christoph Hellwig [this message]
2010-09-26 21:20 ` [PATCH 3/6] hfsplus: protect setflags using i_mutex Christoph Hellwig
2010-09-26 21:20 ` [PATCH 4/6] hfsplus: introduce alloc_mutex Christoph Hellwig
2010-09-26 21:20 ` [PATCH 5/6] hfsplus: use alloc_mutex in hfsplus_sync_fs Christoph Hellwig
2010-09-26 21:20 ` [PATCH 5/6] hfsplus: remove BKL from hfsplus_put_super Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100926211946.GB6394@lst.de \
--to=hch@lst.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=zippel@linux-m68k.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).