CN114327246A - Data storage method in storage medium, storage medium and computer equipment - Google Patents

Data storage method in storage medium, storage medium and computer equipment Download PDF

Info

Publication number
CN114327246A
CN114327246A CN202011083395.8A CN202011083395A CN114327246A CN 114327246 A CN114327246 A CN 114327246A CN 202011083395 A CN202011083395 A CN 202011083395A CN 114327246 A CN114327246 A CN 114327246A
Authority
CN
China
Prior art keywords
file
storage
storage area
storage space
index
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.)
Granted
Application number
CN202011083395.8A
Other languages
Chinese (zh)
Other versions
CN114327246B (en
Inventor
何建国
谢奕
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Aputure Imaging Industries Co Ltd
Original Assignee
Aputure Imaging Industries Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Aputure Imaging Industries Co Ltd filed Critical Aputure Imaging Industries Co Ltd
Priority to CN202011083395.8A priority Critical patent/CN114327246B/en
Publication of CN114327246A publication Critical patent/CN114327246A/en
Application granted granted Critical
Publication of CN114327246B publication Critical patent/CN114327246B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a data storage method in a storage medium, the storage medium and computer equipment, wherein the method comprises the steps of receiving a data writing command aiming at the storage medium, wherein the data writing command comprises the name and the size of a first file to be written; inquiring whether an index unit of the first file exists in the second storage area; if the second storage area does not have the index unit of the first file, distributing an idle first index unit for the first file in the second storage area; inquiring whether a free storage space with the first file size exists in the first storage area; if the first storage area has a free storage space with the size of the first file, distributing a free first storage space for the first file in the first storage area, and writing the first file into the first storage space; and if the second storage area has the index unit of the first file, writing the first file into the target storage space. The storage method can effectively improve the storage efficiency and the use efficiency and prolong the service life of the storage medium.

Description

Data storage method in storage medium, storage medium and computer equipment
Technical Field
The present application relates to the field of data processing technologies, and in particular, to a method for storing data in a storage medium, and a computer device.
Background
An Electrically Erasable Programmable Read-Only Memory (EEPROM) is a semiconductor Memory device that can be electronically rewritten many times. EEPROM has four modes of operation: read mode, write mode, erase mode, and verify mode. To ensure correct writing, after each file is written, a verification step similar to reading is required, and if an error exists, the file is rewritten. Compared with an Erasable Programmable Read-Only Memory (EPROM), the EEPROM can erase information on a chip with a specific voltage without ultraviolet irradiation or taking down so as to write new data.
For the embedded small micro embedded system device, because the function is simple, the Micro Controller Unit (MCU) has small operation capability, and the flash Memory (flash) and Random Access Memory (RAM) of the embedded small micro embedded system device are few, the embedded small micro embedded system device has higher requirements for the number of stored files and storage efficiency.
When the EEPROM writes a file, the storage method comprises the following steps: a fixed address is set as a starting address for storing the data, the data is read and written in a fixed area all the time, and even if the block storage area is damaged and cannot be normally stored, the data can be read and written in the block storage area.
Disclosure of Invention
The embodiment of the application provides a method for storing data in a storage medium, the storage medium and computer equipment, which aim to solve the technical problems that in the prior art, EEPROM data storage efficiency is low, and one type of data can only be read and written in a fixed storage area.
In one aspect, the present invention provides a method for storing data in a storage medium, where a storage area of the storage medium includes a first storage area for storing a target file and a second storage area for storing index information corresponding to the target file; the second storage area comprises a plurality of index units, each index unit can store index information of the target file stored in the first storage area, and the method comprises the following steps:
receiving a data writing command aiming at the storage medium, wherein the data writing command comprises the name and the size of a first file to be written;
inquiring whether an index unit of the first file exists in the second storage area;
if the index unit of the first file does not exist in the second storage area, allocating an idle first index unit for the first file in the second storage area; inquiring whether a free storage space with the first file size exists in the first storage area; if the first storage area has a free storage space with a first file size, allocating a free first storage space for the first file in the first storage area, and writing the first file into the first storage space;
if the second storage area has the index unit of the first file, writing the first file into a target storage space, wherein the target storage space is a storage space corresponding to the index unit of the first file in the first storage area or a free storage space in the first storage area.
Further, allocating a free first storage space for the first file in the first storage area includes:
if the first file is the nth file stored in the first storage area, inquiring the initial address of a storage space for storing the (n-1) th file and the data length of the (n-1) th file in the first storage area, and offsetting the data length of the (n-1) th file by the initial address of the storage space of the (n-1) th file to obtain the initial address of the first storage space;
allocating a free first storage space for the first file in the first storage area according to the initial address of the first storage space and the data length of the first file; wherein n is a natural number.
Further, the method further comprises:
after the first file is written into the first storage space or the target storage space, updating the identification information of the first storage area; the identification information includes information of the number of times of erasing, the start address, and the number of times of writing data of a storage space for storing the first file, and information of the length of data of the first file.
Further, the method further comprises: and after the identification information of the first storage area is updated, updating the index information of the first file in the index unit of the first file.
Further, if the second storage area has an index unit of the first file, writing the first file into a target storage space includes:
judging the number of the index units of the first file in the second storage area;
if an index unit of the first file exists in the second storage area, writing the updated first file into a storage space corresponding to the index unit, or writing the updated first file into a free storage space of the first storage area;
and if two index units of the first file exist in the second storage area, two storage spaces corresponding to the two index units of the first file one to one exist in the first storage area, and the updated first file is written into any one of the two storage spaces.
Further, writing the updated first file into a free storage space of the first storage area, including:
allocating a new index unit for the first file in the second storage area, and inquiring whether a free storage space with the size of the first file exists in the first storage area; if the first storage area has a free storage space with the size of the first file, allocating a free storage space for the first file in the first storage area, and writing the first file into the free storage space.
Further, writing the updated first file into any one of the two storage spaces, including:
the two storage spaces are respectively a third storage space of the first file and a fourth storage space of the first file;
inquiring data writing frequency information of the third storage space and data writing frequency information of the fourth storage space in the first storage area;
and if the data writing times of the fourth storage space are greater than the data writing times of the third storage space, using the first file stored in the fourth storage space for data recovery, and writing the updated first file in the third storage space.
Further, the method further comprises:
if the first file is failed to be written into the first storage space, counting the number of continuous writing failures of the first file written into the first storage space;
if the continuous writing failure times of the first file written in the first storage space reach a preset value, allocating a new index unit for the first file in the second storage area;
inquiring whether a free storage space with the first file size exists in the first storage area; if the first storage area has a free storage space with the size of the first file, allocating a new free storage space for the first file in the first storage area, and writing the first file into the new free storage space.
In a second aspect of the present invention, there is provided a storage medium, a storage area of which includes:
a first storage area for storing an object file written in the first storage area by the data storage method in the storage medium; and the number of the first and second groups,
the second storage area is used for storing index information corresponding to the target file, the second storage area comprises a plurality of index units, and each index unit can store the index information of the target file stored in the first storage area.
In a third aspect of the present invention, there is provided a computer apparatus comprising:
one or more processors;
a storage medium; and the number of the first and second groups,
and writing one or more target files on the storage medium by the data storage method in the storage medium, wherein the target files are loaded by the processor.
According to the data storage method in the storage medium, the storage medium and the computer equipment, whether the file to be written already exists in the first storage area or whether the file with the updating state different from that of the file to be written exists in any file to be written can be rapidly inquired, so that the writing mode of the file to be written can be rapidly determined, and the data writing efficiency can be improved. When a storage area corresponding to a storage space is damaged, other storage areas can be rapidly allocated to store files to be written, the use efficiency of the storage medium can be improved, and the service life of the storage medium is prolonged.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a schematic diagram of a method for storing data in a storage medium according to an embodiment of the present invention;
FIG. 2 is a flow chart illustrating a method for storing data in a storage medium according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of storage area division of a storage medium according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a computer device in an embodiment of the present invention.
In the figure, 1-power supply, 2-processor, 3-storage medium, 4-input unit.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
In the description of the present application, it is to be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "upper", "lower", "front", "rear", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer", and the like indicate orientations or positional relationships based on those shown in the drawings, and are used merely for convenience of description and for simplicity of description, and do not indicate or imply that the referenced device or element must have a particular orientation, be constructed in a particular orientation, and be operated, and thus should not be considered as limiting the present application. Furthermore, the terms "first", "second" and "first" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, features defined as "first", "second", may explicitly or implicitly include one or more of the described features. In the description of the present application, "a plurality" means two or more unless specifically limited otherwise.
Referring to fig. 1, an embodiment of the present invention provides a method for storing data in a storage medium, where a storage area of the storage medium includes a first storage area for storing a target file and a second storage area for storing index information corresponding to the target file; the second storage area comprises a plurality of index units, each index unit can store index information of the file stored in the first storage area, and the method comprises the following steps:
s1, receiving a data writing command aiming at the storage medium, wherein the data writing command comprises the name and the size of a first file to be written;
s2, inquiring whether an index unit of the first file exists in the second storage area;
and S3, determining the storage space of the file to be written in the first storage area according to the state of the index unit of the second storage area relative to the first file, and writing the first file in the corresponding storage space.
Step S3 specifically includes: if the second storage area does not have the index unit of the first file, distributing an idle first index unit for the first file in the second storage area; inquiring whether a free storage space with the first file size exists in the first storage area; if the first storage area has an idle storage space with the size of the first file, allocating an idle first storage space for the first file in the first storage area, and writing the first file into the first storage space;
and if the second storage area has the index unit of the first file, writing the first file into a target storage space, wherein the target storage space is a storage space corresponding to the index unit of the first file in the first storage area or a free storage space in the first storage area.
The specific flow of the data storage method in the storage medium can be seen in fig. 2. The method for storing data in the storage medium is particularly suitable for EEPROM. Referring to fig. 3, the storage area of the storage medium already has the divided first storage area and second storage area, or the first storage area and second storage area may be divided before preparing to store data. The addresses of the first storage area and the second storage area are adjacent, and the first storage area is located at the forefront of the storage area of the storage medium. The start address of the first memory area and the start address of the second memory area are determined at the time of dividing the two memory areas, and the start addresses of the two memory areas are fixed.
The first storage area is used for storing the target file. The stored target file specifically includes: identification information of the file and a data packet. The identification information of the file includes erasure count information, a start address, and data write count information of a storage space for storing the target file, and data length information of the target file.
The second storage area is used for storing the index information corresponding to the target file stored in the first storage area. The second storage area comprises a plurality of index units; the number of the index units is determined according to the size of the storage space of the storage medium, the data length of the file to be stored and the number of the data to be stored. Generally speaking, the number of the index units should be greater than the sum of the number of the files to be stored in the first storage area and the number of the backup files of the files to be stored.
The index information of any index unit comprises the name of the target file stored in the first storage area and the storage state information of the storage space for storing the target file, which correspond to the index unit. The storage state information comprises an idle state, a normal erasing state, an erasing frequency reaching an upper limit state, a storage area error state and a state that the storage space cannot be redistributed. The name of the target file in the index unit may be a sequence number value of the target file in the algorithm.
When the storage state information is in an idle state or a normal erasing state, the storage space corresponding to the index unit can be normally written with a file; when the storage state information is that the erasing times reach an upper limit state, a storage area error state or a storage space cannot be reallocated, the storage space corresponding to the index unit cannot store the corresponding file any more. The storage status information of the index unit may be updated according to the identification information of the corresponding storage space, for example, when the number of times of erasing the storage area of the corresponding storage space reaches a preset value, the storage status information of the index unit corresponding to the storage space may be updated from a "normal erasing status" to an "state where the number of times of erasing reaches an upper limit".
Before any file is not stored in the first storage area, the index information of each index unit in the second storage area is empty. When m files are stored in the first storage area and each file is stored in a corresponding storage space, corresponding index information is stored in the corresponding m index units in the second storage area respectively, and the storage space in which the files are stored in the first storage area is in one-to-one correspondence with the index units in the second storage area. For example, when a storage space in the first storage area stores a first file, the second storage area has an index unit storing index information corresponding to the first file, that is, the index information of the first file.
When a plurality of different files need to be written into the first storage area, the storage method of each file is the same, and the storage method when the first file is written into the first storage area is taken as an example for description. When a data write command is received, the name and size of the first file are acquired. Whether the index unit of the first file exists in each index unit is firstly inquired in the second storage area, whether the first file is stored in the first storage area can be quickly acquired according to whether the file name of the first file exists in the index unit, and the storage mode of the first file is quickly judged. Generally, the index units in the second storage area are sequentially queried from the first index unit in the second storage area, so that the query accuracy and efficiency can be improved.
When a storage space F in the first storage area stores a first file, a corresponding index unit X in the second storage area stores the name of the first file and the storage state information of the corresponding storage space F, and at this time, the index unit of the first file in the second storage area is the index unit. When any storage space in the first storage area does not store the first file, the second storage area does not have a corresponding index unit, and at the moment, the second storage area does not have the index unit of the first file.
If the index unit of the first file does not exist in the second storage area, which indicates that the first file is not stored in the first storage area, a free index unit can be allocated to the first file in the second storage area, that is, the first index unit is allocated to the first file. When the index units are allocated to the files to be written, the files can be allocated according to the sequence order of the index units in the second storage area. For example, the first to tenth index units exist in the second storage area, and if the ten index units are empty, the first index unit is allocated to the first file to serve as the first index unit of the first file; and if the first to third index units all have the index information of the corresponding file, allocating the fourth index unit of the second storage area to the first file to be used as the first index unit of the first file. The index units are distributed in the mode, when the index units in the second storage area are inquired, when one index unit is empty, the index units behind the index unit do not need to be inquired, and the index units can be directly distributed for the corresponding files to be written, because the index units behind the index unit are empty. By adopting the method for distribution, when the index units are distributed, the query accuracy is not influenced, the number of the queried index units can be reduced, and the query efficiency is improved.
After the first index unit is allocated to the first file, whether a storage area except the file stored in the first storage area has a storage space which meets the requirement of storing the first file is inquired in the first storage area. If the free storage space for storing the first file size does not exist, which indicates that the space of the first storage area for not storing data is smaller than the first file size and the first file cannot be stored, the index information of the first index unit allocated to the first file by the second storage area is updated, and the storage state information in the index information is changed into 'the storage space cannot be reallocated'.
If the free storage space capable of storing the first file exists, a free first storage space is allocated to the first file in the first storage area, the size of the first storage space can be the same as that of the first file, and the first file is written into the first storage space.
Specifically, when the first storage space is allocated to the first file, if the first file is a first file stored in the first storage area, the start address of the first storage space is the start address of the first storage area, and the size of the first storage space is the size of the first file. If the first file is the nth file stored in the first storage area, the starting address of the first storage space is obtained by offsetting the data length of the nth-1 file from the starting address of the storage space of the (n-1) th file stored in the first storage area, and the size of the first storage space is the size of the first file.
For example, when an index unit and a storage space are allocated to a first file, if the first storage area and the second storage area are both empty, the first index unit allocated to the first file is a first index unit of the second storage area, the first storage space allocated to the first file in the first storage area is a first storage space of the first storage area, and a start address of the first storage space is a start address of the first storage area.
If the first index unit X1, the second index unit X2, and the third index unit X3 of the second storage area are uniformly corresponding to the first storage space F1, the second storage space F2, and the third storage space F3 of the first storage area, the first storage space F1 stores the first target file _1, the second storage space F2 stores the second target file _2, and the third storage space F3 stores the third target file _3, and the fourth index unit of the second storage area is empty, when the index unit and the storage space are allocated to the first file to be written, that is, the fourth index unit X4 of the second storage area can be allocated as the first index unit of the first file, the fourth storage space F4 allocated in the first storage area is the first storage space of the first file, and the start address of the first storage space F4 is offset from the start address of the third storage space F3 by the data length len _3 of the third target file _ 3.
It is understood that the start address of the first storage space F1 is the start address of the first storage area, the start address of the second storage space F2 is the start address of the first storage space F1 offset by the data length len _1 of the first target file _1, the start address of the third storage space F3 is the start address of the second storage space F2 offset by the data length len _2 of the second target file _2, and the start address of the first storage space F4 storing the first file is the start address of the third storage space F3 offset by the data length len _3 of the third target file _ 3.
After the first storage area allocates the first storage space for the first file, the first file can be stored in the first storage space. The first file stored in the first storage space includes identification information of the first storage space and a data packet of the first file. For example, if the first storage space is a first storage file, the number of times of erasing the storage area in the identification information of the first storage space is 0, the number of times of writing data is 1, and the identification information further includes data length information of the first file and start address information of the first storage space. When the first file is stored in the first storage space for the second time, the data length information of the first file in the identification information and the initial address information of the first storage space are not changed, the erasing times of the storage area are updated to be 1, and the data writing times are updated to be 2.
Accordingly, after the first file is stored in the first storage space, the index information of the first index unit corresponding to the first storage space can be updated. The index information of the first index unit includes a name and storage state information of the first file. When the first storage space stores the file for the first time, at this time, the storage state information corresponding to the first index unit is updated from the "idle state" to the "normal erasing state".
Taking the process of storing three new files, file _1, file _2 and file _3, when the first storage area and the second storage area are both empty, as an example, the method for storing data in the storage medium in the normal state is described. Storage file _ 1: the first index unit X1 of the second storage area is allocated to file _1, the first storage space F1 of the first storage area is allocated to file _1, the start address of the storage space F1 is the start address of the first storage area, and the size of the storage space F1 is the data length len _1 of file _ 1; then, the start address of the storage space F1, the storage area erasure count information, the data writing count information, and the data length len _1 of file _1 are assigned to the identification information of the storage space F1; and updates the index information of index unit X1.
Storage file _ 2: the second index unit X2 of the second storage area is allocated to file _2, the second storage space F2 of the first storage area is allocated to file _2, the start address of the storage space F2 is obtained by shifting the start address of the storage space F1 by the data length len _1 of file _1, and the size of the storage space F2 is the data length len _2 of file _ 2; then, assigning the start address of the storage space F2, the storage area erasing time information, the data writing time information, and the data length of file _2 to the identification information of the storage space F2; and updates the index information of index unit X2.
Storage file _ 3: the third index unit X3 of the second storage area is allocated to file _3, the third storage space F3 of the first storage area is allocated to file _3, the start address of the storage space F3 is obtained by shifting the start address of the storage space F2 by the data length len _2 of file _2, and the size of the storage space F3 is the data length len _3 of file _ 3; then, assigning the start address of the storage space F3, the storage area erasing time information, the data writing time information, and the data length of file _3 to the identification information of the storage space F3; and updates the index information of index unit X3.
The writing process of three new files is completed.
When a data writing command is received and whether the index unit of the first file exists in each index unit is inquired in the second storage area, if the index unit of the first file exists in the second storage area, the fact that the first storage area already has a corresponding storage space is indicated, and a file with the same file name as the first file name is stored in the corresponding storage space. At this time, the first file may be stored to the target storage space of the first storage area. Specifically, the target storage space is a storage space corresponding to an index unit of the first file in the first storage area, or a free storage space in the first storage area.
That is, when the index unit of the first file exists in the second storage area, the index units of the first file can be processed according to the number of the searched index units of the first file. When the second storage area has an index unit of the first file, the first file can be backed up or directly stored in a storage space corresponding to the index unit of the first file for updating. When the index units of the two first files exist in the second storage area, the first files are stored in any one of the two storage spaces corresponding to the index units of the two first files.
The following describes cases where the index unit of the first file exists in the second storage area.
As one of specific storage methods in which the index unit of the first file exists in the second storage area, the second storage area has an index unit of the first file. The second storage area has a first index unit, and the first index unit comprises the name of the first file and the storage state information of the storage space for storing the first file; a first storage space exists in the first storage area, and identification information of the first storage space before updating and a data packet of the first file are stored in the first storage area. At this time, the first file to be written is the updated first file.
The size of the first storage space is the same as that of the first file, and when the storage state information about the first storage space in the first index unit is in a normal erasing state, the updated first file can be directly stored in the first storage space. It can be understood that, when the updated first file is written into the first storage space, the updated first file directly overwrites the first file before update originally stored in the first storage space. At this time, in the identification information in the first storage space, the number of times of erasing the storage area is added by 1, the number of times of writing data is added by 1, and the data length information of the first file and the start address information of the first storage space, which are also included in the identification information, are not changed.
In the index information of the first index unit of the second storage area, the name of the updated first file is unchanged; regarding the storage state information of the first storage space, if the data writing frequency in the identification information of the first storage space does not reach the preset upper limit value, the storage state information of the first index unit is not changed and still is in a normal erasing state; if the data writing frequency in the identification information of the first storage space reaches a preset upper limit value, the storage state information of the first index unit is updated from a normal erasing state to an erasing frequency reaching the upper limit state. It is understood that, if the first file cannot be written into the first storage space, the storage status information of the first index unit is updated from the "normal erasure status" to the "storage area error status". At this point, new free storage space needs to be reallocated for the first file.
As another specific storage method for the second storage area to have the index unit of the first file, the second storage area also has only one index unit of the first file. At this time, the first file may be subjected to backup processing. And allocating a free second index unit for the updated first file in the second storage area. Inquiring whether a free storage space with the first file size exists in the first storage area; and if the free storage space with the size of the first file exists, distributing a free second storage space for the updated first file in the first storage area, and storing the updated second file into the second storage space.
The second storage space is used for storing data for the first time, the erasing times of the storage area in the updated identification information in the second storage space are 0, the data writing times are 1, and the identification information further comprises data length information of the first file and initial address information of the second storage space. After the updated first file is written in the second storage space, in the index information of the second index unit corresponding to the second storage space in the second storage area, the name of the file may include a name of the first file and an identifier different from the name of the first file; the storage state information of the second index unit is updated from the idle state to the normal erasing state. At this time, the second storage area has two index units with respect to the first file name, and correspondingly, there are two storage spaces in the first storage area in which the first files in different update states are stored.
For example, the first file name is file _ 1; when the second storage area has an index unit of the first file, the index unit is a first index unit, and the index information of the first index unit comprises the name information of the first file; a first storage space corresponding to the first storage area stores a first file before update with the name of file _ 1. When the updated first file with the name of file _1 needs to be stored again, a free second index unit can be allocated to the updated first file _1 in the second storage area; and allocating a free second storage space for the updated first file _1 in the first storage area. In the index information of the second index unit, the updated name of the first file may be file _1_ cpy; wherein cpy can be used as an identifier of the updated name of the first file in the index information.
When the updated first file _1 needs to be written again, the first index unit and the second index unit related to the file _1 name can be obtained by querying each index unit with the file _1 name in the second storage area. Accordingly, two storage spaces, namely a first storage space in which the first file before updating is stored and a second storage space in which the first file after updating is stored, exist in the first storage area. When one storage space is in a state that the first file cannot be read, the first file stored in the other storage space can be read for updating or other purposes, and the data protection and data updating efficiency can be improved. The two storage spaces are adopted to store the files of the same file in different updating states, the safety of data use can be improved, meanwhile, the two storage spaces are written alternately, the service life of the storage medium can be prolonged, and the storage area is prevented from being damaged easily due to repeated erasing and writing at the same position.
As still another specific storage method in which the index unit of the first file exists in the second storage area, the second storage area has index units of two first files. If the second storage area has two index units of the first file, correspondingly, two storage spaces exist in the first storage area, and the two storage spaces respectively and correspondingly store the first files in different updating states.
In this case, it can be understood that, for the first file, a backup exists in the first storage area, that is, one of the two storage spaces stores the first file before updating, the other storage space stores the first file after updating, and the first file to be written is the first file after being updated again.
For the re-updated first file to be written, if the storage state information of the two index units of the second storage area is both in a "normal erasing state", the re-updated first file may be written into any one of the two storage spaces corresponding to the first storage area. If the storage state information of one of the two index units in the second storage area is "the erasure number reaches the upper limit state" or "the storage area error state", the processing is performed according to the situation that only one index unit of the first file exists in the second storage area, and the specific processing method is not described herein again. If the storage state information of the two index units in the second storage area is both "the number of times of erasure reaches the upper limit state" or "the storage area error state", the processing is performed according to the situation that the index unit of the first file does not exist in the second storage area, which is not described herein again. And when the storage state information of any index unit is in a 'storage space unallowable state', the storage medium is indicated to be unavailable for storing the file corresponding to the index unit.
The following describes a specific example of the processing manner when the storage state information of both index units in the second storage area is in the "normal erasure state". For convenience of description, in order to avoid misunderstanding of a storage method in which there is no index unit of the first file or only one index unit of the first file in the second storage area, here, when there are two index units of the first file in the second storage area, the two index units in the second storage area are respectively a third index unit and a fourth index unit, and correspondingly, two storage spaces corresponding to the first storage area are respectively a third storage space and a fourth storage space; the third index unit corresponds to the third storage space, and the fourth index unit corresponds to the fourth storage space.
After the second storage area inquires the third index unit and the fourth index unit, correspondingly, the data writing time information in the identification information of the third storage space and the data writing time information in the identification information of the fourth storage space are inquired in the first storage area. If the data writing times of the fourth storage space are greater than the data writing times of the third storage space, the first file stored in the fourth storage space is a first file after the first update, and the first file to be written is a first file after the second update; the first file stored in the fourth storage space is used for recovering the data, so that the data of the first file can be updated more conveniently; and writing the first file to be written after the second updating into a third storage space, wherein the first file originally stored in the third storage space is covered.
And after the second updated first file is written into the third storage space, updating the identification information of the third storage space, wherein the erasing times in the identification information are added by 1, the data writing times are added by 1, and the initial address of the third storage space and the data length information of the first file are unchanged. Correspondingly, updating the storage state information of the index information in the third index unit; at this point, the name in the third index unit may no longer change. The two storage spaces are adopted to store the files of the same file in different updating states, the safety of data use can be improved, meanwhile, the two storage spaces are written alternately, the service life of the storage medium can be prolonged, and the storage area is prevented from being damaged easily due to repeated erasing and writing at the same position.
By adopting the data storage mode, whether the file to be written already exists in the first storage area or whether the file with the updating state different from that of the file to be written exists in any file to be written can be rapidly inquired, so that the writing mode of the file to be written can be rapidly determined, and the data writing efficiency can be improved. When a storage area corresponding to a storage space is damaged, other storage areas can be rapidly allocated to store files to be written, and the use efficiency of the storage medium can be improved.
For any file to be written, in any one-time writing process, if the situation of continuous writing failure occurs, counting the continuous writing failure times. And when the number of continuous writing failure times reaches a preset value, processing according to the condition that the index unit of the file to be written does not exist in the second storage area.
Specifically, the first file is still taken as an example. For the first file _1 to be written, when the second storage area does not have the index unit of the first file, the first storage area can be allocated with a free storage space, and the first file _1 is written into the storage space, or when the second storage area has the index unit of the first file, and the first file _1 can be written into the target storage space, in the writing process of any one of the first file _1, if the writing fails, different processing is performed according to the different times of continuous writing failures.
For example, when the first file _1 is written into the first storage space, if the number of consecutive write failures is lower than the preset value, the write operation is executed again in the first storage space, and the first file _1 is written into the first storage space.
If the continuous write failure times of the first file _1 written into the first storage space reach a preset value or the erasing times of the first storage space reach an upper limit value, whether a free cable exists or not is inquired again in the second storage areaAnd a lead unit. If the second storage area does not have a free index unit, updating the storage state information of the index unit corresponding to the first storage space to be in a 'storage space state incapable of being reallocated'; if there is a free index unit, then a free index unit X is reallocated to the first file _1nAnd inquiring whether a free storage space with the size of the first file _1 exists in the first storage area. If no free storage space with the size of the free first file _1 exists, the index unit X is usednThe storage state information is updated to a 'storage space cannot be reallocated state'; if there is a free storage space of the size of the first file _1, then a free storage space F is allocated for the first filenAnd writes the first file _1 into the storage space Fn
At this time, the process of reallocating the index unit and the storage space for the first file is the same as the storage method when the index unit of the first file does not exist in the second storage area, and is not described herein again.
The present invention also provides a data storage device, comprising:
the device comprises a receiving module, a writing module and a writing module, wherein the receiving module is used for receiving a data writing command aiming at a storage medium, and the data writing command comprises the name and the size of a first file to be written;
the storage module is used for inquiring whether an index unit of the first file exists in the second storage area; if the second storage area does not have the index unit of the first file, distributing an idle first index unit for the first file in the second storage area; inquiring whether a free storage space with the first file size exists in the first storage area; if the first storage area has a free storage space with the size of the first file, distributing a free first storage space for the first file in the first storage area, and writing the first file into the first storage space; and if the second storage area has the index unit of the first file, writing the first file into a target storage space, wherein the target storage space is a storage space corresponding to the index unit of the first file in the first storage area or a free storage space in the first storage area. The storage area of the storage medium comprises a first storage area for storing the target file and a second storage area for storing index information corresponding to the target file; the second storage area comprises a plurality of index units, and each index unit can store index information of the target file stored in the first storage area.
The storage device can quickly inquire whether the file to be written exists in the first storage area or not or whether the file with the updating state different from that of the file to be written exists in the first storage area or not for any file to be written, so that the writing mode of the file to be written is quickly determined, and the data writing efficiency can be improved. When a storage area corresponding to a storage space is damaged, other storage areas can be rapidly allocated to store files to be written, the use efficiency of the storage medium can be improved, and the service life of the storage medium is prolonged.
The present invention also provides a storage medium, a storage area of which includes: a first storage area for storing an object file written in the first storage area by the data storage method in the storage medium; and the second storage area is used for storing the index information corresponding to the target file, and comprises a plurality of index units, and each index unit can store the index information of the target file stored in the first storage area.
The first storage area is used for storing the target file. The stored target file specifically includes: identification information of the file and a data packet. The identification information of the file includes erasure count information, a start address and data write count information of a storage space for storing the file, and data length information of the file.
The second storage area is used for storing index information corresponding to the files stored in the first storage area. The second storage area comprises a plurality of index units; the number of the index units is determined according to the size of the storage space of the storage medium, the data length of the file to be stored and the number of the data to be stored. Generally speaking, the number of the index units should be greater than the sum of the number of the files to be stored in the first storage area and the number of the backup files of the files to be stored.
The index information of any index unit comprises the name of the target file stored in the first storage area and the storage state information of the storage space for storing the target file, which correspond to the index unit. The storage state information comprises an idle state, a normal erasing state, an erasing frequency reaching an upper limit state, a storage area error state and a state that the storage space cannot be redistributed.
When a file needs to be written in the first storage area of the storage medium, the processing method for determining the file to be written in can be quickly realized by inquiring the index information of each index unit of the second storage area, and the data reading and writing speed can be effectively improved. In addition, by inquiring the index information in the index unit of the second storage area and the identification information of the first storage area, the storage state information of any storage space in the first storage area can be clarified, the storage space can be conveniently and reasonably distributed, the storage efficiency of the storage medium can be improved, and the service life of the storage medium can be prolonged.
The invention also provides computer equipment which comprises one or more processors, the storage medium and one or more target files written on the storage medium by the data storage method in the storage medium, wherein the target files are loaded by the processors. It is understood that the object file stored on the storage medium is loaded by the processor and can be applied to the corresponding scene according to the type of the object file.
The computer device may be an independent server, or may be a server network or a server cluster composed of servers, for example, the computer device described in the embodiment of the present invention includes, but is not limited to, a computer, a network host, a single network server, a plurality of network server sets, or a cloud server composed of a plurality of servers. Among them, the Cloud server is constituted by a large number of computers or web servers based on Cloud Computing (Cloud Computing).
It will be appreciated that the computer device used in embodiments of the invention may be a device that includes both receiving and transmitting hardware, i.e. a device having receiving and transmitting hardware capable of performing two-way communication over a two-way communication link. Such a device may include: a cellular or other communication device having a single line display or a multi-line display or a cellular or other communication device without a multi-line display. The specific computer device may be a desktop terminal or a mobile terminal, and the computer device may also be one of a mobile phone, a tablet computer, a notebook computer, and the like.
The computer device may comprise components such as a processor 2 of one or more processing cores, one or more storage media 3, a power supply 1 and an input unit 4. Those skilled in the art will appreciate that the computer device configuration illustrated in FIG. 4 does not constitute a limitation of computer devices, and may include more or fewer components than those illustrated, or some components may be combined, or a different arrangement of components. Wherein:
the processor 2 is a control center of the computer device, connects various parts of the whole computer device by various interfaces and lines, and performs various functions of the computer device and processes data by operating or executing the object files and/or modules stored in the storage medium 3 and calling the object files stored in the storage medium 3, thereby performing overall monitoring of the computer device. Optionally, the processor 2 may include one or more processing cores; preferably, the processor 2 may integrate an application processor, which mainly handles operating systems, user interfaces, application programs, etc., and a modem processor, which mainly handles wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 2.
The storage medium 3 may be used to store object files and modules such as software programs, and the processor 2 executes various functional applications and data processing by operating the object files and modules stored in the storage medium 3. The storage medium 3 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data created according to use of the computer device, and the like. Further, the storage medium 3 may include a high speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device. Accordingly, the storage medium 3 may also include a memory controller to provide the processor 2 access to the storage medium 3.
The computer device further comprises a power supply 1 for supplying power to each component, and preferably, the power supply 1 can be logically connected with the processor 2 through a power management system, so that functions of charging, discharging, power consumption management and the like can be managed through the power management system. The power supply 1 may also include one or more dc or ac power sources, recharging systems, power failure detection circuitry, power converters or inverters, power status indicators, and any other components.
The computer device may further comprise an input unit 4, the input unit 4 being operable to receive input numeric or character information and to generate keyboard, mouse, joystick, optical or trackball signal inputs in relation to user settings and function control.
Although not shown, the computer device may further include a display unit and the like, which are not described in detail herein. Specifically, in this embodiment, the processor 2 in the computer device loads the executable file corresponding to the process of one or more application programs into the storage medium 3 according to the following instructions, and the processor 2 runs the target file stored in the storage medium 3.
In a specific implementation, each unit or structure may be implemented as an independent entity, or may be combined arbitrarily to be implemented as one or several entities, and the specific implementation of each unit or structure may refer to the foregoing method embodiment, which is not described herein again.
The above operations can be implemented in the foregoing embodiments, and are not described in detail herein.
The principle and the implementation of the present application are explained herein by applying specific examples, and the above description of the embodiments is only used to help understand the method and the core idea of the present application; meanwhile, for those skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (10)

1. A data storage method in a storage medium is characterized in that a storage area of the storage medium comprises a first storage area used for storing a target file and a second storage area used for storing index information corresponding to the target file; the second storage area comprises a plurality of index units, each index unit can store index information of the target file stored in the first storage area, and the method comprises the following steps:
receiving a data writing command aiming at the storage medium, wherein the data writing command comprises the name and the size of a first file to be written;
inquiring whether an index unit of the first file exists in the second storage area;
if the index unit of the first file does not exist in the second storage area, allocating an idle first index unit for the first file in the second storage area; inquiring whether a free storage space with the first file size exists in the first storage area; if the first storage area has a free storage space with a first file size, allocating a free first storage space for the first file in the first storage area, and writing the first file into the first storage space;
if the second storage area has the index unit of the first file, writing the first file into a target storage space, wherein the target storage space is a storage space corresponding to the index unit of the first file in the first storage area or a free storage space in the first storage area.
2. The method of claim 1, wherein allocating free first storage space for the first file in the first storage area comprises:
if the first file is the nth file stored in the first storage area, inquiring the initial address of a storage space for storing the (n-1) th file and the data length of the (n-1) th file in the first storage area, and offsetting the data length of the (n-1) th file by the initial address of the storage space of the (n-1) th file to obtain the initial address of the first storage space;
allocating a free first storage space for the first file in the first storage area according to the initial address of the first storage space and the data length of the first file; wherein n is a natural number.
3. The method of claim 1, further comprising:
after the first file is written into the first storage space or the target storage space, updating the identification information of the first storage area; the identification information includes information of the number of times of erasing, the start address, and the number of times of writing data of a storage space for storing the first file, and information of the length of data of the first file.
4. The method of claim 3, further comprising: and after the identification information of the first storage area is updated, updating the index information of the first file in the index unit of the first file.
5. The method according to claim 1, wherein writing the first file into a target storage space if the index unit of the first file exists in the second storage area comprises:
judging the number of the index units of the first file in the second storage area;
if an index unit of the first file exists in the second storage area, writing the updated first file into a storage space corresponding to the index unit, or writing the updated first file into a free storage space of the first storage area;
and if two index units of the first file exist in the second storage area, two storage spaces corresponding to the two index units of the first file one to one exist in the first storage area, and the updated first file is written into any one of the two storage spaces.
6. The method for storing data in a storage medium according to claim 5, wherein writing the updated first file into the free storage space of the first storage area comprises:
allocating a new index unit for the first file in the second storage area, and inquiring whether a free storage space with the size of the first file exists in the first storage area; if the first storage area has a free storage space with the size of the first file, allocating a free storage space for the first file in the first storage area, and writing the first file into the free storage space.
7. The method for storing data in a storage medium according to claim 5, wherein writing the updated first file to any of the two storage spaces comprises:
the two storage spaces are respectively a third storage space of the first file and a fourth storage space of the first file;
inquiring data writing frequency information of the third storage space and data writing frequency information of the fourth storage space in the first storage area;
and if the data writing times of the fourth storage space are greater than the data writing times of the third storage space, using the first file stored in the fourth storage space for data recovery, and writing the updated first file in the third storage space.
8. The method of claim 1, further comprising:
if the first file is failed to be written into the first storage space, counting the number of continuous writing failures of the first file written into the first storage space;
if the continuous writing failure times of the first file written in the first storage space reach a preset value, allocating a new index unit for the first file in the second storage area;
inquiring whether a free storage space with the first file size exists in the first storage area; if the first storage area has a free storage space with the size of the first file, allocating a new free storage space for the first file in the first storage area, and writing the first file into the new free storage space.
9. A storage medium, wherein a storage area of the storage medium comprises:
a first storage area for storing an object file written to the first storage area by the in-storage-medium data storage method according to any one of claims 1 to 8; and the number of the first and second groups,
the second storage area is used for storing index information corresponding to the target file, the second storage area comprises a plurality of index units, and each index unit can store the index information of the target file stored in the first storage area.
10. A computer device, comprising:
one or more processors;
a storage medium; and the number of the first and second groups,
one or more object files written onto the storage medium by the in-storage-medium data storage method of any one of claims 1-8, the object files being loaded by the processor.
CN202011083395.8A 2020-10-12 2020-10-12 Method for storing data in storage medium, storage medium and computer device Active CN114327246B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011083395.8A CN114327246B (en) 2020-10-12 2020-10-12 Method for storing data in storage medium, storage medium and computer device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011083395.8A CN114327246B (en) 2020-10-12 2020-10-12 Method for storing data in storage medium, storage medium and computer device

Publications (2)

Publication Number Publication Date
CN114327246A true CN114327246A (en) 2022-04-12
CN114327246B CN114327246B (en) 2024-02-27

Family

ID=81032415

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011083395.8A Active CN114327246B (en) 2020-10-12 2020-10-12 Method for storing data in storage medium, storage medium and computer device

Country Status (1)

Country Link
CN (1) CN114327246B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116578247A (en) * 2023-07-10 2023-08-11 西安羚控电子科技有限公司 Metadata-based data access method and system

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070022148A1 (en) * 2005-07-20 2007-01-25 Akers David G Reserving an area of a storage medium for a file
CN105138655A (en) * 2015-08-31 2015-12-09 深圳市茁壮网络股份有限公司 Data storage and reading method and device
CN105468642A (en) * 2014-09-09 2016-04-06 杭州海康威视数字技术股份有限公司 Data storage method and apparatus
CN107818269A (en) * 2017-11-27 2018-03-20 杭州中天微系统有限公司 A kind of file saving method and system based on Flash
CN109189772A (en) * 2018-08-21 2019-01-11 华清瑞达(天津)科技有限公司 File management method and system for no file system storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070022148A1 (en) * 2005-07-20 2007-01-25 Akers David G Reserving an area of a storage medium for a file
CN105468642A (en) * 2014-09-09 2016-04-06 杭州海康威视数字技术股份有限公司 Data storage method and apparatus
CN105138655A (en) * 2015-08-31 2015-12-09 深圳市茁壮网络股份有限公司 Data storage and reading method and device
CN107818269A (en) * 2017-11-27 2018-03-20 杭州中天微系统有限公司 A kind of file saving method and system based on Flash
CN109189772A (en) * 2018-08-21 2019-01-11 华清瑞达(天津)科技有限公司 File management method and system for no file system storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
黄鹏;马洪兵;陈从华;: "基于FAT32的音视频存储系统的设计与实现", 电子设计工程 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116578247A (en) * 2023-07-10 2023-08-11 西安羚控电子科技有限公司 Metadata-based data access method and system
CN116578247B (en) * 2023-07-10 2023-10-13 西安羚控电子科技有限公司 Metadata-based data access method and system

Also Published As

Publication number Publication date
CN114327246B (en) 2024-02-27

Similar Documents

Publication Publication Date Title
CN108287669B (en) Date storage method, device and storage medium
US8832371B2 (en) Storage system with multiple flash memory packages and data control method therefor
US8677093B2 (en) Method and apparatus to manage tier information
CN106155915B (en) Data storage processing method and device
US10108359B2 (en) Method and system for efficient cache buffering in a system having parity arms to enable hardware acceleration
CN104636080A (en) Storage system and method therefor
US10489289B1 (en) Physical media aware spacially coupled journaling and trim
US7028140B2 (en) Storage system and method for acquisition and utilization of snapshots
EP3667504B1 (en) Storage medium management method, device and readable storage medium
US11301137B2 (en) Storage system and data arrangement method of storage system
CN103365603A (en) Method and apparatus of memory management by storage system
CN105242879A (en) Data storage method and protocol server
CN114822613A (en) Storage system and control method
JP2021034091A (en) Memory system and control method
CN112748867A (en) Method, electronic device and computer program product for storage management
CN115639970A (en) Storage virtualization method, system, device and equipment based on disk array card
US10620867B2 (en) System and method for performing wear leveling at a non-volatile firmware memory
CN113419672B (en) Storage capacity management method, system and storage medium
CN114327246A (en) Data storage method in storage medium, storage medium and computer equipment
CN113986137A (en) Storage device and storage system
US11262917B2 (en) Storage system and SSD swapping method of storage system
CN111124294B (en) Sector mapping information management method and device, storage medium and equipment
CN114995770B (en) Data processing method, device, equipment, system and readable storage medium
US10846023B2 (en) Storage device and storage area management method for reducing garbage collection processing
CN116301614A (en) Memory data access method, system, device and 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
CB02 Change of applicant information

Address after: 518110 floors 2-4, building 21, Longjun Industrial Zone, Jiuwo, Longping community, Dalang street, Longhua District, Shenzhen City, Guangdong Province

Applicant after: Shenzhen Aitushi Innovation Technology Co.,Ltd.

Address before: 518110 floors 2-4, building 21, Longjun Industrial Zone, Jiuwo, Longping community, Dalang street, Longhua District, Shenzhen City, Guangdong Province

Applicant before: APUTURE IMAGING INDUSTRIES Co.,Ltd.

CB02 Change of applicant information
GR01 Patent grant
GR01 Patent grant