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/capability.h>
12 #include <linux/time.h>
13 #include <linux/sched.h>
14 #include <linux/compat.h>
15 #include <linux/smp_lock.h>
16 #include <asm/current.h>
17 #include <asm/uaccess.h>
20 int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
23 struct ext2_inode_info *ei = EXT2_I(inode);
26 ext2_debug ("cmd = %u, arg = %lu\n", cmd, arg);
29 case EXT2_IOC_GETFLAGS:
30 flags = ei->i_flags & EXT2_FL_USER_VISIBLE;
31 return put_user(flags, (int __user *) arg);
32 case EXT2_IOC_SETFLAGS: {
33 unsigned int oldflags;
38 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
41 if (get_user(flags, (int __user *) arg))
44 if (!S_ISDIR(inode->i_mode))
45 flags &= ~EXT2_DIRSYNC_FL;
47 mutex_lock(&inode->i_mutex);
48 oldflags = ei->i_flags;
51 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
52 * the relevant capability.
54 * This test looks nicer. Thanks to Pauline Middelink
56 if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
57 if (!capable(CAP_LINUX_IMMUTABLE)) {
58 mutex_unlock(&inode->i_mutex);
63 flags = flags & EXT2_FL_USER_MODIFIABLE;
64 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
66 mutex_unlock(&inode->i_mutex);
68 ext2_set_inode_flags(inode);
69 inode->i_ctime = CURRENT_TIME_SEC;
70 mark_inode_dirty(inode);
73 case EXT2_IOC_GETVERSION:
74 return put_user(inode->i_generation, (int __user *) arg);
75 case EXT2_IOC_SETVERSION:
76 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
80 if (get_user(inode->i_generation, (int __user *) arg))
82 inode->i_ctime = CURRENT_TIME_SEC;
83 mark_inode_dirty(inode);
91 long ext2_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
93 struct inode *inode = file->f_path.dentry->d_inode;
96 /* These are just misnamed, they actually get/put from/to user an int */
98 case EXT2_IOC32_GETFLAGS:
99 cmd = EXT2_IOC_GETFLAGS;
101 case EXT2_IOC32_SETFLAGS:
102 cmd = EXT2_IOC_SETFLAGS;
104 case EXT2_IOC32_GETVERSION:
105 cmd = EXT2_IOC_GETVERSION;
107 case EXT2_IOC32_SETVERSION:
108 cmd = EXT2_IOC_SETVERSION;
114 ret = ext2_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));