File system recovery method, device, electronic device and storage medium

By loading the index area of ​​the file system, determining and formatting the damaged index area, and rebuilding the index tree, it solves the unavailability problem caused by the damage to the index area in the file system and achieves effective recovery and data retention of the file system.

CN114625697BActive Publication Date: 2024-09-27CHONGQING UNISINSIGHT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210351728.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-02
Publication Date
2024-09-27
Estimated Expiration
2042-04-02

AI Technical Summary

Technical Problem

The index area in the file system is damaged, causing the file system to become unusable, and it is difficult to effectively restore it with existing technology.

Method used

By loading the index area of ​​the file system to be restored, the damaged index area is determined based on the obtained check value, the damaged index area is formatted and updated, the index tree is rebuilt, and the check is updated based on the cascade relationship between file nodes and directory nodes. Check the value and restore the file system.

Benefits of technology

Effectively delete damaged index area data, retain available data in the file system, reduce data loss, and ensure file system availability after recovery.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114625697B
    Figure CN114625697B
Patent Text Reader

Abstract

The present application provides a file system recovery method, device, electronic device and storage medium, and relates to the field of data processing technology. The method includes: loading the index area of ​​the file system to be recovered, and determining the damaged index area according to the obtained check values ​​of each index area; formatting the damaged index area according to the position of the damaged index area corresponding to the disk, and updating the check value of the damaged index area; reloading the index area of ​​the file system to be recovered, and building an index tree according to the information recorded in each index area; updating the check value of each index area according to the index tree and the cascade relationship between the file nodes and directory nodes in each index area to obtain the recovered file system. This method can retain as much available data in the file system as possible and reduce data loss. Updating the index check value can ensure the validity of the index area check value and the availability of the file system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a file system recovery method, device, electronic device and storage medium. Background Art

[0002] File storage systems have been widely used to store massive amounts of data such as video files due to their large storage space and high data storage accuracy. Therefore, the reliability of file system data storage becomes particularly important. When the file system is damaged, the data stored in the file system will become unavailable, thus affecting the data reading of the file system.

[0003] Therefore, how to recover the damaged file system is an urgent problem to be solved. Summary of the invention

[0004] The purpose of the present application is to provide a file system recovery method, device, electronic device and storage medium to address the deficiencies in the above-mentioned prior art, so as to solve the problem of file system unavailability caused by damage to the index area in the file system.

[0005] To achieve the above purpose, the technical solution adopted in the embodiment of the present application is as follows:

[0006] In a first aspect, an embodiment of the present application provides a file system recovery method, comprising:

[0007] Loading the index area of ​​the file system to be restored, and determining the damaged index area according to the obtained check values ​​of each index area; the file system includes multiple index areas, each index area includes: a primary index area and a backup index area;

[0008] According to the position of the damaged index area in the disk, the damaged index area is formatted, and the check value of the damaged index area is updated;

[0009] Reloading the index area of ​​the file system to be restored, and constructing an index tree according to the information recorded in each index area;

[0010] According to the index tree and the cascade relationship between the file nodes and the directory nodes in each index area, the check value of each index area is updated to obtain a restored file system.

[0011] Optionally, the loading of the index area of ​​the file system to be restored and determining the damaged index area according to the obtained checksum values ​​of each index area include:

[0012] Load the index area of ​​the file system to be restored, and obtain the check value of the primary index area and the check value of the backup index area of ​​each index area;

[0013] If both the check value of the primary index area and the check value of the backup index area of ​​the first index area fail to be checked, it is determined that the first index area is a damaged index area, wherein the first index area is any index area in the file system.

[0014] Optionally, formatting the damaged index area according to the position of the damaged index area in the disk, and updating the check value of the damaged index area includes:

[0015] According to the location of the damaged index area in the disk, clearing the information of all directory nodes and file nodes contained in the damaged index area stored in the location;

[0016] According to the information recorded in the damaged index area after the information is cleared, a new check value for the damaged index area is generated by using a check value generation algorithm;

[0017] The new check value is used to update the check value of the damaged index area.

[0018] Optionally, constructing an index tree according to the information recorded in each index area includes:

[0019] The index tree is constructed according to the hierarchical information and identification information of all directory nodes and file nodes contained in each index area obtained by loading, and the identification information includes: a node identification and a parent node identification.

[0020] Optionally, updating the checksum of each index area according to the index tree and the cascade relationship between the file nodes and the directory nodes in each index area to obtain a restored file system includes:

[0021] According to the cascade relationship between the file nodes and the directory nodes in each index area, the index tree is searched to determine the target directory node and the target file node in each index area, wherein the target directory node includes: a directory node whose parent node cannot be found, and the target file node includes: a file node whose parent node cannot be found;

[0022] Updating the usage status of the target directory node and the target file node in each index area;

[0023] According to the information recorded in each index area after the update, a new check value for each index area is generated by using a check value generation algorithm;

[0024] According to the new check value of each index area, the check value of each index area is updated to obtain the restored file system.

[0025] Optionally, updating the checksum of each index area according to the index tree and the cascade relationship between the file nodes and the directory nodes in each index area to obtain a restored file system includes:

[0026] The index tree is searched according to the cascade relationship between the file nodes and the directory nodes in each index area. If the target directory node and the target file node in each index area are not found, it is determined that the current file system is the restored file system.

