歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux VFS數據結構

Linux VFS數據結構

日期:2017/2/28 16:04:47   编辑:Linux教程

超級塊對象

記錄已安裝文件系統的整體信息,由於具體的文件系統來實現,它對應於具體文件系統的超級塊或控制塊,存儲在磁盤的特定扇區上,如果不是基於磁盤的文件系統,比如sysfs,會生成臨時的超級塊,保存在內存當中。

01struct super_block {

02 struct list_head s_list; /* Keep this first */

03 dev_t s_dev; /* search index; _not_ kdev_t */

04 unsigned long s_blocksize;

05 unsigned char s_blocksize_bits;

06 unsigned char s_dirt;

07 unsigned long long s_maxbytes; /* Max file size */

08 struct file_system_type *s_type;

09 const struct super_operations *s_op;

10 struct dquot_operations *dq_op;

11 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 int s_need_sync_fs;

20 atomic_t s_active;

21#ifdef CONFIG_SECURITY

22 void *s_security;

23#endif

24 struct xattr_handler **s_xattr;

25

26 struct list_head s_inodes; /* all inodes */

27 struct list_head s_dirty; /* dirty inodes */

28 struct list_head s_io; /* parked for writeback */

29 struct list_head s_more_io; /* parked for more writeback */

30 struct hlist_head s_anon; /* anonymous dentries for (nfs) exporting */

31 struct list_head s_files;

32 /* s_dentry_lru and s_nr_dentry_unused are protected by dcache_lock */

33 struct list_head s_dentry_lru; /* unused dentry lru */

34 int s_nr_dentry_unused; /* # of dentry on lru */

35

36 struct block_device *s_bdev;

37 struct mtd_info *s_mtd;

38 struct list_head s_instances;

39 struct quota_info s_dquot; /* Diskquota specific options */

40

41 int s_frozen;

42 wait_queue_head_t s_wait_unfrozen;

43

44 char s_id[32]; /* Informational name */

45

46 void *s_fs_info; /* Filesystem private info */

47 fmode_t s_mode;

48 struct mutex s_vfs_rename_mutex; /* Kludge */

49

50 /* Granularity of c/m/atime in ns.

51 Cannot be worse than a second */

52 u32 s_time_gran;

53

54 char *s_subtype;

55

56 char *s_options;

57 struct list_head s_async_list;

58};

第2行指向超級塊鏈表的指針

第3行設備標識符

第4行以字節為單位的塊大小

第5行以位為單位的塊大小

第6行修改標志

第7行文件的最長長度

第8行文件系統類型

第9行超級塊方法

第10行磁盤限額處理方法

第11行磁盤限額管理方法

第12行網絡文件系統使用的輸出操作

第13行安裝標志

第14行文件系統的魔數

第15行文件系統根目錄的目錄項對象

第16行卸載所用的信號量

第17行超級塊信息量

第18行引用計數器

第19行對超級塊的已安裝文件系統進行同步的標志

第20行次級引用計數器

第22行指向超級塊安全數據結構的指針

第24行指向超級塊擴展屬性結構的指針

第26行所有索引節點的鏈表

第27行改進型索引節點的鏈表

第28行等待被寫入磁盤的索引節點的鏈表

第30行用於處理遠程網絡文件系統的匿名目錄項的鏈表

第31行文件對象的鏈表

第36行指向塊設備驅動程序描述符的指針

第38行用於給定文件系統類型的超級塊對象鏈表的指針

第39行磁盤限額的描述符

第41行凍結文件系統時使用的標志

第42行進程掛起的等待隊列,直到文件系統被解凍

第46行指向特定文件的超級塊信息的指針

第52行時間戳的粒度

超級塊的操作方法

01struct super_operations {

02 struct inode *(*alloc_inode)(struct super_block *sb);

03 void (*destroy_inode)(struct inode *);

04

05 void (*dirty_inode) (struct inode *);

06 int (*write_inode) (struct inode *, int);

07 void (*drop_inode) (struct inode *);

08 void (*delete_inode) (struct inode *);

09 void (*put_super) (struct super_block *);

10 void (*write_super) (struct super_block *);

11 int (*sync_fs)(struct super_block *sb, int wait);

12 int (*freeze_fs) (struct super_block *);

13 int (*unfreeze_fs) (struct super_block *);

14 int (*statfs) (struct dentry *, struct kstatfs *);

15 int (*remount_fs) (struct super_block *, int *, char *);

16 void (*clear_inode) (struct inode *);

17 void (*umount_begin) (struct super_block *);

18

19 int (*show_options)(struct seq_file *, struct vfsmount *);

20 int (*show_stats)(struct seq_file *, struct vfsmount *);

21#ifdef CONFIG_QUOTA

22 ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);

