]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - fs/ext2/ioctl.c
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/mount.h>
16 #include <asm/current.h>
17 #include <linux/uaccess.h>
20 long ext2_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
)
22 struct inode
*inode
= file_inode(filp
);
23 struct ext2_inode_info
*ei
= EXT2_I(inode
);
25 unsigned short rsv_window_size
;
28 ext2_debug ("cmd = %u, arg = %lu\n", cmd
, arg
);
31 case EXT2_IOC_GETFLAGS
:
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
;
37 ret
= mnt_want_write_file(filp
);
41 if (!inode_owner_or_capable(inode
)) {
46 if (get_user(flags
, (int __user
*) arg
)) {
51 flags
= ext2_mask_flags(inode
->i_mode
, flags
);
54 /* Is it quota file? Do not allow user to mess with it */
55 if (IS_NOQUOTA(inode
)) {
60 oldflags
= ei
->i_flags
;
63 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
64 * the relevant capability.
66 * This test looks nicer. Thanks to Pauline Middelink
68 if ((flags
^ oldflags
) & (EXT2_APPEND_FL
| EXT2_IMMUTABLE_FL
)) {
69 if (!capable(CAP_LINUX_IMMUTABLE
)) {
76 flags
= flags
& EXT2_FL_USER_MODIFIABLE
;
77 flags
|= oldflags
& ~EXT2_FL_USER_MODIFIABLE
;
80 ext2_set_inode_flags(inode
);
81 inode
->i_ctime
= current_time(inode
);
84 mark_inode_dirty(inode
);
86 mnt_drop_write_file(filp
);
89 case EXT2_IOC_GETVERSION
:
90 return put_user(inode
->i_generation
, (int __user
*) arg
);
91 case EXT2_IOC_SETVERSION
: {
94 if (!inode_owner_or_capable(inode
))
96 ret
= mnt_want_write_file(filp
);
99 if (get_user(generation
, (int __user
*) arg
)) {
105 inode
->i_ctime
= current_time(inode
);
106 inode
->i_generation
= generation
;
109 mark_inode_dirty(inode
);
111 mnt_drop_write_file(filp
);
114 case EXT2_IOC_GETRSVSZ
:
115 if (test_opt(inode
->i_sb
, RESERVATION
)
116 && S_ISREG(inode
->i_mode
)
117 && ei
->i_block_alloc_info
) {
118 rsv_window_size
= ei
->i_block_alloc_info
->rsv_window_node
.rsv_goal_size
;
119 return put_user(rsv_window_size
, (int __user
*)arg
);
122 case EXT2_IOC_SETRSVSZ
: {
124 if (!test_opt(inode
->i_sb
, RESERVATION
) ||!S_ISREG(inode
->i_mode
))
127 if (!inode_owner_or_capable(inode
))
130 if (get_user(rsv_window_size
, (int __user
*)arg
))
133 ret
= mnt_want_write_file(filp
);
137 if (rsv_window_size
> EXT2_MAX_RESERVE_BLOCKS
)
138 rsv_window_size
= EXT2_MAX_RESERVE_BLOCKS
;
141 * need to allocate reservation structure for this inode
142 * before set the window size
145 * XXX What lock should protect the rsv_goal_size?
146 * Accessed in ext2_get_block only. ext3 uses i_truncate.
148 mutex_lock(&ei
->truncate_mutex
);
149 if (!ei
->i_block_alloc_info
)
150 ext2_init_block_alloc_info(inode
);
152 if (ei
->i_block_alloc_info
){
153 struct ext2_reserve_window_node
*rsv
= &ei
->i_block_alloc_info
->rsv_window_node
;
154 rsv
->rsv_goal_size
= rsv_window_size
;
156 mutex_unlock(&ei
->truncate_mutex
);
157 mnt_drop_write_file(filp
);
166 long ext2_compat_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
168 /* These are just misnamed, they actually get/put from/to user an int */
170 case EXT2_IOC32_GETFLAGS
:
171 cmd
= EXT2_IOC_GETFLAGS
;
173 case EXT2_IOC32_SETFLAGS
:
174 cmd
= EXT2_IOC_SETFLAGS
;
176 case EXT2_IOC32_GETVERSION
:
177 cmd
= EXT2_IOC_GETVERSION
;
179 case EXT2_IOC32_SETVERSION
:
180 cmd
= EXT2_IOC_SETVERSION
;
185 return ext2_ioctl(file
, cmd
, (unsigned long) compat_ptr(arg
));