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 oldflags
= ei
->i_flags
;
50 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
51 * the relevant capability.
53 * This test looks nicer. Thanks to Pauline Middelink
55 if ((flags
^ oldflags
) & (EXT2_APPEND_FL
| EXT2_IMMUTABLE_FL
)) {
56 if (!capable(CAP_LINUX_IMMUTABLE
))
60 flags
= flags
& EXT2_FL_USER_MODIFIABLE
;
61 flags
|= oldflags
& ~EXT2_FL_USER_MODIFIABLE
;
64 ext2_set_inode_flags(inode
);
65 inode
->i_ctime
= CURRENT_TIME_SEC
;
66 mark_inode_dirty(inode
);
69 case EXT2_IOC_GETVERSION
:
70 return put_user(inode
->i_generation
, (int __user
*) arg
);
71 case EXT2_IOC_SETVERSION
:
72 if ((current
->fsuid
!= inode
->i_uid
) && !capable(CAP_FOWNER
))
76 if (get_user(inode
->i_generation
, (int __user
*) arg
))
78 inode
->i_ctime
= CURRENT_TIME_SEC
;
79 mark_inode_dirty(inode
);
87 long ext2_compat_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
89 struct inode
*inode
= file
->f_dentry
->d_inode
;
92 /* These are just misnamed, they actually get/put from/to user an int */
94 case EXT2_IOC32_GETFLAGS
:
95 cmd
= EXT2_IOC_GETFLAGS
;
97 case EXT2_IOC32_SETFLAGS
:
98 cmd
= EXT2_IOC_SETFLAGS
;
100 case EXT2_IOC32_GETVERSION
:
101 cmd
= EXT2_IOC_GETVERSION
;
103 case EXT2_IOC32_SETVERSION
:
104 cmd
= EXT2_IOC_SETVERSION
;
110 ret
= ext2_ioctl(inode
, file
, cmd
, (unsigned long) compat_ptr(arg
));