Operating system core principles-6. External memory management (next) file system

Source: Internet
Author: User
Tags file copy

Why do I need a file system?

Disks are characterized by high capacity, low cost, and persistence, and the data on the disk is not lost even if a power outage occurs. However, it is very difficult for the average user to use the disk because they do not know how to drive a disk and calculate where the data is stored on disk. As you can see from the previous disk basics, understanding the technical details of the disk will overwhelm the user.

The operating system is a magician, which gives the user a variety of fantasies: abstraction . The process is abstract CPU, virtual memory is abstract memory, for the disk, the operating system provides users with the help is to wrap a layer of easy-to-use abstraction outside the disk, the user directly with this layer of abstraction, without needing to know the technical details of the disk. In the operating system, the abstraction that this layer provides to disk is: The file system .

Ii. Basic concepts of the document System what is a 2.1 file system?

The file system is an abstraction that the operating system provides between the disk and the user, and it is a non-existent, invisible interface, as shown in:

(1) the file system makes it easy for users to use the disk : Freeing the user from the details of the data stored, the user does not need to know where the content is stored, does not need to know how to store it, and does not need to know how the disk works.

(2) To put it simply, the file system translates the physical characteristics of the disks it touches into the path names and file names that the user sees. user access to the disk only need to give the file name and path name, without having to know the magnetic column, track, sector, data block and other information .

(3) The main feature of the file system is to store a large amount of information, multiple processes can access a file at the same time, the end of the process will not affect the persistence of the file .

2.2 Objectives of the file system

(1) address Independent

A file does not have to worry about the disk address it holds when it is generated, that is, the creation of the file data is independent of the disk address that the file will store in the future.

(2) address protection

  Address protection requires certain restrictions on access to files, which means that no one can access any files.

difference: file system address protection and memory management under the different address protection, memory management under the address protection refers to a process cannot access another process space, and the file system address protection is not a file cannot access another file space, There is a limit to the access of a file.

2.3 Basic knowledge of files

(1) file naming

A file name can be easily accessed by the name of either English, Chinese, or image names. When the user gives a filename, the operating system can find the content of the corresponding file according to the name. Specifically, you find all the blocks of data that the file holds on disk .

The operating system translates the file name to the address of its data block on disk, because the disk's addressing unit is a sector, and these disk addresses are actually a slice number.

(2) Extension

Extensions are often used to indicate the type of file, how a text file, a binary file, and so on. For example: FILE.C indicates that the file is a C language source file. The extension's indication of the file category is indicative only and is not mandatory.

(3) Content addressing

In addition to giving the filename, you can also give the contents of the file for the operating system to find the use. The database system is a typical application of this kind of realization method.

(4) File access

① Sequential access: accesses from the beginning and reads the data in first served order.

② Random Access: Data records can be read in any order, just as we can watch DVDs and randomly select the paragraphs you want to see.

(5) File attributes

In addition to a file name, there is a lot of information that we are interested in, so the file also has some properties. Different operating systems, the type and number of attributes for a file are different, but each has its own purpose, and the following table lists common file attributes:

(6) File operation

You can manipulate files by creating/deleting, opening/closing, reading and writing additions, finding access locations, reading properties/setting properties, renaming, and so on.

Three, folder implementation address Independent 3.1 Why you have a folder

We can read and write files, then give a file name, how does the operating system know where to read the contents of the file? In other words, what is the location of the file on disk and how does the operating system know? This requires a data structure to record the address of each file on the disk, which is the folder .

Folders, also known as folder, are the trace files that store the mapping of the address from the file to the disk on which the file is located, the "file name → The address on the disk where the file resides ." A folder is a translation mechanism for a file, from a virtual address to an actual address.

3.2 Folder structure

Because folders can have subfolders, a hierarchy is formed, at the top of which is the root folder (also known as the root directory), as shown in:

The root directory is the total starting point of a file system that is loaded into memory when the operating system starts. From the root directory, all files within the filesystem can be found.

Iv. File System invocation 4.1 The "interface" provided by the operating system

The file system interface provided by the operating system to the user is a file system call that users can use to read and write to the file system through these system calls. These system calls include: Open files, close files, read file contents, write file contents, and so on.

4.2 File System Invocation Instance

Shows a simple instance program written in C that uses file system invoke to implement file copy:

The above file copy program is to open source files and target files, and then cycle through the source file content read into a buffer, and then write the contents of the buffer to the output destination file. When the copy is finished, close the source and destination files.

Resources

Heng Hengming, "The philosophical principles of the operating system", mechanical industry Press

Zhou Xurong

Source: http://edisonchou.cnblogs.com

The copyright of this article is owned by the author and the blog Park, welcome reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to give the original link.

Operating system core principles-6. External memory management (next) file system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.