VFS四大對象之一 struct super_block


linux虛擬文件系統四大對象:

1)超級塊(super block)

2)索引節點(inode)

3)目錄項(dentry)

4)文件對象(file)

現在先介紹第一個

一、super_block的含義:

超級塊代表了整個文件系統,超級塊是文件系統的控制塊,有整個文件系統信息,一個文件系統所有的inode都要連接到超級塊上,可以說,一個超級塊就代表了一個文件系統。

說到inode是啥?參照下一篇博客;

 1 struct super_block {
 2     struct list_head    s_list;        /* Keep this first */
 3     dev_t            s_dev;        /* search index; _not_ kdev_t */
 4     unsigned char        s_dirt;
 5     unsigned char        s_blocksize_bits;
 6     unsigned long        s_blocksize;
 7     loff_t            s_maxbytes;    /* Max file size */
 8     struct file_system_type    *s_type;
 9     const struct super_operations    *s_op;
10     const struct dquot_operations    *dq_op;
11     const struct quotactl_ops    *s_qcop;
12     const struct export_operations *s_export_op;
13     unsigned long        s_flags;
14     unsigned long        s_magic;
15     struct dentry        *s_root;
16     struct rw_semaphore    s_umount;
17     struct mutex        s_lock;
18     int            s_count;
19     atomic_t        s_active;
20 #ifdef CONFIG_SECURITY
21     void                    *s_security;
22 #endif
23     const struct xattr_handler **s_xattr;
24 
25     struct list_head    s_inodes;    /* all inodes */
26     struct hlist_bl_head    s_anon;        /* anonymous dentries for (nfs) exporting */
27 #ifdef CONFIG_SMP
28     struct list_head __percpu *s_files;
29 #else
30     struct list_head    s_files;
31 #endif
32     struct list_head    s_mounts;    /* list of mounts; _not_ for fs use */
33     /* s_dentry_lru, s_nr_dentry_unused protected by dcache.c lru locks */
34     struct list_head    s_dentry_lru;    /* unused dentry lru */
35     int            s_nr_dentry_unused;    /* # of dentry on lru */
36 
37     /* s_inode_lru_lock protects s_inode_lru and s_nr_inodes_unused */
38     spinlock_t        s_inode_lru_lock ____cacheline_aligned_in_smp;
39     struct list_head    s_inode_lru;        /* unused inode lru */
40     int            s_nr_inodes_unused;    /* # of inodes on lru */
41 
42     struct block_device    *s_bdev;
43     struct backing_dev_info *s_bdi;
44     struct mtd_info        *s_mtd;
45     struct hlist_node    s_instances;
46     struct quota_info    s_dquot;    /* Diskquota specific options */
47 
48     int            s_frozen;
49     wait_queue_head_t    s_wait_unfrozen;
50 
51     char s_id[32];                /* Informational name */
52     u8 s_uuid[16];                /* UUID */
53 
54     void             *s_fs_info;    /* Filesystem private info */
55     unsigned int        s_max_links;
56     fmode_t            s_mode;
57 
58     /* Granularity of c/m/atime in ns.
59        Cannot be worse than a second */
60     u32           s_time_gran;
61 
62     /*
63      * The next field is for VFS *only*. No filesystems have any business
64      * even looking at it. You had been warned.
65      */
66     struct mutex s_vfs_rename_mutex;    /* Kludge */
67 
68     /*
69      * Filesystem subtype.  If non-empty the filesystem type field
70      * in /proc/mounts will be "type.subtype"
71      */
72     char *s_subtype;
73 
74     /*
75      * Saved mount options for lazy filesystems using
76      * generic_show_options()
77      */
78     char __rcu *s_options;
79     const struct dentry_operations *s_d_op; /* default d_op for dentries */
80 
81     /*
82      * Saved pool identifier for cleancache (-1 means none)
83      */
84     int cleancache_poolid;
85 
86     struct shrinker s_shrink;    /* per-sb shrinker handle */
87 
88     /* Number of inodes with nlink == 0 but still referenced */
89     atomic_long_t s_remove_count;
90 
91     /* Being remounted read-only */
92     int s_readonly_remount;
93 };

 

這個數據結構十分龐大,畢竟是聚集了一個文件系統的重要信息,我們關注一些比較重要的信息就行了。

 

1 struct list_head    s_list;

s_list 這是第一個成員,是一個雙向循環鏈表,把所有的super_block連接起來,一個super_block代表一個在linux上的文件系統,這個list上邊的就是所有的在linux上記錄的文件系統。

 

1 dev_t s_dev;

 s_dev:設備標識符

 

1 unsigned char        s_dirt;
2 unsigned char        s_blocksize_bits;
3 unsigned long        s_blocksize;
4 loff_t            s_maxbytes;    /* Max file size */

 s_dev:包含該具體文件系統的塊設備標識符。例如,對於 /dev/hda1,其設備標識符為 0x301

s_blocksize:文件系統中數據塊大小,以字節單位

s_blocksize_bits:上面的size大小占用位數,例如512字節就是9 bits

s_dirt:臟位,標識是否超級塊被修改

 

1 loff_t            s_maxbytes;    /* Max file size */

 s_maxbytes:允許的最大的文件大小(字節數)

 

 

1 struct file_system_type    *s_type;

 struct file_system_type *s_type:文件系統類型(也就是當前這個文件系統屬於哪個類型?ext2還是fat32)要區分“文件系統”和“文件系統類型”不一樣!一個文件系統類型下可以包括很多文件系統即很多的super_block。

 

1 const struct super_operations    *s_op;
2 const struct dquot_operations    *dq_op;

struct super_operations *s_op:指向某個特定的具體文件系統的用於超級塊操作的函數集合。

struct dquot_operations *dq_op:指向某個特定的具體文件系統用於限額操作的函數集合。

 

 

1 const struct quotactl_ops    *s_qcop;

struct quotactl_ops     *s_qcop:用於配置磁盤限額的的方法,處理來自用戶空間的請求。

 

1 const struct export_operations *s_export_op;

struct export_operations *s_export_op:導出方法

 

1 unsigned long        s_flags;

s_flags:安裝標識

 

1 unsigned long        s_magic;

s_magic:區別於其他文件系統的標識

 

1 struct dentry        *s_root;

s_root:指向該具體文件系統安裝目錄的目錄項

 

1 struct rw_semaphore    s_umount;

 

s_umount:對超級塊讀寫時進行同步

 

1 struct mutex        s_lock;

 

s_lock:鎖標志位,若置該位,則其它進程不能對該超級塊操作

 

1 int            s_count;

 

s_count:對超級塊的使用計數

 

1 atomic_t        s_active;

 

s_active:引用計數

 

 

s_dirty:已修改的索引節點inode形成的鏈表,一個文件系統中有很多的inode,有些inode節點的內容會被修改,那么會先被記錄,然后寫回磁盤。

s_locked_inodes:要進行同步的索引節點形成的鏈表

s_files:所有的已經打開文件的鏈表,這個file和實實在在的進程相關的

s_bdev:指向文件系統被安裝的塊設備

uu 聯合體域包括屬於具體文件系統的超級塊信息

s_instances:具體的意義后來會說的!(同一類型的文件系統通過這個子墩將所有的super_block連接起來)

s_dquot:磁盤限額相關選項

 

Reference:

http://www.linuxidc.com/Linux/2011-02/32127.htm

http://blog.csdn.net/shanshanpt/article/details/38943731


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM