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