A file storage method, apparatus, device, medium, and program

By selecting the storage strategy with the fewest logical blocks based on the amount of file data and the availability of free logical blocks in the file system, the file system fragmentation problem is solved, and the read/write performance and resource utilization efficiency of the storage device are improved.

CN119148925BActive Publication Date: 2025-11-14AUTOCHIPS
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410949688.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-15
Publication Date
2025-11-14
Estimated Expiration
2044-07-15

AI Technical Summary

Technical Problem

Frequent concurrent write operations lead to high fragmentation of the file system, affecting read and write performance and potentially causing write amplification issues in storage devices.

Method used

Based on the statistical results of file data volume and free logical blocks, the storage strategy with the fewest logical blocks is selected. The file is divided into blocks and stored in pre-divided logical blocks, with priority given to the strategy with the lowest redundancy capacity to reduce fragmentation.

Benefits of technology

It effectively reduces file system fragmentation, improves read and write performance, and optimizes storage resource utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119148925B_ABST
    Figure CN119148925B_ABST
Patent Text Reader

Abstract

This application provides a file storage method, apparatus, device, medium, and program. The method includes: determining candidate storage strategies for storing files by selecting logical blocks from free logical blocks based on the data volume of the file to be stored and statistical results of free logical blocks; free logical blocks are logical blocks in a free state among at least one logical block pre-divided from the data area of ​​the file system, and the at least one logical block includes logical blocks of at least one capacity specification; if at least one candidate storage strategy is determined, determining a target storage strategy that meets preset conditions from all candidate storage strategies; selecting logical blocks from the free logical blocks that match the target storage strategy, and storing the file in blocks within the selected logical blocks; wherein the preset conditions include: condition one, when selecting logical blocks according to each candidate strategy, the number of logical blocks selected by the target candidate strategy is minimized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computers, and more specifically to the field of computer operating systems, and particularly to a file storage method, apparatus, device, medium, and program. Background Technology

[0002] Computer operating systems typically provide file systems. A file system is the method and data structure used by the operating system to define files on storage devices (commonly disks) or partitions; that is, the method of organizing files on storage devices. From the operating system's perspective, the file system organizes and allocates space on storage devices, is responsible for storing files, and protects and retrieves stored files. Specifically, it is responsible for creating files for users, storing, reading, modifying, and dumping files, controlling file access, and deleting files when the user no longer needs them.

[0003] However, frequent concurrent writing of different files to the file system (such as multi-channel recording with a DVR) often leads to frequent allocation and release of small blocks of space, resulting in a large number of small blocks of space filling the file system and causing a high degree of file system fragmentation. If the file system is too fragmented, it may not only cause problems requiring frequent random read and write operations, but may also enable write amplification on some storage devices, thereby severely degrading the read and write performance of the file system. Summary of the Invention

[0004] The purpose of this application is to provide a file storage method, apparatus, device, medium, chip, and computer program product that can, to a certain extent, solve the technical problem of high file system fragmentation caused by concurrent read and write operations.

[0005] A first aspect of this application provides a file storage method, the method comprising:

[0006] Based on the data volume of the file to be stored and the statistical results of the free logical blocks, a candidate storage strategy is determined to select logical blocks from the free logical blocks to store the file; the free logical blocks are at least one logical block that is in a free state from the data area of ​​the file system in advance, and the at least one logical block includes at least one logical block of at least one capacity specification.

[0007] Given at least one candidate storage strategy, select the target storage strategy that meets the preset conditions from all candidate storage strategies.

[0008] Select a logical block from the free logical blocks that matches the target storage strategy, and store the file in the selected logical block.

[0009] The preset conditions include: Condition 1: When selecting logic blocks according to each candidate strategy, the number of logic blocks selected by the target candidate strategy is the minimum.

[0010] A second aspect of this application provides a file storage device, the device comprising:

[0011] The first determining module is used to determine a candidate storage strategy for selecting logical blocks from the free logical blocks to store the file based on the data volume of the file to be stored and the statistical results of the free logical blocks; the free logical blocks are at least one logical block that is in a free state from the data area of ​​the file system in advance, and the at least one logical block includes at least one logical block of at least one capacity specification.

[0012] The second determining module is used to determine the target storage strategy that meets the preset conditions from all candidate storage strategies when at least one candidate storage strategy has been determined.

[0013] The first storage module is used to select logical blocks that match the target storage strategy from the free logical blocks, and store the file in blocks into the selected logical blocks;

[0014] The preset conditions include: Condition 1: When selecting logic blocks according to each candidate strategy, the number of logic blocks selected by the target candidate strategy is the minimum.

[0015] A third aspect of this application provides an electronic device, the electronic device comprising: a processor and a memory, the memory storing a program or instructions executable on the processor, the program or instructions, when executed by the processor, implementing the steps of the file storage method as described in the first aspect.

