The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/include/linux/fs.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: 31e01782ee1b1a6d746f4e638d4286fb


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.