📄 fs.h.txt
字号:
any question,send email to netxiong@263.net
相关文件:
/fs/block_dev.c
/fs/buffer.c
struct super_block {
struct list_head s_list; //连接所有的super_block结构
kdev_t s_dev;
unsigned long s_blocksize; //块大小
unsigned char s_blocksize_bits;
unsigned char s_dirt;
unsigned long long s_maxbytes; /* 文件的最大长度 字节计算 */
struct file_system_type *s_type; //文件类型
struct super_operations *s_op;
struct dquot_operations *dq_op;
unsigned long s_flags;
unsigned long s_magic; //文件魔数
struct dentry *s_root;
struct rw_semaphore s_umount;
struct semaphore s_lock;
int s_count;
atomic_t s_active;
struct list_head s_dirty; /* dirty inodes */
struct list_head s_locked_inodes;/* inodes being synced */
struct list_head s_files;
struct block_device *s_bdev;
struct list_head s_instances;
struct quota_info s_dquot; /* Diskquota specific options */
union {
struct minix_sb_info minix_sb;
struct ext2_sb_info ext2_sb; //各种文件系统的联合
struct ext3_sb_info ext3_sb;
……
} u;
struct semaphore s_vfs_rename_sem; /* Kludge */
struct semaphore s_nfsd_free_path_sem;
};
struct nameidata {
struct dentry *dentry; //路径名称所对应的dentry结构,也就是这个路径的换存
struct vfsmount *mnt; //这个路径所对应的文件系统的vfsmount结构(如果有一个文件系统安装的话)
struct qstr last;
unsigned int flags;
int last_type;
};
struct file {
struct list_head f_list;
struct dentry *f_dentry;
struct vfsmount *f_vfsmnt;
struct file_operations *f_op;
atomic_t f_count;
unsigned int f_flags;
mode_t f_mode;
loff_t f_pos; //文件的读写指针(?)
unsigned long f_reada, f_ramax, f_raend, f_ralen, f_rawin;
struct fown_struct f_owner;
unsigned int f_uid, f_gid;
int f_error;
unsigned long f_version;
/* needed for tty driver, and maybe others */
void *private_data;
/* preallocated helper kiobuf to speedup O_DIRECT */
struct kiobuf *f_iobuf;
long f_iobuf_lock;
};
//这个结构主要用于描述inode节点的状态的
struct inodes_stat_t {
int nr_inodes; //inode节点的总数量
int nr_unused; //没有使用的inode节点的数目
int dummy[5];
};
extern struct inodes_stat_t inodes_stat;
struct inode {
struct list_head i_hash;
struct list_head i_list;
struct list_head i_dentry;
struct list_head i_dirty_buffers;
struct list_head i_dirty_data_buffers;
unsigned long i_ino; //标志inode的唯一号码
atomic_t i_count; //访问计数
kdev_t i_dev; //所在的设备
umode_t i_mode;
nlink_t i_nlink;
uid_t i_uid;
gid_t i_gid;
kdev_t i_rdev;
loff_t i_size; //文件的当前大小
time_t i_atime; //最后一次访问时间
time_t i_mtime; //最后一次修改时间
time_t i_ctime; //最初创建时间
unsigned int i_blkbits;
unsigned long i_blksize;
unsigned long i_blocks;
unsigned long i_version;
unsigned short i_bytes;
struct semaphore i_sem;
struct semaphore i_zombie;
struct inode_operations *i_op; //inode操作函数集
struct file_operations *i_fop; //对应的文件操作集
struct super_block *i_sb;
wait_queue_head_t i_wait;
struct file_lock *i_flock;
struct address_space *i_mapping; //这个指针就是指向下面的i_data属性
struct address_space i_data; //主要的文件缓冲操作属性
struct dquot *i_dquot[MAXQUOTAS];
/* These three should probably be a union */
struct list_head i_devices;
struct pipe_inode_info *i_pipe;
struct block_device *i_bdev;
struct char_device *i_cdev;
unsigned long i_dnotify_mask; /* Directory notify events */
struct dnotify_struct *i_dnotify; /* for directory notifications */
unsigned long i_state;
unsigned int i_flags;
unsigned char i_sock;
atomic_t i_writecount;
unsigned int i_attr_flags;
__u32 i_generation;
union {
struct minix_inode_info minix_i;
struct ext2_inode_info ext2_i;
struct ext3_inode_info ext3_i;
struct hpfs_inode_info hpfs_i;
struct ntfs_inode_info ntfs_i;
struct msdos_inode_info msdos_i;
struct umsdos_inode_info umsdos_i;
……
}u;
}
struct address_space {
struct list_head clean_pages; /* list of clean pages */
struct list_head dirty_pages; /* list of dirty pages */
struct list_head locked_pages; /* list of locked pages */
unsigned long nrpages; /* number of total pages */
struct address_space_operations *a_ops; /* methods */
struct inode *host; /* owner: inode, block_device */
struct vm_area_struct *i_mmap; /* list of private mappings */
struct vm_area_struct *i_mmap_shared; /* list of shared mappings */
spinlock_t i_shared_lock; /* and spinlock protecting it */
int gfp_mask; /* how to allocate the pages */
};
**************************基本数据结构***************************
(1)struct block_device_operations {
int (*open) (struct inode *, struct file *);
int (*release) (struct inode *, struct file *);
int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
int (*check_media_change) (kdev_t);
int (*revalidate) (kdev_t);
};
这个结构用于块设备blkdevs(block_dev.c中)的操作,从2.4以后,不再有write,read等操作。
(2)struct buffer_head {
struct buffer_head *b_next; /* Hash 请求链表的连接指针 */
unsigned long b_blocknr; /* 在设备上的块号 */
unsigned short b_size; /* 块大小 */
unsigned short b_list; /* List that this buffer appears */
kdev_t b_dev; /* 设备号 (B_FREE = free) */
atomic_t b_count; /* 用户使用计数 */
kdev_t b_rdev; /* 真实的设备 */
unsigned long b_state; /* buffer state bitmap (see above) */
unsigned long b_flushtime; /* Time when (dirty) buffer should be witten */
struct buffer_head *b_next_free;/* lru/free list linkage */
struct buffer_head *b_prev_free;/* doubly linked list of buffers */
struct buffer_head *b_this_page;/* 一个环形指针链,用来连接在一个内存页面中的buffer */
struct buffer_head *b_reqnext; /* request queue */
struct buffer_head **b_pprev; /* doubly linked list of hash-queue */
char * b_data; /* pointer to data block */
struct page *b_page; /* 这个buffer所在的那个内存页面的结构 */
void (*b_end_io)(struct buffer_head *bh, int uptodate); /* I/O completin */
void *b_private; /* reserved for b_end_io */
unsigned long b_rsector; /* Real buffer location on disk */
wait_queue_head_t b_wait;
struct inode * b_inode;
struct list_head b_inode_buffers; /* doubly linked list of inode dirty buffers */
};
*****************************************************************
***************************buffer基本定义************************
这里定义的这些类型,是用于/fs/buffer.c中的,用来定义buffer的种类。
#define BUF_CLEAN0
#define BUF_LOCKED 1 /* Buffers scheduled for write */
#define BUF_DIRTY 2 /* Dirty buffers, not yet scheduled for write */
#define BUF_PROTECTED 3 /* Ramdisk persistent storage */
#define NR_LIST 4
实际上以下的这些宏定义都是返回相应的buffer的状态
#define __buffer_state(bh,state) (((bh)->b_state & (1UL<<H_##state)) != 0)
#define buffer_uptodate(bh) __buffer_state(bh,Uptodate)
#define buffer_dirty(bh) __buffer_state(bh,Dirty)
#define buffer_locked(bh) __buffer_state(bh,Lock)
#define buffer_req(bh) __buffer_state(bh,Req)
#define buffer_mapped(bh) __buffer_state(bh,Mapped)
#define buffer_new(bh) __buffer_state(bh,New)
#define buffer_protected(bh) __buffer_state(bh,Protected)
#define BH_Uptodate 0 /* 1 如果buffer包含有效数据*/
#define BH_Dirty 1 /* 1 如果buffer脏 */
#define BH_Lock 2 /* 1 如果buffer被锁定*/
#define BH_Req 3 /* 0 如果buffer已经无效 */
#define BH_Mapped 4 /* 1 如果buffer有disk mapping */
#define BH_New 5 /* 1 如果buffer是新的并且没有被写过*/
以上的一组定义的作用是buffer的一系列状态
*****************************************************************
*********************读写状态的定义******************************
#define READ 0 //读命令
#define WRITE 1 //写命令
#define READA 2
*****************************************************************
*********************buffer的状态设置*****************************
static inline void mark_buffer_uptodate(struct buffer_head * bh, int on)
if (on)
set_bit(BH_Uptodate, &bh->b_state);
else
clear_bit(BH_Uptodate, &bh->b_state);
对bh按照参数进行设置
******************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -