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
);
25 unsigned short rsv_window_size
;
27 ext2_debug ("cmd = %u, arg = %lu\n", cmd
, arg
);
30 case EXT2_IOC_GETFLAGS
:
31 ext2_get_inode_flags(ei
);
32 flags
= ei
->i_flags
& EXT2_FL_USER_VISIBLE
;
33 return put_user(flags
, (int __user
*) arg
);
34 case EXT2_IOC_SETFLAGS
: {
35 unsigned int oldflags
;
40 if (!is_owner_or_cap(inode
))
43 if (get_user(flags
, (int __user
*) arg
))
46 if (!S_ISDIR(inode
->i_mode
))
47 flags
&= ~EXT2_DIRSYNC_FL
;
49 mutex_lock(&inode
->i_mutex
);
50 oldflags
= ei
->i_flags
;
53 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
54 * the relevant capability.
56 * This test looks nicer. Thanks to Pauline Middelink
58 if ((flags
^ oldflags
) & (EXT2_APPEND_FL
| EXT2_IMMUTABLE_FL
)) {
59 if (!capable(CAP_LINUX_IMMUTABLE
)) {
60 mutex_unlock(&inode
->i_mutex
);
65 flags
= flags
& EXT2_FL_USER_MODIFIABLE
;
66 flags
|= oldflags
& ~EXT2_FL_USER_MODIFIABLE
;
68 mutex_unlock(&inode
->i_mutex
);
70 ext2_set_inode_flags(inode
);
71 inode
->i_ctime
= CURRENT_TIME_SEC
;
72 mark_inode_dirty(inode
);
75 case EXT2_IOC_GETVERSION
:
76 return put_user(inode
->i_generation
, (int __user
*) arg
);
77 case EXT2_IOC_SETVERSION
:
78 if (!is_owner_or_cap(inode
))
82 if (get_user(inode
->i_generation
, (int __user
*) arg
))
84 inode
->i_ctime
= CURRENT_TIME_SEC
;
85 mark_inode_dirty(inode
);
87 case EXT2_IOC_GETRSVSZ
:
88 if (test_opt(inode
->i_sb
, RESERVATION
)
89 && S_ISREG(inode
->i_mode
)
90 && ei
->i_block_alloc_info
) {
91 rsv_window_size
= ei
->i_block_alloc_info
->rsv_window_node
.rsv_goal_size
;
92 return put_user(rsv_window_size
, (int __user
*)arg
);
95 case EXT2_IOC_SETRSVSZ
: {
97 if (!test_opt(inode
->i_sb
, RESERVATION
) ||!S_ISREG(inode
->i_mode
))
100 if (IS_RDONLY(inode
))
103 if ((current
->fsuid
!= inode
->i_uid
) && !capable(CAP_FOWNER
))
106 if (get_user(rsv_window_size
, (int __user
*)arg
))
109 if (rsv_window_size
> EXT2_MAX_RESERVE_BLOCKS
)
110 rsv_window_size
= EXT2_MAX_RESERVE_BLOCKS
;
113 * need to allocate reservation structure for this inode
114 * before set the window size
117 * XXX What lock should protect the rsv_goal_size?
118 * Accessed in ext2_get_block only. ext3 uses i_truncate.
120 mutex_lock(&ei
->truncate_mutex
);
121 if (!ei
->i_block_alloc_info
)
122 ext2_init_block_alloc_info(inode
);
124 if (ei
->i_block_alloc_info
){
125 struct ext2_reserve_window_node
*rsv
= &ei
->i_block_alloc_info
->rsv_window_node
;
126 rsv
->rsv_goal_size
= rsv_window_size
;
128 mutex_unlock(&ei
->truncate_mutex
);
137 long ext2_compat_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
139 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
142 /* These are just misnamed, they actually get/put from/to user an int */
144 case EXT2_IOC32_GETFLAGS
:
145 cmd
= EXT2_IOC_GETFLAGS
;
147 case EXT2_IOC32_SETFLAGS
:
148 cmd
= EXT2_IOC_SETFLAGS
;
150 case EXT2_IOC32_GETVERSION
:
151 cmd
= EXT2_IOC_GETVERSION
;
153 case EXT2_IOC32_SETVERSION
:
154 cmd
= EXT2_IOC_SETVERSION
;
160 ret
= ext2_ioctl(inode
, file
, cmd
, (unsigned long) compat_ptr(arg
));