§Filesystems are a collection of files that are stored in the system in some way
§So many file system!
Disk file:
§Boot block
§Super block
−Magic number
−Revision
−Mount count and Maximum Mount count
−Block Group number
−Block size
−Block per Group
−Free Blocks
//need sync to disk
−Free inodes
//need sync to disk
−First inode
‘/’
§Index(GDT)
−Block bitmap
−inode bitmap
−Inode table
VFS:
§abstraction layer on top of a more concrete file system
−Sys_read, sys_write, sys_open,
…
§interface
−File_operations
−Dentry
−File name (sub directory), parent directory,
…
−File tree
−6 list_head:
−d_vfsmnt
−d_hash
dentry_hashtable
−d_lru
dentry_unused
−d_child
patent->d_subdirs
−d_subdirs
sub->dentry
−d_alias
−Inode
−Files information
−File type, atime, mtime, link numer, length, ACL, location
Dentry:
§struct dentry { /*include/linux/dcache.h*/
§ atomic_t d_count;
§ unsigned int d_flags;
§ struct inode * d_inode; /* Where the name belongs to - NULL is negative */
§ struct dentry * d_parent; /* parent directory */
§ struct list_head d_hash; /* lookup hash list */
§ struct list_head d_lru; /* d_count = 0 LRU list */
§ struct list_head d_child; /* child of parent list */
§ struct list_head d_subdirs; /* our children */
§ struct list_head d_alias; /* inode alias list */
§ int d_mounted;
§ struct qstr d_name;
§ unsigned long d_time; /* used by d_revalidate */
§ struct dentry_operations *d_op;
§ struct super_block * d_sb; /* The root of the dentry tree */
§ unsigned long d_vfs_flags;
§ void * d_fsdata; /* fs-specific data */
§ unsigned char d_iname[DNAME_INLINE_LEN]; /* small names */
§};
Super block:
2 struct super_block {
3 struct list_head s_list; /* Keep this first */
4 dev_t s_dev; /* search index; _not_ kdev_t */
5 unsigned long s_blocksize; //数据块大小
6 unsigned char s_blocksize_bits; //块大小占用的位数
7 unsigned char s_dirt; //脏位,如果该位置位,说明超级块被修改
8 unsigned long long s_maxbytes; //单个文件最大体积
9 struct file_system_type *s_type; //文件系统结构
10 struct super_operations *s_op; //超级块支持的操作
11 struct dquot_operations *dq_op; //
12 struct quotactl_ops *s_qcop; //用户配额限制
13 struct export_operations *s_export_op; //
14
15 unsigned longs_flags;
16 unsigned long s_magic; //区块的magic数
17 struct dentry *s_root; //根目录
18 struct rw_semaphore s_umount; //
19 struct mutex s_lock; //
20 int s_count; //
3 struct list_head s_list; /* Keep this first */
4 dev_t s_dev; /* search index; _not_ kdev_t */
5 unsigned long s_blocksize; //数据块大小
6 unsigned char s_blocksize_bits; //块大小占用的位数
7 unsigned char s_dirt; //脏位,如果该位置位,说明超级块被修改
8 unsigned long long s_maxbytes; //单个文件最大体积
9 struct file_system_type *s_type; //文件系统结构
10 struct super_operations *s_op; //超级块支持的操作
11 struct dquot_operations *dq_op; //
12 struct quotactl_ops *s_qcop; //用户配额限制
13 struct export_operations *s_export_op; //
14
15 unsigned longs_flags;
16 unsigned long s_magic; //区块的magic数
17 struct dentry *s_root; //根目录
18 struct rw_semaphore s_umount; //
19 struct mutex s_lock; //
20 int s_count; //
21 int s_syncing; //
22 int s_need_sync_fs; //
23 atomic_t s_active; //是否活动
24 void *s_security; //
25 struct xattr_handler **s_xattr; //
26
22 int s_need_sync_fs; //
23 atomic_t s_active; //是否活动
24 void *s_security; //
25 struct xattr_handler **s_xattr; //
26
27 struct list_head s_inodes; //所有inode
28 struct list_head s_dirty; //脏inode
29 struct list_head s_io; //用于写回的缓存
30 struct hlist_head s_anon; //nfs匿名入口
31 struct list_head s_files; //文件链表头
32
33 struct block_device *s_bdev;
34 struct list_head s_instances;
35 struct quota_info s_dquot; //配额定制选项
36
37 int s_frozen;
38 wait_queue_head_t s_wait_unfrozen;
39
40 char s_id[32]; //名字
41
……
28 struct list_head s_dirty; //脏inode
29 struct list_head s_io; //用于写回的缓存
30 struct hlist_head s_anon; //nfs匿名入口
31 struct list_head s_files; //文件链表头
32
33 struct block_device *s_bdev;
34 struct list_head s_instances;
35 struct quota_info s_dquot; //配额定制选项
36
37 int s_frozen;
38 wait_queue_head_t s_wait_unfrozen;
39
40 char s_id[32]; //名字
41
……
Lookup file:
§Path_init
−initialize nameidata (struct)
§Path_walk
−Calculate name hash(H), hast_table(H),
−i_hash_next, i_hash_prev
−Cached_lookup()
hit dentry cache
−real_lookup()
miss dentry cache
−d_alloc()
−Ext2_lookup/ext3_lookup/……
−Xxx_find_entry()
−iget()
−Read Record block from HDD/SDD (Buffer head)
Open/read/write….
§Sys_open/read/write…
§Path_init/path_walk
§Page cache list
−Radix tree
−Page virtual address
−page cache
−Struct inode > ext2/…_inode
−Address_space
−Clean_pages
−Dirty_pages
−Locked_pages
§Virtual page
−Buffer_head
§Buffer cache
−LRU
−SLAB cache
−Submit_bh->submit_bio
−BIO
−Kflushd
§Page mapping
−Mmap()