File: /usr/src/linux/include/linux/fs.h
1 #ifndef _LINUX_FS_H
2 #define _LINUX_FS_H
3
4 /*
5 * This file has definitions for some important file table
6 * structures etc.
7 */
8
9 #include <linux/config.h>
10 #include <linux/linkage.h>
11 #include <linux/limits.h>
12 #include <linux/wait.h>
13 #include <linux/types.h>
14 #include <linux/vfs.h>
15 #include <linux/net.h>
16 #include <linux/kdev_t.h>
17 #include <linux/ioctl.h>
18 #include <linux/list.h>
19 #include <linux/dcache.h>
20 #include <linux/stat.h>
21 #include <linux/cache.h>
22 #include <linux/stddef.h>
23 #include <linux/string.h>
24
25 #include <asm/atomic.h>
26 #include <asm/bitops.h>
27
28 struct poll_table_struct;
29
30
31 /*
32 * It's silly to have NR_OPEN bigger than NR_FILE, but you can change
33 * the file limit at runtime and only root can increase the per-process
34 * nr_file rlimit, so it's safe to set up a ridiculously high absolute
35 * upper limit on files-per-process.
36 *
37 * Some programs (notably those using select()) may have to be
38 * recompiled to take full advantage of the new limits..
39 */
40
41 /* Fixed constants first: */
42 #undef NR_OPEN
43 #define NR_OPEN (1024*1024) /* Absolute upper limit on fd num */
44 #define INR_OPEN 1024 /* Initial setting for nfile rlimits */
45
46 #define BLOCK_SIZE_BITS 10
47 #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
48
49 /* buffer header fixed size for the blkdev I/O through pagecache */
50 #define BUFFERED_BLOCKSIZE_BITS 10
51 #define BUFFERED_BLOCKSIZE (1 << BUFFERED_BLOCKSIZE_BITS)
52
53 /* And dynamically-tunable limits and defaults: */
54 struct files_stat_struct {
55 int nr_files; /* read only */
56 int nr_free_files; /* read only */
57 int max_files; /* tunable */
58 };
59 extern struct files_stat_struct files_stat;
60
61 struct inodes_stat_t {
62 int nr_inodes;
63 int nr_unused;
64 int dummy[5];
65 };
66 extern struct inodes_stat_t inodes_stat;
67
68 extern int leases_enable, dir_notify_enable, lease_break_time;
69
70 #define NR_FILE 8192 /* this can well be larger on a larger system */
71 #define NR_RESERVED_FILES 10 /* reserved for root */
72 #define NR_SUPER 256
73
74 #define MAY_EXEC 1
75 #define MAY_WRITE 2
76 #define MAY_READ 4
77
78 #define FMODE_READ 1
79 #define FMODE_WRITE 2
80
81 #define READ 0
82 #define WRITE 1
83 #define READA 2 /* read-ahead - don't block if no resources */
84 #define SPECIAL 4 /* For non-blockdevice requests in request queue */
85
86 #define SEL_IN 1
87 #define SEL_OUT 2
88 #define SEL_EX 4
89
90 /* public flags for file_system_type */
91 #define FS_REQUIRES_DEV 1
92 #define FS_NO_DCACHE 2 /* Only dcache the necessary things. */
93 #define FS_NO_PRELIM 4 /* prevent preloading of dentries, even if
94 * FS_NO_DCACHE is not set.
95 */
96 #define FS_SINGLE 8 /* Filesystem that can have only one superblock */
97 #define FS_NOMOUNT 16 /* Never mount from userland */
98 #define FS_LITTER 32 /* Keeps the tree in dcache */
99 #define FS_ODD_RENAME 32768 /* Temporary stuff; will go away as soon
100 * as nfs_rename() will be cleaned up
101 */
102 /*
103 * These are the fs-independent mount-flags: up to 32 flags are supported
104 */
105 #define MS_RDONLY 1 /* Mount read-only */
106 #define MS_NOSUID 2 /* Ignore suid and sgid bits */
107 #define MS_NODEV 4 /* Disallow access to device special files */
108 #define MS_NOEXEC 8 /* Disallow program execution */
109 #define MS_SYNCHRONOUS 16 /* Writes are synced at once */
110 #define MS_REMOUNT 32 /* Alter flags of a mounted FS */
111 #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
112 #define MS_NOATIME 1024 /* Do not update access times. */
113 #define MS_NODIRATIME 2048 /* Do not update directory access times */
114 #define MS_BIND 4096
115 #define MS_NOUSER (1<<31)
116
117 /*
118 * Superblock flags that can be altered by MS_REMOUNT
119 */
120 #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME|\
121 MS_NODIRATIME)
122
123 /*
124 * Old magic mount flag and mask
125 */
126 #define MS_MGC_VAL 0xC0ED0000
127 #define MS_MGC_MSK 0xffff0000
128
129 /* Inode flags - they have nothing to superblock flags now */
130
131 #define S_SYNC 1 /* Writes are synced at once */
132 #define S_NOATIME 2 /* Do not update access times */
133 #define S_QUOTA 4 /* Quota initialized for file */
134 #define S_APPEND 8 /* Append-only file */
135 #define S_IMMUTABLE 16 /* Immutable file */
136 #define S_DEAD 32 /* removed, but still open directory */
137 #define S_NOQUOTA 64 /* Inode is not counted to quota */
138
139 /*
140 * Note that nosuid etc flags are inode-specific: setting some file-system
141 * flags just means all the inodes inherit those flags by default. It might be
142 * possible to override it selectively if you really wanted to with some
143 * ioctl() that is not currently implemented.
144 *
145 * Exception: MS_RDONLY is always applied to the entire file system.
146 *
147 * Unfortunately, it is possible to change a filesystems flags with it mounted
148 * with files in use. This means that all of the inodes will not have their
149 * i_flags updated. Hence, i_flags no longer inherit the superblock mount
150 * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org
151 */
152 #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
153
154 #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
155 #define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || ((inode)->i_flags & S_SYNC))
156 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
157
158 #define IS_QUOTAINIT(inode) ((inode)->i_flags & S_QUOTA)
159 #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
160 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
161 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
162 #define IS_NOATIME(inode) (__IS_FLG(inode, MS_NOATIME) || ((inode)->i_flags & S_NOATIME))
163 #define IS_NODIRATIME(inode) __IS_FLG(inode, MS_NODIRATIME)
164
165 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
166
167 /* the read-only stuff doesn't really belong here, but any other place is
168 probably as bad and I don't want to create yet another include file. */
169
170 #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
171 #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
172 #define BLKRRPART _IO(0x12,95) /* re-read partition table */
173 #define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */
174 #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
175 #define BLKRASET _IO(0x12,98) /* Set read ahead for block device */
176 #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
177 #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
178 #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
179 #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
180 #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
181 #define BLKSSZGET _IO(0x12,104)/* get block device sector size */
182 #if 0
183 #define BLKPG _IO(0x12,105)/* See blkpg.h */
184 #define BLKELVGET _IOR(0x12,106,sizeof(blkelv_ioctl_arg_t))/* elevator get */
185 #define BLKELVSET _IOW(0x12,107,sizeof(blkelv_ioctl_arg_t))/* elevator set */
186 /* This was here just to show that the number is taken -
187 probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */
188 #endif
189 /* A jump here: 108-111 have been used for various private purposes. */
190 #define BLKBSZGET _IOR(0x12,112,sizeof(int))
191 #define BLKBSZSET _IOW(0x12,113,sizeof(int))
192 #define BLKGETSIZE64 _IOR(0x12,114,sizeof(u64)) /* return device size in bytes (u64 *arg) */
193
194 #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
195 #define FIBMAP _IO(0x00,1) /* bmap access */
196 #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */
197
198 #ifdef __KERNEL__
199
200 #include <asm/semaphore.h>
201 #include <asm/byteorder.h>
202
203 extern void update_atime (struct inode *);
204 #define UPDATE_ATIME(inode) update_atime (inode)
205
206 extern void buffer_init(unsigned long);
207 extern void inode_init(unsigned long);
208 extern void mnt_init(unsigned long);
209
210 /* bh state bits */
211 enum bh_state_bits {
212 BH_Uptodate, /* 1 if the buffer contains valid data */
213 BH_Dirty, /* 1 if the buffer is dirty */
214 BH_Lock, /* 1 if the buffer is locked */
215 BH_Req, /* 0 if the buffer has been invalidated */
216 BH_Mapped, /* 1 if the buffer has a disk mapping */
217 BH_New, /* 1 if the buffer is new and not yet written out */
218 BH_Async, /* 1 if the buffer is under end_buffer_io_async I/O */
219 BH_Wait_IO, /* 1 if we should throttle on this buffer */
220
221 BH_PrivateStart,/* not a state bit, but the first bit available
222 * for private allocation by other entities
223 */
224 };
225
226 /*
227 * Try to keep the most commonly used fields in single cache lines (16
228 * bytes) to improve performance. This ordering should be
229 * particularly beneficial on 32-bit processors.
230 *
231 * We use the first 16 bytes for the data which is used in searches
232 * over the block hash lists (ie. getblk() and friends).
233 *
234 * The second 16 bytes we use for lru buffer scans, as used by
235 * sync_buffers() and refill_freelist(). -- sct
236 */
237 struct buffer_head {
238 /* First cache line: */
239 struct buffer_head *b_next; /* Hash queue list */
240 unsigned long b_blocknr; /* block number */
241 unsigned short b_size; /* block size */
242 unsigned short b_list; /* List that this buffer appears */
243 kdev_t b_dev; /* device (B_FREE = free) */
244
245 atomic_t b_count; /* users using this block */
246 kdev_t b_rdev; /* Real device */
247 unsigned long b_state; /* buffer state bitmap (see above) */
248 unsigned long b_flushtime; /* Time when (dirty) buffer should be written */
249
250 struct buffer_head *b_next_free;/* lru/free list linkage */
251 struct buffer_head *b_prev_free;/* doubly linked list of buffers */
252 struct buffer_head *b_this_page;/* circular list of buffers in one page */
253 struct buffer_head *b_reqnext; /* request queue */
254
255 struct buffer_head **b_pprev; /* doubly linked list of hash-queue */
256 char * b_data; /* pointer to data block */
257 struct page *b_page; /* the page this bh is mapped to */
258 void (*b_end_io)(struct buffer_head *bh, int uptodate); /* I/O completion */
259 void *b_private; /* reserved for b_end_io */
260
261 unsigned long b_rsector; /* Real buffer location on disk */
262 wait_queue_head_t b_wait;
263
264 struct inode * b_inode;
265 struct list_head b_inode_buffers; /* doubly linked list of inode dirty buffers */
266 };
267
268 typedef void (bh_end_io_t)(struct buffer_head *bh, int uptodate);
269 void init_buffer(struct buffer_head *, bh_end_io_t *, void *);
270
271 #define __buffer_state(bh, state) (((bh)->b_state & (1UL << BH_##state)) != 0)
272
273 #define buffer_uptodate(bh) __buffer_state(bh,Uptodate)
274 #define buffer_dirty(bh) __buffer_state(bh,Dirty)
275 #define buffer_locked(bh) __buffer_state(bh,Lock)
276 #define buffer_req(bh) __buffer_state(bh,Req)
277 #define buffer_mapped(bh) __buffer_state(bh,Mapped)
278 #define buffer_new(bh) __buffer_state(bh,New)
279 #define buffer_async(bh) __buffer_state(bh,Async)
280
281 #define bh_offset(bh) ((unsigned long)(bh)->b_data & ~PAGE_MASK)
282
283 extern void set_bh_page(struct buffer_head *bh, struct page *page, unsigned long offset);
284
285 #define touch_buffer(bh) SetPageReferenced(bh->b_page)
286
287
288 #include <linux/pipe_fs_i.h>
289 #include <linux/minix_fs_i.h>
290 #include <linux/ext2_fs_i.h>
291 #include <linux/hpfs_fs_i.h>
292 #include <linux/ntfs_fs_i.h>
293 #include <linux/msdos_fs_i.h>
294 #include <linux/umsdos_fs_i.h>
295 #include <linux/iso_fs_i.h>
296 #include <linux/nfs_fs_i.h>
297 #include <linux/sysv_fs_i.h>
298 #include <linux/affs_fs_i.h>
299 #include <linux/ufs_fs_i.h>
300 #include <linux/efs_fs_i.h>
301 #include <linux/coda_fs_i.h>
302 #include <linux/romfs_fs_i.h>
303 #include <linux/shmem_fs.h>
304 #include <linux/smb_fs_i.h>
305 #include <linux/hfs_fs_i.h>
306 #include <linux/adfs_fs_i.h>
307 #include <linux/qnx4_fs_i.h>
308 #include <linux/reiserfs_fs_i.h>
309 #include <linux/bfs_fs_i.h>
310 #include <linux/udf_fs_i.h>
311 #include <linux/ncp_fs_i.h>
312 #include <linux/proc_fs_i.h>
313 #include <linux/usbdev_fs_i.h>
314 #include <linux/jffs2_fs_i.h>
315 #include <linux/cramfs_fs_sb.h>
316
317 /*
318 * Attribute flags. These should be or-ed together to figure out what
319 * has been changed!
320 */
321 #define ATTR_MODE 1
322 #define ATTR_UID 2
323 #define ATTR_GID 4
324 #define ATTR_SIZE 8
325 #define ATTR_ATIME 16
326 #define ATTR_MTIME 32
327 #define ATTR_CTIME 64
328 #define ATTR_ATIME_SET 128
329 #define ATTR_MTIME_SET 256
330 #define ATTR_FORCE 512 /* Not a change, but a change it */
331 #define ATTR_ATTR_FLAG 1024
332
333 /*
334 * This is the Inode Attributes structure, used for notify_change(). It
335 * uses the above definitions as flags, to know which values have changed.
336 * Also, in this manner, a Filesystem can look at only the values it cares
337 * about. Basically, these are the attributes that the VFS layer can
338 * request to change from the FS layer.
339 *
340 * Derek Atkins <warlord@MIT.EDU> 94-10-20
341 */
342 struct iattr {
343 unsigned int ia_valid;
344 umode_t ia_mode;
345 uid_t ia_uid;
346 gid_t ia_gid;
347 loff_t ia_size;
348 time_t ia_atime;
349 time_t ia_mtime;
350 time_t ia_ctime;
351 unsigned int ia_attr_flags;
352 };
353
354 /*
355 * This is the inode attributes flag definitions
356 */
357 #define ATTR_FLAG_SYNCRONOUS 1 /* Syncronous write */
358 #define ATTR_FLAG_NOATIME 2 /* Don't update atime */
359 #define ATTR_FLAG_APPEND 4 /* Append-only file */
360 #define ATTR_FLAG_IMMUTABLE 8 /* Immutable file */
361 #define ATTR_FLAG_NODIRATIME 16 /* Don't update atime for directory */
362
363 /*
364 * Includes for diskquotas and mount structures.
365 */
366 #include <linux/quota.h>
367 #include <linux/mount.h>
368
369 /*
370 * oh the beauties of C type declarations.
371 */
372 struct page;
373 struct address_space;
374 struct kiobuf;
375
376 struct address_space_operations {
377 int (*writepage)(struct page *);
378 int (*readpage)(struct file *, struct page *);
379 int (*sync_page)(struct page *);
380 int (*prepare_write)(struct file *, struct page *, unsigned, unsigned);
381 int (*commit_write)(struct file *, struct page *, unsigned, unsigned);
382 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
383 int (*bmap)(struct address_space *, long);
384 #define KERNEL_HAS_O_DIRECT /* this is for modules out of the kernel */
385 int (*direct_IO)(int, struct inode *, struct kiobuf *, unsigned long, int);
386 };
387
388 struct address_space {
389 struct list_head clean_pages; /* list of clean pages */
390 struct list_head dirty_pages; /* list of dirty pages */
391 struct list_head locked_pages; /* list of locked pages */
392 unsigned long nrpages; /* number of total pages */
393 struct address_space_operations *a_ops; /* methods */
394 struct inode *host; /* owner: inode, block_device */
395 struct vm_area_struct *i_mmap; /* list of private mappings */
396 struct vm_area_struct *i_mmap_shared; /* list of shared mappings */
397 spinlock_t i_shared_lock; /* and spinlock protecting it */
398 int gfp_mask; /* how to allocate the pages */
399 };
400
401 struct char_device {
402 struct list_head hash;
403 atomic_t count;
404 dev_t dev;
405 atomic_t openers;
406 struct semaphore sem;
407 };
408
409 struct block_device {
410 struct list_head bd_hash;
411 atomic_t bd_count;
412 struct inode * bd_inode;
413 dev_t bd_dev; /* not a kdev_t - it's a search key */
414 int bd_openers;
415 const struct block_device_operations *bd_op;
416 struct semaphore bd_sem; /* open/close mutex */
417 struct list_head bd_inodes;
418 };
419
420 struct inode {
421 struct list_head i_hash;
422 struct list_head i_list;
423 struct list_head i_dentry;
424
425 struct list_head i_dirty_buffers;
426 struct list_head i_dirty_data_buffers;
427
428 unsigned long i_ino;
429 atomic_t i_count;
430 kdev_t i_dev;
431 umode_t i_mode;
432 nlink_t i_nlink;
433 uid_t i_uid;
434 gid_t i_gid;
435 kdev_t i_rdev;
436 loff_t i_size;
437 time_t i_atime;
438 time_t i_mtime;
439 time_t i_ctime;
440 unsigned long i_blksize;
441 unsigned long i_blocks;
442 unsigned long i_version;
443 struct semaphore i_sem;
444 struct semaphore i_zombie;
445 struct inode_operations *i_op;
446 struct file_operations *i_fop; /* former ->i_op->default_file_ops */
447 struct super_block *i_sb;
448 wait_queue_head_t i_wait;
449 struct file_lock *i_flock;
450 struct address_space *i_mapping;
451 struct address_space i_data;
452 struct dquot *i_dquot[MAXQUOTAS];
453 /* These three should probably be a union */
454 struct list_head i_devices;
455 struct pipe_inode_info *i_pipe;
456 struct block_device *i_bdev;
457 struct char_device *i_cdev;
458
459 unsigned long i_dnotify_mask; /* Directory notify events */
460 struct dnotify_struct *i_dnotify; /* for directory notifications */
461
462 unsigned long i_state;
463
464 unsigned int i_flags;
465 unsigned char i_sock;
466
467 atomic_t i_writecount;
468 unsigned int i_attr_flags;
469 __u32 i_generation;
470 union {
471 struct minix_inode_info minix_i;
472 struct ext2_inode_info ext2_i;
473 struct hpfs_inode_info hpfs_i;
474 struct ntfs_inode_info ntfs_i;
475 struct msdos_inode_info msdos_i;
476 struct umsdos_inode_info umsdos_i;
477 struct iso_inode_info isofs_i;
478 struct nfs_inode_info nfs_i;
479 struct sysv_inode_info sysv_i;
480 struct affs_inode_info affs_i;
481 struct ufs_inode_info ufs_i;
482 struct efs_inode_info efs_i;
483 struct romfs_inode_info romfs_i;
484 struct shmem_inode_info shmem_i;
485 struct coda_inode_info coda_i;
486 struct smb_inode_info smbfs_i;
487 struct hfs_inode_info hfs_i;
488 struct adfs_inode_info adfs_i;
489 struct qnx4_inode_info qnx4_i;
490 struct reiserfs_inode_info reiserfs_i;
491 struct bfs_inode_info bfs_i;
492 struct udf_inode_info udf_i;
493 struct ncp_inode_info ncpfs_i;
494 struct proc_inode_info proc_i;
495 struct socket socket_i;
496 struct usbdev_inode_info usbdev_i;
497 struct jffs2_inode_info jffs2_i;
498 void *generic_ip;
499 } u;
500 };
501
502 struct fown_struct {
503 int pid; /* pid or -pgrp where SIGIO should be sent */
504 uid_t uid, euid; /* uid/euid of process setting the owner */
505 int signum; /* posix.1b rt signal to be delivered on IO */
506 };
507
508 struct file {
509 struct list_head f_list;
510 struct dentry *f_dentry;
511 struct vfsmount *f_vfsmnt;
512 struct file_operations *f_op;
513 atomic_t f_count;
514 unsigned int f_flags;
515 mode_t f_mode;
516 loff_t f_pos;
517 unsigned long f_reada, f_ramax, f_raend, f_ralen, f_rawin;
518 struct fown_struct f_owner;
519 unsigned int f_uid, f_gid;
520 int f_error;
521
522 unsigned long f_version;
523
524 /* needed for tty driver, and maybe others */
525 void *private_data;
526
527 /* preallocated helper kiobuf to speedup O_DIRECT */
528 struct kiobuf *f_iobuf;
529 long f_iobuf_lock;
530 };
531 extern spinlock_t files_lock;
532 #define file_list_lock() spin_lock(&files_lock);
533 #define file_list_unlock() spin_unlock(&files_lock);
534
535 #define get_file(x) atomic_inc(&(x)->f_count)
536 #define file_count(x) atomic_read(&(x)->f_count)
537
538 extern int init_private_file(struct file *, struct dentry *, int);
539
540 #define MAX_NON_LFS ((1UL<<31) - 1)
541
542 #define FL_POSIX 1
543 #define FL_FLOCK 2
544 #define FL_BROKEN 4 /* broken flock() emulation */
545 #define FL_ACCESS 8 /* for processes suspended by mandatory locking */
546 #define FL_LOCKD 16 /* lock held by rpc.lockd */
547 #define FL_LEASE 32 /* lease held on this file */
548
549 /*
550 * The POSIX file lock owner is determined by
551 * the "struct files_struct" in the thread group
552 * (or NULL for no owner - BSD locks).
553 *
554 * Lockd stuffs a "host" pointer into this.
555 */
556 typedef struct files_struct *fl_owner_t;
557
558 struct file_lock {
559 struct file_lock *fl_next; /* singly linked list for this inode */
560 struct list_head fl_link; /* doubly linked list of all locks */
561 struct list_head fl_block; /* circular list of blocked processes */
562 fl_owner_t fl_owner;
563 unsigned int fl_pid;
564 wait_queue_head_t fl_wait;
565 struct file *fl_file;
566 unsigned char fl_flags;
567 unsigned char fl_type;
568 loff_t fl_start;
569 loff_t fl_end;
570
571 void (*fl_notify)(struct file_lock *); /* unblock callback */
572 void (*fl_insert)(struct file_lock *); /* lock insertion callback */
573 void (*fl_remove)(struct file_lock *); /* lock removal callback */
574
575 struct fasync_struct * fl_fasync; /* for lease break notifications */
576
577 union {
578 struct nfs_lock_info nfs_fl;
579 } fl_u;
580 };
581
582 /* The following constant reflects the upper bound of the file/locking space */
583 #ifndef OFFSET_MAX
584 #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
585 #define OFFSET_MAX INT_LIMIT(loff_t)
586 #define OFFT_OFFSET_MAX INT_LIMIT(off_t)
587 #endif
588
589 extern struct list_head file_lock_list;
590
591 #include <linux/fcntl.h>
592
593 extern int fcntl_getlk(unsigned int, struct flock *);
594 extern int fcntl_setlk(unsigned int, unsigned int, struct flock *);
595
596 extern int fcntl_getlk64(unsigned int, struct flock64 *);
597 extern int fcntl_setlk64(unsigned int, unsigned int, struct flock64 *);
598
599 /* fs/locks.c */
600 extern void locks_init_lock(struct file_lock *);
601 extern void locks_copy_lock(struct file_lock *, struct file_lock *);
602 extern void locks_remove_posix(struct file *, fl_owner_t);
603 extern void locks_remove_flock(struct file *);
604 extern struct file_lock *posix_test_lock(struct file *, struct file_lock *);
605 extern int posix_lock_file(struct file *, struct file_lock *, unsigned int);
606 extern void posix_block_lock(struct file_lock *, struct file_lock *);
607 extern void posix_unblock_lock(struct file_lock *);
608 extern int __get_lease(struct inode *inode, unsigned int flags);
609 extern time_t lease_get_mtime(struct inode *);
610 extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
611 extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
612
613 struct fasync_struct {
614 int magic;
615 int fa_fd;
616 struct fasync_struct *fa_next; /* singly linked list */
617 struct file *fa_file;
618 };
619
620 #define FASYNC_MAGIC 0x4601
621
622 /* SMP safe fasync helpers: */
623 extern int fasync_helper(int, struct file *, int, struct fasync_struct **);
624 /* can be called from interrupts */
625 extern void kill_fasync(struct fasync_struct **, int, int);
626 /* only for net: no internal synchronization */
627 extern void __kill_fasync(struct fasync_struct *, int, int);
628
629 struct nameidata {
630 struct dentry *dentry;
631 struct vfsmount *mnt;
632 struct qstr last;
633 unsigned int flags;
634 int last_type;
635 };
636
637 #define DQUOT_USR_ENABLED 0x01 /* User diskquotas enabled */
638 #define DQUOT_GRP_ENABLED 0x02 /* Group diskquotas enabled */
639
640 struct quota_mount_options
641 {
642 unsigned int flags; /* Flags for diskquotas on this device */
643 struct semaphore dqio_sem; /* lock device while I/O in progress */
644 struct semaphore dqoff_sem; /* serialize quota_off() and quota_on() on device */
645 struct file *files[MAXQUOTAS]; /* fp's to quotafiles */
646 time_t inode_expire[MAXQUOTAS]; /* expiretime for inode-quota */
647 time_t block_expire[MAXQUOTAS]; /* expiretime for block-quota */
648 char rsquash[MAXQUOTAS]; /* for quotas threat root as any other user */
649 };
650
651 /*
652 * Umount options
653 */
654
655 #define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */
656
657 #include <linux/minix_fs_sb.h>
658 #include <linux/ext2_fs_sb.h>
659 #include <linux/hpfs_fs_sb.h>
660 #include <linux/ntfs_fs_sb.h>
661 #include <linux/msdos_fs_sb.h>
662 #include <linux/iso_fs_sb.h>
663 #include <linux/nfs_fs_sb.h>
664 #include <linux/sysv_fs_sb.h>
665 #include <linux/affs_fs_sb.h>
666 #include <linux/ufs_fs_sb.h>
667 #include <linux/efs_fs_sb.h>
668 #include <linux/romfs_fs_sb.h>
669 #include <linux/smb_fs_sb.h>
670 #include <linux/hfs_fs_sb.h>
671 #include <linux/adfs_fs_sb.h>
672 #include <linux/qnx4_fs_sb.h>
673 #include <linux/reiserfs_fs_sb.h>
674 #include <linux/bfs_fs_sb.h>
675 #include <linux/udf_fs_sb.h>
676 #include <linux/ncp_fs_sb.h>
677 #include <linux/usbdev_fs_sb.h>
678 #include <linux/cramfs_fs_sb.h>
679 #include <linux/jffs2_fs_sb.h>
680
681 extern struct list_head super_blocks;
682 extern spinlock_t sb_lock;
683
684 #define sb_entry(list) list_entry((list), struct super_block, s_list)
685 #define S_BIAS (1<<30)
686 struct super_block {
687 struct list_head s_list; /* Keep this first */
688 kdev_t s_dev;
689 unsigned long s_blocksize;
690 unsigned char s_blocksize_bits;
691 unsigned char s_dirt;
692 unsigned long long s_maxbytes; /* Max file size */
693 struct file_system_type *s_type;
694 struct super_operations *s_op;
695 struct dquot_operations *dq_op;
696 unsigned long s_flags;
697 unsigned long s_magic;
698 struct dentry *s_root;
699 struct rw_semaphore s_umount;
700 struct semaphore s_lock;
701 int s_count;
702 atomic_t s_active;
703
704 struct list_head s_dirty; /* dirty inodes */
705 struct list_head s_locked_inodes;/* inodes being synced */
706 struct list_head s_files;
707
708 struct block_device *s_bdev;
709 struct list_head s_instances;
710 struct quota_mount_options s_dquot; /* Diskquota specific options */
711
712 union {
713 struct minix_sb_info minix_sb;
714 struct ext2_sb_info ext2_sb;
715 struct hpfs_sb_info hpfs_sb;
716 struct ntfs_sb_info ntfs_sb;
717 struct msdos_sb_info msdos_sb;
718 struct isofs_sb_info isofs_sb;
719 struct nfs_sb_info nfs_sb;
720 struct sysv_sb_info sysv_sb;
721 struct affs_sb_info affs_sb;
722 struct ufs_sb_info ufs_sb;
723 struct efs_sb_info efs_sb;
724 struct shmem_sb_info shmem_sb;
725 struct romfs_sb_info romfs_sb;
726 struct smb_sb_info smbfs_sb;
727 struct hfs_sb_info hfs_sb;
728 struct adfs_sb_info adfs_sb;
729 struct qnx4_sb_info qnx4_sb;
730 struct reiserfs_sb_info reiserfs_sb;
731 struct bfs_sb_info bfs_sb;
732 struct udf_sb_info udf_sb;
733 struct ncp_sb_info ncpfs_sb;
734 struct usbdev_sb_info usbdevfs_sb;
735 struct jffs2_sb_info jffs2_sb;
736 struct cramfs_sb_info cramfs_sb;
737 void *generic_sbp;
738 } u;
739 /*
740 * The next field is for VFS *only*. No filesystems have any business
741 * even looking at it. You had been warned.
742 */
743 struct semaphore s_vfs_rename_sem; /* Kludge */
744
745 /* The next field is used by knfsd when converting a (inode number based)
746 * file handle into a dentry. As it builds a path in the dcache tree from
747 * the bottom up, there may for a time be a subpath of dentrys which is not
748 * connected to the main tree. This semaphore ensure that there is only ever
749 * one such free path per filesystem. Note that unconnected files (or other
750 * non-directories) are allowed, but not unconnected diretories.
751 */
752 struct semaphore s_nfsd_free_path_sem;
753 };
754
755 /*
756 * VFS helper functions..
757 */
758 extern int vfs_create(struct inode *, struct dentry *, int);
759 extern int vfs_mkdir(struct inode *, struct dentry *, int);
760 extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
761 extern int vfs_symlink(struct inode *, struct dentry *, const char *);
762 extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
763 extern int vfs_rmdir(struct inode *, struct dentry *);
764 extern int vfs_unlink(struct inode *, struct dentry *);
765 extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
766
767 /*
768 * File types
769 */
770 #define DT_UNKNOWN 0
771 #define DT_FIFO 1
772 #define DT_CHR 2
773 #define DT_DIR 4
774 #define DT_BLK 6
775 #define DT_REG 8
776 #define DT_LNK 10
777 #define DT_SOCK 12
778 #define DT_WHT 14
779
780 /*
781 * This is the "filldir" function type, used by readdir() to let
782 * the kernel specify what kind of dirent layout it wants to have.
783 * This allows the kernel to read directories into kernel space or
784 * to have different dirent layouts depending on the binary type.
785 */
786 typedef int (*filldir_t)(void *, const char *, int, loff_t, ino_t, unsigned);
787
788 struct block_device_operations {
789 int (*open) (struct inode *, struct file *);
790 int (*release) (struct inode *, struct file *);
791 int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
792 int (*check_media_change) (kdev_t);
793 int (*revalidate) (kdev_t);
794 };
795
796 /*
797 * NOTE:
798 * read, write, poll, fsync, readv, writev can be called
799 * without the big kernel lock held in all filesystems.
800 */
801 struct file_operations {
802 struct module *owner;
803 loff_t (*llseek) (struct file *, loff_t, int);
804 ssize_t (*read) (struct file *, char *, size_t, loff_t *);
805 ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
806 int (*readdir) (struct file *, void *, filldir_t);
807 unsigned int (*poll) (struct file *, struct poll_table_struct *);
808 int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
809 int (*mmap) (struct file *, struct vm_area_struct *);
810 int (*open) (struct inode *, struct file *);
811 int (*flush) (struct file *);
812 int (*release) (struct inode *, struct file *);
813 int (*fsync) (struct file *, struct dentry *, int datasync);
814 int (*fasync) (int, struct file *, int);
815 int (*lock) (struct file *, int, struct file_lock *);
816 ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
817 ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
818 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
819 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
820 };
821
822 struct inode_operations {
823 int (*create) (struct inode *,struct dentry *,int);
824 struct dentry * (*lookup) (struct inode *,struct dentry *);
825 int (*link) (struct dentry *,struct inode *,struct dentry *);
826 int (*unlink) (struct inode *,struct dentry *);
827 int (*symlink) (struct inode *,struct dentry *,const char *);
828 int (*mkdir) (struct inode *,struct dentry *,int);
829 int (*rmdir) (struct inode *,struct dentry *);
830 int (*mknod) (struct inode *,struct dentry *,int,int);
831 int (*rename) (struct inode *, struct dentry *,
832 struct inode *, struct dentry *);
833 int (*readlink) (struct dentry *, char *,int);
834 int (*follow_link) (struct dentry *, struct nameidata *);
835 void (*truncate) (struct inode *);
836 int (*permission) (struct inode *, int);
837 int (*revalidate) (struct dentry *);
838 int (*setattr) (struct dentry *, struct iattr *);
839 int (*getattr) (struct dentry *, struct iattr *);
840 };
841
842 /*
843 * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called
844 * without the big kernel lock held in all filesystems.
845 */
846 struct super_operations {
847 void (*read_inode) (struct inode *);
848
849 /* reiserfs kludge. reiserfs needs 64 bits of information to
850 ** find an inode. We are using the read_inode2 call to get
851 ** that information. We don't like this, and are waiting on some
852 ** VFS changes for the real solution.
853 ** iget4 calls read_inode2, iff it is defined
854 */
855 void (*read_inode2) (struct inode *, void *) ;
856 void (*dirty_inode) (struct inode *);
857 void (*write_inode) (struct inode *, int);
858 void (*put_inode) (struct inode *);
859 void (*delete_inode) (struct inode *);
860 void (*put_super) (struct super_block *);
861 void (*write_super) (struct super_block *);
862 void (*write_super_lockfs) (struct super_block *);
863 void (*unlockfs) (struct super_block *);
864 int (*statfs) (struct super_block *, struct statfs *);
865 int (*remount_fs) (struct super_block *, int *, char *);
866 void (*clear_inode) (struct inode *);
867 void (*umount_begin) (struct super_block *);
868
869 /* Following are for knfsd to interact with "interesting" filesystems
870 * Currently just reiserfs, but possibly FAT and others later
871 *
872 * fh_to_dentry is given a filehandle fragement with length, and a type flag
873 * and must return a dentry for the referenced object or, if "parent" is
874 * set, a dentry for the parent of the object.
875 * If a dentry cannot be found, a "root" dentry should be created and
876 * flaged as DCACHE_NFSD_DISCONNECTED. nfsd_iget is an example implementation.
877 *
878 * dentry_to_fh is given a dentry and must generate the filesys specific
879 * part of the file handle. Available length is passed in *lenp and used
880 * length should be returned therein.
881 * If need_parent is set, then dentry_to_fh should encode sufficient information
882 * to find the (current) parent.
883 * dentry_to_fh should return a 1byte "type" which will be passed back in
884 * the fhtype arguement to fh_to_dentry. Type of 0 is reserved.
885 * If filesystem was exportable before the introduction of fh_to_dentry,
886 * types 1 and 2 should be used is that same way as the generic code.
887 * Type 255 means error.
888 *
889 * Lengths are in units of 4bytes, not bytes.
890 */
891 struct dentry * (*fh_to_dentry)(struct super_block *sb, __u32 *fh, int len, int fhtype, int parent);
892 int (*dentry_to_fh)(struct dentry *, __u32 *fh, int *lenp, int need_parent);
893 };
894
895 /* Inode state bits.. */
896 #define I_DIRTY_SYNC 1 /* Not dirty enough for O_DATASYNC */
897 #define I_DIRTY_DATASYNC 2 /* Data-related inode changes pending */
898 #define I_DIRTY_PAGES 4 /* Data-related inode changes pending */
899 #define I_LOCK 8
900 #define I_FREEING 16
901 #define I_CLEAR 32
902
903 #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)
904
905 extern void __mark_inode_dirty(struct inode *, int);
906 static inline void mark_inode_dirty(struct inode *inode)
907 {
908 __mark_inode_dirty(inode, I_DIRTY);
909 }
910
911 static inline void mark_inode_dirty_sync(struct inode *inode)
912 {
913 __mark_inode_dirty(inode, I_DIRTY_SYNC);
914 }
915
916 static inline void mark_inode_dirty_pages(struct inode *inode)
917 {
918 __mark_inode_dirty(inode, I_DIRTY_PAGES);
919 }
920
921 struct dquot_operations {
922 void (*initialize) (struct inode *, short);
923 void (*drop) (struct inode *);
924 int (*alloc_block) (const struct inode *, unsigned long, char);
925 int (*alloc_inode) (const struct inode *, unsigned long);
926 void (*free_block) (const struct inode *, unsigned long);
927 void (*free_inode) (const struct inode *, unsigned long);
928 int (*transfer) (struct dentry *, struct iattr *);
929 };
930
931 struct file_system_type {
932 const char *name;
933 int fs_flags;
934 struct super_block *(*read_super) (struct super_block *, void *, int);
935 struct module *owner;
936 struct file_system_type * next;
937 struct list_head fs_supers;
938 };
939
940 #define DECLARE_FSTYPE(var,type,read,flags) \
941 struct file_system_type var = { \
942 name: type, \
943 read_super: read, \
944 fs_flags: flags, \
945 owner: THIS_MODULE, \
946 }
947
948 #define DECLARE_FSTYPE_DEV(var,type,read) \
949 DECLARE_FSTYPE(var,type,read,FS_REQUIRES_DEV)
950
951 /* Alas, no aliases. Too much hassle with bringing module.h everywhere */
952 #define fops_get(fops) \
953 (((fops) && (fops)->owner) \
954 ? ( try_inc_mod_count((fops)->owner) ? (fops) : NULL ) \
955 : (fops))
956
957 #define fops_put(fops) \
958 do { \
959 if ((fops) && (fops)->owner) \
960 __MOD_DEC_USE_COUNT((fops)->owner); \
961 } while(0)
962
963 extern int register_filesystem(struct file_system_type *);
964 extern int unregister_filesystem(struct file_system_type *);
965 extern struct vfsmount *kern_mount(struct file_system_type *);
966 extern int may_umount(struct vfsmount *);
967 extern long do_mount(char *, char *, char *, unsigned long, void *);
968
969 #define kern_umount mntput
970
971 extern int vfs_statfs(struct super_block *, struct statfs *);
972
973 /* Return value for VFS lock functions - tells locks.c to lock conventionally
974 * REALLY kosha for root NFS and nfs_lock
975 */
976 #define LOCK_USE_CLNT 1
977
978 #define FLOCK_VERIFY_READ 1
979 #define FLOCK_VERIFY_WRITE 2
980
981 extern int locks_mandatory_locked(struct inode *);
982 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
983
984 /*
985 * Candidates for mandatory locking have the setgid bit set
986 * but no group execute bit - an otherwise meaningless combination.
987 */
988 #define MANDATORY_LOCK(inode) \
989 (IS_MANDLOCK(inode) && ((inode)->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID)
990
991 static inline int locks_verify_locked(struct inode *inode)
992 {
993 if (MANDATORY_LOCK(inode))
994 return locks_mandatory_locked(inode);
995 return 0;
996 }
997
998 static inline int locks_verify_area(int read_write, struct inode *inode,
999 struct file *filp, loff_t offset,
1000 size_t count)
1001 {
1002 if (inode->i_flock && MANDATORY_LOCK(inode))
1003 return locks_mandatory_area(read_write, inode, filp, offset, count);
1004 return 0;
1005 }
1006
1007 static inline int locks_verify_truncate(struct inode *inode,
1008 struct file *filp,
1009 loff_t size)
1010 {
1011 if (inode->i_flock && MANDATORY_LOCK(inode))
1012 return locks_mandatory_area(
1013 FLOCK_VERIFY_WRITE, inode, filp,
1014 size < inode->i_size ? size : inode->i_size,
1015 (size < inode->i_size ? inode->i_size - size
1016 : size - inode->i_size)
1017 );
1018 return 0;
1019 }
1020
1021 static inline int get_lease(struct inode *inode, unsigned int mode)
1022 {
1023 if (inode->i_flock && (inode->i_flock->fl_flags & FL_LEASE))
1024 return __get_lease(inode, mode);
1025 return 0;
1026 }
1027
1028 /* fs/open.c */
1029
1030 asmlinkage long sys_open(const char *, int, int);
1031 asmlinkage long sys_close(unsigned int); /* yes, it's really unsigned */
1032 extern int do_truncate(struct dentry *, loff_t start);
1033
1034 extern struct file *filp_open(const char *, int, int);
1035 extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
1036 extern int filp_close(struct file *, fl_owner_t id);
1037 extern char * getname(const char *);
1038
1039 /* fs/dcache.c */
1040 extern void vfs_caches_init(unsigned long);
1041
1042 #define __getname() kmem_cache_alloc(names_cachep, SLAB_KERNEL)
1043 #define putname(name) kmem_cache_free(names_cachep, (void *)(name))
1044
1045 enum {BDEV_FILE, BDEV_SWAP, BDEV_FS, BDEV_RAW};
1046 extern int register_blkdev(unsigned int, const char *, struct block_device_operations *);
1047 extern int unregister_blkdev(unsigned int, const char *);
1048 extern struct block_device *bdget(dev_t);
1049 extern int bd_acquire(struct inode *inode);
1050 extern void bd_forget(struct inode *inode);
1051 extern void bdput(struct block_device *);
1052 extern struct char_device *cdget(dev_t);
1053 extern void cdput(struct char_device *);
1054 extern int blkdev_open(struct inode *, struct file *);
1055 extern int blkdev_close(struct inode *, struct file *);
1056 extern struct file_operations def_blk_fops;
1057 extern struct address_space_operations def_blk_aops;
1058 extern struct file_operations def_fifo_fops;
1059 extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
1060 extern int blkdev_get(struct block_device *, mode_t, unsigned, int);
1061 extern int blkdev_put(struct block_device *, int);
1062
1063 /* fs/devices.c */
1064 extern const struct block_device_operations *get_blkfops(unsigned int);
1065 extern int register_chrdev(unsigned int, const char *, struct file_operations *);
1066 extern int unregister_chrdev(unsigned int, const char *);
1067 extern int chrdev_open(struct inode *, struct file *);
1068 extern const char * bdevname(kdev_t);
1069 extern const char * cdevname(kdev_t);
1070 extern const char * kdevname(kdev_t);
1071 extern void init_special_inode(struct inode *, umode_t, int);
1072
1073 /* Invalid inode operations -- fs/bad_inode.c */
1074 extern void make_bad_inode(struct inode *);
1075 extern int is_bad_inode(struct inode *);
1076
1077 extern struct file_operations read_fifo_fops;
1078 extern struct file_operations write_fifo_fops;
1079 extern struct file_operations rdwr_fifo_fops;
1080 extern struct file_operations read_pipe_fops;
1081 extern struct file_operations write_pipe_fops;
1082 extern struct file_operations rdwr_pipe_fops;
1083
1084 extern int fs_may_remount_ro(struct super_block *);
1085
1086 extern int try_to_free_buffers(struct page *, unsigned int);
1087 extern void refile_buffer(struct buffer_head * buf);
1088 extern void end_buffer_io_sync(struct buffer_head *bh, int uptodate);
1089
1090 /* reiserfs_writepage needs this */
1091 extern void set_buffer_async_io(struct buffer_head *bh) ;
1092
1093 #define BUF_CLEAN 0
1094 #define BUF_LOCKED 1 /* Buffers scheduled for write */
1095 #define BUF_DIRTY 2 /* Dirty buffers, not yet scheduled for write */
1096 #define NR_LIST 3
1097
1098 static inline void get_bh(struct buffer_head * bh)
1099 {
1100 atomic_inc(&(bh)->b_count);
1101 }
1102
1103 static inline void put_bh(struct buffer_head *bh)
1104 {
1105 smp_mb__before_atomic_dec();
1106 atomic_dec(&bh->b_count);
1107 }
1108
1109 /*
1110 * This is called by bh->b_end_io() handlers when I/O has completed.
1111 */
1112 static inline void mark_buffer_uptodate(struct buffer_head * bh, int on)
1113 {
1114 if (on)
1115 set_bit(BH_Uptodate, &bh->b_state);
1116 else
1117 clear_bit(BH_Uptodate, &bh->b_state);
1118 }
1119
1120 #define atomic_set_buffer_clean(bh) test_and_clear_bit(BH_Dirty, &(bh)->b_state)
1121
1122 static inline void __mark_buffer_clean(struct buffer_head *bh)
1123 {
1124 refile_buffer(bh);
1125 }
1126
1127 static inline void mark_buffer_clean(struct buffer_head * bh)
1128 {
1129 if (atomic_set_buffer_clean(bh))
1130 __mark_buffer_clean(bh);
1131 }
1132
1133 extern void FASTCALL(__mark_dirty(struct buffer_head *bh));
1134 extern void FASTCALL(__mark_buffer_dirty(struct buffer_head *bh));
1135 extern void FASTCALL(mark_buffer_dirty(struct buffer_head *bh));
1136 extern void FASTCALL(buffer_insert_inode_data_queue(struct buffer_head *, struct inode *));
1137
1138 #define atomic_set_buffer_dirty(bh) test_and_set_bit(BH_Dirty, &(bh)->b_state)
1139
1140 static inline void mark_buffer_async(struct buffer_head * bh, int on)
1141 {
1142 if (on)
1143 set_bit(BH_Async, &bh->b_state);
1144 else
1145 clear_bit(BH_Async, &bh->b_state);
1146 }
1147
1148 /*
1149 * If an error happens during the make_request, this function
1150 * has to be recalled. It marks the buffer as clean and not
1151 * uptodate, and it notifys the upper layer about the end
1152 * of the I/O.
1153 */
1154 static inline void buffer_IO_error(struct buffer_head * bh)
1155 {
1156 mark_buffer_clean(bh);
1157 /*
1158 * b_end_io has to clear the BH_Uptodate bitflag in the error case!
1159 */
1160 bh->b_end_io(bh, 0);
1161 }
1162
1163 extern void buffer_insert_inode_queue(struct buffer_head *, struct inode *);
1164 static inline void mark_buffer_dirty_inode(struct buffer_head *bh, struct inode *inode)
1165 {
1166 mark_buffer_dirty(bh);
1167 buffer_insert_inode_queue(bh, inode);
1168 }
1169
1170 extern void balance_dirty(void);
1171 extern int check_disk_change(kdev_t);
1172 extern int invalidate_inodes(struct super_block *);
1173 extern int invalidate_device(kdev_t, int);
1174 extern void invalidate_inode_pages(struct inode *);
1175 extern void invalidate_inode_pages2(struct address_space *);
1176 extern void invalidate_inode_buffers(struct inode *);
1177 #define invalidate_buffers(dev) __invalidate_buffers((dev), 0, 0)
1178 #define destroy_buffers(dev) __invalidate_buffers((dev), 1, 0)
1179 #define update_buffers(dev) \
1180 do { \
1181 __invalidate_buffers((dev), 0, 1); \
1182 __invalidate_buffers((dev), 0, 2); \
1183 } while (0)
1184 extern void __invalidate_buffers(kdev_t dev, int, int);
1185 extern void sync_inodes(kdev_t);
1186 extern void sync_unlocked_inodes(void);
1187 extern void write_inode_now(struct inode *, int);
1188 extern int sync_buffers(kdev_t, int);
1189 extern void sync_dev(kdev_t);
1190 extern int fsync_dev(kdev_t);
1191 extern int fsync_super(struct super_block *);
1192 extern int fsync_no_super(kdev_t);
1193 extern void sync_inodes_sb(struct super_block *);
1194 extern int osync_inode_buffers(struct inode *);
1195 extern int osync_inode_data_buffers(struct inode *);
1196 extern int fsync_inode_buffers(struct inode *);
1197 extern int fsync_inode_data_buffers(struct inode *);
1198 extern int inode_has_buffers(struct inode *);
1199 extern void filemap_fdatasync(struct address_space *);
1200 extern void filemap_fdatawait(struct address_space *);
1201 extern void sync_supers(kdev_t);
1202 extern int bmap(struct inode *, int);
1203 extern int notify_change(struct dentry *, struct iattr *);
1204 extern int permission(struct inode *, int);
1205 extern int vfs_permission(struct inode *, int);
1206 extern int get_write_access(struct inode *);
1207 extern int deny_write_access(struct file *);
1208 static inline void put_write_access(struct inode * inode)
1209 {
1210 atomic_dec(&inode->i_writecount);
1211 }
1212 static inline void allow_write_access(struct file *file)
1213 {
1214 if (file)
1215 atomic_inc(&file->f_dentry->d_inode->i_writecount);
1216 }
1217 extern int do_pipe(int *);
1218
1219 extern int open_namei(const char *, int, int, struct nameidata *);
1220
1221 extern int kernel_read(struct file *, unsigned long, char *, unsigned long);
1222 extern struct file * open_exec(const char *);
1223
1224 /* fs/dcache.c -- generic fs support functions */
1225 extern int is_subdir(struct dentry *, struct dentry *);
1226 extern ino_t find_inode_number(struct dentry *, struct qstr *);
1227
1228 /*
1229 * Kernel pointers have redundant information, so we can use a
1230 * scheme where we can return either an error code or a dentry
1231 * pointer with the same return value.
1232 *
1233 * This should be a per-architecture thing, to allow different
1234 * error and pointer decisions.
1235 */
1236 static inline void *ERR_PTR(long error)
1237 {
1238 return (void *) error;
1239 }
1240
1241 static inline long PTR_ERR(const void *ptr)
1242 {
1243 return (long) ptr;
1244 }
1245
1246 static inline long IS_ERR(const void *ptr)
1247 {
1248 return (unsigned long)ptr > (unsigned long)-1000L;
1249 }
1250
1251 /*
1252 * The bitmask for a lookup event:
1253 * - follow links at the end
1254 * - require a directory
1255 * - ending slashes ok even for nonexistent files
1256 * - internal "there are more path compnents" flag
1257 */
1258 #define LOOKUP_FOLLOW (1)
1259 #define LOOKUP_DIRECTORY (2)
1260 #define LOOKUP_CONTINUE (4)
1261 #define LOOKUP_POSITIVE (8)
1262 #define LOOKUP_PARENT (16)
1263 #define LOOKUP_NOALT (32)
1264 /*
1265 * Type of the last component on LOOKUP_PARENT
1266 */
1267 enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
1268
1269 /*
1270 * "descriptor" for what we're up to with a read for sendfile().
1271 * This allows us to use the same read code yet
1272 * have multiple different users of the data that
1273 * we read from a file.
1274 *
1275 * The simplest case just copies the data to user
1276 * mode.
1277 */
1278 typedef struct {
1279 size_t written;
1280 size_t count;
1281 char * buf;
1282 int error;
1283 } read_descriptor_t;
1284
1285 typedef int (*read_actor_t)(read_descriptor_t *, struct page *, unsigned long, unsigned long);
1286
1287 /* needed for stackable file system support */
1288 extern loff_t default_llseek(struct file *file, loff_t offset, int origin);
1289
1290 extern int __user_walk(const char *, unsigned, struct nameidata *);
1291 extern int path_init(const char *, unsigned, struct nameidata *);
1292 extern int path_walk(const char *, struct nameidata *);
1293 extern void path_release(struct nameidata *);
1294 extern int follow_down(struct vfsmount **, struct dentry **);
1295 extern int follow_up(struct vfsmount **, struct dentry **);
1296 extern struct dentry * lookup_one_len(const char *, struct dentry *, int);
1297 extern struct dentry * lookup_hash(struct qstr *, struct dentry *);
1298 #define user_path_walk(name,nd) __user_walk(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, nd)
1299 #define user_path_walk_link(name,nd) __user_walk(name, LOOKUP_POSITIVE, nd)
1300
1301 extern void iput(struct inode *);
1302 extern void force_delete(struct inode *);
1303 extern struct inode * igrab(struct inode *);
1304 extern ino_t iunique(struct super_block *, ino_t);
1305
1306 typedef int (*find_inode_t)(struct inode *, unsigned long, void *);
1307 extern struct inode * iget4(struct super_block *, unsigned long, find_inode_t, void *);
1308 static inline struct inode *iget(struct super_block *sb, unsigned long ino)
1309 {
1310 return iget4(sb, ino, NULL, NULL);
1311 }
1312
1313 extern void clear_inode(struct inode *);
1314 extern struct inode * get_empty_inode(void);
1315 static inline struct inode * new_inode(struct super_block *sb)
1316 {
1317 struct inode *inode = get_empty_inode();
1318 if (inode) {
1319 inode->i_sb = sb;
1320 inode->i_dev = sb->s_dev;
1321 }
1322 return inode;
1323 }
1324 extern void remove_suid(struct inode *inode);
1325
1326 extern void insert_inode_hash(struct inode *);
1327 extern void remove_inode_hash(struct inode *);
1328 extern struct file * get_empty_filp(void);
1329 extern void file_move(struct file *f, struct list_head *list);
1330 extern struct buffer_head * get_hash_table(kdev_t, int, int);
1331 extern struct buffer_head * getblk(kdev_t, int, int);
1332 extern void ll_rw_block(int, int, struct buffer_head * bh[]);
1333 extern void submit_bh(int, struct buffer_head *);
1334 extern int is_read_only(kdev_t);
1335 extern void __brelse(struct buffer_head *);
1336 static inline void brelse(struct buffer_head *buf)
1337 {
1338 if (buf)
1339 __brelse(buf);
1340 }
1341 extern void __bforget(struct buffer_head *);
1342 static inline void bforget(struct buffer_head *buf)
1343 {
1344 if (buf)
1345 __bforget(buf);
1346 }
1347 extern void set_blocksize(kdev_t, int);
1348 extern struct buffer_head * bread(kdev_t, int, int);
1349 extern void wakeup_bdflush(void);
1350
1351 extern int brw_page(int, struct page *, kdev_t, int [], int);
1352
1353 typedef int (get_block_t)(struct inode*,long,struct buffer_head*,int);
1354
1355 /* Generic buffer handling for block filesystems.. */
1356 extern int discard_bh_page(struct page *, unsigned long, int);
1357 #define block_flushpage(page, offset) discard_bh_page(page, offset, 1)
1358 #define block_invalidate_page(page) discard_bh_page(page, 0, 0)
1359 extern int block_symlink(struct inode *, const char *, int);
1360 extern int block_write_full_page(struct page*, get_block_t*);
1361 extern int block_read_full_page(struct page*, get_block_t*);
1362 extern int block_prepare_write(struct page*, unsigned, unsigned, get_block_t*);
1363 extern int cont_prepare_write(struct page*, unsigned, unsigned, get_block_t*,
1364 unsigned long *);
1365 extern int block_sync_page(struct page *);
1366
1367 int generic_block_bmap(struct address_space *, long, get_block_t *);
1368 int generic_commit_write(struct file *, struct page *, unsigned, unsigned);
1369 int block_truncate_page(struct address_space *, loff_t, get_block_t *);
1370 extern int generic_direct_IO(int, struct inode *, struct kiobuf *, unsigned long, int, get_block_t *);
1371 extern void create_empty_buffers(struct page *, kdev_t, unsigned long);
1372
1373 extern int waitfor_one_page(struct page*);
1374 extern int generic_file_mmap(struct file *, struct vm_area_struct *);
1375 extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size);
1376 extern ssize_t generic_file_read(struct file *, char *, size_t, loff_t *);
1377 extern ssize_t generic_file_write(struct file *, const char *, size_t, loff_t *);
1378 extern void do_generic_file_read(struct file *, loff_t *, read_descriptor_t *, read_actor_t);
1379 extern loff_t no_llseek(struct file *file, loff_t offset, int origin);
1380 extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin);
1381 extern ssize_t generic_read_dir(struct file *, char *, size_t, loff_t *);
1382 extern int generic_file_open(struct inode * inode, struct file * filp);
1383
1384 extern struct file_operations generic_ro_fops;
1385
1386 extern int vfs_readlink(struct dentry *, char *, int, const char *);
1387 extern int vfs_follow_link(struct nameidata *, const char *);
1388 extern int page_readlink(struct dentry *, char *, int);
1389 extern int page_follow_link(struct dentry *, struct nameidata *);
1390 extern struct inode_operations page_symlink_inode_operations;
1391
1392 extern int vfs_readdir(struct file *, filldir_t, void *);
1393 extern int dcache_readdir(struct file *, void *, filldir_t);
1394
1395 extern struct file_system_type *get_fs_type(const char *name);
1396 extern struct super_block *get_super(kdev_t);
1397 extern void drop_super(struct super_block *sb);
1398 static inline int is_mounted(kdev_t dev)
1399 {
1400 struct super_block *sb = get_super(dev);
1401 if (sb) {
1402 drop_super(sb);
1403 return 1;
1404 }
1405 return 0;
1406 }
1407 unsigned long generate_cluster(kdev_t, int b[], int);
1408 unsigned long generate_cluster_swab32(kdev_t, int b[], int);
1409 extern kdev_t ROOT_DEV;
1410 extern char root_device_name[];
1411
1412
1413 extern void show_buffers(void);
1414 extern void mount_root(void);
1415
1416 #ifdef CONFIG_BLK_DEV_INITRD
1417 extern kdev_t real_root_dev;
1418 extern int change_root(kdev_t, const char *);
1419 #endif
1420
1421 extern ssize_t char_read(struct file *, char *, size_t, loff_t *);
1422 extern ssize_t block_read(struct file *, char *, size_t, loff_t *);
1423 extern int read_ahead[];
1424
1425 extern ssize_t char_write(struct file *, const char *, size_t, loff_t *);
1426 extern ssize_t block_write(struct file *, const char *, size_t, loff_t *);
1427
1428 extern int file_fsync(struct file *, struct dentry *, int);
1429 extern int generic_buffer_fdatasync(struct inode *inode, unsigned long start_idx, unsigned long end_idx);
1430 extern int generic_osync_inode(struct inode *, int);
1431 #define OSYNC_METADATA (1<<0)
1432 #define OSYNC_DATA (1<<1)
1433 #define OSYNC_INODE (1<<2)
1434
1435 extern int inode_change_ok(struct inode *, struct iattr *);
1436 extern int inode_setattr(struct inode *, struct iattr *);
1437
1438 /*
1439 * Common dentry functions for inclusion in the VFS
1440 * or in other stackable file systems. Some of these
1441 * functions were in linux/fs/ C (VFS) files.
1442 *
1443 */
1444
1445 /*
1446 * Locking the parent is needed to:
1447 * - serialize directory operations
1448 * - make sure the parent doesn't change from
1449 * under us in the middle of an operation.
1450 *
1451 * NOTE! Right now we'd rather use a "struct inode"
1452 * for this, but as I expect things to move toward
1453 * using dentries instead for most things it is
1454 * probably better to start with the conceptually
1455 * better interface of relying on a path of dentries.
1456 */
1457 static inline struct dentry *lock_parent(struct dentry *dentry)
1458 {
1459 struct dentry *dir = dget(dentry->d_parent);
1460
1461 down(&dir->d_inode->i_sem);
1462 return dir;
1463 }
1464
1465 static inline struct dentry *get_parent(struct dentry *dentry)
1466 {
1467 return dget(dentry->d_parent);
1468 }
1469
1470 static inline void unlock_dir(struct dentry *dir)
1471 {
1472 up(&dir->d_inode->i_sem);
1473 dput(dir);
1474 }
1475
1476 /*
1477 * Whee.. Deadlock country. Happily there are only two VFS
1478 * operations that does this..
1479 */
1480 static inline void double_down(struct semaphore *s1, struct semaphore *s2)
1481 {
1482 if (s1 != s2) {
1483 if ((unsigned long) s1 < (unsigned long) s2) {
1484 struct semaphore *tmp = s2;
1485 s2 = s1; s1 = tmp;
1486 }
1487 down(s1);
1488 }
1489 down(s2);
1490 }
1491
1492 /*
1493 * Ewwwwwwww... _triple_ lock. We are guaranteed that the 3rd argument is
1494 * not equal to 1st and not equal to 2nd - the first case (target is parent of
1495 * source) would be already caught, the second is plain impossible (target is
1496 * its own parent and that case would be caught even earlier). Very messy.
1497 * I _think_ that it works, but no warranties - please, look it through.
1498 * Pox on bloody lusers who mandated overwriting rename() for directories...
1499 */
1500
1501 static inline void triple_down(struct semaphore *s1,
1502 struct semaphore *s2,
1503 struct semaphore *s3)
1504 {
1505 if (s1 != s2) {
1506 if ((unsigned long) s1 < (unsigned long) s2) {
1507 if ((unsigned long) s1 < (unsigned long) s3) {
1508 struct semaphore *tmp = s3;
1509 s3 = s1; s1 = tmp;
1510 }
1511 if ((unsigned long) s1 < (unsigned long) s2) {
1512 struct semaphore *tmp = s2;
1513 s2 = s1; s1 = tmp;
1514 }
1515 } else {
1516 if ((unsigned long) s1 < (unsigned long) s3) {
1517 struct semaphore *tmp = s3;
1518 s3 = s1; s1 = tmp;
1519 }
1520 if ((unsigned long) s2 < (unsigned long) s3) {
1521 struct semaphore *tmp = s3;
1522 s3 = s2; s2 = tmp;
1523 }
1524 }
1525 down(s1);
1526 } else if ((unsigned long) s2 < (unsigned long) s3) {
1527 struct semaphore *tmp = s3;
1528 s3 = s2; s2 = tmp;
1529 }
1530 down(s2);
1531 down(s3);
1532 }
1533
1534 static inline void double_up(struct semaphore *s1, struct semaphore *s2)
1535 {
1536 up(s1);
1537 if (s1 != s2)
1538 up(s2);
1539 }
1540
1541 static inline void triple_up(struct semaphore *s1,
1542 struct semaphore *s2,
1543 struct semaphore *s3)
1544 {
1545 up(s1);
1546 if (s1 != s2)
1547 up(s2);
1548 up(s3);
1549 }
1550
1551 static inline void double_lock(struct dentry *d1, struct dentry *d2)
1552 {
1553 double_down(&d1->d_inode->i_sem, &d2->d_inode->i_sem);
1554 }
1555
1556 static inline void double_unlock(struct dentry *d1, struct dentry *d2)
1557 {
1558 double_up(&d1->d_inode->i_sem,&d2->d_inode->i_sem);
1559 dput(d1);
1560 dput(d2);
1561 }
1562
1563 #endif /* __KERNEL__ */
1564
1565 #endif /* _LINUX_FS_H */
1566