File management method and device, equipment and storage medium
By using memory to generate write operation results and write flags in an embedded system, a file management method of taking turns to write between the first file and the second file is realized, which solves the problem of file corruption during power outage, and improves file security and storage efficiency.
Patent Information
- Application Number
- CN202510050749.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-13
- Publication Date
- 2025-04-15
AI Technical Summary
File storage in embedded systems is easily damaged when power is out, and prior art hardware and software solutions have problems of high cost and low efficiency.
By generating the operation execution result of the write operation request in memory and using the write flag to write it in turn between the first file and the second file, it is ensured that only one file is being written at any time, thereby realizing mutual backup of files.
Even in the case of power outage, the file is corrupted and the data that loses the write operation at most is lost, which improves the security and storage efficiency of the file and meets the needs of embedded systems with frequent operations and high real-time requirements.
Smart Images

Figure CN119829334A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data storage, and mainly to a file management method, device, equipment and storage medium. Background Art
[0002] In embedded systems, file storage is a common storage method. Various configuration data and operating parameters are mostly stored in the file system in the form of files. However, the embedded file system has limited power-off protection for files. Abnormal power failure often causes file corruption, which in turn causes device malfunction.
[0003] In order to solve this problem, part of the related technology is solved from the hardware: adding capacitors, when the power is abnormally cut off, the capacitors are powered, and the modules with writing tasks receive the power-off signal, and the unwritten data continues to be written into the file to ensure the integrity of the file. This method is simple and effective, but it will increase the hardware cost. Another part is solved by software: for example, when writing, back up the file in two copies, one for file writing and one for file backup. When writing, write the data to the backup file for file writing. After writing, rename the written backup file to the original file name and delete the backup file. This method can solve the problem of file corruption during power outages, but one write requires multiple IO operations: two file copies, one file read, one file rename, and one backup file deletion. Since the IO operation time is much higher than that of memory, in a system where file writing is more frequent and real-time requirements are higher, the writing process is time-consuming and inefficient, and cannot meet storage requirements.
[0004] Therefore, for embedded systems, how to easily implement power-off protection for files is a difficult problem that needs to be solved. Summary of the invention
[0005] One of the purposes of the present application is to provide a file management method to solve or at least partially solve the problems in the related art. The second purpose of the present application is to provide a file management device, the third purpose of the present application is to provide an electronic device, and the fourth purpose of the present application is to provide a medium.
[0006] In order to achieve the above purpose, the technical solution of this application is as follows: A file management method, characterized in that the method comprises: Generate an operation execution result corresponding to the current write operation request in the second memory block according to the current write operation request and the file content in the first memory block; Determine whether the write flag in the first memory block indicates a first file; the write flag is used to indicate the file to be written during update; When the write flag indicates the first file, updating the first file according to the operation execution result; When the update of the first file is completed, the write flag is adjusted to indicate that the file to be written during the update is the second file; and according to the operation execution result, the file content in the first memory block is updated.
[0007] Optionally, the parameter of the write flag is 0 or 1; and determining whether the write flag in the first memory block indicates the first file includes: In a case where the parameter of the write flag is 0, determining that the write flag indicates the first file; In a case where the parameter of the write flag is 1, it is determined that the write flag indicates the second file.
[0008] Optionally, when the write flag indicates the first file, updating the first file according to the operation execution result includes: When the parameter of the write flag is 0, clear the content of the first file; The operation execution result is copied to the first file.
[0009] Optionally, before generating the operation execution result corresponding to the current write operation request in the second memory block according to the current write operation request and the file content in the first memory block, the method further includes: Detecting whether the first file corresponds to the second file; In the case that the first file has a corresponding second file, determining a target file of the latest version from the first file and the second file according to timestamps of the first file and the second file; The content of the target file is extracted into the first memory block, and the write flag is adjusted to indicate that the file to be written during the update is another file.
[0010] Optionally, when the first file has a corresponding second file, determining the latest version of the target file from the first file and the second file according to timestamps of the first file and the second file includes: In the case that both the first file and the second file have timestamps, determining the one with a later timestamp between the first file and the second file as the target file; In the case that one of the first file and the second file does not have a timestamp, the one of the first file and the second file that has a timestamp is determined as the target file.
[0011] Optionally, after updating the file content in the first memory block according to the operation execution result, the method further includes: Receive a read operation request; In response to the read operation request, data is read from the first memory block.
[0012] Optionally, generating, in the second memory block, an operation execution result corresponding to the current write operation request according to the current write operation request and the file content in the first memory block, includes: Applying for the second memory block; In response to the current write operation request, copy the file content in the first memory block to the second memory block; Execute the write operation corresponding to the current write operation request on the file content in the second memory block, and generate the operation execution result; A file end mark is added to the operation execution result; the file end mark is used to indicate that there is updated complete data in the second memory block.
[0013] A file management device, comprising: A generating module, used for generating an operation execution result corresponding to the current write operation request in the second memory block according to the current write operation request and the file content in the first memory block; A determination module, used to determine whether the write flag in the first memory block indicates a first file; the write flag is used to indicate a file to be written during update; An updating module, configured to update the first file according to the operation execution result when the write flag indicates the first file; The adjustment module is used to adjust the write flag to indicate that the file to be written during the update is the second file when the update of the first file is completed; and update the file content in the first memory block according to the operation execution result.
[0014] An electronic device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned file management method when executing the computer program.
[0015] A non-volatile storage medium stores a computer program, which implements the above-mentioned file management method when executed by a processor.
[0016] Beneficial effects of this application: In the present application, an operation execution result corresponding to the current write operation request is generated in the second memory block according to the current write operation request and the file content in the first memory block; it is determined whether the write flag in the first memory block indicates the first file; the write flag is used to indicate the file to be written when updating; when the write flag indicates the first file, the first file is updated according to the operation execution result; when the first file is updated, the write flag is adjusted to indicate that the file to be written when updating is the second file, and the file content in the first memory block is updated according to the operation execution result; in this way, according to the write flag, writing is performed alternately between the first file and the second file in a zigzag manner, and it is ensured that at the same time, only one of the first file and the second file is being written, so as to achieve the purpose of backing up the two files with each other. Even if the file is damaged in the case of power failure, at most the data of the write operation is lost. In this way, the needs of embedded systems with frequent operations and high real-time requirements can be met, the security of the file is improved, and the power-off protection of the file is conveniently realized. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0018] Figure 1 is a flow chart of a file management method described in an embodiment of the present application; Figure 2 is a schematic diagram of a writing result of the file management method described in an embodiment of the present application; Figure 3 It is a logical diagram of data writing of the file management method described in one embodiment of the present application; Figure 4 It is a data loading logic diagram of the file management method described in one embodiment of the present application; Figure 5 It is a schematic diagram of the framework of the file management device described in one embodiment of the present application.
[0019] Among them, 500-file management device, 501-generation module, 502-determination module, 503-update module, 504-adjustment module. DETAILED DESCRIPTION
[0020] The following will describe the implementation methods of the present application with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand other advantages and effects of the present application from the contents disclosed in this specification. The present application can also be implemented or applied through other different specific implementation methods, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present application. It should be understood that the preferred embodiments are only for illustrating the present application, not for limiting the scope of protection of the present application.
[0021] Reference Figure 1 , Figure 1 FIG. 1 is a flow chart of a file management method described in an embodiment of the present application. Figure 1 As shown, the file management method is applied to an embedded system and is specifically performed in the following steps: Step S101: Generate an operation execution result corresponding to the current write operation request in the second memory block according to the current write operation request and the file content in the first memory block.
[0022] Specifically, a write operation request is a request to perform a write operation on a file in the system (for example, deleting, modifying, replacing, or adding data in a file). In response to the write operation, the file will be updated. A corresponding backup file exists for a certain file. The file content in the first memory block is the complete content contained in the latest version of this file and its backup file; therefore, according to the current write operation request and the file content in the first memory block, the file content in the first memory block is first copied in the second memory block, and then the write operation corresponding to the write operation request is performed in the second memory block, thereby generating the operation execution result corresponding to the write operation request in the second memory block. The operation execution result is the complete file content updated according to the current write operation.
[0023] By first executing the write operation in the memory through the first memory block and the second memory block, not only can it be detected whether the write operation can be successfully executed, but also because the memory operation takes less time than the IO operation, the execution efficiency of the write operation can be improved.
[0024] Step S102: determine whether the write flag in the first memory block indicates a first file.
[0025] The write flag is used to indicate the file to be written during the update.
[0026] Specifically, the first memory block not only loads the latest version of the complete file content, but also records a write flag, which is used to indicate the file to be written during the update, that is, to determine which of the first file and the second file is the file to be updated during the update, and which file to perform the write operation on.
[0027] The first file and the second file are backup files of each other. Only one of the first file and the second file can be written and updated at the same time. In the process of continuous alternating updates, the file contents of the two files differ by one write operation. When it is necessary to update a file, the present application proposes that when an update is required, the write flag is used to determine which file is to be written and updated, and the other file is not updated. Even if the system is powered off during the writing process, data can be restored through the other file.
[0028] In a feasible implementation manner, the parameter of the write flag is 0 or 1; the above step S102, determining whether the write flag in the first memory block indicates the first file, includes: In a case where the parameter of the write flag is 0, determining that the write flag indicates the first file; In a case where the parameter of the write flag is 1, it is determined that the write flag indicates the second file.
[0029] In this embodiment, there are two parameters of the write flag (such as 0 and 1), which correspond to the first file and the second file respectively. If the parameter of the write flag corresponds to the first file, the write flag indicates the first file, and the first file is updated for this write operation; if the parameter of the write flag corresponds to the second file, the write flag indicates the second file, and the second file is updated for this write operation. By setting the write flag, when updating files, the first file and the second file are written in turn, and only one file is written each time, so that the first file and the second file are backup files of each other.
[0030] Step S103: when the write flag indicates the first file, update the first file according to the operation execution result.
[0031] Specifically, if the write flag indicates the first file, that is, the first file is updated, then the update of the first file can be completed according to the operation execution result stored in the second memory block (that is, the complete file content obtained after the write operation corresponding to the current write operation request is executed).
[0032] In a feasible implementation manner, following the above implementation manner, when the write flag indicates the first file, updating the first file according to the operation execution result includes: When the parameter of the write flag is 0, clear the content of the first file; The operation execution result is copied to the first file.
[0033] In this embodiment, when the write flag indicates the first file, the content of the first file is cleared first, and then the updated file content (operation execution result) in the second memory block is copied to the first file, that is, the first file is written in a truncate manner (the file content is cleared if the file exists). Since the files stored in the embedded system are various configuration data and operating parameters, the storage space occupied by the file is very small. When the first file is written in a truncate manner, the write failure caused by the limitation of some file formats can be avoided, thereby quickly completing the update of the first file.
[0034] Step S104: when the update of the first file is completed, the write flag is adjusted to indicate that the file to be written during the update is the second file, and the file content in the first memory block is updated according to the operation execution result.
[0035] Specifically, after updating the first file and the second file that are backup files of each other according to the write flag, the write flag is adjusted so that the write flag indicates that the file to be written in the next update is the second file. In this way, when the file is updated according to the next write operation, the second file is updated, and the write flag is adjusted again so that when the file is updated according to the next write operation, the first file is updated, and so on... Reference Figure 2 , Figure 2 Schematic diagram of the writing result of the file management method described in one embodiment of the present application. Figure 2 , further illustrating the file management effect of this application. Figure 2 As shown, WIDX is a write flag, FILE is the first file, FILE1 is the second file, and the updated content is the operation data corresponding to the current write operation. When WIDX is 0, it indicates that the first file FILE is updated the next time the file is updated according to the write operation; when WIDX is 1, it indicates that the second file FILE1 is updated the next time the file is updated according to the write operation.
[0036] Assuming that the content of a file is empty in the initial state, the parameter of the write flag in the memory is 0.
[0037] The first write operation needs to write A=0, so A=0 is written to the first file according to "WIDX=0", and the second file is not written. The latest content "A=0" and the adjusted write flag "WIDX=1" are retained in the memory; The second write operation needs to write A=1, so A=1 is written to the second file according to "WIDX=1", and the first file is not written. After the second file is written, the content saved in the memory is the latest version of the file content "A=1", and the write flag is adjusted again, so that "WIDX=0"; In the third write operation, B=1 is written, so "B=1" is written to the first file according to "WIDX=0", and the second file is not written. The content saved in the memory is the latest version of the complete file content, and the flag is written again after adjustment, so that "WIDX=1"; and so on... After a file is updated, the file content in the first memory block is updated according to the operation execution result, that is, the operation execution result is written into the first memory block, so that the first memory block is always loaded with the complete file content of the latest version. Therefore, each write operation can be executed based on the file content in the first memory block, and then the file is updated to the latest version according to the obtained operation execution result, thereby ensuring the data consistency of the first file and the second file.
[0038] In this embodiment, the operation execution result corresponding to the current write operation request is generated in the second memory block according to the current write operation request and the file content in the first memory block; it is determined whether the write flag in the first memory block indicates the first file; the write flag is used to indicate the file to be written when updating; when the write flag indicates the first file, the first file is updated according to the operation execution result; when the update of the first file is completed, the write flag is adjusted to indicate that the file to be written when updating is the second file, and the file content in the first memory block is updated according to the operation execution result; in this way, according to the write flag, writing is performed alternately between the first file and the second file in a zigzag manner, and it is ensured that at the same time, only one file of the first file and the second file is being written, so as to achieve the purpose of backing up the two files with each other. Even if the file is damaged in the case of power failure, at most the data of the write operation is lost. In this way, the needs of embedded systems with frequent operations and high real-time requirements can be met, the security of the file is improved, and the power-off protection of the file is conveniently realized.
[0039] In a feasible implementation manner, the above step S101, based on the current write operation request and the file content in the first memory block, generates the operation execution result corresponding to the current write operation request in the second memory block, including the following steps: Applying for the second memory block; In response to the current write operation request, copy the file content in the first memory block to the second memory block; Execute the write operation corresponding to the current write operation request on the file content in the second memory block, and generate the operation execution result; A file end mark is added to the operation execution result; the file end mark is used to indicate that there is updated complete data in the second memory block.
[0040] Specifically, the first memory block is loaded with the latest version of the complete file content and the write mark. When the file needs to be written, a new second memory block is applied for. In response to the current write operation request, the file content in the first memory block is copied to the second memory block; for the file content in the second memory block, the write operation corresponding to the current write operation request is performed, and the operation execution result is generated in the second memory block. In this way, the file content in the first memory block and the updated content are merged into the second memory block, and the file end mark is added to the second memory block. The end mark is mainly used to verify the integrity and timeliness of the file. In this embodiment, the file end mark is represented by a timestamp to facilitate the start of writing to the file.
[0041] In this embodiment, the write operation is pre-executed in the memory and the operation execution result is obtained, which not only reduces the IO operations, but also executes the write operation in the second memory block to avoid the damage to the first memory block caused by the failure of the write operation execution. In this way, by successfully completing the write operation in the memory before writing the file, unnecessary IO operations are reduced, the file content is further protected, and the security of the file is improved.
[0042] In one embodiment of the present application, after updating the file content in the first memory block according to the operation execution result, the file management method further includes: Receive a read operation request; In response to the read operation request, data is read from the first memory block.
[0043] Specifically, after adjusting the write flag, the updated complete file content is reloaded into the first memory block. At this time, the first memory block stores the current latest version of the file content and the adjusted write flag. When the file is updated according to the write operation next time, the file management method described in the previous embodiment is supported. Due to the latest version of the file content in the first memory block, when a read operation request for the file is received, data can be directly read from the first memory block.
[0044] Reference Figure 3 , Figure 3 Schematic diagram of data writing logic of the file management method described in one embodiment of the present application. Figure 3In the example, the memory block MEM is the first memory block, MEM1 is the second memory block, WIDX is the write flag, FILE is the first file, FILE1 is the second file, and the updated content is the operation data corresponding to the current write operation. When WIDX is 0, it indicates that the first file FILE is updated when the file is updated according to the write operation next time; when WIDX is 1, it indicates that the second file FILE1 is updated when the file is updated according to the write operation next time. When the file update is completed and the write flag is adjusted, the result of the operation is loaded into the first memory block. The first memory block then stores the complete file content and can support the read operation of the file.
[0045] In this embodiment, the first memory block with complete file content is loaded to respond to the read operation of the file, thus replacing the IO operation with the memory operation, reducing the time of the read operation and improving the data processing speed of the embedded system.
[0046] In one embodiment of the present application, in step S101, before generating the operation execution result corresponding to the current write operation request in the second memory block according to the current write operation request and the file content in the first memory block, the file management method further includes the following steps: Step S201, detecting whether the first file corresponds to the second file.
[0047] Specifically, the first file and the second file are backup files of each other, and if the file corresponding to the write operation request has no backup file, the technical solution cannot be implemented. Therefore, before executing the technical solution, it is necessary to detect whether the first file has a corresponding second file that is a backup file of each other.
[0048] Step S202: if the first file has a corresponding second file, determine the latest version of the target file from the first file and the second file according to the timestamps of the first file and the second file.
[0049] Specifically, if both the first file and the second file exist, the timestamps of the last writes of the first file and the second file are determined. In this way, it is determined which of the first file and the second file has the content of the latest version of the complete file (i.e., the target file), so as to perform the write operation on the latest version of the file and ensure the normal execution of the write operation.
[0050] In a feasible implementation manner, in step S202, when the first file has a corresponding second file, determining the latest version of the target file from the first file and the second file according to the timestamps of the first file and the second file includes: In the case that both the first file and the second file have timestamps, determining the one with a later timestamp between the first file and the second file as the target file; In the case that one of the first file and the second file does not have a timestamp, the one of the first file and the second file that has a timestamp is determined as the target file.
[0051] Specifically, further reference Figure 4 , Figure 4 FIG. 1 is a data loading logic diagram of the file management method described in an embodiment of the present application. Figure 4 As shown, the memory block MEM is the first memory block, MEM1 is the second memory block, WIDX is the write flag, FILE is the first file, FILE1 is the second file, and the update content is the operation data corresponding to the current write operation. When WIDX is 0, it indicates that the first file FILE is updated when the file is updated according to the write operation next time; when WIDX is 1, it indicates that the second file FILE1 is updated when the file is updated according to the write operation next time. Before the file management method starts to execute, data loading is required.
[0052] exist Figure 4 When the file starts to be loaded, first 1) check whether the backup file FILE1 of the file FILE exists. If it does not exist, go to step 2). If it exists, go to step 3).
[0053] 2) Copy the FILE file and name the new file FILE1. Load the FILE file content into the memory MEM and set the write flag WIDX to 1.
[0054] 3) Get the file end timestamps of files FILE and FILE1. Let the end timestamp of FILE be T and the end timestamp of FILE1 be T1. If T exists but T1 does not, then load the content of FILE into MEM and set WIDX to 1. If T1 exists but T does not, then load the content of FILE1 into MEM and set WIDX to 0. If both T and T1 exist, then compare the sizes of T and T1. If T is greater than T1, it means that the last write operation of the file occurred on FILE and the content of FILE is newer. Load the content of FILE into the memory MEM and set WIDX to 1. If T1 is greater than T, it means that FILE1 is newer. Load the content of FILE1 into MEM and set WIDX to 0.
[0055] In this way, when the program is started, the file loading is completed, and on this basis, the execution of the file management method is supported.
[0056] In this implementation, based on the timestamps of the first file and the second file, it is determined which of the first file and the second file records the file content of a newer version, so as to load data into the first memory block.
[0057] Step S203: extract the content of the target file into the first memory block, and adjust the write flag to indicate that the file to be written during the update is another file.
[0058] Specifically, after determining the target file, the content of the target file is loaded into the first memory block, so that the file content in the first memory block is the complete content of the latest version, so as to perform the write operation in the memory. After determining that one of the first file and the second file is the target file, the other file is the file to be written in the next update. Figure 2 Based on the setting of this write flag, after the next update, the difference between the first file and the second file is a write operation. In this way, the consistency of the files is guaranteed.
[0059] In addition, the file management method further includes: if the first file does not have a corresponding second file, generating a second file corresponding to the first file according to the first file. It can be understood that at this time, the content of the first file is copied to the second file, that is, a corresponding backup file is generated.
[0060] In this embodiment, before executing the write operation, the first file and the second file are loaded first, and the complete file content of the latest version is loaded in the first memory block and the parameters of the write flag are determined. In this way, when the write operation is detected and the file content needs to be updated, the two files are written in a Z-shape in turn on this basis to achieve mutual backup of the files. Even if there is a sudden abnormal power outage, only the file written this time is damaged, and the content written last time is fully saved in another file, so that the content written last time can be restored from another file, ensuring minimal file loss.
[0061] Reference Figure 5 , Figure 5 Schematic diagram of the framework of the file management device described in one embodiment of the present application. Figure 5 In one embodiment of the present application, based on the same or similar technical concept as the above embodiment, a file management device 500 is proposed, the device comprising: A generating module 501, configured to generate an operation execution result corresponding to the current write operation request in the second memory block according to the current write operation request and the file content in the first memory block; A determination module 502 is used to determine whether a write flag in the first memory block indicates a first file; the write flag is used to indicate a file to be written during update; An updating module 503 is configured to update the first file according to the operation execution result when the write flag indicates the first file; The adjustment module 504 is used to adjust the write flag to indicate that the file to be written during the update is the second file when the update of the first file is completed, and update the file content in the first memory block according to the operation execution result.
[0062] In this embodiment, the operation execution result corresponding to the current write operation request is generated in the second memory block according to the current write operation request and the file content in the first memory block; it is determined whether the write flag in the first memory block indicates the first file; the write flag is used to indicate the file to be written when updating; when the write flag indicates the first file, the first file is updated according to the operation execution result; when the update of the first file is completed, the write flag is adjusted to indicate that the file to be written when updating is the second file, and the file content in the first memory block is updated according to the operation execution result; in this way, according to the write flag, writing is performed alternately between the first file and the second file in a zigzag manner, and it is ensured that at the same time, only one file of the first file and the second file is being written, so as to achieve the purpose of backing up the two files with each other. Even if the file is damaged in the case of power failure, at most the data of the write operation is lost. In this way, the needs of embedded systems with frequent operations and high real-time requirements can be met, the security of the file is improved, and the power-off protection of the file is conveniently realized.
[0063] In a feasible implementation manner, the parameter of the write flag is 0 or 1; the determination module 502 includes: A first determining module, configured to determine, when the parameter of the write flag is 0, that the write flag indicates the first file; The second determining module is used to determine, when the parameter of the write flag is 1, that the write flag indicates the second file.
[0064] In a feasible implementation manner, the updating module 503 includes: A clearing module, used for clearing the content of the first file when the parameter of the write flag is 0; A first copying module is used to copy the operation execution result to the first file.
[0065] In a feasible implementation manner, the device 500 further includes: A detection module, used to detect whether the first file corresponds to the second file; a target file selection module, configured to determine the latest version of the target file from the first file and the second file according to timestamps of the first file and the second file when the first file corresponds to the second file; The content loading module is used to extract the content of the target file into the first memory block, and adjust the write flag to indicate that the file to be written during the update is another file.
[0066] In a feasible implementation manner, the target file selection module includes: A first selection module is used for determining the one with a later timestamp between the first file and the second file as the target file when both the first file and the second file have timestamps; The second selection module is used to determine the one of the first file and the second file with a timestamp as the target file when one of the first file and the second file does not have a timestamp.
[0067] In a feasible implementation manner, the device 500 further includes: A read operation receiving module, used for receiving a read operation request; A read operation response module is used to read data from the first memory block in response to the read operation request.
[0068] In a feasible implementation manner, the generating module 501 includes: An allocation module, used for applying for the second memory block; A second copy module, configured to copy the file content in the first memory block to the second memory block in response to the current write operation request; an execution module, configured to execute the write operation corresponding to the current write operation request on the file content in the second memory block, and generate the operation execution result; An adding module is used to add a file end mark to the operation execution result; the file end mark is used to indicate that there is updated complete data in the second memory block.
[0069] In the present application, the description of the device embodiment is relatively short, and specific details can be referred to the above method embodiment, which will not be repeated here.
[0070] In one embodiment of the present application, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned file management method when executing the computer program.
[0071] In one embodiment of the present application, a non-volatile storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the file management method as described in the above embodiment is implemented.
[0072] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0073] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the embodiments of the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0074] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0075] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0076] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1The steps for the functions specified in one or more boxes.
[0077] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.
[0078] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0079] The above is a detailed introduction to the provided file management method, device, electronic device and medium. Specific examples are used in this article to illustrate the principles and embodiments of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific embodiments and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A file management method, characterized in that: The method comprises: Generate an operation execution result corresponding to the current write operation request in the second memory block according to the current write operation request and the file content in the first memory block; Determine whether the write flag in the first memory block indicates a first file; the write flag is used to indicate the file to be written during update; When the write flag indicates the first file, updating the first file according to the operation execution result; When the update of the first file is completed, the write flag is adjusted to indicate that the file to be written during the update is the second file; and according to the operation execution result, the file content in the first memory block is updated.
2. The method according to claim 1, characterized in that: The parameter of the write flag is 0 or 1; and determining whether the write flag in the first memory block indicates the first file includes: In a case where the parameter of the write flag is 0, determining that the write flag indicates the first file; In a case where the parameter of the write flag is 1, it is determined that the write flag indicates the second file.
3. The method according to claim 2, characterized in that When the write flag indicates the first file, updating the first file according to the operation execution result includes: When the parameter of the write flag is 0, clear the content of the first file; The operation execution result is copied to the first file.
4. The method according to claim 1, characterized in that: Before generating an operation execution result corresponding to the current write operation request in the second memory block according to the current write operation request and the file content in the first memory block, the method further includes: Detecting whether the first file corresponds to the second file; In a case where the first file has a corresponding second file, determining a target file of the latest version from the first file and the second file according to timestamps of the first file and the second file; The content of the target file is extracted into the first memory block, and the write flag is adjusted to indicate that the file to be written during the update is another file.
5. The method according to claim 4, characterized in that The determining, when the first file has a corresponding second file, the latest version of the target file from the first file and the second file according to the timestamps of the first file and the second file, comprises: In the case that both the first file and the second file have timestamps, determining the one with a later timestamp between the first file and the second file as the target file; In the case that one of the first file and the second file does not have a timestamp, the one of the first file and the second file that has a timestamp is determined as the target file.
6. The method according to claim 1, characterized in that After updating the file content in the first memory block according to the operation execution result, the method further includes: Receive a read operation request; In response to the read operation request, data is read from the first memory block.
7. The method according to claim 1, characterized in that The step of generating, in the second memory block, an operation execution result corresponding to the current write operation request according to the current write operation request and the file content in the first memory block, comprises: Applying for the second memory block; In response to the current write operation request, copy the file content in the first memory block to the second memory block; Execute the write operation corresponding to the current write operation request on the file content in the second memory block, and generate the operation execution result; A file end mark is added to the operation execution result; the file end mark is used to indicate that there is updated complete data in the second memory block.
8. A file management device, characterized in that: The device comprises: A generating module, used for generating an operation execution result corresponding to the current write operation request in the second memory block according to the current write operation request and the file content in the first memory block; A determination module, used to determine whether the write flag in the first memory block indicates a first file; the write flag is used to indicate a file to be written during update; An updating module, configured to update the first file according to the operation execution result when the write flag indicates the first file; The adjustment module is used to adjust the write flag to indicate that the file to be written during the update is the second file when the update of the first file is completed; and update the file content in the first memory block according to the operation execution result.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the file management method according to any one of claims 1 to 7 is implemented.
10. A non-volatile storage medium, characterized in that: A computer program is stored thereon, and when the program is executed by a processor, the file management method as described in any one of claims 1 to 7 is implemented.