This application claims the priority benefit of Taiwan application serial no. 106132398, filed on Sep. 21, 2017. The entirety of the above-mentioned patent application is hereby incorporated by reference herein and made a part of this specification.
The present disclosure relates to a data access method and an electronic apparatus applying the method, in particular, to a data access method of transactional file system and an electronic apparatus applying the method.
A file system of a file allocation table (FAT) may be used on a consumption type mobile device, and a file may be operated by using an application programming interface (API) of a standard file system of Microsoft. Therefore, the file system of the FAT realizes an effect that a storage unit of a mobile device uses the same file system with a desktop computer. However, on the mobile device, power-off protection of the file system of the FAT is not perfect. Because the mobile device is an apparatus with low electric quantity and is in an environment with power-off crisis for a long time, when power failure occurs, the file system of the FAT is damaged, causing the state that all file data cannot be accessed.
Therefore, the present disclosure provides a data access method of transactional file system and an electronic apparatus applying the method, and provides a capacity of fail-safe of a file system of an FAT on a mobile device.
The present disclosure provides a data access method of transactional file system, which is applied to an electronic apparatus with a storage unit. The storage unit stores a transaction point table, wherein the transaction point table has a plurality of transaction points. The method includes the following steps: selecting a valid transaction point as a first transaction point from the transaction points of the transaction point table; copying information in the first transaction point to a second transaction point in the transaction points, and executing a data access operation according to the information in the second transaction point; and executing a commit instruction when the data access operation is completed, and setting the second transaction point as a valid transaction point according to the commit instruction.
In one embodiment of the present disclosure, when failure occurs in the process of executing the data access operation, the storage unit is restored to a state in which the data access operation is not executed by using the information in the first transaction point.
In one embodiment of the present disclosure, wherein the step of executing the data access operation includes: copying first data corresponding to the first transaction point to generate second data, and storing the second data to a first cluster of the storage unit; using a first flag to mark a second cluster configured to store the first data and a file path of the first data in the storage unit; and executing data access operation on the second data.
In one embodiment of the present disclosure, wherein after the step of setting the second transaction point as a valid transaction point according to the commit instruction, the method further includes: using a second flag to mark a second cluster configured to store the first data and the file path of the first data so as to release a space of the second cluster.
In one embodiment of the present disclosure, wherein the step of copying information in the first transaction point to a second transaction point in the transaction points includes: generating a count value and recording the count value into the second transaction point, and the count value in the second transaction point is greater than count values of other transaction points in the transaction point table.
In one embodiment of the present disclosure, wherein the step of setting the second transaction point as a valid transaction point according to the commit instruction includes: generating check information according to the information in the second transaction point and the count value in the second transaction point, and recording the check information to the second transaction point.
In one embodiment of the present disclosure, wherein the second transaction point in the transaction point table is a next transaction point of the first transaction point.
In one embodiment of the present disclosure, wherein each of the transaction points includes a transaction file allocation table and a file information table.
In one embodiment of the present disclosure, wherein the count value of the valid transaction point is greater than count values of other transaction points in the transaction point table, and the valid transaction point includes correct check information.
The disclosure provides an electronic apparatus. The electronic apparatus includes a storage unit and a processing unit. The storage unit stores a transaction point table, wherein the transaction point table includes a plurality of transaction points. When the processing unit executes data access operation, the processing unit selects a valid transaction point as a first transaction point from the abovementioned transaction points. The processing unit copies information in the first transaction point to a second transaction point in the abovementioned transaction points, and executes the data access operation according to the information in the second transaction point. When the data access operation is completed, the processing unit executes a commit instruction, and sets the second transaction point as a valid transaction point according to the commit instruction.
In one embodiment of the present disclosure, when failure occurs in the process of executing the data access operation, the processing unit restores the storage unit to a state in which the data access operation is not executed by using the information in the first transaction point.
In one embodiment of the present disclosure, wherein in the process of executing the data access operation, the processing unit copies first data corresponding to the first transaction point to generate second data, and stores the second data to a first cluster of the storage unit. The processing unit uses a first flag to mark a second cluster configured to store the first data and the file path of the first data in the storage unit. Then the processing unit executes the data access operation on the second data.
In one embodiment of the present disclosure, wherein after the operation of setting the second transaction point as a valid transaction point according to the commit instruction, the processing unit uses a second flag to mark a second cluster configured to store the first data and the file path of the first data so as to release a space of the second cluster.
In one embodiment of the present disclosure, wherein in the operation of copying the information in the first transaction point to a second transaction point in the transaction points, the processing unit generates a count value and records the count value into the second transaction point, and the count value in the second transaction point is greater than the count values of other transaction points in the transaction point table.
In one embodiment of the present disclosure, wherein in the operation of setting the second transaction point as a valid transaction point according to the commit instruction, the processing unit generates check information according to the information in the second transaction point and the count value in the second transaction point, and records the check information to the second transaction point.
In one embodiment of the present disclosure, the second transaction point in the transaction point table is a next transaction point of the first transaction point.
In one embodiment of the present disclosure, each of the transaction points includes a transaction file allocation table and a file information table.
In one embodiment of the present disclosure, wherein a count value of a valid transaction point is greater than count values of other transaction points in the transaction point table, and the valid transaction point includes correct check information.
Based on the above, the disclosure provides the data access method of transactional file system and the electronic apparatus applying the method, and when a user accesses data, a file system enters a start transaction state. When all access actions in transaction have been successfully executed, commit of establishment of a new valid transaction point will be started. When establishment of the new valid transaction point is completed, the system will enter a committed state, and at the moment, next transaction may be performed. When unpredictable conditions such as power failure and crash occur at the system, the file system may return to a correct state of transaction or a correct state before the data access operation again. Therefore, the disclosure provides the capacity of fail-safe of the file system of an FAT on a mobile device.
In order to make the aforementioned and other objectives and advantages of the present disclosure comprehensible, embodiments accompanied with figures are described in detail below.
The processing unit 112 may be a central processing unit (CPU), or other programmable microprocessors for a general purpose or special purpose, a digital signal processor (DSP), a programmable controller, an application specific integrated circuit (ASIC) or other similar elements or combination of the elements.
The storage unit 114 may be a stationary or mobile random access memory (RAM) of any type, a read-only memory (ROM), a flash memory or similar elements or combination of the elements. In the present exemplary embodiment, the storage unit 114 of the electronic apparatus 100 may store a plurality of program code segments, and after being installed, the program code segments may be executed by the processing unit 112. For example, the storage unit of the electronic apparatus 100 includes a plurality of modules, and these modules respectively execute various operations of the electronic apparatus 100, wherein each module is formed by one or a plurality of program code segments. However, the present invention is not limited to above description, and various operations of the electronic apparatus 100 may also be implemented by other hardware forms.
Particularly, in an exemplary embodiment of the present invention, the storage unit 114 further includes a transaction point table and a data cluster. Specifically,
Referring to
In addition, each transaction point in the transaction point table 200 may include a transaction file allocation table and a file information table. Particularly,
Referring to
In addition, in the transaction point table 200, a next transaction point of the newest valid transaction point is the oldest transaction point (that is, the transaction point with the minimum count value). In other words, transaction points in the transaction point table 200 are logically arranged in an annular sequence. For example, assuming that the count value 30 of the transaction point 20a is greater than count values of other transaction points in the transaction point table 200, the sequence from the transaction point with the minimum count value (that is, the oldest transaction point) to the transaction point with the maximal count value (that is, the newest transaction point) is transaction point 20b, transaction point 20c, transaction point 20d, transaction point 20e, transaction point 20f, transaction point 20g, transaction point 20h and transaction point 20a.
The file information table 320a is mainly used for storing file information stored in the data cluster 210. The file information, for example, includes a file name and file information. The file information, for example, may include a file start location of a file stored in the data cluster 210, file size and modification time, etc. The processing unit 112 may find a complete file needing to be accessed by using the file start location in the file information table 320a, a flag of each data cluster in the transaction file allocation table 310a or a linkage state of data stored in the clusters.
Referring to
In the present exemplary embodiment, when the processing unit 112 needs to execute a data access operation, firstly, the electronic apparatus 100 may enter a transaction start state. At the moment, the processing unit 112 may select a valid transaction point as a first transaction point from transaction points 20a-20h. In the present exemplary embodiment, a count value of a valid transaction point is greater than count values of other transaction points in the transaction point table, and the valid transaction point includes correct check information. That is, the first transaction point is a newest valid transaction point. Assuming that the processing unit 112 selects the transaction point 20a as the first transaction point, then the count value of the transaction point 20a may be greater than count values of other transaction points in the transaction point table 200 and the transaction point 20a includes comet check information.
After the transaction point 20a is selected as the abovementioned first transaction point, the processing unit 112 may copy information (that is, the transaction file allocation table and the file information table of the transaction point 20a) in the transaction point 20a to the next transaction point 20b (also called as the second transaction point), and the processing unit 112 adds one to the original count value of the transaction point 20a to generate a new count value, and records the new count value to the transaction file allocation table of the transaction table 20b. That is, the new count value recorded in the transaction table 20b may be greater than count values of other transaction points in the transaction point table 200.
Then, the processing unit 112 may execute the data access operation according to information in the transaction point 20b (that is, the transaction file allocation table and the file information table of the transaction point 20b).
Referring to
Particularly, in the process of executing the data access operation, because the cluster originally configured to store the data F3 and the file paths D2-D3 is marked by using the first flag and is reserved in the storage unit 114 without being modified, when failure (for example, the electronic apparatus 100 is powered off) occurs in the process of executing the data access operation, the processing unit 112 may restore the data F3 and the file paths D2-D3 in the previous transaction point (namely the transaction point 20a), so as to restore the storage unit 114 to a state in which the data access operation is not executed.
When the data access operation is completed, the electronic apparatus 100 may enter a commit state. At the moment, the processing unit 112 may execute a commit instruction, and set the transaction point 20b as the newest valid transaction point according to the commit instruction. Specifically, the processing unit 112 may generate check information according to the information recorded by the transaction file allocation table in the transaction point 20b and the count value in the transaction point 20b, and record the check information to the transaction file allocation table in the transaction point 20b. The check information may be generated by a familiar Exclusive OR (XOR) algorithm, and is not further described herein. In addition, referring to
It should be noted that in the present disclosure, a system for executing the operations of the embodiments of
Referring to
Based on the above, the present invention provides the data access method of transactional file system and the electronic apparatus applying the method, and when a user accesses a file, a file system enters a state of Start Transaction. When all access actions in transaction have been successfully executed, commit may be started, and a new valid transaction point may be established. When establishment of the new valid transaction point is completed, the system may enter a committed state, and at the moment, next transaction may be performed. When unpredictable conditions such as power failure and crash occur at the system, the file system may return to a correct state of transaction or a correct state before the data access operation again. Therefore, the invention provides the capacity of Fail-safe of the file system of the FAT on a mobile device.
Although the present invention has been disclosed as above through the embodiments, the embodiments are not intended to limit the present invention, any person of ordinary skill in the art may make some alternation and modification without deviating from the spirit and scope of the present invention, and therefore, the protection scope of the present invention should be subject to the appended claims.
Number | Date | Country | Kind |
---|---|---|---|
106132398 | Sep 2017 | TW | national |