CN115981560A - High-reliability file system design method based on NAND flash - Google Patents

High-reliability file system design method based on NAND flash Download PDF

Info

Publication number
CN115981560A
CN115981560A CN202211680962.7A CN202211680962A CN115981560A CN 115981560 A CN115981560 A CN 115981560A CN 202211680962 A CN202211680962 A CN 202211680962A CN 115981560 A CN115981560 A CN 115981560A
Authority
CN
China
Prior art keywords
file
block
main
storage block
storage
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211680962.7A
Other languages
Chinese (zh)
Inventor
祁宝刚
王瑞
曹春雨
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Tianyu Yunan Technology Co ltd
Original Assignee
Beijing Tianyu Yunan Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Tianyu Yunan Technology Co ltd filed Critical Beijing Tianyu Yunan Technology Co ltd
Priority to CN202211680962.7A priority Critical patent/CN115981560A/en
Publication of CN115981560A publication Critical patent/CN115981560A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

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

Abstract

The invention provides a high-reliability file system design method based on NAND flash, 1) the NAND flash is easy to generate bad blocks in production and use, 2) the NAND flash updates storage contents by adopting the principle of firstly erasing and then writing, and the conditions of equipment power failure/abnormal program exit and the like may occur in the period, which can cause the loss of the storage contents, and aiming at the problem, the high-reliability file system is designed. The file system is a design method for important data protection aiming at the characteristics of a NAND flash physical storage medium and a storage content updating mode. The method adopts a bad block skipping mode to manage bad blocks, adopts a main storage block and a spare storage block to carry out redundancy backup, skips the bad blocks when updating data each time, and writes the data into the corresponding main storage block and the spare storage block in sequence respectively.

Description

