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/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
,
21 ext2_debug ("cmd = %u, arg = %lu\n", cmd
, arg
);
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
;
33 if ((current
->fsuid
!= inode
->i_uid
) && !capable(CAP_FOWNER
))
36 if (get_user(flags
, (int *) arg
))
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
))
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
;
59 inode
->i_flags
&= ~S_SYNC
;
60 if (flags
& EXT2_APPEND_FL
)
61 inode
->i_flags
|= S_APPEND
;
63 inode
->i_flags
&= ~S_APPEND
;
64 if (flags
& EXT2_IMMUTABLE_FL
)
65 inode
->i_flags
|= S_IMMUTABLE
;
67 inode
->i_flags
&= ~S_IMMUTABLE
;
68 if (flags
& EXT2_NOATIME_FL
)
69 inode
->i_flags
|= S_NOATIME
;
71 inode
->i_flags
&= ~S_NOATIME
;
72 inode
->i_ctime
= CURRENT_TIME
;
73 mark_inode_dirty(inode
);
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
))
83 if (get_user(inode
->i_generation
, (int *) arg
))
85 inode
->i_ctime
= CURRENT_TIME
;
86 mark_inode_dirty(inode
);