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