2008年04月29日

Makefile:

TEXT:
  1. #
  2. # Makefile for the linux -filesystem routines.
  3. #
  4.  
  5. obj-$(CONFIG_EXT2_FS) += .o
  6.  
  7. -y := balloc.o dir.o file.o fsync.o ialloc.o inode.o \
  8.           ioctl.o namei.o super.o symlink.o
  9.  
  10. -$(CONFIG_EXT2_FS_XATTR)     += xattr.o xattr_user.o xattr_trusted.o
  11. -$(CONFIG_EXT2_FS_POSIX_ACL) += acl.o
  12. -$(CONFIG_EXT2_FS_SECURITY)  += xattr_security.o
  13. -$(CONFIG_EXT2_FS_XIP)       += xip.o

obj-$(CONFIG_EXT2_FS)指定编译生成的目标文件,CONFIG_EXT2_FS变量在配置内核时指定,有三个选项:y,m,x分别代表编译,以模块方式编译,不编译。

-y指定了编译.o时所需要同时编译的其它文件。

下面四个是文件系统的一些扩展属性,也是在编译内核时配置是否使用。

.h:

C:
  1. #include <linux /fs.h>
  2. #include </linux><linux /ext2_fs.h>
  3.  
  4. /*
  5.  * mount options
  6.  */
  7. struct ext2_mount_options {
  8.         unsigned long s_mount_opt;
  9.         uid_t s_resuid;
  10.         gid_t s_resgid;
  11. };
  12. //这里定义了一个文件系统挂载时所使用的一些选项,uid_t,gid_t在i386上是unsigned int。
  13. //s_mount_opt:安装选项
  14. //s_resuid:可以使用保留块的用户id
  15. //s_resgid:可以使用保留块的用户组id
  16.  
  17. /*
  18.  * second extended file system inode data in memory
  19.  */
  20. struct ext2_inode_info {
  21.         __le32  i_data[15];
  22.         __u32   i_flags;
  23.         __u32   i_faddr;
  24.         __u8    i_frag_no;
  25.         __u8    i_frag_size;
  26.         __u16   i_state;
  27.         __u32   i_file_acl;
  28.         __u32   i_dir_acl;
  29.         __u32   i_dtime;
  30.  
  31.         /*
  32.          * i_block_group is the number of the block group which contains
  33.          * this file's inode.  Constant across the lifetime of the inode,
  34.          * it is ued for making block allocation decisions - we try to
  35.          * place a file's data blocks near its inode block, and new inodes
  36.          * near to their parent directory's inode.
  37.          */
  38.         __u32   i_block_group;
  39.  
  40.         /* block reservation info */
  41.         struct ext2_block_alloc_info *i_block_alloc_info;
  42.  
  43.         __u32   i_dir_start_lookup;
  44. #ifdef CONFIG_EXT2_FS_XATTR
  45.         /*
  46.          * Extended attributes can be read independently of the main file
  47.          * data. Taking i_mutex even when reading would cause contention
  48.          * between readers of EAs and writers of regular file data, so
  49.          * instead we synchronize on xattr_sem when reading or changing
  50.          * EAs.
  51.          */
  52.         struct rw_semaphore xattr_sem;
  53. #endif
  54. #ifdef CONFIG_EXT2_FS_POSIX_ACL
  55.         struct posix_acl        *i_acl;
  56.         struct posix_acl        *i_default_acl;
  57. #endif
  58.         rwlock_t i_meta_lock;
  59.  
  60.         /*
  61.          * truncate_mutex is for serialising ext2_truncate() against
  62.          * ext2_getblock().  It also protects the internals of the inode's
  63.          * reservation data structures: ext2_reserve_window and
  64.          * ext2_reserve_window_node.
  65.          */
  66.         struct mutex truncate_mutex;
  67.         struct inode    vfs_inode;
  68.         struct list_head i_orphan;      /* unlinked but open inodes */
  69. };
  70.  
  71. //ext2_inode_info这个结构体定义了inode在内存中存放的信息。
  72. //__le32  i_data[15];  __le32是带bitwise属性的unsigned int;数据块指针数组
  73. //__u32   i_flags;  __u32是unsigned int;文件标志
  74. //__u32   i_faddr;  fragment地址
  75. //__u8    i_frag_no;  fragment号
  76. //__u8    i_frag_size;  fragment大小
  77. //__u16   i_state;  
  78. //__u32   i_file_acl;  文件访问控制链表
  79. //__u32   i_dir_acl;  目录访问控制链表
  80. //__u32   i_dtime;  文件删除时间
  81. //__u32   i_block_group;  inode所在组号
  82. //struct ext2_block_alloc_info *i_block_alloc_info;  block保留信息
  83.  
  84.  
  85. /*
  86.  * Inode dynamic state flags
  87.  */
  88. #define EXT2_STATE_NEW                  0x00000001 /* inode is newly created */
  89.  
  90.  
  91. /*
  92.  * Function prototypes
  93.  */
  94.  
  95. /*
  96.  * Ok, these declarations are also in </linux><linux /kernel.h> but none of the
  97.  * source programs needs to include it so they are duplicated here.
  98.  */
  99.  
  100. static inline struct ext2_inode_info *EXT2_I(struct inode *inode)
  101. {
  102.         return container_of(inode, struct ext2_inode_info, vfs_inode);
  103. }
  104. //EXT2_I函数利用到了内核中经常使用的一个宏:container_of,它的参数为inode指针,返回一个ext2_inode_info的指针,也就是inode所在结构体的地址。
  105. //container_of在linux-2.6.24/include/linux/kernel.h里定义为:
  106. //#define container_of(ptr, type, member) ({                      \
  107.        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
  108.        (type *)( (char *)__mptr - offsetof(type,member) );})
  109.  
  110. //这个宏的原理其实很简单就是利用结构体中某个元素的地址减去该元素相对于结构体的偏移量,得到结构体的地址。
  111.  
  112. //offsetof在linux-2.6.24/include/linux/stddef.h中定义为:
  113. //#undef offsetof
  114. //#ifdef __compiler_offsetof
  115. //#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
  116. //#else
  117. //#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
  118. //#endif
  119.  
  120.  
  121. //接下来这这些是定义在其它文件中的函数的申明。
  122. /* balloc.c */
  123. extern int ext2_bg_has_super(struct super_block *sb, int group);
  124. extern unsigned long ext2_bg_num_gdb(struct super_block *sb, int group);
  125. extern ext2_fsblk_t ext2_new_block(struct inode *, unsigned long, int *);
  126. extern ext2_fsblk_t ext2_new_blocks(struct inode *, unsigned long,
  127.                                 unsigned long *, int *);
  128. extern void ext2_free_blocks (struct inode *, unsigned long,
  129.                               unsigned long);
  130. extern unsigned long ext2_count_free_blocks (struct super_block *);
  131. extern unsigned long ext2_count_dirs (struct super_block *);
  132. extern void ext2_check_blocks_bitmap (struct super_block *);
  133. extern struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
  134.                                                     unsigned int block_group,
  135.                                                     struct buffer_head ** bh);
  136. extern void ext2_discard_reservation (struct inode *);
  137. extern int ext2_should_retry_alloc(struct super_block *sb, int *retries);
  138. extern void ext2_init_block_alloc_info(struct inode *);
  139. extern void ext2_rsv_window_add(struct super_block *sb, struct ext2_reserve_window_node *rsv);
  140.  
  141. /* dir.c */
  142. extern int ext2_add_link (struct dentry *, struct inode *);
  143. extern ino_t ext2_inode_by_name(struct inode *, struct dentry *);
  144. extern int ext2_make_empty(struct inode *, struct inode *);
  145. extern struct ext2_dir_entry_2 * ext2_find_entry (struct inode *,struct dentry *, struct page **);
  146. extern int ext2_delete_entry (struct ext2_dir_entry_2 *, struct page *);
  147. extern int ext2_empty_dir (struct inode *);
  148. extern struct ext2_dir_entry_2 * ext2_dotdot (struct inode *, struct page **);
  149. extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, struct inode *);
  150.  
  151. /* fsync.c */
  152. extern int ext2_sync_file (struct file *, struct dentry *, int);
  153.  
  154. /* ialloc.c */
  155. extern struct inode * ext2_new_inode (struct inode *, int);
  156. extern void ext2_free_inode (struct inode *);
  157. extern unsigned long ext2_count_free_inodes (struct super_block *);
  158. extern void ext2_check_inodes_bitmap (struct super_block *);
  159. extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
  160.  
  161. /* inode.c */
  162. extern void ext2_read_inode (struct inode *);
  163. extern int ext2_write_inode (struct inode *, int);
  164. extern void ext2_put_inode (struct inode *);
  165. extern void ext2_delete_inode (struct inode *);
  166. extern int ext2_sync_inode (struct inode *);
  167. extern int ext2_get_block(struct inode *, sector_t, struct buffer_head *, int);
  168. extern void ext2_truncate (struct inode *);
  169. extern int ext2_setattr (struct dentry *, struct iattr *);
  170. extern void ext2_set_inode_flags(struct inode *inode);
  171. extern void ext2_get_inode_flags(struct ext2_inode_info *);
  172. int __ext2_write_begin(struct file *file, struct address_space *mapping,
  173.                 loff_t pos, unsigned len, unsigned flags,
  174.                 struct page **pagep, void **fsdata);
  175.  
  176. /* ioctl.c */
  177. extern int ext2_ioctl (struct inode *, struct file *, unsigned int,
  178.                        unsigned long);
  179. extern long ext2_compat_ioctl(struct file *, unsigned int, unsigned long);
  180.  
  181. /* namei.c */
  182. struct dentry *ext2_get_parent(struct dentry *child);
  183.  
  184. /* super.c */
  185. extern void ext2_error (struct super_block *, const char *, const char *, ...)
  186.         __attribute__ ((format (printf, 3, 4)));
  187. extern void ext2_warning (struct super_block *, const char *, const char *, ...)
  188.         __attribute__ ((format (printf, 3, 4)));
  189. extern void ext2_update_dynamic_rev (struct super_block *sb);
  190. extern void ext2_write_super (struct super_block *);
  191.  
  192. /*
  193.  * Inodes and files operations
  194.  */
  195.  
  196. /* dir.c */
  197. extern const struct file_operations ext2_dir_operations;
  198.  
  199. /* file.c */
  200. extern const struct inode_operations ext2_file_inode_operations;
  201. extern const struct file_operations ext2_file_operations;
  202. extern const struct file_operations ext2_xip_file_operations;
  203.  
  204. /* inode.c */
  205. extern const struct address_space_operations ext2_aops;
  206. extern const struct address_space_operations ext2_aops_xip;
  207. extern const struct address_space_operations ext2_nobh_aops;
  208.  
  209. /* namei.c */
  210. extern const struct inode_operations ext2_dir_inode_operations;
  211. extern const struct inode_operations ext2_special_inode_operations;
  212.  
  213. /* symlink.c */
  214. extern const struct inode_operations ext2_fast_symlink_inode_operations;
  215. extern const struct inode_operations ext2_symlink_inode_operations;
  216.  
  217. static inline ext2_fsblk_t
  218. ext2_group_first_block_no(struct super_block *sb, unsigned long group_no)
  219. {
  220.         return group_no * (ext2_fsblk_t)EXT2_BLOCKS_PER_GROUP(sb) +
  221.                 le32_to_cpu(EXT2_SB(sb)->s_es->s_first_data_block);
  222. }

标签 :

发表评论

在下面加入你的评论,或者 trackback 从你的博客站点。 订阅本文的评论。

:

:

:

«
»