Small-capacity Nor flash file storage device, method, apparatus, and medium
By using multiple file information blocks and content blocks in Nor flash file storage devices, combining record index and loop storage methods, file corruption and hash table complexity problems caused by power failure are solved, and fast file synchronization and stable data storage are achieved.
Patent Information
- Application Number
- CN202211256659.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-14
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2042-10-14
AI Technical Summary
The existing Nor flash file system is prone to corruption of the entire file when powered down, resulting in the content being unreadable. The hash table storage method leads to complex file information headers, long initialization time, and slow synchronization of file content.
A small-capacity Nor flash file storage device is used to use multiple file information blocks and file content blocks to write and erase data through record indexes to avoid power failure and damage, and use of loop storage methods and single-byte indexes to quickly calculate the write index position, reducing the use of hashing algorithms.
In the case of power failure, only one file information block content will be affected, and the content of other blocks will be retained, and the write index position will be quickly calculated, avoid file crashes, and improve file synchronization speed.
Smart Images

Figure CN115617769B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of file storage technology, and in particular to a small-capacity Nor flash file storage device, method, apparatus and medium. Background Art
[0002] Currently, file systems are commonly used in Nor flash. File systems used in computers are prone to corruption of entire files in the event of an unexpected power outage, rendering the entire file unreadable.
[0003] Furthermore, existing file systems generally use hash tables for storage, using a hash algorithm to find the address corresponding to the stored content and read and write data. This results in complex file headers, long file index initialization times, and difficulty or slow synchronization when storing the same file content across multiple storage systems.
[0004] In view of this, the applicant filed this application after studying the existing technology. Summary of the Invention
[0005] The present invention provides a small-capacity Nor flash file storage device, method, apparatus and medium to improve at least one of the above technical problems.
[0006] First,
[0007] An embodiment of the present invention provides a small-capacity Nor flash file storage device, which includes a processor, a memory, and record files and computer programs stored in the memory.
[0008] A record file includes at least two file information blocks and at least two file content blocks. The file information blocks correspond one-to-one with the file content blocks and record whether data is stored in the file content blocks. A file content block can store multiple records. The file information blocks contain record indexes that correspond one-to-one with the records.
[0009] The computer program can be executed by a processor to implement the data writing step. The data writing step includes steps S1 to S6.
[0010] S1. Obtain the data to be recorded and the write index, wherein the write index is used to identify the number of the next record in the record file.
[0011] S2. Calculate the target storage location of the data to be recorded in the file content block according to the write index.
[0012] S3. Determine whether the target storage location is the first record of the file content block. If so, erase the file content block where the target storage location is located, and then write the data to be recorded to the target storage location. Otherwise, directly write the data to be recorded to the target storage location.
[0013] S4. Calculate the target index position corresponding to the target storage position in the file information block according to the write index.
[0014] S5. Determine whether the target index position is the first record index of the file information block. If so, erase the file information block where the target index position is located. Then, mark the target index position as having a record. Otherwise, directly mark the target index position as having a record.
[0015] S6: The write index value is incremented by 1, and then a determination is made as to whether the write index is greater than the maximum write index value. If so, the write index value is assigned the minimum write index value.
[0016] Second aspect,
[0017] An embodiment of the present invention provides a file storage method for a small-capacity Nor flash, wherein the file storage method includes data writing, and the data writing includes steps S1 to S6.
[0018] S1. Obtain the data to be recorded and the write index, wherein the write index is used to identify the number of the next record in the record file.
[0019] S2. Calculate the target storage location of the data to be recorded in the file content block according to the write index.
[0020] S3. Determine whether the target storage location is the first record of the file content block. If so, erase the file content block where the target storage location is located, and then write the data to be recorded to the target storage location. Otherwise, directly write the data to be recorded to the target storage location.
[0021] S4. Calculate the target index position corresponding to the target storage position in the file information block according to the write index.
[0022] S5. Determine whether the target index position is the first record index of the file information block. If so, erase the file information block where the target index position is located. Then, mark the target index position as having a record. Otherwise, directly mark the target index position as having a record.
[0023] S6: The write index value is incremented by 1, and then a determination is made as to whether the write index is greater than the maximum write index value. If so, the write index value is assigned the minimum write index value.
[0024] Thirdly,
[0025] An embodiment of the present invention provides a small-capacity Nor flash file storage device, which includes a data writing module. The data writing module includes:
[0026] The write index acquisition unit is used to acquire the data to be recorded and the write index, wherein the write index is used to identify the number of the next record in the record file.
[0027] The storage position calculation unit is used to calculate the target storage position of the data to be recorded in the file content block according to the write index.
[0028] The storage write unit is configured to determine whether the target storage location is the first record in the file content block. If so, the file content block at the target storage location is erased, and the data to be recorded is then written to the target storage location. Otherwise, the data to be recorded is directly written to the target storage location.
[0029] The index position calculation unit is used to calculate the target index position corresponding to the target storage position in the file information block according to the write index.
[0030] The index writing unit is configured to determine whether the target index position is the first record index of the file information block. If so, the file information block containing the target index position is erased. The target index position is then marked as having a record. Otherwise, the target index position is directly marked as having a record.
[0031] The write index update unit is used to increase the write index value by 1 and then determine whether the write index is greater than the maximum write index value. If so, the write index is set to the minimum write index value.
[0032] Fourthly,
[0033] An embodiment of the present invention provides a computer-readable storage medium including a stored computer program, wherein when the computer program is executed, the device containing the computer-readable storage medium is controlled to execute the small-capacity Nor flash file storage method described in any paragraph of the second aspect.
[0034] By adopting the above technical solution, the present invention can achieve the following technical effects:
[0035] The file storage device of an embodiment of the present invention records files with multiple file information blocks. In the event of an unexpected power outage, only the contents of one file information block are affected, while the contents of the other file information blocks remain preserved, thus preventing the entire file system from being corrupted. Furthermore, the use of record indexes in the file information blocks, which correspond one-to-one with the stored records, eliminates the need for a hash algorithm when calculating the write index, enabling faster calculation of the write index and providing excellent practical benefits. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. It should be understood that the following drawings only illustrate certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without paying any creative work.
[0037] Figure 1 It is a flowchart of the data writing steps.
[0038] Figure 2 It records the overall structure of the file.
[0039] Figure 3 It is the overall structure of the file information block.
[0040] Figure 4 It means a single-byte index.
[0041] Figure 5 It is the correspondence between a single-byte index and a record in a content block.
[0042] Figure 6 It is the RAM information of the record file.
[0043] Figure 7 It is the writing process of the record file.
[0044] Figure 8 It is the initialization process of the record file.
[0045] Figure 9 It is the reading process of the record file.
[0046] Figure 10 It is a structural diagram of a file storage device. DETAILED DESCRIPTION
[0047] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0048] Example 1
[0049] See also Figures 1 to 8A first embodiment of the present invention provides a small-capacity Nor Flash file storage device, comprising a processor, a memory, and a record file and a computer program stored in the memory. The record file comprises at least two file information blocks and at least two file content blocks. The file information blocks correspond one-to-one with the file content blocks and are used to record whether data is stored in the file content blocks. The file content blocks can store multiple records. The file information blocks contain record indexes that correspond one-to-one with the records.
[0050] In this embodiment, the record file has N file information blocks and N file content blocks. Each file content block can store X records. Each information block has X record indexes (the number of records that each information block can store). Therefore, the maximum number of records that the record file can record is N x.
[0051] Specifically, such as Figure 2 As shown, the record file includes a plurality of file information blocks and content blocks connected in sequence, for example: file information block 1 - file information block 2 - ... file information block N - file content block 1 - file content block 2 - ... - file content block N.
[0052] In each file information block, there are X record indexes. Each record index is used to identify whether each record in the X records has data. Figure 5 As shown, the number of file information blocks is 1 to X, where X is at least equal to 2. The single-byte index of file information block 1 corresponds to the smaller address of the file content block, and the single-byte index of file information block N corresponds to the larger address of the file content block.
[0053] It should be noted that the small-capacity Nor Flash file storage device of the present invention is used in power meters, distribution terminals, protection devices, and other applications where SOE records, historical data, timing records, and fault records are stored. Generally, national standards or customers specify a maximum number of records that can be stored. When the record is full, the oldest record is deleted and a new one is written, thus forming a circular record.
[0054] like Figure 7 As shown, the computer program can be executed by a processor to implement the data writing step. The data writing step includes steps S1 to S6.
[0055] S1. Obtain the data to be recorded and the write index, wherein the write index is used to identify the number of the next record in the record file.
[0056] Specifically, the write index indicates the number of the next record to be saved within the total number of records, NX. In this embodiment, the write index ranges from 0 to NX-1. Subsequent address calculation equations are calculated based on this value selection rule. In other embodiments, the write index value range can be other ranges, such as 1 to NX, and this is not specifically limited in the present invention.
[0057] S2. Calculate the target storage location of the data to be recorded in the file content block according to the write index.
[0058] Specifically, the file information block size, file content block size, and the size of each record in the record file are fixed. Therefore, the target storage location can be quickly calculated based on the write index, without the need for hashing.
[0059] Target storage location = file start address + file information block size * number of file information blocks + file content block size * (write index / number of records stored in a single file content block, rounded down) + (write index % number of single file content blocks). Where % is the remainder, i.e., the remainder of write index / number of single file content blocks.
[0060] S3. Determine whether the target storage location is the first record of the file content block. If so, erase the file content block where the target storage location is located, and then write the data to be recorded to the target storage location. Otherwise, directly write the data to be recorded to the target storage location.
[0061] In this embodiment, a circular storage method is used for recording. That is, when the record of the current content block among N content blocks is full, the next content block is erased and new content is written into the next content block. When the record of the last content block is full, the content of the first content block is erased and the new content is written into it again. N content blocks form a circular storage.
[0062] Therefore, it is determined whether the location where the record is to be written is the starting location of the sector (content block). If it is at the starting location, then the sector (content block) may store an old record. Therefore, in this embodiment, when the location to be written is the starting location, the content block is erased first to avoid content confusion, which has good practical significance.
[0063] S4. Calculate the target index position corresponding to the target storage position in the file information block according to the write index.
[0064] Target index position addr = file start address + target information block size * (write index / number of index records contained in a single file information block, rounded down) + 7 + oft. In the formula, oft is (write index%number of index records contained in a single file information block), which is the remainder of the write index / number of index records contained in a single file information block. 7 represents 7 bytes, which is a 4-byte initialization flag for the current information block + a 1-byte not full flag + a 1-byte full flag + a 1-byte flag indicating successful initialization of the next information block. It should be noted that the above-mentioned calculation formulas for the target storage position and the target index position are only examples and do not constitute a specific limitation of the present invention.
[0065] In other embodiments, the content in the file information block can be of other types. For example, the current information block initialization success flag can be 1 byte, there can be no incomplete flag, and the number of bytes of other flags can be set to other sizes. The present invention does not limit the specific structure of the file information block, as long as it contains the current information block initialization success flag, the full flag, the next information block initialization success flag, and N record indexes; when the composition of the file information block changes, the calculation formula of the target storage position and the calculation formula of the target index position will change accordingly.
[0066] S5. Determine whether the target index position is the first record index of the file information block. If so, erase the file information block where the target index position is located. Then, mark the target index position as having a record. Otherwise, directly mark the target index position as having a record.
[0067] Similar to the principle of erasing content blocks, the embodiment of the present invention adopts a circular storage method for recording. Therefore, when the location of the stored record is a new block, the new block is erased to avoid the storage of old records in the block, which would cause the content of the recorded file to be disordered, which has great practical significance.
[0068] On the basis of the above embodiment, in an optional embodiment of the present invention, as Figure 3 As shown, the file information block includes an information block initialization flag, a subsequent information block initialization success flag, and multiple record indexes. Preferably, step S5 specifically includes step S51 and step S53.
[0069] S51: Determine whether the target index position is the first record index of the file information block. If so, erase the file information block where the target index position is located to remove all identifiers in the current file information block, then mark the information block initialization identifier of the current file information block, and mark the information block initialization success identifier of the next file information block of the previous file information block.
[0070] S53: Mark the record index at the target index position as having a record.
[0071] On the basis of the above embodiment, in an optional embodiment of the present invention, as Figure 3 As shown, the file information block includes a full flag and a not full flag. Preferably, step S5 specifically further includes step S52. S52: Determine whether the target index position is the last record index of the file information block. If so, mark the full flag of the current information block.
[0072] Specifically, step S51 comprises determining whether the target index position is the first record index of the file information block. If so, erasing the file information block where the target index position is located to remove all identifiers in the current file information block, then marking the information block initialization identifier and the not-full identifier of the current file information block, and marking the information block initialization success identifier of the next information block of the previous file information block.
[0073] In this embodiment, the information block status is recorded using an information block initialization flag, a non-full flag, a full flag, a flag indicating the next information block has been successfully initialized, and X record indexes. During the initialization process, these records can be used to quickly calculate and identify the next record to be stored in the N records of the record file. In other words, the write index can be quickly calculated based on the file information block. This calculation process is much faster than a hash algorithm, making content synchronization between multiple storage systems more convenient and rapid.
[0074] S6: The write index value is incremented by 1, and then a determination is made as to whether the write index is greater than the maximum write index value. If so, the write index value is assigned the minimum write index value.
[0075] Specifically, after data recording is completed, the write index value is increased by 1 to point to the next record. When the write index reaches the maximum value, the next record is the first record, which corresponds to the minimum value of the write index, thus completing the loop recording.
[0076] The file storage device of the embodiment of the present invention records a file with multiple file information blocks. When power is lost unexpectedly, only the content of one file information block is affected, and the contents of other file information blocks are still preserved, so the entire file system will not be corrupted.
[0077] In addition, in the file information block, a record index that corresponds one-to-one to the stored record is used. There is no need to use a hash algorithm when calculating the write index, and the write index can be calculated more quickly, which has great practical significance.
[0078] Based on the above embodiment, in an optional embodiment of the present invention, the record index is a single-byte index. Figure 3As shown, each file information block includes a 4-byte information block initialization flag, a 1-byte not full flag, a 1-byte full flag, a 1-byte flag indicating successful initialization of the next information block, and X 1-byte single-byte indexes.
[0079] like Figure 4 As shown, each byte in the single-byte index indicates whether the corresponding file content record address has data recorded. A value equal to 0xff indicates that the file content address mapped by the write index has no data recorded. A value equal to 0x0 indicates that the file content address mapped by the write index has one record recorded.
[0080] like Figure 6 For example, file RAM information, file initialization is to extract the file information into static RAM to facilitate subsequent file read and write operations and file information recording to Nor Flash.
[0081] like Figure 8 As shown, based on the above embodiment, in an optional embodiment of the present invention, a computer program can be executed by a processor to implement the file initialization step. The file initialization step includes steps A1 to A3.
[0082] A1. Get file attribute information.
[0083] Based on the above embodiment, in an optional embodiment of the present invention, the file storage device further includes file attribute information stored in the memory. Figure 6 As shown, file attribute information includes the file number, the number of file information blocks, the number of records that can be stored in each file information block, the file start address, the file end address, and the data size of each record. It should be noted that the above file attribute information is only an example. In practice, those skilled in the art may select only part of the file attribute information or include more file attribute information according to their actual needs.
[0084] Preferably, the processor may be a single-chip microcomputer. In an optional embodiment, the memory includes ROM memory and Norflash memory. Computer programs and file attribute information are stored in the ROM memory and / or Norflash memory. Log files are stored in the Norflash memory. Specifically, the ROM memory may be a built-in memory of the single-chip microcomputer. The Norflash memory is an external memory.
[0085] A2. Read the file information block according to the file attribute information.
[0086] Specifically, the single chip microcomputer directly reads the pre-stored file attribute information, thereby obtaining the address of the record file and reading the record file.
[0087] A3. Calculate the write index based on the file information block to obtain the file RAM information.
[0088] Specifically, in addition to reading the file attribute information, the most important initialization step is to calculate the write index. In this embodiment, the simplest way to calculate the write index is to traverse all file information blocks and find the first record index marked as having no record. This does not require the use of a hash algorithm, is faster to identify, and has great practical significance.
[0089] like Figure 8 As shown, in an optional embodiment, step A3 includes steps A32 to A38.
[0090] A32. Starting from the first file information block, read the information block initialization flag, the full flag, and the subsequent information block initialization success flag, and perform the following steps to obtain the write index:
[0091] A33. Determine whether the currently read file information block is initialized successfully. If not, increment the information block sequence number by 1 and read the next file information block. If yes, proceed to the next step.
[0092] A34. Determine whether the next file information block is initialized successfully. If so, increment the information block sequence number by 1 and read the next file information block. If not, proceed to the next step.
[0093] A35. Determine whether the currently read file information block is full. If so, assign the write index value corresponding to the first record of the next information block. If not, proceed to the next step.
[0094] A36. Search for multiple record indexes of the currently read file information block, obtain the first unrecorded record index, and assign the write index to the write index value corresponding to the first unrecorded record index.
[0095] A37. When the last file information block is read, determine whether the currently read file information block is initialized successfully. If not, assign the write index value to the minimum write index value. If so, proceed to the next step.
[0096] A38. Search for multiple record indexes of the last file information block, obtain the first unrecorded record index, and assign the write index to the write index value corresponding to the first unrecorded record index.
[0097] Preferably, step A3 also includes step A31.
[0098] A31. Read the last file information block. If it is determined that the last file information block is successfully initialized and full, and the next information block is not successfully initialized, the write index is assigned the minimum value. Otherwise, proceed to the next step.
[0099] Specifically, step A31 may be arranged before step A32 or after step A37, and the step numbers do not limit the order of the steps.
[0100] In this embodiment, it is first determined whether the file information block is just full. If so, the write index is assigned to the minimum write index value. If not, traverse and read from the first file information block. If the information block initialization is unsuccessful, read the next information block until the last information block initialization is unsuccessful, then the write index is assigned to the minimum write index value. If the information block initialization is successful, it is determined whether the current information block is just full. If it is just full, the write index value = information block number * number of record indexes contained in the information block. Since the write index value starts from 0, the calculated write index is just the first record of the next information block. If the current information block is not full, it means that the write index is a record index of the current information block. Therefore, the record index of the current information block is identified by binary search, so as to find the first unrecorded record index and obtain its corresponding write index.
[0101] The write index calculation method of the embodiment of the present invention adopts a binary search method instead of a hash algorithm, and its calculation speed is faster.
[0102] like Figure 9 As shown, based on the above embodiment, in an optional embodiment of the present invention, a computer program can be executed by a processor to implement the data reading step. The data reading step includes steps B1 to B4.
[0103] B1. Obtain the write index and the record sequence number of the record to be read.
[0104] Specifically, the record number of the latest record is 1, the record number of the previous record is 2, and so on.
[0105] B2. Calculate the read index based on the write index and record sequence number.
[0106] Specifically, the read index is the location of the next record to be recorded. The record sequence number is the number of records to be read, counting forward from the latest record.
[0107] When the write index is greater than the record number, the read index = write index - record number.
[0108] When the write index is smaller than the record number, the read index = maximum number of records NX + write index - record number.
[0109] B3. Calculate the address of the record to be read in the file content block based on the read index.
[0110] Specifically, the address is calculated according to the read index, and the calculation equation thereof is the same as that for calculating the address according to the write index, and the calculation equation for the target storage location is not repeated herein in the present invention.
[0111] B4. Read the record to be read according to the address.
[0112] This embodiment of the present invention uses a single-byte index to map file content addresses, enabling file information to be processed during power outages. This ensures that at most one record will be lost during a power outage. The write index has a one-to-one correspondence with the Nor Flash hardware byte address, facilitating data synchronization when multiple storage systems store the same file content. Furthermore, file information index initialization requires only a simple determination and calculation to determine the write index location, significantly faster than using a hash table to store indexes. This allows for rapid file indexing when storing large numbers of files.
[0113] Example 2
[0114] See also Figures 7 to 9 An embodiment of the present invention provides a file storage method for a small-capacity Nor flash, which can be executed by a small-capacity Nor flash file storage device (hereinafter referred to as a "file storage device"). In particular, the method is executed by one or more processors in the file storage device to implement data writing.
[0115] The file storage method includes data writing, which includes steps S1 to S6.
[0116] S1. Obtain the data to be recorded and the write index, wherein the write index is used to identify the number of the next record in the record file.
[0117] S2. Calculate the target storage location of the data to be recorded in the file content block according to the write index.
[0118] S3. Determine whether the target storage location is the first record of the file content block. If so, erase the file content block where the target storage location is located, and then write the data to be recorded to the target storage location. Otherwise, directly write the data to be recorded to the target storage location.
[0119] S4. Calculate the target index position corresponding to the target storage position in the file information block according to the write index.
[0120] S5. Determine whether the target index position is the first record index of the file information block. If so, erase the file information block where the target index position is located. Then, mark the target index position as having a record. Otherwise, directly mark the target index position as having a record.
[0121] S6: The write index value is incremented by 1, and then a determination is made as to whether the write index is greater than the maximum write index value. If so, the write index value is assigned the minimum write index value.
[0122] In an optional embodiment, step S5 specifically includes step S51 and step S53.
[0123] S51: Determine whether the target index position is the first record index of the file information block. If so, erase the file information block where the target index position is located to remove all identifiers in the current file information block, then mark the information block initialization identifier of the current file information block, and mark the information block initialization success identifier of the next file information block of the previous file information block.
[0124] S53: Mark the record index at the target index position as having a record.
[0125] In an optional embodiment, step S5 specifically further includes step S52.
[0126] S52 determines whether the target index position is the last record index of the file information block. If so, the full flag of the current information block is marked.
[0127] In an optional embodiment, step S51 specifically includes determining whether the target index position is the first record index of the file information block. If so, erasing the file information block where the target index position is located to remove all identifiers in the current file information block, then marking the information block initialization identifier and the not-full identifier of the current file information block, and marking the information block initialization success identifier of the next information block of the previous file information block.
[0128] In an optional embodiment, the file storage method includes file initialization, which includes steps A1 to A3.
[0129] A1. Get file attribute information.
[0130] A2. Read the file information block according to the file attribute information.
[0131] A3. Calculate the write index based on the file information block to obtain the file RAM information.
[0132] In an optional embodiment, step A3 includes steps A32 to A38.
[0133] A32. Starting from the first file information block, read the information block initialization flag, the full flag, and the subsequent information block initialization success flag, and perform the following steps to obtain the write index:
[0134] A33. Determine whether the currently read file information block is initialized successfully. If not, increment the information block sequence number by 1 and read the next file information block. If yes, proceed to the next step.
[0135] A34. Determine whether the next file information block is initialized successfully. If so, increment the information block sequence number by 1 and read the next file information block. If not, proceed to the next step.
[0136] A35. Determine whether the currently read file information block is full. If so, assign the write index value corresponding to the first record of the next information block. If not, proceed to the next step.
[0137] A36. Search for multiple record indexes of the currently read file information block, obtain the first unrecorded record index, and assign the write index to the write index value corresponding to the first unrecorded record index.
[0138] A37. When the last file information block is read, determine whether the currently read file information block is initialized successfully. If not, assign the write index value to the minimum write index value. If so, proceed to the next step.
[0139] A38. Search for multiple record indexes of the last file information block, obtain the first unrecorded record index, and assign the write index to the write index value corresponding to the first unrecorded record index.
[0140] In an optional embodiment, step A3 also includes step A31.
[0141] A31. Read the last file information block. If it is determined that the last file information block is successfully initialized and full, and the next information block is not successfully initialized, the write index is assigned the minimum value. Otherwise, proceed to the next step.
[0142] In an optional embodiment, the file storage method includes data reading, which includes steps B1 to B4.
[0143] B1. Obtain the write index and the record sequence number of the record to be read.
[0144] B2. Calculate the read index based on the write index and record sequence number.
[0145] B3. Calculate the address of the file content block to be read based on the write index.
[0146] B4. Read the record to be read according to the address.
[0147] Example 3:
[0148] See also Figure 9 The embodiment of the present invention provides a small-capacity Nor flash file storage device, which includes a data writing module. The data writing module includes:
[0149] The write index acquisition unit 1 is used to acquire the data to be recorded and the write index, wherein the write index is used to identify the number of the next record in the record file.
[0150] The storage position calculation unit 2 is used to calculate the target storage position of the data to be recorded in the file content block according to the write index.
[0151] The storage writing unit 3 is configured to determine whether the target storage location is the first record of the file content block. If so, the file content block at the target storage location is erased, and then the data to be recorded is written to the target storage location. Otherwise, the data to be recorded is directly written to the target storage location.
[0152] The index position calculation unit 4 is configured to calculate a target index position corresponding to the target storage position in the file information block according to the write index.
[0153] Index writing unit 5 is used to determine whether the target index position is the first record index of the file information block. If so, the file information block where the target index position is located is erased. The target index position is then marked as having a record. Otherwise, the target index position is directly marked as having a record.
[0154] The write index updating unit 6 is configured to add 1 to the write index value and then determine whether the write index is greater than the write index maximum value. If so, the write index is assigned the write index minimum value.
[0155] In an optional embodiment, the index writing unit 5 includes:
[0156] The information block erasing subunit is configured to determine whether the target index position is the first record index of a file information block. If so, it erases the file information block at the target index position to remove all identifiers in the current file information block. It then marks the information block initialization identifier of the current file information block and the information block initialization success identifier subsequent to the previous file information block.
[0157] The index writing subunit is used to mark the record index at the target index position as having a record.
[0158] In an optional embodiment, the index writing unit 5 further includes:
[0159] The full flag subunit is used to determine whether the target index position is the last record index of the file information block. If so, the full flag of the current information block is marked.
[0160] In an optional embodiment, the information block erasing subunit is specifically configured to determine whether the target index position is the first record index of the file information block. If so, the file information block at the target index position is erased to remove all identifiers in the current file information block, and then the information block initialization identifier and the not-full identifier of the current file information block are marked, as well as the information block initialization success identifier of the subsequent file information block.
[0161] In an optional embodiment, the file storage device includes a file initialization module. The file initialization module includes:
[0162] The attribute acquisition unit is used to obtain file attribute information.
[0163] The information block reading unit is used to read the file information block according to the file attribute information.
[0164] The write index calculation unit is used to calculate the write index according to the file information block to obtain the file RAM information.
[0165] In an optional embodiment, the write index calculation unit includes:
[0166] The information reading subunit is used to read the information block initialization flag, the full flag, and the subsequent information block initialization success flag starting from the first file information block, and perform the following steps to obtain the write index:
[0167] The first current information block initialization judgment subunit is used to judge whether the currently read file information block is initialized successfully. If not, the information block sequence number is increased by 1 and the next file information block is read. If so, the next step is executed.
[0168] The first subsequent information block initialization judgment subunit is used to judge whether the subsequent file information block is initialized successfully. If so, the information block sequence number is increased by 1 and the next file information block is read. If not, the next step is executed.
[0169] The current information block full determination subunit is used to determine whether the currently read file information block is full. If so, the write index is assigned the write index value corresponding to the first record of the next information block. If not, the next step is executed.
[0170] The first index search subunit is used to search for multiple record indexes of the currently read file information block, obtain the first unrecorded record index, and assign the write index to the write index value corresponding to the first unrecorded record index.
[0171] The second current information block initialization judgment subunit is used to judge whether the currently read file information block is initialized successfully when reading the last file information block. If not, the write index is assigned to the minimum write index value. If so, the next step is executed.
[0172] The second index search subunit is used to search for multiple record indexes of the last file information block, obtain the first unrecorded record index, and assign the write index to the write index value corresponding to the first unrecorded record index.
[0173] In an optional embodiment, the write index calculation unit further includes:
[0174] The second subsequent information block initialization judgment subunit is used to read the last file information block. If it is determined that the last file information block has been successfully initialized and is full, and the subsequent information block has not been successfully initialized, the write index is assigned the minimum value. Otherwise, the next step is executed.
[0175] In an optional embodiment, the file storage device includes a data reading module. The data reading module includes:
[0176] The record sequence number acquisition subunit is used to obtain the write index and the record sequence number of the record to be read.
[0177] The read index calculation subunit is used to calculate the read index according to the write index and the record sequence number.
[0178] The read address calculation subunit is used to calculate the address to be read recorded in the file content block according to the write index.
[0179] The reading subunit is used to read the record to be read according to the address.
[0180] Example 4:
[0181] An embodiment of the present invention provides a computer-readable storage medium including a stored computer program, wherein when the computer program is executed, the device containing the computer-readable storage medium is controlled to execute the small-capacity Nor flash file storage method described in any one of the sections of the second embodiment.
[0182] In the several embodiments provided in the embodiments of the present invention, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device and method embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architectures, functions, and operations of the devices, methods, and computer program products according to multiple embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or part of the code, which contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions marked in the boxes can also occur in an order different from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, as well as the combination of boxes in the block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified functions or actions, or can be implemented using a combination of dedicated hardware and computer instructions.
[0183] In addition, the functional modules in the various embodiments of the present invention may be integrated together to form an independent part, or each module may exist independently, or two or more modules may be integrated to form an independent part.
[0184] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, electronic device, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes various media that can store program code, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk. It should be noted that, in this article, the terms "include", "comprising" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device that includes a series of elements includes not only those elements, but also other elements that are not explicitly listed, or also includes elements inherent to such a process, method, article or device. Without further constraints, an element defined by the phrase "comprises a..." does not preclude the existence of additional identical elements in the process, method, article or apparatus that includes the element.
[0185] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The singular forms "a", "an", "the" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise.
[0186] It should be understood that the term "and / or" as used herein is merely a description of the relationship between associated objects, indicating that three possible relationships exist. For example, "A and / or B" can represent: A exists alone, A and B exist simultaneously, or B exists alone. Furthermore, the character " / " in this document generally indicates that the associated objects are in an "or" relationship.
[0187] The word "if," as used herein, may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting," depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to the determination" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)," depending on the context.
[0188] The "first" and "second" mentioned in the embodiments are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It is understood that the specific order or precedence of "first" and "second" can be interchanged where appropriate. It should be understood that the objects distinguished by "first" and "second" can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein.
[0189] The foregoing description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Those skilled in the art will readily appreciate that various modifications and variations of the present invention are possible. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present invention are intended to be within the scope of protection of the present invention.
Claims
1. A small-capacity Nor flash file storage device, characterized in that: The system comprises a processor, a memory, and a record file and a computer program stored in the memory; the record file comprises at least two file information blocks and at least two file content blocks; the file information blocks correspond one-to-one with the file content blocks and are used to record whether data is stored in the file content blocks; the file content blocks can store multiple records; the file information blocks contain record indexes that correspond one-to-one with the records; The computer program can be executed by the processor to implement the following data writing steps: Obtaining the data to be recorded and the write index; wherein the write index is used to identify the number of the next record in the record file; Calculating a target storage location of the data to be recorded in the file content block according to the write index; Determine whether the target storage location is the first record of the file content block; if so, erase the file content block where the target storage location is located, and then write the data to be recorded into the target storage location; otherwise, directly write the data to be recorded into the target storage location; Calculate a target index position corresponding to the target storage position in the file information block according to the write index; Determine whether the target index position is the first record index of the file information block; if so, erase the file information block where the target index position is located; then mark the target index position as having a record; otherwise, directly mark the target index position as having a record; The write index value is increased by 1, and then it is determined whether the write index is greater than the maximum write index value; if so, the write index is assigned the minimum write index value.
2. The small-capacity Nor flash file storage device according to claim 1, characterized in that: The file information block includes an information block initialization flag, a subsequent information block initialization success flag, and multiple record indexes; Determine whether the target index position is the first record index of the file information block; if so, erase the file information block where the target index position is located, and then mark the target index position as having a record; otherwise, directly mark the target index position as having a record, specifically including: Determine whether the target index position is the first record index of the file information block; if so, erase the file information block where the target index position is located to remove all identifiers in the current file information block, then mark the information block initialization identifier of the current file information block, and mark the information block initialization success identifier of the next file information block of the previous file information block; Mark the record index at the target index position as having a record.
3. The small-capacity Nor flash file storage device according to claim 2, characterized in that: The record index is a single-byte index; the file information block includes a full flag and a not full flag; Before or after marking the target index position as having a record, also includes: Determine whether the target index position is the last record index of the file information block; if so, mark the full flag of the current information block; Determine whether the target index position is the first record index of the file information block; if so, erase the file information block where the target index position is located to remove all identifiers in the current file information block, then mark the information initialization identifier of the current information block, and mark the initialization success identifier of the next information block of the previous information block, specifically including: Determine whether the target index position is the first record index of the file information block; if so, erase the file information block where the target index position is located to remove all identifiers in the current file information block, and then mark the information block initialization identifier and the not full identifier of the current file information block, and mark the information block initialization success identifier of the next information block of the previous file information block.
4. The small-capacity Nor flash file storage device according to claim 1, characterized in that: Also included is file attribute information stored in the memory; the file attribute information includes the file number, the number of file information blocks, the number of records that can be stored in each file information block, the file start address, the file end address, and the data size of each record; The memory includes a ROM memory and a Nor flash memory; the computer program and the file attribute information are stored in the ROM memory and / or the Nor flash memory; the record file is stored in the Nor flash memory; The computer program can be executed by the processor to implement the following file initialization steps: Get file attribute information; Reading a file information block according to the file attribute information; A write index is calculated based on the file information block to obtain file RAM information.
5. The small-capacity Nor flash file storage device according to claim 4, characterized in that: Calculating and writing indexes specifically includes: Starting from the first file information block, read the information block initialization flag, full flag, and the next information block initialization success flag, and perform the following steps to obtain the write index: Determine whether the currently read file information block is initialized successfully; if not, increment the information block number by 1 and read the next file information block; if so, execute the next step; Determine whether the next file information block is initialized successfully; if so, increment the information block number by 1 and read the next file information block; if not, proceed to the next step; Determine whether the currently read file information block is full; if so, assign the write index value to the write index value corresponding to the first record of the next information block; if not, execute the next step; Search multiple record indexes of the currently read file information block, obtain the first unrecorded record index, and assign the write index to the write index value corresponding to the first unrecorded record index; When the last file information block is read, determine whether the initialization of the currently read file information block is successful; if not, assign the write index value to the write index minimum value; if so, execute the next step; Search multiple record indexes of the last file information block, obtain the first unrecorded record index, and assign the write index to the write index value corresponding to the first unrecorded record index; Starting from the first file information block, before reading the information block initialization flag, the full flag, and the next information block initialization success flag, it also includes: Read the last file information block. When it is determined that the last file information block is initialized successfully and is full, and the next information block is not initialized successfully, write the index value to the minimum value; otherwise, execute the next step.
6. The small-capacity Nor flash file storage device according to claim 4, characterized in that: The computer program can be executed by the processor to implement the following data reading steps: Get the write index and the record number of the record to be read; Calculating a read index based on the write index and the record sequence number; Calculate the address of the file content block to be read according to the read index; The record to be read is read according to the address.
7. A file storage method for small-capacity Nor flash, characterized in that: The file storage method includes data writing; the data writing includes: Obtaining the data to be recorded and the write index; wherein the write index is used to identify the number of the next record in the record file; Calculating a target storage location of the data to be recorded in the file content block according to the write index; Determine whether the target storage location is the first record of the file content block; if so, erase the file content block where the target storage location is located, and then write the data to be recorded into the target storage location; otherwise, directly write the data to be recorded into the target storage location; Calculate a target index position corresponding to the target storage position in the file information block according to the write index; Determine whether the target index position is the first record index of the file information block; if so, erase the file information block where the target index position is located; then mark the target index position as having a record; otherwise, directly mark the target index position as having a record; The write index value is increased by 1, and then it is determined whether the write index is greater than the maximum write index value; if so, the write index is assigned the minimum write index value.
8. A small-capacity Nor flash file storage device, characterized in that: Contains a data writing module; the data writing module includes: A write index acquisition unit, configured to acquire data to be recorded and a write index; wherein the write index is used to identify the number of the next record in the record file; a storage position calculation unit, configured to calculate a target storage position of the data to be recorded in the file content block according to the write index; a storage writing unit, configured to determine whether the target storage location is the first record of a file content block; if so, erase the file content block where the target storage location is located, and then write the data to be recorded to the target storage location; otherwise, directly write the data to be recorded to the target storage location; An index position calculation unit, configured to calculate a target index position corresponding to the target storage position in the file information block according to the write index; An index writing unit is configured to determine whether the target index position is the first record index of a file information block; if so, erase the file information block where the target index position is located; and then mark the target index position as having a record; otherwise, directly mark the target index position as having a record; The write index update unit is used to add 1 to the write index value and then determine whether the write index is greater than the write index maximum value; if so, the write index is assigned the write index minimum value.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium includes a stored computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the file storage method for small-capacity Nor flash according to claim 7.
Citation Information
Patent Citations
Flash data storage method
CN106293532A
Management method for data storage in Flash
CN113190182A