VFS-目录项对象(dentry)

  • 每个文件除了有一个索引节点 inode 数据结构外,还有一个目录项 dentry 数据结构
  • dentry 结构代表的是逻辑意义上的文件,描述的是文件逻辑上的属性,目录项对象在磁盘上并没有对应的映像

  • inode 结构代表的是物理意义上的文件,记录的是物理上的属性 对于一个具体的文件,系统 其 inode 结构在磁盘上就有对应的映像

  • 一个索引节点对象可能对应多个目录项对象

VFS-文件对象(file)

  • 进程是通过文件描述符来访问文件的
  By convention, UNIX System shells associate file descriptor 0 with the standard
input
of a process, file descriptor 1 with the standard output, and file descriptor 2 with
the standard error
. This convention is used by the shells and many applications; it is
not a feature of the UNIX kernel. Nevertheless, many applications would break if these
associations weren’t followed.
  Although their values are standardized by POSIX.1, the magic numbers 0, 1, and
should be replaced in POSIX-compliant applications with the symbolic constants
STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO to improve readability.
These constants are defined in the <unistd.h> header.
  File descriptors range from 0 through OPEN_MAX−1. (Recall Figure 2.11.) Early
historical implementations of the UNIX System had an upper limit of 19, allowing a
maximum of 20 open files per process, but many systems subsequently increased this
limit to 63.
  • Linux 中专门用了一个 file 文件对象来保存打开文件的文件位置,这个对象称为打开的文件描述 open file description
  • 文件描述符是用来描述打开的文件的 。 每个进程用一个 files_struct 结构来记录文件描述符的使用情况,这个 files_struct 结构称为用户打开文件表, 它是进程的私有数据
  • file 结构中主要保存了文件位置,还把指向该文件索引节点的指针也放在其中 。file 结构形成一个双链表,称为系统打开文件表

   

   

  • 超级块是对一个文件系统的描述

  查看超级块的命令:DUMPE2FS  (dumpe2fs - dump ext2/ext3/ext4 filesystem information)

DUMPE2FS(8)                           System Manager's Manual                           DUMPE2FS(8)

NAME
dumpe2fs - dump ext2/ext3/ext4 filesystem information SYNOPSIS
dumpe2fs [ -bfghixV ] [ -o superblock=superblock ] [ -o blocksize=blocksize ] device DESCRIPTION
dumpe2fs prints the super block and blocks group information for the filesystem present on
device. Note: When used with a mounted filesystem, the printed information may be old or inconsis‐
tent. OPTIONS
-b print the blocks which are reserved as bad in the filesystem. -o superblock=superblock
use the block superblock when examining the filesystem. This option is not usually
needed except by a filesystem wizard who is examining the remains of a very badly
corrupted filesystem. -o blocksize=blocksize
use blocks of blocksize bytes when examining the filesystem. This option is not usu‐
ally needed except by a filesystem wizard who is examining the remains of a very
badly corrupted filesystem.
##################################################################################################
至于DUMPE2FS(8), 8是什么意思呢?
The table below shows the section numbers of the manual followed by the types of pages they
contain. 1 Executable programs or shell commands
2 System calls (functions provided by the kernel)
3 Library calls (functions within program libraries)
4 Special files (usually found in /dev)
5 File formats and conventions eg /etc/passwd
6 Games
7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)
8 System administration commands (usually only for root)(系统管理命令)
9 Kernel routines [Non standard]
~$ df -Th	# 只可以查看已经挂载的分区和文件系统类型。
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 888M 0 888M 0% /dev
tmpfs tmpfs 184M 6.0M 178M 4% /run
/dev/vda1 ext4 50G 4.5G 43G 10% /
tmpfs tmpfs 917M 24K 917M 1% /dev/shm
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup
tmpfs tmpfs 184M 0 184M 0% /run/user/500
#dumpe2fs /dev/loop0 	【-h不打印Group信息】