[0016] A fourth aspect of this application provides a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the file storage method as described in the first aspect.

[0017] A fifth aspect of this application provides a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the file storage method as described in the first aspect.

[0018] A sixth aspect of this application provides a computer program product stored in a storage medium, which is executed by at least one processor to implement the file storage method as described in the first aspect.

[0019] In this embodiment, at least one logical block is pre-divided from the data area of ​​the file system, and these logical blocks have at least one capacity specification. When writing a file to the data area of ​​the file system, the file is stored in blocks within these pre-divided logical blocks. Furthermore, when writing a file (i.e., the file to be stored), based on the file's data volume and the statistical results of free logical blocks in the file system, a candidate storage strategy is determined. The candidate storage strategy that occupies the fewest logical blocks is selected as the target storage strategy. Then, logical blocks are selected from the free logical blocks to store the file according to the target storage strategy. This ensures that the number of logical blocks occupied each time a file is written to the file system is minimized. Even with concurrent read and write operations to the file system, a storage strategy that minimizes the number of logical blocks occupied is always used to store the file, thereby effectively reducing the fragmentation of the file system. Attached Figure Description

[0020] Figure 1 This is a schematic diagram illustrating the division of logical blocks from the data area of ​​a file system, provided in an embodiment of this application.

[0021] Figure 2 This is a schematic diagram of a file system structure provided in an embodiment of this application;

[0022] Figure 3 yes Figure 1 Bitmap of a logic block with a medium capacity specification of F0;

[0023] Figure 4 This is a flowchart illustrating the steps of a file storage method provided in an embodiment of this application;

[0024] Figure 5 This is a state diagram corresponding to the storage of an example file provided in an embodiment of this application;

[0025] Figure 6 This is a schematic diagram of the structure of a file storage device provided in an embodiment of this application;

[0026] Figure 7 This application also provides a schematic diagram of the structure of an electronic device;

[0027] Figure 8 This application also provides a schematic diagram of the structure of another electronic device. Detailed Implementation

[0028] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.

[0029] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class, without limiting the number of objects; for example, a first object can be one or more. Furthermore, "and / or" in the specification and claims indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0030] The file storage method, apparatus, device, storage medium, chip, and computer program product provided in this application can effectively solve the technical problem of high file system fragmentation caused by concurrent read and write operations. The following description is in conjunction with the accompanying drawings.

[0031] A file system typically includes an information area and a data area. The data area logically stores files, while the information area stores information about the files stored in the data area (such as filename, file size, file location, etc.). In this embodiment, at least one logical block is pre-divided from the data area of ​​the file system, and these logical blocks include at least one capacity specification.

[0032] For example, such as Figure 1 The diagram illustrates a method for dividing logical blocks from the data area of ​​a file system, as provided in an embodiment of this application. Please refer to... Figure 1 For example, four types of logical blocks with different capacity sizes are partitioned from the data area of ​​the file system: F1, F2, F3, and F4, where F4 > F3 > F2 > F1. Of course, in other embodiments, more (or fewer) types of logical blocks with different capacity sizes can be partitioned from the data area of ​​the file system. For example, five, six, or more types of logical blocks with different capacity sizes can be partitioned from the data area of ​​the file system; or three, two, or fewer types of logical blocks with different capacity sizes can be partitioned from the data area of ​​the file system. In this embodiment, no specific limitation is made on the number of types of logical blocks with different capacity sizes partitioned from the data area of ​​the file system.

[0033] In some alternative implementations, the capacity specifications at each level of the at least one capacity specification are arranged in a geometric progression. That is, the capacity specifications at each level of the logical blocks partitioned from the data area in the file system are arranged in a geometric progression.

[0034] For example, Figure 1The sequence of capacity specifications for each level of the logic block shown is a geometric sequence, that is, the sequence F1, F2, F3, F4 is a geometric sequence. Assuming its common ratio is q, then F2 = qF1, ..., F n =qF n-1 The general term can be expressed as F. n =q n-1 F1, where n∈N + N + Let q represent the set of positive integers. Optionally, q = 2. Of course, q can also take other positive integers greater than 2, such as q = 3 or q = 4, etc.

[0035] In some optional implementations, during formatting, the file system creates logical blocks and corresponding logical block descriptor tables based on pre-set parameters (these parameters include at least those related to dividing logical blocks from the file system's data area, such as the size of the logical block pool, the capacity specifications of each level of logical blocks, and the number of logical blocks at each level; where the logical block pool is the set of all logical blocks, and the size of the logical block pool is the total capacity of all logical blocks). The logical block descriptor table records relevant information about the logical blocks. The logical block descriptor table is stored in a reserved area within the file system (e.g., the file system's information area). It should be noted that, to improve the access performance of the storage device, preferably, all logical blocks of the same capacity level typically occupy a contiguous physical storage space on the storage device.

