~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/include/linux/fs.h

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.