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