Method for determining storage partition of storage unit, storage medium and electronic device

CN116339628BActive Publication Date: 2026-08-18WEICHAI POWER CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310275330.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-16
Publication Date
2026-08-18
Estimated Expiration
2043-03-16

AI Technical Summary

Technical Problem

[0004]本申请的主要目的在于提供一种存储单元的存储分区的确定方法、存储单元的存储分区的确定装置、存储介质和电子设备,以至少解决现有技术中存储介质的擦写频繁、效率较低且影响存储介质的寿命的问题

Benefits of technology

[0015]Applying the technical solution of this application, the method for determining the storage partition of the storage unit in this application first obtains multiple storage partitions, each storage partition including multiple data units, and each data unit storing multiple fields, including a usage field, a valid field, a data name field, a data length field, a data content field, and a data verification field; then, each storage partition is detected to obtain multiple detection results, which correspond one-to-one with the storage partitions. The multiple detection results include the number of valid units, the number of invalid units, and the number of blank units in the storage partition. The number of valid units is the number of valid data units stored in the storage partition, the number of invalid units is the number of invalid data units stored in the storage partition, and the number of blank units is the number of data units without stored data in the storage partition; finally, based on at least one of the following: the number of valid units, the number of invalid units, and the number of blank units in each storage partition, a target partition and a non-target partition are determined. The target partition is the storage partition with the most valid units or the most blank units. The target partition is used for reading and writing data, and the non-target partition is used to continue writing data when the target partition is full. This method determines the target partition and the non-target partition, so that when one storage partition is full, the other partition is used to complete the partition switch. This avoids frequent erasure and writing of the storage medium and solves the problems of frequent erasure and writing, low efficiency and reduced lifespan of the storage medium in the prior art.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116339628B_ABST
    Figure CN116339628B_ABST
Patent Text Reader

Abstract

The application provides a method for determining storage partitions of a storage unit, a storage medium and an electronic device. The method comprises the following steps: obtaining a plurality of storage partitions, each of the storage partitions comprising a plurality of data units, and each of the data units storing a plurality of fields; detecting each of the storage partitions to obtain a plurality of detection results, the detection results corresponding to the storage partitions one by one, and the plurality of detection results comprising a number of valid units of the storage partitions, a number of invalid units of the storage partitions and a number of blank units of the storage partitions; and determining a target partition and a non-target partition according to at least one of the number of valid units of each of the storage partitions, the number of invalid units of each of the storage partitions and the number of blank units of each of the storage partitions. The application determines the target partition and the non-target partition, so that the partition switching is completed by means of another partition when one storage partition is full, and the problem of frequent erasing and writing, low efficiency and influence on the service life of the storage medium in the prior art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data reading and writing, and more specifically, to a method for determining the storage partition of a storage unit, a device for determining the storage partition of a storage unit, a storage medium, and an electronic device. Background Technology

[0002] When reading and writing data on storage media (such as FLASH and EEPROM), unexpected interruptions (such as power failures) may occur. Without protective measures, this can easily lead to data corruption (loss or modification) in the storage area. If this area originally stored important system data, the corruption of that data could have catastrophic consequences for the entire system.

[0003] Existing technologies for improving the reliability of data read / write operations on storage media typically involve providing a data backup area. Old or new data is first written to the backup area, and then the backup data is deleted only after ensuring the correctness of the data exchange. However, this not only requires complex control methods but also leads to frequent erasure and rewriting of the storage media, resulting in low efficiency and a shortened lifespan. Summary of the Invention

[0004] The main objective of this application is to provide a method for determining the storage partition of a storage unit, a device for determining the storage partition of a storage unit, a storage medium, and an electronic device, so as to at least solve the problems of frequent erasure and writing of storage media, low efficiency, and impact on the lifespan of storage media in the prior art.

[0005] To achieve the above objectives, according to one aspect of this application, a method for determining storage partitions of a storage unit is provided, comprising: acquiring multiple storage partitions, each storage partition including multiple data units, each data unit storing multiple fields, the multiple fields including a usage field, a valid field, a data name field, a data length field, a data content field, and a data validation field; detecting each storage partition to obtain multiple detection results, the detection results corresponding one-to-one with the storage partitions, the multiple detection results including the number of valid units in the storage partition, the number of invalid units in the storage partition, and the number of blank units in the storage partition, wherein the number of valid units is the storage partition's number of valid units. The number of valid data units stored in the storage partition, the number of invalid data units being the number of invalid data units stored in the storage partition, and the number of blank data units being the number of data units in the storage partition without stored data; a target partition and a non-target partition are determined based on at least one of the following: the number of valid data units in each storage partition, the number of invalid data units in each storage partition, and the number of blank data units in each storage partition, wherein the target partition is the storage partition with the most valid data units or the most blank data units, the target partition is used for reading and writing data, and the non-target partition is used to continue writing data when the target partition is full.

[0006] Optionally, determining target partitions and non-target partitions based on at least one of the following: the number of valid units in each storage partition, the number of invalid units in each storage partition, and the number of blank units in each storage partition includes: determining the storage partition with the most valid units as the target partition when at least two storage partitions have different numbers of valid units; determining the storage partition with the fewest invalid units as the target partition when any two storage partitions have the same number of valid units; and determining the storage partition with the most blank units as the target partition when any two storage partitions have the same number of valid units and the number of invalid units in any two storage partitions are also the same.

[0007] Optionally, each of the storage partitions is tested to obtain multiple test results, each test result corresponding to a storage partition. This includes: sequentially testing multiple data units in the storage partition according to a preset order, and sequentially performing usage field testing, valid field testing, data length field testing, and data validation field testing on each data unit to obtain an initial test result. The initial test result includes whether the data unit is a valid unit, an invalid unit, or a blank unit. Based on the multiple initial test results, the number of valid units, the number of invalid units, and the number of blank units in the storage partition are determined to obtain the test result.

[0008] Optionally, for each of the data units, the following steps are performed sequentially: usage field detection, valid field detection, data length field detection, and data validation field detection to obtain an initial detection result. This includes: if the usage field satisfies a first condition, continuing to perform the valid field detection, data length field detection, and data validation field detection sequentially to obtain the initial detection result, where the first condition indicates that the data unit is not a blank unit; if the usage field does not satisfy the first condition and at least one detected data unit is not a blank unit, determining the data unit as an invalid unit; and if the usage field does not satisfy the first condition and all detected data units are blank units, determining the data unit as a blank unit.

[0009] Optionally, for each of the data units, the following steps are performed sequentially: usage field detection, valid field detection, data length field detection, and data validation field detection to obtain an initial detection result. This includes: if the usage field satisfies a first condition, continuing to perform the valid field detection; and if the valid field satisfies a second condition, continuing to perform the data length field detection and the data validation field detection sequentially to obtain the initial detection result. The second condition indicates that the data unit is a valid unit, and the first condition indicates that the data unit is not a blank unit. If the valid field does not satisfy the second condition, the data unit is determined to be an invalid unit.

