Data partition storage and reading method, system, computer device and storage medium
By performing an XOR operation on the device system parameter data to obtain the check byte and redundantly storing it in the flash memory, the problem of data corruption in the device under abnormal voltage is solved, ensuring the reliability of the data and the correctness of the reading.
Patent Information
- Application Number
- CN202211633122.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-19
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2042-12-19
AI Technical Summary
When the device is powered on or off with unstable voltage or experiences abnormal voltage shock, the data in the FLASH storage area is easily damaged or lost, causing device malfunction or failure.
The check byte is obtained by performing an XOR operation on the data to be stored, and at least three target storage addresses are randomly selected in the flash memory to store the data and the check byte. The storage is confirmed to be successful after ensuring that the stored data is consistent with the check byte, and the correctness of the data is verified by the data check byte when reading.
It realizes the redundant storage of equipment system parameter data under abnormal circumstances, ensures the reliability and correctness of the data, and improves the reliability of the equipment and the reliability of data reading.
Smart Images

Figure CN115857820B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data storage technology, and in particular to a data partition storage and reading method, system, computer equipment and storage medium. Background Art
[0002] Device system parameter data is generally stored directly in the corresponding FLASH designated storage area. When the device is experiencing unstable power supply voltages, or is subject to certain abnormal voltage shocks, or in other abnormal situations, the data in the FLASH storage area may be damaged or lost, which will cause the device to malfunction or fail, and it will not be able to operate normally. Summary of the Invention
[0003] Based on this, it is necessary to address the above problems and propose a data partition storage and reading method, system, computer device and storage medium to ensure that the device always operates normally.
[0004] A data partition storage and reading method, comprising:
[0005] Obtain data to be stored, perform an XOR operation on each byte of the data to be stored, obtain an XOR result, perform an XOR operation on the XOR result and 0X55, and obtain a check byte;
[0006] Obtaining a preset storage space based on the number of bytes of the data to be stored and the number of bytes of the check bytes, and randomly selecting at least three target storage addresses in the flash memory, wherein the storage space corresponding to each of the target storage addresses is greater than or equal to the preset storage space;
[0007] The data to be stored and the check byte are stored in the at least three target storage addresses respectively, and the stored data stored in each of the target storage addresses is read. When the stored data are consistent with the data to be stored and the check byte, it is confirmed that the data is stored successfully.
[0008] The step of storing the data to be stored and the check byte in the at least three target storage addresses respectively includes:
[0009] Storing the data to be stored and the check bytes one by one into the at least three target storage addresses;
[0010] The step of reading the storage data stored in each of the target storage addresses comprises:
[0011] After each target storage address is stored, the stored data of the target storage address is read to determine whether the stored data is consistent with the data to be stored and the check byte; if the stored data is consistent with the data to be stored and the check byte, the next target storage address is stored;
[0012] When all the target storage addresses are stored and all the stored data are consistent with the data to be stored and the check byte, it is confirmed that the data storage is successful.
[0013] Wherein, after the step of determining whether the stored data is consistent with the data to be stored and the check byte, the following steps are included:
[0014] If the stored data is inconsistent with the data to be stored and the check byte, the operation of storing the next target storage address is suspended, and a corresponding error message is reported to prompt the user.
[0015] Wherein, when the stored data is consistent with the data to be stored and the check byte, after the step of confirming that the data is stored successfully, the following steps are included:
[0016] Reading the stored data in each of the target storage addresses, and obtaining the storage check byte and valid data in each of the stored data;
[0017] Perform an XOR operation on each byte of the valid data to obtain a data XOR result, perform an XOR operation on the data XOR result and 0X55 to obtain a data check byte;
[0018] The data check byte corresponding to each of the target storage addresses is compared with the storage check byte, and based on the comparison result, the storage data of at least one of the target storage addresses is selected for reading and use.
[0019] The step of selecting the stored data of at least one target storage address to read and use based on the comparison result includes:
[0020] If the data check byte and the storage check byte corresponding to each of the target storage addresses are consistent, the storage data of any one of the target storage addresses is selected for reading and use.
[0021] The step of selecting the stored data of at least one target storage address to read and use based on the comparison result includes:
[0022] If there is at least one target storage address whose corresponding data check byte is consistent with the storage check byte, then the storage data of the target storage address whose data check byte is consistent with the storage check byte is selected for reading and use;
[0023] According to the storage data of the target storage address consistent with the data check byte and the storage check byte, the storage data of the target storage address inconsistent with the data check byte and the storage check byte is copied back.
[0024] The step of selecting at least one storage data of the target storage address for reading and using based on the comparison result comprises:
[0025] If the data check byte and the storage check byte corresponding to each target storage address are inconsistent, a new storage address is selected.
[0026] The effective data of each target storage address is compared byte by byte. If the effective data corresponding to the current byte exceeds a preset number of same values, the same values are taken as the byte value corresponding to the current byte.
[0027] The byte values corresponding to all bytes are obtained to generate new effective data, and new check bytes are generated based on the new effective data.
[0028] At least two new target storage addresses are randomly selected in the remaining storage space of the flash memory, and the new effective data and the new check bytes are respectively stored in the at least two new target storage addresses.
[0029] The new storage data stored in each new target storage address is read. When the new storage data is consistent with the new effective data and the new check bytes, it is confirmed that the storage data is successful.
[0030] A data partition storage and reading system applied to a flash memory, comprising:
[0031] An acquisition module is configured to acquire to-be-stored data, perform XOR operation on each byte of the to-be-stored data, acquire an XOR result, perform XOR operation on the XOR result and 0X55, and acquire a check byte.
[0032] A space module is configured to acquire a preset storage space based on the number of bytes of the to-be-stored data and the number of bytes of the check byte, and randomly select at least three target storage addresses in the flash memory, wherein the storage space corresponding to each target storage address is greater than or equal to the preset storage space.
[0033] A storage module is configured to store the to-be-stored data and the check byte in the at least three target storage addresses respectively, read the storage data stored in each target storage address, and confirm that the storage data is successful when the storage data is consistent with the to-be-stored data and the check byte.
[0034] A computer device includes a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps described above.
[0035] A computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the processor is caused to perform the steps described above.
[0036] The embodiments of the present invention have the following beneficial effects:
[0037] After performing an XOR operation on each byte of the data to be stored, perform an XOR operation with 0X55 to obtain a check byte, randomly select at least three target storage addresses in the flash memory, store the data to be stored and the check byte in at least three target storage addresses respectively, read the stored data stored in each target storage address, and when the stored data is consistent with the data to be stored and the check byte, confirm that the data storage is successful. The device system parameter data can be backed up multiple times through redundant storage, and the stored device system parameter data can be ensured to be correct, thereby improving the reliability and effectiveness of reading the data when the device system parameter data is subsequently used. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0039] in:
[0040] Figure 1 This is a flow chart of a first embodiment of the data partition storage and reading method provided by the present invention;
[0041] Figure 2 1 is a flow chart of a second embodiment of the data partition storage and reading method provided by the present invention;
[0042] Figure 3 It is a structural diagram of an embodiment of a data partition storage and reading system provided by the present invention;
[0043] Figure 4 The figure shows the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0044] With reference to the drawings and embodiments of the present application, the technical solutions in the embodiments of the present application will be described clearly and completely. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of the present application.
[0045] Please refer to Figure 1 , Figure 1 is a flowchart of a first embodiment of a data partition storage and reading method provided by the present application. The data partition storage and reading method provided by the present application comprises the following steps:
[0046] S101: Obtain the to-be-stored data, perform an exclusive OR operation on each byte of the to-be-stored data to obtain an exclusive OR result, and perform an exclusive OR operation on the exclusive OR result and 0X55 to obtain a check byte.
[0047] In a specific implementation scenario, the to-be-stored data is device system parameter data, which needs to be repeatedly used in the subsequent device use process, and therefore the to-be-stored data must be stored in the device and the storage content cannot be erroneous. In the embodiment, the to-be-stored data needs to be stored in the flash memory of the device. However, when the device is powered on or off or is subjected to some abnormal voltage impact, voltage instability occurs, or in some other abnormal situations, the data in the flash memory will be abnormally damaged or lost.
[0048] Therefore, in the embodiment, the to-be-stored data is stored by using a redundant storage method, so as to improve the correctness and reliability of the data in the flash memory after an abnormal situation occurs. Assuming that the to-be-stored data comprises N bytes, which are N0, N1…N (N-2) , N (N-1) , a check byte is calculated based on the N bytes, which is 1 byte in the implementation scenario, and is obtained by performing an exclusive OR operation on the exclusive OR result and 0X55. When performing an exclusive OR operation on two values a and b, if the values of a and b are different, the exclusive OR result is 1. If the values of a and b are the same, the exclusive OR result is 0. 0x55 is converted into binary, that is, 01010101. By performing an exclusive OR operation on 0x55, the calculation error can be effectively avoided, the initial result of the calculation is retained, and the reliability of the check byte is improved. The to-be-stored data and the check byte need to be stored in the flash memory. Please refer to the following table, which is a data table to be stored in the flash memory.
[0049]
[0050] Data table to be stored in the flash memory
[0051] S102: Obtain a preset storage space based on the number of bytes of the data to be stored and the number of bytes of the check bytes, and randomly select at least three target storage addresses in the flash memory, each of which corresponds to a storage space greater than or equal to the preset storage space.
[0052] In a specific implementation scenario, the preset storage space is obtained based on the number of bytes of the data to be stored and the number of bytes of the check bytes, and the preset storage space is greater than or equal to the sum of the number of bytes of the data to be stored and the number of bytes of the check bytes. For example, in this implementation scenario, the number of bytes of the data to be stored is N, and the number of bytes of the check bytes is 1, so the preset storage space M is greater than or equal to N+1 bytes. At least three target storage addresses are randomly selected in the flash memory, and each of the target storage addresses corresponds to a storage space greater than or equal to the preset storage space. The purpose of randomly selecting the target storage addresses is to store multiple copies of the data to be stored to improve the reliability of the storage. The at least three target storage addresses are used to store at least three copies of the data to be stored to improve the reliability of using the data later. For example, in this implementation scenario, 3 target storage addresses A1, A2 and A3 are selected. The storage space corresponding to any one of the target storage addresses A1, A2 and A3 is greater than or equal to N+1.
[0053] S103: Store the data to be stored and the check bytes in at least three target storage addresses respectively, read the storage data in each target storage address, and confirm that the storage data is successful when the storage data is consistent with the data to be stored and the check bytes.
[0054] In a specific implementation scenario, the data to be stored and the check bytes are stored as a storage whole in each target storage address. When storing, the storage can be stored in sequence, for example, the storage whole is first stored in the target storage address A1, then the storage whole is stored in the target storage address A2, and finally the storage whole is stored in the target storage address A3. The storage whole can also be stored in the target storage addresses A1, A2 and A3 simultaneously.
[0055] When storing in sequence, after storing each target storage address, the storage data of the stored target storage address is read, and it is judged whether the storage data is consistent with the data to be stored and the check bytes. If the storage data is consistent with the data to be stored and the check bytes, the next target storage address is stored. If the storage data is not consistent with the data to be stored and the check bytes, the operation of storing the next target storage address is suspended, and the corresponding error information is reported to prompt the user. When all the target storage addresses are stored, and all the storage data is consistent with the data to be stored and the check bytes, it is confirmed that the storage data is successful.
[0056] For example, after the storage is stored in the target storage address A1, the storage data currently stored in the target storage address A1 is compared with the storage, that is, the data to be stored + the check byte. If the two are completely consistent, the operation of storing the storage in the target storage address A2 is executed. If the two are not completely consistent, the operation of storing the storage in the target storage address A2 is suspended, and the corresponding error message is reported to prompt the user that the storage is abnormal, such as notifying the user that the first storage failed, or that the storage at the target storage address A1 failed. The user can then choose to re-execute the storage operation or re-select a new target storage address for storage.
[0057] When the entire storage is successfully stored in the target storage addresses A1, A2, and A3, and the stored data in the target storage addresses A1, A2, and A3 are consistent with the entire storage, the storage is confirmed to be successful. At this time, the user can be prompted with a successful storage, or the user can choose to delete the data to be stored and the check byte, and retain the stored data in A1, A2, and A3.
[0058] It can be seen from the above description that in this embodiment, each byte of the data to be stored is subjected to an XOR operation and then to an XOR operation with 0X55 to obtain a check byte, at least three target storage addresses are randomly selected in the flash memory, the data to be stored and the check byte are respectively stored in the at least three target storage addresses, and the storage data stored in each target storage address is read. When the stored data is consistent with the data to be stored and the check byte, the storage of the data is confirmed to be successful. The device system parameter data can be backed up multiple times through redundant storage, and the stored device system parameter data can be ensured to be correct, thereby improving the reliability and effectiveness of the read data when the device system parameter data is subsequently used.
[0059] Please refer to Figure 2 , Figure 2 1 is a flow chart of a second embodiment of the data partition storage and reading method provided by the present invention. The data partition storage and reading method provided by the present invention comprises the following steps:
[0060] S201: Obtain data to be stored, perform an XOR operation on each byte of the data to be stored, obtain an XOR result, perform an XOR operation on the XOR result and 0X55, and obtain a check byte.
[0061] S202: Obtain a preset storage space based on the number of bytes of data to be stored and the number of check bytes, and randomly select at least three target storage addresses in the flash memory, where the storage space corresponding to each target storage address is greater than or equal to the preset storage space.
[0062] S203: storing the data to be stored and the check byte in at least three target storage addresses respectively, reading the stored data stored in each target storage address, and confirming that the data is stored successfully when the stored data are consistent with the data to be stored and the check byte.
[0063] In a specific implementation scenario, steps S201-S203 are substantially the same as steps S101-S103 in the first embodiment of the data partition storage and reading method provided by the present invention, and are not described in detail here.
[0064] S204: Read the storage data in each target storage address, and obtain the storage check byte and valid data in each storage data.
[0065] In a specific implementation scenario, when device parameter data is needed, the stored data at each target storage address is read. For example, in this implementation scenario, the stored data at target storage addresses A1, A2, and A3 are read to obtain the storage check byte corresponding to the check byte and the valid data corresponding to the data to be stored in each stored data.
[0066] S205: Perform an XOR operation on each byte of the valid data to obtain a data XOR result, perform an XOR operation on the data XOR result and 0X55 to obtain a data check byte.
[0067] In a specific implementation scenario, each byte of the valid data is XORed with each other and then XORed with 0x55 to obtain a data check byte. The steps for obtaining the data check byte are the same as those for obtaining the check byte based on the data to be stored. Therefore, if the valid data and the data to be stored are completely consistent, the data check byte should theoretically also be consistent with the stored check byte.
[0068] S206: Compare the data check byte corresponding to each target storage address with the storage check byte, and select storage data of at least one target storage address to read and use based on the comparison result.
[0069] In a specific implementation scenario, the data check byte and the storage check byte corresponding to each target storage address are compared, and based on the comparison result, the storage data of at least one target storage address is selected for reading and use.
[0070] For example, in this implementation scenario, there are target storage addresses A1, A2, and A3, which respectively store valid data B1, B2, and B3, and store check bytes S1, S2, and S3. The data check bytes calculated based on the valid data B1, B2, and B3 are C1, C2, and C3, respectively. The storage check bytes S1, S2, and S3 are compared with the data check bytes C1, C2, and C3.
[0071] If S1=C1, S2=C2, S3=C3, it can be inferred that the valid data B1, B2 and B3 have no errors and are consistent with the data to be stored. They can all be read and used. When needed, any one of B1, B2 and B3 can be selected.
[0072] If there is at least one pair of storage check bytes S1, S2 and S3 and data check bytes C1, C2 and C3 that are consistent, S1=C1, S2=C2, S3≠C3, then it can be inferred that there is no error in the valid data B1 and B2, and they are consistent with the data to be stored, and both can be read and used. When needed, any one of B1 and B2 can be selected.
[0073] If the storage check bytes S1, S2 and S3 are inconsistent with the data check bytes C1, C2 and C3, S1≠C1, S2≠C2, S3≠C3, then it can be inferred that the valid data B1, B2 and B3 are all erroneous and cannot be used directly. It is necessary to infer the usable data based on the stored valid data B1, B2 and B3.
[0074] In this embodiment, a new storage address can be reselected in the flash memory, and the storage space size requirement of the new storage address is consistent with the target storage address requirement and is greater than or equal to N+1. The values of each byte in the valid data B1, B2 and B3 are compared. If the valid data corresponding to the current byte Xn has more than a preset number (for example, 2) of the same value m, the same value m is used as the byte value corresponding to the current byte Xn, and m is stored in the position corresponding to the Xn byte in the new storage address. Starting from the first byte of the valid data B1, B2 and B3, the above operation is performed until the end of the Nth byte, and the byte values corresponding to the N bytes are obtained. The byte values corresponding to all bytes are obtained to generate new valid data, and a new check byte is generated based on the new valid data. The step of generating a new check byte can be consistent with the step of generating a check byte based on the data to be stored, and will not be repeated here.
[0075] At least two new target storage addresses are randomly selected from the remaining storage space of the flash memory, where the selection criteria for the new target storage addresses are consistent with the selection criteria for the target storage addresses, and the new valid data and the new check byte are stored in the at least two new target storage addresses, respectively. For example, new target storage addresses A4 and A5 are selected, and the new valid data and the new check byte are stored in A4 and A5, respectively.
[0076] In other implementation scenarios, the newly stored data stored in each new target storage address is read. When the newly stored data is consistent with the new valid data and the new check byte, the data storage is confirmed to be successful. After the storage is completed in the new target storage address A4, the newly stored data stored in A4 is read. If the newly stored data is consistent with the new valid data and the new check byte, the operation of storing the data in A5 is performed. After the storage is completed in the new target storage address A5, the newly stored data stored in A5 is read. If the new stored data is consistent with the new valid data and the new check byte, the storage is determined to be successful. When the device system parameter data is needed later, the newly stored data in the new target storage addresses A4 and A5 are read, and the operations of steps S204-S206 are performed.
[0077] Furthermore, the data in the original target storage addresses A1, A2 and A3 can be deleted because these data contain errors and cannot be used. Deleting them in time can avoid resource waste and free up storage space.
[0078] It can be seen from the above description that in this embodiment, the device system parameter data is redundantly stored. When needed, the storage check bytes stored in each target storage address and the data check bytes calculated based on the stored valid data can be compared to determine whether the valid data stored in each target storage address is consistent with the data to be stored, so that the valid data consistent with the data to be stored can be selected for use, and the erroneous stored data can be corrected through comparison to obtain the correct data for easy use, which can effectively improve the reliability of the device system parameter data and maintain the reliable operation of the equipment.
[0079] See also Figure 3 , Figure 3 1 is a schematic diagram of a data partition storage and reading system according to an embodiment of the present invention. The data partition storage and reading system 10 is applied to a flash memory and includes an acquisition module 11, a space module 12 and a storage module 13.
[0080] The acquisition module 11 is used to obtain the data to be stored, perform an XOR operation on each byte of the data to be stored, obtain the XOR result, perform an XOR operation on the XOR result and 0X55, and obtain the check byte. The space module 12 is used to obtain a preset storage space based on the number of bytes of the data to be stored and the number of bytes of the check byte, and randomly select at least three target storage addresses in the flash memory, and the storage space corresponding to each target storage address is greater than or equal to the preset storage space. The storage module 13 is used to store the data to be stored and the check byte in at least three target storage addresses respectively, read the stored data stored in each target storage address, and confirm that the data storage is successful when the stored data is consistent with the data to be stored and the check byte.
[0081] The space module 12 is used to store the data to be stored and the check byte one by one into at least three target storage addresses. The storage module 13 is used to read the stored data of each target storage address after storing it, and determine whether the stored data is consistent with the data to be stored and the check byte. If the stored data is consistent with the data to be stored and the check byte, the next target storage address is stored. When all target storage addresses have been stored and all stored data are consistent with the data to be stored and the check byte, the data storage is confirmed to be successful.
[0082] The storage module 13 is used to suspend the operation of storing the next target storage address if the stored data is inconsistent with the data to be stored and the check byte, and report the corresponding error information to prompt the user.
[0083] The data partition storage and reading system 10 also includes a reading module 14, which is used to read the storage data in each target storage address, obtain the storage check byte and valid data in each storage data; perform an XOR operation on each byte of the valid data to obtain the data XOR result, perform an XOR operation on the data XOR result and 0X55 to obtain the data check byte; compare the data check byte and the storage check byte corresponding to each target storage address, and select the storage data of at least one target storage address for reading and use based on the comparison result.
[0084] The reading module 14 is configured to select the storage data of any target storage address to read and use if the data check byte and the storage check byte corresponding to each target storage address are consistent.
[0085] The reading module 14 is configured to select the storage data of the target storage address whose data check byte is consistent with the storage check byte if there is at least one target storage address whose corresponding data check byte is consistent with the storage check byte for reading and using;
[0086] The storage data at the target storage address whose data check byte is consistent with the storage check byte is copied and written back to the storage data at the target storage address whose data check byte is inconsistent with the storage check byte.
[0087] The reading module 14 is used to select a new storage address if the data check byte and the storage check byte corresponding to each target storage address are inconsistent; compare the valid data of each target storage address byte by byte, and if the valid data corresponding to the current byte has more than a preset number of identical values, use the identical value as the byte value corresponding to the current byte; obtain the byte values corresponding to all bytes to generate new valid data, and generate a new check byte based on the new valid data; randomly select at least two new target storage addresses in the remaining storage space of the flash memory, and store the new valid data and the new check byte in the at least two new target storage addresses respectively; read the new storage data stored in each new target storage address, and when the new storage data are consistent with the new valid data and the new check byte, confirm that the data storage is successful.
[0088] It can be seen from the above description that in this embodiment, each byte of the data to be stored is subjected to an XOR operation and then to an XOR operation with 0X55 to obtain a check byte, at least three target storage addresses are randomly selected in the flash memory, the data to be stored and the check byte are respectively stored in at least three target storage addresses, and the storage data stored in each target storage address is read. When the stored data are consistent with the data to be stored and the check byte, the storage data is confirmed to be successful. The device system parameter data can be backed up in multiple ways through redundant storage. When needed, the storage check byte stored in each target storage address and the data check byte calculated based on the stored valid data can be compared to determine whether the valid data stored in each target storage address is consistent with the data to be stored, so that the valid data consistent with the data to be stored can be selected for use, and the erroneous stored data can be corrected through comparison to obtain the correct data for easy use, which can effectively improve the reliability of the device system parameter data and maintain the reliable operation of the device.
[0089] Figure 4 FIG1 shows an internal structure diagram of a computer device in an embodiment. The computer device can be a terminal or a server. Figure 4 As shown, the computer device includes a processor, a memory, and a network interface connected via a system bus. The memory includes a non-volatile storage medium and an internal memory. The non-volatile storage medium of the computer device stores an operating system and may also store a computer program. When the computer program is executed by the processor, the processor can implement the age recognition method. The internal memory may also store a computer program. When the computer program is executed by the processor, the processor can implement the age recognition method. It will be understood by those skilled in the art that Figure 4The structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0090] In one embodiment, a computer device is provided, comprising a memory and a processor, the memory storing a computer program, the computer program being executed by the processor to cause the processor to perform the steps of Figure 1 or Figure 2 the steps.
[0091] In one embodiment, a computer readable storage medium is provided, storing a computer program, the computer program being executed by a processor to cause the processor to perform the steps of Figure 1 or Figure 2 the steps:
[0092] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by a computer program instructing related hardware. The program can be stored in a non-volatile computer readable storage medium, and when the program is executed, it can include the processes of the above-mentioned embodiments. Any reference to memory, storage, database or other medium used in the embodiments provided by the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0093] Each technical feature of the above embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above embodiments are described, but as long as the combinations of the technical features do not exist, they should be considered as the scope of the present application.
[0094] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person of ordinary skill in the art may make various modifications and improvements without departing from the spirit of the present invention, all of which fall within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be determined by the appended claims.
Claims
1. A data partition storage and reading method, characterized in that: Applications in flash memory, including: Obtain data to be stored, perform an XOR operation on each byte of the data to be stored, obtain an XOR result, perform an XOR operation on the XOR result and 0X55, and obtain a check byte; Obtaining a preset storage space based on the number of bytes of the data to be stored and the number of bytes of the check bytes, and randomly selecting at least three target storage addresses in the flash memory, wherein the storage space corresponding to each of the target storage addresses is greater than or equal to the preset storage space; Storing the data to be stored and the check bytes into the at least three target storage addresses one by one; After each target storage address is stored, the stored data of the target storage address is read to determine whether the stored data is consistent with the data to be stored and the check byte; if the stored data is consistent with the data to be stored and the check byte, the next target storage address is stored; When all the target storage addresses are stored and all the stored data are consistent with the data to be stored and the check byte, it is confirmed that the data storage is successful.
2. The data partition storage and reading method according to claim 1, characterized in that: After the step of determining whether the stored data is consistent with the data to be stored and the check byte, the method further includes: If the stored data is inconsistent with the data to be stored and the check byte, the operation of storing the next target storage address is suspended, and a corresponding error message is reported to prompt the user.
3. The data partition storage and reading method according to claim 1, characterized in that: If all the stored data are consistent with the data to be stored and the check byte, then after the step of confirming that the data is stored successfully, the method further includes: Reading the stored data in each of the target storage addresses, and obtaining the storage check byte and valid data in each of the stored data; Perform an XOR operation on each byte of the valid data to obtain a data XOR result, perform an XOR operation on the data XOR result and 0X55 to obtain a data check byte; The data check byte corresponding to each of the target storage addresses is compared with the storage check byte, and based on the comparison result, the storage data of at least one of the target storage addresses is selected for reading and use.
4. The data partition storage and reading method according to claim 3, characterized in that: The step of selecting the stored data of at least one target storage address to read and use based on the comparison result includes: If the data check byte and the storage check byte corresponding to each of the target storage addresses are consistent, the storage data of any one of the target storage addresses is selected for reading and use.
5. The data partition storage and reading method according to claim 3, characterized in that: The step of selecting the stored data of at least one target storage address to read and use based on the comparison result includes: If there is at least one target storage address whose corresponding data check byte is consistent with the storage check byte, then the storage data of the target storage address whose data check byte is consistent with the storage check byte is selected for reading and use; A copy-write operation is performed on the storage data at the target storage address whose data check byte is consistent with the storage check byte, for the storage data at the target storage address whose data check byte is inconsistent with the storage check byte.
6. The data partition storage and reading method according to claim 3, characterized in that: The step of selecting the stored data of at least one target storage address to read and use based on the comparison result includes: If the data check byte and the storage check byte corresponding to each target storage address are inconsistent, selecting a new storage address; Comparing the valid data of each target storage address byte by byte, if the valid data corresponding to the current byte has more than a preset number of identical values, taking the identical values as the byte value corresponding to the current byte; Obtain the byte values corresponding to all bytes to generate new valid data, and generate new check bytes based on the new valid data; Randomly selecting at least two new target storage addresses from the remaining storage space of the flash memory, and storing the new valid data and the new check byte in the at least two new target storage addresses respectively; The newly stored data stored in each of the new target storage addresses is read, and when the newly stored data are consistent with the new valid data and the new check byte, it is confirmed that the data storage is successful.
7. A data partition storage and reading system, characterized in that: Applications in flash memory, including: An acquisition module is used to acquire data to be stored, perform an XOR operation on each byte of the data to be stored, obtain an XOR result, perform an XOR operation on the XOR result and 0X55, and obtain a check byte; a space module, configured to obtain a preset storage space based on the number of bytes of the data to be stored and the number of bytes of the check bytes, and randomly select at least three target storage addresses in the flash memory, wherein the storage space corresponding to each of the target storage addresses is greater than or equal to the preset storage space; a storage module, configured to store the data to be stored and the check byte into the at least three target storage addresses one by one; after storing each target storage address, read the stored data of the target storage address, determine whether the stored data is consistent with the data to be stored and the check byte, and if the stored data is consistent with the data to be stored and the check byte, store the next target storage address; When all the target storage addresses are stored and all the stored data are consistent with the data to be stored and the check byte, it is confirmed that the data storage is successful.
8. A computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the processor is caused to perform the steps of the method according to any one of claims 1 to 6.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor is caused to perform the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Data recovery method and device
CN105279048A
Data processing method and device, computer equipment and storage medium
CN113010114A
Data read-write method, device and equipment based on memory and storage medium
CN114741231A