File data access method and device based on NAND flash, equipment and storage medium
By using a chained storage block structure and index information lookup, the problem of uneven erasure and write in the NAND FLASH file directory area was solved, achieving balanced use and extended lifespan of storage blocks, and improving file data writing efficiency.
Patent Information
- Application Number
- CN202210940627.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-06
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2042-08-06
AI Technical Summary
Uneven write/erase frequencies in the NAND flash file directory area can cause storage blocks to fail prematurely, shortening its lifespan and potentially even damaging the entire file system.
A chained storage block structure is adopted, which distributes file data across each storage block. File data is retrieved through the index information of the file header block, reducing the number of erases and writes to critical areas. Storage blocks with free or dirty data are used first for erasure and writing, thus balancing the use of storage blocks.
It improves the wear leveling performance of NAND FLASH, extends its lifespan, reduces the number of erase cycles of storage blocks, and improves the writing efficiency of file data and the utilization rate of storage blocks.
Smart Images

Figure CN115359825B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of file storage, and in particular to a method, apparatus, device and storage medium for accessing file data based on NAND FLASH. Background Technology
[0002] NAND FLASH is a high-capacity storage chip characterized by high capacity density, low manufacturing cost, and fast access speed. It is widely used in the industry and is commonly used as a storage chip in devices such as USB flash drives, solid-state drives, and memory cards.
[0003] NAND flash erases data block by block, while reading and writing can be done in bytes. Writing file data requires first erasing the block containing the data to be written, and then performing the write operation. For example, to write one byte of data, the entire block must be erased. Each time file data is written, the block containing the file directory area of the NAND flash needs to be erased and rewritten, resulting in a high write frequency for the file directory area.
[0004] Such uneven writing and erasing may cause the storage blocks in the file directory area to be corrupted prematurely, resulting in bad blocks, which shortens the lifespan of the NAND FLASH file system and may even lead to the destruction of the entire NAND FLASH file system. Summary of the Invention
[0005] To improve the wear leveling performance of NAND FLASH and thus extend its lifespan, this application provides a file data access method, apparatus, device, and storage medium based on NAND FLASH.
[0006] Firstly, this application provides a file data access method based on NAND FLASH, employing the following technical solution:
[0007] A method for accessing file data based on NADA FLASH, comprising:
[0008] Get file data;
[0009] Select a writable storage block from the NAND FLASH as the current storage block based on block attributes;
[0010] Write the data in the file that has not been written to the NAND FLASH into the current storage block;
[0011] Determine whether all data in the file that has not been written to the NAND FLASH has been written to the current storage block;
[0012] If no, repeat the step of selecting a writable storage block from the NAND FLASH as the current storage block until the file is completely written into the NAND FLASH.
[0013] If a plurality of writable storage blocks are selected as the current storage block in sequence, the first selected writable storage block is a file header block, the last selected writable storage block is a file tail block, and the remaining selected writable blocks are ordinary storage blocks.
[0014] The current storage block has index information bits, the index information bits of the file header block include a file name bit, a block attribute bit, a block sequence number bit of a next storage block, and a data length bit of a last storage block.
[0015] The index information bits of the file tail block include a block attribute bit.
[0016] The index information bits of the ordinary storage block include a block attribute bit and a block sequence number bit of a next storage block.
[0017] If the current storage block is the file header block, after the writable storage block is selected from the NAND FLASH as the current storage block based on the block attribute, the index information of the file header block is updated based on the block sequence number of the next storage block of the file header block.
[0018] If the current storage block is an ordinary storage block, after the writable storage block is selected from the NAND FLASH as the current storage block based on the block attribute, the index information of the ordinary header block is updated based on the block sequence number of the next storage block of the ordinary header block.
[0019] If the current storage block is the file tail block, after the writable storage block is selected from the NAND FLASH as the current storage block based on the block attribute, file data is written until the file is completely written into the NAND FLASH.
[0020] By using the above technical solution, by storing file data in a chain structure of storage blocks, and by using a chain structure to distribute file data to each storage block for distributed storage, there is no need to set a key area (such as a file directory area) in the NAND FLASH, the entire file data can be queried through the index information of the file header block, when the file data is rewritten, the number of times of erasing and writing the key area storage block is reduced, the possibility of damaging the entire NAND FLASH is reduced, the performance of balancing the wear of the NAND FLASH is improved, and the service life of the NAND FLASH is improved.
[0021] Optionally, the block attribute comprises free, writing, valid and dirty data.
[0022] When the current storage block is erased, the block attribute of the current storage block is updated to free.
[0023] When the file data is written into the current storage block, the block attribute of the current storage block is updated to writing.
[0024] When the file data is written into the current storage block, the block attribute of the current storage block is updated to valid.
[0025] When the file self-check is performed, if the block data of the current storage block is invalid, the block attribute of the current storage block is updated to dirty data.
[0026] By using the above technical solution, the storage block with writable attribute is queried, the balanced use of the storage block is ensured, and the possibility of waste of the storage block is reduced.
[0027] Optionally, the selecting a writable storage block from the NAND FLASH as the current storage block based on the block attribute comprises:
[0028] Querying whether there is a storage block with free attribute, if there is a storage block with free attribute, selecting any one of the storage block with free attribute as the current storage block;
[0029] If there is no storage block with free attribute, querying whether there is a storage block with dirty data attribute;
[0030] If there is a storage block with dirty data attribute, selecting any one of the storage block with dirty data attribute;
[0031] Erasing the storage block, and taking the erased storage block as the current storage block.
[0032] By using the above technical solution, the storage block with free attribute which is not written is used preferentially, after all the storage blocks with free attribute are written, the storage block with dirty data attribute which is written is erased for writing, so that the balanced allocation of the erasing and writing times of each storage block is realized, and the performance of wear leveling of the NAND FLASH is improved.
[0033] Optionally, the file data comprises a file name, before the selecting a writable storage block from the NAND FLASH as the current storage block based on the block attribute, further comprising:
[0034] Querying whether there is historical data of the file data based on the file name;
[0035] If the history data of the file data exists in the NAND FLASH, the file data is cut into N data blocks according to the size of a storage block;
[0036] The N data blocks are compared with the block data of the storage block corresponding to the history data, the storage block to which the N data blocks are written and / or rewritten is determined, and the data block of the file data corresponding to the storage block is written and / or rewritten to the storage block.
[0037] By using the above technical solution, when the file data is written, the history data is rewritten only when the history data is rewritten, otherwise the storage block of the NAND FLASH is not erased, but the storage block of the history data or the writable storage block in the NAND FLASH is directly written, the number of erasing all the storage blocks of the history data is reduced, not only the file data read / write efficiency is improved, but also the number of NAND FLASH erasing operations is reduced, for the file which only appends the file data, the storage block of the history data is not erased, the performance of writing the file data is greatly improved.
[0038] Optionally, the query whether the history data of the file data exists based on the file name comprises:
[0039] The file header block of the file data is queried based on the file name;
[0040] If the file header block of the file data exists, the normal data block or the file tail block of the file data is queried based on the index information of the file header block;
[0041] The next normal data block or the file tail block of the file data is queried based on the index information of the normal data block, until all the storage blocks of the file data are confirmed;
[0042] All the storage blocks of the file data are read to obtain the history data of the file data.
[0043] By using the above technical solution, the file data is stored in the NAND FLASH in a chain structure of storage blocks, and the different storage blocks of the file data are identified by index information, so that the file data is easily found and self-checked.
[0044] Optionally, the comparison of the N data blocks with the block data of the storage block corresponding to the history data, the determination of the storage block to which the N data blocks are written and / or rewritten, and the writing and / or rewriting of the data block of the file data corresponding to the storage block to the storage block comprise:
[0045] The number of blocks of the data block currently written into the file data is identified as 0;
[0046] selecting one of the N data blocks as the current writing data block and setting the current writing data block, and increasing the number of blocks of the file data by 1;
[0047] judging whether the block position of the current writing data block exceeds the block length of the historical data stored in the storage block;
[0048] if the block position of the current writing data block does not exceed the block length, determining the storage block of the historical data based on the block position of the current writing data block;
[0049] judging whether the storage block has writing and / or rewriting based on the block data of the current writing data block and the storage block;
[0050] if the storage block has writing, writing the data block into the storage block;
[0051] if the storage block has rewriting, erasing the block data of the storage block and writing the data block into the storage block;
[0052] if the storage block has no writing and / or rewriting, performing the step of selecting one of the N data blocks as the current writing data block until the number of blocks of the file data is not less than N;
[0053] if the block position of the current writing data block exceeds the block length, selecting a writable storage block from the NAND FLASH based on the block attribute and directly writing the current data block into the writable storage block;
[0054] performing the step of selecting one of the N data blocks as the current writing data block until the number of blocks of the file data is not less than N.
[0055] By using the above technical solution, when only rewriting the historical data during file data writing, the storage block of the NAND FLASH is erased, otherwise, the storage block of the historical data or the writable storage block of the NAND FLASH is directly written, compared with the related art, one byte of data is written, the entire storage block is erased, the number of erasing the storage block of the NAND FLASH is reduced, and the efficiency of writing the file data is improved;
[0056] when a new storage block needs to be added for the file data, the storage block with the idle block attribute is used preferentially, after all the idle storage blocks are written, the storage block with the dirty data block attribute is erased and written, so that the number of erasing and writing of each storage block is balanced.
[0057] Optionally, the file self-checking comprises:
[0058] querying whether there is a file header block based on the index information of the current storage block;
[0059] if there is a file header block, recording the block attribute of the file header block as valid;
[0060] querying a file tail block or at least one normal storage block based on the file header block;
[0061] judging whether the block data of the normal storage block or the file tail block is valid based on the file header block;
[0062] if the block data of the normal storage block or the file tail block is valid, marking the block attribute of the normal storage block or the file tail block as valid;
[0063] if the block data of the normal storage block or the file tail block is invalid, marking the block attribute of the normal storage block or the file tail block as dirty data.
[0064] if there is no file header block, querying whether there is a storage block with valid block attribute; if there is, updating the block attribute of the storage block as dirty data.
[0065] By using the above technical solution, the index information of the file header block is used to query the normal storage block or the file tail block, the index information of the normal storage block or the file tail block is used to query the storage block with valid file data, and the index information of the storage block with invalid file data is updated; if there is no file header block in the NAND FLASH, the storage block with valid block attribute in the NAND FLASH is queried, which indicates that the storage block is invalid; for the invalid storage block or the storage block with writing attribute, the storage block is erased and recycled, and the data of other storage blocks is not affected, thereby improving the utilization rate of the storage block and reducing the possibility of storage block waste.
[0066] In a second aspect, the application provides a file data access device based on NAND FLASH, which uses the following technical solution:
[0067] A file data access device based on NAND FLASH, comprising:
[0068] an acquisition module, configured to acquire file data;
[0069] a selection module, configured to select a writable storage block from the NAND FLASH as a current storage block based on a block attribute;
[0070] a writing module, configured to write data in the file data which is not written in the NAND FLASH into the current storage block;
[0071] a judging module, configured to judge whether data in the file data which is not written in the NAND FLASH is all written into the current storage block; if not, repeat the step of selecting a writable storage block from the NAND FLASH as the current storage block until the file is all written into the NAND FLASH;
[0072] as a module, if a plurality of writable storage blocks are selected as the current storage block in sequence, the first selected writable storage block is a file head block, the last selected writable storage block is a file tail block, and the rest of the selected writable blocks are ordinary storage blocks;
[0073] wherein the current storage block has index information bits, the index information bits of the file head block include a file name bit, a block attribute bit, a block serial number bit of a next storage block and a data length bit of a last storage block; the index information bits of the file tail block include a block attribute bit; and the index information bits of the ordinary storage block include a block attribute bit and a block serial number bit of a next storage block;
[0074] a first updating module, configured to, if the current storage block is the file head block, update the index information of the file head block based on the block serial number of the next storage block of the file head block after the writable storage block is selected from the NAND FLASH as the current storage block based on the block attribute;
[0075] a second updating module, configured to, if the current storage block is an ordinary storage block, update the index information of the ordinary head block based on the block serial number of the next storage block of the ordinary head block after the writable storage block is selected from the NAND FLASH as the current storage block based on the block attribute;
[0076] a third updating module, configured to, if the current storage block is the file tail block, write file data until the file is all written into the NAND FLASH after the writable storage block is selected from the NAND FLASH as the current storage block based on the block attribute.
[0077] By adopting the technical scheme, the file data is stored in a chain storage block structure, and the chain structure is a discontinuous storage block mode, the file data is distributed to each storage block by adopting the chain structure for distributed storage, the key area (for example, a file directory area) storage block does not need to be set in the NAND FLASH, the entire file data can be queried through the index information of the file header block, when the file data is rewritten, the number of erasing and writing times of the key area storage block is reduced, the possibility of damage of the entire NAND FLASH is reduced, the performance of NAND FLASH wear leveling is improved, and the service life of the NAND FLASH is improved.
[0078] In a third aspect, the present application provides an electronic device, which adopts the technical scheme as follows:
[0079] An electronic device, comprising a processor coupled with a memory;
[0080] The processor is configured to execute a computer program stored in the memory, so that the electronic device executes the file data access method based on the NAND FLASH according to any one of the first aspect.
[0081] In a fourth aspect, the present application provides a computer readable storage medium, which adopts the technical scheme as follows:
[0082] A computer readable storage medium, which stores a computer program capable of being loaded and executed by a processor to execute the file data access method based on the NAND FLASH according to any one of the first aspect. BRIEF DESCRIPTION OF DRAWINGS
[0083] Figure 1 is a flowchart of the file data access method based on the NAND FLASH according to the embodiments of the present application.
[0084] Figure 2 is a structural diagram of a file header block, a normal storage block and a file tail block according to the embodiments of the present application.
[0085] Figure 3 is a structural block diagram of storing file data into the NAND FLASH according to the embodiments of the present application.
[0086] Figure 4 is a flowchart of steps Sa-Sc according to the embodiments of the present application.
[0087] Figure 5 is a structural block diagram of the file data access device 200 based on the NAND FLASH according to the embodiments of the present application.
[0088] Figure 6Fig. 1 is a structural block diagram of an electronic device 300 according to an embodiment of the present application. DETAILED DESCRIPTION
[0089] In order to make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some but not all of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative work fall within the protection scope of the present application.
[0090] In addition, the term "and / or" in the present application is only used to describe the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B can mean that A exists alone, A and B exist together, and B exists alone. In addition, the character " / " in the present application generally represents an "or" relationship between the associated objects unless otherwise specified.
[0091] The embodiments of the present application will be described in further detail below with reference to the drawings of the specification.
[0092] The embodiments of the present application provide a file data access method based on a NAND FLASH. The method is executed by an electronic device, which can be a server or a terminal device. The server can be a standalone physical server, a service cluster or a distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. The terminal device can be a desktop computer, a notebook computer, a mobile phone, or the like, but is not limited thereto.
[0093] As shown in Fig. 1, the main flow of the method is described as follows (steps S101-S108). Figure 1
[0094] Step S101, obtaining file data;
[0095] In the embodiment, the file structure of the file data includes but is not limited to the file name and the file length of the file.
[0096] Step S102, selecting a writable storage block as a current storage block from the NAND FLASH based on a block attribute;
[0097] In the embodiment, the block attribute includes free, writing, valid, and dirty data. The block attribute of the storage block is described below.
[0098] When the current storage block is erased, the block attribute of the current storage block is updated as free; when the file data is written into the current storage block, the block attribute of the current storage block is updated as writing; when the file data is written into the current storage block, the block attribute of the current storage block is updated as valid; when the file self-check is performed, if the block data of the current storage block is invalid, the block attribute of the current storage block is updated as dirty data.
[0099] Since the nominal value of the number of erasing and writing of each storage block of the NAND FLASH is consistent, the unbalanced number of erasing and writing will make some storage blocks on the NAND FLASH be written and damaged too early, and the storage blocks with lower frequency of erasing and writing are not reasonably utilized. Therefore, in order to improve the wear leveling performance of the NAND FLASH, the step of selecting a writable storage block from the NAND FLASH is also optimized.
[0100] Specifically, the step S102 includes the following sub-steps (steps S1021-S1024) (not shown in the figure):
[0101] In step S1021, it is inquired whether there is a storage block with the block attribute as free, and if there is a storage block with the block attribute as free, any one of the storage blocks with the block attribute as free is selected as the current storage block;
[0102] In step S1022, if there is no storage block with the block attribute as free, it is inquired whether there is a storage block with the block attribute as dirty data;
[0103] In step S1023, if there is a storage block with the block attribute as dirty data, any one of the storage blocks with the block attribute as dirty data is selected;
[0104] In step S1024, the storage block is erased, and the erased storage block is taken as the current storage block.
[0105] The different storage blocks can be identified by the block attribute, when the file data needs to be written, the storage block with the block attribute as free which has not been written is preferentially used, after all the storage blocks with the block attribute as free have been written, the storage block with the block attribute as dirty data which has been written is erased for writing, which reduces the possibility of over-frequent erasing and writing of some storage blocks, makes the balanced allocation of the number of erasing and writing of each storage block, and improves the wear leveling performance of the NAND FLASH.
[0106] In step S103, the data in the file data which has not been written into the NAND FLASH is written into the current storage block;
[0107] In the embodiment, the writing of the NAND FLASH is to change the data of the current storage block at the FLASH address from BIT1 to BIT0, and the erasing is to change the data of the current data block at the FLASH address from BIT0 to BIT1. Since the current storage block is selected in the manner of the sub-step of step S102 as described above, the current storage block is an idle storage block and can be directly written, thus improving the efficiency of writing the file data into the current storage block.
[0108] Step S104, judging whether all the data of the file data not written into the NAND FLASH is written into the current storage block;
[0109] If not, repeating the step of selecting a writable storage block from the NAND FLASH as the current storage block until the file is completely written into the NAND FLASH;
[0110] Step S105, if a plurality of writable storage blocks are selected as the current storage block, the first selected writable storage block is the file head block, the last selected writable storage block is the file tail block, and the remaining selected writable storage blocks are ordinary storage blocks.
[0111] In the embodiment, for example, the size of one storage block is 4KB, and the file data of 10KB needs to be written. Then, a writable storage block is selected as the current storage block, the file data is written, and the current storage block is the file head block. Then, the next writable storage block is selected as the current storage block, the remaining 6KB of the file data is continuously written, and the current storage block is an ordinary data block. Then, the next writable storage block is continuously selected as the current storage block, the remaining 2KB of the file data is continuously written, and the current storage block is the file tail block.
[0112] Figure 2 The structure diagram of the file head block, the ordinary storage block and the file tail block is shown.
[0113] As shown in Figure 2 , the current storage block has index information bits. The index information bits of the file head block include a file name bit, a block attribute bit, a block serial number bit of the next storage block and a data length bit of the last storage block. The index information bits of the file tail block include a block attribute bit. The index information bits of the ordinary storage block include a block attribute bit and a block serial number bit of the next storage block.
[0114] Step S106, if the current storage block is the file header block, after selecting a writable storage block from the NAND FLASH as the current storage block based on the block attribute, updating the block serial number of the next storage block in the index information bit of the file header block based on the block serial number of the next storage block of the file header block; and when the file header block is written with file data, updating the block attribute in the index information bit of the file header block to writing in progress, and after the file header block is written, updating the block attribute in the index information bit of the file header block to valid.
[0115] Step S107, if the current storage block is the normal storage block, after selecting a writable storage block from the NAND FLASH as the current storage block based on the block attribute, updating the block serial number of the next storage block in the index information of the normal header block based on the block serial number of the next storage block of the normal header block; and when the normal storage block is written with file data, updating the block attribute in the index information bit of the normal storage block to writing in progress, and after the normal storage block is written, updating the block attribute in the index information bit of the normal storage block to valid.
[0116] Step S108, if the current storage block is the file tail block, after selecting a writable storage block from the NAND FLASH as the current storage block based on the block attribute, then writing file data until the file is completely written into the NAND FLASH; and when the file tail block is written with file data, updating the block attribute in the index information bit of the file tail block to writing in progress, and after the file tail block is written, updating the block attribute in the index information bit of the file tail block to valid, and updating the data length bit of the last storage block in the index information bit of the file header block.
[0117] The storage structure of file data is described below.
[0118] Figure 3 The structure block diagram of storing file data into the NAND FLASH is shown.
[0119] As shown in Figure 3 , for example, there are 16 storage blocks in the NAND FLASH, which are storage blocks 1-16, and the NAND FLASH stores files, which are file 1 and file 2, and all storage blocks in file 1 and file 2 are linked together through the index information.
[0120] The file data of the file 1 is stored in 6 storage blocks, i.e., storage block 1, storage block 2, storage block 7, storage block 12, storage block 16 and storage block 15, the first storage block 1 of the file 1 is the file header block of the file 1, the last storage block 15 is the file tail block, and the other storage blocks are the normal storage blocks; the file data of the file 2 is stored in 4 storage blocks, i.e., storage block 5, storage block 10, storage block 11 and storage block 14, the first storage block 5 of the file 2 is the file header block of the file 2, the last storage block 14 is the file tail block, and the other storage blocks are the normal storage blocks. The storage blocks in which no file data is stored in the NAND FLASH, such as storage block 3, storage block 4, storage block 6, storage block 8, database block 9 and storage block 10, are the storage blocks with the block attribute of free or the block attribute of dirty data.
[0121] The present scheme manages the file data in a distributed wear leveling manner, stores the file data in a chain data block structure, and adopts a non-continuous storage block manner. The file data is distributed to each storage block by adopting the chain structure for distributed storage, and no storage block of a key area (such as a file directory area) needs to be set in the NAND FLASH. The entire file data can be queried by the index information of the file header block. When the file data is rewritten, the number of erasing and writing times of the storage block of the key area is reduced, the possibility of damaging the entire NAND FLASH is reduced, the performance of wear leveling of the NAND FLASH is improved, and the service life of the NAND FLASH is improved.
[0122] As an optional implementation manner of the present embodiment, there is another file data writing condition.
[0123] If the file data has historical data, before a writable storage block is selected from the NAND FLASH as the current storage block based on the block attribute, the following steps (steps Sa-Sc) are further included.
[0124] In step Sa, whether the historical data of the file data exists is queried based on the file name.
[0125] Specifically, first, whether the file header block of the file data exists is queried based on the file name; if the file header block of the file data exists, the normal data block or the file tail block of the file data is queried based on the index information of the file header block; then, the next normal data block or the file tail block of the file data is queried based on the index information of the normal data block, until all the storage blocks of the file data are confirmed; finally, all the storage blocks of the file data are read to obtain the historical data of the file data.
[0126] In step Sb, if the historical data of the file data exists in the NAND FLASH, the file data is cut into N data blocks according to the size of the storage block.
[0127] Step Sc, comparing the N data blocks with the block data of the storage block corresponding to the historical data, determining the storage block to which the N data blocks are written and / or rewritten, and writing and / or rewriting the data blocks of the file data corresponding to the storage block to the storage block.
[0128] Specifically, step Sc includes the following sub-steps (steps Sc1-Sc5) (not shown in the figure):
[0129] Step Sc1, identifying that the number of blocks of the current writing file data is 0;
[0130] Step Sc2, selecting a data block from the N data blocks, setting it as the current writing data block, and identifying the number of blocks of the current writing file data by 1;
[0131] Step Sc3, judging whether the block position of the current writing data block exceeds the block length of the storage of the historical data to the storage block;
[0132] Step Sc4, if the block position of the current writing data block does not exceed the block length, determining the storage block of the historical data based on the block position of the current writing data block;
[0133] Step Sc5, judging whether the storage block exists writing and / or rewriting based on the block data of the current writing data block and the storage block;
[0134] If the storage block exists writing, the data block is written to the storage block;
[0135] If the storage block exists rewriting, the block data of the storage block is erased, and the data block is written to the storage block;
[0136] If the storage block does not exist writing and / or rewriting, the step of selecting a data block from the N data blocks and setting it as the current writing data block is executed; until the number of blocks of the file data is not less than N;
[0137] Step Sc6, if the block position of the current writing data block exceeds the block length, selecting a writable storage block from the NAND FLASH based on the block attribute, and directly writing the current data block to the writable storage block;
[0138] The step of selecting a data block from the N data blocks and setting it as the current writing data block is executed until the number of blocks of the file data is not less than N.
[0139] In the embodiment, for example, the size of the file data is 12 KB, the size of the data block is 4 KB, the file data is cut into four data blocks according to the size of the storage block, which are data block a, data block b, data block c and data block d respectively, and the data block position of each data block is recorded, data block a is the first data block of the file data, data block b is the second data block of the to-be-written data, and data block c and data block d are in the same way.
[0140] Suppose that the historical data of the file data is stored in three storage blocks, when the to-be-written data is written, one data block is selected from the four data blocks to start writing, when the to-be-written data is not written, the number of the blocks of the file data currently written is identified as 0, when data block b is selected to start writing, the data block identifier of the file data currently written is added by 1 to determine that the second storage block of the historical data is the current storage block to be rewritten, the storage block corresponding to the historical data is determined according to the position of the data block, the step of selecting the data block is repeated, the data block identifier is added by 1, until all the data blocks are selected, data block a is the first storage block of the historical data, data block c is the third storage block of the historical data, and data block d needs to be selected as a storage block with an idle block attribute or a data block with a dirty block attribute according to the way of selecting a writable storage block of the NAND FLASH (the way of the sub-step S102 of the above step).
[0141] Suppose that the historical data of the file data is stored in five storage blocks, the storage block corresponding to the historical data is determined according to the position of the data block, which is the same as the way of determining the storage block of the historical data of data block a, data block b and data block c, which will not be described here.
[0142] It should be noted that when one data block is selected from the four data blocks, one data block of the to-be-written data can be selected in sequence, or one data block of the to-be-written data can be selected randomly, which is not limited in the embodiment.
[0143] The method can erase only when the historical data is rewritten when the file data is written, otherwise, the storage block of the NAND FLASH is not erased, but directly written into the storage block of the historical data or the writable data block of the NAND FLASH, compared with the related art, one byte of data is written, the entire storage block is erased, the number of erasing the storage block of the NAND FLASH is reduced, and the efficiency of writing the file data is improved; when a new storage block needs to be added for the file data, the storage block with an idle block attribute which is not written is used preferentially, after all the storage blocks with the idle block attribute are written, the storage block with the dirty block attribute which is written is erased to write, so that the number of erasing and writing each storage block is evenly distributed.
[0144] In order to further improve the service life of the NAND FLASH, the method is further optimized.
[0145] As an optional embodiment of the present embodiment, the file self-checking is further included.
[0146] Based on the index information of the current storage block, it is inquired whether there is a file header block; if there is a file header block, the block attribute of the file header block is recorded as valid; based on the file header block, a file tail block or at least one normal storage block in which the file data is written is inquired; based on the file header block, it is judged whether the block data of the normal storage block or the file tail block is valid; if the block data of the normal storage block or the file tail block is valid, the block attribute of the normal storage block or the file tail block is marked as valid; if the block data of the normal storage block or the file tail block is invalid, the block attribute of the normal storage block or the file tail block is marked as dirty data. If there is no file header block, it is inquired whether there is a storage block with valid block attribute; if there is, the block attribute of the storage block is updated as dirty data.
[0147] In the present embodiment, after power-on, the file self-checking is needed, the normal storage block or the file tail block is inquired by using the index information of the file header block, the storage block with valid file data is inquired by using the index information of the normal storage block or the file tail block, the index information of the storage block with invalid file data is updated; if there is no file header block in the NAND FLASH, the storage block with valid block attribute in the NAND FLASH is inquired, which indicates that the storage block is invalid; for the invalid storage block or the storage block with writing-in-progress block attribute, the storage block is erased and recycled, and the data of other storage blocks is not affected, thereby improving the utilization rate of the storage block and reducing the possibility of waste of the storage block.
[0148] The above is the introduction of the method embodiment, and the device embodiment is used to further illustrate the present application.
[0149] Figure 5 The structure block diagram of the file data access device 200 based on the NAND FLASH is shown in the present embodiment.
[0150] As shown in Figure 5 The file data access device 200 based on the NAND FLASH mainly includes:
[0151] The obtaining module 201 is used to obtain the file data.
[0152] The selecting module 202 is used to select a writable storage block from the NAND FLASH as the current storage block based on the block attribute.
[0153] The writing module 203 is used to write the data in the file data which is not written in the NAND FLASH into the current storage block.
[0154] determining whether all data in the file data not written in the NAND FLASH is written in the current storage block; if not, repeating the step of selecting a writable storage block from the NAND FLASH as the current storage block until all the file data is written in the NAND FLASH;
[0155] As the module 205, if a plurality of writable storage blocks are selected as the current storage block in sequence, the first selected writable storage block is the file head block, the last selected writable storage block is the file tail block, and the remaining selected writable blocks are ordinary storage blocks.
[0156] The current storage block has index information bits, the index information bits of the file head block include a file name bit, a block attribute bit, a block serial number bit of the next storage block, and a data length bit of the last storage block; the index information bits of the file tail block include a block attribute bit; and the index information bits of the ordinary storage block include a block attribute bit and a block serial number bit of the next storage block.
[0157] The first updating module 206 is configured to, if the current storage block is the file head block, update the index information of the file head block based on the block serial number of the next storage block of the file head block after selecting a writable storage block from the NAND FLASH as the current storage block based on the block attribute.
[0158] The second updating module 207 is configured to, if the current storage block is the ordinary storage block, update the index information of the ordinary head block based on the block serial number of the next storage block of the ordinary head block after selecting a writable storage block from the NAND FLASH as the current storage block based on the block attribute.
[0159] The third updating module 208 is configured to, if the current storage block is the file tail block, write the file data until all the file data is written in the NAND FLASH after selecting a writable storage block from the NAND FLASH as the current storage block based on the block attribute.
[0160] Further, the block attribute includes idle, writing, valid, and dirty data.
[0161] When the current storage block is subjected to an erasing operation, the block attribute of the current storage block is updated to be idle.
[0162] When the file data is written in the current storage block, the block attribute of the current storage block is updated to be writing.
[0163] When the file data is written in the current storage block, the block attribute of the current storage block is updated to be valid.
[0164] When the file self-checking is performed, if the block data of the current storage block is invalid, the block attribute of the current storage block is updated as dirty data.
[0165] As an optional implementation of the embodiment, the writing module 203 comprises:
[0166] The first query submodule is configured to query whether there is a storage block with an idle block attribute, and if there is a storage block with an idle block attribute, select any one of the storage block with an idle block attribute as the current storage block.
[0167] The second query submodule is configured to query whether there is a storage block with dirty data if there is no storage block with an idle block attribute.
[0168] The selection submodule is configured to select any one of the storage block with dirty data if there is a storage block with dirty data.
[0169] The erasing submodule is configured to erase the storage block and take the erased storage block as the current storage block.
[0170] As an optional implementation of the embodiment, the file data comprises a file name, and before selecting a writable storage block from the NAND FLASH as the current storage block based on the block attribute, the file data access device 200 based on the NAND FLASH further comprises a historical data query module, and the historical data query module comprises:
[0171] The third query submodule is configured to query whether there is historical data of the file data based on the file name.
[0172] The cutting submodule is configured to cut the file data into N data blocks according to the size of the storage block if there is historical data of the file data in the NAND FLASH.
[0173] The comparison submodule is configured to compare the N data blocks with the block data of the historical data corresponding storage block, determine the storage block to which the N data blocks are written and / or rewritten, and write and / or rewrite the data block of the file data corresponding to the storage block to the storage block.
[0174] In the optional implementation, the third query submodule is specifically configured to:
[0175] query whether there is a file header block of the file data based on the file name;
[0176] if there is a file header block of the file data, query the normal data block or the file tail block of the file data based on the index information of the file header block;
[0177] The index information of the common data block is used to query the next common data block or the file tail block of the file data until all the storage blocks of the file data are confirmed;
[0178] All the storage blocks of the file data are read to obtain the historical data of the file data.
[0179] In the optional embodiment, the comparison submodule is specifically configured to:
[0180] The block number of the data block currently writing the file data is identified as 0;
[0181] One data block is selected from the N data blocks, the data block is set as the current writing data block, and the block number of the file data currently writing is identified by 1;
[0182] It is judged whether the block position of the current writing data block exceeds the block length of the storage of the historical data;
[0183] If the block position of the current writing data block does not exceed the block length, the storage block of the historical data is determined based on the block position of the current writing data block;
[0184] Based on the block data of the current writing data block and the storage block, it is judged whether the storage block exists in the writing and / or rewriting condition;
[0185] If the storage block exists in the writing condition, the data block is written into the storage block;
[0186] If the storage block exists in the rewriting condition, the block data of the storage block is erased, and the data block is written into the storage block;
[0187] If the storage block does not exist in the writing and / or rewriting condition, the step of selecting one data block from the N data blocks and setting the data block as the current writing data block is executed; until the block number of the file data is not less than N;
[0188] If the block position of the current writing data block exceeds the block length, one writable storage block is selected from the NAND FLASH based on the block attribute, and the current data block is directly written into the writable storage block;
[0189] The step of selecting one data block from the N data blocks and setting the data block as the current writing data block is executed until the block number of the file data is not less than N.
[0190] As an optional embodiment of the embodiment, the file data access device 200 based on the NAND FLASH further comprises a file self-checking module, and the file self-checking module is specifically configured to:
[0191] The index information of the current storage block is used to query whether the file head block exists;
[0192] If the file header block exists, the block attribute of the file header block is marked as valid;
[0193] Based on the file header block, the file tail block or at least one normal storage block storing the file data is queried;
[0194] Based on the file header block, it is determined whether the block data of the normal storage block or the file tail block is valid;
[0195] If the block data of the normal storage block or the file tail block is valid, the block attribute of the normal storage block or the file tail block is marked as valid.
[0196] If the block data of the normal storage block or the file tail block is invalid, the block attribute of the normal storage block or the file tail block is marked as dirty data.
[0197] If the file header block does not exist, it is queried whether there is a storage block with a valid block attribute; if there is, the block attribute of the storage block is updated as dirty data.
[0198] In one example, the modules in any of the above apparatuses can be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASICs), or one or more digital signal processors (DSPs), or one or more field programmable gate arrays (FPGAs), or a combination of at least two of these integrated circuit forms.
[0199] For another example, when the modules in the apparatuses can be implemented in the form of a processing element scheduler, the processing element can be a general purpose processor, such as a central processing unit (CPU) or other processor that can invoke programs. For another example, these modules can be integrated together to implement in the form of a system-on-a-chip (SOC).
[0200] In the present application, various messages / information / devices / network elements / systems / apparatuses / actions / operations / processes / concepts, etc. of various objects that can appear in the present application are named, and it can be understood that these specific names do not constitute a limitation on the related objects, and the names can be changed according to the scene, context or usage habits, etc. The technical meaning of the technical terms in the present application should be mainly determined from the function and technical effect embodied / implemented in the technical scheme.
[0201] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the system, device and module described above can refer to the corresponding processes in the foregoing method embodiments, and will not be described here.
[0202] Those of ordinary skill in the art can appreciate that the modules and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether the functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0203] Figure 6 A structural block diagram of an electronic device 300 according to an embodiment of the present application.
[0204] As shown in Figure 6 The electronic device 300 includes a processor 301 and a memory 302, and can further include one or more of an information input / output (I / O) interface 303 and a communication component 304, and a communication bus 305.
[0205] The processor 301 is configured to control the overall operation of the electronic device 300 to complete all or part of the steps of the NANDFLASH-based file data access method described above; the memory 302 is configured to store various types of data to support the operation of the electronic device 300, which can include, for example, instructions for operating any application or method on the electronic device 300, and application-related data. The memory 302 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as one or more of a static random access memory (SRAM), an electrically erasable programmable read-only memory (EEPROM), an erasable programmable read-only memory (EPROM), a programmable read-only memory (PROM), a read-only memory (ROM), a magnetic memory, a flash memory, a magnetic disk, or an optical disk.
[0206] The I / O interface 303 provides an interface between the processor 301 and other interface modules, which can be a keyboard, a mouse, a button, etc. The buttons can be virtual buttons or physical buttons. The communication component 304 is configured to test wired or wireless communication between the electronic device 300 and other devices. The wireless communication, for example, Wi-Fi, Bluetooth, Near Field Communication (NFC), 2G, 3G or 4G, or a combination of one or more of them, and thus the corresponding communication component 104 can include a Wi-Fi component, a Bluetooth component, an NFC component.
[0207] The communication bus 305 can include a path for transmitting information between the components. The communication bus 305 can be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The communication bus 305 can be divided into an address bus, a data bus, a control bus, etc.
[0208] The electronic device 300 can be implemented by one or more ASICs (Application Specific Integrated Circuits), DSPs (Digital Signal Processors), DSPDs (Digital Signal Processing Devices), PLDs (Programmable Logic Devices), FPGAs (Field Programmable Gate Arrays), controllers, microcontrollers, microprocessors, or other electronic elements for performing the NAND FLASH-based file data access method according to the embodiments.
[0209] The electronic device 300 can include, but is not limited to, a mobile terminal of a digital broadcast receiver, a PDA (Personal Digital Assistant), a PMP (Portable Multimedia Player), etc., and a fixed terminal such as a digital TV, a desktop computer, etc., and can also be a server, etc.
[0210] The computer-readable storage medium according to the embodiments of the present application will be described below. The computer-readable storage medium described below can be referred to in correspondence with the NAND FLASH-based file data access method described above.
[0211] The application further provides a computer readable storage medium, and the computer readable storage medium stores a computer program, and the computer program is executed by a processor to realize the steps of the NAND FLASH-based file data access method.
[0212] The computer readable storage medium can include a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media capable of storing program codes.
[0213] The term "comprising" or "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such a process, method, article or device.
[0214] The above description is merely preferred embodiments of the application and a description of the principles of the technology applied. Those skilled in the art should understand that the application scope involved in the application is not limited to the technical solutions formed by the specific combinations of the above technical features, and should also cover other technical solutions formed by any combination of the above technical features or equivalent features without departing from the above application concept. For example, the above features are replaced with the technical features applied in the application (but not limited to) having similar functions to form technical solutions.
Claims
1. A file data storage method based on NAND FLASH, characterized in that, include: Get file data; Select a writable storage block from the NAND FLASH as the current storage block based on block attributes; Write the data in the file that has not been written to the NAND FLASH into the current storage block; Determine whether all data in the file that has not been written to the NAND FLASH has been written to the current storage block; If not, repeat the step of selecting a writable storage block from the NAND FLASH as the current storage block until the entire file is written to the NAND FLASH; If multiple writable storage blocks are selected sequentially as the current storage block, the first writable storage block selected is the file header block, the last writable storage block selected is the file tail block, and the remaining writable modules are ordinary storage blocks. The current storage block has index information bits, and the index information bits of the file header block include file name bits, block attribute bits, block sequence number bits of the next storage block, and data length bits of the last storage block; The index information bits of the file tail block include block attribute bits; The index information bits of the ordinary storage block include block attribute bits and the block sequence number bit of the next storage block; If the current storage block is the file header block, then after selecting a writable storage block from the NAND FLASH based on the block attributes as the current storage block, the index information of the file header block is updated based on the block number of the next storage block of the file header block; If the current storage block is the ordinary storage block, then after selecting a writable storage block from the NAND FLASH based on the block attributes as the current storage block, the index information of the ordinary storage block is updated based on the block number of the next storage block of the ordinary storage block. If the current storage block is the end block of the file, then after selecting a writable storage block from the NAND FLASH based on the block attributes as the current storage block, file data is written until the entire file is written to the NAND FLASH. The block attributes include free, being written, valid, and dirty data; The file data includes a file name, and before selecting a writable storage block from the NAND FLASH as the current storage block based on block attributes, it also includes: Based on the file name, query whether there is historical data for the file. If historical data of the file data exists in the NAND FLASH, then the file data is divided into N data blocks according to the size of the storage block; The N data blocks are compared with the block data of the storage blocks corresponding to the historical data to determine the storage blocks to which the N data blocks are written and / or rewritten, and the data blocks of the file data corresponding to the storage blocks are written and / or rewritten to the storage blocks.
2. The method according to claim 1, characterized in that, After the current storage block is erased, the block attribute of the current storage block is updated to free. When writing the file data to the current storage block, update the block attribute of the current storage block to "writing". When the file data is written to the current storage block, the block attribute of the current storage block is updated to be valid; When performing a file self-check, if the block data of the current storage block is invalid, the block attribute of the current storage block is updated to dirty data.
3. The method according to claim 2, characterized in that, The step of selecting a writable storage block from NAND FLASH as the current storage block based on block attributes includes: Check if there is a storage block with the block attribute being free. If there is a storage block with the block attribute being free, select any one of the storage blocks with the block attribute being free as the current storage block. If there is no storage block with the block attribute of free, then query whether there is a storage block with the block attribute of dirty data. If there exists a storage block with the block attribute of dirty data, then select any one of the storage blocks with the block attribute of dirty data; Erase the storage block and use the erased storage block as the current storage block.
4. The method according to claim 1, characterized in that, The historical data for querying whether the file data exists based on the file name includes: Based on the file name, query whether the file header block of the file data exists; If a file header block of the file data exists, then query the ordinary data block or the file tail block of the file data based on the index information of the file header block; Based on the index information of the ordinary data block, query the next ordinary data block or the end block of the file data until all storage blocks of the file data are confirmed; Read all storage blocks of the file data to obtain the historical data of the file data.
5. The method according to claim 1, characterized in that, The step of comparing the N data blocks with the block data of the storage blocks corresponding to the historical data, determining the storage blocks to be written to and / or rewritten by the N data blocks, and writing and / or rewriting the data blocks of the file data corresponding to the storage blocks to the storage blocks includes: The number of data blocks currently being written to the file is 0; Select one of the N data blocks, set it as the current data block to be written, and increment the number of blocks currently writing the file data by 1; Determine whether the current block position of the data being written exceeds the block length of the historical data stored in the storage block; If the block position of the currently written data block does not exceed the block length, then the storage block of the historical data is determined based on the block position of the currently written data block; Based on the currently written data block and the block data of the storage block, it is determined whether there is a write and / or rewrite situation in the storage block; If the storage block is being written to, then the data block is written to the storage block; If the storage block is overwritten, the block data of the storage block is erased and the data block is written into the storage block; If the storage block is not being written to and / or overwritten, then the step of selecting one of the N data blocks and setting it as the current write data block is executed. Until the number of blocks of the file data is not less than N; If the current data block being written exceeds the block length, a writable storage block is selected from the NAND FLASH based on the block attributes, and the current data block is directly written to the writable storage block. The step of selecting one of the N data blocks and setting it as the current data block to be written is performed until the number of blocks of the file data is not less than N.
6. The method according to claim 2, characterized in that, The file self-check includes: Based on the index information of the current storage block, query whether a file header block exists; If a file header block exists, then record that the block attribute of the file header block is valid; Based on the file header block, query the file tail block or at least one of the ordinary storage blocks into which file data is written; Based on the file header block, determine whether the block data of the ordinary storage block or the file tail block is valid; If the block data of the ordinary storage block or the file tail block is valid, then the block attribute of the ordinary storage block or the file tail block is marked as valid; If the block data of the ordinary storage block or the end of the file block is invalid, then the block attribute of the ordinary storage block or the end of the file block is marked as dirty data; If no file header block exists, check if there is a storage block with valid block attributes; if so, update the block attributes of the storage block to dirty data.
7. A NAND FLASH-based file data storage and retrieval device, characterized in that, include: The acquisition module is used to acquire file data; The selection module is used to select a writable storage block from the NAND FLASH as the current storage block based on block attributes; The write module is used to write data from the file data that has not been written to the NAND FLASH into the current storage block; The judgment module is used to determine whether all the data in the file data that has not been written to NAND FLASH has been written to the current storage block; If not, repeat the step of selecting a writable storage block from the NAND FLASH as the current storage block until the entire file is written to the NAND FLASH; As a module, if multiple writable storage blocks are selected sequentially as the current storage block, the first writable storage block selected is the file header block, the last writable storage block selected is the file tail block, and the remaining writable modules are ordinary storage blocks. The current storage block has index information bits, and the index information bits of the file header block include file name bits, block attribute bits, block sequence number bits of the next storage block, and data length bits of the last storage block; The index information bits of the file tail block include block attribute bits; The index information bits of the ordinary storage block include block attribute bits and the block sequence number bit of the next storage block; The first update module is used to update the index information of the file header block based on the block number of the next storage block of the file header block if the current storage block is the file header block. The second update module is used to update the index information of the ordinary storage block based on the block number of the next storage block of the ordinary storage block after selecting a writable storage block from NANDFLASH based on the block attributes as the current storage block if the current storage block is the ordinary storage block. The third update module is used to write file data until the entire file is written to the NANDFLASH after selecting a writable storage block from the NANDFLASH as the current storage block based on the block attributes if the current storage block is the end block of the file. The block attributes include free, being written, valid, and dirty data; The file data includes a file name, and before selecting a writable storage block from the NAND FLASH as the current storage block based on block attributes, it also includes: Based on the file name, query whether there is historical data for the file. If historical data of the file data exists in the NAND FLASH, then the file data is divided into N data blocks according to the size of the storage block; The N data blocks are compared with the block data of the storage blocks corresponding to the historical data to determine the storage blocks to which the N data blocks are written and / or rewritten, and the data blocks of the file data corresponding to the storage blocks are written and / or rewritten to the storage blocks.
8. An electronic device, characterized in that, The device includes a processor coupled to a memory; the processor is configured to execute a computer program stored in the memory to cause the electronic device to perform the method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer program is stored that can be loaded by a processor and execute the method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Method and device for modifying data in memory
CN101650692A
Multi-system shared memory management method and device
CN108064377A
Data operation method and device of file system, apparatus and readable storage medium
CN110673800A