[0027] Optionally, updating the usage status of the target directory node and the target file node in each index area includes:

[0028] The use status of the target directory node in each index area is updated from being in use to being unused, and the use status of the target file node is updated from being in use to being unused.

[0029] In a second aspect, an embodiment of the present application further provides a file system recovery device, including: a determination module, a processing module, a construction module, and an update module;

[0030] The determination module is used to load the index area of ​​the file system to be restored, and determine the damaged index area according to the obtained check values ​​of each index area; the file system includes multiple index areas, each index area includes: a primary index area and a backup index area;

[0031] The processing module is used to format the damaged index area according to the position of the damaged index area corresponding to the disk, and update the check value of the damaged index area;

[0032] The construction module is used to reload the index area of ​​the file system to be restored and to construct an index tree according to the information recorded in each index area;

[0033] The update module is used to update the check value of each index area according to the index tree and the cascade relationship between the file nodes and the directory nodes in each index area to obtain a restored file system.

[0034] Optionally, the determination module is specifically used to load the index area of ​​the file system to be restored, and obtain the check value of the primary index area and the check value of the backup index area of ​​each index area;

[0035] If both the check value of the primary index area and the check value of the backup index area of ​​the first index area fail to be checked, it is determined that the first index area is a damaged index area, wherein the first index area is any index area in the file system.

[0036] Optionally, the processing module is specifically configured to clear information of all directory nodes and file nodes contained in the damaged index area stored in the location corresponding to the damaged index area in the disk;

[0037] According to the information recorded in the damaged index area after the information is cleared, a new check value for the damaged index area is generated by using a check value generation algorithm;

[0038] The new check value is used to update the check value of the damaged index area.

[0039] Optionally, the construction module is specifically used to construct the index tree according to the hierarchical information and identification information of all directory nodes and file nodes contained in each index area obtained by loading, and the identification information includes: node identification and parent node identification.

[0040] Optionally, the update module is specifically used to search the index tree according to the cascade relationship between the file nodes and the directory nodes in each index area, and determine the target directory node and the target file node in each index area, wherein the target directory node includes: a directory node whose parent node cannot be found, and the target file node includes: a file node whose parent node cannot be found;

[0041] Updating the usage status of the target directory node and the target file node in each index area;

[0042] According to the information recorded in each index area after the update, a new check value for each index area is generated by using a check value generation algorithm;

[0043] According to the new check value of each index area, the check value of each index area is updated to obtain the restored file system.

[0044] Optionally, the update module is specifically used to search the index tree according to the cascading relationship between the file nodes and directory nodes in each index area, and if the target directory node and the target file node in each index area are not found, determine that the current file system is the restored file system.

[0045] Optionally, the determination module is specifically configured to update the usage status of the target directory node in each index area from being in use to being unused, and to update the usage status of the target file node from being in use to being unused.

[0046] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor. When the electronic device is running, the processor and the storage medium communicate through the bus, and the processor executes the machine-readable instructions to perform the steps of the method provided in the first aspect.

[0047] In a fourth aspect, an embodiment of the present application provides a storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the method provided in the first aspect are executed.

[0048] The beneficial effects of this application are:

[0049] The present application provides a file system recovery method, device, electronic device and storage medium, the method comprising: loading the index area of ​​the file system to be recovered, determining the damaged index area according to the obtained check values ​​of each index area; formatting the damaged index area according to the position of the damaged index area in the disk, and updating the check value of the damaged index area; reloading the index area of ​​the file system to be recovered, and building an index tree according to the information recorded in each index area; updating the check value of each index area according to the index tree and the cascade relationship of the file nodes and directory nodes in each index area, and obtaining the recovered file system. The method can format the damaged index area determined to be damaged, so as to delete the data of the damaged index area, without processing other undamaged index areas in the file system. In addition, according to the index tree and the information of the file nodes and directory nodes recorded in each index area, the file nodes and directory nodes that have lost the cascade relationship can be deleted, so as to retain as much available data in the file system as possible and reduce data loss. Since the index check value is determined based on the information recorded in the index area, the index check value is updated in real time after each processing of the information in the index area, which can ensure the validity of the index area check value, thereby ensuring the availability of the restored file system. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0051] Figure 1 A schematic diagram of the structure of a file system provided in an embodiment of the present application;

[0052] Figure 2A flowchart of a file system recovery method provided in an embodiment of the present application;

[0053] Figure 3 A flowchart of another file system recovery method provided in an embodiment of the present application;

[0054] Figure 4 A flowchart of another file system recovery method provided in an embodiment of the present application;

[0055] Figure 5 A schematic diagram of the structure of an index tree provided in an embodiment of the present application;

[0056] Figure 6 A flowchart of another file system recovery method provided in an embodiment of the present application;

[0057] Figure 7 A schematic diagram of updating an index check value provided in an embodiment of the present application;

[0058] Figure 8 A schematic diagram of a file system recovery device provided in an embodiment of the present application;

