VFS,super_block,inode,dentry—结构体图解


1、super_block
- 相关的数据结构为:
struct super_block
{
struct list_head s_list;/* Keep this first */// 连接super_block的链表
dev_t s_dev;/* search index; _not_ kdev_t */
unsignedlong s_blocksize;
unsignedlong s_old_blocksize;
unsignedchar s_blocksize_bits;
unsignedchar s_dirt;
unsignedlonglong s_maxbytes;/* Max file size */
struct file_system_type *s_type;// 所表示的文件系统的类型
struct super_operations *s_op;// 文件相关操作函数集合表
struct dquot_operations *dq_op;//
struct quotactl_ops *s_qcop;//
struct export_operations *s_export_op;//
unsignedlong s_flags;//
unsignedlong s_magic;//
struct dentry *s_root;// Linux文件系统中某个索引节点(inode)的链接
struct rw_semaphore s_umount;//
struct semaphore s_lock;//
int s_count;//
int s_syncing;//
int s_need_sync_fs;//
atomic_t s_active;//
void*s_security;//
struct xattr_handler **s_xattr;//
struct list_head s_inodes;/* all inodes */// 链接文件系统的inode
struct list_head s_dirty;/* dirty inodes */
struct list_head s_io;/* parked for writeback */
struct hlist_head s_anon;/* anonymous dentries for (nfs) exporting */
struct list_head s_files;// 对于每一个打开的文件,由file对象来表示。链接文件系统中file
struct block_device *s_bdev;//
struct list_head s_instances;//
struct quota_info s_dquot;/* Diskquota specific options */
int s_frozen;//
wait_queue_head_t s_wait_unfrozen;//
char s_id[32];/* Informational name */
void*s_fs_info;/* Filesystem private info */
/**
* The next field is for VFS *only*. No filesystems have any business
* even looking at it. You had been warned.
*/
struct semaphore s_vfs_rename_sem;/* Kludge */
/* Granuality of c/m/atime in ns.
Cannot be worse than a second */
u32 s_time_gran;
};
- super_block存在于两个链表中,一个是系统所有super_block的链表, 一个是对于特定的文件系统的super_block链表.

- 对于特定的文件系统(文件系统层的具体文件系统), 该文件系统的所有的super_block 都存在于file_sytem_type中的fs_supers链表中.
而所有的文件系统,都存在于file_systems链表中.这是通过调用register_filesystem接口来注册文件系统的.
int register_filesystem(struct file_system_type * fs)

/*
* 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;
unsignedshort i_opflags;
kuid_t i_uid;
kgid_t i_gid;
unsignedint i_flags;
#ifdef CONFIG_FS_POSIX_ACL
struct posix_acl *i_acl;
struct posix_acl *i_default_acl;
#endif
conststruct 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 */
unsignedlong 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
{
constunsignedint i_nlink;
unsignedint __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 */
unsignedshort i_bytes;
unsignedint i_blkbits;
blkcnt_t i_blocks;
#ifdef __NEED_I_SIZE_ORDERED
seqcount_t i_size_seqcount;
#endif
/* Misc */
unsignedlong i_state;
struct mutex i_mutex;
unsignedlong dirtied_when;/* jiffies of first dirtying */
unsignedlong 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
conststruct 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 */
};
一个是inode所在文件系统的super_block的 s_inodes 链表中
一个是根据inode的使用状态存在于以下三个链表中的某个链表中:
- 未用的: inode_unused 链表
- 正在使用的: inode_in_use 链表
- 脏的: super block中的s_dirty 链表
另外,还有一个重要的链表: inode_hashtable(这个暂不介绍).
struct dentry
{
/* RCU lookup touched fields */
unsignedint 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 */
unsignedchar d_iname[DNAME_INLINE_LEN];/* small names */
/* Ref lookup also touches following */
struct lockref d_lockref;/* per-dentry lock and refcount */
conststruct dentry_operations *d_op;
struct super_block *d_sb;/* The root of the dentry tree */
unsignedlong 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;
};
- 所有未用的目录项: dentry_unused 链表
- 正在使用的目录项: 对应inode的 i_dentry 链表
- 表示父子目录结构的链表
另外,还有一个重要的链表: inode_hashtable(这个暂不介绍).

