Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1 | /* |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2 | * linux/fs/ext4/ioctl.c |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 1993, 1994, 1995 |
| 5 | * Remy Card (card@masi.ibp.fr) |
| 6 | * Laboratoire MASI - Institut Blaise Pascal |
| 7 | * Universite Pierre et Marie Curie (Paris VI) |
| 8 | */ |
| 9 | |
| 10 | #include <linux/fs.h> |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 11 | #include <linux/jbd2.h> |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 12 | #include <linux/capability.h> |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 13 | #include <linux/time.h> |
| 14 | #include <linux/compat.h> |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 15 | #include <linux/mount.h> |
Akira Fujita | 748de67 | 2009-06-17 19:24:03 -0400 | [diff] [blame] | 16 | #include <linux/file.h> |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 17 | #include <asm/uaccess.h> |
Christoph Hellwig | 3dcf545 | 2008-04-29 18:13:32 -0400 | [diff] [blame] | 18 | #include "ext4_jbd2.h" |
| 19 | #include "ext4.h" |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 20 | |
Andi Kleen | 5cdd7b2 | 2008-04-29 22:03:54 -0400 | [diff] [blame] | 21 | long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 22 | { |
Andi Kleen | 5cdd7b2 | 2008-04-29 22:03:54 -0400 | [diff] [blame] | 23 | struct inode *inode = filp->f_dentry->d_inode; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 24 | struct ext4_inode_info *ei = EXT4_I(inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 25 | unsigned int flags; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 26 | |
Theodore Ts'o | af5bc92 | 2008-09-08 22:25:24 -0400 | [diff] [blame] | 27 | ext4_debug("cmd = %u, arg = %lu\n", cmd, arg); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 28 | |
| 29 | switch (cmd) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 30 | case EXT4_IOC_GETFLAGS: |
Jan Kara | ff9ddf7 | 2007-07-18 09:24:20 -0400 | [diff] [blame] | 31 | ext4_get_inode_flags(ei); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 32 | flags = ei->i_flags & EXT4_FL_USER_VISIBLE; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 33 | return put_user(flags, (int __user *) arg); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 34 | case EXT4_IOC_SETFLAGS: { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 35 | handle_t *handle = NULL; |
Aneesh Kumar K.V | 4db46fc | 2008-10-08 23:34:06 -0400 | [diff] [blame] | 36 | int err, migrate = 0; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 37 | struct ext4_iloc iloc; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 38 | unsigned int oldflags; |
| 39 | unsigned int jflag; |
| 40 | |
Satyam Sharma | 3bd858a | 2007-07-17 15:00:08 +0530 | [diff] [blame] | 41 | if (!is_owner_or_cap(inode)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 42 | return -EACCES; |
| 43 | |
| 44 | if (get_user(flags, (int __user *) arg)) |
| 45 | return -EFAULT; |
| 46 | |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 47 | err = mnt_want_write(filp->f_path.mnt); |
| 48 | if (err) |
| 49 | return err; |
| 50 | |
Duane Griffin | 2dc6b0d | 2009-02-15 18:09:20 -0500 | [diff] [blame] | 51 | flags = ext4_mask_flags(inode->i_mode, flags); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 52 | |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 53 | err = -EPERM; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 54 | mutex_lock(&inode->i_mutex); |
Jan Kara | e47776a | 2007-11-14 16:58:56 -0800 | [diff] [blame] | 55 | /* Is it quota file? Do not allow user to mess with it */ |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 56 | if (IS_NOQUOTA(inode)) |
| 57 | goto flags_out; |
| 58 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 59 | oldflags = ei->i_flags; |
| 60 | |
| 61 | /* The JOURNAL_DATA flag is modifiable only by root */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 62 | jflag = flags & EXT4_JOURNAL_DATA_FL; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | * The IMMUTABLE and APPEND_ONLY flags can only be changed by |
| 66 | * the relevant capability. |
| 67 | * |
| 68 | * This test looks nicer. Thanks to Pauline Middelink |
| 69 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 70 | if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) { |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 71 | if (!capable(CAP_LINUX_IMMUTABLE)) |
| 72 | goto flags_out; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /* |
| 76 | * The JOURNAL_DATA flag can only be changed by |
| 77 | * the relevant capability. |
| 78 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 79 | if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) { |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 80 | if (!capable(CAP_SYS_RESOURCE)) |
| 81 | goto flags_out; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 82 | } |
Aneesh Kumar K.V | 4db46fc | 2008-10-08 23:34:06 -0400 | [diff] [blame] | 83 | if (oldflags & EXT4_EXTENTS_FL) { |
| 84 | /* We don't support clearning extent flags */ |
| 85 | if (!(flags & EXT4_EXTENTS_FL)) { |
| 86 | err = -EOPNOTSUPP; |
| 87 | goto flags_out; |
| 88 | } |
| 89 | } else if (flags & EXT4_EXTENTS_FL) { |
| 90 | /* migrate the file */ |
| 91 | migrate = 1; |
| 92 | flags &= ~EXT4_EXTENTS_FL; |
| 93 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 94 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 95 | handle = ext4_journal_start(inode, 1); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 96 | if (IS_ERR(handle)) { |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 97 | err = PTR_ERR(handle); |
| 98 | goto flags_out; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 99 | } |
| 100 | if (IS_SYNC(inode)) |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 101 | ext4_handle_sync(handle); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 102 | err = ext4_reserve_inode_write(handle, inode, &iloc); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 103 | if (err) |
| 104 | goto flags_err; |
| 105 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 106 | flags = flags & EXT4_FL_USER_MODIFIABLE; |
| 107 | flags |= oldflags & ~EXT4_FL_USER_MODIFIABLE; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 108 | ei->i_flags = flags; |
| 109 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 110 | ext4_set_inode_flags(inode); |
Kalpak Shah | ef7f383 | 2007-07-18 09:15:20 -0400 | [diff] [blame] | 111 | inode->i_ctime = ext4_current_time(inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 112 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 113 | err = ext4_mark_iloc_dirty(handle, inode, &iloc); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 114 | flags_err: |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 115 | ext4_journal_stop(handle); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 116 | if (err) |
| 117 | goto flags_out; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 118 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 119 | if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) |
| 120 | err = ext4_change_inode_journal_flag(inode, jflag); |
Aneesh Kumar K.V | 4db46fc | 2008-10-08 23:34:06 -0400 | [diff] [blame] | 121 | if (err) |
| 122 | goto flags_out; |
| 123 | if (migrate) |
| 124 | err = ext4_ext_migrate(inode); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 125 | flags_out: |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 126 | mutex_unlock(&inode->i_mutex); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 127 | mnt_drop_write(filp->f_path.mnt); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 128 | return err; |
| 129 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 130 | case EXT4_IOC_GETVERSION: |
| 131 | case EXT4_IOC_GETVERSION_OLD: |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 132 | return put_user(inode->i_generation, (int __user *) arg); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 133 | case EXT4_IOC_SETVERSION: |
| 134 | case EXT4_IOC_SETVERSION_OLD: { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 135 | handle_t *handle; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 136 | struct ext4_iloc iloc; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 137 | __u32 generation; |
| 138 | int err; |
| 139 | |
Satyam Sharma | 3bd858a | 2007-07-17 15:00:08 +0530 | [diff] [blame] | 140 | if (!is_owner_or_cap(inode)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 141 | return -EPERM; |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 142 | |
| 143 | err = mnt_want_write(filp->f_path.mnt); |
| 144 | if (err) |
| 145 | return err; |
| 146 | if (get_user(generation, (int __user *) arg)) { |
| 147 | err = -EFAULT; |
| 148 | goto setversion_out; |
| 149 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 150 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 151 | handle = ext4_journal_start(inode, 1); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 152 | if (IS_ERR(handle)) { |
| 153 | err = PTR_ERR(handle); |
| 154 | goto setversion_out; |
| 155 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 156 | err = ext4_reserve_inode_write(handle, inode, &iloc); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 157 | if (err == 0) { |
Kalpak Shah | ef7f383 | 2007-07-18 09:15:20 -0400 | [diff] [blame] | 158 | inode->i_ctime = ext4_current_time(inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 159 | inode->i_generation = generation; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 160 | err = ext4_mark_iloc_dirty(handle, inode, &iloc); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 161 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 162 | ext4_journal_stop(handle); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 163 | setversion_out: |
| 164 | mnt_drop_write(filp->f_path.mnt); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 165 | return err; |
| 166 | } |
Jose R. Santos | e23291b | 2007-07-18 08:57:06 -0400 | [diff] [blame] | 167 | #ifdef CONFIG_JBD2_DEBUG |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 168 | case EXT4_IOC_WAIT_FOR_READONLY: |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 169 | /* |
| 170 | * This is racy - by the time we're woken up and running, |
| 171 | * the superblock could be released. And the module could |
| 172 | * have been unloaded. So sue me. |
| 173 | * |
| 174 | * Returns 1 if it slept, else zero. |
| 175 | */ |
| 176 | { |
| 177 | struct super_block *sb = inode->i_sb; |
| 178 | DECLARE_WAITQUEUE(wait, current); |
| 179 | int ret = 0; |
| 180 | |
| 181 | set_current_state(TASK_INTERRUPTIBLE); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 182 | add_wait_queue(&EXT4_SB(sb)->ro_wait_queue, &wait); |
| 183 | if (timer_pending(&EXT4_SB(sb)->turn_ro_timer)) { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 184 | schedule(); |
| 185 | ret = 1; |
| 186 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 187 | remove_wait_queue(&EXT4_SB(sb)->ro_wait_queue, &wait); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 188 | return ret; |
| 189 | } |
| 190 | #endif |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 191 | case EXT4_IOC_GROUP_EXTEND: { |
| 192 | ext4_fsblk_t n_blocks_count; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 193 | struct super_block *sb = inode->i_sb; |
Peng Tao | ac046f1 | 2009-07-13 09:30:17 -0400 | [diff] [blame] | 194 | int err, err2=0; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 195 | |
| 196 | if (!capable(CAP_SYS_RESOURCE)) |
| 197 | return -EPERM; |
| 198 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 199 | if (get_user(n_blocks_count, (__u32 __user *)arg)) |
| 200 | return -EFAULT; |
| 201 | |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 202 | err = mnt_want_write(filp->f_path.mnt); |
| 203 | if (err) |
| 204 | return err; |
| 205 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 206 | err = ext4_group_extend(sb, EXT4_SB(sb)->s_es, n_blocks_count); |
Peng Tao | ac046f1 | 2009-07-13 09:30:17 -0400 | [diff] [blame] | 207 | if (EXT4_SB(sb)->s_journal) { |
| 208 | jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); |
| 209 | err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal); |
| 210 | jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); |
| 211 | } |
Hidehiro Kawai | 7ffe1ea | 2008-10-10 20:29:21 -0400 | [diff] [blame] | 212 | if (err == 0) |
| 213 | err = err2; |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 214 | mnt_drop_write(filp->f_path.mnt); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 215 | |
| 216 | return err; |
| 217 | } |
Akira Fujita | 748de67 | 2009-06-17 19:24:03 -0400 | [diff] [blame] | 218 | |
| 219 | case EXT4_IOC_MOVE_EXT: { |
| 220 | struct move_extent me; |
| 221 | struct file *donor_filp; |
| 222 | int err; |
| 223 | |
| 224 | if (copy_from_user(&me, |
| 225 | (struct move_extent __user *)arg, sizeof(me))) |
| 226 | return -EFAULT; |
| 227 | |
| 228 | donor_filp = fget(me.donor_fd); |
| 229 | if (!donor_filp) |
| 230 | return -EBADF; |
| 231 | |
| 232 | if (!capable(CAP_DAC_OVERRIDE)) { |
| 233 | if ((current->real_cred->fsuid != inode->i_uid) || |
| 234 | !(inode->i_mode & S_IRUSR) || |
| 235 | !(donor_filp->f_dentry->d_inode->i_mode & |
| 236 | S_IRUSR)) { |
| 237 | fput(donor_filp); |
| 238 | return -EACCES; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | err = ext4_move_extents(filp, donor_filp, me.orig_start, |
| 243 | me.donor_start, me.len, &me.moved_len); |
| 244 | fput(donor_filp); |
| 245 | |
| 246 | if (!err) |
| 247 | if (copy_to_user((struct move_extent *)arg, |
| 248 | &me, sizeof(me))) |
| 249 | return -EFAULT; |
| 250 | return err; |
| 251 | } |
| 252 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 253 | case EXT4_IOC_GROUP_ADD: { |
| 254 | struct ext4_new_group_data input; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 255 | struct super_block *sb = inode->i_sb; |
Peng Tao | ac046f1 | 2009-07-13 09:30:17 -0400 | [diff] [blame] | 256 | int err, err2=0; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 257 | |
| 258 | if (!capable(CAP_SYS_RESOURCE)) |
| 259 | return -EPERM; |
| 260 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 261 | if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 262 | sizeof(input))) |
| 263 | return -EFAULT; |
| 264 | |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 265 | err = mnt_want_write(filp->f_path.mnt); |
| 266 | if (err) |
| 267 | return err; |
| 268 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 269 | err = ext4_group_add(sb, &input); |
Peng Tao | ac046f1 | 2009-07-13 09:30:17 -0400 | [diff] [blame] | 270 | if (EXT4_SB(sb)->s_journal) { |
| 271 | jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); |
| 272 | err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal); |
| 273 | jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); |
| 274 | } |
Hidehiro Kawai | 7ffe1ea | 2008-10-10 20:29:21 -0400 | [diff] [blame] | 275 | if (err == 0) |
| 276 | err = err2; |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 277 | mnt_drop_write(filp->f_path.mnt); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 278 | |
| 279 | return err; |
| 280 | } |
| 281 | |
Aneesh Kumar K.V | c14c6fd | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 282 | case EXT4_IOC_MIGRATE: |
Aneesh Kumar K.V | 2a43a87 | 2008-09-13 12:52:26 -0400 | [diff] [blame] | 283 | { |
| 284 | int err; |
| 285 | if (!is_owner_or_cap(inode)) |
| 286 | return -EACCES; |
| 287 | |
| 288 | err = mnt_want_write(filp->f_path.mnt); |
| 289 | if (err) |
| 290 | return err; |
| 291 | /* |
| 292 | * inode_mutex prevent write and truncate on the file. |
| 293 | * Read still goes through. We take i_data_sem in |
| 294 | * ext4_ext_swap_inode_data before we switch the |
| 295 | * inode format to prevent read. |
| 296 | */ |
| 297 | mutex_lock(&(inode->i_mutex)); |
| 298 | err = ext4_ext_migrate(inode); |
| 299 | mutex_unlock(&(inode->i_mutex)); |
| 300 | mnt_drop_write(filp->f_path.mnt); |
| 301 | return err; |
| 302 | } |
Aneesh Kumar K.V | c14c6fd | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 303 | |
Theodore Ts'o | ccd2506 | 2009-02-26 01:04:07 -0500 | [diff] [blame] | 304 | case EXT4_IOC_ALLOC_DA_BLKS: |
| 305 | { |
| 306 | int err; |
| 307 | if (!is_owner_or_cap(inode)) |
| 308 | return -EACCES; |
| 309 | |
| 310 | err = mnt_want_write(filp->f_path.mnt); |
| 311 | if (err) |
| 312 | return err; |
| 313 | err = ext4_alloc_da_blocks(inode); |
| 314 | mnt_drop_write(filp->f_path.mnt); |
| 315 | return err; |
| 316 | } |
| 317 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 318 | default: |
| 319 | return -ENOTTY; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | #ifdef CONFIG_COMPAT |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 324 | long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 325 | { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 326 | /* These are just misnamed, they actually get/put from/to user an int */ |
| 327 | switch (cmd) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 328 | case EXT4_IOC32_GETFLAGS: |
| 329 | cmd = EXT4_IOC_GETFLAGS; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 330 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 331 | case EXT4_IOC32_SETFLAGS: |
| 332 | cmd = EXT4_IOC_SETFLAGS; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 333 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 334 | case EXT4_IOC32_GETVERSION: |
| 335 | cmd = EXT4_IOC_GETVERSION; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 336 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 337 | case EXT4_IOC32_SETVERSION: |
| 338 | cmd = EXT4_IOC_SETVERSION; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 339 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 340 | case EXT4_IOC32_GROUP_EXTEND: |
| 341 | cmd = EXT4_IOC_GROUP_EXTEND; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 342 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 343 | case EXT4_IOC32_GETVERSION_OLD: |
| 344 | cmd = EXT4_IOC_GETVERSION_OLD; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 345 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 346 | case EXT4_IOC32_SETVERSION_OLD: |
| 347 | cmd = EXT4_IOC_SETVERSION_OLD; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 348 | break; |
Jose R. Santos | e23291b | 2007-07-18 08:57:06 -0400 | [diff] [blame] | 349 | #ifdef CONFIG_JBD2_DEBUG |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 350 | case EXT4_IOC32_WAIT_FOR_READONLY: |
| 351 | cmd = EXT4_IOC_WAIT_FOR_READONLY; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 352 | break; |
| 353 | #endif |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 354 | case EXT4_IOC32_GETRSVSZ: |
| 355 | cmd = EXT4_IOC_GETRSVSZ; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 356 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 357 | case EXT4_IOC32_SETRSVSZ: |
| 358 | cmd = EXT4_IOC_SETRSVSZ; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 359 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 360 | case EXT4_IOC_GROUP_ADD: |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 361 | break; |
| 362 | default: |
| 363 | return -ENOIOCTLCMD; |
| 364 | } |
Andi Kleen | 5cdd7b2 | 2008-04-29 22:03:54 -0400 | [diff] [blame] | 365 | return ext4_ioctl(file, cmd, (unsigned long) compat_ptr(arg)); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 366 | } |
| 367 | #endif |