File processing method and device, storage medium and electronic equipment
By copying file index data from the F2FS file system to the inode structure of the target file, the problems of storage media waste and slow processing speed are solved, achieving storage space saving and processing speed improvement.
Patent Information
- Application Number
- CN202410784189.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-17
- Publication Date
- 2025-12-19
AI Technical Summary
Existing file copying methods result in wasted storage space and reduced processing speed of the F2FS file system.
By obtaining the inode structures of the source and target files in the F2FS file system, copying the file index data to the index area of the target file, making the data block addresses of the target file and the source file index consistent, and then retrieving the data of the target file from the data block of the source file index.
It avoids data duplication in the storage medium, saves storage space, and significantly improves the file processing speed of the F2FS file system.
Smart Images

Figure CN121166624A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, specifically to a file processing method, apparatus, storage medium, and electronic device. Background Technology
[0002] Flash memory is a type of non-volatile storage that erases data in blocks and rewrites it at the byte level. F2FS (Flash Friendly File System) is a journal-tracking file system specifically designed for flash memory devices.
[0003] Currently, in the F2FS file system, when a file needs to be copied, the data of the source file is copied to the new file. That is, the data content in the data block indexed by the source file is copied to the new data block indexed by the new file, and the new data block is written to the storage medium.
[0004] However, since the data blocks of the source file index have also been written to the storage medium, this copying method will cause the data content in the storage medium to be duplicated, wasting the space of the storage medium. The degree of waste will increase as the file size increases, and it will also affect the file processing speed in the F2FS file system. Summary of the Invention
[0005] In view of this, this application provides a file processing method, apparatus, storage medium and electronic device, the main purpose of which is to improve the technical problem that the file copying method in the prior art causes data content duplication in the storage medium, wastes storage medium space and affects the file processing speed in the F2FS file system.
[0006] Firstly, this application provides a document processing method, including:
[0007] In response to a file copy command, the first inode structure corresponding to the source file in the F2FS file system is obtained, and the second inode structure corresponding to the target file in the F2FS file system is obtained, wherein the target file is a new file obtained by copying the source file;
[0008] The file index data of the source file is obtained by querying the array elements in the first inode structure. The file index data includes the address of the data block of the source file index.
[0009] The file index data is copied to the index area in the second inode structure, so that the address of the data block of the target file index is the same as the address of the data block of the source file index, and the data of the target file is obtained from the data block of the source file index;
[0010] In response to a processing instruction for a file to be processed, the file to be processed is processed based on the first inode structure or the second inode structure, wherein the file to be processed includes the source file or the target file.
[0011] Secondly, this application provides a document processing apparatus, comprising:
[0012] The acquisition module is configured to, in response to a file copy command, acquire the first inode structure corresponding to the source file in the F2FS file system, and acquire the second inode structure corresponding to the target file in the F2FS file system, wherein the target file is a new file obtained by copying the source file;
[0013] The query module is configured to obtain the file index data of the source file by querying array elements in the first inode structure, wherein the file index data includes the address of the data block indexed by the source file;
[0014] The copy module is configured to copy the file index data to the index region in the second inode structure, such that the address of the data block of the target file index is the same as the address of the data block of the source file index, and the data of the target file is obtained from the data block of the source file index;
[0015] The processing module is configured to process the file to be processed based on the first inode structure or the second inode structure in response to a processing instruction for the file to be processed, wherein the file to be processed includes the source file or the target file.
[0016] Thirdly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.
[0017] Fourthly, this application provides an electronic device including a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, wherein the processor executes the computer program to implement the method described in the first aspect.
[0018] By means of the above technical solution, this application provides a file processing method, apparatus, storage medium, and electronic device. Specifically, in response to a file copy instruction, the method first obtains the first inode structure corresponding to the source file in the F2FS file system and the second inode structure corresponding to the target file in the F2FS file system, wherein the target file is a new file obtained by copying the source file; then, the method obtains the file index data of the source file by querying the array elements in the first inode structure, wherein the file index data includes the address of the data block indexed by the source file; then, the file index data is copied to the index area in the second inode structure, so that the address of the data block indexed by the target file is consistent with the address of the data block indexed by the source file, wherein the data of the target file is obtained from the data block indexed by the source file; in response to a processing instruction for a file to be processed, the method processes the file to be processed based on the first inode structure or the second inode structure, wherein the file to be processed includes the source file or the target file. By applying the technical solution of this application, the inode structures corresponding to the source and target files in the F2FS file system are first obtained. Then, based on the inode structures, the file index data of the source file is copied to the target file, making the addresses of the indexed data blocks of the target and source files consistent, thus completing the copying of the file in the F2FS file system. File processing is then performed according to file processing instructions. Compared with existing technologies, this application avoids data duplication in the storage medium by ensuring that the target and source files index the same data block address, thereby saving storage space and significantly improving the file processing speed in the F2FS file system.
[0019] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, specific embodiments of this application are given below. Attached Figure Description
[0020] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0021] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 A flowchart illustrating a document processing method provided in an embodiment of this application is shown.
[0023] Figure 2 A schematic diagram illustrating an application example provided in an embodiment of this application is shown;
[0024] Figure 3 A flowchart illustrating another file processing method provided in an embodiment of this application is shown;
[0025] Figure 4 A schematic diagram illustrating an application example provided in an embodiment of this application is shown;
[0026] Figure 5 A schematic diagram illustrating an application example provided in an embodiment of this application is shown;
[0027] Figure 6 A schematic diagram illustrating an application example provided in an embodiment of this application is shown;
[0028] Figure 7 A schematic diagram illustrating an application example provided in an embodiment of this application is shown;
[0029] Figure 8 A schematic diagram of the structure of a document processing apparatus provided in an embodiment of this application is shown. Detailed Implementation
[0030] To better understand the above-mentioned objectives, features, and advantages of this application, the solution of this application will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described in these embodiments can be combined with each other.
[0031] To address the technical issues of data duplication in current file copying technologies, which wastes storage space and slows down file processing in F2FS file systems, this embodiment provides a file processing method, such as... Figure 1 As shown, the method includes:
[0032] Step 101: In response to the file copy command, obtain the first inode structure corresponding to the source file in the F2FS file system, and obtain the second inode structure corresponding to the target file in the F2FS file system.
[0033] The target file is the new file obtained by copying the source file. The inode structure is a crucial data structure in the F2FS file system, storing metadata related to files or directories. For example, an inode structure can contain fields such as i_name, i_pino, i_size, i_cino, and i_addr. The inode structure allows for efficient management of F2FS file system metadata.
[0034] Step 102: Obtain the file index data of the source file by querying the array elements in the first inode structure.
[0035] The file index data includes the addresses of the data blocks in the source file index, which can help manage file creation, copying, deletion, modification, and reading operations in the F2FS file system.
[0036] Step 103: Copy the file index data to the index area in the second inode structure so that the address of the data block of the target file index is consistent with the address of the data block of the source file index.
[0037] The data in the target file can be obtained from the data blocks indexed in the source file.
[0038] In some examples, indexing data blocks at the same address as the source file in the target file can significantly improve file copying speed, and the larger the file size, the more significant the speed improvement. It also reduces the writing of duplicate data blocks, extending the lifespan of the storage medium.
[0039] like Figure 2 As shown, copying a file requires first allocating two new free data blocks, block100 and block101. Then, the content of block1 indexed by the source file file1 is copied to block100, and the content of block2 is copied to block101. This copying method copies all the data from the source file to the new file, resulting in duplicate data. This duplicate data writing reduces the lifespan of the storage medium. Furthermore, blocks100 and block101 indexed by the new file file2 also need to be written to the storage medium, wasting storage space. This waste increases with the size of the file.
[0040] Step 104: In response to the processing instruction for the file to be processed, process the file to be processed based on the first inode structure or the second inode structure. The file to be processed includes the source file or the target file.
[0041] For example, after copying a file in the F2FS file system, the source or target file can be processed according to processing instructions to achieve file deletion, modification, and reading functions. Applying the file processing method in this embodiment can greatly improve the speed of file deletion, modification, and reading in the F2FS file system.
[0042] This embodiment first responds to a file copy command by obtaining the first inode structure corresponding to the source file in the F2FS file system and the second inode structure corresponding to the target file in the F2FS file system, wherein the target file is the new file obtained by copying the source file. Then, it obtains the file index data of the source file from the first inode structure by querying array elements, wherein the file index data includes the address of the data block indexed by the source file. Next, it copies the file index data to the index area in the second inode structure, making the address of the data block indexed by the target file consistent with the address of the data block indexed by the source file, wherein the data of the target file is obtained from the data block indexed by the source file. Responding to a processing command for a file to be processed, it processes the file to be processed based on the first or second inode structure, wherein the file to be processed includes either the source file or the target file. Compared with existing technologies, this embodiment avoids data duplication in the storage medium by making the target file and the source file index the same data block, thereby saving storage medium space and greatly improving the file processing speed in the F2FS file system.
[0043] Furthermore, as a refinement and extension of the above embodiments, in order to fully illustrate the specific implementation process of the method in this embodiment, this embodiment provides the following: Figure 3 The specific method shown includes:
[0044] Step 201: In response to the file copy command, obtain the first inode structure corresponding to the source file in the F2FS file system, and obtain the second inode structure corresponding to the target file in the F2FS file system.
[0045] The target file is the new file obtained by copying the source file. For example... Figure 4 As shown, file1 is the source file and file2 is the target file. To copy file1 from directory a to directory b, a new F2FS inode structure needs to be allocated first, which is the second inode structure corresponding to file2. Most of the information in the second inode structure comes from the first inode structure corresponding to file1. For example, the information in the i_size field of the second inode structure comes from the i_size field of the first inode structure of file1. Other special fields of the second inode structure can be modified as needed. For example, the i_pino field of the second inode structure can be filled with the file number of the parent directory, i.e., i_pino = 2, and the i_name field needs to be filled with file2.
[0046] Optionally, the method in this embodiment further includes adding an inode number to the first inode structure and the second inode structure respectively, wherein the inode number is used to identify whether it is a file obtained by copying.
[0047] In some examples, without changing the F2FS inode structure, the space of the original i_addr[0] can be used as the i_cino field and filled with the file inode number of the second inode structure, i.e., i_cino = 10. For example, if a file is not obtained by copying, its inode number in the i_cino field is 0; if another file is obtained by copying, its inode number in the i_cino field can be filled with 10. Therefore, it is possible to determine whether a file is obtained by copying by the inode number of the i_cino field, and the corresponding source file can be found by the inode number of the target file's i_cino field, and conversely, the corresponding target file can be found by the inode number of the source file's i_cino field.
[0048] Step 202: Obtain the first array element in the first inode structure. The first array element stores the address index value of the data block of the source file.
[0049] For example, such as Figure 4 As shown, the first array element in the first inode structure can be i_addr[1], i_addr[2], i_addr[3], etc., where i_addr is an array used to store memory addresses, and i_addr[1] can be the address value of the first storage location.
[0050] Step 203: Determine the second array element in the second inode structure that corresponds to the first array element.
[0051] The identifier of the second array element in the second inode structure is the same as the identifier of the first array element in the first inode structure.
[0052] For example, the identifier of an array element can be its name, ID number, and / or position in the inode structure. For instance, the second array element can be i_addr[1], i_addr[2], i_addr[3], etc. in the second inode structure, corresponding one-to-one with the first array element.
[0053] Step 204: Copy the address index value to the second array element.
[0054] For example, such as Figure 4As shown, the index values of i_addr[1] and i_addr[2] in file1 are copied to i_addr[1] and i_addr[2] in file2, so that the block addresses of the storage medium indexed by file2 and file1 are consistent. This realizes that the target file and the source file share the data of the data block in the storage medium without the need to reallocate the data block in the storage medium, reducing the writing of duplicate data blocks and thus improving the service life of the storage medium.
[0055] Optionally, the method in this embodiment further includes: adding a reference count value to the data block corresponding to the address index value in the F2FS file system, wherein the reference count value is used to determine the number of files that reference the data block corresponding to the address index value.
[0056] For example, Figure 4 The Copy Block Info Table (CBIT) in the F2FS file system is a data structure used to record the number of times a data block in the storage medium is referenced by copied files. Within the CBIT area, the corresponding reference count value (count) can be found by indexing the block addresses of block1 and block2. Increasing the reference count value by 1 indicates that the corresponding block address is referenced by two files, meaning the data in that block is shared between the two files. If block1 and block2 are subsequently shared again, the reference count value can be increased further. By dynamically adjusting the reference count value, the F2FS file system can automatically track the usage of data blocks, avoiding memory leaks and achieving effective resource reuse, ensuring efficient and correct use and release of shared resources.
[0057] For example, after the copy is completed, the inode structure of file2 is also written to the storage medium, and the corresponding data in the CP, Segment Info Table (SIT), Node Address Table (NAT), and Segment Summary Area (SSA) are updated during the next checkpoint (CP) data synchronization to ensure that the F2FS file system metadata is written to disk.
[0058] Step 205: In response to the processing instruction for the file to be processed, process the file to be processed based on the first inode structure or the second inode structure. The file to be processed includes the source file or the target file.
[0059] In some examples, the processing instructions for the file to be processed may include: file deletion instructions, file modification instructions, and file read instructions.
[0060] Optionally, the method in this embodiment further includes: in response to a file deletion command, in response to a file deletion command for the file to be processed, obtaining the reference count value of the data block of the index of the file to be processed; if the reference count value of the data block of the index of the file to be processed is greater than a first preset threshold, then reducing the reference count value of the data block of the index of the file to be processed, and deleting the inode structure corresponding to the file to be processed in the F2FS file system; if the reference count value of the data block of the index of the file to be processed is equal to the first preset threshold, then restoring the reference count value of the data block of the index of the file to be processed to its initial state, and deleting the data block of the index of the file to be processed and the inode structure corresponding to the file to be processed in the F2FS file system.
[0061] For example, one can first locate the inode structure of the file to be processed, obtain the file's index entry, and then determine whether the index entry is shared by other files. Figure 5 As shown, i_addr[1] and i_addr[2] of file1 point to block1 and block2, respectively. The corresponding reference count values of block1 and block2 can be found in CBIT. If the reference count value is greater than 1, it means that the block is shared by other files. At this time, it is only necessary to decrease the reference count value. If the reference count value is equal to 1, it means that the block is not shared by other files. At this time, it is necessary to decrement the reference count by 1 to the initial state of 0, and then delete the block. The corresponding bit in the bitmap of the SIT area is cleared to indicate that the block has been deleted. The block can be used as a free block later. Then delete the inode structure of file1. When the checkpoint data synchronization is performed next time, update the corresponding data in the CP, SIT, NAT and SSA areas to ensure that the F2FS file system metadata is written to disk.
[0062] Optionally, the method in this embodiment further includes: in response to a file modification instruction for the file to be processed, determining a first data block corresponding to the data to be modified in the file to be processed, and creating a second data block for storing the corresponding modified data; for the inode structure corresponding to the file to be processed in the F2FS file system, changing the first data block indexed by the file to be processed to the second data block indexed, and increasing the reference count value of the second data block.
[0063] For example, you can first find the index of the block corresponding to the data that needs to be modified in file2, such as... Figure 6 The i_addr[2] index contains block2. Then, a new free block is allocated, such as... Figure 6Block 3 in file2 is used to store the modified data. The index entry of i_addr[2] in the inode structure of file2 is updated to the data block address of block 3, and the reference count of block 3 is incremented.
[0064] Further optionally, the method in this embodiment further includes: obtaining the reference count value of the first data block; if the reference count value of the first data block is greater than a second preset threshold, then reducing the reference count value of the first data block; if the reference count value of the first data block is equal to the second preset threshold, then restoring the reference count value of the first data block to its initial state and deleting the first data block.
[0065] For example, find the reference count value for block2 in CBIT, then decrease the reference count by 1. If the reference count for block2 is 0, it means no file references this data block, so block2 can be deleted. If the reference count for block2 is 2, it means two files still reference it, so block2 does not need to be deleted. Find the reference count for block3 in CBIT, then increase the reference count value to 1, indicating that one file references this block. After modification, write the inode structure of file2 to the storage medium, and update the corresponding data in the CP, SIT, NAT, and SSA areas during the next checkpoint data synchronization to ensure that the F2FS file system metadata is written to disk.
[0066] Optionally, the method in this embodiment further includes: in response to a file read instruction for the file to be processed, obtaining the target inode structure corresponding to the file to be processed in the F2FS file system, and identifying the file to be processed based on the inode number added to the target inode structure; if the file to be processed is identified as a target file, determining whether there is a data page corresponding to the target data block to be read in the radix tree of the source file, wherein the radix tree is used to locate the storage location of the data in the file; when there is a data page corresponding to the target data block in the radix tree of the source file, copying the data page corresponding to the target data block to the radix tree of the target file, and reading data based on the data page in the radix tree of the target file.
[0067] In some examples, the inode number of the file to be processed can be used to identify whether the file was obtained by copying. For example, reading the inode structure of file2 in directory b, and finding that i_cino = 10 indicates that the file was obtained by copying, the source file corresponding to that file can be found in the F2FS file system, which is file1 in this example.
[0068] For example, such as Figure 7 As shown, a radix tree is an efficient data structure mainly used to achieve fast lookup of key-value pairs. By merging paths with the same prefix, the depth of the tree is reduced, thereby reducing the use of storage space and improving the query speed. We can try to find the data page corresponding to the i_addr[1] index in the Radix tree of file1. If it can be found, the page is referenced and added to the Radix tree of file2. Subsequent readings of i_addr[1] of file2 can be directly obtained from the Radix tree of file2 without reading the medium block1 again. This reduces the number of times the target file directly reads the shared data block from the storage medium, saves reading time, and improves the reading speed of the target file.
[0069] Alternatively, after identifying the file to be processed based on the inode number added to the target inode structure, if the file to be processed is identified as a source file, the corresponding data block data in the storage medium is read through the address of the data block indexed by the source file; the read data block data is saved into the data page in the radix tree of the source file; and data is read based on the data page in the radix tree of the source file.
[0070] For example, when reading file1 in directory a, first read the inode structure of file1. If the file to be processed is identified as the source file based on i_cino=0, then the data of block1 in the storage medium is read into the data page page1 in the running memory through the index entries of i_addr[1] and i_addr[2], and page1 is inserted into the Radix_tree corresponding to file1. Radix_tree is a trie-based data structure used in the F2FS file system to maintain the cache structure of each file in the running memory after reading the file data. Then the same operation is performed on block2, reading the data of block2 in the storage medium into the data page page2 in the running memory, and inserting page2 into the Radix_tree corresponding to file1, and so on.
[0071] Optionally, the determination of whether a data page corresponding to the target data block to be read exists in the radix tree of the source file includes: if the reference count value of the target data block is greater than a third preset threshold, and the array elements of the corresponding index addresses of the target data block in the first inode structure and the second inode structure are the same, then the determination of whether a data page corresponding to the target data block exists in the radix tree of the source file.
[0072] For example, first read the i_addr[1] index of the inode structure of file2 and find that it is block1. Then find the corresponding reference count value in the CBIT area. If the reference count value is greater than 1 and the i_addr[1] index of the inode structure of the source file is also equal to block1, then it means that file1 and file2 share the data corresponding to block1. Then find the data page corresponding to block1 in the radix tree of the source file.
[0073] Optionally, the method in this embodiment further includes: if the reference count value of the target data block is equal to a third preset threshold, then reading the corresponding data block data in the storage medium through the address of the target data block; saving the read data block data into a data page in the radix tree of the target file; and reading data based on the data page in the radix tree of the target file.
[0074] For example, first read the i_addr[2] index item of the inode structure of file2 as block3, then find the corresponding reference count value of 1 in the CBIT area, which means that only the file to be processed references this block. Then, it is necessary to read the data of block3 from the storage medium into page3 of the running memory and insert page3 into the Radix_tree corresponding to file2.
[0075] Compared to existing technologies, when copying files using the method in this embodiment, only the file's metadata inode structure needs to be allocated. The target file's data blocks are shared with the source file, eliminating the need to allocate new free data blocks. When deleting a file, if the file's data blocks are shared with other files, only the reference count of the data blocks needs to be reduced, without deleting the data blocks. When modifying a file, only the file's index entries need to be modified so that the file index contains the data blocks containing the modified content; other shared file data remains unchanged. When reading a file, the cache of the source file's data blocks in memory can be utilized, reducing the need to read shared data blocks from the storage medium. By ensuring that the target file and source file index the same data block address, data duplication in the storage medium is avoided, thus saving storage space and significantly improving the file processing speed in the F2FS file system.
[0076] Furthermore, as Figure 1 To illustrate the specific implementation of the method shown, this embodiment provides a file processing device, such as... Figure 8 As shown, the device includes: an acquisition module 31, a query module 32, a copy module 33, and a processing module 34.
[0077] The acquisition module 31 is configured to, in response to a file copy command, acquire the first inode structure corresponding to the source file in the F2FS file system, and acquire the second inode structure corresponding to the target file in the F2FS file system, wherein the target file is a new file obtained by copying the source file;
[0078] The query module 32 is configured to obtain the file index data of the source file by querying array elements in the first inode structure, wherein the file index data includes the address of the data block of the source file index;
[0079] The copy module 33 is configured to copy the file index data to the index area in the second inode structure, such that the address of the data block of the target file index is the same as the address of the data block of the source file index, and the data of the target file is obtained from the data block of the source file index.
[0080] The processing module 34 is configured to process the file to be processed based on the first inode structure or the second inode structure in response to a processing instruction for the file to be processed, wherein the file to be processed includes the source file or the target file.
[0081] In some examples, module 31 is specifically configured to add inode numbers to the first inode structure and the second inode structure, respectively, the inode numbers being used to identify whether the file is obtained by copying.
[0082] In some examples, the query module 32 is specifically configured to obtain a first array element in the first inode structure, wherein the first array element stores the address index value of the data block of the source file; correspondingly, the copy module 33 is specifically configured to determine a second array element in the second inode structure that corresponds to the first array element, wherein the identifier of the second array element in the second inode structure is the same as the identifier of the first array element in the first inode structure; and copy the address index value into the second array element.
[0083] In some examples, the copy module 33 is further configured to add a reference count value to the data block corresponding to the address index value in the F2FS file system, the reference count value being used to determine the number of files referencing the data block corresponding to the address index value.
[0084] In some examples, processing module 34 is specifically configured to, in response to a file deletion instruction for the file to be processed, obtain the reference count value of the data block of the index of the file to be processed; if the reference count value of the data block of the index of the file to be processed is greater than a first preset threshold, decrease the reference count value of the data block of the index of the file to be processed and delete the inode structure corresponding to the file to be processed in the F2FS file system; if the reference count value of the data block of the index of the file to be processed is equal to the first preset threshold, restore the reference count value of the data block of the index of the file to be processed to the initial state and delete the data block of the index of the file to be processed and the inode structure corresponding to the file to be processed in the F2FS file system.
[0085] In some examples, the processing module 34 is further configured to, in response to a file modification instruction on the file to be processed, determine a first data block corresponding to the data to be modified in the file to be processed, and create a second data block for storing the corresponding modified data; for the inode structure corresponding to the file to be processed in the F2FS file system, change the first data block indexed by the file to be processed to the second data block indexed, and increment the reference count value of the second data block.
[0086] In some examples, the processing module 34 is further configured to obtain the reference count value of the first data block; if the reference count value of the first data block is greater than a second preset threshold, then decrease the reference count value of the first data block; if the reference count value of the first data block is equal to the second preset threshold, then restore the reference count value of the first data block to its initial state and delete the first data block.
[0087] In some examples, the processing module 34 is further configured to, in response to a file read instruction for the file to be processed, obtain the target inode structure corresponding to the file to be processed in the F2FS file system, and identify the file to be processed based on the inode number added to the target inode structure; if the file to be processed is identified as the target file, then in the radix tree of the source file, determine whether there exists a data page corresponding to the target data block to be read in the target file, the radix tree being used to locate the storage location of the data in the file; when the data page corresponding to the target data block exists in the radix tree of the source file, copy the data page corresponding to the target data block to the radix tree of the target file, and read the data based on the data page in the radix tree of the target file.
[0088] In some examples, the processing module 34 is further configured to, if the file to be processed is identified as the source file, read the corresponding data block data in the storage medium through the address of the data block indexed by the source file; save the read data block data into the data page in the radix tree of the source file; and read data according to the data page in the radix tree of the source file.
[0089] In some examples, the processing module 34 is further configured to determine whether a data page corresponding to the target data block exists in the radix tree of the source file if the reference count value of the target data block is greater than a third preset threshold and the array elements of the corresponding index addresses of the target data block in the first inode structure and the second inode structure are the same.
[0090] In some examples, the processing module 34 is further configured to, if the reference count value of the target data block is equal to the third preset threshold, read the corresponding data block data in the storage medium through the address of the target data block; save the read data block data into the data page in the radix tree of the target file; and read data according to the data page in the radix tree of the target file.
[0091] Based on the above, Figure 1 and Figure 3 Accordingly, this embodiment also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described method. Figure 1 and Figure 3 The method shown.
[0092] Based on this understanding, the technical solution of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as CD-ROM, USB flash drive, mobile hard drive, etc.) and includes several instructions to cause a computer device (such as personal computer, server, or network device, etc.) to execute the methods of various implementation scenarios of this application.
[0093] Based on the above, Figure 1 and Figure 3 The method shown, and Figure 8 To achieve the above objectives, this application also provides an electronic device, which can be configured on the end side of a vehicle (such as a new energy vehicle), as shown in the virtual device embodiment. The device includes a storage medium and a processor; the storage medium is used to store a computer program; the processor is used to execute the computer program to achieve the above-described... Figure 1 and Figure 3 The method shown.
[0094] Optionally, the aforementioned physical devices may also include a user interface, a network interface, a camera, radio frequency (RF) circuitry, sensors, audio circuitry, a Wi-Fi module, etc. The user interface may include a display screen, input units such as a keyboard, etc., and optional user interfaces may also include USB interfaces, card reader interfaces, etc. The network interface may optionally include standard wired interfaces, wireless interfaces (such as Wi-Fi interfaces), etc.
[0095] Those skilled in the art will understand that the physical device structure provided in this embodiment does not constitute a limitation on the physical device, and may include more or fewer components, or combine certain components, or have different component arrangements.
[0096] The storage medium may also include an operating system and a network communication module. The operating system is a program that manages the hardware and software resources of the aforementioned physical device, supporting the operation of information processing programs and other software and / or programs. The network communication module is used to enable communication between the various components within the storage medium, as well as communication with other hardware and software in the information processing physical device.
[0097] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware platforms, or it can be implemented by hardware. By applying the solution of this embodiment, the target file and the source file index the data block at the same address, avoiding the duplication of data content in the storage medium, thereby saving storage medium space, and at the same time greatly improving the file processing speed in the F2FS file system.
[0098] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the term "comprising" or any other variations thereof is 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. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes the element.
[0099] The above are merely specific embodiments of this application, enabling those skilled in the art to understand or implement this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to these embodiments, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A file processing method, characterized in that, include: In response to a file copy command, the first inode structure corresponding to the source file in the F2FS file system is obtained, and the second inode structure corresponding to the target file in the F2FS file system is obtained, wherein the target file is a new file obtained by copying the source file; The file index data of the source file is obtained by querying the array elements in the first inode structure. The file index data includes the address of the data block of the source file index. The file index data is copied to the index area in the second inode structure, so that the address of the data block of the target file index is the same as the address of the data block of the source file index, and the data of the target file is obtained from the data block of the source file index; In response to a processing instruction for a file to be processed, the file to be processed is processed based on the first inode structure or the second inode structure, wherein the file to be processed includes the source file or the target file.
2. The method according to claim 1, characterized in that, The method further includes: An inode number is added to the first inode structure and the second inode structure respectively. The inode number is used to identify whether the file is obtained by copying.
3. The method according to claim 2, characterized in that, The step of obtaining the file index data of the source file by querying array elements in the first inode structure includes: Obtain the first array element in the first inode structure, where the first array element stores the address index value of the data block of the source file; The step of copying the file index data to the index region in the second inode structure includes: Determine the second array element in the second inode structure that corresponds to the first array element, wherein the identifier of the second array element in the second inode structure is the same as the identifier of the first array element in the first inode structure; Copy the address index value into the second array element.
4. The method according to claim 3, characterized in that, The method further includes: In the F2FS file system, a reference count value is added to the data block corresponding to the address index value. The reference count value is used to determine the number of files that reference the data block corresponding to the address index value.
5. The method according to claim 4, characterized in that, The process of processing the file to be processed in response to a processing instruction for the file to be processed, based on the first inode structure or the second inode structure, includes: In response to a file deletion instruction on the file to be processed, the reference count value of the data block of the file index to be processed is obtained; If the reference count of the data block of the file to be processed is greater than the first preset threshold, then the reference count of the data block of the file to be processed is reduced, and the inode structure corresponding to the file to be processed in the F2FS file system is deleted. If the reference count of the data block of the file to be processed is equal to the first preset threshold, then the reference count of the data block of the file to be processed is restored to the initial state, and the data block of the file to be processed and the inode structure corresponding to the file to be processed in the F2FS file system are deleted.
6. The method according to claim 4, characterized in that, The process of processing the file to be processed in response to a processing instruction for the file to be processed, based on the first inode structure or the second inode structure, includes: In response to a file modification instruction on the file to be processed, a first data block corresponding to the data to be modified in the file to be processed is determined, and a second data block is created to store the corresponding modified data. For the inode structure corresponding to the file to be processed in the F2FS file system, the first data block indexed by the file to be processed is changed to the second data block indexed, and the reference count value of the second data block is increased.
7. The method according to claim 6, characterized in that, The method further includes: Obtain the reference count value of the first data block; If the reference count value of the first data block is greater than the second preset threshold, then the reference count value of the first data block is reduced. If the reference count value of the first data block is equal to the second preset threshold, then the reference count value of the first data block is restored to the initial state and the first data block is deleted.
8. The method according to claim 4, characterized in that, The process of processing the file to be processed in response to a processing instruction for the file to be processed, based on the first inode structure or the second inode structure, includes: In response to a file read instruction for the file to be processed, the target inode structure corresponding to the file to be processed in the F2FS file system is obtained, and the file to be processed is identified according to the inode number added to the target inode structure. If the file to be processed is identified as the target file, then in the radix tree of the source file, it is determined whether there is a data page corresponding to the target data block to be read in the target file. The radix tree is used to locate the storage location of the data in the file. When the source file's radix tree contains a data page corresponding to the target data block, the data page corresponding to the target data block is copied into the target file's radix tree, and data is read based on the data page in the target file's radix tree.
9. The method according to claim 8, characterized in that, After identifying the file to be processed based on the inode number added to the target inode structure, the method further includes: If the file to be processed is identified as the source file, the corresponding data block data in the storage medium is read through the address of the data block indexed by the source file. The read data block data is saved into the data page of the radix tree of the source file; Data is read based on the data pages in the radix tree of the source file.
10. The method according to claim 8, characterized in that, In the radix tree of the source file, determining whether a data page corresponding to the target data block to be read exists in the target file includes: If the reference count of the target data block is greater than the third preset threshold, and the array elements of the corresponding index addresses of the target data block in the first inode structure and the second inode structure are the same, then it is determined whether there is a data page corresponding to the target data block in the radix tree of the source file.
11. The method according to claim 10, characterized in that, The method further includes: If the reference count value of the target data block is equal to the third preset threshold, then the corresponding data block data in the storage medium is read through the address of the target data block; The read data block data is saved into the data page of the radix tree of the target file; Data is read based on the data pages in the radix tree of the target file.
12. A document processing device, characterized in that, include: The acquisition module is configured to, in response to a file copy command, acquire the first inode structure corresponding to the source file in the F2FS file system, and acquire the second inode structure corresponding to the target file in the F2FS file system, wherein the target file is a new file obtained by copying the source file; The query module is configured to obtain the file index data of the source file by querying array elements in the first inode structure, wherein the file index data includes the address of the data block indexed by the source file; The copy module is configured to copy the file index data to the index region in the second inode structure, such that the address of the data block of the target file index is the same as the address of the data block of the source file index, and the data of the target file is obtained from the data block of the source file index; The processing module is configured to process the file to be processed based on the first inode structure or the second inode structure in response to a processing instruction for the file to be processed, wherein the file to be processed includes the source file or the target file.
13. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 11.
14. An electronic device comprising a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method of any one of claims 1 to 11.
