Ok. I didn't make 2.4.0 in 2000. Tough. I tried, but we had some
[davej-history.git] / fs / ext2 / ioctl.c
blob6413da21b82a2c8da703fed127e1c524d4e3c602
1 /*
2 * linux/fs/ext2/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)
8 */
10 #include <linux/fs.h>
11 #include <linux/ext2_fs.h>
12 #include <linux/sched.h>
13 #include <asm/uaccess.h>
16 int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
17 unsigned long arg)
19 unsigned int flags;
21 ext2_debug ("cmd = %u, arg = %lu\n", cmd, arg);
23 switch (cmd) {
24 case EXT2_IOC_GETFLAGS:
25 flags = inode->u.ext2_i.i_flags & EXT2_FL_USER_VISIBLE;
26 return put_user(flags, (int *) arg);
27 case EXT2_IOC_SETFLAGS: {
28 unsigned int oldflags;
30 if (IS_RDONLY(inode))
31 return -EROFS;
33 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
34 return -EPERM;
36 if (get_user(flags, (int *) arg))
37 return -EFAULT;
39 oldflags = inode->u.ext2_i.i_flags;
42 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
43 * the relevant capability.
45 * This test looks nicer. Thanks to Pauline Middelink
47 if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
48 if (!capable(CAP_LINUX_IMMUTABLE))
49 return -EPERM;
52 flags = flags & EXT2_FL_USER_MODIFIABLE;
53 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
54 inode->u.ext2_i.i_flags = flags;
56 if (flags & EXT2_SYNC_FL)
57 inode->i_flags |= S_SYNC;
58 else
59 inode->i_flags &= ~S_SYNC;
60 if (flags & EXT2_APPEND_FL)
61 inode->i_flags |= S_APPEND;
62 else
63 inode->i_flags &= ~S_APPEND;
64 if (flags & EXT2_IMMUTABLE_FL)
65 inode->i_flags |= S_IMMUTABLE;
66 else
67 inode->i_flags &= ~S_IMMUTABLE;
68 if (flags & EXT2_NOATIME_FL)
69 inode->i_flags |= S_NOATIME;
70 else
71 inode->i_flags &= ~S_NOATIME;
72 inode->i_ctime = CURRENT_TIME;
73 mark_inode_dirty(inode);
74 return 0;
76 case EXT2_IOC_GETVERSION:
77 return put_user(inode->i_generation, (int *) arg);
78 case EXT2_IOC_SETVERSION:
79 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
80 return -EPERM;
81 if (IS_RDONLY(inode))
82 return -EROFS;
83 if (get_user(inode->i_generation, (int *) arg))
84 return -EFAULT;
85 inode->i_ctime = CURRENT_TIME;
86 mark_inode_dirty(inode);
87 return 0;
88 default:
89 return -ENOTTY;