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;
41 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
44 if (get_user(flags, (int __user *) 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 ((oldflags & EXT3_IMMUTABLE_FL) ||
63 (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL))) {
64 if (!capable(CAP_LINUX_IMMUTABLE))
69 * The JOURNAL_DATA flag can only be changed by
70 * the relevant capability.
72 if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL)) {
73 if (!capable(CAP_SYS_RESOURCE))
78 handle = ext3_journal_start(inode, 1);
80 return PTR_ERR(handle);
83 err = ext3_reserve_inode_write(handle, inode, &iloc);
87 flags = flags & EXT3_FL_USER_MODIFIABLE;
88 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
91 ext3_set_inode_flags(inode);
92 inode->i_ctime = CURRENT_TIME;
94 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
96 ext3_journal_stop(handle);
100 if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL))
101 err = ext3_change_inode_journal_flag(inode, jflag);
104 case EXT3_IOC_GETVERSION:
105 case EXT3_IOC_GETVERSION_OLD:
106 return put_user(inode->i_generation, (int __user *) arg);
107 case EXT3_IOC_SETVERSION:
108 case EXT3_IOC_SETVERSION_OLD: {
110 struct ext3_iloc iloc;
114 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
116 if (IS_RDONLY(inode))
118 if (get_user(generation, (int __user *) arg))
121 handle = ext3_journal_start(inode, 1);
123 return PTR_ERR(handle);
124 err = ext3_reserve_inode_write(handle, inode, &iloc);
126 inode->i_ctime = CURRENT_TIME;
127 inode->i_generation = generation;
128 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
130 ext3_journal_stop(handle);
133 #ifdef CONFIG_JBD_DEBUG
134 case EXT3_IOC_WAIT_FOR_READONLY:
136 * This is racy - by the time we're woken up and running,
137 * the superblock could be released. And the module could
138 * have been unloaded. So sue me.
140 * Returns 1 if it slept, else zero.
143 struct super_block *sb = inode->i_sb;
144 DECLARE_WAITQUEUE(wait, current);
147 set_current_state(TASK_INTERRUPTIBLE);
148 add_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait);
149 if (timer_pending(&EXT3_SB(sb)->turn_ro_timer)) {
153 remove_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait);
157 #if defined(CONFIG_VSERVER_LEGACY) && !defined(CONFIG_INOXID_NONE)
158 case EXT3_IOC_SETXID: {
160 struct ext3_iloc iloc;
164 /* fixme: if stealth, return -ENOTTY */
165 if (!capable(CAP_CONTEXT))
167 if (IS_RDONLY(inode))
169 if (!(inode->i_sb->s_flags & MS_TAGXID))
171 if (get_user(xid, (int *) arg))
174 handle = ext3_journal_start(inode, 1);
176 return PTR_ERR(handle);
177 err = ext3_reserve_inode_write(handle, inode, &iloc);
181 inode->i_xid = (xid & 0xFFFF);
182 inode->i_ctime = CURRENT_TIME;
184 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
185 ext3_journal_stop(handle);