[0010] Optionally, for each of the data units, the following steps are performed sequentially: usage field detection, valid field detection, data length field detection, and data validation field detection to obtain an initial detection result. This includes: if the usage field satisfies a first condition and the valid field satisfies a second condition, then the data length field detection is performed; and if the data length field satisfies a third condition, then the data validation field detection is performed to obtain the initial detection result. The third condition is that the data length represented by the data length field is within a preset length range. The first condition indicates that the data unit is not a blank unit, and the second condition indicates that the data unit is a valid unit. If the data length field does not satisfy the third condition, the data unit is determined to be an invalid unit.

[0011] Optionally, for each data unit, the following steps are performed sequentially: usage field detection, valid field detection, data length field detection, and data validation field detection to obtain an initial detection result. This includes: if the usage field satisfies a first condition, the valid field satisfies a second condition, and the data length field satisfies a third condition, then the data validation field detection continues. If the data validation field satisfies a fourth condition, the data unit is determined to be a valid unit. The fourth condition is that the value of the data validation field is a target value and the data written to the data unit is unique. The target value indicates that the data name field, data length field, and data content field are correct. The first condition indicates that the data unit is not a blank unit, the second condition indicates that the data unit is a valid unit, and the third condition is that the data length represented by the data length field is within a preset length range. If the data validation field does not satisfy the fourth condition and not all fields of the data validation field are preset values, the data unit is determined to be an invalid unit. If the data validation field does not satisfy the fourth condition and all fields of the data validation field are preset values, the value of the data validation field is repaired, and it is determined whether the repaired data validation field satisfies the fourth condition.

[0012] Optionally, the storage partition is two. After determining the target partition and the non-target partition based on at least one of the following: the number of valid units in each storage partition, the number of invalid units in each storage partition, and the number of blank units in each storage partition, the method further includes: when there is target data to be written and the target partition does not have any blank units, copying all valid data in the target partition to the non-target partition and confirming the non-target partition as the current target partition; erasing all content in the target partition and writing the target data into the current target partition.

[0013] According to another aspect of this application, a computer-readable storage medium is provided, the computer-readable storage medium including a stored program, wherein, when the program is executed, it controls the device where the computer-readable storage medium is located to execute any of the storage cell determination methods.

[0014] According to another aspect of this application, an electronic device is provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs including a method for determining a storage partition of any of the aforementioned storage units.

[0015] Applying the technical solution of this application, the method for determining the storage partition of the storage unit in this application first obtains multiple storage partitions, each storage partition including multiple data units, and each data unit storing multiple fields, including a usage field, a valid field, a data name field, a data length field, a data content field, and a data verification field; then, each storage partition is detected to obtain multiple detection results, which correspond one-to-one with the storage partitions. The multiple detection results include the number of valid units, the number of invalid units, and the number of blank units in the storage partition. The number of valid units is the number of valid data units stored in the storage partition, the number of invalid units is the number of invalid data units stored in the storage partition, and the number of blank units is the number of data units without stored data in the storage partition; finally, based on at least one of the following: the number of valid units, the number of invalid units, and the number of blank units in each storage partition, a target partition and a non-target partition are determined. The target partition is the storage partition with the most valid units or the most blank units. The target partition is used for reading and writing data, and the non-target partition is used to continue writing data when the target partition is full. This method determines the target partition and the non-target partition, so that when one storage partition is full, the other partition is used to complete the partition switch. This avoids frequent erasure and writing of the storage medium and solves the problems of frequent erasure and writing, low efficiency and reduced lifespan of the storage medium in the prior art. Attached Figure Description

[0016] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:

[0017] Figure 1 A hardware structure block diagram of a mobile terminal for determining a storage partition of a storage unit according to an embodiment of this application is shown.

[0018] Figure 2 A flowchart illustrating a method for determining the storage partition of a storage unit according to an embodiment of this application is shown.

[0019] Figure 3 A schematic diagram of the structure of a storage partition of a storage unit provided according to an embodiment of this application is shown;

[0020] Figure 4 A flowchart illustrating another method for determining the storage partition of a storage unit according to an embodiment of this application is shown.

[0021] Figure 5 A schematic flowchart of a data writing process according to an embodiment of this application is shown;

[0022] Figure 6 A schematic flowchart of a data reading process according to an embodiment of this application is shown;

[0023] Figure 7 A structural block diagram of a storage partition determination device for a storage cell according to an embodiment of this application is shown. Detailed Implementation

[0024] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.

[0025] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.

[0026] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0027] For ease of description, the following explains some of the nouns or terms used in the embodiments of this application:

[0028] FLASH: A type of non-volatile memory that retains data for extended periods without a power supply. Common non-volatile memory types include NorFlash and NandFlash.

[0029] EEPROM: Electrically Erasable Programmable Read-Only Memory, is a type of memory chip that retains data even when power is off. It can be erased and reprogrammed (rewritten) by applying a voltage higher than normal.

[0030] As described in the background section, existing technologies require complex control methods and result in frequent erasure and writing of the storage medium, leading to low efficiency and affecting the lifespan of the storage medium. To address the problems of frequent erasure and writing, low efficiency, and reduced lifespan of the storage medium in existing technologies, embodiments of this application provide a method for determining the storage partition of a storage unit, a device for determining the storage partition of a storage unit, a storage medium, and an electronic device.

[0031] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.

[0032] The methods and embodiments provided in this application can be executed on a mobile terminal, computer terminal, or similar computing device. Taking running on a mobile terminal as an example, Figure 1 This is a hardware structure block diagram of a mobile terminal for a method of determining the storage partition of a storage unit according to an embodiment of the present invention. Figure 1 As shown, a mobile terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. The mobile terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the mobile terminal described above. For example, the mobile terminal may also include components that are more... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.

[0033] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the device information display method in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory and non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. The transmission device 106 is used to receive or send data via a network. Specific examples of the aforementioned networks may include wireless networks provided by the mobile terminal's communication provider. In one example, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0034] This embodiment provides a method for determining the storage partition of a storage unit running on a mobile terminal, computer terminal, or similar computing device. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0035] Figure 2 This is a flowchart of a method for determining the storage partition of a storage unit according to an embodiment of this application. Figure 2 As shown, the method includes the following steps:

[0036] Step S201: Obtain multiple storage partitions, each of which includes multiple data units, and each of which stores multiple fields, including a usage field, a valid field, a data name field, a data length field, a data content field, and a data validation field.

