A method for reconstructing a read-only file system image, an electronic device, and a storage medium
By managing data blocks using data block index information in a read-only file system image, file modification, addition, and deletion can be implemented, solving the problem of time-consuming large image construction and improving construction efficiency.
Patent Information
- Application Number
- CN202511384941.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-26
- Publication Date
- 2026-01-27
- Estimated Expiration
- 2045-09-26
AI Technical Summary
In existing technologies, when the file system image is too large, rebuilding the read-only file system image takes a long time and the image building efficiency is low.
By determining the image reconstruction type, the data block index information is used to achieve individual management of each data block in the read-only file system image, including file modification, addition and deletion, direct replacement or saving of data blocks, and updating of index information, thus avoiding the reconstruction based on the original readable and writable file system.
The ability to quickly create new read-only file system images based on existing read-only file system images reduces rebuild time and improves image building efficiency.
Smart Images

Figure CN120872914B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of storage technology, and in particular to a method for reconstructing a read-only file system image, an electronic device, and a storage medium. Background Technology
[0002] A read-only file system allows reading the contents of files and directories, but prohibits writing, modifying, deleting, or creating new files.
[0003] Currently, to modify a read-only file, you first need to modify the file content based on the existing readable and writable file system, and then rebuild the read-only file system image. When the file system image is too large, rebuilding the file system image takes a long time and reduces work efficiency. Summary of the Invention
[0004] This application provides a method, electronic device, and storage medium for reconstructing a read-only file system image, to at least solve the problems in related technologies where rebuilding a file system image is time-consuming and inefficient when the file system image is too large.
[0005] This application provides a method for reconstructing a read-only file system image, including:
[0006] Determine the image reconstruction type to which the received read-only file system image reconstruction request belongs;
[0007] When the image reconstruction type is file modification, the first data block index information corresponding to each first data block in the file to be modified and the modified file are obtained. The file to be modified is replaced with the modified file according to the first data block index information, and the index information is updated according to the obtained modification result.
[0008] When the image reconstruction type is file addition, the newly added file and the index information of the second data block corresponding to each second data block in the newly added file are obtained. The newly added file is saved according to the index information of each second data block, and the index information is updated according to the obtained file addition result.
[0009] When the image reconstruction type is file deletion, obtain the file to be deleted and the index information of the third data block corresponding to each third data block in the file to be deleted, delete the file to be deleted according to the index information of each third data block, and update the index information according to the deletion result.
[0010] Reconstruct the read-only file system image based on the updated index information.
[0011] This application also provides an electronic device, including: a memory for storing a computer program; and a processor for implementing the steps of any of the above-described methods for reconstructing a read-only file system image when executing the computer program.
[0012] This application also provides a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, it implements the steps of any of the above-described methods for reconstructing a read-only file system image.
[0013] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of any of the above-described methods for reconstructing a read-only file system image.
[0014] This application achieves several improvements by determining the image reconstruction type. For file modifications, the corresponding files in the old read-only file system image are directly replaced based on the index information of the first data blocks in the file to be modified, and the index information is updated accordingly. For file additions, the new files are saved based on the index information of the second data blocks in the new files, and the index information is updated accordingly. For file deletions, the files are deleted based on the index information of the third data blocks in the files to be deleted. This allows for individual management of each data block in the read-only file system image through data block index information. It enables the rapid creation of new read-only file system images based on existing ones, eliminating the need to modify file content and rebuild the image from an existing readable / writable file system. Therefore, it solves the technical problem of high time consumption and low image construction efficiency when rebuilding a large file system image, significantly reducing the time required to rebuild the image and improving its efficiency. Attached Figure Description
[0015] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 A flowchart illustrating the implementation of a method for reconstructing a read-only file system image, as provided in this application embodiment;
[0017] Figure 2 A flowchart illustrating the implementation of another method for reconstructing a read-only file system image provided in this application embodiment;
[0018] Figure 3A simplified schematic diagram illustrating the reconstruction process of a read-only file system image provided in this application embodiment;
[0019] Figure 4 This is a structural block diagram of a read-only file system image reconstruction system provided in an embodiment of this application. Detailed Implementation
[0020] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.
[0021] It should be noted that, in the description of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or sequence.
[0022] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0023] The embodiments of this application provide a method for reconstructing a read-only file system image. The method is described in detail below in conjunction with the execution flow of the reconstructing method for a read-only file system image.
[0024] See Figure 1 , Figure 1 The following is a flowchart illustrating an implementation method for reconstructing a read-only file system image, which may include the following steps.
[0025] S101: Determine the image reconstruction type to which the received read-only file system image reconstruction request belongs.
[0026] When a read-only file system image needs to be reconstructed, a read-only file system image reconstruction request is generated and sent to the read-only file system image reconstruction center. The read-only file system image reconstruction center receives the read-only file system image reconstruction request and determines the image reconstruction type to which the received read-only file system image reconstruction request belongs.
[0027] The read-only file system image reconstruction center can be used for processors, servers, etc., to reconstruct read-only file system images.
[0028] S102: When the image reconstruction type is file modification, obtain the index information of the first data block corresponding to each first data block in the file to be modified and the modified file, replace the file to be modified with the modified file according to the index information of each first data block, and update the index information according to the obtained modification results.
[0029] After determining the image reconstruction type of the read-only file system image reconstruction request, when the reconstruction type is file modification, the file to be modified contains each first data block, and each first data block has its own corresponding first data block index information. The process involves obtaining the first data block index information corresponding to each first data block in the file to be modified, along with the modified file. Based on the first data block index information, the modified file is used to replace the file to be modified. The first data block index information corresponding to each first data block may contain the hash value corresponding to that first data block, and the index information is updated based on the obtained modification results. By updating the index information based on the obtained modification results, an effective record of the relationship between each data block after file modification and its corresponding data block index information is achieved.
[0030] A data block is a 4KB block that splits the contents of a file into multiple 4KB blocks.
[0031] S103: When the image reconstruction type is file addition, obtain the index information of the second data block corresponding to each second data block in the new file, save the new file according to the index information of each second data block, and update the index information according to the obtained file addition result.
[0032] After determining the image reconstruction type of the read-only file system image reconstruction request, when the reconstruction type is file addition, the system obtains the index information of the second data blocks corresponding to each second data block in the new file. The new file is saved based on the index information, and the index information is updated according to the file addition result. By using the index information of each second data block in the new file, the accurate addition of each second data block in the new file to the old read-only file system image is achieved. By updating the index information according to the file addition result, the system effectively records the correspondence between each data block after file addition and its corresponding index information.
[0033] S104: When the image reconstruction type is file deletion, obtain the file to be deleted and the index information of the third data block corresponding to each third data block in the file to be deleted, delete the file to be deleted according to the index information of each third data block, and update the index information according to the deletion result.
[0034] After determining the image reconstruction type of the read-only file system image reconstruction request, when the reconstruction type is file deletion, the system obtains the file to be deleted and the index information of each third data block within that file. The file is then deleted based on these index information, and the index information is updated according to the deletion results. By using the index information of each third data block in the file to be deleted, accurate deletion of each third data block from the old read-only file system image is achieved. Updating the index information based on the deletion results ensures effective recording of the data block index information obtained after file deletion and release.
[0035] S105: Reconstruct the read-only file system image based on the updated index information.
[0036] After updating the index information and obtaining the updated results, the read-only file system image is reconstructed based on these results. By using data block index information, individual management of each data block within the read-only file system image is achieved. This allows for the rapid creation of new read-only file system images based on existing ones, eliminating the need to modify file content on an existing readable and writable file system before rebuilding the read-only file system image. This significantly reduces the time required to rebuild the file system image and improves image construction efficiency.
[0037] This application achieves several improvements by determining the image reconstruction type. For file modifications, the corresponding files in the old read-only file system image are directly replaced based on the index information of the first data blocks in the file to be modified, and the index information is updated accordingly. For file additions, the new files are saved based on the index information of the second data blocks in the new files, and the index information is updated accordingly. For file deletions, the files are deleted based on the index information of the third data blocks in the files to be deleted. This allows for individual management of each data block in the read-only file system image through data block index information. It enables the rapid creation of new read-only file system images based on existing ones, eliminating the need to modify file content and rebuild the image from an existing readable / writable file system. Therefore, it solves the technical problem of high time consumption and low image construction efficiency when rebuilding a large file system image, significantly reducing the time required to rebuild the image and improving its efficiency.
[0038] See Figure 2 , Figure 2 The following is a flowchart illustrating an implementation method for reconstructing a read-only file system image, which may include the following steps.
[0039] S201: Determine the image reconstruction type to which the received read-only file system image reconstruction request belongs.
[0040] S202: When the image reconstruction type is file modification, obtain the first file name of the file to be modified in the old read-only file system image.
[0041] Each file in the old read-only file system image has its own corresponding filename. When the image reconstruction type is file modification, the first filename of the file to be modified in the old read-only file system image is obtained.
[0042] S203: Retrieve directory blocks from the old read-only file system image.
[0043] The old read-only file system image contains directory blocks, which store metadata indexes corresponding to each file in the old read-only file system image. Retrieve the directory blocks from the old read-only file system image.
[0044] S204: Locate the first metadata index of the file to be modified in the directory block based on the first file name.
[0045] The directory block stores the mapping between the metadata index and filename of each file in the old read-only file system image. After obtaining the directory block from the old read-only file system image, the first metadata index of the file to be modified is found in the directory block based on the first filename.
[0046] S205: Read the metadata information of the file to be modified in the old read-only file system image at the first position based on the first metadata index.
[0047] There is a correspondence between the metadata index and the location information of the metadata information in the old read-only file system image. After finding the first metadata index of the file to be modified from the directory block based on the first file name, the first location information of the metadata information of the file to be modified in the old read-only file system image is read based on the first metadata index.
[0048] S206: Obtain the first metadata information of the file to be modified in the old read-only file system image based on the first location information.
[0049] After reading the first location information of the metadata information of the file to be modified in the old read-only file system image based on the first metadata index, the first metadata information of the file to be modified in the old read-only file system image is obtained based on the first location information.
[0050] S207: Obtain the index information of the first data block corresponding to each first data block in the file to be modified from the first metadata information.
[0051] The index information of each first data block records the first hash value corresponding to each first data block.
[0052] After obtaining the first metadata information corresponding to the file to be modified, the index information of the first data block corresponding to each first data block in the file to be modified is obtained from the first metadata information. The index information of each first data block records the first hash value corresponding to each first data block.
[0053] S208: Read the modified file, compress the modified file into fourth data blocks, and calculate the second hash value corresponding to each fourth data block.
[0054] Each fourth data block has the same data block size as each first data block.
[0055] Read the modified file and compress it into fourth data blocks. Each fourth data block has the same size as each first data block. For example, the size of each data block can be set to 4k. Calculate the second hash value corresponding to each fourth data block.
[0056] S209: Modify the file according to each first hash value and each second hash value, and update the index information according to the modification results.
[0057] After calculating the second hash value corresponding to each fourth data block, the file is modified based on the first and second hash values, and the index information is updated based on the modification results. For example, the correspondence between the first and second hash values is determined based on the first data block index information. By comparing each first hash value with its corresponding second hash value, the first data block to be modified is obtained. Then, after modifying each first data block, the index information is updated based on the modification results. The metadata index corresponding to the file to be modified is found based on the file name. The metadata information of the file to be modified is then found based on the metadata information, and the data block index information corresponding to each data block in the file to be modified is found from the metadata information. This implements the lookup of the data block index information of each data block in the file to be modified. Each data block index information stores the hash value of each data block. The hash values of each data block in the modified file are obtained. By comparing the hash values of the data blocks in the file to be modified with the hash values of the data blocks in the modified file, the file to be modified is modified based on the comparison results. By making full use of the hash value in the data block index information, the data block to be modified can be quickly and accurately identified, and thus the read-only file system image can be modified by modifying only the data block to be modified.
[0058] In one specific embodiment of this application, modifying a file based on each first hash value and each second hash value may include the following steps:
[0059] Step 1: Traverse the second hash values corresponding to each first hash value based on the index information of the first data block;
[0060] Step 2: Perform a consistency comparison between each first hash value and its corresponding second hash value to obtain the hash value comparison results;
[0061] Step 3: Compare the number of each first data block in the file to be modified with the number of each fourth data block in the modified file to obtain the data block count comparison result;
[0062] Step 4: Modify the file based on the comparison results of each hash value and the comparison results of the number of data blocks.
[0063] For ease of description, the four steps above can be combined for explanation.
[0064] After calculating the second hash value corresponding to each fourth data block, the second hash values corresponding to each first hash value are traversed according to the index information of the first data block. A consistency comparison is performed between each first hash value and its corresponding second hash value to obtain the hash value comparison result. The number of each first data block in the file to be modified is compared with the number of each fourth data block in the modified file to obtain the data block count comparison result. The file is modified based on both the hash value comparison result and the data block count comparison result. The hash value comparison result identifies the first data blocks that need to be modified, achieving accurate filtering of the data blocks to be modified. The data block count comparison result determines whether the space after the old read-only file system image needs to be occupied, effectively identifying the space occupied by each fourth data block in the modified file.
[0065] In one specific embodiment of this application, modifying the file based on the comparison results of each hash value and the comparison results of the number of data blocks, and updating the index information based on the obtained modification results, may include the following steps:
[0066] Step 1: Select the hash value comparison results with inconsistent hash values from the hash value comparison results, and determine the first data block corresponding to the selected hash value comparison results as the data block to be replaced;
[0067] Step 2: Record the index information of the first data block to be replaced;
[0068] Step 3: When the number of data blocks is greater than or equal to the number of the fourth data blocks, replace the first data block corresponding to the first data block index information with the fourth data block corresponding to the first data block index information, and update the index information according to the replacement result.
[0069] Step 4: When the comparison of the number of data blocks shows that the number of each first data block is less than the number of each fourth data block, obtain the location of the free data block in the old read-only file system image;
[0070] Step 5: Save each fourth data block according to the location of the free data block and the recorded index information of the first data block, and update the index information according to the saved results.
[0071] For ease of description, the five steps above can be combined for explanation.
[0072] After comparing each first hash value with its corresponding second hash value to obtain the hash value comparison results, the hash value comparison results with inconsistent hash values are selected, and the first data block corresponding to the selected hash value comparison results is determined as the data block to be replaced. The index information of the first data block to be replaced is recorded. When the number of data blocks is greater than or equal to the number of fourth data blocks, it means that the position after the old read-only file system image does not need to be occupied. The fourth data block corresponding to the recorded first data block index information is used to replace the first data block corresponding to the recorded first data block index information, and the index information is updated according to the replacement result. When the number of data blocks is less than the number of fourth data blocks, it means that the position after the old read-only file system image needs to be occupied. The free data block position in the old read-only file system image is obtained, and each fourth data block is saved according to the free data block position and the recorded first data block index information. The index information is updated according to the saving result. By comparing the number of data blocks in the file to be modified with the number of data blocks in the modified file, and combining the comparison results of the number of data blocks and the comparison results of hash values, the file modification method is determined. This ensures that each data block in the modified file can be accurately added to the corresponding position in the old read-only file system image, thus achieving accurate modification of the file to be modified.
[0073] In one specific embodiment of this application, when the number of data blocks is greater than or equal to the number of fourth data blocks, replacing the first data block corresponding to the recorded first data block index information with the fourth data block corresponding to the recorded first data block index information may include the following steps:
[0074] Step 1: When the number of data blocks is equal to the number of fourth data blocks, replace the first data block corresponding to the first data block index information with the fourth data block corresponding to the first data block index information.
[0075] Step 2: When the number of data blocks is greater than the number of fourth data blocks, determine the data blocks to be deleted based on the recorded index information of the first data blocks and the second hash values.
[0076] Step 3: Perform the deletion operation on the data block to be deleted, and select the remaining first data block index information from the recorded first data block index information, excluding the first data block index information corresponding to the data block to be deleted;
[0077] Step 4: Replace the first data block corresponding to the first data block index information of the record with the fourth data block corresponding to the selected first data block index information.
[0078] For ease of description, the four steps above can be combined for explanation.
[0079] When the number of data blocks is equal to the number of fourth data blocks, it indicates that no position was released after data block replacement. The fourth data block corresponding to the recorded first data block index is used to replace the first data block corresponding to the recorded first data block index. When the number of data blocks is greater than the number of fourth data blocks, it indicates that position was released after data block replacement. The data block to be deleted is determined based on the recorded first data block index and each second hash value. The data block to be deleted is then deleted. The remaining first data block indexes (excluding those corresponding to the data block to be deleted) are selected from the recorded first data block indexes, and the fourth data blocks corresponding to these selected first data block indexes are used to replace the first data block corresponding to the recorded first data block index. By distinguishing whether the number of first data blocks is greater than or equal to the number of fourth data blocks, when the result is equal, file modification is achieved solely through data block replacement; when the result is greater, file modification is achieved through a combination of data block replacement and data block deletion, thus achieving accurate file modification.
[0080] When deleting a data block, it can be done by filling its location with zeros, and the index information of the zero-filled block is recorded, perhaps stored in a superblock. When data needs to be written to the zero-filled block, the superblock is consulted to locate the zero-filled block, and the data to be written replaces the original zeros. This ensures accurate marking of free data block locations and reduces additional operations. By recording the data block index information in the superblock, timely retrieval of the index information is achieved, facilitating its subsequent reuse.
[0081] In one specific embodiment of this application, updating the index information based on the obtained replacement result may include the following steps:
[0082] Step 1: Delete the index information of the first data block corresponding to the data block to be deleted in the old read-only file system image, and save the deleted index information of the first data block to the superblock;
[0083] Step 2: Update the index information of the remaining first data blocks in the old read-only file system image based on the second hash value of the fourth data block corresponding to the index information of the remaining first data blocks.
[0084] For ease of description, the two steps above can be combined for explanation.
[0085] The header of the old read-only file system image contains a superblock, which records the locations of free data blocks in the old read-only file system image. The index information of the first data block corresponding to the data block to be deleted in the old read-only file system image is deleted, and the deleted first data block index information is saved to the superblock. Based on the second hash value of the fourth data block corresponding to the remaining first data block index information, the index information of the remaining first data blocks in the old read-only file system image is updated. By saving the deleted first data block index information to the superblock, the first data block index information is promptly reclaimed, facilitating its reuse. By updating the data block index information promptly, the accurate recording of the correspondence between each data block and its index information in the modified file is achieved.
[0086] In one specific embodiment of this application, saving each fourth data block according to the location of the free data block and the recorded index information of the first data block may include the following steps:
[0087] Step 1: Determine the fourth data block to be saved to the end of the old read-only file system image based on the recorded first data block index information;
[0088] Step 2: Save the fourth data block, which is to be saved to the end of the old read-only file system image, to the end of the old read-only file system image;
[0089] Step 3: According to the recorded first data block index information, save the remaining fourth data blocks in each fourth data block, except for the fourth data block to be saved to the end of the old read-only file system image, to the free data block location.
[0090] For ease of description, the three steps above can be combined for explanation.
[0091] After obtaining the location of free data blocks in the old read-only file system image, the fourth data block to be saved to the end of the old read-only file system image is determined based on the recorded first data block index information. This fourth data block is then saved to the end of the old read-only file system image. Following the recorded first data block index information, the remaining fourth data blocks, excluding the one to be saved to the end of the old read-only file system image, are saved to the free data block location. This achieves full utilization of the free data block location.
[0092] In one specific embodiment of this application, updating the index information based on the obtained saving results may include the following steps:
[0093] Update the data block index information in the first metadata information based on the saved results.
[0094] After each fourth data block is saved, the saving result is obtained, and the data block index information in the first metadata information is updated according to the obtained saving result. By updating the data block index information in the first metadata information in a timely manner according to the saving result, the accurate recording of the correspondence between data blocks and data block index information is achieved.
[0095] S210: When the image reconstruction type is file addition, obtain the new file and compress the new file to obtain each second data block.
[0096] When the image reconstruction type is file addition, the newly added file is obtained and compressed to obtain each second data block. The size of the second data block is the same as the size of the first data block.
[0097] S211: Calculate the third hash value corresponding to each second data block.
[0098] After compressing the new file to obtain the second data blocks, the third hash value corresponding to each second data block is calculated.
[0099] S212: Construct the second metadata information of the newly added file and the second data block index information corresponding to each second data block, and save each third hash value to the second data block index information.
[0100] After calculating the third hash value corresponding to each second data block, the second metadata information of the newly added file and the second data block index information corresponding to each second data block are constructed, and the third hash value is saved to the second data block index information.
[0101] S213: Update the index information of each second data block to the second metadata information respectively, and save the second metadata information to the end of the old read-only file system image.
[0102] After saving each third hash value to the corresponding second data block index information, the second data block index information is updated to the second metadata information, and the second metadata information is saved to the end of the old read-only file system image. This completes the initialization of the metadata information corresponding to the newly added file.
[0103] S214: Obtain the first data block index information of the location of free data blocks in the old read-only file system image from the superblock.
[0104] The first data block index information of the location of free data blocks in the old read-only file system image is obtained from the superblock, so that the location of free data blocks in the old read-only file system image can be determined based on the first data block index information.
[0105] S215: Save each second data block according to the index information of the first data block, update the metadata information, and update the directory block according to the updated metadata information.
[0106] After retrieving the first data block index information of the location of free data blocks in the old read-only file system image from the superblock, the second data blocks are saved according to the first data block index information, and the metadata information is updated. The directory blocks are then updated based on the updated metadata information. This achieves accurate recording of the relationship between each data block and its index information after the addition of a new file.
[0107] In one specific embodiment of this application, saving each second data block according to the first data block index information may include the following steps:
[0108] Step 1: Determine if the number of free data block locations is greater than or equal to the number of second data blocks. If yes, proceed to Step 2; otherwise, proceed to Step 3.
[0109] Step 2: Save each second data block to the location of each free data block;
[0110] Step 3: Select a number of second data blocks from each second data block location that are free data blocks, and save each selected second data block to its respective free data block location. Save the remaining second data blocks from each second data block, except those saved to their respective free data block locations, to the end of the old read-only file system image.
[0111] For ease of description, the three steps above can be combined for explanation.
[0112] After obtaining the first data block index information of the free data block locations in the old read-only file system image from the superblock, it is determined whether the number of free data block locations is greater than or equal to the number of second data blocks. If so, it means that the free data block locations alone can meet the storage requirements of the second data blocks, and each second data block is saved to its respective free data block location. If not, it means that the free data block locations alone cannot meet the storage requirements of the second data blocks, and the selected second data blocks are selected from the free data block locations and saved to their respective free data block locations. The remaining second data blocks, excluding those saved to their respective free data block locations, are saved to the end of the old read-only file system image. By comparing the number of free data block locations with the number of newly added data blocks, the effective utilization of free data block locations is achieved while ensuring the effective storage of newly added data blocks.
[0113] S216: When the image reconstruction type is file deletion, obtain the second file name of the file to be deleted.
[0114] When the image reconstruction type is file deletion, obtain the second filename of the file to be deleted.
[0115] S217: Retrieve directory blocks from an old read-only file system image.
[0116] Retrieve directory blocks from an old read-only file system image.
[0117] S218: Locate the second metadata index of the file to be deleted from the directory block based on the second file name.
[0118] After obtaining the second file name and directory block of the file to be deleted, the second metadata index of the file to be deleted is found from the directory block based on the second file name.
[0119] S219: Obtain the second location information of the metadata information of the file to be deleted in the old read-only file system image based on the second metadata index.
[0120] After finding the second metadata index of the file to be deleted, the second location information of the metadata information of the file to be deleted in the old read-only file system image is obtained based on the second metadata index.
[0121] S220: Based on the second location information, find the third metadata information corresponding to the file to be deleted, and based on the third metadata information, find the third data block index information corresponding to each third data block in the file to be deleted.
[0122] After obtaining the second location information of the metadata information of the file to be deleted in the old read-only file system image, the third metadata information of the file to be deleted is found based on the second location information, and the index information of the third data block corresponding to each third data block in the file to be deleted is found based on the third metadata information.
[0123] S221: Locate each third data block based on its index information.
[0124] After finding the index information of each third data block in the file to be deleted, the third data block is located based on the index information.
[0125] S222: Delete the third metadata information and each third data block, and update the index information based on the deletion results.
[0126] After locating each third data block, the third metadata information and each third data block are deleted, and the index information is updated based on the deletion results. By updating the index information based on the deletion results, the correspondence between each data block and the data block index information is updated in a timely manner.
[0127] In one specific embodiment of this application, updating the index information based on the obtained deletion results may include the following steps:
[0128] Save the index information of each third data block to the superblock and mark the index information of each third data block as unused.
[0129] After deleting the third-level metadata information and each third-level data block, the index information of each third-level data block is saved to the superblock, and the index information of each third-level data block is marked as unused. This enables timely recycling of the data block index information and facilitates its subsequent reuse.
[0130] S223: Reconstruct the read-only file system image based on the updated index information.
[0131] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.
[0132] See Figure 3 , Figure 3This is a simplified schematic diagram illustrating the reconstruction process of a read-only file system image provided in this application embodiment. An image creation device, a file reading device, a file modification device, a metadata management device, a file insertion device, and a file comparison device are pre-configured. The image creation device is used to create a new read-only file system image from an old read-only file system image after file modification or file addition processing is completed. The file reading device is used to read the metadata information of the corresponding file in the old read-only file system image and obtain the index information of each data block when creating a new read-only file system image after file modification. The file comparison device is used to compare the newly modified file with the old file to determine whether the file in the image is the corresponding modified file. The file modification device is used to replace the modified file data block information in the image. The metadata management device is used to update the metadata information corresponding to the file in the image after file modification. The file insertion device is used to insert the new file into the image when a new file is added during image construction.
[0133] For file modifications, the system specifies the file to be modified, locates the corresponding file's storage location within the image, reads the file's content from the image, replaces it with the content of the file to be updated, and then updates the file's metadata. If the original file's data blocks are insufficient, the system searches for free data blocks within the image and stores them there. For added files, the system compresses the file content, saves the metadata to the end of the image, stores the actual data blocks in free data blocks within the image, and then updates the corresponding directory blocks. This method allows for the rapid creation of new read-only file system images based on existing ones, significantly reducing the time required to rebuild the file system image.
[0134] Embodiments of this application also provide a system for reconstructing a read-only file system image.
[0135] See Figure 4 , Figure 4 A structural block diagram of a read-only file system image reconstruction system provided in this application embodiment, the system may include:
[0136] The image reconstruction type determination module 41 is used to determine the image reconstruction type to which the received read-only file system image reconstruction request belongs;
[0137] The first index information update module 42 is used to obtain the first data block index information and the modified file corresponding to each first data block in the file to be modified when the image reconstruction type is file modification, replace the file to be modified with the modified file according to the first data block index information, and update the index information according to the obtained modification result.
[0138] The second index information update module 43 is used to obtain the index information of the newly added file and the index information of the second data block corresponding to each second data block in the newly added file when the image reconstruction type is file addition; save the newly added file according to the index information of each second data block; and update the index information according to the obtained file addition result.
[0139] The third index information update module 44 is used to obtain the file to be deleted and the index information of the third data block corresponding to each third data block in the file to be deleted when the image reconstruction type is file deletion, delete the file to be deleted according to the index information of each third data block, and update the index information according to the deletion result.
[0140] The read-only file system image reconstruction module 45 is used to reconstruct the read-only file system image based on the updated results obtained from the index information.
[0141] This application achieves several improvements by determining the image reconstruction type. For file modifications, the corresponding files in the old read-only file system image are directly replaced based on the index information of the first data blocks in the file to be modified, and the index information is updated accordingly. For file additions, the new files are saved based on the index information of the second data blocks in the new files, and the index information is updated accordingly. For file deletions, the files are deleted based on the index information of the third data blocks in the files to be deleted. This allows for individual management of each data block in the read-only file system image through data block index information. It enables the rapid creation of new read-only file system images based on existing ones, eliminating the need to modify file content and rebuild the image from an existing readable / writable file system. Therefore, it solves the technical problem of high time consumption and low image construction efficiency when rebuilding a large file system image, significantly reducing the time required to rebuild the image and improving its efficiency.
[0142] In one specific embodiment of this application, the first index information update module 42 may include:
[0143] The first file name retrieval submodule is used to retrieve the first file name of the file to be modified in the old read-only file system image.
[0144] The first directory block retrieval submodule is used to retrieve directory blocks from the old read-only file system image.
[0145] The first metadata index lookup submodule is used to find the first metadata index of the file to be modified from the directory block based on the first file name;
[0146] The first location information reading submodule is used to read the first location information of the metadata information corresponding to the file to be modified in the old read-only file system image based on the first metadata index.
[0147] The first metadata information acquisition submodule is used to acquire the first metadata information of the file to be modified in the old read-only file system image based on the first location information.
[0148] The first data block index information acquisition submodule is used to obtain the first data block index information corresponding to each first data block in the file to be modified from the first metadata information; wherein, each first data block index information records the first hash value corresponding to each first data block;
[0149] The second hash value calculation submodule is used to read the modified file, compress the modified file into each fourth data block, and calculate the second hash value corresponding to each fourth data block; wherein, each fourth data block has the same data block size as each first data block;
[0150] The file modification submodule is used to modify files based on each first hash value and each second hash value.
[0151] In one specific embodiment of this application, the file modification submodule may include:
[0152] The second hash value traversal unit is used to traverse the second hash value corresponding to each first hash value according to the index information of the first data block;
[0153] The hash value comparison result acquisition unit is used to perform a consistency comparison between each first hash value and its corresponding second hash value to obtain the hash value comparison result.
[0154] The data block number comparison result acquisition unit is used to compare the number of each first data block in the file to be modified with the number of each fourth data block in the modified file to obtain the data block number comparison result;
[0155] The file modification unit is used to modify files based on the comparison results of each hash value and the comparison results of the number of data blocks.
[0156] In one specific embodiment of this application, the first index information update module 42 may include:
[0157] The data block to be replaced submodule is used to select the hash value comparison results with inconsistent hash values from the hash value comparison results, and determine the first data block corresponding to the selected hash value comparison result as the data block to be replaced;
[0158] The first data block index information recording submodule is used to record the first data block index information of the data block to be replaced;
[0159] The first index information update submodule is used to replace the first data block corresponding to the first data block index information with the fourth data block corresponding to the recorded first data block index information when the data block count comparison result is that the number of each first data block is greater than or equal to the number of each fourth data block, and update the index information according to the replacement result.
[0160] The free data block location acquisition submodule is used to obtain the location of free data blocks in the old read-only file system image when the number of first data blocks is less than the number of fourth data blocks in the data block count comparison result.
[0161] The second index information update submodule is used to save each fourth data block according to the location of the free data block and the recorded index information of the first data block, and update the index information according to the saved results.
[0162] In one specific embodiment of this application, the first index information update submodule may include:
[0163] The first data block replacement unit is used to replace the first data block corresponding to the first data block index information with the fourth data block corresponding to the first data block index information when the data block quantity comparison result is that the number of each first data block is equal to the number of each fourth data block.
[0164] The data block determination unit is used to determine the data block to be deleted based on the recorded first data block index information and each second hash value when the data block quantity comparison result shows that the number of each first data block is greater than the number of each fourth data block.
[0165] The first data block index information selection unit is used to perform a deletion operation on the data block to be deleted, and to select the remaining first data block index information from the recorded first data block index information, excluding the first data block index information corresponding to the data block to be deleted.
[0166] The second data block replacement unit is used to replace the first data block corresponding to the first data block index information of the record with the fourth data block corresponding to the selected other first data block index information.
[0167] In one specific embodiment of this application, the first index information update submodule may include:
[0168] The first data block index information storage unit is used to delete the first data block index information corresponding to the data block to be deleted in the old read-only file system image, and save the deleted first data block index information to the super block.
[0169] The first index information update unit is used to update the index information of the remaining first data blocks in the old read-only file system image based on the second hash value of the fourth data block corresponding to the index information of the remaining first data blocks.
[0170] In one specific embodiment of this application, the second index information update submodule may include:
[0171] The data block determination unit is used to determine the fourth data block to be saved to the end of the old read-only file system image based on the recorded first data block index information;
[0172] The first data block storage unit is used to save the fourth data block, which is to be saved to the end of the old read-only file system image, to the end of the old read-only file system image.
[0173] The second data block storage unit is used to save the remaining fourth data blocks, except for the fourth data block to be saved to the end of the old read-only file system image, to the free data block location according to the recorded first data block index information.
[0174] In one specific embodiment of this application, the second index information update submodule is specifically a module that updates the data block index information in the first metadata information according to the obtained saving result.
[0175] In one specific embodiment of this application, the second index information update module 43 may include:
[0176] The file compression submodule is used to obtain the newly added file and compress it to obtain the second data blocks.
[0177] The third hash value calculation submodule is used to calculate the third hash value corresponding to each second data block;
[0178] The hash value storage submodule is used to construct the second metadata information of the newly added file and the second data block index information corresponding to each second data block, and to save each third hash value to the corresponding second data block index information;
[0179] The metadata information storage submodule is used to update the index information of each second data block to the second metadata information, and save the second metadata information to the end of the old read-only file system image;
[0180] The data block index information acquisition submodule is used to obtain the first data block index information of the location of free data blocks in the old read-only file system image from the superblock;
[0181] The directory block update submodule is used to save each second data block according to the index information of the first data block, update the metadata information, and update the directory block according to the obtained metadata information update result.
[0182] In one specific embodiment of this application, the directory block update submodule may include:
[0183] The judgment unit is used to determine whether the number of free data block locations is greater than or equal to the number of second data blocks;
[0184] The third data block storage unit is used to save each second data block to each free data block location when the number of determined free data block locations is greater than or equal to the number of second data blocks.
[0185] The fourth data block saving unit is used to select a number of second data blocks from each second data block when the number of free data block locations is less than the number of second data blocks, and save each selected second data block to each free data block location, and save the remaining second data blocks from each second data block except those saved to each free data block location to the end of the old read-only file system image.
[0186] In one specific embodiment of this application, the third index information update module 44 may include:
[0187] The second file name retrieval submodule is used to retrieve the second file name of the file to be deleted.
[0188] The second directory block retrieval submodule is used to retrieve directory blocks from the old read-only file system image.
[0189] The second metadata index lookup submodule is used to find the second metadata index of the file to be deleted from the directory block based on the second file name;
[0190] The second location information acquisition submodule is used to obtain the second location information of the metadata information of the file to be deleted in the old read-only file system image based on the second metadata index.
[0191] The third data block index information lookup submodule is used to find the third metadata information corresponding to the file to be deleted based on the second location information, and to find the third data block index information corresponding to each third data block in the file to be deleted based on the third metadata information.
[0192] The third data block lookup submodule is used to look up each third data block based on the index information of each third data block.
[0193] The delete submodule is used to delete third-party metadata information and each third-party data block.
[0194] In one specific embodiment of this application, the third index information update module 44 is specifically a module that saves the index information of each third data block to the super block and marks the index information of each third data block as unused.
[0195] For a description of the features in the embodiment corresponding to the reconstruction system of the read-only file system image, please refer to the relevant description of the embodiment corresponding to the reconstruction method of the read-only file system image, which will not be repeated here.
[0196] Embodiments of this application also provide an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the steps in any of the above embodiments of the method for reconstructing a read-only file system image.
[0197] Embodiments of this application also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above-described embodiments of the method for reconstructing a read-only file system image.
[0198] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.
[0199] Embodiments of this application also provide a computer program product, which includes a computer program that, when executed by a processor, implements the steps in any of the above-described methods for reconstructing a read-only file system image.
[0200] Embodiments of this application also provide another computer program product, including a non-volatile computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in any of the above-described reconstruction method embodiments of a read-only file system image.
[0201] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0202] The foregoing has provided a detailed description of the method for reconstructing a read-only file system image, the electronic device, and the storage medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only intended to help understand the method and core ideas of this application. It should be noted that those skilled in the art can make several improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of this application.
Claims
1. A method for reconstructing a read-only file system image, characterized in that, include: Determine the image reconstruction type to which the received read-only file system image reconstruction request belongs; When the image reconstruction type is file modification, the first data block index information corresponding to each first data block in the file to be modified and the modified file are obtained. The file to be modified is replaced with the modified file according to the first data block index information, and the index information is updated according to the obtained modification result. When the image reconstruction type is file addition, the newly added file and the index information of the second data block corresponding to each second data block in the newly added file are obtained. The newly added file is saved according to the index information of each second data block, and the index information is updated according to the obtained file addition result. When the image reconstruction type is file deletion, obtain the file to be deleted and the index information of the third data block corresponding to each third data block in the file to be deleted, delete the file to be deleted according to the index information of each third data block, and update the index information according to the deletion result. Reconstruct the read-only file system image based on the updated index information; The process includes obtaining the index information of the first data blocks corresponding to each first data block in the file to be modified and the modified file, and replacing the file to be modified with the modified file according to the index information of each first data block, including: Obtain the first filename of the file to be modified in the old read-only file system image; Obtain the directory blocks from the old read-only file system image; The first metadata index of the file to be modified is located from the directory block based on the first file name; The metadata information corresponding to the file to be modified is read from the first metadata index, and the first location information in the old read-only file system image is read. Based on the first location information, obtain the first metadata information of the file to be modified in the old read-only file system image; Obtain the first data block index information corresponding to each first data block in the file to be modified from the first metadata information; wherein, each first data block index information records the first hash value corresponding to each first data block; The modified file is read and compressed into fourth data blocks, and the second hash value corresponding to each fourth data block is calculated; wherein, the size of each fourth data block is the same as that of each first data block. Modify the file based on each first hash value and each second hash value; Modify the file based on each first hash value and each second hash value, including: Based on the index information of the first data block, traverse the second hash values corresponding to each first hash value; Each first hash value is compared with its corresponding second hash value to obtain the hash value comparison result. The number of each first data block in the file to be modified is compared with the number of each fourth data block in the modified file to obtain the data block number comparison result; The file is modified based on the comparison results of each hash value and the comparison results of the number of data blocks; The file is modified based on the comparison results of each hash value and the comparison results of the number of data blocks, and the index information is updated based on the obtained modification results, including: Select the hash value comparison results that are inconsistent from the hash value comparison results, and determine the first data block corresponding to the selected hash value comparison results as the data block to be replaced; Record the first data block index information of the data block to be replaced; When the number of data blocks is compared and the number of each first data block is greater than or equal to the number of each fourth data block, the first data block corresponding to the first data block index information is replaced by the fourth data block corresponding to the first data block index information, and the index information is updated according to the replacement result. When the comparison result of the number of data blocks is that the number of each first data block is less than the number of each fourth data block, the location of the free data block in the old read-only file system image is obtained. Each fourth data block is saved according to the location of the free data block and the recorded index information of the first data block, and the index information is updated according to the saved results. When the comparison result of the number of data blocks shows that the number of each first data block is greater than or equal to the number of each fourth data block, the first data block corresponding to the recorded first data block index information is replaced with the fourth data block corresponding to the recorded first data block index information, including: When the data block count comparison result is that the number of each first data block is equal to the number of each fourth data block, the first data block corresponding to the first data block index information is replaced by the fourth data block corresponding to the first data block index information. When the comparison result of the number of data blocks shows that the number of each first data block is greater than the number of each fourth data block, the data blocks to be deleted are determined according to the recorded first data block index information and each second hash value. The deletion operation is performed on the data block to be deleted, and the remaining first data block index information is selected from the recorded first data block index information, excluding the first data block index information corresponding to the data block to be deleted. Specifically, when deleting the data block to be deleted, it is deleted by filling the position of the data block to be deleted with 0s, and the data block index information corresponding to the data block filled with 0s is stored in the super block. When it is necessary to write data to the data block filled with 0s, the data block index information is searched in the super block, the data block filled with 0s is found according to the data block index information, and the original filling is replaced with the data to be written. Replace the first data block corresponding to the first data block index information of the record with the fourth data block corresponding to the selected first data block index information.
2. The method for reconstructing a read-only file system image according to claim 1, characterized in that, Update the index information based on the replacement results, including: Delete the index information of the first data block corresponding to the data block to be deleted in the old read-only file system image, and save the deleted index information of the first data block to the super block; The index information of the remaining first data blocks in the old read-only file system image is updated based on the second hash value of the fourth data block corresponding to the index information of the remaining first data blocks.
3. The method for reconstructing a read-only file system image according to claim 1, characterized in that, Each fourth data block is saved according to the location of the free data block and the recorded index information of the first data block, including: The fourth data block to be saved to the end of the old read-only file system image is determined based on the recorded first data block index information; The fourth data block to be saved to the end of the old read-only file system image is saved to the end of the old read-only file system image; According to the recorded first data block index information, the remaining fourth data blocks in each fourth data block, except for the fourth data block to be saved to the end of the old read-only file system image, are saved to the free data block location.
4. The method for reconstructing a read-only file system image according to claim 3, characterized in that, Update the index information based on the saved results, including: Update the data block index information in the first metadata information based on the obtained saving results.
5. The method for reconstructing a read-only file system image according to claim 1, characterized in that, Obtain the newly added file and the index information of the second data blocks corresponding to each second data block in the newly added file; save the newly added file according to the index information of each second data block; and update the index information according to the obtained file addition results, including: The newly added file is obtained and compressed to obtain each second data block; Calculate the third hash value corresponding to each second data block; Construct the second metadata information of the newly added file and the second data block index information corresponding to each second data block, and save each third hash value to the second data block index information accordingly; Update the index information of each second data block to the second metadata information respectively, and save the second metadata information to the end of the old read-only file system image; Obtain the first data block index information of the location of free data blocks in the old read-only file system image from the superblock; Each second data block is saved according to the index information of the first data block, and the metadata information is updated. The directory block is then updated according to the updated metadata information.
6. The method for reconstructing a read-only file system image according to claim 5, characterized in that, Each second data block is saved according to the index information of the first data block, including: Determine whether the number of free data block locations is greater than or equal to the number of the second data blocks; If so, save each second data block to the location of each free data block; If not, select the number of second data blocks at the free data block location from each second data block, save each selected second data block to each free data block location, and save the remaining second data blocks from each second data block except those saved to each free data block location to the end of the old read-only file system image.
7. The method for reconstructing a read-only file system image according to claim 1, characterized in that, Obtain the file to be deleted and the index information of the third data blocks corresponding to each third data block in the file to be deleted, and delete the file to be deleted according to the index information of each third data block, including: Obtain the second filename of the file to be deleted; Retrieve directory blocks from an old read-only file system image; The second metadata index of the file to be deleted is located from the directory block based on the second file name; The metadata information corresponding to the file to be deleted is obtained from the second metadata index, and its second location information is obtained in the old read-only file system image. Based on the second location information, find the third metadata information corresponding to the file to be deleted, and based on the third metadata information, find the third data block index information corresponding to each third data block in the file to be deleted; Find each third data block based on its index information; The third metadata information and each third data block are deleted.
8. The method for reconstructing a read-only file system image according to claim 7, characterized in that, Update the index information based on the deletion results, including: Save the index information of each third data block to the superblock and mark the index information of each third data block as unused.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the method for reconstructing a read-only file system image as described in any one of claims 1 to 8 when executing the computer program.
Citation Information
Patent Citations
File management system and method for container in cloud computing
CN120316088A
File system processing method, electronic equipment and medium
CN120386773A
