Operating System Principles Chapter 11 File System Implementation

Operating System Principles for Undergraduate Students Learning Record
Learning Record Family Bucket

11.1 File system

1. File system overview

Method and data structure for organizing files on storage device

The module responsible for managing and storing file information in the operating system

Most of the file system exists in the operating system, but some microkernels do not have a file system

System angle:

  1. Organize and allocate space on storage devices
  2. Responsible for file retrieval, reading and writing, etc.
  3. Goal: Access Speed ​​and Storage Space Efficiency

User perspective:

  1. Provides a file access mechanism for access by name
  2. file organization
  3. Goal: Convenient file access mechanism

2. File system hierarchy

basic file system

Physical block read and write

Send control commands to device drivers

file organization module

Manage files, logical blocks, and physical blocks

Convert the logical address of the file to a physical address, manage free space, and allocate physical blocks for the file

logical file system

Manage metadata in the file system: all structural data except file data

File access by name, file directory management, FCB management, storage protection

3. File system implementation

Physical block: composed of one or more sectors, the basic file read and write unit

Partition: Partition

Volume (logical disk): Volume, logical partition on the disk, built on the physical partition

two file systems

  • disk file system
  • memory file system

4. Disk file system

5. Memory file system

Partition Table: All installation partition information

Directory buffer structure: save the most recently accessed directory information

System open file table, process open file table

Purpose: To improve file system performance through buffering techniques

6. Virtual file system

Purpose: Support multiple file systems

Consolidate multiple filesystems into one directory structure

Mask differences between file systems for users

Virtual File System VFS

File system interface: a unified interface for applications to access files

VFS interface: define VFS interface for various file systems

7. Network file system

NFS: save storage space and achieve sharing

access remote file system

8. Commonly used file systems

Windows:FAT NTFS ReFS

Linux:Ext(Ext2 3 4 )

Mac OS:HFS

11.2 Storage space allocation method

physical block

The basic unit of reading and writing storage devices

Basic unit of allocation for storage devices

Corresponds to the page size of the memory

logical block: a block in the file space

The size is consistent with the physical block
A logical block is stored in a physical block

continuous allocation

Each file occupies a contiguous set of physical blocks on disk

FCB only gives: start block number and length

shortcoming:

Waste of space (small space cannot be allocated)
files cannot grow dynamically (file A)
is not conducive to file insertion and deletion (need to move data)

link assignment

Discrete Physical Block Allocation

explicit allocation, implicit allocation

Implicit linking: the pointer address of the next block is given in the physical block

Advantages: can expand the allocation, easy to insert and delete files

Disadvantages: Unable to achieve random access, slow access to files

Show Links: Take out the pointer and store them together

Greatly improved retrieval speed

FAT table, not suitable for large-capacity disk File Allocation Table, one partition has two FAT tables

Link table size: 16-bit entry, which is 128KB; 32-bit entry, which is 16GB

index allocation

Scattered FAT, each file is assigned a FAT table, that is, the index table

Index block: stores the physical block pointing to the block number of each physical block of the file

Address mapping:

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-9PUqUGJX-1641540972514) (E:\Documents and PPT\Junior Course Study\Operating System\Pictures\Tenth Chapter One\Index Table Address Mapping.png)]

multilevel index

For files larger than 4MB, a multi-level index method is required

joint strategy mixed strategy

iNodes in Unix

Level 3 indexes support 48KB + 4MB + 4GB + 4 TB. Since you want to use level 3 indexes, you will only use level 3 indexes when you have used up all the previous direct indexes, level 1 indexes, and level 2 indexes

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-ve9W3Khr-1641540972516) (E:\Documents and PPT\Junior Course Study\Operating System\Pictures\Tenth One chapter\mixed indexing method.png)]

11.3 Free space management

free list

The free list is directly managed in an array-like manner

free list

Link together all free blocks on disk

bitmap

Use a binary bit to indicate the usage of a block

1: Disk block is free

0: the disk block has been allocated

Learn to calculate the row and column, the calculation of the block number

Bitmaps require additional space

block size = 2^12 bytes

disk size = 2^30 bytes

n = 2^30 / 2^12 = 2^18 bits

Bitmaps are stored in physical blocks, small-capacity disk space management

group link

Combining free list and free linked list

Example: UNIX system

Divide free blocks into several groups, every 100 blocks as a group

Each set of first free blocks contains:

  • Total number of free blocks
  • The address of the first block of the next set of free blocks
  • List of block numbers of other free blocks in this group

MOOC unit work

1. A file has 20 disk blocks (block number: 0-19), assuming that the file control block is in memory (if the file uses index allocation, the index table is not in memory). In the following cases, please calculate how many disk I/O operations are required under the three allocation methods of continuous allocation, link allocation, and single-level index allocation? (Every time a disk block is read in or written out, a disk I/O operation is required. In addition, assuming that in the continuous allocation mode, there are no free disk blocks at the head of the file, but there are free disk blocks at the end of the file. 1) At the beginning of the
file 2) Add a disk block
before the 15th block of the file and write the content;
3) Delete a disk block at the end of the file;
4) Add a disk block and write the content at the end of the file.

