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