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);
25 ext3_debug ("cmd = %u, arg = %lu\n", cmd, arg);
28 case EXT3_IOC_GETFLAGS:
29 flags = ei->i_flags & EXT3_FL_USER_VISIBLE;
30 return put_user(flags, (int __user *) arg);
31 case EXT3_IOC_SETFLAGS: {
32 handle_t *handle = NULL;
34 struct ext3_iloc iloc;
35 unsigned int oldflags;
38 if (IS_RDONLY(inode) ||
39 (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
42 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
45 if (get_user(flags, (int __user *) arg))
48 if (!S_ISDIR(inode->i_mode))
49 flags &= ~EXT3_DIRSYNC_FL;
51 oldflags = ei->i_flags;
53 /* The JOURNAL_DATA flag is modifiable only by root */
54 jflag = flags & EXT3_JOURNAL_DATA_FL;
57 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
58 * the relevant capability.
60 * This test looks nicer. Thanks to Pauline Middelink
62 if ((oldflags & EXT3_IMMUTABLE_FL) ||
64 (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL))) {
65 if (!capable(CAP_LINUX_IMMUTABLE))
70 * The JOURNAL_DATA flag can only be changed by
71 * the relevant capability.
73 if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL)) {
74 if (!capable(CAP_SYS_RESOURCE))
79 handle = ext3_journal_start(inode, 1);
81 return PTR_ERR(handle);
84 err = ext3_reserve_inode_write(handle, inode, &iloc);
88 flags = flags & EXT3_FL_USER_MODIFIABLE;
89 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
92 ext3_set_inode_flags(inode);
93 inode->i_ctime = CURRENT_TIME;
95 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
97 ext3_journal_stop(handle);
101 if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL))
102 err = ext3_change_inode_journal_flag(inode, jflag);
105 case EXT3_IOC_GETVERSION:
106 case EXT3_IOC_GETVERSION_OLD:
107 return put_user(inode->i_generation, (int __user *) arg);
108 case EXT3_IOC_SETVERSION:
109 case EXT3_IOC_SETVERSION_OLD: {
111 struct ext3_iloc iloc;
115 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
117 if (IS_RDONLY(inode) ||
118 (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
120 if (get_user(generation, (int __user *) arg))
123 handle = ext3_journal_start(inode, 1);
125 return PTR_ERR(handle);
126 err = ext3_reserve_inode_write(handle, inode, &iloc);
128 inode->i_ctime = CURRENT_TIME;
129 inode->i_generation = generation;
130 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
132 ext3_journal_stop(handle);
135 #ifdef CONFIG_JBD_DEBUG
136 case EXT3_IOC_WAIT_FOR_READONLY:
138 * This is racy - by the time we're woken up and running,
139 * the superblock could be released. And the module could
140 * have been unloaded. So sue me.
142 * Returns 1 if it slept, else zero.
145 struct super_block *sb = inode->i_sb;
146 DECLARE_WAITQUEUE(wait, current);
149 set_current_state(TASK_INTERRUPTIBLE);
150 add_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait);
151 if (timer_pending(&EXT3_SB(sb)->turn_ro_timer)) {
155 remove_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait);
159 #if defined(CONFIG_VSERVER_LEGACY) && !defined(CONFIG_INOXID_NONE)
160 case EXT3_IOC_SETXID: {
162 struct ext3_iloc iloc;
166 /* fixme: if stealth, return -ENOTTY */
167 if (!capable(CAP_CONTEXT))
169 if (IS_RDONLY(inode))
171 if (!(inode->i_sb->s_flags & MS_TAGXID))
173 if (get_user(xid, (int *) arg))
176 handle = ext3_journal_start(inode, 1);
178 return PTR_ERR(handle);
179 err = ext3_reserve_inode_write(handle, inode, &iloc);
183 inode->i_xid = (xid & 0xFFFF);
184 inode->i_ctime = CURRENT_TIME;
186 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
187 ext3_journal_stop(handle);