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 <asm/uaccess.h>
18 int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
21 struct ext3_inode_info *ei = EXT3_I(inode);
24 ext3_debug ("cmd = %u, arg = %lu\n", cmd, arg);
27 case EXT3_IOC_GETFLAGS:
28 flags = ei->i_flags & EXT3_FL_USER_VISIBLE;
29 return put_user(flags, (int *) arg);
30 case EXT3_IOC_SETFLAGS: {
31 handle_t *handle = NULL;
33 struct ext3_iloc iloc;
34 unsigned int oldflags;
40 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
43 if (get_user(flags, (int *) arg))
46 if (!S_ISDIR(inode->i_mode))
47 flags &= ~EXT3_DIRSYNC_FL;
49 oldflags = ei->i_flags;
51 /* The JOURNAL_DATA flag is modifiable only by root */
52 jflag = flags & EXT3_JOURNAL_DATA_FL;
55 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
56 * the relevant capability.
58 * This test looks nicer. Thanks to Pauline Middelink
60 if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
61 if (!capable(CAP_LINUX_IMMUTABLE))
66 * The JOURNAL_DATA flag can only be changed by
67 * the relevant capability.
69 if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL)) {
70 if (!capable(CAP_SYS_RESOURCE))
75 handle = ext3_journal_start(inode, 1);
77 return PTR_ERR(handle);
80 err = ext3_reserve_inode_write(handle, inode, &iloc);
84 flags = flags & EXT3_FL_USER_MODIFIABLE;
85 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
88 ext3_set_inode_flags(inode);
89 inode->i_ctime = CURRENT_TIME;
91 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
93 ext3_journal_stop(handle);
97 if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL))
98 err = ext3_change_inode_journal_flag(inode, jflag);
101 case EXT3_IOC_GETVERSION:
102 case EXT3_IOC_GETVERSION_OLD:
103 return put_user(inode->i_generation, (int *) arg);
104 case EXT3_IOC_SETVERSION:
105 case EXT3_IOC_SETVERSION_OLD: {
107 struct ext3_iloc iloc;
111 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
113 if (IS_RDONLY(inode))
115 if (get_user(generation, (int *) arg))
118 handle = ext3_journal_start(inode, 1);
120 return PTR_ERR(handle);
121 err = ext3_reserve_inode_write(handle, inode, &iloc);
123 inode->i_ctime = CURRENT_TIME;
124 inode->i_generation = generation;
125 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
127 ext3_journal_stop(handle);
130 #ifdef CONFIG_JBD_DEBUG
131 case EXT3_IOC_WAIT_FOR_READONLY:
133 * This is racy - by the time we're woken up and running,
134 * the superblock could be released. And the module could
135 * have been unloaded. So sue me.
137 * Returns 1 if it slept, else zero.
140 struct super_block *sb = inode->i_sb;
141 DECLARE_WAITQUEUE(wait, current);
144 set_current_state(TASK_INTERRUPTIBLE);
145 add_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait);
146 if (timer_pending(&EXT3_SB(sb)->turn_ro_timer)) {
150 remove_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait);