CN113641629A - File writing and reading method of FLASH memory - Google Patents

File writing and reading method of FLASH memory Download PDF

Info

Publication number
CN113641629A
CN113641629A CN202110935528.8A CN202110935528A CN113641629A CN 113641629 A CN113641629 A CN 113641629A CN 202110935528 A CN202110935528 A CN 202110935528A CN 113641629 A CN113641629 A CN 113641629A
Authority
CN
China
Prior art keywords
page
file
storage
item
data
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
CN202110935528.8A
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.)
Zhuhai Geehy Semiconductor Co Ltd
Original Assignee
Zhuhai Geehy Semiconductor 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 Zhuhai Geehy Semiconductor Co Ltd filed Critical Zhuhai Geehy Semiconductor Co Ltd
Priority to CN202110935528.8A priority Critical patent/CN113641629A/en
Publication of CN113641629A publication Critical patent/CN113641629A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/11File system administration, e.g. details of archiving or snapshots
    • GPHYSICS
    • G11INFORMATION STORAGE
    • G11CSTATIC STORES
    • G11C16/00Erasable programmable read-only memories
    • G11C16/02Erasable programmable read-only memories electrically programmable
    • G11C16/06Auxiliary circuits, e.g. for writing into memory
    • G11C16/08Address circuits; Decoders; Word-line control circuits

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Techniques For Improving Reliability Of Storages (AREA)

Abstract

The invention provides a file writing and reading method of a FLASH memory, the FLASH memory is used for realizing the writing, reading or deleting operation of a file, and the method comprises the following steps: the FLASH storage area is divided into a plurality of pages starting with No. 0 by the minimum unit of FLASH erasure, and comprises: the guide area is used for describing the information of the FLASH memory; the storage page volume comprises a plurality of items, the address sequence stored by each item corresponds to the item number and is used for storing the page number of the next storage page of the file data, and the item numbers correspond to the page numbers of the corresponding storage pages one by one; the file description volume is used for describing information of storage files, and the information of the storage files comprises: file information and a starting page number of the file; the file data storage area is used for storing file data. The file writing and reading method of the FLASH memory provided by the invention can reduce the storage space required by the storage page volume and improve the index efficiency.

Description

File writing and reading method of FLASH memory
The application is a divisional application of an invention patent application with the application number of 201710189447.1 and the application date of 2017, 03 and 27, and is named as a FLASH memory and storage file management method.
Technical Field
The invention relates to the technical field of FLASH memories, in particular to a file writing and reading method of a FLASH memory.
Background
FLASH Memory is a Non-Volatile Memory (Non-Volatile Memory) based on semiconductor technology, has the advantages of low power consumption, large capacity, small volume, light weight, high access speed and the like, and has been gradually replacing other semiconductor Memory devices and widely applied to mobile electronic products. Any FLASH memory has a fixed storage capacity, and the write operation can only be performed in an empty or erased unit, so in most cases, the erase operation must be performed before the write operation is performed, but the life of the FLASH chip is limited, and the FLASH chip is easily damaged beyond the maximum erase times.
The common FLASH chip fixedly divides FLASH into a plurality of storage areas according to the capacity, the number and the size of the files, records the initial address corresponding to each file, firstly finds the initial address and the area size corresponding to a certain file when the file needs to be read, written, erased and the like, and then carries out data reading, writing, erasing and the like on the address. The scheme is simple and easy to implement, but the size of the file is estimated to be distributed, and if the estimation is not accurate, correct storage cannot be achieved or space resources are wasted.
In order to solve the above problems, a patent application with application number 01142240.8 and named as a FLASH storage file management method provides a relatively complete false start system management method, which divides a FLASH storage area into two areas, namely a file index area and a file data storage area, wherein the file index area is used for recording file directories and distribution information of basic distribution unit blocks, and the file data storage area is used for storing specific contents of files. The block allocation information contains the block number, the occupation state and the linked list pointer pointing to the next block, thereby realizing reasonable allocation and flexible use of FLASH storage capacity. However, the allocation information in the prior art includes the block number of the block, the occupied state, and the linked list pointer pointing to the next block, which occupies a large amount of storage space and has low index efficiency.
Disclosure of Invention
The invention provides a file writing and reading method of a FLASH memory, which is used for solving the technical problems of more storage space occupied by distribution information and low index efficiency in the prior art.
The invention provides a file writing method of a FLASH memory, which is applied to the FLASH memory, wherein the FLASH memory comprises a plurality of pages, page numbers and allocation information of the pages, and the pages are erasable minimum unit storage units of the FLASH memory and are used for storing files; the page number is the serial number of the page in the FLASH memory; the allocation information of the page represents a linked list structure of the page, the allocation information of the page comprises a plurality of items, the items store one or more of information representing that the corresponding storage page has no data, information representing that the corresponding storage page has invalid data, page number information of a next page of the corresponding storage page, information representing that the corresponding storage page is the end of file, and information representing that the corresponding storage page is a bad page, the item numbers are item serial numbers of the items in the allocation information of the corresponding pages, and the item numbers of the items correspond to the page numbers with the same values of the pages; the method comprises the following steps:
reading information of a file to be written, wherein the information of the file to be written comprises the length of the file to be written and data of the file to be written;
comparing the length of the file to be written with the size of a storage space of an empty page, wherein an item corresponding to the empty page stores information indicating that the page has no data;
judging whether the FLASH memory has enough space to write the data of the file to be written in based on the comparison result;
if the FLASH memory is judged to have enough space, searching a first empty page without data of the FLASH memory, and determining a writing position of a file to be written;
determining the page number of the first empty page without data as the initial page number of the file, and storing the initial page number of the file;
writing the data of the file to be written into a storage page from the first empty page without data;
starting from the initial page number of the file, storing the page number of the next storage page corresponding to the storage page in the item corresponding to the page number of the storage page in which the data of the file to be written is written;
and storing information representing the file end of the file to be written in an item corresponding to the page number of the last storage page in which the file data is written.
Optionally, if it is determined that the FLASH memory has insufficient space, the method further includes:
and storing the item storage information of the deleted storage page which shows that the data of the storage page is invalid in the item of the distribution information of the page of the FLASH memory, rewriting the item storage information into the information which shows that the storage page has no data, and releasing the storage space of the deleted storage page.
Optionally, after writing the data of the file to be written to the storage page, the method further includes:
storing the information of the corresponding item to the distribution information of the page according to the sequence of the item number corresponding to the page number of the storage page written in the file data to be written; wherein the length of the storage content of each item is set to be a fixed byte length, and the address of each item in the allocation information of the page corresponds in proportion to the item number of the item.
Optionally, after writing the data of the file to be written to the storage page, the method further includes:
reading the file data content stored in the storage page;
comparing the file data content stored in each storage page with the data of the corresponding part of the file to be written;
and judging whether the written data of the file to be written is wrong or not according to the comparison result.
Optionally, the method further includes:
and if the written data of the file to be written is wrong, outputting error prompt information.
The second aspect of the invention provides a file reading method of a FLASH memory, which is applied to the FLAH memory, wherein the FLASH memory comprises a plurality of pages, page numbers and allocation information of the pages; the page is the erasable minimum unit storage unit of the FLASH memory and is used for storing files; the page number is the page serial number of the page in the FLASH memory; the allocation information of the page represents a linked list structure of the page, the allocation information of the page comprises a plurality of items, and the items store one of page number information of a next page of the corresponding storage page and information representing that the corresponding storage page is the end of file; the item number is an item serial number of the item in the distribution information of the page, and the item number of the item corresponds to the page number with the same value of the page; the method comprises the following steps:
reading the initial page number of the file;
reading data of a file stored in a storage page corresponding to a starting page number of the file;
reading the page number of the next storage page stored by the item in the item number corresponding to the page number of the read storage page from the starting page number;
and reading the data of the file stored in the storage page corresponding to the page number of the next storage page until the item storing the information representing the end of the file is read in the item of the item number corresponding to the page number of the read storage page, and finishing reading the data of the file.
Optionally, the method further includes:
and determining the address of the allocation information of the item in the page according to the item number corresponding to the page number of the read storage page, and reading the page number of the next storage page stored by the item based on the address of the item, wherein the length of the storage content of each item is set to be a fixed byte length, and the address of the allocation information of each item in the page corresponds to the item number of the item in proportion.
The file writing and reading method of the FLASH memory provided by the invention has the advantages that the address sequence stored by each item in the storage page volume is consistent with the item number (0 item is at the 0 addressing position, 1 item is at the 2 addressing position, and 2 items are at the 4 addressing position), the item numbers correspond to the page numbers of the corresponding storage pages one by one, so that the mapping relation among the addresses, the item numbers and the pages is formed, and through the mapping relation, the storage page volume only needs to store the page number of the next page, so that the allocation use condition of the page can be indicated, the storage space required by the storage page volume is reduced, the index efficiency is improved, and the practicability of the FLASH memory is effectively improved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this specification, illustrate embodiments of the invention and together with the description serve to explain the principles of the invention and not to limit the invention. In the drawings:
fig. 1 is a schematic structural diagram of a FLASH memory frame structure according to an embodiment of the present invention;
fig. 2 is a diagram illustrating a correspondence between FLASH storage page volume addressing and item numbers according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of a FLASH file reading use case provided in the embodiment of the present invention;
FIG. 4 is a flowchart of a storage file management method based on a FLASH memory according to an embodiment of the present invention;
fig. 5 is a flowchart illustrating a process of detecting whether a rename file corresponding to the file to be written exists according to an embodiment of the present invention;
FIG. 6 is a flowchart illustrating a method for determining whether a file description volume space of an idle file is sufficient for writing the file description according to an embodiment of the present invention;
fig. 7 is a flowchart of a method for releasing space in a FLASH release file description volume according to an embodiment of the present invention;
fig. 8 is a flowchart illustrating a process of determining whether a storage space of an idle file is sufficient for writing data of the file to be written according to an embodiment of the present invention;
fig. 9 is a flowchart of a method for releasing the occupied space of the deleted file by the FLASH according to the embodiment of the present invention;
fig. 10 is a flowchart illustrating a process of detecting whether data written into the file to be written has an error according to an embodiment of the present invention;
FIG. 11 is a flowchart of a method for writing a file based on a FLASH memory according to an embodiment of the present invention;
FIG. 12 is a flowchart of a storage file management method based on a FLASH memory according to another embodiment of the present invention;
fig. 13 is a flowchart of a storage file management method based on a FLASH memory according to another embodiment of the present invention.
Detailed Description
The following detailed description of embodiments of the present invention is provided in connection with the accompanying drawings and examples. The following examples are intended to illustrate the invention but are not intended to limit the scope of the invention.
In order to support operations such as random writing, reading or deleting of FLASH file data, the embodiment of the invention provides a FLASH memory, which comprises a FLASH memory area, wherein the FLASH memory area is divided into a plurality of pages starting with number 0 according to the minimum unit of FLASH erasing, and then the memory area of the FLASH memory is divided according to functions. In this embodiment, the FLASH memory chip may be applied to a Near Field Communication (NFC) card, where a "page" in this embodiment is defined as a minimum unit of FLASH erase, a "volume" is defined as one or more continuous "pages" for storing a type of data, the storage capacity of each "page" is 1024 bytes, and a FLASH chip with a storage capacity of 2M may divide a FLASH memory area into 2048 pages. Each page may also be defined as a different capacity size.
Fig. 1 is a schematic structural diagram of a frame structure of a FLASH memory, and as can be seen from fig. 1, a FLASH memory in the FLASH memory is divided into a boot area, a storage page volume, a file description volume, and a file data storage area in this embodiment. The system comprises a boot area, a storage page volume and a file description volume, wherein the boot area, the storage page volume and the file description volume belong to a system area and are used for describing the distribution and use conditions of information, file information and pages of a FLASH memory, and only occupy a few storage pages; the file data storage area is used for storing data of a file, occupies most storage pages, and specifically, the specific functions of the above parts are as follows:
the boot area is used for describing the information of the FLASH memory, such as the storage name, the version number, the memory generation time, the type of the memory, and the like, and the details are shown in table 1:
TABLE 1
Starting byte position Name (R) Occupied byte Current content
0 Memory storage name 4 “NFSS”
4 Version number 4 “1000”
8 Page length 2 1024
10 The whole stored page number 2 1994
12 Boot sector start page number 2 0
14 Number of lead area pages 2 1
16 Starting page number of storage page volume 2 1
18 Number of pages of storage page volume 2 4
20 File description volume start number 2 5
22 Number of pages occupied by file description volume 2 5
24 Initial page number of file data area 2 10
26 Number of pages occupied by file data area 2 1984
28 Memory generation time 8
36 Memory type encoding 2
38 Retention 256
294 Memory name length 2
296 Memory name Indefinite article
Remainder of Retention
As can be seen from the above table, the storage capacity of the FLASH memory used in the embodiment of the present invention is 2M, which is divided into 2048 pages according to the minimum unit of FLASH erase, and the number of pages used in the entire memory is 1994 pages. The initial page of the boot sector is page 0, and 1 page is occupied; the initial page of the storage page volume is page 1, and 4 pages are occupied; the file description page volume has a starting page of page 5, occupying 5 total pages, and the remaining pages 10 to 1984 are allocated as file data storage areas.
The storage page volume indicates allocation information of pages and indicates a linked list structure of pages where file data is stored. The allocation information includes a plurality of entries, each entry for storing the page number of the next storage page of the file data, each entry within the storage page volume being a 16-bit integer occupying two 8-bit bytes, so that addressing from the beginning of the storage page volume is twice the entry sequence number. As shown in fig. 2, the order of addresses held by each entry corresponds to the entry number (0 entry at 0 addressing, 1 entry at 2 addressing, and 2 entry at 4 addressing), it should be noted that the correspondence may be identical, and the entry number corresponds to the page number of the corresponding storage page one to one (0 entry corresponds to page 0, 1 entry corresponds to page 1, and 2 entry corresponds to page 2), and the contents of the entry normally indicate the page number of the next storage page of the file data. For example, the address of the 100H entry is the 200H byte, and if the contents of the two bytes are 70H, this indicates that the file uses the data area of the 100H page, and the number of the next page used by the file is 70H.
It should be noted that the embodiment of the present invention makes the following limitations on the content of each item: 1)0x0000 indicates that the corresponding page data is invalid; 2)0xFFFF indicates that the corresponding page has no data written; 3)0x7FFF indicates end of file; 4)0x0006 denotes a system area; 5)0x0003 indicates that this page is a bad page.
The file description volume is used for describing information of stored files, each item of the file description volume corresponds to a file stored in the FLASH memory, the content of the file description volume is file information and the initial page number of the file, and the structure of each item is shown in table 2:
TABLE 2
Starting position Name (R) Occupied byte
0 File description length 2
2 File attributes 2
4 File generation time 8
12 Starting page number of file 2
14 File length 4
18 File check word 16
34 Reserved area 16
50 Filename Length 2
52 Filename Indefinite article
The file description of a file may include information such as the starting page number and the length of the file, and may further include one or more other information such as the file name, the file attribute, the length of the file, the starting page number of the file, the file generation time, and the like.
And the file data area is used for storing file data and occupies most of the pages of the FLASH storage area.
According to the FLASH memory provided by the embodiment, the address sequence stored in each item in the storage page volume is consistent with the item number (0 item is at the 0 addressing position, 1 item is at the 2 addressing position, and 2 items are at the 4 addressing position), and the item number is in one-to-one correspondence with the page number of the corresponding storage page, so that the mapping relation among the address, the item number and the page is formed.
The following describes a file management method for a FLASH file according to an embodiment of the present invention with a specific example. Txt file structure is shown in fig. 3, the first ten pages of storage area of FLASH memory are divided into FLASH system area, and the rest is FLASH file data storage area.
According to the information of the file description volume, the file name of the file is sample.txt, the starting page number of the file is 0x000c, the length of the file is 0x0600, namely 1536 bytes, and one page can store 1024 bytes, so that the data of the sample.txt in the file needs to occupy two pages;
knowing that the initial page number of the file is 0x000c from the file description volume, searching 0x000c items with the content of 0x0010 in the page allocation volume according to the mapping relation between the item numbers and the page allocation volume addressing, namely, the next page number of the file is 0x0010, and since the content of the 0x0010 item is 0x0001, the next page points to a system area, which indicates that no file storage data exists behind the file; txt is stored in two pages, 0x000c and 0x0010, and the storage area of the file is determined by a linked list of page numbers starting from the file start page number in the header.
In the embodiment of the invention, the address sequence stored by each item of the page allocation volume is consistent with the item number (0 item is at the 0 addressing position, 1 item is at the 2 addressing position, and 2 items are at the 4 addressing position), and each item corresponds to the corresponding storage page one by one, so that the storage page volume only needs to store the page number of the next page through the mapping relation of the address, the item number and the page, the allocation use condition of the page can be indicated, the storage space required by the storage page volume is reduced, and the index efficiency is improved.
After the FLASH memory area is divided, the file writing, reading and deleting operations can be executed according to the file management method of the embodiment of the invention. After the system establishes contact with the FLASH memory, the storage page volume and the file description volume of the NFC card (the FLASH memory is applied to the NFC card) are read first, and the file list is extracted, so that the file operation is performed on the NFC card quickly in the whole operation process.
FIG. 4 is a flowchart of a storage file management method based on a FLASH memory according to an embodiment of the present invention; as can be seen from fig. 4, this embodiment provides a method for managing a storage file based on the above FLASH memory, where the method for managing a storage file is a file writing method, and specifically, a process of writing a file is started from parameter-file description, so as to establish a link table relationship between file description and pages, and write data into a file data storage area, and specifically, the method includes:
s101: reading information of a file to be written;
the information of the file to be written may include a name of the file to be written, a length of the file to be written, content of the file to be written, and the like.
S102: determining the size of the file description of the file to be written, and judging whether the file description volume in the FLASH memory has enough space for writing the file description;
the file description of the file to be written can be determined through the read information of the file to be written, so that the size of the file description can be determined.
S1031: if the file description volume has enough space to write the file description, judging whether a file data storage area in the FLASH memory has enough space to write the file data to be written;
when it is confirmed that there is enough space in the file description volume, it is indicated that normal write operation can be performed for the file description at this time, and since the present embodiment aims to write the data of the file to be written into the FLASH memory, it is necessary to determine whether there is enough space in the file data storage region to write the data of the file to be written into the FLASH memory in order to ensure that the data of the file to be written is written normally.
S1041: if the file data storage area has enough space to write in the data of the file to be written, searching a first empty page number of the file data storage area as a file initial page number, and writing a file description in a file description volume;
when it is determined that the file data storage area has enough space to write the data of the file to be written, normal write operations can be performed on both the file description and the data of the file to be written, and therefore, preparations can be made for the write operations, such as: the file start page number can be determined, and the file start page number is used for determining the writing position of the file to be written, and generally, the first empty page number in the file data storage area is used as the file start page number, and the file description can be written into the file description volume.
S105: and writing the file data to be written in the file data storage area from the initial page number of the file description.
S106: and updating the storage page volume according to the page linked list relation stored in the file data storage area, and ending the writing process.
After writing the file description to the file description volume, the file data to be written may be written starting at the position of the starting page number in the file description, thereby completing the file writing operation.
It should be noted that, after the above-mentioned determining whether the file description volume in the FLASH memory has enough space to write the file description, the method may further include:
s1032: and if the file description volume does not have enough space to write the file description, outputting the abnormal condition that the file description volume has insufficient space.
Further, after the above-mentioned determining whether the file data storage area in the FLASH memory has enough space to write the file data to be written, the method may further include:
s1042: and if the file data storage area does not have enough space for writing the data of the file to be written, the space of the output file data storage area is insufficient and abnormal.
The method for managing storage files provided in this embodiment implements a process of writing files by using the structure of the FLASH memory, and specifically, the FLASH memory keeps an address sequence of each item in a storage page volume consistent with an item number (0 item is at an addressing position 0, 1 item is at an addressing position 2, and 2 items are at an addressing position 4), and the item numbers correspond to corresponding storage page numbers one to one, so as to form a mapping relationship among addresses, item numbers, and pages.
Fig. 5 is a flowchart of detecting whether there is a rename file corresponding to a file to be written in according to an embodiment of the present invention, and referring to fig. 5 on the basis of the above embodiment, in order to further improve the stability and reliability of the method for managing a storage file, after reading information of the file to be written, the method is further configured to further include:
s201: detecting whether a duplicate name file corresponding to a file to be written exists or not;
after the information of the file to be written is obtained, the stored file can be detected according to the information of the file to be written, whether a duplicate name file corresponding to the file to be written exists in the stored file is detected, and specifically, name information in the information of the file to be written and name information of the stored file can be analyzed and compared.
S202: if yes, outputting the duplicate name file abnormal operation;
if the analysis and comparison result shows that the name information in the file information to be written is the same as the name information of the stored information, it can be confirmed that a duplicate name file corresponding to the file to be written exists in the FLASH memory, and at this time, a process of performing secondary writing on the same file may occur.
S203: and if not, determining the size of the file description of the file to be written.
If the analysis and comparison result indicates that the name information in the information of the file to be written is different from the name information of the stored information, it may be determined that the file to be written is not stored in the FLASH memory at this time, so that the writing operation of the file to be written may be performed normally, that is, the size of the file description of the file to be written may be obtained, and then the subsequent writing operation may be performed according to steps 102 to 105 in the above embodiment, which may specifically refer to the above statements and will not be described herein again.
According to the storage file management method provided by the embodiment, whether the duplicate name file corresponding to the file to be written exists in the FLASH memory is detected, so that the operation of performing secondary error writing on the same file is avoided, the stability and the reliability of the writing operation on the file to be written are effectively ensured, and the stability and the reliability of the use of the storage file management method are further improved.
FIG. 6 is a flowchart illustrating a method for determining whether a file description volume space of an idle file is sufficient for writing a file description according to an embodiment of the present invention; fig. 7 is a flowchart of a method for releasing space in a FLASH release file description volume according to an embodiment of the present invention; on the basis of the above embodiment, as can be seen with continued reference to fig. 6-7, before searching for the first empty page number of the file data storage area as the starting page number of the file, the present embodiment may be configured to further include:
s301: judging whether the space of the file description volume of the idle file is enough to write the file description;
when there is enough space in the file description volume to write the file description, there may be two cases, one is that the file description volume space of the idle file has enough space to write the file description, and the other is that the whole file description volume (including the file description volume space of the idle file, the file description volume space of the used file, the file description volume space of the invalid file, etc.) has enough space to write the file description.
S302: if the space is insufficient, releasing the occupied space described by the invalid file, and searching a first empty page number of the file data storage area as a file initial page number; alternatively, the first and second electrodes may be,
if the space of the file description volume of the idle file is not enough to write the file description, at this time, in order to ensure the normal writing of the file description, the occupied space of the invalid file description can be released, so as to increase the size of the space for storing the file description, and fig. 7 is an implementation manner of releasing the space in the file description volume by FLASH, the process of releasing the occupied space of the invalid file description is performed in the file description volume, and the purpose is to squeeze the deleted file description, regenerate a new file description volume, reconstruct the file description volume according to the file list, then erase the original file description volume, and rewrite the new file description volume; after the occupied space described by the invalid file is released, the first empty page number of the file data storage area may be continuously searched as the starting page number of the file, and the subsequent implementation processes of step S1041 to step S105 in the foregoing embodiment may be performed, which may specifically refer to the above statements and is not described herein again.
S303: if the space is sufficient, the first empty page number of the file data storage area is directly searched as the starting page number of the file.
If the file description volume space of the idle file is sufficient for writing the file description, the first empty page number of the file data storage area may be directly searched as the starting page number of the file, and the subsequent implementation processes of step S1041 to step S105 in the above embodiment may be performed, which may specifically refer to the above statements and will not be described herein again.
According to the method for managing the stored file, whether the file description volume space of the idle file is enough for writing the file description is judged, so that the safe reliability of writing the file description can be effectively ensured, and the stability and the reliability of the method for managing the stored file are further improved.
FIG. 8 is a flowchart illustrating a method for determining whether a storage space of an idle file is sufficient for writing data of a file to be written according to an embodiment of the present invention; fig. 9 is a flowchart of a method for releasing the occupied space of the deleted file by the FLASH according to the embodiment of the present invention; on the basis of the foregoing embodiment, as can be seen with continued reference to fig. 8-9, before writing the file data to be written in the file data storage area from the start page number of the file description, the method of this embodiment is configured to further include:
s401: judging whether the storage space of the idle file is enough to write in the data of the file to be written;
when the file data storage area has enough space to write the data of the file to be written, two situations may be included, one being that the storage space of the idle file has enough space to write the data of the file to be written, and the other being that the entire file data storage area (including the storage space of the idle file, the storage space of the used file, the occupied space of the deleted file, etc.) has enough space to write the data of the file to be written, so to further improve the stability and reliability of the file management method, it is necessary to determine whether the storage space of the idle file is enough to write the data of the file to be written, and a specific determination process may analyze and compare the size of the data of the file to be written with the size of the storage space of the idle file.
S402: if the space is insufficient, releasing the occupied space of the deleted file, and writing the file data to be written in the file data storage area from the initial page number described by the file; alternatively, the first and second electrodes may be,
if the storage space of the idle file is not enough to write the data of the file to be written, at this time, in order to ensure the normal write operation of the data to be written, the occupied space of the deleted file may be released, so as to increase the size of the space for storing the data to be written, and fig. 9 is an implementation manner of releasing the occupied space of the deleted file by FLASH. This operation need only be done within the memory page volume, which acts to rewrite all pages marked as 0x0000 (invalidated) to 0 xffff; after the space occupied by the deleted file is released, the data of the file to be written may be written in the file data storage area from the start page number described in the file, and the subsequent implementation processes of step S1041 to step S105 in the foregoing embodiment may be performed, which may specifically refer to the above statements and will not be described herein again.
S403: and if the space is enough, writing the file data to be written in the file data storage area directly from the initial page number of the file description.
If the storage space of the idle file is sufficient for writing the data of the file to be written, the data of the file to be written may be written in the file data storage area directly from the start page number of the file description, and the subsequent implementation processes of step S1041 to step S105 in the above embodiment may be specifically referred to the above statements, which are not described herein again.
According to the method for managing the stored file, whether the storage space of the idle file is enough for writing the data of the file to be written is judged, so that the stability and the reliability of the writing operation of the data of the file to be written can be effectively guaranteed, and the stability and the reliability of the method for managing the stored file are further improved.
FIG. 10 is a flowchart illustrating an embodiment of detecting whether data written into a file to be written has an error; on the basis of the foregoing embodiment, as can be seen with continued reference to fig. 10, in order to further determine the security reliability of the data writing operation, after writing the file data to be written in the file data storage area from the starting page number of the file description, the present embodiment sets the method to further include:
s501: detecting whether the written file data to be written has errors;
after the writing operation of the file data to be written is finished, the content of the file data written into the FLASH memory and the content of the file data to be written can be analyzed and compared to detect whether the written file data to be written has errors.
S502: if the written file data to be written has errors, outputting error information; alternatively, the first and second electrodes may be,
and when the analysis and comparison result shows that the written file data content is inconsistent with the content of the file data to be written, the written file data to be written has an error, so that the error writing operation can be confirmed, and error information is output to remind a user conveniently.
S503: and if the data of the file to be written is correct, updating the storage page volume according to the page linked list relation stored in the file data storage area of the file to be written.
And when the analysis and comparison result shows that the content of the written file data is consistent with the content of the file data to be written, the written file data to be written is a correct writing operation, and the storage page volume is updated according to the page linked list relation stored in the file data storage area of the file to be written, so that a user can conveniently read or delete the written file to be written.
The storage file management method provided by the embodiment can effectively ensure the correct reliability of the writing operation of the file data to be written by detecting whether the written file data to be written has errors, and further improves the stability and reliability of the storage file management method.
In specific application, fig. 11 is a flowchart of a method for writing a file based on a FLASH memory according to an embodiment of the present invention; as can be seen with reference to fig. 11, the data file writing step includes:
step A: b, the system reads the information of the file, then detects whether there is a duplicate name file, if yes, outputs the duplicate name file to be abnormal, if not, executes step B;
and B: determining the size of the file description, judging whether the file description volume of the FLASH has enough space to write the file description, if the space is insufficient, outputting an abnormal condition that the space of the file description volume is insufficient, and if the space of the file description volume is enough, executing the step C;
and C: judging whether the file data storage area has enough space for writing the file data, if the space is insufficient, outputting that the space of the file data storage area is insufficient and abnormal, and if the space is sufficient, executing the step D;
step D: judging whether the space of the idle file description volume is enough for writing the file description, if so, releasing the space occupied by the invalid file description, and executing the step E; if the space is enough, directly executing the step E;
step E: searching the first empty page number of the file data storage area as the initial page number of the file, writing the file description, and executing the step F;
step F: judging whether the idle storage space is enough for writing file data, if the space is insufficient, releasing the occupied space of the deleted file, and executing the step G; if the space is sufficient, executing step G;
step G: writing data in the file data storage area starting from the start page number of the file description; executing the step H;
step H: detecting whether the written data has errors, and if the written data has errors, returning error information; if the result is correct, executing the step I;
step I: and updating the storage page volume according to the page linked list relation stored in the file data storage area, and ending the writing process.
FIG. 12 is a flowchart of a storage file management method based on a FLASH memory according to another embodiment of the present invention; as can be seen from fig. 12, the present embodiment provides another storage file management method, which is a method for reading a file, and the above-mentioned process for reading a file starts with a parameter-file description, and aims to read data of a page of a linked list determined by a starting page number of a file in the file description, and specifically, the method includes:
step A: the system reads the initial page number of the file from the file description volume;
and B: reading file data stored in a storage page corresponding to the initial page number of the file;
specifically, the specific position of the starting page number of the file may be determined, specifically, whether the starting page number of the file is 0x0001 preset or not may be detected, if so, correct reading information is returned, if not, other positions where the starting page number of the file is located may be determined, and after the specific position of the starting page number of the file is confirmed, file data stored in a storage page corresponding to the starting page number of the file is read;
and C: and reading the page number of the next page of the file according to the file storage page volume, and reading the file data stored in the storage page corresponding to the page number until the file data is completely read.
Specifically, after the file data stored in the storage page corresponding to the starting page number of the file is read, in order to read the whole file data, the page number of the next page of the file may be acquired, and then the file data stored in the corresponding storage page is read according to the page number.
Further, in order to improve the correct reliability of file reading, after reading the file data stored in the storage page corresponding to the starting page number of the file, the method is configured to further include:
step D: judging whether the reading is correct or not;
if the reading is wrong, returning error information and ending the reading of the file;
if the reading is correct, inquiring the content of the corresponding item in the storage page volume according to the initial page number of the file, acquiring the page number of the next page, and reading the file data stored in the storage page corresponding to the page number.
Wherein the error information includes: a read operation error; a file length error; and checking the word error at the end of the file.
The method for managing storage files provided in this embodiment implements a process of writing in files by using the structure of the FLASH memory, and specifically, the FLASH memory keeps an address sequence of each item in a storage page volume consistent with an item number (0 item is at an addressing position 0, 1 item is at an addressing position 2, and 2 items are at an addressing position 4), and the item numbers correspond to corresponding storage page numbers one by one, so as to form a mapping relationship among addresses, item numbers, and pages.
Fig. 13 is a flowchart of a storage file management method based on a FLASH memory according to another embodiment of the present invention, and referring to fig. 13, the present embodiment provides another storage file management method, where the storage file management method is a method for deleting a file, and the file deleting process starts from a parameter-file description, and is intended to mark a file description of a deleted file and a data saving page thereof, and specifically, the method for deleting a file includes:
step A: reading the address addr of the starting page number of the file description and the starting page number pageNum of the file data from the file description volume, and setting the address content specified by the addr in the storage page volume to be 0 (indicating that the corresponding page data of the item is invalid);
after the initial page number pageNum of the file data is read, whether the page number pageNum is preset 0x0001 or not can be judged, and if yes, correct information is returned; if not, step B may continue.
And B: and inquiring the content of the corresponding item in the storage page volume according to the initial page number of the file data, acquiring the address addr of the next page number and the pageNum of the next page number, and setting the content of the specified address of the address addr of the next page number in the storage page volume to be 0 (indicating that the corresponding page data of the item is invalid) until the file data is deleted completely.
Further, in order to improve the reliability of deleting the file, after setting the content of the addr designated address in the storage page volume to 0, the method is further configured to further include:
and C: judging whether the deletion operation is wrong or not;
if the deletion operation is wrong, returning error information;
if the deletion operation is correct, the content of the address of the next page number located at the current page number in the storage page volume may be set to 0 to complete the deletion operation on the whole file.
Wherein the error information includes: operation error and error of data page number occupied by files.
The method for managing storage files provided in this embodiment implements a process of writing in files by using the structure of the FLASH memory, and specifically, the FLASH memory keeps an address sequence of each item in a storage page volume consistent with an item number (0 item is at an addressing position 0, 1 item is at an addressing position 2, and 2 items are at an addressing position 4), and the item numbers correspond to corresponding storage page numbers one by one, so as to form a mapping relationship among addresses, item numbers, and pages.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.

Claims (7)

1. A file writing method of a FLASH memory is characterized in that the FLASH memory comprises a plurality of pages, page numbers and allocation information of the pages, wherein the pages are erasable minimum unit storage units of the FLASH memory and are used for storing files; the page number is the serial number of the page in the FLASH memory; the allocation information of the page represents a linked list structure of the page, the allocation information of the page comprises a plurality of items, the items store one or more of information representing that the corresponding storage page has no data, information representing that the corresponding storage page has invalid data, page number information of a next page of the corresponding storage page, information representing that the corresponding storage page is the end of file, and information representing that the corresponding storage page is a bad page, the item numbers are item serial numbers of the items in the allocation information of the corresponding pages, and the item numbers of the items correspond to the page numbers with the same values of the pages; the method comprises the following steps:
reading information of a file to be written, wherein the information of the file to be written comprises the length of the file to be written and data of the file to be written;
comparing the length of the file to be written with the size of a storage space of an empty page, wherein an item corresponding to the empty page stores information indicating that the page has no data;
judging whether the FLASH memory has enough space to write the data of the file to be written in based on the comparison result;
if the FLASH memory is judged to have enough space, searching a first empty page without data of the FLASH memory, and determining a writing position of a file to be written;
determining the page number of the first empty page without data as the initial page number of the file, and storing the initial page number of the file;
writing the data of the file to be written into a storage page from the first empty page without data;
starting from the initial page number of the file, storing the page number of the next storage page corresponding to the storage page in the item corresponding to the page number of the storage page in which the data of the file to be written is written;
and storing information representing the file end of the file to be written in an item corresponding to the page number of the last storage page in which the file data is written.
2. The method of claim 1, wherein if it is determined that FLASH memory does not have sufficient space, the method further comprises:
and storing the item storage information of the deleted storage page which shows that the data of the storage page is invalid in the item of the distribution information of the page of the FLASH memory, rewriting the item storage information into the information which shows that the storage page has no data, and releasing the storage space of the deleted storage page.
3. The method of claim 1, wherein after writing data of the file to be written to a memory page, the method further comprises:
storing the information of the corresponding item to the distribution information of the page according to the sequence of the item number corresponding to the page number of the storage page written in the file data to be written; wherein the length of the storage content of each item is set to be a fixed byte length, and the address of each item in the allocation information of the page corresponds in proportion to the item number of the item.
4. The method according to any of claims 1-3, wherein after writing the data of the file to be written to a memory page, the method further comprises:
reading the file data content stored in the storage page;
comparing the file data content stored in each storage page with the data of the corresponding part of the file to be written;
and judging whether the written data of the file to be written is wrong or not according to the comparison result.
5. The method of claim 4, further comprising:
and if the written data of the file to be written is wrong, outputting error prompt information.
6. A file reading method of a FLASH memory is characterized in that the FLASH memory comprises a plurality of pages, page numbers and page allocation information; the page is the erasable minimum unit storage unit of the FLASH memory and is used for storing files; the page number is the page serial number of the page in the FLASH memory; the allocation information of the page represents a linked list structure of the page, the allocation information of the page comprises a plurality of items, and the items store one of page number information of a next page of the corresponding storage page and information representing that the corresponding storage page is the end of file; the item number is an item serial number of the item in the distribution information of the page, and the item number of the item corresponds to the page number with the same value of the page; the method comprises the following steps:
reading the initial page number of the file;
reading data of a file stored in a storage page corresponding to a starting page number of the file;
reading the page number of the next storage page stored by the item in the item number corresponding to the page number of the read storage page from the starting page number;
and reading the data of the file stored in the storage page corresponding to the page number of the next storage page until the item storing the information representing the end of the file is read in the item of the item number corresponding to the page number of the read storage page, and finishing reading the data of the file.
7. The method of claim 6, further comprising:
and determining the address of the allocation information of the item in the page according to the item number corresponding to the page number of the read storage page, and reading the page number of the next storage page stored by the item based on the address of the item, wherein the length of the storage content of each item is set to be a fixed byte length, and the address of the allocation information of each item in the page corresponds to the item number of the item in proportion.
CN202110935528.8A 2017-03-27 2017-03-27 File writing and reading method of FLASH memory Pending CN113641629A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110935528.8A CN113641629A (en) 2017-03-27 2017-03-27 File writing and reading method of FLASH memory

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110935528.8A CN113641629A (en) 2017-03-27 2017-03-27 File writing and reading method of FLASH memory
CN201710189447.1A CN108664482B (en) 2017-03-27 2017-03-27 FLASH memory and storage file management method