[0037] Specifically, generally only two storage partitions need to be set up, namely the first storage partition and the second storage partition, and these two storage partitions contain an equal number of data units, such as... Figure 3As shown, the available space on the storage medium is divided into two equal-sized areas. The capacity of one storage space is sufficient to meet data storage needs. In most cases, only one partition (the target partition) will be operated on. Data transfer is only performed when the storage space is exhausted, copying the valid data to the other partition (the non-target partition, also called the spare partition). As shown in the diagram below, each storage partition is divided into small blocks of the same size. Each small block can store one data unit, and each data unit consists of several sub-blocks. Initially, all data units in the storage area are written with 1s. The storage content is managed using a data unit approach, and the settings of various fields ensure the correctness of the read and write processes.

[0038] Among them, such as Figure 3 As shown, the explanations of each field (sub-block) of the data unit are as follows:

[0039] 1) Whether to use the flag (i.e., use field): This occupies 4 bytes. When all bytes are 1, it indicates that no data has been written, meaning the data unit is empty. If data is written, this flag is set to a magic word that can be self-checked, such as 0xA55B5AA5, meaning the high 2 bytes are the complement of the low 2 bytes. When this field has other values, it is considered that an error occurred during writing.

[0040] 2) Validity flag (i.e., valid field): Occupies 4 bytes, all 1s indicate valid data. When data is invalid, this flag is set to a self-checking magic word, such as 0xA55B5AA5, where the high 2 bytes are the complement of the low 2 bytes. Any other value in this field indicates an error occurred during writing.

[0041] 3) Data Name: Fixed length (can be determined according to specific needs). Data is managed in a "key-value pair" manner. This field is the "key" and stores the content as a string. It can be used to determine whether the data already exists when writing data.

[0042] 4) Data length: Occupies 4 bytes and is used to represent the actual length of the data content. If this value exceeds the agreed maximum limit, it is considered that an error has occurred during writing.

[0043] 5) Data Content: Occupies a fixed length (which can be determined according to specific needs). The actual length is obtained from the "Data Length" field. Data is managed in a "key-value pair" manner, and this field is the "value". If the "key" already exists and the "value" is equal when writing data, it will not be written again.

[0044] 6) Data verification: This occupies 2 bytes and is the value obtained by performing a cyclic redundancy check (CRC) on the data name, data length, and data content fields. It is used to verify whether errors occurred when writing these parts of the data.

[0045] Step S202: Detect each of the above-mentioned storage partitions and obtain multiple detection results. The detection results correspond one-to-one with the above-mentioned storage partitions. The multiple detection results include the number of valid units, the number of invalid units, and the number of blank units in the above-mentioned storage partitions. The number of valid units is the number of valid data units stored in the above-mentioned storage partitions. The number of invalid units is the number of invalid data units stored in the above-mentioned storage partitions. The number of blank units is the number of data units in the above-mentioned storage partitions that do not store data.

[0046] Specifically, each time power is supplied, the data in multiple storage partitions is verified. Various measures are taken to check for and even repair various anomalies that occur during the data writing process. The target partition and non-target partitions are determined by statistical results, and the data in the non-target partitions is erased (all data is written to 1).

[0047] The specific implementation steps of step S202 are as follows:

[0048] Step S2021: The multiple data units in the above storage partition are detected sequentially according to a preset order, and the data units are detected sequentially by the field of use, the field of validity, the data length field and the data verification field to obtain an initial detection result. The initial detection result includes the data unit being one of the following: a valid unit, an invalid unit, or a blank unit.

[0049] First, perform field detection by following these steps:

[0050] Step S301: If the above-mentioned field satisfies the first condition, continue to perform the above-mentioned valid field detection, the above-mentioned data length field detection and the above-mentioned data verification field detection in sequence to obtain the above-mentioned initial detection result. The above-mentioned first condition is characterized as the above-mentioned data unit is not the above-mentioned blank unit.

[0051] Step S302: If the above-mentioned usage field does not meet the above-mentioned first condition and at least one of the above-mentioned detected data units is not the above-mentioned blank unit, the above-mentioned data unit is determined to be the above-mentioned invalid unit;

[0052] Step S303: If the above-mentioned usage field does not meet the above-mentioned first condition and all the above-mentioned data units that have been detected are the above-mentioned blank units, then the above-mentioned data unit is determined to be the above-mentioned blank unit.

[0053] Specifically, when all values ​​in a field are 1, the data unit is considered blank. When a field is set to a magic word, the data unit is considered not blank, and the process continues with subsequent fields. If a field is neither all values ​​of 1 nor a magic word, it indicates an error and requires correction by setting the field to a magic word. Furthermore, the field has a self-validation function, meaning it can perform self-validation when an error occurs. This allows for error checking and even repair of various anomalies that may occur during data writing.

[0054] Next, perform valid field checks as follows:

[0055] Step S401: If the above-mentioned field satisfies the first condition, continue to perform the above-mentioned valid field detection, and if the above-mentioned valid field satisfies the second condition, continue to perform the above-mentioned data length field detection and the above-mentioned data verification field detection in sequence to obtain the above-mentioned initial detection result. The above-mentioned second condition indicates that the above-mentioned data unit is the above-mentioned valid unit, and the above-mentioned first condition indicates that the above-mentioned data unit is not the above-mentioned blank unit.

[0056] Step S402: If the above-mentioned valid field does not meet the above-mentioned second condition, the above-mentioned data unit is determined to be the above-mentioned invalid unit.

[0057] Specifically, if all valid fields are 1, the data unit is considered valid. If a valid field is a magic word, the data unit is considered invalid. If neither all valid fields are 1 nor a magic word, the field is considered faulty and needs to be corrected by setting the field to a magic word. Furthermore, the valid fields can perform self-checking, meaning they can be checked and even corrected for various anomalies that may occur during data writing.

[0058] Then, perform data length field checks as follows:

[0059] Step S501: If the above-mentioned used field satisfies the first condition and the above-mentioned valid field satisfies the second condition, the above-mentioned data length field detection is continued, and if the above-mentioned data length field satisfies the third condition, the above-mentioned data verification field detection is continued to obtain the above-mentioned initial detection result. The above-mentioned third condition is that the data length represented by the above-mentioned data length field is within the preset length range. The above-mentioned first condition is characterized by the above-mentioned data unit not being the above-mentioned blank unit, and the above-mentioned second condition is characterized by the above-mentioned data unit being the above-mentioned valid unit.

[0060] Step S502: If the data length field does not meet the third condition, the data unit is determined to be an invalid unit.

[0061] Specifically, since the data length field does not have a self-validation function, the data validation field is used to verify whether an error occurred when the data length field was written. This allows for error checking and even repair of various abnormal situations that may occur in the data length field during the data writing process.

[0062] Finally, perform data validation field checks according to the following steps:

[0063] Step S601: If the above-mentioned usage field satisfies the first condition, the above-mentioned valid field satisfies the second condition, and the above-mentioned data length field satisfies the third condition, the above-mentioned data verification field detection continues, and if the above-mentioned data verification field satisfies the fourth condition, the above-mentioned data unit is determined to be the above-mentioned valid unit. The above-mentioned fourth condition is that the value of the above-mentioned data verification field is the target value and the data written in the above-mentioned data unit is unique. The above-mentioned target value indicates that the above-mentioned data name field, the above-mentioned data length field, and the above-mentioned data content field are correct. The above-mentioned first condition indicates that the above-mentioned data unit is not the above-mentioned blank unit. The above-mentioned second condition indicates that the above-mentioned data unit is the above-mentioned valid unit. The above-mentioned third condition is that the data length represented by the above-mentioned data length field is within the preset length range.

[0064] Step S602: If the above data verification field does not meet the fourth condition and not all field bits of the above data verification field are preset values, the above data unit is determined to be the above invalid unit.

[0065] Step S603: If the above data verification field does not meet the fourth condition and all the field bits of the above data verification field are the above preset values, repair the value of the above data verification field and determine whether the repaired above data verification field meets the fourth condition.

[0066] Specifically, if all values ​​in the data validation field are 1, it indicates that the field is incorrect and needs to be repaired. This is achieved by performing a cyclic redundancy check (CRC) on the data name field, data length field, and data content field to obtain new values, which are then rewritten into the data validation field. In other words, the data validation field cannot be all 1. This allows for error checking and even repair of various anomalies that may occur in the data validation field during the data writing process.

[0067] Step S2022: Based on the multiple initial detection results mentioned above, determine the number of valid cells, the number of invalid cells, and the number of blank cells in the storage partition to obtain the detection results.