[0059] Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0060] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be understood that the drawings in the present application only serve the purpose of explanation and description and are not used to limit the scope of protection of the present application. In addition, it should be understood that the schematic drawings are not drawn in real proportion. The flowchart used in this application shows the operations implemented according to some embodiments of the present application. It should be understood that the operations of the flowchart can be implemented out of sequence, and the steps without logical context can be reversed in order or implemented simultaneously. In addition, those skilled in the art can add one or more other operations to the flowchart under the guidance of the content of the present application, or remove one or more operations from the flowchart.

[0061] In addition, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.

[0062] It should be noted that the term "comprising" will be used in the embodiments of the present application to indicate the existence of the features declared thereafter, but does not exclude the addition of other features.

[0063] First, the structure of the file system involved in the present application is briefly described. The method of the present application can be implemented based on the file system of this specific structure. Figure 1 A structural diagram of a file system provided for an embodiment of the present application. The file system of the present application performs structural division of the disk space during initialization. The disk space of the file system includes: a reserved area, two super blocks, and multiple block groups, each block group may include two index areas and a data area, the two index areas are respectively a primary index area and a backup index area, wherein the size of the reserved area may be 4M, the size of each super block may be 4K, and the size of each block group may be 256G+2M.

[0064] Optionally, each block group may include a primary index area and a backup index area, wherein a primary index area or a backup index area may be referred to as a block group index GInode, and the size thereof is 1M, and a primary index area or a backup index area may be further subdivided into 64 sub-unit indexes (SInode), each sub-unit index is 16K, wherein a sub-index unit may include: an index log record of 4K, a directory index unit of 4K, and a file index unit of 8K. An index check value is recorded in the index log record, and a target index unit may include multiple directory nodes, each of which is 128B, and a file index unit may include multiple file nodes, each of which is 128B.

[0065] The primary index area and the backup index area are located at the two ends of the block group, and the data area is between the primary index area and the backup index area. Each data area includes multiple data blocks, such as Figure 1 As shown, a data area may include 64 data blocks, and the size of each data block may be 64M.

[0066] In addition, the primary / backup index area includes index log records, directory index units, and file index units, respectively. The index log records in the index area are used to record index log information, wherein the log information may include index checksums, index update time and number of times, and log information, etc.; the directory index unit and the file index unit are index units for recording directory attributes and file attributes, respectively. The index checksum value size can be 4K, the directory index unit size can be 4K, and the file index unit size can be 8K. Among them, the directory index unit includes 32 directory nodes, each of which can be 128B in size, and the file index unit includes 64 file nodes, each of which can be 128B in size, and the number of file nodes corresponds to the number of data blocks one by one.

[0067] The superblock is used to record the overall information of the entire file system, including the signature of the file system, the superblock checksum, the number of block groups, the number of data blocks, the size of data blocks, the system creation time, the update time, etc. In addition, it can also include: the number of accesses, the number of index units, the number of block groups, the size of data blocks, the size of index units, the universally unique identifier (UUID) and the formatting status, etc. The superblock is divided into the primary and backup superblocks. The primary and backup relationship is used to improve the reliability of the system by restoring the data of another superblock when a superblock information is abnormal.

[0068] It should be noted that the above-mentioned reserved area, super block size and unit block group size are only an optional allocation method, which is not limited to the above and can be appropriately adjusted according to actual conditions.

[0069] In addition, the index area is a key area of ​​the file system, and the index log record is used to record index log information, and the log information may include an index check value. The information of each directory node may include at least one of the following: directory name, usage status, level, parent node identifier (parent node ID), directory identifier (directory ID), directory creation time and modification time; the information of each file node may include at least one of the following: file name, usage status, level, parent node identifier, file identifier (file node ID), file creation time and modification time, file segment number and size.

[0070] It should be noted that the number of block groups into which the above-mentioned disk is divided, the number of index areas included in each block group, the size of the index area and the size of the data area, the number of data blocks included in the data area and the size of each data block can be a possible example, and the present application is not limited to this.

[0071] Figure 2 A flowchart of a file system recovery method provided in an embodiment of the present application; Figure 2 As shown, the method of the present application may include:

[0072] S201: Load the index area of ​​the file system to be restored, and determine the damaged index area according to the obtained check values ​​of each index area.

[0073] like Figure 1 As shown, the file system to which the method is applied may include multiple index areas, each index area is distributed in a corresponding block group, and the index area in each block group may include: a primary index area and a backup index area. The information recorded in the primary index area and the backup index area is completely the same.

[0074] Usually, each index area records an index check value. When the information recorded in the index area changes, for example, when a directory or file in the file system is accidentally deleted, the directory node information and file node information recorded in the index area will change. When the information recorded in the index area changes, the index check value corresponding to the index area will also change. Therefore, the index check value of the index area can be used to verify the validity of the index area to ensure the normal use of the file system.

[0075] During the process of loading the file system to be recovered, the index areas in all the block groups of the file system to be recovered can be loaded to read the check values ​​of each index area, wherein the check values ​​are stored in the index log record units of the index areas, and the check values ​​of the index areas are used to verify the validity of the index areas. Each index area can be verified based on the check values ​​of each index area, so as to determine the damaged index areas from all the index areas.

[0076] S202: format the damaged index area according to the position of the damaged index area in the disk, and update the check value of the damaged index area.

[0077] In some embodiments, when the file system structure is fixed, the location of the index area in the file system is also fixed, and when the file system is loaded, the location of each index area corresponding to the disk can be directly read.