[0036] For example, such as Figure 2 As shown, Figure 2 This is a schematic diagram of a file system structure provided in an embodiment of this application. This example file system is an improvement upon the FAT file system. The Data Area block is the data area of ​​the file system, and logical blocks are partitioned from this area. Logical blocks partitioned from the data area can be as follows: Figure 1 The logic block shown. Please continue reading... Figure 2 All blocks except the Data Area are the information area of ​​this file system. Further improvements were made within the allowed free space of the file system, adding a File-Entry Table area to the reserved area to record relevant information about logical blocks.

[0037] Please continue reading Figure 2The File-Entry Table includes a header area, a read-only area (RO AREA), and a read-write area (RW AREA). The header area records metadata about the logical block descriptor table, such as version information, total number of logical blocks, capacity of each capacity level (e.g., F1 mentioned earlier), and the number of logical blocks at each capacity level. The RO AREA records the capacity level of logical blocks for each capacity level, the sequence number of each logical block, the starting address of each logical block, and whether each logical block is available. The RW AREA records connection information and occupancy status of each logical block.

[0038] In some optional implementations, a free logical block table is created in the file system, recording logical blocks that are not yet occupied. Optionally, the free logical block table is created when the file system is mounted. For example, during mounting, the logical block descriptor table stored in the file system is loaded and read, and an index is created for each logical block (an index for a logical block includes the physical address of the physical storage space allocated to that logical block on the physical storage device, etc.). Simultaneously, a free logical block table is created based on the occupancy status of each logical block read from the logical block descriptor table.

[0039] For example, the free logical block table is represented by a bitmap. A bitmap is created for each type of logical block capacity, recording the occupancy status of each logical block within that capacity level. Furthermore, the order of the bit blocks in this bitmap matches the order of the corresponding physical blocks on the physical storage device. Figure 3 As shown, an exemplary illustration is presented. Figure 1 The bitmap represents a logic block with a capacity specification of F1. There is a one-to-one correspondence between the bit blocks and the logic blocks with a capacity specification of F1; that is, one bit block records the occupancy status of a unique logic block with a capacity specification of F1. The background of the bit block corresponding to an occupied logic block is shaded, while the background of the bit block corresponding to an unoccupied logic block is transparent. Based on this exemplary bitmap, it can be seen that the logic block corresponding to bit block 301 is in an idle state, i.e., unoccupied; while the logic blocks corresponding to bit blocks 308 and 311 are both occupied. The bitmaps corresponding to logic blocks of other capacity specifications are... Figure 3 The bitmap shown is similar, and those skilled in the art can understand it accordingly, so it will not be described again here.

[0040] Based on this, the file storage method provided in the embodiments of this application will be described below.

[0041] like Figure 4The diagram illustrates a flowchart of the file storage method provided in this application embodiment. The file storage method includes the following steps S11-S13:

[0042] S11, based on the data volume of the file to be stored and the statistical results of the free logical blocks, determine the candidate storage strategy for selecting logical blocks from the free logical blocks to store the file.

[0043] The amount of data in a file, commonly referred to as file size, is usually measured in bits (this is the smallest unit; other units include KB, MB, GB, TB, etc.). A free logical block is a logical block that is currently idle within at least one logical block pre-allocated from the file system's data area. This at least one logical block includes logical blocks of at least one capacity specification. For details regarding logical blocks, free logical blocks, and their capacity specifications, please refer to the preceding explanation; they will not be repeated here. The statistical result of free logical blocks refers to the result obtained by counting the logical blocks in the logical block pool that are in an idle state (i.e., not yet occupied).

[0044] In some optional implementations, the data size of the file to be stored is x, and the statistics of free logical blocks are shown in Table 1 below:

[0045] Table 1. Statistical results of idle logic blocks in the logic pool

[0046]

[0047] in, This indicates that the capacity specification in the logic block pool is F. n The number of free logic blocks is indivual.

[0048] Alternatively, create a state transition expression as follows:

[0049]