[0068] Data corruption typically occurs during the data writing process. To ensure data reliability, data must be checked at the very beginning of power-on. The power-on data check process checks and repairs errors that may occur during normal data writing and during its own (this process's) data writing process. It also uses certain criteria to determine the current storage partition and the backup storage partition to ensure that subsequent read and write processes can proceed normally.

[0069] Step S203: Determine a target partition and a non-target partition based on at least one of the following: the number of valid units in each of the above-mentioned storage partitions, the number of invalid units in each of the above-mentioned storage partitions, and the number of blank units in each of the above-mentioned storage partitions. The target partition is the storage partition with the most valid units or the most blank units. The target partition is used for reading and writing data. The non-target partition is used to continue writing data when the target partition is full.

[0070] Specifically, data reading and writing are accomplished through the cooperation of two storage areas, ensuring data reliability during the reading and writing process. Storage area operations mainly include data reading, data writing, and power-on data checking. Each power-on data checking process identifies the target partition and non-target partitions, and erases the data in the non-target partitions (writing all 1s).

[0071] The specific implementation steps of step S203 are as follows:

[0072] Step S2031: If at least two of the above-mentioned storage partitions have different numbers of valid units, the storage partition with the largest number of valid units shall be determined as the target partition.

[0073] For example: If there are 10 storage partitions, 3 of them have different numbers of valid units, and the other 7 have the same number of valid units, then the storage partition with the most valid units among these 10 storage partitions will be determined as the target partition mentioned above.

[0074] Step S2032: If any two of the above storage partitions have the same number of valid units, the storage partition with the fewest invalid units shall be determined as the target partition.

[0075] For example, if there are 10 storage partitions, all of which have the same number of valid units, but the total number of data units and the number of invalid units are different, then the storage partition with the fewest invalid units among these 10 storage partitions will be determined as the target partition.

[0076] Step S2033: If any two of the above storage partitions have the same number of valid units and any two of the above storage partitions have the same number of invalid units, the storage partition with the most blank units is determined as the target partition.

[0077] For example, if there are 10 storage partitions, and all 10 storage partitions have the same number of valid units and invalid units, but the total number of data units in these 10 storage partitions is different, then the storage partition with the most blank units among these 10 storage partitions will be determined as the target partition mentioned above.

[0078] Specifically, the number of data units in multiple storage partitions may be the same or different. If the number of data units in multiple storage partitions is the same, it is only necessary to proceed to step S2032, and there is no need to proceed to step S2033. However, if the number of data units in multiple storage partitions is different, then step S2033 is performed. This ensures that the target partition has the maximum number of readable valid units and the maximum number of blank units in the target partition that can be written to.

[0079] Wherein, there are two storage partitions. After determining the target partition and the non-target partition based on at least one of the following: the number of valid units in each of the storage partitions, the number of invalid units in each of the storage partitions, and the number of blank units in each of the storage partitions, the method further includes: when there is target data to be written and the target partition does not have the aforementioned blank units, copying all valid data in the target partition to the non-target partition and confirming the non-target partition as the current target partition; erasing all contents in the target partition and writing the target data into the current target partition.

[0080] Data is written sequentially to the empty cells of the current partition. Only when the storage partition is full will a partition switch be completed using a spare partition, thus avoiding frequent erasure and rewriting of the storage medium. (If duplicate data names exist, the original data will be invalidated).

[0081] The method for determining the storage partitions of the aforementioned storage unit in this application first obtains multiple storage partitions, each including multiple data units, and each data unit stores multiple fields, including a usage field, a valid field, a data name field, a data length field, a data content field, and a data verification field. Then, each storage partition is tested to obtain multiple test results, each corresponding one-to-one with a storage partition. These test results include the number of valid units, the number of invalid units, and the number of blank units in the storage partition. The number of valid units is the number of valid data units stored in the storage partition, the number of invalid data units is the number of invalid data units stored in the storage partition, and the number of blank units is the number of data units without stored data in the storage partition. Finally, based on at least one of the following: the number of valid units, the number of invalid units, and the number of blank units in each storage partition, a target partition and a non-target partition are determined. The target partition is the storage partition with the most valid units or the most blank units. The target partition is used for reading and writing data, and the non-target partition is used to continue writing the aforementioned data when the target partition is full. This method determines the target partition and the non-target partition, so that when one storage partition is full, the other partition is used to complete the partition switch. This avoids frequent erasure and writing of the storage medium and solves the problems of frequent erasure and writing, low efficiency and reduced lifespan of the storage medium in the prior art.

[0082] To enable those skilled in the art to better understand the technical solution of this application, the implementation process of the method for determining the storage partition of the storage unit of this application will be described in detail below with reference to specific embodiments.

[0083] This embodiment relates to a method for determining the storage partition of a specific storage unit, such as... Figure 4 As shown, there are two storage partitions, and the method includes:

[0084] Step S1: First, perform a power-on data check. Then, starting from the last data unit of each storage partition, traverse the two partitions sequentially. Next, check if all flags of the used fields are 1. If all flags of the used fields are 1, determine if there are any non-empty data units among the detected data units. If there are non-empty data units among the detected data units, it proves that the data unit is faulty, and the unit is marked as used and invalid, and the number of invalid units in the storage partition is incremented by 1. If there are no non-empty data units among the detected data units, determine that the data unit is a blank unit, and the number of blank units in the storage partition is incremented by 1. Then, confirm whether the data unit is the last data unit detected. If it is, determine the target partition and non-target partition by the number of valid units, invalid units, and blank units. If not, continue to analyze the next data unit.

[0085] Step S2: If the field being used is not all 1, determine if the field being used is a flag magic word. If not, it means the field being used is incorrect and needs to be fixed by setting the field being used to a flag magic word. If it is, perform a valid field check.

[0086] Step S3: Determine if all valid fields are 1. If not all valid fields are 1, determine if the valid field is a flag magic word. If not, the valid field is faulty and needs to be repaired by resetting the valid field to the flag magic word. If the valid field is a flag magic word, the data unit is determined to be invalid, and the number of invalid units in the storage partition is incremented by 1. Then, confirm if the data unit is the last data unit detected. If yes, determine the target partition and non-target partition by the number of valid units, invalid units, and blank units. If not, continue analyzing the next data unit.

[0087] Step S4: If all valid field flags are 1, determine whether the data length field exceeds the preset length range. If it does, determine that the data length field is incorrect, set the data unit to invalid, increment the number of invalid units in the storage partition by 1, and confirm whether the data unit is the last data unit detected. If so, determine the target partition and non-target partition by the number of valid units, invalid units, and blank units. If not, continue to analyze the next data unit.

[0088] Step S5: If the data length field does not exceed the preset length range, determine if the data verification field is all 1. If the data verification field is all 1, it is determined that the data verification field is faulty, and it is repaired. The recalculated verification value is written, the number of valid units in the storage partition where the unit is located is incremented by 1, and it is confirmed whether the data unit is the last data unit detected. If so, the target partition and non-target partition are determined by the number of valid units, invalid units, and blank units. If not, continue to analyze the next data unit.

[0089] Step S6: If not all data verification fields are 1, determine if the verification value indicates an error in the data unit. If yes, mark the data unit as invalid and increment the invalid unit count of the storage partition. If no, determine if the data unit is a duplicate, i.e., compare the data name and data content fields of the data unit with those of previously detected data units. If it is a duplicate, mark the data unit as invalid and increment the invalid unit count of the storage partition. If it is not a duplicate, pass the verification, increment the valid unit count of the storage partition, and confirm if the data unit was the last detected data unit. If yes, use the number of valid units, invalid units, and blank units to determine whether it is a target partition or a non-target partition. If not, continue analyzing the next data unit.

[0090] After determining the target partition, erase all data in the non-target partition, i.e., write all 1s.

[0091] In one optional embodiment, after the power-on data check process is completed, a data writing process is also included, such as... Figure 5 As shown, the data writing process includes: determining the target partition; checking if there is a cell with the same name whose data content matches the data to be written; if so, no data writing is performed; if not, checking if the target partition has blank cells; if blank cells exist, filling each part of the blank cells sequentially according to the data to be written; after filling, checking again for cells with the same name; if so, invalidating the cell; otherwise, ending the process; if no blank cells exist, switching storage areas, copying all valid data from the target partition to a non-target partition, confirming the non-target partition as the current target partition, erasing the content of the original target partition (writing all values ​​to 1), locating the blank cells in the current target partition, and then filling each part of the blank cells sequentially according to the data to be written, before proceeding with the subsequent process. Data is written sequentially to the blank cells of the current partition. Partition switching is only performed when the storage partition is full, thus avoiding frequent erasure and rewriting of the storage medium. (If duplicate data names exist, the original data can be invalidated.)

[0092] As an optional solution, a data reading process is also included, such as... Figure 6 As shown, the target partition is first determined, then a data unit is read, and it is determined whether the data unit is used. If it is not used, the process ends. If it is used, the validity of the data unit is checked. If it is valid, the data name is checked to see if it matches the data name to be read. If they match, the data content is read according to the data length. If the data unit is invalid, another data unit is read downwards. If the data name does not match the data name to be read, another data unit is read downwards as well.

[0093] The system reads data units from the storage area in a loop. Since the data is written sequentially, when it is determined that the current data unit is not used (blank unit), the loop is exited directly (subsequent data units are all blank units).

[0094] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.

[0095] This application also provides a device for determining the storage partition of a storage unit. It should be noted that the device for determining the storage partition of a storage unit in this application can be used to execute the method for determining the storage partition of a storage unit provided in this application. This device is used to implement the above embodiments and preferred embodiments, and details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.

[0096] The following describes the device for determining the storage partition of the storage unit provided in the embodiments of this application.

[0097] Figure 7 This is a schematic diagram of a device for determining the storage partition of a storage unit according to an embodiment of this application. Figure 7 As shown, the device includes an acquisition unit 10, a detection unit 20, and a determination unit 30. The acquisition unit 10 is used to acquire multiple storage partitions, each of which includes multiple data units. Each data unit stores multiple fields, including a usage field, a valid field, a data name field, a data length field, a data content field, and a data validation field. The detection unit 20 is used to detect each of the storage partitions and obtain multiple detection results. Each detection result corresponds one-to-one with the storage partition. The multiple detection results include the number of valid units in the storage partition, the number of invalid units in the storage partition, and the number of blank units in the storage partition. The number of valid units is the number of units stored in the storage partition. The number of valid data units stored in the storage partition, the number of invalid data units being the number of invalid data units stored in the storage partition, and the number of blank data units being the number of data units in the storage partition without stored data; the determining unit 30 is used to determine a target partition and a non-target partition based on at least one of the following: the number of valid data units in each of the storage partitions, the number of invalid data units in each of the storage partitions, and the number of blank data units in each of the storage partitions, wherein the target partition is the storage partition with the most valid data units or the most blank data units, the target partition is used for reading and writing data, and the non-target partition is used to continue writing data when the target partition is full.

[0098] For example, the determining unit includes a first determining subunit, a second determining subunit, and a third determining subunit. The first determining subunit is used to determine the storage partition with the most valid units as the target partition when at least two of the aforementioned storage partitions have different numbers of valid units. The second determining subunit is used to determine the storage partition with the fewest invalid units as the target partition when any two of the aforementioned storage partitions have the same number of valid units. The third determining subunit is used to determine the storage partition with the most blank units as the target partition when any two of the aforementioned storage partitions have the same number of valid units and any two of the aforementioned storage partitions have the same number of invalid units. This ensures that the target partition has the maximum number of readable valid units and the maximum number of blank units that can be written to.

[0099] As an optional solution, the detection unit includes a detection module and a determination module. The detection module is used to sequentially detect multiple data units in the aforementioned storage partition according to a preset order, and for each data unit, it sequentially performs usage field detection, valid field detection, data length field detection, and data validation field detection to obtain an initial detection result. The initial detection result includes whether the data unit is a valid unit, an invalid unit, or a blank unit. The determination module is used to determine the number of valid units, the number of invalid units, and the number of blank units in the aforementioned storage partition based on the multiple initial detection results, thereby obtaining the aforementioned detection result. This ensures that subsequent read and write processes can proceed normally.

[0100] In an optional instance, the detection module includes a first detection submodule, a first determination submodule, and a second determination submodule. The first detection submodule is used to continue performing the above-mentioned valid field detection, data length field detection, and data validation field detection sequentially when the above-mentioned usage field meets the first condition, to obtain the above-mentioned initial detection result. The above-mentioned first condition is characterized as the above-mentioned data unit not being the above-mentioned blank unit. The first determination submodule is used to determine the above-mentioned data unit as the above-mentioned invalid unit when the above-mentioned usage field does not meet the above-mentioned first condition and at least one of the above-mentioned detected data units is not the above-mentioned blank unit. The second determination submodule is used to determine the above-mentioned data unit as the above-mentioned blank unit when the above-mentioned usage field does not meet the above-mentioned first condition and all of the above-mentioned detected data units are the above-mentioned blank units. This allows for error checking and even repair of various abnormal situations that occur in the usage field during the data writing process.

[0101] As an optional solution, the detection module includes a second detection submodule and a third determination submodule. The second detection submodule is used to continue the above valid field detection if the above-mentioned usage field meets the first condition, and if the above-mentioned valid field meets the second condition, it continues to perform the above-mentioned data length field detection and the above-mentioned data verification field detection in sequence to obtain the above-mentioned initial detection result. The above-mentioned second condition indicates that the above-mentioned data unit is the above-mentioned valid unit, and the above-mentioned first condition indicates that the above-mentioned data unit is not the above-mentioned blank unit. The third determination submodule is used to determine the above-mentioned data unit as the above-mentioned invalid unit if the above-mentioned valid field does not meet the above-mentioned second condition. In this way, various abnormal situations that occur in the valid fields during the data writing process can be checked for errors and even repaired.

[0102] For example, the detection module includes a third detection submodule and a fourth determination submodule. The third detection submodule is used to continue the data length field detection if the used field meets the first condition and the valid field meets the second condition, and to continue the data verification field detection if the data length field meets the third condition, thus obtaining the initial detection result. The third condition is that the data length represented by the data length field is within a preset length range, the first condition is that the data unit is not a blank unit, and the second condition is that the data unit is a valid unit. The fourth determination submodule is used to determine that the data unit is an invalid unit if the data length field does not meet the third condition. This allows for error checking and even repair of various anomalies in the data length field during the data writing process.

[0103] In an optional embodiment, the detection module includes a fourth detection submodule, a fifth determination subunit, and a sixth determination subunit. The fourth detection submodule is used to continue detecting the data verification field when the usage field satisfies the first condition, the valid field satisfies the second condition, and the data length field satisfies the third condition. Furthermore, when the data verification field satisfies the fourth condition, the data unit is determined to be a valid unit. The fourth condition is that the value of the data verification field is a target value and the data written to the data unit is unique. The target value indicates that the data name field, the data length field, and the data content field are correct. The first condition represents... The first condition is that the data unit is not a blank unit; the second condition indicates that the data unit is a valid unit; the third condition is that the data length represented by the data length field is within a preset length range; the fifth determining subunit is used to determine that the data unit is an invalid unit if the data verification field does not meet the fourth condition and not all of the field bits of the data verification field are preset values; the sixth determining subunit is used to repair the value of the data verification field and determine whether the repaired data verification field meets the fourth condition if the data verification field does not meet the fourth condition and all of the field bits of the data verification field are preset values. This allows for error checking and even repair of various anomalies that occur in the data verification field during the data writing process.

[0104] In an optional embodiment, there are two storage partitions. The apparatus further includes a copy unit and an erase unit. The copy unit, after determining the target partition and the non-target partition based on at least one of the following: the number of valid units in each storage partition, the number of invalid units in each storage partition, and the number of blank units in each storage partition, copies all valid data from the target partition to the non-target partition when there is target data to be written and the target partition does not have any blank units. The non-target partition is then designated as the current target partition. The erase unit erases all content in the target partition and writes the target data into the current target partition. Data is written sequentially to the blank units of the current partition. Partition switching is only performed using a spare partition when the storage partition is full, thus avoiding frequent erasure and rewriting of the storage medium. (If duplicate data names exist, the original data is simply invalidated.)

[0105] The storage partition determination device for the aforementioned storage unit of this application comprises: an acquisition unit for acquiring multiple storage partitions, each storage partition including multiple data units, each data unit storing multiple fields, including a usage field, a valid field, a data name field, a data length field, a data content field, and a data verification field; a detection unit for detecting each storage partition and obtaining multiple detection results, each detection result corresponding one-to-one with a storage partition, the multiple detection results including the number of valid units, the number of invalid units, and the number of blank units in the storage partition, the number of valid units being the number of valid data units stored in the storage partition, the number of invalid units being the number of invalid data units stored in the storage partition, and the number of blank units being the number of data units without stored data in the storage partition; and a determination unit for determining a target partition and a non-target partition based on at least one of the following: the number of valid units, the number of invalid units, and the number of blank units in each storage partition, the target partition being the storage partition with the most valid units or the most blank units, the target partition being used for reading and writing data, and the non-target partition being used to continue writing the aforementioned data when the target partition is full. This device determines target and non-target partitions, enabling partition switching to be completed using another partition when one storage partition is full. This avoids frequent erasure and rewriting of the storage medium, solving the problems of frequent erasure and rewriting, low efficiency, and reduced lifespan of the storage medium in existing technologies.

[0106] The device for determining the storage partition of the aforementioned storage unit includes a processor and a memory. The aforementioned acquisition units, etc., are all stored as program units in the memory, and the processor executes these program units stored in the memory to achieve the corresponding functions. All of the aforementioned modules are located in the same processor; alternatively, the aforementioned modules may be located in different processors in any combination.

[0107] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and adjusting kernel parameters can address the problems of frequent write / erase operations, low efficiency, and reduced lifespan of storage media in existing technologies.

[0108] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0109] This invention provides a computer-readable storage medium including a stored program, wherein, when the program is executed, it controls the device where the computer-readable storage medium is located to execute a method for determining the storage partition of the storage unit.

