Chapter 7: Linux system disk and file management (1)

First, the file system characteristics

File system mode of operation
which is related to the operating system's file data. Newer operating system file data in addition to the actual file contents, often contain a lot of attributes, such as the Linux operating system file permissions (rwx) and file attributes (owner, group, time parameters, etc.). File system data will typically be stored in the two portions of different blocks, permission attribute to the inode place, the actual data block in the data block. In addition, there is a super overall difference information record a file system, comprising a block of the inode total amount, the amount of the remaining amount.

  • inode: Record file attributes of a file occupies an inode, while recording data block numbers for this file is located
  • block: the actual contents of the log file, if a large file will occupy multiple block

Benefits block stored inode number: disk in a short time to read out all the data relatively high write efficiency
called indexed file system data access methods such
[image dump outer link fails, the source station may have anti-theft chain mechanism, it is recommended to save the pictures uploaded directly down (img-InDc3rdD-1582378667339) ( https://user-images.githubusercontent.com/56629574/67255341-272c0e00-f4b4-11e9-9b77-b2e51ef2b399.png)]

The reason fragments appear: block file write too discrete, making the file read performance will become poor. FAT file system needs defragmentation, and Ext2 file system indexing basic need.

[Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-5rPpPWgH-1582378667341) ( https://user-images.githubusercontent.com/56629574/67255679-dc12fa80-f4b5 -11e9-9fe3-4b350f147619.png)]
the FAT file system format is not the inode, there is no way to read out all at once, block numbers are recorded for each block among a front. If the record dispersed, you need to repeatedly turn the disk to read inefficient.

Two, Linux's EXT2 file system (inode)

File system inode and block the outset
planned, but if the file system GB, the inode and block all put together it would be unwise, for the file system to format a plurality of blocks
[external link Pictures dump fails, the source station may have a security chain mechanism, it is recommended to save the pictures uploaded directly down (img-jn1VlT9D-1582378667343) ( https://user-images.githubusercontent.com/56629574/67256617-b3413400-f4ba-11e9-91c9 -d4225b733d5e.png)]

Three, data block (data block)

1571713132(1)

  • In principle, the block size and the number of finished formatting you can not change (unless reformatting)
  • Data from more than one file can be placed within each block
  • If the file is larger than the block, a file with the plurality of block block
  • If the file is smaller than the block, the block can not be used by the remaining capacity (the waste of disk space)

Four, inode table (inode table)

  • Inode number has been fixed at a size format
  • Each inode size is fixed 128bytes
  • Each file will only take up only a inode
  • The number of file systems can be established with the relevant inode number
  • When the system reads the file, first find the inode, inode and analyze whether recorded in line with the user's permission, if they meet can begin the actual reading of the contents of block
  • 128bytes of each inode is, a recording block 4byte spent
    1571714606(1)
    each inode is 128bytes of, there are 12 control directly to block number, block number directly can be achieved.
    Indirect is a chance to be a block as a recording area block numbers, if the file is too large, an indirect block to record the number.
    [Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-qLGY7sPF-1582378667348) ( https://user-images.githubusercontent.com/56629574/67257515-f00f2a00-f4be -11e9-82f2-bb5f12891d82.png)]

Five, inode remaining portion

  • block bitmap (block table): For example, the new document uses block, need to know which block is empty
  • inode bitmap: Similar to above
  • superblock: General information recording this filesystem, including the total amount of inode / block, the amount of the remaining amount, and the format of the file system related information;
  • Filesystem Description: a block number which between start and end of each segment block number of each block (superblock, bitmap, inodemap, data block) interposed, respectively.

Six directory

创建目录,文件系统会分配一个inode与至少一块block给该目录。其中,inode记录该目录的相关权限与属性,并可记录分配到的block号码;block则记录在该目录下的文件名占用的inode号码数据。所以,inode并没有记录文件名:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zAMcapxH-1582378667350)(https://user-images.githubusercontent.com/56629574/67261145-01156680-f4d2-11e9-806b-3ab98e3ac640.png)]
inode并不记录文件名,文件名记录在目录的block中。所以新增/删除/更改文件名与目录的w权限有关。
因为文件名记录在目录的block块中,因此当我们要读取某个文件时,就必会经过目录的inode与block,然后才能找到待读取的inode号码,最终才会读到正确的文件的block内的数据。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-RTwUpL2g-1582378667351)(https://user-images.githubusercontent.com/56629574/67261636-24d9ac00-f4d4-11e9-8c81-2ef7185bb174.png)]

七、EXT2/EXT3/EXT4文件的存取与日志式文件系统的功能

新建文件或目录

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WNzQfQdu-1582378667352)(https://user-images.githubusercontent.com/56629574/67262138-3f148980-f4d6-11e9-95e9-66ec84488a43.png)]

Published 550 original articles · won praise 88 · views 260 000 +

Guess you like

Origin blog.csdn.net/jiangshangchunjiezi/article/details/104451166