File storage method and device, equipment, medium and program
By pre-dividing logical blocks of multiple capacity specifications in the file system and selecting the optimal storage strategy based on the file data volume and the statistical results of the idle logic block, the problem of file system fragmentation is solved and the read and write performance is improved.
Patent Information
- Application Number
- CN202410949688.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2024-12-17
- Estimated Expiration
- 2044-07-15
AI Technical Summary
Frequent concurrent write operations lead to high degree of fragmentation of the file system, which in turn affects read and write performance.
By pre-dividing logical blocks of multiple capacity specifications, and based on the data amount of files to be stored and the statistical results of the free logical blocks, the storage strategy that occupies the least logical blocks is selected to store files in chunks, reducing the degree of fragmentation of the file system.
It effectively reduces the degree of fragmentation of the file system and improves the read and write performance of the file system, especially in concurrent read and write situations.
Smart Images

Figure CN119148925A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, more specifically to the field of computer operating systems, and in particular to a file storage method, device, equipment, medium and program. Background Art
[0002] Computer operating systems usually provide a file system. The file system is the method and data structure used by the operating system to identify files on storage devices (usually disks) or partitions; that is, the method of organizing files on storage devices. From the operating system's perspective, the file system is a system that organizes and allocates space on storage devices, is responsible for file storage, 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 revoking files when users no longer use them.
[0003] However, frequently writing different files to the file system concurrently (such as DVR multi-channel recording) often leads to frequent application and release of small blocks of space, which causes the file system to be filled with a large number of small blocks of space, resulting in a high degree of file system fragmentation. If the file system is too fragmented, it may not only cause the problem of frequent random read and write, but also may cause write amplification problems on some storage devices, thus seriously reducing the read and write performance of the file system. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a file storage method, apparatus, device, medium, chip and computer program product, which can to a certain extent solve the technical problem of high degree of file system fragmentation caused by concurrent reading and writing of the file system.
[0005] A first aspect of an embodiment of the present application provides a file storage method, the method comprising:
[0006] Determine, according to the statistical result of the data amount of the file to be stored and the free logical blocks, a candidate storage strategy for selecting a logical block from the free logical blocks to store the file; the free logical block is a logical block in an idle state from at least one logical block pre-divided from the data area of the file system, and the at least one logical block includes a logical block of at least one capacity specification;
[0007] When at least one candidate storage strategy is determined, a target storage strategy that meets a preset condition is determined from all candidate storage strategies;
[0008] Selecting a logic block matching the target storage policy from the free logic blocks, and storing the file blocks in the selected logic 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 least.
[0010] A second aspect of an embodiment of the present application provides a file storage device, the device comprising:
[0011] A first determination module is used to determine a candidate storage strategy for selecting a logical block from the free logical blocks to store the file according to the data amount of the file to be stored and the statistical result of the free logical blocks; the free logical block is a logical block in an idle state in at least one logical block pre-divided from the data area of the file system, and the at least one logical block includes a logical block of at least one capacity specification;
[0012] A second determination module is used to determine a target storage strategy that meets a preset condition from all candidate storage strategies when at least one candidate storage strategy is determined;
[0013] A first storage module, configured to select a logic block matching the target storage policy from the free logic blocks, and store the file blocks in the selected logic block;
[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 least.
[0015] A third aspect of an embodiment of the present application provides an electronic device, comprising: a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the program or instructions are executed by the processor, the steps of the file storage method described in the first aspect are implemented.
[0016] A fourth aspect of 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 storage method described in the first aspect are implemented.
[0017] A fifth aspect of an embodiment of the present application provides a chip, comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run a program or instruction to implement the file storage method as described in the first aspect.
[0018] A sixth aspect of 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 file storage method as described in the first aspect.
[0019] In an embodiment of the present application, at least one logical (area) block is pre-divided from the data area of the file system, and the divided logical blocks have at least one capacity specification. When writing files to the data area of the file system, the files are stored in blocks in the pre-divided logical blocks; and when writing files (i.e., files to be stored), according to the data volume of the files and the statistical results of the free logical blocks in the file system, the optional candidate storage strategies are determined, and the candidate storage strategy with the least occupied logical blocks is selected from the optional candidate storage strategies as the target storage strategy, and then the logical blocks are selected from the free logical blocks according to the target storage strategy to store the files. Thus, the logical blocks occupied each time a file is written to the file system are as few as possible, and even if the file system is read and written concurrently, the storage strategy that occupies as few logical blocks as possible will always be used to store the files, thereby effectively reducing the degree of fragmentation of the file system. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 It is a schematic diagram of dividing logical blocks from a data area of a file system provided by an embodiment of the present application;
[0021] Figure 2 It is a structural diagram of a file system provided in an embodiment of the present application;
[0022] Figure 3 yes Figure 1 A bitmap of a logic block with medium capacity specification F0;
[0023] Figure 4 is a flowchart of a file storage method provided by an embodiment of the present application;
[0024] Figure 5 This is a state diagram corresponding to the storage of an example file provided in an embodiment of the present application;
[0025] Figure 6 is a structural schematic diagram of a file storage device provided in an embodiment of the present application;
[0026] Figure 7 The present application also provides a schematic diagram of the structure of an electronic device;
[0027] Figure 8 The embodiment of the present application also provides a structural schematic diagram of another electronic device. DETAILED DESCRIPTION
[0028] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.
[0029] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable when appropriate, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0030] The file storage method, device, equipment, storage medium, chip and computer program product provided in the embodiments of the present application can effectively solve the technical problem of high file system fragmentation caused by concurrent reading and writing of the file system.
[0031] The file system usually includes an information area and a data area. The data area is used to store files logically, and the information area is used to store relevant information of the files stored in the data area (such as file name, file size, file location, etc.). In the embodiment of the present application, at least one logical block is pre-divided from the data area of the file system, and the divided logical blocks include at least one capacity specification.
[0032] For example, Figure 1 , which shows a schematic diagram of dividing logical blocks from the data area of the file system provided by an embodiment of the present application. Figure 1 , illustratively, four types of logical blocks with capacity specifications are divided from the data area of the file system, namely, capacity specifications F1, F2, F3 and F4, wherein F4>F3>F2>F1. Of course, in some other embodiments, more (or fewer) types of logical blocks with capacity specifications may be divided from the data area of the file system, for example, five, six or more types of logical blocks with capacity specifications may be divided from the data area of the file system, or three, two or fewer types of logical blocks with capacity specifications may be divided from the data area of the file system. In the embodiment of the present application, there is no specific limitation on the number of types of capacity specifications of the logical blocks divided from the data area of the file system.
[0033] In some optional implementations, the capacity specifications of each level in the at least one capacity specification are arranged in a geometric progression, that is, the capacity specifications of each level of the logic blocks divided from the data area in the file system are arranged in a geometric progression.
[0034] For example, Figure 1The sequence of capacity specifications of each level of the logic block shown in is a geometric sequence, that is, the sequence F1, F2, F3, F4 is a geometric sequence. Assuming that their 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 + represents a set of positive integers. Optionally, q=2. Of course, q can also be other positive integers greater than 2, such as q=3 or q=4.
[0035] In some optional implementations, the file system will create logical blocks and corresponding logical block descriptor tables according to pre-set parameters (these parameters include at least parameters related to dividing logical blocks from the data area of the file system, such as the size of the logical block pool, the capacity specifications of logical blocks at each level, the number of logical blocks at each level, etc.; wherein the logical block pool is a collection of all logical blocks, and the size of the logical block pool is the sum of the capacities of all logical blocks.) when formatting. The logical block descriptor table records the relevant information of the logical blocks. The logical block descriptor table is stored in a reserved area in the file system (such as the information area of the file system). It should be noted that in order to improve the access performance of the storage device, preferably, all logical blocks of the same level of capacity specifications usually occupy a continuous physical storage space on the storage device.
[0036] For example, Figure 2 As shown, Figure 2 : is a structural diagram of a file system provided by an embodiment of the present application. The file system of this example is improved on the basis of the FAT file system, wherein the Data Area block is the data area of the file system, and the logical block is divided from the block. The logical block divided from the data area can be as follows Figure 1 Please continue to refer to Figure 2 All blocks except the Data Area block are the information area of the file system. Improvements have been made within the allowable range of free space in the file system, and a logical block descriptor table (File-Entry Table) area has been added to the reserved area to record relevant information of the logical block.
[0037] Please continue to see Figure 2, File-Entry Table includes: a head area, a read-only area (RO AREA) and a readable and writable area (RW AREA). The head area records the meta-information of the logical block descriptor table, such as: the version information of the logical block descriptor table, the total number of logical blocks, the capacity of each level of capacity specifications (such as the aforementioned F1), the number of logical blocks of each level of capacity specifications, etc. The RO AREA records the levels of logical blocks of various capacity specifications, the sequence number of each logical block, the starting address of each logical block, whether each logical block is available, etc. The RW AREA records the connection information of each logical block, the occupancy status of each logical block, etc.
[0038] In some optional implementations, a free logical block table is created in the file system, and the free logical block table records the logical blocks that have not been occupied. Optionally, the free logical block table is created when the file system is mounted. Exemplarily, when mounting, the logical block descriptor table stored in the file system is loaded and read, and an index is created for each logical block (the index of a logical block includes the physical address of the physical storage space allocated to the logical block on the physical storage device, etc.), and the free logical block table is created based on the occupation 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 logical block of a capacity specification, and the bitmap records the occupation status of each logical block in the logical block of the capacity specification of that level. And the order of the bitmap blocks is consistent with the order of the physical blocks corresponding to the logical blocks (on the physical storage device). Figure 3 As shown, it is exemplarily shown Figure 1 The bitmap of the logical blocks with the capacity specification of F1 in the bitmap has a one-to-one correspondence with the logical blocks with the capacity specification of F1, that is, one bit block is used to record the occupancy status of a unique logical block with the capacity specification of F1 corresponding to it, wherein the background of the bit block corresponding to the occupied logical block is shaded, and the background of the bit block corresponding to the unoccupied logical block is transparent. Based on this exemplary bitmap, it can be seen that the logical block corresponding to bit block 301 is in an idle state, that is, it is not occupied; and the logical blocks corresponding to bit blocks 308 and bit blocks 311 are both occupied. The bitmaps corresponding to logical blocks of other capacity specifications are similar to Figure 3 The bitmap shown is similar, and those skilled in the art can understand it accordingly, and will not be described in detail here.
[0040] On this basis, the file storage method provided in the embodiment of the present application is described below.
[0041] like Figure 4FIG. 1 is a schematic diagram showing the steps of the file storage method provided by an embodiment of the present application. The file storage method comprises the following steps S11-S13:
[0042] S11, determining a candidate storage strategy for selecting a logical block from the free logical blocks to store the file according to the data amount of the file to be stored and the statistical result of the free logical blocks.
[0043] The data volume of a file is also commonly referred to as the file size, which is usually measured in bits (bit; of course, this is the smallest unit, there are also KB, MB, GB, TB, etc.). A free logical block is a logical block that is in an idle state in at least one logical block pre-divided from the data area of the file system, and the at least one logical block includes a logical block of at least one capacity specification. For details about logical blocks, free logical blocks, and the capacity specifications of logical blocks, please refer to the previous description, which 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 (that is, not yet occupied).
[0044] In some optional implementations, the data volume of the file to be stored is x, and the statistical results of the free logical blocks are shown in the following Table 1:
[0045] Table 1 Statistics of free logical blocks in the logical pool
[0046]
[0047] in, Indicates that the capacity specification of the logical block pool is F n The number of free logical blocks is indivual.
[0048] Optionally, create the following state transition:
[0049]
[0050] Among them, S(t, j t ) and S(i, j i ) represent the state, S(t, j t ) is S(i, j i ) predecessor state, S(i, j i ) is S(t, j t )'s successor state; S(t, j t ) indicates that the capacity specification F is to be selected from the logical pool r , ..., F s , ..., F t The total capacity of the selected free logical blocks is j t Similarly, S(i, ji ) indicates that the capacity specification F is to be selected from the logical pool r , ..., F s , ..., F t 、F i The total capacity of the selected free logical blocks is j i The capacity specification is F r , ..., F s The free logical block is in S(t, j t ) is selected from the logic pool; where r∈N + , s∈N + , t∈N + , i∈N + , r<s<t<i≤n; k i Indicates that the capacity specification selected from the logical pool is F i The number of free logical blocks, k i ∈N + , obviously, (That is, when selecting free logical blocks of a certain capacity specification, at most all free logical blocks of this capacity specification in the logical block pool shall be selected, and it cannot violate the laws of physics and supernaturally make the number of free logical blocks of this capacity specification selected greater than the number of free logical blocks of this capacity specification in the logical block pool).
[0051] Formula ① means: In state S(t, j t ) and then select k from the logical block pool i The capacity specification is F i The logic block, the state changes from S(t, j t ) jumps to state S(i, j i ). Obviously, j t +k i F i =j i Therefore, formula ① can also be expressed as:
[0052]
[0053] Based on the above formulas ① and ②, the following equation can also be established:
[0054]
[0055] in, is in state The total number of free logical blocks selected from the logical block pool when
[0056] In the terminated state hour, That is, in 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, so as to ensure that the file can be stored in the file system. In other words, in the extension of a "path (i.e., the jump relationship from the previous state to the next state)", when the total capacity j of the free logical blocks selected corresponding to a certain state is greater than or equal to the data size of the file to be stored, the file can be stored in the file system. i ≥x, the state can be determined as the terminal state
[0057] Based on the above Table 1, Formula ① (or Formula ②), the currently selectable candidate storage strategy is determined, that is, based on the above Formula ① (or Formula ②), the candidate storage strategy from state S (0, 0) (i.e., the initial state, no free logical block has been selected from the logical block pool) to All feasible "paths" are obtained, and each path corresponds to an optional candidate storage strategy. All available storage strategies are exhausted, that is, all candidate storage strategies are determined.
[0058] For ease of understanding, an example is used below to illustrate the present invention.
[0059] Assume that there are four free logical blocks of capacity specifications F1 = 50MB, F2 = 100MB, F3 = 200MB, and F4 = 400MB in the logical block pool. The current number of free logical blocks of capacity specifications F1, F2, F3, and F4 is 10, 20, 5, and 7, respectively. The data volume of the file to be stored is 270MB. Based on the above formula ①, the following state transition process is obtained:
[0060]
[0061]
[0062]
[0063]
[0064]
[0065]
[0066]
[0067]
[0068]
[0069]
[0070]
[0071]
[0072] It can be seen that there are currently 12 candidate storage strategies in this example, such as the above transfer process ⑤ to the transfer process As shown in the formula.
[0073] S12, when at least one candidate storage strategy is determined, a target storage strategy that meets a preset condition is determined from all candidate storage strategies. The preset condition includes: Condition 1: when selecting logic blocks according to each candidate strategy, the number of logic blocks selected by the target candidate strategy is the least.
[0074] After all optional candidate storage strategies are determined according to the state transfer equation (i.e., formula ①), the candidate storage strategy that requires the least number of free logical blocks is selected as the target storage strategy.
[0075] For example, in the above example, it is clear that the transfer process The number of free logical blocks required is minimal, that is, only one free logical block with a capacity specification of F4=400MB is required.
[0076] S13, selecting a logic block matching the target storage policy from the free logic blocks, and storing the file blocks in the selected logic block.
[0077] According to the target storage strategy, a corresponding logical block is selected from the free logical blocks in the logical block pool, and the file to be stored is divided and stored in the selected logical block.
[0078] In the above example, a free logical block with a capacity specification of F4=400MB is selected from the logical block pool to store the file with a data volume of 270MB. It should be supplemented that the file to be stored in this example does not need to be divided into blocks and can be directly stored in a 400MB logical block. However, assuming that the target storage strategy is to use a free logical block with a capacity specification of 100MB and a free logical block with a capacity specification of 200MB to store the file with a data volume of 270MB, the file can be divided into a file block with a data volume of 200MB and a file block with a data volume of 70MB, and then the 200MB file block is stored in the free logical block with a capacity specification of 200MB, and the 70MB file block is stored in the free logical block with a capacity specification of 100MB.
[0079] In an embodiment of the present application, at least one logical (area) block is pre-divided from the data area of the file system, and the divided logical blocks have at least one capacity specification. When writing files to the data area of the file system, the files are stored in blocks in the pre-divided logical blocks; and when writing files (i.e., files to be stored), according to the data volume of the files and the statistical results of the free logical blocks in the file system, the optional candidate storage strategies are determined, and the candidate storage strategy with the least occupied logical blocks is selected from the optional candidate storage strategies as the target storage strategy, and then the logical blocks are selected from the free logical blocks according to the target storage strategy to store the files. Thus, the logical blocks occupied each time a file is written to the file system are as few as possible, and even if the file system is read and written concurrently, the storage strategy that occupies as few logical blocks as possible will always be used to store the files, thereby effectively reducing the degree of fragmentation of the file system.
[0080] Contrast Japanese style It can be seen that in the formula In the state transfer process shown in FIG. 1 , although the required free logical blocks are the least, 130MB of storage space will be wasted (one free logical block will correspond to an equal storage space allocated on the storage device. When a file is stored in the free logical block, the physical storage space corresponding to the logical block is completely occupied and can no longer be used to store other data). This wasted 130MB is called redundant capacity (the so-called redundant capacity is the surplus capacity after storing a file in a free logical block); Formula In the state transfer process shown, although one more free logical block is needed, the redundant capacity generated is only 30MB. Storage resources are very valuable resources. If the effective utilization rate of storage resources is reduced just to reduce file system fragmentation, it will appear to be "loss of one thing for another". Therefore, it is preferred to reduce file system fragmentation on the basis of ensuring a high effective utilization rate of storage resources as much as possible.
[0081] To this end, the embodiments of the present application further propose that in some optional implementations, the preset conditions also include: Condition 2, when the file is stored in accordance with each candidate strategy, the redundant 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 preferentially meet Condition 2 and also meet Condition 1.
[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 first determined from these candidate storage strategies, and then the candidate storage strategy requiring the least 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 270MB file and its file system as an example, in this example, from the transfer process ⑤ to the transfer process The candidate storage strategies that satisfy condition 2 are determined from the corresponding 12 candidate storage strategies: transfer process ⑧, ⑩, Formula and The redundant capacity of these four candidate storage strategies is 30MB. Then, from the transfer process, formula ⑧, formula ⑩, Formula and The candidate storage strategy that satisfies condition 1 is determined to be the transfer process. The candidate storage strategy corresponding to the formula is to select a 100MB free logical block and a 200MB free logical block from the logical block pool to store the file, and the number of logical blocks required is 2. This reduces the fragmentation of the file system while ensuring that the storage resources have a high effective utilization rate as much as possible.
[0084] It should be noted that when selecting free logical block storage files from the logical pool, for the selection of the same capacity specification, logical block storage files of the same capacity specification that are continuous in physical address are selected as much as possible (this can be done by Figure 3 The bitmap shown in the figure determines whether the free logical blocks are continuous in physical address) so as to improve the read and write performance of the file system.
[0085] In some optional implementations, the aforementioned step S11 includes the following steps:
[0086] According to the data volume of the file to be stored and the statistical results of the free logical blocks, the minimum capacity required to store the file is determined; according to the data volume of the file and the minimum capacity, a candidate storage strategy is determined.
[0087] Still continuing with the above example, the data volume of the file to be stored in the file system is x, and the statistical results of the free logical blocks are shown in Table 1. When determining the minimum capacity required to store the file, the "bottom-up" selection method is adopted. 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 in (free) F1 logical blocks.
[0089]
[0090] in, The above formula represents The value of is rounded up, for example
[0091] Compare and size.
[0092] like The minimum capacity required to store the file
[0093] like Then, based on fully taking the free F1 logical blocks (i.e. taking all the free F1 logical blocks from the logical block pool), continue to take the (free) F2 logical blocks upwards and determine the number of F2 logical blocks needed.
[0094]
[0095] in,
[0096] Compare and size.
[0097] like The minimum capacity required to store the file
[0098] like Then, based on the full use of the free F1 logic block and F2 logic block, continue to take the (free) F3 logic block upwards, and determine the number of F2 logic blocks required.
[0099]
[0100] in,
[0101] Compare and size.
[0102] And so on, determine whether it is necessary to fetch free logical blocks upwards.
[0103] The total capacity of free logical blocks until they are taken out Or until all free logical blocks in the logical block pool are used up.
[0104] If after taking all the free logical blocks in the logical block pool, z is still less than x, it means that the remaining storage resources in the storage device are insufficient to store the file with a data volume of x, that is, 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 volume of x. At this time, a prompt message indicating insufficient remaining space can be output, such as a pop-up window displaying "Insufficient remaining space on the disk (file system mounted on the disk)" to prompt the user that the remaining space on the storage device is insufficient to store the file.
[0105] Secondly, according to the data volume x and the minimum capacity z of the file to be stored, a candidate storage strategy is determined.
[0106] At this point, the termination state can be Determined as S(i stop , z). Therefore, we only need to determine the transition from the initial state S(0,0) to the final state S(i stop , z) can determine the candidate storage strategy.
[0107] Still taking the aforementioned storage of 270MB of files and their file systems as an example, in this example, the number of F1 logical blocks required is :
[0108]
[0109] Obviously, 6<10 (10 is the number of F1 logic blocks in the idle state), so z=6×50=300; therefore, the terminal state is S(i stop , 300). Next, determine the transition from the initial state S(0,0) to the final state S(i stop , 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] Compared with the above description, it can be seen that in the process of determining the feasible path from the initial state to the terminal state, this implementation can effectively reduce the amount of calculation (from 12 paths to 4), thereby improving the efficiency of determining candidate storage strategies and improving the performance of the file system.
[0116] In some optional implementations, after step S13, the method further includes:
[0117] A directory entry for the file is created in the file system.
[0118] That is, a directory entry of the file stored in the data area is created in the information area of the file system so that the user can easily access the file. Optionally, the value of the field of the file start address recorded in the directory entry is the first address of the logical block after the file is combined.
[0119] Optionally, the method further comprises:
[0120] In the logic block descriptor table, the state of the logic block occupied by the file is changed to occupied; and the logic block descriptor table records various attribute information of all the logic blocks.
[0121] At the same time, the usage status of the corresponding logical block can also be modified in the bitmap to determine the candidate storage strategy when storing files subsequently.
[0122] In some optional embodiments, the method further comprises:
[0123] In the case of deleting the file, the directory entry is deleted from the file system, the logical block occupied by the file is released, and the occupation state of the released logical block is modified to free in the logical block descriptor table.
[0124] In some optional implementations, before step S11, the method further includes:
[0125] Read the logical block descriptor table;
[0126] According to the logic block descriptor table, checking the legitimacy of the at least one logic block;
[0127] If the checking result shows that the at least one logical block is legal, the statistical result based on the data amount of the file to be stored and the free logical blocks is executed to determine a candidate storage strategy for selecting a logical block from the free logical blocks to store the file.
[0128] For example, read the head part in the logic block descriptor table to check whether the version meets the requirements and whether the information such as the number of logic blocks is correct; read the RO Area part in the logic block descriptor table to check whether there is a problem of logic block overlap, whether the sequence number of the logic block is correct, whether the address of the logic block exceeds the device limit, etc.; read the RWArea part in the logic block descriptor table to check whether there is a problem of link list loop / intersection in the linked list composed of logic blocks, whether each used logic block linked list has a corresponding directory entry, otherwise it is considered to be a lost logic block linked list, etc. When the logic blocks in the file system are checked and confirmed to be legal, the step of storing files in the file system is executed, that is, step S11.
[0129] In the embodiment of the present application, files are stored only after it is determined that the file system is normal, so as to avoid the phenomenon that files are stored in an abnormal file system so that the files are damaged and data is lost.
[0130] The file storage method provided in the embodiment of the present application can be executed by a file storage device. In the embodiment of the present application, the file storage device provided in the embodiment of the present application is described by taking the method for executing file storage by a file storage device as an example.
[0131] like Figure 6 , which shows a schematic diagram of the structure of a file storage device provided by an embodiment of the present application. Figure 6 , the file storage device 120 comprises:
[0132] A first determination module 121 is used to determine a candidate storage strategy for selecting a logical block from the free logical blocks to store the file according to the data amount of the file to be stored and the statistical result of the free logical blocks; the free logical block is a logical block in an idle state from at least one logical block pre-divided from the data area of the file system, and the at least one logical block includes a logical block of at least one capacity specification;
[0133] The second determination module 122 is used to determine a target storage strategy that meets a preset condition from all candidate storage strategies when at least one candidate storage strategy is determined;
[0134] A first storage module 123, configured to select a logic block matching the target storage policy from the free logic blocks, and store the file blocks in the selected logic block;
[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 least.
[0136] In some optional implementations, the preset conditions also include: condition two, when the file is stored according to each candidate strategy, the redundant 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 preferentially meet condition two and also meet condition one.
[0137] In some optional implementations, the first determining module 121 includes:
[0138] A first determination submodule, used to determine the minimum capacity required to store the file according to the data volume of the file to be stored and the statistical result of the free logical blocks;
[0139] The second determination submodule is used to determine a candidate storage strategy according to the data volume of the file and the minimum capacity.
[0140] In some optional implementations, the file storage device 120 further includes:
[0141] The first creation module is used to create a directory entry of the file in the file system.
[0142] In some optional implementations, the file storage device 120 further includes:
[0143] The first modification module is used to modify the state of the logic block occupied by the file to occupied in the logic block descriptor table; the logic block descriptor table records various attribute information of all logic blocks.
[0144] In some optional implementations, the file storage device 120 further includes:
[0145] The first deletion module is used to delete the directory entry from the file system when deleting the file, release the logical block occupied by the file, and modify the occupation state of the released logical block to free in the logical block descriptor table.
[0146] In some optional implementations, the file storage device 120 further includes:
[0147] The first output module is used to output prompt information indicating that the remaining space is insufficient when it is determined that there is no candidate strategy.
[0148] In some optional implementations, the file storage device 120 further includes:
[0149] A first reading module, used for reading a logical block descriptor table;
[0150] A first checking module, configured to check the legitimacy of the at least one logic block according to the logic block descriptor table;
[0151] The first execution module is used to, when the check result shows that the at least one logical block is legal, execute the statistical result based on the data amount of the file to be stored and the free logical blocks, and determine the candidate storage strategy for selecting a logical block from the free logical blocks to store the file.
[0152] In some optional embodiments, the capacity specifications of each level in the at least one capacity specification are arranged in a geometric progression.
[0153] The file storage device 120 in the embodiment of the present application can be an electronic device or a component in the electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices other than a terminal. Exemplarily, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (augmented reality, AR) / virtual reality (virtual reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc. It can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.
[0154] The file storage device 120 in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.
[0155] The file storage device 120 provided in the embodiment of the present application can achieve Figure 4 To avoid repetition, the various processes implemented by the method embodiment are not described here.
[0156] In some optional embodiments, such as Figure 7 As shown, an embodiment of the present application also provides an electronic device 130, including a processor 131 and a memory 132, and the memory 132 stores a program or instruction that can be executed on the processor 131. When the program or instruction is executed by the processor 131, the various steps of the above-mentioned file storage method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0157] It should be noted that the electronic devices in the embodiments of the present application include the mobile electronic devices and non-mobile electronic devices mentioned above.
[0158] Figure 8 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of the present 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 appreciate that the electronic device 140 may also include a power source (such as a battery) for supplying power to each component, and the power source may be logically connected to the processor 1410 through a power management system, so as to implement functions such as managing charging, discharging, and power consumption management through the power management system. Figure 8 The electronic device structure shown in the figure does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently, which will not be described in detail here.
[0160] The processor 1410 is configured to:
[0161] Determine, according to the statistical result of the data amount of the file to be stored and the free logical blocks, a candidate storage strategy for selecting a logical block from the free logical blocks to store the file; the free logical block is a logical block in an idle state from at least one logical block pre-divided from the data area of the file system, and the at least one logical block includes a logical block of at least one capacity specification;
[0162] When at least one candidate storage strategy is determined, a target storage strategy that meets a preset condition is determined from all candidate storage strategies;
[0163] Selecting a logic block that matches the target storage policy from the free logic blocks, and storing the file blocks in the selected logic 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 least.
[0165] It should be understood that in the embodiment of the present application, the input unit 144 may include a graphics processor (Graphics Processing Unit, GPU) 1441 and a microphone 1442, and the graphics processor 1441 processes the image data of a static picture or video obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The display unit 146 may include a display panel 1461, and the display panel 1461 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 147 includes a touch panel 1471 and at least one of other input devices 1472. The touch panel 1471 is also called a touch screen. The touch panel 1471 may include two parts: a touch detection device and a touch controller. Other input devices 1472 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which will not be repeated here.
[0166] The memory 149 can be used to store software programs and various data. The memory 149 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory 149 may include a volatile memory or a non-volatile memory, or the memory 149 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory Read-Only Memory, ROM), a programmable read-only memory (Programmable ROM, PROM), an erasable programmable read-only memory (Erasable PROM, EPROM), an electrically erasable programmable read-only memory (Electrically EPROM, 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 (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM) and a direct memory bus random access memory (DRRAM). The memory 149 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.
[0167] The processor 1410 may include one or more processing units; optionally, the processor 1410 integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor 1410.
[0168] Any of the above-mentioned product embodiments can implement the various processes of the above-mentioned file storage method embodiments through its own processor operation, and can achieve the same technical effect. To avoid repetition, they will not be described one by one.
[0169] The embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by the processor, each process of the above-mentioned file storage method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it is not repeated here. Among them, the processor is the processor in the electronic device or electronic system described in the above embodiment. The readable storage medium includes a computer-readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a disk or an optical disk, etc.
[0170] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned file storage method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0171] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
[0172] An 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 the various processes of the above-mentioned file storage method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0173] In the implementation methods provided in the embodiments of the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device implementation methods described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0174] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0175] In addition, each functional unit in each implementation of the embodiment of the present 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 above integrated unit can be implemented in the form of hardware or in the form of software functional units.
[0176] If the integrated unit is implemented in the form of 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 the embodiment of the present application is essentially 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, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform all or part of the steps of the method described in each implementation method of the embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.
[0177] The above description is only an implementation method of the embodiment of the present application, and does not limit the patent scope of the embodiment of the present application. The above specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can make many forms of equivalent structures or equivalent process changes made by using the description and drawings of the embodiment of the present application, or directly or indirectly apply them in other related technical fields without departing from the scope of protection of the purpose of the present application and the claims, which are also included in the patent protection scope of the embodiment of the present application.
Claims
1. A file storage method, characterized in that: The method comprises: Determine a candidate storage strategy for selecting a logical block from the free logical blocks to store the file according to the data amount of the file to be stored and the statistical result of the free logical blocks in the free state in at least one logical block including at least one capacity specification pre-divided from the data area of the file system; When at least one candidate storage strategy is determined, a target storage strategy that meets a preset condition is determined from all candidate storage strategies; Selecting a logic block matching the target storage policy from the free logic blocks, and storing the file blocks in the selected logic 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 least.
2. The method according to claim 1, characterized in that in, The preset conditions also include: condition 2, when the file is stored according to each candidate strategy, the redundant 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 preferentially meet condition 2 and also meet condition 1.
3. The method according to claim 1 or 2, characterized in that: The step of determining, based on the data amount of the file to be stored and the statistical result of the free logical blocks, a candidate storage strategy for selecting a logical block from the free logical blocks to store the file comprises: Determine the minimum capacity required to store the file according to the data volume of the file to be stored and the statistical results of the free logical blocks; A candidate storage strategy is determined according to 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 blocks in the selected logical blocks, the method further includes: A directory entry for the file is created in the file system.
5. The method according to claim 4, characterized in that After storing the file blocks in the selected logical blocks, the method further includes: In the logic block descriptor table, the state of the logic block occupied by the file is changed to occupied; and the logic block descriptor table records various attribute information of all the logic blocks.
6. The method according to claim 5, characterized in that The method further comprises: In the case of deleting the file, the directory entry is deleted from the file system, the logical block occupied by the file is released, and the occupation state of the released logical block is modified to free in the logical block descriptor table.
7. The method according to claim 1 or 2, characterized in that: The method further comprises: Read the logical block descriptor table; According to the logic block descriptor table, checking the legitimacy of the at least one logic block; If the checking result shows that the at least one logical block is legal, the statistical result based on the data amount of the file to be stored and the free logical blocks is executed to determine a candidate storage strategy for selecting a logical block from the free logical blocks to store the file.
8. A file storage device, characterized in that: The device comprises: A first determination module is used to determine a candidate storage strategy for selecting a logical block from the free logical blocks to store the file according to the data amount of the file to be stored and the statistical result of the free logical blocks in the free state in at least one logical block including at least one capacity specification pre-divided from the data area of the file system; A second determination module is used to determine a target storage strategy that meets a preset condition from all candidate storage strategies when at least one candidate storage strategy is determined; A first storage module, configured to select a logic block matching the target storage policy from the free logic blocks, and store the file blocks in the selected logic 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 least.
9. An electronic device, characterized in that: The electronic device comprises: a processor and a memory, wherein the memory stores a program or instruction that can be run on the processor, and when the program or instruction is executed by the processor, the steps of the file storage method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium / computer program product, characterized in that: The computer-readable storage medium stores a program or instruction, and when the program or instruction is executed by the processor, the step 2 of the file storage method according to any one of claims 1 to 7 is implemented. The computer program product comprises a program or an instruction, and when the program or the instruction is executed by a processor, the steps of the file storage method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
File system fragmentation method and device
CN111209257A
Data writing and moving method, data writing and moving method, data cleaning information sending method, data writing and moving device and file system
CN113064551A
Data storage method and device, computer equipment and storage medium
CN114661249A
Data storage method, device and system
CN118227033A
Storage controller and data management method
US20070168629A1
