CN113900994B - File writing method and device - Google Patents
File writing method and device Download PDFInfo
- Publication number
- CN113900994B CN113900994B CN202111455415.4A CN202111455415A CN113900994B CN 113900994 B CN113900994 B CN 113900994B CN 202111455415 A CN202111455415 A CN 202111455415A CN 113900994 B CN113900994 B CN 113900994B
- Authority
- CN
- China
- Prior art keywords
- cluster
- allocation
- area
- subarea
- backup
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 73
- 238000013500 data storage Methods 0.000 claims abstract description 28
- 238000007726 management method Methods 0.000 claims description 36
- 230000008569 process Effects 0.000 claims description 13
- 238000004590 computer program Methods 0.000 claims description 4
- 230000002035 prolonged effect Effects 0.000 abstract description 5
- 238000011989 factory acceptance test Methods 0.000 description 16
- 238000012949 factory acceptance testing Methods 0.000 description 16
- 239000003925 fat Substances 0.000 description 16
- 238000004364 calculation method Methods 0.000 description 10
- 238000004891 communication Methods 0.000 description 10
- 238000010586 diagram Methods 0.000 description 5
- 230000004048 modification Effects 0.000 description 5
- 238000012986 modification Methods 0.000 description 5
- 230000006872 improvement Effects 0.000 description 4
- 238000012544 monitoring process Methods 0.000 description 4
- 238000005516 engineering process Methods 0.000 description 3
- 230000001502 supplementing effect Effects 0.000 description 3
- 230000003321 amplification Effects 0.000 description 2
- 230000006870 function Effects 0.000 description 2
- 238000003199 nucleic acid amplification method Methods 0.000 description 2
- 238000012545 processing Methods 0.000 description 2
- 230000003068 static effect Effects 0.000 description 2
- 239000013589 supplement Substances 0.000 description 2
- 102100029074 Exostosin-2 Human genes 0.000 description 1
- 101000918275 Homo sapiens Exostosin-2 Proteins 0.000 description 1
- 230000002159 abnormal effect Effects 0.000 description 1
- 230000005856 abnormality Effects 0.000 description 1
- 230000006978 adaptation Effects 0.000 description 1
- 230000006399 behavior Effects 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 238000004883 computer application Methods 0.000 description 1
- 230000003993 interaction Effects 0.000 description 1
- 238000012423 maintenance Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000037361 pathway Effects 0.000 description 1
- 230000004044 response Effects 0.000 description 1
- 239000007787 solid Substances 0.000 description 1
- 238000012546 transfer Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/13—File access structures, e.g. distributed indices
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/60—Information retrieval; Database structures therefor; File system structures therefor of audio data
- G06F16/61—Indexing; Data structures therefor; Storage structures
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/70—Information retrieval; Database structures therefor; File system structures therefor of video data
- G06F16/71—Indexing; Data structures therefor; Storage structures
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Software Systems (AREA)
- Multimedia (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The application provides a file writing method and a device, a data storage area is divided into a plurality of pre-allocation subareas in a storage medium in advance, and a pre-allocation information area for recording the average erasing times and the addressing duration of the pre-allocation subarea clusters is divided from the storage medium. Under the condition that a file writing requirement exists, determining a candidate pre-allocation subarea of which the average erasing times of the clusters meet the condition; and determining a target pre-allocation subarea with addressing duration satisfying the condition from the candidate pre-allocation subareas, and writing data into the target pre-allocation subarea. Thus, by determining the candidate pre-allocation subarea with lower average erasing times of the clusters each time, balanced erasing is realized, and the service life of the storage medium is prolonged; in addition, the writing efficiency is improved by determining the target preallocated subarea with shorter addressing time.
Description
Technical Field
The present application relates to the field of computer application technologies, and in particular, to a file writing method and apparatus.
Background
The storage medium is generally composed of a plurality of minimum management units (generally called clusters), and the file management system manages the storage medium by managing the plurality of clusters in the storage medium.
For some usage scenarios, the file written each time is almost large, and the maximum value of the file does not exceed a fixed value. For example, in an audio/video monitoring scene, the files stored each time are audio/video data with fixed duration. In order to increase the writing speed and avoid the problem of write amplification in such a scenario, a pre-allocation method is often adopted, in which a data storage area of a storage medium is divided into a plurality of pre-allocation sub-areas in advance according to a theoretical maximum value of each written file, each pre-allocation sub-area includes a plurality of continuous clusters, and each pre-allocation sub-area is used for storing one written file. In the case of a file writing requirement, the file management system randomly selects one pre-allocation subarea from the unused pre-allocation subareas for file writing.
The method for randomly selecting the pre-allocation sub-area in the related art causes low file writing efficiency and reduced service life of the storage medium.
Disclosure of Invention
In order to overcome the problems in the related art, the application provides a file writing method and a file writing device.
According to a first aspect of embodiments of the present application, there is provided a file writing method applied to a file management system, where a storage medium managed by the file management system at least includes: a data storage area and a pre-allocation information area; the data storage area is divided into a plurality of pre-allocation subareas in advance;
the method comprises the following steps:
under the condition that a file writing requirement exists, determining at least one candidate pre-allocation sub-area from the unused pre-allocation sub-areas according to the recorded cluster average erasing times of the unused pre-allocation sub-areas in the pre-allocation information area;
when the number of the candidate preallocation subareas is larger than a first set value, determining a target preallocation subarea from each candidate preallocation subarea according to the addressing duration of the recorded candidate preallocation subareas in the preallocation information area;
and writing a file into a target pre-allocation sub-area, and updating the cluster average erasing times of the target pre-allocation sub-area in the pre-allocation information area.
According to a second aspect of the embodiments of the present application, there is provided a file writing apparatus applied to a file management system, where a storage medium managed by the file management system at least includes: a data storage area and a pre-allocation information area; the data storage area is divided into a plurality of pre-allocation subareas in advance;
the device comprises:
the candidate preallocation subarea determining module is used for determining at least one candidate preallocation subarea from the unused preallocation subareas according to the cluster average erasing times of the unused preallocation subareas recorded in the preallocation information area under the condition that a file writing requirement exists;
the target pre-allocation subarea determining module is used for determining a target pre-allocation subarea from each candidate pre-allocation subarea according to the addressing time of the recorded candidate pre-allocation subarea in the pre-allocation information area when the number of the candidate pre-allocation subareas is larger than a first set value;
and the file writing module is used for writing a file into the target pre-allocation sub-area and updating the cluster average erasing times of the target pre-allocation sub-area in the pre-allocation information area.
According to a third aspect of embodiments of the present application, there is provided a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the file writing method described above.
According to a fourth aspect of embodiments of the present application, there is provided a computer apparatus, comprising:
one or more processors;
a memory for storing one or more programs;
when the one or more programs are executed by the one or more processors, the one or more processors implement the file writing method described above.
In one or more embodiments of the present application, a data storage area is divided into a plurality of pre-allocated sub-areas in a storage medium in advance, and a pre-allocated information area for recording average erasing times and addressing duration of the pre-allocated sub-area clusters is divided from the storage medium. Under the condition that a file writing requirement exists, determining a candidate pre-allocation subarea of which the average erasing times of the clusters meet the condition; and determining a target pre-allocation subarea with addressing duration satisfying the condition from the candidate pre-allocation subareas, and writing data into the target pre-allocation subarea. Thus, by determining the candidate pre-allocation subarea with lower average erasing times of the clusters each time, balanced erasing is realized, and the service life of the storage medium is prolonged; in addition, the writing efficiency is improved by determining the target preallocated subarea with shorter addressing time.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the application.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this application, illustrate embodiments consistent with the present application and together with the description, serve to explain the principles of the application.
FIG. 1 is a flow chart illustrating a file writing method according to an exemplary embodiment of the present application.
FIG. 2A is a schematic diagram of a storage medium format according to an embodiment of the present application.
FIG. 2B is a flowchart illustrating a file writing method according to an embodiment of the present application.
FIG. 3 is a block diagram of a file writing apparatus according to an exemplary embodiment of the present application.
Fig. 4 is a hardware configuration diagram of a computer device in which a file writing apparatus according to an exemplary embodiment is shown.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in this application and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
It is to be understood that although the terms first, second, third, etc. may be used herein to describe various information, such information should not be limited to these terms. These terms are only used to distinguish one type of information from another. For example, first information may also be referred to as second information, and similarly, second information may also be referred to as first information, without departing from the scope of the present application. The word "if" as used herein may be interpreted as "at … …" or "when … …" or "in response to a determination", depending on the context.
The storage medium is typically composed of a plurality of minimum management units, such physical minimum management units being typically referred to as clusters. For a storage medium, which requires a file management system to be responsible for managing files, a file includes several clusters in the storage medium that are managed together by the file management system. Common file management systems include FAT32, NTFS, EXT2/3, and the like.
Some storage media have an upper limit of erasure, such as flash memory, solid state disk, etc. The erase and write limits of these storage media are limited by the erase and write limits of each cluster of the storage media. When the number of times of erasing and writing of a cluster exceeds the upper limit of erasing and writing, the cluster may be unusable, and the unusable cluster is called a bad cluster. The proportion of the number of bad clusters to all clusters exceeds a certain value, which results in that the whole storage medium cannot be used.
For some scenes, such as an audio and video monitoring scene, in the scene, the file written each time is audio and video data with a fixed time length, so that the file written each time is almost large, and an upper limit value exists in the size. For the file writing scene that the file written each time is not much larger than a specific value, in order to increase the writing speed and avoid the problem of write amplification during data writing, a pre-allocation method is often adopted, and according to the theoretical maximum value of the file written each time, a data storage area of a storage medium is divided into a plurality of pre-allocation sub-areas (the size of each pre-allocation sub-area is also the theoretical maximum value of the written file), each pre-allocation sub-area comprises a plurality of continuous clusters, and each pre-allocation sub-area is used for storing one written file. Thus, when a file writing requirement exists, the file can be directly written into an unused pre-allocation subarea.
For an audio and video monitoring scene, files need to be written frequently, and the service life of a storage medium in the scene is long. For a storage medium with an upper erasure limit, the upper erasure limit of a cluster determines the service life of the storage medium, and specifically, when the number of erasures of a certain cluster reaches the upper erasure limit, the cluster cannot be used, and the unusable cluster is generally called a bad cluster. In case of a bad cluster on a certain storage medium, it may result in the storage medium being unusable. For example, in the case that a bad cluster is included in a pre-allocated sub-area, a file cannot be written into the pre-allocated sub-area, which leads to the storage medium being unable to be used normally.
In the related art, because the occurrence of a bad cluster cannot be avoided, in order to prolong the service life of a storage medium, a part of clusters are often prepared in advance in the storage medium as backup clusters, when file writing is abnormal, that is, when a file cannot be normally written due to the bad cluster in a pre-allocation sub-area, one backup cluster is selected, the bad cluster is replaced by the selected backup cluster, and then data is continuously written into the replaced pre-allocation sub-area.
Wherein, the process of replacing the bad cluster by the backup cluster, specifically, each cluster has a cluster number, the cluster numbers are generally continuous, the size of the cluster number is determined by the physical position of the cluster in the storage medium, and the closer the physical position is, the smaller the cluster number is. Each pre-allocation subarea comprises which clusters are generally represented by a cluster chain, the cluster chain comprises a plurality of cluster numbers, and a backup cluster is used for replacing a bad cluster, namely the cluster number of the bad cluster in the cluster chain is replaced by the cluster number of the backup cluster. Thus, when data is written, the data can be written according to the replaced cluster chain.
Although this way can make the bad clusters replaced, when the proportion of the bad clusters in a certain storage medium to all clusters exceeds a certain value, the storage medium can be made unusable. Therefore, in order to extend the lifetime of the storage medium, it is also necessary to reduce the speed of bad cluster generation.
Considering that, first, when many clusters have become bad clusters, the erasure times of many clusters are far from the erasure upper limit, that is, there is no method for equalizing erasures in the related art, so in the embodiment of the present application, the cluster average erasure times of each pre-allocation sub-area (that is, how many times each cluster has been erased on average) are counted, and according to the cluster average erasure times, in the case that there is a data writing demand each time, a pre-allocation sub-area with a smaller cluster average erasure times is selected to write a file. This ensures balanced erasure.
Further, for the above scenario, the data flow is large, and the requirement for file writing efficiency is high. This requires that the file writing efficiency be improved while the storage medium life is extended. Considering that addressing is needed when a file is written, namely each cluster in the pre-allocation sub-area is found, the speed of writing the file is influenced by the addressing time length, so that the file is written by selecting the pre-allocation sub-area with shorter addressing time length to improve the file writing efficiency while ensuring balanced erasing and writing. Therefore, the file writing efficiency is improved while the balanced erasing is ensured.
In other words, in one or more embodiments of the present application, the data storage area is divided into a plurality of pre-allocated sub-areas in the storage medium in advance, and the pre-allocated information area for recording the average erasing times and the addressing duration of the pre-allocated sub-area clusters is divided into the storage medium. Under the condition that a file writing requirement exists, determining a candidate pre-allocation subarea of which the average erasing times of the clusters meet the condition; and determining a target pre-allocation subarea with addressing duration satisfying the condition from the candidate pre-allocation subareas, and writing data into the target pre-allocation subarea. Thus, by determining the candidate pre-allocation subarea with lower average erasing times of the clusters each time, balanced erasing is realized, and the service life of the storage medium is prolonged; in addition, the writing efficiency is improved by determining the target preallocated subarea with shorter addressing time.
Next, a file writing method provided in the present application will be described in detail.
The file writing method shown in the embodiment of the application is applied to a file management system, and the storage medium managed by the file management system at least comprises: a data storage area and a pre-allocation information area; the data storage area is divided into a plurality of pre-allocation subareas in advance; the pre-allocation information area is used for recording the average cluster erasing times and the addressing duration of each pre-allocation sub-area.
The file management system may be a FAT32 file management system, in other words, the method of the embodiment of the present application may be improved based on a FAT32 file management system. Of course, the file management system in the embodiment of the present application may be other file management systems.
Wherein several pre-allocation sub-areas may be of the same size. The size of each pre-allocated sub-area in this case is determined by (greater than or equal to) the theoretical upper limit of the written file. For example, for the field of audio and video monitoring, if each written file is 5 minutes of audio and video data, the theoretical size of the written file can be calculated according to the audio code rate and the video code rate, and assuming that the theoretical size of the written file is about 59.62MB, the size of each pre-allocation sub-area can be set to 64MB in order to ensure that all written files can be written into the pre-allocation sub-area, so that the size of the pre-allocation sub-area is larger than that of all pre-allocation sub-areas.
The pre-allocation information area can theoretically be anywhere on the storage medium, but it is considered that it is preferable not to insert the pre-allocation information area in the middle of the pre-allocation sub-area in order to ensure the integrity and continuity of the pre-allocation sub-area (which can prevent the write-up problem and improve the writing efficiency) in the first place. Second, the pre-allocation information area is preferably not inserted in the middle of the data storage area, considering that all the pre-allocation sub-areas in the data storage area can be managed easily if they are contiguous. And thirdly, when the pre-allocation is carried out, when the last pre-allocation subzone is allocated, the remaining clusters cannot form a pre-allocation subzone, if the pre-allocation information zone is placed in the middle of the data storage zone, the calculation is increased (the last cluster is calculated before the allocation is needed), in order to reduce the calculation, after the pre-allocation is finished, when the remaining clusters cannot form a pre-allocation file, the remaining clusters can be used as the pre-allocation information zone, namely the pre-allocation information zone is placed behind the data storage zone. Finally, if the file management system in the embodiment of the present application is modified based on an existing file management system (such as FAT 32), it is better to place the pre-allocation information area after the data storage area in order to minimize the influence on the existing file management system and facilitate the modification.
The average number of times of erasing a cluster means how many times each cluster has been erased, and the addressing duration means how long it will take to address when writing.
Finally, it should be noted that, when the storage medium is mounted, the file management system needs to format the storage medium into the format described above for the subsequent file writing method to be executed normally. In other words, when the storage medium is mounted, the file management system first determines whether the storage medium is in the above-described configuration according to the format identifier stored in the storage medium, and if the storage medium is not in the above-described configuration, the file management system needs to format the storage medium into the above-described configuration.
After the description of the storage medium in the embodiment of the present application, the respective steps of the file writing method will be described next.
As shown in fig. 1, fig. 1 is a flowchart of a file writing method according to an exemplary embodiment, which includes the following steps:
Specifically, in the above steps, the candidate pre-allocation sub-area is determined according to the average cluster erasing times (the determination method of the candidate pre-allocation sub-area makes the average cluster erasing times of the candidate pre-allocation sub-area smaller), and each file writing is performed on the pre-allocation sub-area with the smaller average cluster erasing times, so that balanced erasing is realized, and the service life of the storage medium is prolonged. In addition, it should be noted that the average number of cluster erasures of the candidate pre-allocated sub-areas is less than the average number of cluster erasures of the N pre-allocated sub-areas in the data storage area. N is any value between 1 and M-1, and M is the total number of pre-allocated sub-regions.
After the purpose of the entire step is explained, the terms and sentences of the step will be explained in detail.
And reading the cluster average erasing times of each pre-allocation sub-area from the pre-allocation information area according to the cluster average erasing times of the pre-allocation sub-areas. As to how to judge whether each pre-allocated sub-area is used, whether each pre-allocated sub-area is used or not may be recorded in the pre-allocation information area. If the method in this application is based on the improvement of FAT32, then since the FAT table originally stores whether each cluster is used, it can be determined whether each pre-allocated sub-area is used according to the FAT table.
The method for determining the candidate pre-allocation sub-area may determine the pre-allocation sub-area with the cluster average erasing times smaller than a certain value as the candidate pre-allocation sub-area, may also determine the cluster average erasing times as a sequence, and determine a plurality of pre-allocation sub-areas with smaller cluster average erasing times as the candidate pre-allocation sub-area, or may determine the pre-allocation sub-area with the smallest cluster average erasing times as the candidate pre-allocation sub-area. In the last case, in the case that the number of candidate pre-allocated sub-regions is 1 (the number of pre-allocated sub-regions with the smallest cluster average erasure number is 1), the candidate pre-allocated sub-regions can be directly determined as the target pre-allocated sub-regions. The number of the preallocated sub-areas with the smallest average cluster erasing times is 1, that is, the average cluster erasing times of no other preallocated sub-areas are equal to or less than the average cluster erasing times of the preallocated sub-areas.
Finally, the calculation method of the average number of erasing/writing of the clusters will be described. The average number of times of erasing and writing a cluster may be increased by 1 each time a file is written or deleted. Considering further that for the pre-allocation sub-area, in order to ensure that the file is not written into other pre-allocation sub-areas beyond the boundary at each time of writing the file, the size of each pre-allocation sub-area is larger than the size of the written file, in order to make the calculated average number of cluster erasures more accurate at each time of writing or deleting the file, the average number of cluster erasures may be calculated based on the following method: and when the file is written in each time, calculating the average erasing times of the clusters according to the number of the clusters actually used by the written file and the total number of the clusters in the pre-allocation subarea. In other words, the cluster average number of times of erasure can be calculated according to the following formula (1):
wherein,representing the total cluster number of the pre-allocated files,it shows that the number of times of erasing and writing,indicating the number of clusters actually used by the file written by the pre-allocated sub-area,indicating the average number of times the file was last erased,and the average erasing times of the current file are shown.
And 103, when the number of the candidate preallocation subareas is larger than a first set value, determining a target preallocation subarea from each candidate preallocation subarea according to the addressing duration of the recorded candidate preallocation subareas in the preallocation information area, otherwise, determining the candidate preallocation subareas as the target preallocation subareas.
In particular, this step aims to improve the file writing efficiency. The file writing time is influenced by the addressing time, and the longer the addressing time, the slower the file writing is caused, so that when data is written in each time, in order to improve the file writing efficiency as much as possible on the basis of ensuring balanced erasing, the preallocated subarea with the shorter addressing time is selected for file writing in each time. If the number of candidate pre-allocated sub-areas is not greater than the first set value, a target pre-allocated sub-area may be determined from the candidate pre-allocated sub-areas. In addition, it should be noted that the addressing time of the target pre-allocated sub-area is shorter than the addressing time of Q pre-allocated sub-areas. Q is an arbitrary value between 1 and P-1, and P is the total number of candidate pre-allocated sub-regions.
After the purpose of the whole step 103 is explained, a specific word in the step 103 will be explained next.
The first set value may be 1 or another value.
The addressing duration represents the duration for searching the address of each cluster required to be used in the pre-allocated subarea in the file writing process. The specific calculation method may be to use the time length consumed by the last file writing as the addressing time length (if there is a backup cluster replacement, the time consumed by the backup cluster replacement needs to be subtracted from the time of file writing, and the obtained value is used as the addressing time length).
In addition, any addressing duration can also be obtained and recorded through the following steps: determining a target cluster from the pre-allocation subarea; all clusters in the pre-allocation subarea are arranged according to cluster chains, and the target cluster is not continuous with the previous cluster and/or the next cluster on the cluster chain; determining the addressing time of the target cluster according to the distance between the target cluster and the designated cluster on the cluster chain; and determining the addressing time of the pre-allocation subarea according to the addressing time of all target clusters in the pre-allocation subarea.
The calculation logic and calculation method of the above method will be explained in detail below: considering that if two clusters before and after the cluster chain in the pre-allocated sub-area are consecutive in physical address (i.e. the cluster numbers are consecutive), the addressing duration of the next cluster can be regarded as 0, and based on the above consideration, the addressing duration can be calculated only according to the non-consecutive clusters (the original pre-allocated file is physically consecutive, the non-consecutive cluster generation is caused by the replacement of the backup cluster, and the backup cluster replacement related method will be described below) in the pre-allocated sub-area and the physical location of the previous cluster and/or the next cluster. The cluster chain (a linked list obtained by sorting the cluster numbers according to the positions of the cluster numbers in the pre-allocation subareas) of each pre-allocation subarea can be recorded in the pre-allocation information area, and in the case that the embodiment of the present application is improved based on the FAT32, the cluster chain of each pre-allocation file can be acquired based on the FAT table.
Further, considering that the size of the addressing duration is the addressing speed multiplied by the addressing length, and the addressing speed is the same for different clusters in the same storage medium, the addressing duration can be expressed according to the addressing length.
Based on the above consideration, the specific addressing duration calculation method may be: and finding a cluster which is not continuous with the cluster number of the previous cluster or the next cluster from the cluster chain according to the cluster number of each cluster, if the cluster is not continuous with the previous cluster, calculating the absolute value of the physical address of the previous cluster minus the physical address of the cluster, and if the cluster is not continuous with the next cluster, calculating the absolute value of the physical address of the cluster minus the physical address of the next cluster. And adding the addressing time lengths of all discontinuous clusters for the addressing time length calculated aiming at the cluster to obtain the addressing time length of the pre-allocated subarea, namely, in the calculating process, the designated cluster refers to a previous cluster or a next cluster of a cluster chain where the cluster is located. The specific calculation method is shown in the following formula (2):
wherein,indicating the number of non-contiguous clusters in the cluster chain,representing cluster chainsThe physical address of the cluster, and, correspondingly,andrespectively representing cluster chainsCluster andphysical address of cluster number. Fb1Number in cluster chain representing all clusters discontinuous from front to back, Fb2Indicating the number in the cluster chain of all clusters not consecutive to the previous cluster, Fb3Indicating the number in the cluster chain of all clusters that are not consecutive to the next cluster,representing cluster chainsThe addressing duration of a cluster of numbers,representing the total addressing duration.
Further, considering that the variation of the addressing duration of the cluster chain is mainly caused by the relative physical position offset of the addressing start point and the discontinuous clusters, in order to simplify the calculation, the starting cluster of the data storage area is taken as the designated cluster, and after the discontinuous clusters are found, the addressing duration of each discontinuous cluster can be calculated according to the following formula (3):
wherein,a cluster number indicating a discontinuous cluster,to representThe physical address of the cluster of numbers,a start cluster representing a data storage area,all replacement cluster numbers (i.e. cluster numbers of non-contiguous clusters) representing the pre-allocated sub-area,to representThe addressing duration of the cluster. Then, the total addressing durationCan be calculated by the following formula (4):
in addition, it should be noted that, in order to facilitate the next calculation, the pre-allocation information area may also store the addressing time of each discontinuous cluster in addition to the addressing time of the whole pre-allocation sub-area.
And 105, writing a file into the target pre-allocation sub-area, and updating the cluster average erasing times of the target pre-allocation sub-area in the pre-allocation information area.
Specifically, after the target pre-allocated sub-region is determined, a file write operation is performed. And the written file has write behavior, which affects the average erasing times of the clusters, so the average erasing times of the clusters in the pre-allocated sub-area are updated.
In addition, when the file writing is completed, the state of the target pre-allocated subarea needs to be updated. If whether each pre-allocation sub-area is used is recorded in the pre-allocation information area, the state of the pre-allocation sub-area in the pre-allocation information area is correspondingly changed. If the improvement is based on FAT32, the state of the clusters of the pre-allocated sub-area needs to be modified in the FAT.
In addition to the above method, the present application also improves the backup cluster replacement and supplement method in the related art.
First, a method of backup cluster replacement will be explained: the storage medium further includes: a backup cluster area, a backup cluster information area and a cluster information area; the backup cluster area comprises at least one backup cluster, the backup cluster information area is used for recording the erasing times of the backup cluster, and the cluster information area is used for recording the identification of each cluster in the pre-allocation sub-area.
If the data storage area, the backup cluster area and the cluster information area (FAT table) are originally existing areas based on the original FAT32, the backup cluster information area and the pre-allocation information area are newly added areas, and the backup cluster information area and the pre-allocation information area can be placed at the end of the whole storage medium together with the pre-allocation information area based on the same consideration.
In addition, since the backup cluster information area needs to be changed every time the backup cluster is replaced, and similarly, the pre-allocation information area needs to be changed every time the file is written and deleted, in order to avoid frequent erasing and writing of the two areas, after the storage medium is mounted, the information of the two areas can be stored in the device memory in a limited manner, backup is performed every other period of time (for example, half an hour), that is, the information is written into the corresponding area of the storage medium, and when the storage medium is unloaded, the information of the two areas in the memory is backed up to the storage medium.
After the structure of the entire storage medium is explained, how to replace a bad cluster with a backup cluster will be explained as follows: when the target pre-allocation subarea has the condition that the file cannot be written in, determining the identifier of a bad cluster which causes the file to be written in the target pre-allocation subarea; determining a target backup cluster for replacing the bad cluster from a backup cluster area, replacing the mark of the bad cluster in the cluster information area with the mark of the target backup cluster, updating the average cluster erasing times of the target pre-allocation sub-area in the pre-allocation information area according to the erasing times of the target backup cluster recorded in the backup cluster information area, and continuing to write files.
Specifically, when a file is abnormally written, that is, a file cannot be normally written due to a bad cluster, the target backup cluster needs to be used to replace the bad cluster. The specific replacement process is to replace the cluster number (cluster identifier) of the bad cluster in the cluster chain with the cluster number of the target backup cluster, and update the average cluster erasing times according to the erasing times of the backup cluster, so that the file writing can be completed according to the more accurate average cluster erasing times when the file is written.
In addition, when the addressing duration is calculated according to the cluster number of the non-contiguous cluster, after the replacement of the target backup cluster is completed, the addressing duration of the pre-allocated sub-area where the replacement occurs needs to be updated.
It should be noted that if the improvement is made based on FAT32, after the replacement of the bad cluster by the backup cluster is completed, the state of the replaced backup cluster in the FAT needs to be modified to be allocated.
A method of determining bad cluster identity and physical location is described next: the cluster information area is also recorded with the corresponding relation between the physical position of the cluster and the identification of the cluster; the determining the identification of the bad cluster in the target pre-allocation subarea, which causes the file to be unwritable, includes: determining a logical position offset of the bad cluster relative to the target pre-allocated subregion starting cluster; determining the physical position of the bad cluster corresponding to the logical position offset according to the sequence of each cluster in the target pre-allocation sub-area recorded in the cluster information area and the physical position of the starting cluster; and determining a cluster identifier corresponding to the physical position of the bad cluster in the corresponding relation, and taking the determined cluster identifier as the identifier of the bad cluster.
In other words, the cluster chain stored in the cluster information area records the physical position of each cluster in addition to the order and cluster number of each cluster (of course, since the size of each cluster is fixed, the physical position of each cluster may be calculated from the start position of cluster No. 1 and the cluster number). For convenience of explanation, the contents described in the cluster chain will be explained by the following table:
1 | 2 | 3 | 4 | …… | |
cluster number | 1 | 3 | 5 | 6 | …… |
Physical address | A | C | E | F | …… |
In the above table, the first row represents the order of the clusters in the cluster chain, the second row represents the actual cluster number of each cluster in the cluster chain, and the third row represents the physical location of each cluster. In the example of the above table, the cluster numbers of the second row are not consecutive, so that the physical addresses of the third row are not represented by continuous english alphabets, but by discontinuous english alphabets, the physical addresses corresponding to the discontinuous cluster numbers are not consecutive. When a bad cluster is found, the file management system only knows that the current bad cluster is the several clusters (logical position offset) of the whole pre-allocated file, and can determine the physical address of the bad cluster according to the sequence and the physical address of each cluster in a cluster chain stored in a cluster information area, and further determine the cluster number according to the physical address. Of course, the above process may also be directly determining the cluster number of the bad cluster according to the sequence of each cluster in the cluster chain, and then determining the physical address of the bad cluster according to the cluster chain after determining the cluster number.
In addition, in the above process, because the bad cluster is to be replaced, no matter the identification of the bad cluster or the physical address of the bad cluster is determined first, the whole process needs to determine one and then determine the other, otherwise, the replacement of the bad cluster to the backup cluster cannot be completed without the identification of the bad cluster or the physical address. Of course, the same is true for the backup cluster, and when the backup cluster is replaced, the physical address of the backup cluster needs to be determined.
The selection of replacing the cluster number in the cluster chain instead of deleting the cluster number of the bad cluster and supplementing the cluster number of the backup cluster to the end is considered that the cluster chain generally exists in a linked list form, and if the latter method is selected, the positions of all clusters in the cluster chain after the bad cluster need to be modified, so that the modification becomes troublesome, and therefore, the replacement mode is selected to replace the bad cluster into the backup cluster.
After describing the method for replacing the bad cluster by the backup cluster, the embodiment of the present application will also describe a method for supplementing the backup cluster.
Determining a target backup cluster for replacing the bad cluster from the backup cluster area comprises: determining the number of backup clusters in the backup cluster area; and when the number of the backup clusters is greater than or equal to a preset threshold value, determining a target backup cluster for replacing the bad cluster from the backup cluster area, otherwise, adding at least one backup cluster to the backup cluster area, and determining a target backup cluster for replacing the bad cluster from the recorded backup cluster in the backup cluster area and the newly added backup cluster.
Specifically, when a target backup cluster is determined, the number of backup clusters is determined, when the number of backup clusters is greater than or equal to a preset threshold, the target backup cluster is determined directly from a backup cluster area, if the number of backup clusters is less than the preset threshold, a new backup cluster is added, and then the target backup cluster is determined. The preset threshold may be 1, or may be other values.
The method for adding the backup cluster can release at least one pre-allocation subarea and take the cluster of the released at least one pre-allocation subarea as the backup cluster.
The method for adding the backup cluster can also be as follows: determining at least one reference pre-allocation subarea according to the cluster average erasing times of the unused pre-allocation subareas recorded in the pre-allocation information area; and newly adding at least one cluster in the reference pre-allocation sub-area as a backup cluster and recording the backup cluster area, recording the erasing times of the newly added backup cluster in the backup cluster information area, and deleting the related record of the reference pre-allocation sub-area from the pre-allocation information area.
Specifically, if a backup cluster is newly added by releasing any one of the pre-allocation sub-areas, the priority of the release is not considered, which may cause the pre-allocation sub-area with a smaller cluster average erasing frequency and higher read-write efficiency to be preferentially released, so that the cluster average erasing frequency of the remaining pre-allocation sub-areas is larger, or the read-write efficiency is lower, and the pre-allocation sub-area with a larger cluster average erasing frequency is more likely to have a bad cluster, which may cause the pre-allocation sub-area without a bad cluster to be preferentially released, which may cause the usable pre-allocation sub-area to have a bad cluster or lower read-write efficiency, which may cause the erasing speed to be slow, the slow erasing to be slow, and finally the audio/video storage data to be lost.
In order to solve the above problem, in the embodiment of the present application, when releasing the pre-allocation sub-region, the pre-allocation sub-region with a relatively large average erasing frequency is preferentially released, so that slow-erasing and slow-writing of the remaining pre-allocation sub-regions are prevented. And correspondingly updating the pre-allocation information area and the backup cluster information area after the release.
In addition, further, under the condition that the average erasing times of a plurality of pre-allocation subarea clusters meet the set condition, the pre-allocation subarea with longer addressing time length is preferentially selected for releasing, so that the slow erasing and slow writing caused by releasing the pre-allocation subarea with higher erasing efficiency (shorter addressing time length) are prevented.
In other words, said determining at least one reference pre-allocated sub-area based on the average number of cluster erasures of unused pre-allocated sub-areas recorded by said pre-allocated information area comprises: determining the number of pre-allocation sub-areas with cluster average erasing times meeting set conditions in the unused pre-allocation sub-areas according to the cluster average erasing times of the unused pre-allocation sub-areas recorded in the pre-allocation information area; when the number is a second set value, determining the pre-allocation subarea meeting the set condition as the reference pre-allocation subarea; and when the number is larger than a second set value, according to the addressing time length in each pre-allocation subarea which is recorded in the pre-allocation information area and meets the set condition, determining the pre-allocation subarea of which the addressing time length meets the set time length from each pre-allocation subarea which meets the set condition, and determining the pre-allocation subarea of which the addressing time length meets the set time length as the reference pre-allocation subarea.
In addition, as for how to update the erasure count of the newly added backup cluster, the cluster average erasure count may be taken as the erasure count of each cluster.
Further, in order to improve the accuracy of the calculated erasing times, the erasing times of the backup cluster can be updated by the following method: the pre-distribution information area also stores the erasing times of each cluster; the increasing of the erasing times of the newly added backup cluster in the backup cluster information area comprises the following steps: and determining the erasing times of each cluster in the pre-distribution subarea with the largest average erasing times of the clusters from the pre-distribution information area, and taking the acquired erasing times as the erasing times of the newly added clusters in the backup cluster information area.
Therefore, the pre-allocation subarea with high erasing frequency and low reading and writing efficiency is preferentially released, and other pre-allocation subareas can be ensured to be continuously used.
By balanced erasing, the service life of the storage medium is prolonged, the erasing efficiency is judged by addressing duration, and the written pre-allocation sub-area is selected according to the erasing efficiency, so that the file writing efficiency is improved, and the equipment maintenance cost of a user is reduced. Compared with the balanced erasing method in the related art, the balanced erasing is only carried out according to the erasing times of each pre-distribution sub-area, the cluster is deepened into the embodiment, the erasing times are counted, the cluster average erasing times of the pre-distribution sub-areas are calculated, then the erasing of each pre-distribution file is distributed more accurately, and the service life of each pre-distribution sub-area is balanced. And, this application has further added the management method of the cluster, estimate the erasing and writing efficiency of the sub-area of pre-allocation according to addressing duration. When the backup cluster pool is insufficient, the cluster supplement backup cluster pool of the file with higher average erasing frequency and lower reading and writing efficiency is released, and the erasing and writing efficiency of the whole pre-allocated file is improved.
Next, a file writing method shown in the present application will be described by a specific embodiment.
In the FAT32 file management system, first, when the format of the storage medium is not the required format, the storage medium is formatted, and a backup cluster information area and a pre-allocation information area are added to the format of the FAT32 storage system. The format of the formatted storage medium is shown in fig. 2A.
The reserved sector contains the boot record of the operating system, including some basic file system information, especially its type and other pointers to other sectors, and the boot call code of the operating system. The root directory area stores a directory table storing file and directory information. The FAT area, i.e. the cluster information area above, is important to manage the files and free clusters in the storage space, so that two identical FATs are kept to ensure that the second header can be used in time when the first one is damaged.
The data storage area occupies most of the storage medium, stores user data, and stores data in cluster units after being located in the FAT area, and the number is numbered from 2, that is, the starting position of cluster number 2 is the real starting position of the data area. In addition, the data storage area in fig. 2A is divided into a plurality of pre-allocated sub-areas by dashed lines, and of course, the number of pre-allocated sub-areas in fig. 2A does not represent a limitation to the pre-allocated sub-areas in the embodiment of the present application.
The cluster pool management area stores the related information of the clusters, including a backup cluster area, a backup cluster information area and a pre-allocation information area. Wherein the backup cluster area contains backup clusters for replacing the bad clusters. The backup cluster information area stores attribute information of each cluster in the backup cluster area, such as: cluster number, erase and write times, and cluster physical address. The pre-distribution information area stores the cluster average erasing times, the total addressing time, each erasing time and each discontinuous cluster addressing time of the pre-distribution subarea.
It should be noted that the frame size ratio of the different areas in fig. 2A does not represent the ratio of the area in the actual storage medium.
After the description of the configuration of the storage medium, a file writing method will be described next. As shown in fig. 2B, fig. 2B is a flowchart of a file writing method according to an embodiment of the present application, including the following steps:
And step 204, writing data in the determined pre-allocation subarea.
And step 206, recording the logic position offset of the bad cluster, and determining the cluster number and the physical position of the bad cluster according to the FAT table.
Specific methods of determination are detailed above.
And step 208, releasing the pre-allocated subarea with the largest average erasing times and the longest total addressing time, supplementing the backup clusters, and updating the FAT area, the backup cluster information area and the pre-allocated information area.
Updating the FAT area updates the state of clusters in the freed pre-allocated sub-area. And updating the backup cluster information area, namely adding the information of the newly added backup cluster in the backup cluster information area. The information of the released pre-allocated sub-area is deleted in the pre-allocated information area.
And updating the backup cluster information area, namely deleting the backup cluster from the backup cluster information area, and updating the FAT area, namely updating the state of the FAT area.
Corresponding to the embodiment of the file writing method, the application also provides an embodiment of a file writing device and a terminal applied by the file writing device.
As shown in fig. 3, fig. 3 is a block diagram of a file writing device according to an exemplary embodiment, which is applied to a file management system, where the storage medium managed by the file management system at least includes: a data storage area and a pre-allocation information area; the data storage area is divided into a plurality of pre-allocation subareas in advance; the device comprises:
and a candidate pre-allocation sub-area determining module 310, configured to determine, in the presence of a file write request, at least one candidate pre-allocation sub-area from among the unused pre-allocation sub-areas according to the average cluster erasure count of the unused pre-allocation sub-areas recorded in the pre-allocation information area.
And the target pre-allocation subarea determining module 320 is configured to determine a target pre-allocation subarea from each candidate pre-allocation subarea according to the addressing duration of the recorded candidate pre-allocation subarea in the pre-allocation information area when the number of the candidate pre-allocation subareas is greater than a first set value, and otherwise, determine the candidate pre-allocation subarea as the target pre-allocation subarea.
The file writing module 330 is configured to write a file into a target pre-allocation sub-area, and update the average cluster erasing times of the target pre-allocation sub-area in the pre-allocation information area.
Further, the storage medium managed by the file management system further includes: a backup cluster area, a backup cluster information area and a cluster information area; the backup cluster area comprises at least one backup cluster, the backup cluster information area is used for recording the erasing times of the backup cluster, and the cluster information area is used for recording the identification of each cluster in the pre-allocation sub-area; the device further comprises: the bad cluster replacement module 340 includes: a bad cluster identifier determining sub-module (not shown in the figure) configured to determine, when the target pre-allocation sub-area has a situation that the file cannot be written in, an identifier of a bad cluster in the target pre-allocation sub-area, which causes the file to be unwritten; a target backup cluster determining submodule (not shown in the figure) for determining a target backup cluster for replacing the bad cluster from the backup cluster area; and an information modification sub-module (not shown in the figure) configured to replace the identifier of the bad cluster in the cluster information area with the identifier of the target backup cluster, update the average cluster erasing times of the target pre-allocation sub-area in the pre-allocation information area according to the erasing times of the target backup cluster recorded in the backup cluster information area, and continue writing the file.
Wherein, the cluster information area also records the corresponding relation between the physical position of the cluster and the mark of the cluster; the bad cluster identifier determining sub-module in the bad cluster replacement module 340 is specifically configured to: when the target pre-allocation sub-area has the condition that the file cannot be written in, determining the logic position offset of the bad cluster relative to the starting cluster of the target pre-allocation sub-area; determining the physical position of the bad cluster corresponding to the logical position offset according to the sequence of each cluster in the target pre-allocation sub-area recorded in the cluster information area and the physical position of the starting cluster; and determining a cluster identifier corresponding to the physical position of the bad cluster in the corresponding relation, and taking the determined cluster identifier as the identifier of the bad cluster.
In addition, the target backup cluster determination submodule in the bad cluster replacement module 340 includes: a backup cluster number determining component (not shown in the figure) for determining the number of backup clusters in the backup cluster area; a target backup cluster determining component (not shown in the figure) for determining a target backup cluster for replacing the bad cluster from the backup cluster area when the number of the backup clusters is greater than or equal to a preset threshold; and a backup cluster adding component (not shown in the figure) configured to add at least one backup cluster to the backup cluster area when the number of the backup clusters is smaller than a preset threshold, and determine a target backup cluster for replacing the bad cluster from the recorded backup clusters in the backup cluster area and the added backup cluster.
Wherein, the backup cluster newly added component specifically comprises: a reference preallocation subarea determining subcomponent (not shown in the figure) for determining at least one reference preallocation subarea according to the cluster average erasing times of unused preallocation subareas recorded in the preallocation information area; a replacement subcomponent (not shown in the figure) for adding at least one cluster in the reference pre-allocation sub-area as a backup cluster and recording the backup cluster area, recording the erasing and writing times of the added backup cluster in the backup cluster information area, deleting the related record of the reference pre-allocation sub-area from the pre-allocation information area, and determining a target backup cluster for replacing the bad cluster from the recorded backup cluster in the backup cluster area and the added backup cluster.
Wherein the reference pre-allocated sub-region determination subcomponent is specifically configured to: determining the number of pre-allocation sub-areas with cluster average erasing times meeting set conditions in the unused pre-allocation sub-areas according to the cluster average erasing times of the unused pre-allocation sub-areas recorded in the pre-allocation information area; when the number is a second set value, determining the pre-allocation subarea meeting the set condition as the reference pre-allocation subarea; and when the number is larger than a second set value, according to the addressing time length in each pre-allocation subarea which is recorded in the pre-allocation information area and meets the set condition, determining the pre-allocation subarea of which the addressing time length meets the set time length from each pre-allocation subarea which meets the set condition, and determining the pre-allocation subarea of which the addressing time length meets the set time length as the reference pre-allocation subarea.
In addition, the apparatus further includes an addressing duration obtaining module (not shown in the figure) for obtaining the addressing duration, and is configured to: determining a target cluster from the pre-allocation subarea; all clusters in the pre-allocation subarea are arranged according to cluster chains, and the target cluster is not continuous with the previous cluster and/or the next cluster on the cluster chain; determining the addressing time of the target cluster according to the distance between the target cluster and the designated cluster on the cluster chain; and determining the addressing time of the pre-allocation subarea according to the addressing time of all target clusters in the pre-allocation subarea.
The implementation process of the functions and actions of each module in the above device is specifically described in the implementation process of the corresponding step in the above method, and is not described herein again.
For the device embodiments, since they substantially correspond to the method embodiments, reference may be made to the partial description of the method embodiments for relevant points. The above-described embodiments of the apparatus are merely illustrative, wherein the modules described as separate parts may or may not be physically separate, and the parts displayed as modules may or may not be physical modules, may be located in one place, or may be distributed on a plurality of network modules. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of the application. One of ordinary skill in the art can understand and implement it without inventive effort.
As shown in fig. 4, fig. 4 is a hardware structure diagram of a computer device in which the file writing apparatus of the embodiment is located, and the device may include: a processor 410, a memory 420, an input/output interface 430, a communication interface 440, and a bus 450. Wherein processor 410, memory 420, input/output interface 430, and communication interface 440 are communicatively coupled to each other within the device via bus 450.
The processor 410 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an Application Specific Integrated Circuit (ASIC), or one or more Integrated circuits, and is configured to execute related programs to implement the technical solutions provided in the embodiments of the present Application.
The Memory 420 may be implemented in the form of a ROM (Read Only Memory), a RAM (Random Access Memory), a static storage device, a dynamic storage device, or the like. The memory 420 may store an operating system and other application programs, and when the technical solution provided by the embodiments of the present application is implemented by software or firmware, the relevant program codes are stored in the memory 420 and called to be executed by the processor 410.
The input/output interface 430 is used for connecting an input/output module to realize information input and output. The i/o module may be configured as a component in a device (not shown) or may be external to the device to provide a corresponding function. The input devices may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output devices may include a display, a speaker, a vibrator, an indicator light, etc.
The communication interface 440 is used for connecting a communication module (not shown in the figure) to realize communication interaction between the device and other devices. The communication module can realize communication in a wired mode (such as USB, network cable and the like) and also can realize communication in a wireless mode (such as mobile network, WIFI, Bluetooth and the like).
It should be noted that although the above-mentioned device only shows the processor 410, the memory 420, the input/output interface 430, the communication interface 440 and the bus 450, in a specific implementation, the device may also include other components necessary for normal operation. Furthermore, it will be understood by those skilled in the art that the above-described apparatus may also include only those components necessary to implement the embodiments of the present application, and not necessarily all of the components shown in the figures.
An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored, and the computer program, when executed by a processor, implements the file writing method described above.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
The foregoing description of specific embodiments of the present application has been presented. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
Other embodiments of the present application will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the application and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the application being indicated by the following claims.
It will be understood that the present application is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the application is limited only by the appended claims.
The above description is only exemplary of the present application and should not be taken as limiting the present application, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the scope of protection of the present application.
Claims (10)
1. A file writing method, applied to a file management system, wherein a storage medium managed by the file management system at least includes: a data storage area and a pre-allocation information area; the data storage area is divided into a plurality of pre-allocation subareas in advance, and each pre-allocation subarea comprises a plurality of continuous clusters;
the method comprises the following steps:
under the condition that a file writing requirement exists, determining at least one candidate pre-allocation sub-area from the unused pre-allocation sub-areas according to the recorded cluster average erasing times of the unused pre-allocation sub-areas in the pre-allocation information area;
when the number of the candidate preallocation subareas is larger than a first set value, determining a target preallocation subarea from each candidate preallocation subarea according to the addressing duration of the recorded candidate preallocation subarea in the preallocation information area, otherwise, determining the candidate preallocation subarea as the target preallocation subarea; the addressing time length is used for representing the time length for searching the address of each cluster needing to be used in the pre-allocated subarea in the file writing process;
and writing a file into a target pre-allocation sub-area, and updating the cluster average erasing times of the target pre-allocation sub-area in the pre-allocation information area.
2. The method of claim 1, wherein the storage medium further comprises: a backup cluster area, a backup cluster information area and a cluster information area; the backup cluster area comprises at least one backup cluster, the backup cluster information area is used for recording the erasing times of the backup cluster, and the cluster information area is used for recording the identification of each cluster in the pre-allocation sub-area;
the method further comprises the following steps:
when the target pre-allocation subarea has the condition that the file cannot be written in, determining the identifier of a bad cluster which causes the file to be written in the target pre-allocation subarea;
determining a target backup cluster for replacing the bad cluster from a backup cluster area, replacing the mark of the bad cluster in the cluster information area with the mark of the target backup cluster, updating the average cluster erasing times of the target pre-allocation sub-area in the pre-allocation information area according to the erasing times of the target backup cluster recorded in the backup cluster information area, and continuing to write files.
3. The method according to claim 2, wherein the cluster information area further records a correspondence between a physical location of a cluster and an identification of the cluster;
the determining the identification of the bad cluster causing the file to be unwritable in the target pre-allocation subarea includes:
determining a logical position offset of the bad cluster relative to the target pre-allocated subregion starting cluster;
determining the physical position of the bad cluster corresponding to the logical position offset according to the sequence of each cluster in the target pre-allocation sub-area recorded in the cluster information area and the physical position of the starting cluster;
and determining a cluster identifier corresponding to the physical position of the bad cluster in the corresponding relation, and taking the determined cluster identifier as the identifier of the bad cluster.
4. The method of claim 2, wherein the determining a target backup cluster for replacing the bad cluster from the backup cluster area comprises:
determining the number of backup clusters in the backup cluster area;
and when the number of the backup clusters is greater than or equal to a preset threshold value, determining a target backup cluster for replacing the bad cluster from the backup cluster area, otherwise, adding at least one backup cluster to the backup cluster area, and determining a target backup cluster for replacing the bad cluster from the recorded backup cluster in the backup cluster area and the newly added backup cluster.
5. The method according to claim 4, wherein said adding at least one backup cluster to the backup cluster area comprises:
determining at least one reference pre-allocation subarea according to the cluster average erasing times of the unused pre-allocation subareas recorded in the pre-allocation information area;
and newly adding at least one cluster in the reference pre-allocation sub-area as a backup cluster and recording the backup cluster area, recording the erasing times of the newly added backup cluster in the backup cluster information area, and deleting the related record of the reference pre-allocation sub-area from the pre-allocation information area.
6. The method of claim 5, wherein determining at least one reference pre-allocated sub-area based on the average number of cluster erasures of unused pre-allocated sub-areas recorded in the pre-allocated information area comprises:
determining the number of pre-allocation sub-areas with cluster average erasing times meeting set conditions in the unused pre-allocation sub-areas according to the cluster average erasing times of the unused pre-allocation sub-areas recorded in the pre-allocation information area;
when the number is a second set value, determining the pre-allocation subarea meeting the set condition as the reference pre-allocation subarea;
and when the number is larger than a second set value, according to the addressing time length in each pre-allocation subarea which is recorded in the pre-allocation information area and meets the set condition, determining the pre-allocation subarea of which the addressing time length meets the set time length from each pre-allocation subarea which meets the set condition, and determining the pre-allocation subarea of which the addressing time length meets the set time length as the reference pre-allocation subarea.
7. Method according to any of claims 1 to 6, characterized in that the addressing duration of any pre-allocated sub-area is obtained and recorded by the following steps:
determining a target cluster from the pre-allocation subarea; all clusters in the pre-allocation subarea are arranged according to cluster chains, and the target cluster is not continuous with the previous cluster and/or the next cluster on the cluster chain;
determining the addressing time of the target cluster according to the distance between the target cluster and the designated cluster on the cluster chain;
and determining the addressing time of the pre-allocation subarea according to the addressing time of all target clusters in the pre-allocation subarea.
8. A file writing apparatus applied to a file management system, the storage medium managed by the file management system comprising at least: a data storage area and a pre-allocation information area; the data storage area is divided into a plurality of pre-allocation subareas in advance, and each pre-allocation subarea comprises a plurality of continuous clusters;
the device comprises:
the candidate preallocation subarea determining module is used for determining at least one candidate preallocation subarea from the unused preallocation subareas according to the cluster average erasing times of the unused preallocation subareas recorded in the preallocation information area under the condition that a file writing requirement exists;
the target pre-allocation subarea determining module is used for determining a target pre-allocation subarea from each candidate pre-allocation subarea according to the addressing time of the recorded candidate pre-allocation subarea in the pre-allocation information area when the number of the candidate pre-allocation subareas is larger than a first set value; the addressing time length is used for representing the time length for searching the address of each cluster needing to be used in the pre-allocated subarea in the file writing process;
and the file writing module is used for writing a file into the target pre-allocation sub-area and updating the cluster average erasing times of the target pre-allocation sub-area in the pre-allocation information area.
9. A computer-readable storage medium, characterized in that a computer program is stored thereon, which when executed by a processor implements the file writing method according to any one of claims 1 to 7.
10. A computer device, characterized in that the computer device comprises:
one or more processors;
a memory for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement the file writing method of any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111455415.4A CN113900994B (en) | 2021-12-02 | 2021-12-02 | File writing method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111455415.4A CN113900994B (en) | 2021-12-02 | 2021-12-02 | File writing method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113900994A CN113900994A (en) | 2022-01-07 |
CN113900994B true CN113900994B (en) | 2022-03-01 |
Family
ID=79195228
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202111455415.4A Active CN113900994B (en) | 2021-12-02 | 2021-12-02 | File writing method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113900994B (en) |
Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102880556A (en) * | 2012-09-12 | 2013-01-16 | 浙江大学 | Wear leveling method and system of Nand Flash |
CN104461401A (en) * | 2014-12-25 | 2015-03-25 | 珠海煌荣集成电路科技有限公司 | Data reading and writing management method and device for SPI flash memory |
CN106155587A (en) * | 2016-06-29 | 2016-11-23 | 联想(北京)有限公司 | Information processing method and storage device |
CN106844583A (en) * | 2017-01-10 | 2017-06-13 | 厦门雅迅网络股份有限公司 | A kind of optimization method that FAT file system is set up on NOR Flash |
CN108280029A (en) * | 2018-02-28 | 2018-07-13 | 郑州云海信息技术有限公司 | A kind of data erasing-writing method and system based on Nor Flash chip |
CN110188084A (en) * | 2019-05-16 | 2019-08-30 | 浙江讯盟科技有限公司 | A kind of distributed file storage system and file memory method |
CN111813339A (en) * | 2020-07-03 | 2020-10-23 | 深圳市国微电子有限公司 | Data writing method and device of Flash Nand Flash, electronic equipment and storage medium |
CN113064919A (en) * | 2021-03-31 | 2021-07-02 | 北京达佳互联信息技术有限公司 | Data processing method, data storage system, computer device and storage medium |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105279166B (en) * | 2014-06-20 | 2019-01-25 | 中国电信股份有限公司 | File management method and system |
CN109697019B (en) * | 2017-10-20 | 2022-12-27 | 北京京东尚科信息技术有限公司 | Data writing method and system based on FAT file system |
US11392436B2 (en) * | 2020-04-01 | 2022-07-19 | Western Digital Technologies, Inc. | Advanced file recovery method for flash memory |
-
2021
- 2021-12-02 CN CN202111455415.4A patent/CN113900994B/en active Active
Patent Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102880556A (en) * | 2012-09-12 | 2013-01-16 | 浙江大学 | Wear leveling method and system of Nand Flash |
CN104461401A (en) * | 2014-12-25 | 2015-03-25 | 珠海煌荣集成电路科技有限公司 | Data reading and writing management method and device for SPI flash memory |
CN106155587A (en) * | 2016-06-29 | 2016-11-23 | 联想(北京)有限公司 | Information processing method and storage device |
CN106844583A (en) * | 2017-01-10 | 2017-06-13 | 厦门雅迅网络股份有限公司 | A kind of optimization method that FAT file system is set up on NOR Flash |
CN108280029A (en) * | 2018-02-28 | 2018-07-13 | 郑州云海信息技术有限公司 | A kind of data erasing-writing method and system based on Nor Flash chip |
CN110188084A (en) * | 2019-05-16 | 2019-08-30 | 浙江讯盟科技有限公司 | A kind of distributed file storage system and file memory method |
CN111813339A (en) * | 2020-07-03 | 2020-10-23 | 深圳市国微电子有限公司 | Data writing method and device of Flash Nand Flash, electronic equipment and storage medium |
CN113064919A (en) * | 2021-03-31 | 2021-07-02 | 北京达佳互联信息技术有限公司 | Data processing method, data storage system, computer device and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN113900994A (en) | 2022-01-07 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN112486852B (en) | Solid state disk and address mapping method thereof | |
CN113220239A (en) | Erasing and writing method, device and equipment for flash storage and readable storage medium | |
US11853566B2 (en) | Management method and system for address space of low delay file system and medium | |
CN113568582B (en) | Data management method, device and storage equipment | |
CN109684271B (en) | Snapshot data management method and device, electronic equipment and machine-readable storage medium | |
CN116466879B (en) | CXL memory module, memory data replacement method and computer system | |
CN107229421B (en) | Method and device for creating video data storage system, method and device for writing file into video data storage system and method and device for reading video data storage system | |
CN114237984A (en) | Recovery method and system of Trim data under abnormal power failure and solid state disk | |
JP4347707B2 (en) | Information recording medium formatting method and information recording medium | |
CN110806840A (en) | Flash memory card data storage method based on multiple data streams, flash memory card and equipment | |
CN113434470B (en) | Data distribution method and device and electronic equipment | |
CN111221475A (en) | Storage space management method, device, equipment and readable medium | |
CN114005476A (en) | Flash memory, flash memory erasing and writing counting method, electronic equipment and computer storage medium | |
KR100954603B1 (en) | A log file of file system and method for recovering file system | |
CN113900994B (en) | File writing method and device | |
CN113190182A (en) | Management method for data storage in Flash | |
CN113190325A (en) | Container creation method and device | |
CN110764694B (en) | Method and system for controlling storage space | |
CN109739688B (en) | Snapshot resource space management method and device and electronic equipment | |
US8301862B2 (en) | Formatting device | |
CN116301614A (en) | Memory data access method, system, device and storage medium | |
CN115328851A (en) | Data protection method, device, equipment and medium | |
CN111124294B (en) | Sector mapping information management method and device, storage medium and equipment | |
CN114238162A (en) | Garbage recycling method and device, readable storage medium and electronic equipment | |
CN109960611B (en) | Data recovery method and device, electronic equipment and machine-readable storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |