"Operating System" file management (vi)

Source: Internet
Author: User

First, preface

This is the last article of the operating system series, file management, because the system's memory is limited and can not be stored for a long time, so usually always put them in the form of files in the external memory, need to transfer them into memory. How to manage files efficiently is the target of operating system implementation.

II. Documentation and documentation systems

The modern OS almost always organizes and manages a large number of programs and data stored in a computer through a file system. The management function of a file system is achieved by organizing the programs and data that it manages into a series of files . A file is a collection of several related elements that have a file name. An element is usually a record, and a record is a set of meaningful data items . Data can be composed into data items, records, files.

Data items, data items are the lowest-level data organization. is divided into basic data items (a character set used to describe a property of an object, which is the smallest logical unit of data in the data organization, i.e. atomic data, also known as a data element or field) and a combined data item (consisting of several basic data items)

A ② record is a set of related data items that describe a property of an object in some way, in order to uniquely identify a record, to identify one or collection data item in the record, to refer to their collection as a keyword, which is a data item that uniquely identifies a record.

A ③ file , a collection of related elements with a file name, is divided into structured files and unstructured files. Structured files consist of several related records, and unstructured files are treated as a stream of characters. The file is the largest unit of data for the file system. The file should have its own properties, including the file type (such as source, destination, executable, etc.), the file length (the current length of the file, or the maximum allowable length), the physical location of the file (A pointer indicating where the file is on the device and where it is located), the time the file was established (the last time the file was modified).

A file can correspond to several records, and one record can correspond to several data items.

File System Management Objects are: files (as a direct object of file management), directory (in order to facilitate user access and retrieval of files, in the file system configuration directory, each directory entry, must contain the file name and the location of the physical address, The organization and management of the directory is convenient and improve the file access speed of the key), disk (disk) storage space (files and directories must occupy storage space, the effective management of this part of the space can not only improve the utilization of external memory, but also improve the access speed of files).

 2.1 File Operations

Create a file , when creating a new file, the system first allocates the necessary external memory space for the new file, and establishes a directory entry for it in the directory of the file system, and the directory entry should record the name of the new file and its properties in the external memory address.

Delete A file, you can remove it from the file system when it is no longer needed, and when it is deleted, the system should first find the directory entry from the directory to delete the file, make it an empty item, and then reclaim the storage space that the file occupies.

Read The file, the file must be read in the corresponding system call to give the file name and the memory target address should be read in. At this point, the system looks for the directory and finds the specified directory entry where the read file will be located in the external memory. In the catalog item, there is also a pointer to read/write to the file.

Write a file, write the file, the corresponding system call must be given the file name and its memory source address. At this point, the system looks for the directory, finds the specified directory entry, and writes from a write pointer in the reuse directory.

truncate the file , if the content of a file is obsolete and need to update all, one way is to delete the file, and then recreate a new file, but if the file name and attributes are not changed, you can take the method of truncating the file, which set the original file length of 0, discard the contents of the original file.

Sets the read/write location of the file to set the location of the file read/write pointers so that each time you read/write the file, you do not need to start from the beginning but from the location you set. Sequential access can be changed to random access.

