Ten years of JAVA relocation - operating system file system

An operating system file system is a mechanism in an operating system for organizing and managing files and directories. It provides a structured way to store, access and manage file data.

1. File : A file is a unit of data stored in a computer system. It can be various types of data such as text files, image files, audio files, etc. Files are identified by a filename and extension, and can contain metadata about the file, such as creation time, modification time, etc.

2. Directory : A directory is a container used to organize and manage files. It can contain files and other directories, forming a hierarchy. Directories are identified by a path, which is a string describing the location of the directory, which can be absolute (starting from the root directory) or relative (relative to the current directory).

3. File operations : The file system provides a set of operations to manage files, such as create, open, read, write, delete, rename, etc. These operations allow applications to read and write files and provide file access control.

4. File system hierarchy : File systems can adopt different hierarchical structures. Common file system hierarchies include hierarchical directory structure, flat directory structure and index directory structure. They determine how files and directories are related and organized.

5. File system management : The file system is also responsible for managing the physical space allocation on the storage device and the storage location of files. It uses data structures such as bitmaps, inodes, etc. to track the location and status of files and ensure file integrity and reliability.

The file system is an important part of the operating system, which provides convenient file management and access for applications and users. Different operating systems may use different file systems, such as Windows using NTFS, Linux using EXT4, etc.
**

Operating system file organization

**
The file organization method of the operating system refers to how the operating system organizes and manages files.

1. Hierarchical file organization : This method organizes files into a hierarchical structure, similar to a tree structure. The root directory is at the top level, and each subdirectory can contain files and other subdirectories.

2. Flat file organization : In a flat file organization, all files are stored in the same directory, and there is no concept of subdirectories. File names must be unique to avoid conflicts.

3. Indexed file organization : Indexed file organization uses an index table to record the location and attributes of files. This index table can be searched and sorted according to file names, file types, etc., to improve file access efficiency.

4. Relational file organization : Relational file organization uses the concept of database to organize files. Documents are treated as records and can be retrieved and managed using the query language of a relational database.
Rather than storing files directly as binary streams, relational file organization stores the file's attributes and metadata in database tables. In a relational database, files are treated as records, and each record contains the properties of the file (such as file name, size, creation date, etc.) and a pointer or reference to the actual location where the file is stored. The actual file contents are typically stored in binary form on disk rather than directly in a database table. Records in database tables contain references to where the files are actually stored, allowing the file contents to be accessed and manipulated when needed.

5. Object-based file organization : Object-based file organization treats files as objects, and each object has its own properties and methods. This method can manage files more flexibly and supports object-oriented programming ideas.

File Control Block (FCB)

**File Control Block (FCB)** is a data structure used in the operating system to manage files. Each file has a corresponding file control block in the file system. The file control block contains the file's metadata and attribute information, as well as the file's physical location on the storage device.

File control blocks typically contain the following information:

1. File attributes : including file name, file type, file size, creation date, modification date, etc.

2. File permissions : records the file's read, write, execution and other permission information, used to control file access permissions.

3. File pointer : Points to the physical location of the file on the storage device, including the starting position of the file, the current read and write position, etc.

4. File status : records the open status, lock status, access count and other information of the file, and is used to control concurrent access and operations of the file.

5. File index : Stores the index information of the file, which is used to quickly locate and access the content of the file.

The function of the file control block is to provide an abstraction layer through which the operating system can manage and operate files, including creating, opening, closing, reading, writing, deleting and other operations. The design of the file control block can vary according to different file systems and operating systems, but its basic purpose is to effectively manage and control file access and operations.

File storage control

File storage control refers to how the operating system manages and controls the storage and access of files on storage devices. It involves the physical storage location of files, file read and write operations, file allocation and release, etc.

The implementation of file storage control usually includes the following aspects:

1. File allocation : File allocation refers to allocating space for files on a storage device. Common file allocation methods include continuous allocation, chain allocation and index allocation.

  • Contiguous allocation: Store files on contiguous disk blocks. This approach is simple and intuitive, but can lead to external fragmentation issues.
  • Chained allocation: Use a linked list to link the data blocks of a file together. Each data block contains a pointer to the next data block. This approach avoids external fragmentation but may result in less efficient access.
  • Index allocation: Use an index table to indicate the location of data blocks in a file. Each entry in the index table contains a pointer to a data block. This method can improve file access efficiency, but requires additional index table space.

2. File reading and writing : File reading and writing refers to the reading and writing operations of file contents. The operating system tracks the read and write locations of files through the file pointer in the file control block. When reading a file, the operating system reads the corresponding data block according to the file pointer. When writing to a file, the operating system writes the data to the appropriate location and updates the file pointer.

3. File protection : File protection refers to the permission control and security management of files. The operating system restricts file access rights through the permission fields in the file control block to ensure that only authorized users can access and modify the file.

