linux文件系统与模型【笔记】 surper block/inode/dentry/file
因为有文件,所以有管理文件的系统=>因为有很多种文件系统,所以有虚拟文件系统对它们进行封装,让上层的程序只需要调用简单的接口。
文件系统是存储和组织信息的机制,它的目的是管理各种存储设备,所谓的管理是指:存储/操作等。
文件系统管理的对象不同,对应的文件就不同:普通文件,socket文件,目录文件,链接文件,设备文件,管道文件。
文件系统分类:磁盘文件系统,如ext3,ext4;网络文件系统,如NFS;特殊文件系统,这类系统不管理本地或者远程的磁盘,如/proc。
linux支持的文件系统可以查看源码中的fs文件夹,如下:
norton@norton-laptop:~/linuxKernel/linux-2.6.34/fs$ ls
9p bio.c dlm fs_struct.c Kconfig notify select.c
adfs bio-integrity.c drop_caches.c fs-writeback.c Kconfig.binfmt ntfs seq_file.c
affs block_dev.c ecryptfs fuse libfs.c ocfs2 signalfd.c
afs btrfs efs generic_acl.c lockd omfs smbfs
aio.c buffer.c eventfd.c gfs2 locks.c open.c splice.c
anon_inodes.c cachefiles eventpoll.c hfs logfs openpromfs squashfs
attr.c ceph exec.c hfsplus Makefile partitions stack.c
autofs char_dev.c exofs hostfs mbcache.c pipe.c stat.c
autofs4 cifs exportfs hpfs minix pnode.c super.c
bad_inode.c coda ext2 hppfs mpage.c pnode.h sync.c
befs compat_binfmt_elf.c ext3 hugetlbfs namei.c posix_acl.c sysfs
bfs compat.c ext4 inode.c namespace.c proc sysv
binfmt_aout.c compat_ioctl.c fat internal.h ncpfs qnx4 timerfd.c
binfmt_elf.c configfs fcntl.c ioctl.c nfs quota ubifs
binfmt_elf_fdpic.c cramfs fifo.c ioprio.c nfs_common ramfs udf
binfmt_em86.c dcache.c file.c isofs nfsctl.c readdir.c ufs
binfmt_flat.c dcookies.c filesystems.c jbd nfsd read_write.c utimes.c
binfmt_misc.c debugfs file_table.c jbd2 nilfs2 read_write.h xattr_acl.c
binfmt_script.c devpts freevxfs jffs2 nls reiserfs xattr.c
binfmt_som.c direct-io.c fscache jfs no-block.c romfs xfs
虚拟文件系统VFS
是建立在各个文件系统上的抽象层,屏蔽了不同文件系统的差异。它之所以有这样的功能是因为它提供了一个“通用的文件系统模型”。该通用模型能够表示很多(即它支持的了)的文件系统。它只提供API接口,桥接实际的文件系统和具体的应用,不会做任何处理文件相关的决策。
VFS采用面向对象的设计思路,将一系列概念抽象出来的同时,也包括处理这些对象的方法。
VFS对象模型
1.超级快(struct super_block)
代表一个已经安装的文件系统。如果是基于磁盘的文件系统,则存放在磁盘扇区。如果不是和基于磁盘的文件系统,如sysfs是基于内存的文件系统,则super_block存放在内存中。
2.索引节点(struct inode)
代表存储设备上的一个实际文件,存储文件相关的信息。linux把文件和文件信息分离出来,文件的相关信息又称为文件的“元数据”,文件信息包括:访问权限,大小,创建时间等。inode结构里面有hash链表,因为inode节点很多,查找效率低,需要借助hash表提高效率。相同hash值的inode节点会被放到一起。
3.目录项(struct dentry)
描述文件系统的层次结构,目录和文件(如.c文件)本身也是“目录项”的对象。通过目录项去找inode。它只存在内存中,不存在磁盘里,具体存在directory cache。它的存在是为了提高系统性能。定义在/include/linux/dcache.h中。
4.文件(struct file)
代表已经被打开(open)的文件。主要用于建立“进程”和文件之间的关系。一个物理文件可能对应多个“文件对象”,但只有唯一的对应的inode。file的结构体中有一个union,用了rcu链表,所以我转载了关于rcu机制的文章,不知道是不是这个rcu机制,仅供参考:http://blog.csdn.net/xzongyuan/article/details/20382995。
总结下4个模型的特征:
1.超级块是磁盘或者内存的抽象,通过超级块,我们可以访问磁盘或内存的具体位置;
2.索引节点,主要是用于找具体某个文件,之所以叫做索引,是因为它不是文件本身,只是文件描述信息的抽象。
3.目录项,它是一个抽象概念的模型,抽象的是文件的层次逻辑关系。它主要用来构建文件系统的层次性,因此它不代表具体某个对象。
4.文件。真正的文件对象,进程需要通过它来处理文件数据。该文件模型使得进程有能力通过目录项/索引节点/超级块来访问磁盘和内存。
/include/linux/fs.h
struct file {/** fu_list becomes invalid after file_free is called and queued via* fu_rcuhead for RCU freeing*/union {struct list_head fu_list;struct rcu_head fu_rcuhead;} f_u;struct path f_path;
#define f_dentry f_path.dentry
#define f_vfsmnt f_path.mntconst struct file_operations *f_op;spinlock_t f_lock; /* f_ep_links, f_flags, no IRQ */atomic_long_t f_count;unsigned int f_flags;fmode_t f_mode;loff_t f_pos;struct fown_struct f_owner;const struct cred *f_cred;struct file_ra_state f_ra;u64 f_version;
#ifdef CONFIG_SECURITYvoid *f_security;
#endif/* needed for tty driver, and maybe others */void *private_data;#ifdef CONFIG_EPOLL/* Used by fs/eventpoll.c to link all the hooks to this file */struct list_head f_ep_links;
#endif /* #ifdef CONFIG_EPOLL */struct address_space *f_mapping;
#ifdef CONFIG_DEBUG_WRITECOUNTunsigned long f_mnt_write_state;
#endif
};
5.其它。还有很多VFS对象,如表示文件系统类型的对象file_system_type,表示挂载点的对象vfsmount。不同的文件类型(file_system_type)通过next关联,相同文件类型的superblock通过s_instance(super block实例)字段链接在一起。所有的相同文件类型的vfsmount通过mnt_list连接在一起。
代码在include/linux/fs.h和include/linux/mount.h中。
struct file_system_type {const char *name;int fs_flags;int (*get_sb) (struct file_system_type *, int,const char *, void *, struct vfsmount *);void (*kill_sb) (struct super_block *);struct module *owner;struct file_system_type * next;struct list_head fs_supers;struct lock_class_key s_lock_key;struct lock_class_key s_umount_key;struct lock_class_key i_lock_key;struct lock_class_key i_mutex_key;struct lock_class_key i_mutex_dir_key;struct lock_class_key i_alloc_sem_key;
}
struct vfsmount {struct list_head mnt_hash;struct vfsmount *mnt_parent; /* fs we are mounted on */struct dentry *mnt_mountpoint; /* dentry of mountpoint */struct dentry *mnt_root; /* root of the mounted tree */struct super_block *mnt_sb; /* pointer to superblock */struct list_head mnt_mounts; /* list of children, anchored here */struct list_head mnt_child; /* and going through their mnt_child */int mnt_flags;/* 4 bytes hole on 64bits arches */const char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */struct list_head mnt_list;struct list_head mnt_expire; /* link in fs-specific expiry list */struct list_head mnt_share; /* circular list of shared mounts */struct list_head mnt_slave_list;/* list of slave mounts */struct list_head mnt_slave; /* slave list entry */struct vfsmount *mnt_master; /* slave is on master->mnt_slave_list */struct mnt_namespace *mnt_ns; /* containing namespace */int mnt_id; /* mount identifier */int mnt_group_id; /* peer group identifier *//** We put mnt_count & mnt_expiry_mark at the end of struct vfsmount* to let these frequently modified fields in a separate cache line* (so that reads of mnt_flags wont ping-pong on SMP machines)*/atomic_t mnt_count;int mnt_expiry_mark; /* true if marked for expiry */int mnt_pinned;int mnt_ghosts;
#ifdef CONFIG_SMPint __percpu *mnt_writers;
#elseint mnt_writers;
#endif
};
VFS对象之间不是孤立的,其关系如下。
进程描述符task_struct的files字段描述了所有打开的文件,存放在fd_array数组里。通过该数组找到file对象(该file对象实际存放在super_block指定的文件系统中),可以找到dentry项,从而找到inode。这件就建立了文件对象和物理文件之间的关联。
Linux以一组通用的对象看待所有文件系统:super block,inode,dentry和file。
linux文件系统与模型【笔记】 surper block/inode/dentry/file相关推荐
- 【操作系统】LinuxKernel-VFS虚拟文件系统 认知框架构建(super_block,inode,dentry,file)
VFS 概念 虚拟文件系统(也称为虚拟文件系统交换机)是内核中的软件层,为用户空间程序提供文件系统接口.它还在内核中提供了一个抽象,允许不同的文件系统实现共存 "一切皆文件"是Li ...
- linux VFS 虚拟文件系统 简介 super_block inode dentry file
1.简介 1.Linux 中允许众多不同的文件系统共存,如 ext2, ext3, vfat 等.通过使用同一套文件 I/O 系统 调用即可对 Linux 中的任意文件进行操作而无需考虑其所在的具体文 ...
- Linux文件系统与日志分析(inode、inode节点耗尽故障处理、文件备份和恢复、日志文件管理)
Linux文件系统与日志分析 一.inode和block概述 1.文件和扇区 2.块(block) 3.文件数据 二.inode(索引节点) 1.inode的内容 2.inode的号码 3.inode ...
- linux flush 文件,Linux文件系统学习:io的plug过程-blk_flush_plug_list的情况
在上篇文章中我们看到 if (plug) { if (!request_count) trace_block_plug(q); else { if (request_count >= BLK_M ...
- linux文件系统实现原理简述【转】
本文转载自:https://blog.csdn.net/eleven_xiy/article/details/71249365 [摘要] [背景] [正文] [总结] 注意:请使用谷歌浏览器阅读(IE ...
- 深入理解linux文件系统( 理解inode与block,理解硬链接软链接,掌握恢复误删文件及其分析方法,掌握用户日志及其查询命令 )
文章目录 深入理解linux文件系统 前言 inode与block详解 inode和bolck概述 1:数据(block)块: 2:元信息 : inode(索引节点) inodu的内容 Linux系统 ...
- Linux文件系统与日志分析 ------ inode、block及日志
文件系统与日志分析 inode 与 block 介绍 inode的内容 inode 的号码 inode 的大小 inode的特殊作用 硬链接与软链接 软链接 硬链接 日志分析 日志的功能 日志文件的分 ...
- Linux文件系统之inode,block,superblock
文件存储在硬盘上,硬盘的最小存储单位叫做扇区sector,每个扇区存储512个字节(0.5)kb,系统读取文件时不会一个一个扇区的读,而是一次性连续读取多个扇区,即一次性读1个'块'( ...
- 【操作系统】Linux文件系统 block、inode、superblock
UNIX文件系统 1. 数据区块(block) 真正存放文件的地方. 2. inode 存储内容: 特点: 结构示意图: inode本身128B,inode记录一个数据区块需要4B,数据区块按照1KB ...
最新文章
- 2019-11-13 惯性环节怎么写成m语言
- map集合怎么取value值最大的前三_Java之集合(下)
- JAVA开发环境及其开发
- linux删除modules文件夹,linux – 为什么我不能删除这个dkms模块?
- study of javaserver faces lifecycle
- 收录批量查询神器 bluecattools
- (转载)web.xml中 IntrospectorCleanupListener的作用
- 阿里资深技术专家:35岁IT职场人的8个经验总结!
- 15日精读掌握《高德纳:具体数学》计划(2019.5/27-2019/6/10)
- 74cms v6.0.48模版注入+文件包含getshell复现
- matlab命令行窗口显示长度设置_MATLAB的命令窗口、图形窗口
- excel图片根据表格内容动态变化
- 浙江大学黄杨思博计算机学院,竺可桢学院2010-2011学年荣誉称号发文名单
- JQ show和hide(隐藏显示)、fadeIn和fadeOut(淡入淡出)、slideDown和slideUp(隐藏显示)
- xbox手柄适配器驱动_XBox无线适配器MN-740更新
- python字符串转json(python字符串转浮点数)
- p5.js 编程临摹动态图形(互动媒体技术作业)
- 心蓝12306订票助手
- linux下opencv4查看版本
- 《白帽子讲Web安全》memo0
热门文章
- 项目初始化报 404 Not Found - GET https://registry.npmjs.org(转)
- 仿选股宝选个头条上下拉加载一页的功能
- 5G系统——5G-GUTI、5G-TMSI、5G-S-TMSI、SUPI、SUCI
- 可编译易用的模块化nf-HiPAC移植成功
- 贴图平移凹凸贴图偏移
- 记一次ARM-鲲鹏服务器读写parquet报错解决过程
- Dva 的connect使用
- JVM和ART、DVM(dalvik VM)的区别
- BootstarpTable在IE11的兼容问题
- java 级数_编写一个Java程序实现级数运算。