[0050] Wherein, S(t,j) t ) and S(i,j i Both S(t, j) represent states. t ) is S(i,j i Precursor states, S(i, j) i ) is S(t,j t The successor state of S(t, j); t This indicates that a capacity specification of F is to be selected from the logic pool. r ..., F s ..., F t The available logic blocks, and the total capacity of the selected available logic blocks is j. t The state at time; similarly, S(i, j)i This indicates that a capacity specification of F is to be selected from the logic pool. r ..., F s ..., F t F i The available logic blocks, and the total capacity of the selected available logic blocks is j. i The current state; the capacity specification is F. r ..., F s The free logic block is in S(t,j) t The previous state was selected from the logic pool; where r∈N + s∈N + , t∈N + , i∈N + , r < s < t < i ≤ n; k i This indicates that the capacity specification selected from the logic pool is F. i The number of free logical blocks, k i ∈N + Obviously, (That is, when selecting a free logic block of a certain capacity specification, at most all free logic blocks of that capacity specification in the logic block pool will be selected, and the number of selected free logic blocks of that capacity specification cannot be supernaturally made to exceed the number of free logic blocks of that capacity specification in the logic block pool, in violation of physical laws).

[0051] Equation ① indicates that in state S(t, j) t Based on this, k is selected from the logic block pool. i The capacity specification is F i The logic block, the state changes from S(t, j) t The state transitions to state S(i, j). i Obviously, j t +k i F i =j i Therefore, equation ① can also be expressed as:

[0052]

[0053] Based on equations ① and ② above, the following equations can also be established:

[0054]

[0055] in, It is in a state The total number of free logical blocks selected from the logical block pool.

[0056] In the terminated state hour, In other words, at the termination state, the total capacity of the free logical blocks to be selected from the logical pool should be greater than or equal to the data size of the file to be stored, to ensure that the file can be stored in the file system. That is, in the extension of a "path" (i.e., the jump relationship between the previous state and the next state), when the total capacity j of the selected free logical blocks corresponding to a certain state... i When x ≥ x, the state can be defined as the terminal state.

[0057] Based on Table 1 and Equation ① (or Equation ②) above, the currently available candidate storage strategies are determined, that is, based on Equation ① (or Equation ②) above, the transition from state S(0, 0) (i.e., the initial state, where no free logical blocks have been selected from the logical block pool) to... This involves identifying all feasible "paths," each corresponding to an optional candidate storage strategy. Exhausting all available storage strategies determines all candidate storage strategies.

[0058] To facilitate understanding, an example will be provided below.

[0059] Suppose the logical block pool contains four types of free logical blocks: F1 = 50MB, F2 = 100MB, F3 = 200MB, and F4 = 400MB. The current number of free logical blocks of each type is 10, 20, 5, and 7 respectively. The file to be stored contains 270MB of data. Based on equation ① above, the following state transition process applies:

[0060]

[0061]

[0062]

[0063]

[0064]

[0065]

[0066]

[0067]

[0068]

[0069]

[0070]

[0071]

[0072] Therefore, in this example, there are currently 12 candidate storage strategies, as shown in the transfer process ⑤ above. As shown in the formula.

[0073] S12, if at least one candidate storage strategy is determined, a target storage strategy that meets preset conditions is determined from all candidate storage strategies. The preset conditions include: Condition 1, when selecting logical blocks according to each candidate strategy, the target candidate strategy selects the fewest number of logical blocks.

[0074] After determining all available candidate storage strategies based on the state transition equation (i.e., equation ①), the candidate storage strategy that requires the fewest number of free logical blocks is selected as the target storage strategy.

[0075] For example, the transfer process is obvious in the above example. The required free logical block is minimal, requiring only one free logical block with a capacity specification of F4 = 400MB.

[0076] S13, Select a logical block from the free logical blocks that matches the target storage strategy, and store the file in blocks into the selected logical blocks.

[0077] According to the target storage strategy, select the corresponding logical blocks from the free logical blocks in the logical block pool, and store the file to be stored in blocks into the selected logical blocks.

[0078] In the aforementioned example, a free logical block with a capacity of F4 = 400MB is selected from the logical block pool to store the 270MB file. It should be noted that in this example, the file to be stored does not need to be divided into blocks and can be directly stored in the 400MB logical block. However, assuming the target storage strategy is to use a 100MB free logical block and a 200MB free logical block to store the 270MB file, then the file can be divided into a 200MB file block and a 70MB file block. The 200MB file block is then stored in the 200MB free logical block, and the 70MB file block is stored in the 100MB free logical block.

[0079] In this embodiment, at least one logical block is pre-divided from the data area of ​​the file system, and these logical blocks have at least one capacity specification. When writing a file to the data area of ​​the file system, the file is stored in blocks within these pre-divided logical blocks. Furthermore, when writing a file (i.e., the file to be stored), based on the file's data volume and the statistical results of free logical blocks in the file system, a candidate storage strategy is determined. The candidate storage strategy that occupies the fewest logical blocks is selected as the target storage strategy. Then, logical blocks are selected from the free logical blocks to store the file according to the target storage strategy. This ensures that the number of logical blocks occupied each time a file is written to the file system is minimized. Even with concurrent read and write operations to the file system, a storage strategy that minimizes the number of logical blocks occupied is always used to store the file, thereby effectively reducing the fragmentation of the file system.

[0080] Comparison Japanese style It can be seen that in the formula The state transition process shown requires the fewest free logical blocks, but wastes 130MB of storage space (a free logical block corresponds to an equal-sized storage space on the storage device; when a file is stored in that free logical block, the corresponding physical storage space is completely occupied and cannot be used to store other data). This wasted 130MB is called redundant capacity (redundant capacity refers to the capacity remaining after a file is stored in a free logical block); During the state transition process shown, although one more free logical block is required compared to the previous method, the resulting redundant capacity is only 30MB. Storage resources are quite valuable, and reducing the effective utilization rate of storage resources solely to reduce file system fragmentation would be counterproductive. Therefore, it is preferable to reduce file system fragmentation while ensuring the highest possible effective utilization rate of storage resources.

[0081] Therefore, in some optional implementations, the preset conditions further include: Condition 2, when storing the file according to each candidate strategy, the redundancy capacity of the target storage strategy is the lowest; and the target storage strategy is a candidate storage strategy that also satisfies Condition 1 and is selected from the candidate storage strategies that preferentially satisfy Condition 2.

[0082] That is, when determining the target candidate strategy from the candidate storage strategies, preferably, the candidate storage strategy with the least redundant capacity is determined first from these candidate storage strategies, and then the candidate storage strategy requiring the fewest free logical blocks is determined from these candidate storage strategies with the least redundant capacity as the target storage strategy.

[0083] For example, still taking the aforementioned storage of a 270MB file and its file system as an example, in this example, from transfer process ⑤ to transfer process Of the 12 candidate storage strategies, the candidate storage strategies that satisfy condition two are equations ⑧ and ⑩ of the transfer process. formula and The redundancy capacity of these four candidate storage strategies is 30MB; then, from the transfer process, equations ⑧ and ⑩... formula and The candidate storage strategy that satisfies condition one among the four candidate storage strategies corresponding to the formula is the transfer process. The corresponding candidate storage strategy involves selecting one 100MB free logical block and one 200MB free logical block from the logical block pool to store the file, requiring a total of two logical blocks. This reduces file system fragmentation while ensuring the highest possible utilization of storage resources.

[0084] It should be further noted that when selecting free logical block storage files from the logical pool, for the same capacity specification, logical block storage files of the same capacity specification that are physically contiguous should be selected as much as possible (this can be achieved through...). Figure 3 The bitmap shown indicates whether free logical blocks are contiguous in physical address, in order to improve the read and write performance of the file system.

[0085] In some optional implementations, step S11 described above includes the following steps:

[0086] Based on the data volume of the file to be stored and the statistical results of free logical blocks, determine the minimum capacity required to store the file; based on the data volume of the file and the minimum capacity, determine candidate storage strategies.

[0087] Continuing with the previous example, let x be the amount of data in the file to be stored in the file system. The statistics for free logical blocks are shown in Table 1. When determining the minimum capacity required to store the file, a bottom-up selection method is used, as follows:

[0088] First, based on the minimum capacity specification F1 and the data volume x, determine the number of F1 logical blocks required to store the file using (free) F1 logical blocks.

[0089]

[0090] in, The above formula represents the expression for The value is rounded up, for example

[0091] Compare and Size.

[0092] like The minimum capacity required to store the file.

[0093] like After fully retrieving all available F1 logic blocks (i.e., retrieving all available F1 logic blocks from the logic block pool), continue retrieving (available) F2 logic blocks upwards, and determine the number of F2 logic blocks still needed.

[0094]

[0095] in,

[0096] Compare and Size.

[0097] like The minimum capacity required to store the file.

[0098] like Based on the fully available F1 and F2 logic blocks, continue to select (available) F3 logic blocks upwards, and determine the number of F2 logic blocks still needed.

[0099]

[0100] in,

[0101] Compare and Size.

[0102] By analogy, determine whether it is necessary to retrieve a free logic block from above.

[0103] Total capacity until the free logic blocks are retrieved Or until all free logical blocks in the logical block pool have been retrieved.

[0104] If z is still less than x after all free logical blocks in the logical block pool have been retrieved, it means that the remaining storage resources in the storage device are insufficient to store the file with a data size of x. In other words, the file system fails to determine the candidate storage strategy and there is no candidate storage strategy that can be used to store the file with a data size of x. At this time, a prompt message indicating insufficient remaining space can be output, such as displaying "Insufficient remaining space on the disk (the file system is mounted on the disk)" in a pop-up window to prompt the user that there is insufficient remaining space on the storage device to store the file.

[0105] Secondly, candidate storage strategies are determined based on the data volume x and minimum capacity z of the file to be stored.

[0106] At this point, the termination state can be... Determined as S(i) stop Therefore, it is only necessary to determine the state from the initial state S(0, 0) to the final state S(i, z). stop The candidate storage strategy can be determined by considering all the possible paths between z).