[0078] Optionally, based on the location of the damaged index area in the disk, the information of the index area stored at the location may be formatted, wherein there may be multiple damaged index areas, and each damaged index area may be processed in the same way.

[0079] In this way, by formatting only the information in the damaged index area, as much available data in the file system as possible can be retained, thereby reducing data loss.

[0080] Since the check value of the index area changes according to the changes in the information recorded in the index area, the validity of the index area can be checked. When the information recorded in the index area changes, if the check value is not updated in time, the check will fail and the index area will be unusable.

[0081] In this embodiment, after the damaged index area is formatted, its index check value may be updated to ensure the availability of the file system.

[0082] S203: Reload the index area of ​​the file system to be restored, and construct an index tree according to the information recorded in each index area.

[0083] Optionally, after executing the above processing, the index area of ​​the file system to be restored may be reloaded again to construct an index tree according to the information of the file nodes and the information of the directory nodes recorded in each index area.

[0084] In some embodiments, the index area of ​​the file system to be restored may be loaded from the disk, and the information of all directory nodes and all file nodes may be read.

[0085] Among them, Figure 1 As shown, each index area includes: multiple index units, each index unit includes an index check value, multiple directory nodes and multiple file nodes; the information of each directory node includes at least one of the following: directory name, usage status, hierarchy, parent directory identifier, directory identifier, directory creation time and modification time; the information of each file node includes at least one of the following: file name, usage status, hierarchy, parent directory identifier, file identifier, file creation time and modification time, file fragment number and size.

[0086] It should be explained that the level refers to the level of the node. The parent node ID refers to the ID of the node above the current node. For example, if the ID of directory 1 is 1000, the ID of directory 2 under directory 1 is 1001, and the ID of directory 3 under directory 2 is 1002, then the parent node ID of directory 3 is 1001 and the parent node ID of directory 2 is 1000. The directory ID refers to the ID of the current node.

[0087] In some embodiments, the process of loading the file system to be restored is to parse and obtain all the information contained in the file system from the file system to be restored, including the information of the data area index area, etc. By loading each index area of ​​the file system, all the information contained in each index area can be read, including the information of all file nodes under the file index unit and the information of all directory nodes under the directory index unit.

[0088] Optionally, the information of the directory node whose usage status is used and the information of the file node can be saved in the hierarchical linked list. The current usage status of the directory node can be determined by the usage status in the directory node information, and the current usage status of the file node can also be determined according to the usage status in the file node information. Optionally, according to the usage status of each file node and directory node read, the usage status can be set to 1, that is, the information of the directory node and the file node whose usage status is used can be saved in the hierarchical linked list.

[0089] Among them, the information of each file node and directory node may be saved in a corresponding level in a hierarchical linked list according to the level of each file node and the level of the directory node.

[0090] Then, the hierarchical linked list is parsed layer by layer, and an index tree is created based on the connection relationship identified by the parent node.

[0091] Optionally, the hierarchical linked list may be parsed layer by layer, and an index tree may be constructed according to the identification relationship between the parent nodes of each directory node and file node.

[0092] S204: Update the checksum of each index area according to the index tree and the cascade relationship between the file nodes and the directory nodes in each index area to obtain a restored file system.

[0093] In some embodiments, in order to further verify the recovery of the file system, the cascade relationship between the file nodes and directory nodes in each loaded index area can be used to search in the index tree constructed above to see whether the cascade relationship between the file nodes and directory nodes in the index area is complete, that is, whether the parent node of each node can be accurately found. Based on the search result, if the cascade relationship is incomplete, it means that the index area is unavailable, so the index area can be processed, and the check value is updated again according to the information recorded in the processed index area, so as to obtain a restored file system.

[0094] In summary, the file system recovery method provided in this embodiment includes: loading the index area of ​​the file system to be recovered, and determining the damaged index area based on the check value of each index area obtained; formatting the damaged index area according to the position of the damaged index area corresponding to the disk, and updating the check value of the damaged index area; reloading the index area of ​​the file system to be recovered, and building an index tree according to the information recorded in each index area; updating the check value of each index area according to the index tree and the cascade relationship of the file nodes and directory nodes in each index area, and obtaining the recovered file system. This method can format the damaged index area determined to be damaged, so as to delete the data in the damaged index area, without processing other undamaged index areas in the file system. In addition, according to the index tree and the information of the file nodes and directory nodes recorded in each index area, the file nodes and directory nodes that have lost the cascade relationship can be deleted, so as to retain as much available data in the file system as possible and reduce data loss. Since the index check value is determined based on the information recorded in the index area, the index check value is updated in real time after each processing of the information in the index area, which can ensure the validity of the index area check value, thereby ensuring the availability of the restored file system.

[0095] Figure 3 A flowchart of another file system recovery method provided by an embodiment of the present application; Optionally, in the above step S201, loading the index area of ​​the file system to be recovered, and determining the damaged index area according to the obtained check values ​​of each index area may include:

[0096] S301: Load the index area of ​​the file system to be restored, and obtain the check value of the primary index area and the check value of the backup index area of ​​each index area.

