A file management method, device, terminal and medium based on embedded system
By generating backup files in an embedded system and performing file recovery mechanism, the file loss and corruption of traditional file systems during abnormal power failure is solved, effectively manage and protect small files, and reduce development costs and hardware requirements. .
Patent Information
- Application Number
- CN202111035647.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-03
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2041-09-03
AI Technical Summary
Traditional file systems are prone to loss or corruption of files when powered off abnormally, and existing recovery methods occupy disk space, making it difficult to effectively manage small files in embedded systems with hardware limitations.
In an embedded system, a backup file is generated when a write operation is detected, and the original file is deleted after the write operation is completed; during the read operation, determine whether the last write operation is completed normally. If it is not completed, the file will be restored, and the file will be backed up or Recovery of backup files reads the original file contents.
It realizes the management and protection of small files in embedded systems, avoids file loss and corruption, reduces development costs and hardware requirements, and has good compatibility.
Smart Images

Figure CN113886327B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of file management, and in particular to a file management method, device, terminal and medium based on an embedded system. Background Art
[0002] In the management of files by traditional file systems, a large amount of file editing and storage work is involved. When a traditional file system loses power abnormally during a file write operation, files in the file system are lost or damaged, resulting in functional abnormalities.
[0003] Existing file systems, such as database software or file systems of medium and large server operating systems, usually use log systems or disk backups to recover lost files. In addition, for more complex situations such as file damage, it is necessary to add processing programs in combination with business-specific services to judge and handle abnormal situations. However, log systems or disk backup methods will occupy disk space, resulting in reduced disk utilization. Under hardware constraints, it is difficult for embedded systems to use large database software and disk backup mechanisms to manage and protect files. Existing file systems not only increase the additional development of upper-level users and software developers, but are also limited by specific hardware and processing systems. There are also certain requirements for the storage location of data, lack of compatibility, and relatively high costs. Summary of the invention
[0004] The present invention provides a file management method, device, terminal and medium based on an embedded system, which can be suitable for handling the management and protection of small files when the embedded system hardware and file system are limited, and avoid the situation where the file is lost or damaged due to abnormal power failure.
[0005] In order to solve the above technical problems, an embodiment of the present invention provides a file management method based on an embedded system, comprising:
[0006] When it is detected that the application software needs to perform a write operation on the first file, a second file is generated on the disk, the content to be written is written into the second file, and the first file is backed up to generate a first backup file;
[0007] The second file is renamed as the first file, and after the renaming is completed, the first backup file is deleted to complete the write operation process.
[0008] Furthermore, the management method also includes:
[0009] When it is detected that a read operation needs to be performed on the first file, determining whether a first backup file corresponding to the first file exists on the disk to determine whether a previous write operation process of the first file is completed normally;
[0010] If not, determining that the last write operation process of the first file is completed normally, deleting the second file corresponding to the first file, and performing a read operation on the first file on the disk;
[0011] If it exists, it is determined that the last write operation process of the first file is not completed normally, the first file on the disk is restored, and a read operation is performed on the restored first file.
[0012] Further, the file recovery of the first file on the disk is specifically:
[0013] Determine whether a second file corresponding to the first file exists on the disk;
[0014] If the second file exists, recovering the first file on the disk according to the second file;
[0015] If the second file does not exist, the first file on the disk is restored according to the first backup file.
[0016] Further, the performing file recovery on the first file on the disk according to the second file is specifically:
[0017] The second file is renamed as the first file, and the first backup file is deleted, so as to complete the file recovery of the first file on the disk.
[0018] Further, the performing file recovery on the first file on the disk according to the first backup file is specifically as follows:
[0019] The first backup file is renamed as the first file, and the file recovery of the first file on the disk is completed.
[0020] In order to solve the same technical problem, the present invention also provides a file management device based on an embedded system, comprising: a writing module, a backup module, a renaming module and a reading module;
[0021] The writing module is used to generate a second file on the disk and write the content to be written into the second file when detecting that the application software needs to perform a write operation on the first file;
[0022] The backup module is used to back up the first file to generate a first backup file;
[0023] The renaming module is used to rename the second file to the first file, and after the naming is completed, delete the first backup file;
[0024] The reading module is used to determine whether a first backup file corresponding to the first file exists on the disk when it is detected that a read operation needs to be performed on the first file, so as to determine whether the last write operation process of the first file is completed normally;
[0025] If it does not exist, determining that the last write operation process of the first file is completed normally, deleting the second file corresponding to the first file, and performing a read operation on the first file on the disk;
[0026] If it exists, it is determined that the last write operation process of the first file is not completed normally, the first file on the disk is restored, and a read operation is performed on the restored first file.
[0027] The reading module further includes: a first judgment unit, a second judgment unit, a first recovery reading unit and a second recovery reading unit;
[0028] Wherein, the first judgment unit is used to judge whether there is a first backup file corresponding to the first file on the disk when it is detected that a read operation needs to be performed on the first file, so as to determine whether the last write operation process of the first file is completed normally;
[0029] The second judgment unit is used to judge whether there is a second file corresponding to the first file on the disk when the last write operation process of the first file is not completed normally;
[0030] The first recovery reading unit is used for, when detecting that a read operation needs to be performed on the first file, if a first backup file corresponding to the first file does not exist on the disk, determining that the last write operation process of the first file is completed normally, and performing a read operation on the first file on the disk;
[0031] If a first backup file corresponding to the first file exists on the disk, determining that the last write operation process of the first file was not completed normally, restoring the first file on the disk, and performing a read operation on the restored first file;
[0032] The second recovery reading unit is used for, when the last write operation process of the first file is not completed normally, recovering the first file on the disk according to the second file if the second file exists;
[0033] If the second file does not exist, the first file on the disk is restored according to the first backup file.
[0034] In order to solve the same technical problem, the present invention also provides a terminal, including a processor, a memory and a computer program stored in the memory; wherein the computer program can be executed by the processor to implement the file management method based on the embedded system.
[0035] In order to solve the same technical problem, the present invention also provides a computer-readable storage medium, which includes a stored computer program; wherein, when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the file management method based on the embedded system.
[0036] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0037] The present invention provides a file management method, device, terminal and medium based on an embedded system, which is not limited by hardware and file system, has no specific requirements for the location of data stored on the memory, has compatibility with the file system, and is suitable for the management of small files. When a write operation needs to be performed on a first file, the management and protection of the file can be achieved by backing up the first file and generating a second file for writing new content, without the need to add additional software devices or perform excessive data backup.
[0038] Furthermore, when the file system is abnormally powered off, if it is determined that the last write operation of the first file was not completed normally, a recovery mechanism is used to read the original old file or continue the last latest progress to continue the file write operation. The present invention reduces the additional development of the operating system by upper-level users and software developers on the basis of compatibility, thereby reducing development costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 : A flowchart of an embodiment of a file management method based on an embedded system provided by the present invention;
[0040] Figure 2 : A flow chart of another embodiment of the file management method based on embedded system provided by the present invention;
[0041] Figure 3 : A schematic diagram of the structure of a file management device based on an embedded system provided by the present invention;
[0042] Figure 4 : A schematic diagram of the structure of a reading module of a file management device based on an embedded system provided by the present invention. DETAILED DESCRIPTION
[0043] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0044] Embodiment 1:
[0045] Please refer to Figure 1 , which is a flow chart of an embodiment of the file management method based on an embedded system provided by the present invention, including steps 101 to 102, each of which is specifically as follows:
[0046] Step 101: When it is detected that the application software needs to perform a write operation on the first file, a second file is generated on the disk, the content to be written is written into the second file, and the first file is backed up to generate a first backup file.
[0047] In this embodiment, by backing up the first file, it is ensured that during the file writing operation, when an exception occurs in the file system, the original file still exists.
[0048] Step 102: rename the second file to the first file, and after the renaming is completed, delete the first backup file to complete the write operation process.
[0049] In this embodiment, the deletion of the first backup file is used as a sign of completing the write operation process.
[0050] As an example of this embodiment, the file management method of the present invention also includes a file reading process, which is described in detail in Figure 2 . Figure 2 A flowchart diagram of another embodiment of the file management method based on embedded system provided by the present invention. Figure 2 and Figure 1 The difference is that after step 102, steps 203 to 209 are also included. The steps of this example are as follows:
[0051] Step 203: When it is detected that a read operation needs to be performed on the first file, it is determined whether a first backup file corresponding to the first file exists on the disk.
[0052] In this example, if it is determined that the first backup file corresponding to the first file does not exist on the disk, step 204 is executed; if it is determined that the first backup file corresponding to the first file exists on the disk, step 206 is executed.
[0053] Step 204: Delete the second file corresponding to the first file.
[0054] In this embodiment, it is determined whether the last write operation process of the first file is completed normally by judging whether the first backup file corresponding to the first file exists on the disk. If not, it is determined that the last write operation process of the first file is completed normally; if exists, it is determined that the last write operation process of the first file is not completed normally.
[0055] In this embodiment, when it is determined that the last write operation process of the first file is completed normally, after executing step 204, step 205 is executed to complete the read operation process.
[0056] Step 205: Perform a read operation on the first file.
[0057] In this embodiment, when it is determined that the last write operation process of the first file is not completed normally, the recovery mechanism is started to restore the first file on the disk, and a read operation is performed on the restored first file.
[0058] Step 206: Determine whether there is a second file corresponding to the first file on the disk.
[0059] In this embodiment, if it is determined that the second file corresponding to the first file does not exist on the disk, step 207 is executed; if it is determined that the second file corresponding to the first file exists on the disk, step 208 is executed.
[0060] Step 207: Rename the first backup file corresponding to the first file as the first file.
[0061] In this embodiment, when it is determined that the second file corresponding to the first file does not exist on the disk, after executing step 207, step 205 is executed to complete the read operation process.
[0062] In this embodiment, the content of the restored first file is the content of the original file.
[0063] Step 208: Rename the second file corresponding to the first file as the first file.
[0064] In this embodiment, when it is determined that the second file corresponding to the first file exists on the disk, after executing step 208, step 209 is executed, and finally step 205 is executed to complete the read operation process.
[0065] Step 209: Delete the first backup file corresponding to the first file.
[0066] In this embodiment, the content of the restored first file is the latest file content.
[0067] It should be noted that steps 203 to 209 may be, but are not limited to, performed after step 102. As long as a read operation occurs, steps 203 to 209 may be performed. After step 205 is performed, the file may also be normally written according to steps 101 to 102.
[0068] Please refer to Figure 3 In order to solve the same technical problem, the present invention also provides a file management device based on an embedded system, comprising:
[0069] A writing module, for generating a second file on a disk and writing the content to be written into the second file when detecting that the application software needs to perform a write operation on the first file;
[0070] A backup module, used for backing up the first file to generate a first backup file;
[0071] A renaming module, used to rename the second file to the first file, and after the naming is completed, delete the first backup file;
[0072] A reading module, for determining whether a first backup file corresponding to the first file exists on the disk when it is detected that a read operation needs to be performed on the first file, so as to determine whether a previous write operation process of the first file is completed normally;
[0073] If it does not exist, determining that the last write operation process of the first file is completed normally, deleting the second file, and performing a read operation on the first file on the disk;
[0074] If it exists, it is determined that the last write operation process of the first file is not completed normally, the first file on the disk is restored, and a read operation is performed on the restored first file.
[0075] Please refer to Figure 4 , the reading module further includes: a first judgment unit, a second judgment unit, a first recovery reading unit and a second recovery reading unit;
[0076] A first judgment unit is used to judge whether there is a first backup file corresponding to the first file on the disk when it is detected that a read operation needs to be performed on the first file, so as to determine whether the last write operation process of the first file is completed normally;
[0077] A second judgment unit, configured to judge whether there is a second file corresponding to the first file on the disk when the last write operation process of the first file is not completed normally;
[0078] A first recovery reading unit is used for, when it is detected that a read operation needs to be performed on a first file, if a first backup file corresponding to the first file does not exist on the disk, determining that the last write operation process of the first file is completed normally, deleting a second file corresponding to the first file, and performing a read operation on the first file on the disk;
[0079] If a first backup file corresponding to the first file exists on the disk, determining that the last write operation process of the first file was not completed normally, restoring the first file on the disk, and performing a read operation on the restored first file;
[0080] A second recovery reading unit, configured to recover the first file on the disk according to the second file if the second file exists, when the last write operation process of the first file is not completed normally;
[0081] If the second file does not exist, the first file on the disk is restored according to the first backup file.
[0082] It should be noted that the first judgment unit, the second judgment unit, the first recovery reading unit and the second recovery reading unit cooperate to complete the reading and recovery of the file, thereby achieving the management and protection of the file.
[0083] In order to solve the same technical problem, the present invention also provides a terminal, including a processor, a memory and a computer program stored in the memory; wherein the computer program can be executed by the processor to implement the file management method based on the embedded system.
[0084] In order to solve the same technical problem, the present invention also provides a computer-readable storage medium, which includes a stored computer program; wherein, when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the file management method based on the embedded system.
[0085] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0086] The present invention provides a file management method, device, terminal and medium based on an embedded system, which is not limited by hardware and file system, has no specific requirements for the location of data stored on the memory, has compatibility with the file system, and is suitable for the management of small files. When a write operation needs to be performed on a first file, the management and protection of the file can be achieved by backing up the first file and generating a second file for writing new content, without the need to add additional software devices or perform excessive data backup.
[0087] Furthermore, when the file system is abnormally powered off, if it is determined that the last write operation of the first file was not completed normally, a recovery mechanism is used to read the original old file or continue the last latest progress to continue the file write operation. The present invention reduces the additional development of the operating system by upper-level users and software developers on the basis of compatibility, thereby reducing development costs.
[0088] The specific embodiments described above further illustrate the purpose, technical solutions and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. It is particularly pointed out that for those skilled in the art, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the scope of protection of the present invention.
Claims
1. A file management method based on an embedded system, characterized in that: include: When it is detected that the application software needs to perform a write operation on the first file, a second file is generated on the disk, the content to be written is written into the second file, and the first file is backed up to generate a first backup file; Rename the second file to the first file, and after the renaming is completed, delete the first backup file to complete the write operation process; Also includes: When it is detected that a read operation needs to be performed on the first file, determining whether a first backup file corresponding to the first file exists on the disk to determine whether a previous write operation process of the first file is completed normally; If not, determining that the last write operation process of the first file is completed normally, deleting the second file corresponding to the first file, and performing a read operation on the first file on the disk; If it exists, it is determined that the last write operation process of the first file is not completed normally, the first file on the disk is restored, and a read operation is performed on the restored first file.
2. The file management method based on embedded system according to claim 1, characterized in that: The file recovery of the first file on the disk is specifically: Determine whether a second file corresponding to the first file exists on the disk; If the second file exists, recovering the first file on the disk according to the second file; If the second file does not exist, the first file on the disk is restored according to the first backup file.
3. The file management method based on embedded system according to claim 2, characterized in that: The performing file recovery on the first file on the disk according to the second file is specifically: The second file is renamed as the first file, and the first backup file is deleted, so as to complete the file recovery of the first file on the disk.
4. The file management method based on embedded system according to claim 2, characterized in that: The performing file recovery on the first file on the disk according to the first backup file is specifically: The first backup file is renamed as the first file, and the file recovery of the first file on the disk is completed.
5. A file management device based on an embedded system, characterized in that: include: Write module, backup module, rename module and read module; The writing module is used to generate a second file on the disk and write the content to be written into the second file when detecting that the application software needs to perform a write operation on the first file; The backup module is used to back up the first file to generate a first backup file; The renaming module is used to rename the second file to the first file, and after the naming is completed, delete the first backup file; The reading module is used to determine whether a first backup file corresponding to the first file exists on the disk when it is detected that a read operation needs to be performed on the first file, so as to determine whether the last write operation process of the first file is completed normally; If it does not exist, determining that the last write operation process of the first file is completed normally, deleting the second file, and performing a read operation on the first file on the disk; If it exists, it is determined that the last write operation process of the first file is not completed normally, the first file on the disk is restored, and a read operation is performed on the restored first file.
6. The file management device based on embedded system according to claim 5, characterized in that: The reading module comprises: a first judgment unit, a second judgment unit, a first recovery reading unit and a second recovery reading unit; Wherein, the first judgment unit is used to judge whether there is a first backup file corresponding to the first file on the disk when it is detected that a read operation needs to be performed on the first file, so as to determine whether the last write operation process of the first file is completed normally; The second judgment unit is used to judge whether there is a second file corresponding to the first file on the disk when the last write operation process of the first file is not completed normally; The first recovery reading unit is used for, when detecting that a read operation needs to be performed on the first file, if a first backup file corresponding to the first file does not exist on the disk, determining that the last write operation process of the first file is completed normally, deleting the second file corresponding to the first file, and performing a read operation on the first file on the disk; If a first backup file corresponding to the first file exists on the disk, determining that the last write operation process of the first file was not completed normally, restoring the first file on the disk, and performing a read operation on the restored first file; The second recovery reading unit is used for, when the last write operation process of the first file is not completed normally, recovering the first file on the disk according to the second file if the second file exists; If the second file does not exist, the first file on the disk is restored according to the first backup file.
7. A terminal, characterized in that: It comprises a processor, a memory and a computer program stored in the memory; wherein the computer program can be executed by the processor to implement the file management method based on the embedded system as described in any one of claims 1 to 4.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program; wherein, when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the file management method based on an embedded system as described in any one of claims 1 to 4.