[0107] Taking the aforementioned example of storing a 270MB file and its file system, the number of F1 logical blocks required in this example... :

[0108]

[0109] Clearly, 6 < 10 (10 is the number of F1 logic blocks in the idle state), therefore z = 6 × 50 = 300; therefore, the termination state is S(i stop Next, determine the state from the initial state S(0, 0) to the final state S(i, 300). stop All feasible paths between (300) are as follows:

[0110]

[0111]

[0112]

[0113]

[0114] The above transfer process can also be used Figure 5 The state transition diagram shown is used for description.

[0115] As can be seen from the foregoing description, this implementation method can effectively reduce the amount of computation (from 12 paths to 4 paths) in the process of determining feasible paths from the initial state to the final state, thereby improving the efficiency of determining candidate storage strategies and enhancing the performance of the file system.

[0116] In some alternative implementations, the method further includes the following after step S13:

[0117] Create a directory entry for the file in the file system.

[0118] This involves creating directory entries for the files stored in the data area of ​​the file system's information area, allowing users to easily access the files. Optionally, the value of the file's starting address field recorded in the directory entry is the starting address of the logical block formed by combining the files.

[0119] Optionally, the method further includes:

[0120] In the logical block descriptor table, the status of the logical block occupied by the file is changed to occupied; the logical block descriptor table records the attribute information of all logical blocks.

[0121] Additionally, the usage status of the corresponding logical blocks can be modified in the bitmap to determine the candidate storage strategy when storing files later.

[0122] In some optional implementations, the method further includes:

[0123] In the case of deleting the file, the directory entry is removed from the file system, the logical block occupied by the file is released, and the occupied status of the released logical block is changed to free in the logical block descriptor table.

[0124] In some optional implementations, the method further includes the following steps prior to step S11:

[0125] Read the logical block descriptor table;

[0126] The validity of the at least one logical block is checked based on the logical block descriptor table.

[0127] If the check result is that at least one logical block is valid, the process of determining a candidate storage strategy for storing the file from the free logical blocks is performed based on the data volume of the file to be stored and the statistical results of the free logical blocks.

[0128] For example, the `head` portion of the logical block descriptor table is read to check if the version meets the requirements and if the number of logical blocks is correct; the `RO Area` portion of the logical block descriptor table is read to check for overlapping logical blocks, correct block numbers, and addresses exceeding device limits; the `RWArea` portion of the logical block descriptor table is read to check for loops / intersections in the linked lists of logical blocks, and whether each used logical block linked list has a corresponding directory entry; otherwise, it is considered a missing logical block linked list. After confirming the validity of the logical blocks in the file system, the step of storing the file in the file system, i.e., step S11, is then executed.

[0129] In this embodiment of the application, files are stored only after it is confirmed that the file system is normal, so as to avoid the phenomenon that storing files to an abnormal file system will cause file corruption and data loss.

[0130] The file storage method provided in this application can be executed by a file storage device. This application uses a file storage device executing the file storage method as an example to illustrate the file storage device provided in this application.

[0131] like Figure 6 The diagram shows a structural schematic of a file storage device provided in an embodiment of this application. Please refer to [link / reference]. Figure 6 The file storage device 120 includes:

[0132] The first determining module 121 is used to determine a candidate storage strategy for selecting logical blocks from the free logical blocks to store the file based on the data volume of the file to be stored and the statistical results of the free logical blocks; the free logical blocks are at least one logical block that is in a free state from the data area of ​​the file system in advance, and the at least one logical block includes at least one logical block of at least one capacity specification.

[0133] The second determining module 122 is used to determine a target storage strategy that meets preset conditions from all candidate storage strategies when at least one candidate storage strategy has been determined.

[0134] The first storage module 123 is used to select logical blocks that match the target storage strategy from the free logical blocks and store the file in blocks into the selected logical blocks;

[0135] The preset conditions include: Condition 1: When selecting logic blocks according to each candidate strategy, the number of logic blocks selected by the target candidate strategy is the minimum.

[0136] In some optional implementations, the preset conditions further include: Condition 2, when storing the file according to each candidate strategy, the redundancy capacity of the target storage strategy is the lowest; and the target storage strategy is a candidate storage strategy that also satisfies Condition 1, selected from the candidate storage strategies that preferentially satisfy Condition 2.

[0137] In some optional implementations, the first determining module 121 includes:

[0138] The first determining submodule is used to determine the minimum capacity required to store the file based on the data volume of the file to be stored and the statistical results of the free logical blocks;

[0139] The second determining submodule is used to determine candidate storage strategies based on the data volume of the file and the minimum capacity.

[0140] In some alternative embodiments, the file storage device 120 further includes:

[0141] The first creation module is used to create directory entries for the file in the file system.

[0142] In some alternative embodiments, the file storage device 120 further includes:

[0143] The first modification module is used to modify the status of the logical blocks occupied by the file to occupied in the logical block descriptor table; the logical block descriptor table records various attribute information of all logical blocks.

[0144] In some alternative embodiments, the file storage device 120 further includes:

[0145] The first deletion module is used to delete the directory entry from the file system when the file is deleted, release the logical block occupied by the file, and modify the occupied status of the released logical block to free in the logical block descriptor table.

[0146] In some alternative embodiments, the file storage device 120 further includes:

[0147] The first output module is used to output a prompt message indicating insufficient remaining space when it is determined that there are no candidate strategies.

[0148] In some alternative embodiments, the file storage device 120 further includes:

[0149] The first reading module is used to read the logical block descriptor table;

[0150] The first checking module is used to check the legality of the at least one logical block according to the logical block descriptor table;

[0151] The first execution module is configured to, if the check result is that the at least one logical block is valid, execute the step of determining a candidate storage strategy for selecting logical blocks from the free logical blocks to store the file based on the data volume of the file to be stored and the statistical results of the free logical blocks.

[0152] In some alternative implementations, the capacity specifications at each level of the at least one capacity specification are arranged in a geometric sequence.

[0153] The file storage device 120 in this embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or any other device besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine, etc. This embodiment does not specifically limit the specific type of device.

[0154] The file storage device 120 in this embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this embodiment does not specifically limit its use.

[0155] The file storage device 120 provided in this embodiment can achieve... Figure 4 The various processes implemented in the method implementation examples will not be described again here to avoid repetition.

[0156] In some alternative implementations, such as Figure 7 As shown, this application embodiment also provides an electronic device 130, including a processor 131 and a memory 132. The memory 132 stores a program or instructions that can run on the processor 131. When the program or instructions are executed by the processor 131, they implement the various steps of the above-described file storage method embodiment and can achieve the same technical effect. To avoid repetition, they will not be described again here.

[0157] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.

[0158] Figure 8 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of this application.

[0159] The electronic device 140 includes, but is not limited to, components such as: a radio frequency unit 141, a network module 142, an audio output unit 143, an input unit 144, a sensor 145, a display unit 146, a user input unit 147, an interface unit 148, a memory 149, and a processor 1410. Those skilled in the art will understand that the electronic device 140 may also include a power supply (such as a battery) for powering the various components. The power supply can be logically connected to the processor 1410 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. Figure 8 The electronic device structure 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.

[0160] The processor 1410 is used for:

[0161] Based on the data volume of the file to be stored and the statistical results of the free logical blocks, a candidate storage strategy is determined to select logical blocks from the free logical blocks to store the file; the free logical blocks are at least one logical block that is in a free state from the data area of ​​the file system in advance, and the at least one logical block includes at least one logical block of at least one capacity specification.

[0162] Given at least one candidate storage strategy, select the target storage strategy that meets the preset conditions from all candidate storage strategies.

[0163] Select a logical block from the free logical blocks that matches the target storage strategy, and store the file in the selected logical block.

[0164] The preset conditions include: Condition 1: When selecting logic blocks according to each candidate strategy, the number of logic blocks selected by the target candidate strategy is the minimum.

[0165] It should be understood that, in this embodiment, the input unit 144 may include a graphics processing unit (GPU) 1441 and a microphone 1442. The GPU 1441 processes image data of still images or videos obtained by an image capture device (such as a camera) in video capture mode or image capture mode. The display unit 146 may include a display panel 1461, which may be configured in the form of a liquid crystal display, an organic light-emitting diode, or the like. The user input unit 147 includes at least one of a touch panel 1471 and other input devices 1472. The touch panel 1471 is also called a touch screen. The touch panel 1471 may include a touch detection device and a touch controller. Other input devices 1472 may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, and joysticks, which will not be described in detail here.

[0166] The memory 149 can be used to store software programs and various data. The memory 149 may primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area may store the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, the memory 149 may include volatile memory or non-volatile memory, or both. 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 flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct memory bus RAM (DRRAM). The memory 149 in the embodiments of this application includes, but is not limited to, these and any other suitable types of memory.

[0167] Processor 1410 may include one or more processing units; optionally, processor 1410 integrates an application processor and a modem processor, wherein the application processor mainly handles operations involving the operating system, user interface, and applications, and the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into processor 1410.

[0168] Each of the above product embodiments can implement the various processes of the above file storage method embodiments through its own processor, and can achieve the same technical effect. To avoid repetition, they will not be described in detail.

[0169] This application also provides a readable storage medium storing a program or instructions. When executed by a processor, the program or instructions implement the various processes of the above-described file storage method embodiments and achieve the same technical effects. To avoid repetition, these will not be described again here. The processor is the processor in the electronic device or electronic system described in the above embodiments. The readable storage medium includes a computer-readable storage medium, such as a computer read-only memory (ROM), random access memory (RAM), a magnetic disk, or an optical disk.

[0170] This application embodiment also 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 the various processes of the above-described file storage method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0171] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.