[0097] Optionally, an index log recording unit of each index area in the file system can be loaded, and the check value of each index area can be read from the index log recording unit, wherein the primary index area of ​​each index area records the check value of the primary index area, and the backup index area records the check value of the backup index area.

[0098] S302: If both the check value of the primary index area and the check value of the backup index area of ​​the first index area fail to be checked, determine that the first index area is a damaged index area, wherein the first index area is any index area in the file system.

[0099] In some embodiments, for any index area, if both the check value of the primary index area and the check value of the backup index area of ​​the index area fail to be checked, it may indicate that the index area is damaged and the information of the directory node and file node recorded in the index area is unavailable.

[0100] It should be noted that the “first” in the first index area mentioned here does not have any practical meaning, and the first index area may be any index area in the file system to be restored.

[0101] Figure 4 A flowchart of another file system recovery method provided by an embodiment of the present application; optionally, in step S202, formatting the damaged index area according to the position of the damaged index area corresponding to the disk, and updating the check value of the damaged index area may include:

[0102] S401. According to the location of the damaged index area in the disk, clear the information of all directory nodes and file nodes contained in the damaged index area stored in the location.

[0103] In some embodiments, the positions of the index areas in the file system to be restored corresponding to the disk are fixed, and the positions of the index areas corresponding to the disk can be read when the index areas are loaded.

[0104] Optionally, the information stored at the location of the damaged index area in the disk can be cleared, that is, the usage status of all file nodes and directory nodes in the damaged index area recorded in the location is updated from 1 to 0, wherein the usage status of 1 indicates that the node is used, and the usage status of 0 indicates that the node is not used. The usage status of the node is updated from 1 to 0, that is, the node is updated from the used state to the unused state, thereby achieving the purpose of deleting the data of the damaged index area from the file system. Here, only the information of the damaged index area is deleted without affecting other data in the file system, so that the available data in the file system can be retained to the greatest extent.

[0105] S402: Generate a new check value for the damaged index area using a check value generation algorithm according to the information recorded in the damaged index area after the information is cleared.

[0106] In some embodiments, the check value of the index area is generated based on the information recorded in the index area, which includes the information of the file node and the directory node. When the damaged index area is formatted, the information recorded in the damaged index area will change, and the index check value corresponding to the index area will also need to be updated accordingly. If the index check value is not updated, when the index area is re-checked, the check value will not match the information in the index area, which will cause the check to fail.

[0107] Optionally, a new check value of the damaged index area may be generated by using a CRC (Cyclic Redundancy Check) algorithm according to the information of the file nodes and directory nodes recorded in the reformatted damaged index area.

[0108] S403: Use a new check value to update the check value of the damaged index area.

[0109] Optionally, the new check value obtained by the above calculation can be written into the index log recording unit of the damaged index area to overwrite the previous check value, so that the check value of the damaged index area can be updated in real time.

[0110] Optionally, in the above step S203, constructing an index tree according to the information recorded in each index area may include: constructing an index tree according to the hierarchical information and identification information of all directory nodes and file nodes contained in each index area obtained by loading, and the identification information includes: node identification and parent node identification.

[0111] Figure 5 A schematic diagram of the structure of an index tree provided in an embodiment of the present application. Assume that the hierarchical information and identification information of the directory nodes and file nodes contained in each index area are as shown in the following hierarchical linked list:

[0112]

[0113]

[0114] Then, based on the information of each file node and directory node in the hierarchical linked list, according to the relationship between the parent node identifiers of each node, it can be known that the first layer of the index tree includes directory node 1, directory node 2, and directory node 3, and the second layer includes: directory node 5, directory node 6, directory node 7, and directory node 8, among which the parent node of directory node 5 is directory node 2, the parent node of directory node 6 is directory node 1, the parent node of directory node 7 is directory node 3, and the parent node of directory node 8 is directory node 2. Similarly, the third layer of the index tree includes: file node 1, file node 2, file node 3, and file node 4. The parent node of file node 1 is directory node 7, the parent node of file node 2 is directory node 8, the parent node of file node 3 is directory node 5, and the parent node of file node 4 is directory node 6. Based on this, the following can be constructed: Figure 5 The index tree shown.

[0115] It should be noted that the constructed index tree clearly expresses the index relationship between each directory node and file node.

[0116] Figure 6 A flowchart of another file system recovery method provided by an embodiment of the present application; optionally, in step S204, according to the index tree and the cascade relationship between the file nodes and the directory nodes in each index area, the check value of each index area is updated to obtain the recovered file system, which may include:

[0117] S601. Search the index tree according to the cascading relationship between the file nodes and the directory nodes in each index area, and determine the target directory node and the target file node in each index area. The target directory node includes: a directory node whose parent node cannot be found, and the target file node includes: a file node whose parent node cannot be found.

[0118] Optionally, the target directory node and the target file node can be searched based on the index tree constructed as above. For any file node or directory node in any index area, if its parent node cannot be found in the index tree according to the parent node identifier of the file node or directory node, it can be said that the parent node of the directory node or file node has been lost. In this case, if you want to search for the directory node or file node level by level according to the index tree, the file node or directory node cannot be found due to the loss of its parent node, that is, the directory node or file node is unavailable.

[0119] Thus, a file node whose parent node cannot be found can be determined as a target file node, and a directory node whose parent node cannot be found can be determined as a target directory node.