VFS,super_block,inode,dentry—结构体图解的更多相关文章
- 2018.5.2 file结构体
f_flags,File Status Flag f_pos,表示当前读写位置 f_count,表示引用计数(Reference Count): dup.fork等系统调用会导致多个文件描述符指向同一 ...
- inode file 结构
inode位图(inode Bitmap) 和块位图类似,本身占一个块,其中每个bit表示一个inode是否空闲可用. inode表(inode Table) 我们知道,一个文件除了数据需要存储之外, ...
- C语言文件操作 FILE结构体
内存中的数据都是暂时的,当程序结束时,它们都将丢失.为了永久性的保存大量的数据,C语言提供了对文件的操作. 1.文件和流 C将每个文件简单地作为顺序字节流(如下图).每个文件用文件结束符结束,或者在特 ...
- 文件系统系列学习笔记 - inode/dentry/file/super(2)
此篇文章主要介绍下linux 文件系统下的主要对象及他们之间的关系. 1 inode inode结构中主要包含对文件或者目录原信息的描述,原信息包括但不限于文件大小.文件在磁盘块中的位置信息.权限位. ...
- file结构体中private_data指针的疑惑
转:http://www.360doc.com/content/12/0506/19/1299815_209093142.shtml hi all and barry, 最近在学习字符设备驱动,不太明 ...
- file结构体中private_data指针的疑惑【转】
本文转载自:http://www.cnblogs.com/pengdonglin137/p/3328984.html hi all and barry, 最近在学习字符设备驱动,不太明白private ...
- vfs:结构体对象
VFS结构体 super_block 存储一个已安装的文件系统的控制信息,代表一个已安装的文件系统:每次一个实际的文件系统被安装时, 内核会从磁盘的特定位置读取一些控制信息来填充内存中的超级块对象.一 ...
- 文件系统VFS数据结构(超级块 inode dentry file)(收集整理)
Linux虚拟文件系统四大对象: 1)超级块(super block) 2)索引节点(inode) 3)目录项(dentry) 4)文件对象(file) 一个进程在对一个文件进行操作时各种对象的引用过 ...
- Linux字符设备中的两个重要结构体(file、inode)
对于Linux系统中,一般字符设备和驱动之间的函数调用关系如下图所示 上图描述了用户空间应用程序通过系统调用来调用程序的过程.一般而言在驱动程序的设计中,会关系 struct file 和 struc ...
随机推荐
- 【线段树】【CF1083C】 Max Mex
Description 给定一棵有 \(n\) 个点的树,每个节点有点权.所有的点权构成了一个 \(0~\sim~n - 1\) 的排列.有 \(q\) 次操作,每次操作 \(1\) 为交换两个点的点 ...
- YY淘宝商品数据库设计
http://www.cnblogs.com/mmmjiang13/archive/2010/11/04/1868609.html 前言 这几个月都在做一个通过淘宝API线下管理淘宝店的系统,学习了很 ...
- python 获取本机 IP
原文 通过 UDP 获取本机 IP,目前见过最优雅的方法 这个方法是目前见过最优雅获取本机服务器的IP方法了.没有任何的依赖,也没有去猜测机器上的网络设备信息. 而且是利用 UDP 协议来实现的,生成 ...
- Integer两种转int方法比较
方法一: Integer.parseInt(); 返回的是一个 int 的值. 方法二: new Integer.valueof(); 返回的是 Integer 的对象. new Integer.va ...
- python 多线程中的同步锁 Lock Rlock Semaphore Event Conditio
摘要:在使用多线程的应用下,如何保证线程安全,以及线程之间的同步,或者访问共享变量等问题是十分棘手的问题,也是使用多线程下面临的问题,如果处理不好,会带来较严重的后果,使用python多线程中提供Lo ...
- MySQL触发器的正确使用与案例分析
以下的文章主要向大家讲述的是MySQL触发器的实际使用详细说明与实际案例分析,同时本文也列举了一些在MySQL触发器的实际式操作中的代码,以下就是文章的详细内容介绍,望大家借鉴. 触发器案例 mysq ...
- 初等数论及其应用——Lucas定理
Lucas定理用于解决较大组合数的取模问题,下面的理论整理源自冯志刚的<初等数论>,其与百度百科上呈现的Lucas定理形式上不同,但是容易看到二者的转化形式. 首先我们来整理一下冯志刚的& ...
- Metrics.NET实践(1)
起因:对应用的监控和测量是WEB应用的一个重要话题,尤其在监控错误率,并发量,以及框架库中的动态值.于是,在性能优化的时候找到了metrics.net. 简介 开始使用 度量 Gauges Count ...
- 全解析jQuery插件开发!很好很强大!
最近对JQuery插件开发超级感兴趣,看到这样一篇好文章,可以说是<用实例一步步教你写Jquery插件>的十全大补,大家可以两篇结合着看看! jQuery插件的开发包括两种: 一种是类级别 ...
- Xilinx Altera FPGA中的逻辑资源(Slices VS LE)比较
前言 经常有朋友会问我,“我这个方案是用A家的FPGA还是X家的FPGA呢?他们的容量够不够呢?他们的容量怎么比较呢?”当然,在大部分时候,我在给客户做设计的时候,直接会用到最高容量的产品,因为我们的 ...