Commit d30a2605be9d5132d95944916e8f578fcfe4f976

Authored by David Woodhouse
Committed by Jens Axboe
1 parent 2ebca85abc

Add BLKDISCARD ioctl to allow userspace to discard sectors

We may well want mkfs tools to use this to mark the whole device as
unwanted before they format it, for example.

The ioctl takes a pair of uint64_ts, which are start offset and length
in _bytes_. Although at the moment it might make sense for them both to
be in 512-byte sectors, I don't want to limit the ABI to that.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>

Showing 3 changed files with 78 additions and 0 deletions Inline Diff

block/compat_ioctl.c
1 #include <linux/blkdev.h> 1 #include <linux/blkdev.h>
2 #include <linux/blkpg.h> 2 #include <linux/blkpg.h>
3 #include <linux/blktrace_api.h> 3 #include <linux/blktrace_api.h>
4 #include <linux/cdrom.h> 4 #include <linux/cdrom.h>
5 #include <linux/compat.h> 5 #include <linux/compat.h>
6 #include <linux/elevator.h> 6 #include <linux/elevator.h>
7 #include <linux/fd.h> 7 #include <linux/fd.h>
8 #include <linux/hdreg.h> 8 #include <linux/hdreg.h>
9 #include <linux/syscalls.h> 9 #include <linux/syscalls.h>
10 #include <linux/smp_lock.h> 10 #include <linux/smp_lock.h>
11 #include <linux/types.h> 11 #include <linux/types.h>
12 #include <linux/uaccess.h> 12 #include <linux/uaccess.h>
13 13
14 static int compat_put_ushort(unsigned long arg, unsigned short val) 14 static int compat_put_ushort(unsigned long arg, unsigned short val)
15 { 15 {
16 return put_user(val, (unsigned short __user *)compat_ptr(arg)); 16 return put_user(val, (unsigned short __user *)compat_ptr(arg));
17 } 17 }
18 18
19 static int compat_put_int(unsigned long arg, int val) 19 static int compat_put_int(unsigned long arg, int val)
20 { 20 {
21 return put_user(val, (compat_int_t __user *)compat_ptr(arg)); 21 return put_user(val, (compat_int_t __user *)compat_ptr(arg));
22 } 22 }
23 23
24 static int compat_put_long(unsigned long arg, long val) 24 static int compat_put_long(unsigned long arg, long val)
25 { 25 {
26 return put_user(val, (compat_long_t __user *)compat_ptr(arg)); 26 return put_user(val, (compat_long_t __user *)compat_ptr(arg));
27 } 27 }
28 28
29 static int compat_put_ulong(unsigned long arg, compat_ulong_t val) 29 static int compat_put_ulong(unsigned long arg, compat_ulong_t val)
30 { 30 {
31 return put_user(val, (compat_ulong_t __user *)compat_ptr(arg)); 31 return put_user(val, (compat_ulong_t __user *)compat_ptr(arg));
32 } 32 }
33 33
34 static int compat_put_u64(unsigned long arg, u64 val) 34 static int compat_put_u64(unsigned long arg, u64 val)
35 { 35 {
36 return put_user(val, (compat_u64 __user *)compat_ptr(arg)); 36 return put_user(val, (compat_u64 __user *)compat_ptr(arg));
37 } 37 }
38 38
39 struct compat_hd_geometry { 39 struct compat_hd_geometry {
40 unsigned char heads; 40 unsigned char heads;
41 unsigned char sectors; 41 unsigned char sectors;
42 unsigned short cylinders; 42 unsigned short cylinders;
43 u32 start; 43 u32 start;
44 }; 44 };
45 45
46 static int compat_hdio_getgeo(struct gendisk *disk, struct block_device *bdev, 46 static int compat_hdio_getgeo(struct gendisk *disk, struct block_device *bdev,
47 struct compat_hd_geometry __user *ugeo) 47 struct compat_hd_geometry __user *ugeo)
48 { 48 {
49 struct hd_geometry geo; 49 struct hd_geometry geo;
50 int ret; 50 int ret;
51 51
52 if (!ugeo) 52 if (!ugeo)
53 return -EINVAL; 53 return -EINVAL;
54 if (!disk->fops->getgeo) 54 if (!disk->fops->getgeo)
55 return -ENOTTY; 55 return -ENOTTY;
56 56
57 /* 57 /*
58 * We need to set the startsect first, the driver may 58 * We need to set the startsect first, the driver may
59 * want to override it. 59 * want to override it.
60 */ 60 */
61 geo.start = get_start_sect(bdev); 61 geo.start = get_start_sect(bdev);
62 ret = disk->fops->getgeo(bdev, &geo); 62 ret = disk->fops->getgeo(bdev, &geo);
63 if (ret) 63 if (ret)
64 return ret; 64 return ret;
65 65
66 ret = copy_to_user(ugeo, &geo, 4); 66 ret = copy_to_user(ugeo, &geo, 4);
67 ret |= __put_user(geo.start, &ugeo->start); 67 ret |= __put_user(geo.start, &ugeo->start);
68 if (ret) 68 if (ret)
69 ret = -EFAULT; 69 ret = -EFAULT;
70 70
71 return ret; 71 return ret;
72 } 72 }
73 73
74 static int compat_hdio_ioctl(struct inode *inode, struct file *file, 74 static int compat_hdio_ioctl(struct inode *inode, struct file *file,
75 struct gendisk *disk, unsigned int cmd, unsigned long arg) 75 struct gendisk *disk, unsigned int cmd, unsigned long arg)
76 { 76 {
77 mm_segment_t old_fs = get_fs(); 77 mm_segment_t old_fs = get_fs();
78 unsigned long kval; 78 unsigned long kval;
79 unsigned int __user *uvp; 79 unsigned int __user *uvp;
80 int error; 80 int error;
81 81
82 set_fs(KERNEL_DS); 82 set_fs(KERNEL_DS);
83 error = blkdev_driver_ioctl(inode, file, disk, 83 error = blkdev_driver_ioctl(inode, file, disk,
84 cmd, (unsigned long)(&kval)); 84 cmd, (unsigned long)(&kval));
85 set_fs(old_fs); 85 set_fs(old_fs);
86 86
87 if (error == 0) { 87 if (error == 0) {
88 uvp = compat_ptr(arg); 88 uvp = compat_ptr(arg);
89 if (put_user(kval, uvp)) 89 if (put_user(kval, uvp))
90 error = -EFAULT; 90 error = -EFAULT;
91 } 91 }
92 return error; 92 return error;
93 } 93 }
94 94
95 struct compat_cdrom_read_audio { 95 struct compat_cdrom_read_audio {
96 union cdrom_addr addr; 96 union cdrom_addr addr;
97 u8 addr_format; 97 u8 addr_format;
98 compat_int_t nframes; 98 compat_int_t nframes;
99 compat_caddr_t buf; 99 compat_caddr_t buf;
100 }; 100 };
101 101
102 struct compat_cdrom_generic_command { 102 struct compat_cdrom_generic_command {
103 unsigned char cmd[CDROM_PACKET_SIZE]; 103 unsigned char cmd[CDROM_PACKET_SIZE];
104 compat_caddr_t buffer; 104 compat_caddr_t buffer;
105 compat_uint_t buflen; 105 compat_uint_t buflen;
106 compat_int_t stat; 106 compat_int_t stat;
107 compat_caddr_t sense; 107 compat_caddr_t sense;
108 unsigned char data_direction; 108 unsigned char data_direction;
109 compat_int_t quiet; 109 compat_int_t quiet;
110 compat_int_t timeout; 110 compat_int_t timeout;
111 compat_caddr_t reserved[1]; 111 compat_caddr_t reserved[1];
112 }; 112 };
113 113
114 static int compat_cdrom_read_audio(struct inode *inode, struct file *file, 114 static int compat_cdrom_read_audio(struct inode *inode, struct file *file,
115 struct gendisk *disk, unsigned int cmd, unsigned long arg) 115 struct gendisk *disk, unsigned int cmd, unsigned long arg)
116 { 116 {
117 struct cdrom_read_audio __user *cdread_audio; 117 struct cdrom_read_audio __user *cdread_audio;
118 struct compat_cdrom_read_audio __user *cdread_audio32; 118 struct compat_cdrom_read_audio __user *cdread_audio32;
119 __u32 data; 119 __u32 data;
120 void __user *datap; 120 void __user *datap;
121 121
122 cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio)); 122 cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio));
123 cdread_audio32 = compat_ptr(arg); 123 cdread_audio32 = compat_ptr(arg);
124 124
125 if (copy_in_user(&cdread_audio->addr, 125 if (copy_in_user(&cdread_audio->addr,
126 &cdread_audio32->addr, 126 &cdread_audio32->addr,
127 (sizeof(*cdread_audio32) - 127 (sizeof(*cdread_audio32) -
128 sizeof(compat_caddr_t)))) 128 sizeof(compat_caddr_t))))
129 return -EFAULT; 129 return -EFAULT;
130 130
131 if (get_user(data, &cdread_audio32->buf)) 131 if (get_user(data, &cdread_audio32->buf))
132 return -EFAULT; 132 return -EFAULT;
133 datap = compat_ptr(data); 133 datap = compat_ptr(data);
134 if (put_user(datap, &cdread_audio->buf)) 134 if (put_user(datap, &cdread_audio->buf))
135 return -EFAULT; 135 return -EFAULT;
136 136
137 return blkdev_driver_ioctl(inode, file, disk, cmd, 137 return blkdev_driver_ioctl(inode, file, disk, cmd,
138 (unsigned long)cdread_audio); 138 (unsigned long)cdread_audio);
139 } 139 }
140 140
141 static int compat_cdrom_generic_command(struct inode *inode, struct file *file, 141 static int compat_cdrom_generic_command(struct inode *inode, struct file *file,
142 struct gendisk *disk, unsigned int cmd, unsigned long arg) 142 struct gendisk *disk, unsigned int cmd, unsigned long arg)
143 { 143 {
144 struct cdrom_generic_command __user *cgc; 144 struct cdrom_generic_command __user *cgc;
145 struct compat_cdrom_generic_command __user *cgc32; 145 struct compat_cdrom_generic_command __user *cgc32;
146 u32 data; 146 u32 data;
147 unsigned char dir; 147 unsigned char dir;
148 int itmp; 148 int itmp;
149 149
150 cgc = compat_alloc_user_space(sizeof(*cgc)); 150 cgc = compat_alloc_user_space(sizeof(*cgc));
151 cgc32 = compat_ptr(arg); 151 cgc32 = compat_ptr(arg);
152 152
153 if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) || 153 if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
154 get_user(data, &cgc32->buffer) || 154 get_user(data, &cgc32->buffer) ||
155 put_user(compat_ptr(data), &cgc->buffer) || 155 put_user(compat_ptr(data), &cgc->buffer) ||
156 copy_in_user(&cgc->buflen, &cgc32->buflen, 156 copy_in_user(&cgc->buflen, &cgc32->buflen,
157 (sizeof(unsigned int) + sizeof(int))) || 157 (sizeof(unsigned int) + sizeof(int))) ||
158 get_user(data, &cgc32->sense) || 158 get_user(data, &cgc32->sense) ||
159 put_user(compat_ptr(data), &cgc->sense) || 159 put_user(compat_ptr(data), &cgc->sense) ||
160 get_user(dir, &cgc32->data_direction) || 160 get_user(dir, &cgc32->data_direction) ||
161 put_user(dir, &cgc->data_direction) || 161 put_user(dir, &cgc->data_direction) ||
162 get_user(itmp, &cgc32->quiet) || 162 get_user(itmp, &cgc32->quiet) ||
163 put_user(itmp, &cgc->quiet) || 163 put_user(itmp, &cgc->quiet) ||
164 get_user(itmp, &cgc32->timeout) || 164 get_user(itmp, &cgc32->timeout) ||
165 put_user(itmp, &cgc->timeout) || 165 put_user(itmp, &cgc->timeout) ||
166 get_user(data, &cgc32->reserved[0]) || 166 get_user(data, &cgc32->reserved[0]) ||
167 put_user(compat_ptr(data), &cgc->reserved[0])) 167 put_user(compat_ptr(data), &cgc->reserved[0]))
168 return -EFAULT; 168 return -EFAULT;
169 169
170 return blkdev_driver_ioctl(inode, file, disk, cmd, (unsigned long)cgc); 170 return blkdev_driver_ioctl(inode, file, disk, cmd, (unsigned long)cgc);
171 } 171 }
172 172
173 struct compat_blkpg_ioctl_arg { 173 struct compat_blkpg_ioctl_arg {
174 compat_int_t op; 174 compat_int_t op;
175 compat_int_t flags; 175 compat_int_t flags;
176 compat_int_t datalen; 176 compat_int_t datalen;
177 compat_caddr_t data; 177 compat_caddr_t data;
178 }; 178 };
179 179
180 static int compat_blkpg_ioctl(struct inode *inode, struct file *file, 180 static int compat_blkpg_ioctl(struct inode *inode, struct file *file,
181 unsigned int cmd, struct compat_blkpg_ioctl_arg __user *ua32) 181 unsigned int cmd, struct compat_blkpg_ioctl_arg __user *ua32)
182 { 182 {
183 struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a)); 183 struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a));
184 compat_caddr_t udata; 184 compat_caddr_t udata;
185 compat_int_t n; 185 compat_int_t n;
186 int err; 186 int err;
187 187
188 err = get_user(n, &ua32->op); 188 err = get_user(n, &ua32->op);
189 err |= put_user(n, &a->op); 189 err |= put_user(n, &a->op);
190 err |= get_user(n, &ua32->flags); 190 err |= get_user(n, &ua32->flags);
191 err |= put_user(n, &a->flags); 191 err |= put_user(n, &a->flags);
192 err |= get_user(n, &ua32->datalen); 192 err |= get_user(n, &ua32->datalen);
193 err |= put_user(n, &a->datalen); 193 err |= put_user(n, &a->datalen);
194 err |= get_user(udata, &ua32->data); 194 err |= get_user(udata, &ua32->data);
195 err |= put_user(compat_ptr(udata), &a->data); 195 err |= put_user(compat_ptr(udata), &a->data);
196 if (err) 196 if (err)
197 return err; 197 return err;
198 198
199 return blkdev_ioctl(inode, file, cmd, (unsigned long)a); 199 return blkdev_ioctl(inode, file, cmd, (unsigned long)a);
200 } 200 }
201 201
202 #define BLKBSZGET_32 _IOR(0x12, 112, int) 202 #define BLKBSZGET_32 _IOR(0x12, 112, int)
203 #define BLKBSZSET_32 _IOW(0x12, 113, int) 203 #define BLKBSZSET_32 _IOW(0x12, 113, int)
204 #define BLKGETSIZE64_32 _IOR(0x12, 114, int) 204 #define BLKGETSIZE64_32 _IOR(0x12, 114, int)
205 205
206 struct compat_floppy_struct { 206 struct compat_floppy_struct {
207 compat_uint_t size; 207 compat_uint_t size;
208 compat_uint_t sect; 208 compat_uint_t sect;
209 compat_uint_t head; 209 compat_uint_t head;
210 compat_uint_t track; 210 compat_uint_t track;
211 compat_uint_t stretch; 211 compat_uint_t stretch;
212 unsigned char gap; 212 unsigned char gap;
213 unsigned char rate; 213 unsigned char rate;
214 unsigned char spec1; 214 unsigned char spec1;
215 unsigned char fmt_gap; 215 unsigned char fmt_gap;
216 const compat_caddr_t name; 216 const compat_caddr_t name;
217 }; 217 };
218 218
219 struct compat_floppy_drive_params { 219 struct compat_floppy_drive_params {
220 char cmos; 220 char cmos;
221 compat_ulong_t max_dtr; 221 compat_ulong_t max_dtr;
222 compat_ulong_t hlt; 222 compat_ulong_t hlt;
223 compat_ulong_t hut; 223 compat_ulong_t hut;
224 compat_ulong_t srt; 224 compat_ulong_t srt;
225 compat_ulong_t spinup; 225 compat_ulong_t spinup;
226 compat_ulong_t spindown; 226 compat_ulong_t spindown;
227 unsigned char spindown_offset; 227 unsigned char spindown_offset;
228 unsigned char select_delay; 228 unsigned char select_delay;
229 unsigned char rps; 229 unsigned char rps;
230 unsigned char tracks; 230 unsigned char tracks;
231 compat_ulong_t timeout; 231 compat_ulong_t timeout;
232 unsigned char interleave_sect; 232 unsigned char interleave_sect;
233 struct floppy_max_errors max_errors; 233 struct floppy_max_errors max_errors;
234 char flags; 234 char flags;
235 char read_track; 235 char read_track;
236 short autodetect[8]; 236 short autodetect[8];
237 compat_int_t checkfreq; 237 compat_int_t checkfreq;
238 compat_int_t native_format; 238 compat_int_t native_format;
239 }; 239 };
240 240
241 struct compat_floppy_drive_struct { 241 struct compat_floppy_drive_struct {
242 signed char flags; 242 signed char flags;
243 compat_ulong_t spinup_date; 243 compat_ulong_t spinup_date;
244 compat_ulong_t select_date; 244 compat_ulong_t select_date;
245 compat_ulong_t first_read_date; 245 compat_ulong_t first_read_date;
246 short probed_format; 246 short probed_format;
247 short track; 247 short track;
248 short maxblock; 248 short maxblock;
249 short maxtrack; 249 short maxtrack;
250 compat_int_t generation; 250 compat_int_t generation;
251 compat_int_t keep_data; 251 compat_int_t keep_data;
252 compat_int_t fd_ref; 252 compat_int_t fd_ref;
253 compat_int_t fd_device; 253 compat_int_t fd_device;
254 compat_int_t last_checked; 254 compat_int_t last_checked;
255 compat_caddr_t dmabuf; 255 compat_caddr_t dmabuf;
256 compat_int_t bufblocks; 256 compat_int_t bufblocks;
257 }; 257 };
258 258
259 struct compat_floppy_fdc_state { 259 struct compat_floppy_fdc_state {
260 compat_int_t spec1; 260 compat_int_t spec1;
261 compat_int_t spec2; 261 compat_int_t spec2;
262 compat_int_t dtr; 262 compat_int_t dtr;
263 unsigned char version; 263 unsigned char version;
264 unsigned char dor; 264 unsigned char dor;
265 compat_ulong_t address; 265 compat_ulong_t address;
266 unsigned int rawcmd:2; 266 unsigned int rawcmd:2;
267 unsigned int reset:1; 267 unsigned int reset:1;
268 unsigned int need_configure:1; 268 unsigned int need_configure:1;
269 unsigned int perp_mode:2; 269 unsigned int perp_mode:2;
270 unsigned int has_fifo:1; 270 unsigned int has_fifo:1;
271 unsigned int driver_version; 271 unsigned int driver_version;
272 unsigned char track[4]; 272 unsigned char track[4];
273 }; 273 };
274 274
275 struct compat_floppy_write_errors { 275 struct compat_floppy_write_errors {
276 unsigned int write_errors; 276 unsigned int write_errors;
277 compat_ulong_t first_error_sector; 277 compat_ulong_t first_error_sector;
278 compat_int_t first_error_generation; 278 compat_int_t first_error_generation;
279 compat_ulong_t last_error_sector; 279 compat_ulong_t last_error_sector;
280 compat_int_t last_error_generation; 280 compat_int_t last_error_generation;
281 compat_uint_t badness; 281 compat_uint_t badness;
282 }; 282 };
283 283
284 #define FDSETPRM32 _IOW(2, 0x42, struct compat_floppy_struct) 284 #define FDSETPRM32 _IOW(2, 0x42, struct compat_floppy_struct)
285 #define FDDEFPRM32 _IOW(2, 0x43, struct compat_floppy_struct) 285 #define FDDEFPRM32 _IOW(2, 0x43, struct compat_floppy_struct)
286 #define FDGETPRM32 _IOR(2, 0x04, struct compat_floppy_struct) 286 #define FDGETPRM32 _IOR(2, 0x04, struct compat_floppy_struct)
287 #define FDSETDRVPRM32 _IOW(2, 0x90, struct compat_floppy_drive_params) 287 #define FDSETDRVPRM32 _IOW(2, 0x90, struct compat_floppy_drive_params)
288 #define FDGETDRVPRM32 _IOR(2, 0x11, struct compat_floppy_drive_params) 288 #define FDGETDRVPRM32 _IOR(2, 0x11, struct compat_floppy_drive_params)
289 #define FDGETDRVSTAT32 _IOR(2, 0x12, struct compat_floppy_drive_struct) 289 #define FDGETDRVSTAT32 _IOR(2, 0x12, struct compat_floppy_drive_struct)
290 #define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct compat_floppy_drive_struct) 290 #define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct compat_floppy_drive_struct)
291 #define FDGETFDCSTAT32 _IOR(2, 0x15, struct compat_floppy_fdc_state) 291 #define FDGETFDCSTAT32 _IOR(2, 0x15, struct compat_floppy_fdc_state)
292 #define FDWERRORGET32 _IOR(2, 0x17, struct compat_floppy_write_errors) 292 #define FDWERRORGET32 _IOR(2, 0x17, struct compat_floppy_write_errors)
293 293
294 static struct { 294 static struct {
295 unsigned int cmd32; 295 unsigned int cmd32;
296 unsigned int cmd; 296 unsigned int cmd;
297 } fd_ioctl_trans_table[] = { 297 } fd_ioctl_trans_table[] = {
298 { FDSETPRM32, FDSETPRM }, 298 { FDSETPRM32, FDSETPRM },
299 { FDDEFPRM32, FDDEFPRM }, 299 { FDDEFPRM32, FDDEFPRM },
300 { FDGETPRM32, FDGETPRM }, 300 { FDGETPRM32, FDGETPRM },
301 { FDSETDRVPRM32, FDSETDRVPRM }, 301 { FDSETDRVPRM32, FDSETDRVPRM },
302 { FDGETDRVPRM32, FDGETDRVPRM }, 302 { FDGETDRVPRM32, FDGETDRVPRM },
303 { FDGETDRVSTAT32, FDGETDRVSTAT }, 303 { FDGETDRVSTAT32, FDGETDRVSTAT },
304 { FDPOLLDRVSTAT32, FDPOLLDRVSTAT }, 304 { FDPOLLDRVSTAT32, FDPOLLDRVSTAT },
305 { FDGETFDCSTAT32, FDGETFDCSTAT }, 305 { FDGETFDCSTAT32, FDGETFDCSTAT },
306 { FDWERRORGET32, FDWERRORGET } 306 { FDWERRORGET32, FDWERRORGET }
307 }; 307 };
308 308
309 #define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table) 309 #define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table)
310 310
311 static int compat_fd_ioctl(struct inode *inode, struct file *file, 311 static int compat_fd_ioctl(struct inode *inode, struct file *file,
312 struct gendisk *disk, unsigned int cmd, unsigned long arg) 312 struct gendisk *disk, unsigned int cmd, unsigned long arg)
313 { 313 {
314 mm_segment_t old_fs = get_fs(); 314 mm_segment_t old_fs = get_fs();
315 void *karg = NULL; 315 void *karg = NULL;
316 unsigned int kcmd = 0; 316 unsigned int kcmd = 0;
317 int i, err; 317 int i, err;
318 318
319 for (i = 0; i < NR_FD_IOCTL_TRANS; i++) 319 for (i = 0; i < NR_FD_IOCTL_TRANS; i++)
320 if (cmd == fd_ioctl_trans_table[i].cmd32) { 320 if (cmd == fd_ioctl_trans_table[i].cmd32) {
321 kcmd = fd_ioctl_trans_table[i].cmd; 321 kcmd = fd_ioctl_trans_table[i].cmd;
322 break; 322 break;
323 } 323 }
324 if (!kcmd) 324 if (!kcmd)
325 return -EINVAL; 325 return -EINVAL;
326 326
327 switch (cmd) { 327 switch (cmd) {
328 case FDSETPRM32: 328 case FDSETPRM32:
329 case FDDEFPRM32: 329 case FDDEFPRM32:
330 case FDGETPRM32: 330 case FDGETPRM32:
331 { 331 {
332 compat_uptr_t name; 332 compat_uptr_t name;
333 struct compat_floppy_struct __user *uf; 333 struct compat_floppy_struct __user *uf;
334 struct floppy_struct *f; 334 struct floppy_struct *f;
335 335
336 uf = compat_ptr(arg); 336 uf = compat_ptr(arg);
337 f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL); 337 f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL);
338 if (!karg) 338 if (!karg)
339 return -ENOMEM; 339 return -ENOMEM;
340 if (cmd == FDGETPRM32) 340 if (cmd == FDGETPRM32)
341 break; 341 break;
342 err = __get_user(f->size, &uf->size); 342 err = __get_user(f->size, &uf->size);
343 err |= __get_user(f->sect, &uf->sect); 343 err |= __get_user(f->sect, &uf->sect);
344 err |= __get_user(f->head, &uf->head); 344 err |= __get_user(f->head, &uf->head);
345 err |= __get_user(f->track, &uf->track); 345 err |= __get_user(f->track, &uf->track);
346 err |= __get_user(f->stretch, &uf->stretch); 346 err |= __get_user(f->stretch, &uf->stretch);
347 err |= __get_user(f->gap, &uf->gap); 347 err |= __get_user(f->gap, &uf->gap);
348 err |= __get_user(f->rate, &uf->rate); 348 err |= __get_user(f->rate, &uf->rate);
349 err |= __get_user(f->spec1, &uf->spec1); 349 err |= __get_user(f->spec1, &uf->spec1);
350 err |= __get_user(f->fmt_gap, &uf->fmt_gap); 350 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
351 err |= __get_user(name, &uf->name); 351 err |= __get_user(name, &uf->name);
352 f->name = compat_ptr(name); 352 f->name = compat_ptr(name);
353 if (err) { 353 if (err) {
354 err = -EFAULT; 354 err = -EFAULT;
355 goto out; 355 goto out;
356 } 356 }
357 break; 357 break;
358 } 358 }
359 case FDSETDRVPRM32: 359 case FDSETDRVPRM32:
360 case FDGETDRVPRM32: 360 case FDGETDRVPRM32:
361 { 361 {
362 struct compat_floppy_drive_params __user *uf; 362 struct compat_floppy_drive_params __user *uf;
363 struct floppy_drive_params *f; 363 struct floppy_drive_params *f;
364 364
365 uf = compat_ptr(arg); 365 uf = compat_ptr(arg);
366 f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL); 366 f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL);
367 if (!karg) 367 if (!karg)
368 return -ENOMEM; 368 return -ENOMEM;
369 if (cmd == FDGETDRVPRM32) 369 if (cmd == FDGETDRVPRM32)
370 break; 370 break;
371 err = __get_user(f->cmos, &uf->cmos); 371 err = __get_user(f->cmos, &uf->cmos);
372 err |= __get_user(f->max_dtr, &uf->max_dtr); 372 err |= __get_user(f->max_dtr, &uf->max_dtr);
373 err |= __get_user(f->hlt, &uf->hlt); 373 err |= __get_user(f->hlt, &uf->hlt);
374 err |= __get_user(f->hut, &uf->hut); 374 err |= __get_user(f->hut, &uf->hut);
375 err |= __get_user(f->srt, &uf->srt); 375 err |= __get_user(f->srt, &uf->srt);
376 err |= __get_user(f->spinup, &uf->spinup); 376 err |= __get_user(f->spinup, &uf->spinup);
377 err |= __get_user(f->spindown, &uf->spindown); 377 err |= __get_user(f->spindown, &uf->spindown);
378 err |= __get_user(f->spindown_offset, &uf->spindown_offset); 378 err |= __get_user(f->spindown_offset, &uf->spindown_offset);
379 err |= __get_user(f->select_delay, &uf->select_delay); 379 err |= __get_user(f->select_delay, &uf->select_delay);
380 err |= __get_user(f->rps, &uf->rps); 380 err |= __get_user(f->rps, &uf->rps);
381 err |= __get_user(f->tracks, &uf->tracks); 381 err |= __get_user(f->tracks, &uf->tracks);
382 err |= __get_user(f->timeout, &uf->timeout); 382 err |= __get_user(f->timeout, &uf->timeout);
383 err |= __get_user(f->interleave_sect, &uf->interleave_sect); 383 err |= __get_user(f->interleave_sect, &uf->interleave_sect);
384 err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors)); 384 err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors));
385 err |= __get_user(f->flags, &uf->flags); 385 err |= __get_user(f->flags, &uf->flags);
386 err |= __get_user(f->read_track, &uf->read_track); 386 err |= __get_user(f->read_track, &uf->read_track);
387 err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect)); 387 err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect));
388 err |= __get_user(f->checkfreq, &uf->checkfreq); 388 err |= __get_user(f->checkfreq, &uf->checkfreq);
389 err |= __get_user(f->native_format, &uf->native_format); 389 err |= __get_user(f->native_format, &uf->native_format);
390 if (err) { 390 if (err) {
391 err = -EFAULT; 391 err = -EFAULT;
392 goto out; 392 goto out;
393 } 393 }
394 break; 394 break;
395 } 395 }
396 case FDGETDRVSTAT32: 396 case FDGETDRVSTAT32:
397 case FDPOLLDRVSTAT32: 397 case FDPOLLDRVSTAT32:
398 karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL); 398 karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL);
399 if (!karg) 399 if (!karg)
400 return -ENOMEM; 400 return -ENOMEM;
401 break; 401 break;
402 case FDGETFDCSTAT32: 402 case FDGETFDCSTAT32:
403 karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL); 403 karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL);
404 if (!karg) 404 if (!karg)
405 return -ENOMEM; 405 return -ENOMEM;
406 break; 406 break;
407 case FDWERRORGET32: 407 case FDWERRORGET32:
408 karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL); 408 karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL);
409 if (!karg) 409 if (!karg)
410 return -ENOMEM; 410 return -ENOMEM;
411 break; 411 break;
412 default: 412 default:
413 return -EINVAL; 413 return -EINVAL;
414 } 414 }
415 set_fs(KERNEL_DS); 415 set_fs(KERNEL_DS);
416 err = blkdev_driver_ioctl(inode, file, disk, kcmd, (unsigned long)karg); 416 err = blkdev_driver_ioctl(inode, file, disk, kcmd, (unsigned long)karg);
417 set_fs(old_fs); 417 set_fs(old_fs);
418 if (err) 418 if (err)
419 goto out; 419 goto out;
420 switch (cmd) { 420 switch (cmd) {
421 case FDGETPRM32: 421 case FDGETPRM32:
422 { 422 {
423 struct floppy_struct *f = karg; 423 struct floppy_struct *f = karg;
424 struct compat_floppy_struct __user *uf = compat_ptr(arg); 424 struct compat_floppy_struct __user *uf = compat_ptr(arg);
425 425
426 err = __put_user(f->size, &uf->size); 426 err = __put_user(f->size, &uf->size);
427 err |= __put_user(f->sect, &uf->sect); 427 err |= __put_user(f->sect, &uf->sect);
428 err |= __put_user(f->head, &uf->head); 428 err |= __put_user(f->head, &uf->head);
429 err |= __put_user(f->track, &uf->track); 429 err |= __put_user(f->track, &uf->track);
430 err |= __put_user(f->stretch, &uf->stretch); 430 err |= __put_user(f->stretch, &uf->stretch);
431 err |= __put_user(f->gap, &uf->gap); 431 err |= __put_user(f->gap, &uf->gap);
432 err |= __put_user(f->rate, &uf->rate); 432 err |= __put_user(f->rate, &uf->rate);
433 err |= __put_user(f->spec1, &uf->spec1); 433 err |= __put_user(f->spec1, &uf->spec1);
434 err |= __put_user(f->fmt_gap, &uf->fmt_gap); 434 err |= __put_user(f->fmt_gap, &uf->fmt_gap);
435 err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name); 435 err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name);
436 break; 436 break;
437 } 437 }
438 case FDGETDRVPRM32: 438 case FDGETDRVPRM32:
439 { 439 {
440 struct compat_floppy_drive_params __user *uf; 440 struct compat_floppy_drive_params __user *uf;
441 struct floppy_drive_params *f = karg; 441 struct floppy_drive_params *f = karg;
442 442
443 uf = compat_ptr(arg); 443 uf = compat_ptr(arg);
444 err = __put_user(f->cmos, &uf->cmos); 444 err = __put_user(f->cmos, &uf->cmos);
445 err |= __put_user(f->max_dtr, &uf->max_dtr); 445 err |= __put_user(f->max_dtr, &uf->max_dtr);
446 err |= __put_user(f->hlt, &uf->hlt); 446 err |= __put_user(f->hlt, &uf->hlt);
447 err |= __put_user(f->hut, &uf->hut); 447 err |= __put_user(f->hut, &uf->hut);
448 err |= __put_user(f->srt, &uf->srt); 448 err |= __put_user(f->srt, &uf->srt);
449 err |= __put_user(f->spinup, &uf->spinup); 449 err |= __put_user(f->spinup, &uf->spinup);
450 err |= __put_user(f->spindown, &uf->spindown); 450 err |= __put_user(f->spindown, &uf->spindown);
451 err |= __put_user(f->spindown_offset, &uf->spindown_offset); 451 err |= __put_user(f->spindown_offset, &uf->spindown_offset);
452 err |= __put_user(f->select_delay, &uf->select_delay); 452 err |= __put_user(f->select_delay, &uf->select_delay);
453 err |= __put_user(f->rps, &uf->rps); 453 err |= __put_user(f->rps, &uf->rps);
454 err |= __put_user(f->tracks, &uf->tracks); 454 err |= __put_user(f->tracks, &uf->tracks);
455 err |= __put_user(f->timeout, &uf->timeout); 455 err |= __put_user(f->timeout, &uf->timeout);
456 err |= __put_user(f->interleave_sect, &uf->interleave_sect); 456 err |= __put_user(f->interleave_sect, &uf->interleave_sect);
457 err |= __copy_to_user(&uf->max_errors, &f->max_errors, sizeof(f->max_errors)); 457 err |= __copy_to_user(&uf->max_errors, &f->max_errors, sizeof(f->max_errors));
458 err |= __put_user(f->flags, &uf->flags); 458 err |= __put_user(f->flags, &uf->flags);
459 err |= __put_user(f->read_track, &uf->read_track); 459 err |= __put_user(f->read_track, &uf->read_track);
460 err |= __copy_to_user(uf->autodetect, f->autodetect, sizeof(f->autodetect)); 460 err |= __copy_to_user(uf->autodetect, f->autodetect, sizeof(f->autodetect));
461 err |= __put_user(f->checkfreq, &uf->checkfreq); 461 err |= __put_user(f->checkfreq, &uf->checkfreq);
462 err |= __put_user(f->native_format, &uf->native_format); 462 err |= __put_user(f->native_format, &uf->native_format);
463 break; 463 break;
464 } 464 }
465 case FDGETDRVSTAT32: 465 case FDGETDRVSTAT32:
466 case FDPOLLDRVSTAT32: 466 case FDPOLLDRVSTAT32:
467 { 467 {
468 struct compat_floppy_drive_struct __user *uf; 468 struct compat_floppy_drive_struct __user *uf;
469 struct floppy_drive_struct *f = karg; 469 struct floppy_drive_struct *f = karg;
470 470
471 uf = compat_ptr(arg); 471 uf = compat_ptr(arg);
472 err = __put_user(f->flags, &uf->flags); 472 err = __put_user(f->flags, &uf->flags);
473 err |= __put_user(f->spinup_date, &uf->spinup_date); 473 err |= __put_user(f->spinup_date, &uf->spinup_date);
474 err |= __put_user(f->select_date, &uf->select_date); 474 err |= __put_user(f->select_date, &uf->select_date);
475 err |= __put_user(f->first_read_date, &uf->first_read_date); 475 err |= __put_user(f->first_read_date, &uf->first_read_date);
476 err |= __put_user(f->probed_format, &uf->probed_format); 476 err |= __put_user(f->probed_format, &uf->probed_format);
477 err |= __put_user(f->track, &uf->track); 477 err |= __put_user(f->track, &uf->track);
478 err |= __put_user(f->maxblock, &uf->maxblock); 478 err |= __put_user(f->maxblock, &uf->maxblock);
479 err |= __put_user(f->maxtrack, &uf->maxtrack); 479 err |= __put_user(f->maxtrack, &uf->maxtrack);
480 err |= __put_user(f->generation, &uf->generation); 480 err |= __put_user(f->generation, &uf->generation);
481 err |= __put_user(f->keep_data, &uf->keep_data); 481 err |= __put_user(f->keep_data, &uf->keep_data);
482 err |= __put_user(f->fd_ref, &uf->fd_ref); 482 err |= __put_user(f->fd_ref, &uf->fd_ref);
483 err |= __put_user(f->fd_device, &uf->fd_device); 483 err |= __put_user(f->fd_device, &uf->fd_device);
484 err |= __put_user(f->last_checked, &uf->last_checked); 484 err |= __put_user(f->last_checked, &uf->last_checked);
485 err |= __put_user((u64)f->dmabuf, &uf->dmabuf); 485 err |= __put_user((u64)f->dmabuf, &uf->dmabuf);
486 err |= __put_user((u64)f->bufblocks, &uf->bufblocks); 486 err |= __put_user((u64)f->bufblocks, &uf->bufblocks);
487 break; 487 break;
488 } 488 }
489 case FDGETFDCSTAT32: 489 case FDGETFDCSTAT32:
490 { 490 {
491 struct compat_floppy_fdc_state __user *uf; 491 struct compat_floppy_fdc_state __user *uf;
492 struct floppy_fdc_state *f = karg; 492 struct floppy_fdc_state *f = karg;
493 493
494 uf = compat_ptr(arg); 494 uf = compat_ptr(arg);
495 err = __put_user(f->spec1, &uf->spec1); 495 err = __put_user(f->spec1, &uf->spec1);
496 err |= __put_user(f->spec2, &uf->spec2); 496 err |= __put_user(f->spec2, &uf->spec2);
497 err |= __put_user(f->dtr, &uf->dtr); 497 err |= __put_user(f->dtr, &uf->dtr);
498 err |= __put_user(f->version, &uf->version); 498 err |= __put_user(f->version, &uf->version);
499 err |= __put_user(f->dor, &uf->dor); 499 err |= __put_user(f->dor, &uf->dor);
500 err |= __put_user(f->address, &uf->address); 500 err |= __put_user(f->address, &uf->address);
501 err |= __copy_to_user((char __user *)&uf->address + sizeof(uf->address), 501 err |= __copy_to_user((char __user *)&uf->address + sizeof(uf->address),
502 (char *)&f->address + sizeof(f->address), sizeof(int)); 502 (char *)&f->address + sizeof(f->address), sizeof(int));
503 err |= __put_user(f->driver_version, &uf->driver_version); 503 err |= __put_user(f->driver_version, &uf->driver_version);
504 err |= __copy_to_user(uf->track, f->track, sizeof(f->track)); 504 err |= __copy_to_user(uf->track, f->track, sizeof(f->track));
505 break; 505 break;
506 } 506 }
507 case FDWERRORGET32: 507 case FDWERRORGET32:
508 { 508 {
509 struct compat_floppy_write_errors __user *uf; 509 struct compat_floppy_write_errors __user *uf;
510 struct floppy_write_errors *f = karg; 510 struct floppy_write_errors *f = karg;
511 511
512 uf = compat_ptr(arg); 512 uf = compat_ptr(arg);
513 err = __put_user(f->write_errors, &uf->write_errors); 513 err = __put_user(f->write_errors, &uf->write_errors);
514 err |= __put_user(f->first_error_sector, &uf->first_error_sector); 514 err |= __put_user(f->first_error_sector, &uf->first_error_sector);
515 err |= __put_user(f->first_error_generation, &uf->first_error_generation); 515 err |= __put_user(f->first_error_generation, &uf->first_error_generation);
516 err |= __put_user(f->last_error_sector, &uf->last_error_sector); 516 err |= __put_user(f->last_error_sector, &uf->last_error_sector);
517 err |= __put_user(f->last_error_generation, &uf->last_error_generation); 517 err |= __put_user(f->last_error_generation, &uf->last_error_generation);
518 err |= __put_user(f->badness, &uf->badness); 518 err |= __put_user(f->badness, &uf->badness);
519 break; 519 break;
520 } 520 }
521 default: 521 default:
522 break; 522 break;
523 } 523 }
524 if (err) 524 if (err)
525 err = -EFAULT; 525 err = -EFAULT;
526 526
527 out: 527 out:
528 kfree(karg); 528 kfree(karg);
529 return err; 529 return err;
530 } 530 }
531 531
532 struct compat_blk_user_trace_setup { 532 struct compat_blk_user_trace_setup {
533 char name[32]; 533 char name[32];
534 u16 act_mask; 534 u16 act_mask;
535 u32 buf_size; 535 u32 buf_size;
536 u32 buf_nr; 536 u32 buf_nr;
537 compat_u64 start_lba; 537 compat_u64 start_lba;
538 compat_u64 end_lba; 538 compat_u64 end_lba;
539 u32 pid; 539 u32 pid;
540 }; 540 };
541 #define BLKTRACESETUP32 _IOWR(0x12, 115, struct compat_blk_user_trace_setup) 541 #define BLKTRACESETUP32 _IOWR(0x12, 115, struct compat_blk_user_trace_setup)
542 542
543 static int compat_blk_trace_setup(struct block_device *bdev, char __user *arg) 543 static int compat_blk_trace_setup(struct block_device *bdev, char __user *arg)
544 { 544 {
545 struct blk_user_trace_setup buts; 545 struct blk_user_trace_setup buts;
546 struct compat_blk_user_trace_setup cbuts; 546 struct compat_blk_user_trace_setup cbuts;
547 struct request_queue *q; 547 struct request_queue *q;
548 char b[BDEVNAME_SIZE]; 548 char b[BDEVNAME_SIZE];
549 int ret; 549 int ret;
550 550
551 q = bdev_get_queue(bdev); 551 q = bdev_get_queue(bdev);
552 if (!q) 552 if (!q)
553 return -ENXIO; 553 return -ENXIO;
554 554
555 if (copy_from_user(&cbuts, arg, sizeof(cbuts))) 555 if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
556 return -EFAULT; 556 return -EFAULT;
557 557
558 bdevname(bdev, b); 558 bdevname(bdev, b);
559 559
560 buts = (struct blk_user_trace_setup) { 560 buts = (struct blk_user_trace_setup) {
561 .act_mask = cbuts.act_mask, 561 .act_mask = cbuts.act_mask,
562 .buf_size = cbuts.buf_size, 562 .buf_size = cbuts.buf_size,
563 .buf_nr = cbuts.buf_nr, 563 .buf_nr = cbuts.buf_nr,
564 .start_lba = cbuts.start_lba, 564 .start_lba = cbuts.start_lba,
565 .end_lba = cbuts.end_lba, 565 .end_lba = cbuts.end_lba,
566 .pid = cbuts.pid, 566 .pid = cbuts.pid,
567 }; 567 };
568 memcpy(&buts.name, &cbuts.name, 32); 568 memcpy(&buts.name, &cbuts.name, 32);
569 569
570 mutex_lock(&bdev->bd_mutex); 570 mutex_lock(&bdev->bd_mutex);
571 ret = do_blk_trace_setup(q, b, bdev->bd_dev, &buts); 571 ret = do_blk_trace_setup(q, b, bdev->bd_dev, &buts);
572 mutex_unlock(&bdev->bd_mutex); 572 mutex_unlock(&bdev->bd_mutex);
573 if (ret) 573 if (ret)
574 return ret; 574 return ret;
575 575
576 if (copy_to_user(arg, &buts.name, 32)) 576 if (copy_to_user(arg, &buts.name, 32))
577 return -EFAULT; 577 return -EFAULT;
578 578
579 return 0; 579 return 0;
580 } 580 }
581 581
582 static int compat_blkdev_driver_ioctl(struct inode *inode, struct file *file, 582 static int compat_blkdev_driver_ioctl(struct inode *inode, struct file *file,
583 struct gendisk *disk, unsigned cmd, unsigned long arg) 583 struct gendisk *disk, unsigned cmd, unsigned long arg)
584 { 584 {
585 int ret; 585 int ret;
586 586
587 switch (cmd) { 587 switch (cmd) {
588 case HDIO_GET_UNMASKINTR: 588 case HDIO_GET_UNMASKINTR:
589 case HDIO_GET_MULTCOUNT: 589 case HDIO_GET_MULTCOUNT:
590 case HDIO_GET_KEEPSETTINGS: 590 case HDIO_GET_KEEPSETTINGS:
591 case HDIO_GET_32BIT: 591 case HDIO_GET_32BIT:
592 case HDIO_GET_NOWERR: 592 case HDIO_GET_NOWERR:
593 case HDIO_GET_DMA: 593 case HDIO_GET_DMA:
594 case HDIO_GET_NICE: 594 case HDIO_GET_NICE:
595 case HDIO_GET_WCACHE: 595 case HDIO_GET_WCACHE:
596 case HDIO_GET_ACOUSTIC: 596 case HDIO_GET_ACOUSTIC:
597 case HDIO_GET_ADDRESS: 597 case HDIO_GET_ADDRESS:
598 case HDIO_GET_BUSSTATE: 598 case HDIO_GET_BUSSTATE:
599 return compat_hdio_ioctl(inode, file, disk, cmd, arg); 599 return compat_hdio_ioctl(inode, file, disk, cmd, arg);
600 case FDSETPRM32: 600 case FDSETPRM32:
601 case FDDEFPRM32: 601 case FDDEFPRM32:
602 case FDGETPRM32: 602 case FDGETPRM32:
603 case FDSETDRVPRM32: 603 case FDSETDRVPRM32:
604 case FDGETDRVPRM32: 604 case FDGETDRVPRM32:
605 case FDGETDRVSTAT32: 605 case FDGETDRVSTAT32:
606 case FDPOLLDRVSTAT32: 606 case FDPOLLDRVSTAT32:
607 case FDGETFDCSTAT32: 607 case FDGETFDCSTAT32:
608 case FDWERRORGET32: 608 case FDWERRORGET32:
609 return compat_fd_ioctl(inode, file, disk, cmd, arg); 609 return compat_fd_ioctl(inode, file, disk, cmd, arg);
610 case CDROMREADAUDIO: 610 case CDROMREADAUDIO:
611 return compat_cdrom_read_audio(inode, file, disk, cmd, arg); 611 return compat_cdrom_read_audio(inode, file, disk, cmd, arg);
612 case CDROM_SEND_PACKET: 612 case CDROM_SEND_PACKET:
613 return compat_cdrom_generic_command(inode, file, disk, cmd, arg); 613 return compat_cdrom_generic_command(inode, file, disk, cmd, arg);
614 614
615 /* 615 /*
616 * No handler required for the ones below, we just need to 616 * No handler required for the ones below, we just need to
617 * convert arg to a 64 bit pointer. 617 * convert arg to a 64 bit pointer.
618 */ 618 */
619 case BLKSECTSET: 619 case BLKSECTSET:
620 /* 620 /*
621 * 0x03 -- HD/IDE ioctl's used by hdparm and friends. 621 * 0x03 -- HD/IDE ioctl's used by hdparm and friends.
622 * Some need translations, these do not. 622 * Some need translations, these do not.
623 */ 623 */
624 case HDIO_GET_IDENTITY: 624 case HDIO_GET_IDENTITY:
625 case HDIO_DRIVE_TASK: 625 case HDIO_DRIVE_TASK:
626 case HDIO_DRIVE_CMD: 626 case HDIO_DRIVE_CMD:
627 /* 0x330 is reserved -- it used to be HDIO_GETGEO_BIG */ 627 /* 0x330 is reserved -- it used to be HDIO_GETGEO_BIG */
628 case 0x330: 628 case 0x330:
629 /* 0x02 -- Floppy ioctls */ 629 /* 0x02 -- Floppy ioctls */
630 case FDMSGON: 630 case FDMSGON:
631 case FDMSGOFF: 631 case FDMSGOFF:
632 case FDSETEMSGTRESH: 632 case FDSETEMSGTRESH:
633 case FDFLUSH: 633 case FDFLUSH:
634 case FDWERRORCLR: 634 case FDWERRORCLR:
635 case FDSETMAXERRS: 635 case FDSETMAXERRS:
636 case FDGETMAXERRS: 636 case FDGETMAXERRS:
637 case FDGETDRVTYP: 637 case FDGETDRVTYP:
638 case FDEJECT: 638 case FDEJECT:
639 case FDCLRPRM: 639 case FDCLRPRM:
640 case FDFMTBEG: 640 case FDFMTBEG:
641 case FDFMTEND: 641 case FDFMTEND:
642 case FDRESET: 642 case FDRESET:
643 case FDTWADDLE: 643 case FDTWADDLE:
644 case FDFMTTRK: 644 case FDFMTTRK:
645 case FDRAWCMD: 645 case FDRAWCMD:
646 /* CDROM stuff */ 646 /* CDROM stuff */
647 case CDROMPAUSE: 647 case CDROMPAUSE:
648 case CDROMRESUME: 648 case CDROMRESUME:
649 case CDROMPLAYMSF: 649 case CDROMPLAYMSF:
650 case CDROMPLAYTRKIND: 650 case CDROMPLAYTRKIND:
651 case CDROMREADTOCHDR: 651 case CDROMREADTOCHDR:
652 case CDROMREADTOCENTRY: 652 case CDROMREADTOCENTRY:
653 case CDROMSTOP: 653 case CDROMSTOP:
654 case CDROMSTART: 654 case CDROMSTART:
655 case CDROMEJECT: 655 case CDROMEJECT:
656 case CDROMVOLCTRL: 656 case CDROMVOLCTRL:
657 case CDROMSUBCHNL: 657 case CDROMSUBCHNL:
658 case CDROMMULTISESSION: 658 case CDROMMULTISESSION:
659 case CDROM_GET_MCN: 659 case CDROM_GET_MCN:
660 case CDROMRESET: 660 case CDROMRESET:
661 case CDROMVOLREAD: 661 case CDROMVOLREAD:
662 case CDROMSEEK: 662 case CDROMSEEK:
663 case CDROMPLAYBLK: 663 case CDROMPLAYBLK:
664 case CDROMCLOSETRAY: 664 case CDROMCLOSETRAY:
665 case CDROM_DISC_STATUS: 665 case CDROM_DISC_STATUS:
666 case CDROM_CHANGER_NSLOTS: 666 case CDROM_CHANGER_NSLOTS:
667 case CDROM_GET_CAPABILITY: 667 case CDROM_GET_CAPABILITY:
668 /* Ignore cdrom.h about these next 5 ioctls, they absolutely do 668 /* Ignore cdrom.h about these next 5 ioctls, they absolutely do
669 * not take a struct cdrom_read, instead they take a struct cdrom_msf 669 * not take a struct cdrom_read, instead they take a struct cdrom_msf
670 * which is compatible. 670 * which is compatible.
671 */ 671 */
672 case CDROMREADMODE2: 672 case CDROMREADMODE2:
673 case CDROMREADMODE1: 673 case CDROMREADMODE1:
674 case CDROMREADRAW: 674 case CDROMREADRAW:
675 case CDROMREADCOOKED: 675 case CDROMREADCOOKED:
676 case CDROMREADALL: 676 case CDROMREADALL:
677 /* DVD ioctls */ 677 /* DVD ioctls */
678 case DVD_READ_STRUCT: 678 case DVD_READ_STRUCT:
679 case DVD_WRITE_STRUCT: 679 case DVD_WRITE_STRUCT:
680 case DVD_AUTH: 680 case DVD_AUTH:
681 arg = (unsigned long)compat_ptr(arg); 681 arg = (unsigned long)compat_ptr(arg);
682 /* These intepret arg as an unsigned long, not as a pointer, 682 /* These intepret arg as an unsigned long, not as a pointer,
683 * so we must not do compat_ptr() conversion. */ 683 * so we must not do compat_ptr() conversion. */
684 case HDIO_SET_MULTCOUNT: 684 case HDIO_SET_MULTCOUNT:
685 case HDIO_SET_UNMASKINTR: 685 case HDIO_SET_UNMASKINTR:
686 case HDIO_SET_KEEPSETTINGS: 686 case HDIO_SET_KEEPSETTINGS:
687 case HDIO_SET_32BIT: 687 case HDIO_SET_32BIT:
688 case HDIO_SET_NOWERR: 688 case HDIO_SET_NOWERR:
689 case HDIO_SET_DMA: 689 case HDIO_SET_DMA:
690 case HDIO_SET_PIO_MODE: 690 case HDIO_SET_PIO_MODE:
691 case HDIO_SET_NICE: 691 case HDIO_SET_NICE:
692 case HDIO_SET_WCACHE: 692 case HDIO_SET_WCACHE:
693 case HDIO_SET_ACOUSTIC: 693 case HDIO_SET_ACOUSTIC:
694 case HDIO_SET_BUSSTATE: 694 case HDIO_SET_BUSSTATE:
695 case HDIO_SET_ADDRESS: 695 case HDIO_SET_ADDRESS:
696 case CDROMEJECT_SW: 696 case CDROMEJECT_SW:
697 case CDROM_SET_OPTIONS: 697 case CDROM_SET_OPTIONS:
698 case CDROM_CLEAR_OPTIONS: 698 case CDROM_CLEAR_OPTIONS:
699 case CDROM_SELECT_SPEED: 699 case CDROM_SELECT_SPEED:
700 case CDROM_SELECT_DISC: 700 case CDROM_SELECT_DISC:
701 case CDROM_MEDIA_CHANGED: 701 case CDROM_MEDIA_CHANGED:
702 case CDROM_DRIVE_STATUS: 702 case CDROM_DRIVE_STATUS:
703 case CDROM_LOCKDOOR: 703 case CDROM_LOCKDOOR:
704 case CDROM_DEBUG: 704 case CDROM_DEBUG:
705 break; 705 break;
706 default: 706 default:
707 /* unknown ioctl number */ 707 /* unknown ioctl number */
708 return -ENOIOCTLCMD; 708 return -ENOIOCTLCMD;
709 } 709 }
710 710
711 if (disk->fops->unlocked_ioctl) 711 if (disk->fops->unlocked_ioctl)
712 return disk->fops->unlocked_ioctl(file, cmd, arg); 712 return disk->fops->unlocked_ioctl(file, cmd, arg);
713 713
714 if (disk->fops->ioctl) { 714 if (disk->fops->ioctl) {
715 lock_kernel(); 715 lock_kernel();
716 ret = disk->fops->ioctl(inode, file, cmd, arg); 716 ret = disk->fops->ioctl(inode, file, cmd, arg);
717 unlock_kernel(); 717 unlock_kernel();
718 return ret; 718 return ret;
719 } 719 }
720 720
721 return -ENOTTY; 721 return -ENOTTY;
722 } 722 }
723 723
724 static int compat_blkdev_locked_ioctl(struct inode *inode, struct file *file, 724 static int compat_blkdev_locked_ioctl(struct inode *inode, struct file *file,
725 struct block_device *bdev, 725 struct block_device *bdev,
726 unsigned cmd, unsigned long arg) 726 unsigned cmd, unsigned long arg)
727 { 727 {
728 struct backing_dev_info *bdi; 728 struct backing_dev_info *bdi;
729 729
730 switch (cmd) { 730 switch (cmd) {
731 case BLKRAGET: 731 case BLKRAGET:
732 case BLKFRAGET: 732 case BLKFRAGET:
733 if (!arg) 733 if (!arg)
734 return -EINVAL; 734 return -EINVAL;
735 bdi = blk_get_backing_dev_info(bdev); 735 bdi = blk_get_backing_dev_info(bdev);
736 if (bdi == NULL) 736 if (bdi == NULL)
737 return -ENOTTY; 737 return -ENOTTY;
738 return compat_put_long(arg, 738 return compat_put_long(arg,
739 (bdi->ra_pages * PAGE_CACHE_SIZE) / 512); 739 (bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
740 case BLKROGET: /* compatible */ 740 case BLKROGET: /* compatible */
741 return compat_put_int(arg, bdev_read_only(bdev) != 0); 741 return compat_put_int(arg, bdev_read_only(bdev) != 0);
742 case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */ 742 case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */
743 return compat_put_int(arg, block_size(bdev)); 743 return compat_put_int(arg, block_size(bdev));
744 case BLKSSZGET: /* get block device hardware sector size */ 744 case BLKSSZGET: /* get block device hardware sector size */
745 return compat_put_int(arg, bdev_hardsect_size(bdev)); 745 return compat_put_int(arg, bdev_hardsect_size(bdev));
746 case BLKSECTGET: 746 case BLKSECTGET:
747 return compat_put_ushort(arg, 747 return compat_put_ushort(arg,
748 bdev_get_queue(bdev)->max_sectors); 748 bdev_get_queue(bdev)->max_sectors);
749 case BLKRASET: /* compatible, but no compat_ptr (!) */ 749 case BLKRASET: /* compatible, but no compat_ptr (!) */
750 case BLKFRASET: 750 case BLKFRASET:
751 if (!capable(CAP_SYS_ADMIN)) 751 if (!capable(CAP_SYS_ADMIN))
752 return -EACCES; 752 return -EACCES;
753 bdi = blk_get_backing_dev_info(bdev); 753 bdi = blk_get_backing_dev_info(bdev);
754 if (bdi == NULL) 754 if (bdi == NULL)
755 return -ENOTTY; 755 return -ENOTTY;
756 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE; 756 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
757 return 0; 757 return 0;
758 case BLKGETSIZE: 758 case BLKGETSIZE:
759 if ((bdev->bd_inode->i_size >> 9) > ~0UL) 759 if ((bdev->bd_inode->i_size >> 9) > ~0UL)
760 return -EFBIG; 760 return -EFBIG;
761 return compat_put_ulong(arg, bdev->bd_inode->i_size >> 9); 761 return compat_put_ulong(arg, bdev->bd_inode->i_size >> 9);
762 762
763 case BLKGETSIZE64_32: 763 case BLKGETSIZE64_32:
764 return compat_put_u64(arg, bdev->bd_inode->i_size); 764 return compat_put_u64(arg, bdev->bd_inode->i_size);
765 765
766 case BLKTRACESETUP32: 766 case BLKTRACESETUP32:
767 return compat_blk_trace_setup(bdev, compat_ptr(arg)); 767 return compat_blk_trace_setup(bdev, compat_ptr(arg));
768 case BLKTRACESTART: /* compatible */ 768 case BLKTRACESTART: /* compatible */
769 case BLKTRACESTOP: /* compatible */ 769 case BLKTRACESTOP: /* compatible */
770 case BLKTRACETEARDOWN: /* compatible */ 770 case BLKTRACETEARDOWN: /* compatible */
771 return blk_trace_ioctl(bdev, cmd, compat_ptr(arg)); 771 return blk_trace_ioctl(bdev, cmd, compat_ptr(arg));
772 } 772 }
773 return -ENOIOCTLCMD; 773 return -ENOIOCTLCMD;
774 } 774 }
775 775
776 /* Most of the generic ioctls are handled in the normal fallback path. 776 /* Most of the generic ioctls are handled in the normal fallback path.
777 This assumes the blkdev's low level compat_ioctl always returns 777 This assumes the blkdev's low level compat_ioctl always returns
778 ENOIOCTLCMD for unknown ioctls. */ 778 ENOIOCTLCMD for unknown ioctls. */
779 long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) 779 long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
780 { 780 {
781 int ret = -ENOIOCTLCMD; 781 int ret = -ENOIOCTLCMD;
782 struct inode *inode = file->f_mapping->host; 782 struct inode *inode = file->f_mapping->host;
783 struct block_device *bdev = inode->i_bdev; 783 struct block_device *bdev = inode->i_bdev;
784 struct gendisk *disk = bdev->bd_disk; 784 struct gendisk *disk = bdev->bd_disk;
785 785
786 switch (cmd) { 786 switch (cmd) {
787 case HDIO_GETGEO: 787 case HDIO_GETGEO:
788 return compat_hdio_getgeo(disk, bdev, compat_ptr(arg)); 788 return compat_hdio_getgeo(disk, bdev, compat_ptr(arg));
789 case BLKFLSBUF: 789 case BLKFLSBUF:
790 case BLKROSET: 790 case BLKROSET:
791 case BLKDISCARD:
791 /* 792 /*
792 * the ones below are implemented in blkdev_locked_ioctl, 793 * the ones below are implemented in blkdev_locked_ioctl,
793 * but we call blkdev_ioctl, which gets the lock for us 794 * but we call blkdev_ioctl, which gets the lock for us
794 */ 795 */
795 case BLKRRPART: 796 case BLKRRPART:
796 return blkdev_ioctl(inode, file, cmd, 797 return blkdev_ioctl(inode, file, cmd,
797 (unsigned long)compat_ptr(arg)); 798 (unsigned long)compat_ptr(arg));
798 case BLKBSZSET_32: 799 case BLKBSZSET_32:
799 return blkdev_ioctl(inode, file, BLKBSZSET, 800 return blkdev_ioctl(inode, file, BLKBSZSET,
800 (unsigned long)compat_ptr(arg)); 801 (unsigned long)compat_ptr(arg));
801 case BLKPG: 802 case BLKPG:
802 return compat_blkpg_ioctl(inode, file, cmd, compat_ptr(arg)); 803 return compat_blkpg_ioctl(inode, file, cmd, compat_ptr(arg));
803 } 804 }
804 805
805 lock_kernel(); 806 lock_kernel();
806 ret = compat_blkdev_locked_ioctl(inode, file, bdev, cmd, arg); 807 ret = compat_blkdev_locked_ioctl(inode, file, bdev, cmd, arg);
807 /* FIXME: why do we assume -> compat_ioctl needs the BKL? */ 808 /* FIXME: why do we assume -> compat_ioctl needs the BKL? */
808 if (ret == -ENOIOCTLCMD && disk->fops->compat_ioctl) 809 if (ret == -ENOIOCTLCMD && disk->fops->compat_ioctl)
809 ret = disk->fops->compat_ioctl(file, cmd, arg); 810 ret = disk->fops->compat_ioctl(file, cmd, arg);
810 unlock_kernel(); 811 unlock_kernel();
811 812
812 if (ret != -ENOIOCTLCMD) 813 if (ret != -ENOIOCTLCMD)
813 return ret; 814 return ret;
814 815
815 return compat_blkdev_driver_ioctl(inode, file, disk, cmd, arg); 816 return compat_blkdev_driver_ioctl(inode, file, disk, cmd, arg);
816 } 817 }
817 818
1 #include <linux/capability.h> 1 #include <linux/capability.h>
2 #include <linux/blkdev.h> 2 #include <linux/blkdev.h>
3 #include <linux/blkpg.h> 3 #include <linux/blkpg.h>
4 #include <linux/hdreg.h> 4 #include <linux/hdreg.h>
5 #include <linux/backing-dev.h> 5 #include <linux/backing-dev.h>
6 #include <linux/buffer_head.h> 6 #include <linux/buffer_head.h>
7 #include <linux/smp_lock.h> 7 #include <linux/smp_lock.h>
8 #include <linux/blktrace_api.h> 8 #include <linux/blktrace_api.h>
9 #include <asm/uaccess.h> 9 #include <asm/uaccess.h>
10 10
11 static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user *arg) 11 static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user *arg)
12 { 12 {
13 struct block_device *bdevp; 13 struct block_device *bdevp;
14 struct gendisk *disk; 14 struct gendisk *disk;
15 struct blkpg_ioctl_arg a; 15 struct blkpg_ioctl_arg a;
16 struct blkpg_partition p; 16 struct blkpg_partition p;
17 long long start, length; 17 long long start, length;
18 int part; 18 int part;
19 int i; 19 int i;
20 int err; 20 int err;
21 21
22 if (!capable(CAP_SYS_ADMIN)) 22 if (!capable(CAP_SYS_ADMIN))
23 return -EACCES; 23 return -EACCES;
24 if (copy_from_user(&a, arg, sizeof(struct blkpg_ioctl_arg))) 24 if (copy_from_user(&a, arg, sizeof(struct blkpg_ioctl_arg)))
25 return -EFAULT; 25 return -EFAULT;
26 if (copy_from_user(&p, a.data, sizeof(struct blkpg_partition))) 26 if (copy_from_user(&p, a.data, sizeof(struct blkpg_partition)))
27 return -EFAULT; 27 return -EFAULT;
28 disk = bdev->bd_disk; 28 disk = bdev->bd_disk;
29 if (bdev != bdev->bd_contains) 29 if (bdev != bdev->bd_contains)
30 return -EINVAL; 30 return -EINVAL;
31 part = p.pno; 31 part = p.pno;
32 if (part <= 0 || part >= disk->minors) 32 if (part <= 0 || part >= disk->minors)
33 return -EINVAL; 33 return -EINVAL;
34 switch (a.op) { 34 switch (a.op) {
35 case BLKPG_ADD_PARTITION: 35 case BLKPG_ADD_PARTITION:
36 start = p.start >> 9; 36 start = p.start >> 9;
37 length = p.length >> 9; 37 length = p.length >> 9;
38 /* check for fit in a hd_struct */ 38 /* check for fit in a hd_struct */
39 if (sizeof(sector_t) == sizeof(long) && 39 if (sizeof(sector_t) == sizeof(long) &&
40 sizeof(long long) > sizeof(long)) { 40 sizeof(long long) > sizeof(long)) {
41 long pstart = start, plength = length; 41 long pstart = start, plength = length;
42 if (pstart != start || plength != length 42 if (pstart != start || plength != length
43 || pstart < 0 || plength < 0) 43 || pstart < 0 || plength < 0)
44 return -EINVAL; 44 return -EINVAL;
45 } 45 }
46 /* partition number in use? */ 46 /* partition number in use? */
47 mutex_lock(&bdev->bd_mutex); 47 mutex_lock(&bdev->bd_mutex);
48 if (disk->part[part - 1]) { 48 if (disk->part[part - 1]) {
49 mutex_unlock(&bdev->bd_mutex); 49 mutex_unlock(&bdev->bd_mutex);
50 return -EBUSY; 50 return -EBUSY;
51 } 51 }
52 /* overlap? */ 52 /* overlap? */
53 for (i = 0; i < disk->minors - 1; i++) { 53 for (i = 0; i < disk->minors - 1; i++) {
54 struct hd_struct *s = disk->part[i]; 54 struct hd_struct *s = disk->part[i];
55 55
56 if (!s) 56 if (!s)
57 continue; 57 continue;
58 if (!(start+length <= s->start_sect || 58 if (!(start+length <= s->start_sect ||
59 start >= s->start_sect + s->nr_sects)) { 59 start >= s->start_sect + s->nr_sects)) {
60 mutex_unlock(&bdev->bd_mutex); 60 mutex_unlock(&bdev->bd_mutex);
61 return -EBUSY; 61 return -EBUSY;
62 } 62 }
63 } 63 }
64 /* all seems OK */ 64 /* all seems OK */
65 err = add_partition(disk, part, start, length, ADDPART_FLAG_NONE); 65 err = add_partition(disk, part, start, length, ADDPART_FLAG_NONE);
66 mutex_unlock(&bdev->bd_mutex); 66 mutex_unlock(&bdev->bd_mutex);
67 return err; 67 return err;
68 case BLKPG_DEL_PARTITION: 68 case BLKPG_DEL_PARTITION:
69 if (!disk->part[part-1]) 69 if (!disk->part[part-1])
70 return -ENXIO; 70 return -ENXIO;
71 if (disk->part[part - 1]->nr_sects == 0) 71 if (disk->part[part - 1]->nr_sects == 0)
72 return -ENXIO; 72 return -ENXIO;
73 bdevp = bdget_disk(disk, part); 73 bdevp = bdget_disk(disk, part);
74 if (!bdevp) 74 if (!bdevp)
75 return -ENOMEM; 75 return -ENOMEM;
76 mutex_lock(&bdevp->bd_mutex); 76 mutex_lock(&bdevp->bd_mutex);
77 if (bdevp->bd_openers) { 77 if (bdevp->bd_openers) {
78 mutex_unlock(&bdevp->bd_mutex); 78 mutex_unlock(&bdevp->bd_mutex);
79 bdput(bdevp); 79 bdput(bdevp);
80 return -EBUSY; 80 return -EBUSY;
81 } 81 }
82 /* all seems OK */ 82 /* all seems OK */
83 fsync_bdev(bdevp); 83 fsync_bdev(bdevp);
84 invalidate_bdev(bdevp); 84 invalidate_bdev(bdevp);
85 85
86 mutex_lock_nested(&bdev->bd_mutex, 1); 86 mutex_lock_nested(&bdev->bd_mutex, 1);
87 delete_partition(disk, part); 87 delete_partition(disk, part);
88 mutex_unlock(&bdev->bd_mutex); 88 mutex_unlock(&bdev->bd_mutex);
89 mutex_unlock(&bdevp->bd_mutex); 89 mutex_unlock(&bdevp->bd_mutex);
90 bdput(bdevp); 90 bdput(bdevp);
91 91
92 return 0; 92 return 0;
93 default: 93 default:
94 return -EINVAL; 94 return -EINVAL;
95 } 95 }
96 } 96 }
97 97
98 static int blkdev_reread_part(struct block_device *bdev) 98 static int blkdev_reread_part(struct block_device *bdev)
99 { 99 {
100 struct gendisk *disk = bdev->bd_disk; 100 struct gendisk *disk = bdev->bd_disk;
101 int res; 101 int res;
102 102
103 if (disk->minors == 1 || bdev != bdev->bd_contains) 103 if (disk->minors == 1 || bdev != bdev->bd_contains)
104 return -EINVAL; 104 return -EINVAL;
105 if (!capable(CAP_SYS_ADMIN)) 105 if (!capable(CAP_SYS_ADMIN))
106 return -EACCES; 106 return -EACCES;
107 if (!mutex_trylock(&bdev->bd_mutex)) 107 if (!mutex_trylock(&bdev->bd_mutex))
108 return -EBUSY; 108 return -EBUSY;
109 res = rescan_partitions(disk, bdev); 109 res = rescan_partitions(disk, bdev);
110 mutex_unlock(&bdev->bd_mutex); 110 mutex_unlock(&bdev->bd_mutex);
111 return res; 111 return res;
112 } 112 }
113 113
114 static void blk_ioc_discard_endio(struct bio *bio, int err)
115 {
116 if (err) {
117 if (err == -EOPNOTSUPP)
118 set_bit(BIO_EOPNOTSUPP, &bio->bi_flags);
119 clear_bit(BIO_UPTODATE, &bio->bi_flags);
120 }
121 complete(bio->bi_private);
122 }
123
124 static int blk_ioctl_discard(struct block_device *bdev, uint64_t start,
125 uint64_t len)
126 {
127 struct request_queue *q = bdev_get_queue(bdev);
128 int ret = 0;
129
130 if (start & 511)
131 return -EINVAL;
132 if (len & 511)
133 return -EINVAL;
134 start >>= 9;
135 len >>= 9;
136
137 if (start + len > (bdev->bd_inode->i_size >> 9))
138 return -EINVAL;
139
140 if (!q->prepare_discard_fn)
141 return -EOPNOTSUPP;
142
143 while (len && !ret) {
144 DECLARE_COMPLETION_ONSTACK(wait);
145 struct bio *bio;
146
147 bio = bio_alloc(GFP_KERNEL, 0);
148 if (!bio)
149 return -ENOMEM;
150
151 bio->bi_end_io = blk_ioc_discard_endio;
152 bio->bi_bdev = bdev;
153 bio->bi_private = &wait;
154 bio->bi_sector = start;
155
156 if (len > q->max_hw_sectors) {
157 bio->bi_size = q->max_hw_sectors << 9;
158 len -= q->max_hw_sectors;
159 start += q->max_hw_sectors;
160 } else {
161 bio->bi_size = len << 9;
162 len = 0;
163 }
164 submit_bio(WRITE_DISCARD, bio);
165
166 wait_for_completion(&wait);
167
168 if (bio_flagged(bio, BIO_EOPNOTSUPP))
169 ret = -EOPNOTSUPP;
170 else if (!bio_flagged(bio, BIO_UPTODATE))
171 ret = -EIO;
172 bio_put(bio);
173 }
174 return ret;
175 }
176
114 static int put_ushort(unsigned long arg, unsigned short val) 177 static int put_ushort(unsigned long arg, unsigned short val)
115 { 178 {
116 return put_user(val, (unsigned short __user *)arg); 179 return put_user(val, (unsigned short __user *)arg);
117 } 180 }
118 181
119 static int put_int(unsigned long arg, int val) 182 static int put_int(unsigned long arg, int val)
120 { 183 {
121 return put_user(val, (int __user *)arg); 184 return put_user(val, (int __user *)arg);
122 } 185 }
123 186
124 static int put_long(unsigned long arg, long val) 187 static int put_long(unsigned long arg, long val)
125 { 188 {
126 return put_user(val, (long __user *)arg); 189 return put_user(val, (long __user *)arg);
127 } 190 }
128 191
129 static int put_ulong(unsigned long arg, unsigned long val) 192 static int put_ulong(unsigned long arg, unsigned long val)
130 { 193 {
131 return put_user(val, (unsigned long __user *)arg); 194 return put_user(val, (unsigned long __user *)arg);
132 } 195 }
133 196
134 static int put_u64(unsigned long arg, u64 val) 197 static int put_u64(unsigned long arg, u64 val)
135 { 198 {
136 return put_user(val, (u64 __user *)arg); 199 return put_user(val, (u64 __user *)arg);
137 } 200 }
138 201
139 static int blkdev_locked_ioctl(struct file *file, struct block_device *bdev, 202 static int blkdev_locked_ioctl(struct file *file, struct block_device *bdev,
140 unsigned cmd, unsigned long arg) 203 unsigned cmd, unsigned long arg)
141 { 204 {
142 struct backing_dev_info *bdi; 205 struct backing_dev_info *bdi;
143 int ret, n; 206 int ret, n;
144 207
145 switch (cmd) { 208 switch (cmd) {
146 case BLKRAGET: 209 case BLKRAGET:
147 case BLKFRAGET: 210 case BLKFRAGET:
148 if (!arg) 211 if (!arg)
149 return -EINVAL; 212 return -EINVAL;
150 bdi = blk_get_backing_dev_info(bdev); 213 bdi = blk_get_backing_dev_info(bdev);
151 if (bdi == NULL) 214 if (bdi == NULL)
152 return -ENOTTY; 215 return -ENOTTY;
153 return put_long(arg, (bdi->ra_pages * PAGE_CACHE_SIZE) / 512); 216 return put_long(arg, (bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
154 case BLKROGET: 217 case BLKROGET:
155 return put_int(arg, bdev_read_only(bdev) != 0); 218 return put_int(arg, bdev_read_only(bdev) != 0);
156 case BLKBSZGET: /* get the logical block size (cf. BLKSSZGET) */ 219 case BLKBSZGET: /* get the logical block size (cf. BLKSSZGET) */
157 return put_int(arg, block_size(bdev)); 220 return put_int(arg, block_size(bdev));
158 case BLKSSZGET: /* get block device hardware sector size */ 221 case BLKSSZGET: /* get block device hardware sector size */
159 return put_int(arg, bdev_hardsect_size(bdev)); 222 return put_int(arg, bdev_hardsect_size(bdev));
160 case BLKSECTGET: 223 case BLKSECTGET:
161 return put_ushort(arg, bdev_get_queue(bdev)->max_sectors); 224 return put_ushort(arg, bdev_get_queue(bdev)->max_sectors);
162 case BLKRASET: 225 case BLKRASET:
163 case BLKFRASET: 226 case BLKFRASET:
164 if(!capable(CAP_SYS_ADMIN)) 227 if(!capable(CAP_SYS_ADMIN))
165 return -EACCES; 228 return -EACCES;
166 bdi = blk_get_backing_dev_info(bdev); 229 bdi = blk_get_backing_dev_info(bdev);
167 if (bdi == NULL) 230 if (bdi == NULL)
168 return -ENOTTY; 231 return -ENOTTY;
169 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE; 232 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
170 return 0; 233 return 0;
171 case BLKBSZSET: 234 case BLKBSZSET:
172 /* set the logical block size */ 235 /* set the logical block size */
173 if (!capable(CAP_SYS_ADMIN)) 236 if (!capable(CAP_SYS_ADMIN))
174 return -EACCES; 237 return -EACCES;
175 if (!arg) 238 if (!arg)
176 return -EINVAL; 239 return -EINVAL;
177 if (get_user(n, (int __user *) arg)) 240 if (get_user(n, (int __user *) arg))
178 return -EFAULT; 241 return -EFAULT;
179 if (bd_claim(bdev, file) < 0) 242 if (bd_claim(bdev, file) < 0)
180 return -EBUSY; 243 return -EBUSY;
181 ret = set_blocksize(bdev, n); 244 ret = set_blocksize(bdev, n);
182 bd_release(bdev); 245 bd_release(bdev);
183 return ret; 246 return ret;
184 case BLKPG: 247 case BLKPG:
185 return blkpg_ioctl(bdev, (struct blkpg_ioctl_arg __user *) arg); 248 return blkpg_ioctl(bdev, (struct blkpg_ioctl_arg __user *) arg);
186 case BLKRRPART: 249 case BLKRRPART:
187 return blkdev_reread_part(bdev); 250 return blkdev_reread_part(bdev);
188 case BLKGETSIZE: 251 case BLKGETSIZE:
189 if ((bdev->bd_inode->i_size >> 9) > ~0UL) 252 if ((bdev->bd_inode->i_size >> 9) > ~0UL)
190 return -EFBIG; 253 return -EFBIG;
191 return put_ulong(arg, bdev->bd_inode->i_size >> 9); 254 return put_ulong(arg, bdev->bd_inode->i_size >> 9);
192 case BLKGETSIZE64: 255 case BLKGETSIZE64:
193 return put_u64(arg, bdev->bd_inode->i_size); 256 return put_u64(arg, bdev->bd_inode->i_size);
194 case BLKTRACESTART: 257 case BLKTRACESTART:
195 case BLKTRACESTOP: 258 case BLKTRACESTOP:
196 case BLKTRACESETUP: 259 case BLKTRACESETUP:
197 case BLKTRACETEARDOWN: 260 case BLKTRACETEARDOWN:
198 return blk_trace_ioctl(bdev, cmd, (char __user *) arg); 261 return blk_trace_ioctl(bdev, cmd, (char __user *) arg);
199 } 262 }
200 return -ENOIOCTLCMD; 263 return -ENOIOCTLCMD;
201 } 264 }
202 265
203 int blkdev_driver_ioctl(struct inode *inode, struct file *file, 266 int blkdev_driver_ioctl(struct inode *inode, struct file *file,
204 struct gendisk *disk, unsigned cmd, unsigned long arg) 267 struct gendisk *disk, unsigned cmd, unsigned long arg)
205 { 268 {
206 int ret; 269 int ret;
207 if (disk->fops->unlocked_ioctl) 270 if (disk->fops->unlocked_ioctl)
208 return disk->fops->unlocked_ioctl(file, cmd, arg); 271 return disk->fops->unlocked_ioctl(file, cmd, arg);
209 272
210 if (disk->fops->ioctl) { 273 if (disk->fops->ioctl) {
211 lock_kernel(); 274 lock_kernel();
212 ret = disk->fops->ioctl(inode, file, cmd, arg); 275 ret = disk->fops->ioctl(inode, file, cmd, arg);
213 unlock_kernel(); 276 unlock_kernel();
214 return ret; 277 return ret;
215 } 278 }
216 279
217 return -ENOTTY; 280 return -ENOTTY;
218 } 281 }
219 EXPORT_SYMBOL_GPL(blkdev_driver_ioctl); 282 EXPORT_SYMBOL_GPL(blkdev_driver_ioctl);
220 283
221 /* 284 /*
222 * always keep this in sync with compat_blkdev_ioctl() and 285 * always keep this in sync with compat_blkdev_ioctl() and
223 * compat_blkdev_locked_ioctl() 286 * compat_blkdev_locked_ioctl()
224 */ 287 */
225 int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd, 288 int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd,
226 unsigned long arg) 289 unsigned long arg)
227 { 290 {
228 struct block_device *bdev = inode->i_bdev; 291 struct block_device *bdev = inode->i_bdev;
229 struct gendisk *disk = bdev->bd_disk; 292 struct gendisk *disk = bdev->bd_disk;
230 int ret, n; 293 int ret, n;
231 294
232 switch(cmd) { 295 switch(cmd) {
233 case BLKFLSBUF: 296 case BLKFLSBUF:
234 if (!capable(CAP_SYS_ADMIN)) 297 if (!capable(CAP_SYS_ADMIN))
235 return -EACCES; 298 return -EACCES;
236 299
237 ret = blkdev_driver_ioctl(inode, file, disk, cmd, arg); 300 ret = blkdev_driver_ioctl(inode, file, disk, cmd, arg);
238 /* -EINVAL to handle old uncorrected drivers */ 301 /* -EINVAL to handle old uncorrected drivers */
239 if (ret != -EINVAL && ret != -ENOTTY) 302 if (ret != -EINVAL && ret != -ENOTTY)
240 return ret; 303 return ret;
241 304
242 lock_kernel(); 305 lock_kernel();
243 fsync_bdev(bdev); 306 fsync_bdev(bdev);
244 invalidate_bdev(bdev); 307 invalidate_bdev(bdev);
245 unlock_kernel(); 308 unlock_kernel();
246 return 0; 309 return 0;
247 310
248 case BLKROSET: 311 case BLKROSET:
249 ret = blkdev_driver_ioctl(inode, file, disk, cmd, arg); 312 ret = blkdev_driver_ioctl(inode, file, disk, cmd, arg);
250 /* -EINVAL to handle old uncorrected drivers */ 313 /* -EINVAL to handle old uncorrected drivers */
251 if (ret != -EINVAL && ret != -ENOTTY) 314 if (ret != -EINVAL && ret != -ENOTTY)
252 return ret; 315 return ret;
253 if (!capable(CAP_SYS_ADMIN)) 316 if (!capable(CAP_SYS_ADMIN))
254 return -EACCES; 317 return -EACCES;
255 if (get_user(n, (int __user *)(arg))) 318 if (get_user(n, (int __user *)(arg)))
256 return -EFAULT; 319 return -EFAULT;
257 lock_kernel(); 320 lock_kernel();
258 set_device_ro(bdev, n); 321 set_device_ro(bdev, n);
259 unlock_kernel(); 322 unlock_kernel();
260 return 0; 323 return 0;
324
325 case BLKDISCARD: {
326 uint64_t range[2];
327
328 if (!(file->f_mode & FMODE_WRITE))
329 return -EBADF;
330
331 if (copy_from_user(range, (void __user *)arg, sizeof(range)))
332 return -EFAULT;
333
334 return blk_ioctl_discard(bdev, range[0], range[1]);
335 }
336
261 case HDIO_GETGEO: { 337 case HDIO_GETGEO: {
262 struct hd_geometry geo; 338 struct hd_geometry geo;
263 339
264 if (!arg) 340 if (!arg)
265 return -EINVAL; 341 return -EINVAL;
266 if (!disk->fops->getgeo) 342 if (!disk->fops->getgeo)
267 return -ENOTTY; 343 return -ENOTTY;
268 344
269 /* 345 /*
270 * We need to set the startsect first, the driver may 346 * We need to set the startsect first, the driver may
271 * want to override it. 347 * want to override it.
272 */ 348 */
273 geo.start = get_start_sect(bdev); 349 geo.start = get_start_sect(bdev);
274 ret = disk->fops->getgeo(bdev, &geo); 350 ret = disk->fops->getgeo(bdev, &geo);
275 if (ret) 351 if (ret)
276 return ret; 352 return ret;
277 if (copy_to_user((struct hd_geometry __user *)arg, &geo, 353 if (copy_to_user((struct hd_geometry __user *)arg, &geo,
278 sizeof(geo))) 354 sizeof(geo)))
279 return -EFAULT; 355 return -EFAULT;
280 return 0; 356 return 0;
281 } 357 }
282 } 358 }
283 359
284 lock_kernel(); 360 lock_kernel();
285 ret = blkdev_locked_ioctl(file, bdev, cmd, arg); 361 ret = blkdev_locked_ioctl(file, bdev, cmd, arg);
286 unlock_kernel(); 362 unlock_kernel();
287 if (ret != -ENOIOCTLCMD) 363 if (ret != -ENOIOCTLCMD)
288 return ret; 364 return ret;
289 365
290 return blkdev_driver_ioctl(inode, file, disk, cmd, arg); 366 return blkdev_driver_ioctl(inode, file, disk, cmd, arg);
291 } 367 }
292 EXPORT_SYMBOL_GPL(blkdev_ioctl); 368 EXPORT_SYMBOL_GPL(blkdev_ioctl);
293 369
1 #ifndef _LINUX_FS_H 1 #ifndef _LINUX_FS_H
2 #define _LINUX_FS_H 2 #define _LINUX_FS_H
3 3
4 /* 4 /*
5 * This file has definitions for some important file table 5 * This file has definitions for some important file table
6 * structures etc. 6 * structures etc.
7 */ 7 */
8 8
9 #include <linux/limits.h> 9 #include <linux/limits.h>
10 #include <linux/ioctl.h> 10 #include <linux/ioctl.h>
11 11
12 /* 12 /*
13 * It's silly to have NR_OPEN bigger than NR_FILE, but you can change 13 * It's silly to have NR_OPEN bigger than NR_FILE, but you can change
14 * the file limit at runtime and only root can increase the per-process 14 * the file limit at runtime and only root can increase the per-process
15 * nr_file rlimit, so it's safe to set up a ridiculously high absolute 15 * nr_file rlimit, so it's safe to set up a ridiculously high absolute
16 * upper limit on files-per-process. 16 * upper limit on files-per-process.
17 * 17 *
18 * Some programs (notably those using select()) may have to be 18 * Some programs (notably those using select()) may have to be
19 * recompiled to take full advantage of the new limits.. 19 * recompiled to take full advantage of the new limits..
20 */ 20 */
21 21
22 /* Fixed constants first: */ 22 /* Fixed constants first: */
23 #undef NR_OPEN 23 #undef NR_OPEN
24 extern int sysctl_nr_open; 24 extern int sysctl_nr_open;
25 #define INR_OPEN 1024 /* Initial setting for nfile rlimits */ 25 #define INR_OPEN 1024 /* Initial setting for nfile rlimits */
26 26
27 #define BLOCK_SIZE_BITS 10 27 #define BLOCK_SIZE_BITS 10
28 #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS) 28 #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
29 29
30 #define SEEK_SET 0 /* seek relative to beginning of file */ 30 #define SEEK_SET 0 /* seek relative to beginning of file */
31 #define SEEK_CUR 1 /* seek relative to current file position */ 31 #define SEEK_CUR 1 /* seek relative to current file position */
32 #define SEEK_END 2 /* seek relative to end of file */ 32 #define SEEK_END 2 /* seek relative to end of file */
33 #define SEEK_MAX SEEK_END 33 #define SEEK_MAX SEEK_END
34 34
35 /* And dynamically-tunable limits and defaults: */ 35 /* And dynamically-tunable limits and defaults: */
36 struct files_stat_struct { 36 struct files_stat_struct {
37 int nr_files; /* read only */ 37 int nr_files; /* read only */
38 int nr_free_files; /* read only */ 38 int nr_free_files; /* read only */
39 int max_files; /* tunable */ 39 int max_files; /* tunable */
40 }; 40 };
41 extern struct files_stat_struct files_stat; 41 extern struct files_stat_struct files_stat;
42 extern int get_max_files(void); 42 extern int get_max_files(void);
43 43
44 struct inodes_stat_t { 44 struct inodes_stat_t {
45 int nr_inodes; 45 int nr_inodes;
46 int nr_unused; 46 int nr_unused;
47 int dummy[5]; /* padding for sysctl ABI compatibility */ 47 int dummy[5]; /* padding for sysctl ABI compatibility */
48 }; 48 };
49 extern struct inodes_stat_t inodes_stat; 49 extern struct inodes_stat_t inodes_stat;
50 50
51 extern int leases_enable, lease_break_time; 51 extern int leases_enable, lease_break_time;
52 52
53 #ifdef CONFIG_DNOTIFY 53 #ifdef CONFIG_DNOTIFY
54 extern int dir_notify_enable; 54 extern int dir_notify_enable;
55 #endif 55 #endif
56 56
57 #define NR_FILE 8192 /* this can well be larger on a larger system */ 57 #define NR_FILE 8192 /* this can well be larger on a larger system */
58 58
59 #define MAY_EXEC 1 59 #define MAY_EXEC 1
60 #define MAY_WRITE 2 60 #define MAY_WRITE 2
61 #define MAY_READ 4 61 #define MAY_READ 4
62 #define MAY_APPEND 8 62 #define MAY_APPEND 8
63 #define MAY_ACCESS 16 63 #define MAY_ACCESS 16
64 #define MAY_OPEN 32 64 #define MAY_OPEN 32
65 65
66 #define FMODE_READ 1 66 #define FMODE_READ 1
67 #define FMODE_WRITE 2 67 #define FMODE_WRITE 2
68 68
69 /* Internal kernel extensions */ 69 /* Internal kernel extensions */
70 #define FMODE_LSEEK 4 70 #define FMODE_LSEEK 4
71 #define FMODE_PREAD 8 71 #define FMODE_PREAD 8
72 #define FMODE_PWRITE FMODE_PREAD /* These go hand in hand */ 72 #define FMODE_PWRITE FMODE_PREAD /* These go hand in hand */
73 73
74 /* File is being opened for execution. Primary users of this flag are 74 /* File is being opened for execution. Primary users of this flag are
75 distributed filesystems that can use it to achieve correct ETXTBUSY 75 distributed filesystems that can use it to achieve correct ETXTBUSY
76 behavior for cross-node execution/opening_for_writing of files */ 76 behavior for cross-node execution/opening_for_writing of files */
77 #define FMODE_EXEC 16 77 #define FMODE_EXEC 16
78 78
79 #define RW_MASK 1 79 #define RW_MASK 1
80 #define RWA_MASK 2 80 #define RWA_MASK 2
81 #define READ 0 81 #define READ 0
82 #define WRITE 1 82 #define WRITE 1
83 #define READA 2 /* read-ahead - don't block if no resources */ 83 #define READA 2 /* read-ahead - don't block if no resources */
84 #define SWRITE 3 /* for ll_rw_block() - wait for buffer lock */ 84 #define SWRITE 3 /* for ll_rw_block() - wait for buffer lock */
85 #define READ_SYNC (READ | (1 << BIO_RW_SYNC)) 85 #define READ_SYNC (READ | (1 << BIO_RW_SYNC))
86 #define READ_META (READ | (1 << BIO_RW_META)) 86 #define READ_META (READ | (1 << BIO_RW_META))
87 #define WRITE_SYNC (WRITE | (1 << BIO_RW_SYNC)) 87 #define WRITE_SYNC (WRITE | (1 << BIO_RW_SYNC))
88 #define SWRITE_SYNC (SWRITE | (1 << BIO_RW_SYNC)) 88 #define SWRITE_SYNC (SWRITE | (1 << BIO_RW_SYNC))
89 #define WRITE_BARRIER (WRITE | (1 << BIO_RW_BARRIER)) 89 #define WRITE_BARRIER (WRITE | (1 << BIO_RW_BARRIER))
90 #define WRITE_DISCARD (WRITE | (1 << BIO_RW_DISCARD)) 90 #define WRITE_DISCARD (WRITE | (1 << BIO_RW_DISCARD))
91 91
92 #define SEL_IN 1 92 #define SEL_IN 1
93 #define SEL_OUT 2 93 #define SEL_OUT 2
94 #define SEL_EX 4 94 #define SEL_EX 4
95 95
96 /* public flags for file_system_type */ 96 /* public flags for file_system_type */
97 #define FS_REQUIRES_DEV 1 97 #define FS_REQUIRES_DEV 1
98 #define FS_BINARY_MOUNTDATA 2 98 #define FS_BINARY_MOUNTDATA 2
99 #define FS_HAS_SUBTYPE 4 99 #define FS_HAS_SUBTYPE 4
100 #define FS_REVAL_DOT 16384 /* Check the paths ".", ".." for staleness */ 100 #define FS_REVAL_DOT 16384 /* Check the paths ".", ".." for staleness */
101 #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() 101 #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move()
102 * during rename() internally. 102 * during rename() internally.
103 */ 103 */
104 104
105 /* 105 /*
106 * These are the fs-independent mount-flags: up to 32 flags are supported 106 * These are the fs-independent mount-flags: up to 32 flags are supported
107 */ 107 */
108 #define MS_RDONLY 1 /* Mount read-only */ 108 #define MS_RDONLY 1 /* Mount read-only */
109 #define MS_NOSUID 2 /* Ignore suid and sgid bits */ 109 #define MS_NOSUID 2 /* Ignore suid and sgid bits */
110 #define MS_NODEV 4 /* Disallow access to device special files */ 110 #define MS_NODEV 4 /* Disallow access to device special files */
111 #define MS_NOEXEC 8 /* Disallow program execution */ 111 #define MS_NOEXEC 8 /* Disallow program execution */
112 #define MS_SYNCHRONOUS 16 /* Writes are synced at once */ 112 #define MS_SYNCHRONOUS 16 /* Writes are synced at once */
113 #define MS_REMOUNT 32 /* Alter flags of a mounted FS */ 113 #define MS_REMOUNT 32 /* Alter flags of a mounted FS */
114 #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */ 114 #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
115 #define MS_DIRSYNC 128 /* Directory modifications are synchronous */ 115 #define MS_DIRSYNC 128 /* Directory modifications are synchronous */
116 #define MS_NOATIME 1024 /* Do not update access times. */ 116 #define MS_NOATIME 1024 /* Do not update access times. */
117 #define MS_NODIRATIME 2048 /* Do not update directory access times */ 117 #define MS_NODIRATIME 2048 /* Do not update directory access times */
118 #define MS_BIND 4096 118 #define MS_BIND 4096
119 #define MS_MOVE 8192 119 #define MS_MOVE 8192
120 #define MS_REC 16384 120 #define MS_REC 16384
121 #define MS_VERBOSE 32768 /* War is peace. Verbosity is silence. 121 #define MS_VERBOSE 32768 /* War is peace. Verbosity is silence.
122 MS_VERBOSE is deprecated. */ 122 MS_VERBOSE is deprecated. */
123 #define MS_SILENT 32768 123 #define MS_SILENT 32768
124 #define MS_POSIXACL (1<<16) /* VFS does not apply the umask */ 124 #define MS_POSIXACL (1<<16) /* VFS does not apply the umask */
125 #define MS_UNBINDABLE (1<<17) /* change to unbindable */ 125 #define MS_UNBINDABLE (1<<17) /* change to unbindable */
126 #define MS_PRIVATE (1<<18) /* change to private */ 126 #define MS_PRIVATE (1<<18) /* change to private */
127 #define MS_SLAVE (1<<19) /* change to slave */ 127 #define MS_SLAVE (1<<19) /* change to slave */
128 #define MS_SHARED (1<<20) /* change to shared */ 128 #define MS_SHARED (1<<20) /* change to shared */
129 #define MS_RELATIME (1<<21) /* Update atime relative to mtime/ctime. */ 129 #define MS_RELATIME (1<<21) /* Update atime relative to mtime/ctime. */
130 #define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */ 130 #define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */
131 #define MS_I_VERSION (1<<23) /* Update inode I_version field */ 131 #define MS_I_VERSION (1<<23) /* Update inode I_version field */
132 #define MS_ACTIVE (1<<30) 132 #define MS_ACTIVE (1<<30)
133 #define MS_NOUSER (1<<31) 133 #define MS_NOUSER (1<<31)
134 134
135 /* 135 /*
136 * Superblock flags that can be altered by MS_REMOUNT 136 * Superblock flags that can be altered by MS_REMOUNT
137 */ 137 */
138 #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK) 138 #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK)
139 139
140 /* 140 /*
141 * Old magic mount flag and mask 141 * Old magic mount flag and mask
142 */ 142 */
143 #define MS_MGC_VAL 0xC0ED0000 143 #define MS_MGC_VAL 0xC0ED0000
144 #define MS_MGC_MSK 0xffff0000 144 #define MS_MGC_MSK 0xffff0000
145 145
146 /* Inode flags - they have nothing to superblock flags now */ 146 /* Inode flags - they have nothing to superblock flags now */
147 147
148 #define S_SYNC 1 /* Writes are synced at once */ 148 #define S_SYNC 1 /* Writes are synced at once */
149 #define S_NOATIME 2 /* Do not update access times */ 149 #define S_NOATIME 2 /* Do not update access times */
150 #define S_APPEND 4 /* Append-only file */ 150 #define S_APPEND 4 /* Append-only file */
151 #define S_IMMUTABLE 8 /* Immutable file */ 151 #define S_IMMUTABLE 8 /* Immutable file */
152 #define S_DEAD 16 /* removed, but still open directory */ 152 #define S_DEAD 16 /* removed, but still open directory */
153 #define S_NOQUOTA 32 /* Inode is not counted to quota */ 153 #define S_NOQUOTA 32 /* Inode is not counted to quota */
154 #define S_DIRSYNC 64 /* Directory modifications are synchronous */ 154 #define S_DIRSYNC 64 /* Directory modifications are synchronous */
155 #define S_NOCMTIME 128 /* Do not update file c/mtime */ 155 #define S_NOCMTIME 128 /* Do not update file c/mtime */
156 #define S_SWAPFILE 256 /* Do not truncate: swapon got its bmaps */ 156 #define S_SWAPFILE 256 /* Do not truncate: swapon got its bmaps */
157 #define S_PRIVATE 512 /* Inode is fs-internal */ 157 #define S_PRIVATE 512 /* Inode is fs-internal */
158 158
159 /* 159 /*
160 * Note that nosuid etc flags are inode-specific: setting some file-system 160 * Note that nosuid etc flags are inode-specific: setting some file-system
161 * flags just means all the inodes inherit those flags by default. It might be 161 * flags just means all the inodes inherit those flags by default. It might be
162 * possible to override it selectively if you really wanted to with some 162 * possible to override it selectively if you really wanted to with some
163 * ioctl() that is not currently implemented. 163 * ioctl() that is not currently implemented.
164 * 164 *
165 * Exception: MS_RDONLY is always applied to the entire file system. 165 * Exception: MS_RDONLY is always applied to the entire file system.
166 * 166 *
167 * Unfortunately, it is possible to change a filesystems flags with it mounted 167 * Unfortunately, it is possible to change a filesystems flags with it mounted
168 * with files in use. This means that all of the inodes will not have their 168 * with files in use. This means that all of the inodes will not have their
169 * i_flags updated. Hence, i_flags no longer inherit the superblock mount 169 * i_flags updated. Hence, i_flags no longer inherit the superblock mount
170 * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org 170 * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org
171 */ 171 */
172 #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg)) 172 #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
173 173
174 #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY) 174 #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
175 #define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || \ 175 #define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || \
176 ((inode)->i_flags & S_SYNC)) 176 ((inode)->i_flags & S_SYNC))
177 #define IS_DIRSYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \ 177 #define IS_DIRSYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
178 ((inode)->i_flags & (S_SYNC|S_DIRSYNC))) 178 ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
179 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK) 179 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
180 #define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME) 180 #define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
181 #define IS_I_VERSION(inode) __IS_FLG(inode, MS_I_VERSION) 181 #define IS_I_VERSION(inode) __IS_FLG(inode, MS_I_VERSION)
182 182
183 #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA) 183 #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
184 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND) 184 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
185 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE) 185 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
186 #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL) 186 #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL)
187 187
188 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD) 188 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
189 #define IS_NOCMTIME(inode) ((inode)->i_flags & S_NOCMTIME) 189 #define IS_NOCMTIME(inode) ((inode)->i_flags & S_NOCMTIME)
190 #define IS_SWAPFILE(inode) ((inode)->i_flags & S_SWAPFILE) 190 #define IS_SWAPFILE(inode) ((inode)->i_flags & S_SWAPFILE)
191 #define IS_PRIVATE(inode) ((inode)->i_flags & S_PRIVATE) 191 #define IS_PRIVATE(inode) ((inode)->i_flags & S_PRIVATE)
192 192
193 /* the read-only stuff doesn't really belong here, but any other place is 193 /* the read-only stuff doesn't really belong here, but any other place is
194 probably as bad and I don't want to create yet another include file. */ 194 probably as bad and I don't want to create yet another include file. */
195 195
196 #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */ 196 #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
197 #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */ 197 #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
198 #define BLKRRPART _IO(0x12,95) /* re-read partition table */ 198 #define BLKRRPART _IO(0x12,95) /* re-read partition table */
199 #define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */ 199 #define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */
200 #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */ 200 #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
201 #define BLKRASET _IO(0x12,98) /* set read ahead for block device */ 201 #define BLKRASET _IO(0x12,98) /* set read ahead for block device */
202 #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */ 202 #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
203 #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */ 203 #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
204 #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */ 204 #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
205 #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */ 205 #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
206 #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */ 206 #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
207 #define BLKSSZGET _IO(0x12,104)/* get block device sector size */ 207 #define BLKSSZGET _IO(0x12,104)/* get block device sector size */
208 #if 0 208 #if 0
209 #define BLKPG _IO(0x12,105)/* See blkpg.h */ 209 #define BLKPG _IO(0x12,105)/* See blkpg.h */
210 210
211 /* Some people are morons. Do not use sizeof! */ 211 /* Some people are morons. Do not use sizeof! */
212 212
213 #define BLKELVGET _IOR(0x12,106,size_t)/* elevator get */ 213 #define BLKELVGET _IOR(0x12,106,size_t)/* elevator get */
214 #define BLKELVSET _IOW(0x12,107,size_t)/* elevator set */ 214 #define BLKELVSET _IOW(0x12,107,size_t)/* elevator set */
215 /* This was here just to show that the number is taken - 215 /* This was here just to show that the number is taken -
216 probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */ 216 probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */
217 #endif 217 #endif
218 /* A jump here: 108-111 have been used for various private purposes. */ 218 /* A jump here: 108-111 have been used for various private purposes. */
219 #define BLKBSZGET _IOR(0x12,112,size_t) 219 #define BLKBSZGET _IOR(0x12,112,size_t)
220 #define BLKBSZSET _IOW(0x12,113,size_t) 220 #define BLKBSZSET _IOW(0x12,113,size_t)
221 #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */ 221 #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
222 #define BLKTRACESETUP _IOWR(0x12,115,struct blk_user_trace_setup) 222 #define BLKTRACESETUP _IOWR(0x12,115,struct blk_user_trace_setup)
223 #define BLKTRACESTART _IO(0x12,116) 223 #define BLKTRACESTART _IO(0x12,116)
224 #define BLKTRACESTOP _IO(0x12,117) 224 #define BLKTRACESTOP _IO(0x12,117)
225 #define BLKTRACETEARDOWN _IO(0x12,118) 225 #define BLKTRACETEARDOWN _IO(0x12,118)
226 #define BLKDISCARD _IO(0x12,119)
226 227
227 #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ 228 #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
228 #define FIBMAP _IO(0x00,1) /* bmap access */ 229 #define FIBMAP _IO(0x00,1) /* bmap access */
229 #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */ 230 #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */
230 231
231 #define FS_IOC_GETFLAGS _IOR('f', 1, long) 232 #define FS_IOC_GETFLAGS _IOR('f', 1, long)
232 #define FS_IOC_SETFLAGS _IOW('f', 2, long) 233 #define FS_IOC_SETFLAGS _IOW('f', 2, long)
233 #define FS_IOC_GETVERSION _IOR('v', 1, long) 234 #define FS_IOC_GETVERSION _IOR('v', 1, long)
234 #define FS_IOC_SETVERSION _IOW('v', 2, long) 235 #define FS_IOC_SETVERSION _IOW('v', 2, long)
235 #define FS_IOC32_GETFLAGS _IOR('f', 1, int) 236 #define FS_IOC32_GETFLAGS _IOR('f', 1, int)
236 #define FS_IOC32_SETFLAGS _IOW('f', 2, int) 237 #define FS_IOC32_SETFLAGS _IOW('f', 2, int)
237 #define FS_IOC32_GETVERSION _IOR('v', 1, int) 238 #define FS_IOC32_GETVERSION _IOR('v', 1, int)
238 #define FS_IOC32_SETVERSION _IOW('v', 2, int) 239 #define FS_IOC32_SETVERSION _IOW('v', 2, int)
239 240
240 /* 241 /*
241 * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS) 242 * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS)
242 */ 243 */
243 #define FS_SECRM_FL 0x00000001 /* Secure deletion */ 244 #define FS_SECRM_FL 0x00000001 /* Secure deletion */
244 #define FS_UNRM_FL 0x00000002 /* Undelete */ 245 #define FS_UNRM_FL 0x00000002 /* Undelete */
245 #define FS_COMPR_FL 0x00000004 /* Compress file */ 246 #define FS_COMPR_FL 0x00000004 /* Compress file */
246 #define FS_SYNC_FL 0x00000008 /* Synchronous updates */ 247 #define FS_SYNC_FL 0x00000008 /* Synchronous updates */
247 #define FS_IMMUTABLE_FL 0x00000010 /* Immutable file */ 248 #define FS_IMMUTABLE_FL 0x00000010 /* Immutable file */
248 #define FS_APPEND_FL 0x00000020 /* writes to file may only append */ 249 #define FS_APPEND_FL 0x00000020 /* writes to file may only append */
249 #define FS_NODUMP_FL 0x00000040 /* do not dump file */ 250 #define FS_NODUMP_FL 0x00000040 /* do not dump file */
250 #define FS_NOATIME_FL 0x00000080 /* do not update atime */ 251 #define FS_NOATIME_FL 0x00000080 /* do not update atime */
251 /* Reserved for compression usage... */ 252 /* Reserved for compression usage... */
252 #define FS_DIRTY_FL 0x00000100 253 #define FS_DIRTY_FL 0x00000100
253 #define FS_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */ 254 #define FS_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
254 #define FS_NOCOMP_FL 0x00000400 /* Don't compress */ 255 #define FS_NOCOMP_FL 0x00000400 /* Don't compress */
255 #define FS_ECOMPR_FL 0x00000800 /* Compression error */ 256 #define FS_ECOMPR_FL 0x00000800 /* Compression error */
256 /* End compression flags --- maybe not all used */ 257 /* End compression flags --- maybe not all used */
257 #define FS_BTREE_FL 0x00001000 /* btree format dir */ 258 #define FS_BTREE_FL 0x00001000 /* btree format dir */
258 #define FS_INDEX_FL 0x00001000 /* hash-indexed directory */ 259 #define FS_INDEX_FL 0x00001000 /* hash-indexed directory */
259 #define FS_IMAGIC_FL 0x00002000 /* AFS directory */ 260 #define FS_IMAGIC_FL 0x00002000 /* AFS directory */
260 #define FS_JOURNAL_DATA_FL 0x00004000 /* Reserved for ext3 */ 261 #define FS_JOURNAL_DATA_FL 0x00004000 /* Reserved for ext3 */
261 #define FS_NOTAIL_FL 0x00008000 /* file tail should not be merged */ 262 #define FS_NOTAIL_FL 0x00008000 /* file tail should not be merged */
262 #define FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ 263 #define FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
263 #define FS_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ 264 #define FS_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
264 #define FS_EXTENT_FL 0x00080000 /* Extents */ 265 #define FS_EXTENT_FL 0x00080000 /* Extents */
265 #define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */ 266 #define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */
266 #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */ 267 #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
267 268
268 #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */ 269 #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
269 #define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */ 270 #define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
270 271
271 272
272 #define SYNC_FILE_RANGE_WAIT_BEFORE 1 273 #define SYNC_FILE_RANGE_WAIT_BEFORE 1
273 #define SYNC_FILE_RANGE_WRITE 2 274 #define SYNC_FILE_RANGE_WRITE 2
274 #define SYNC_FILE_RANGE_WAIT_AFTER 4 275 #define SYNC_FILE_RANGE_WAIT_AFTER 4
275 276
276 #ifdef __KERNEL__ 277 #ifdef __KERNEL__
277 278
278 #include <linux/linkage.h> 279 #include <linux/linkage.h>
279 #include <linux/wait.h> 280 #include <linux/wait.h>
280 #include <linux/types.h> 281 #include <linux/types.h>
281 #include <linux/kdev_t.h> 282 #include <linux/kdev_t.h>
282 #include <linux/dcache.h> 283 #include <linux/dcache.h>
283 #include <linux/path.h> 284 #include <linux/path.h>
284 #include <linux/stat.h> 285 #include <linux/stat.h>
285 #include <linux/cache.h> 286 #include <linux/cache.h>
286 #include <linux/kobject.h> 287 #include <linux/kobject.h>
287 #include <linux/list.h> 288 #include <linux/list.h>
288 #include <linux/radix-tree.h> 289 #include <linux/radix-tree.h>
289 #include <linux/prio_tree.h> 290 #include <linux/prio_tree.h>
290 #include <linux/init.h> 291 #include <linux/init.h>
291 #include <linux/pid.h> 292 #include <linux/pid.h>
292 #include <linux/mutex.h> 293 #include <linux/mutex.h>
293 #include <linux/capability.h> 294 #include <linux/capability.h>
294 #include <linux/semaphore.h> 295 #include <linux/semaphore.h>
295 296
296 #include <asm/atomic.h> 297 #include <asm/atomic.h>
297 #include <asm/byteorder.h> 298 #include <asm/byteorder.h>
298 299
299 struct export_operations; 300 struct export_operations;
300 struct hd_geometry; 301 struct hd_geometry;
301 struct iovec; 302 struct iovec;
302 struct nameidata; 303 struct nameidata;
303 struct kiocb; 304 struct kiocb;
304 struct pipe_inode_info; 305 struct pipe_inode_info;
305 struct poll_table_struct; 306 struct poll_table_struct;
306 struct kstatfs; 307 struct kstatfs;
307 struct vm_area_struct; 308 struct vm_area_struct;
308 struct vfsmount; 309 struct vfsmount;
309 310
310 extern void __init inode_init(void); 311 extern void __init inode_init(void);
311 extern void __init inode_init_early(void); 312 extern void __init inode_init_early(void);
312 extern void __init files_init(unsigned long); 313 extern void __init files_init(unsigned long);
313 314
314 struct buffer_head; 315 struct buffer_head;
315 typedef int (get_block_t)(struct inode *inode, sector_t iblock, 316 typedef int (get_block_t)(struct inode *inode, sector_t iblock,
316 struct buffer_head *bh_result, int create); 317 struct buffer_head *bh_result, int create);
317 typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset, 318 typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
318 ssize_t bytes, void *private); 319 ssize_t bytes, void *private);
319 320
320 /* 321 /*
321 * Attribute flags. These should be or-ed together to figure out what 322 * Attribute flags. These should be or-ed together to figure out what
322 * has been changed! 323 * has been changed!
323 */ 324 */
324 #define ATTR_MODE (1 << 0) 325 #define ATTR_MODE (1 << 0)
325 #define ATTR_UID (1 << 1) 326 #define ATTR_UID (1 << 1)
326 #define ATTR_GID (1 << 2) 327 #define ATTR_GID (1 << 2)
327 #define ATTR_SIZE (1 << 3) 328 #define ATTR_SIZE (1 << 3)
328 #define ATTR_ATIME (1 << 4) 329 #define ATTR_ATIME (1 << 4)
329 #define ATTR_MTIME (1 << 5) 330 #define ATTR_MTIME (1 << 5)
330 #define ATTR_CTIME (1 << 6) 331 #define ATTR_CTIME (1 << 6)
331 #define ATTR_ATIME_SET (1 << 7) 332 #define ATTR_ATIME_SET (1 << 7)
332 #define ATTR_MTIME_SET (1 << 8) 333 #define ATTR_MTIME_SET (1 << 8)
333 #define ATTR_FORCE (1 << 9) /* Not a change, but a change it */ 334 #define ATTR_FORCE (1 << 9) /* Not a change, but a change it */
334 #define ATTR_ATTR_FLAG (1 << 10) 335 #define ATTR_ATTR_FLAG (1 << 10)
335 #define ATTR_KILL_SUID (1 << 11) 336 #define ATTR_KILL_SUID (1 << 11)
336 #define ATTR_KILL_SGID (1 << 12) 337 #define ATTR_KILL_SGID (1 << 12)
337 #define ATTR_FILE (1 << 13) 338 #define ATTR_FILE (1 << 13)
338 #define ATTR_KILL_PRIV (1 << 14) 339 #define ATTR_KILL_PRIV (1 << 14)
339 #define ATTR_OPEN (1 << 15) /* Truncating from open(O_TRUNC) */ 340 #define ATTR_OPEN (1 << 15) /* Truncating from open(O_TRUNC) */
340 #define ATTR_TIMES_SET (1 << 16) 341 #define ATTR_TIMES_SET (1 << 16)
341 342
342 /* 343 /*
343 * This is the Inode Attributes structure, used for notify_change(). It 344 * This is the Inode Attributes structure, used for notify_change(). It
344 * uses the above definitions as flags, to know which values have changed. 345 * uses the above definitions as flags, to know which values have changed.
345 * Also, in this manner, a Filesystem can look at only the values it cares 346 * Also, in this manner, a Filesystem can look at only the values it cares
346 * about. Basically, these are the attributes that the VFS layer can 347 * about. Basically, these are the attributes that the VFS layer can
347 * request to change from the FS layer. 348 * request to change from the FS layer.
348 * 349 *
349 * Derek Atkins <warlord@MIT.EDU> 94-10-20 350 * Derek Atkins <warlord@MIT.EDU> 94-10-20
350 */ 351 */
351 struct iattr { 352 struct iattr {
352 unsigned int ia_valid; 353 unsigned int ia_valid;
353 umode_t ia_mode; 354 umode_t ia_mode;
354 uid_t ia_uid; 355 uid_t ia_uid;
355 gid_t ia_gid; 356 gid_t ia_gid;
356 loff_t ia_size; 357 loff_t ia_size;
357 struct timespec ia_atime; 358 struct timespec ia_atime;
358 struct timespec ia_mtime; 359 struct timespec ia_mtime;
359 struct timespec ia_ctime; 360 struct timespec ia_ctime;
360 361
361 /* 362 /*
362 * Not an attribute, but an auxilary info for filesystems wanting to 363 * Not an attribute, but an auxilary info for filesystems wanting to
363 * implement an ftruncate() like method. NOTE: filesystem should 364 * implement an ftruncate() like method. NOTE: filesystem should
364 * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL). 365 * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL).
365 */ 366 */
366 struct file *ia_file; 367 struct file *ia_file;
367 }; 368 };
368 369
369 /* 370 /*
370 * Includes for diskquotas. 371 * Includes for diskquotas.
371 */ 372 */
372 #include <linux/quota.h> 373 #include <linux/quota.h>
373 374
374 /** 375 /**
375 * enum positive_aop_returns - aop return codes with specific semantics 376 * enum positive_aop_returns - aop return codes with specific semantics
376 * 377 *
377 * @AOP_WRITEPAGE_ACTIVATE: Informs the caller that page writeback has 378 * @AOP_WRITEPAGE_ACTIVATE: Informs the caller that page writeback has
378 * completed, that the page is still locked, and 379 * completed, that the page is still locked, and
379 * should be considered active. The VM uses this hint 380 * should be considered active. The VM uses this hint
380 * to return the page to the active list -- it won't 381 * to return the page to the active list -- it won't
381 * be a candidate for writeback again in the near 382 * be a candidate for writeback again in the near
382 * future. Other callers must be careful to unlock 383 * future. Other callers must be careful to unlock
383 * the page if they get this return. Returned by 384 * the page if they get this return. Returned by
384 * writepage(); 385 * writepage();
385 * 386 *
386 * @AOP_TRUNCATED_PAGE: The AOP method that was handed a locked page has 387 * @AOP_TRUNCATED_PAGE: The AOP method that was handed a locked page has
387 * unlocked it and the page might have been truncated. 388 * unlocked it and the page might have been truncated.
388 * The caller should back up to acquiring a new page and 389 * The caller should back up to acquiring a new page and
389 * trying again. The aop will be taking reasonable 390 * trying again. The aop will be taking reasonable
390 * precautions not to livelock. If the caller held a page 391 * precautions not to livelock. If the caller held a page
391 * reference, it should drop it before retrying. Returned 392 * reference, it should drop it before retrying. Returned
392 * by readpage(). 393 * by readpage().
393 * 394 *
394 * address_space_operation functions return these large constants to indicate 395 * address_space_operation functions return these large constants to indicate
395 * special semantics to the caller. These are much larger than the bytes in a 396 * special semantics to the caller. These are much larger than the bytes in a
396 * page to allow for functions that return the number of bytes operated on in a 397 * page to allow for functions that return the number of bytes operated on in a
397 * given page. 398 * given page.
398 */ 399 */
399 400
400 enum positive_aop_returns { 401 enum positive_aop_returns {
401 AOP_WRITEPAGE_ACTIVATE = 0x80000, 402 AOP_WRITEPAGE_ACTIVATE = 0x80000,
402 AOP_TRUNCATED_PAGE = 0x80001, 403 AOP_TRUNCATED_PAGE = 0x80001,
403 }; 404 };
404 405
405 #define AOP_FLAG_UNINTERRUPTIBLE 0x0001 /* will not do a short write */ 406 #define AOP_FLAG_UNINTERRUPTIBLE 0x0001 /* will not do a short write */
406 #define AOP_FLAG_CONT_EXPAND 0x0002 /* called from cont_expand */ 407 #define AOP_FLAG_CONT_EXPAND 0x0002 /* called from cont_expand */
407 408
408 /* 409 /*
409 * oh the beauties of C type declarations. 410 * oh the beauties of C type declarations.
410 */ 411 */
411 struct page; 412 struct page;
412 struct address_space; 413 struct address_space;
413 struct writeback_control; 414 struct writeback_control;
414 415
415 struct iov_iter { 416 struct iov_iter {
416 const struct iovec *iov; 417 const struct iovec *iov;
417 unsigned long nr_segs; 418 unsigned long nr_segs;
418 size_t iov_offset; 419 size_t iov_offset;
419 size_t count; 420 size_t count;
420 }; 421 };
421 422
422 size_t iov_iter_copy_from_user_atomic(struct page *page, 423 size_t iov_iter_copy_from_user_atomic(struct page *page,
423 struct iov_iter *i, unsigned long offset, size_t bytes); 424 struct iov_iter *i, unsigned long offset, size_t bytes);
424 size_t iov_iter_copy_from_user(struct page *page, 425 size_t iov_iter_copy_from_user(struct page *page,
425 struct iov_iter *i, unsigned long offset, size_t bytes); 426 struct iov_iter *i, unsigned long offset, size_t bytes);
426 void iov_iter_advance(struct iov_iter *i, size_t bytes); 427 void iov_iter_advance(struct iov_iter *i, size_t bytes);
427 int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes); 428 int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes);
428 size_t iov_iter_single_seg_count(struct iov_iter *i); 429 size_t iov_iter_single_seg_count(struct iov_iter *i);
429 430
430 static inline void iov_iter_init(struct iov_iter *i, 431 static inline void iov_iter_init(struct iov_iter *i,
431 const struct iovec *iov, unsigned long nr_segs, 432 const struct iovec *iov, unsigned long nr_segs,
432 size_t count, size_t written) 433 size_t count, size_t written)
433 { 434 {
434 i->iov = iov; 435 i->iov = iov;
435 i->nr_segs = nr_segs; 436 i->nr_segs = nr_segs;
436 i->iov_offset = 0; 437 i->iov_offset = 0;
437 i->count = count + written; 438 i->count = count + written;
438 439
439 iov_iter_advance(i, written); 440 iov_iter_advance(i, written);
440 } 441 }
441 442
442 static inline size_t iov_iter_count(struct iov_iter *i) 443 static inline size_t iov_iter_count(struct iov_iter *i)
443 { 444 {
444 return i->count; 445 return i->count;
445 } 446 }
446 447
447 /* 448 /*
448 * "descriptor" for what we're up to with a read. 449 * "descriptor" for what we're up to with a read.
449 * This allows us to use the same read code yet 450 * This allows us to use the same read code yet
450 * have multiple different users of the data that 451 * have multiple different users of the data that
451 * we read from a file. 452 * we read from a file.
452 * 453 *
453 * The simplest case just copies the data to user 454 * The simplest case just copies the data to user
454 * mode. 455 * mode.
455 */ 456 */
456 typedef struct { 457 typedef struct {
457 size_t written; 458 size_t written;
458 size_t count; 459 size_t count;
459 union { 460 union {
460 char __user *buf; 461 char __user *buf;
461 void *data; 462 void *data;
462 } arg; 463 } arg;
463 int error; 464 int error;
464 } read_descriptor_t; 465 } read_descriptor_t;
465 466
466 typedef int (*read_actor_t)(read_descriptor_t *, struct page *, 467 typedef int (*read_actor_t)(read_descriptor_t *, struct page *,
467 unsigned long, unsigned long); 468 unsigned long, unsigned long);
468 469
469 struct address_space_operations { 470 struct address_space_operations {
470 int (*writepage)(struct page *page, struct writeback_control *wbc); 471 int (*writepage)(struct page *page, struct writeback_control *wbc);
471 int (*readpage)(struct file *, struct page *); 472 int (*readpage)(struct file *, struct page *);
472 void (*sync_page)(struct page *); 473 void (*sync_page)(struct page *);
473 474
474 /* Write back some dirty pages from this mapping. */ 475 /* Write back some dirty pages from this mapping. */
475 int (*writepages)(struct address_space *, struct writeback_control *); 476 int (*writepages)(struct address_space *, struct writeback_control *);
476 477
477 /* Set a page dirty. Return true if this dirtied it */ 478 /* Set a page dirty. Return true if this dirtied it */
478 int (*set_page_dirty)(struct page *page); 479 int (*set_page_dirty)(struct page *page);
479 480
480 int (*readpages)(struct file *filp, struct address_space *mapping, 481 int (*readpages)(struct file *filp, struct address_space *mapping,
481 struct list_head *pages, unsigned nr_pages); 482 struct list_head *pages, unsigned nr_pages);
482 483
483 /* 484 /*
484 * ext3 requires that a successful prepare_write() call be followed 485 * ext3 requires that a successful prepare_write() call be followed
485 * by a commit_write() call - they must be balanced 486 * by a commit_write() call - they must be balanced
486 */ 487 */
487 int (*prepare_write)(struct file *, struct page *, unsigned, unsigned); 488 int (*prepare_write)(struct file *, struct page *, unsigned, unsigned);
488 int (*commit_write)(struct file *, struct page *, unsigned, unsigned); 489 int (*commit_write)(struct file *, struct page *, unsigned, unsigned);
489 490
490 int (*write_begin)(struct file *, struct address_space *mapping, 491 int (*write_begin)(struct file *, struct address_space *mapping,
491 loff_t pos, unsigned len, unsigned flags, 492 loff_t pos, unsigned len, unsigned flags,
492 struct page **pagep, void **fsdata); 493 struct page **pagep, void **fsdata);
493 int (*write_end)(struct file *, struct address_space *mapping, 494 int (*write_end)(struct file *, struct address_space *mapping,
494 loff_t pos, unsigned len, unsigned copied, 495 loff_t pos, unsigned len, unsigned copied,
495 struct page *page, void *fsdata); 496 struct page *page, void *fsdata);
496 497
497 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */ 498 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
498 sector_t (*bmap)(struct address_space *, sector_t); 499 sector_t (*bmap)(struct address_space *, sector_t);
499 void (*invalidatepage) (struct page *, unsigned long); 500 void (*invalidatepage) (struct page *, unsigned long);
500 int (*releasepage) (struct page *, gfp_t); 501 int (*releasepage) (struct page *, gfp_t);
501 ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov, 502 ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
502 loff_t offset, unsigned long nr_segs); 503 loff_t offset, unsigned long nr_segs);
503 int (*get_xip_mem)(struct address_space *, pgoff_t, int, 504 int (*get_xip_mem)(struct address_space *, pgoff_t, int,
504 void **, unsigned long *); 505 void **, unsigned long *);
505 /* migrate the contents of a page to the specified target */ 506 /* migrate the contents of a page to the specified target */
506 int (*migratepage) (struct address_space *, 507 int (*migratepage) (struct address_space *,
507 struct page *, struct page *); 508 struct page *, struct page *);
508 int (*launder_page) (struct page *); 509 int (*launder_page) (struct page *);
509 int (*is_partially_uptodate) (struct page *, read_descriptor_t *, 510 int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
510 unsigned long); 511 unsigned long);
511 }; 512 };
512 513
513 /* 514 /*
514 * pagecache_write_begin/pagecache_write_end must be used by general code 515 * pagecache_write_begin/pagecache_write_end must be used by general code
515 * to write into the pagecache. 516 * to write into the pagecache.
516 */ 517 */
517 int pagecache_write_begin(struct file *, struct address_space *mapping, 518 int pagecache_write_begin(struct file *, struct address_space *mapping,
518 loff_t pos, unsigned len, unsigned flags, 519 loff_t pos, unsigned len, unsigned flags,
519 struct page **pagep, void **fsdata); 520 struct page **pagep, void **fsdata);
520 521
521 int pagecache_write_end(struct file *, struct address_space *mapping, 522 int pagecache_write_end(struct file *, struct address_space *mapping,
522 loff_t pos, unsigned len, unsigned copied, 523 loff_t pos, unsigned len, unsigned copied,
523 struct page *page, void *fsdata); 524 struct page *page, void *fsdata);
524 525
525 struct backing_dev_info; 526 struct backing_dev_info;
526 struct address_space { 527 struct address_space {
527 struct inode *host; /* owner: inode, block_device */ 528 struct inode *host; /* owner: inode, block_device */
528 struct radix_tree_root page_tree; /* radix tree of all pages */ 529 struct radix_tree_root page_tree; /* radix tree of all pages */
529 spinlock_t tree_lock; /* and lock protecting it */ 530 spinlock_t tree_lock; /* and lock protecting it */
530 unsigned int i_mmap_writable;/* count VM_SHARED mappings */ 531 unsigned int i_mmap_writable;/* count VM_SHARED mappings */
531 struct prio_tree_root i_mmap; /* tree of private and shared mappings */ 532 struct prio_tree_root i_mmap; /* tree of private and shared mappings */
532 struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */ 533 struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */
533 spinlock_t i_mmap_lock; /* protect tree, count, list */ 534 spinlock_t i_mmap_lock; /* protect tree, count, list */
534 unsigned int truncate_count; /* Cover race condition with truncate */ 535 unsigned int truncate_count; /* Cover race condition with truncate */
535 unsigned long nrpages; /* number of total pages */ 536 unsigned long nrpages; /* number of total pages */
536 pgoff_t writeback_index;/* writeback starts here */ 537 pgoff_t writeback_index;/* writeback starts here */
537 const struct address_space_operations *a_ops; /* methods */ 538 const struct address_space_operations *a_ops; /* methods */
538 unsigned long flags; /* error bits/gfp mask */ 539 unsigned long flags; /* error bits/gfp mask */
539 struct backing_dev_info *backing_dev_info; /* device readahead, etc */ 540 struct backing_dev_info *backing_dev_info; /* device readahead, etc */
540 spinlock_t private_lock; /* for use by the address_space */ 541 spinlock_t private_lock; /* for use by the address_space */
541 struct list_head private_list; /* ditto */ 542 struct list_head private_list; /* ditto */
542 struct address_space *assoc_mapping; /* ditto */ 543 struct address_space *assoc_mapping; /* ditto */
543 } __attribute__((aligned(sizeof(long)))); 544 } __attribute__((aligned(sizeof(long))));
544 /* 545 /*
545 * On most architectures that alignment is already the case; but 546 * On most architectures that alignment is already the case; but
546 * must be enforced here for CRIS, to let the least signficant bit 547 * must be enforced here for CRIS, to let the least signficant bit
547 * of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON. 548 * of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON.
548 */ 549 */
549 550
550 struct block_device { 551 struct block_device {
551 dev_t bd_dev; /* not a kdev_t - it's a search key */ 552 dev_t bd_dev; /* not a kdev_t - it's a search key */
552 struct inode * bd_inode; /* will die */ 553 struct inode * bd_inode; /* will die */
553 int bd_openers; 554 int bd_openers;
554 struct mutex bd_mutex; /* open/close mutex */ 555 struct mutex bd_mutex; /* open/close mutex */
555 struct semaphore bd_mount_sem; 556 struct semaphore bd_mount_sem;
556 struct list_head bd_inodes; 557 struct list_head bd_inodes;
557 void * bd_holder; 558 void * bd_holder;
558 int bd_holders; 559 int bd_holders;
559 #ifdef CONFIG_SYSFS 560 #ifdef CONFIG_SYSFS
560 struct list_head bd_holder_list; 561 struct list_head bd_holder_list;
561 #endif 562 #endif
562 struct block_device * bd_contains; 563 struct block_device * bd_contains;
563 unsigned bd_block_size; 564 unsigned bd_block_size;
564 struct hd_struct * bd_part; 565 struct hd_struct * bd_part;
565 /* number of times partitions within this device have been opened. */ 566 /* number of times partitions within this device have been opened. */
566 unsigned bd_part_count; 567 unsigned bd_part_count;
567 int bd_invalidated; 568 int bd_invalidated;
568 struct gendisk * bd_disk; 569 struct gendisk * bd_disk;
569 struct list_head bd_list; 570 struct list_head bd_list;
570 struct backing_dev_info *bd_inode_backing_dev_info; 571 struct backing_dev_info *bd_inode_backing_dev_info;
571 /* 572 /*
572 * Private data. You must have bd_claim'ed the block_device 573 * Private data. You must have bd_claim'ed the block_device
573 * to use this. NOTE: bd_claim allows an owner to claim 574 * to use this. NOTE: bd_claim allows an owner to claim
574 * the same device multiple times, the owner must take special 575 * the same device multiple times, the owner must take special
575 * care to not mess up bd_private for that case. 576 * care to not mess up bd_private for that case.
576 */ 577 */
577 unsigned long bd_private; 578 unsigned long bd_private;
578 }; 579 };
579 580
580 /* 581 /*
581 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache 582 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
582 * radix trees 583 * radix trees
583 */ 584 */
584 #define PAGECACHE_TAG_DIRTY 0 585 #define PAGECACHE_TAG_DIRTY 0
585 #define PAGECACHE_TAG_WRITEBACK 1 586 #define PAGECACHE_TAG_WRITEBACK 1
586 587
587 int mapping_tagged(struct address_space *mapping, int tag); 588 int mapping_tagged(struct address_space *mapping, int tag);
588 589
589 /* 590 /*
590 * Might pages of this file be mapped into userspace? 591 * Might pages of this file be mapped into userspace?
591 */ 592 */
592 static inline int mapping_mapped(struct address_space *mapping) 593 static inline int mapping_mapped(struct address_space *mapping)
593 { 594 {
594 return !prio_tree_empty(&mapping->i_mmap) || 595 return !prio_tree_empty(&mapping->i_mmap) ||
595 !list_empty(&mapping->i_mmap_nonlinear); 596 !list_empty(&mapping->i_mmap_nonlinear);
596 } 597 }
597 598
598 /* 599 /*
599 * Might pages of this file have been modified in userspace? 600 * Might pages of this file have been modified in userspace?
600 * Note that i_mmap_writable counts all VM_SHARED vmas: do_mmap_pgoff 601 * Note that i_mmap_writable counts all VM_SHARED vmas: do_mmap_pgoff
601 * marks vma as VM_SHARED if it is shared, and the file was opened for 602 * marks vma as VM_SHARED if it is shared, and the file was opened for
602 * writing i.e. vma may be mprotected writable even if now readonly. 603 * writing i.e. vma may be mprotected writable even if now readonly.
603 */ 604 */
604 static inline int mapping_writably_mapped(struct address_space *mapping) 605 static inline int mapping_writably_mapped(struct address_space *mapping)
605 { 606 {
606 return mapping->i_mmap_writable != 0; 607 return mapping->i_mmap_writable != 0;
607 } 608 }
608 609
609 /* 610 /*
610 * Use sequence counter to get consistent i_size on 32-bit processors. 611 * Use sequence counter to get consistent i_size on 32-bit processors.
611 */ 612 */
612 #if BITS_PER_LONG==32 && defined(CONFIG_SMP) 613 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
613 #include <linux/seqlock.h> 614 #include <linux/seqlock.h>
614 #define __NEED_I_SIZE_ORDERED 615 #define __NEED_I_SIZE_ORDERED
615 #define i_size_ordered_init(inode) seqcount_init(&inode->i_size_seqcount) 616 #define i_size_ordered_init(inode) seqcount_init(&inode->i_size_seqcount)
616 #else 617 #else
617 #define i_size_ordered_init(inode) do { } while (0) 618 #define i_size_ordered_init(inode) do { } while (0)
618 #endif 619 #endif
619 620
620 struct inode { 621 struct inode {
621 struct hlist_node i_hash; 622 struct hlist_node i_hash;
622 struct list_head i_list; 623 struct list_head i_list;
623 struct list_head i_sb_list; 624 struct list_head i_sb_list;
624 struct list_head i_dentry; 625 struct list_head i_dentry;
625 unsigned long i_ino; 626 unsigned long i_ino;
626 atomic_t i_count; 627 atomic_t i_count;
627 unsigned int i_nlink; 628 unsigned int i_nlink;
628 uid_t i_uid; 629 uid_t i_uid;
629 gid_t i_gid; 630 gid_t i_gid;
630 dev_t i_rdev; 631 dev_t i_rdev;
631 u64 i_version; 632 u64 i_version;
632 loff_t i_size; 633 loff_t i_size;
633 #ifdef __NEED_I_SIZE_ORDERED 634 #ifdef __NEED_I_SIZE_ORDERED
634 seqcount_t i_size_seqcount; 635 seqcount_t i_size_seqcount;
635 #endif 636 #endif
636 struct timespec i_atime; 637 struct timespec i_atime;
637 struct timespec i_mtime; 638 struct timespec i_mtime;
638 struct timespec i_ctime; 639 struct timespec i_ctime;
639 unsigned int i_blkbits; 640 unsigned int i_blkbits;
640 blkcnt_t i_blocks; 641 blkcnt_t i_blocks;
641 unsigned short i_bytes; 642 unsigned short i_bytes;
642 umode_t i_mode; 643 umode_t i_mode;
643 spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */ 644 spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */
644 struct mutex i_mutex; 645 struct mutex i_mutex;
645 struct rw_semaphore i_alloc_sem; 646 struct rw_semaphore i_alloc_sem;
646 const struct inode_operations *i_op; 647 const struct inode_operations *i_op;
647 const struct file_operations *i_fop; /* former ->i_op->default_file_ops */ 648 const struct file_operations *i_fop; /* former ->i_op->default_file_ops */
648 struct super_block *i_sb; 649 struct super_block *i_sb;
649 struct file_lock *i_flock; 650 struct file_lock *i_flock;
650 struct address_space *i_mapping; 651 struct address_space *i_mapping;
651 struct address_space i_data; 652 struct address_space i_data;
652 #ifdef CONFIG_QUOTA 653 #ifdef CONFIG_QUOTA
653 struct dquot *i_dquot[MAXQUOTAS]; 654 struct dquot *i_dquot[MAXQUOTAS];
654 #endif 655 #endif
655 struct list_head i_devices; 656 struct list_head i_devices;
656 union { 657 union {
657 struct pipe_inode_info *i_pipe; 658 struct pipe_inode_info *i_pipe;
658 struct block_device *i_bdev; 659 struct block_device *i_bdev;
659 struct cdev *i_cdev; 660 struct cdev *i_cdev;
660 }; 661 };
661 int i_cindex; 662 int i_cindex;
662 663
663 __u32 i_generation; 664 __u32 i_generation;
664 665
665 #ifdef CONFIG_DNOTIFY 666 #ifdef CONFIG_DNOTIFY
666 unsigned long i_dnotify_mask; /* Directory notify events */ 667 unsigned long i_dnotify_mask; /* Directory notify events */
667 struct dnotify_struct *i_dnotify; /* for directory notifications */ 668 struct dnotify_struct *i_dnotify; /* for directory notifications */
668 #endif 669 #endif
669 670
670 #ifdef CONFIG_INOTIFY 671 #ifdef CONFIG_INOTIFY
671 struct list_head inotify_watches; /* watches on this inode */ 672 struct list_head inotify_watches; /* watches on this inode */
672 struct mutex inotify_mutex; /* protects the watches list */ 673 struct mutex inotify_mutex; /* protects the watches list */
673 #endif 674 #endif
674 675
675 unsigned long i_state; 676 unsigned long i_state;
676 unsigned long dirtied_when; /* jiffies of first dirtying */ 677 unsigned long dirtied_when; /* jiffies of first dirtying */
677 678
678 unsigned int i_flags; 679 unsigned int i_flags;
679 680
680 atomic_t i_writecount; 681 atomic_t i_writecount;
681 #ifdef CONFIG_SECURITY 682 #ifdef CONFIG_SECURITY
682 void *i_security; 683 void *i_security;
683 #endif 684 #endif
684 void *i_private; /* fs or device private pointer */ 685 void *i_private; /* fs or device private pointer */
685 }; 686 };
686 687
687 /* 688 /*
688 * inode->i_mutex nesting subclasses for the lock validator: 689 * inode->i_mutex nesting subclasses for the lock validator:
689 * 690 *
690 * 0: the object of the current VFS operation 691 * 0: the object of the current VFS operation
691 * 1: parent 692 * 1: parent
692 * 2: child/target 693 * 2: child/target
693 * 3: quota file 694 * 3: quota file
694 * 695 *
695 * The locking order between these classes is 696 * The locking order between these classes is
696 * parent -> child -> normal -> xattr -> quota 697 * parent -> child -> normal -> xattr -> quota
697 */ 698 */
698 enum inode_i_mutex_lock_class 699 enum inode_i_mutex_lock_class
699 { 700 {
700 I_MUTEX_NORMAL, 701 I_MUTEX_NORMAL,
701 I_MUTEX_PARENT, 702 I_MUTEX_PARENT,
702 I_MUTEX_CHILD, 703 I_MUTEX_CHILD,
703 I_MUTEX_XATTR, 704 I_MUTEX_XATTR,
704 I_MUTEX_QUOTA 705 I_MUTEX_QUOTA
705 }; 706 };
706 707
707 extern void inode_double_lock(struct inode *inode1, struct inode *inode2); 708 extern void inode_double_lock(struct inode *inode1, struct inode *inode2);
708 extern void inode_double_unlock(struct inode *inode1, struct inode *inode2); 709 extern void inode_double_unlock(struct inode *inode1, struct inode *inode2);
709 710
710 /* 711 /*
711 * NOTE: in a 32bit arch with a preemptable kernel and 712 * NOTE: in a 32bit arch with a preemptable kernel and
712 * an UP compile the i_size_read/write must be atomic 713 * an UP compile the i_size_read/write must be atomic
713 * with respect to the local cpu (unlike with preempt disabled), 714 * with respect to the local cpu (unlike with preempt disabled),
714 * but they don't need to be atomic with respect to other cpus like in 715 * but they don't need to be atomic with respect to other cpus like in
715 * true SMP (so they need either to either locally disable irq around 716 * true SMP (so they need either to either locally disable irq around
716 * the read or for example on x86 they can be still implemented as a 717 * the read or for example on x86 they can be still implemented as a
717 * cmpxchg8b without the need of the lock prefix). For SMP compiles 718 * cmpxchg8b without the need of the lock prefix). For SMP compiles
718 * and 64bit archs it makes no difference if preempt is enabled or not. 719 * and 64bit archs it makes no difference if preempt is enabled or not.
719 */ 720 */
720 static inline loff_t i_size_read(const struct inode *inode) 721 static inline loff_t i_size_read(const struct inode *inode)
721 { 722 {
722 #if BITS_PER_LONG==32 && defined(CONFIG_SMP) 723 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
723 loff_t i_size; 724 loff_t i_size;
724 unsigned int seq; 725 unsigned int seq;
725 726
726 do { 727 do {
727 seq = read_seqcount_begin(&inode->i_size_seqcount); 728 seq = read_seqcount_begin(&inode->i_size_seqcount);
728 i_size = inode->i_size; 729 i_size = inode->i_size;
729 } while (read_seqcount_retry(&inode->i_size_seqcount, seq)); 730 } while (read_seqcount_retry(&inode->i_size_seqcount, seq));
730 return i_size; 731 return i_size;
731 #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT) 732 #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
732 loff_t i_size; 733 loff_t i_size;
733 734
734 preempt_disable(); 735 preempt_disable();
735 i_size = inode->i_size; 736 i_size = inode->i_size;
736 preempt_enable(); 737 preempt_enable();
737 return i_size; 738 return i_size;
738 #else 739 #else
739 return inode->i_size; 740 return inode->i_size;
740 #endif 741 #endif
741 } 742 }
742 743
743 /* 744 /*
744 * NOTE: unlike i_size_read(), i_size_write() does need locking around it 745 * NOTE: unlike i_size_read(), i_size_write() does need locking around it
745 * (normally i_mutex), otherwise on 32bit/SMP an update of i_size_seqcount 746 * (normally i_mutex), otherwise on 32bit/SMP an update of i_size_seqcount
746 * can be lost, resulting in subsequent i_size_read() calls spinning forever. 747 * can be lost, resulting in subsequent i_size_read() calls spinning forever.
747 */ 748 */
748 static inline void i_size_write(struct inode *inode, loff_t i_size) 749 static inline void i_size_write(struct inode *inode, loff_t i_size)
749 { 750 {
750 #if BITS_PER_LONG==32 && defined(CONFIG_SMP) 751 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
751 write_seqcount_begin(&inode->i_size_seqcount); 752 write_seqcount_begin(&inode->i_size_seqcount);
752 inode->i_size = i_size; 753 inode->i_size = i_size;
753 write_seqcount_end(&inode->i_size_seqcount); 754 write_seqcount_end(&inode->i_size_seqcount);
754 #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT) 755 #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
755 preempt_disable(); 756 preempt_disable();
756 inode->i_size = i_size; 757 inode->i_size = i_size;
757 preempt_enable(); 758 preempt_enable();
758 #else 759 #else
759 inode->i_size = i_size; 760 inode->i_size = i_size;
760 #endif 761 #endif
761 } 762 }
762 763
763 static inline unsigned iminor(const struct inode *inode) 764 static inline unsigned iminor(const struct inode *inode)
764 { 765 {
765 return MINOR(inode->i_rdev); 766 return MINOR(inode->i_rdev);
766 } 767 }
767 768
768 static inline unsigned imajor(const struct inode *inode) 769 static inline unsigned imajor(const struct inode *inode)
769 { 770 {
770 return MAJOR(inode->i_rdev); 771 return MAJOR(inode->i_rdev);
771 } 772 }
772 773
773 extern struct block_device *I_BDEV(struct inode *inode); 774 extern struct block_device *I_BDEV(struct inode *inode);
774 775
775 struct fown_struct { 776 struct fown_struct {
776 rwlock_t lock; /* protects pid, uid, euid fields */ 777 rwlock_t lock; /* protects pid, uid, euid fields */
777 struct pid *pid; /* pid or -pgrp where SIGIO should be sent */ 778 struct pid *pid; /* pid or -pgrp where SIGIO should be sent */
778 enum pid_type pid_type; /* Kind of process group SIGIO should be sent to */ 779 enum pid_type pid_type; /* Kind of process group SIGIO should be sent to */
779 uid_t uid, euid; /* uid/euid of process setting the owner */ 780 uid_t uid, euid; /* uid/euid of process setting the owner */
780 int signum; /* posix.1b rt signal to be delivered on IO */ 781 int signum; /* posix.1b rt signal to be delivered on IO */
781 }; 782 };
782 783
783 /* 784 /*
784 * Track a single file's readahead state 785 * Track a single file's readahead state
785 */ 786 */
786 struct file_ra_state { 787 struct file_ra_state {
787 pgoff_t start; /* where readahead started */ 788 pgoff_t start; /* where readahead started */
788 unsigned int size; /* # of readahead pages */ 789 unsigned int size; /* # of readahead pages */
789 unsigned int async_size; /* do asynchronous readahead when 790 unsigned int async_size; /* do asynchronous readahead when
790 there are only # of pages ahead */ 791 there are only # of pages ahead */
791 792
792 unsigned int ra_pages; /* Maximum readahead window */ 793 unsigned int ra_pages; /* Maximum readahead window */
793 int mmap_miss; /* Cache miss stat for mmap accesses */ 794 int mmap_miss; /* Cache miss stat for mmap accesses */
794 loff_t prev_pos; /* Cache last read() position */ 795 loff_t prev_pos; /* Cache last read() position */
795 }; 796 };
796 797
797 /* 798 /*
798 * Check if @index falls in the readahead windows. 799 * Check if @index falls in the readahead windows.
799 */ 800 */
800 static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index) 801 static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index)
801 { 802 {
802 return (index >= ra->start && 803 return (index >= ra->start &&
803 index < ra->start + ra->size); 804 index < ra->start + ra->size);
804 } 805 }
805 806
806 #define FILE_MNT_WRITE_TAKEN 1 807 #define FILE_MNT_WRITE_TAKEN 1
807 #define FILE_MNT_WRITE_RELEASED 2 808 #define FILE_MNT_WRITE_RELEASED 2
808 809
809 struct file { 810 struct file {
810 /* 811 /*
811 * fu_list becomes invalid after file_free is called and queued via 812 * fu_list becomes invalid after file_free is called and queued via
812 * fu_rcuhead for RCU freeing 813 * fu_rcuhead for RCU freeing
813 */ 814 */
814 union { 815 union {
815 struct list_head fu_list; 816 struct list_head fu_list;
816 struct rcu_head fu_rcuhead; 817 struct rcu_head fu_rcuhead;
817 } f_u; 818 } f_u;
818 struct path f_path; 819 struct path f_path;
819 #define f_dentry f_path.dentry 820 #define f_dentry f_path.dentry
820 #define f_vfsmnt f_path.mnt 821 #define f_vfsmnt f_path.mnt
821 const struct file_operations *f_op; 822 const struct file_operations *f_op;
822 atomic_long_t f_count; 823 atomic_long_t f_count;
823 unsigned int f_flags; 824 unsigned int f_flags;
824 mode_t f_mode; 825 mode_t f_mode;
825 loff_t f_pos; 826 loff_t f_pos;
826 struct fown_struct f_owner; 827 struct fown_struct f_owner;
827 unsigned int f_uid, f_gid; 828 unsigned int f_uid, f_gid;
828 struct file_ra_state f_ra; 829 struct file_ra_state f_ra;
829 830
830 u64 f_version; 831 u64 f_version;
831 #ifdef CONFIG_SECURITY 832 #ifdef CONFIG_SECURITY
832 void *f_security; 833 void *f_security;
833 #endif 834 #endif
834 /* needed for tty driver, and maybe others */ 835 /* needed for tty driver, and maybe others */
835 void *private_data; 836 void *private_data;
836 837
837 #ifdef CONFIG_EPOLL 838 #ifdef CONFIG_EPOLL
838 /* Used by fs/eventpoll.c to link all the hooks to this file */ 839 /* Used by fs/eventpoll.c to link all the hooks to this file */
839 struct list_head f_ep_links; 840 struct list_head f_ep_links;
840 spinlock_t f_ep_lock; 841 spinlock_t f_ep_lock;
841 #endif /* #ifdef CONFIG_EPOLL */ 842 #endif /* #ifdef CONFIG_EPOLL */
842 struct address_space *f_mapping; 843 struct address_space *f_mapping;
843 #ifdef CONFIG_DEBUG_WRITECOUNT 844 #ifdef CONFIG_DEBUG_WRITECOUNT
844 unsigned long f_mnt_write_state; 845 unsigned long f_mnt_write_state;
845 #endif 846 #endif
846 }; 847 };
847 extern spinlock_t files_lock; 848 extern spinlock_t files_lock;
848 #define file_list_lock() spin_lock(&files_lock); 849 #define file_list_lock() spin_lock(&files_lock);
849 #define file_list_unlock() spin_unlock(&files_lock); 850 #define file_list_unlock() spin_unlock(&files_lock);
850 851
851 #define get_file(x) atomic_long_inc(&(x)->f_count) 852 #define get_file(x) atomic_long_inc(&(x)->f_count)
852 #define file_count(x) atomic_long_read(&(x)->f_count) 853 #define file_count(x) atomic_long_read(&(x)->f_count)
853 854
854 #ifdef CONFIG_DEBUG_WRITECOUNT 855 #ifdef CONFIG_DEBUG_WRITECOUNT
855 static inline void file_take_write(struct file *f) 856 static inline void file_take_write(struct file *f)
856 { 857 {
857 WARN_ON(f->f_mnt_write_state != 0); 858 WARN_ON(f->f_mnt_write_state != 0);
858 f->f_mnt_write_state = FILE_MNT_WRITE_TAKEN; 859 f->f_mnt_write_state = FILE_MNT_WRITE_TAKEN;
859 } 860 }
860 static inline void file_release_write(struct file *f) 861 static inline void file_release_write(struct file *f)
861 { 862 {
862 f->f_mnt_write_state |= FILE_MNT_WRITE_RELEASED; 863 f->f_mnt_write_state |= FILE_MNT_WRITE_RELEASED;
863 } 864 }
864 static inline void file_reset_write(struct file *f) 865 static inline void file_reset_write(struct file *f)
865 { 866 {
866 f->f_mnt_write_state = 0; 867 f->f_mnt_write_state = 0;
867 } 868 }
868 static inline void file_check_state(struct file *f) 869 static inline void file_check_state(struct file *f)
869 { 870 {
870 /* 871 /*
871 * At this point, either both or neither of these bits 872 * At this point, either both or neither of these bits
872 * should be set. 873 * should be set.
873 */ 874 */
874 WARN_ON(f->f_mnt_write_state == FILE_MNT_WRITE_TAKEN); 875 WARN_ON(f->f_mnt_write_state == FILE_MNT_WRITE_TAKEN);
875 WARN_ON(f->f_mnt_write_state == FILE_MNT_WRITE_RELEASED); 876 WARN_ON(f->f_mnt_write_state == FILE_MNT_WRITE_RELEASED);
876 } 877 }
877 static inline int file_check_writeable(struct file *f) 878 static inline int file_check_writeable(struct file *f)
878 { 879 {
879 if (f->f_mnt_write_state == FILE_MNT_WRITE_TAKEN) 880 if (f->f_mnt_write_state == FILE_MNT_WRITE_TAKEN)
880 return 0; 881 return 0;
881 printk(KERN_WARNING "writeable file with no " 882 printk(KERN_WARNING "writeable file with no "
882 "mnt_want_write()\n"); 883 "mnt_want_write()\n");
883 WARN_ON(1); 884 WARN_ON(1);
884 return -EINVAL; 885 return -EINVAL;
885 } 886 }
886 #else /* !CONFIG_DEBUG_WRITECOUNT */ 887 #else /* !CONFIG_DEBUG_WRITECOUNT */
887 static inline void file_take_write(struct file *filp) {} 888 static inline void file_take_write(struct file *filp) {}
888 static inline void file_release_write(struct file *filp) {} 889 static inline void file_release_write(struct file *filp) {}
889 static inline void file_reset_write(struct file *filp) {} 890 static inline void file_reset_write(struct file *filp) {}
890 static inline void file_check_state(struct file *filp) {} 891 static inline void file_check_state(struct file *filp) {}
891 static inline int file_check_writeable(struct file *filp) 892 static inline int file_check_writeable(struct file *filp)
892 { 893 {
893 return 0; 894 return 0;
894 } 895 }
895 #endif /* CONFIG_DEBUG_WRITECOUNT */ 896 #endif /* CONFIG_DEBUG_WRITECOUNT */
896 897
897 #define MAX_NON_LFS ((1UL<<31) - 1) 898 #define MAX_NON_LFS ((1UL<<31) - 1)
898 899
899 /* Page cache limit. The filesystems should put that into their s_maxbytes 900 /* Page cache limit. The filesystems should put that into their s_maxbytes
900 limits, otherwise bad things can happen in VM. */ 901 limits, otherwise bad things can happen in VM. */
901 #if BITS_PER_LONG==32 902 #if BITS_PER_LONG==32
902 #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1) 903 #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
903 #elif BITS_PER_LONG==64 904 #elif BITS_PER_LONG==64
904 #define MAX_LFS_FILESIZE 0x7fffffffffffffffUL 905 #define MAX_LFS_FILESIZE 0x7fffffffffffffffUL
905 #endif 906 #endif
906 907
907 #define FL_POSIX 1 908 #define FL_POSIX 1
908 #define FL_FLOCK 2 909 #define FL_FLOCK 2
909 #define FL_ACCESS 8 /* not trying to lock, just looking */ 910 #define FL_ACCESS 8 /* not trying to lock, just looking */
910 #define FL_EXISTS 16 /* when unlocking, test for existence */ 911 #define FL_EXISTS 16 /* when unlocking, test for existence */
911 #define FL_LEASE 32 /* lease held on this file */ 912 #define FL_LEASE 32 /* lease held on this file */
912 #define FL_CLOSE 64 /* unlock on close */ 913 #define FL_CLOSE 64 /* unlock on close */
913 #define FL_SLEEP 128 /* A blocking lock */ 914 #define FL_SLEEP 128 /* A blocking lock */
914 915
915 /* 916 /*
916 * Special return value from posix_lock_file() and vfs_lock_file() for 917 * Special return value from posix_lock_file() and vfs_lock_file() for
917 * asynchronous locking. 918 * asynchronous locking.
918 */ 919 */
919 #define FILE_LOCK_DEFERRED 1 920 #define FILE_LOCK_DEFERRED 1
920 921
921 /* 922 /*
922 * The POSIX file lock owner is determined by 923 * The POSIX file lock owner is determined by
923 * the "struct files_struct" in the thread group 924 * the "struct files_struct" in the thread group
924 * (or NULL for no owner - BSD locks). 925 * (or NULL for no owner - BSD locks).
925 * 926 *
926 * Lockd stuffs a "host" pointer into this. 927 * Lockd stuffs a "host" pointer into this.
927 */ 928 */
928 typedef struct files_struct *fl_owner_t; 929 typedef struct files_struct *fl_owner_t;
929 930
930 struct file_lock_operations { 931 struct file_lock_operations {
931 void (*fl_copy_lock)(struct file_lock *, struct file_lock *); 932 void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
932 void (*fl_release_private)(struct file_lock *); 933 void (*fl_release_private)(struct file_lock *);
933 }; 934 };
934 935
935 struct lock_manager_operations { 936 struct lock_manager_operations {
936 int (*fl_compare_owner)(struct file_lock *, struct file_lock *); 937 int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
937 void (*fl_notify)(struct file_lock *); /* unblock callback */ 938 void (*fl_notify)(struct file_lock *); /* unblock callback */
938 int (*fl_grant)(struct file_lock *, struct file_lock *, int); 939 int (*fl_grant)(struct file_lock *, struct file_lock *, int);
939 void (*fl_copy_lock)(struct file_lock *, struct file_lock *); 940 void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
940 void (*fl_release_private)(struct file_lock *); 941 void (*fl_release_private)(struct file_lock *);
941 void (*fl_break)(struct file_lock *); 942 void (*fl_break)(struct file_lock *);
942 int (*fl_mylease)(struct file_lock *, struct file_lock *); 943 int (*fl_mylease)(struct file_lock *, struct file_lock *);
943 int (*fl_change)(struct file_lock **, int); 944 int (*fl_change)(struct file_lock **, int);
944 }; 945 };
945 946
946 /* that will die - we need it for nfs_lock_info */ 947 /* that will die - we need it for nfs_lock_info */
947 #include <linux/nfs_fs_i.h> 948 #include <linux/nfs_fs_i.h>
948 949
949 struct file_lock { 950 struct file_lock {
950 struct file_lock *fl_next; /* singly linked list for this inode */ 951 struct file_lock *fl_next; /* singly linked list for this inode */
951 struct list_head fl_link; /* doubly linked list of all locks */ 952 struct list_head fl_link; /* doubly linked list of all locks */
952 struct list_head fl_block; /* circular list of blocked processes */ 953 struct list_head fl_block; /* circular list of blocked processes */
953 fl_owner_t fl_owner; 954 fl_owner_t fl_owner;
954 unsigned char fl_flags; 955 unsigned char fl_flags;
955 unsigned char fl_type; 956 unsigned char fl_type;
956 unsigned int fl_pid; 957 unsigned int fl_pid;
957 struct pid *fl_nspid; 958 struct pid *fl_nspid;
958 wait_queue_head_t fl_wait; 959 wait_queue_head_t fl_wait;
959 struct file *fl_file; 960 struct file *fl_file;
960 loff_t fl_start; 961 loff_t fl_start;
961 loff_t fl_end; 962 loff_t fl_end;
962 963
963 struct fasync_struct * fl_fasync; /* for lease break notifications */ 964 struct fasync_struct * fl_fasync; /* for lease break notifications */
964 unsigned long fl_break_time; /* for nonblocking lease breaks */ 965 unsigned long fl_break_time; /* for nonblocking lease breaks */
965 966
966 struct file_lock_operations *fl_ops; /* Callbacks for filesystems */ 967 struct file_lock_operations *fl_ops; /* Callbacks for filesystems */
967 struct lock_manager_operations *fl_lmops; /* Callbacks for lockmanagers */ 968 struct lock_manager_operations *fl_lmops; /* Callbacks for lockmanagers */
968 union { 969 union {
969 struct nfs_lock_info nfs_fl; 970 struct nfs_lock_info nfs_fl;
970 struct nfs4_lock_info nfs4_fl; 971 struct nfs4_lock_info nfs4_fl;
971 struct { 972 struct {
972 struct list_head link; /* link in AFS vnode's pending_locks list */ 973 struct list_head link; /* link in AFS vnode's pending_locks list */
973 int state; /* state of grant or error if -ve */ 974 int state; /* state of grant or error if -ve */
974 } afs; 975 } afs;
975 } fl_u; 976 } fl_u;
976 }; 977 };
977 978
978 /* The following constant reflects the upper bound of the file/locking space */ 979 /* The following constant reflects the upper bound of the file/locking space */
979 #ifndef OFFSET_MAX 980 #ifndef OFFSET_MAX
980 #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1))) 981 #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
981 #define OFFSET_MAX INT_LIMIT(loff_t) 982 #define OFFSET_MAX INT_LIMIT(loff_t)
982 #define OFFT_OFFSET_MAX INT_LIMIT(off_t) 983 #define OFFT_OFFSET_MAX INT_LIMIT(off_t)
983 #endif 984 #endif
984 985
985 #include <linux/fcntl.h> 986 #include <linux/fcntl.h>
986 987
987 extern int fcntl_getlk(struct file *, struct flock __user *); 988 extern int fcntl_getlk(struct file *, struct flock __user *);
988 extern int fcntl_setlk(unsigned int, struct file *, unsigned int, 989 extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
989 struct flock __user *); 990 struct flock __user *);
990 991
991 #if BITS_PER_LONG == 32 992 #if BITS_PER_LONG == 32
992 extern int fcntl_getlk64(struct file *, struct flock64 __user *); 993 extern int fcntl_getlk64(struct file *, struct flock64 __user *);
993 extern int fcntl_setlk64(unsigned int, struct file *, unsigned int, 994 extern int fcntl_setlk64(unsigned int, struct file *, unsigned int,
994 struct flock64 __user *); 995 struct flock64 __user *);
995 #endif 996 #endif
996 997
997 extern void send_sigio(struct fown_struct *fown, int fd, int band); 998 extern void send_sigio(struct fown_struct *fown, int fd, int band);
998 extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg); 999 extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
999 extern int fcntl_getlease(struct file *filp); 1000 extern int fcntl_getlease(struct file *filp);
1000 1001
1001 /* fs/sync.c */ 1002 /* fs/sync.c */
1002 extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset, 1003 extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
1003 loff_t endbyte, unsigned int flags); 1004 loff_t endbyte, unsigned int flags);
1004 1005
1005 /* fs/locks.c */ 1006 /* fs/locks.c */
1006 extern void locks_init_lock(struct file_lock *); 1007 extern void locks_init_lock(struct file_lock *);
1007 extern void locks_copy_lock(struct file_lock *, struct file_lock *); 1008 extern void locks_copy_lock(struct file_lock *, struct file_lock *);
1008 extern void __locks_copy_lock(struct file_lock *, const struct file_lock *); 1009 extern void __locks_copy_lock(struct file_lock *, const struct file_lock *);
1009 extern void locks_remove_posix(struct file *, fl_owner_t); 1010 extern void locks_remove_posix(struct file *, fl_owner_t);
1010 extern void locks_remove_flock(struct file *); 1011 extern void locks_remove_flock(struct file *);
1011 extern void posix_test_lock(struct file *, struct file_lock *); 1012 extern void posix_test_lock(struct file *, struct file_lock *);
1012 extern int posix_lock_file(struct file *, struct file_lock *, struct file_lock *); 1013 extern int posix_lock_file(struct file *, struct file_lock *, struct file_lock *);
1013 extern int posix_lock_file_wait(struct file *, struct file_lock *); 1014 extern int posix_lock_file_wait(struct file *, struct file_lock *);
1014 extern int posix_unblock_lock(struct file *, struct file_lock *); 1015 extern int posix_unblock_lock(struct file *, struct file_lock *);
1015 extern int vfs_test_lock(struct file *, struct file_lock *); 1016 extern int vfs_test_lock(struct file *, struct file_lock *);
1016 extern int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *); 1017 extern int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *);
1017 extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl); 1018 extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl);
1018 extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl); 1019 extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl);
1019 extern int __break_lease(struct inode *inode, unsigned int flags); 1020 extern int __break_lease(struct inode *inode, unsigned int flags);
1020 extern void lease_get_mtime(struct inode *, struct timespec *time); 1021 extern void lease_get_mtime(struct inode *, struct timespec *time);
1021 extern int generic_setlease(struct file *, long, struct file_lock **); 1022 extern int generic_setlease(struct file *, long, struct file_lock **);
1022 extern int vfs_setlease(struct file *, long, struct file_lock **); 1023 extern int vfs_setlease(struct file *, long, struct file_lock **);
1023 extern int lease_modify(struct file_lock **, int); 1024 extern int lease_modify(struct file_lock **, int);
1024 extern int lock_may_read(struct inode *, loff_t start, unsigned long count); 1025 extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
1025 extern int lock_may_write(struct inode *, loff_t start, unsigned long count); 1026 extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
1026 extern struct seq_operations locks_seq_operations; 1027 extern struct seq_operations locks_seq_operations;
1027 1028
1028 struct fasync_struct { 1029 struct fasync_struct {
1029 int magic; 1030 int magic;
1030 int fa_fd; 1031 int fa_fd;
1031 struct fasync_struct *fa_next; /* singly linked list */ 1032 struct fasync_struct *fa_next; /* singly linked list */
1032 struct file *fa_file; 1033 struct file *fa_file;
1033 }; 1034 };
1034 1035
1035 #define FASYNC_MAGIC 0x4601 1036 #define FASYNC_MAGIC 0x4601
1036 1037
1037 /* SMP safe fasync helpers: */ 1038 /* SMP safe fasync helpers: */
1038 extern int fasync_helper(int, struct file *, int, struct fasync_struct **); 1039 extern int fasync_helper(int, struct file *, int, struct fasync_struct **);
1039 /* can be called from interrupts */ 1040 /* can be called from interrupts */
1040 extern void kill_fasync(struct fasync_struct **, int, int); 1041 extern void kill_fasync(struct fasync_struct **, int, int);
1041 /* only for net: no internal synchronization */ 1042 /* only for net: no internal synchronization */
1042 extern void __kill_fasync(struct fasync_struct *, int, int); 1043 extern void __kill_fasync(struct fasync_struct *, int, int);
1043 1044
1044 extern int __f_setown(struct file *filp, struct pid *, enum pid_type, int force); 1045 extern int __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
1045 extern int f_setown(struct file *filp, unsigned long arg, int force); 1046 extern int f_setown(struct file *filp, unsigned long arg, int force);
1046 extern void f_delown(struct file *filp); 1047 extern void f_delown(struct file *filp);
1047 extern pid_t f_getown(struct file *filp); 1048 extern pid_t f_getown(struct file *filp);
1048 extern int send_sigurg(struct fown_struct *fown); 1049 extern int send_sigurg(struct fown_struct *fown);
1049 1050
1050 /* 1051 /*
1051 * Umount options 1052 * Umount options
1052 */ 1053 */
1053 1054
1054 #define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */ 1055 #define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */
1055 #define MNT_DETACH 0x00000002 /* Just detach from the tree */ 1056 #define MNT_DETACH 0x00000002 /* Just detach from the tree */
1056 #define MNT_EXPIRE 0x00000004 /* Mark for expiry */ 1057 #define MNT_EXPIRE 0x00000004 /* Mark for expiry */
1057 1058
1058 extern struct list_head super_blocks; 1059 extern struct list_head super_blocks;
1059 extern spinlock_t sb_lock; 1060 extern spinlock_t sb_lock;
1060 1061
1061 #define sb_entry(list) list_entry((list), struct super_block, s_list) 1062 #define sb_entry(list) list_entry((list), struct super_block, s_list)
1062 #define S_BIAS (1<<30) 1063 #define S_BIAS (1<<30)
1063 struct super_block { 1064 struct super_block {
1064 struct list_head s_list; /* Keep this first */ 1065 struct list_head s_list; /* Keep this first */
1065 dev_t s_dev; /* search index; _not_ kdev_t */ 1066 dev_t s_dev; /* search index; _not_ kdev_t */
1066 unsigned long s_blocksize; 1067 unsigned long s_blocksize;
1067 unsigned char s_blocksize_bits; 1068 unsigned char s_blocksize_bits;
1068 unsigned char s_dirt; 1069 unsigned char s_dirt;
1069 unsigned long long s_maxbytes; /* Max file size */ 1070 unsigned long long s_maxbytes; /* Max file size */
1070 struct file_system_type *s_type; 1071 struct file_system_type *s_type;
1071 const struct super_operations *s_op; 1072 const struct super_operations *s_op;
1072 struct dquot_operations *dq_op; 1073 struct dquot_operations *dq_op;
1073 struct quotactl_ops *s_qcop; 1074 struct quotactl_ops *s_qcop;
1074 const struct export_operations *s_export_op; 1075 const struct export_operations *s_export_op;
1075 unsigned long s_flags; 1076 unsigned long s_flags;
1076 unsigned long s_magic; 1077 unsigned long s_magic;
1077 struct dentry *s_root; 1078 struct dentry *s_root;
1078 struct rw_semaphore s_umount; 1079 struct rw_semaphore s_umount;
1079 struct mutex s_lock; 1080 struct mutex s_lock;
1080 int s_count; 1081 int s_count;
1081 int s_syncing; 1082 int s_syncing;
1082 int s_need_sync_fs; 1083 int s_need_sync_fs;
1083 atomic_t s_active; 1084 atomic_t s_active;
1084 #ifdef CONFIG_SECURITY 1085 #ifdef CONFIG_SECURITY
1085 void *s_security; 1086 void *s_security;
1086 #endif 1087 #endif
1087 struct xattr_handler **s_xattr; 1088 struct xattr_handler **s_xattr;
1088 1089
1089 struct list_head s_inodes; /* all inodes */ 1090 struct list_head s_inodes; /* all inodes */
1090 struct list_head s_dirty; /* dirty inodes */ 1091 struct list_head s_dirty; /* dirty inodes */
1091 struct list_head s_io; /* parked for writeback */ 1092 struct list_head s_io; /* parked for writeback */
1092 struct list_head s_more_io; /* parked for more writeback */ 1093 struct list_head s_more_io; /* parked for more writeback */
1093 struct hlist_head s_anon; /* anonymous dentries for (nfs) exporting */ 1094 struct hlist_head s_anon; /* anonymous dentries for (nfs) exporting */
1094 struct list_head s_files; 1095 struct list_head s_files;
1095 /* s_dentry_lru and s_nr_dentry_unused are protected by dcache_lock */ 1096 /* s_dentry_lru and s_nr_dentry_unused are protected by dcache_lock */
1096 struct list_head s_dentry_lru; /* unused dentry lru */ 1097 struct list_head s_dentry_lru; /* unused dentry lru */
1097 int s_nr_dentry_unused; /* # of dentry on lru */ 1098 int s_nr_dentry_unused; /* # of dentry on lru */
1098 1099
1099 struct block_device *s_bdev; 1100 struct block_device *s_bdev;
1100 struct mtd_info *s_mtd; 1101 struct mtd_info *s_mtd;
1101 struct list_head s_instances; 1102 struct list_head s_instances;
1102 struct quota_info s_dquot; /* Diskquota specific options */ 1103 struct quota_info s_dquot; /* Diskquota specific options */
1103 1104
1104 int s_frozen; 1105 int s_frozen;
1105 wait_queue_head_t s_wait_unfrozen; 1106 wait_queue_head_t s_wait_unfrozen;
1106 1107
1107 char s_id[32]; /* Informational name */ 1108 char s_id[32]; /* Informational name */
1108 1109
1109 void *s_fs_info; /* Filesystem private info */ 1110 void *s_fs_info; /* Filesystem private info */
1110 1111
1111 /* 1112 /*
1112 * The next field is for VFS *only*. No filesystems have any business 1113 * The next field is for VFS *only*. No filesystems have any business
1113 * even looking at it. You had been warned. 1114 * even looking at it. You had been warned.
1114 */ 1115 */
1115 struct mutex s_vfs_rename_mutex; /* Kludge */ 1116 struct mutex s_vfs_rename_mutex; /* Kludge */
1116 1117
1117 /* Granularity of c/m/atime in ns. 1118 /* Granularity of c/m/atime in ns.
1118 Cannot be worse than a second */ 1119 Cannot be worse than a second */
1119 u32 s_time_gran; 1120 u32 s_time_gran;
1120 1121
1121 /* 1122 /*
1122 * Filesystem subtype. If non-empty the filesystem type field 1123 * Filesystem subtype. If non-empty the filesystem type field
1123 * in /proc/mounts will be "type.subtype" 1124 * in /proc/mounts will be "type.subtype"
1124 */ 1125 */
1125 char *s_subtype; 1126 char *s_subtype;
1126 1127
1127 /* 1128 /*
1128 * Saved mount options for lazy filesystems using 1129 * Saved mount options for lazy filesystems using
1129 * generic_show_options() 1130 * generic_show_options()
1130 */ 1131 */
1131 char *s_options; 1132 char *s_options;
1132 }; 1133 };
1133 1134
1134 extern struct timespec current_fs_time(struct super_block *sb); 1135 extern struct timespec current_fs_time(struct super_block *sb);
1135 1136
1136 /* 1137 /*
1137 * Snapshotting support. 1138 * Snapshotting support.
1138 */ 1139 */
1139 enum { 1140 enum {
1140 SB_UNFROZEN = 0, 1141 SB_UNFROZEN = 0,
1141 SB_FREEZE_WRITE = 1, 1142 SB_FREEZE_WRITE = 1,
1142 SB_FREEZE_TRANS = 2, 1143 SB_FREEZE_TRANS = 2,
1143 }; 1144 };
1144 1145
1145 #define vfs_check_frozen(sb, level) \ 1146 #define vfs_check_frozen(sb, level) \
1146 wait_event((sb)->s_wait_unfrozen, ((sb)->s_frozen < (level))) 1147 wait_event((sb)->s_wait_unfrozen, ((sb)->s_frozen < (level)))
1147 1148
1148 #define get_fs_excl() atomic_inc(&current->fs_excl) 1149 #define get_fs_excl() atomic_inc(&current->fs_excl)
1149 #define put_fs_excl() atomic_dec(&current->fs_excl) 1150 #define put_fs_excl() atomic_dec(&current->fs_excl)
1150 #define has_fs_excl() atomic_read(&current->fs_excl) 1151 #define has_fs_excl() atomic_read(&current->fs_excl)
1151 1152
1152 #define is_owner_or_cap(inode) \ 1153 #define is_owner_or_cap(inode) \
1153 ((current->fsuid == (inode)->i_uid) || capable(CAP_FOWNER)) 1154 ((current->fsuid == (inode)->i_uid) || capable(CAP_FOWNER))
1154 1155
1155 /* not quite ready to be deprecated, but... */ 1156 /* not quite ready to be deprecated, but... */
1156 extern void lock_super(struct super_block *); 1157 extern void lock_super(struct super_block *);
1157 extern void unlock_super(struct super_block *); 1158 extern void unlock_super(struct super_block *);
1158 1159
1159 /* 1160 /*
1160 * VFS helper functions.. 1161 * VFS helper functions..
1161 */ 1162 */
1162 extern int vfs_permission(struct nameidata *, int); 1163 extern int vfs_permission(struct nameidata *, int);
1163 extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *); 1164 extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *);
1164 extern int vfs_mkdir(struct inode *, struct dentry *, int); 1165 extern int vfs_mkdir(struct inode *, struct dentry *, int);
1165 extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t); 1166 extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
1166 extern int vfs_symlink(struct inode *, struct dentry *, const char *); 1167 extern int vfs_symlink(struct inode *, struct dentry *, const char *);
1167 extern int vfs_link(struct dentry *, struct inode *, struct dentry *); 1168 extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
1168 extern int vfs_rmdir(struct inode *, struct dentry *); 1169 extern int vfs_rmdir(struct inode *, struct dentry *);
1169 extern int vfs_unlink(struct inode *, struct dentry *); 1170 extern int vfs_unlink(struct inode *, struct dentry *);
1170 extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); 1171 extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
1171 1172
1172 /* 1173 /*
1173 * VFS dentry helper functions. 1174 * VFS dentry helper functions.
1174 */ 1175 */
1175 extern void dentry_unhash(struct dentry *dentry); 1176 extern void dentry_unhash(struct dentry *dentry);
1176 1177
1177 /* 1178 /*
1178 * VFS file helper functions. 1179 * VFS file helper functions.
1179 */ 1180 */
1180 extern int file_permission(struct file *, int); 1181 extern int file_permission(struct file *, int);
1181 1182
1182 /* 1183 /*
1183 * File types 1184 * File types
1184 * 1185 *
1185 * NOTE! These match bits 12..15 of stat.st_mode 1186 * NOTE! These match bits 12..15 of stat.st_mode
1186 * (ie "(i_mode >> 12) & 15"). 1187 * (ie "(i_mode >> 12) & 15").
1187 */ 1188 */
1188 #define DT_UNKNOWN 0 1189 #define DT_UNKNOWN 0
1189 #define DT_FIFO 1 1190 #define DT_FIFO 1
1190 #define DT_CHR 2 1191 #define DT_CHR 2
1191 #define DT_DIR 4 1192 #define DT_DIR 4
1192 #define DT_BLK 6 1193 #define DT_BLK 6
1193 #define DT_REG 8 1194 #define DT_REG 8
1194 #define DT_LNK 10 1195 #define DT_LNK 10
1195 #define DT_SOCK 12 1196 #define DT_SOCK 12
1196 #define DT_WHT 14 1197 #define DT_WHT 14
1197 1198
1198 #define OSYNC_METADATA (1<<0) 1199 #define OSYNC_METADATA (1<<0)
1199 #define OSYNC_DATA (1<<1) 1200 #define OSYNC_DATA (1<<1)
1200 #define OSYNC_INODE (1<<2) 1201 #define OSYNC_INODE (1<<2)
1201 int generic_osync_inode(struct inode *, struct address_space *, int); 1202 int generic_osync_inode(struct inode *, struct address_space *, int);
1202 1203
1203 /* 1204 /*
1204 * This is the "filldir" function type, used by readdir() to let 1205 * This is the "filldir" function type, used by readdir() to let
1205 * the kernel specify what kind of dirent layout it wants to have. 1206 * the kernel specify what kind of dirent layout it wants to have.
1206 * This allows the kernel to read directories into kernel space or 1207 * This allows the kernel to read directories into kernel space or
1207 * to have different dirent layouts depending on the binary type. 1208 * to have different dirent layouts depending on the binary type.
1208 */ 1209 */
1209 typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned); 1210 typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
1210 1211
1211 struct block_device_operations { 1212 struct block_device_operations {
1212 int (*open) (struct inode *, struct file *); 1213 int (*open) (struct inode *, struct file *);
1213 int (*release) (struct inode *, struct file *); 1214 int (*release) (struct inode *, struct file *);
1214 int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long); 1215 int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
1215 long (*unlocked_ioctl) (struct file *, unsigned, unsigned long); 1216 long (*unlocked_ioctl) (struct file *, unsigned, unsigned long);
1216 long (*compat_ioctl) (struct file *, unsigned, unsigned long); 1217 long (*compat_ioctl) (struct file *, unsigned, unsigned long);
1217 int (*direct_access) (struct block_device *, sector_t, 1218 int (*direct_access) (struct block_device *, sector_t,
1218 void **, unsigned long *); 1219 void **, unsigned long *);
1219 int (*media_changed) (struct gendisk *); 1220 int (*media_changed) (struct gendisk *);
1220 int (*revalidate_disk) (struct gendisk *); 1221 int (*revalidate_disk) (struct gendisk *);
1221 int (*getgeo)(struct block_device *, struct hd_geometry *); 1222 int (*getgeo)(struct block_device *, struct hd_geometry *);
1222 struct module *owner; 1223 struct module *owner;
1223 }; 1224 };
1224 1225
1225 /* These macros are for out of kernel modules to test that 1226 /* These macros are for out of kernel modules to test that
1226 * the kernel supports the unlocked_ioctl and compat_ioctl 1227 * the kernel supports the unlocked_ioctl and compat_ioctl
1227 * fields in struct file_operations. */ 1228 * fields in struct file_operations. */
1228 #define HAVE_COMPAT_IOCTL 1 1229 #define HAVE_COMPAT_IOCTL 1
1229 #define HAVE_UNLOCKED_IOCTL 1 1230 #define HAVE_UNLOCKED_IOCTL 1
1230 1231
1231 /* 1232 /*
1232 * NOTE: 1233 * NOTE:
1233 * read, write, poll, fsync, readv, writev, unlocked_ioctl and compat_ioctl 1234 * read, write, poll, fsync, readv, writev, unlocked_ioctl and compat_ioctl
1234 * can be called without the big kernel lock held in all filesystems. 1235 * can be called without the big kernel lock held in all filesystems.
1235 */ 1236 */
1236 struct file_operations { 1237 struct file_operations {
1237 struct module *owner; 1238 struct module *owner;
1238 loff_t (*llseek) (struct file *, loff_t, int); 1239 loff_t (*llseek) (struct file *, loff_t, int);
1239 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); 1240 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
1240 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); 1241 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
1241 ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); 1242 ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
1242 ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); 1243 ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
1243 int (*readdir) (struct file *, void *, filldir_t); 1244 int (*readdir) (struct file *, void *, filldir_t);
1244 unsigned int (*poll) (struct file *, struct poll_table_struct *); 1245 unsigned int (*poll) (struct file *, struct poll_table_struct *);
1245 int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long); 1246 int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
1246 long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); 1247 long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
1247 long (*compat_ioctl) (struct file *, unsigned int, unsigned long); 1248 long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
1248 int (*mmap) (struct file *, struct vm_area_struct *); 1249 int (*mmap) (struct file *, struct vm_area_struct *);
1249 int (*open) (struct inode *, struct file *); 1250 int (*open) (struct inode *, struct file *);
1250 int (*flush) (struct file *, fl_owner_t id); 1251 int (*flush) (struct file *, fl_owner_t id);
1251 int (*release) (struct inode *, struct file *); 1252 int (*release) (struct inode *, struct file *);
1252 int (*fsync) (struct file *, struct dentry *, int datasync); 1253 int (*fsync) (struct file *, struct dentry *, int datasync);
1253 int (*aio_fsync) (struct kiocb *, int datasync); 1254 int (*aio_fsync) (struct kiocb *, int datasync);
1254 int (*fasync) (int, struct file *, int); 1255 int (*fasync) (int, struct file *, int);
1255 int (*lock) (struct file *, int, struct file_lock *); 1256 int (*lock) (struct file *, int, struct file_lock *);
1256 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int); 1257 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
1257 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); 1258 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
1258 int (*check_flags)(int); 1259 int (*check_flags)(int);
1259 int (*dir_notify)(struct file *filp, unsigned long arg); 1260 int (*dir_notify)(struct file *filp, unsigned long arg);
1260 int (*flock) (struct file *, int, struct file_lock *); 1261 int (*flock) (struct file *, int, struct file_lock *);
1261 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); 1262 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
1262 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); 1263 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
1263 int (*setlease)(struct file *, long, struct file_lock **); 1264 int (*setlease)(struct file *, long, struct file_lock **);
1264 }; 1265 };
1265 1266
1266 struct inode_operations { 1267 struct inode_operations {
1267 int (*create) (struct inode *,struct dentry *,int, struct nameidata *); 1268 int (*create) (struct inode *,struct dentry *,int, struct nameidata *);
1268 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *); 1269 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
1269 int (*link) (struct dentry *,struct inode *,struct dentry *); 1270 int (*link) (struct dentry *,struct inode *,struct dentry *);
1270 int (*unlink) (struct inode *,struct dentry *); 1271 int (*unlink) (struct inode *,struct dentry *);
1271 int (*symlink) (struct inode *,struct dentry *,const char *); 1272 int (*symlink) (struct inode *,struct dentry *,const char *);
1272 int (*mkdir) (struct inode *,struct dentry *,int); 1273 int (*mkdir) (struct inode *,struct dentry *,int);
1273 int (*rmdir) (struct inode *,struct dentry *); 1274 int (*rmdir) (struct inode *,struct dentry *);
1274 int (*mknod) (struct inode *,struct dentry *,int,dev_t); 1275 int (*mknod) (struct inode *,struct dentry *,int,dev_t);
1275 int (*rename) (struct inode *, struct dentry *, 1276 int (*rename) (struct inode *, struct dentry *,
1276 struct inode *, struct dentry *); 1277 struct inode *, struct dentry *);
1277 int (*readlink) (struct dentry *, char __user *,int); 1278 int (*readlink) (struct dentry *, char __user *,int);
1278 void * (*follow_link) (struct dentry *, struct nameidata *); 1279 void * (*follow_link) (struct dentry *, struct nameidata *);
1279 void (*put_link) (struct dentry *, struct nameidata *, void *); 1280 void (*put_link) (struct dentry *, struct nameidata *, void *);
1280 void (*truncate) (struct inode *); 1281 void (*truncate) (struct inode *);
1281 int (*permission) (struct inode *, int); 1282 int (*permission) (struct inode *, int);
1282 int (*setattr) (struct dentry *, struct iattr *); 1283 int (*setattr) (struct dentry *, struct iattr *);
1283 int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *); 1284 int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *);
1284 int (*setxattr) (struct dentry *, const char *,const void *,size_t,int); 1285 int (*setxattr) (struct dentry *, const char *,const void *,size_t,int);
1285 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t); 1286 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
1286 ssize_t (*listxattr) (struct dentry *, char *, size_t); 1287 ssize_t (*listxattr) (struct dentry *, char *, size_t);
1287 int (*removexattr) (struct dentry *, const char *); 1288 int (*removexattr) (struct dentry *, const char *);
1288 void (*truncate_range)(struct inode *, loff_t, loff_t); 1289 void (*truncate_range)(struct inode *, loff_t, loff_t);
1289 long (*fallocate)(struct inode *inode, int mode, loff_t offset, 1290 long (*fallocate)(struct inode *inode, int mode, loff_t offset,
1290 loff_t len); 1291 loff_t len);
1291 }; 1292 };
1292 1293
1293 struct seq_file; 1294 struct seq_file;
1294 1295
1295 ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, 1296 ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
1296 unsigned long nr_segs, unsigned long fast_segs, 1297 unsigned long nr_segs, unsigned long fast_segs,
1297 struct iovec *fast_pointer, 1298 struct iovec *fast_pointer,
1298 struct iovec **ret_pointer); 1299 struct iovec **ret_pointer);
1299 1300
1300 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *); 1301 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
1301 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *); 1302 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
1302 extern ssize_t vfs_readv(struct file *, const struct iovec __user *, 1303 extern ssize_t vfs_readv(struct file *, const struct iovec __user *,
1303 unsigned long, loff_t *); 1304 unsigned long, loff_t *);
1304 extern ssize_t vfs_writev(struct file *, const struct iovec __user *, 1305 extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
1305 unsigned long, loff_t *); 1306 unsigned long, loff_t *);
1306 1307
1307 struct super_operations { 1308 struct super_operations {
1308 struct inode *(*alloc_inode)(struct super_block *sb); 1309 struct inode *(*alloc_inode)(struct super_block *sb);
1309 void (*destroy_inode)(struct inode *); 1310 void (*destroy_inode)(struct inode *);
1310 1311
1311 void (*dirty_inode) (struct inode *); 1312 void (*dirty_inode) (struct inode *);
1312 int (*write_inode) (struct inode *, int); 1313 int (*write_inode) (struct inode *, int);
1313 void (*drop_inode) (struct inode *); 1314 void (*drop_inode) (struct inode *);
1314 void (*delete_inode) (struct inode *); 1315 void (*delete_inode) (struct inode *);
1315 void (*put_super) (struct super_block *); 1316 void (*put_super) (struct super_block *);
1316 void (*write_super) (struct super_block *); 1317 void (*write_super) (struct super_block *);
1317 int (*sync_fs)(struct super_block *sb, int wait); 1318 int (*sync_fs)(struct super_block *sb, int wait);
1318 void (*write_super_lockfs) (struct super_block *); 1319 void (*write_super_lockfs) (struct super_block *);
1319 void (*unlockfs) (struct super_block *); 1320 void (*unlockfs) (struct super_block *);
1320 int (*statfs) (struct dentry *, struct kstatfs *); 1321 int (*statfs) (struct dentry *, struct kstatfs *);
1321 int (*remount_fs) (struct super_block *, int *, char *); 1322 int (*remount_fs) (struct super_block *, int *, char *);
1322 void (*clear_inode) (struct inode *); 1323 void (*clear_inode) (struct inode *);
1323 void (*umount_begin) (struct super_block *); 1324 void (*umount_begin) (struct super_block *);
1324 1325
1325 int (*show_options)(struct seq_file *, struct vfsmount *); 1326 int (*show_options)(struct seq_file *, struct vfsmount *);
1326 int (*show_stats)(struct seq_file *, struct vfsmount *); 1327 int (*show_stats)(struct seq_file *, struct vfsmount *);
1327 #ifdef CONFIG_QUOTA 1328 #ifdef CONFIG_QUOTA
1328 ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t); 1329 ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
1329 ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); 1330 ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
1330 #endif 1331 #endif
1331 }; 1332 };
1332 1333
1333 /* 1334 /*
1334 * Inode state bits. Protected by inode_lock. 1335 * Inode state bits. Protected by inode_lock.
1335 * 1336 *
1336 * Three bits determine the dirty state of the inode, I_DIRTY_SYNC, 1337 * Three bits determine the dirty state of the inode, I_DIRTY_SYNC,
1337 * I_DIRTY_DATASYNC and I_DIRTY_PAGES. 1338 * I_DIRTY_DATASYNC and I_DIRTY_PAGES.
1338 * 1339 *
1339 * Four bits define the lifetime of an inode. Initially, inodes are I_NEW, 1340 * Four bits define the lifetime of an inode. Initially, inodes are I_NEW,
1340 * until that flag is cleared. I_WILL_FREE, I_FREEING and I_CLEAR are set at 1341 * until that flag is cleared. I_WILL_FREE, I_FREEING and I_CLEAR are set at
1341 * various stages of removing an inode. 1342 * various stages of removing an inode.
1342 * 1343 *
1343 * Two bits are used for locking and completion notification, I_LOCK and I_SYNC. 1344 * Two bits are used for locking and completion notification, I_LOCK and I_SYNC.
1344 * 1345 *
1345 * I_DIRTY_SYNC Inode is dirty, but doesn't have to be written on 1346 * I_DIRTY_SYNC Inode is dirty, but doesn't have to be written on
1346 * fdatasync(). i_atime is the usual cause. 1347 * fdatasync(). i_atime is the usual cause.
1347 * I_DIRTY_DATASYNC Data-related inode changes pending. We keep track of 1348 * I_DIRTY_DATASYNC Data-related inode changes pending. We keep track of
1348 * these changes separately from I_DIRTY_SYNC so that we 1349 * these changes separately from I_DIRTY_SYNC so that we
1349 * don't have to write inode on fdatasync() when only 1350 * don't have to write inode on fdatasync() when only
1350 * mtime has changed in it. 1351 * mtime has changed in it.
1351 * I_DIRTY_PAGES Inode has dirty pages. Inode itself may be clean. 1352 * I_DIRTY_PAGES Inode has dirty pages. Inode itself may be clean.
1352 * I_NEW get_new_inode() sets i_state to I_LOCK|I_NEW. Both 1353 * I_NEW get_new_inode() sets i_state to I_LOCK|I_NEW. Both
1353 * are cleared by unlock_new_inode(), called from iget(). 1354 * are cleared by unlock_new_inode(), called from iget().
1354 * I_WILL_FREE Must be set when calling write_inode_now() if i_count 1355 * I_WILL_FREE Must be set when calling write_inode_now() if i_count
1355 * is zero. I_FREEING must be set when I_WILL_FREE is 1356 * is zero. I_FREEING must be set when I_WILL_FREE is
1356 * cleared. 1357 * cleared.
1357 * I_FREEING Set when inode is about to be freed but still has dirty 1358 * I_FREEING Set when inode is about to be freed but still has dirty
1358 * pages or buffers attached or the inode itself is still 1359 * pages or buffers attached or the inode itself is still
1359 * dirty. 1360 * dirty.
1360 * I_CLEAR Set by clear_inode(). In this state the inode is clean 1361 * I_CLEAR Set by clear_inode(). In this state the inode is clean
1361 * and can be destroyed. 1362 * and can be destroyed.
1362 * 1363 *
1363 * Inodes that are I_WILL_FREE, I_FREEING or I_CLEAR are 1364 * Inodes that are I_WILL_FREE, I_FREEING or I_CLEAR are
1364 * prohibited for many purposes. iget() must wait for 1365 * prohibited for many purposes. iget() must wait for
1365 * the inode to be completely released, then create it 1366 * the inode to be completely released, then create it
1366 * anew. Other functions will just ignore such inodes, 1367 * anew. Other functions will just ignore such inodes,
1367 * if appropriate. I_LOCK is used for waiting. 1368 * if appropriate. I_LOCK is used for waiting.
1368 * 1369 *
1369 * I_LOCK Serves as both a mutex and completion notification. 1370 * I_LOCK Serves as both a mutex and completion notification.
1370 * New inodes set I_LOCK. If two processes both create 1371 * New inodes set I_LOCK. If two processes both create
1371 * the same inode, one of them will release its inode and 1372 * the same inode, one of them will release its inode and
1372 * wait for I_LOCK to be released before returning. 1373 * wait for I_LOCK to be released before returning.
1373 * Inodes in I_WILL_FREE, I_FREEING or I_CLEAR state can 1374 * Inodes in I_WILL_FREE, I_FREEING or I_CLEAR state can
1374 * also cause waiting on I_LOCK, without I_LOCK actually 1375 * also cause waiting on I_LOCK, without I_LOCK actually
1375 * being set. find_inode() uses this to prevent returning 1376 * being set. find_inode() uses this to prevent returning
1376 * nearly-dead inodes. 1377 * nearly-dead inodes.
1377 * I_SYNC Similar to I_LOCK, but limited in scope to writeback 1378 * I_SYNC Similar to I_LOCK, but limited in scope to writeback
1378 * of inode dirty data. Having a separate lock for this 1379 * of inode dirty data. Having a separate lock for this
1379 * purpose reduces latency and prevents some filesystem- 1380 * purpose reduces latency and prevents some filesystem-
1380 * specific deadlocks. 1381 * specific deadlocks.
1381 * 1382 *
1382 * Q: What is the difference between I_WILL_FREE and I_FREEING? 1383 * Q: What is the difference between I_WILL_FREE and I_FREEING?
1383 * Q: igrab() only checks on (I_FREEING|I_WILL_FREE). Should it also check on 1384 * Q: igrab() only checks on (I_FREEING|I_WILL_FREE). Should it also check on
1384 * I_CLEAR? If not, why? 1385 * I_CLEAR? If not, why?
1385 */ 1386 */
1386 #define I_DIRTY_SYNC 1 1387 #define I_DIRTY_SYNC 1
1387 #define I_DIRTY_DATASYNC 2 1388 #define I_DIRTY_DATASYNC 2
1388 #define I_DIRTY_PAGES 4 1389 #define I_DIRTY_PAGES 4
1389 #define I_NEW 8 1390 #define I_NEW 8
1390 #define I_WILL_FREE 16 1391 #define I_WILL_FREE 16
1391 #define I_FREEING 32 1392 #define I_FREEING 32
1392 #define I_CLEAR 64 1393 #define I_CLEAR 64
1393 #define __I_LOCK 7 1394 #define __I_LOCK 7
1394 #define I_LOCK (1 << __I_LOCK) 1395 #define I_LOCK (1 << __I_LOCK)
1395 #define __I_SYNC 8 1396 #define __I_SYNC 8
1396 #define I_SYNC (1 << __I_SYNC) 1397 #define I_SYNC (1 << __I_SYNC)
1397 1398
1398 #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES) 1399 #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)
1399 1400
1400 extern void __mark_inode_dirty(struct inode *, int); 1401 extern void __mark_inode_dirty(struct inode *, int);
1401 static inline void mark_inode_dirty(struct inode *inode) 1402 static inline void mark_inode_dirty(struct inode *inode)
1402 { 1403 {
1403 __mark_inode_dirty(inode, I_DIRTY); 1404 __mark_inode_dirty(inode, I_DIRTY);
1404 } 1405 }
1405 1406
1406 static inline void mark_inode_dirty_sync(struct inode *inode) 1407 static inline void mark_inode_dirty_sync(struct inode *inode)
1407 { 1408 {
1408 __mark_inode_dirty(inode, I_DIRTY_SYNC); 1409 __mark_inode_dirty(inode, I_DIRTY_SYNC);
1409 } 1410 }
1410 1411
1411 /** 1412 /**
1412 * inc_nlink - directly increment an inode's link count 1413 * inc_nlink - directly increment an inode's link count
1413 * @inode: inode 1414 * @inode: inode
1414 * 1415 *
1415 * This is a low-level filesystem helper to replace any 1416 * This is a low-level filesystem helper to replace any
1416 * direct filesystem manipulation of i_nlink. Currently, 1417 * direct filesystem manipulation of i_nlink. Currently,
1417 * it is only here for parity with dec_nlink(). 1418 * it is only here for parity with dec_nlink().
1418 */ 1419 */
1419 static inline void inc_nlink(struct inode *inode) 1420 static inline void inc_nlink(struct inode *inode)
1420 { 1421 {
1421 inode->i_nlink++; 1422 inode->i_nlink++;
1422 } 1423 }
1423 1424
1424 static inline void inode_inc_link_count(struct inode *inode) 1425 static inline void inode_inc_link_count(struct inode *inode)
1425 { 1426 {
1426 inc_nlink(inode); 1427 inc_nlink(inode);
1427 mark_inode_dirty(inode); 1428 mark_inode_dirty(inode);
1428 } 1429 }
1429 1430
1430 /** 1431 /**
1431 * drop_nlink - directly drop an inode's link count 1432 * drop_nlink - directly drop an inode's link count
1432 * @inode: inode 1433 * @inode: inode
1433 * 1434 *
1434 * This is a low-level filesystem helper to replace any 1435 * This is a low-level filesystem helper to replace any
1435 * direct filesystem manipulation of i_nlink. In cases 1436 * direct filesystem manipulation of i_nlink. In cases
1436 * where we are attempting to track writes to the 1437 * where we are attempting to track writes to the
1437 * filesystem, a decrement to zero means an imminent 1438 * filesystem, a decrement to zero means an imminent
1438 * write when the file is truncated and actually unlinked 1439 * write when the file is truncated and actually unlinked
1439 * on the filesystem. 1440 * on the filesystem.
1440 */ 1441 */
1441 static inline void drop_nlink(struct inode *inode) 1442 static inline void drop_nlink(struct inode *inode)
1442 { 1443 {
1443 inode->i_nlink--; 1444 inode->i_nlink--;
1444 } 1445 }
1445 1446
1446 /** 1447 /**
1447 * clear_nlink - directly zero an inode's link count 1448 * clear_nlink - directly zero an inode's link count
1448 * @inode: inode 1449 * @inode: inode
1449 * 1450 *
1450 * This is a low-level filesystem helper to replace any 1451 * This is a low-level filesystem helper to replace any
1451 * direct filesystem manipulation of i_nlink. See 1452 * direct filesystem manipulation of i_nlink. See
1452 * drop_nlink() for why we care about i_nlink hitting zero. 1453 * drop_nlink() for why we care about i_nlink hitting zero.
1453 */ 1454 */
1454 static inline void clear_nlink(struct inode *inode) 1455 static inline void clear_nlink(struct inode *inode)
1455 { 1456 {
1456 inode->i_nlink = 0; 1457 inode->i_nlink = 0;
1457 } 1458 }
1458 1459
1459 static inline void inode_dec_link_count(struct inode *inode) 1460 static inline void inode_dec_link_count(struct inode *inode)
1460 { 1461 {
1461 drop_nlink(inode); 1462 drop_nlink(inode);
1462 mark_inode_dirty(inode); 1463 mark_inode_dirty(inode);
1463 } 1464 }
1464 1465
1465 /** 1466 /**
1466 * inode_inc_iversion - increments i_version 1467 * inode_inc_iversion - increments i_version
1467 * @inode: inode that need to be updated 1468 * @inode: inode that need to be updated
1468 * 1469 *
1469 * Every time the inode is modified, the i_version field will be incremented. 1470 * Every time the inode is modified, the i_version field will be incremented.
1470 * The filesystem has to be mounted with i_version flag 1471 * The filesystem has to be mounted with i_version flag
1471 */ 1472 */
1472 1473
1473 static inline void inode_inc_iversion(struct inode *inode) 1474 static inline void inode_inc_iversion(struct inode *inode)
1474 { 1475 {
1475 spin_lock(&inode->i_lock); 1476 spin_lock(&inode->i_lock);
1476 inode->i_version++; 1477 inode->i_version++;
1477 spin_unlock(&inode->i_lock); 1478 spin_unlock(&inode->i_lock);
1478 } 1479 }
1479 1480
1480 extern void touch_atime(struct vfsmount *mnt, struct dentry *dentry); 1481 extern void touch_atime(struct vfsmount *mnt, struct dentry *dentry);
1481 static inline void file_accessed(struct file *file) 1482 static inline void file_accessed(struct file *file)
1482 { 1483 {
1483 if (!(file->f_flags & O_NOATIME)) 1484 if (!(file->f_flags & O_NOATIME))
1484 touch_atime(file->f_path.mnt, file->f_path.dentry); 1485 touch_atime(file->f_path.mnt, file->f_path.dentry);
1485 } 1486 }
1486 1487
1487 int sync_inode(struct inode *inode, struct writeback_control *wbc); 1488 int sync_inode(struct inode *inode, struct writeback_control *wbc);
1488 1489
1489 struct file_system_type { 1490 struct file_system_type {
1490 const char *name; 1491 const char *name;
1491 int fs_flags; 1492 int fs_flags;
1492 int (*get_sb) (struct file_system_type *, int, 1493 int (*get_sb) (struct file_system_type *, int,
1493 const char *, void *, struct vfsmount *); 1494 const char *, void *, struct vfsmount *);
1494 void (*kill_sb) (struct super_block *); 1495 void (*kill_sb) (struct super_block *);
1495 struct module *owner; 1496 struct module *owner;
1496 struct file_system_type * next; 1497 struct file_system_type * next;
1497 struct list_head fs_supers; 1498 struct list_head fs_supers;
1498 1499
1499 struct lock_class_key s_lock_key; 1500 struct lock_class_key s_lock_key;
1500 struct lock_class_key s_umount_key; 1501 struct lock_class_key s_umount_key;
1501 1502
1502 struct lock_class_key i_lock_key; 1503 struct lock_class_key i_lock_key;
1503 struct lock_class_key i_mutex_key; 1504 struct lock_class_key i_mutex_key;
1504 struct lock_class_key i_mutex_dir_key; 1505 struct lock_class_key i_mutex_dir_key;
1505 struct lock_class_key i_alloc_sem_key; 1506 struct lock_class_key i_alloc_sem_key;
1506 }; 1507 };
1507 1508
1508 extern int get_sb_bdev(struct file_system_type *fs_type, 1509 extern int get_sb_bdev(struct file_system_type *fs_type,
1509 int flags, const char *dev_name, void *data, 1510 int flags, const char *dev_name, void *data,
1510 int (*fill_super)(struct super_block *, void *, int), 1511 int (*fill_super)(struct super_block *, void *, int),
1511 struct vfsmount *mnt); 1512 struct vfsmount *mnt);
1512 extern int get_sb_single(struct file_system_type *fs_type, 1513 extern int get_sb_single(struct file_system_type *fs_type,
1513 int flags, void *data, 1514 int flags, void *data,
1514 int (*fill_super)(struct super_block *, void *, int), 1515 int (*fill_super)(struct super_block *, void *, int),
1515 struct vfsmount *mnt); 1516 struct vfsmount *mnt);
1516 extern int get_sb_nodev(struct file_system_type *fs_type, 1517 extern int get_sb_nodev(struct file_system_type *fs_type,
1517 int flags, void *data, 1518 int flags, void *data,
1518 int (*fill_super)(struct super_block *, void *, int), 1519 int (*fill_super)(struct super_block *, void *, int),
1519 struct vfsmount *mnt); 1520 struct vfsmount *mnt);
1520 void generic_shutdown_super(struct super_block *sb); 1521 void generic_shutdown_super(struct super_block *sb);
1521 void kill_block_super(struct super_block *sb); 1522 void kill_block_super(struct super_block *sb);
1522 void kill_anon_super(struct super_block *sb); 1523 void kill_anon_super(struct super_block *sb);
1523 void kill_litter_super(struct super_block *sb); 1524 void kill_litter_super(struct super_block *sb);
1524 void deactivate_super(struct super_block *sb); 1525 void deactivate_super(struct super_block *sb);
1525 int set_anon_super(struct super_block *s, void *data); 1526 int set_anon_super(struct super_block *s, void *data);
1526 struct super_block *sget(struct file_system_type *type, 1527 struct super_block *sget(struct file_system_type *type,
1527 int (*test)(struct super_block *,void *), 1528 int (*test)(struct super_block *,void *),
1528 int (*set)(struct super_block *,void *), 1529 int (*set)(struct super_block *,void *),
1529 void *data); 1530 void *data);
1530 extern int get_sb_pseudo(struct file_system_type *, char *, 1531 extern int get_sb_pseudo(struct file_system_type *, char *,
1531 const struct super_operations *ops, unsigned long, 1532 const struct super_operations *ops, unsigned long,
1532 struct vfsmount *mnt); 1533 struct vfsmount *mnt);
1533 extern int simple_set_mnt(struct vfsmount *mnt, struct super_block *sb); 1534 extern int simple_set_mnt(struct vfsmount *mnt, struct super_block *sb);
1534 int __put_super_and_need_restart(struct super_block *sb); 1535 int __put_super_and_need_restart(struct super_block *sb);
1535 void unnamed_dev_init(void); 1536 void unnamed_dev_init(void);
1536 1537
1537 /* Alas, no aliases. Too much hassle with bringing module.h everywhere */ 1538 /* Alas, no aliases. Too much hassle with bringing module.h everywhere */
1538 #define fops_get(fops) \ 1539 #define fops_get(fops) \
1539 (((fops) && try_module_get((fops)->owner) ? (fops) : NULL)) 1540 (((fops) && try_module_get((fops)->owner) ? (fops) : NULL))
1540 #define fops_put(fops) \ 1541 #define fops_put(fops) \
1541 do { if (fops) module_put((fops)->owner); } while(0) 1542 do { if (fops) module_put((fops)->owner); } while(0)
1542 1543
1543 extern int register_filesystem(struct file_system_type *); 1544 extern int register_filesystem(struct file_system_type *);
1544 extern int unregister_filesystem(struct file_system_type *); 1545 extern int unregister_filesystem(struct file_system_type *);
1545 extern struct vfsmount *kern_mount_data(struct file_system_type *, void *data); 1546 extern struct vfsmount *kern_mount_data(struct file_system_type *, void *data);
1546 #define kern_mount(type) kern_mount_data(type, NULL) 1547 #define kern_mount(type) kern_mount_data(type, NULL)
1547 extern int may_umount_tree(struct vfsmount *); 1548 extern int may_umount_tree(struct vfsmount *);
1548 extern int may_umount(struct vfsmount *); 1549 extern int may_umount(struct vfsmount *);
1549 extern long do_mount(char *, char *, char *, unsigned long, void *); 1550 extern long do_mount(char *, char *, char *, unsigned long, void *);
1550 extern struct vfsmount *collect_mounts(struct vfsmount *, struct dentry *); 1551 extern struct vfsmount *collect_mounts(struct vfsmount *, struct dentry *);
1551 extern void drop_collected_mounts(struct vfsmount *); 1552 extern void drop_collected_mounts(struct vfsmount *);
1552 1553
1553 extern int vfs_statfs(struct dentry *, struct kstatfs *); 1554 extern int vfs_statfs(struct dentry *, struct kstatfs *);
1554 1555
1555 /* /sys/fs */ 1556 /* /sys/fs */
1556 extern struct kobject *fs_kobj; 1557 extern struct kobject *fs_kobj;
1557 1558
1558 #define FLOCK_VERIFY_READ 1 1559 #define FLOCK_VERIFY_READ 1
1559 #define FLOCK_VERIFY_WRITE 2 1560 #define FLOCK_VERIFY_WRITE 2
1560 1561
1561 extern int locks_mandatory_locked(struct inode *); 1562 extern int locks_mandatory_locked(struct inode *);
1562 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t); 1563 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
1563 1564
1564 /* 1565 /*
1565 * Candidates for mandatory locking have the setgid bit set 1566 * Candidates for mandatory locking have the setgid bit set
1566 * but no group execute bit - an otherwise meaningless combination. 1567 * but no group execute bit - an otherwise meaningless combination.
1567 */ 1568 */
1568 1569
1569 static inline int __mandatory_lock(struct inode *ino) 1570 static inline int __mandatory_lock(struct inode *ino)
1570 { 1571 {
1571 return (ino->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID; 1572 return (ino->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID;
1572 } 1573 }
1573 1574
1574 /* 1575 /*
1575 * ... and these candidates should be on MS_MANDLOCK mounted fs, 1576 * ... and these candidates should be on MS_MANDLOCK mounted fs,
1576 * otherwise these will be advisory locks 1577 * otherwise these will be advisory locks
1577 */ 1578 */
1578 1579
1579 static inline int mandatory_lock(struct inode *ino) 1580 static inline int mandatory_lock(struct inode *ino)
1580 { 1581 {
1581 return IS_MANDLOCK(ino) && __mandatory_lock(ino); 1582 return IS_MANDLOCK(ino) && __mandatory_lock(ino);
1582 } 1583 }
1583 1584
1584 static inline int locks_verify_locked(struct inode *inode) 1585 static inline int locks_verify_locked(struct inode *inode)
1585 { 1586 {
1586 if (mandatory_lock(inode)) 1587 if (mandatory_lock(inode))
1587 return locks_mandatory_locked(inode); 1588 return locks_mandatory_locked(inode);
1588 return 0; 1589 return 0;
1589 } 1590 }
1590 1591
1591 extern int rw_verify_area(int, struct file *, loff_t *, size_t); 1592 extern int rw_verify_area(int, struct file *, loff_t *, size_t);
1592 1593
1593 static inline int locks_verify_truncate(struct inode *inode, 1594 static inline int locks_verify_truncate(struct inode *inode,
1594 struct file *filp, 1595 struct file *filp,
1595 loff_t size) 1596 loff_t size)
1596 { 1597 {
1597 if (inode->i_flock && mandatory_lock(inode)) 1598 if (inode->i_flock && mandatory_lock(inode))
1598 return locks_mandatory_area( 1599 return locks_mandatory_area(
1599 FLOCK_VERIFY_WRITE, inode, filp, 1600 FLOCK_VERIFY_WRITE, inode, filp,
1600 size < inode->i_size ? size : inode->i_size, 1601 size < inode->i_size ? size : inode->i_size,
1601 (size < inode->i_size ? inode->i_size - size 1602 (size < inode->i_size ? inode->i_size - size
1602 : size - inode->i_size) 1603 : size - inode->i_size)
1603 ); 1604 );
1604 return 0; 1605 return 0;
1605 } 1606 }
1606 1607
1607 static inline int break_lease(struct inode *inode, unsigned int mode) 1608 static inline int break_lease(struct inode *inode, unsigned int mode)
1608 { 1609 {
1609 if (inode->i_flock) 1610 if (inode->i_flock)
1610 return __break_lease(inode, mode); 1611 return __break_lease(inode, mode);
1611 return 0; 1612 return 0;
1612 } 1613 }
1613 1614
1614 /* fs/open.c */ 1615 /* fs/open.c */
1615 1616
1616 extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs, 1617 extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs,
1617 struct file *filp); 1618 struct file *filp);
1618 extern long do_sys_open(int dfd, const char __user *filename, int flags, 1619 extern long do_sys_open(int dfd, const char __user *filename, int flags,
1619 int mode); 1620 int mode);
1620 extern struct file *filp_open(const char *, int, int); 1621 extern struct file *filp_open(const char *, int, int);
1621 extern struct file * dentry_open(struct dentry *, struct vfsmount *, int); 1622 extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
1622 extern int filp_close(struct file *, fl_owner_t id); 1623 extern int filp_close(struct file *, fl_owner_t id);
1623 extern char * getname(const char __user *); 1624 extern char * getname(const char __user *);
1624 1625
1625 /* fs/dcache.c */ 1626 /* fs/dcache.c */
1626 extern void __init vfs_caches_init_early(void); 1627 extern void __init vfs_caches_init_early(void);
1627 extern void __init vfs_caches_init(unsigned long); 1628 extern void __init vfs_caches_init(unsigned long);
1628 1629
1629 extern struct kmem_cache *names_cachep; 1630 extern struct kmem_cache *names_cachep;
1630 1631
1631 #define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL) 1632 #define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL)
1632 #define __putname(name) kmem_cache_free(names_cachep, (void *)(name)) 1633 #define __putname(name) kmem_cache_free(names_cachep, (void *)(name))
1633 #ifndef CONFIG_AUDITSYSCALL 1634 #ifndef CONFIG_AUDITSYSCALL
1634 #define putname(name) __putname(name) 1635 #define putname(name) __putname(name)
1635 #else 1636 #else
1636 extern void putname(const char *name); 1637 extern void putname(const char *name);
1637 #endif 1638 #endif
1638 1639
1639 #ifdef CONFIG_BLOCK 1640 #ifdef CONFIG_BLOCK
1640 extern int register_blkdev(unsigned int, const char *); 1641 extern int register_blkdev(unsigned int, const char *);
1641 extern void unregister_blkdev(unsigned int, const char *); 1642 extern void unregister_blkdev(unsigned int, const char *);
1642 extern struct block_device *bdget(dev_t); 1643 extern struct block_device *bdget(dev_t);
1643 extern void bd_set_size(struct block_device *, loff_t size); 1644 extern void bd_set_size(struct block_device *, loff_t size);
1644 extern void bd_forget(struct inode *inode); 1645 extern void bd_forget(struct inode *inode);
1645 extern void bdput(struct block_device *); 1646 extern void bdput(struct block_device *);
1646 extern struct block_device *open_by_devnum(dev_t, unsigned); 1647 extern struct block_device *open_by_devnum(dev_t, unsigned);
1647 #else 1648 #else
1648 static inline void bd_forget(struct inode *inode) {} 1649 static inline void bd_forget(struct inode *inode) {}
1649 #endif 1650 #endif
1650 extern const struct file_operations def_blk_fops; 1651 extern const struct file_operations def_blk_fops;
1651 extern const struct file_operations def_chr_fops; 1652 extern const struct file_operations def_chr_fops;
1652 extern const struct file_operations bad_sock_fops; 1653 extern const struct file_operations bad_sock_fops;
1653 extern const struct file_operations def_fifo_fops; 1654 extern const struct file_operations def_fifo_fops;
1654 #ifdef CONFIG_BLOCK 1655 #ifdef CONFIG_BLOCK
1655 extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long); 1656 extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
1656 extern int blkdev_ioctl(struct inode *, struct file *, unsigned, unsigned long); 1657 extern int blkdev_ioctl(struct inode *, struct file *, unsigned, unsigned long);
1657 extern int blkdev_driver_ioctl(struct inode *inode, struct file *file, 1658 extern int blkdev_driver_ioctl(struct inode *inode, struct file *file,
1658 struct gendisk *disk, unsigned cmd, 1659 struct gendisk *disk, unsigned cmd,
1659 unsigned long arg); 1660 unsigned long arg);
1660 extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); 1661 extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
1661 extern int blkdev_get(struct block_device *, mode_t, unsigned); 1662 extern int blkdev_get(struct block_device *, mode_t, unsigned);
1662 extern int blkdev_put(struct block_device *); 1663 extern int blkdev_put(struct block_device *);
1663 extern int bd_claim(struct block_device *, void *); 1664 extern int bd_claim(struct block_device *, void *);
1664 extern void bd_release(struct block_device *); 1665 extern void bd_release(struct block_device *);
1665 #ifdef CONFIG_SYSFS 1666 #ifdef CONFIG_SYSFS
1666 extern int bd_claim_by_disk(struct block_device *, void *, struct gendisk *); 1667 extern int bd_claim_by_disk(struct block_device *, void *, struct gendisk *);
1667 extern void bd_release_from_disk(struct block_device *, struct gendisk *); 1668 extern void bd_release_from_disk(struct block_device *, struct gendisk *);
1668 #else 1669 #else
1669 #define bd_claim_by_disk(bdev, holder, disk) bd_claim(bdev, holder) 1670 #define bd_claim_by_disk(bdev, holder, disk) bd_claim(bdev, holder)
1670 #define bd_release_from_disk(bdev, disk) bd_release(bdev) 1671 #define bd_release_from_disk(bdev, disk) bd_release(bdev)
1671 #endif 1672 #endif
1672 #endif 1673 #endif
1673 1674
1674 /* fs/char_dev.c */ 1675 /* fs/char_dev.c */
1675 #define CHRDEV_MAJOR_HASH_SIZE 255 1676 #define CHRDEV_MAJOR_HASH_SIZE 255
1676 extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *); 1677 extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *);
1677 extern int register_chrdev_region(dev_t, unsigned, const char *); 1678 extern int register_chrdev_region(dev_t, unsigned, const char *);
1678 extern int register_chrdev(unsigned int, const char *, 1679 extern int register_chrdev(unsigned int, const char *,
1679 const struct file_operations *); 1680 const struct file_operations *);
1680 extern void unregister_chrdev(unsigned int, const char *); 1681 extern void unregister_chrdev(unsigned int, const char *);
1681 extern void unregister_chrdev_region(dev_t, unsigned); 1682 extern void unregister_chrdev_region(dev_t, unsigned);
1682 extern void chrdev_show(struct seq_file *,off_t); 1683 extern void chrdev_show(struct seq_file *,off_t);
1683 1684
1684 /* fs/block_dev.c */ 1685 /* fs/block_dev.c */
1685 #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */ 1686 #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */
1686 1687
1687 #ifdef CONFIG_BLOCK 1688 #ifdef CONFIG_BLOCK
1688 #define BLKDEV_MAJOR_HASH_SIZE 255 1689 #define BLKDEV_MAJOR_HASH_SIZE 255
1689 extern const char *__bdevname(dev_t, char *buffer); 1690 extern const char *__bdevname(dev_t, char *buffer);
1690 extern const char *bdevname(struct block_device *bdev, char *buffer); 1691 extern const char *bdevname(struct block_device *bdev, char *buffer);
1691 extern struct block_device *lookup_bdev(const char *); 1692 extern struct block_device *lookup_bdev(const char *);
1692 extern struct block_device *open_bdev_excl(const char *, int, void *); 1693 extern struct block_device *open_bdev_excl(const char *, int, void *);
1693 extern void close_bdev_excl(struct block_device *); 1694 extern void close_bdev_excl(struct block_device *);
1694 extern void blkdev_show(struct seq_file *,off_t); 1695 extern void blkdev_show(struct seq_file *,off_t);
1695 #else 1696 #else
1696 #define BLKDEV_MAJOR_HASH_SIZE 0 1697 #define BLKDEV_MAJOR_HASH_SIZE 0
1697 #endif 1698 #endif
1698 1699
1699 extern void init_special_inode(struct inode *, umode_t, dev_t); 1700 extern void init_special_inode(struct inode *, umode_t, dev_t);
1700 1701
1701 /* Invalid inode operations -- fs/bad_inode.c */ 1702 /* Invalid inode operations -- fs/bad_inode.c */
1702 extern void make_bad_inode(struct inode *); 1703 extern void make_bad_inode(struct inode *);
1703 extern int is_bad_inode(struct inode *); 1704 extern int is_bad_inode(struct inode *);
1704 1705
1705 extern const struct file_operations read_pipefifo_fops; 1706 extern const struct file_operations read_pipefifo_fops;
1706 extern const struct file_operations write_pipefifo_fops; 1707 extern const struct file_operations write_pipefifo_fops;
1707 extern const struct file_operations rdwr_pipefifo_fops; 1708 extern const struct file_operations rdwr_pipefifo_fops;
1708 1709
1709 extern int fs_may_remount_ro(struct super_block *); 1710 extern int fs_may_remount_ro(struct super_block *);
1710 1711
1711 #ifdef CONFIG_BLOCK 1712 #ifdef CONFIG_BLOCK
1712 /* 1713 /*
1713 * return READ, READA, or WRITE 1714 * return READ, READA, or WRITE
1714 */ 1715 */
1715 #define bio_rw(bio) ((bio)->bi_rw & (RW_MASK | RWA_MASK)) 1716 #define bio_rw(bio) ((bio)->bi_rw & (RW_MASK | RWA_MASK))
1716 1717
1717 /* 1718 /*
1718 * return data direction, READ or WRITE 1719 * return data direction, READ or WRITE
1719 */ 1720 */
1720 #define bio_data_dir(bio) ((bio)->bi_rw & 1) 1721 #define bio_data_dir(bio) ((bio)->bi_rw & 1)
1721 1722
1722 extern int check_disk_change(struct block_device *); 1723 extern int check_disk_change(struct block_device *);
1723 extern int __invalidate_device(struct block_device *); 1724 extern int __invalidate_device(struct block_device *);
1724 extern int invalidate_partition(struct gendisk *, int); 1725 extern int invalidate_partition(struct gendisk *, int);
1725 #endif 1726 #endif
1726 extern int invalidate_inodes(struct super_block *); 1727 extern int invalidate_inodes(struct super_block *);
1727 unsigned long __invalidate_mapping_pages(struct address_space *mapping, 1728 unsigned long __invalidate_mapping_pages(struct address_space *mapping,
1728 pgoff_t start, pgoff_t end, 1729 pgoff_t start, pgoff_t end,
1729 bool be_atomic); 1730 bool be_atomic);
1730 unsigned long invalidate_mapping_pages(struct address_space *mapping, 1731 unsigned long invalidate_mapping_pages(struct address_space *mapping,
1731 pgoff_t start, pgoff_t end); 1732 pgoff_t start, pgoff_t end);
1732 1733
1733 static inline unsigned long __deprecated 1734 static inline unsigned long __deprecated
1734 invalidate_inode_pages(struct address_space *mapping) 1735 invalidate_inode_pages(struct address_space *mapping)
1735 { 1736 {
1736 return invalidate_mapping_pages(mapping, 0, ~0UL); 1737 return invalidate_mapping_pages(mapping, 0, ~0UL);
1737 } 1738 }
1738 1739
1739 static inline void invalidate_remote_inode(struct inode *inode) 1740 static inline void invalidate_remote_inode(struct inode *inode)
1740 { 1741 {
1741 if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || 1742 if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
1742 S_ISLNK(inode->i_mode)) 1743 S_ISLNK(inode->i_mode))
1743 invalidate_mapping_pages(inode->i_mapping, 0, -1); 1744 invalidate_mapping_pages(inode->i_mapping, 0, -1);
1744 } 1745 }
1745 extern int invalidate_inode_pages2(struct address_space *mapping); 1746 extern int invalidate_inode_pages2(struct address_space *mapping);
1746 extern int invalidate_inode_pages2_range(struct address_space *mapping, 1747 extern int invalidate_inode_pages2_range(struct address_space *mapping,
1747 pgoff_t start, pgoff_t end); 1748 pgoff_t start, pgoff_t end);
1748 extern void generic_sync_sb_inodes(struct super_block *sb, 1749 extern void generic_sync_sb_inodes(struct super_block *sb,
1749 struct writeback_control *wbc); 1750 struct writeback_control *wbc);
1750 extern int write_inode_now(struct inode *, int); 1751 extern int write_inode_now(struct inode *, int);
1751 extern int filemap_fdatawrite(struct address_space *); 1752 extern int filemap_fdatawrite(struct address_space *);
1752 extern int filemap_flush(struct address_space *); 1753 extern int filemap_flush(struct address_space *);
1753 extern int filemap_fdatawait(struct address_space *); 1754 extern int filemap_fdatawait(struct address_space *);
1754 extern int filemap_write_and_wait(struct address_space *mapping); 1755 extern int filemap_write_and_wait(struct address_space *mapping);
1755 extern int filemap_write_and_wait_range(struct address_space *mapping, 1756 extern int filemap_write_and_wait_range(struct address_space *mapping,
1756 loff_t lstart, loff_t lend); 1757 loff_t lstart, loff_t lend);
1757 extern int wait_on_page_writeback_range(struct address_space *mapping, 1758 extern int wait_on_page_writeback_range(struct address_space *mapping,
1758 pgoff_t start, pgoff_t end); 1759 pgoff_t start, pgoff_t end);
1759 extern int __filemap_fdatawrite_range(struct address_space *mapping, 1760 extern int __filemap_fdatawrite_range(struct address_space *mapping,
1760 loff_t start, loff_t end, int sync_mode); 1761 loff_t start, loff_t end, int sync_mode);
1761 extern int filemap_fdatawrite_range(struct address_space *mapping, 1762 extern int filemap_fdatawrite_range(struct address_space *mapping,
1762 loff_t start, loff_t end); 1763 loff_t start, loff_t end);
1763 1764
1764 extern long do_fsync(struct file *file, int datasync); 1765 extern long do_fsync(struct file *file, int datasync);
1765 extern void sync_supers(void); 1766 extern void sync_supers(void);
1766 extern void sync_filesystems(int wait); 1767 extern void sync_filesystems(int wait);
1767 extern void __fsync_super(struct super_block *sb); 1768 extern void __fsync_super(struct super_block *sb);
1768 extern void emergency_sync(void); 1769 extern void emergency_sync(void);
1769 extern void emergency_remount(void); 1770 extern void emergency_remount(void);
1770 extern int do_remount_sb(struct super_block *sb, int flags, 1771 extern int do_remount_sb(struct super_block *sb, int flags,
1771 void *data, int force); 1772 void *data, int force);
1772 #ifdef CONFIG_BLOCK 1773 #ifdef CONFIG_BLOCK
1773 extern sector_t bmap(struct inode *, sector_t); 1774 extern sector_t bmap(struct inode *, sector_t);
1774 #endif 1775 #endif
1775 extern int notify_change(struct dentry *, struct iattr *); 1776 extern int notify_change(struct dentry *, struct iattr *);
1776 extern int inode_permission(struct inode *, int); 1777 extern int inode_permission(struct inode *, int);
1777 extern int generic_permission(struct inode *, int, 1778 extern int generic_permission(struct inode *, int,
1778 int (*check_acl)(struct inode *, int)); 1779 int (*check_acl)(struct inode *, int));
1779 1780
1780 extern int get_write_access(struct inode *); 1781 extern int get_write_access(struct inode *);
1781 extern int deny_write_access(struct file *); 1782 extern int deny_write_access(struct file *);
1782 static inline void put_write_access(struct inode * inode) 1783 static inline void put_write_access(struct inode * inode)
1783 { 1784 {
1784 atomic_dec(&inode->i_writecount); 1785 atomic_dec(&inode->i_writecount);
1785 } 1786 }
1786 static inline void allow_write_access(struct file *file) 1787 static inline void allow_write_access(struct file *file)
1787 { 1788 {
1788 if (file) 1789 if (file)
1789 atomic_inc(&file->f_path.dentry->d_inode->i_writecount); 1790 atomic_inc(&file->f_path.dentry->d_inode->i_writecount);
1790 } 1791 }
1791 extern int do_pipe(int *); 1792 extern int do_pipe(int *);
1792 extern int do_pipe_flags(int *, int); 1793 extern int do_pipe_flags(int *, int);
1793 extern struct file *create_read_pipe(struct file *f, int flags); 1794 extern struct file *create_read_pipe(struct file *f, int flags);
1794 extern struct file *create_write_pipe(int flags); 1795 extern struct file *create_write_pipe(int flags);
1795 extern void free_write_pipe(struct file *); 1796 extern void free_write_pipe(struct file *);
1796 1797
1797 extern struct file *do_filp_open(int dfd, const char *pathname, 1798 extern struct file *do_filp_open(int dfd, const char *pathname,
1798 int open_flag, int mode); 1799 int open_flag, int mode);
1799 extern int may_open(struct nameidata *, int, int); 1800 extern int may_open(struct nameidata *, int, int);
1800 1801
1801 extern int kernel_read(struct file *, unsigned long, char *, unsigned long); 1802 extern int kernel_read(struct file *, unsigned long, char *, unsigned long);
1802 extern struct file * open_exec(const char *); 1803 extern struct file * open_exec(const char *);
1803 1804
1804 /* fs/dcache.c -- generic fs support functions */ 1805 /* fs/dcache.c -- generic fs support functions */
1805 extern int is_subdir(struct dentry *, struct dentry *); 1806 extern int is_subdir(struct dentry *, struct dentry *);
1806 extern ino_t find_inode_number(struct dentry *, struct qstr *); 1807 extern ino_t find_inode_number(struct dentry *, struct qstr *);
1807 1808
1808 #include <linux/err.h> 1809 #include <linux/err.h>
1809 1810
1810 /* needed for stackable file system support */ 1811 /* needed for stackable file system support */
1811 extern loff_t default_llseek(struct file *file, loff_t offset, int origin); 1812 extern loff_t default_llseek(struct file *file, loff_t offset, int origin);
1812 1813
1813 extern loff_t vfs_llseek(struct file *file, loff_t offset, int origin); 1814 extern loff_t vfs_llseek(struct file *file, loff_t offset, int origin);
1814 1815
1815 extern void inode_init_once(struct inode *); 1816 extern void inode_init_once(struct inode *);
1816 extern void iput(struct inode *); 1817 extern void iput(struct inode *);
1817 extern struct inode * igrab(struct inode *); 1818 extern struct inode * igrab(struct inode *);
1818 extern ino_t iunique(struct super_block *, ino_t); 1819 extern ino_t iunique(struct super_block *, ino_t);
1819 extern int inode_needs_sync(struct inode *inode); 1820 extern int inode_needs_sync(struct inode *inode);
1820 extern void generic_delete_inode(struct inode *inode); 1821 extern void generic_delete_inode(struct inode *inode);
1821 extern void generic_drop_inode(struct inode *inode); 1822 extern void generic_drop_inode(struct inode *inode);
1822 1823
1823 extern struct inode *ilookup5_nowait(struct super_block *sb, 1824 extern struct inode *ilookup5_nowait(struct super_block *sb,
1824 unsigned long hashval, int (*test)(struct inode *, void *), 1825 unsigned long hashval, int (*test)(struct inode *, void *),
1825 void *data); 1826 void *data);
1826 extern struct inode *ilookup5(struct super_block *sb, unsigned long hashval, 1827 extern struct inode *ilookup5(struct super_block *sb, unsigned long hashval,
1827 int (*test)(struct inode *, void *), void *data); 1828 int (*test)(struct inode *, void *), void *data);
1828 extern struct inode *ilookup(struct super_block *sb, unsigned long ino); 1829 extern struct inode *ilookup(struct super_block *sb, unsigned long ino);
1829 1830
1830 extern struct inode * iget5_locked(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *); 1831 extern struct inode * iget5_locked(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *);
1831 extern struct inode * iget_locked(struct super_block *, unsigned long); 1832 extern struct inode * iget_locked(struct super_block *, unsigned long);
1832 extern void unlock_new_inode(struct inode *); 1833 extern void unlock_new_inode(struct inode *);
1833 1834
1834 extern void __iget(struct inode * inode); 1835 extern void __iget(struct inode * inode);
1835 extern void iget_failed(struct inode *); 1836 extern void iget_failed(struct inode *);
1836 extern void clear_inode(struct inode *); 1837 extern void clear_inode(struct inode *);
1837 extern void destroy_inode(struct inode *); 1838 extern void destroy_inode(struct inode *);
1838 extern struct inode *new_inode(struct super_block *); 1839 extern struct inode *new_inode(struct super_block *);
1839 extern int should_remove_suid(struct dentry *); 1840 extern int should_remove_suid(struct dentry *);
1840 extern int file_remove_suid(struct file *); 1841 extern int file_remove_suid(struct file *);
1841 1842
1842 extern void __insert_inode_hash(struct inode *, unsigned long hashval); 1843 extern void __insert_inode_hash(struct inode *, unsigned long hashval);
1843 extern void remove_inode_hash(struct inode *); 1844 extern void remove_inode_hash(struct inode *);
1844 static inline void insert_inode_hash(struct inode *inode) { 1845 static inline void insert_inode_hash(struct inode *inode) {
1845 __insert_inode_hash(inode, inode->i_ino); 1846 __insert_inode_hash(inode, inode->i_ino);
1846 } 1847 }
1847 1848
1848 extern struct file * get_empty_filp(void); 1849 extern struct file * get_empty_filp(void);
1849 extern void file_move(struct file *f, struct list_head *list); 1850 extern void file_move(struct file *f, struct list_head *list);
1850 extern void file_kill(struct file *f); 1851 extern void file_kill(struct file *f);
1851 #ifdef CONFIG_BLOCK 1852 #ifdef CONFIG_BLOCK
1852 struct bio; 1853 struct bio;
1853 extern void submit_bio(int, struct bio *); 1854 extern void submit_bio(int, struct bio *);
1854 extern int bdev_read_only(struct block_device *); 1855 extern int bdev_read_only(struct block_device *);
1855 #endif 1856 #endif
1856 extern int set_blocksize(struct block_device *, int); 1857 extern int set_blocksize(struct block_device *, int);
1857 extern int sb_set_blocksize(struct super_block *, int); 1858 extern int sb_set_blocksize(struct super_block *, int);
1858 extern int sb_min_blocksize(struct super_block *, int); 1859 extern int sb_min_blocksize(struct super_block *, int);
1859 extern int sb_has_dirty_inodes(struct super_block *); 1860 extern int sb_has_dirty_inodes(struct super_block *);
1860 1861
1861 extern int generic_file_mmap(struct file *, struct vm_area_struct *); 1862 extern int generic_file_mmap(struct file *, struct vm_area_struct *);
1862 extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *); 1863 extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);
1863 extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size); 1864 extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size);
1864 int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk); 1865 int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk);
1865 extern ssize_t generic_file_aio_read(struct kiocb *, const struct iovec *, unsigned long, loff_t); 1866 extern ssize_t generic_file_aio_read(struct kiocb *, const struct iovec *, unsigned long, loff_t);
1866 extern ssize_t generic_file_aio_write(struct kiocb *, const struct iovec *, unsigned long, loff_t); 1867 extern ssize_t generic_file_aio_write(struct kiocb *, const struct iovec *, unsigned long, loff_t);
1867 extern ssize_t generic_file_aio_write_nolock(struct kiocb *, const struct iovec *, 1868 extern ssize_t generic_file_aio_write_nolock(struct kiocb *, const struct iovec *,
1868 unsigned long, loff_t); 1869 unsigned long, loff_t);
1869 extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *, 1870 extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *,
1870 unsigned long *, loff_t, loff_t *, size_t, size_t); 1871 unsigned long *, loff_t, loff_t *, size_t, size_t);
1871 extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *, 1872 extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *,
1872 unsigned long, loff_t, loff_t *, size_t, ssize_t); 1873 unsigned long, loff_t, loff_t *, size_t, ssize_t);
1873 extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos); 1874 extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos);
1874 extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos); 1875 extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos);
1875 extern int generic_segment_checks(const struct iovec *iov, 1876 extern int generic_segment_checks(const struct iovec *iov,
1876 unsigned long *nr_segs, size_t *count, int access_flags); 1877 unsigned long *nr_segs, size_t *count, int access_flags);
1877 1878
1878 /* fs/splice.c */ 1879 /* fs/splice.c */
1879 extern ssize_t generic_file_splice_read(struct file *, loff_t *, 1880 extern ssize_t generic_file_splice_read(struct file *, loff_t *,
1880 struct pipe_inode_info *, size_t, unsigned int); 1881 struct pipe_inode_info *, size_t, unsigned int);
1881 extern ssize_t generic_file_splice_write(struct pipe_inode_info *, 1882 extern ssize_t generic_file_splice_write(struct pipe_inode_info *,
1882 struct file *, loff_t *, size_t, unsigned int); 1883 struct file *, loff_t *, size_t, unsigned int);
1883 extern ssize_t generic_file_splice_write_nolock(struct pipe_inode_info *, 1884 extern ssize_t generic_file_splice_write_nolock(struct pipe_inode_info *,
1884 struct file *, loff_t *, size_t, unsigned int); 1885 struct file *, loff_t *, size_t, unsigned int);
1885 extern ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe, 1886 extern ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe,
1886 struct file *out, loff_t *, size_t len, unsigned int flags); 1887 struct file *out, loff_t *, size_t len, unsigned int flags);
1887 extern long do_splice_direct(struct file *in, loff_t *ppos, struct file *out, 1888 extern long do_splice_direct(struct file *in, loff_t *ppos, struct file *out,
1888 size_t len, unsigned int flags); 1889 size_t len, unsigned int flags);
1889 1890
1890 extern void 1891 extern void
1891 file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping); 1892 file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping);
1892 extern loff_t no_llseek(struct file *file, loff_t offset, int origin); 1893 extern loff_t no_llseek(struct file *file, loff_t offset, int origin);
1893 extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin); 1894 extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin);
1894 extern loff_t generic_file_llseek_unlocked(struct file *file, loff_t offset, 1895 extern loff_t generic_file_llseek_unlocked(struct file *file, loff_t offset,
1895 int origin); 1896 int origin);
1896 extern int generic_file_open(struct inode * inode, struct file * filp); 1897 extern int generic_file_open(struct inode * inode, struct file * filp);
1897 extern int nonseekable_open(struct inode * inode, struct file * filp); 1898 extern int nonseekable_open(struct inode * inode, struct file * filp);
1898 1899
1899 #ifdef CONFIG_FS_XIP 1900 #ifdef CONFIG_FS_XIP
1900 extern ssize_t xip_file_read(struct file *filp, char __user *buf, size_t len, 1901 extern ssize_t xip_file_read(struct file *filp, char __user *buf, size_t len,
1901 loff_t *ppos); 1902 loff_t *ppos);
1902 extern int xip_file_mmap(struct file * file, struct vm_area_struct * vma); 1903 extern int xip_file_mmap(struct file * file, struct vm_area_struct * vma);
1903 extern ssize_t xip_file_write(struct file *filp, const char __user *buf, 1904 extern ssize_t xip_file_write(struct file *filp, const char __user *buf,
1904 size_t len, loff_t *ppos); 1905 size_t len, loff_t *ppos);
1905 extern int xip_truncate_page(struct address_space *mapping, loff_t from); 1906 extern int xip_truncate_page(struct address_space *mapping, loff_t from);
1906 #else 1907 #else
1907 static inline int xip_truncate_page(struct address_space *mapping, loff_t from) 1908 static inline int xip_truncate_page(struct address_space *mapping, loff_t from)
1908 { 1909 {
1909 return 0; 1910 return 0;
1910 } 1911 }
1911 #endif 1912 #endif
1912 1913
1913 #ifdef CONFIG_BLOCK 1914 #ifdef CONFIG_BLOCK
1914 ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, 1915 ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1915 struct block_device *bdev, const struct iovec *iov, loff_t offset, 1916 struct block_device *bdev, const struct iovec *iov, loff_t offset,
1916 unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io, 1917 unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io,
1917 int lock_type); 1918 int lock_type);
1918 1919
1919 enum { 1920 enum {
1920 DIO_LOCKING = 1, /* need locking between buffered and direct access */ 1921 DIO_LOCKING = 1, /* need locking between buffered and direct access */
1921 DIO_NO_LOCKING, /* bdev; no locking at all between buffered/direct */ 1922 DIO_NO_LOCKING, /* bdev; no locking at all between buffered/direct */
1922 DIO_OWN_LOCKING, /* filesystem locks buffered and direct internally */ 1923 DIO_OWN_LOCKING, /* filesystem locks buffered and direct internally */
1923 }; 1924 };
1924 1925
1925 static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb, 1926 static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb,
1926 struct inode *inode, struct block_device *bdev, const struct iovec *iov, 1927 struct inode *inode, struct block_device *bdev, const struct iovec *iov,
1927 loff_t offset, unsigned long nr_segs, get_block_t get_block, 1928 loff_t offset, unsigned long nr_segs, get_block_t get_block,
1928 dio_iodone_t end_io) 1929 dio_iodone_t end_io)
1929 { 1930 {
1930 return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, 1931 return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset,
1931 nr_segs, get_block, end_io, DIO_LOCKING); 1932 nr_segs, get_block, end_io, DIO_LOCKING);
1932 } 1933 }
1933 1934
1934 static inline ssize_t blockdev_direct_IO_no_locking(int rw, struct kiocb *iocb, 1935 static inline ssize_t blockdev_direct_IO_no_locking(int rw, struct kiocb *iocb,
1935 struct inode *inode, struct block_device *bdev, const struct iovec *iov, 1936 struct inode *inode, struct block_device *bdev, const struct iovec *iov,
1936 loff_t offset, unsigned long nr_segs, get_block_t get_block, 1937 loff_t offset, unsigned long nr_segs, get_block_t get_block,
1937 dio_iodone_t end_io) 1938 dio_iodone_t end_io)
1938 { 1939 {
1939 return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, 1940 return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset,
1940 nr_segs, get_block, end_io, DIO_NO_LOCKING); 1941 nr_segs, get_block, end_io, DIO_NO_LOCKING);
1941 } 1942 }
1942 1943
1943 static inline ssize_t blockdev_direct_IO_own_locking(int rw, struct kiocb *iocb, 1944 static inline ssize_t blockdev_direct_IO_own_locking(int rw, struct kiocb *iocb,
1944 struct inode *inode, struct block_device *bdev, const struct iovec *iov, 1945 struct inode *inode, struct block_device *bdev, const struct iovec *iov,
1945 loff_t offset, unsigned long nr_segs, get_block_t get_block, 1946 loff_t offset, unsigned long nr_segs, get_block_t get_block,
1946 dio_iodone_t end_io) 1947 dio_iodone_t end_io)
1947 { 1948 {
1948 return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, 1949 return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset,
1949 nr_segs, get_block, end_io, DIO_OWN_LOCKING); 1950 nr_segs, get_block, end_io, DIO_OWN_LOCKING);
1950 } 1951 }
1951 #endif 1952 #endif
1952 1953
1953 extern const struct file_operations generic_ro_fops; 1954 extern const struct file_operations generic_ro_fops;
1954 1955
1955 #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m)) 1956 #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m))
1956 1957
1957 extern int vfs_readlink(struct dentry *, char __user *, int, const char *); 1958 extern int vfs_readlink(struct dentry *, char __user *, int, const char *);
1958 extern int vfs_follow_link(struct nameidata *, const char *); 1959 extern int vfs_follow_link(struct nameidata *, const char *);
1959 extern int page_readlink(struct dentry *, char __user *, int); 1960 extern int page_readlink(struct dentry *, char __user *, int);
1960 extern void *page_follow_link_light(struct dentry *, struct nameidata *); 1961 extern void *page_follow_link_light(struct dentry *, struct nameidata *);
1961 extern void page_put_link(struct dentry *, struct nameidata *, void *); 1962 extern void page_put_link(struct dentry *, struct nameidata *, void *);
1962 extern int __page_symlink(struct inode *inode, const char *symname, int len, 1963 extern int __page_symlink(struct inode *inode, const char *symname, int len,
1963 gfp_t gfp_mask); 1964 gfp_t gfp_mask);
1964 extern int page_symlink(struct inode *inode, const char *symname, int len); 1965 extern int page_symlink(struct inode *inode, const char *symname, int len);
1965 extern const struct inode_operations page_symlink_inode_operations; 1966 extern const struct inode_operations page_symlink_inode_operations;
1966 extern int generic_readlink(struct dentry *, char __user *, int); 1967 extern int generic_readlink(struct dentry *, char __user *, int);
1967 extern void generic_fillattr(struct inode *, struct kstat *); 1968 extern void generic_fillattr(struct inode *, struct kstat *);
1968 extern int vfs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 1969 extern int vfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
1969 void inode_add_bytes(struct inode *inode, loff_t bytes); 1970 void inode_add_bytes(struct inode *inode, loff_t bytes);
1970 void inode_sub_bytes(struct inode *inode, loff_t bytes); 1971 void inode_sub_bytes(struct inode *inode, loff_t bytes);
1971 loff_t inode_get_bytes(struct inode *inode); 1972 loff_t inode_get_bytes(struct inode *inode);
1972 void inode_set_bytes(struct inode *inode, loff_t bytes); 1973 void inode_set_bytes(struct inode *inode, loff_t bytes);
1973 1974
1974 extern int vfs_readdir(struct file *, filldir_t, void *); 1975 extern int vfs_readdir(struct file *, filldir_t, void *);
1975 1976
1976 extern int vfs_stat(char __user *, struct kstat *); 1977 extern int vfs_stat(char __user *, struct kstat *);
1977 extern int vfs_lstat(char __user *, struct kstat *); 1978 extern int vfs_lstat(char __user *, struct kstat *);
1978 extern int vfs_stat_fd(int dfd, char __user *, struct kstat *); 1979 extern int vfs_stat_fd(int dfd, char __user *, struct kstat *);
1979 extern int vfs_lstat_fd(int dfd, char __user *, struct kstat *); 1980 extern int vfs_lstat_fd(int dfd, char __user *, struct kstat *);
1980 extern int vfs_fstat(unsigned int, struct kstat *); 1981 extern int vfs_fstat(unsigned int, struct kstat *);
1981 1982
1982 extern int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, 1983 extern int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
1983 unsigned long arg); 1984 unsigned long arg);
1984 1985
1985 extern void get_filesystem(struct file_system_type *fs); 1986 extern void get_filesystem(struct file_system_type *fs);
1986 extern void put_filesystem(struct file_system_type *fs); 1987 extern void put_filesystem(struct file_system_type *fs);
1987 extern struct file_system_type *get_fs_type(const char *name); 1988 extern struct file_system_type *get_fs_type(const char *name);
1988 extern struct super_block *get_super(struct block_device *); 1989 extern struct super_block *get_super(struct block_device *);
1989 extern struct super_block *user_get_super(dev_t); 1990 extern struct super_block *user_get_super(dev_t);
1990 extern void drop_super(struct super_block *sb); 1991 extern void drop_super(struct super_block *sb);
1991 1992
1992 extern int dcache_dir_open(struct inode *, struct file *); 1993 extern int dcache_dir_open(struct inode *, struct file *);
1993 extern int dcache_dir_close(struct inode *, struct file *); 1994 extern int dcache_dir_close(struct inode *, struct file *);
1994 extern loff_t dcache_dir_lseek(struct file *, loff_t, int); 1995 extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
1995 extern int dcache_readdir(struct file *, void *, filldir_t); 1996 extern int dcache_readdir(struct file *, void *, filldir_t);
1996 extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *); 1997 extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
1997 extern int simple_statfs(struct dentry *, struct kstatfs *); 1998 extern int simple_statfs(struct dentry *, struct kstatfs *);
1998 extern int simple_link(struct dentry *, struct inode *, struct dentry *); 1999 extern int simple_link(struct dentry *, struct inode *, struct dentry *);
1999 extern int simple_unlink(struct inode *, struct dentry *); 2000 extern int simple_unlink(struct inode *, struct dentry *);
2000 extern int simple_rmdir(struct inode *, struct dentry *); 2001 extern int simple_rmdir(struct inode *, struct dentry *);
2001 extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); 2002 extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
2002 extern int simple_sync_file(struct file *, struct dentry *, int); 2003 extern int simple_sync_file(struct file *, struct dentry *, int);
2003 extern int simple_empty(struct dentry *); 2004 extern int simple_empty(struct dentry *);
2004 extern int simple_readpage(struct file *file, struct page *page); 2005 extern int simple_readpage(struct file *file, struct page *page);
2005 extern int simple_prepare_write(struct file *file, struct page *page, 2006 extern int simple_prepare_write(struct file *file, struct page *page,
2006 unsigned offset, unsigned to); 2007 unsigned offset, unsigned to);
2007 extern int simple_write_begin(struct file *file, struct address_space *mapping, 2008 extern int simple_write_begin(struct file *file, struct address_space *mapping,
2008 loff_t pos, unsigned len, unsigned flags, 2009 loff_t pos, unsigned len, unsigned flags,
2009 struct page **pagep, void **fsdata); 2010 struct page **pagep, void **fsdata);
2010 extern int simple_write_end(struct file *file, struct address_space *mapping, 2011 extern int simple_write_end(struct file *file, struct address_space *mapping,
2011 loff_t pos, unsigned len, unsigned copied, 2012 loff_t pos, unsigned len, unsigned copied,
2012 struct page *page, void *fsdata); 2013 struct page *page, void *fsdata);
2013 2014
2014 extern struct dentry *simple_lookup(struct inode *, struct dentry *, struct nameidata *); 2015 extern struct dentry *simple_lookup(struct inode *, struct dentry *, struct nameidata *);
2015 extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *); 2016 extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *);
2016 extern const struct file_operations simple_dir_operations; 2017 extern const struct file_operations simple_dir_operations;
2017 extern const struct inode_operations simple_dir_inode_operations; 2018 extern const struct inode_operations simple_dir_inode_operations;
2018 struct tree_descr { char *name; const struct file_operations *ops; int mode; }; 2019 struct tree_descr { char *name; const struct file_operations *ops; int mode; };
2019 struct dentry *d_alloc_name(struct dentry *, const char *); 2020 struct dentry *d_alloc_name(struct dentry *, const char *);
2020 extern int simple_fill_super(struct super_block *, int, struct tree_descr *); 2021 extern int simple_fill_super(struct super_block *, int, struct tree_descr *);
2021 extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count); 2022 extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count);
2022 extern void simple_release_fs(struct vfsmount **mount, int *count); 2023 extern void simple_release_fs(struct vfsmount **mount, int *count);
2023 2024
2024 extern ssize_t simple_read_from_buffer(void __user *to, size_t count, 2025 extern ssize_t simple_read_from_buffer(void __user *to, size_t count,
2025 loff_t *ppos, const void *from, size_t available); 2026 loff_t *ppos, const void *from, size_t available);
2026 2027
2027 #ifdef CONFIG_MIGRATION 2028 #ifdef CONFIG_MIGRATION
2028 extern int buffer_migrate_page(struct address_space *, 2029 extern int buffer_migrate_page(struct address_space *,
2029 struct page *, struct page *); 2030 struct page *, struct page *);
2030 #else 2031 #else
2031 #define buffer_migrate_page NULL 2032 #define buffer_migrate_page NULL
2032 #endif 2033 #endif
2033 2034
2034 extern int inode_change_ok(struct inode *, struct iattr *); 2035 extern int inode_change_ok(struct inode *, struct iattr *);
2035 extern int __must_check inode_setattr(struct inode *, struct iattr *); 2036 extern int __must_check inode_setattr(struct inode *, struct iattr *);
2036 2037
2037 extern void file_update_time(struct file *file); 2038 extern void file_update_time(struct file *file);
2038 2039
2039 extern int generic_show_options(struct seq_file *m, struct vfsmount *mnt); 2040 extern int generic_show_options(struct seq_file *m, struct vfsmount *mnt);
2040 extern void save_mount_options(struct super_block *sb, char *options); 2041 extern void save_mount_options(struct super_block *sb, char *options);
2041 2042
2042 static inline ino_t parent_ino(struct dentry *dentry) 2043 static inline ino_t parent_ino(struct dentry *dentry)
2043 { 2044 {
2044 ino_t res; 2045 ino_t res;
2045 2046
2046 spin_lock(&dentry->d_lock); 2047 spin_lock(&dentry->d_lock);
2047 res = dentry->d_parent->d_inode->i_ino; 2048 res = dentry->d_parent->d_inode->i_ino;
2048 spin_unlock(&dentry->d_lock); 2049 spin_unlock(&dentry->d_lock);
2049 return res; 2050 return res;
2050 } 2051 }
2051 2052
2052 /* Transaction based IO helpers */ 2053 /* Transaction based IO helpers */
2053 2054
2054 /* 2055 /*
2055 * An argresp is stored in an allocated page and holds the 2056 * An argresp is stored in an allocated page and holds the
2056 * size of the argument or response, along with its content 2057 * size of the argument or response, along with its content
2057 */ 2058 */
2058 struct simple_transaction_argresp { 2059 struct simple_transaction_argresp {
2059 ssize_t size; 2060 ssize_t size;
2060 char data[0]; 2061 char data[0];
2061 }; 2062 };
2062 2063
2063 #define SIMPLE_TRANSACTION_LIMIT (PAGE_SIZE - sizeof(struct simple_transaction_argresp)) 2064 #define SIMPLE_TRANSACTION_LIMIT (PAGE_SIZE - sizeof(struct simple_transaction_argresp))
2064 2065
2065 char *simple_transaction_get(struct file *file, const char __user *buf, 2066 char *simple_transaction_get(struct file *file, const char __user *buf,
2066 size_t size); 2067 size_t size);
2067 ssize_t simple_transaction_read(struct file *file, char __user *buf, 2068 ssize_t simple_transaction_read(struct file *file, char __user *buf,
2068 size_t size, loff_t *pos); 2069 size_t size, loff_t *pos);
2069 int simple_transaction_release(struct inode *inode, struct file *file); 2070 int simple_transaction_release(struct inode *inode, struct file *file);
2070 2071
2071 static inline void simple_transaction_set(struct file *file, size_t n) 2072 static inline void simple_transaction_set(struct file *file, size_t n)
2072 { 2073 {
2073 struct simple_transaction_argresp *ar = file->private_data; 2074 struct simple_transaction_argresp *ar = file->private_data;
2074 2075
2075 BUG_ON(n > SIMPLE_TRANSACTION_LIMIT); 2076 BUG_ON(n > SIMPLE_TRANSACTION_LIMIT);
2076 2077
2077 /* 2078 /*
2078 * The barrier ensures that ar->size will really remain zero until 2079 * The barrier ensures that ar->size will really remain zero until
2079 * ar->data is ready for reading. 2080 * ar->data is ready for reading.
2080 */ 2081 */
2081 smp_mb(); 2082 smp_mb();
2082 ar->size = n; 2083 ar->size = n;
2083 } 2084 }
2084 2085
2085 /* 2086 /*
2086 * simple attribute files 2087 * simple attribute files
2087 * 2088 *
2088 * These attributes behave similar to those in sysfs: 2089 * These attributes behave similar to those in sysfs:
2089 * 2090 *
2090 * Writing to an attribute immediately sets a value, an open file can be 2091 * Writing to an attribute immediately sets a value, an open file can be
2091 * written to multiple times. 2092 * written to multiple times.
2092 * 2093 *
2093 * Reading from an attribute creates a buffer from the value that might get 2094 * Reading from an attribute creates a buffer from the value that might get
2094 * read with multiple read calls. When the attribute has been read 2095 * read with multiple read calls. When the attribute has been read
2095 * completely, no further read calls are possible until the file is opened 2096 * completely, no further read calls are possible until the file is opened
2096 * again. 2097 * again.
2097 * 2098 *
2098 * All attributes contain a text representation of a numeric value 2099 * All attributes contain a text representation of a numeric value
2099 * that are accessed with the get() and set() functions. 2100 * that are accessed with the get() and set() functions.
2100 */ 2101 */
2101 #define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \ 2102 #define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
2102 static int __fops ## _open(struct inode *inode, struct file *file) \ 2103 static int __fops ## _open(struct inode *inode, struct file *file) \
2103 { \ 2104 { \
2104 __simple_attr_check_format(__fmt, 0ull); \ 2105 __simple_attr_check_format(__fmt, 0ull); \
2105 return simple_attr_open(inode, file, __get, __set, __fmt); \ 2106 return simple_attr_open(inode, file, __get, __set, __fmt); \
2106 } \ 2107 } \
2107 static struct file_operations __fops = { \ 2108 static struct file_operations __fops = { \
2108 .owner = THIS_MODULE, \ 2109 .owner = THIS_MODULE, \
2109 .open = __fops ## _open, \ 2110 .open = __fops ## _open, \
2110 .release = simple_attr_release, \ 2111 .release = simple_attr_release, \
2111 .read = simple_attr_read, \ 2112 .read = simple_attr_read, \
2112 .write = simple_attr_write, \ 2113 .write = simple_attr_write, \
2113 }; 2114 };
2114 2115
2115 static inline void __attribute__((format(printf, 1, 2))) 2116 static inline void __attribute__((format(printf, 1, 2)))
2116 __simple_attr_check_format(const char *fmt, ...) 2117 __simple_attr_check_format(const char *fmt, ...)
2117 { 2118 {
2118 /* don't do anything, just let the compiler check the arguments; */ 2119 /* don't do anything, just let the compiler check the arguments; */
2119 } 2120 }
2120 2121
2121 int simple_attr_open(struct inode *inode, struct file *file, 2122 int simple_attr_open(struct inode *inode, struct file *file,
2122 int (*get)(void *, u64 *), int (*set)(void *, u64), 2123 int (*get)(void *, u64 *), int (*set)(void *, u64),
2123 const char *fmt); 2124 const char *fmt);
2124 int simple_attr_release(struct inode *inode, struct file *file); 2125 int simple_attr_release(struct inode *inode, struct file *file);
2125 ssize_t simple_attr_read(struct file *file, char __user *buf, 2126 ssize_t simple_attr_read(struct file *file, char __user *buf,
2126 size_t len, loff_t *ppos); 2127 size_t len, loff_t *ppos);
2127 ssize_t simple_attr_write(struct file *file, const char __user *buf, 2128 ssize_t simple_attr_write(struct file *file, const char __user *buf,
2128 size_t len, loff_t *ppos); 2129 size_t len, loff_t *ppos);
2129 2130
2130 2131
2131 #ifdef CONFIG_SECURITY 2132 #ifdef CONFIG_SECURITY
2132 static inline char *alloc_secdata(void) 2133 static inline char *alloc_secdata(void)
2133 { 2134 {
2134 return (char *)get_zeroed_page(GFP_KERNEL); 2135 return (char *)get_zeroed_page(GFP_KERNEL);
2135 } 2136 }
2136 2137
2137 static inline void free_secdata(void *secdata) 2138 static inline void free_secdata(void *secdata)
2138 { 2139 {
2139 free_page((unsigned long)secdata); 2140 free_page((unsigned long)secdata);
2140 } 2141 }
2141 #else 2142 #else
2142 static inline char *alloc_secdata(void) 2143 static inline char *alloc_secdata(void)
2143 { 2144 {
2144 return (char *)1; 2145 return (char *)1;
2145 } 2146 }
2146 2147
2147 static inline void free_secdata(void *secdata) 2148 static inline void free_secdata(void *secdata)
2148 { } 2149 { }
2149 #endif /* CONFIG_SECURITY */ 2150 #endif /* CONFIG_SECURITY */
2150 2151
2151 struct ctl_table; 2152 struct ctl_table;
2152 int proc_nr_files(struct ctl_table *table, int write, struct file *filp, 2153 int proc_nr_files(struct ctl_table *table, int write, struct file *filp,
2153 void __user *buffer, size_t *lenp, loff_t *ppos); 2154 void __user *buffer, size_t *lenp, loff_t *ppos);
2154 2155
2155 int get_filesystem_list(char * buf); 2156 int get_filesystem_list(char * buf);
2156 2157
2157 #endif /* __KERNEL__ */ 2158 #endif /* __KERNEL__ */
2158 #endif /* _LINUX_FS_H */ 2159 #endif /* _LINUX_FS_H */
2159 2160