[0172] This application provides a computer program product that is stored in a storage medium and executed by at least one processor to implement the various processes of the file storage method embodiments described above, and achieves the same technical effects. To avoid repetition, further details are omitted here.

[0173] In the embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.

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

[0175] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0176] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application embodiment, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0177] The above descriptions are merely embodiments of this application and do not limit the patent scope of this application. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art, under the guidance of this application, may make equivalent structural or procedural transformations based on the description and drawings of the embodiments of this application, or directly or indirectly apply them to other related technical fields, without departing from the spirit and scope of protection of the claims. All such transformations are similarly included within the patent protection scope of the embodiments of this application.

Claims

1. A file storage method, characterized in that, The method includes: Based on the data volume of the file to be stored and the statistical results of the idle logical blocks in the at least one logical block of at least one capacity size that are in an idle state, which are pre-divided from the data area of ​​the file system, a candidate storage strategy is determined to select logical blocks from the idle logical blocks to store the file. Given at least one candidate storage strategy, select the target storage strategy that meets the preset conditions from all candidate storage strategies; Select a logical block from the free logical blocks that matches the target storage strategy, and store the file in the selected logical block. The preset conditions include: Condition 1: When selecting logic blocks according to each candidate strategy, the number of logic blocks selected by the target candidate strategy is the minimum.

