root/include/linux/fs.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. mark_buffer_clean
  2. mark_buffer_dirty
  3. iget

   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/linkage.h>
  10 #include <linux/limits.h>
  11 #include <linux/wait.h>
  12 #include <linux/types.h>
  13 #include <linux/vfs.h>
  14 #include <linux/net.h>
  15 
  16 /*
  17  * It's silly to have NR_OPEN bigger than NR_FILE, but I'll fix
  18  * that later. Anyway, now the file code is no longer dependent
  19  * on bitmaps in unsigned longs, but uses the new fd_set structure..
  20  *
  21  * Some programs (notably those using select()) may have to be 
  22  * recompiled to take full advantage of the new limits..
  23  */
  24 #undef NR_OPEN
  25 #define NR_OPEN 256
  26 
  27 #define NR_INODE 2048   /* this should be bigger than NR_FILE */
  28 #define NR_FILE 1024    /* this can well be larger on a larger system */
  29 #define NR_SUPER 32
  30 #define NR_IHASH 131
  31 #define BLOCK_SIZE 1024
  32 #define BLOCK_SIZE_BITS 10
  33 
  34 #define MAY_EXEC 1
  35 #define MAY_WRITE 2
  36 #define MAY_READ 4
  37 
  38 #define READ 0
  39 #define WRITE 1
  40 #define READA 2         /* read-ahead - don't pause */
  41 #define WRITEA 3        /* "write-ahead" - silly, but somewhat useful */
  42 
  43 extern void buffer_init(void);
  44 extern unsigned long inode_init(unsigned long start, unsigned long end);
  45 extern unsigned long file_table_init(unsigned long start, unsigned long end);
  46 extern unsigned long name_cache_init(unsigned long start, unsigned long end);
  47 
  48 #define MAJOR(a) (int)((unsigned short)(a) >> 8)
  49 #define MINOR(a) (int)((unsigned short)(a) & 0xFF)
  50 #define MKDEV(a,b) ((int)((((a) & 0xff) << 8) | ((b) & 0xff)))
  51 #define NODEV MKDEV(0,0)
  52 
  53 #ifndef NULL
  54 #define NULL ((void *) 0)
  55 #endif
  56 
  57 #define NIL_FILP        ((struct file *)0)
  58 #define SEL_IN          1
  59 #define SEL_OUT         2
  60 #define SEL_EX          4
  61 
  62 /*
  63  * These are the fs-independent mount-flags: up to 16 flags are supported
  64  */
  65 #define MS_RDONLY        1 /* mount read-only */
  66 #define MS_NOSUID        2 /* ignore suid and sgid bits */
  67 #define MS_NODEV         4 /* disallow access to device special files */
  68 #define MS_NOEXEC        8 /* disallow program execution */
  69 #define MS_SYNCHRONOUS  16 /* writes are synced at once */
  70 #define MS_REMOUNT      32 /* alter flags of a mounted FS */
  71 
  72 #define S_APPEND    256 /* append-only file */
  73 #define S_IMMUTABLE 512 /* immutable file */
  74 
  75 /*
  76  * Flags that can be altered by MS_REMOUNT
  77  */
  78 #define MS_RMT_MASK (MS_RDONLY)
  79 
  80 /*
  81  * Magic mount flag number. Has to be or-ed to the flag values.
  82  */
  83 #define MS_MGC_VAL 0xC0ED0000 /* magic flag number to indicate "new" flags */
  84 #define MS_MGC_MSK 0xffff0000 /* magic flag number mask */
  85 
  86 /*
  87  * Note that read-only etc flags are inode-specific: setting some file-system
  88  * flags just means all the inodes inherit those flags by default. It might be
  89  * possible to override it selectively if you really wanted to with some
  90  * ioctl() that is not currently implemented.
  91  *
  92  * Exception: MS_RDONLY is always applied to the entire file system.
  93  */
  94 #define IS_RDONLY(inode) (((inode)->i_sb) && ((inode)->i_sb->s_flags & MS_RDONLY))
  95 #define IS_NOSUID(inode) ((inode)->i_flags & MS_NOSUID)
  96 #define IS_NODEV(inode) ((inode)->i_flags & MS_NODEV)
  97 #define IS_NOEXEC(inode) ((inode)->i_flags & MS_NOEXEC)
  98 #define IS_SYNC(inode) ((inode)->i_flags & MS_SYNCHRONOUS)
  99 
 100 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
 101 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
 102 
 103 /* the read-only stuff doesn't really belong here, but any other place is
 104    probably as bad and I don't want to create yet another include file. */
 105 
 106 #define BLKROSET 4701 /* set device read-only (0 = read-write) */
 107 #define BLKROGET 4702 /* get read-only status (0 = read_write) */
 108 #define BLKRRPART 4703 /* re-read partition table */
 109 #define BLKGETSIZE 4704 /* return device size */
 110 #define BLKFLSBUF 4705 /* flush buffer cache */
 111 #define BLKRASET 4706 /* Set read ahead for block device */
 112 #define BLKRAGET 4707 /* get current read ahead setting */
 113 
 114 #define BMAP_IOCTL 1    /* obsolete - kept for compatibility */
 115 #define FIBMAP     1    /* bmap access */
 116 #define FIGETBSZ   2    /* get the block size used for bmap */
 117 
 118 typedef char buffer_block[BLOCK_SIZE];
 119 
 120 struct buffer_head {
 121         char * b_data;                  /* pointer to data block (1024 bytes) */
 122         unsigned long b_size;           /* block size */
 123         unsigned long b_blocknr;        /* block number */
 124         dev_t b_dev;                    /* device (0 = free) */
 125         unsigned short b_count;         /* users using this block */
 126         unsigned char b_uptodate;
 127         unsigned char b_dirt;           /* 0-clean,1-dirty */
 128         unsigned char b_lock;           /* 0 - ok, 1 -locked */
 129         unsigned char b_req;            /* 0 if the buffer has been invalidated */
 130         unsigned char b_list;           /* List that this buffer appears */
 131         unsigned char b_reuse;          /* 0 - normal, 1 - better reused for something else */
 132         unsigned long b_flushtime;      /* Time when this (dirty) buffer should be written */
 133         unsigned long b_lru_time;       /* Time when this buffer was last used. */
 134         struct wait_queue * b_wait;
 135         struct buffer_head * b_prev;            /* doubly linked list of hash-queue */
 136         struct buffer_head * b_next;
 137         struct buffer_head * b_prev_free;       /* doubly linked list of buffers */
 138         struct buffer_head * b_next_free;
 139         struct buffer_head * b_this_page;       /* circular list of buffers in one page */
 140         struct buffer_head * b_reqnext;         /* request queue */
 141 };
 142 
 143 #include <linux/pipe_fs_i.h>
 144 #include <linux/minix_fs_i.h>
 145 #include <linux/ext_fs_i.h>
 146 #include <linux/ext2_fs_i.h>
 147 #include <linux/hpfs_fs_i.h>
 148 #include <linux/msdos_fs_i.h>
 149 #include <linux/umsdos_fs_i.h>
 150 #include <linux/iso_fs_i.h>
 151 #include <linux/nfs_fs_i.h>
 152 #include <linux/xia_fs_i.h>
 153 #include <linux/sysv_fs_i.h>
 154 
 155 #ifdef __KERNEL__
 156 
 157 /*
 158  * Attribute flags.  These should be or-ed together to figure out what
 159  * has been changed!
 160  */
 161 #define ATTR_MODE       1
 162 #define ATTR_UID        2
 163 #define ATTR_GID        4
 164 #define ATTR_SIZE       8
 165 #define ATTR_ATIME      16
 166 #define ATTR_MTIME      32
 167 #define ATTR_CTIME      64
 168 #define ATTR_ATIME_SET  128
 169 #define ATTR_MTIME_SET  256
 170 
 171 /*
 172  * This is the Inode Attributes structure, used for notify_change().  It
 173  * uses the above definitions as flags, to know which values have changed.
 174  * Also, in this manner, a Filesystem can look at only the values it cares
 175  * about.  Basically, these are the attributes that the VFS layer can
 176  * request to change from the FS layer.
 177  *
 178  * Derek Atkins <warlord@MIT.EDU> 94-10-20
 179  */
 180 struct iattr {
 181         unsigned int    ia_valid;
 182         umode_t         ia_mode;
 183         uid_t           ia_uid;
 184         gid_t           ia_gid;
 185         off_t           ia_size;
 186         time_t          ia_atime;
 187         time_t          ia_mtime;
 188         time_t          ia_ctime;
 189 };
 190 
 191 struct inode {
 192         dev_t           i_dev;
 193         unsigned long   i_ino;
 194         umode_t         i_mode;
 195         nlink_t         i_nlink;
 196         uid_t           i_uid;
 197         gid_t           i_gid;
 198         dev_t           i_rdev;
 199         off_t           i_size;
 200         time_t          i_atime;
 201         time_t          i_mtime;
 202         time_t          i_ctime;
 203         unsigned long   i_blksize;
 204         unsigned long   i_blocks;
 205         unsigned long   i_version;
 206         struct semaphore i_sem;
 207         struct inode_operations * i_op;
 208         struct super_block * i_sb;
 209         struct wait_queue * i_wait;
 210         struct file_lock * i_flock;
 211         struct vm_area_struct * i_mmap;
 212         struct inode * i_next, * i_prev;
 213         struct inode * i_hash_next, * i_hash_prev;
 214         struct inode * i_bound_to, * i_bound_by;
 215         struct inode * i_mount;
 216         unsigned short i_count;
 217         unsigned short i_wcount;
 218         unsigned short i_flags;
 219         unsigned char i_lock;
 220         unsigned char i_dirt;
 221         unsigned char i_pipe;
 222         unsigned char i_sock;
 223         unsigned char i_seek;
 224         unsigned char i_update;
 225         union {
 226                 struct pipe_inode_info pipe_i;
 227                 struct minix_inode_info minix_i;
 228                 struct ext_inode_info ext_i;
 229                 struct ext2_inode_info ext2_i;
 230                 struct hpfs_inode_info hpfs_i;
 231                 struct msdos_inode_info msdos_i;
 232                 struct umsdos_inode_info umsdos_i;
 233                 struct iso_inode_info isofs_i;
 234                 struct nfs_inode_info nfs_i;
 235                 struct xiafs_inode_info xiafs_i;
 236                 struct sysv_inode_info sysv_i;
 237                 struct socket socket_i;
 238                 void * generic_ip;
 239         } u;
 240 };
 241 
 242 struct file {
 243         mode_t f_mode;
 244         loff_t f_pos;
 245         unsigned short f_flags;
 246         unsigned short f_count;
 247         off_t f_reada;
 248         struct file *f_next, *f_prev;
 249         int f_owner;            /* pid or -pgrp where SIGIO should be sent */
 250         struct inode * f_inode;
 251         struct file_operations * f_op;
 252         unsigned long f_version;
 253         void *private_data;     /* needed for tty driver, and maybe others */
 254 };
 255 
 256 struct file_lock {
 257         struct file_lock *fl_next;      /* singly linked list for this inode  */
 258         struct file_lock *fl_nextlink;  /* doubly linked list of all locks */
 259         struct file_lock *fl_prevlink;  /* used to simplify lock removal */
 260         struct file_lock *fl_block;
 261         struct task_struct *fl_owner;
 262         struct wait_queue *fl_wait;
 263         struct file *fl_file;
 264         char fl_flags;
 265         char fl_type;
 266         off_t fl_start;
 267         off_t fl_end;
 268 };
 269 
 270 struct fasync_struct {
 271         int    magic;
 272         struct fasync_struct    *fa_next; /* singly linked list */
 273         struct file             *fa_file;
 274 };
 275 
 276 #define FASYNC_MAGIC 0x4601
 277 
 278 extern int fasync_helper(struct inode *, struct file *, int, struct fasync_struct **);
 279 
 280 #include <linux/minix_fs_sb.h>
 281 #include <linux/ext_fs_sb.h>
 282 #include <linux/ext2_fs_sb.h>
 283 #include <linux/hpfs_fs_sb.h>
 284 #include <linux/msdos_fs_sb.h>
 285 #include <linux/iso_fs_sb.h>
 286 #include <linux/nfs_fs_sb.h>
 287 #include <linux/xia_fs_sb.h>
 288 #include <linux/sysv_fs_sb.h>
 289 
 290 struct super_block {
 291         dev_t s_dev;
 292         unsigned long s_blocksize;
 293         unsigned char s_blocksize_bits;
 294         unsigned char s_lock;
 295         unsigned char s_rd_only;
 296         unsigned char s_dirt;
 297         struct file_system_type *s_type;
 298         struct super_operations *s_op;
 299         unsigned long s_flags;
 300         unsigned long s_magic;
 301         unsigned long s_time;
 302         struct inode * s_covered;
 303         struct inode * s_mounted;
 304         struct wait_queue * s_wait;
 305         union {
 306                 struct minix_sb_info minix_sb;
 307                 struct ext_sb_info ext_sb;
 308                 struct ext2_sb_info ext2_sb;
 309                 struct hpfs_sb_info hpfs_sb;
 310                 struct msdos_sb_info msdos_sb;
 311                 struct isofs_sb_info isofs_sb;
 312                 struct nfs_sb_info nfs_sb;
 313                 struct xiafs_sb_info xiafs_sb;
 314                 struct sysv_sb_info sysv_sb;
 315                 void *generic_sbp;
 316         } u;
 317 };
 318 
 319 /*
 320  * This is the "filldir" function type, used by readdir() to let
 321  * the kernel specify what kind of dirent layout it wants to have.
 322  * This allows the kernel to read directories into kernel space or
 323  * to have different dirent layouts depending on the binary type.
 324  */
 325 typedef int (*filldir_t)(void *, const char *, int, off_t, ino_t);
 326         
 327 struct file_operations {
 328         int (*lseek) (struct inode *, struct file *, off_t, int);
 329         int (*read) (struct inode *, struct file *, char *, int);
 330         int (*write) (struct inode *, struct file *, const char *, int);
 331         int (*readdir) (struct inode *, struct file *, void *, filldir_t);
 332         int (*select) (struct inode *, struct file *, int, select_table *);
 333         int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
 334         int (*mmap) (struct inode *, struct file *, struct vm_area_struct *);
 335         int (*open) (struct inode *, struct file *);
 336         void (*release) (struct inode *, struct file *);
 337         int (*fsync) (struct inode *, struct file *);
 338         int (*fasync) (struct inode *, struct file *, int);
 339         int (*check_media_change) (dev_t dev);
 340         int (*revalidate) (dev_t dev);
 341 };
 342 
 343 struct inode_operations {
 344         struct file_operations * default_file_ops;
 345         int (*create) (struct inode *,const char *,int,int,struct inode **);
 346         int (*lookup) (struct inode *,const char *,int,struct inode **);
 347         int (*link) (struct inode *,struct inode *,const char *,int);
 348         int (*unlink) (struct inode *,const char *,int);
 349         int (*symlink) (struct inode *,const char *,int,const char *);
 350         int (*mkdir) (struct inode *,const char *,int,int);
 351         int (*rmdir) (struct inode *,const char *,int);
 352         int (*mknod) (struct inode *,const char *,int,int,int);
 353         int (*rename) (struct inode *,const char *,int,struct inode *,const char *,int);
 354         int (*readlink) (struct inode *,char *,int);
 355         int (*follow_link) (struct inode *,struct inode *,int,int,struct inode **);
 356         int (*bmap) (struct inode *,int);
 357         void (*truncate) (struct inode *);
 358         int (*permission) (struct inode *, int);
 359         int (*smap) (struct inode *,int);
 360 };
 361 
 362 struct super_operations {
 363         void (*read_inode) (struct inode *);
 364         int (*notify_change) (struct inode *, struct iattr *);
 365         void (*write_inode) (struct inode *);
 366         void (*put_inode) (struct inode *);
 367         void (*put_super) (struct super_block *);
 368         void (*write_super) (struct super_block *);
 369         void (*statfs) (struct super_block *, struct statfs *, int);
 370         int (*remount_fs) (struct super_block *, int *, char *);
 371 };
 372 
 373 struct file_system_type {
 374         struct super_block *(*read_super) (struct super_block *, void *, int);
 375         const char *name;
 376         int requires_dev;
 377         struct file_system_type * next;
 378 };
 379 
 380 extern int register_filesystem(struct file_system_type *);
 381 extern int unregister_filesystem(struct file_system_type *);
 382 
 383 asmlinkage int sys_open(const char *, int, int);
 384 asmlinkage int sys_close(unsigned int);         /* yes, it's really unsigned */
 385 
 386 extern void kill_fasync(struct fasync_struct *fa, int sig);
 387 
 388 extern int getname(const char * filename, char **result);
 389 extern void putname(char * name);
 390 
 391 extern int register_blkdev(unsigned int, const char *, struct file_operations *);
 392 extern int unregister_blkdev(unsigned int major, const char * name);
 393 extern int blkdev_open(struct inode * inode, struct file * filp);
 394 extern struct file_operations def_blk_fops;
 395 extern struct inode_operations blkdev_inode_operations;
 396 
 397 extern int register_chrdev(unsigned int, const char *, struct file_operations *);
 398 extern int unregister_chrdev(unsigned int major, const char * name);
 399 extern int chrdev_open(struct inode * inode, struct file * filp);
 400 extern struct file_operations def_chr_fops;
 401 extern struct inode_operations chrdev_inode_operations;
 402 
 403 extern void init_fifo(struct inode * inode);
 404 
 405 extern struct file_operations connecting_fifo_fops;
 406 extern struct file_operations read_fifo_fops;
 407 extern struct file_operations write_fifo_fops;
 408 extern struct file_operations rdwr_fifo_fops;
 409 extern struct file_operations read_pipe_fops;
 410 extern struct file_operations write_pipe_fops;
 411 extern struct file_operations rdwr_pipe_fops;
 412 
 413 extern struct file_system_type *get_fs_type(const char *name);
 414 
 415 extern int fs_may_mount(dev_t dev);
 416 extern int fs_may_umount(dev_t dev, struct inode * mount_root);
 417 extern int fs_may_remount_ro(dev_t dev);
 418 
 419 extern struct file *first_file;
 420 extern int nr_files;
 421 extern struct super_block super_blocks[NR_SUPER];
 422 
 423 extern int shrink_buffers(unsigned int priority, unsigned long limit);
 424 extern void refile_buffer(struct buffer_head * buf);
 425 extern void set_writetime(struct buffer_head * buf, int flag);
 426 extern void refill_freelist(int size);
 427 
 428 extern struct buffer_head ** buffer_pages;
 429 extern int nr_buffers;
 430 extern int buffermem;
 431 extern int nr_buffer_heads;
 432 
 433 #define BUF_CLEAN 0
 434 #define BUF_UNSHARED 1 /* Buffers that were shared but are not any more */
 435 #define BUF_LOCKED 2   /* Buffers scheduled for write */
 436 #define BUF_LOCKED1 3  /* Supers, inodes */
 437 #define BUF_DIRTY 4    /* Dirty buffers, not yet scheduled for write */
 438 #define BUF_SHARED 5   /* Buffers shared */
 439 #define NR_LIST 6
 440 
 441 extern inline void mark_buffer_clean(struct buffer_head * bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 442 {
 443   if(bh->b_dirt) {
 444     bh->b_dirt = 0;
 445     if(bh->b_list == BUF_DIRTY) refile_buffer(bh);
 446   }
 447 }
 448 
 449 extern inline void mark_buffer_dirty(struct buffer_head * bh, int flag)
     /* [previous][next][first][last][top][bottom][index][help] */
 450 {
 451   if(!bh->b_dirt) {
 452     bh->b_dirt = 1;
 453     set_writetime(bh, flag);
 454     if(bh->b_list != BUF_DIRTY) refile_buffer(bh);
 455   }
 456 }
 457 
 458 
 459 extern int check_disk_change(dev_t dev);
 460 extern void invalidate_inodes(dev_t dev);
 461 extern void invalidate_buffers(dev_t dev);
 462 extern int floppy_is_wp(int minor);
 463 extern void sync_inodes(dev_t dev);
 464 extern void sync_dev(dev_t dev);
 465 extern int fsync_dev(dev_t dev);
 466 extern void sync_supers(dev_t dev);
 467 extern int bmap(struct inode * inode,int block);
 468 extern int notify_change(struct inode *, struct iattr *);
 469 extern int namei(const char * pathname, struct inode ** res_inode);
 470 extern int lnamei(const char * pathname, struct inode ** res_inode);
 471 extern int permission(struct inode * inode,int mask);
 472 extern int get_write_access(struct inode * inode);
 473 extern void put_write_access(struct inode * inode);
 474 extern int open_namei(const char * pathname, int flag, int mode,
 475         struct inode ** res_inode, struct inode * base);
 476 extern int do_mknod(const char * filename, int mode, dev_t dev);
 477 extern int do_pipe(int *);
 478 extern void iput(struct inode * inode);
 479 extern struct inode * __iget(struct super_block * sb,int nr,int crsmnt);
 480 extern struct inode * get_empty_inode(void);
 481 extern void insert_inode_hash(struct inode *);
 482 extern void clear_inode(struct inode *);
 483 extern struct inode * get_pipe_inode(void);
 484 extern struct file * get_empty_filp(void);
 485 extern int close_fp(struct file *filp);
 486 extern struct buffer_head * get_hash_table(dev_t dev, int block, int size);
 487 extern struct buffer_head * getblk(dev_t dev, int block, int size);
 488 extern void ll_rw_block(int rw, int nr, struct buffer_head * bh[]);
 489 extern void ll_rw_page(int rw, int dev, unsigned long nr, char * buffer);
 490 extern void ll_rw_swap_file(int rw, int dev, unsigned int *b, int nb, char *buffer);
 491 extern int is_read_only(int dev);
 492 extern void brelse(struct buffer_head * buf);
 493 extern void set_blocksize(dev_t dev, int size);
 494 extern struct buffer_head * bread(dev_t dev, int block, int size);
 495 extern unsigned long bread_page(unsigned long addr,dev_t dev,int b[],int size,int no_share);
 496 extern void bwrite_page(unsigned long addr,dev_t dev,int b[],int size);
 497 extern struct buffer_head * breada(dev_t dev,int block, int size, 
 498                                    unsigned int pos, unsigned int filesize);
 499 extern void put_super(dev_t dev);
 500 unsigned long generate_cluster(dev_t dev, int b[], int size);
 501 extern dev_t ROOT_DEV;
 502 
 503 extern void show_buffers(void);
 504 extern void mount_root(void);
 505 
 506 extern int char_read(struct inode *, struct file *, char *, int);
 507 extern int block_read(struct inode *, struct file *, char *, int);
 508 extern int read_ahead[];
 509 
 510 extern int char_write(struct inode *, struct file *, const char *, int);
 511 extern int block_write(struct inode *, struct file *, const char *, int);
 512 
 513 extern int generic_mmap(struct inode *, struct file *, struct vm_area_struct *);
 514 
 515 extern int block_fsync(struct inode *, struct file *);
 516 extern int file_fsync(struct inode *, struct file *);
 517 
 518 extern void dcache_add(struct inode *, const char *, int, unsigned long);
 519 extern int dcache_lookup(struct inode *, const char *, int, unsigned long *);
 520 
 521 extern int inode_change_ok(struct inode *, struct iattr *);
 522 extern void inode_setattr(struct inode *, struct iattr *);
 523 
 524 extern inline struct inode * iget(struct super_block * sb,int nr)
     /* [previous][next][first][last][top][bottom][index][help] */
 525 {
 526         return __iget(sb,nr,1);
 527 }
 528 
 529 #endif /* __KERNEL__ */
 530 
 531 #endif

/* [previous][next][first][last][top][bottom][index][help] */