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 ext2_get_inode_flags(ei);
31 flags = ei->i_flags & EXT2_FL_USER_VISIBLE;
32 return put_user(flags, (int __user *) arg);
33 case EXT2_IOC_SETFLAGS: {
34 unsigned int oldflags;
39 if (!is_owner_or_cap(inode))
42 if (get_user(flags, (int __user *) arg))
45 if (!S_ISDIR(inode->i_mode))
46 flags &= ~EXT2_DIRSYNC_FL;
48 mutex_lock(&inode->i_mutex);
49 oldflags = ei->i_flags;
52 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
53 * the relevant capability.
55 * This test looks nicer. Thanks to Pauline Middelink
57 if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
58 if (!capable(CAP_LINUX_IMMUTABLE)) {
59 mutex_unlock(&inode->i_mutex);
64 flags = flags & EXT2_FL_USER_MODIFIABLE;
65 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
67 mutex_unlock(&inode->i_mutex);
69 ext2_set_inode_flags(inode);
70 inode->i_ctime = CURRENT_TIME_SEC;
71 mark_inode_dirty(inode);
74 case EXT2_IOC_GETVERSION:
75 return put_user(inode->i_generation, (int __user *) arg);
76 case EXT2_IOC_SETVERSION:
77 if (!is_owner_or_cap(inode))
81 if (get_user(inode->i_generation, (int __user *) arg))
83 inode->i_ctime = CURRENT_TIME_SEC;
84 mark_inode_dirty(inode);
92 long ext2_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
94 struct inode *inode = file->f_path.dentry->d_inode;
97 /* These are just misnamed, they actually get/put from/to user an int */
99 case EXT2_IOC32_GETFLAGS:
100 cmd = EXT2_IOC_GETFLAGS;
102 case EXT2_IOC32_SETFLAGS:
103 cmd = EXT2_IOC_SETFLAGS;
105 case EXT2_IOC32_GETVERSION:
106 cmd = EXT2_IOC_GETVERSION;
108 case EXT2_IOC32_SETVERSION:
109 cmd = EXT2_IOC_SETVERSION;
115 ret = ext2_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));