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

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