[Notes] Operating System (10)-File System Interface

Preface

The most difficult part of the operating system has passed, and then the storage management part. This chapter is easy to understand because we can relate to the PC file system used, so we are not unfamiliar at all.

1. File concept

A file is a named collection of related information recorded in external storage. From the user's perspective, a file is the smallest allocation unit of logical external storage. That is, data cannot be written to external storage unless it is in a file.

Generally, files represent programs and data. Data files can be numbers, characters, alphanumeric or binary. The file can be in free form, such as a text file, or it can have a strict form. Generally, a file is composed of bits, bytes, and licensed records, and its specific meaning is defined by the creator and user of the file . Therefore, the concept of a file bag is extremely broad.

1. File attributes

  • name
  • Identifier: A unique label that identifies a file in the file system, usually a number; this is an unreadable file name for humans
  • Types of
  • position
  • size
  • Protection: Access control information that determines who can read, write, execute, etc.
  • Time, date, and user ID: information about file creation, last modification, and last access. This data is used for protection, security and usage tracking.
  • and many more

2. File operations

  • Create a file
  • Write file
  • Read file
  • Relocate within the file
  • Delete Files
  • Truncate file
  • and many more

The attributes of each opened file:

  • File pointer: For systems that do not use the file offset as the system call read() and write() parameters, the system must track the last read and write position as the current file position pointer. This pointer is unique to a certain process that opens the file, so it must be stored separately from the disk file attributes.
  • File open counter: indicates that the file is opened by several processes. Because multiple processes may open the same file, the system must wait for the last process to close the file before deleting the open file entry. The file opening counter tracks the number of openings and closings, and the entry can be deleted when the counter is 0 at the last closing.
  • File disk location
  • access permission

3. File Type

Insert picture description here
The role of file types

  1. It is convenient to let the operating system know whether it supports identifying the current operation type.
  2. Determine which program can operate the current file by file type.
  3. Determine the internal structure of the document.

2. Access method

1. Sequential access

Based on the file-based tape model, file information is processed in sequence, one record at a time, not only for sequential access devices, but also for random access devices. For example, editors and compilers. A large number of file operations are read and write. The read operation reads the next part of the file and automatically moves the file pointer forward to track the I/O position. Similarly, a write operation will add content to the end of a file, and the corresponding file pointer will move after the newly added data.
Insert picture description here

2. Direct access

File-based disk model, this is because the disk allows random reading and writing of arbitrary file blocks . For direct access, the file can be used as a block or record number sequence. Therefore, you can read block 14 first, then read block 53, and finally write block 7. For direct file access, the read and write order is unlimited.

  • Direct access to the file provides immediate access to a large amount of information, so it is extremely useful. Databases usually use this type of file.
  • The block number provided by the user to the operating system is usually a relative block number. The relative block number is an index relative to the beginning of the file. Therefore, the number of the first block of the file is 0, the next block is 1, and so on. The real absolute disk address of the first block may be 14703, the next block is 3098, etc.

Insert picture description here

3. Access in other ways

Other access methods are usually based on indexes. These visits usually involve the creation of file indexes. The index includes pointers to each block.
Insert picture description here

Third, the directory structure

1. Storage structure

Insert picture description here

2. Directory overview

The file system realizes "access by name" to files.

The file system needs to establish such a data structure to realize the mapping relationship between the file name and the physical location of the file. The data structure that reflects this correspondence is called a file directory. Each leaf node of the directory is guaranteed to be retrieved by the file name and contains information about the physical location of the file.

Insert picture description here

The directory can be regarded as a symbol table, which can convert file names into directory entries

** Directory related operations: **

  • Search file
  • Create a file
  • Delete Files
  • Traverse directory
  • Rename file
  • Tracking file system: manage files, including backup and release disk space.

3. Single-level directory structure

Insert picture description here
Advantages: simple structure, easy to support.

Disadvantages: naming duplication problem, user grouping problem, file sharing problem between different users.

4. Two-tier directory structure

Insert picture description here
Advantages: Solving naming problems and efficient searching.

Disadvantages: File sharing issues between different users (some systems simply do not allow local users' files to be accessed by other users).

5. Tree structure directory

Extend the directory structure to a tree of any height, and no longer distinguish different subdirectories according to users, so files under other users can be accessed through paths.

Absolute path: The directories on the path are given from the root to the directory file.

Relative path: Define the path starting from the current directory.
Insert picture description here
Advantages: easy to manage, efficient search.

Disadvantages: sharing the same file by multiple users.

6. Catalogue of Acyclic Graphs

The operating directory contains shared subdirectories and files. Shared files are not used for file copying. For a shared file, there is only one real file. When multiple users work in a group, you only need to set the shared file directory as a subdirectory under each user directory to complete group sharing.
Insert picture description here
Advantages: realize file sharing

Disadvantages:

  • There are multiple absolute paths for the same file, which are counted repeatedly when traversing.
  • If you delete a shared file, it will leave a dangling pointer.

solve:

  • Proposed symbolic link: also known as the concept of soft link, that is, a pointer to a shared directory, which is realized by an absolute path name, and the real file is located through the path name to obtain analysis, which is different from the only absolute path of the shared file. That is, what it stores is not a real file node, but a pointer to the real file node. Pointer to pointer.
  • After the introduction of the link concept, when the actual file is deleted, the link remains, and the user is notified that the link is invalid when the user accesses the link to access the file. Both Windows and Unix use this method.

7. List of General Diagrams

When a ring is allowed in the directory, there is a problem of repeated traversal and a problem that the reference count cannot be 0 and can never be deleted because of its own reference when it is deleted.

solution:

  • Set the maximum number of traversals in the infinite loop traversal, if it exceeds, it will automatically jump out.
  • Traverse it twice, the first pass marks all accessible spaces, and the second pass adds the unvisited spaces to the free space linked list.

Insert picture description here

Four, file system installation

The file system must be installed before being used by the process. Specifically, the directory structure can be built on multiple volumes, which must be mounted in order for them to be used in the file system namespace. Usually, the mount point is an empty directory.

In the figure below, the triangle represents the directory subtree. Picture ah shows an existing file system, picture b shows an uninstalled file system residing on the hard disk. At this time, only the file in Figure a can be accessed. Figure c shows the situation of the file system after mounting the volume in Figure b to /users** ( that is, the original file directory under /users will be hidden after installation )**. At this time, only the directory shown in Figure c can be accessed. After uninstalling the installed file system, the file system is restored to the situation shown in Figure a.

Figure a: Existing file system

Figure b: Unmounted volume

Figure c: Mounting point
Insert picture description here

Insert picture description here

Five, protection

The file owner specifies the access rights of the file.

Take Unix as an example:

  • Unix authorizes three groups of users: owner, group, and public through three basic operations: Read, Write, and Execute.
  • Using 9-bit binary representation, 1 means allow, 0 means deny.
  • Example: 111 110 001 means the owner can read, write, and execute, the same group of users can read, write, and the public user can execute.

Guess you like

Origin blog.csdn.net/qq_41882686/article/details/112878561