1 Convert EXT2 to use unlocked_ioctl
3 From: Mathieu Segaud <mathieu.segaud@regala.cx>
5 Change ext2_ioctl() to be an unlocked_ioctl(), explicitly
8 Signed-off-by: Mathieu Segaud <mathieu.segaud@regala.cx>
9 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
15 fs/ext2/ioctl.c | 103 +++++++++++++++++++++++++++++++++++++------------------
16 4 files changed, 73 insertions(+), 39 deletions(-)
18 diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c
19 index d868e26..dbee3c9 100644
22 @@ -703,7 +703,7 @@ const struct file_operations ext2_dir_operations = {
23 .llseek = generic_file_llseek,
24 .read = generic_read_dir,
25 .readdir = ext2_readdir,
26 - .ioctl = ext2_ioctl,
27 + .unlocked_ioctl = ext2_ioctl,
29 .compat_ioctl = ext2_compat_ioctl,
31 diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h
32 index c87ae29..bb9948c 100644
35 @@ -139,8 +139,7 @@ int __ext2_write_begin(struct file *file, struct address_space *mapping,
36 struct page **pagep, void **fsdata);
39 -extern int ext2_ioctl (struct inode *, struct file *, unsigned int,
41 +extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
42 extern long ext2_compat_ioctl(struct file *, unsigned int, unsigned long);
45 diff --git a/fs/ext2/file.c b/fs/ext2/file.c
46 index c051798..17fe628 100644
49 @@ -48,7 +48,7 @@ const struct file_operations ext2_file_operations = {
50 .write = do_sync_write,
51 .aio_read = generic_file_aio_read,
52 .aio_write = generic_file_aio_write,
53 - .ioctl = ext2_ioctl,
54 + .unlocked_ioctl = ext2_ioctl,
56 .compat_ioctl = ext2_compat_ioctl,
58 @@ -65,7 +65,7 @@ const struct file_operations ext2_xip_file_operations = {
59 .llseek = generic_file_llseek,
60 .read = xip_file_read,
61 .write = xip_file_write,
62 - .ioctl = ext2_ioctl,
63 + .unlocked_ioctl = ext2_ioctl,
65 .compat_ioctl = ext2_compat_ioctl,
67 diff --git a/fs/ext2/ioctl.c b/fs/ext2/ioctl.c
68 index 320b2cb..0f18ac5 100644
72 #include <asm/uaccess.h>
75 -int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
76 +long ext2_ioctl(struct file *filp, unsigned int cmd,
79 - struct ext2_inode_info *ei = EXT2_I(inode);
80 + struct ext2_inode_info *ei;
81 + struct inode *inode;
83 unsigned short rsv_window_size;
87 + inode = filp->f_path.dentry->d_inode;
90 ext2_debug ("cmd = %u, arg = %lu\n", cmd, arg);
92 @@ -30,18 +36,25 @@ int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
93 case EXT2_IOC_GETFLAGS:
94 ext2_get_inode_flags(ei);
95 flags = ei->i_flags & EXT2_FL_USER_VISIBLE;
96 - return put_user(flags, (int __user *) arg);
97 + retval = put_user(flags, (int __user *) arg);
99 case EXT2_IOC_SETFLAGS: {
100 unsigned int oldflags;
102 - if (IS_RDONLY(inode))
104 + if (IS_RDONLY(inode)) {
109 - if (!is_owner_or_cap(inode))
111 + if (!is_owner_or_cap(inode)) {
116 - if (get_user(flags, (int __user *) arg))
118 + if (get_user(flags, (int __user *) arg)) {
123 if (!S_ISDIR(inode->i_mode))
124 flags &= ~EXT2_DIRSYNC_FL;
125 @@ -50,7 +63,8 @@ int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
126 /* Is it quota file? Do not allow user to mess with it */
127 if (IS_NOQUOTA(inode)) {
128 mutex_unlock(&inode->i_mutex);
133 oldflags = ei->i_flags;
135 @@ -63,7 +77,8 @@ int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
136 if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
137 if (!capable(CAP_LINUX_IMMUTABLE)) {
138 mutex_unlock(&inode->i_mutex);
145 @@ -75,41 +90,59 @@ int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
146 ext2_set_inode_flags(inode);
147 inode->i_ctime = CURRENT_TIME_SEC;
148 mark_inode_dirty(inode);
152 case EXT2_IOC_GETVERSION:
153 - return put_user(inode->i_generation, (int __user *) arg);
154 + retval = put_user(inode->i_generation, (int __user *) arg);
156 case EXT2_IOC_SETVERSION:
157 - if (!is_owner_or_cap(inode))
159 - if (IS_RDONLY(inode))
161 - if (get_user(inode->i_generation, (int __user *) arg))
163 + if (!is_owner_or_cap(inode)) {
167 + if (IS_RDONLY(inode)) {
171 + if (get_user(inode->i_generation, (int __user *) arg)) {
175 inode->i_ctime = CURRENT_TIME_SEC;
176 mark_inode_dirty(inode);
179 case EXT2_IOC_GETRSVSZ:
180 if (test_opt(inode->i_sb, RESERVATION)
181 && S_ISREG(inode->i_mode)
182 && ei->i_block_alloc_info) {
183 rsv_window_size = ei->i_block_alloc_info->rsv_window_node.rsv_goal_size;
184 - return put_user(rsv_window_size, (int __user *)arg);
185 + retval = put_user(rsv_window_size, (int __user *)arg);
191 case EXT2_IOC_SETRSVSZ: {
193 - if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
195 + if (!test_opt(inode->i_sb, RESERVATION) ||
196 + !S_ISREG(inode->i_mode)) {
201 - if (IS_RDONLY(inode))
203 + if (IS_RDONLY(inode)) {
208 - if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
210 + if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER)) {
215 - if (get_user(rsv_window_size, (int __user *)arg))
217 + if (get_user(rsv_window_size, (int __user *)arg)) {
222 if (rsv_window_size > EXT2_MAX_RESERVE_BLOCKS)
223 rsv_window_size = EXT2_MAX_RESERVE_BLOCKS;
224 @@ -131,11 +164,15 @@ int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
225 rsv->rsv_goal_size = rsv_window_size;
227 mutex_unlock(&ei->truncate_mutex);
242 @@ -161,9 +198,7 @@ long ext2_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
247 ret = ext2_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));