fs.h

Go to the documentation of this file.
00001 #ifndef _LINUX_FS_H
00002 #define _LINUX_FS_H
00003 
00004 /**
00005 *
00006 
00007  * This file has definitions for some important file table
00008  * structures etc.
00009 
00010 
00011 */
00012 
00013 #include <linux/linkage.h>
00014 #include <linux/limits.h>
00015 #include <linux/wait.h>
00016 #include <linux/types.h>
00017 #include <linux/dirent.h>
00018 #include <linux/vfs.h>
00019 #include <linux/net.h>
00020 
00021 /**
00022 *
00023 
00024  * It's silly to have NR_OPEN bigger than NR_FILE, but I'll fix
00025  * that later. Anyway, now the file code is no longer dependent
00026  * on bitmaps in unsigned longs, but uses the new fd_set structure..
00027  *
00028  * Some programs (notably those using select()) may have to be 
00029  * recompiled to take full advantage of the new limits..
00030 
00031 
00032 */
00033 #undef NR_OPEN
00034 #define NR_OPEN 256
00035 
00036 #define NR_INODE 2048   ///< this should be bigger than NR_FILE 
00037 #define NR_FILE 1024    ///< this can well be larger on a larger system 
00038 #define NR_SUPER 32
00039 #define NR_HASH 997
00040 #define NR_IHASH 131
00041 #define NR_FILE_LOCKS 64
00042 #define BLOCK_SIZE 1024
00043 #define BLOCK_SIZE_BITS 10
00044 
00045 #define MAY_EXEC 1
00046 #define MAY_WRITE 2
00047 #define MAY_READ 4
00048 
00049 #define READ 0
00050 #define WRITE 1
00051 #define READA 2         ///< read-ahead - don't pause 
00052 #define WRITEA 3        ///< "write-ahead" - silly, but somewhat useful 
00053 
00054 extern void buffer_init(void);
00055 extern unsigned long inode_init(unsigned long start, unsigned long end);
00056 extern unsigned long file_table_init(unsigned long start, unsigned long end);
00057 
00058 #define MAJOR(a) (int)((unsigned short)(a) >> 8)
00059 #define MINOR(a) (int)((unsigned short)(a) & 0xFF)
00060 #define MKDEV(a,b) ((int)((((a) & 0xff) << 8) | ((b) & 0xff)))
00061 
00062 #ifndef NULL
00063 #define NULL ((void *) 0)
00064 #endif
00065 
00066 #define NIL_FILP        ((struct file *)0)
00067 #define SEL_IN          1
00068 #define SEL_OUT         2
00069 #define SEL_EX          4
00070 
00071 /**
00072 *
00073 
00074  * These are the fs-independent mount-flags: up to 16 flags are supported
00075 
00076 
00077 */
00078 #define MS_RDONLY    1 ///< mount read-only 
00079 #define MS_NOSUID    2 ///< ignore suid and sgid bits 
00080 #define MS_NODEV     4 ///< disallow access to device special files 
00081 #define MS_NOEXEC    8 ///< disallow program execution 
00082 #define MS_SYNC     16 ///< writes are synced at once 
00083 #define MS_REMOUNT  32 ///< alter flags of a mounted FS 
00084 
00085 /**
00086 *
00087 
00088  * Flags that can be altered by MS_REMOUNT
00089 
00090 
00091 */
00092 #define MS_RMT_MASK (MS_RDONLY)
00093 
00094 /**
00095 *
00096 
00097  * Magic mount flag number. Has to be or-ed to the flag values.
00098 
00099 
00100 */
00101 #define MS_MGC_VAL 0xC0ED0000 ///< magic flag number to indicate "new" flags 
00102 #define MS_MGC_MSK 0xffff0000 ///< magic flag number mask 
00103 
00104 /**
00105 *
00106 
00107  * Note that read-only etc flags are inode-specific: setting some file-system
00108  * flags just means all the inodes inherit those flags by default. It might be
00109  * possible to overrride it sevelctively if you really wanted to with some
00110  * ioctl() that is not currently implemented.
00111  *
00112  * Exception: MS_RDONLY is always applied to the entire file system.
00113 
00114 
00115 */
00116 #define IS_RDONLY(inode) (((inode)->i_sb) && ((inode)->i_sb->s_flags & MS_RDONLY))
00117 #define IS_NOSUID(inode) ((inode)->i_flags & MS_NOSUID)
00118 #define IS_NODEV(inode) ((inode)->i_flags & MS_NODEV)
00119 #define IS_NOEXEC(inode) ((inode)->i_flags & MS_NOEXEC)
00120 #define IS_SYNC(inode) ((inode)->i_flags & MS_SYNC)
00121 
00122 /**
00123 *
00124  the read-only stuff doesn't really belong here, but any other place is
00125 
00126 
00127 */
00128 
00129 #define BLKROSET 4701 ///< set device read-only (0 = read-write) 
00130 #define BLKROGET 4702 ///< get read-only status (0 = read_write) 
00131 #define BLKRRPART 4703 ///< re-read partition table 
00132 #define BLKGETSIZE 4704 ///< return device size 
00133 #define BLKFLSBUF 4705 ///< flush buffer cache 
00134 
00135 /// These are a few other constants  only used by scsi  devices 
00136 
00137 #define SCSI_IOCTL_GET_IDLUN 0x5382
00138 
00139 /// Used to turn on and off tagged queueing for scsi devices 
00140 
00141 #define SCSI_IOCTL_TAGGED_ENABLE 0x5383
00142 #define SCSI_IOCTL_TAGGED_DISABLE 0x5384
00143 
00144 
00145 #define BMAP_IOCTL 1    ///< obsolete - kept for compatibility 
00146 #define FIBMAP     1    ///< bmap access 
00147 #define FIGETBSZ   2    ///< get the block size used for bmap 
00148 
00149 /// these flags tell notify_change what is being changed 
00150 
00151 #define NOTIFY_SIZE     1
00152 #define NOTIFY_MODE     2
00153 #define NOTIFY_TIME     4
00154 #define NOTIFY_UIDGID   8
00155 
00156 typedef char buffer_block[BLOCK_SIZE];
00157 
00158 struct buffer_head {
00159         char * b_data;                  ///< pointer to data block (1024 bytes) 
00160         unsigned long b_size;           ///< block size 
00161         unsigned long b_blocknr;        ///< block number 
00162         dev_t b_dev;                    ///< device (0 = free) 
00163         unsigned short b_count;         ///< users using this block 
00164         unsigned char b_uptodate;
00165         unsigned char b_dirt;           ///< 0-clean,1-dirty 
00166         unsigned char b_lock;           ///< 0 - ok, 1 -locked 
00167         unsigned char b_req;            ///< 0 if the buffer has been invalidated 
00168         struct wait_queue * b_wait;
00169         struct buffer_head * b_prev;            ///< doubly linked list of hash-queue 
00170         struct buffer_head * b_next;
00171         struct buffer_head * b_prev_free;       ///< doubly linked list of buffers 
00172         struct buffer_head * b_next_free;
00173         struct buffer_head * b_this_page;       ///< circular list of buffers in one page 
00174         struct buffer_head * b_reqnext;         ///< request queue 
00175 };
00176 
00177 #include <linux/pipe_fs_i.h>
00178 #include <linux/minix_fs_i.h>
00179 #include <linux/ext_fs_i.h>
00180 #include <linux/ext2_fs_i.h>
00181 #include <linux/hpfs_fs_i.h>
00182 #include <linux/msdos_fs_i.h>
00183 #include <linux/iso_fs_i.h>
00184 #include <linux/nfs_fs_i.h>
00185 #include <linux/xia_fs_i.h>
00186 #include <linux/sysv_fs_i.h>
00187 
00188 struct inode {
00189         dev_t           i_dev;
00190         unsigned long   i_ino;
00191         umode_t         i_mode;
00192         nlink_t         i_nlink;
00193         uid_t           i_uid;
00194         gid_t           i_gid;
00195         dev_t           i_rdev;
00196         off_t           i_size;
00197         time_t          i_atime;
00198         time_t          i_mtime;
00199         time_t          i_ctime;
00200         unsigned long   i_blksize;
00201         unsigned long   i_blocks;
00202         struct semaphore i_sem;
00203         struct inode_operations * i_op;
00204         struct super_block * i_sb;
00205         struct wait_queue * i_wait;
00206         struct file_lock * i_flock;
00207         struct vm_area_struct * i_mmap;
00208         struct inode * i_next, * i_prev;
00209         struct inode * i_hash_next, * i_hash_prev;
00210         struct inode * i_bound_to, * i_bound_by;
00211         struct inode * i_mount;
00212         struct socket * i_socket;
00213         unsigned short i_count;
00214         unsigned short i_flags;
00215         unsigned char i_lock;
00216         unsigned char i_dirt;
00217         unsigned char i_pipe;
00218         unsigned char i_seek;
00219         unsigned char i_update;
00220         union {
00221                 struct pipe_inode_info pipe_i;
00222                 struct minix_inode_info minix_i;
00223                 struct ext_inode_info ext_i;
00224                 struct ext2_inode_info ext2_i;
00225                 struct hpfs_inode_info hpfs_i;
00226                 struct msdos_inode_info msdos_i;
00227                 struct iso_inode_info isofs_i;
00228                 struct nfs_inode_info nfs_i;
00229                 struct xiafs_inode_info xiafs_i;
00230                 struct sysv_inode_info sysv_i;
00231         } u;
00232 };
00233 
00234 struct file {
00235         mode_t f_mode;
00236         dev_t f_rdev;                   ///< needed for /dev/tty 
00237         off_t f_pos;
00238         unsigned short f_flags;
00239         unsigned short f_count;
00240         unsigned short f_reada;
00241         struct file *f_next, *f_prev;
00242         struct inode * f_inode;
00243         struct file_operations * f_op;
00244 };
00245 
00246 struct file_lock {
00247         struct file_lock *fl_next;      ///< singly linked list 
00248         struct task_struct *fl_owner;   ///< NULL if on free list, for sanity checks 
00249         unsigned int fl_fd;             ///< File descriptor for this lock 
00250         struct wait_queue *fl_wait;
00251         char fl_type;
00252         char fl_whence;
00253         off_t fl_start;
00254         off_t fl_end;
00255 };
00256 
00257 #include <linux/minix_fs_sb.h>
00258 #include <linux/ext_fs_sb.h>
00259 #include <linux/ext2_fs_sb.h>
00260 #include <linux/hpfs_fs_sb.h>
00261 #include <linux/msdos_fs_sb.h>
00262 #include <linux/iso_fs_sb.h>
00263 #include <linux/nfs_fs_sb.h>
00264 #include <linux/xia_fs_sb.h>
00265 #include <linux/sysv_fs_sb.h>
00266 
00267 struct super_block {
00268         dev_t s_dev;
00269         unsigned long s_blocksize;
00270         unsigned char s_blocksize_bits;
00271         unsigned char s_lock;
00272         unsigned char s_rd_only;
00273         unsigned char s_dirt;
00274         struct super_operations *s_op;
00275         unsigned long s_flags;
00276         unsigned long s_magic;
00277         unsigned long s_time;
00278         struct inode * s_covered;
00279         struct inode * s_mounted;
00280         struct wait_queue * s_wait;
00281         union {
00282                 struct minix_sb_info minix_sb;
00283                 struct ext_sb_info ext_sb;
00284                 struct ext2_sb_info ext2_sb;
00285                 struct hpfs_sb_info hpfs_sb;
00286                 struct msdos_sb_info msdos_sb;
00287                 struct isofs_sb_info isofs_sb;
00288                 struct nfs_sb_info nfs_sb;
00289                 struct xiafs_sb_info xiafs_sb;
00290                 struct sysv_sb_info sysv_sb;
00291         } u;
00292 };
00293 
00294 struct file_operations {
00295         int (*lseek) (struct inode *, struct file *, off_t, int);
00296         int (*read) (struct inode *, struct file *, char *, int);
00297         int (*write) (struct inode *, struct file *, char *, int);
00298         int (*readdir) (struct inode *, struct file *, struct dirent *, int);
00299         int (*select) (struct inode *, struct file *, int, select_table *);
00300         int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
00301         int (*mmap) (struct inode *, struct file *, unsigned long, size_t, int, unsigned long);
00302         int (*open) (struct inode *, struct file *);
00303         void (*release) (struct inode *, struct file *);
00304         int (*fsync) (struct inode *, struct file *);
00305 };
00306 
00307 struct inode_operations {
00308         struct file_operations * default_file_ops;
00309         int (*create) (struct inode *,const char *,int,int,struct inode **);
00310         int (*lookup) (struct inode *,const char *,int,struct inode **);
00311         int (*link) (struct inode *,struct inode *,const char *,int);
00312         int (*unlink) (struct inode *,const char *,int);
00313         int (*symlink) (struct inode *,const char *,int,const char *);
00314         int (*mkdir) (struct inode *,const char *,int,int);
00315         int (*rmdir) (struct inode *,const char *,int);
00316         int (*mknod) (struct inode *,const char *,int,int,int);
00317         int (*rename) (struct inode *,const char *,int,struct inode *,const char *,int);
00318         int (*readlink) (struct inode *,char *,int);
00319         int (*follow_link) (struct inode *,struct inode *,int,int,struct inode **);
00320         int (*bmap) (struct inode *,int);
00321         void (*truncate) (struct inode *);
00322         int (*permission) (struct inode *, int);
00323 };
00324 
00325 struct super_operations {
00326         void (*read_inode) (struct inode *);
00327         int (*notify_change) (int flags, struct inode *);
00328         void (*write_inode) (struct inode *);
00329         void (*put_inode) (struct inode *);
00330         void (*put_super) (struct super_block *);
00331         void (*write_super) (struct super_block *);
00332         void (*statfs) (struct super_block *, struct statfs *);
00333         int (*remount_fs) (struct super_block *, int *, char *);
00334 };
00335 
00336 struct file_system_type {
00337         struct super_block *(*read_super) (struct super_block *, void *, int);
00338         char *name;
00339         int requires_dev;
00340 };
00341 
00342 #ifdef __KERNEL__
00343 
00344 asmlinkage int sys_open(const char *, int, int);
00345 asmlinkage int sys_close(unsigned int);         ///< yes, it's really unsigned 
00346 
00347 extern int getname(const char * filename, char **result);
00348 extern void putname(char * name);
00349 
00350 extern int register_blkdev(unsigned int, const char *, struct file_operations *);
00351 extern int unregister_blkdev(unsigned int major, const char * name);
00352 extern int blkdev_open(struct inode * inode, struct file * filp);
00353 extern struct file_operations def_blk_fops;
00354 extern struct inode_operations blkdev_inode_operations;
00355 
00356 extern int register_chrdev(unsigned int, const char *, struct file_operations *);
00357 extern int unregister_chrdev(unsigned int major, const char * name);
00358 extern int chrdev_open(struct inode * inode, struct file * filp);
00359 extern struct file_operations def_chr_fops;
00360 extern struct inode_operations chrdev_inode_operations;
00361 
00362 extern void init_fifo(struct inode * inode);
00363 
00364 extern struct file_operations connecting_fifo_fops;
00365 extern struct file_operations read_fifo_fops;
00366 extern struct file_operations write_fifo_fops;
00367 extern struct file_operations rdwr_fifo_fops;
00368 extern struct file_operations read_pipe_fops;
00369 extern struct file_operations write_pipe_fops;
00370 extern struct file_operations rdwr_pipe_fops;
00371 
00372 extern struct file_system_type *get_fs_type(char *name);
00373 
00374 extern int fs_may_mount(dev_t dev);
00375 extern int fs_may_umount(dev_t dev, struct inode * mount_root);
00376 extern int fs_may_remount_ro(dev_t dev);
00377 
00378 extern struct file *first_file;
00379 extern int nr_files;
00380 extern struct super_block super_blocks[NR_SUPER];
00381 
00382 extern int shrink_buffers(unsigned int priority);
00383 
00384 extern int nr_buffers;
00385 extern int buffermem;
00386 extern int nr_buffer_heads;
00387 
00388 extern void check_disk_change(dev_t dev);
00389 extern void invalidate_inodes(dev_t dev);
00390 extern void invalidate_buffers(dev_t dev);
00391 extern int floppy_change(struct buffer_head * first_block);
00392 extern void sync_inodes(dev_t dev);
00393 extern void sync_dev(dev_t dev);
00394 extern int fsync_dev(dev_t dev);
00395 extern void sync_supers(dev_t dev);
00396 extern int bmap(struct inode * inode,int block);
00397 extern int notify_change(int flags, struct inode * inode);
00398 extern int namei(const char * pathname, struct inode ** res_inode);
00399 extern int lnamei(const char * pathname, struct inode ** res_inode);
00400 extern int permission(struct inode * inode,int mask);
00401 extern int open_namei(const char * pathname, int flag, int mode,
00402         struct inode ** res_inode, struct inode * base);
00403 extern int do_mknod(const char * filename, int mode, dev_t dev);
00404 extern void iput(struct inode * inode);
00405 extern struct inode * __iget(struct super_block * sb,int nr,int crsmnt);
00406 extern struct inode * iget(struct super_block * sb,int nr);
00407 extern struct inode * get_empty_inode(void);
00408 extern void insert_inode_hash(struct inode *);
00409 extern void clear_inode(struct inode *);
00410 extern struct inode * get_pipe_inode(void);
00411 extern struct file * get_empty_filp(void);
00412 extern struct buffer_head * get_hash_table(dev_t dev, int block, int size);
00413 extern struct buffer_head * getblk(dev_t dev, int block, int size);
00414 extern void ll_rw_block(int rw, int nr, struct buffer_head * bh[]);
00415 extern void ll_rw_page(int rw, int dev, int nr, char * buffer);
00416 extern void ll_rw_swap_file(int rw, int dev, unsigned int *b, int nb, char *buffer);
00417 extern void brelse(struct buffer_head * buf);
00418 extern void set_blocksize(dev_t dev, int size);
00419 extern struct buffer_head * bread(dev_t dev, int block, int size);
00420 extern unsigned long bread_page(unsigned long addr,dev_t dev,int b[],int size,int prot);
00421 extern struct buffer_head * breada(dev_t dev,int block,...);
00422 extern void put_super(dev_t dev);
00423 extern dev_t ROOT_DEV;
00424 
00425 extern void show_buffers(void);
00426 extern void mount_root(void);
00427 
00428 extern int char_read(struct inode *, struct file *, char *, int);
00429 extern int block_read(struct inode *, struct file *, char *, int);
00430 extern int read_ahead[];
00431 
00432 extern int char_write(struct inode *, struct file *, char *, int);
00433 extern int block_write(struct inode *, struct file *, char *, int);
00434 
00435 extern int generic_mmap(struct inode *, struct file *, unsigned long, size_t, int, unsigned long);
00436 
00437 extern int block_fsync(struct inode *, struct file *);
00438 extern int file_fsync(struct inode *, struct file *);
00439 
00440 #endif // __KERNEL__ 
00441 
00442 #endif

Generated on Mon May 1 21:47:00 2006 for KernelAPI by  doxygen 1.4.6-5