2 * linux/fs/ext3/ioctl.c
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)
11 #include <linux/jbd.h>
12 #include <linux/ext3_fs.h>
13 #include <linux/ext3_jbd.h>
14 #include <linux/time.h>
15 #include <linux/vserver/xid.h>
16 #include <asm/uaccess.h>
19 int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
22 struct ext3_inode_info *ei = EXT3_I(inode);
24 unsigned short rsv_window_size;
26 ext3_debug ("cmd = %u, arg = %lu\n", cmd, arg);
29 case EXT3_IOC_GETFLAGS:
30 flags = ei->i_flags & EXT3_FL_USER_VISIBLE;
31 return put_user(flags, (int __user *) arg);
32 case EXT3_IOC_SETFLAGS: {
33 handle_t *handle = NULL;
35 struct ext3_iloc iloc;
36 unsigned int oldflags;
39 if (IS_RDONLY(inode) ||
40 (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
43 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
46 if (get_user(flags, (int __user *) arg))
49 if (!S_ISDIR(inode->i_mode))
50 flags &= ~EXT3_DIRSYNC_FL;
52 oldflags = ei->i_flags;
54 /* The JOURNAL_DATA flag is modifiable only by root */
55 jflag = flags & EXT3_JOURNAL_DATA_FL;
58 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
59 * the relevant capability.
61 * This test looks nicer. Thanks to Pauline Middelink
63 if ((oldflags & EXT3_IMMUTABLE_FL) ||
64 ((flags ^ oldflags) & (EXT3_APPEND_FL |
65 EXT3_IMMUTABLE_FL | EXT3_IUNLINK_FL))) {
66 if (!capable(CAP_LINUX_IMMUTABLE))
71 * The JOURNAL_DATA flag can only be changed by
72 * the relevant capability.
74 if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL)) {
75 if (!capable(CAP_SYS_RESOURCE))
80 handle = ext3_journal_start(inode, 1);
82 return PTR_ERR(handle);
85 err = ext3_reserve_inode_write(handle, inode, &iloc);
89 flags = flags & EXT3_FL_USER_MODIFIABLE;
90 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
93 ext3_set_inode_flags(inode);
94 inode->i_ctime = CURRENT_TIME_SEC;
96 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
98 ext3_journal_stop(handle);
102 if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL))
103 err = ext3_change_inode_journal_flag(inode, jflag);
106 case EXT3_IOC_GETVERSION:
107 case EXT3_IOC_GETVERSION_OLD:
108 return put_user(inode->i_generation, (int __user *) arg);
109 case EXT3_IOC_SETVERSION:
110 case EXT3_IOC_SETVERSION_OLD: {
112 struct ext3_iloc iloc;
116 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
118 if (IS_RDONLY(inode) ||
119 (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
121 if (get_user(generation, (int __user *) arg))
124 handle = ext3_journal_start(inode, 1);
126 return PTR_ERR(handle);
127 err = ext3_reserve_inode_write(handle, inode, &iloc);
129 inode->i_ctime = CURRENT_TIME_SEC;
130 inode->i_generation = generation;
131 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
133 ext3_journal_stop(handle);
136 #ifdef CONFIG_JBD_DEBUG
137 case EXT3_IOC_WAIT_FOR_READONLY:
139 * This is racy - by the time we're woken up and running,
140 * the superblock could be released. And the module could
141 * have been unloaded. So sue me.
143 * Returns 1 if it slept, else zero.
146 struct super_block *sb = inode->i_sb;
147 DECLARE_WAITQUEUE(wait, current);
150 set_current_state(TASK_INTERRUPTIBLE);
151 add_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait);
152 if (timer_pending(&EXT3_SB(sb)->turn_ro_timer)) {
156 remove_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait);
160 case EXT3_IOC_GETRSVSZ:
161 if (test_opt(inode->i_sb, RESERVATION)
162 && S_ISREG(inode->i_mode)
163 && ei->i_block_alloc_info) {
164 rsv_window_size = ei->i_block_alloc_info->rsv_window_node.rsv_goal_size;
165 return put_user(rsv_window_size, (int __user *)arg);
168 case EXT3_IOC_SETRSVSZ: {
170 if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
173 if (IS_RDONLY(inode) ||
174 (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
177 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
180 if (get_user(rsv_window_size, (int __user *)arg))
183 if (rsv_window_size > EXT3_MAX_RESERVE_BLOCKS)
184 rsv_window_size = EXT3_MAX_RESERVE_BLOCKS;
187 * need to allocate reservation structure for this inode
188 * before set the window size
190 down(&ei->truncate_sem);
191 if (!ei->i_block_alloc_info)
192 ext3_init_block_alloc_info(inode);
194 if (ei->i_block_alloc_info){
195 struct ext3_reserve_window_node *rsv = &ei->i_block_alloc_info->rsv_window_node;
196 rsv->rsv_goal_size = rsv_window_size;
198 up(&ei->truncate_sem);
201 case EXT3_IOC_GROUP_EXTEND: {
202 unsigned long n_blocks_count;
203 struct super_block *sb = inode->i_sb;
206 if (!capable(CAP_SYS_RESOURCE))
209 if (IS_RDONLY(inode) ||
210 (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
213 if (get_user(n_blocks_count, (__u32 __user *)arg))
216 err = ext3_group_extend(sb, EXT3_SB(sb)->s_es, n_blocks_count);
217 journal_lock_updates(EXT3_SB(sb)->s_journal);
218 journal_flush(EXT3_SB(sb)->s_journal);
219 journal_unlock_updates(EXT3_SB(sb)->s_journal);
223 case EXT3_IOC_GROUP_ADD: {
224 struct ext3_new_group_data input;
225 struct super_block *sb = inode->i_sb;
228 if (!capable(CAP_SYS_RESOURCE))
231 if (IS_RDONLY(inode) ||
232 (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
235 if (copy_from_user(&input, (struct ext3_new_group_input __user *)arg,
239 err = ext3_group_add(sb, &input);
240 journal_lock_updates(EXT3_SB(sb)->s_journal);
241 journal_flush(EXT3_SB(sb)->s_journal);
242 journal_unlock_updates(EXT3_SB(sb)->s_journal);
247 #if defined(CONFIG_VSERVER_LEGACY) && !defined(CONFIG_INOXID_NONE)
248 case EXT3_IOC_SETXID: {
250 struct ext3_iloc iloc;
254 /* fixme: if stealth, return -ENOTTY */
255 if (!capable(CAP_CONTEXT))
257 if (IS_RDONLY(inode) ||
258 (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
260 if (!(inode->i_sb->s_flags & MS_TAGXID))
262 if (get_user(xid, (int *) arg))
265 handle = ext3_journal_start(inode, 1);
267 return PTR_ERR(handle);
268 err = ext3_reserve_inode_write(handle, inode, &iloc);
272 inode->i_xid = (xid & 0xFFFF);
273 inode->i_ctime = CURRENT_TIME;
275 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
276 ext3_journal_stop(handle);