4. File management operations : The operating system provides a series of file management operations, such as creating files, deleting files, renaming files, copying files, etc. These operations involve the creation, update, and deletion of file control blocks.

file system hierarchy

The hierarchical structure of a file system refers to the organizational relationship between files and directories, similar to a tree structure. In a file system, the root directory is at the top level, while other directories and files are located at different levels below the root directory.

1. Root directory : The root directory is the top-level directory of the file system, and all other directories and files are located below the root directory. The root directory is usually the starting point of a file system, through which the contents of the entire file system can be accessed.

2. Directory : Directory is a special file used to organize and store files and other directories. Each directory can contain multiple files and subdirectories. Through the hierarchical relationship of directories, a multi-layer directory structure can be formed. Subdirectories can contain more subdirectories, creating a deeper hierarchy.

3. Path : A path is a string used to locate a file or directory in a hierarchy. Paths can be absolute or relative. An absolute path starts from the root directory and continues to the full path of the target file or directory. Relative paths are paths relative to the current directory.

4. File : File is the basic unit for storing data, which can be text files, image files, audio files, etc. Files can be stored directly in the directory or in subdirectories. Hierarchy allows files to be organized in different directories for better management and access.

The hierarchical structure of the file system provides a logical organization that makes the storage and access of files more orderly and flexible. Hierarchy makes it easy to locate and manage files while providing better scalability and maintainability.

disk structure

A magnetic disk is usually made up of multiple platters (or platters), each of which has two sides (top and bottom). Each surface is divided into one or more concentric tracks, and the tracks are divided into sectors.

The structure of a disk can be described as a three-dimensional cylinder model, which consists of identical tracks on multiple disks to form a cylinder. Cylinder refers to the relative position on all platters on the same track. For example, the first track on all platters forms the first cylinder, the second track on all platters forms the second cylinder, and so on.

Each sector has a unique address that is used to locate and access data on the disk. Sectors usually have a fixed size, a common sector size is 512 bytes or 4KB.

In order to read and write data, the disk is equipped with a head that can move on the surface of the disk. The heads can be positioned between different tracks to access specific sectors.

The structure and working principle of magnetic disks are an important part of computer storage. They provide high-speed data storage and retrieval capabilities and are widely used in hard drives and other storage devices in computer systems.

Common disk scheduling algorithms

  1. First-Come, First-Served (FCFS): Disk access is performed in the order of requests, that is, the request that arrives first is served first. This algorithm is simple and intuitive, but it may lead to a long average seek time and is not suitable for situations where disk access pressure is high.

  2. Shortest Seek Time First (SSTF): Select the request closest to the current head position for access to minimize the seek time. This algorithm can improve the response speed of the disk, but may cause some requests to wait for a long time.

  3. Scan algorithm (SCAN): Also known as the elevator algorithm, the head moves in one direction, processes requests in that direction in turn, until it reaches the edge, and then moves in the opposite direction. This algorithm can avoid long waits for some requests, but may cause some requests to be skipped during head movement.

  4. Circular scan algorithm (Circular SCAN, C-SCAN): similar to the scan algorithm, but the head does not move in reverse after reaching the edge, but directly returns to the innermost circle for the next round of scanning. This algorithm can improve disk throughput, but may result in longer wait times for some requests.

  5. Shortest Time First (STF): Sort requests based on their completion time, and prioritize requests that take the shortest time. This algorithm can minimize the total disk access time, but requires knowing the execution time of each request in advance.

Each of these disk scheduling algorithms has advantages and disadvantages and is suitable for different application scenarios and access patterns. Choosing an appropriate disk scheduling algorithm can improve disk performance and efficiency.

Inexpensive redundant storage array

Cheap Redundant Array of Independent Disks (RAID) is a technology that provides data redundancy and performance improvement by combining multiple disks. RAID can provide redundant backup of data to prevent data loss caused by a single disk failure, and can improve data read and write performance by accessing multiple disks at the same time.

There are different levels of RAID, common ones include:

  1. RAID 0: Striping, which stores data on multiple disks to improve read and write performance, but does not have a redundant backup function.
  2. RAID 1: Mirroring (Mirroring), writes data to two disks at the same time, providing redundant backup, but does not improve performance.
  3. RAID 5: Striping with Parity, which stores data and parity information on multiple disks, provides redundant backup and improves read and write performance. Requires at least 3 hard drives
  4. RAID 6: Similar to RAID 5, but uses two parities for a higher level of redundancy. Requires at least 4 hard drives
  5. RAID 10: Combine multiple RAID 1s into RAID 0 to provide redundant backup and improved read and write performance.

Guess you like

Origin blog.csdn.net/weixin_43485737/article/details/132832207