CN116775379A - Linked list type data storage method, intelligent terminal and storage medium - Google Patents

Linked list type data storage method, intelligent terminal and storage medium Download PDF

Info

Publication number
CN116775379A
CN116775379A CN202310814836.4A CN202310814836A CN116775379A CN 116775379 A CN116775379 A CN 116775379A CN 202310814836 A CN202310814836 A CN 202310814836A CN 116775379 A CN116775379 A CN 116775379A
Authority
CN
China
Prior art keywords
data
stored
sector
storage
file
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
CN202310814836.4A
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.)
Shenzhen Toprank Electronics Co ltd
Original Assignee
Shenzhen Toprank Electronics 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 Shenzhen Toprank Electronics Co ltd filed Critical Shenzhen Toprank Electronics Co ltd
Priority to CN202310814836.4A priority Critical patent/CN116775379A/en
Publication of CN116775379A publication Critical patent/CN116775379A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1415Saving, restoring, recovering or retrying at system level
    • G06F11/1435Saving, restoring, recovering or retrying at system level using file system or storage system metadata
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0238Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory
    • G06F12/0246Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory in block erasable memory, e.g. flash memory
    • 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/13File access structures, e.g. distributed indices
    • 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/17Details of further file system functions
    • G06F16/172Caching, prefetching or hoarding of files
    • 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/18File system types
    • G06F16/1847File system types specifically adapted to static storage, e.g. adapted to flash memory or SSD
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures
    • G06F16/9024Graphs; Linked lists
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/10Providing a specific technical effect
    • G06F2212/1032Reliability improvement, data loss prevention, degraded operation etc
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/10Providing a specific technical effect
    • G06F2212/1041Resource optimization
    • G06F2212/1044Space efficiency improvement

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Library & Information Science (AREA)
  • Quality & Reliability (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application relates to a linked list type data storage method, an intelligent terminal and a storage medium, belonging to the technical field of storage, wherein the method comprises the following steps: storing an information data structure of the storage file; the storage file is established on a file system and is a linked list file; the storage file comprises an information data structure and a data structure; reading file system information of the file system to obtain the latest file information of the stored file; the file information comprises a plurality of sector data; storing the data structure of the sector data; reading the last package of storage data of the sector data according to the file system information; carrying out power failure detection on the last packet of stored data; and writing the stored data after the power failure detection is successful. The method has the effect of effectively improving the capability of preventing the linked list data from being lost.

Description

Linked list type data storage method, intelligent terminal and storage medium
Technical Field
The present application relates to the field of storage technologies, and in particular, to a linked list data storage method, an intelligent terminal, and a storage medium.
Background
The linked list data is a data structure, and when an uncertain number of elements need to be stored, the elements can be dynamically added and deleted through the linked list data structure. Different from static data structures such as an array, the linked list can flexibly allocate nodes under the condition that all storage spaces do not need to be applied at one time, and data addition and deletion are realized. Therefore, the linked list data structure is stored in the memory, so that unnecessary memory overhead can be saved, and meanwhile, the efficiency and the running speed of the program are improved.
However, during the writing, reading, etc. of linked list data, the linked list data often has the phenomena that the necessary information is not correctly stored due to the data structure before writing, the necessary information is missing or wrong during reading, the linked list data is lost due to the reasons of data interruption, etc. during writing, the necessary information refers to the necessary node information, position information, state information, etc.
With respect to the related art, the applicant believes that there is a great risk of losing the storage manner of the linked list data.
Disclosure of Invention
In order to effectively improve the capability of preventing linked list data loss, the application provides a linked list data storage method, an intelligent terminal and a storage medium.
In a first aspect, the present application provides a linked list data storage method, which adopts the following technical scheme:
a linked list data storage method, comprising:
storing an information data structure of the storage file; the storage file is established on a file system and is a linked list file; the storage file comprises an information data structure and a data structure;
reading file system information of the file system to obtain the latest file information of the stored file; the file information comprises a plurality of sector data;
storing the data structure of the sector data;
reading the last package of storage data of the sector data according to the file system information;
carrying out power failure detection on the last packet of stored data;
and writing the stored data after the power failure detection is successful.
By adopting the technical scheme, the information data structure is stored firstly, so that the information is effectively ensured to be correctly stored before the stored data is written, and the probability of error or interruption in the data storage process is effectively reduced; secondly, through carrying out power failure detection on the stored data, the stored data can be conveniently and correctly stored and recovered under the condition of power failure, so that the probability of data loss is effectively reduced; the storage data is written in, so that the data can be conveniently ensured to be stored, and the probability of data loss caused by errors or interruption in the data writing process is effectively reduced.
Optionally, the storing the information data structure of the storage file includes:
storing physical addresses of all data structures in the storage file; the physical address is used for locating the data structure;
checking each data structure based on a checking algorithm to obtain a checking value of each data structure;
storing all the check values and the physical addresses corresponding to each check value in the information data structure, and storing the information data structure.
By adopting the technical scheme, the information data structure of the storage file is stored, the check value and the physical address corresponding to each check value are firstly stored in the information data structure, and finally the information data structure is stored, so that the check of the storage data by the check value is facilitated, and the storage data is positioned by the physical address corresponding to each check value.
Optionally, the data structure includes a plurality of sectors;
the reading the file system information of the file system to obtain the latest file information of the stored file includes:
reading a starting sector in the data structure; the starting sector comprises a first sector and a second sector;
respectively carrying out data verification on sector data stored in the first sector and the second sector;
and acquiring sector data which passes the verification and is up to date, and taking the sector data as the file information.
By adopting the technical scheme, the data verification is carried out on the sector data in the first sector and the second sector, so that the utilization rate of the storage space is effectively improved.
Optionally, the sector data includes a plurality of data packets;
the storing of the data structure of the sector data includes:
defining a structural body of a data structure, wherein the structural body is used for storing the address, the data content, the data storage time stamp, the address and the check bit of the next packet of data;
acquiring the latest data packet, and taking the latest data packet as a new data packet and storing the new data packet;
updating the address of the last packet of data and the address of the next packet of data in the data structure;
checking the new data packet, generating check bits, and storing the check bits in the new data packet;
and storing the data structure storing a plurality of new data packets.
By adopting the technical scheme, the new data packet is checked, and check bits are generated for ensuring the integrity and correctness of sector data, and the address of the previous packet of data and the address of the next packet of data are used for connecting a plurality of data packets into a linked list, so that the data structure is in chain combination, and the operations such as adding, deleting and modifying the data are convenient.
Optionally, the detecting the power failure of the last packet of the stored data includes:
determining a data position and a data address of the last packet of stored data;
reading the last packet of storage data according to the data address, and taking the last packet of storage data as a last data packet;
checking the last data packet;
if the verification is successful, continuing to read the data of the last data packet;
and if the verification fails, clearing the data of the storage area where the last data packet is located.
By adopting the technical scheme, the power-down detection of the last packet of storage data is convenient for reducing the probability of data loss caused by accidental power-down of the last packet of storage data in the sector data, and the power-down detection is convenient for determining the physical address of the last packet of storage data, so that the integrity of the last packet of storage data in the sector data is effectively ensured.
Optionally, the writing the stored data after the power failure detection is successful includes:
after the power failure detection is successful, calculating the starting address of the next packet of data according to the stored data;
if the starting address is the first address of a sector, all data of the sector are emptied;
and if the starting address is not the head address of the sector, writing the storage data.
By adopting the technical scheme, after the power failure detection is successful, the starting address of the next packet of data is calculated according to the stored data, so that the probability of data loss or accidental deletion is reduced.
Optionally, after the writing of the stored data, the method includes:
recording addresses of the stored data and the next packet of data;
reading the stored data and checking the stored data;
if the verification is successful, skipping the writing step;
and if the verification fails, re-writing the stored data.
By adopting the technical scheme, after the stored data is written, the stored data is verified, so that the accuracy of the stored data can be conveniently determined; meanwhile, when verification fails, the stored data is written again, so that the probability of loss of the stored data is effectively reduced.
Optionally, after the writing of the stored data after the power-down detection is successful, the method includes:
when the stored data is read, calculating a starting time stamp and an ending time stamp for reading the stored data according to a preset data time range of the stored data;
reading the head addresses of all the sectors, and acquiring a target sector closest to the starting time address of the data time range according to an approximation algorithm;
acquiring a first address of the stored data in the target sector;
reading the stored data according to the head address of the stored data and the data time range, and checking the stored data;
if the verification fails, the stored data is read again;
if the verification is successful, continuing to read the next data of the target sector until all the data which accords with the data time range are read.
By adopting the technical scheme, after the stored data is written after the power failure detection is successful, the starting time stamp and the ending time stamp of the read stored data are calculated, so that the data range of the stored data to be read can be conveniently determined; secondly, reading the first addresses of all the sectors storing data, and obtaining a target sector of the initial time address through an approximation algorithm; and finally, acquiring the first address of the stored data by using a binary search method, and acquiring the first address of the stored data by using an approximation algorithm, wherein the first address of the sector of the stored data is only required to be searched, and the initial address of the whole data structure is not required to be found, so that the storage space of the stored data can be reduced by more than half, and the space utilization rate is effectively improved.
In a second aspect, the present application provides an intelligent terminal, which adopts the following technical scheme:
an intelligent terminal comprises a memory, a processor and a computer program stored in the memory and capable of running on the processor, wherein the linked list type data storage method is adopted when the processor loads and executes the computer program.
By adopting the technical scheme, the linked list type data storage method generates the computer program, stores the computer program in the memory and is loaded and executed by the processor, so that the intelligent terminal is manufactured according to the memory and the processor, and is convenient to use.
In a third aspect, the present application provides a computer readable storage medium, which adopts the following technical scheme:
a computer readable storage medium having a computer program stored therein, the computer program when loaded and executed by a processor employing the linked list data storage method described above.
By adopting the technical scheme, the linked list type data storage method generates a computer program, and the computer program is stored in a computer readable storage medium to be loaded and executed by a processor, and the computer program is convenient to read and store by the computer readable storage medium.
In summary, the application has at least one of the following beneficial technical effects:
1. firstly, the information data structure is stored, so that the information is effectively ensured to be correctly stored before the stored data is written, and the probability of error or interruption in the data storage process is effectively reduced; secondly, through carrying out power failure detection on the stored data, the stored data can be conveniently and correctly stored and recovered under the condition of power failure, so that the probability of data loss is effectively reduced; the storage data is written in, so that the data can be conveniently ensured to be stored, and the probability of data loss caused by errors or interruption in the data writing process is effectively reduced.
2. The power-down detection of the last packet of storage data is convenient for reducing the probability of data loss caused by accidental power-down of the last packet of storage data in the sector data, and the power-down detection is convenient for determining the physical address of the last packet of storage data, so that the integrity of the last packet of storage data in the sector data is effectively ensured.
3. The initial address of the storage data is obtained through the approximation algorithm, and the initial address of the whole data structure is not required to be found as the initial address of the sector of the storage data is only required to be found, so that the storage space of the storage data can be reduced by more than half, and the space utilization rate is effectively improved.
Drawings
FIG. 1 is a flow chart of a method for storing linked list data according to an embodiment of the present application.
FIG. 2 is a flow chart of a method for storing linked list data according to an embodiment of the present application.
FIG. 3 is a flow chart illustrating a method for storing linked list data according to an embodiment of the present application.
FIG. 4 is a flow chart of a method for storing linked list data according to an embodiment of the present application.
FIG. 5 is a flow chart of a method for storing linked list data according to an embodiment of the present application.
FIG. 6 is a flow chart of a method for storing linked list data according to an embodiment of the present application.
FIG. 7 is a flow chart of a method for storing linked list data according to an embodiment of the present application.
FIG. 8 is a flow chart of a method for storing linked list data according to an embodiment of the present application.
Detailed Description
The application is described in further detail below with reference to fig. 1 to 8.
The embodiment of the application discloses a linked list type data storage method.
Referring to fig. 1, a linked list data storage method includes the steps of:
s101, storing an information data structure of a storage file; the storage file is established on a file system and is a linked list file; the storage file includes an information data structure and a data structure.
For ease of understanding, the file system is described as follows: the file system of this embodiment is a Norflash linked list file system, where Norflash is a non-volatile memory (NVM) that is typically used to store boot programs and firmware code for embedded systems. Compared with NAND flash memory, norflash has faster access speed and higher reliability, but lower storage density. Norflash is commonly used for low-volume applications such as smart cards, singlechips, and routers.
The Norflash linked list file system is an embedded file system which can be used for Norflash flash. It organizes files and directories in a linked list-like manner and does not require file system scanning on storage media, thus having less memory footprint and fast startup time. The Norflash linked list file system supports dynamic file sizes and file name lengths, and can compress and decompress files. It is generally suitable for storing small application programs such as data of a bootstrap program, a kernel, a configuration file and the like in an embedded system.
The storage file is stored in the Norflash flash memory, and the storage file is a linked list file, which indicates that the data stored in the storage file is linked list data. The linked list file is realized by simulating a linked list on the Norflash flash memory, storing the data of the file according to the node form of the linked list, wherein each node represents a data block in the stored file.
The information data structure refers to basic metadata in the storage file for describing and identifying the storage file, including file name, file size, storage address, checksum, creation time, etc., and the data structure refers to specific data content stored in the storage file, such as text, image, audio, video, etc. In particular, the data structures may be used to solve various computational problems, such as searching, sorting, filtering, and the like. The data structure describes the organization and storage of the data and defines the interfaces and algorithms by which the data operates.
S102, reading file system information of a file system to obtain the latest file information of a storage file; the file information includes a number of sector data.
The file system information refers to basic information of the file system, such as attribute information of storage files and directories in the file system, including file or directory size, authority of the files or directories, time stamp, block pointer, etc., and file information of the latest storage file can be obtained by reading the file system information of the file system, and the file information refers to data stored in the storage file. Specifically, the file information is composed of a plurality of sector data.
S103, storing the data structure of the sector data.
Sector data refers to data stored in a sector and having a certain structure and format, including information such as location, size, and format. In a file system, a sector is the smallest physical unit of a storage medium, and is the actual storage unit of a storage device such as a hard disk, a magnetic disk, or the like, and is used to store sector data. One sector may store data for one or more storage files.
S104, reading the last package of storage data of the sector data according to the file system information.
When the current execution body is started, the file system information is read, and the physical address of the last packet of storage data is obtained, namely the last packet of storage data can be positioned and read through the physical address.
S105, power failure detection is carried out on the last packet of stored data.
The power-down detection of the last packet of stored data refers to the process of detecting the residual electric quantity of the last packet of stored data when the last packet of data is deleted in the storage process of the last packet of stored data. The process determines whether the data stored in the sector has been deleted by detecting whether the data has a last packet remaining. The power failure detection can be used for protecting the integrity of the stored data in the stored data storage process, and effectively preventing the stored data from being lost. If the last packet of data stored in the sector remains, it indicates that the storage process is in progress, and no power down detection is possible.
S106, writing the storage data after the power failure detection is successful.
The successful power-down detection indicates that the stored data is not lost, and the stored data is written after the successful power-down detection.
The implementation principle of the embodiment is as follows: firstly, the information data structure is stored, so that the information is effectively ensured to be correctly stored before the stored data is written, and the probability of error or interruption in the data storage process is effectively reduced; secondly, through carrying out power failure detection on the stored data, the stored data can be conveniently and correctly stored and recovered under the condition of power failure, so that the probability of data loss is effectively reduced; the storage data is written in, so that the data can be conveniently ensured to be stored, and the probability of data loss caused by errors or interruption in the data writing process is effectively reduced.
A detailed description will be given by way of fig. 2 based on one of the implementations of the embodiment shown in fig. 1.
Referring to fig. 2, storing an information data structure of a storage file includes the steps of:
s201, storing physical addresses of all data structures in a storage file; the physical address is used to locate the data structure.
The physical address of a data structure refers to the storage location of the stored data on a sector, i.e., the physical size and location of the data itself. The physical address of the data structure is known, i.e. the data structure can be retrieved based on the physical address, i.e. the localization data structure.
S202, checking each data structure based on a checking algorithm to obtain a checking value of each data structure.
In this embodiment, the check algorithm is a CRC check algorithm. Specifically, the CRC check algorithm is an algorithm for generating polynomial check, which determines whether there is an error by calculating an exclusive-or relationship between two input parameters, so as to ensure the integrity and reliability of an information data structure in a file system during a read-write process. And after the data structures are verified according to the verification algorithm, the verification value of each data structure can be obtained.
S203, storing all the check values and the physical addresses corresponding to the check values in the information data structure, and storing the information data structure.
The information data structure includes a check value and a physical address to which the check value corresponds.
According to the linked list data storage method provided by the embodiment, the information data structure of the storage file is stored, firstly, the check values and the physical addresses corresponding to the check values are stored in the information data structure, and finally, the information data structure is stored, so that the stored data can be checked through the check values, and the stored data can be positioned through the physical addresses corresponding to the check values.
A detailed description will be given by way of fig. 3 based on one of the implementations of the embodiment shown in fig. 1.
Referring to fig. 3, the data structure includes a number of sectors;
reading file system information of a file system to obtain the latest file information of a stored file, comprising the following steps:
s301, reading a starting sector in a data structure; the starting sector includes a first sector and a second sector.
In this embodiment, the start sector includes two sectors, i.e., a first sector and a second sector, i.e., the start sector for reading file information in file system information.
S302, respectively performing data verification on sector data stored in the first sector and the second sector.
In this embodiment, the data of the sectors stored in the first sector and the second sector are respectively checked by a CRC check algorithm, where a condition for passing the check is that the calculated check value is identical to the check value stored in the information data structure.
S303, acquiring sector data which passes the verification and is up to date, and taking the sector data as file information.
If the verification is passed, the verification value after the data verification is consistent with the verification value stored in the information data structure, and the latest sector data is acquired at the moment, wherein the sector data is file information.
According to the linked list data storage method provided by the embodiment, only sector data in the first sector and the second sector are subjected to data verification, so that the utilization rate of storage space is effectively improved.
A detailed description will be given by way of fig. 4 based on one of the implementations of the embodiment shown in fig. 1.
Referring to fig. 4, sector data includes a number of data packets;
storing a data structure of sector data, comprising the steps of:
s401, defining a structural body of a data structure, and storing an address, data content, data storage time stamp, an address and check bit of next packet data of previous packet data.
The address of the last packet of data is the address pointing to the previous packet of data, and is used for connecting a plurality of packets of data into a linked list to form a continuous data stream; the data content refers to the data content stored in the current data packet; the data storage time stamp refers to the storage time of the current data packet; the address of the next packet data is the address pointing to the next data packet, and is used for connecting a plurality of data packets into a linked list; the check bits are used to ensure the integrity and correctness of the data storage, and are typically calculated using a CRC check algorithm or the like.
The syntax defining the structure is as follows:
struct struct_name {
member_type1 member_name1;
member_type2 member_name2;
...
member_typeN member_nameN;
};
a structure is a custom data type that can be used to define and organize data. The structure may be made up of members of multiple data types, each member having its own data type and name. By defining the structure, a composite data type can be created that contains multiple members.
A structure is one implementation of a data structure. The structure body can describe the organization mode and the storage mode of the data, and provides a foundation for realizing the data structure. In actual programming, the fabric may be used as a basic building block for a data structure to implement various data structures, such as queues, stacks, linked lists, and the like.
S402, acquiring the latest data packet, and taking the latest data packet as a new data packet and storing the new data packet.
Specifically, the latest data packet is obtained by the address or the storage time stamp of the last packet of data and stored.
S403, updating the address of the last packet of data and the address of the next packet of data in the data structure.
The steps of updating the address of the last packet of data and the address of the next packet of data in the data structure are two, as follows:
1. and (3) rewriting: and taking the address of the previous packet of data as the address of the next packet of data, and modifying the parameter value of the next packet of data to ensure that the new parameter value is consistent with the parameter value of the previous packet of data.
2. Insertion: and inserting new data into the previous packet of data to ensure that the new parameter value is consistent with the parameter value of the previous packet of data.
S404, checking the new data packet, generating check bits, and storing the check bits in the new data packet.
And checking the new data packet through CRC, generating check bits, and storing the check bits in the new data packet.
S405, storing a data structure storing a plurality of new data packets.
The data structure storing a plurality of new data packets is stored as required, and can be stored in a file or database mode.
According to the linked list type data storage method provided by the embodiment, the new data packet is checked, and check bits are generated and used for guaranteeing the integrity and correctness of sector data, and the address of the previous packet of data and the address of the next packet of data are used for connecting a plurality of data packets into a linked list, so that the data structure is a chain type combination, and the operations such as adding, deleting and modifying of the data are facilitated.
A detailed description will be given by way of fig. 5 based on one of the implementations of the embodiment shown in fig. 1.
Referring to fig. 5, the power-down detection of the last packet of stored data includes the following steps:
s501, determining the data position and the data address of the data stored in the last packet.
The data position and the data address of the last packet of storage data can be obtained through the file system information.
S502, reading the last packet of storage data according to the data address, and taking the last packet of storage data as a last data packet.
Specifically, after the last packet of stored data is read, the stored data is restored to the form of a structure.
S503, checking the last data packet.
The data packet is verified using a hash function or other verification algorithm.
S504, if the verification is successful, continuing to read the data of the last data packet.
S505, if verification fails, the data of the storage area where the last data packet is located is emptied.
If the verification is successful, continuing to read the data of the last data packet; otherwise, the data in the storage area where the last data packet is located is emptied and recorded again.
According to the linked list type data storage method provided by the embodiment, the power-down detection of the last packet of storage data is convenient for reducing the probability of data loss caused by accidental power-down of the last packet of storage data in the sector data, and the power-down detection is convenient for determining the physical address of the last packet of storage data, so that the integrity of the last packet of storage data in the sector data is effectively ensured.
A detailed description will be given by way of fig. 6 based on one of the implementations of the embodiment shown in fig. 1.
Referring to fig. 6, writing stored data after successful power down detection includes the steps of:
s601, after the power failure detection is successful, calculating the start address of the next packet of data according to the stored data.
After the power failure detection is successful, when a new data packet is to be stored in the file system, the current execution body analyzes the size of the current data packet according to the storage structure of the Norflash memory and the 4K storage space, and then calculates the starting address of the next data packet.
S602, if the initial address is the first address of a sector, all data of the sector are emptied.
S603, if the initial address is not the head address of the sector, writing the storage data.
When writing operation is performed, the file system first determines whether the start address is the first address of the sector where the start address is located. If the initial address is the first address of the sector, all the contents of the sector are emptied, and then the data is written. The purpose of this is to prevent overwriting of data previously stored in the sector when writing data, ensuring that the writing of current data does not interfere with the storage of other data. If the initial address is not the initial address of the sector, the storage data is written.
According to the linked list data storage method provided by the embodiment, after the power failure detection is successful, the starting address of the next packet of data is calculated according to the stored data, so that the probability of data loss or accidental deletion is reduced.
A detailed description will be given by way of fig. 7 based on one of the implementations of the embodiment shown in fig. 1.
Referring to fig. 7, after writing the stored data, the method includes the steps of:
s701, the addresses of the stored data and the next packet data are recorded.
After the addresses of the stored data and the next packet data are acquired, the addresses of the stored data and the next packet data are recorded and stored.
S702, reading the stored data and checking the stored data.
In this embodiment, the stored data is checked by a CRC check algorithm or the like.
S703, if the verification is successful, the writing step is skipped.
S704, if verification fails, the stored data is written again.
If the verification passes, the stored data is indicated to be correctly stored in the flash memory, and the program can be jumped out to continue to execute other tasks. If the verification is not passed, the data is attempted to be rewritten and the verification is performed again until the verification is passed.
According to the linked list data storage method provided by the embodiment, after the stored data is written, the stored data is verified, so that the accuracy of the stored data can be conveniently determined; meanwhile, when verification fails, the stored data is written again, so that the probability of loss of the stored data is effectively reduced.
A detailed description will be given by way of fig. 8 based on one of the implementations of the embodiment shown in fig. 1.
Referring to fig. 8, after writing the stored data after the power-down detection is successful, the steps of:
s801, when the stored data is read, calculating a start time stamp and an end time stamp of the read stored data according to a preset data time range of the stored data.
And according to a preset data time range of the stored data, calculating a start time stamp and an end time stamp of the read stored data. Specifically, the start time stamp and the end time stamp of the read storage data can be calculated according to a preset instruction, namely, the time range of the known data and the time stamp of the last data end can be calculated to obtain the start time stamp and the end time stamp of the storage data.
S802, reading the head addresses of all the sectors, and acquiring a target sector closest to the starting time address of the data time range according to an approximation algorithm.
The head addresses of all sectors are read in the file system information. The approximation algorithm is used for approximating the data, and in this embodiment, the approximation algorithm is used for acquiring an address closest to the start time stamp, and after acquiring the start time address closest to the data time range, the target sector of the start time address can be acquired.
S803, acquiring a first address of the stored data in the target sector.
In this example, the first address of the stored data is obtained in the target sector by a binary search method, where the binary search method is used to obtain the first address of the stored data corresponding to the start time stamp to be read. Specifically, the binary search method is an approximation algorithm that uses two different algorithms to traverse a data set, as follows: 1. traversing the preamble: the element closest to the to-be-evaluated value is found in the data set and traversed from the root node to the other nodes. 2. And (5) performing subsequent traversal: the element that is least similar to the element to be evaluated is looked up after the root node and traversed from the root node to the other nodes.
S804, reading the storage data according to the first address and the data time range of the storage data, and checking the storage data.
Knowing the head address of the stored data and the time frame of the stored data, the stored data can be located and read. The stored data is checked by a CRC check algorithm or the like.
S805, if the verification fails, the stored data is read again.
And S806, if the verification is successful, continuing to read the next data of the target sector until all the data which accord with the data time range are read.
If the verification fails, the data is read again; if the verification is successful, the next data is continuously read until all the data conforming to the time range are read.
Under the condition that the data volume is relatively large, the next data can be directly read after the verification is successful, so that the data reading efficiency can be greatly improved, frequent reading operation in flash can be effectively avoided, and the time and the resource cost are saved. If the verification fails, the reading operation needs to be carried out again, and the accuracy and the reliability of data reading are ensured.
According to the linked list type data storage method provided by the embodiment, after the stored data is written after the power failure detection is successful, the starting time stamp and the ending time stamp of the read stored data are calculated, so that the data range of the stored data to be read can be conveniently determined; secondly, reading the first addresses of all the sectors storing data, and obtaining a target sector of the initial time address through an approximation algorithm; and finally, acquiring the first address of the stored data by using a binary search method, and acquiring the first address of the stored data by using an approximation algorithm, wherein the first address of the sector of the stored data is only required to be searched, and the initial address of the whole data structure is not required to be found, so that the storage space of the stored data can be reduced by more than half, and the space utilization rate is effectively improved.
The embodiment of the application also discloses an intelligent terminal which comprises a memory, a processor and a computer program which is stored in the memory and can run on the processor, wherein the linked list type data storage method in the embodiment is adopted when the processor executes the computer program.
The intelligent terminal may adopt a computer device such as a desktop computer, a notebook computer or a cloud server, and the intelligent terminal includes, but is not limited to, a processor and a memory, for example, the intelligent terminal may further include an input/output device, a network access device, a bus, and the like.
The processor may be a Central Processing Unit (CPU), or of course, according to actual use, other general purpose processors, digital Signal Processors (DSP), application Specific Integrated Circuits (ASIC), ready-made programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., and the general purpose processor may be a microprocessor or any conventional processor, etc., which is not limited in this respect.
The memory may be an internal storage unit of the intelligent terminal, for example, a hard disk or a memory of the intelligent terminal, or an external storage device of the intelligent terminal, for example, a plug-in hard disk, a Smart Memory Card (SMC), a secure digital card (SD) or a flash memory card (FC) provided on the intelligent terminal, or the like, and may be a combination of the internal storage unit of the intelligent terminal and the external storage device, where the memory is used to store a computer program and other programs and data required by the intelligent terminal, and the memory may be used to temporarily store data that has been output or is to be output, which is not limited by the present application.
The linked list data storage method in the embodiment is stored in the memory of the intelligent terminal through the intelligent terminal, and is loaded and executed on the processor of the intelligent terminal, so that the linked list data storage method is convenient to use.
The embodiment of the application also discloses a computer readable storage medium, and the computer readable storage medium stores a computer program, wherein the linked list data storage method in the embodiment is adopted when the computer program is executed by a processor.
The computer program may be stored in a computer readable medium, where the computer program includes computer program code, where the computer program code may be in a source code form, an object code form, an executable file form, or some middleware form, etc., and the computer readable medium includes any entity or device capable of carrying the computer program code, a recording medium, a usb disk, a removable hard disk, a magnetic disk, an optical disk, a computer memory, a read-only memory (ROM), a Random Access Memory (RAM), an electrical carrier signal, a telecommunication signal, a software distribution medium, etc., where the computer readable medium includes, but is not limited to, the above components.
The linked list data storage method in the above embodiment is stored in the computer readable storage medium through the computer readable storage medium, and is loaded and executed on a processor, so as to facilitate the storage and application of the method.
The above embodiments are not intended to limit the scope of the present application, so: all equivalent changes in structure, shape and principle of the application should be covered in the scope of protection of the application.

Claims (10)

1. A linked list data storage method, comprising:
storing an information data structure of the storage file; the storage file is established on a file system and is a linked list file; the storage file comprises an information data structure and a data structure;
reading file system information of the file system to obtain the latest file information of the stored file; the file information comprises a plurality of sector data;
storing the data structure of the sector data;
reading the last package of storage data of the sector data according to the file system information;
carrying out power failure detection on the last packet of stored data;
and writing the stored data after the power failure detection is successful.
2. The method for storing linked list data according to claim 1, wherein storing the information data structure of the storage file comprises:
storing physical addresses of all data structures in the storage file; the physical address is used for locating the data structure;
checking each data structure based on a checking algorithm to obtain a checking value of each data structure;
storing all the check values and the physical addresses corresponding to each check value in the information data structure, and storing the information data structure.
3. A linked list data storage method as in claim 1 wherein said data structure comprises a plurality of sectors;
the reading the file system information of the file system to obtain the latest file information of the stored file includes:
reading a starting sector in the data structure; the starting sector comprises a first sector and a second sector;
respectively carrying out data verification on sector data stored in the first sector and the second sector;
and acquiring sector data which passes the verification and is up to date, and taking the sector data as the file information.
4. A linked list data storage method as in claim 3 wherein said sector data comprises a plurality of data packets;
the storing of the data structure of the sector data includes:
defining a structural body of a data structure, wherein the structural body is used for storing the address, the data content, the data storage time stamp, the address and the check bit of the next packet of data;
acquiring the latest data packet, and taking the latest data packet as a new data packet and storing the new data packet;
updating the address of the last packet of data and the address of the next packet of data in the data structure;
checking the new data packet, generating check bits, and storing the check bits in the new data packet;
and storing the data structure storing a plurality of new data packets.
5. The method of claim 1, wherein the power-down detection of the last packet of the stored data comprises:
determining a data position and a data address of the last packet of stored data;
reading the last packet of storage data according to the data address, and taking the last packet of storage data as a last data packet;
checking the last data packet;
if the verification is successful, continuing to read the data of the last data packet;
and if the verification fails, clearing the data of the storage area where the last data packet is located.
6. The method of claim 1, wherein writing the stored data after the power-down detection is successful comprises:
after the power failure detection is successful, calculating the starting address of the next packet of data according to the stored data;
if the starting address is the first address of a sector, all data of the sector are emptied;
and if the starting address is not the head address of the sector, writing the storage data.
7. The method of claim 6, wherein after said writing said stored data, comprising:
recording addresses of the stored data and the next packet of data;
reading the stored data and checking the stored data;
if the verification is successful, skipping the writing step;
and if the verification fails, re-writing the stored data.
8. A linked list data storage method as defined in claim 3, wherein after said writing said stored data after successful power down detection, comprising:
when the stored data is read, calculating a starting time stamp and an ending time stamp for reading the stored data according to a preset data time range of the stored data;
reading the head addresses of all the sectors, and acquiring a target sector closest to the starting time address of the data time range according to an approximation algorithm;
acquiring a first address of the stored data in the target sector;
reading the stored data according to the head address of the stored data and the data time range, and checking the stored data;
if the verification fails, the stored data is read again;
if the verification is successful, continuing to read the next data of the target sector until all the data which accords with the data time range are read.
9. A smart terminal comprising a memory, a processor and a computer program stored in the memory and capable of running on the processor, characterized in that the method according to any one of claims 1 to 8 is used when the computer program is loaded and executed by the processor.
10. A computer readable storage medium having a computer program stored therein, characterized in that the method according to any of claims 1 to 8 is employed when the computer program is loaded and executed by a processor.
CN202310814836.4A 2023-07-04 2023-07-04 Linked list type data storage method, intelligent terminal and storage medium Pending CN116775379A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310814836.4A CN116775379A (en) 2023-07-04 2023-07-04 Linked list type data storage method, intelligent terminal and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310814836.4A CN116775379A (en) 2023-07-04 2023-07-04 Linked list type data storage method, intelligent terminal and storage medium

Publications (1)

Publication Number Publication Date
CN116775379A true CN116775379A (en) 2023-09-19

Family

ID=87989400

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310814836.4A Pending CN116775379A (en) 2023-07-04 2023-07-04 Linked list type data storage method, intelligent terminal and storage medium

Country Status (1)

Country Link
CN (1) CN116775379A (en)

Similar Documents

Publication Publication Date Title
CN112328435B (en) Method, device, equipment and storage medium for backing up and recovering target data
US6606628B1 (en) File system for nonvolatile memory
US8549271B1 (en) Method, system, and computer readable medium for updating and utilizing the contents of a non-essential region of a memory device
CN110765076B (en) Data storage method, device, electronic equipment and storage medium
CN107203331B (en) Method and device for writing data
CN109976669B (en) Edge storage method, device and storage medium
US8219739B2 (en) Read-only optimized flash file system architecture
WO2019041891A1 (en) Method and device for generating upgrade package
CN111177143A (en) Key value data storage method and device, storage medium and electronic equipment
CN108664482B (en) FLASH memory and storage file management method
US7895164B1 (en) Efficient checkpoint process
CN108694049B (en) Method and equipment for updating software
CN112346771B (en) Upgrade file generation method and device
KR101676175B1 (en) Apparatus and method for memory storage to protect data-loss after power loss
CN116775379A (en) Linked list type data storage method, intelligent terminal and storage medium
CN114327292B (en) File management method, system, electronic device and storage medium
US11294592B2 (en) Method and device for data processing, and computer device
CN115328851A (en) Data protection method, device, equipment and medium
CN110874285B (en) Method for realizing reducible write operation of EXT file system
CN114489481A (en) Method and system for storing and accessing data in hard disk
US11640390B2 (en) Bulk file verification
KR102360879B1 (en) Methods and apparatuses for cacheline conscious extendible hashing
CN116541210B (en) Backup method and system for source file
CN113703671B (en) Data block erasing method and related device
EP2212812A2 (en) Multi-way checkpoints in a data storage system

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