High-reliability file system design method based on NAND flash
Technical Field
The invention relates to the technical field of computers, in particular to a high-reliability file system design method based on NAND flash, which designs a high-reliability virtual file system and realizes reliable read-write protection of a target system file.
Background
A high-reliability file system design method based on NAND flash. The technical composition is as follows:
a flash memory: is an electronically erasable memory that allows for multiple erasures or writes during operation, is a non-volatile memory.
NAND flash: is composed of a plurality of blocks (blocks), each block being composed of a plurality of pages (pages). The erasing operation of the NAND flash is to take a memory block as a unit, the reading and writing operation is to take a page as a unit, a common address and data bus are provided, the NAND flash is a continuous storage medium, the speed of reading data is slow, the speed of writing mass data is fast, and the NAND flash is suitable for a storage environment for storing mass data.
Main and standby storage blocks: is a logical concept consisting of two physically adjacent storage blocks, one called primary storage block and the other backup storage block, for storing data. The main storage block content is identical to the spare storage block content.
NAND flash bad block: it means that some areas, which are present in the NAND flash, cannot be subjected to the erase/write operation. Since the read and write operations in the NAND flash are in page units, the erase is in block units, and the erase operation must be performed before the write operation, the minimum operable unit is one block. If any irreparable bit errors are generated in a block, then this block is a bad block.
Bad block management of NAND flash: because the NAND flash bad blocks are randomly distributed, the NAND flash bad blocks need to be scanned and marked, which is similar to the processing way of the hard disk bad sectors. Due to the existence of the bad block, when data is stored in the NAND flash, the bad block management is needed.
And the NAND flash write operation is abnormal: 1) Due to the existence of the NAND flash bad block, data are directly stored in the bad block, and data writing failure is generated, so that the stored data are lost; 2) The technical point is extracted from the working principle of 'NAND-Flash memory' in the title, namely 'https:// www.21ic.com/embedded/hardware/storage/201807/67834. Html'. In the process of updating the sector content, due to the occurrence of abnormal conditions such as power failure and the like, the updating of the sector content fails, and the stored data is lost.
FAT table: a File Allocation Table (File Allocation Table), which is self-defined File Allocation information used for describing storage block information corresponding to files in the File system;
CRC: cyclic Redundancy Check (CRC) is a Cyclic Redundancy Check code according to a network data packet or a computer, and is a most commonly used error checking code in the field of data communication, and is characterized in that the lengths of an information field and a Check field can be arbitrarily selected.
The user application program: refers to an application program using the present system to access NAND flash memory space.
Disclosure of Invention
The invention provides a high-reliability file system design method based on an NAND flash, which can process the abnormal conditions of the write operation of the NAND flash, realize the high-reliability update and storage of files and prevent the damage or loss of the stored contents.
The method comprises the following specific steps:
step a1: storing file contents and an FAT table in a storage space of the NAND flash by taking a main storage block and a standby storage block as a basic storage unit;
step a2: the user application program uses the system loading, reading and updating file interfaces of the file system to access the files of the main and standby storage blocks;
step a3: a system loading interface of the file system loads the file contents of the main and standby storage blocks to a memory space through an FAT table;
step a4: a file reading interface of the file system returns file contents to a user application program by accessing a memory space;
step a5: the update file interface of the file system stores the file content of the memory space to the storage space of the main storage block and the standby storage block through the FAT table.
Further, the FAT table used in step a1 is a file access table stored in the first main/standby storage block, and the FAT table is composed of attribute information of each file, and the attribute information of the file is composed of information such as one or more addresses, file names, and file sizes of the main/standby storage blocks where the file is located.
Further, the main and standby memory blocks used in step a1 are a storage manner for storing the same data content by physically storing two adjacent memory blocks through the NAND flash.
Further, step a3 describes a method for loading the main and standby storage blocks in the file system, where when a file is loaded, the corresponding main and standby storage blocks are first found through the FAT table, and then the contents of the storage blocks are read into the memory space. The method specifically comprises the following steps:
step b1: detecting a bad block identifier of a main storage block;
and b2: if the main storage block is not a bad block, then read the contents of the main storage block (one storage block size) into memory space;
step b3: and if the main storage block is a bad block, reading the content of the standby storage block of the main and standby storage blocks into the memory space, acquiring a new spare main and standby storage block, writing the content of the standby storage block into the new main and standby storage block, updating the FAT by using the new main and standby storage block address, and loading the storage block address used by the file.
Further, step b3 illustrates a method for recovering a bad block in the file system, where a storage block stored in a file in the bad block is obtained through a FAT table, and the content of the relevant storage block is recovered by using the file as a unit, and specifically includes the following steps:
step c1: searching a FAT table and acquiring the block addresses of the main and standby storage blocks of file storage;
step c2: if the files in the bad block are stored in a plurality of main and standby storage blocks (A1, A2 \8230, an and other main and standby storage blocks), aiming at the main and standby storage blocks A1, A2 ..., an, the flow of the step b3 is executed, and the files are restored to the main and standby storage blocks.
Further, step a5 illustrates a method for updating file contents to the active/standby storage blocks in the file system, and the method includes the following steps of obtaining, through the FAT table, the active/standby storage blocks stored in the update file, obtaining the active/standby storage block addresses into which the storage contents can be written, and writing the file contents into the active/standby storage blocks:
step d1: applying the steps c1 and b1 to the updated file to obtain a bad block identifier of the main storage device and the standby storage device;
step d2: if one of the main and standby storage blocks is a bad block, firstly, two adjacent idle storage blocks are obtained as the main and standby storage blocks, then the file content in the memory is updated into the main and standby storage blocks according to the principle of firstly erasing and then writing data into the storage blocks, and finally the FAT table is updated;
step d3: if the data can be written into the storage blocks in both the main storage block and the standby storage block, the file contents in the memory are updated into the main storage block and the standby storage block according to the principle of primary and standby.
The beneficial effects of the invention are as follows:
when data are stored based on the NAND flash, if the NAND flash has a bad block or the device is suddenly powered off, incomplete data can be generated when the data are stored in the NAND flash, and information loss is caused.
Drawings
FIG. 1 is a schematic diagram of the use of a master/slave storage block of the file system.
FIG. 2A description of a memory block by the file system.
Fig. 3 shows the correspondence between FAT and file in the file system.
Figure 4 file storage schematic in this file system.
FIG. 5 is a schematic illustration of bad block handling in the file system.
Detailed Description
The invention will be described in connection with the drawings and illustrative examples, with the aim of understanding the nature of the technical innovation and the efficiency of its objects achieved.
1. Use of the main and standby storage blocks:
the NAND flash active-standby storage block used by the system comprises two storage blocks which have the same size and are adjacent in storage position. The main and standby memory blocks of the present file system are shown in fig. 1. The main storage blocks are all in the first half, the standby storage blocks are all in the second half, and the main storage blocks and the standby storage blocks are in one-to-one correspondence. In the illustration of fig. 1, the contents of block 1 and block 2 are identical, and the contents of block 3 and block 4 are identical.
The format of each memory block is shown in fig. 2, and the memory block format description is divided into a memory block header and a memory block body. The memory block head describes the basic situation of the memory block, and the C language structure of the memory block head is defined as follows:
struct block_head
{
unsigned int block_crc;
unsigned int magic;
int sect_size;
int config_blocks;
int file_num;
int group_size;
int generate_time;
int reserved;
};
where block _ CRC is the value of CRC32 of the content of the storage block, magic is the storage block identifying the use of the file system, sect _ size indicates the storage block size, config _ blocks indicates how many storage blocks there are in the file system, file _ num indicates how many files are saved by the current storage block, group _ size indicates the file grouping size, generation _ time indicates the time information to produce the file system, reserved is a reserved field.
The C language definition of the memory block is as follows:
struct block_info
{
struct block_head head;
unsigned char contents[BLOCK_DATA_SIZE] ;
};
each storage block consists of a storage block head and a storage block body, and the size of the storage block body is obtained by subtracting the length of the storage block head from the size of the storage block.
2. FAT definition
The present file system indexes the position information of all files by FAT. The FAT is stored in the head of the memory block of the first memory block, and the correspondence between the FAT and the file is shown in fig. 3.
The FAT has a plurality of entries, one for each file, and the C language definition of the file allocation entry is as follows:
struct vfs_fat {
unknown char valid// valid
unsigned char which_block[MAX_BLOCK_NUM]; //where blocks
Configured char needed code, whether it is encrypted or not
unsigned char multi_blocks;
Signaled int real _ size// file length
Signaled int code _ len// occupied space
unsigned int sect_offset ;
unsigned char in_cfg_sect;
unsigned char reserved[3];
char filename[FILE_NAME_LENTH];
};
The valid field identifies whether the file is valid, the while _ block field indicates which storage blocks the file is in, the need _ code field indicates whether the file is encrypted, the multi _ blocks field indicates that the file occupies several storage blocks, the real _ size field indicates the actual length of the file, the code _ len field indicates the length of the file after encryption, the sect _ offset field indicates the offset of the file in the storage blocks, the in _ cfg _ sect field indicates whether the file is in the storage blocks, the reserved field is a reserved field, and the filename field is name information of the file, and the 8.3 format standard is adopted.
3. Generation of a file system
The FAT and the actual content of the file constitute the file system, which is shown in fig. 3. The file system needs to be formed into a file to facilitate the programming of the storage block.
The file system file content is stored in a space where the storage block is a discrete block, as shown in fig. 4. The file system is formed into files through a file system generation tool, and fig. 4 shows a case that the file system stores 3 main/standby storage blocks, each storage block includes a storage block head and a storage block body, and the storage block bodies store the contents of all files to form a storage block file of 3 continuous storage blocks.
And programming the file system file to the storage block, wherein the user application program can use the file content of the file system through the interface of the file system.
4. Loading and update write operations for file systems
The loading operation of the file system comprises the following steps:
step e1: loading the FAT, and finding out the information of the main storage block and the standby storage block corresponding to the file system through the FAT;
step e2: judging whether a main storage block in a corresponding main/standby storage block is a bad block, if so, applying for a new main/standby storage block, and covering the content of the standby storage block to the new main/standby storage block, wherein the service condition of the main/standby storage block is shown in fig. 5, and the specific steps are as follows;
step e2.1: reading the content of a backup storage block in a main backup storage block to a memory space;
step e2.2: acquiring an idle new main/standby storage block;
step e2.3: writing the content of the standby storage block into a new main/standby storage block according to the principle that the NAND flash firstly erases and then writes data;
step e2.4: updating the storage block address of the FAT by using the new main and standby storage block address;
step e3: judging whether the magic field of the main storage block head in the corresponding main/standby storage block is correct, and if not, applying the steps e2.1-e2.4;
step e4: calculating CRC32 value of main storage block content, if it is consistent with block _ CRC field in main storage block header, if not, applying steps e2.1-e2.4;
step e5: judging whether the corresponding backup storage block is a bad block, if so, applying the steps e2.1-e2.4, and writing the content of the main storage block into a new backup storage block; judging whether the magic field and the CRC32 value in the corresponding standby storage block are correct or not, if not, applying the steps e2.1-e2.4, and writing the contents of the main storage block into the standby storage block;
step e6: if the files in the bad block are stored in a plurality of main and standby storage blocks (A1, A2 ...Anand other main and standby storage blocks), aiming at the main and standby storage blocks A1, A2 ...Anand other main and standby storage blocks, the flow of the steps e2-e5 is executed, and the files are recovered to the main and standby storage blocks.
The file updating operation comprises the following steps:
step f1: finding out the information of the main and standby storage blocks corresponding to the file through the FAT table;
step f2: detecting bad block information of the main storage block and the standby storage block;
step f2.1: if one of the main and standby storage blocks is a bad block, firstly, two adjacent idle storage blocks are obtained as the main and standby storage blocks;
step f2.2: updating the file contents in the memory into the main and standby storage blocks according to the principle of firstly erasing and then writing data into the storage blocks;
step f2.3: finally updating the FAT table;
step f2.4: and finishing the update operation of the file.
Step f3: if the data can be written in the main storage block and the standby storage block, the following subsequent operations are executed;
step f4: copying the content of the whole main/standby storage block into a memory;
step f5: updating the content of the file in the memory;
step f6: calculating the CRC32 value of a main storage block in the memory, and updating a block _ CRC field of a main storage block head in the memory;
step f7: erasing the corresponding main storage block;
step f8: writing the memory content into the main storage block;
step f9: erasing the corresponding spare memory block;
step f10: and writing the memory content into the standby storage block.