23 ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);

24#endif

25 int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);

26};

第2行為索引節點對象分配空間,包括具體文件系統的數據所需要的空間。

第3行撤消索引節點對象。

第5行當索引節點標記為修改(髒)時調用。

第6行用通過傳遞參數指定的索引節點對象的內容更新一個文件系統的索引節點。索引節點對象的i_ino字段標識所涉及磁盤上文件系統的索引節點。flag參數表示I/O操作是否應當同步。

第7行撤消索引節點時調用

第8行在必須撤消索引節點時調用。刪除內存中的VFS索引節點和磁盤上的文件數據及元數據

第9行釋放通過傳遞的參數指定的超級塊對象

第10行用指定對象的內容更新文件系統的超級塊

第11行在清除文件系統來更新磁盤上的具體文件系統數據時調用。

第14行將文件系統的統計信息返回,填寫在buf緩存區中。

第15行用新選項重新安裝文件系統

第16行當撤消磁盤索引節點執行具體文件操作時調用。

第17行中斷一個安裝操作

第19行用來顯示特定文件系統的選項

第22行限額系統使用該方法從文件中讀取數據。

第23行限額系統使用該方法將數據寫入文件中

索引節點對象

存放關於具體文件的一般信息。對基於磁盤的文件系統,通常對應於存放在磁盤上的文件控制塊。每個索引節點對象都有一個索引節點號,這個節點號唯一的標識文件系統中的文件。。

01struct inode {

02 struct hlist_node i_hash;

03 struct list_head i_list;

04 struct list_head i_sb_list;

05 struct list_head i_dentry;

06 unsigned long i_ino;

07 atomic_t i_count;

08 unsigned int i_nlink;

09 uid_t i_uid;

10 gid_t i_gid;

11 dev_t i_rdev;

12 u64 i_version;

13 loff_t i_size;

14#ifdef __NEED_I_SIZE_ORDERED

15 seqcount_t i_size_seqcount;

16#endif

17 struct timespec i_atime;

18 struct timespec i_mtime;

19 struct timespec i_ctime;

20 unsigned int i_blkbits;

21 blkcnt_t i_blocks;

22 unsigned short i_bytes;

23 umode_t i_mode;

24 spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */

25 struct mutex i_mutex;

26 struct rw_semaphore i_alloc_sem;

27 const struct inode_operations *i_op;

28 const struct file_operations *i_fop; /* former ->i_op->default_file_ops */

29 struct super_block *i_sb;

30 struct file_lock *i_flock;

31 struct address_space *i_mapping;

32 struct address_space i_data;

33#ifdef CONFIG_QUOTA

34 struct dquot *i_dquot[MAXQUOTAS];

35#endif

36 struct list_head i_devices;

37 union {

38 struct pipe_inode_info *i_pipe;

39 struct block_device *i_bdev;

40 struct cdev *i_cdev;

41 };

42 int i_cindex;

43

44 __u32 i_generation;

45

46#ifdef CONFIG_DNOTIFY

47 unsigned long i_dnotify_mask; /* Directory notify events */

48 struct dnotify_struct *i_dnotify; /* for directory notifications */

49#endif

50

51#ifdef CONFIG_INOTIFY

52 struct list_head inotify_watches; /* watches on this inode */

53 struct mutex inotify_mutex; /* protects the watches list */

54#endif

55

56 unsigned long i_state;

57 unsigned long dirtied_when; /* jiffies of first dirtying */

58

59 unsigned int i_flags;

60

61 atomic_t i_writecount;

62#ifdef CONFIG_SECURITY

63 void *i_security;

64#endif

65 void *i_private; /* fs or device private pointer */

66};

第2行用於散列鏈表的指針

第3行用於描述索引節點當前狀態的鏈表的指針