[0120] S602: Update the usage status of the target directory node and the target file node in each index area.

[0121] Optionally, since the parent nodes of the target directory node and the target file node are both lost, the target directory node and the target file node are both unavailable, and then the target file node and the target directory node may be cleared.

[0122] Optionally, updating the usage status of the target directory node and the target file node in each index area may include: updating the usage status of the target directory node in each index area from being in use to being unused, and updating the usage status of the target file node from being in use to being unused. That is, the usage status of the target directory node is set from 1 to 0, and the usage status of the target file node is also set from 1 to 0.

[0123] S603: Generate a new check value for each index area using a check value generation algorithm according to the updated information recorded in each index area.

[0124] Optionally, if the usage status of the target directory node and the target file node in each index area is updated, the information recorded in the index area containing the target file node and the target directory node will also change. Therefore, the check value of the index area needs to be updated again to ensure the validity of the index check value.

[0125] Similarly, the CRC algorithm as described above may also be used to generate a new check value.

[0126] S604: Update the check value of each index area according to the new check value of each index area to obtain a restored file system.

[0127] Optionally, the generated new check value of each index area may be written into the index log record unit of each index area to overwrite the previous index check value, and at this time, the recovery of the file system to be recovered is completed.

[0128] Optionally, in step S204, the check value of each index area is updated according to the index tree and the cascade relationship between the file nodes and the directory nodes in each index area to obtain the restored file system, which may include: searching the index tree according to the cascade relationship between the file nodes and the directory nodes in each index area, and if the target directory node and the target file node in each index area are not found, determining that the current file system is a restored file system.

[0129] In some embodiments, if the target directory node and the target file node are not found in each index area according to the search index tree, that is, the directory cascade relationship of the file nodes and directory nodes recorded in each index area is complete, then it can be considered that all information in the current file system is available. Here, no other processing is performed, and the current file system can be used as the restored file system.

[0130] Therefore, through the above method, the recovery of the file system when the index area is damaged is completed.

[0131] Figure 7 A schematic diagram of updating an index check value provided in an embodiment of the present application. Figure 7 The method of the present application is described by means of specific examples.

[0132] Assume that the data block of the file system to be restored is 64M, the index area is 12K, of which the check value occupies 4K, the directory index unit is 4K (including 32 directory nodes, each directory node is 128B), and the file index unit is 4K (including 32 file nodes, each file node is 128B).

[0133] Assume that both the primary and backup index checksums of index area 1 are damaged, the directory video1 in the " / video1 / file2" file is located in directory node 1 of index area 1, and file2 is located in file node 1 of index area 2.

[0134] The specific recovery process of the file system to be restored is as follows:

[0135] First: when loading the entire index area of ​​the file system to be restored, if it is found that both the primary and backup index area checks of index area 1 fail, index area 1 is determined to be a damaged index area and is recorded in the damage level linked list.

[0136] Second: according to the location of the damaged index area in the file system disk recorded in the damage level linked list, all the primary and backup index areas of index area 1 are formatted, and the checksum of index area 1 is regenerated;

[0137] Third: Try to load the entire index area of ​​the file system to be restored again. At this time, all verifications are passed, and the information of the directory nodes and file nodes of each index area is saved in the hierarchical linked list. The index tree is constructed through the hierarchical linked list. It is found that the file node 1 located in the index area 2 cannot find the parent node vidoe1 in the constructed index tree according to the parent node ID 1000. Then, according to the position of the file node 1 in the disk of the file system, the use status of the file node 1 is set to 0, and the verification value of the index area 2 is regenerated;

[0138] Fourth: After completing step 3, try to load the file system to be restored to build an index tree, and then complete the recovery of the file system.

[0139] In summary, the file system recovery method provided in this embodiment includes: loading the index area of ​​the file system to be recovered, and determining the damaged index area according to the obtained check values ​​of each index area; formatting the damaged index area according to the position of the damaged index area corresponding to the disk, and updating the check value of the damaged index area; reloading the index area of ​​the file system to be recovered, and building an index tree according to the information recorded in each index area; updating the check value of each index area according to the index tree and the cascade relationship of the file nodes and directory nodes in each index area, and obtaining the recovered file system. This method can format the damaged index area determined to be damaged, so as to delete the data in the damaged index area, without processing other undamaged index areas in the file system. In addition, according to the index tree and the information of the file nodes and directory nodes recorded in each index area, the file nodes and directory nodes that have lost the cascade relationship can be deleted, so as to retain as much available data in the file system as possible and reduce data loss. Since the index check value is determined based on the information recorded in the index area, the index check value is updated in real time after each processing of the information in the index area, which can ensure the validity of the index area check value, thereby ensuring the availability of the restored file system.

[0140] The above description is directed to the recovery of the file system when the index area is damaged. However, in this embodiment, the recovery of the file system when the super block is damaged is also provided.

[0141] Optionally, it may include: loading the super block of the file system to be recovered, reading the check value of the super block; including the check value of the primary super block and the check value of the backup super block; if the check value of the primary super block and the check value of the backup super block both fail to be verified, it is determined that the super block is damaged; obtaining the disk capacity of the file system to be recovered, and recalculating various information recorded in the super block in the file system to be recovered according to the disk capacity and the data format, including at least: the number of block groups and the number of data blocks; generating a new check value of the super block based on the information contained in the recalculated super block, and updating the check value of the super block to the new check value.