Most of the operations of the file currently provided by the OS are generally done in two steps: First, retrieve the file directory to find the properties of the specified file and its location on the external memory, and then implement the appropriate operations on the file, such as read/write files, etc., when the user requires multiple read/write or other operations on a file, Each time you start by retrieving the directory, to avoid retrieving the directory multiple times, the open file system call is introduced in most of the OS, and the first time the user requests a file system operation, the file is opened with the open system call.

  open means that the system copies the attributes of the named file (including the file's physical location on the external memory) from external memory to a table in the Memory open File table, and returns the table destination number (index number) to the user , and later, when the user asks for the file to be manipulated again, You can use the index number returned by the system to request the operation of the system, the system can directly use the index number to open the file table to find, so as to avoid the re-retrieval of the file, if the user no longer need to implement the operation of the file, you can use the shutdown system call to close the file, The OS will remove the file from the table in the Open File table.

Third, the logical structure of the document

The following two forms of structure exist for any file

The logical Structure of the ① file, which is a form of file that is observed from the user's point of view, is the data and its structure that the user can directly manipulate, independent of the physical characteristics of the file, also known as the file organization.

The physical structure of the ② file, also known as the storage structure of the file, refers to the storage organization of the file on the external memory, not only to the storage medium, but also to the external memory distribution mode.

  3.1 Types of file logical structures

The logical structure of the document can be divided into two categories, one is a structure file , which refers to a file composed of more than one record, so that he is called a record file, and another type of unstructured files , which refers to the character stream composed of files, also known as streaming files.

has a structure file , each record is used to describe an entity in an entity set, each record has the same or different number of data items, records are divided into fixed-length records (the length of all records in the file is the same, all records of the data items are in the same position in the record, Have the same order and length) and variable length records (the lengths of the records in the file are different, possibly because the data items contained in one record are not the same). Depending on the needs of the user and the system, these records can be organized in a number of ways, such as sequential files (records are formed in some order, records are usually fixed-length, records in files can be found quickly), index files (when recorded as variable length, You typically create an index table, set a table entry for each record, speed up the retrieval of records, and index order files (an index table for a file that sets a table entry for the first record in each group of records).

unstructured files, for source programs, executables, library functions, etc. are usually used in the form of unstructured files, that is, streaming files, the length in bytes.

  3.2 Sequential Files

A file is a collection of records, which can be in any order, so it can be arranged in a variety of different order, generally, can be summed up in the following two cases.

string Structure , the order of the records is not related to the keyword, usually in chronological order, the first record is recorded as a record, followed by a second record, and so on.

Sequential Structure , all records in the file are listed by keyword, and can be arranged from large to small by keyword length. Sequential structures are more efficient to retrieve.

The best application for sequential files is when bulk access to records, that is, every time you want to read or write a large number of records, at this time, the sequential file access efficiency is the highest in all logical files, in addition, only sequential files can be stored on tape, and can work effectively. However, it is more difficult to add or delete a file.

  3.3 Index File

For fixed-length recording files, sequential access and direct access can be conveniently implemented, however, it is difficult to achieve variable-length records. In order to solve the variable length record retrieval problem, an index table for the variable length record file is established, and for each record in the master file, a corresponding table entry is provided in the Index table to record the length of the record and the pointer to the record (point to the first address of the record in the logical addressing space), because the index is sorted by record key The Index table itself is a sequential file of fixed-length records . Thus, direct access can be achieved conveniently.

When the index file is retrieved, first based on the keywords provided by the user (program), and using binary to find the index table, find the corresponding table entry, and then use the table key to point to the record pointer value, to access the required records. The index table must be modified whenever a new record is added to the index file. The problem with index tables is that, in addition to having a primary file, you need to configure an index table that requires an index entry for each record, thus increasing storage costs.

  3.4 Index Order File

It overcomes the disadvantage that the variable length record is inconvenient to the direct access, and the cost is not too big, it is the product of the combination of sequential file and index file, it divides all the records in the sequential file into several groups, and establishes an index table for sequential files. Establish an index entry in the index table for the first record in each group that contains the key value of the record and a pointer to the record.

When retrieving the index sequence file, first use the keyword and some search algorithm provided by the user to retrieve the index table, find the table item of the first record in the record group, get the position of the first record in the main file of the record group, and then use the sequential lookup method to find the main file. Find the required records from the.

  3.5 Direct files

For a direct file, the physical address of the specified record is obtained directly according to the given record key value, in other words, the record key value itself determines the physical address of the record, which is called a key-value conversion from the record key value to the physical address of the record.

  3.6 Hashing (hash) file

  using the hash function can convert the record key value to the address of the corresponding record , in order to realize the dynamic allocation of the file storage space, usually the hash function is not the corresponding record of the address, but to a table of contents table The purpose of the pointer, the table destination content points to the corresponding record of the physical block.

Iv. distribution mode of external memory

Because the disk has a direct access feature, it provides a lot of flexibility when the disk is used to store files. And the physical structure of the document is related to the distribution of the outer village, in the use of continuous distribution mode of the file physical structure is a sequential file structure, in the use of link allocation will form a linked file structure, and index allocation will form an indexed file structure.

  4.1 Continuous distribution

Continuous allocation requires that each file be assigned a contiguous set of blocks, and a set of disk block addresses defines a linear address on the disk. In the continuous distribution mode, the records in the logical file can be stored sequentially in the contiguous physical disk blocks, so that the resulting file structure is called the sequential file structure , which ensures that the sequence of records in the logical file is consistent with the order of the disk blocks in the memory. For continuous distribution (assuming the record is as large as the disk block).

As with dynamic allocation of partition allocations, as space is allocated during file creation and when file deletion is reclaimed, the disk space is split into many small chunks, which are hard to store files, which is external memory fragments, and similarly, you can use a compact method to close all the files on the disk together, Put all the pieces into a large contiguous storage space.

The advantages of continuous distribution are as follows

① sequential access is easy, and accessing a file that occupies contiguous space is easy.

② sequential access is fast, because the disk blocks that are loaded by successive allocations may be located on one or several adjacent tracks, which is the smallest head movement distance, and this speed of file access makes several storage space allocation methods the highest.

The disadvantages of continuous distribution are as follows

① requires contiguous storage space to allocate a contiguous amount of storage space for each file, resulting in a lot of external fragmentation, severely reducing the external memory space utilization, and regular compactness that can cost a lot of machine time.

② must realize the length of the file, know the length of the file beforehand, and then, depending on its size, find a chunk of its size enough in the storage space to mount the file, which is very inefficient for dynamically growing files.

  4.2 Link Assignment

If you store a logical file on a external memory, it does not require a contiguous space for the entire file, but it can be loaded into multiple discrete blocks, eliminating the disadvantage of continuous distribution. When using the link allocation method, a linked list of multiple discrete disk blocks belonging to a file can be linked to a linked file by means of a link pointer on each disk block, and the physical file is referred to as a link. The distribution of links takes the form of discrete distribution, eliminates the external fragments, and therefore significantly improves the utilization of external memory space, and it is very convenient for the file to be increased, deleted, changed and checked. Links can be divided into implicit links and display links in two forms.

Implicit links , in each directory entry in the file directory, must contain pointers to the first and last disk blocks of the linked file .

Note: The 9th disk block points to the 16th disk block, the 16th disk block points to the 1th disk block, the 1th disk block points to the 10th disk block, and the 10th disk block points to the 25th disk block (end block).

The main problem of implicit link assignment is that it is only suitable for sequential access, the efficiency of random access and its inefficiency. In addition, its reliability is poor, any one pointer problem, will lead to the entire chain of disconnection. You can make a cluster of several disk blocks, and then allocate them in clusters, reducing the time to find the specified block, but increasing the internal fragmentation.

displays a link to a pointer to each physical block of the linked file, explicitly placed in a linked table of memory, which is set only one sheet across the disk.

Description: The number of the table starts at 0, until N-1,n is the total number of disk blocks, the link pointer is stored in each table entry, that is, the next block number, in which the first block number belonging to a file, or the block number corresponding to the chain head pointer of each chain, is populated as the file address of the corresponding file. FCB ( The Physical Address field of the file Control Block, because the process of finding the record is in memory, thus lifting the retrieval speed, reducing the number of times to access the disk , because all the disk block numbers assigned to the file are in the table, Therefore, the table is called the file allocation table, FAT (Files Allocation table).

The problem with link assignment is as follows: efficient direct storage is not supported (for direct access to a larger file, a number of disk block numbers must be searched sequentially in fat);fat needs to occupy a larger memory space (Because the disk block number of the disk block used by a file is randomly distributed in fat, only the whole fat is transferred into memory to ensure that all the disk block numbers of a file are found in fat, and fat takes up more capacity when the disk capacity is large)

Index Allocation , in fact, when you open a file, just need to put the number of the disk block number of the file into memory, there is no need to put the entire fat into memory, for this, each file should be the corresponding block number of the central place together, The way of allocation of index is based on the idea of a form of distribution. It allocates an index block (table) for each file, and all the disk block numbers assigned to the file are recorded in the index block, which is an array of many disk block numbers. When you create a file, you only need to fill in the directory entry for which you are building a pointer to that index block (a single-level index ).

Description: The index mode supports direct access, you can find the block I in the index block, the index method will not produce external fragmentation, when the file is large, the index allocation is better than the link allocation method. The main problem is that it may take a lot of external memory space, and whenever a file is created, it must be assigned an index block that records all the disk block numbers assigned to the file. For small files, the utilization of index blocks is very low.

When the OS allocates disk space for a large file, if the disk block number of the allocated block is already full of an index block, the OS assigns another index block to the file, which is used to record the disk block number that continues to be allocated later, and so on, and then links each index block sequentially with the chain pointer, when the file is too large, Too many index blocks, efficiency is inefficient. At this point, you should establish a second index for these index blocks, called the first-level index, which can be re-indexed, called a secondary index, and so on. Called Multilevel Index allocation .

Note: In the two-level index allocation mode, if each disk block size is 1KB, each disk block number of 4 bytes, then in an index block can hold 256 block number, so that in the two-level index, can include the total number of disk block number of storage file is 64K (256 * 256) block number, The maximum allowed file length is 64MB, if the disk block number is 4KB, then the maximum file size of the first-level index is 4MB, and the maximum file size of the two-level index is 4GB.

Mixed Index allocation method, a combination of multiple index allocation methods, such as a direct address (set 10 direct address entries in the index node, each item is stored in the file data is the disk block of the block number, if each disk block size of 4KB, When the file is no more than 40KB, you can directly from the index node to read out the entire disk number of the file, an indirect address (using an address entry in the index node to provide an indirect address, which is essentially a first-class index allocation method, in an almost fast can be stored 1K disk block number, the maximum file is 4MB), Multiple indirect address (when the file is larger than 4MB + 40KB, the system uses two times the allocation method, its essence is the two-level index allocation method, two times the maximum file size of the address is 4GB, the same, can use three indirect addresses, the maximum file size is 4TB).

V. Directory Management

In order to be able to effectively manage the file, they must be properly organized, which is mainly through the file directory, the file directory is a data structure, used to identify the system files and their physical address for retrieval purposes, the directory management requirements are as follows

Implementation of the name Access , that is, users only need to provide the system with the required access to the name of the file, you can quickly and accurately locate the specified file on the external memory storage location, which is the most basic function of directory management.

Improve the speed of directory retrieval , through the rational organization of the directory structure of the method, can speed up the retrieval of the directory speed, so as to improve the file access speed.

file sharing , in multi-user systems, users should be allowed to share a file.

allow file names, the system should allow different users to use the same name for different files, so that users according to their own habits to name and use files.

  5.1 File control block

  In order to be able to access the file correctly, the file must be set up for describing and controlling the data structure, called the file control block FCB, the file management program can use the information in the file control block, the file to apply a variety of actions, files and file control block one by one corresponding, and people put An ordered set of file control blocks is called a file directory , and a file control block is a file directory entry. Typically, a file directory can also be viewed as a file, called a catalog file .

The file control block contains basic information, access control information, and usage information.

basic information , including the name of a file (identifying the symbol name of a document, in each system, each file has a unique name, the user to access the name); The physical location of the file (the location where the file is stored on the external memory, including the name of the device that holds the file, the file's starting block number on the foreign village, Indicates the file length of the disk block or bytes occupied by the file, the logical structure of the file (indicates whether the file is a streaming file or a record file, the number of records, whether the file is fixed or variable length), the physical structure of the file (indicates whether the file is sequential, chained, or indexed)

access control information , including access to the main file, authorized user access and access rights of the general user.

usage information , including the date and time the file was created, the date and time the file was last modified, and the current usage information (this information includes the number of processes currently open the file, whether it is locked by another process, whether the file has been modified in memory but not yet copied to the disk)

  5.2 Index nodes

  The file directory is usually stored on disk , when there are many files, the file directory may occupy a large number of disk blocks, in the process of searching, the first disk block of the directory file into memory, and then the user given the file name and directory entries in the file name by comparison. If the specified file is not found, then the directory entry in the next disk block is then transferred to memory. When retrieving a catalog file, only the file name is used, only when a directory entry is found (that is, where the file name matches the name specified to find), the physical address of the file needs to be read from the directory entry, and some other information describing the file is not available when retrieving the catalog , obviously, This information does not need to be transferred into memory when retrieving the directory .

   Each file has a unique Disk index node , which mainly includes the following

The ① file master identifier, which is the identifier of the individual or group that owns the file.

② file types, including regular files, catalog files, or special files.

③ file access rights, refers to various types of user access to the file.

④ the physical address of the file, each index and the order contains 13 address items, they directly or indirectly give the data file where the number of the disk block.

⑤ file length, which is the length of the file in bytes.

The ⑥ file connection count indicates that all pointers to the file name are counted in this file system.

⑦ file access time, which is the time the file was most recently accessed by the process, the time it was recently modified, and the time the index node was recently modified.

When the file is opened, the disk index node is copied to the Memory index node for later use, adding content to the memory index node.

The ① index node number that identifies the memory index node.

② status indicating if I node is locked or modified.

③ access count, whenever there is a process to access this I node, the access Count plus 1, access and then minus 1.

The logical device number of the file system to which the ④ file belongs.

⑤ the link pointer, set a pointer to the idle list and the hash column, respectively.

  5.3 Directory Structure

directory structure of the Organization, related to file system access speed, but also related to file sharing and security, the current commonly used directory structure form a single-level directory, two-level directory, multilevel directory.

Single-level directory structure , in the entire system to create only a table of contents, each file for a directory entry, directory entries containing the file name, file extension, file length, file type, the physical address of the file, the status bit (indicates whether the catalog item is idle) and so on. Whenever you want to create a new file, you must first check all the directory entries to ensure that the new file name is unique in the directory, and then find a blank directory entry in the table of contents, fill in the new file filename and other explanatory information, and set the status of 1, delete the file, first find the file directory entry from the directory. Reclaim the storage space that the file occupies, and then clear the directory entry. A single-level directory is a bit simple and can implement the basic function of directory management-access by name, but slow lookup (find a directory entry takes more time), do not allow duplicate names (all files in one directory table cannot have the same name as another file, which is unavoidable), It is not easy to implement file sharing (each user has his or her own namespace or naming habit, so different users should be allowed to access the same file using different filenames)
Level Two directory structure , create a separate user file directoryfor each user UFD (user file directory), these file directories have a similar structure, composed of file control blocks for all files of the user. In addition, the system also has a Master file directory MfD(master Files directory), in the main file directory, each user directory file occupies a directory entry, whose directory entries include the user name and pointer to the user directory file .

Level two directory structure customer service The disadvantage of a single-level directory, has the following advantages: improve the speed of retrieving the directory (if there are N subdirectories in the home directory, a maximum of M directory entries per user directory, to find a specified directory entry, at most only need to retrieve n+m directory entries). In different user directories, the same file name can be used (as long as in the user's own UFD, each file name is unique, different users can have the same file name). Different users can also use different file names to access the same shared file on the system . However, when multiple users need to work together to complete a large task, it is inconvenient to share files among users.

③ Multi-level directory structure, for large file systems, usually use three or more levels of directory structure, to improve the retrieval speed of the directory and file system performance. The multilevel directory structure is also called the tree structure, the main directory is called the root directory , the data file is called the leaf , and the other directories are the nodes of the tree .

Description: The box represents the directory file, the circle represents the data file, the main directory has the user total directory A, B, C, in the B user's total directory B, also includes three sub-directories F, E, D, where each sub-directory contains multiple files, in order to improve the system flexibility, directory entries that should be allowed in a directory file are both the FCB for the catalog file and the FCB for the data file, which can be indicated by one of the catalog entries. As in user A's total directory, directory entry A is the catalog file FCB, and catalog items B and D are the FCB for the data file.

In the tree directory structure, from the root directory to any data file, there is only a unique path, from the root of the tree, the entire directory file name and the data file name, in turn, "/" to make up the path name of the data file. each file in the system has a unique path name . For example, user B accesses file J, which is accessed using the path name/b/f/j.

When a file system contains many levels, each access to a file will be used from the root of the tree until the leaves (data files), including the various intermediate nodes (directories) of the full path name, which is very troublesome, for each process to set a current directory, also known as the working directory, The process's access to each file is relative to the current directory. The path name consisting of a data file that is worth starting from the current directory is a relative pathname , and the path name starting from the root of the tree is the absolute path name.

Add and delete directories , in the tree directory structure, the user can create a UFD for themselves, and can recreate subdirectories, when users want to create a new file, only need to see their own UFD and its subdirectories have the same file name as the new file, if none, You can add a new catalog entry to the UFD or to one of its subdirectories. In the tree directory, how to delete a directory, should be the case, to delete the directory is empty, it is simply deleted, so that it in its top level of directory entries are empty, if not empty, you can use the following method: do not delete the non-empty directory (when the directory is not empty, In order to delete a non-empty directory, you must first delete all the files in the directory so that it is called an empty directory, and then delete, if the directory contains subdirectories, it should be recursively called to delete, you can delete the non-empty directory (all files and subdirectories in the directory are deleted at the same time).

 5.4 Directory Query Technology

When the user wants to access an existing file, the system first uses the user-supplied file name to query the directory, find the file control block or corresponding index node, and then, according to the file Physical address (disk block number) recorded in the FCB or index node, the physical location of the file on disk, and finally, Then, through the disk driver, read the required files into memory. At present, there are linear retrieval method and hash method in common way.

Linear Retrieval Method , which is also called sequential retrieval method, in the tree directory, the user provides the file name is composed of multiple file component name of the path name, you need to find the multilevel directory, assuming that the user given a file path named/usr/ast/mbox, the lookup process is as follows.

Note: First, the system should read into the first file component name USR, with it and the root file (or the current directory file) in the directory entries in the file name in the order of comparison, to find a match, and get the index of the match number is 6, and then from the 6th index node to get the USR directory file placed in the 132th block, Reads the disk block contents into memory. Next, the system then reads the second component name AST in the pathname, compares it with the file name order of each directory entry in the second-level catalog file placed in the 132th block, finds a match, gets the AST directory file in the 26th index node, and learns from the 26th index node/usr/ The AST is stored in block No. 496 and then read into block No. 496. Then, the third component of the file name Mbox read into, with it and the third quarter of the catalog file/usr/ast in the directory entries of the file name, and finally get the/usr/ast/mbox index node number is 60, that is, the 60th index node in the storage of the specified file's physical address, The directory query operation ends, and if a file component name is found in the sequential lookup process, the lookup is stopped and the file is returned with no information found.

Hash Method , the system uses the user-supplied file name and converts it to the index value of the file directory, and then uses the index value in the directory to find, which will improve the retrieval speed.

VI. File storage space management

  6.1 Idle Table method

  The idle table method is a continuous allocation method, which is identical to the dynamic allocation of memory, which allocates a contiguous storage space for each file, that is, the system also establishes a free table for all the idle areas on external memory, each of which corresponds to a free table entry , including the table item ordinal, The first block number of the idle area, the free block number for that area, and then increments all the idle areas by their starting block number.

The allocation of free disk area is similar to the dynamic allocation of memory, the first adaptive algorithm and the first adaptive algorithm are also adopted. When the system recycles the storage space released by the user, it also takes a method similar to memory recycling, that is, whether the recycle area is adjacent to the front and back areas of the insertion point in the free table, and the neighboring participants should be merged. When the file is small, it adopts the continuous allocation method, when the file is large, it can use the discrete distribution.

  6.2 Idle Link List method

  The idle list method is to pull all the free extents into an idle chain. The linked list is divided into two forms, the free disk block chain and the free disk area chain.

① free block chain, which is all the free space on the disk, a block to pull into a chain, when the user to create a file and request allocation of storage space, the system from the beginning of the chain, and then take the appropriate number of free disk blocks assigned to the user, when the file is deleted and free space, The system inserts the reclaimed disk block into the end of the free block chain in turn, with the advantage that the process for allocating and reclaiming a block is simple, but you may want to repeat the operation multiple times when you allocate a disk block to a file.

② the free disk area chain, which is to pull all the free extents on the disk (each block can contain several blocks) into a chain, on each panel in addition to a pointer that is just the next free area, there should be able to indicate the size of the area (block number) information. The allocation of the disk area is similar to the dynamic allocation of memory, the first adaptation algorithm can be used, the recovery area and the adjacent free disk area should be merged when the disk area is reclaimed, and when the first adaptation algorithm is adopted, the explicit link method can be used to improve the retrieval speed and a linked list is established in memory for the free disk area.

  6.3-bit Illustration method

The use of a binary representation of a disk block in the usage, when its value is 0 o'clock, indicating that the corresponding disk block is idle, to 1 o'clock, indicating that it has been allocated, all disk blocks on the disks have a bits corresponding to it, so that the corresponding bits of all the disk blocks constitute a set, called a bit diagram, usually can be M * n bits to form a bit diagram and make M * N equal to the total number of blocks of the disk.

The allocation of disk blocks is divided into three steps as follows

① a sequential scan of a bit diagram from which to find one or a set of bits with a value of 0.

② converts the found one or a group of bits into a winning disk block number.

③ modify the bit diagram.

The recovery of the disk block is divided into the following two steps

① converts the disk block number of the reclaimed disk block into a line number and a column number in a bit diagram.

② modify the bit diagram.

The advantage of this method is that it is easy to find one or a set of contiguous blocks of free disk from the bit diagram, in addition, because the bit diagram is small and takes up less space, it can be saved in memory, so that every time the allocation of the partition, there is no need to first read the disk allocation table into memory, save disk startup time.

  6.4 Group Linking method

Both the idle-table method and the Idle-list method do not apply to large systems, as this will make the free table or the idle list very long, in Unix-based group chaining method, combined with both methods.

① empty line block of the organization, the free disk block stack is used to hold the currently available set of free disk block block number (up to 100 number), and the stack of free disk block numbers n, by the way, the N-stack top pointer use, the stack is a critical resource, the system set a lock for the process mutually exclusive access. Among them, S.free (0) is the bottom of the stack, the stack is full when the top is s.free (99).

All free disk blocks in the ② file area are divided into groups, such as each 100 disk block as a group.

③ the total number of disk blocks contained in each group N and all disk block numbers of the group into the first block of its previous group S.free (0) ~s.free (99), so that the first block of each group can be linked into a chain.

④ the total number of blocks in the first set and all the block numbers into the free disk block number stack as the free block number currently available for allocation.

⑤ the last group has only 99 disk blocks, its block number is recorded in its previous group of S.free (1) ~s.free (99), and in S.free (0) is stored 0, as the end of the free block chain.

When the system wants to assign a disk block to the user for a file, the disk block allocation process must be called to complete. This process first checks whether the free disk block number stack is locked, if unlocked, take a free block number from the top of the stack, assign the corresponding disk block to the user, and then move the top pointer down one grid. If the disk block number is already a stack, i.e. S.free (0), this is the last assignable block number in the current stack. Since the next set of available block numbers is recorded in the disk block corresponding to the block number, therefore, the disk read process must be called, the stack chassis block number corresponding to the contents of the disk block read into the stack, as the new block number stack content, and the original stack corresponding to the disk block allocation (where the useful data is read into the stack). Then, allocate a corresponding buffer (as buffer for the block). Finally, the number of free disk blocks in the stack is reduced by 1 and returned.

When the system reclaims the free disk block, the disk block recycling process must be called to recycle. It is the disk block number of the recycling block is credited to the top of the free disk block number stack, and the number of free disk blocks plus 1 operation. When the number of free disk blocks in the stack has reached 100, indicating that the stack is full, the 100 disk block numbers in the existing stack are credited to the newly reclaimed disk block, and the block number is used as the new bottom of the stack.

Vii. Summary

  This article has learned the main content of document management, understand the system is how to efficiently organize the details of the document. And thank you for watching the Garden friends ~

"Operating System" file management (vi)

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.