Operating System Principles Chapter 10 File System

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

10.1 File concept

file: a collection of related information with a filename

File name: unique, easy to remember

File structure: it is easy for the program to understand the content of the file

  • Unstructured: text stream, byte stream
  • Simple record structure: linear, fixed length, variable length, HTML document
  • Complex structures: formatted documents, multimedia files

File type: generally determined by the extension (also known as the file extension, separated by ".")

10.2 File Operation

Why is there an operation to open a file?

The data structure is required:

  • Open Files Table: Tracks open files
  • File pointer: point to the last read and write location

10.3 File structure

logical file

The organizational structure of files presented to users

Also known as file logical structure

The logical file determines the file access method

File access method:

  • Sequential access: access one after another, typical representative: files on tape
  • Direct access: you can specify a path to the file, typical device: disk
logical file storage access data
sequence file ~40MB ~400K
direct file ~100MB 100B
index file ~44MB 44B

10.4 File directory

File control block FCB: store various attributes required for file operations

i Node (lower ds)

Index node: The directory entry only holds two things, the file name and the pointer (pointing to the i Node, which stores information other than the file name, including the location of the file)

single level directory

two-level directory

tree directory

Directed Acyclic Graph: File Sharing

Hard Links vs Soft Links

Click the link below to view the specific use

The difference between hard links and symbolic links - Brief Book (jianshu.com)

Hard link function:

The role of the hard link is to allow a file to have multiple valid path names, so that users can establish a hard link to important files to prevent "accidental deletion" function. Deleting only one connection does not affect the node itself and other connections. Only when the last connection is deleted, the connection of the data block of the file and the directory will be released. In other words, the condition for a file to be truly deleted is that all hard-linked files related to it are deleted.

Also, if you create the link name as a hidden file beginning with ., you can also hide your privacy very well.

Soft link function:

Soft links are also called symbolic links (Symbolic Link). Soft link files are similar to Windows shortcuts. It's actually a special file. In a symbolic link, the file is actually a text file that contains information about the location of another file

Advantages and disadvantages:

Soft links overcome the shortcomings of hard links. There is no file system limitation, and any user can create symbolic links pointing to directories. Therefore, it is more widely used now, and it has greater flexibility, and can even link files across different machines and different networks.

Of course, soft links also have the disadvantages that hard links do not have, because the link file contains the path information of the original file, so when the original file is moved from one directory to another directory, and then access the link file, the system will not find it, and the hard link will be Without this defect, you can move it as you want; and it requires the system to allocate additional space to create a new index node and save the path of the original file.

MOOC unit work

1. Each directory file of a file system can store up to 40 subordinate files (directory files or ordinary files), and each physical block can store 10 directory entries. 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 file control block of the ordinary file. My questions are:
1) If a single-level directory is used, how many physical blocks should be read at most and at least to find a file?
2) If a secondary directory is used, what is the maximum and minimum number of physical blocks that need to be read in to find a file?

Single-level directory: at most 5 physical blocks, at least 2 physical blocks, reading in FCB is also counted as reading in physical blocks once

Secondary directory: up to 9 physical blocks, minimum 3 physical blocks

2. What is the purpose of introducing the i-node into the file system of the Unix system? Please give an example.

‍Reducing the size of directory entries also reduces the number of read blocks.

Example:

Suppose the physical block size is 4KB, and there are 10,000 files in a certain directory.

The FCB (directory entry) size of each file is 2KB, then

Catalog file size: 20000KB

The number of physical blocks required by the directory file: 5000 blocks

The average number of physical blocks that need to be accessed to retrieve files: (5000+1)/2=2500.5

After using the inode, the size of an inode is 64B

Directory file size: 640000B=625KB

The number of physical blocks required by the directory file: 157 blocks

The average number of physical blocks that need to be accessed to retrieve files: (157+1)/2=79

3. Please talk about the disadvantages and advantages of symbolic links used in Windows.

‏Advantages:

Soft links overcome the shortcomings of hard links. There is no file system limitation, and any user can create symbolic links pointing to directories. Therefore, it is more widely used now, and it has greater flexibility, and can even link files across different machines and different networks.

shortcoming:

Because the link file contains the path information of the original file, when the original file is moved from one directory to another directory, and then the link file is accessed, the system cannot find it.

It requires the system to allocate additional space for creating new inodes and saving the path of the original file.

4. Please give an example to explain which files are better to use sequential files, and which files are better to use direct files? Why?

‌File information is stored in order, and sequential files are used for one-record-by-record access, because such files can only be accessed in sequence, so it is better to use sequential files for storage.

The file that wants to directly locate a certain record of the file for access uses the direct file, because for those who want to directly access a certain location, the direct file access is efficient and can be quickly located.

5. In the tree directory, is it better to have more directory levels? Why? please give an example

It is not that the more directory levels the better, because to search for a file in the tree directory, you need to visit the intermediate nodes step by step according to the path name, which increases the number of disk accesses and will undoubtedly affect the query speed. If there are many directory levels, there may be a lot of disk access times.

Guess you like

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