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 *) arg);
31 case EXT3_IOC_SETFLAGS: {
32 handle_t *handle = NULL;
34 struct ext3_iloc iloc;
35 unsigned int oldflags;
41 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
44 if (get_user(flags, (int *) arg))
47 if (!S_ISDIR(inode->i_mode))
48 flags &= ~EXT3_DIRSYNC_FL;
50 oldflags = ei->i_flags;
52 /* The JOURNAL_DATA flag is modifiable only by root */
53 jflag = flags & EXT3_JOURNAL_DATA_FL;
56 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
57 * the relevant capability.
59 * This test looks nicer. Thanks to Pauline Middelink
61 if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
62 if (!capable(CAP_LINUX_IMMUTABLE))
67 * The JOURNAL_DATA flag can only be changed by
68 * the relevant capability.
70 if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL)) {
71 if (!capable(CAP_SYS_RESOURCE))
76 handle = ext3_journal_start(inode, 1);
78 return PTR_ERR(handle);
81 err = ext3_reserve_inode_write(handle, inode, &iloc);
85 flags = flags & EXT3_FL_USER_MODIFIABLE;
86 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
89 ext3_set_inode_flags(inode);
90 inode->i_ctime = CURRENT_TIME;
92 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
94 ext3_journal_stop(handle);
98 if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL))
99 err = ext3_change_inode_journal_flag(inode, jflag);
102 case EXT3_IOC_GETVERSION:
103 case EXT3_IOC_GETVERSION_OLD:
104 return put_user(inode->i_generation, (int *) arg);
105 case EXT3_IOC_SETVERSION:
106 case EXT3_IOC_SETVERSION_OLD: {
108 struct ext3_iloc iloc;
112 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
114 if (IS_RDONLY(inode))
116 if (get_user(generation, (int *) arg))
119 handle = ext3_journal_start(inode, 1);
121 return PTR_ERR(handle);
122 err = ext3_reserve_inode_write(handle, inode, &iloc);
124 inode->i_ctime = CURRENT_TIME;
125 inode->i_generation = generation;
126 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
128 ext3_journal_stop(handle);
131 #ifdef CONFIG_JBD_DEBUG
132 case EXT3_IOC_WAIT_FOR_READONLY:
134 * This is racy - by the time we're woken up and running,
135 * the superblock could be released. And the module could
136 * have been unloaded. So sue me.
138 * Returns 1 if it slept, else zero.
141 struct super_block *sb = inode->i_sb;
142 DECLARE_WAITQUEUE(wait, current);
145 set_current_state(TASK_INTERRUPTIBLE);
146 add_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait);
147 if (timer_pending(&EXT3_SB(sb)->turn_ro_timer)) {
151 remove_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait);
155 #if defined(CONFIG_VSERVER_LEGACY) && !defined(CONFIG_INOXID_NONE)
156 case EXT3_IOC_SETXID: {
158 struct ext3_iloc iloc;
162 /* fixme: if stealth, return -ENOTTY */
163 if (!capable(CAP_CONTEXT))
165 if (IS_RDONLY(inode))
167 if (!(inode->i_sb->s_flags & MS_TAGXID))
169 if (get_user(xid, (int *) arg))
172 handle = ext3_journal_start(inode, 1);
174 return PTR_ERR(handle);
175 err = ext3_reserve_inode_write(handle, inode, &iloc);
179 inode->i_xid = (xid & 0xFFFF);
180 inode->i_ctime = CURRENT_TIME;
182 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
183 ext3_journal_stop(handle);