dumpe2fs 1.42.9 (网上示例仅供参照)
Filesystem volume name: <none>
Last mounted on: <not available> 最后挂载目录
Filesystem UUID: cef5f647-058f-49bd-88c6-baf3ce2338a0
Filesystem magic number: 0xEF53 ext4文件系统标志
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 25688 文件系统inode号总数,由系统决定但可以指定比例
Block count: 102400 文件系统block总数,==容量/默认的1KB
Reserved block count: 5120 保留的block总数,默认比例为5%
Free blocks: 93504 空闲的block总数,
Free inodes: 25677 空闲的inode总数
First block: 1 第一个block号
Block size: 1024 block大小
Fragment size: 1024
Group descriptor size: 64 块组描述大小
Reserved GDT blocks: 256 预留块组描述block数量
Blocks per group: 8192 块组中block数量
Fragments per group: 8192
Inodes per group: 1976 块组中inode数量==25688/13
Inode blocks per group: 247 块组中inode占用block总数
Flex block group size: 16 inode表大小?
Filesystem created: Tue Nov 27 13:26:27 2018
Last mount time: Tue Nov 27 13:28:39 2018
Last write time: Tue Nov 27 13:28:39 2018
Mount count: 1 挂载次数
Maximum mount count: -1
Last checked: Tue Nov 27 13:26:27 2018
Check interval: 0 (<none>)
Lifetime writes: 4447 kB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11 文件系统的第一个inode号
Inode size: 128 inode大小
Journal inode: 8 日志文件inode号
Default directory hash: half_md4
Directory Hash Seed: 45d2f9d4-714a-4ccf-9c9d-308d12552317
Journal backup: inode blocks
Journal features: journal_64bit
日志大小: 4096k
Journal length: 4096
Journal sequence: 0x00000002
Journal start: 1 Group 0: (Blocks 1-8192) [ITABLE_ZEROED]
Checksum 0x0229, unused inodes 1965
主 superblock at 1, Group descriptors at 2-2
保留的GDT块位于 3-258
Block bitmap at 259 (+258), Inode bitmap at 275 (+274)
Inode表位于 291-537 (+290)
4683 free blocks, 1965 free inodes, 2 directories, 1965个未使用的inodes
可用块数: 3510-8192
可用inode数: 12-1976
  • 索引节点是对一个文件物理属性的描述

     索引节点(Inode)查看命令: stat  <file>

  • 目录项是对一个文件逻辑属性的描述
  • 一个进程所处的位置是由 fs_struct 来描述的,而一个进程 或用户 打开的文件是由
    files_struct 来描述的,而整个系统所打开的文件是由 file 结构来描述

  • VFS-数据结构之间的关系

    

  文件系统的注册和注销

  • 当内核被编译时 就已经确定了可以支持哪些文件系统,这些文件系统在系统引导时在 VFS 中进行注册 。
  • VFS 的初始化函数用来向 VFS 注册,即填写文件注册表 file_system_type 数据结构
  • 注册调用 register_filesystem 函数
  • 注销即删除一个 file_system_type 结构,需调用 unregister_filesystem() 函数

 文件系统的安装

  • 安装一个文件系统实际上是安装一个物理设备
  • 自己( 一般是超级用户 )安装文件系统时 需要指定三种信息:文件系统的名称包含
    文件系统的物理块设备文件系统在已有文件系统中的安装点

  • mount  -t  iso9660  /dev/hdc  /mnt/cdrom 其中 iso9660 是光驱文件系统的名称,
     /dev/hdc 是包含文件系统的物理块设备 ,/mnt/cdrom 就是将要安装到的目录,即安装点 。

  • 在用户程序中要安装一个文件系统则可以调用 mount 系统调用 。 安装过程主要工作
    是创建安装点对象,将其挂接到根文件系统的指定安装点下,然后初始化超级块对象,从而
    获得文件系统基本信息和相关的操作 。

 文件系统的安装

  • 如果文件系统中的文件当前正在使用 该文件系统是不能被卸载的
  • 否则,查看对应的 VFS 超级块,如果该文件系统的 VFS 超级块标志为 脏,则必须将超级块信息写回磁盘

  • 之后,对应的 VFS 超级块被释放,vfsmount 数据结构将从 vfsmntlist 链表中断开并被释放

  • 具体的实现代码为 fs/super.c 中的 sys_umount 函数