Claims (5)

1. The high-reliability file system design method based on the NAND flash is characterized by comprising the following steps of:
step a1: the method comprises the steps that a storage space of the NAND flash is used for storing file contents and an FAT table by taking a main storage block and a standby storage block as basic storage units, wherein the main storage block and the standby storage block are two adjacent storage blocks with physical storage addresses, and the data contents stored in the main storage block are the same as the data contents stored in the standby storage block;
step a2: the user application program uses the system loading, reading and updating file interfaces of the file system to access the files of the main and standby storage blocks;
step a3: a system loading interface of the file system loads the file contents of the main and standby storage blocks to a memory space through an FAT table;
step a4: a file reading interface of the file system returns file contents to a user application program by accessing a memory space;
step a5: the update file interface of the file system stores the file content of the memory space to the storage space of the main storage block and the standby storage block through the FAT table.
2. The method according to claim 1, wherein the FAT table used in step a1 is a file access table stored in the first main/standby storage block, the FAT table is composed of attribute information of each file, and the attribute information of the file is composed of at least one or more main/standby storage block addresses, file names, and file size information of the file.
3. The method according to claim 1, wherein step a3 describes a method for loading the main and standby memory blocks in the file system, and when loading a file, the corresponding main and standby memory blocks are first found through the FAT table, and then contents of the main and standby memory blocks are read into the memory space, and the method specifically includes the following steps:
step b1: detecting a bad block identifier of a main storage block;
step b2: if the main storage block is not a bad block, reading the content of the main storage block to a memory space;
step b3: if the main storage block is a bad block, reading the content of the standby storage block of the main storage block and the standby storage block to the memory space, acquiring a new spare main storage block, writing the content of the standby storage block into the new main storage block and the standby storage block, updating the FAT by using the new main storage block address, and loading the storage block address used by the file.
4. The method according to claim 1, wherein the step b3 describes a method for recovering a bad block by the file system, and the method obtains a main storage block and a spare storage block stored in a file in the bad block through a FAT table, and recovers contents of a related storage block in a unit of the file, and specifically includes the following steps:
step c1: searching a FAT table and acquiring the block addresses of the main and standby storage blocks of file storage;
step c2: if the files in the bad block are stored in the main and standby storage blocks A1 and A2 \8230, an, aiming at the main and standby storage blocks A1 and A2 \8230, an, the flow of the step b3 is executed, and the files are restored to the main and standby storage blocks.
5. The method according to claim 1, wherein step a5 describes a method for updating file contents in the file system to the active/standby storage blocks, and the method includes the following steps:
step d1: applying the steps c1 and b1 to the updated file to obtain a bad block identifier of the main storage device and the standby storage device;
step d2: if one of the main and standby storage blocks is a bad block, applying step b3;
step d3: if the data can be written into the storage blocks in both the main storage block and the standby storage block, the file contents in the memory are updated into the main storage block and the standby storage block according to the principle of primary and standby.
CN202211680962.7A 2022-12-27 2022-12-27 High-reliability file system design method based on NAND flash Pending CN115981560A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211680962.7A CN115981560A (en) 2022-12-27 2022-12-27 High-reliability file system design method based on NAND flash

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211680962.7A CN115981560A (en) 2022-12-27 2022-12-27 High-reliability file system design method based on NAND flash