(1) Continuous allocation: 0 times, directly modify the starting block number and length of FCB

​ Link allocation implicit: 1 time, first read the block number of the second block, and then modify the FCB starting block number

​ Single-level index: 2 times, read into the index table, modify the index items in the index block, and then write to the disk block

(2) Continuous allocation: read block numbers 14-19, write block numbers 15-20, and write a new block, 13 times

Link allocation: implicit: read the first 14 blocks to find the pointer to the 15th block 14 times, write the content of the new block and the address of the old 15th block, write the address of the new block in the 14th block, a total of 16 times

​ Single-level index: 3 times, read the content of the index block, modify the index item and write it to the disk block, and write the content of the new block

(3) Continuous allocation: 0 times, directly modify the length of the FCB table

​ Link allocation: Implicit: 20 times, the first 19 times read the address of the twentieth block, and then modify the address to -1 to indicate that the 19th block is the end block

​ Single-level index: 2 times, read the index table, and modify the content of the index item in the index block

(4) Continuous allocation: 1 time, write content, and modify the file length of FCB

​ Link allocation: implicit: 22 times, the first 20 times find the content of the twentieth block, then write the content of the new block, and finally modify the pointer of the twentieth block to point to the address of the new block

​ Single-level index: 3 times, read the content of the index block, modify the index item and write it to the disk block, and write the content of the new block

2. The directory file adopts link type. Each disk block stores the description of 10 lower-level files, and can store up to 40 lower-level files. If the lower-level file is a directory file, the upper-level directory points to the first block of the directory file, otherwise it points to the ordinary file. File control block. Ordinary files adopt the form of two-level index, and 12 disk block addresses are given in the file control block. The first 10 disk block addresses point to the physical addresses of the first 10 pages, and the 11th disk block address points to the first-level index table, and the first-level index table Given 256 disk block addresses, that is, the addresses of the 10th to 265th pages of the file are pointed out, the 12th disk block address points to the secondary index table, and the addresses of 256 primary index tables are indicated in the secondary index table. Excuse me:

‌1) How many pages can an ordinary file in the file system have at most?

‏max = 10 + 256 + 256*256 = 65802 pages

‌2) If you want to read a certain page in the file /A/D/K/Q, how many times do you need to start the disk at least? How many times do you want to start the disk at most? (Every time a disk block is read, a disk operation needs to be started)

least most
Memory/->A 0 0
A->D 1 4
D->K 1 4
K->Q 1 4
Q->FCB 1 1
FCB->a certain page 1 3
total 5 16

insert image description here

3. Assume that the size of a logical block and a physical block of a file system on a disk are both 512B. Assuming that the FCB of each file is already in memory, for the three allocation methods (continuous allocation, explicit link allocation and single-level index allocation), please ask:

‏1) How is the mapping from logical address to physical address implemented in the system?

‏2) Give an example to illustrate the mapping process from logical address to physical address in single-level index allocation.

Suppose the logical address is LA, the logical block and physical block 512B are S, and the relative starting address of the logical address is G

(1) Continuous allocation: LA/S = Q...RQ is the logical block number, R is the offset within the block

​ B = Q + start block number recorded in FCB D = R

​ Physical address (B, D)

​ Display link: LA/S = Q...RQ is the logical block number, R is the offset within the block

​ B = Q and G get the physical block number in the linked list D = R

​ Physical address (B, D)

​ Single-level index: LA/S = Q...RQ is the logical block number, R is the offset within the block

​ B = physical block number corresponding to item Q in the index table D = R

​ Physical address (B, D)

(2) For example, assuming that the logical address is 1028, the content of the index block of the file is indexed as follows: 6 1 13 -1 -1 -1

Then, 1028 /512 = 2 … 4

The lookup index table is number 13, then the physical address is PA = (13, 4)

4. Please give an example of a specific file system to illustrate what content the file system generally consists of?

The file system generally consists of file classification, file directory structure, file logical structure, file physical structure, storage management, system calls, and disk structure.

For example: In the UNIX file system, there are three types of files: ordinary files, directory files, and device files.

File logical structure: Unstructured streaming files,

File physical structure: multiple index structure,

File directory structure: Graphical directory, using hard links to realize file sharing, using index nodes to improve file access efficiency,

File storage management: free space management: group link;

Disk structure: Physical structure, platters, heads, spindles

Memory structure: single-process open file table, system open file table (including read-write flag, number of processes sharing the read-write pointer, active node number, read-write pointer, etc.)

File system calls: Create files, delete files, read files, open files, close files, locate file pointers, link files, set file permissions, create pipeline files, copy files and other functions to realize file operations and file protection.

Guess you like

Origin blog.csdn.net/weixin_45788387/article/details/122365791