Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, the technical scheme in the embodiment of the present invention is clearly and completely described, obviously, described embodiment is only the present invention's part embodiment, rather than whole embodiment.Based on embodiments of the invention, those of ordinary skills, not making under the creative work prerequisite the every other embodiment obtained, belong to protection scope of the present invention.
As described in Figure 1, the embodiment of the present invention provides a kind of file synchronisation method, can be applied in the embedded system based on LINUX, and method comprises:
11, by the file synchronization in flash memory flash in the LINUX embedded system in random store-memory body disk RAMDISK, and the file in described RAMDISK is carried out to inotify registration or dnotify registration.
12, the file that the application program of LINUX embedded system is registered in the RAMDISK after rear or described dnotify registers described inotify is operated, after described inotify registration or the file in the described RAMDISK after described dnotify registration while changing, by the file synchronization in the described RAMDISK changed in described flash.
The file synchronisation method of the embodiment of the present invention, do not change in the situation of reading and writing of files mode of application program of LINUX embedded system, use LINUX kernel inotify or dnotify documentary information mechanism, file in RAMDISK and the File Mapping in flash are got up, the application program of embedded system only need to be read and write the file in RAMDISK, thereby improved the read or write speed of embedded system, improved the response speed of system.
Optionally, in above-mentioned steps 12, the file that the application program of LINUX embedded system is registered in the RAMDISK after rear or described dnotify registers described inotify is operated, can comprise: the file that described inotify is registered after rear or described dnotify registers carries out read operation, perhaps write operation, perhaps move operation, or deletion action etc.
Optionally, in above-mentioned steps 12, after described inotify registration or the described file after described dnotify registration change, can comprise: after described inotify registration or the described file after described dnotify registration be modified, or be moved or deleted etc.
Optionally, the file synchronisation method of the embodiment of the present invention can also comprise:
The frequency characteristic be modified according to file and file purposes, by the Divide File in described flash, be Log Types file and Configuration Type file, the frequency that described Log Types file is modified is greater than the frequency that described Configuration Type file is modified, described Log Types file is for log, and described Configuration Type file loads the setting of required environment for application program.
The Log Types file for log, operates frequency large usually, and and the mode that only can append with content of Log Types file revise.The Configuration Type file loads the setting of required environment for application program, although the Configuration Type file can be modified, usually operate frequency little.
Further, for the Log Types file, owing to usually can not being modified, in flash, do not need to be backed up.And, for the Configuration Type file, owing to usually can being modified, increasing, need the file in flash is backed up, obtain corresponding master file and backup file.
Optionally, in the file synchronisation method of the embodiment of the present invention, can determine that the file in flash belongs to Log Types file or Configuration Type file by reading configuration file.
Below, to Log Types file and Configuration Type file, respectively the file synchronisation method of the embodiment of the present invention described:
For the Log Types file, the file synchronization in flash, in RAMDISK, can be comprised:
Directly by the Log Types file copy in flash in RAMDISK.
Further, for the Log Types file, the file synchronization in the RAMDISK changed, in flash, can be comprised:
Use the synchronous method of increment, by the Log Types file synchronization in RAMDISK in flash.Based in this Log Types file every record fixing length, or finish with newline, the record increased in file can be synchronized in flash, and will all not be synchronized in flash by whole file.
Optionally, for the Log Types file, after starting (comprise initial start and restart) LINUX embedded system, can according to the characteristics of this Log Types file, (every records fixing length, perhaps with newline, finish), Log Types file in flash is carried out to the check of integrality, imperfect if the last item of Log Types file records, can fall the last item record deletion.
For the Configuration Type file, the file synchronization in flash, in RAMDISK, can be comprised:
CRC (Cyclic Redundancy Check according to master file in flash, cyclic redundancy check (CRC)) value or MD5 (Message-Digest Algorithm 5, Message-Digest Algorithm 5) legitimacy of the described master file of value judgement, when described master file is legal, is synchronized in RAMDISK by described master file and is synchronized in described backup file;
When described master file is illegal, legitimacy according to backup file in the crc value of backup file in flash or the described flash of MD5 value judgement, when described backup file is legal, is synchronized in RAMDISK by described backup file and is synchronized in described master file.
Wherein, crc value or MD5 value can comprise: initial crc value or MD5 value, or upgrade crc value or MD5 value.
Wherein, be not limited to CRC algorithm or MD5, anyly can realize that the algorithm that judges file validation can be suitable for.
Further, for the Configuration Type file, the file synchronization in the RAMDISK changed, in flash, can be comprised:
According to CRC algorithm or MD5, calculate renewal crc value or the MD5 value of the file in the RAMDISK changed;
First described renewal crc value or MD5 value are synchronized to master file in described flash, then by the file synchronization in the described described RAMDISK changed to master file corresponding in described flash;
First described renewal crc value or MD5 value are synchronized to backup file in described flash, then by the file synchronization in the described described RAMDISK changed to backup file corresponding in described flash.
Optionally, the file synchronisation method of the embodiment of the present invention, can be used hardware cryptographic engine, carrys out crc value or the MD5 value of calculation document, reduces the expense of CPU.Exemplary, C3 hardware cryptographic engine for example, so when the crc value of calculation document or MD5 value, can call API (the Application Programming Interface of C3 hardware cryptographic engine, application programming interface) calculate, thereby reduced the expense of CPU (Central Processing Unit, central processing unit).
As described in Figure 2, corresponding to the file synchronisation method of above-described embodiment, the embodiment of the present invention provides a kind of file synchronization device 20, and this device 20 can be small-size computer, or personal computer, and network node etc. comprise:
The first lock unit 21, for the file synchronization by LINUX embedded system flash memory flash in random store-memory body disk RAMDISK.
Registering unit 22, carry out inotify registration or dnotify registration for the file to described RAMDISK.
The second lock unit 23, the file of described inotify being registered to the RAMDISK after rear or described dnotify registers for the application program of LINUX embedded system is operated, after described inotify registration or the file in the described RAMDISK after described dnotify registration while changing, by the file synchronization in the described RAMDISK changed in described flash.
The file synchronization device of the embodiment of the present invention, do not change in the situation of reading and writing of files mode of application program of LINUX embedded system, use LINUX kernel inotify or dnotify documentary information mechanism, file in RAMDISK and the File Mapping in flash are got up, the application program of embedded system only need to be read and write the file in RAMDISK, thereby improved the read or write speed of embedded system, improved the response speed of system.
Optionally, the first lock unit 21 and the second lock unit 23 can be realized by a lock unit, unrestricted.
Optionally, the second lock unit 23, specifically can carry out read operation for the file after or described dnotify registration rear to described inotify registration, perhaps write operation, perhaps move operation, or deletion action, the described file that described inotify registers after rear or described dnotify registration is modified, perhaps be moved or when deleted, by the file synchronization in the described RAMDISK changed in described flash.
The file synchronization device of the embodiment of the present invention can also comprise:
Division unit, for frequency characteristic and the file purposes be modified according to file, by the Divide File in described flash, be Log Types file and Configuration Type file, the frequency that described Log Types file is modified is greater than the frequency that described Configuration Type file is modified, described Log Types file is for log, and described Configuration Type file loads the setting of required environment for application program.And,
Backup units, for for described Configuration Type file, backed up the file in flash, obtains corresponding master file and backup file.
Optionally, for the Configuration Type file, the first lock unit 21, specifically can for:
Legitimacy according to the crc value of master file in flash or the described master file of MD5 value judgement, when described master file is legal, is synchronized in RAMDISK by described master file and is synchronized in described backup file;
When described master file is illegal, legitimacy according to backup file in the crc value of backup file in flash or the described flash of MD5 value judgement, when described backup file is legal, is synchronized in RAMDISK by described backup file and is synchronized in described master file.
Wherein, crc value or MD5 value can comprise: initially establish crc value or MD5 value, or upgrade crc value or MD5 value.
Further, optional, for the Configuration Type file, the second lock unit 23, specifically can for:
According to CRC algorithm or MD5, calculate renewal crc value or the MD5 value of the file in the RAMDISK changed;
First described renewal crc value or MD5 value are synchronized to master file in described flash, then by the file synchronization in the described described RAMDISK changed to master file corresponding in described flash;
First described renewal crc value or MD5 value are synchronized to backup file in described flash, then by the file synchronization in the described described RAMDISK changed to backup file corresponding in described flash.
File synchronization device and the formation thereof of the embodiment of the present invention, can correspondence be understood with reference to the related content of the file synchronisation method of above-described embodiment, and therefore not to repeat here.
The embodiment of the present invention provides a kind of file syn chronizing system, comprise lock unit, flash and RAMDISK, described lock unit is used for, and the file synchronization in flash, in RAMDISK, and is carried out to inotify registration or dnotify registration to the file in described RAMDISK; The file that the application program of LINUX embedded system is registered in the RAMDISK after rear or described dnotify registers described inotify is operated, after described inotify registration or the file in the described RAMDISK after described dnotify registration while changing, by the file synchronization in the described RAMDISK changed in described flash.
The file syn chronizing system of the embodiment of the present invention, do not change in the situation of reading and writing of files mode of application program of LINUX embedded system, use LINUX kernel inotify or dnotify documentary information mechanism, file in RAMDISK and the File Mapping in flash are got up, the application program of embedded system only need to be read and write the file in RAMDISK, thereby improved the read or write speed of embedded system, improved the response speed of system.
The embodiment of the present invention provides a kind of file synchronisation method, for response speed and the user experience that improves embedded system, in the situation that do not change the reading and writing of files mode of the application program of embedded system, increase a lock unit, use LINUX kernel inotify or dnotify documentary information mechanism, file in RAMDISK and the File Mapping in flash are got up, the application program of embedded system only need to be read and write the file in RAMDISK, thereby improved the read or write speed of embedded system, improved the response speed of system.
As shown in Figure 3, the file synchronisation method of the embodiment of the present invention comprises:
31, start the LINUX embedded system.
Start the LINUX embedded system, because lock unit must, before other process initiations, arrive RAMDISK to the file synchronization in flash.Therefore, can use process lock, prevent other processes in the situation that read less than the RAMDISK File and start, cause unpredictable mistake, until lock unit the file synchronization in flash in RAMDISK, could discharge process lock, allow other process initiations.
32, by the file synchronization in flash in RAMDISK.
Lock unit is determined the type of file by reading configuration file, and then determines which file synchronization in flash in RAMDISK.
Exemplary, " LOG " expression " Log Types " in the ProtectType field of configuration file, " CONF " expression " Configuration Type ".
Exemplary, table 1:
As shown in Figure 4, for Log Types, by the file synchronization in flash in RAMDISK, specifically: be directly corresponding file in flash, be synchronized in RAMDISK.
As shown in Figure 5, for Configuration Type, by the file synchronization in flash in RAMDISK, specifically:
51, the legitimacy of judgement master file.
The legitimacy of master file if the master file is legal, enter 52 as judged by CRC algorithm or MD5, if the master file is illegal, enter 53.
If 52 master files are legal, the master file synchronization in RAMDISK, upgrade the backup file simultaneously.
As the master file synchronization in RAMDISK, upgrade the backup file, and crc value or the MD5 value of upgrading the backup file simultaneously.
If 53 master files are illegal, the legitimacy of judgement backup file.
The legitimacy of backup file if the backup file is legal, enter 54 as judged by CRC algorithm or MD5, if the backup file is illegal, enter abnormality processing.
If 54 backup files are legal, the backup file synchronization in RAMDISK, upgrade the master file simultaneously.
As the backup file synchronization in RAMDISK, upgrade the master file, and crc value or the MD5 value of upgrading the master file simultaneously.
Afterwards, the file synchronization in flash, after RAMDISK, need is discharged to process lock, allow other process initiations.
33, the file in Inotify or dnotify registration RAMDISK.
Call the API (Application Programming Interface, application programming interface) of LINUX kernel inotify or dnotify, carry out the file in Inotify or dnotify registration RAMDISK.
File in Inotify or dnotify registration RAMDISK, can be understood with reference to prior art, and therefore not to repeat here.
34, receive that LINUX kernel inotify or dnotify notice RAMDISK File change.
Use the API of LINUX kernel inotify or dnotify, determine that the RAMDISK File changes.
Receive that LINUX kernel inotify or dnotify notice RAMDISK File change, can be understood with reference to prior art, therefore not to repeat here.
35, by vicissitudinous file synchronization in RAMDISK in flash.
As shown in Figure 6, for Log Types, use the synchronous mode of increment, the file synchronization in RAMDISK in flash.
As shown in Figure 7, for Configuration Type, the file synchronization in RAMDISK, in flash, being comprised:
71, calculate renewal crc value or the MD5 value of the file in RAMDISK by CRC algorithm or MD5.
72, first will upgrade crc value or the MD5 value is synchronized to master file in flash, then the file synchronization in RAMDISK is to corresponding master file in flash.
73, first will upgrade crc value or the MD5 value is synchronized to backup file in flash, then by the file synchronization in RAMDISK to corresponding backup file in flash.
The umconfig.tx in LINUX embedded system flash of below take is example, and the file synchronization of Configuration Type is briefly described:
During the initial electrifying startup of LINUX embedded system, in flash, the MD5 value of the master file of umconfig.txt and backup file is all that 11223344, master file is legal, by the master file synchronization in RAMDISK.
When the umconfig.txt in RAMDISK is modified, calculate the MD5 value of the umconfig.txt in RAMDISK, as, the MD5 value is 55667788.The MD5 value of upgrading the master file of umconfig.txt in flash is 55667788, and the umconfig.txt in RAMDISK is updated to the master file of umconfig.txt in flash.The MD5 value of upgrading the backup file of umconfig.txt in flash is 55667788, and the umconfig.txt in RAMDISK is updated to the backup file of umconfig.txt in flash.Now, in flash, the MD5 value of the master file of umconfig.txt and backup file is all 55667788.
If the umconfig.txt in RAMDISK is updated in the master file process of umconfig.txt in flash, the unexpected power down of LINUX embedded system, the MD5 value that can cause the master file of umconfig.txt in flash is 55667788, but in flash, the content of the master file of umconfig.txt is imperfect, and in flash, the content of the backup file of umconfig.txt is complete, the MD5 value of backup file is still 11223344.
So, the LINUX embedded system re-powers while starting, the master file that is umconfig.txt in 55667788 judgement flash according to the MD5 value is illegal, and then the backup file that is umconfig.txt in 11223344 judgement flash according to the MD5 value is legal, thereby by the backup file synchronization of umconfig.txt in flash in RAMDISK, and by the backup file synchronization of umconfig.txt in flash the master file to umconfig.txt in flash.
One of ordinary skill in the art will appreciate that all or part of flow process realized in above-described embodiment method, to come the hardware that instruction is relevant to complete by computer program, described program can be stored in a computer read/write memory medium, this program, when carrying out, can comprise the flow process as the embodiment of above-mentioned each side method.Wherein, described storage medium can be magnetic disc, CD, read-only store-memory body (Read-Only Memory, ROM) or random store-memory body (Random Access Memory, RAMDISK) etc.