Use the method for flash memory saved system configuration in a kind of linux system
Technical field
The present invention relates to field of computer, relate in particular to a kind of in linux system the method based on the reliable saved system configuration that is based upon read-write file system on the flash memory.
Background technology
At present basically have two kinds with flash memory as the method for the embedded system saved system configuration of storage medium, a kind of is by the direct operating flash memory subregion of MTD interface, and system configuration is kept in the fixing MTD subregion; Another kind is that system configuration is kept in the read-write file system, uses existing database saved system configuration.First method needs structure and the querying method of designed, designed configuration item, and be difficult to realize the abrasion equilibrium processing of flash memory, especially for the flash memory of NAND type, if appearring in the subregion of saved system configuration, bad piece will cause the whole system configuration to damage, in addition, flash memory is generally erasable by piece, if device powers down will cause system configuration to need full recovery in erasable process; Second method has been utilized the abrasion equilibrium function of flash memory file system, but still faces the problem that outage need to recover whole system configuration in the erasable process.
Summary of the invention
In order to solve the deficiency of existing system configuration management mode, the present invention proposes a kind of method that under linux system, disposes based on the reliable saved system that is based upon the read-write file system on the flash memory.The characteristic that the method has mainly been utilized the ff of file system self, the abrasion equilibrium of flash memory is processed, with two different current configurations of catalogue saved system and system configuration backup, and each configuration item is saved in an independent file realizes, guaranteed that the damage of single configuration item file can not have influence on other configuration items.The specific implementation step of this method is as follows:
(1) default value of the configuration item of system configuration and configuration item is kept in the system in the mode of text, this file is kept at a fixed position, file reading out data and can not carry out write operation to this file from then on only during the administration configuration item recovers when the individual configuration item damages guaranteeing.
(2) system configuration is carried out initialization during device start, initialized process comprises: at first whether the current configuration of check system and system configuration backup directory exist, and if there is no then create; Then all configuration items in the Ergodic Theory default configuration file, with the configuration item file in the current config directory of open function opening system and the system configuration backup directory, judge whether the configuration item file exists or no normal with the rreturn value of this function, if two catalogue Files are all normal and identical then continue to judge next configuration item; If two catalogue Files all normally but not identical are then used the configuration item in the configuration item recovery system configuration backup catalogue in the current config directory of system; If the file in catalogue does not exist or occurs unusually, then recover with the file in another catalogue; If the file in two catalogues do not exist or occur unusual, the configuration item in recover these two catalogues with the default configuration in the system default configuration file.
When (3) needing to read the currency of a configuration item in system's operational process, only need the configuration item file in the current config directory of reading system; If this file occurs unusual, then the configuration item file in the reading system configuration backup catalogue; If these two files all have problems, then the default value in the reading system default configuration file.
When (4) needing the value of a configuration item is set in system's operational process, configuration item in the current config directory of system need to be set first, configuration item in the system configuration backup directory is set again, can guarantee like this if when the transition that two files are set is cut off the power supply constantly, can return to latest configuration during system initialization.
The invention has the beneficial effects as follows: when having realized utilizing flash memory to preserve configuration information, the abrasion equilibrium of flash disk operation is processed, solved the problem of the system configuration damage that system cut-off causes in bad piece and the flash memory wiping/writing process.
Advantage of the present invention is: and concrete flash type is irrelevant, and NOR and nand flash memory all are suitable for; Be convenient to transplant, can be applied to YAFFS2 and JFFS2 etc. and be based upon file system on the flash memory.
Description of drawings
Fig. 1 is system installing structure synoptic diagram of the present invention;
Fig. 2 is the process flow diagram of initialization system configuration of the present invention.
Implementation method
How further specify the present invention below in conjunction with accompanying drawing realizes:
Realize a configuration management function library, by this function library operation default configuration file, current configuration and backup configuration.
The initialize process of system need to carry out initialization to system configuration, and the initialization flow process as shown in Figure 2.At first enumerate the configuration item in the default configuration file, open under the current configuration respective file and check by the title of configuration item, if file is normal configuration item in the backup configuration is checked, the value that compares two configuration items if the backup configuration item is normal, process next configuration item if be worth identical then continue, cover the backup configuration item if the backup configuration item is unusual or value does not coexist with current configuration item; If current configuration item is checking the backup configuration item unusually, if the backup configuration item normally then recover current configuration item with the backup configuration item; If two configuration items all unusually then create configuration item according to default configuration.
Other processes must waiting system the configuration initialization could read and write configuration information after finishing.For same configuration item, if there is simultaneously the integrality that surpasses a read-write requests then lock to guarantee file content by file read-write.