ext2文件系统源代码之ext2.h
2016-03-16 15:09
281 查看
今天,我们看一下ext2文件系统源代码里面的ext2.h文件,这是一个头文件,里边都是一些函数的声明和一些结构体的定义,很多引用ext2的函数的地方都需要包含这个头文件,所以这个头文件用处是很广泛的,但是这个文件很简单,并且还很短,这就让我们理解变得很轻松了。
#include <linux/fs.h> #include <linux/ext2_fs.h> /*ext2挂载选项结构体*/ struct ext2_mount_options { /*挂载选项位图*/ unsigned long s_mount_opt; /*保存用户id和保存组id*/ uid_t s_resuid; gid_t s_resgid; }; /*在内存里的ext2文件系统的inode信息数据*/ struct ext2_inode_info { __le32 i_data[15]; __u32 i_flags; __u32 i_faddr; __u8 i_frag_no; __u8 i_frag_size; __u16 i_state; __u32 i_file_acl; __u32 i_dir_acl; __u32 i_dtime; /*i_block_group是这个文件的inode所在的块组号码,ext2文件系统分配block的时候尽量使得block和他的inode在一个块组,分配inode的时候尽量使得inode和它的父目录的inode在一个块组 */ __u32 i_block_group; /*i_next_alloc_block记录最近分配的块的逻辑编号,这个名字取得不是很好 */ __u32 i_next_alloc_block; /*i_next_alloc_goal记录最近分配的块的物理编号,这个变量给了我们下一次分配的优先位置*/ __u32 i_next_alloc_goal; __u32 i_prealloc_block; __u32 i_prealloc_count; __u32 i_dir_start_lookup; /*配置了CONFIG_EXT2_FS_XATTR宏才会有的属性操作的信号量*/ #ifdef CONFIG_EXT2_FS_XATTR struct rw_semaphore xattr_sem; #endif /*配置了CONFIG_EXT2_FS_POSIX_ACL宏才会有的属性操作的acl操作结构体,之前讲过的哦*/ #ifdef CONFIG_EXT2_FS_POSIX_ACL struct posix_acl *i_acl; struct posix_acl *i_default_acl; #endif rwlock_t i_meta_lock; /*我们一般用到的inode结构体就是这个*/ struct inode vfs_inode; }; /*ext2的标记位,这个标识ext2刚刚建立*/ #define EXT2_STATE_NEW 0x00000001 /* inode is newly created */ /*从inode结构体获得ext2_inode_info的函数,直接通过container_of宏,上边我们刚讲过,vfs_inode就是此处的inode*/ static inline struct ext2_inode_info *EXT2_I(struct inode *inode) { return container_of(inode, struct ext2_inode_info, vfs_inode); } /* balloc.c的函数声明,我们都讲过的哦 */ extern int ext2_bg_has_super(struct super_block *sb, int group); extern unsigned long ext2_bg_num_gdb(struct super_block *sb, int group); extern int ext2_new_block (struct inode *, unsigned long, __u32 *, __u32 *, int *); extern void ext2_free_blocks (struct inode *, unsigned long, unsigned long); extern unsigned long ext2_count_free_blocks (struct super_block *); extern unsigned long ext2_count_dirs (struct super_block *); extern void ext2_check_blocks_bitmap (struct super_block *); extern struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb, unsigned int block_group, struct buffer_head ** bh); /* dir.c的函数声明,我们都讲过的哦 */ extern int ext2_add_link (struct dentry *, struct inode *); extern ino_t ext2_inode_by_name(struct inode *, struct dentry *); extern int ext2_make_empty(struct inode *, struct inode *); extern struct ext2_dir_entry_2 * ext2_find_entry (struct inode *,struct dentry *, struct page **); extern int ext2_delete_entry (struct ext2_dir_entry_2 *, struct page *); extern int ext2_empty_dir (struct inode *); extern struct ext2_dir_entry_2 * ext2_dotdot (struct inode *, struct page **); extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, struct inode *); /* fsync.c 的函数声明*/ extern int ext2_sync_file (struct file *, struct dentry *, int); /* ialloc.c的函数声明 */ extern struct inode * ext2_new_inode (struct inode *, int); extern void ext2_free_inode (struct inode *); extern unsigned long ext2_count_free_inodes (struct super_block *); extern void ext2_check_inodes_bitmap (struct super_block *); extern unsigned long ext2_count_free (struct buffer_head *, unsigned); /* inode.c的函数声明 */ extern void ext2_read_inode (struct inode *); extern int ext2_write_inode (struct inode *, int); extern void ext2_put_inode (struct inode *); extern void ext2_delete_inode (struct inode *); extern int ext2_sync_inode (struct inode *); extern void ext2_discard_prealloc (struct inode *); extern int ext2_get_block(struct inode *, sector_t, struct buffer_head *, int); extern void ext2_truncate (struct inode *); extern int ext2_setattr (struct dentry *, struct iattr *); extern void ext2_set_inode_flags(struct inode *inode); extern void ext2_get_inode_flags(struct ext2_inode_info *); /* ioctl.c的函数声明 */ extern int ext2_ioctl (struct inode *, struct file *, unsigned int, unsigned long); extern long ext2_compat_ioctl(struct file *, unsigned int, unsigned long); /* namei.c的函数声明 */ struct dentry *ext2_get_parent(struct dentry *child); /* super.c的函数声明 */ extern void ext2_error (struct super_block *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4))); extern void ext2_warning (struct super_block *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4))); extern void ext2_update_dynamic_rev (struct super_block *sb); extern void ext2_write_super (struct super_block *); /* * Inodes和files结构体的函数操作结构体集合 */ /* dir.c文件里的*/ extern const struct file_operations ext2_dir_operations; /* file.c文件里的 */ extern const struct inode_operations ext2_file_inode_operations; extern const struct file_operations ext2_file_operations; extern const struct file_operations ext2_xip_file_operations; /* inode.c文件里的 */ extern const struct address_space_operations ext2_aops; extern const struct address_space_operations ext2_aops_xip; extern const struct address_space_operations ext2_nobh_aops; /* namei.c文件里的 */ extern const struct inode_operations ext2_dir_inode_operations; extern const struct inode_operations ext2_special_inode_operations; /* symlink.c文件里的 */ extern const struct inode_operations ext2_fast_symlink_inode_operations; extern const struct inode_operations ext2_symlink_inode_operations;
相关文章推荐