File management method and device, electronic equipment and readable storage medium
By introducing the inline tail mode into the file system, the tail block data and metadata information of the file are stored in the file metadata block, solving the problem of waste of disk space in file storage, and achieving more efficient storage resource utilization and fast file reading.
Patent Information
- Application Number
- CN202510493428.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-18
- Publication Date
- 2025-07-22
AI Technical Summary
In the prior art, file systems have a problem of wasting disk space when storing small files, especially in F2FS, where the metadata information of the file occupies a complete block, resulting in inefficient storage.
By introducing the inline tail mode, the file's tail block data and metadata information are stored in the file's metadata block, the file storage structure is optimized, and the data block is allocated separately to store the tail block data.
Improves storage resource utilization efficiency, saves disk space occupied by file storage, and enhances the organization and reading speed of file storage.
Smart Images

Figure CN120353399A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the technical field of file management, and particularly relates to a file management method, apparatus, electronic device, and readable storage medium. Background Art
[0002] With the rapid development of mobile terminal application technology, the demand for file storage has shown an explosive growth. As an important carrier for file data management, the storage efficiency of disk storage directly affects system performance and cost.
[0003] The storage unit of a file system is usually a block of a fixed size. The size of a block is 4K. When storing a file, even if the size of the file is much smaller than the size of a block, it will occupy a complete block for storage, resulting in waste of disk space. Especially in F2FS (Flash - Friendly File System), file metadata information such as file size, modification time and other file attribute information will directly occupy a block. Even if the file is an empty file, a block will be allocated to store metadata information such as file attribute information, corresponding to the file metadata structure, that is, the f2fs_inode structure. In this way, when storing files with a small amount of data such as log files, small configuration files, and text files, a large amount of storage space is often wasted.
[0004] To address the above problems, the inline tail mode is introduced in F2FS. The inline tail mode means that after a file is created, if the amount of written data of the file is less than or equal to 3.5k, this 3.5k data will be written into the file metadata structure, that is, the f2fs_inode, instead of re - allocating a data block to store this 3.5k data, thus saving disk space. However, the inline tail mode can save one data block for files less than or equal to 3.5k. If the file is larger than 3.5k, the inline tail mode is no longer applicable. For example, for a file with a size of 4.1k, when storing this file, two data blocks need to be allocated to store the file data. Among them, one data block stores 4k data, and the other data block stores the remaining 0.1k data. Plus the block occupied by the file metadata information, a total of 3 blocks are required to store a file with a size of 4.1k, resulting in space waste. Summary of the Invention
[0005] The purpose of the embodiments of this application is to provide a file management method, apparatus, electronic device, and readable storage medium, which can save the disk space occupied by file storage.
[0006] In a first aspect, an embodiment of the present application provides a file management method, which includes: obtaining the data volume of the tail block data of a file to be stored; and storing the tail block data and the metadata information of the file to be stored in a file metadata block when the data volume of the tail block data is less than or equal to a first threshold.
[0007] In a second aspect, an embodiment of the present application provides a file management device, which includes: a processing unit configured to obtain the data volume of the tail block data of a file to be stored; and a storage unit configured to store the tail block data and the metadata information of the file to be stored in a file metadata block when the data volume of the tail block data is less than or equal to a first threshold.
[0008] In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor and a memory. The memory stores a program or instruction that can run on the processor. When the program or instruction is executed by the processor, the steps of the file management method as in the first aspect are implemented.
[0009] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of the file management method as in the first aspect are implemented.
[0010] In a fifth aspect, an embodiment of the present application provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor, and the processor is configured to run a program or instruction to implement the steps of the file management method as in the first aspect.
[0011] In a sixth aspect, an embodiment of the present application provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the steps of the file management method as in the first aspect.
[0012] In the file management method provided by the embodiment of the present application, the data volume of the tail block data of a file to be stored is obtained; and when the data volume of the tail block data is less than or equal to a first threshold, the tail block data and the metadata information of the file to be stored are stored in a file metadata block. Through the above file management method, for a file to be stored whose data volume of the tail block data is less than or equal to the first threshold, the tail block data of the file to be stored together with the metadata information is stored in the file metadata block. In this way, a reasonable plan for file storage is achieved, there is no need to separately allocate a data block to store the tail block data, the utilization efficiency of storage resources is improved, and the disk space occupied by file storage is saved. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 is one of the flow diagrams of the file management method provided by the embodiment of the present application;
[0014] Figure 2It is the second flowchart of the file management method provided by the embodiment of the present application;
[0015] Figure 3 It is the third flowchart of the file management method provided by the embodiment of the present application;
[0016] Figure 4 It is the fourth flowchart of the file management method provided by the embodiment of the present application;
[0017] Figure 5 It is the fifth flowchart of the file management method provided by the embodiment of the present application;
[0018] Figure 6 It is the structural block diagram of the file management device provided by the embodiment of the present application;
[0019] Figure 7 It is the structural block diagram of the electronic device provided by the embodiment of the present application;
[0020] Figure 8 It is the hardware structural schematic diagram of the electronic device provided by the embodiment of the present application. Detailed implementation manners
[0021] Next, the technical solutions in the embodiments of the present application will be clearly described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are some, rather than all, of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art belong to the scope protected by the present application.
[0022] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, rather than to describe a specific order or sequence. It should be understood that such terms can be interchanged under appropriate circumstances so that the embodiments of the present application can be implemented in an order different from those illustrated or described herein, and the objects distinguished by "first", "second", etc. are usually of the same category, and the number of objects is not limited. For example, the first object can be one or multiple. In addition, "and / or" in the specification and claims means at least one of the connected objects, and the character " / " generally means an "or" relationship between the associated objects before and after.
[0023] Next, in conjunction with the accompanying drawings, the file management method, device, electronic device, and readable storage medium provided by the embodiments of the present application will be described in detail through specific embodiments and their application scenarios.
[0024] As Figure 1 shown, the embodiment of the present application provides a file management method, and the method may include the following S102 and S104:
[0025] S102: Obtain the data volume of the tail block data of the file to be stored.
[0026] The file management method proposed in the embodiments of this application is executed by an electronic device, which can specifically be intelligent electronic devices such as smart phones, tablet computers, laptop computers, and smart watches, and no specific limitations are made here.
[0027] Among them, the tail block data is the data at the end of the file to be stored that cannot occupy an entire conventional-sized data block such as 4K. For example, if the size of the file to be stored is 4.1K, the tail block data is 0.1K of data.
[0028] In the actual application process, before obtaining the data volume of the tail block data of the file to be stored, it is also necessary to enable the first storage mode, that is, the inline tail mode. The inline tail mode is a mode optimized for file storage in F2FS. In this mode, the data at the end of the file, that is, the tail block data, is directly stored in the f2fs_inode structure of the file, that is, the file metadata block, to avoid a small amount of tail block data occupying an entire conventional-sized data block such as 4K.
[0029] S104: When the data volume of the tail block data is less than or equal to the first threshold, store the tail block data and the metadata information of the file to be stored in the file metadata block.
[0030] Among them, the above-mentioned first threshold can specifically be 3392 bytes.
[0031] Furthermore, the above-mentioned metadata information can specifically include information such as the file attribute information and file extended attribute information of the file to be stored, and no specific limitations are made here.
[0032] Specifically, in the file management method provided in the embodiments of this application, when writing, that is, storing, the file to be stored, if the inline tail mode is enabled for the file to be stored, obtain the data volume of the tail block data of the file to be stored, and determine whether the data volume of the tail block data exceeds the first threshold. When the data volume of the tail block data is less than or equal to the first threshold, based on the tail block data and metadata information of the file to be stored, reorganize the data to be stored of the file to be stored in the inline tail mode, and store the tail block data and metadata information of the file to be stored in the file metadata block together.
[0033] In the file management method provided by the embodiments of the present application, the data volume of the tail block data of the file to be stored is obtained; in the case where the data volume of the tail block data is less than or equal to the first threshold, the tail block data and the metadata information of the file to be stored are stored in the file metadata block. Through the above file management method, for the file to be stored whose data volume of the tail block data is less than or equal to the first threshold, the tail block data of the file to be stored is stored in the file metadata block together with the metadata information. In this way, a reasonable plan for file storage is realized, there is no need to separately allocate a data block to store the tail block data, the utilization efficiency of storage resources is improved, and the disk space occupied by file storage is saved.
[0034] In the embodiments of the present application, the file metadata block includes a second storage area, and the step of storing the tail block data and the metadata information of the file to be stored in the file metadata block may specifically include S106 below:
[0035] S106: Store the tail block data and the metadata information of the file to be stored in the second storage area.
[0036] Among them, the metadata information includes the first file attribute information of the file to be stored, file extension attribute information, index identification information, and data identification information.
[0037] Among them, the first file attribute information includes basic attribute information such as file size, file mode, and file modification time.
[0038] Further, the above file extension attribute information may specifically include data block address information of the file to be stored, extended field information, second file attribute information other than the above basic attribute information, etc., which are not specifically limited herein.
[0039] Further, the above index identification information may specifically be an nid (index identifier) value, and the nid value is used to locate and identify index nodes or data blocks at different levels in a multi-level index structure.
[0040] Further, the data identification information is used to identify the data structure type to which the union structure in the file metadata block belongs.
[0041] It can be understood that the metadata information occupies one block on the disk, namely the file metadata block, for storage. In traditional F2FS, as shown in Table 1 below, the file metadata block corresponds to the f2fs_node structure, and the f2fs_node is composed of two parts. One part is a union structure, which occupies 4072 bytes and contains the f2fs_inode (index node in F2FS) structure, the direct_node (direct node) structure, and the indirect_node (indirect node) structure. The other part is a fixed structure node_footer, which occupies 24 bytes. Among them, for the union structure, only one of the f2fs_inode structure, the direct_node structure, and the indirect_node structure is stored on the disk, and the specific type of the stored structure is determined by the node_footer.
[0042] Table 1: One of the example tables of the file metadata block structure
[0043]
[0044] However, the above storage structure is only used to store the metadata information of the file. Even if the file is an empty file, a block will be allocated to store the metadata information of the file, wasting disk space.
[0045] Based on this, as shown in Table 2 below, the inline tail mode is introduced in F2FS. By modifying the f2fs_inode part, when the amount of data written to the file is less than or equal to 3.5k, the file data is written into the file metadata structure, that is, the f2fs_inode, to save disk space.
[0046] Table 2: Another example table of the file metadata block structure
[0047]
[0048] Specifically, as shown in Table 2, the file metadata block includes a first storage area, a second storage area, a third storage area, and a fourth storage area. Among them, the first storage area is the inode info part, which occupies 360 bytes and is used to store the first file attribute information of the file to be stored; the second storage area is the i_addr array part. The i_addr array includes 923 elements, each element is 4 bytes in size, and the i_addr array occupies a total of 3692 bytes. This part is used to store the file extended attribute information and the tail block data of the file to be stored; the third storage area is the i_nid array part, which occupies 20 bytes and is used to store the index identification information of the file to be stored; the fourth storage area is the node_footer part, which occupies 24 bytes and is used to store the data identification information of the file to be stored. In this way, storing the tail block data and metadata information in different types of partitions enhances the organization and standardization of file storage, improves the storage efficiency when storing files, avoids information chaos, and when reading files, it can quickly locate the required information, improving the speed and accuracy of file reading and access.
[0049] In the above embodiment provided by the present application, the file metadata block includes a second storage area, and the tail block data and the metadata information of the file to be stored are stored in the second storage area. In this way, a reasonable plan for file storage is realized, the utilization efficiency of storage resources is improved, and the disk space occupied by file storage is saved.
[0050] In the embodiment of the present application, before the above S106, the above file management method may specifically further include the following S108. On this basis, the above S106 may specifically include the following S106a:
[0051] S108: Update the storage structure of the second storage area to the first storage structure.
[0052] In the file metadata block structure shown in Table 2, the storage structure of the second storage area is the second storage structure. Under the second storage structure, the second storage area includes a first sub-area, a fourth sub-area, a fifth sub-area, and a sixth sub-area. Among them, the first sub-area is the extra info part, which occupies 36 bytes and is used to supplement the second file attribute information not included in the first storage area; the fourth sub-area is the inline xattr
[50] part, which occupies 200 bytes and is used to store the XATTR (eXtended ATTRibutes) information of the file to be stored; the fifth sub-area is the reserved part, and the sixth sub-area is the addr part. The fifth sub-area and the sixth sub-area together occupy 3456 bytes. These two parts are used to store file data. Among them, the file data is preferentially stored in the addr part, and the reserved part is used for functional expansion or specific data storage requirements within the system.
[0053] Based on the file metadata block structure shown in Table 2, for files smaller than or equal to 3.5k, the storage of file data can save one data block. If the file is larger than 3.5k, it is no longer applicable.
[0054] Therefore, in the file management method provided in the embodiments of the present application, the storage structure of the second storage area is adjusted, and the storage structure of the second storage area is updated to the first storage structure. Under the first storage structure, the data distribution information that can be stored in the second storage area is adjusted, and the second storage area can be used to store the data block address information and the tail block data of the file to be stored.
[0055] Among them, the data distribution information is used to indicate the data distribution rules that can be stored in the file metadata block, that is, the corresponding storage locations of different types of data in the file metadata block.
[0056] Specifically, as shown in Table 3 below, under the first storage structure, the sixth sub-area, that is, the addr part, is divided into a second sub-area and a seventh sub-area. Among them, the second sub-area is the addr
[16] array part. The addr
[16] array includes 16 elements, each element stores a data block address information, and a data block address information occupies 4 bytes. The addr
[16] array together occupies 64 bytes. Based on this, the carrying range of the file size that can be stored in the inline tail mode is 4K to 64K; the seventh sub-area is the inline tail part. The fifth sub-area and the seventh sub-area form a third sub-area. The third sub-area occupies 3392 bytes. The third sub-area is used to store the tail block data of the file to be stored. Based on this, the upper limit of the data volume of the tail block data, that is, the above-mentioned first threshold, is 3392 bytes.
[0057] Among them, the data block address (blkaddr) information is the address information of the data block storing the file data of the file to be stored.
[0058] Table 3: The Third Example Table of File Metadata Block Structure
[0059]
[0060] S106a: Store the tail block data and the metadata information of the file to be stored into the updated second storage area.
[0061] Specifically, in the file management method provided in the embodiments of the present application, when the data volume of the tail block data of the file to be stored is less than or equal to the first threshold, update the storage structure of the second storage area of the file metadata block to the first storage structure, and then, according to the data distribution information corresponding to the second storage area of the first storage structure, store the tail block data and the metadata information of the file to be stored in the updated second storage area, and then synchronously write the file metadata block to the disk. In this way, when storing small data volume files, the inline tail mode is introduced, the storage structure of the file metadata block is adjusted, and the tail block data of the small data volume file is stored in the file metadata block, so that each small data volume file can save one data block for storage.
[0062] In the above embodiments provided by the present application, the storage structure of the second storage area is updated to the first storage structure; the tail block data and the metadata information of the file to be stored are stored into the updated second storage area. In this way, by introducing the inline tail mode and adjusting the storage structure of the file metadata block, a reasonable plan for file storage is realized, the utilization efficiency of storage resources is improved, and the disk space occupied by file storage is saved.
[0063] In the embodiments of the present application, the above S108 may specifically include S108a described below:
[0064] S108a: When the second storage area is in the extended mode, update the storage structure of the second storage area to the first storage structure.
[0065] Among them, the extended mode is the extra mode. The extra mode is an existing mode in F2FS. In F2FS, the extra mode is used to optimize the storage and access methods of F2FS for different types of data.
[0066] Among them, enabling the extra mode means that F2FS enables the composite storage mode, and f2fs_inode can store file indexes and file data. When the extra mode is disabled, f2fs_inode only stores file indexes.
[0067] Specifically, enabling the extra mode means that F2FS enables the inline data attribute and the inline xattr attribute. Among them, the inline data attribute means that for files smaller than or equal to 3.5K, the file data can be directly stored in the f2fs_inode; the inline xattr attribute means that file extended attribute information such as selinux labels can be stored in the f2fs_inode.
[0068] That is to say, since the inline_data attribute and the inline_xattr attribute are enabled simultaneously, the second storage area can store multiple types of data. Among them, when the inline data attribute is enabled, the space occupation of small-data-volume files can be optimized, and the file data of small-number files can be stored in a specific area. When the inline xattr attribute is enabled, file extended attribute information can be stored in a specific area.
[0069] Specifically, the second storage area, that is, the i_addr array, includes multiple elements. In the case where the second storage area is in the extended mode, the extended field information of the file to be stored is stored in the first 9 elements of the i_addr array, that is, i_addr[0] to i_addr[8], and the remaining array space stores the file data and file extended attribute information of the file to be stored; while in the case where the second storage area is not in the extended mode, multiple storage locations in the second storage area are used to store the data block address information of the file to be stored. In this way, by subdividing the storage locations of different types of information, different types of information can be managed more precisely, the adaptability and flexibility of file storage are improved, storage resources are fully utilized, and the space occupied by file storage is reduced.
[0070] In the file management method provided in the embodiment of the present application, in the case where the second storage area is in the extended mode, the structure of the addr part in the second storage area is adjusted, and the storage structure of the second storage area is updated to the first storage structure, so that the second storage area has a position for storing the tail block data of the file, so that the second storage area can store the data block address information and the tail data of the file to be stored.
[0071] In the above embodiment provided by the present application, in the case where the second storage area is in the extended mode, the storage structure of the second storage area is updated to the first storage structure. In this way, the second storage area can store the data block address information and the tail data of the file to be stored, which can fully utilize storage resources and reduce the space occupied by file storage.
[0072] In the embodiment of the present application, the updated second storage area includes a first sub-area, a second sub-area, a third sub-area, and a fourth sub-area. The metadata information of the file to be stored includes the second file attribute information of the file to be stored, the data block address information of the file to be stored, and the file extension attribute information of the file to be stored. On this basis, the above S106a may specifically include the following S110 to S116:
[0073] S110: Store the second file attribute information of the file to be stored in the first sub-area.
[0074] Among them, as shown in Table 3, the updated second storage area, that is, the i_addr array part, includes the first sub-area, that is, the extra info part, and the first sub-area is used to store the second file attribute information of the file to be stored.
[0075] S112: Store the data block address information of the file to be stored in the second sub-area.
[0076] Among them, as shown in Table 3, the updated second storage area, that is, the i_addr array part, includes the second sub-area, that is, the addr
[16] array part, and the second sub-area is used to store the data block address information of the file to be stored.
[0077] S114: Store the tail block data of the file to be stored in the third sub-area.
[0078] Among them, as shown in Table 3, the updated second storage area, that is, the i_addr array part, includes the third sub-area, that is, the reserved part and the inline tail part. The third sub-area is used to store the tail block data of the file to be stored, and the size of the tail block data of the file to be stored does not exceed 3392 bytes.
[0079] S116: Store the file extension attribute information of the file to be stored in the fourth sub-area.
[0080] Among them, as shown in Table 3, in the file metadata block under the first storage structure, the updated second storage area, that is, the i_addr array part, includes the fourth sub-area, that is, the inline xattr
[50] part, and the fourth sub-area is used to store the file extension attribute information of the file to be stored.
[0081] Specifically, in the file management method provided in the embodiments of the present application, the updated second storage area includes a first sub-area, a second sub-area, a third sub-area, and a fourth sub-area. The metadata information of the file to be stored includes the second file attribute information of the file to be stored, the data block address information of the file to be stored, and the file extension attribute information of the file to be stored. The second file attribute information of the file to be stored is stored in the first sub-area, the data block address information of the file to be stored is stored in the second sub-area, the tail block data of the file to be stored is stored in the third sub-area, and the file extension attribute information of the file to be stored is stored in the fourth sub-area.
[0082] In the above embodiments provided by the present application, the updated second storage area includes a first sub-area, a second sub-area, a third sub-area, and a fourth sub-area; the metadata information of the file to be stored includes the second file attribute information of the file to be stored, the data block address information of the file to be stored, and the file extension attribute information of the file to be stored; the second file attribute information of the file to be stored is stored in the first sub-area; the data block address information of the file to be stored is stored in the second sub-area; the tail block data of the file to be stored is stored in the third sub-area; the file extension attribute information of the file to be stored is stored in the fourth sub-area. In this way, the orderliness and structure of file storage are enhanced, which is conducive to organizing and managing file information more efficiently. When storing and reading files, it is convenient to accurately and quickly locate and operate various types of information, improving the overall performance of the file system.
[0083] In the embodiments of the present application, after the above S104, the above file management method may specifically further include the following S120 to S124:
[0084] S120: Obtain the file offset of the file to be read.
[0085] Among them, the file offset is used to indicate from which byte of the file to start reading the file during the process of reading the file.
[0086] It can be understood that in the traditional file reading method, after obtaining the file offset of the file to be read, the logical block of the file to be read is calculated based on the file offset value, and the logical block is converted into the corresponding physical block address inside F2FS, and then the file data is read from the physical block.
[0087] In the file management method provided in the embodiments of the present application, the inline tail mode is introduced. After obtaining the file offset of the file to be read, based on this file offset, it is calculated whether the file to be stored is stored in accordance with the first storage mode, that is, the inline tail mode, that is, it is determined whether the tail block data of the file to be read is stored in the file metadata block.
[0088] S122: When the file offset indicates that the file to be read enables the first storage mode, query the file metadata block address corresponding to the file to be read.
[0089] Among them, in the first storage mode, the tail block data of the file to be read is stored in the file metadata block.
[0090] Specifically, in the file management method provided in the embodiments of the present application, when the file offset of the file to be read indicates that the file to be read is stored in accordance with the first storage mode, that is, when the file offset of the file to be read indicates that the tail block data of the file to be read is stored in the file metadata block, the tail block address of the file to be read is no longer calculated, but the file metadata block address of the file to be read is directly queried.
[0091] S124: According to the file metadata block address, read the tail block data of the file to be read from the file metadata block of the file to be read.
[0092] Specifically, in the file management method provided in the embodiments of the present application, after querying the file metadata block address of the file to be read, based on this file metadata block address, determine the file metadata block of the file to be read, and according to the data distribution information of this file metadata block, read the tail block data of the file to be read from this file metadata block. In this way, efficient reading after file storage is realized, and the coherence and fluency of the read and write operations of the file system are ensured.
[0093] In the above embodiments provided by the present application, obtain the file offset of the file to be read; when the file offset indicates that the file to be read enables the first storage mode, query the file metadata block address corresponding to the file to be read, where, in the first storage mode, the tail block data of the file to be read is stored in the file metadata block; according to the file metadata block address, read the tail block data of the file to be read from the file metadata block of the file to be read. In this way, efficient reading after file storage is realized, and the coherence and fluency of the read and write operations of the file system are ensured.
[0094] In the embodiments of the present application, the above S102 may specifically include the following S102a to S102c:
[0095] S102a: Obtain the amount of data written to the file to be stored.
[0096] Among them, the amount of data written to the file to be stored is the sum of the first amount of data that has been written to the disk of the file to be stored and the second amount of data newly written this time.
[0097] S102b: When the amount of data written is greater than the second threshold, perform a division operation on the amount of data written and the second threshold to obtain a remainder value.
[0098] Among them, the second threshold is the size of a regular data block, that is, the second threshold is 4K.
[0099] S102c: Determine the remainder value as the data volume of the tail block data of the file to be stored.
[0100] Specifically, in the file management method provided in the embodiments of the present application, obtain the write data volume of the file to be stored, and when the write data volume is greater than the second threshold, perform a division operation on the write data volume and the second threshold to obtain a remainder value, and enter the obtained remainder value as the data volume of the tail block data of the file to be stored.
[0101] For example, if the write data volume of the file to be stored is 4.1K, the data volume of the tail block data of the file to be stored is 0.1K; if the write data volume of the file to be stored is 17.3K, the data volume of the tail block data of the file to be stored is 1.3K.
[0102] In the above embodiments provided by the present application, obtain the write data volume of the file to be stored; when the write data volume is greater than the second threshold, perform a division operation on the write data volume and the second threshold to obtain a remainder value; determine the remainder value as the data volume of the tail block data of the file to be stored. In this way, based on the written data and the data to be written of the file to be stored, the data volume of the tail block data of the file to be stored is determined, ensuring the accuracy of the determined tail block data volume.
[0103] In the embodiments of the present application, the above file management method may specifically further include the following S118:
[0104] S118: When the file to be stored enables the first storage mode and the write data volume of the file to be stored is greater than the third threshold, store the tail block data of the file to be stored in the first data block.
[0105] Among them, the storage structure of the second storage area of the file metadata block is the second storage structure.
[0106] Furthermore, the third threshold is 64K, that is, the carrying range of the file size that can be stored in the inline tail mode is 4K to 64K.
[0107] Specifically, in the file management method provided in the embodiments of the present application, after obtaining the write data volume of the file to be stored, when the file to be stored enables the first storage mode and the write data volume of the file to be stored is within a preset range, the tail block data of the file to be stored is stored through the file metadata block. Otherwise, when the write data volume is outside the preset range, the tail block data of the file to be stored is not stored through the file metadata block, but a new data block, i.e., the first data block, is re-allocated to store the tail block data of the file to be stored. At this time, the storage structure of the second storage area of the file metadata block is restored to the second storage structure shown in Table 2.
[0108] Among them, the preset range is the carrying range of the file size that can be stored in the inline tail mode, that is, the preset range is from 4K to 64K.
[0109] Exemplarily, the size of the file to be stored is 4.1k. When storing this file, 4k of data occupies one data block for storage, and the remaining 0.1k of tail block data is stored in the file metadata block, thus saving the data block occupied by the 0.1k of tail block data in the traditional storage method.
[0110] Exemplarily, the size of the file to be stored is 64.1k. When storing this file, 64k of data occupies 16 data blocks for storage, and the remaining 0.1k of tail block data also occupies 1 data block, i.e., the first database, for storage, and the metadata information is stored in the file metadata block. A total of 18 data blocks are used to store this file.
[0111] That is to say, in the file management method provided in the embodiments of the present application, when the write data volume of the file to be stored is less than or equal to 3.5k, based on the storage structure shown in Table 2 above, the file data of the file to be stored is stored in the file metadata block; when the write data volume of the file to be stored is within the preset range, based on the storage structure shown in Table 3 above, the tail block data of the file to be stored is stored in the file metadata block; when the write data volume of the file to be stored is greater than 3.5k and the write data volume of the file to be stored is outside the preset range, a new data block is allocated to store the tail block data of the file to be stored.
[0112] In the above embodiments provided by the present application, when the file to be stored enables the first storage mode and the write data volume of the file to be stored is greater than the third threshold, the tail block data of the file to be stored is stored in the first data block; the storage structure of the second storage area of the file metadata block is the second storage structure. In this way, based on the write data volume of the file to be stored, the storage structure of the file metadata block is flexibly adjusted, improving the adaptability and flexibility of file storage, being able to make full use of storage resources, and saving the space occupied by file storage.
[0113] In summary, as Figure 3 shown, in the file management method provided by the embodiment of the present application, the file writing process may specifically include the following S202 to S214:
[0114] S202: Assign the iterative write function write_iter of the file operation interface i_fop to the file iterative write function f2fs_file_write_iter of F2FS.
[0115] S204: Assign the write start function write_begin of the asynchronous operation interface a_ops to the write start function f2fs_write_begin of F2FS.
[0116] S206: Execute the preparation for the write start operation.
[0117] S208: Atomically copy the data set from the iterator.
[0118] S210: Assign the write end function write_end of the asynchronous operation interface a_ops to the write end function f2fs_write_end of F2FS.
[0119] S212: Assign the write page function writepage of the asynchronous operation interface a_ops to the write data page function f2fs_write_data_page of F2FS.
[0120] S214: Execute the F2FS operation to write a single data page.
[0121] Among them, as Figure 4 shown, the above S206 may specifically include the following S302 to S312:
[0122] S302: Determine whether the inline tail flag is set. If so, execute S304. If not, end the process.
[0123] S304: Determine whether the current index value is greater than the tail index value. If so, execute S312. If not, execute S306.
[0124] S306: Determine whether the file to be stored supports the inline tail mode. If so, execute S308. If not, execute S312.
[0125] S308: Reconstruct the data to be stored of the file to be stored in the inline tail mode.
[0126] S310: Set the index page.
[0127] S312: Restore the storage structure of the second storage area of the file metadata block from the first storage structure to the second storage structure.
[0128] Among them, the inline tail flag is set, indicating that the electronic device has enabled the inline tail mode for file storage. The current index value is greater than the tail index value, indicating that the amount of written data of the file to be stored exceeds the preset range.
[0129] Further, as Figure 5 shown, the above S214 may specifically include the following S314 and S316:
[0130] S314: Determine whether the file to be stored supports the inline tail mode. If it does, execute S316; if not, end the process.
[0131] S316: Write the tail block data and metadata information of the file to be stored into the file metadata block.
[0132] Further, as Figure 2 shown, in the file management method provided in the embodiments of the present application, the file reading process may specifically include the following S402 to S410:
[0133] S402: Read a page.
[0134] S404: Assign the function pointer of the read dataset read_folio of the asynchronous operation a_ops to the function f2fs_read_data_folio for reading the dataset in F2FS.
[0135] S406: Call the multi-page read page function of F2FS.
[0136] S408: Determine whether there is tail block data. If there is, execute S410; if not, end the process.
[0137] S410: Read the tail block data from the file metadata block.
[0138] Specifically, in the file management method provided in the embodiments of the present application, by measures such as redesigning the disk structure of the file metadata block and optimizing the file reading and writing process, the tail block data of small data volume files is stored in the file metadata block to save the occupied space of the tail block data of small data volume files, so that each small data volume file can save the disk storage space of one block, improving the disk space utilization rate. Among them, since there are a large number of small data volume files in the application programs of the electronic device, based on the file management method provided in the embodiments of the present application, the disk space occupied by the application programs can be saved, and the benefit will increase as the number of application program files increases, thereby improving the performance of the electronic device.
[0139] For example, the size of an application is 44.29 GB. After scanning, the number of files with a size ranging from 4K to 64K in it is 35,462. Since there is likely to be a tail block for each file, based on the file management method provided in the embodiments of the present application, the application can save up to 138 MB of disk space. Based on this, as the number of applications in the electronic device increases, the saved disk space becomes larger.
[0140] In the embodiments of the present application, the execution subject of the provided file management method can be a file management device. In the embodiments of the present application, taking the file management device executing the above file management method as an example, the file management device provided in the embodiments of the present application is described.
[0141] As Figure 6 shown, the embodiments of the present application provide a file management device 500, and the device may include the following processing unit 502 and storage unit 504.
[0142] The processing unit 502 is configured to obtain the data volume of the tail block data of the file to be stored;
[0143] The storage unit 504 is configured to store the tail block data and the metadata information of the file to be stored in the file metadata block when the data volume of the tail block data is less than or equal to the first threshold.
[0144] The file management device 500 provided in the embodiments of the present application obtains the data volume of the tail block data of the file to be stored; when the data volume of the tail block data is less than or equal to the first threshold, stores the tail block data and the metadata information of the file to be stored in the file metadata block. Through the above file management device 500, for the file to be stored whose data volume of the tail block data is less than or equal to the first threshold, the tail block data of the file to be stored is stored together with the metadata information in the file metadata block. In this way, a reasonable plan for file storage is realized, there is no need to separately allocate a data block to store the tail block data, the utilization efficiency of storage resources is improved, and the disk space occupied by file storage is saved.
[0145] In the embodiments of the present application, the file metadata block includes a second storage area, and the storage unit 504 is specifically configured to: store the tail block data and the metadata information of the file to be stored in the second storage area.
[0146] In the above embodiments provided by the present application, the file metadata block includes a second storage area, and the tail block data and the metadata information of the file to be stored are stored in the second storage area. In this way, a reasonable plan for file storage is realized, the utilization efficiency of storage resources is improved, and the disk space occupied by file storage is saved.
[0147] In the embodiment of the present application, before storing the tail block data and the metadata information of the file to be stored into the second storage area, the processing unit 502 is further configured to: update the storage structure of the second storage area to the first storage structure; the storage unit 504 is specifically configured to: store the tail block data and the metadata information of the file to be stored into the updated second storage area.
[0148] In the above embodiment provided by the present application, the storage structure of the second storage area is updated to the first storage structure; the tail block data and the metadata information of the file to be stored are stored into the updated second storage area. In this way, by introducing the inline tail mode and adjusting the storage structure of the file metadata block, a reasonable plan for file storage is achieved, the utilization efficiency of storage resources is improved, and the disk space occupied by file storage is saved.
[0149] In the embodiment of the present application, the processing unit 502 is specifically configured to: when the second storage area is in the expansion mode, update the storage structure of the second storage area to the first storage structure.
[0150] In the above embodiment provided by the present application, when the second storage area is in the expansion mode, the storage structure of the second storage area is updated to the first storage structure. In this way, the second storage area can store the data block address information and the tail data of the file to be stored, which can make full use of storage resources and reduce the space occupied by file storage.
[0151] In the embodiment of the present application, the updated second storage area includes a first sub-area, a second sub-area, a third sub-area, and a fourth sub-area. The storage unit 504 is specifically configured to: store the second file attribute information of the file to be stored in the first sub-area; store the data block address information of the file to be stored in the second sub-area; store the tail block data of the file to be stored in the third sub-area; store the file extension attribute information of the file to be stored in the fourth sub-area.
[0152] In the above embodiment provided by the present application, the updated second storage area includes a first sub-area, a second sub-area, a third sub-area, and a fourth sub-area. The second file attribute information of the file to be stored is stored in the first sub-area; the data block address information of the file to be stored is stored in the second sub-area; the tail block data of the file to be stored is stored in the third sub-area; the file extension attribute information of the file to be stored is stored in the fourth sub-area. In this way, the orderliness and structure of file storage are enhanced, which is beneficial to organizing and managing file information more efficiently. When storing and reading files, it is convenient to accurately and quickly locate and operate various types of information, improving the overall performance of the file system.
[0153] In the embodiment of the present application, after storing the tail block data and the metadata information of the file to be stored into the file metadata block, the processing unit 502 is further configured to: obtain the file offset of the file to be read; such asFigure 6 As shown in the figure, the file management device 500 further includes: a query unit 506, configured to query the file metadata block address corresponding to the file to be read when the file offset indicates that the file to be read enables the first storage mode, where, in the first storage mode, the tail block data of the file to be read is stored in the file metadata block; a reading unit 508, configured to read the tail block data of the file to be read from the file metadata block of the file to be read according to the file metadata block address.
[0154] In the above embodiments provided by the present application, the file offset of the file to be read is obtained; when the file offset indicates that the file to be read enables the first storage mode, the file metadata block address corresponding to the file to be read is queried, where, in the first storage mode, the tail block data of the file to be read is stored in the file metadata block; according to the file metadata block address, the tail block data of the file to be read is read from the file metadata block of the file to be read. In this way, efficient reading after file storage is achieved, ensuring the coherence and fluency of the read and write operations of the file system.
[0155] In the embodiments of the present application, the processing unit 502 is specifically configured to: obtain the write data volume of the file to be stored; when the write data volume is greater than a second threshold, perform a division operation on the write data volume and the second threshold to obtain a remainder value; and determine the remainder value as the data volume of the tail block data of the file to be stored.
[0156] In the above embodiments provided by the present application, the write data volume of the file to be stored is obtained; when the write data volume is greater than a second threshold, perform a division operation on the write data volume and the second threshold to obtain a remainder value; and determine the remainder value as the data volume of the tail block data of the file to be stored. In this way, based on the written data and the data to be written of the file to be stored, the data volume of the tail block data of the file to be stored is determined, ensuring the accuracy of the determined tail block data volume.
[0157] In the embodiments of the present application, the storage unit 504 is further configured to: when the file to be stored enables the first storage mode and the write data volume of the file to be stored is greater than a third threshold, store the tail block data of the file to be stored in the first data block; the storage structure of the second storage area of the file metadata block is the second storage structure.
[0158] In the above embodiments provided by the present application, when the file to be stored enables the first storage mode and the write data volume of the file to be stored is greater than a third threshold, store the tail block data of the file to be stored in the first data block; the storage structure of the second storage area of the file metadata block is the second storage structure. In this way, based on the write data volume of the file to be stored, the storage structure of the file metadata block is flexibly adjusted, improving the adaptability and flexibility of file storage, being able to make full use of storage resources and saving the space occupied by file storage.
[0159] The file management device 500 in the embodiments of the present application may be an electronic device or a component in an electronic device, such as an integrated circuit or a chip. The electronic device may be a terminal or other devices other than terminals. Exemplarily, the electronic device may be a mobile phone, a tablet computer, a laptop computer, a handheld computer, a vehicle-mounted electronic device, a Mobile Internet Device (MID), an augmented reality (AR) / virtual reality (VR) device, a robot, a wearable device, an ultra-mobile personal computer (UMPC), a netbook, or a personal digital assistant (PDA), etc. It may also be a server, a Network Attached Storage (NAS), a personal computer (PC), a television (TV), a teller machine, or a self-service machine, etc. The embodiments of the present application do not make specific limitations.
[0160] The file management device 500 in the embodiments of the present application may be a device with an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems. The embodiments of the present application do not make specific limitations.
[0161] The file management device 500 provided in the embodiments of the present application can implement Figures 1 to 5 each process implemented by the method embodiments. To avoid repetition, it will not be elaborated here.
[0162] Optionally, as Figure 7 shown, the embodiments of the present application further provide an electronic device 600, including a processor 602 and a memory 604. A program or instruction that can run on the processor 602 is stored on the memory 604. When the program or instruction is executed by the processor 602, it implements each step of the above-mentioned file management method embodiments and can achieve the same technical effects. To avoid repetition, it will not be elaborated here.
[0163] It should be noted that the electronic devices in the embodiments of the present application include the above-mentioned mobile electronic devices and non-mobile electronic devices.
[0164] Figure 8 A schematic diagram of the hardware structure of an electronic device for implementing the embodiments of the present application.
[0165] The electronic device 700 includes, but is not limited to, components such as a radio frequency unit 701, a network module 702, an audio output unit 703, an input unit 704, a sensor 705, a display unit 706, a user input unit 707, an interface unit 708, a memory 709, and a processor 710.
[0166] Those skilled in the art can understand that the electronic device 700 may further include a power source (such as a battery) for supplying power to each component. The power source can be logically connected to the processor 710 through a power management system, so as to implement functions such as management of charging, discharging, and power consumption management through the power management system. Figure 8 The structure of the electronic device shown does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here.
[0167] Among them, the processor 710 is used to obtain the data volume of the tail block data of the file to be stored.
[0168] The memory 709 is used to store the tail block data and the metadata information of the file to be stored into the file metadata block when the data volume of the tail block data is less than or equal to a first threshold.
[0169] In the embodiment of the present application, the data volume of the tail block data of the file to be stored is obtained; when the data volume of the tail block data is less than or equal to the first threshold, the tail block data and the metadata information of the file to be stored are stored into the file metadata block. In the embodiment of the present application, for a file to be stored whose data volume of the tail block data is less than or equal to the first threshold, the tail block data of the file to be stored together with the metadata information is stored in the file metadata block. In this way, a reasonable plan for file storage is realized, there is no need to separately allocate a data block to store the tail block data, the utilization efficiency of storage resources is improved, and the disk space occupied by file storage is saved.
[0170] Optionally, the file metadata block includes a second storage area, and the memory 709 is specifically used to: store the tail block data and the metadata information of the file to be stored into the second storage area.
[0171] For the file management method provided by the embodiment of the present application, the file metadata block includes a second storage area, and the tail block data and the metadata information of the file to be stored are stored into the second storage area. In this way, a reasonable plan for file storage is realized, the utilization efficiency of storage resources is improved, and the disk space occupied by file storage is saved.
[0172] Optionally, before storing the tail block data and the metadata information of the file to be stored into the second storage area, the processor 710 is further configured to: update the storage structure of the second storage area to the first storage structure; specifically, the memory 709 is configured to: store the tail block data and the metadata information of the file to be stored into the updated second storage area.
[0173] In the above embodiments provided by the present application, the storage structure of the second storage area is updated to the first storage structure; the tail block data and the metadata information of the file to be stored are stored into the updated second storage area. In this way, by introducing the inline tail mode and adjusting the storage structure of the file metadata block, a reasonable plan for file storage is achieved, the utilization efficiency of storage resources is improved, and the disk space occupied by file storage is saved.
[0174] Optionally, the processor 710 is specifically configured to: when the second storage area is in the expansion mode, update the storage structure of the second storage area to the first storage structure.
[0175] In the above embodiments provided by the present application, when the second storage area is in the expansion mode, the storage structure of the second storage area is updated to the first storage structure. In this way, the second storage area can store the data block address information and the tail data of the file to be stored, which can make full use of the storage resources and reduce the space occupied by file storage.
[0176] Optionally, the updated second storage area includes a first sub-area, a second sub-area, a third sub-area, and a fourth sub-area. Specifically, the memory 709 is configured to: store the second file attribute information of the file to be stored in the first sub-area; store the data block address information of the file to be stored in the second sub-area; store the tail block data of the file to be stored in the third sub-area; store the file extension attribute information of the file to be stored in the fourth sub-area.
[0177] In the above embodiments provided by the present application, the updated second storage area includes a first sub-area, a second sub-area, a third sub-area, and a fourth sub-area. The second file attribute information of the file to be stored is stored in the first sub-area; the data block address information of the file to be stored is stored in the second sub-area; the tail block data of the file to be stored is stored in the third sub-area; the file extension attribute information of the file to be stored is stored in the fourth sub-area. In this way, the orderliness and structure of file storage are enhanced, which is beneficial to organizing and managing file information more efficiently. When storing and reading files, it is convenient to accurately and quickly locate and operate various types of information, improving the overall performance of the file system.
[0178] Optionally, after storing the tail block data and the metadata information of the file to be stored into the file metadata block, the processor 710 is further configured to: obtain the file offset of the file to be read; when the file offset indicates that the file to be read enables the first storage mode, query the file metadata block address corresponding to the file to be read, where, in the first storage mode, the tail block data of the file to be read is stored in the file metadata block; and read the tail block data of the file to be read from the file metadata block of the file to be read according to the file metadata block address.
[0179] In the above embodiments provided by the present application, the file offset of the file to be read is obtained; when the file offset indicates that the file to be read enables the first storage mode, the file metadata block address corresponding to the file to be read is queried, where, in the first storage mode, the tail block data of the file to be read is stored in the file metadata block; and the tail block data of the file to be read is read from the file metadata block of the file to be read according to the file metadata block address. In this way, efficient reading after file storage is achieved, ensuring the coherence and fluency of the read and write operations of the file system.
[0180] Optionally, the processor 710 is specifically configured to: obtain the amount of data written to the file to be stored; when the amount of data written is greater than a second threshold, perform a division operation on the amount of data written and the second threshold to obtain a remainder value; and determine the amount of data of the tail block data of the file to be stored as the remainder value.
[0181] In the above embodiments provided by the present application, the amount of data written to the file to be stored is obtained; when the amount of data written is greater than a second threshold, perform a division operation on the amount of data written and the second threshold to obtain a remainder value; and determine the amount of data of the tail block data of the file to be stored as the remainder value. In this way, based on the data already written and the data to be written to the file to be stored, the amount of data of the tail block data of the file to be stored is determined, ensuring the accuracy of the determined amount of tail block data.
[0182] Optionally, the memory 709 is further configured to: when the file to be stored enables the first storage mode and the amount of data written to the file to be stored is greater than a third threshold, store the tail block data of the file to be stored into the first data block; and the storage structure of the second storage area of the file metadata block is a second storage structure.
[0183] In the above embodiments provided by the present application, when the file to be stored enables the first storage mode and the amount of data written to the file to be stored is greater than a third threshold, store the tail block data of the file to be stored into the first data block; and the storage structure of the second storage area of the file metadata block is a second storage structure. In this way, based on the amount of data written to the file to be stored, the storage structure of the file metadata block is flexibly adjusted, improving the adaptability and flexibility of file storage, enabling full utilization of storage resources, and saving the space occupied by file storage.
[0184] It should be understood that in the embodiments of the present application, the input unit 704 may include a Graphics Processing Unit (GPU) 7041 and a microphone 7042. The graphics processor 7041 processes the image data of still pictures or videos obtained by an image capturing device (such as a camera) in a video capture mode or an image capture mode. The display unit 706 may include a display panel 7061, and the display panel 7061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 707 includes at least one of a touch panel 7071 and other input devices 7072. The touch panel 7071 is also referred to as a touch screen. The touch panel 7071 may include two parts: a touch detection device and a touch controller. The other input devices 7072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, power switch keys, etc.), a trackball, a mouse, and a joystick, which will not be elaborated here.
[0185] The memory 709 can be used to store software programs and various data. The memory 709 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data. Among them, the first storage area may store an operating system, application programs or instructions required for at least one function (such as a sound playback function, an image playback function, etc.). In addition, the memory 709 may include a volatile memory or a non-volatile memory, or the memory 709 may include both a volatile memory and a non-volatile memory. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDR SDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synch link dynamic random access memory (SLDRAM), and a direct rambus random access memory (DRRAM). The memory 709 in the embodiments of the present application includes, but is not limited to, these and any other suitable types of memories.
[0186] The processor 710 may include one or more processing units; optionally, the processor 710 integrates an application processor and a modem processor. Among them, the application processor mainly processes operations related to the operating system, user interface, and application programs, etc., and the modem processor mainly processes wireless communication signals, such as a baseband processor. It can be understood that the above modem processor may not be integrated into the processor 710 either.
[0187] The embodiments of the present application also provide a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, it implements each process of the above-mentioned embodiment of the file management method and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.
[0188] Among them, the processor is the processor in the electronic device in the above-mentioned embodiment. The readable storage medium includes computer-readable storage media, such as computer read-only memory ROM, random access memory RAM, magnetic disk or optical disc, etc.
[0189] Another embodiment of the present application provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement each process of the above-mentioned embodiment of the file management method, and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.
[0190] It should be understood that the chip mentioned in the embodiment of the present application can also be referred to as a system-on-chip, system chip, chip system or system-on-chip, etc.
[0191] The embodiment of the present application provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement each process of the above-mentioned embodiment of the file management method, and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.
[0192] It should be noted that in this article, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including a..." does not exclude the existence of additional identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in a reverse order according to the functions involved. For example, the described methods may be performed in an order different from that described, and various steps may be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0193] Through the description of the above embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. The computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disc), and includes several instructions for causing a terminal (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of the present application.
[0194] The embodiments of the present application have been described above in conjunction with the accompanying drawings. However, the present application is not limited to the above specific embodiments. The above specific embodiments are merely illustrative rather than restrictive. Under the inspiration of the present application, those of ordinary skill in the art can also make many forms without departing from the purpose of the present application and the scope protected by the claims, and all of them fall within the protection scope of the present application.
Claims
1. A file management method, characterized in that, Including: Obtaining the data volume of the tail block data of the file to be stored; When the data volume of the tail block data is less than or equal to a first threshold, storing the tail block data and the metadata information of the file to be stored into a file metadata block.
2. The document management method according to claim 1, wherein The file metadata block includes a second storage area; The storing the tail block data and the metadata information of the file to be stored into the file metadata block includes: Storing the tail block data and the metadata information of the file to be stored into the second storage area.
3. The document management method according to claim 2, wherein Before storing the tail block data and the metadata information of the file to be stored into the second storage area, the method further includes: Updating the storage structure of the second storage area to a first storage structure; The storing the tail block data and the metadata information of the file to be stored into the second storage area includes: Storing the tail block data and the metadata information of the file to be stored into the updated second storage area.
4. The document management method according to claim 3, characterized in that The updating the storage structure of the second storage area to the first storage structure includes: When the second storage area is in an extended mode, updating the storage structure of the second storage area to the first storage structure.
5. The document management method according to claim 3, wherein The updated second storage area includes a first sub-area, a second sub-area, a third sub-area, and a fourth sub-area; the metadata information of the file to be stored includes the second file attribute information of the file to be stored, the data block address information of the file to be stored, and the file extension attribute information of the file to be stored; The storing the tail block data and the metadata information of the file to be stored into the updated second storage area includes: Storing the second file attribute information of the file to be stored in the first sub-area; Storing the data block address information of the file to be stored in the second sub-area; Storing the tail block data of the file to be stored in the third sub-area; Storing the file extension attribute information of the file to be stored in the fourth sub-area.
6. The document management method according to claim 1, characterized in that After storing the tail block data and the metadata information of the file to be stored into the file metadata block, the method further includes: Obtaining the file offset of the file to be read; When the file offset indicates that the file to be read enables a first storage mode, querying the file metadata block address corresponding to the file to be read, wherein, in the first storage mode, the tail block data of the file to be read is stored in the file metadata block; Reading the tail block data of the file to be read from the file metadata block of the file to be read according to the file metadata block address.
7. The document management method according to claim 1, characterized in that The obtaining the data volume of the tail block data of the file to be stored includes: Obtaining the write data volume of the file to be stored; When the write data volume is greater than a second threshold, performing a division operation on the write data volume and the second threshold to obtain a remainder value; Determining the remainder value as the data volume of the tail block data of the file to be stored.
8. The document management method according to claim 1, characterized in that, The method further includes: When the first storage mode is enabled for the file to be stored and the amount of written data of the file to be stored is greater than a third threshold, the tail block data of the file to be stored is stored in a first data block; the storage structure of the second storage area of the file metadata block is a second storage structure.
9. A file management device, characterized in that, It includes: A processing unit for obtaining the amount of data of the tail block data of the file to be stored; A storage unit for storing the tail block data and the metadata information of the file to be stored in a file metadata block when the amount of data of the tail block data is less than or equal to a first threshold.
10. The document management device according to claim 9, wherein The file metadata block includes a second storage area; specifically, the storage unit is used for: Storing the tail block data and the metadata information of the file to be stored in the second storage area.
11. The document management device according to claim 10, wherein Before storing the tail block data and the metadata information of the file to be stored in the second storage area, the processing unit is further used for: Updating the storage structure of the second storage area to a first storage structure; Specifically, the storage unit is used for: Storing the tail block data and the metadata information of the file to be stored in the updated second storage area.
12. The document management device according to claim 11, wherein Specifically, the processing unit is used for: When the second storage area is in an extended mode, updating the storage structure of the second storage area to the first storage structure.
13. The document management device according to claim 11, characterized in that, The updated second storage area includes a first sub-area, a second sub-area, a third sub-area, and a fourth sub-area; the metadata information of the file to be stored includes the second file attribute information of the file to be stored, the data block address information of the file to be stored, and the file extension attribute information of the file to be stored; specifically, the storage unit is used for: Storing the second file attribute information of the file to be stored in the first sub-area; Storing the data block address information of the file to be stored in the second sub-area; Storing the tail block data of the file to be stored in the third sub-area; Storing the file extension attribute information of the file to be stored in the fourth sub-area.
14. An electronic device, characterized in that, It includes a processor and a memory, and the memory stores a program or instruction that can run on the processor. When the program or instruction is executed by the processor, the steps of the file management method according to any one of claims 1 to 8 are implemented.
15. A readable storage medium, characterized in that, A program or instruction is stored on the readable storage medium. When the program or instruction is executed by a processor, the steps of the file management method according to any one of claims 1 to 8 are implemented.