File operation method, file operating system, electronic device and storage medium
By generating log data in solid-state hard disk to build file system index, the write amplification effect caused by traditional file operation methods is solved, equipment loss is reduced, and operation efficiency and life is improved.
Patent Information
- Application Number
- CN202010966292.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-15
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2040-09-15
AI Technical Summary
Traditional file operation methods lead to amplification effect of solid-state drives, increasing losses to solid-state drives and reducing their service life.
By generating log data, building a file system index, using the file system index in memory for file operations, avoiding in-situ modification of metadata information on the storage device, and reducing erming operations.
It reduces the loss of storage equipment, improves the efficiency of file operation, and extends the service life of the equipment.
Smart Images

Figure CN114185849B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of storage technologies, and particularly to a file operation method, a file operating system, an electronic device, and a storage medium. Background Art
[0002] With the development of flash memory technology, storage devices using flash memory particles as storage media are increasingly favored. For example, solid-state drives (SSDs) have fast read and write speeds, low power consumption, no noise, anti-vibration, low heat generation, small size, and a large operating temperature range, and are widely used in military, vehicle-mounted, industrial, medical, aerospace and other fields.
[0003] The flash memory particles used in solid-state drives generally consist of thousands of data blocks of the same size inside. The size of a data block is generally several hundred KB to several MB. Each data block is further divided into several data pages of the same size inside. The size of a data page is generally 4KB or 8KB.
[0004] When writing data into a solid-state drive, it can only be written in terms of data pages. If a certain data page in the solid-state drive has already been written with data, then data cannot be directly written into this data page again. It can only be written again after the data in this data page is cleared. This characteristic of the solid-state drive will introduce a situation of write amplification, that is, if a certain data in a data page needs to be modified, the entire data page needs to be moved to another clean data page to write the new data, that is, the data actually written on the flash memory particles is much larger than the data modified by the user itself.
[0005] The flash memory particles work in such a "erase" and "program" cycle. One such cycle is called a program / erase (abbreviated as P / E). The number of P / E cycles of each data block in the flash memory particles is limited; when the number of P / E cycles of a certain data block reaches the upper limit, it cannot be guaranteed to continue to effectively access data.
[0006] Therefore, although solid-state drives have many advantages, they have their own read and write characteristics, and the service life of solid-state drives has an upper limit. After reaching the upper limit, the solid-state drive will be unusable.
[0007] Traditional file operation methods all modify data in place, such as the modification of file metadata, etc. This in-place modification will bring a write amplification effect and increase the loss of the solid-state drive. Summary of the Invention
[0008] The following is an overview of the subject matter described in detail in this article. This overview is not intended to limit the scope of protection of the claims.
[0009] An embodiment of the present invention provides a file operation method, a file operation system, an electronic device, and a storage medium, which can reduce the wear and tear of the storage device.
[0010] In a first aspect, an embodiment of the present invention provides a file operation method, including:
[0011] Generating corresponding log data in the storage device according to the historical operation information of the storage device, and constructing a file system index of the storage device in the memory according to the log data;
[0012] Determining a target file according to a user's file operation instruction, searching for the target file according to the file system index, and performing an operation corresponding to the file operation instruction on the target file.
[0013] In a second aspect, an embodiment of the present invention further provides a file operation system, including:
[0014] A construction unit, configured to generate corresponding log data in the storage device according to the historical operation information of the storage device, and construct a file system index of the storage device in the memory according to the log data;
[0015] An operation unit, configured to determine a target file according to a user's file operation instruction, search for the target file according to the file system index, and perform an operation corresponding to the file operation instruction on the target file.
[0016] In a third aspect, an embodiment of the present invention further provides an electronic device:
[0017] Including at least one processor and a memory for communicatively connecting with the at least one processor; the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the file operation method described in the first aspect.
[0018] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, where the computer-readable storage medium stores computer-executable instructions for causing a computer to execute the file operation method described in the first aspect.
[0019] The embodiments of the present invention at least include the following beneficial effects: generating corresponding log data in the storage device according to the historical operation information of the storage device, and constructing a file system index of the storage device in the memory according to the log data; determining a target file according to a file operation instruction of a user, searching for the target file according to the file system index, and performing an operation corresponding to the file operation instruction on the target file. By generating log data according to historical operation records, the log data can be used to record the operations of users, and a file system index of the storage device can be constructed in the memory. In this way, the file system index can form a complete file operating system, and the operations on files can be carried out through the file system index. Therefore, the metadata information of files does not need to be stored in the data area of the storage device, and the operations on files do not involve in-place modification of the metadata information of the storage device, avoiding multiple erasures of the storage device and reducing the wear of the storage device. At the same time, since the file system index is located in the memory, the access speed is fast, which is beneficial to improving the efficiency of file operations.
[0020] Other features and advantages of the present invention will be described in the following description, and some of them will become obvious from the description or be understood by implementing the present invention. The objectives and other advantages of the present invention can be achieved and obtained through the structures specifically pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The drawings are used to provide a further understanding of the technical solutions of the present invention, and constitute a part of the description. They are used together with the embodiments of the present invention to explain the technical solutions of the present invention, and do not constitute a limitation to the technical solutions of the present invention.
[0022] Figure 1 is a schematic structural diagram of a file operating system provided by an embodiment of the present invention;
[0023] Figure 2 is a flowchart of a file operation method provided by an embodiment of the present invention;
[0024] Figure 3 is a schematic structural diagram of a file system index provided by an embodiment of the present invention;
[0025] Figure 4 is a flowchart of generating corresponding log data in a storage device according to the historical operation information of the storage device provided by an embodiment of the present invention;
[0026] Figure 5 is a flowchart of constructing a file system index of a storage device in the memory according to log data provided by an embodiment of the present invention;
[0027] Figure 6 is a schematic structural diagram of a log block provided by an embodiment of the present invention;
[0028] Figure 7 It is a flowchart provided by an embodiment of the present invention for finding a target file according to a file system index and performing an operation corresponding to a file operation instruction on the target file (the file operation instruction is a file reading instruction);
[0029] Figure 8 It is a flowchart provided by an embodiment of the present invention for finding a target file according to a file system index and performing an operation corresponding to a file operation instruction on the target file (the file operation instruction is a file modification instruction);
[0030] Figure 9 It is a flowchart provided by an embodiment of the present invention for finding a target file according to a file system index and performing an operation corresponding to a file operation instruction on the target file (the file operation instruction is another file modification instruction);
[0031] Figure 10 It is a flowchart provided by an embodiment of the present invention for finding a target file according to a file system index and performing an operation corresponding to a file operation instruction on the target file (the file operation instruction is a file deletion instruction);
[0032] Figure 11 It is a flowchart provided by an embodiment of the present invention for finding a target file according to a file system index and performing an operation corresponding to a file operation instruction on the target file (the file operation instruction is a file moving instruction);
[0033] Figure 12 It is a schematic diagram of log data recovery provided by an embodiment of the present invention;
[0034] Figure 13 It is a schematic diagram of data block recovery provided by an embodiment of the present invention;
[0035] Figure 14 It is a flowchart of a specific example of a file operation method provided by an embodiment of the present invention;
[0036] Figure 15 It is a schematic diagram of the structure of a file operation system provided by an embodiment of the present invention;
[0037] Figure 16 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. Detailed implementation manners
[0038] In order to make the objectives, technical solutions and advantages of the present invention clearer and more understandable, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0039] It should be understood that in the description of the embodiments of the present invention, the meaning of "multiple (or plural)" is more than two. Understandings such as "greater than", "less than", "exceeding", etc. do not include the corresponding number, and understandings such as "above", "below", "within", etc. include the corresponding number. If there is a description of "first", "second", etc., it is only for the purpose of distinguishing technical features, and cannot be understood as indicating or implying relative importance or implicitly indicating the quantity of the indicated technical features or implicitly indicating the sequence relationship of the indicated technical features.
[0040] The embodiments of the present invention are described by taking a solid-state drive as an example. Refer to Figure 1 , which is a schematic diagram of the architecture of the file operating system provided by the embodiments of the present invention. The file operating system includes a superblock, a log area, and a data area. Among them, the superblock is used to store the global data of the file operating system. When the file operating system is used for the first time, the hard disk is first formatted, and the global data is written into the superblock. The global data is the partition size, partition start position, etc. of the hard disk. The log area is used to store the historical operation records of users on the file operating system and the metadata of the corresponding files, etc. The log area can be divided into multiple log blocks, and each log block corresponds to an operation record. Exemplarily, the size of a single log block can be 128 bytes. The data area is used to store the data of the file itself. The data area contains multiple data blocks, and each data block contains multiple data pages. Exemplarily, the size of each data page can be set to 4 kilobytes.
[0041] Based on Figure 1 the file operating system shown, refer to Figure 2 , the embodiments of the present invention provide a file operation method, including but not limited to the following steps 201 to step 202:
[0042] Step 201: Generate corresponding log data in the storage device according to the historical operation information of the storage device, and construct a file system index of the storage device in the memory;
[0043] Among them, in step 201, the storage device can be a solid-state drive, including a common solid-state drive, a removable solid-state drive, or other storage devices similar to a solid-state drive. The historical operation information of the storage device includes all operation records since the storage device was initially used, and corresponding log data is generated according to these operation records. For example, when a new file is created on the hard disk, a creation log of the file is generated, or when a certain file on the hard disk is moved, a movement log of the file is generated.
[0044] Since the file system index is constructed according to the log data, the file system index is equivalent to the log data on the hard disk, so that the file system index can be used as a complete file operating system. Refer to Figure 3, in one embodiment, the file system index can be a tree - like data structure, making the architecture of the entire file system index clearer. The file system index can have multiple file nodes. For example, file node A represents disk partition 1, file nodes B1 and B2 represent folder 1 and folder 2 under disk partition 1, and file nodes C1, C2, and C3 respectively represent file 1, file 2, and file 3 in folder 1. Among them, each file node can store metadata information of the file, the file name of the directory entry, the target file of the soft link, and other metadata information. For example, file node B1 stores the file name in folder 1, and file node C1 stores the metadata information of file 1, and so on.
[0045] Step 202: Determine the target file according to the user's file operation instruction, find the target file according to the file system index, and perform an operation corresponding to the file operation instruction on the target file.
[0046] Among them, in step 202, the operation performed on the target file can be creation, moving, modification, deletion, etc. For example, when moving a certain file from folder 1 to folder 2, add this move record to the log data and correspondingly modify the metadata information of this file in the file node of the file system index.
[0047] In the above steps 201 to 202, by generating log data according to the historical operation records, the log data can be used to record the user's operations, and the file system index of the storage device can be constructed in memory according to the log data. In this way, the file system index can form a complete file operating system, and the operations on the file can be carried out through the file system index. Therefore, the metadata information of the file does not need to be stored in the data area of the storage device, and the operation on the file does not involve in - place modification of the metadata information of the storage device, avoiding multiple erasures of the storage device and reducing the wear of the storage device; at the same time, since the file system index is located in memory, the access speed is fast, which is beneficial to improving the efficiency of file operations.
[0048] Refer to Figure 4 , in one embodiment, in the above step 201, generating the corresponding log data in the storage device according to the historical operation information of the storage device can specifically include the following steps 401 to 402:
[0049] Step 401: Associate the historical operation information with the same file identifier.
[0050] Among them, in step 401, there can be multiple historical operation information of the storage device, and each historical operation information corresponds to a file identifier. The file identifier is used to uniquely identify a certain target file. For example, it can be a file number, etc. The specific file number can be set according to the actual situation and can be a combination of one or more of numbers and characters. For example, when there are multiple historical operation records for a certain target file, they are respectively recorded through multiple log blocks, and each log block will be associated through a unique file number. For example, log block one and log block two are associated through file number A100.
[0051] Step 402: Sort the historical operation information in chronological order of operation time to generate corresponding log data in the storage device.
[0052] Among them, in step 402, when sorting the historical operation information in chronological order of operation time, it can be identified by using the method of global ID. For example, a global ID can be assigned to the corresponding log block according to the operation time corresponding to the historical operation information. The global ID can be natural numbers such as 1, 2, 3, etc. Therefore, when sorting the historical operation information in chronological order of operation time, it can be sorted according to the size order of the global ID. Combining with the fact that the historical operation information is associated through a unique file identifier in step 501 and then sorting each historical operation information in chronological order of operation time can make the log data in the storage device more tidy and is conducive to improving the efficiency of data reading.
[0053] Refer to Figure 5 In an embodiment, in the above step 502, building a file system index of the storage device in the memory according to the log data specifically may include the following steps 501 to step 502:
[0054] Step 501: Confirm the path information of the files in the data block and the metadata information corresponding to the files in the data block according to the log data;
[0055] Among them, in step 501, the path information is the mapping data between multiple file nodes, such as disk partition one / folder one / file one. Confirming the path information and metadata information according to the log data. For example, in an embodiment, the log data includes: creating folder one in disk partition one and creating file one in the folder. Then, multiple file nodes can be confirmed according to this log data: disk partition one, folder one, and file one. And the path information between them can be confirmed: disk partition one / folder one / file one. At the same time, since the log data is generated from historical operation information, the metadata information of the files in the data block can also be confirmed.
[0056] Step 502: Build a file system index of the storage device according to the path information and metadata information.
[0057] Among them, in step 502, a tree - like data structure can be formed first according to the path information, and the corresponding metadata information can be stored in the corresponding file node, so as to form the file system index of the storage device. In addition, in other embodiments, the file system index is not limited to a tree - like data structure, for example, it can also be a tabular data structure, etc.
[0058] In one embodiment, based on the above - mentioned file system index, various types of operations can be performed on the target file in the hard disk, such as reading, modifying, deleting, or moving, etc. First, the target file needs to be created. Specifically, find the directory entry corresponding to the target file in the file system index, and add the target file under the directory entry. Among them, the directory entry corresponding to the target file can be the folder where the target file is located. For example, if the user needs to add a file one in folder one, then add the file one in the file node corresponding to folder one in the file system index. Then, write the target file to the corresponding data page in the storage device, add the creation record of the target file in the log data, and update the metadata information corresponding to the target file in the file system index.
[0059] Among them, adding the creation record of the target file in the log data not only describes the specific operation, but also records the corresponding metadata information of the target file. For example, referring to Figure 6 , the creation record of the target file can involve multiple log blocks, including "create file", "used data block 5", etc.
[0060] The file operation method of the embodiment of the present invention will be described below in combination with different operation processes.
[0061] Reading a file
[0062] In one embodiment, the file operation instruction is a file reading instruction. Referring to Figure 7 , in step 202 above, find the target file according to the file system index, and perform the operation corresponding to the file operation instruction on the target file. Specifically, it can include the following steps 701 to step 702:
[0063] Step 701: Determine the file node where the target file is located in the file system index, and read the metadata information corresponding to the target file from the file node;
[0064] Step 702: Confirm the location of the target file in the storage device according to the metadata information corresponding to the target file, and read the target file from the storage device;
[0065] Among them, in step 702, the location of the target file in the storage device is confirmed according to the metadata information corresponding to the target file, which may be to confirm the data block information or data page information of the target file in the storage device according to the metadata information of the target file, and then read the target file from the corresponding data block or data page of the storage device.
[0066] Step 703: Update the log data.
[0067] Among them, in step 703, after reading the target file, the log data corresponding to the target file is also updated to ensure that the log data is up-to-date when rebuilding the file system index after a power failure and restart. For example, a read record is added to the log data of the target file, and the read record may include the file number read, the read time, etc.
[0068] Modify the file
[0069] In one embodiment, the file operation instruction is a file modification instruction. In one case, new data is appended and written to the target file. Correspondingly, referring to Figure 8 , in step 202 above, the target file is found according to the file system index, and the operation corresponding to the file operation instruction is executed on the target file. Specifically, it may also include the following steps 801 to step 803:
[0070] Step 801: Determine the file node where the target file is located in the file system index, and read the metadata information corresponding to the target file from the file node;
[0071] Step 802: Confirm the data page where the target file is located according to the metadata information corresponding to the target file, and write the new data to the data page where the target file is located;
[0072] Among them, in step 802, the new data is the data that needs to be appended and written to the target file, and the new data can be written to the data page where the target file originally was in sequence. If the data page where the target file originally was is full, the new data is written to a new data page, and then the metadata information of the target file is updated.
[0073] Step 803: Update the log data and the metadata information corresponding to the target file in the file system index.
[0074] Among them, in step 803, after appending the new data to the target file, the log data corresponding to the target file is also updated to ensure that the log data is up-to-date when rebuilding the file system index after a power failure and restart. For example, a modification record is added to the log data of the target file. The modification record may include the file number of the target file, the modification time, the data block where the new data is located, the data page where the new data is located, etc. Also, the metadata information corresponding to the target file in the file node is updated to keep the file system index in sync with the storage device.
[0075] In one embodiment, another case of modifying a file is to modify the data in the target file. Accordingly, referring to Figure 9 , in step 202 above, the target file is found according to the file system index, and the operation corresponding to the file operation instruction is performed on the target file. Specifically, it may also include the following steps 901 to step 903:
[0076] Step 901: Determine the file node where the target file is located in the file system index, and read the metadata information corresponding to the target file from the file node;
[0077] Step 902: Confirm the data page where the target file is located according to the metadata information corresponding to the target file, merge the modified data with the target file and write it into a new data page, and mark the data page where the target file was originally located as invalid;
[0078] Among them, in step 902, the modified data is the data that needs to be modified and written into the target file. After merging the modified data with the target file, it is written into a new data page. For example, file one includes data ABCD, and now it is necessary to change the data D in file one to data E. Then, the data ABC in file one is merged with data E and written into a new data page, and the data page where the original data ABCD in file one was located is marked as invalid, and the metadata information of the target file is updated. Among them, when marking a data page as invalid, the data in the data page is not immediately erased, which is convenient for subsequent data recovery and other operations.
[0079] Step 903: Update the log data and the metadata information corresponding to the target file in the file system index.
[0080] Among them, after writing the modified data to the target file in step 903, the log data corresponding to the target file is also updated, so that when the file system index is rebuilt after a power failure and restart, the log data is ensured to be up-to-date. For example, a modification record is added to the log data of the target file. The modification record may include the file number of the target file, the modification time, the data block where the modified target file is located, the data page where the modified target file is located, etc. Also, the metadata information corresponding to the target file in the file node is updated to keep the file system index in sync with the storage device.
[0081] In this way, the modification of the target file is recorded through the log data, which neither involves in-place modification of the file metadata information nor in-place modification of the data of the target file itself, thus reducing the wear of the storage device.
[0082] Delete file
[0083] In one embodiment, the file operation instruction is a delete file instruction. Referring to Figure 10 , in step 202 above, the target file is found according to the file system index, and the operation corresponding to the file operation instruction is performed on the target file, which may specifically include the following steps 1001 to step 1003:
[0084] Step 1001: Determine the data block where the target file is located in the file system index, and read the metadata information corresponding to the target file from the data block;
[0085] Step 1002: Confirm the data page where the target file is located according to the metadata information corresponding to the target file, delete the file node where the target file is located, and mark the data page where the target file is located as invalid;
[0086] Among them, in step 1002, when marking the data page where the target file is located as invalid, the data of this data page will not be erased immediately, which is convenient for subsequent data recovery and other operations.
[0087] Step 1003: Update the log data.
[0088] Among them, in step 1003, after deleting the target file, the log data corresponding to the target file is also updated, so that when the file system index is rebuilt after a power failure and restart, the log data is ensured to be up-to-date. For example, a deletion record is added to the log data of the target file. The deletion record may include the deleted file number, the deletion time, etc.
[0089] Move file
[0090] In one embodiment, the file operation instruction is a move file instruction. Referring to Figure 11In the above step 202, the target file is searched according to the file system index, and the operation corresponding to the file operation instruction is performed on the target file. Specifically, the following steps 1101 to 1103 may be included:
[0091] Step 1101: Determine the file node where the target file is located in the file system index;
[0092] Step 1102: Modify the file node where the target file is located;
[0093] In step 1102, the file node where the target file is located is modified. For example, if the target file is originally located in folder one and now needs to be moved to folder two, the file node where the target file is located is modified to folder two.
[0094] Step 1103: Update log data.
[0095] Among them, in step 1103, after the target file is moved, the log data corresponding to the target file is also updated so that when the file system index is rebuilt after power failure and restart, the log data is guaranteed to be the latest. For example, a move record is added to the log data of the target file. The move record may include the file number of the move, the move time, the file nodes before and after the target file is moved, etc.
[0096] Since the hard disk space is limited, continuously writing data to the log area and data area of the hard disk will cause the log area and data area to be full. Therefore, in one embodiment, the above file operation method also includes recycling log data in the log area and data blocks in the data area.
[0097] Among them, the log data can be recycled in two ways: when the target file is deleted, the log data recording the deletion of the target file is deleted; another way is to merge the log data corresponding to the same target file. Figure 12 , 6 log data are shown as an example, and the global ID increases from 1 to 6. A smaller global ID indicates that the log data was generated earlier, and a larger global ID indicates that the log data was generated later. These 6 log data involve 3 files respectively, and the corresponding file numbers are A100, A101, and A102 respectively. The log data with global ID 1 and global ID 6 can be deleted because the files corresponding to the log data with global ID 6 have been deleted. The log data with global ID 2 and global ID 4 can be merged because they all correspond to the same file. Similarly, the log data with global ID 3 and global ID 5 can also be merged. For data writing and data modification of the same file, after the corresponding log data are merged, just record the data blocks used by the final file.
[0098] In one embodiment, the triggering condition for recycling log data can be that the capacity of the log data reaches a first threshold. Here, the first threshold can be freely set according to the actual situation, such as the proportion of the used capacity, for example, 80%, 85% or 90%, etc. Of course, it can also be a specific capacity value, and the embodiments of the present invention do not make any limitations in this regard.
[0099] In one embodiment, the number of log areas can be more than two. When any one of the log areas is filled up, it can also trigger the recycling of log data.
[0100] It can be understood that the above two ways of recycling log data can be executed alternatively or both, and the embodiments of the present invention do not make any limitations in this regard.
[0101] Among them, for recycling data blocks, one way is that when all the data pages in a data block are marked as invalid, the data block is erased completely; another way is to sort all the data blocks in the storage device in descending order according to the proportion of the remaining valid data pages, merge several data blocks ranked at the end and write them into a new data block, and then erase these several data blocks ranked at the end completely. For example, referring to Figure 13 , there are a total of 8 data blocks, and each data block includes multiple data pages. The white data pages marked with a dashed box indicate unused (clean data pages), the black data pages indicate that the corresponding files have been deleted, and the white data pages marked with a solid line indicate that the corresponding files are still valid. All the data pages in the third data block correspond to deleted files, so the data block is directly erased and recycled. Among the fourth and sixth data blocks, the number of data pages corresponding to deleted files ranks among the top (ranked in descending order by the number), that is, the proportion of their remaining valid data pages ranks at the end. Therefore, the valid data pages of the fourth and sixth data blocks are merged and moved to the seventh data block, and then the fourth and sixth data blocks are erased completely.
[0102] In one embodiment, the triggering condition for recycling data blocks can be that the proportion of clean data blocks in the storage device is less than a second threshold. Here, the second threshold can be freely set according to the actual situation, and the embodiments of the present invention do not make any limitations in this regard.
[0103] The following uses a practical example to illustrate the file operation method provided by the embodiments of the present invention.
[0104] Referring to Figure 14 , the file operation method provided by the embodiments of the present invention can specifically include the following steps 1401 to step 1412:
[0105] Step 1401: Mount the file operating system;
[0106] Step 1402: Scan the superblock and the log area;
[0107] Step 1403: Generate a file system index in the form of a tree - like data structure in memory based on the log data in the log area;
[0108] Step 1404: Respond to a file operation instruction. When the file operation instruction is a file read instruction, jump to Step 1405; when the file operation instruction is a file modification instruction, jump to Step 1406;
[0109] Step 1405: Obtain the corresponding file data from the file system index, read the corresponding file from the hard disk, and jump to Step 1404;
[0110] Step 1406: Obtain the corresponding file data from the file system index, modify the corresponding file, and write the modified data to the corresponding data block;
[0111] Step 1407: Determine whether data block recycling is required. If so, jump to Step 1408; otherwise, jump to Step 1409;
[0112] Step 1408: Recycle the corresponding data block and jump to Step 1407;
[0113] Step 1409: Update the corresponding metadata information in the file operating system;
[0114] Step 1410: Update the log data;
[0115] Step 1411: Determine whether log data recycling is required. If so, jump to Step 1412; otherwise, end the process;
[0116] Step 1412: Recycle the corresponding log data and jump to Step 1411.
[0117] In the embodiments of the present invention, by generating log data according to historical operation records, the log data can be used to record user operations, and a file system index of the storage device can be constructed in memory based on the log data. In this way, the file system index can form a complete file operating system, and file operations can be carried out through the file system index. Therefore, the metadata information of the file does not need to be stored in the data area of the storage device, and the file operations do not involve in - place modification of the metadata information of the storage device, avoiding multiple erasures of the storage device and reducing the wear of the storage device. At the same time, since the file system index is located in memory, the access speed is fast, which is beneficial to improving the efficiency of file operations.
[0118] It should also be understood that the various embodiments provided by the embodiments of the present invention can be combined arbitrarily to achieve different technical effects.
[0119] Refer to Figure 15, an embodiment of the present invention further provides a file operating system, including:
[0120] A construction unit 1501, configured to generate corresponding log data in a storage device according to historical operation information of the storage device, and construct a file system index of the storage device in a memory according to the log data;
[0121] An operation unit 1502, configured to determine a target file according to a file operation instruction of a user, find the target file according to the file system index, and perform an operation corresponding to the file operation instruction on the target file.
[0122] The file operating system in the above embodiment and the file operation method in the above embodiment are based on the same inventive concept. Therefore, when the file operating system operates on a file, it does not involve in-place modification of data in the storage device, can avoid multiple erasures of the storage device, and reduce the wear of the storage device.
[0123] Figure 16 FIG. shows an electronic device 1600 provided by an embodiment of the present invention. The electronic device 1600 includes: a memory 1601, a processor 1602, and a computer program stored on the memory 1601 and executable on the processor 1602. When the computer program runs, it is used to execute the above file operation method. Exemplarily, the electronic device 1600 may be a personal computer, a tablet computer, etc.
[0124] The processor 1602 and the memory 1601 may be connected through a bus or other means.
[0125] The memory 1601, as a non-transitory computer-readable storage medium, can be used to store a non-transitory software program and a non-transitory computer-executable program, such as the file operation method described in an embodiment of the present invention. The processor 1602 realizes the above file operation method by running the non-transitory software program and instructions stored in the memory 1601.
[0126] The memory 1601 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system and application programs required for at least one function; the data storage area can store the execution of the above file operation method. In addition, the memory 1601 may include a high-speed random access memory 1601, and may further include a non-transitory memory 1601, such as at least one storage device memory 1601 component, a flash memory device or other non-transitory solid-state storage devices. In some embodiments, the memory 1601 may optionally include a memory 1601 remotely set relative to the processor 1602, and these remote memories 1601 may be connected to the electronic device 1600 through a network. Examples of the above network include but are not limited to the Internet, an enterprise internal network, a local area network, a mobile communication network, and combinations thereof.
[0127] The non-transitory software program and instructions required to implement the above file operation method are stored in the memory 1601. When executed by one or more processors 1602, the above file operation method is executed. For example, the method steps 201 to 202 in Figure 2 are executed, Figure 4 the method steps 401 to 402 in Figure 5 are executed, Figure 7 the method steps 501 to 502 in Figure 8 are executed, Figure 9 the method steps 701 to 703 in Figure 10 are executed, Figure 11 the method steps 801 to 803 in Figure 14 are executed,
[0128] The embodiments of the present invention also provide a computer-readable storage medium storing computer-executable instructions for executing the above file operation method.
[0129] In one embodiment, the computer-readable storage medium stores computer-executable instructions that are executed by one or more control processors. For example, when executed by a processor 1602 in the above electronic device 1600, the above processor 1602 can be made to execute the above file operation method. For example, the method steps 201 to 202 in Figure 2 are executed, Figure 4 the method steps 401 to 402 in Figure 5 are executed, Figure 7 the method steps 501 to 502 in Figure 8 are executed, Figure 9 the method steps 701 to 703 in Figure 10 are executed, Figure 11 the method steps 801 to 803 in Figure 14 are executed,
[0130] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0131] Those of ordinary skill in the art will understand that all or some of the steps and systems disclosed in the above methods can be implemented as software, firmware, hardware, and their appropriate combinations. Some physical components or all physical components can be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or can be implemented as hardware, or can be implemented as an integrated circuit, such as an application specific integrated circuit. Such software can be distributed on a computer-readable medium, which can include a computer storage medium (or non-transitory medium) and a communication medium (or transitory medium). As is well known to those of ordinary skill in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information, such as computer-readable instructions, data structures, program modules, or other data. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic storage devices or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer. In addition, as is well known to those of ordinary skill in the art, communication media typically includes computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transmission mechanism, and can include any information delivery medium.
[0132] The above has specifically described the preferred embodiments of the present invention, but the present invention is not limited to the above embodiments. Those skilled in the art can also make various equivalent deformations or substitutions without departing from the spirit of the present invention, and these equivalent deformations or substitutions are all included within the scope defined by the claims of the present invention.
Claims
1. A file operation method, comprising: Acquire historical operation information of a storage device; wherein, there are multiple historical operation information, each of which corresponds to a file identifier; and the storage device is provided with multiple data blocks; Associating the historical operation information with the same file identifier; sorting the historical operation information in chronological order of operation, and generating corresponding log data in a storage device; confirming path information of the files in the data block and metadata information corresponding to the files in the data block based on the log data; constructing a file system index of the storage device in a memory based on the path information and the metadata information; the historical operation information of the storage device includes all operation records of the storage device since the storage device was initially used; A target file is determined according to a file operation instruction of a user, the target file is searched for according to the file system index, and an operation corresponding to the file operation instruction is performed on the target file.
2. The file operation method according to claim 1, characterized in that: The file operation instruction is a read instruction, the file system index includes a plurality of file nodes, and the file nodes store metadata information. Searching for the target file according to the file system index and performing an operation corresponding to the file operation instruction on the target file include: Determine the file node where the target file is located in the file system index, and read metadata information corresponding to the target file from the file node; Confirming the location of the target file in the storage device according to metadata information corresponding to the target file, and reading the target file from the storage device; The log data is updated.
3. The file operation method according to claim 1, characterized in that: The file operation instruction is a modification instruction, the file system index includes a plurality of file nodes, the file nodes store metadata information, the storage device is provided with a plurality of data pages, searching for the target file according to the file system index, and performing an operation corresponding to the file operation instruction on the target file, including: Determine the file node where the target file is located in the file system index, and read metadata information corresponding to the target file from the file node; Confirming the data page where the target file is located according to the metadata information corresponding to the target file, and writing the newly added data into the data page where the target file is located; The log data and metadata information corresponding to the target file in the file system index are updated.
4. The file operation method according to claim 1, characterized in that: The file operation instruction is a modification instruction, the file system index includes a plurality of file nodes, the file nodes store metadata information, the storage device is provided with a plurality of data pages, searching for the target file according to the file system index, and performing an operation corresponding to the file operation instruction on the target file, including: Determine the file node where the target file is located in the file system index, and read metadata information corresponding to the target file from the file node; confirming the data page where the target file is located according to the metadata information corresponding to the target file, merging the modified data with the target file and writing the result into a new data page, and marking the data page where the target file originally was located as invalid; The log data and metadata information corresponding to the target file in the file system index are updated.
5. The file operation method according to claim 1, characterized in that: The file operation instruction is a delete instruction, the file system index includes multiple file nodes, the file nodes store metadata information, the storage device is provided with multiple data pages, and searching for the target file according to the file system index and performing an operation corresponding to the file operation instruction on the target file include: Determine the file node where the target file is located in the file system index, and read metadata information corresponding to the target file from the file node; confirming the data page where the target file is located according to the metadata information corresponding to the target file, deleting the file node where the target file is located, and marking the data page where the target file is located as invalid; The log data is updated.
6. The file operation method according to claim 1, characterized in that: The file operation instruction is a move instruction, the file system index includes a plurality of file nodes, and searching for the target file according to the file system index and performing an operation corresponding to the file operation instruction on the target file include: Determining the file node where the target file is located in the file system index; Modify the file node where the target file is located; The log data is updated.
7. The file operation method according to claim 1, characterized in that: The method further comprises: When the capacity of the log data reaches a first threshold, the log data is recycled.
8. The file operation method according to claim 7, characterized in that: The recycling of the log data specifically includes at least one of the following: When the target file is deleted, deleting the log data recording the deletion record of the target file; Merge the log data corresponding to the same target file.
9. The file operation method according to claim 1, characterized in that: The storage device is provided with a plurality of data blocks, and the method further comprises: When the proportion of clean data blocks in the storage device is less than a second threshold, the data blocks of the storage device are recycled.
10. The file operation method according to claim 9, characterized in that: The data block includes a plurality of data pages, and the reclaiming of the data block of the storage device includes at least one of the following: When the data of all data pages in a data block are marked as invalid, the data block is erased; All data blocks in the storage device are sorted in descending order according to the proportion of remaining valid data pages, several data blocks with lower rankings are merged and written into new data blocks, and the several data blocks with lower rankings are erased.
11. A file operating system, characterized in that: include: A construction unit is configured to obtain historical operation information of a storage device; wherein the historical operation information includes a plurality of pieces of information, each piece of information corresponding to a file identifier; the storage device is provided with a plurality of data blocks; the historical operation information with the same file identifier is associated; the historical operation information is sorted in chronological order of operation, and corresponding log data is generated in the storage device; path information of the files in the data blocks and metadata information corresponding to the files in the data blocks are confirmed based on the log data; a file system index of the storage device is constructed in a memory based on the path information and the metadata information; the historical operation information of the storage device includes all operation records of the storage device since the storage device was initially used; The operation unit is used to determine a target file according to a file operation instruction of a user, search for the target file according to the file system index, and perform an operation corresponding to the file operation instruction on the target file.
12. An electronic device, characterized in that: The invention comprises at least one processor and a memory for communicating with the at least one processor; the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the file operation method according to any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the file operation method according to any one of claims 1 to 10.
Citation Information
Patent Citations
A distributed file system index method and device based on log merging
CN108984686A
File management method and system, electronic equipment and storage medium
CN110018998A