[0110] Specifically, the methods for determining the storage partitions of a storage unit include:

[0111] Step S201: Obtain multiple storage partitions, each of which includes multiple data units, and each of which stores multiple fields, including a usage field, a valid field, a data name field, a data length field, a data content field, and a data validation field.

[0112] Specifically, generally only two storage partitions are needed, and these two storage partitions contain an equal number of data units, such as... Figure 3 As shown, the available space on the storage medium is divided into two equal-sized areas. The capacity of one storage space is sufficient to meet data storage needs. In most cases, only one partition (the target partition) will be operated on. Data transfer is only performed when the storage space is exhausted, copying the valid data to the other partition (the non-target partition, also called the spare partition). As shown in the diagram below, each storage partition is divided into small blocks of the same size. Each small block can store one data unit, and each data unit consists of several sub-blocks. Initially, all data units in the storage area are written with 1s. The storage content is managed using a data unit approach, and the settings of various fields ensure the correctness of the read and write processes.

[0113] Step S202: Detect each of the above-mentioned storage partitions and obtain multiple detection results. The detection results correspond one-to-one with the above-mentioned storage partitions. The multiple detection results include the number of valid units, the number of invalid units, and the number of blank units in the above-mentioned storage partitions. The number of valid units is the number of valid data units stored in the above-mentioned storage partitions. The number of invalid units is the number of invalid data units stored in the above-mentioned storage partitions. The number of blank units is the number of data units in the above-mentioned storage partitions that do not store data.

