Linux檔案系統
引入:VFS
VFS(Virtual Filesystem Switch)稱為虛擬檔案系統或虛擬檔案系統轉換,是一個核心軟體層,在具體的檔案系統之上抽象的一層,用來處理與Posix檔案系統相關的所有呼叫,給各種檔案系統提供一個通用的介面,使上層的應用程式能夠使用通用的介面訪問不同檔案系統,同時也為不同檔案系統的通訊提供了媒介。
VFS提供了一個抽象層,將POSIX API介面與不同儲存裝置的具體介面實現進行了分離,使得底層的檔案系統型別、裝置型別對上層應用程式透明。
linux下“一切皆檔案”是Unix/Linux的基本哲學之一。unix標準檔案:普通檔案,目錄檔案,符號連結檔案,裝置檔案,管道檔案。
通用檔案模型
資料型別 | Superblock | inode | dentry | file |
功能 | 儲存檔案系統後設資料 | 檔案相關的後設資料 | 檔案(目錄)名稱和具體的inode的對應關係,快取最近最常訪問的檔案或目錄,提示系統效能 | |
儲存內容 | 檔案系統型別、大小、狀態(存放於磁碟檔案系統控制塊) | 檔案的所有者(使用者、組)、訪問時間、檔案型別等(存放於磁碟檔案控制塊) | ||
是否儲存在介質中 | 是 | 是 | 否 | 否 |
何時建立 | mount時從介質中讀取,並常駐記憶體 | |||
重要成員 | s_list、
| |||
涉及操作函式 | *s_op | |||
維護 | 所有SB物件以雙向迴圈連結串列連結在一起 | |||
是否快取 | 是 |
Superblock
其成員相關資訊在介質中儲存,mount時讀取介質資訊並在記憶體中建立。
結構體定義
struct super_block {
struct list_head s_list; /* 支援掛載多個檔案系統,並將super_block鏈起來 */
dev_t s_dev; /* search index; _not_ kdev_t */
unsigned char s_blocksize_bits;
unsigned long s_blocksize;
loff_t s_maxbytes; /* Max file size */
struct file_system_type *s_type; /* 檔案系統型別 */
const struct super_operations *s_op; /* 檔案系統相關操作函式 */
const struct dquot_operations *dq_op;
const struct quotactl_ops *s_qcop;
const struct export_operations *s_export_op;
unsigned long s_flags;
unsigned long s_magic;
struct dentry *s_root;/* 該檔案系統的根目錄 */
struct rw_semaphore s_umount;
int s_count;
atomic_t s_active;
#ifdef CONFIG_SECURITY
void *s_security;
#endif
const struct xattr_handler **s_xattr;
struct list_head s_inodes; /* all inodes */
struct hlist_bl_head s_anon; /* anonymous dentries for (nfs) exporting */
struct list_head s_mounts; /* list of mounts; _not_ for fs use */
struct block_device *s_bdev;
struct backing_dev_info *s_bdi;
struct mtd_info *s_mtd;
struct hlist_node s_instances;
unsigned int s_quota_types; /* Bitmask of supported quota types */
struct quota_info s_dquot; /* Diskquota specific options */
struct sb_writers s_writers;
char s_id[32]; /* Informational name */
u8 s_uuid[16]; /* UUID */
void *s_fs_info; /* Filesystem private info */
unsigned int s_max_links;
fmode_t s_mode;
/* Granularity of c/m/atime in ns.
Cannot be worse than a second */
u32 s_time_gran;
/*
* The next field is for VFS *only*. No filesystems have any business
* even looking at it. You had been warned.
*/
struct mutex s_vfs_rename_mutex; /* Kludge */
/*
* Filesystem subtype. If non-empty the filesystem type field
* in /proc/mounts will be "type.subtype"
*/
char *s_subtype;
/*
* Saved mount options for lazy filesystems using
* generic_show_options()
*/
char __rcu *s_options;
const struct dentry_operations *s_d_op; /* default d_op for dentries */
/*
* Saved pool identifier for cleancache (-1 means none)
*/
int cleancache_poolid;
struct shrinker s_shrink; /* per-sb shrinker handle */
/* Number of inodes with nlink == 0 but still referenced */
atomic_long_t s_remove_count;
/* Being remounted read-only */
int s_readonly_remount;
/* AIO completions deferred from interrupt context */
struct workqueue_struct *s_dio_done_wq;
struct hlist_head s_pins;
/*
* Keep the lru lists last in the structure so they always sit on their
* own individual cachelines.
*/
struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
struct rcu_head rcu;
/*
* Indicates how deep in a filesystem stack this SB is
*/
int s_stack_depth;
};
重要成員
型別 | 型別名 | 成員名 | 作用 |
struct | list_head | s_list | 支援掛載多個檔案系統,並將super_block鏈起來 |
struct | dentry | s_root | 該檔案系統的根目錄 |
struct | super_operations | *s_op | 檔案系統相關操作函式 |
*s_d_op | |||
struct | file_system_type | *s_type | 檔案系統型別名稱,mount時指定型別名 |
void | *s_fs_info | 指向具體檔案系統的超級塊資訊 | |
Index node(inode)
靜態:建立檔案系統時生成inode,儲存在具體儲存裝置上,記錄了檔案系統的元資訊;
動態:VFS在記憶體中使用inode資料結構,來管理檔案系統的檔案物件,記錄了檔案物件的詳細資訊,部分欄位與關聯的檔案物件有關,會動態建立。
結構體定義
/*
* Keep mostly read-only and often accessed (especially for
* the RCU path lookup and 'stat' data) fields at the beginning
* of the 'struct inode'
*/
struct inode {
umode_t i_mode;
unsigned short i_opflags;
kuid_t i_uid;
kgid_t i_gid;
unsigned int i_flags;
#ifdef CONFIG_FS_POSIX_ACL
struct posix_acl *i_acl;
struct posix_acl *i_default_acl;
#endif
const struct inode_operations *i_op;
struct super_block *i_sb;
struct address_space *i_mapping;
#ifdef CONFIG_SECURITY
void *i_security;
#endif
/* Stat data, not accessed from path walking */
unsigned long i_ino;
/*
* Filesystems may only read i_nlink directly. They shall use the
* following functions for modification:
*
* (set|clear|inc|drop)_nlink
* inode_(inc|dec)_link_count
*/
union {
const unsigned int i_nlink;
unsigned int __i_nlink;
};
dev_t i_rdev;
loff_t i_size;
struct timespec i_atime;
struct timespec i_mtime;
struct timespec i_ctime;
spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */
unsigned short i_bytes;
unsigned int i_blkbits;
blkcnt_t i_blocks;
#ifdef __NEED_I_SIZE_ORDERED
seqcount_t i_size_seqcount;
#endif
/* Misc */
unsigned long i_state;
struct mutex i_mutex;
unsigned long dirtied_when; /* jiffies of first dirtying */
unsigned long dirtied_time_when;
struct hlist_node i_hash;
struct list_head i_wb_list; /* backing dev IO list */
struct list_head i_lru; /* inode LRU list */
struct list_head i_sb_list;
union {
struct hlist_head i_dentry;
struct rcu_head i_rcu;
};
u64 i_version;
atomic_t i_count;
atomic_t i_dio_count;
atomic_t i_writecount;
#ifdef CONFIG_IMA
atomic_t i_readcount; /* struct files open RO */
#endif
const struct file_operations *i_fop; /* former ->i_op->default_file_ops */
struct file_lock_context *i_flctx;
struct address_space i_data;
struct list_head i_devices;
union {
struct pipe_inode_info *i_pipe;
struct block_device *i_bdev;
struct cdev *i_cdev;
};
__u32 i_generation;
#ifdef CONFIG_FSNOTIFY
__u32 i_fsnotify_mask; /* all events this inode cares about */
struct hlist_head i_fsnotify_marks;
#endif
void *i_private; /* fs or device private pointer */
};
重要成員
型別 | 型別名 | 成員名 | 作用 |
struct | inode_operations | *i_op | 索引節點操作函式列表 |
struct | super_block | *i_sb | 指向所屬的超級塊物件 |
long | \ | i_ino | 索引節點編號 |
short | \ | i_bytes | 最後一個塊的有效位元組數 |
int | i_blkbits | 每個塊所佔位數 | |
blkcnt_t | i_blocks | 檔案所佔塊數 | |
Directory entry(dentry)
結構體定義
struct dentry {
/* RCU lookup touched fields */
unsigned int d_flags; /* protected by d_lock */
seqcount_t d_seq; /* per dentry seqlock */
struct hlist_bl_node d_hash; /* lookup hash list */
struct dentry *d_parent; /* parent directory */
struct qstr d_name;
struct inode *d_inode; /* Where the name belongs to - NULL is
* negative */
unsigned char d_iname[DNAME_INLINE_LEN]; /* small names */
/* Ref lookup also touches following */
struct lockref d_lockref; /* per-dentry lock and refcount */
const struct dentry_operations *d_op;
struct super_block *d_sb; /* The root of the dentry tree */
unsigned long d_time; /* used by d_revalidate */
void *d_fsdata; /* fs-specific data */
struct list_head d_lru; /* LRU list */
struct list_head d_child; /* child of parent list */
struct list_head d_subdirs; /* our children */
/*
* d_alias and d_rcu can share memory
*/
union {
struct hlist_node d_alias; /* inode alias list */
struct rcu_head d_rcu;
} d_u;
};
重要成員
型別 | 型別名 | 成員名 | 作用 |
int | \ | d_flags | 標記,如是否為掛載點 |
d_hash | hash連結串列 | ||
struct | dentry | d_parent | 當前目錄項的父目錄項 |
unsigned char | d_iname | 檔名 | |
struct | qstr | d_name |
長檔名
|
d_inode | 與此dentry關聯的檔案inode | ||
struct | list_head | d_subdirs | 子目錄項鍊表 |
struct | super_block | *d_sb | 所屬檔案系統超級塊 |
File
結構體定義
重要成員
型別 | 型別名 | 成員名 | 作用 |
|
檔案系統分析
https://blog.csdn.net/jasonchen_gbd/article/details/51511261
相關文章
- [Linux]檔案系統Linux
- Linux系統篇-檔案系統&虛擬檔案系統Linux
- Linux系統檔案系統及檔案基礎篇Linux
- 論Linux檔案系統Linux
- Linux AUFS 檔案系統Linux
- linux的檔案系統Linux
- 分散式檔案系統(HDFS)與 linux系統檔案系統 對比分散式Linux
- 『學了就忘』Linux檔案系統管理 — 57、Linux檔案系統介紹Linux
- 檔案系統(十一):Linux Squashfs只讀檔案系統介紹Linux
- linux 檔案系統擴容Linux
- Linux檔案系統詳解Linux
- linux之路(五)檔案系統Linux
- Linux檔案系統、目錄Linux
- Linux 檔案系統詳解Linux
- 導覽Linux系統檔案系統型別Linux型別
- Linux系統程式設計【4】——檔案系統Linux程式設計
- linux系統檔案開啟數Linux
- Linux 檔案系統擴充套件Linux套件
- 12_Linux檔案系統概念Linux
- windows共享到linux系統檔案WindowsLinux
- Linux檔案系統的實現Linux
- Linux EXT2 檔案系統Linux
- 理解Linux檔案系統之 inodeLinux
- Linux 檢視系統檔案命令Linux
- 二、Linux檔案系統結構Linux
- Linux 檔案系統基本介紹Linux
- Linux雜記-根檔案系統Linux
- Linux系統網路檔案配置Linux
- Linux系統中常見的檔案系統有哪些?Linux
- Linux系統掛載win系統的共享檔案Linux
- Linux系統檔案學習內容多嗎?linux系統命令Linux
- (3)Linux效能調優之Linux檔案系統Linux
- linux系統配置及相關檔案Linux
- Linux檔案系統與日誌分析Linux
- Linux深入探索12-檔案系統Linux
- Linux系統程式設計-檔案IOLinux程式設計
- 導覽Linux 檔案系統型別Linux型別
- Linux 檔案系統型別導覽Linux型別