2. The method according to claim 1, characterized in that, in, The preset conditions also include: Condition 2, when storing the file according to each candidate strategy, the redundancy capacity of the target storage strategy is the lowest; and the target storage strategy is a candidate storage strategy that is selected from the candidate storage strategies that first satisfy Condition 2 and also satisfy Condition 1.

3. The method according to claim 1 or 2, characterized in that, The step of determining a candidate storage strategy for selecting logical blocks from the free logical blocks to store the file, based on the data volume of the file to be stored and the statistical results of the free logical blocks, includes: Based on the data volume of the file to be stored and the statistical results of free logical blocks, determine the minimum capacity required to store the file; Candidate storage strategies are determined based on the data volume of the file and the minimum capacity.

4. The method according to claim 1 or 2, characterized in that, After storing the file in blocks into selected logical blocks, the method further includes: Create a directory entry for the file in the file system.

5. The method according to claim 4, characterized in that, After storing the file in blocks into selected logical blocks, the method further includes: In the logical block descriptor table, the status of the logical block occupied by the file is changed to occupied; the logical block descriptor table records the attribute information of all logical blocks.

6. The method according to claim 5, characterized in that, The method further includes: In the case of deleting the file, the directory entry is removed from the file system, the logical block occupied by the file is released, and the occupied status of the released logical block is changed to free in the logical block descriptor table.