[0142] In some embodiments, the disk capacity of the file system to be restored may be obtained, and a check may be made to determine whether the capacity complies with the minimum capacity of the file system.

[0143] The number of block groups is calculated according to the disk capacity (disk space size) (number of block groups = disk space size - reserved area - super block size * 2) / block group size), where the reserved area and block group size are pre-set fixed values.

[0144] Since the total size of the file system occupied by a block group is fixed, the size of the file system occupied by a block group can be calculated based on the calculated number of block groups, and the number of data blocks can be calculated based on the size of a block group and the size of a data block.

[0145] In addition, based on the number of block groups, the number of index areas can be calculated as the number of block groups*2; the signature information in the super block rewrites the original signature information; the file system creation time and update time are both updated to the current time.

[0146] Based on the information in the super block calculated above, a CRC algorithm can be used to regenerate a new check value of the super block, so that the new check value is written into the super block area, overwriting the previous check value, and completing the recovery of the file system.

[0147] The following describes the apparatus, device, storage medium, etc. used to execute the file system recovery method provided in this application. The specific implementation process and technical effects are described above and will not be repeated below.

[0148] Figure 8 This is a schematic diagram of a file system recovery device provided in an embodiment of the present application. The functions implemented by the file system recovery device correspond to the steps performed by the above method. The device can be understood as a terminal device, a server, or a processor of a server, or can be understood as a component independent of the above server or processor that implements the functions of the present application under the control of the server, such as Figure 8 As shown, the device may include: a determination module 810, a processing module 820, a construction module 830, and an update module 840;

[0149] The determination module 810 is used to load the index area of ​​the file system to be restored, and determine the damaged index area according to the obtained check values ​​of each index area; the file system includes multiple index areas, each index area includes: a primary index area and a backup index area;

[0150] The processing module 820 is used to format the damaged index area according to the position of the damaged index area in the disk, and update the check value of the damaged index area;

[0151] A construction module 830 is used to reload the index area of ​​the file system to be restored and to construct an index tree according to the information recorded in each index area;

[0152] The update module 840 is used to update the check value of each index area according to the index tree and the cascade relationship between the file nodes and the directory nodes in each index area to obtain a restored file system.

[0153] Optionally, the determination module 810 is specifically used to load the index area of ​​the file system to be restored, and obtain the check value of the primary index area and the check value of the backup index area of ​​each index area;

[0154] If both the check value of the primary index area and the check value of the backup index area of ​​the first index area fail to be checked, it is determined that the first index area is a damaged index area, wherein the first index area is any index area in the file system.

[0155] Optionally, the processing module 820 is specifically configured to clear information of all directory nodes and file nodes contained in the damaged index area stored in the location according to the location corresponding to the damaged index area in the disk;

[0156] According to the information recorded in the damaged index area after the information is cleared, a new check value of the damaged index area is generated by using a check value generation algorithm;

[0157] The checksum of the damaged index area is updated with a new checksum.

[0158] Optionally, the construction module 830 is specifically used to construct an index tree according to the hierarchical information and identification information of all directory nodes and file nodes contained in each index area obtained by loading, and the identification information includes: node identification and parent node identification.

[0159] Optionally, the update module 840 is specifically used to search the index tree according to the cascade relationship between the file nodes and the directory nodes in each index area, and determine the target directory node and the target file node in each index area, the target directory node includes: a directory node whose parent node cannot be found, and the target file node includes: a file node whose parent node cannot be found;

[0160] Update the usage status of the target directory node and the target file node in each index area;

[0161] According to the information recorded in each index area after the update, a new check value for each index area is generated by using a check value generation algorithm;

[0162] According to the new check value of each index area, the check value of each index area is updated to obtain a restored file system.

[0163] Optionally, the update module 840 is specifically used to search the index tree according to the cascade relationship between the file nodes and directory nodes in each index area. If the target directory node and the target file node in each index area are not found, it is determined that the current file system is a restored file system.

[0164] Optionally, the determination module 840 is specifically configured to update the usage status of the target directory node in each index area from being in use to being unused, and to update the usage status of the target file node from being in use to being unused.

[0165] The above-mentioned device is used to execute the method provided by the aforementioned embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.

[0166] The above modules may be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASIC), or one or more digital singnal processors (DSP), or one or more field programmable gate arrays (FPGA). For another example, when a module is implemented in the form of a processing element scheduling program code, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call program code. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).

[0167] The above modules can be connected or communicated with each other via a wired connection or a wireless connection. The wired connection may include a metal cable, an optical cable, a hybrid cable, etc., or any combination thereof. The wireless connection may include a connection in the form of a LAN, a WAN, Bluetooth, a ZigBee, or NFC, or any combination thereof. Two or more modules may be combined into a single module, and any one module may be divided into two or more units. Those skilled in the art will clearly understand that for the convenience and simplicity of description, the specific working process of the system and device described above can refer to the corresponding process in the method embodiment, and will not be repeated in this application.

[0168] Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, the device may include: a processor 801 and a memory 802.