Linux文件系统概述二的更多相关文章

  1. 宿主机Windows访问虚拟机Linux文件(二)

    上一篇文章中详细讲述FTP服务(基于文件传输协议的服务),本文则介绍另一种能够实现此功能Telnet(Telecommunications network 远程登陆)服务.本文介绍的telnet我常用 ...

  2. Linux文件系统概述

    Unix文件是以字节序列组成的信息载体(container),内核不解释文件的内容. Linux文件系统中的文件是数据的集合,文件系统不仅包含着文件中的数据而且还有系统的结构,所有Linux用户和程序 ...

  3. Linux 文件缓存 (二)

    close系统调用入口1. 首先来到系统调用入口,主要使用__close_fd进行了具体的处理过程,并没有耗时操作.(current->files表示进程当前打开文件表信息,fd为需要关闭的文件 ...

  4. 自学Linux Shell8.1-linux文件系统概述及操作

    点击返回 自学Linux命令行与Shell脚本之路 8.1-linux文件系统概述及操作 1. linux支持的文件系统 Windows常用的分区格式有三种,分别是FAT16.FAT32.NTFS格式 ...

  5. 运维系列之二 Linux文件种类和扩展名

    一.文件种类 1.普通文件 用ls查看文件属性时,显示的是[-] 2.目录文件(directory) 文件属性第一个为[d] 3.连接文件(link) 类似于win下的快捷方式,文件第一个属性为[l] ...

  6. 十二、文件和目录——Linux文件系统结构

    12.1 Linux文件系统结构 12.1.1 文件操作基本元素 文件操作相关的最基本元素是:目录结构,索引节点和文件的数据本身 目录结构(目录项) 索引节点(i 节点) 文件的数据 12.1.2 文 ...

  7. Linux系统运维笔记(二),Linux文件编辑命令

    Linux系统运维笔记 Linux文件编辑命令 首先我们使用命令 vi filename 打开一个文件,这个时候进入到的是命令模式 接下来我们按i,然后键盘随便输入写内容. 然后按ESC重新进入到命令 ...

  8. Linux实战教学笔记08:Linux 文件的属性(上半部分)

    第八节 Linux 文件的属性(上半部分) 标签(空格分隔):Linux实战教学笔记 第1章 Linux中的文件 1.1 文件属性概述(ls -lhi) linux里一切皆文件 Linux系统中的文件 ...

  9. Linux设备管理(二)_从cdev_add说起

    我在Linux字符设备驱动框架一文中已经简单的介绍了字符设备驱动的基本的编程框架,这里我们来探讨一下Linux内核(以4.8.5内核为例)是怎么管理字符设备的,即当我们获得了设备号,分配了cdev结构 ...

随机推荐

  1. Maven虐我千百遍,我待Maven如初恋

    前言 在如今的互联网项目开发当中,特别是Java领域,可以说Maven随处可见.Maven的仓库管理.依赖管理.继承和聚合等特性为项目的构建提供了一整套完善的解决方案,可以说如果你搞不懂Maven,那 ...

  2. 洛谷 - P3966 - 单词 - AC自动机

    https://www.luogu.org/problemnew/show/P3966 因为文本串就是字典本身,所以这个和平时的AC自动机不太一样.平时的query要沿着fail树把子树的出现次数依次 ...

  3. laravel 数据库连接Mysql

    找到 config/database.php 'mysql' => [ 'driver' => 'mysql', //数据库的类型 'host' => env('DB_HOST', ...

  4. C++中的声明与定义

    转自:http://www.cnblogs.com/kingcat/archive/2011/12/30/2307426.html C++是一种复杂的计算机语言,很多在现代高级语言中已经不需要程序员操 ...

  5. string.Format 处理 double 的问题

    出处: http://www.cnblogs.com/albert-struggle/archive/2012/05/22/2512744.html 1.格式化货币(跟系统的环境有关,中文系统默认格式 ...

  6. 洛谷P3232 [HNOI2013]游走(高斯消元+期望)

    传送门 所以说我讨厌数学……期望不会高斯消元也不会……好不容易抄好了高斯消元板子被精度卡成琪露诺了…… 首先,我们先算出走每一条边的期望次数,那么为了最小化期望,就让大的期望次数乘上小编号 边的期望次 ...

  7. PostgreSQL - 用psql 运行SQL文件

    对于预先写好的SQL文件,比如/home/user1/updateMyData.sql, 可以有两种方式来运行这个SQL文件. 方式一:连接db后执行SQL文件 首先通过psql连接到对应的db: p ...

  8. 小程序video置顶

    page { overflow-y: none; height: 100vh; } .page__hd_media { position: fixed; width:100vw; top:; heig ...

  9. Script to Monitor Current User Activity in the Database

    Execution Environment: SQL, SQL*Plus, iSQL*Plus Access Privileges: Requires select privileges on vie ...

  10. 082 Remove Duplicates from Sorted List II 有序的链表删除重复的结点 II

    给定一个有序的链表,删除所有有重复数字的节点,只保留原始列表中唯一的数字.例如:给定 1->2->3->3->4->4->5 ,则返回 1->2->5给 ...