7. The method according to claim 1 or 2, characterized in that, The method further includes: Read the logical block descriptor table; The validity of the at least one logical block is checked based on the logical block descriptor table; If the check result is that at least one logical block is valid, the process of determining a candidate storage strategy for storing the file from the free logical blocks is performed based on the data volume of the file to be stored and the statistical results of the free logical blocks.

8. A file storage device, characterized in that, The device includes: The first determining module is used to determine a candidate storage strategy for selecting logical blocks from the free logical blocks to store the file based on the data volume of the file to be stored and the statistical results of the free logical blocks in the at least one logical block including at least one capacity specification that are in a free state, which are pre-divided from the data area of ​​the file system. The second determining module is used to determine the target storage strategy that meets the preset conditions from all candidate storage strategies when at least one candidate storage strategy has been determined. The first storage module is used to select logical blocks that match the target storage strategy from the free logical blocks, and store the file in blocks into the selected logical blocks; The preset conditions include: Condition 1: When selecting logic blocks according to each candidate strategy, the number of logic blocks selected by the target candidate strategy is the minimum.

9. An electronic device, characterized in that, The electronic device includes a processor and a memory, the memory storing a program or instructions executable on the processor, the program or instructions being executed by the processor to implement the steps of the file storage method as described in any one of claims 1 to 7.

10. A computer-readable storage medium / computer program product, characterized in that, A program or instructions are stored on the computer-readable storage medium, and when the program or instructions are executed by a processor, they implement step two of the file storage method as described in any one of claims 1 to 7. The computer program product includes a program or instructions that, when executed by a processor, implement the steps of the file storage method as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • File system fragmentation method and device

    CN111209257A

  • Data storage method and device, computer equipment and storage medium

    CN114661249A