[0169] The memory 802 is used to store programs, and the processor 801 calls the programs stored in the memory 802 to execute the above method embodiment. The specific implementation method and technical effect are similar and will not be repeated here.

[0170] The memory 802 stores program codes, and when the program codes are executed by the processor 801, the processor 801 executes various steps of the method according to various exemplary embodiments of the present application described in the above “Exemplary Method” section of this specification.

[0171] Processor 801 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor (DigitalSignal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, and can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present application can be directly embodied as a hardware processor to be executed, or a combination of hardware and software modules in the processor can be executed.

[0172] The memory 802 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. The memory is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 802 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.

[0173] Optionally, the present application also provides a program product, such as a computer-readable storage medium, including a program, which is used to execute the above method embodiment when executed by a processor.

[0174] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0175] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0176] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional units.

[0177] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (English: processor) to perform some steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (English: Read-Only Memory, abbreviated: ROM), random access memory (English: Random Access Memory, abbreviated: RAM), disk or optical disk and other media that can store program codes.

Claims

1. A file system recovery method, characterized in that: include: Load the index area of ​​the file system to be restored, and determine the damaged index area according to the obtained checksum values ​​of each index area; The file system includes a plurality of index areas, each index area includes: a primary index area and a backup index area; According to the position of the damaged index area in the disk, the damaged index area is formatted, and the check value of the damaged index area is updated; Reloading the index area of ​​the file system to be restored, and constructing an index tree according to the information recorded in each index area; According to the index tree and the cascade relationship between the file nodes and the directory nodes in each index area, the check value of each index area is updated to obtain a restored file system; The updating of the checksum of each index area according to the index tree and the cascade relationship between the file nodes and the directory nodes in each index area to obtain the restored file system includes: According to the cascade relationship between the file nodes and the directory nodes in each index area, the index tree is searched to determine the target directory node and the target file node in each index area, wherein the target directory node includes: a directory node whose parent node cannot be found, and the target file node includes: a file node whose parent node cannot be found; Updating the usage status of the target directory node and the target file node in each index area; According to the information recorded in each index area after the update, a new check value for each index area is generated by using a check value generation algorithm; According to the new check value of each index area, the check value of each index area is updated to obtain the restored file system.

2. The method according to claim 1, characterized in that The loading of the index area of ​​the file system to be restored and determining the damaged index area according to the obtained check values ​​of each index area include: Load the index area of ​​the file system to be restored, and obtain the check value of the primary index area and the check value of the backup index area of ​​each index area; If both the check value of the primary index area and the check value of the backup index area of ​​the first index area fail to be checked, it is determined that the first index area is a damaged index area, wherein the first index area is any index area in the file system.

3. The method according to claim 1, characterized in that The step of formatting the damaged index area according to the position of the damaged index area in the disk, and updating the check value of the damaged index area includes: According to the location of the damaged index area in the disk, clearing the information of all directory nodes and file nodes contained in the damaged index area stored in the location; According to the information recorded in the damaged index area after the information is cleared, a new check value for the damaged index area is generated by using a check value generation algorithm; The new check value is used to update the check value of the damaged index area.

4. The method according to claim 1, characterized in that: The step of constructing an index tree according to the information recorded in each index area includes: The index tree is constructed according to the hierarchical information and identification information of all directory nodes and file nodes contained in each index area obtained by loading, and the identification information includes: a node identification and a parent node identification.

5. The method according to claim 1, characterized in that The updating of the checksum of each index area according to the index tree and the cascade relationship between the file nodes and the directory nodes in each index area to obtain the restored file system includes: The index tree is searched according to the cascade relationship between the file nodes and the directory nodes in each index area. If the target directory node and the target file node in each index area are not found, it is determined that the current file system is the restored file system.

6. The method according to claim 1, characterized in that The updating of the usage status of the target directory node and the target file node in each index area includes: The use status of the target directory node in each index area is updated from being in use to being unused, and the use status of the target file node is updated from being in use to being unused.

7. A file system recovery device, characterized in that: include: Identify modules, process modules, build modules, and update modules; The determination module is used to load the index area of ​​the file system to be restored, and determine the damaged index area according to the obtained check values ​​of each index area; the file system includes multiple index areas, each index area includes: a primary index area and a backup index area; The processing module is used to format the damaged index area according to the position of the damaged index area corresponding to the disk, and update the check value of the damaged index area; The construction module is used to reload the index area of ​​the file system to be restored and to construct an index tree according to the information recorded in each index area; The update module is used to update the check value of each index area according to the index tree and the cascade relationship between the file nodes and the directory nodes in each index area to obtain a restored file system; The update module is specifically used to search the index tree according to the cascade relationship between the file nodes and the directory nodes in each index area, and determine the target directory node and the target file node in each index area, the target directory node includes: the directory node whose parent node cannot be found, and the target file node includes: the file node whose parent node cannot be found; Update the usage status of the target directory node and the target file node in each index area; According to the information recorded in each index area after the update, a new check value for each index area is generated by using a check value generation algorithm; According to the new check value of each index area, the check value of each index area is updated to obtain a restored file system.

8. An electronic device, characterized in that: include: A processor, a storage medium and a bus, wherein the storage medium stores program instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the program instructions to perform the steps of any method described in claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are executed.