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)
11 #include <linux/time.h>
12 #include <linux/sched.h>
13 #include <asm/current.h>
14 #include <asm/uaccess.h>
17 int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
20 struct ext2_inode_info *ei = EXT2_I(inode);
23 ext2_debug ("cmd = %u, arg = %lu\n", cmd, arg);
26 case EXT2_IOC_GETFLAGS:
27 flags = ei->i_flags & EXT2_FL_USER_VISIBLE;
28 return put_user(flags, (int __user *) arg);
29 case EXT2_IOC_SETFLAGS: {
30 unsigned int oldflags;
35 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
38 if (get_user(flags, (int __user *) arg))
41 if (!S_ISDIR(inode->i_mode))
42 flags &= ~EXT2_DIRSYNC_FL;
44 oldflags = ei->i_flags;
47 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
48 * the relevant capability.
50 * This test looks nicer. Thanks to Pauline Middelink
52 if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
53 if (!capable(CAP_LINUX_IMMUTABLE))
57 flags = flags & EXT2_FL_USER_MODIFIABLE;
58 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
61 ext2_set_inode_flags(inode);
62 inode->i_ctime = CURRENT_TIME_SEC;
63 mark_inode_dirty(inode);
66 case EXT2_IOC_GETVERSION:
67 return put_user(inode->i_generation, (int __user *) arg);
68 case EXT2_IOC_SETVERSION:
69 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
73 if (get_user(inode->i_generation, (int __user *) arg))
75 inode->i_ctime = CURRENT_TIME_SEC;
76 mark_inode_dirty(inode);