[0114] Specifically, each time power is supplied, the data in multiple storage partitions is verified. Various measures are taken to check for and even repair various anomalies that occur during the data writing process. The target partition and non-target partitions are determined by statistical results, and the data in the non-target partitions is erased (all data is written to 1).

[0115] Step S203: Determine a target partition and a non-target partition based on at least one of the following: the number of valid units in each of the above-mentioned storage partitions, the number of invalid units in each of the above-mentioned storage partitions, and the number of blank units in each of the above-mentioned storage partitions. The target partition is the storage partition with the most valid units or the most blank units. The target partition is used for reading and writing data. The non-target partition is used to continue writing data when the target partition is full.

[0116] Specifically, data reading and writing are accomplished through the cooperation of two storage areas, ensuring data reliability during the reading and writing process. Storage area operations mainly include data reading, data writing, and power-on data checking. Each power-on data checking process identifies the target partition and non-target partitions, and erases the data in the non-target partitions (writing all 1s).

[0117] This invention provides a processor for running a program, wherein the program executes a method for determining the storage partition of the storage unit.

[0118] Specifically, the methods for determining the storage partitions of a storage unit include:

[0119] Step S201: Obtain multiple storage partitions, each of which includes multiple data units, and each of which stores multiple fields, including a usage field, a valid field, a data name field, a data length field, a data content field, and a data validation field.

[0120] Specifically, generally only two storage partitions are needed, and these two storage partitions contain an equal number of data units, such as... Figure 3 As shown, the available space on the storage medium is divided into two equal-sized areas. The capacity of one storage space is sufficient to meet data storage needs. In most cases, only one partition (the target partition) will be operated on. Data transfer is only performed when the storage space is exhausted, copying the valid data to the other partition (the non-target partition, also called the spare partition). As shown in the diagram below, each storage partition is divided into small blocks of the same size. Each small block can store one data unit, and each data unit consists of several sub-blocks. Initially, all data units in the storage area are written with 1s. The storage content is managed using a data unit approach, and the settings of various fields ensure the correctness of the read and write processes.

[0121] Step S202: Detect each of the above-mentioned storage partitions and obtain multiple detection results. The detection results correspond one-to-one with the above-mentioned storage partitions. The multiple detection results include the number of valid units, the number of invalid units, and the number of blank units in the above-mentioned storage partitions. The number of valid units is the number of valid data units stored in the above-mentioned storage partitions. The number of invalid units is the number of invalid data units stored in the above-mentioned storage partitions. The number of blank units is the number of data units in the above-mentioned storage partitions that do not store data.

[0122] Specifically, each time power is supplied, the data in multiple storage partitions is verified. Various measures are taken to check for and even repair various anomalies that occur during the data writing process. The target partition and non-target partitions are determined by statistical results, and the data in the non-target partitions is erased (all data is written to 1).

[0123] Step S203: Determine a target partition and a non-target partition based on at least one of the following: the number of valid units in each of the above-mentioned storage partitions, the number of invalid units in each of the above-mentioned storage partitions, and the number of blank units in each of the above-mentioned storage partitions. The target partition is the storage partition with the most valid units or the most blank units. The target partition is used for reading and writing data. The non-target partition is used to continue writing data when the target partition is full.

[0124] Specifically, data reading and writing are accomplished through the cooperation of two storage areas, ensuring data reliability during the reading and writing process. Storage area operations mainly include data reading, data writing, and power-on data checking. Each power-on data checking process identifies the target partition and non-target partitions, and erases the data in the non-target partitions (writing all 1s).

[0125] This invention provides a device including a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs at least the following steps:

[0126] Step S201: Obtain multiple storage partitions, each of which includes multiple data units, and each of which stores multiple fields, including a usage field, a valid field, a data name field, a data length field, a data content field, and a data validation field.

[0127] Step S202: Detect each of the above-mentioned storage partitions and obtain multiple detection results. The detection results correspond one-to-one with the above-mentioned storage partitions. The multiple detection results include the number of valid units, the number of invalid units, and the number of blank units in the above-mentioned storage partitions. The number of valid units is the number of valid data units stored in the above-mentioned storage partitions. The number of invalid units is the number of invalid data units stored in the above-mentioned storage partitions. The number of blank units is the number of data units in the above-mentioned storage partitions that do not store data.

[0128] Step S203: Determine a target partition and a non-target partition based on at least one of the following: the number of valid units in each of the above-mentioned storage partitions, the number of invalid units in each of the above-mentioned storage partitions, and the number of blank units in each of the above-mentioned storage partitions. The target partition is the storage partition with the most valid units or the most blank units. The target partition is used for reading and writing data. The non-target partition is used to continue writing data when the target partition is full.

[0129] The devices mentioned in this article can be servers, PCs, tablets, mobile phones, etc.

[0130] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having at least the following method steps:

[0131] Step S201: Obtain multiple storage partitions, each of which includes multiple data units, and each of which stores multiple fields, including a usage field, a valid field, a data name field, a data length field, a data content field, and a data validation field.

[0132] Step S202: Detect each of the above-mentioned storage partitions and obtain multiple detection results. The detection results correspond one-to-one with the above-mentioned storage partitions. The multiple detection results include the number of valid units, the number of invalid units, and the number of blank units in the above-mentioned storage partitions. The number of valid units is the number of valid data units stored in the above-mentioned storage partitions. The number of invalid units is the number of invalid data units stored in the above-mentioned storage partitions. The number of blank units is the number of data units in the above-mentioned storage partitions that do not store data.

[0133] Step S203: Determine a target partition and a non-target partition based on at least one of the following: the number of valid units in each of the above-mentioned storage partitions, the number of invalid units in each of the above-mentioned storage partitions, and the number of blank units in each of the above-mentioned storage partitions. The target partition is the storage partition with the most valid units or the most blank units. The target partition is used for reading and writing data. The non-target partition is used to continue writing data when the target partition is full.

[0134] It is obvious to those skilled in the art that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. They can be implemented using computer-executable program code, and thus can be stored in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those described herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.

