Blame view
fs/ext2/ioctl.c
4.25 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 |
/* * linux/fs/ext2/ioctl.c * * Copyright (C) 1993, 1994, 1995 * Remy Card (card@masi.ibp.fr) * Laboratoire MASI - Institut Blaise Pascal * Universite Pierre et Marie Curie (Paris VI) */ #include "ext2.h" |
16f7e0fe2 [PATCH] capable/c... |
11 |
#include <linux/capability.h> |
1da177e4c Linux-2.6.12-rc2 |
12 13 |
#include <linux/time.h> #include <linux/sched.h> |
e322ff07f [PATCH] BLOCK: Mo... |
14 |
#include <linux/compat.h> |
42a74f206 [PATCH] r/o bind ... |
15 |
#include <linux/mount.h> |
1da177e4c Linux-2.6.12-rc2 |
16 17 |
#include <asm/current.h> #include <asm/uaccess.h> |
14f9f7b28 BKL-removal: conv... |
18 |
long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
1da177e4c Linux-2.6.12-rc2 |
19 |
{ |
14f9f7b28 BKL-removal: conv... |
20 |
struct inode *inode = filp->f_dentry->d_inode; |
1da177e4c Linux-2.6.12-rc2 |
21 22 |
struct ext2_inode_info *ei = EXT2_I(inode); unsigned int flags; |
a686cd898 ext2 reservations |
23 |
unsigned short rsv_window_size; |
42a74f206 [PATCH] r/o bind ... |
24 |
int ret; |
1da177e4c Linux-2.6.12-rc2 |
25 26 27 28 29 30 |
ext2_debug ("cmd = %u, arg = %lu ", cmd, arg); switch (cmd) { case EXT2_IOC_GETFLAGS: |
4f99ed67c ext3: copy i_flag... |
31 |
ext2_get_inode_flags(ei); |
1da177e4c Linux-2.6.12-rc2 |
32 33 34 35 |
flags = ei->i_flags & EXT2_FL_USER_VISIBLE; return put_user(flags, (int __user *) arg); case EXT2_IOC_SETFLAGS: { unsigned int oldflags; |
a561be710 switch a bunch of... |
36 |
ret = mnt_want_write_file(filp); |
42a74f206 [PATCH] r/o bind ... |
37 38 |
if (ret) return ret; |
1da177e4c Linux-2.6.12-rc2 |
39 |
|
2e1496707 userns: rename is... |
40 |
if (!inode_owner_or_capable(inode)) { |
42a74f206 [PATCH] r/o bind ... |
41 42 43 |
ret = -EACCES; goto setflags_out; } |
1da177e4c Linux-2.6.12-rc2 |
44 |
|
42a74f206 [PATCH] r/o bind ... |
45 46 47 48 |
if (get_user(flags, (int __user *) arg)) { ret = -EFAULT; goto setflags_out; } |
1da177e4c Linux-2.6.12-rc2 |
49 |
|
ef8b64618 ext2: tighten res... |
50 |
flags = ext2_mask_flags(inode->i_mode, flags); |
1da177e4c Linux-2.6.12-rc2 |
51 |
|
93f210dd9 [PATCH] protect e... |
52 |
mutex_lock(&inode->i_mutex); |
e47776a0a Forbid user to ch... |
53 54 55 |
/* Is it quota file? Do not allow user to mess with it */ if (IS_NOQUOTA(inode)) { mutex_unlock(&inode->i_mutex); |
42a74f206 [PATCH] r/o bind ... |
56 57 |
ret = -EPERM; goto setflags_out; |
e47776a0a Forbid user to ch... |
58 |
} |
1da177e4c Linux-2.6.12-rc2 |
59 60 61 62 63 64 65 66 67 |
oldflags = ei->i_flags; /* * The IMMUTABLE and APPEND_ONLY flags can only be changed by * the relevant capability. * * This test looks nicer. Thanks to Pauline Middelink */ if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) { |
93f210dd9 [PATCH] protect e... |
68 69 |
if (!capable(CAP_LINUX_IMMUTABLE)) { mutex_unlock(&inode->i_mutex); |
42a74f206 [PATCH] r/o bind ... |
70 71 |
ret = -EPERM; goto setflags_out; |
93f210dd9 [PATCH] protect e... |
72 |
} |
1da177e4c Linux-2.6.12-rc2 |
73 74 75 76 77 |
} flags = flags & EXT2_FL_USER_MODIFIABLE; flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE; ei->i_flags = flags; |
93f210dd9 [PATCH] protect e... |
78 |
mutex_unlock(&inode->i_mutex); |
1da177e4c Linux-2.6.12-rc2 |
79 80 81 82 |
ext2_set_inode_flags(inode); inode->i_ctime = CURRENT_TIME_SEC; mark_inode_dirty(inode); |
42a74f206 [PATCH] r/o bind ... |
83 |
setflags_out: |
2a79f17e4 vfs: mnt_drop_wri... |
84 |
mnt_drop_write_file(filp); |
42a74f206 [PATCH] r/o bind ... |
85 |
return ret; |
1da177e4c Linux-2.6.12-rc2 |
86 87 88 89 |
} case EXT2_IOC_GETVERSION: return put_user(inode->i_generation, (int __user *) arg); case EXT2_IOC_SETVERSION: |
2e1496707 userns: rename is... |
90 |
if (!inode_owner_or_capable(inode)) |
1da177e4c Linux-2.6.12-rc2 |
91 |
return -EPERM; |
a561be710 switch a bunch of... |
92 |
ret = mnt_want_write_file(filp); |
42a74f206 [PATCH] r/o bind ... |
93 94 95 96 97 98 99 100 |
if (ret) return ret; if (get_user(inode->i_generation, (int __user *) arg)) { ret = -EFAULT; } else { inode->i_ctime = CURRENT_TIME_SEC; mark_inode_dirty(inode); } |
2a79f17e4 vfs: mnt_drop_wri... |
101 |
mnt_drop_write_file(filp); |
42a74f206 [PATCH] r/o bind ... |
102 |
return ret; |
a686cd898 ext2 reservations |
103 104 105 106 107 108 109 110 111 112 113 114 |
case EXT2_IOC_GETRSVSZ: if (test_opt(inode->i_sb, RESERVATION) && S_ISREG(inode->i_mode) && ei->i_block_alloc_info) { rsv_window_size = ei->i_block_alloc_info->rsv_window_node.rsv_goal_size; return put_user(rsv_window_size, (int __user *)arg); } return -ENOTTY; case EXT2_IOC_SETRSVSZ: { if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode)) return -ENOTTY; |
2e1496707 userns: rename is... |
115 |
if (!inode_owner_or_capable(inode)) |
a686cd898 ext2 reservations |
116 117 118 119 |
return -EACCES; if (get_user(rsv_window_size, (int __user *)arg)) return -EFAULT; |
a561be710 switch a bunch of... |
120 |
ret = mnt_want_write_file(filp); |
42a74f206 [PATCH] r/o bind ... |
121 122 |
if (ret) return ret; |
a686cd898 ext2 reservations |
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
if (rsv_window_size > EXT2_MAX_RESERVE_BLOCKS) rsv_window_size = EXT2_MAX_RESERVE_BLOCKS; /* * need to allocate reservation structure for this inode * before set the window size */ /* * XXX What lock should protect the rsv_goal_size? * Accessed in ext2_get_block only. ext3 uses i_truncate. */ mutex_lock(&ei->truncate_mutex); if (!ei->i_block_alloc_info) ext2_init_block_alloc_info(inode); if (ei->i_block_alloc_info){ struct ext2_reserve_window_node *rsv = &ei->i_block_alloc_info->rsv_window_node; rsv->rsv_goal_size = rsv_window_size; } mutex_unlock(&ei->truncate_mutex); |
2a79f17e4 vfs: mnt_drop_wri... |
143 |
mnt_drop_write_file(filp); |
a686cd898 ext2 reservations |
144 145 |
return 0; } |
1da177e4c Linux-2.6.12-rc2 |
146 147 148 149 |
default: return -ENOTTY; } } |
e322ff07f [PATCH] BLOCK: Mo... |
150 151 152 153 |
#ifdef CONFIG_COMPAT long ext2_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { |
e322ff07f [PATCH] BLOCK: Mo... |
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
/* These are just misnamed, they actually get/put from/to user an int */ switch (cmd) { case EXT2_IOC32_GETFLAGS: cmd = EXT2_IOC_GETFLAGS; break; case EXT2_IOC32_SETFLAGS: cmd = EXT2_IOC_SETFLAGS; break; case EXT2_IOC32_GETVERSION: cmd = EXT2_IOC_GETVERSION; break; case EXT2_IOC32_SETVERSION: cmd = EXT2_IOC_SETVERSION; break; default: return -ENOIOCTLCMD; } |
14f9f7b28 BKL-removal: conv... |
171 |
return ext2_ioctl(file, cmd, (unsigned long) compat_ptr(arg)); |
e322ff07f [PATCH] BLOCK: Mo... |
172 173 |
} #endif |