第4行用於超級塊的索引節點鏈表的指針

第5行引用索引節點的目錄項對象鏈表的頭

第6行索引節點號

第7行引用計數器

第8行硬鏈接數目

第9行所有者標識符

第10行組標識符

第11行實設備標識符

第13行文件的字節數

第17行上次訪問文件的時間

第18行上次寫文件的時間

第19行上次修改索引節點的時間

第20行塊的字節數

第21行文件的塊數

第26行在直接I/O文件操作中避免出現競爭條件的讀/寫信號量

第27行索引節點的操作

第28行缺省文件操作

第29行指向超級塊對象的指針

第30行指向文件鎖鏈表的指針

第31行指向address_space對象

第32行文件的address_space對象

第34行索引節點磁盤限額

第36行用於具體的字符或塊設備索引節點鏈表的指針

第38行管道文件使用

第39行指向塊設備驅動程序的指針

第40行指向字符設備驅動程序的指針

第42行擁有一組次設備號的設備文件的索引

第44行索引節點版本號

第47行目錄通知事件的位掩碼

第48行用於目錄通知

第56行索引節點的狀態標志

第57行索引節點的弄髒時間

第59行文件系統的安裝標志

第61行用於寫進程的引用計數器

第63行指向索引節點安全結構的指針

索引結點的操作方法

01struct inode_operations {

02 int (*create) (struct inode *,struct dentry *,int, struct nameidata *);

03 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);

04 int (*link) (struct dentry *,struct inode *,struct dentry *);

05 int (*unlink) (struct inode *,struct dentry *);

06 int (*symlink) (struct inode *,struct dentry *,const char *);

07 int (*mkdir) (struct inode *,struct dentry *,int);

08 int (*rmdir) (struct inode *,struct dentry *);

09 int (*mknod) (struct inode *,struct dentry *,int,dev_t);

10 int (*rename) (struct inode *, struct dentry *,

11 struct inode *, struct dentry *);

12 int (*readlink) (struct dentry *, char __user *,int);

13 void * (*follow_link) (struct dentry *, struct nameidata *);

14 void (*put_link) (struct dentry *, struct nameidata *, void *);

15 void (*truncate) (struct inode *);

16 int (*permission) (struct inode *, int);

17 int (*setattr) (struct dentry *, struct iattr *);

18 int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *);

19 int (*setxattr) (struct dentry *, const char *,const void *,size_t,int);

20 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);

21 ssize_t (*listxattr) (struct dentry *, char *, size_t);

22 int (*removexattr) (struct dentry *, const char *);

23 void (*truncate_range)(struct inode *, loff_t, loff_t);

24 long (*fallocate)(struct inode *inode, int mode, loff_t offset,

25 loff_t len);

26 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,

27 u64 len);

28};

第2行為與目錄項對象相關的普通文件創建一個新的磁盤索引節點

第3行為包含在一個目錄項對象中的文件名對應的索引節點查找目錄

第4行創建一個新的名為new_dentry的硬鏈接,它指向dir目錄下名為old_dentry的文件。

第5行從一個目錄中刪除目錄項對象所指定文件的硬鏈接

第6行在某個目錄下,為與目錄項對象相關的符號鏈接創建一個新的索引節點

第7行在某個目錄下,為與目錄項對象相關的目錄創建一個新的索引節點

第8行從一個目錄刪除子目錄,子目錄的名稱包含在目錄項對象中。

第9行在某個目錄中,為與目錄項對象相關的特定文件創建一個新磁盤索引節點。

第10行將old_dir目錄下由old_entry標識的文件移動new_dir目錄下。

第12行將目錄項所指定的符號鏈接中對應的文件路徑名拷貝到buffer所指定的用戶態內存區

第13行解析索引節點對象所指定的符號鏈接

第14行釋放由follow_link方法分配的用於解析符號鏈接的所有臨時數據結構

第15行修改與索引節點相關的文件長度

第16行檢查是否允許對索引節點所指的文件進行指定模式的訪問。

第17行在觸及索引節點屬性後通知一個”修改事件”

第18行由一些文件系統用於讀取索引節點屬性

第19行獲取擴展屬性名稱的整個鏈表

第20行刪除索引節點的擴展屬性。

Copyright © Linux教程網 All Rights Reserved