Related Parent Applications (1)

Application Number Title Priority Date Filing Date
CN201710189447.1A Division CN108664482B (en) 2017-03-27 2017-03-27 FLASH memory and storage file management method

Publications (1)

Publication Number Publication Date
CN113641629A true CN113641629A (en) 2021-11-12

Family

ID=63786293

Family Applications (3)

Application Number Title Priority Date Filing Date
CN202110935528.8A Pending CN113641629A (en) 2017-03-27 2017-03-27 File writing and reading method of FLASH memory
CN202110935551.7A Pending CN113641630A (en) 2017-03-27 2017-03-27 FLASH memory
CN201710189447.1A Active CN108664482B (en) 2017-03-27 2017-03-27 FLASH memory and storage file management method

Family Applications After (2)

Application Number Title Priority Date Filing Date
CN202110935551.7A Pending CN113641630A (en) 2017-03-27 2017-03-27 FLASH memory
CN201710189447.1A Active CN108664482B (en) 2017-03-27 2017-03-27 FLASH memory and storage file management method

Country Status (1)

Country Link
CN (3) CN113641629A (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110716904A (en) * 2019-10-14 2020-01-21 深圳市优创亿科技有限公司 Design method of embedded file system
CN113050876A (en) * 2019-12-27 2021-06-29 中兴通讯股份有限公司 File data writing method, device, equipment and storage medium
CN113934371B (en) * 2021-10-08 2024-04-12 福建星网视易信息系统有限公司 Memory, data management method thereof and computer storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101127004A (en) * 2007-09-24 2008-02-20 中兴通讯股份有限公司 System and method for accessing data on flash memory
CN102279805A (en) * 2011-09-06 2011-12-14 四川九洲电器集团有限责任公司 Memory data storing and reading method
CN103258044A (en) * 2013-05-24 2013-08-21 北京航天自动控制研究所 Two-tuple NANDFLASH data file management method oriented to DSP
CN105468304A (en) * 2015-11-26 2016-04-06 恒宝股份有限公司 Native memory card and management method thereof

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1204501C (en) * 2001-09-18 2005-06-01 华为技术有限公司 FLASH storage file management method
KR20040072875A (en) * 2003-02-11 2004-08-19 유비시스테크놀러지 주식회사 Storage using nand flash memory
CN1277213C (en) * 2004-12-31 2006-09-27 大唐微电子技术有限公司 A flash memory file system management method
KR101392174B1 (en) * 2011-11-09 2014-05-09 한양대학교 산학협력단 Apparatus and method for controlling flash memory storing mapping table of block to erase
CN102708107A (en) * 2011-12-13 2012-10-03 北京安天电子设备有限公司 Method and system for storing appended files
CN103257928B (en) * 2013-04-16 2016-01-13 深圳市江波龙电子有限公司 Flash memory device data managing method and system
US9483397B2 (en) * 2013-07-16 2016-11-01 Intel Corporation Erase management in memory systems
CN106527969B (en) * 2016-09-21 2017-09-19 中国科学院地质与地球物理研究所 A kind of Nand Flash memorizer reading/writing method in a balanced way of life-span

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101127004A (en) * 2007-09-24 2008-02-20 中兴通讯股份有限公司 System and method for accessing data on flash memory
CN102279805A (en) * 2011-09-06 2011-12-14 四川九洲电器集团有限责任公司 Memory data storing and reading method
CN103258044A (en) * 2013-05-24 2013-08-21 北京航天自动控制研究所 Two-tuple NANDFLASH data file management method oriented to DSP
CN105468304A (en) * 2015-11-26 2016-04-06 恒宝股份有限公司 Native memory card and management method thereof

Also Published As

Publication number Publication date
CN113641630A (en) 2021-11-12
CN108664482B (en) 2021-09-07
CN108664482A (en) 2018-10-16

Similar Documents

Publication Publication Date Title
CN107168884B (en) Storage system, information processing system, and method for controlling nonvolatile memory
CN107168885B (en) Storage system, information processing system, and method for controlling nonvolatile memory
CN107168640B (en) Storage system, information processing system, and method for controlling nonvolatile memory
CN107168639B (en) Storage system, information processing system, and method for controlling nonvolatile memory
US8392690B2 (en) Management method for reducing utilization rate of random access memory (RAM) used in flash memory
US20190220396A1 (en) Data Storage Device
US9563375B2 (en) Method for storing metadata of log-structured file system for flash memory
CN111125447A (en) Metadata access method, device and equipment and readable storage medium
US20090307291A1 (en) Smart card storage system and file management method therein
US7761648B2 (en) Caching method for NAND flash translation layer
CN110018998B (en) File management method and system, electronic equipment and storage medium
US20040210706A1 (en) Method for managing flash memory
US10228875B2 (en) Data writing and reading methods for flash
US20110302224A1 (en) Data storage device with preloaded content
US20110153979A1 (en) Modified b+ tree to store nand memory indirection maps
CN108399047B (en) Flash memory file system and data management method thereof
CN108829342B (en) Log storage method, system and storage device
CN108664482B (en) FLASH memory and storage file management method
CN102541969B (en) File protection method and system based on file allocation table (FAT) file system, and memory
WO2020192710A1 (en) Method for processing garbage based on lsm database, solid state hard disk, and storage apparatus
CN114089915B (en) File additional writing operation method and device based on FLASH memory
TW201826125A (en) Memory control scheme for flash memory device
CN110147332B (en) Management method of directory data and memory device
KR100954603B1 (en) A log file of file system and method for recovering file system
CN108376121B (en) Data storage method of Flash memory

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
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20211112