[0135] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0136] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0137] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0138] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0139] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0140] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0141] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0142] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0143] As can be seen from the above description, the embodiments of this application achieve the following technical effects:

[0144] 1) The method for determining the storage partition of the storage unit of the above-mentioned storage unit in this application firstly obtains multiple storage partitions, each storage partition including multiple data units, each data unit storing multiple fields, including usage field, valid field, data name field, data length field, data content field, and data verification field; then, each storage partition is detected to obtain multiple detection results, each detection result corresponding to a storage partition, the multiple detection results including the number of valid units, the number of invalid units, and the number of blank units in the storage partition, the number of valid units being the number of valid data units stored in the storage partition, the number of invalid units being the number of invalid data units stored in the storage partition, and the number of blank units being the number of data units without stored data in the storage partition; finally, based on at least one of the following: the number of valid units, the number of invalid units, and the number of blank units in each storage partition, the target partition and non-target partition are determined, the target partition being the storage partition with the most valid units or the most blank units, the target partition being used for reading and writing data, and the non-target partition being used to continue writing the above data when the target partition is full. This method determines the target partition and the non-target partition, so that when one storage partition is full, the other partition is used to complete the partition switch. This avoids frequent erasure and writing of the storage medium and solves the problems of frequent erasure and writing, low efficiency and reduced lifespan of the storage medium in the prior art.

[0145] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method for determining the storage partition of a storage unit, characterized in that, include: Multiple storage partitions are obtained, each storage partition includes multiple data units, each data unit stores multiple fields, and the multiple fields include a usage field, a valid field, a data name field, a data length field, a data content field, and a data validation field; Each of the storage partitions is tested to obtain multiple test results. Each test result corresponds one-to-one with the storage partition. The multiple test results include the number of valid units, the number of invalid units, and the number of blank units in the storage partition. The number of valid units is the number of valid data units stored in the storage partition. The number of invalid units is the number of invalid data units stored in the storage partition. The number of blank units is the number of data units in the storage partition that do not store data. Target partitions and non-target partitions are determined based on at least one of the following: the number of valid units in each storage partition, the number of invalid units in each storage partition, and the number of blank units in each storage partition. The target partition is the storage partition with the most valid units or the most blank units. The target partition is used for reading and writing data, and the non-target partition is used to continue writing data when the target partition is full. Each of the aforementioned storage partitions is inspected to obtain multiple inspection results, each inspection result corresponding one-to-one with the storage partition. This includes: sequentially inspecting multiple data units within the storage partition according to a preset order, and sequentially inspecting each data unit for used fields, valid fields, data length fields, and data validation fields to obtain an initial inspection result. The initial inspection result includes whether the data unit is a valid unit, an invalid unit, or a blank unit. Based on the multiple initial inspection results, the number of valid units, the number of invalid units, and the number of blank units in the storage partition are determined to obtain the inspection result. For each of the data units, the following steps are performed sequentially: usage field detection, valid field detection, data length field detection, and data validation field detection to obtain an initial detection result. This includes: if the usage field meets a first condition, continuing to perform the valid field detection, data length field detection, and data validation field detection sequentially to obtain the initial detection result, where the first condition indicates that the data unit is not a blank unit; if the usage field does not meet the first condition and at least one detected data unit is not a blank unit, determining the data unit as an invalid unit; and if the usage field does not meet the first condition and all detected data units are blank units, determining the data unit as a blank unit.

2. The determination method according to claim 1, characterized in that, Determining target partitions and non-target partitions based on at least one of the following: the number of valid cells in each storage partition, the number of invalid cells in each storage partition, and the number of blank cells in each storage partition, including: If at least two of the storage partitions have different numbers of valid units, the storage partition with the largest number of valid units shall be determined as the target partition; If any two of the storage partitions have the same number of valid units, the storage partition with the fewest invalid units shall be determined as the target partition. If any two storage partitions have the same number of valid cells and any two storage partitions have the same number of invalid cells, the storage partition with the most blank cells is determined as the target partition.

3. The determination method according to claim 1, characterized in that, For each data unit, the following checks are performed sequentially: usage field check, valid field check, data length field check, and data validation field check, to obtain initial check results, including: If the field being used satisfies the first condition, the valid field detection continues, and if the valid field satisfies the second condition, the data length field detection and the data validation field detection continue sequentially to obtain the initial detection result. The second condition indicates that the data unit is the valid unit, and the first condition indicates that the data unit is not the blank unit. If the valid field does not meet the second condition, the data unit is determined to be the invalid unit.

4. The determination method according to claim 1, characterized in that, For each data unit, the following checks are performed sequentially: usage field check, valid field check, data length field check, and data validation field check, to obtain initial check results, including: If the used field satisfies the first condition and the valid field satisfies the second condition, the data length field detection continues, and if the data length field satisfies the third condition, the data validation field detection continues to be performed to obtain the initial detection result. The third condition is that the data length represented by the data length field is within a preset length range. The first condition indicates that the data unit is not the blank unit, and the second condition indicates that the data unit is the valid unit. If the data length field does not meet the third condition, the data unit is determined to be an invalid unit.

5. The determination method according to claim 1, characterized in that, For each data unit, the following checks are performed sequentially: usage field check, valid field check, data length field check, and data validation field check, to obtain initial check results, including: If the usage field satisfies the first condition, the valid field satisfies the second condition, and the data length field satisfies the third condition, the data validation field detection continues. If the data validation field satisfies the fourth condition, the data unit is determined to be the valid unit. The fourth condition is that the value of the data validation field is the target value and the data written in the data unit is unique. The target value indicates that the data name field, the data length field, and the data content field are correct. The first condition indicates that the data unit is not the blank unit. The second condition indicates that the data unit is the valid unit. The third condition is that the data length represented by the data length field is within a preset length range. If the data validation field does not meet the fourth condition and not all fields of the data validation field are preset values, the data unit is determined to be the invalid unit. If the data validation field does not meet the fourth condition and all field bits of the data validation field are the preset values, the value of the data validation field is repaired and it is determined whether the repaired data validation field meets the fourth condition.

6. The determining method according to any one of claims 1 to 5, characterized in that, The storage partitions are two. After determining the target partition and the non-target partition based on at least one of the following: the number of valid units in each storage partition, the number of invalid units in each storage partition, and the number of blank units in each storage partition, the method further includes: If there is target data to be written and the target partition does not have any blank cells, copy all valid data in the target partition to the non-target partition and confirm the non-target partition as the current target partition; Erase all contents in the target partition and write the target data into the current target partition.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein, when the program is executed, it controls the device containing the computer-readable storage medium to perform the method for determining the storage partition of the storage unit as described in any one of claims 1 to 6.

8. An electronic device, characterized in that, include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs including a method for determining a storage partition of a storage cell according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Garbage collection method for nonvolatile memory device

    US20130117501A1