Merge to Fedora kernel-2.6.7-1.494 and VServer 1.9.1.12. Fix some previous merge...
[linux-2.6.git] / 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/kdev_t.h>
15 #include <linux/ioctl.h>
16 #include <linux/dcache.h>
17 #include <linux/stat.h>
18 #include <linux/cache.h>
19 #include <linux/prio_tree.h>
20 #include <linux/kobject.h>
21 #include <asm/atomic.h>
22
23 struct iovec;
24 struct nameidata;
25 struct pipe_inode_info;
26 struct poll_table_struct;
27 struct kstatfs;
28 struct vm_area_struct;
29 struct vfsmount;
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 /* And dynamically-tunable limits and defaults: */
50 struct files_stat_struct {
51         int nr_files;           /* read only */
52         int nr_free_files;      /* read only */
53         int max_files;          /* tunable */
54 };
55 extern struct files_stat_struct files_stat;
56
57 struct inodes_stat_t {
58         int nr_inodes;
59         int nr_unused;
60         int dummy[5];
61 };
62 extern struct inodes_stat_t inodes_stat;
63
64 extern int leases_enable, dir_notify_enable, lease_break_time;
65
66 #define NR_FILE  8192   /* this can well be larger on a larger system */
67 #define NR_RESERVED_FILES 10 /* reserved for root */
68 #define NR_SUPER 256
69
70 #define MAY_EXEC 1
71 #define MAY_WRITE 2
72 #define MAY_READ 4
73 #define MAY_APPEND 8
74
75 #define FMODE_READ 1
76 #define FMODE_WRITE 2
77
78 #define RW_MASK         1
79 #define RWA_MASK        2
80 #define READ 0
81 #define WRITE 1
82 #define READA 2         /* read-ahead  - don't block if no resources */
83 #define SPECIAL 4       /* For non-blockdevice requests in request queue */
84 #define READ_SYNC       (READ | (1 << BIO_RW_SYNC))
85 #define WRITE_SYNC      (WRITE | (1 << BIO_RW_SYNC))
86
87 #define SEL_IN          1
88 #define SEL_OUT         2
89 #define SEL_EX          4
90
91 /* public flags for file_system_type */
92 #define FS_REQUIRES_DEV 1 
93 #define FS_BINARY_MOUNTDATA 2
94 #define FS_REVAL_DOT    16384   /* Check the paths ".", ".." for staleness */
95 #define FS_ODD_RENAME   32768   /* Temporary stuff; will go away as soon
96                                   * as nfs_rename() will be cleaned up
97                                   */
98 /*
99  * These are the fs-independent mount-flags: up to 32 flags are supported
100  */
101 #define MS_RDONLY        1      /* Mount read-only */
102 #define MS_NOSUID        2      /* Ignore suid and sgid bits */
103 #define MS_NODEV         4      /* Disallow access to device special files */
104 #define MS_NOEXEC        8      /* Disallow program execution */
105 #define MS_SYNCHRONOUS  16      /* Writes are synced at once */
106 #define MS_REMOUNT      32      /* Alter flags of a mounted FS */
107 #define MS_MANDLOCK     64      /* Allow mandatory locks on an FS */
108 #define MS_DIRSYNC      128     /* Directory modifications are synchronous */
109 #define MS_NOATIME      1024    /* Do not update access times. */
110 #define MS_NODIRATIME   2048    /* Do not update directory access times */
111 #define MS_BIND         4096
112 #define MS_MOVE         8192
113 #define MS_REC          16384
114 #define MS_VERBOSE      32768
115 #define MS_POSIXACL     (1<<16) /* VFS does not apply the umask */
116 #define MS_ONE_SECOND   (1<<17) /* fs has 1 sec a/m/ctime resolution */
117 #define MS_TAGXID       (1<<24) /* tag inodes with context information */
118 #define MS_ACTIVE       (1<<30)
119 #define MS_NOUSER       (1<<31)
120
121 /*
122  * Superblock flags that can be altered by MS_REMOUNT
123  */
124 #define MS_RMT_MASK     (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME|\
125                          MS_NODIRATIME)
126
127 /*
128  * Old magic mount flag and mask
129  */
130 #define MS_MGC_VAL 0xC0ED0000
131 #define MS_MGC_MSK 0xffff0000
132
133 /* Inode flags - they have nothing to superblock flags now */
134
135 #define S_SYNC          1       /* Writes are synced at once */
136 #define S_NOATIME       2       /* Do not update access times */
137 #define S_APPEND        4       /* Append-only file */
138 #define S_IMMUTABLE     8       /* Immutable file */
139 #define S_DEAD          16      /* removed, but still open directory */
140 #define S_NOQUOTA       32      /* Inode is not counted to quota */
141 #define S_DIRSYNC       64      /* Directory modifications are synchronous */
142 #define S_NOCMTIME      128     /* Do not update file c/mtime */
143 #define S_SWAPFILE      256     /* Do not truncate: swapon got its bmaps */
144 #define S_BARRIER       512     /* Barrier for chroot() */
145 #define S_IUNLINK       1024    /* Immutable unlink */
146
147 /*
148  * Note that nosuid etc flags are inode-specific: setting some file-system
149  * flags just means all the inodes inherit those flags by default. It might be
150  * possible to override it selectively if you really wanted to with some
151  * ioctl() that is not currently implemented.
152  *
153  * Exception: MS_RDONLY is always applied to the entire file system.
154  *
155  * Unfortunately, it is possible to change a filesystems flags with it mounted
156  * with files in use.  This means that all of the inodes will not have their
157  * i_flags updated.  Hence, i_flags no longer inherit the superblock mount
158  * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org
159  */
160 #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
161
162 #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
163 #define IS_SYNC(inode)          (__IS_FLG(inode, MS_SYNCHRONOUS) || \
164                                         ((inode)->i_flags & S_SYNC))
165 #define IS_DIRSYNC(inode)       (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
166                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
167 #define IS_MANDLOCK(inode)      __IS_FLG(inode, MS_MANDLOCK)
168
169 #define IS_NOQUOTA(inode)       ((inode)->i_flags & S_NOQUOTA)
170 #define IS_APPEND(inode)        ((inode)->i_flags & S_APPEND)
171 #define IS_IMMUTABLE(inode)     ((inode)->i_flags & S_IMMUTABLE)
172 #define IS_IUNLINK(inode)       ((inode)->i_flags & S_IUNLINK)
173 #define IS_IXORUNLINK(inode)    ((IS_IUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
174 #define IS_NOATIME(inode)       (__IS_FLG(inode, MS_NOATIME) || ((inode)->i_flags & S_NOATIME))
175 #define IS_NODIRATIME(inode)    __IS_FLG(inode, MS_NODIRATIME)
176 #define IS_POSIXACL(inode)      __IS_FLG(inode, MS_POSIXACL)
177 #define IS_ONE_SECOND(inode)    __IS_FLG(inode, MS_ONE_SECOND)
178
179 #define IS_BARRIER(inode)       (S_ISDIR((inode)->i_mode) && ((inode)->i_flags & S_BARRIER))
180 #define IS_DEADDIR(inode)       ((inode)->i_flags & S_DEAD)
181 #define IS_NOCMTIME(inode)      ((inode)->i_flags & S_NOCMTIME)
182 #define IS_SWAPFILE(inode)      ((inode)->i_flags & S_SWAPFILE)
183
184 /* the read-only stuff doesn't really belong here, but any other place is
185    probably as bad and I don't want to create yet another include file. */
186
187 #define BLKROSET   _IO(0x12,93) /* set device read-only (0 = read-write) */
188 #define BLKROGET   _IO(0x12,94) /* get read-only status (0 = read_write) */
189 #define BLKRRPART  _IO(0x12,95) /* re-read partition table */
190 #define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */
191 #define BLKFLSBUF  _IO(0x12,97) /* flush buffer cache */
192 #define BLKRASET   _IO(0x12,98) /* set read ahead for block device */
193 #define BLKRAGET   _IO(0x12,99) /* get current read ahead setting */
194 #define BLKFRASET  _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
195 #define BLKFRAGET  _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
196 #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
197 #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
198 #define BLKSSZGET  _IO(0x12,104)/* get block device sector size */
199 #if 0
200 #define BLKPG      _IO(0x12,105)/* See blkpg.h */
201
202 /* Some people are morons.  Do not use sizeof! */
203
204 #define BLKELVGET  _IOR(0x12,106,size_t)/* elevator get */
205 #define BLKELVSET  _IOW(0x12,107,size_t)/* elevator set */
206 /* This was here just to show that the number is taken -
207    probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */
208 #endif
209 /* A jump here: 108-111 have been used for various private purposes. */
210 #define BLKBSZGET  _IOR(0x12,112,size_t)
211 #define BLKBSZSET  _IOW(0x12,113,size_t)
212 #define BLKGETSIZE64 _IOR(0x12,114,size_t)      /* return device size in bytes (u64 *arg) */
213
214 #define BMAP_IOCTL 1            /* obsolete - kept for compatibility */
215 #define FIBMAP     _IO(0x00,1)  /* bmap access */
216 #define FIGETBSZ   _IO(0x00,2)  /* get the block size used for bmap */
217
218 #ifdef __KERNEL__
219
220 #include <linux/list.h>
221 #include <linux/radix-tree.h>
222 #include <linux/audit.h>
223 #include <linux/init.h>
224 #include <asm/semaphore.h>
225 #include <asm/byteorder.h>
226
227 /* Used to be a macro which just called the function, now just a function */
228 extern void update_atime (struct inode *);
229
230 extern void __init inode_init(unsigned long);
231 extern void __init inode_init_early(void);
232 extern void __init mnt_init(unsigned long);
233 extern void __init files_init(unsigned long);
234
235 struct buffer_head;
236 typedef int (get_block_t)(struct inode *inode, sector_t iblock,
237                         struct buffer_head *bh_result, int create);
238 typedef int (get_blocks_t)(struct inode *inode, sector_t iblock,
239                         unsigned long max_blocks,
240                         struct buffer_head *bh_result, int create);
241 typedef void (dio_iodone_t)(struct inode *inode, loff_t offset,
242                         ssize_t bytes, void *private);
243
244 /*
245  * Attribute flags.  These should be or-ed together to figure out what
246  * has been changed!
247  */
248 #define ATTR_MODE       1
249 #define ATTR_UID        2
250 #define ATTR_GID        4
251 #define ATTR_SIZE       8
252 #define ATTR_ATIME      16
253 #define ATTR_MTIME      32
254 #define ATTR_CTIME      64
255 #define ATTR_ATIME_SET  128
256 #define ATTR_MTIME_SET  256
257 #define ATTR_FORCE      512     /* Not a change, but a change it */
258 #define ATTR_ATTR_FLAG  1024
259 #define ATTR_KILL_SUID  2048
260 #define ATTR_KILL_SGID  4096
261 #define ATTR_XID        8192
262
263 /*
264  * This is the Inode Attributes structure, used for notify_change().  It
265  * uses the above definitions as flags, to know which values have changed.
266  * Also, in this manner, a Filesystem can look at only the values it cares
267  * about.  Basically, these are the attributes that the VFS layer can
268  * request to change from the FS layer.
269  *
270  * Derek Atkins <warlord@MIT.EDU> 94-10-20
271  */
272 struct iattr {
273         unsigned int    ia_valid;
274         umode_t         ia_mode;
275         uid_t           ia_uid;
276         gid_t           ia_gid;
277         xid_t           ia_xid;
278         loff_t          ia_size;
279         struct timespec ia_atime;
280         struct timespec ia_mtime;
281         struct timespec ia_ctime;
282         unsigned int    ia_attr_flags;
283 };
284
285 /*
286  * This is the inode attributes flag definitions
287  */
288 #define ATTR_FLAG_SYNCRONOUS    1       /* Syncronous write */
289 #define ATTR_FLAG_NOATIME       2       /* Don't update atime */
290 #define ATTR_FLAG_APPEND        4       /* Append-only file */
291 #define ATTR_FLAG_IMMUTABLE     8       /* Immutable file */
292 #define ATTR_FLAG_NODIRATIME    16      /* Don't update atime for directory */
293
294 #define ATTR_FLAG_BARRIER       512     /* Barrier for chroot() */
295 #define ATTR_FLAG_IUNLINK       1024    /* Immutable unlink */
296
297 /*
298  * Includes for diskquotas.
299  */
300 #include <linux/quota.h>
301
302 /*
303  * oh the beauties of C type declarations.
304  */
305 struct page;
306 struct address_space;
307 struct writeback_control;
308 struct kiocb;
309
310 struct address_space_operations {
311         int (*writepage)(struct page *page, struct writeback_control *wbc);
312         int (*readpage)(struct file *, struct page *);
313         int (*sync_page)(struct page *);
314
315         /* Write back some dirty pages from this mapping. */
316         int (*writepages)(struct address_space *, struct writeback_control *);
317
318         /* Set a page dirty */
319         int (*set_page_dirty)(struct page *page);
320
321         int (*readpages)(struct file *filp, struct address_space *mapping,
322                         struct list_head *pages, unsigned nr_pages);
323
324         /*
325          * ext3 requires that a successful prepare_write() call be followed
326          * by a commit_write() call - they must be balanced
327          */
328         int (*prepare_write)(struct file *, struct page *, unsigned, unsigned);
329         int (*commit_write)(struct file *, struct page *, unsigned, unsigned);
330         /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
331         sector_t (*bmap)(struct address_space *, sector_t);
332         int (*invalidatepage) (struct page *, unsigned long);
333         int (*releasepage) (struct page *, int);
334         ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
335                         loff_t offset, unsigned long nr_segs);
336 };
337
338 struct backing_dev_info;
339 struct address_space {
340         struct inode            *host;          /* owner: inode, block_device */
341         struct radix_tree_root  page_tree;      /* radix tree of all pages */
342         spinlock_t              tree_lock;      /* and spinlock protecting it */
343         unsigned long           nrpages;        /* number of total pages */
344         pgoff_t                 writeback_index;/* writeback starts here */
345         struct address_space_operations *a_ops; /* methods */
346         struct prio_tree_root   i_mmap;         /* tree of private mappings */
347         unsigned int            i_mmap_writable;/* count VM_SHARED mappings */
348         struct list_head        i_mmap_nonlinear;/*list VM_NONLINEAR mappings */
349         spinlock_t              i_mmap_lock;    /* protect tree, count, list */
350         atomic_t                truncate_count; /* Cover race condition with truncate */
351         unsigned long           flags;          /* error bits/gfp mask */
352         struct backing_dev_info *backing_dev_info; /* device readahead, etc */
353         spinlock_t              private_lock;   /* for use by the address_space */
354         struct list_head        private_list;   /* ditto */
355         struct address_space    *assoc_mapping; /* ditto */
356 };
357
358 struct block_device {
359         dev_t                   bd_dev;  /* not a kdev_t - it's a search key */
360         struct inode *          bd_inode;       /* will die */
361         int                     bd_openers;
362         struct semaphore        bd_sem; /* open/close mutex */
363         struct semaphore        bd_mount_sem;   /* mount mutex */
364         struct list_head        bd_inodes;
365         void *                  bd_holder;
366         int                     bd_holders;
367         struct block_device *   bd_contains;
368         unsigned                bd_block_size;
369         struct hd_struct *      bd_part;
370         unsigned                bd_part_count;
371         int                     bd_invalidated;
372         struct gendisk *        bd_disk;
373         struct list_head        bd_list;
374         struct backing_dev_info *bd_inode_backing_dev_info;
375         /*
376          * Private data.  You must have bd_claim'ed the block_device
377          * to use this.  NOTE:  bd_claim allows an owner to claim
378          * the same device multiple times, the owner must take special
379          * care to not mess up bd_private for that case.
380          */
381         unsigned long           bd_private;
382 };
383
384 /*
385  * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
386  * radix trees
387  */
388 #define PAGECACHE_TAG_DIRTY     0
389 #define PAGECACHE_TAG_WRITEBACK 1
390
391 int mapping_tagged(struct address_space *mapping, int tag);
392
393 /*
394  * Might pages of this file be mapped into userspace?
395  */
396 static inline int mapping_mapped(struct address_space *mapping)
397 {
398         return  !prio_tree_empty(&mapping->i_mmap) ||
399                 !list_empty(&mapping->i_mmap_nonlinear);
400 }
401
402 /*
403  * Might pages of this file have been modified in userspace?
404  * Note that i_mmap_writable counts all VM_SHARED vmas: do_mmap_pgoff
405  * marks vma as VM_SHARED if it is shared, and the file was opened for
406  * writing i.e. vma may be mprotected writable even if now readonly.
407  */
408 static inline int mapping_writably_mapped(struct address_space *mapping)
409 {
410         return mapping->i_mmap_writable != 0;
411 }
412
413 /*
414  * Use sequence counter to get consistent i_size on 32-bit processors.
415  */
416 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
417 #include <linux/seqlock.h>
418 #define __NEED_I_SIZE_ORDERED
419 #define i_size_ordered_init(inode) seqcount_init(&inode->i_size_seqcount)
420 #else
421 #define i_size_ordered_init(inode) do { } while (0)
422 #endif
423
424 struct inode {
425         struct hlist_node       i_hash;
426         struct list_head        i_list;
427         struct list_head        i_dentry;
428         unsigned long           i_ino;
429         atomic_t                i_count;
430         umode_t                 i_mode;
431         unsigned int            i_nlink;
432         uid_t                   i_uid;
433         gid_t                   i_gid;
434         xid_t                   i_xid;
435         dev_t                   i_rdev;
436         loff_t                  i_size;
437         struct timespec         i_atime;
438         struct timespec         i_mtime;
439         struct timespec         i_ctime;
440         unsigned int            i_blkbits;
441         unsigned long           i_blksize;
442         unsigned long           i_version;
443         unsigned long           i_blocks;
444         unsigned short          i_bytes;
445         spinlock_t              i_lock; /* i_blocks, i_bytes, maybe i_size */
446         struct semaphore        i_sem;
447         struct rw_semaphore     i_alloc_sem;
448         struct inode_operations *i_op;
449         struct file_operations  *i_fop; /* former ->i_op->default_file_ops */
450         struct super_block      *i_sb;
451         struct file_lock        *i_flock;
452         struct address_space    *i_mapping;
453         struct address_space    i_data;
454 #ifdef CONFIG_QUOTA
455         struct dquot            *i_dquot[MAXQUOTAS];
456 #endif
457         /* These three should probably be a union */
458         struct list_head        i_devices;
459         struct pipe_inode_info  *i_pipe;
460         struct block_device     *i_bdev;
461         struct cdev             *i_cdev;
462         int                     i_cindex;
463
464         unsigned long           i_dnotify_mask; /* Directory notify events */
465         struct dnotify_struct   *i_dnotify; /* for directory notifications */
466
467         unsigned long           i_state;
468         unsigned long           dirtied_when;   /* jiffies of first dirtying */
469
470         unsigned int            i_flags;
471         unsigned char           i_sock;
472
473         atomic_t                i_writecount;
474         void                    *i_security;
475         __u32                   i_generation;
476         union {
477                 void            *generic_ip;
478         } u;
479 #ifdef __NEED_I_SIZE_ORDERED
480         seqcount_t              i_size_seqcount;
481 #endif
482 };
483
484 /*
485  * NOTE: in a 32bit arch with a preemptable kernel and
486  * an UP compile the i_size_read/write must be atomic
487  * with respect to the local cpu (unlike with preempt disabled),
488  * but they don't need to be atomic with respect to other cpus like in
489  * true SMP (so they need either to either locally disable irq around
490  * the read or for example on x86 they can be still implemented as a
491  * cmpxchg8b without the need of the lock prefix). For SMP compiles
492  * and 64bit archs it makes no difference if preempt is enabled or not.
493  */
494 static inline loff_t i_size_read(struct inode *inode)
495 {
496 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
497         loff_t i_size;
498         unsigned int seq;
499
500         do {
501                 seq = read_seqcount_begin(&inode->i_size_seqcount);
502                 i_size = inode->i_size;
503         } while (read_seqcount_retry(&inode->i_size_seqcount, seq));
504         return i_size;
505 #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
506         loff_t i_size;
507
508         preempt_disable();
509         i_size = inode->i_size;
510         preempt_enable();
511         return i_size;
512 #else
513         return inode->i_size;
514 #endif
515 }
516
517
518 static inline void i_size_write(struct inode *inode, loff_t i_size)
519 {
520 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
521         write_seqcount_begin(&inode->i_size_seqcount);
522         inode->i_size = i_size;
523         write_seqcount_end(&inode->i_size_seqcount);
524 #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
525         preempt_disable();
526         inode->i_size = i_size;
527         preempt_enable();
528 #else
529         inode->i_size = i_size;
530 #endif
531 }
532
533 static inline unsigned iminor(struct inode *inode)
534 {
535         return MINOR(inode->i_rdev);
536 }
537
538 static inline unsigned imajor(struct inode *inode)
539 {
540         return MAJOR(inode->i_rdev);
541 }
542
543 extern struct block_device *I_BDEV(struct inode *inode);
544
545 struct fown_struct {
546         rwlock_t lock;          /* protects pid, uid, euid fields */
547         int pid;                /* pid or -pgrp where SIGIO should be sent */
548         uid_t uid, euid;        /* uid/euid of process setting the owner */
549         void *security;
550         int signum;             /* posix.1b rt signal to be delivered on IO */
551 };
552
553 /*
554  * Track a single file's readahead state
555  */
556 struct file_ra_state {
557         unsigned long start;            /* Current window */
558         unsigned long size;
559         unsigned long next_size;        /* Next window size */
560         unsigned long prev_page;        /* Cache last read() position */
561         unsigned long ahead_start;      /* Ahead window */
562         unsigned long ahead_size;
563         unsigned long serial_cnt;       /* measure of sequentiality */
564         unsigned long average;          /* another measure of sequentiality */
565         unsigned long ra_pages;         /* Maximum readahead window */
566         unsigned long mmap_hit;         /* Cache hit stat for mmap accesses */
567         unsigned long mmap_miss;        /* Cache miss stat for mmap accesses */
568 };
569
570 struct file {
571         struct list_head        f_list;
572         struct dentry           *f_dentry;
573         struct vfsmount         *f_vfsmnt;
574         struct file_operations  *f_op;
575         atomic_t                f_count;
576         unsigned int            f_flags;
577         mode_t                  f_mode;
578         int                     f_error;
579         loff_t                  f_pos;
580         struct fown_struct      f_owner;
581         unsigned int            f_uid, f_gid;
582         struct file_ra_state    f_ra;
583
584         unsigned long           f_version;
585         void                    *f_security;
586
587         /* needed for tty driver, and maybe others */
588         void                    *private_data;
589
590 #ifdef CONFIG_EPOLL
591         /* Used by fs/eventpoll.c to link all the hooks to this file */
592         struct list_head        f_ep_links;
593         spinlock_t              f_ep_lock;
594 #endif /* #ifdef CONFIG_EPOLL */
595         struct address_space    *f_mapping;
596 };
597 extern spinlock_t files_lock;
598 #define file_list_lock() spin_lock(&files_lock);
599 #define file_list_unlock() spin_unlock(&files_lock);
600
601 #define get_file(x)     atomic_inc(&(x)->f_count)
602 #define file_count(x)   atomic_read(&(x)->f_count)
603
604 /* Initialize and open a private file and allocate its security structure. */
605 extern int open_private_file(struct file *, struct dentry *, int);
606 /* Release a private file and free its security structure. */
607 extern void close_private_file(struct file *file);
608
609 #define MAX_NON_LFS     ((1UL<<31) - 1)
610
611 /* Page cache limit. The filesystems should put that into their s_maxbytes 
612    limits, otherwise bad things can happen in VM. */ 
613 #if BITS_PER_LONG==32
614 #define MAX_LFS_FILESIZE        (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1) 
615 #elif BITS_PER_LONG==64
616 #define MAX_LFS_FILESIZE        0x7fffffffffffffffUL
617 #endif
618
619 #define FL_POSIX        1
620 #define FL_FLOCK        2
621 #define FL_ACCESS       8       /* not trying to lock, just looking */
622 #define FL_LOCKD        16      /* lock held by rpc.lockd */
623 #define FL_LEASE        32      /* lease held on this file */
624 #define FL_SLEEP        128     /* A blocking lock */
625
626 /*
627  * The POSIX file lock owner is determined by
628  * the "struct files_struct" in the thread group
629  * (or NULL for no owner - BSD locks).
630  *
631  * Lockd stuffs a "host" pointer into this.
632  */
633 typedef struct files_struct *fl_owner_t;
634
635 /* that will die - we need it for nfs_lock_info */
636 #include <linux/nfs_fs_i.h>
637
638 struct file_lock {
639         struct file_lock *fl_next;      /* singly linked list for this inode  */
640         struct list_head fl_link;       /* doubly linked list of all locks */
641         struct list_head fl_block;      /* circular list of blocked processes */
642         fl_owner_t fl_owner;
643         unsigned int fl_pid;
644         wait_queue_head_t fl_wait;
645         struct file *fl_file;
646         unsigned char fl_flags;
647         unsigned char fl_type;
648         loff_t fl_start;
649         loff_t fl_end;
650
651         void (*fl_notify)(struct file_lock *);  /* unblock callback */
652         void (*fl_insert)(struct file_lock *);  /* lock insertion callback */
653         void (*fl_remove)(struct file_lock *);  /* lock removal callback */
654
655         struct fasync_struct *  fl_fasync; /* for lease break notifications */
656         unsigned long fl_break_time;    /* for nonblocking lease breaks */
657
658         union {
659                 struct nfs_lock_info    nfs_fl;
660         } fl_u;
661 };
662
663 /* The following constant reflects the upper bound of the file/locking space */
664 #ifndef OFFSET_MAX
665 #define INT_LIMIT(x)    (~((x)1 << (sizeof(x)*8 - 1)))
666 #define OFFSET_MAX      INT_LIMIT(loff_t)
667 #define OFFT_OFFSET_MAX INT_LIMIT(off_t)
668 #endif
669
670 extern struct list_head file_lock_list;
671
672 #include <linux/fcntl.h>
673
674 extern long generic_file_fcntl(int fd, unsigned int cmd,
675                                 unsigned long arg, struct file *filp);
676
677 extern int fcntl_getlk(struct file *, struct flock __user *);
678 extern int fcntl_setlk(struct file *, unsigned int, struct flock __user *);
679
680 #if BITS_PER_LONG == 32
681 extern int fcntl_getlk64(struct file *, struct flock64 __user *);
682 extern int fcntl_setlk64(struct file *, unsigned int, struct flock64 __user *);
683 #endif
684
685 extern void send_sigio(struct fown_struct *fown, int fd, int band);
686 extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
687 extern int fcntl_getlease(struct file *filp);
688
689 /* fs/locks.c */
690 extern void locks_init_lock(struct file_lock *);
691 extern void locks_copy_lock(struct file_lock *, struct file_lock *);
692 extern void locks_remove_posix(struct file *, fl_owner_t);
693 extern void locks_remove_flock(struct file *);
694 extern struct file_lock *posix_test_lock(struct file *, struct file_lock *);
695 extern int posix_lock_file(struct file *, struct file_lock *);
696 extern void posix_block_lock(struct file_lock *, struct file_lock *);
697 extern void posix_unblock_lock(struct file *, struct file_lock *);
698 extern int posix_locks_deadlock(struct file_lock *, struct file_lock *);
699 extern int __break_lease(struct inode *inode, unsigned int flags);
700 extern void lease_get_mtime(struct inode *, struct timespec *time);
701 extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
702 extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
703 extern void steal_locks(fl_owner_t from);
704
705 struct fasync_struct {
706         int     magic;
707         int     fa_fd;
708         struct  fasync_struct   *fa_next; /* singly linked list */
709         struct  file            *fa_file;
710 };
711
712 #define FASYNC_MAGIC 0x4601
713
714 /* SMP safe fasync helpers: */
715 extern int fasync_helper(int, struct file *, int, struct fasync_struct **);
716 /* can be called from interrupts */
717 extern void kill_fasync(struct fasync_struct **, int, int);
718 /* only for net: no internal synchronization */
719 extern void __kill_fasync(struct fasync_struct *, int, int);
720
721 extern int f_setown(struct file *filp, unsigned long arg, int force);
722 extern void f_delown(struct file *filp);
723 extern int send_sigurg(struct fown_struct *fown);
724
725 /*
726  *      Umount options
727  */
728
729 #define MNT_FORCE       0x00000001      /* Attempt to forcibily umount */
730 #define MNT_DETACH      0x00000002      /* Just detach from the tree */
731 #define MNT_EXPIRE      0x00000004      /* Mark for expiry */
732
733 extern struct list_head super_blocks;
734 extern spinlock_t sb_lock;
735
736 #define sb_entry(list)  list_entry((list), struct super_block, s_list)
737 #define S_BIAS (1<<30)
738 struct super_block {
739         struct list_head        s_list;         /* Keep this first */
740         dev_t                   s_dev;          /* search index; _not_ kdev_t */
741         unsigned long           s_blocksize;
742         unsigned long           s_old_blocksize;
743         unsigned char           s_blocksize_bits;
744         unsigned char           s_dirt;
745         unsigned long long      s_maxbytes;     /* Max file size */
746         struct file_system_type *s_type;
747         struct super_operations *s_op;
748         struct dquot_operations *dq_op;
749         struct quotactl_ops     *s_qcop;
750         struct export_operations *s_export_op;
751         unsigned long           s_flags;
752         unsigned long           s_magic;
753         struct dentry           *s_root;
754         struct rw_semaphore     s_umount;
755         struct semaphore        s_lock;
756         int                     s_count;
757         int                     s_syncing;
758         int                     s_need_sync_fs;
759         atomic_t                s_active;
760         void                    *s_security;
761
762         struct list_head        s_dirty;        /* dirty inodes */
763         struct list_head        s_io;           /* parked for writeback */
764         struct hlist_head       s_anon;         /* anonymous dentries for (nfs) exporting */
765         struct list_head        s_files;
766
767         struct block_device     *s_bdev;
768         struct list_head        s_instances;
769         struct quota_info       s_dquot;        /* Diskquota specific options */
770
771         int                     s_frozen;
772         wait_queue_head_t       s_wait_unfrozen;
773
774         char s_id[32];                          /* Informational name */
775
776         void                    *s_fs_info;     /* Filesystem private info */
777
778         /*
779          * The next field is for VFS *only*. No filesystems have any business
780          * even looking at it. You had been warned.
781          */
782         struct semaphore s_vfs_rename_sem;      /* Kludge */
783 };
784
785 /*
786  * Snapshotting support.
787  */
788 enum {
789         SB_UNFROZEN = 0,
790         SB_FREEZE_WRITE = 1,
791         SB_FREEZE_TRANS = 2,
792 };
793
794 #define vfs_check_frozen(sb, level) \
795         wait_event((sb)->s_wait_unfrozen, ((sb)->s_frozen < (level)))
796
797 /*
798  * Superblock locking.
799  */
800 static inline void lock_super(struct super_block * sb)
801 {
802         down(&sb->s_lock);
803 }
804
805 static inline void unlock_super(struct super_block * sb)
806 {
807         up(&sb->s_lock);
808 }
809
810 /*
811  * VFS helper functions..
812  */
813 extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *);
814 extern int vfs_mkdir(struct inode *, struct dentry *, int);
815 extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
816 extern int vfs_symlink(struct inode *, struct dentry *, const char *, int);
817 extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
818 extern int vfs_rmdir(struct inode *, struct dentry *);
819 extern int vfs_unlink(struct inode *, struct dentry *);
820 extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
821
822 /*
823  * File types
824  *
825  * NOTE! These match bits 12..15 of stat.st_mode
826  * (ie "(i_mode >> 12) & 15").
827  */
828 #define DT_UNKNOWN      0
829 #define DT_FIFO         1
830 #define DT_CHR          2
831 #define DT_DIR          4
832 #define DT_BLK          6
833 #define DT_REG          8
834 #define DT_LNK          10
835 #define DT_SOCK         12
836 #define DT_WHT          14
837
838 /*
839  * This is the "filldir" function type, used by readdir() to let
840  * the kernel specify what kind of dirent layout it wants to have.
841  * This allows the kernel to read directories into kernel space or
842  * to have different dirent layouts depending on the binary type.
843  */
844 typedef int (*filldir_t)(void *, const char *, int, loff_t, ino_t, unsigned);
845
846 struct block_device_operations {
847         int (*open) (struct inode *, struct file *);
848         int (*release) (struct inode *, struct file *);
849         int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
850         int (*media_changed) (struct gendisk *);
851         int (*revalidate_disk) (struct gendisk *);
852         struct module *owner;
853 };
854
855 /*
856  * "descriptor" for what we're up to with a read for sendfile().
857  * This allows us to use the same read code yet
858  * have multiple different users of the data that
859  * we read from a file.
860  *
861  * The simplest case just copies the data to user
862  * mode.
863  */
864 typedef struct {
865         size_t written;
866         size_t count;
867         union {
868                 char __user * buf;
869                 void *data;
870         } arg;
871         int error;
872 } read_descriptor_t;
873
874 typedef int (*read_actor_t)(read_descriptor_t *, struct page *, unsigned long, unsigned long);
875
876 /*
877  * NOTE:
878  * read, write, poll, fsync, readv, writev can be called
879  *   without the big kernel lock held in all filesystems.
880  */
881 struct file_operations {
882         struct module *owner;
883         loff_t (*llseek) (struct file *, loff_t, int);
884         ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
885         ssize_t (*aio_read) (struct kiocb *, char __user *, size_t, loff_t);
886         ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
887         ssize_t (*aio_write) (struct kiocb *, const char __user *, size_t, loff_t);
888         int (*readdir) (struct file *, void *, filldir_t);
889         unsigned int (*poll) (struct file *, struct poll_table_struct *);
890         int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
891         int (*mmap) (struct file *, struct vm_area_struct *);
892         int (*open) (struct inode *, struct file *);
893         int (*flush) (struct file *);
894         int (*release) (struct inode *, struct file *);
895         int (*fsync) (struct file *, struct dentry *, int datasync);
896         int (*aio_fsync) (struct kiocb *, int datasync);
897         int (*fasync) (int, struct file *, int);
898         int (*lock) (struct file *, int, struct file_lock *);
899         ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
900         ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
901         ssize_t (*sendfile) (struct file *, loff_t *, size_t, read_actor_t, void *);
902         ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
903         unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
904         long (*fcntl)(int fd, unsigned int cmd,
905                         unsigned long arg, struct file *filp);
906 };
907
908 struct inode_operations {
909         int (*create) (struct inode *,struct dentry *,int, struct nameidata *);
910         struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
911         int (*link) (struct dentry *,struct inode *,struct dentry *);
912         int (*unlink) (struct inode *,struct dentry *);
913         int (*symlink) (struct inode *,struct dentry *,const char *);
914         int (*mkdir) (struct inode *,struct dentry *,int);
915         int (*rmdir) (struct inode *,struct dentry *);
916         int (*mknod) (struct inode *,struct dentry *,int,dev_t);
917         int (*rename) (struct inode *, struct dentry *,
918                         struct inode *, struct dentry *);
919         int (*readlink) (struct dentry *, char __user *,int);
920         int (*follow_link) (struct dentry *, struct nameidata *);
921         void (*put_link) (struct dentry *, struct nameidata *);
922         void (*truncate) (struct inode *);
923         int (*permission) (struct inode *, int, struct nameidata *);
924         int (*setattr) (struct dentry *, struct iattr *);
925         int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *);
926         int (*setxattr) (struct dentry *, const char *,const void *,size_t,int);
927         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
928         ssize_t (*listxattr) (struct dentry *, char *, size_t);
929         int (*removexattr) (struct dentry *, const char *);
930 };
931
932 struct seq_file;
933
934 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
935 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
936 extern ssize_t vfs_readv(struct file *, const struct iovec __user *,
937                 unsigned long, loff_t *);
938 extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
939                 unsigned long, loff_t *);
940
941 /*
942  * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called
943  * without the big kernel lock held in all filesystems.
944  */
945 struct super_operations {
946         struct inode *(*alloc_inode)(struct super_block *sb);
947         void (*destroy_inode)(struct inode *);
948
949         void (*read_inode) (struct inode *);
950   
951         void (*dirty_inode) (struct inode *);
952         void (*write_inode) (struct inode *, int);
953         void (*put_inode) (struct inode *);
954         void (*drop_inode) (struct inode *);
955         void (*delete_inode) (struct inode *);
956         void (*put_super) (struct super_block *);
957         void (*write_super) (struct super_block *);
958         int (*sync_fs)(struct super_block *sb, int wait);
959         void (*write_super_lockfs) (struct super_block *);
960         void (*unlockfs) (struct super_block *);
961         int (*statfs) (struct super_block *, struct kstatfs *);
962         int (*remount_fs) (struct super_block *, int *, char *);
963         void (*clear_inode) (struct inode *);
964         void (*umount_begin) (struct super_block *);
965
966         int (*show_options)(struct seq_file *, struct vfsmount *);
967 };
968
969 /* Inode state bits.  Protected by inode_lock. */
970 #define I_DIRTY_SYNC            1 /* Not dirty enough for O_DATASYNC */
971 #define I_DIRTY_DATASYNC        2 /* Data-related inode changes pending */
972 #define I_DIRTY_PAGES           4 /* Data-related inode changes pending */
973 #define I_LOCK                  8
974 #define I_FREEING               16
975 #define I_CLEAR                 32
976 #define I_NEW                   64
977
978 #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)
979
980 extern void __mark_inode_dirty(struct inode *, int);
981 static inline void mark_inode_dirty(struct inode *inode)
982 {
983         __mark_inode_dirty(inode, I_DIRTY);
984 }
985
986 static inline void mark_inode_dirty_sync(struct inode *inode)
987 {
988         __mark_inode_dirty(inode, I_DIRTY_SYNC);
989 }
990
991 static inline void touch_atime(struct vfsmount *mnt, struct dentry *dentry)
992 {
993         /* per-mountpoint checks will go here */
994         update_atime(dentry->d_inode);
995 }
996
997 static inline void file_accessed(struct file *file)
998 {
999         if (!(file->f_flags & O_NOATIME))
1000                 touch_atime(file->f_vfsmnt, file->f_dentry);
1001 }
1002
1003 int sync_inode(struct inode *inode, struct writeback_control *wbc);
1004
1005 /**
1006  * &export_operations - for nfsd to communicate with file systems
1007  * decode_fh:      decode a file handle fragment and return a &struct dentry
1008  * encode_fh:      encode a file handle fragment from a dentry
1009  * get_name:       find the name for a given inode in a given directory
1010  * get_parent:     find the parent of a given directory
1011  * get_dentry:     find a dentry for the inode given a file handle sub-fragment
1012  *
1013  * Description:
1014  *    The export_operations structure provides a means for nfsd to communicate
1015  *    with a particular exported file system  - particularly enabling nfsd and
1016  *    the filesystem to co-operate when dealing with file handles.
1017  *
1018  *    export_operations contains two basic operation for dealing with file handles,
1019  *    decode_fh() and encode_fh(), and allows for some other operations to be defined
1020  *    which standard helper routines use to get specific information from the
1021  *    filesystem.
1022  *
1023  *    nfsd encodes information use to determine which filesystem a filehandle
1024  *    applies to in the initial part of the file handle.  The remainder, termed a
1025  *    file handle fragment, is controlled completely by the filesystem.
1026  *    The standard helper routines assume that this fragment will contain one or two
1027  *    sub-fragments, one which identifies the file, and one which may be used to
1028  *    identify the (a) directory containing the file.
1029  *
1030  *    In some situations, nfsd needs to get a dentry which is connected into a
1031  *    specific part of the file tree.  To allow for this, it passes the function
1032  *    acceptable() together with a @context which can be used to see if the dentry
1033  *    is acceptable.  As there can be multiple dentrys for a given file, the filesystem
1034  *    should check each one for acceptability before looking for the next.  As soon
1035  *    as an acceptable one is found, it should be returned.
1036  *
1037  * decode_fh:
1038  *    @decode_fh is given a &struct super_block (@sb), a file handle fragment (@fh, @fh_len)
1039  *    and an acceptability testing function (@acceptable, @context).  It should return
1040  *    a &struct dentry which refers to the same file that the file handle fragment refers
1041  *    to,  and which passes the acceptability test.  If it cannot, it should return
1042  *    a %NULL pointer if the file was found but no acceptable &dentries were available, or
1043  *    a %ERR_PTR error code indicating why it couldn't be found (e.g. %ENOENT or %ENOMEM).
1044  *
1045  * encode_fh:
1046  *    @encode_fh should store in the file handle fragment @fh (using at most @max_len bytes)
1047  *    information that can be used by @decode_fh to recover the file refered to by the
1048  *    &struct dentry @de.  If the @connectable flag is set, the encode_fh() should store
1049  *    sufficient information so that a good attempt can be made to find not only
1050  *    the file but also it's place in the filesystem.   This typically means storing
1051  *    a reference to de->d_parent in the filehandle fragment.
1052  *    encode_fh() should return the number of bytes stored or a negative error code
1053  *    such as %-ENOSPC
1054  *
1055  * get_name:
1056  *    @get_name should find a name for the given @child in the given @parent directory.
1057  *    The name should be stored in the @name (with the understanding that it is already
1058  *    pointing to a a %NAME_MAX+1 sized buffer.   get_name() should return %0 on success,
1059  *    a negative error code or error.
1060  *    @get_name will be called without @parent->i_sem held.
1061  *
1062  * get_parent:
1063  *    @get_parent should find the parent directory for the given @child which is also
1064  *    a directory.  In the event that it cannot be found, or storage space cannot be
1065  *    allocated, a %ERR_PTR should be returned.
1066  *
1067  * get_dentry:
1068  *    Given a &super_block (@sb) and a pointer to a file-system specific inode identifier,
1069  *    possibly an inode number, (@inump) get_dentry() should find the identified inode and
1070  *    return a dentry for that inode.
1071  *    Any suitable dentry can be returned including, if necessary, a new dentry created
1072  *    with d_alloc_root.  The caller can then find any other extant dentrys by following the
1073  *    d_alias links.  If a new dentry was created using d_alloc_root, DCACHE_NFSD_DISCONNECTED
1074  *    should be set, and the dentry should be d_rehash()ed.
1075  *
1076  *    If the inode cannot be found, either a %NULL pointer or an %ERR_PTR code can be returned.
1077  *    The @inump will be whatever was passed to nfsd_find_fh_dentry() in either the
1078  *    @obj or @parent parameters.
1079  *
1080  * Locking rules:
1081  *  get_parent is called with child->d_inode->i_sem down
1082  *  get_name is not (which is possibly inconsistent)
1083  */
1084
1085 struct export_operations {
1086         struct dentry *(*decode_fh)(struct super_block *sb, __u32 *fh, int fh_len, int fh_type,
1087                          int (*acceptable)(void *context, struct dentry *de),
1088                          void *context);
1089         int (*encode_fh)(struct dentry *de, __u32 *fh, int *max_len,
1090                          int connectable);
1091
1092         /* the following are only called from the filesystem itself */
1093         int (*get_name)(struct dentry *parent, char *name,
1094                         struct dentry *child);
1095         struct dentry * (*get_parent)(struct dentry *child);
1096         struct dentry * (*get_dentry)(struct super_block *sb, void *inump);
1097
1098         /* This is set by the exporting module to a standard helper */
1099         struct dentry * (*find_exported_dentry)(
1100                 struct super_block *sb, void *obj, void *parent,
1101                 int (*acceptable)(void *context, struct dentry *de),
1102                 void *context);
1103
1104
1105 };
1106
1107
1108 struct file_system_type {
1109         const char *name;
1110         int fs_flags;
1111         struct super_block *(*get_sb) (struct file_system_type *, int,
1112                                        const char *, void *);
1113         void (*kill_sb) (struct super_block *);
1114         struct module *owner;
1115         struct file_system_type * next;
1116         struct list_head fs_supers;
1117 };
1118
1119 struct super_block *get_sb_bdev(struct file_system_type *fs_type,
1120         int flags, const char *dev_name, void *data,
1121         int (*fill_super)(struct super_block *, void *, int));
1122 struct super_block *get_sb_single(struct file_system_type *fs_type,
1123         int flags, void *data,
1124         int (*fill_super)(struct super_block *, void *, int));
1125 struct super_block *get_sb_nodev(struct file_system_type *fs_type,
1126         int flags, void *data,
1127         int (*fill_super)(struct super_block *, void *, int));
1128 void generic_shutdown_super(struct super_block *sb);
1129 void kill_block_super(struct super_block *sb);
1130 void kill_anon_super(struct super_block *sb);
1131 void kill_litter_super(struct super_block *sb);
1132 void deactivate_super(struct super_block *sb);
1133 int set_anon_super(struct super_block *s, void *data);
1134 struct super_block *sget(struct file_system_type *type,
1135                         int (*test)(struct super_block *,void *),
1136                         int (*set)(struct super_block *,void *),
1137                         void *data);
1138 struct super_block *get_sb_pseudo(struct file_system_type *, char *,
1139                         struct super_operations *ops, unsigned long);
1140 int __put_super(struct super_block *sb);
1141 void unnamed_dev_init(void);
1142
1143 /* Alas, no aliases. Too much hassle with bringing module.h everywhere */
1144 #define fops_get(fops) \
1145         (((fops) && try_module_get((fops)->owner) ? (fops) : NULL))
1146 #define fops_put(fops) \
1147         do { if (fops) module_put((fops)->owner); } while(0)
1148
1149 extern int register_filesystem(struct file_system_type *);
1150 extern int unregister_filesystem(struct file_system_type *);
1151 extern struct vfsmount *kern_mount(struct file_system_type *);
1152 extern int may_umount_tree(struct vfsmount *);
1153 extern int may_umount(struct vfsmount *);
1154 extern long do_mount(char *, char *, char *, unsigned long, void *);
1155
1156 extern int vfs_statfs(struct super_block *, struct kstatfs *);
1157
1158 /* Return value for VFS lock functions - tells locks.c to lock conventionally
1159  * REALLY kosha for root NFS and nfs_lock
1160  */ 
1161 #define LOCK_USE_CLNT 1
1162
1163 #define FLOCK_VERIFY_READ  1
1164 #define FLOCK_VERIFY_WRITE 2
1165
1166 extern int locks_mandatory_locked(struct inode *);
1167 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
1168
1169 /*
1170  * Candidates for mandatory locking have the setgid bit set
1171  * but no group execute bit -  an otherwise meaningless combination.
1172  */
1173 #define MANDATORY_LOCK(inode) \
1174         (IS_MANDLOCK(inode) && ((inode)->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID)
1175
1176 static inline int locks_verify_locked(struct inode *inode)
1177 {
1178         if (MANDATORY_LOCK(inode))
1179                 return locks_mandatory_locked(inode);
1180         return 0;
1181 }
1182
1183 static inline int locks_verify_area(int read_write, struct inode *inode,
1184                                     struct file *filp, loff_t offset,
1185                                     size_t count)
1186 {
1187         if (inode->i_flock && MANDATORY_LOCK(inode))
1188                 return locks_mandatory_area(read_write, inode, filp, offset, count);
1189         return 0;
1190 }
1191
1192 static inline int locks_verify_truncate(struct inode *inode,
1193                                     struct file *filp,
1194                                     loff_t size)
1195 {
1196         if (inode->i_flock && MANDATORY_LOCK(inode))
1197                 return locks_mandatory_area(
1198                         FLOCK_VERIFY_WRITE, inode, filp,
1199                         size < inode->i_size ? size : inode->i_size,
1200                         (size < inode->i_size ? inode->i_size - size
1201                          : size - inode->i_size)
1202                 );
1203         return 0;
1204 }
1205
1206 static inline int break_lease(struct inode *inode, unsigned int mode)
1207 {
1208         if (inode->i_flock)
1209                 return __break_lease(inode, mode);
1210         return 0;
1211 }
1212
1213 /* fs/open.c */
1214
1215 extern int do_truncate(struct dentry *, loff_t start);
1216 extern struct file *filp_open(const char *, int, int);
1217 extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
1218 extern int filp_close(struct file *, fl_owner_t id);
1219 extern char * getname(const char __user *);
1220
1221 /* fs/dcache.c */
1222 extern void __init vfs_caches_init_early(void);
1223 extern void __init vfs_caches_init(unsigned long);
1224
1225 #define __getname()     kmem_cache_alloc(names_cachep, SLAB_KERNEL)
1226 #define __putname(name) kmem_cache_free(names_cachep, (void *)(name))
1227 #ifndef CONFIG_AUDITSYSCALL
1228 #define putname(name)   __putname(name)
1229 #else
1230 #define putname(name)                                                   \
1231         do {                                                            \
1232                 if (unlikely(current->audit_context))                   \
1233                         audit_putname(name);                            \
1234                 else                                                    \
1235                         __putname(name);                                \
1236         } while (0)
1237 #endif
1238
1239 extern int register_blkdev(unsigned int, const char *);
1240 extern int unregister_blkdev(unsigned int, const char *);
1241 extern struct block_device *bdget(dev_t);
1242 extern void bd_set_size(struct block_device *, loff_t size);
1243 extern void bd_forget(struct inode *inode);
1244 extern void bdput(struct block_device *);
1245 extern int blkdev_open(struct inode *, struct file *);
1246 extern struct block_device *open_by_devnum(dev_t, unsigned);
1247 extern struct file_operations def_blk_fops;
1248 extern struct address_space_operations def_blk_aops;
1249 extern struct file_operations def_chr_fops;
1250 extern struct file_operations bad_sock_fops;
1251 extern struct file_operations def_fifo_fops;
1252 extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
1253 extern int blkdev_ioctl(struct inode *, struct file *, unsigned, unsigned long);
1254 extern int blkdev_get(struct block_device *, mode_t, unsigned);
1255 extern int blkdev_put(struct block_device *);
1256 extern int bd_claim(struct block_device *, void *);
1257 extern void bd_release(struct block_device *);
1258
1259 /* fs/char_dev.c */
1260 extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, char *);
1261 extern int register_chrdev_region(dev_t, unsigned, char *);
1262 extern int register_chrdev(unsigned int, const char *,
1263                            struct file_operations *);
1264 extern int unregister_chrdev(unsigned int, const char *);
1265 extern void unregister_chrdev_region(dev_t, unsigned);
1266 extern int chrdev_open(struct inode *, struct file *);
1267
1268 /* fs/block_dev.c */
1269 #define BDEVNAME_SIZE   32      /* Largest string for a blockdev identifier */
1270 extern const char *__bdevname(dev_t, char *buffer);
1271 extern const char *bdevname(struct block_device *bdev, char *buffer);
1272 extern struct block_device *lookup_bdev(const char *);
1273 extern struct block_device *open_bdev_excl(const char *, int, void *);
1274 extern void close_bdev_excl(struct block_device *);
1275
1276 extern void init_special_inode(struct inode *, umode_t, dev_t);
1277
1278 /* Invalid inode operations -- fs/bad_inode.c */
1279 extern void make_bad_inode(struct inode *);
1280 extern int is_bad_inode(struct inode *);
1281
1282 extern struct file_operations read_fifo_fops;
1283 extern struct file_operations write_fifo_fops;
1284 extern struct file_operations rdwr_fifo_fops;
1285 extern struct file_operations read_pipe_fops;
1286 extern struct file_operations write_pipe_fops;
1287 extern struct file_operations rdwr_pipe_fops;
1288
1289 extern int fs_may_remount_ro(struct super_block *);
1290
1291 /*
1292  * return READ, READA, or WRITE
1293  */
1294 #define bio_rw(bio)             ((bio)->bi_rw & (RW_MASK | RWA_MASK))
1295
1296 /*
1297  * return data direction, READ or WRITE
1298  */
1299 #define bio_data_dir(bio)       ((bio)->bi_rw & 1)
1300
1301 extern int check_disk_change(struct block_device *);
1302 extern int invalidate_inodes(struct super_block *);
1303 extern int __invalidate_device(struct block_device *, int);
1304 extern int invalidate_partition(struct gendisk *, int);
1305 unsigned long invalidate_mapping_pages(struct address_space *mapping,
1306                                         pgoff_t start, pgoff_t end);
1307 unsigned long invalidate_inode_pages(struct address_space *mapping);
1308 static inline void invalidate_remote_inode(struct inode *inode)
1309 {
1310         if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
1311             S_ISLNK(inode->i_mode))
1312                 invalidate_inode_pages(inode->i_mapping);
1313 }
1314 extern void invalidate_inode_pages2(struct address_space *mapping);
1315 extern void write_inode_now(struct inode *, int);
1316 extern int filemap_fdatawrite(struct address_space *);
1317 extern int filemap_flush(struct address_space *);
1318 extern int filemap_fdatawait(struct address_space *);
1319 extern int filemap_write_and_wait(struct address_space *mapping);
1320 extern void sync_supers(void);
1321 extern void sync_filesystems(int wait);
1322 extern void emergency_sync(void);
1323 extern void emergency_remount(void);
1324 extern int do_remount_sb(struct super_block *sb, int flags,
1325                          void *data, int force);
1326 extern sector_t bmap(struct inode *, sector_t);
1327 extern int setattr_mask(unsigned int);
1328 extern int notify_change(struct dentry *, struct iattr *);
1329 extern int permission(struct inode *, int, struct nameidata *);
1330 extern int vfs_permission(struct inode *, int);
1331 extern int get_write_access(struct inode *);
1332 extern int deny_write_access(struct file *);
1333 static inline void put_write_access(struct inode * inode)
1334 {
1335         atomic_dec(&inode->i_writecount);
1336 }
1337 static inline void allow_write_access(struct file *file)
1338 {
1339         if (file)
1340                 atomic_inc(&file->f_dentry->d_inode->i_writecount);
1341 }
1342 extern int do_pipe(int *);
1343
1344 extern int open_namei(const char *, int, int, struct nameidata *);
1345 extern int may_open(struct nameidata *, int, int);
1346
1347 extern int kernel_read(struct file *, unsigned long, char *, unsigned long);
1348 extern struct file * open_exec(const char *);
1349  
1350 /* fs/dcache.c -- generic fs support functions */
1351 extern int is_subdir(struct dentry *, struct dentry *);
1352 extern ino_t find_inode_number(struct dentry *, struct qstr *);
1353
1354 #include <linux/err.h>
1355
1356 /* needed for stackable file system support */
1357 extern loff_t default_llseek(struct file *file, loff_t offset, int origin);
1358
1359 extern loff_t vfs_llseek(struct file *file, loff_t offset, int origin);
1360
1361 extern void inode_init_once(struct inode *);
1362 extern void iput(struct inode *);
1363 extern struct inode * igrab(struct inode *);
1364 extern ino_t iunique(struct super_block *, ino_t);
1365 extern int inode_needs_sync(struct inode *inode);
1366 extern void generic_delete_inode(struct inode *inode);
1367
1368 extern struct inode *ilookup5(struct super_block *sb, unsigned long hashval,
1369                 int (*test)(struct inode *, void *), void *data);
1370 extern struct inode *ilookup(struct super_block *sb, unsigned long ino);
1371
1372 extern struct inode * iget5_locked(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *);
1373 extern struct inode * iget_locked(struct super_block *, unsigned long);
1374 extern void unlock_new_inode(struct inode *);
1375
1376 static inline struct inode *iget(struct super_block *sb, unsigned long ino)
1377 {
1378         struct inode *inode = iget_locked(sb, ino);
1379         
1380         if (inode && (inode->i_state & I_NEW)) {
1381                 sb->s_op->read_inode(inode);
1382                 unlock_new_inode(inode);
1383         }
1384
1385         return inode;
1386 }
1387
1388 extern void __iget(struct inode * inode);
1389 extern void clear_inode(struct inode *);
1390 extern void destroy_inode(struct inode *);
1391 extern struct inode *new_inode(struct super_block *);
1392 extern int remove_suid(struct dentry *);
1393 extern void remove_dquot_ref(struct super_block *, int, struct list_head *);
1394 extern struct semaphore iprune_sem;
1395
1396 extern void __insert_inode_hash(struct inode *, unsigned long hashval);
1397 extern void remove_inode_hash(struct inode *);
1398 static inline void insert_inode_hash(struct inode *inode) {
1399         __insert_inode_hash(inode, inode->i_ino);
1400 }
1401
1402 extern struct file * get_empty_filp(void);
1403 extern void file_move(struct file *f, struct list_head *list);
1404 extern void file_kill(struct file *f);
1405 struct bio;
1406 extern void submit_bio(int, struct bio *);
1407 extern int bdev_read_only(struct block_device *);
1408 extern int set_blocksize(struct block_device *, int);
1409 extern int sb_set_blocksize(struct super_block *, int);
1410 extern int sb_min_blocksize(struct super_block *, int);
1411
1412 extern int generic_file_mmap(struct file *, struct vm_area_struct *);
1413 extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);
1414 extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size);
1415 extern int file_send_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size);
1416 extern ssize_t generic_file_read(struct file *, char __user *, size_t, loff_t *);
1417 int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk);
1418 extern ssize_t generic_file_write(struct file *, const char __user *, size_t, loff_t *);
1419 extern ssize_t generic_file_aio_read(struct kiocb *, char __user *, size_t, loff_t);
1420 extern ssize_t __generic_file_aio_read(struct kiocb *, const struct iovec *, unsigned long, loff_t *);
1421 extern ssize_t generic_file_aio_write(struct kiocb *, const char __user *, size_t, loff_t);
1422 extern ssize_t generic_file_aio_write_nolock(struct kiocb *, const struct iovec *,
1423                                 unsigned long, loff_t *);
1424 extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos);
1425 extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos);
1426 ssize_t generic_file_write_nolock(struct file *file, const struct iovec *iov,
1427                                 unsigned long nr_segs, loff_t *ppos);
1428 extern ssize_t generic_file_sendfile(struct file *, loff_t *, size_t, read_actor_t, void *);
1429 extern void do_generic_mapping_read(struct address_space *mapping,
1430                                     struct file_ra_state *, struct file *,
1431                                     loff_t *, read_descriptor_t *, read_actor_t);
1432 extern void
1433 file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping);
1434 extern ssize_t generic_file_direct_IO(int rw, struct kiocb *iocb,
1435         const struct iovec *iov, loff_t offset, unsigned long nr_segs);
1436 extern ssize_t generic_file_readv(struct file *filp, const struct iovec *iov, 
1437         unsigned long nr_segs, loff_t *ppos);
1438 ssize_t generic_file_writev(struct file *filp, const struct iovec *iov, 
1439                         unsigned long nr_segs, loff_t *ppos);
1440 extern loff_t no_llseek(struct file *file, loff_t offset, int origin);
1441 extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin);
1442 extern loff_t remote_llseek(struct file *file, loff_t offset, int origin);
1443 extern int generic_file_open(struct inode * inode, struct file * filp);
1444
1445 static inline void do_generic_file_read(struct file * filp, loff_t *ppos,
1446                                         read_descriptor_t * desc,
1447                                         read_actor_t actor)
1448 {
1449         do_generic_mapping_read(filp->f_mapping,
1450                                 &filp->f_ra,
1451                                 filp,
1452                                 ppos,
1453                                 desc,
1454                                 actor);
1455 }
1456
1457 ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1458         struct block_device *bdev, const struct iovec *iov, loff_t offset,
1459         unsigned long nr_segs, get_blocks_t get_blocks, dio_iodone_t end_io,
1460         int needs_special_locking);
1461
1462 /*
1463  * For filesystems which need locking between buffered and direct access
1464  */
1465 static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb,
1466         struct inode *inode, struct block_device *bdev, const struct iovec *iov,
1467         loff_t offset, unsigned long nr_segs, get_blocks_t get_blocks,
1468         dio_iodone_t end_io)
1469 {
1470         return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset,
1471                                 nr_segs, get_blocks, end_io, 1);
1472 }
1473
1474 static inline ssize_t blockdev_direct_IO_no_locking(int rw, struct kiocb *iocb,
1475         struct inode *inode, struct block_device *bdev, const struct iovec *iov,
1476         loff_t offset, unsigned long nr_segs, get_blocks_t get_blocks,
1477         dio_iodone_t end_io)
1478 {
1479         return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset,
1480                                 nr_segs, get_blocks, end_io, 0);
1481 }
1482
1483 extern struct file_operations generic_ro_fops;
1484
1485 #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m))
1486
1487 extern int vfs_readlink(struct dentry *, char __user *, int, const char *);
1488 extern int vfs_follow_link(struct nameidata *, const char *);
1489 extern int page_readlink(struct dentry *, char __user *, int);
1490 extern int page_follow_link(struct dentry *, struct nameidata *);
1491 extern int page_follow_link_light(struct dentry *, struct nameidata *);
1492 extern void page_put_link(struct dentry *, struct nameidata *);
1493 extern int page_symlink(struct inode *inode, const char *symname, int len);
1494 extern struct inode_operations page_symlink_inode_operations;
1495 extern int generic_readlink(struct dentry *, char __user *, int);
1496 extern void generic_fillattr(struct inode *, struct kstat *);
1497 extern int vfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
1498 void inode_add_bytes(struct inode *inode, loff_t bytes);
1499 void inode_sub_bytes(struct inode *inode, loff_t bytes);
1500 loff_t inode_get_bytes(struct inode *inode);
1501 void inode_set_bytes(struct inode *inode, loff_t bytes);
1502
1503 extern int vfs_readdir(struct file *, filldir_t, void *);
1504
1505 extern int vfs_stat(char __user *, struct kstat *);
1506 extern int vfs_lstat(char __user *, struct kstat *);
1507 extern int vfs_fstat(unsigned int, struct kstat *);
1508
1509 extern struct file_system_type *get_fs_type(const char *name);
1510 extern struct super_block *get_super(struct block_device *);
1511 extern struct super_block *user_get_super(dev_t);
1512 extern void drop_super(struct super_block *sb);
1513
1514 extern int dcache_dir_open(struct inode *, struct file *);
1515 extern int dcache_dir_close(struct inode *, struct file *);
1516 extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
1517 extern int dcache_readdir(struct file *, void *, filldir_t);
1518 extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
1519 extern int simple_statfs(struct super_block *, struct kstatfs *);
1520 extern int simple_link(struct dentry *, struct inode *, struct dentry *);
1521 extern int simple_unlink(struct inode *, struct dentry *);
1522 extern int simple_rmdir(struct inode *, struct dentry *);
1523 extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
1524 extern int simple_sync_file(struct file *, struct dentry *, int);
1525 extern int simple_empty(struct dentry *);
1526 extern int simple_readpage(struct file *file, struct page *page);
1527 extern int simple_prepare_write(struct file *file, struct page *page,
1528                         unsigned offset, unsigned to);
1529 extern int simple_commit_write(struct file *file, struct page *page,
1530                                 unsigned offset, unsigned to);
1531
1532 extern struct dentry *simple_lookup(struct inode *, struct dentry *, struct nameidata *);
1533 extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *);
1534 extern struct file_operations simple_dir_operations;
1535 extern struct inode_operations simple_dir_inode_operations;
1536 struct tree_descr { char *name; struct file_operations *ops; int mode; };
1537 extern int simple_fill_super(struct super_block *, int, struct tree_descr *);
1538 extern int simple_pin_fs(char *name, struct vfsmount **mount, int *count);
1539 extern void simple_release_fs(struct vfsmount **mount, int *count);
1540
1541 extern int inode_change_ok(struct inode *, struct iattr *);
1542 extern int __must_check inode_setattr(struct inode *, struct iattr *);
1543
1544 extern void inode_update_time(struct inode *inode, int ctime_too);
1545
1546 static inline ino_t parent_ino(struct dentry *dentry)
1547 {
1548         ino_t res;
1549
1550         spin_lock(&dentry->d_lock);
1551         res = dentry->d_parent->d_inode->i_ino;
1552         spin_unlock(&dentry->d_lock);
1553         return res;
1554 }
1555
1556 /* kernel/fork.c */
1557 extern int unshare_files(void);
1558
1559 #ifdef CONFIG_SECURITY
1560 static inline char *alloc_secdata(void)
1561 {
1562         return (char *)get_zeroed_page(GFP_KERNEL);
1563 }
1564
1565 static inline void free_secdata(void *secdata)
1566 {
1567         free_page((unsigned long)secdata);
1568 }
1569 #else
1570 static inline char *alloc_secdata(void)
1571 {
1572         return (char *)1;
1573 }
1574
1575 static inline void free_secdata(void *secdata)
1576 { }
1577 #endif  /* CONFIG_SECURITY */
1578
1579 #endif /* __KERNEL__ */
1580 #endif /* _LINUX_FS_H */