Publications (1)

Publication Number Publication Date
CN115981560A true CN115981560A (en) 2023-04-18

Family

ID=85960784

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211680962.7A Pending CN115981560A (en) 2022-12-27 2022-12-27 High-reliability file system design method based on NAND flash

Country Status (1)

Country Link
CN (1) CN115981560A (en)

Similar Documents

Publication Publication Date Title
JP3708047B2 (en) Managing flash memory
CN100487672C (en) Method and apparatus for splitting a logical block
JP4079506B2 (en) Method for controlling nonvolatile semiconductor memory system
US6381176B1 (en) Method of driving remapping in flash memory and flash memory architecture suitable therefor
US8909986B2 (en) Data storing method for solid state drive to preserve data integrity after power failure
US7702844B2 (en) Address mapping method and mapping information managing method for flash memory, and flash memory using the same
US8341336B2 (en) Region-based management method of non-volatile memory
US20110231597A1 (en) Data access method, memory controller and memory storage system
US20110231713A1 (en) Flash memory module
US20090100290A1 (en) Memory controller, nonvolatile memory device, nonvolatile memory system, and data writing method
US9058255B2 (en) Solid state drive and method for constructing logical-to-physical table thereof
US8516184B2 (en) Data updating using mark count threshold in non-volatile memory
TW201539455A (en) Data storing method, memory control circuit unit and memory storage apparatus
US10642731B2 (en) Memory management method and storage controller
CN112631516B (en) FLASH file management system with service life management function
US8819387B2 (en) Memory storage device, memory controller, and method for identifying valid data
US20110320689A1 (en) Data Storage Devices and Data Management Methods for Processing Mapping Tables
US20130275655A1 (en) Memory management method and memory controller and memory storage device using the same
CN103377143A (en) Memorizer management method, memorizer controller and memorizer memory device
CN112631950A (en) L2P table saving method, system, device and medium
US9223688B2 (en) Data storing method and memory controller and memory storage device using the same
KR100954603B1 (en) A log file of file system and method for recovering file system
JP2007293917A (en) Method for controlling memory system
CN114327292B (en) File management method, system, electronic device and storage medium
US10635583B2 (en) Memory management method and storage controller

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination