技术领域Technical Field
本发明涉及文件升级技术领域,尤其涉及升级文件生成方法及装置。The present invention relates to the technical field of file upgrade, and in particular to a method and device for generating an upgrade file.
背景技术Background technique
在嵌入式Linux系统的应用中,系统启动后都会加载根文件系统,并通过根文件系统启动各种后台服务程序、加载应用程序、提供用户操作界面。In the application of embedded Linux system, the root file system will be loaded after the system starts, and various background service programs will be started, application programs will be loaded, and user operation interface will be provided through the root file system.
目前程序是靠文件系统存放在Flash(如Nor Flash、Nand Flash等非易失闪存设备)分区中。在实际产品中,如果文件系统被损害,不仅系统服务和应用程序无法正常加载和运行,而且会造成系统无法正常启动的严重后果。Currently, programs are stored in Flash (such as non-volatile flash memory devices such as Nor Flash and Nand Flash) partitions by file systems. In actual products, if the file system is damaged, not only system services and applications cannot be loaded and run normally, but also the system cannot be started normally.
在一些要求高可靠性的系统中,为了保证系统的稳定可靠,后台服务程序、应用程序的文件系统会以只读的方式存放在系统的存储设备(如Nor Flash、Nand Flash等非易失闪存设备)某分区中,将文件系统设置为只读不可修改,这样就可以防止和避免意外操作造成文件系统损坏,保证系统启动时文件系统能正常被挂载,增强系统的可靠性。而由于Squashfs、Cramfs具备压缩只读的特点,所以在目前产品开发中常常使用Squashfs、Cramfs作为程序的文件系统,不仅可以增强系统可靠性,而且可以节省硬件成本。In some systems that require high reliability, in order to ensure the stability and reliability of the system, the file system of the background service program and application program will be stored in a partition of the system's storage device (such as non-volatile flash memory devices such as Nor Flash and Nand Flash) in a read-only manner. The file system is set to read-only and cannot be modified. This can prevent and avoid damage to the file system caused by accidental operations, ensure that the file system can be mounted normally when the system starts, and enhance the reliability of the system. Since Squashfs and Cramfs have the characteristics of compressed read-only, Squashfs and Cramfs are often used as the file system of the program in current product development, which can not only enhance system reliability, but also save hardware costs.
而程序需要更新时,要对Squashfs、Cramfs进行升级。目前的升级方法为:通过擦除整个Squashfs、Cramfs文件系统,再写入新的Squashfs、Cramfs文件系统进行升级。When the program needs to be updated, Squashfs and Cramfs need to be upgraded. The current upgrade method is to upgrade by erasing the entire Squashfs and Cramfs file system and then writing a new Squashfs and Cramfs file system.
发明内容Summary of the invention
本发明实施例提出升级文件生成方法及装置,以在保证只读文件系统成功升级的前提下,减少只读文件系统的升级文件的长度。The embodiment of the present invention provides an upgrade file generation method and device, so as to reduce the length of the upgrade file of the read-only file system under the premise of ensuring the successful upgrade of the read-only file system.
本发明实施例的技术方案是这样实现的:The technical solution of the embodiment of the present invention is achieved as follows:
一种升级文件生成方法,该方法包括:A method for generating an upgrade file, the method comprising:
当只读文件系统产生新的版本时,则保存新版本中相对旧版本只读文件系统发生更新的数据块、该数据块在新版本只读文件系统中的位置;其中,只读文件系统中每个文件占用的数据块的数目固定,且,每个数据块在只读文件系统中的位置固定;When a new version of the read-only file system is generated, the data blocks in the new version that are updated relative to the old version of the read-only file system and the positions of the data blocks in the new version of the read-only file system are saved; wherein the number of data blocks occupied by each file in the read-only file system is fixed, and the position of each data block in the read-only file system is fixed;
构造升级文件,将发生更新的数据块在新版本只读文件系统中的位置、发生更新的数据块的数据内容、以及发生更新的数据块在升级文件中的位置放入升级文件中。An upgrade file is constructed, and the position of the updated data block in the new version read-only file system, the data content of the updated data block, and the position of the updated data block in the upgrade file are put into the upgrade file.
一种升级文件生成装置,该装置包括:An upgrade file generating device, the device comprising:
对比模块,用于当只读文件系统产生新的版本时,则保存新版本中相对旧版本只读文件系统发生更新的数据块、该数据块在新版本只读文件系统中的位置;其中,只读文件系统中每个文件占用的数据块的数目固定,且,每个数据块在只读文件系统中的位置固定;The comparison module is used for saving the data blocks updated in the new version relative to the old version of the read-only file system and the positions of the data blocks in the new version of the read-only file system when a new version of the read-only file system is generated; wherein the number of data blocks occupied by each file in the read-only file system is fixed, and the position of each data block in the read-only file system is fixed;
升级文件构造模块,用于构造升级文件,将发生更新的数据块在新版本只读文件系统中的位置、发生更新的数据块的数据内容、以及发生更新的数据块在升级文件中的位置放入升级文件中。The upgrade file construction module is used to construct the upgrade file and put the location of the updated data block in the new version read-only file system, the data content of the updated data block, and the location of the updated data block in the upgrade file into the upgrade file.
一种升级文件生成装置,该装置包括处理器,用于执行如上所述方法的步骤。An upgrade file generation device includes a processor for executing the steps of the above method.
一种非瞬时计算机可读存储介质,该非瞬时计算机可读存储介质存储指令,该指令在由处理器执行时使得处理器执行如上所述方法的步骤。A non-transitory computer-readable storage medium stores instructions which, when executed by a processor, cause the processor to perform the steps of the method described above.
本发明实施例中,将只读文件系统的结构设置为:每个文件占用的数据块的数目固定,且,每个数据块在只读文件系统中的位置固定;当只读文件系统产生新的版本时,保存新版本中相对旧版本只读文件系统发生更新的数据块、该数据块在新版本只读文件系统中的位置,则只根据发生更新的数据块构造升级文件,从而在保证只读文件系统成功升级的前提下,减少了升级文件的长度,加快了升级文件的传输速度。In the embodiment of the present invention, the structure of the read-only file system is set as follows: the number of data blocks occupied by each file is fixed, and the position of each data block in the read-only file system is fixed; when the read-only file system generates a new version, the data blocks in the new version that are updated relative to the old version of the read-only file system and the positions of the data blocks in the new version of the read-only file system are saved, and the upgrade file is constructed only according to the updated data blocks, thereby reducing the length of the upgrade file and accelerating the transmission speed of the upgrade file while ensuring the successful upgrade of the read-only file system.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
图1为本发明一实施例提供的升级文件生成方法流程图;FIG1 is a flow chart of a method for generating an upgrade file according to an embodiment of the present invention;
图2为本发明另一实施例提供的升级文件生成方法流程图;FIG2 is a flow chart of a method for generating an upgrade file provided by another embodiment of the present invention;
图3为本发明实施例提供的表1中的只读文件系统为Squashfs时,Squashfs的结构示意图;3 is a schematic structural diagram of Squashfs when the read-only file system in Table 1 provided by an embodiment of the present invention is Squashfs;
图4为本发明实施例提供的表1中的只读文件系统为Cramfs时,Cramfs的结构示意图;4 is a schematic diagram of the structure of Cramfs when the read-only file system in Table 1 provided by an embodiment of the present invention is Cramfs;
图5为本发明实施例提供的升级文件的结构示例图;FIG5 is a diagram showing an example structure of an upgrade file provided by an embodiment of the present invention;
图6为本发明实施例提供的升级文件的文件头的结构示例图;6 is a diagram showing an example structure of a file header of an upgrade file provided by an embodiment of the present invention;
图7为本发明一实施例提供的升级文件生成装置。FIG. 7 is an upgrade file generating device provided by an embodiment of the present invention.
具体实施方式Detailed ways
下面结合附图及具体实施例对本发明再作进一步详细的说明。The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
发明人对现有的Squashfs和Cramfs升级方法进行分析,发现其缺陷如下:The inventors analyzed the existing Squashfs and Cramfs upgrade methods and found the following defects:
一、由于Squashfs、Cramfs中的各文件数据排布必须按字节紧密排布,因此对Squashfs、Cramfs的升级必须是完整的升级方式,这样在升级时就需擦除Squashfs、Cramfs所在的flash分区,再写入新的Squashfs、Cramfs,如果设备使用nor flash存放Squashfs、Cramfs,整个升级过程是很耗时的,同时也增加了系统的不稳定性,若在升级过程中发生断电,设备重启后,必须重新执行升级过程;1. Since the data arrangement of each file in Squashfs and Cramfs must be closely arranged by bytes, the upgrade of Squashfs and Cramfs must be a complete upgrade method. Therefore, during the upgrade, the flash partition where Squashfs and Cramfs are located must be erased, and then new Squashfs and Cramfs are written. If the device uses nor flash to store Squashfs and Cramfs, the entire upgrade process is very time-consuming and also increases the instability of the system. If a power outage occurs during the upgrade process, the upgrade process must be performed again after the device is restarted;
二、在对Squashfs、Cramfs进行远程升级时传输的是整个Squashfs、Cramfs,对于信号不稳定的偏远山区,升级包传输耗时长。2. When Squashfs and Cramfs are upgraded remotely, the entire Squashfs and Cramfs are transmitted. For remote mountainous areas with unstable signals, the upgrade package transmission takes a long time.
发明人经过对Squashfs和Cramfs升级过程进行分析发现:The inventor analyzed the upgrade process of Squashfs and Cramfs and found that:
在对Squashfs、Cramfs进行升级时,实际往往只需要更新Squashfs、Cramfs中的某个文件,但限制于Squashfs、Cramfs是只读文件系统,现有技术不能直接修改某个文件,因此,现有技术还是需要制作完整的Squashfs、Cramfs。When upgrading Squashfs and Cramfs, it is often necessary to update only a certain file in Squashfs and Cramfs. However, due to the limitation that Squashfs and Cramfs are read-only file systems, the prior art cannot directly modify a certain file. Therefore, the prior art still needs to produce a complete Squashfs and Cramfs.
根据上述分析,为了克服现有技术的缺陷,发明人给出如下解决方案:Based on the above analysis, in order to overcome the defects of the prior art, the inventors provide the following solutions:
图1为本发明一实施例提供的升级文件生成方法流程图,其具体步骤如下:FIG1 is a flow chart of a method for generating an upgrade file according to an embodiment of the present invention, and the specific steps are as follows:
步骤101:当只读文件系统产生新的版本时,则保存新版本中相对旧版本只读文件系统发生更新的数据块、该数据块在新版本只读文件系统中的位置;其中,只读文件系统中每个文件占用的数据块的数目固定,且,每个数据块在只读文件系统中的位置固定。Step 101: When a new version of the read-only file system is generated, data blocks in the new version that are updated relative to the old version of the read-only file system and the positions of the data blocks in the new version of the read-only file system are saved; wherein the number of data blocks occupied by each file in the read-only file system is fixed, and the position of each data block in the read-only file system is fixed.
具体地,当只读文件系统产生新的版本时,依次比较该只读文件系统的新、旧版本中相同位置的各数据块对,若任一数据块对中的两数据块的内容不同,则确定新版本中的数据块发生了更新。Specifically, when a new version of the read-only file system is generated, each data block pair at the same position in the new and old versions of the read-only file system is compared in sequence. If the contents of two data blocks in any data block pair are different, it is determined that the data block in the new version has been updated.
步骤102:构造升级文件,将发生更新的数据块在新版本只读文件系统中的位置、发生更新的数据块的数据内容、以及发生更新的数据块在升级文件中的位置放入升级文件中。Step 102: construct an upgrade file, and put the location of the updated data block in the new version read-only file system, the data content of the updated data block, and the location of the updated data block in the upgrade file into the upgrade file.
本发明实施中,通过设置只读文件系统中每个文件占用的数据块的数目固定,且,每个数据块在只读文件系统中的位置固定,从而使得在只读文件系统中的数据块发生更新时,只需比较新、旧版版中相同位置的各数据块对,就能确定新版本中哪些数据块发生了更新,从而只根据发生更新的数据块构造升级文件,从而在保证只读文件系统成功升级的前提下,减少了升级文件的长度,加快了升级文件的传输速度。In the implementation of the present invention, by setting the number of data blocks occupied by each file in the read-only file system to be fixed, and the position of each data block in the read-only file system to be fixed, when the data blocks in the read-only file system are updated, it is only necessary to compare the data block pairs at the same position in the new and old versions to determine which data blocks in the new version have been updated, so that the upgrade file is constructed only according to the updated data blocks. This reduces the length of the upgrade file and speeds up the transmission of the upgrade file while ensuring the successful upgrade of the read-only file system.
具体地,将发生更新的数据块在新版本只读文件系统中的位置、发生更新的数据块的数据内容、以及发生更新的数据块在升级文件中的位置放入升级文件中可包括:Specifically, putting the location of the updated data block in the new version read-only file system, the data content of the updated data block, and the location of the updated data block in the upgrade file into the upgrade file may include:
将发生更新的数据块在新版本只读文件系统中的位置放入升级文件的文件头或者文件尾或者内容部分,优先选择放入升级文件的文件头,其中,当放入升级文件的文件尾或者内容部分时,需要在文件头中标注具体放在文件尾或者内容部分的哪个位置;Put the updated data block in the new version read-only file system into the file header, file tail or content of the upgrade file, preferably into the file header of the upgrade file. When putting the updated data block into the file tail or content of the upgrade file, it is necessary to mark in the file header where the updated data block is put;
将发生更新的数据块的数据内容放入升级文件的内容部分;Put the data content of the updated data block into the content part of the upgrade file;
将发生更新的数据块在升级文件中的位置放入升级文件的文件头或者文件尾或者内容部分,优先选择放入升级文件的文件头,其中,当放入升级文件的文件尾或者内容部分时,需要在文件头中标注具体放在文件尾或者内容部分的哪个位置。The location of the updated data block in the upgrade file is placed in the file header, file tail or content part of the upgrade file, preferably in the file header of the upgrade file. When placing the data block in the file tail or content part of the upgrade file, it is necessary to mark the specific location of the data block in the file tail or content part in the file header.
其中,发生更新的数据块在新版本只读文件系统中的位置可以该数据块在新版本只读文件系统中的偏移和该数据块的长度表示;发生更新的数据块在升级文件中的位置可以该数据块在升级文件中的偏移和该数据块的长度表示。Among them, the position of the updated data block in the new version of the read-only file system can be represented by the offset of the data block in the new version of the read-only file system and the length of the data block; the position of the updated data block in the upgrade file can be represented by the offset of the data block in the upgrade file and the length of the data block.
在实际应用中,步骤102之后可进一步包括:In practical applications, step 102 may further include:
根据升级文件中发生更新的数据块在新版本只读文件系统中的位置,在旧版本只读文件系统中查找到待更新数据块,所述待更新数据块在旧版本只读文件系统中位置与所述发生更新的数据块在新版本只读文件系统中的位置相对应;将待更新的数据块擦除,并写入新版本中发生更新的数据块。According to the position of the updated data block in the upgrade file in the new version read-only file system, the data block to be updated is found in the old version read-only file system, and the position of the data block to be updated in the old version read-only file system corresponds to the position of the updated data block in the new version read-only file system; the data block to be updated is erased, and the updated data block in the new version is written.
通过上述实施例,使得在更新只读文件系统时,只需对旧版本只读文件系统中发生更新的数据块所在的位置进行数据块的擦除和写入操作,加快了文件系统升级速度。Through the above embodiment, when updating the read-only file system, it is only necessary to perform data block erasing and writing operations on the locations where updated data blocks are located in the old version of the read-only file system, thereby speeding up the file system upgrade.
在实际应用中,步骤101之后、步骤102之前,还可进一步包括:当新版本中存在连续的多个数据块都发生更新,则将该连续的多个数据块作为一个数据段,将独立的发生更新的数据块作为一个数据段;In practical applications, after step 101 and before step 102, the following may be further included: when there are multiple continuous data blocks in the new version that are all updated, the multiple continuous data blocks are regarded as a data segment, and the independent updated data blocks are regarded as a data segment;
且,步骤102中,将新版本中发生更新的数据段在新版本只读文件系统中的位置、以及新版本中发生更新的数据段在升级文件中的位置放入升级文件中;Furthermore, in step 102, the location of the updated data segment in the new version in the read-only file system of the new version and the location of the updated data segment in the new version in the upgrade file are placed in the upgrade file;
且,步骤102之后进一步包括:根据升级文件中的发生更新的数据段在升级文件中的位置,从升级文件的内容部分读取发生更新的数据段;根据升级文件中的发生更新的数据段在新版本只读文件系统中的位置,在旧版本只读文件系统中查找到待更新数据段;将待更新数据段擦除,并写入新版本中发生更新的数据段。Furthermore, after step 102, the following further comprises: reading the updated data segments from the content portion of the upgrade file according to the positions of the updated data segments in the upgrade file in the upgrade file; searching for the data segments to be updated in the old version read-only file system according to the positions of the updated data segments in the upgrade file in the new version read-only file system; erasing the data segments to be updated and writing the updated data segments in the new version.
具体地,将新版本中发生更新的数据段在新版本只读文件系统中的位置、以及新版本中发生更新的数据段在升级文件中的位置放入升级文件中可包括:Specifically, putting the location of the updated data segment in the new version in the read-only file system of the new version and the location of the updated data segment in the new version in the upgrade file into the upgrade file may include:
将新版本中发生更新的数据段在新版本只读文件系统中的位置放入升级文件的文件头或者文件尾或者内容部分,优先选择放入升级文件的文件头,其中,当放入升级文件的文件尾或者内容部分时,需要在文件头中标注具体放在文件尾或者内容部分的哪个位置;Put the updated data segment in the new version into the file header, file tail or content part of the upgrade file at the location in the new version read-only file system, preferably into the file header of the upgrade file. When putting the data segment into the file tail or content part of the upgrade file, it is necessary to mark in the file header where the data segment is put into the file tail or content part;
将新版本中发生更新的数据段在升级文件中的位置放入升级文件的文件头或者文件尾或者内容部分,优先选择放入升级文件的文件头,其中,当放入升级文件的文件尾或者内容部分时,需要在文件头中标注具体放在文件尾或者内容部分的哪个位置。The location of the updated data segment in the new version in the upgrade file is placed in the file header, file tail or content part of the upgrade file, preferably in the file header of the upgrade file. When placing the data segment in the file tail or content part of the upgrade file, it is necessary to mark the specific location of the data segment in the file tail or content part in the file header.
其中,新版本中发生更新的数据段在新版本只读文件系统中的位置可以该数据段在新版本只读文件系统中的偏移和该数据段的长度表示;新版本中发生更新的数据段在升级文件中的位置可以该数据段在升级文件中的偏移和该数据段的长度表示。Among them, the position of the data segment updated in the new version in the new version read-only file system can be represented by the offset of the data segment in the new version read-only file system and the length of the data segment; the position of the data segment updated in the new version in the upgrade file can be represented by the offset of the data segment in the upgrade file and the length of the data segment.
通过上述实施例,将发生更新的连续的多个数据块作为一个数据段,从而进一步减少了升级文件的长度,进一步加快了升级文件的传输速度。Through the above embodiment, a plurality of updated continuous data blocks are regarded as one data segment, thereby further reducing the length of the upgrade file and further accelerating the transmission speed of the upgrade file.
在实际应用中,步骤101之前可进一步包括:在制作初始版本的只读文件系统时,根据预先配置的该文件系统中各个文件包含的最大数据块数,为各个文件分配数据块,然后将每个文件的初始数据依次写入为该文件分配的数据块。In actual applications, the process before step 101 may further include: when making an initial version of a read-only file system, allocating data blocks to each file according to a pre-configured maximum number of data blocks contained in each file in the file system, and then writing the initial data of each file into the data blocks allocated to the file in sequence.
通过上述实施例,根据预先配置的该文件系统中各个文件包含的最大数据块数,为各个文件分配数据块,从而保证了不同大小的文件系统都能够采用本发明实施例提供的升级方法进行升级。Through the above embodiment, data blocks are allocated to each file according to the pre-configured maximum number of data blocks contained in each file in the file system, thereby ensuring that file systems of different sizes can be upgraded using the upgrade method provided by the embodiment of the present invention.
在实际应用中,步骤102之后,还可进一步包括:采用消息摘要算法计算升级文件的加密值,将该加密值和升级文件一起发送给使用该只读文件系统的设备,设备接收到该加密值和升级文件后,采用同样的消息摘要算法计算该升级文件的加密值,若计算得到的加密值和接收到的加密值相同,则确定该升级文件正常。In actual applications, after step 102, it can further include: using a message digest algorithm to calculate the encryption value of the upgrade file, sending the encryption value and the upgrade file together to the device using the read-only file system, and after the device receives the encryption value and the upgrade file, using the same message digest algorithm to calculate the encryption value of the upgrade file. If the calculated encryption value is the same as the received encryption value, it is determined that the upgrade file is normal.
通过上述实施例,实现了对升级文件的加密,保证了升级文件的安全传输。Through the above embodiments, encryption of the upgrade file is achieved, ensuring the secure transmission of the upgrade file.
本发明实施例中的只读文件系统可以为Squashfs,或者为Cramfs。The read-only file system in the embodiment of the present invention may be Squashfs or Cramfs.
图2为本发明另一实施例提供的升级文件生成方法流程图,其具体步骤如下:FIG2 is a flow chart of a method for generating an upgrade file provided by another embodiment of the present invention, and the specific steps are as follows:
步骤200:在制作初始版本的只读文件系统时,根据预先配置的该文件系统中各个文件包含的最大数据块数,为各个文件分配数据块,然后将每个文件的初始数据依次写入为该文件分配的数据块;将该初始版本的只读文件系统配置在设备上。Step 200: When making an initial version of a read-only file system, allocate data blocks to each file according to the pre-configured maximum number of data blocks contained in each file in the file system, and then write the initial data of each file into the data blocks allocated to the file in sequence; configure the initial version of the read-only file system on the device.
只读文件系统包含一个或多个文件。各个文件通常是按照文件名的从a到z的顺序排放在只读文件系统中的。A read-only file system contains one or more files. The files are usually arranged in the order of the file names from a to z.
表1为一只读文件系统中各个文件包含的最大数据块数的配置表:Table 1 is a configuration table of the maximum number of data blocks contained in each file in a read-only file system:
表1Table 1
在每一版本(包含初始版本)的只读文件系统中,每个文件所包含的数据块不一定都被写入数据,即会存在一些预留数据块。In each version of the read-only file system (including the initial version), not all data blocks contained in each file are written with data, that is, there will be some reserved data blocks.
图3为表1中的只读文件系统为Squashfs时,Squashfs的结构示意图。如图3所示,块0为超级块,用于存储文件系统元数据的结构,块n用于存储索引等信息,其它块包括:块1~块n-1用于存储文件数据,其中,哪些块分配给哪个文件是预先定义好的,如图3中,块1~3用于存储文件1的数据,块4~7用于存储文件2的数据,…。由于要确保所有版本的文件数据都能被写入对应块中,因此,会为各文件分配足够的块,从而在将初始版本的文件数据写入块后,会存在一些预留块,如图3中,文件1的数据只占用了块1的全部和块2的一部分,文件2的数据只占用了块4的全部和块5的一部分。FIG3 is a schematic diagram of the structure of Squashfs when the read-only file system in Table 1 is Squashfs. As shown in FIG3, block 0 is a super block for storing the structure of file system metadata, block n is used to store index information, and other blocks include: block 1 to block n-1 for storing file data, where which blocks are allocated to which file is predefined. As shown in FIG3, blocks 1 to 3 are used to store the data of file 1, blocks 4 to 7 are used to store the data of file 2, and so on. In order to ensure that all versions of file data can be written into the corresponding blocks, sufficient blocks will be allocated to each file, so that after the initial version of the file data is written into the block, there will be some reserved blocks. As shown in FIG3, the data of file 1 only occupies all of block 1 and part of block 2, and the data of file 2 only occupies all of block 4 and part of block 5.
图4为表1中的只读文件系统为Cramfs时,Cramfs的结构示意图。如图4所示,块0~块x-1用于存储超级块信息、索引、目录等,块x及以后的块用于存储文件数据,其中,哪些块分配给哪个文件是预先定义好的,如图4中,块x~块x+2用于存储文件1的数据,块x+3~块x+6用于存储文件2的数据,…。由于要确保所有版本的文件数据都能被写入对应块中,因此,会为各文件分配足够的块,从而在将初始版本的文件数据写入块后,会存在一些预留块,如图4中,文件1的数据只占用了块x的全部和块x+1的一部分,文件2的数据只占用了块x+3的全部和块x+4的一部分。FIG4 is a schematic diagram of the structure of Cramfs when the read-only file system in Table 1 is Cramfs. As shown in FIG4, blocks 0 to x-1 are used to store superblock information, indexes, directories, etc., and blocks x and subsequent blocks are used to store file data, wherein which blocks are allocated to which files are predefined. For example, in FIG4, blocks x to x+2 are used to store data of file 1, blocks x+3 to x+6 are used to store data of file 2, and so on. In order to ensure that all versions of file data can be written into the corresponding blocks, sufficient blocks are allocated to each file, so that after the initial version of the file data is written into the blocks, there will be some reserved blocks. For example, in FIG4, the data of file 1 only occupies all of block x and part of block x+1, and the data of file 2 only occupies all of block x+3 and part of block x+4.
步骤201:当远程客户端发现该只读文件系统产生新的版本时,依次比较该只读文件系统的新版本与旧版本中相同位置的各数据块对,若任一数据块对中的两数据块的内容不同,则确定新版本中的数据块发生了更新,则保存新版本中发生了更新的该数据块及该数据块在新版本的只读文件系统中的偏移和该数据块的长度。Step 201: When the remote client finds that a new version of the read-only file system is generated, it compares the data block pairs at the same position in the new version and the old version of the read-only file system in turn. If the contents of the two data blocks in any data block pair are different, it is determined that the data block in the new version has been updated. The updated data block in the new version, the offset of the data block in the new version of the read-only file system, and the length of the data block are saved.
由于只读文件系统中各文件的位置是固定的。因此,通过比较新、旧版本中相同位置数据块的内容是否相同,就可得知哪些数据块发生了更新,只需将发生了更新的新版本中的数据块保存即可。Since the location of each file in the read-only file system is fixed, by comparing the contents of the data blocks at the same location in the new and old versions, we can know which data blocks have been updated, and we only need to save the updated data blocks in the new version.
步骤202:当远程客户端确定所有数据块对都比较完毕时,对于保存的新版本中发生了更新的各数据块,若存在连续的数据块,则将每组连续的数据块作为一个数据段,将剩余的每个数据块分别作为一个数据段。Step 202: When the remote client determines that all data block pairs have been compared, for each updated data block in the saved new version, if there are continuous data blocks, each group of continuous data blocks is regarded as a data segment, and each of the remaining data blocks is regarded as a data segment.
连续的数据块即,发生了更新的多个数据块在新版本的只读文件系统中位置是相邻的。Continuous data blocks refer to multiple updated data blocks that are located adjacently in the new version of the read-only file system.
步骤203:远程客户端构造升级文件。Step 203: The remote client constructs an upgrade file.
其中,将新版本中发生更新的每个数据段在新版本的只读文件系统中的偏移、每个数据段的长度、发生更新的数据段的数目放入升级文件的文件头;按照各数据段包含的数据块号的从小到大的顺序,将各数据段顺序放入升级文件的内容部分;然后,再将各数据段在升级文件中的偏移放入升级文件的文件头。Among them, the offset of each data segment updated in the new version in the read-only file system of the new version, the length of each data segment, and the number of updated data segments are put into the file header of the upgrade file; the data segments are sequentially put into the content part of the upgrade file in the order of the data block numbers contained in each data segment from small to large; then, the offset of each data segment in the upgrade file is put into the file header of the upgrade file.
需要说明的是,在实际应用中,新版本中发生更新的每个数据段在新版本的只读文件系统中的偏移、每个数据段的长度、发生更新的数据段的数目也可放在升级文件的文件尾和内容部分,此时,需要在升级文件的文件头中标注放在升级文件的文件尾和内容部分的具体位置;It should be noted that, in actual applications, the offset of each data segment updated in the new version in the read-only file system of the new version, the length of each data segment, and the number of updated data segments can also be placed in the file tail and content part of the upgrade file. In this case, the specific locations of the file tail and content part of the upgrade file need to be marked in the file header of the upgrade file;
同时,各数据段在升级文件中的偏移也可放入升级文件的文件尾或内容部分,此时,需要在升级文件的文件头中标注放在升级文件的文件尾和内容部分的具体位置。Meanwhile, the offset of each data segment in the upgrade file may also be placed in the file tail or content part of the upgrade file. In this case, the specific positions of the file tail and content part of the upgrade file need to be marked in the file header of the upgrade file.
图5为升级文件的结构示例图,如图5所示,升级文件主要由升级文件头和升级文件内容两部分组成,新版本中发生更新的数据段1~k的数据存放在升级文件内容部分。FIG5 is a diagram showing an example of the structure of an upgrade file. As shown in FIG5 , the upgrade file mainly consists of two parts: an upgrade file header and an upgrade file content. The data of data segments 1 to k updated in the new version are stored in the upgrade file content part.
图6为升级文件的文件头的结构示例图,在该示例中,新版本中发生更新的数据段的数目k、新版本中发生更新的每个数据段包括:数据段1~k的数据在升级文件中的偏移、新版本中发生更新的每个数据段包括:数据段1~k的数据在新版本的只读文件系统中的偏移都放在升级文件的文件头中。Figure 6 is an example diagram of the structure of the file header of the upgrade file. In this example, the number k of data segments updated in the new version, each data segment updated in the new version includes: the offset of the data of data segments 1 to k in the upgrade file, and each data segment updated in the new version includes: the offset of the data of data segments 1 to k in the read-only file system of the new version are all placed in the file header of the upgrade file.
步骤204:远程客户端采用MD(Message-Digest,消息摘要)5算法计算升级文件的加密值,根据加密值生成MD5文件。Step 204: The remote client uses MD (Message-Digest) 5 algorithm to calculate the encryption value of the upgrade file and generates an MD5 file according to the encryption value.
步骤205:远程客户端将升级文件和MD5文件打包压缩成升级包后发送给设备。Step 205: The remote client packages and compresses the upgrade file and the MD5 file into an upgrade package and sends it to the device.
步骤206:设备接收到升级包,解压后得到升级文件和MD5文件,从MD5文件中解析出加密值,对升级文件进行MD5计算,得到加密值,若得到的加密值与解析出的加密值一致,则确定升级文件正常。Step 206: The device receives the upgrade package, decompresses it to obtain the upgrade file and the MD5 file, parses the encryption value from the MD5 file, performs MD5 calculation on the upgrade file to obtain the encryption value. If the obtained encryption value is consistent with the parsed encryption value, it is determined that the upgrade file is normal.
步骤207:设备解析升级文件的文件头,根据解析出的发生更新的数据段的数目以及各数据段在升级文件中的偏移,依次从升级文件的内容部分读取各数据段。Step 207: the device parses the file header of the upgrade file, and reads each data segment from the content portion of the upgrade file in sequence according to the number of updated data segments and the offset of each data segment in the upgrade file.
步骤208:设备根据从文件头中解析出的发生更新的每个数据段在新版本的只读文件系统中的偏移以及每个数据段的长度,在本设备上存储的旧版本的只读文件系统中依次查找到待更新的各数据段,将待更新的数据段从对应存储位置擦除,然后在对应存储位置写入新版本的对应数据段。Step 208: The device searches for the data segments to be updated in the old version of the read-only file system stored on the device in turn based on the offset of each updated data segment in the new version of the read-only file system and the length of each data segment parsed from the file header, erases the data segments to be updated from the corresponding storage locations, and then writes the corresponding data segments of the new version to the corresponding storage locations.
本发明实施例中的只读文件系统可以是镜像文件系统,如:BIN(Binary,二进制)等格式的二进制文件系统。The read-only file system in the embodiment of the present invention may be a mirror file system, such as a binary file system in a BIN (Binary, binary) format.
图7为本发明一实施例提供的升级文件生成装置,该装置主要包括:对比模块71和升级文件构造模块72,其中:FIG7 is an upgrade file generation device provided by an embodiment of the present invention, the device mainly comprises: a comparison module 71 and an upgrade file construction module 72, wherein:
对比模块71,用于当只读文件系统产生新的版本时,则保存新版本中相对旧版本只读文件系统发生更新的数据块、该数据块在新版本只读文件系统中的位置;其中,只读文件系统中每个文件占用的数据块的数目固定,且,每个数据块在只读文件系统中的位置固定。The comparison module 71 is used to save the data blocks in the new version that are updated relative to the old version of the read-only file system and the position of the data blocks in the new version of the read-only file system when a new version of the read-only file system is generated; wherein the number of data blocks occupied by each file in the read-only file system is fixed, and the position of each data block in the read-only file system is fixed.
升级文件构造模块72,用于根据对比模块71保存的新版本中相对旧版本只读文件系统发生更新的数据块、该数据块在新版本只读文件系统中的位置,构造升级文件,将发生更新的数据块在新版本只读文件系统中的位置、发生更新的数据块的数据内容、以及发生更新的数据块在升级文件中的位置放入升级文件中。The upgrade file construction module 72 is used to construct an upgrade file based on the data blocks that are updated in the new version relative to the old version of the read-only file system and the positions of the data blocks in the new version of the read-only file system saved by the comparison module 71, and to put the positions of the updated data blocks in the new version of the read-only file system, the data contents of the updated data blocks, and the positions of the updated data blocks in the upgrade file into the upgrade file.
本发明另一实施例提供一种升级文件生成装置,该装置包括处理器,用于执行如图1或图2所述方法的步骤。Another embodiment of the present invention provides an upgrade file generation device, which includes a processor, configured to execute the steps of the method described in FIG. 1 or FIG. 2 .
本发明实施例还提供一种非瞬时计算机可读存储介质,非瞬时计算机可读存储介质存储指令,该指令在由处理器执行时使得处理器执行如图1或图2所述方法的步骤。An embodiment of the present invention further provides a non-transitory computer-readable storage medium, which stores instructions. When the instructions are executed by a processor, the processor executes the steps of the method described in FIG. 1 or FIG. 2 .
本发明实施例还提供一种电子设备,包括如上所述的非瞬时计算机可读存储介质、以及可访问非瞬时计算机可读存储介质的上述处理器。An embodiment of the present invention further provides an electronic device, comprising the non-transitory computer-readable storage medium as described above, and the processor as described above that can access the non-transitory computer-readable storage medium.
本发明实施例的有益技术效果如下:The beneficial technical effects of the embodiments of the present invention are as follows:
通过将只读文件系统的结构设置为:每个文件占用的数据块的数目固定,且,每个数据块在只读文件系统中的位置固定,从而当只读文件系统产生新的版本时,只需将新版本中相比旧版本发生了更新的数据块放入升级文件,从而在保证只读文件系统成功升级的前提下,减少了升级文件的长度,加快了升级文件的传输速度;By setting the structure of the read-only file system to: the number of data blocks occupied by each file is fixed, and the position of each data block in the read-only file system is fixed, when the read-only file system generates a new version, only the data blocks in the new version that are updated compared to the old version need to be put into the upgrade file, thereby reducing the length of the upgrade file and speeding up the transmission speed of the upgrade file while ensuring the successful upgrade of the read-only file system;
另外,对于使用只读文件系统的设备来说,其无需对整个只读文件系统进行擦除和写入,而只需对只读文件系统的旧版本中需要更新的数据块进行擦除和写入,升级速度大大提高了,且系统稳定性也提高了,若在升级过程中设备断电了,也只对正在升级的文件产生影响,而不会影响其他文件,在设备重启后,只需从正在升级的文件的升级过程重新开始即可。In addition, for devices using a read-only file system, there is no need to erase and write the entire read-only file system. Instead, it is only necessary to erase and write the data blocks that need to be updated in the old version of the read-only file system. The upgrade speed is greatly improved, and the system stability is also improved. If the device loses power during the upgrade process, it will only affect the file being upgraded and will not affect other files. After the device is restarted, it only needs to restart the upgrade process from the file being upgraded.
以上所述仅为本发明的较佳实施例而已,并不用以限制本发明,凡在本发明的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本发明保护的范围之内。The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910725422.8ACN112346771B (en) | 2019-08-07 | 2019-08-07 | Upgrade file generation method and device |
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910725422.8ACN112346771B (en) | 2019-08-07 | 2019-08-07 | Upgrade file generation method and device |
| Publication Number | Publication Date |
|---|---|
| CN112346771A CN112346771A (en) | 2021-02-09 |
| CN112346771Btrue CN112346771B (en) | 2024-05-31 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201910725422.8AActiveCN112346771B (en) | 2019-08-07 | 2019-08-07 | Upgrade file generation method and device |
| Country | Link |
|---|---|
| CN (1) | CN112346771B (en) |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113282325B (en)* | 2021-06-17 | 2022-08-19 | 北京紫光展锐通信技术有限公司 | Method and device for upgrading file system, storage medium and computing equipment |
| CN113626872B (en)* | 2021-10-11 | 2021-12-14 | 宁波集联软件科技有限公司 | Control method for integrity of preset resources in automobile memory chip module |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| EP0994425A2 (en)* | 1998-06-30 | 2000-04-19 | iOra Ltd. | System and method for generating file updates for files stored on read-only media |
| TW428146B (en)* | 1999-05-05 | 2001-04-01 | Inventec Corp | Data file updating method by increment |
| CN1310388A (en)* | 2000-02-21 | 2001-08-29 | 英业达股份有限公司 | A method for updating data files in an incremental manner |
| US6374268B1 (en)* | 1998-04-14 | 2002-04-16 | Hewlett-Packard Company | Methods and systems for an incremental file system |
| CN101770515A (en)* | 2010-01-18 | 2010-07-07 | 杭州顺网科技股份有限公司 | Data block comparison based data updating method |
| CN102054041A (en)* | 2010-12-30 | 2011-05-11 | 用友软件股份有限公司 | Method and system for upgrading metadata |
| CN102096615A (en)* | 2011-01-25 | 2011-06-15 | 上海爱数软件有限公司 | Remote incremental backup method and system |
| CN103777986A (en)* | 2014-01-26 | 2014-05-07 | 宝龙计算机系统(湖南)有限公司 | Method and device for saving modification of Unix-like operating system |
| CN104298532A (en)* | 2014-11-04 | 2015-01-21 | 上海斐讯数据通信技术有限公司 | Upgrading method and upgrading system for software |
| CN104834547A (en)* | 2015-05-14 | 2015-08-12 | 烽火通信科技股份有限公司 | Remote upgrade method and system of Squashfs read-only root file system |
| CN105786563A (en)* | 2016-02-19 | 2016-07-20 | 联州(上海)信息科技有限公司 | Device, system and method for achieving software online update |
| CN106598576A (en)* | 2016-11-30 | 2017-04-26 | 深圳市泛海三江科技发展有限公司 | Equipment parameter updating method and device based on squashfs read-only file |
| CN106886436A (en)* | 2017-01-23 | 2017-06-23 | 青岛海信移动通信技术股份有限公司 | A kind of method and apparatus of android system upgrading |
| CN108228224A (en)* | 2017-12-21 | 2018-06-29 | 杭州中天微系统有限公司 | A kind of method and device of embedded system difference upgrading |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US7555504B2 (en)* | 2003-09-23 | 2009-06-30 | Emc Corporation | Maintenance of a file version set including read-only and read-write snapshot copies of a production file |
| US11157258B2 (en)* | 2017-11-16 | 2021-10-26 | Atlassian Pty Ltd. | Systems and processes for updating computer applications |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6374268B1 (en)* | 1998-04-14 | 2002-04-16 | Hewlett-Packard Company | Methods and systems for an incremental file system |
| EP0994425A2 (en)* | 1998-06-30 | 2000-04-19 | iOra Ltd. | System and method for generating file updates for files stored on read-only media |
| TW428146B (en)* | 1999-05-05 | 2001-04-01 | Inventec Corp | Data file updating method by increment |
| CN1310388A (en)* | 2000-02-21 | 2001-08-29 | 英业达股份有限公司 | A method for updating data files in an incremental manner |
| CN101770515A (en)* | 2010-01-18 | 2010-07-07 | 杭州顺网科技股份有限公司 | Data block comparison based data updating method |
| CN102054041A (en)* | 2010-12-30 | 2011-05-11 | 用友软件股份有限公司 | Method and system for upgrading metadata |
| CN102096615A (en)* | 2011-01-25 | 2011-06-15 | 上海爱数软件有限公司 | Remote incremental backup method and system |
| CN103777986A (en)* | 2014-01-26 | 2014-05-07 | 宝龙计算机系统(湖南)有限公司 | Method and device for saving modification of Unix-like operating system |
| CN104298532A (en)* | 2014-11-04 | 2015-01-21 | 上海斐讯数据通信技术有限公司 | Upgrading method and upgrading system for software |
| CN104834547A (en)* | 2015-05-14 | 2015-08-12 | 烽火通信科技股份有限公司 | Remote upgrade method and system of Squashfs read-only root file system |
| CN105786563A (en)* | 2016-02-19 | 2016-07-20 | 联州(上海)信息科技有限公司 | Device, system and method for achieving software online update |
| CN106598576A (en)* | 2016-11-30 | 2017-04-26 | 深圳市泛海三江科技发展有限公司 | Equipment parameter updating method and device based on squashfs read-only file |
| CN106886436A (en)* | 2017-01-23 | 2017-06-23 | 青岛海信移动通信技术股份有限公司 | A kind of method and apparatus of android system upgrading |
| CN108228224A (en)* | 2017-12-21 | 2018-06-29 | 杭州中天微系统有限公司 | A kind of method and device of embedded system difference upgrading |
| Title |
|---|
| AFC数据块快速备份与恢复策略;1-10;《电脑编程技巧与维护》;20130403(第7期);第49-52+67页* |
| Approximately Opaque Multi-version Permissive Transactional Memory;Basem Assiri, et.al;《45th International Conference on Parallel Processing Workshops (ICPPW)》;20160926;第393-402页* |
| 嵌入式固件远程升级技术的研究与实现;王广辉;《中国优秀硕士学位论文全文数据库 (信息科技辑)》;20120115(第1期);第I137-41页* |
| 赵伟华等.《计算机操作系统》.西安电子科技大学出版社,2018,第304-307页.* |
| Publication number | Publication date |
|---|---|
| CN112346771A (en) | 2021-02-09 |
| Publication | Publication Date | Title |
|---|---|---|
| WO2015070521A1 (en) | Method for making ubi format system file into factory burnt image file | |
| CN107247603A (en) | Support the remote upgrade method and system of firmware auto restore facility | |
| US20050071839A1 (en) | Communication terminal and communication network for partially updating software, software update method, and software creation device and method therefor | |
| CN101983376A (en) | Access device, information recording device, information recording system, file management method, and program | |
| CN105786542A (en) | Intelligent device and system update method of the intelligent device | |
| CN105786549A (en) | Smart device and upgrading method thereof | |
| WO2020010724A1 (en) | Front-end static resource management method, apparatus, computer device and storage medium | |
| WO2020024062A1 (en) | Methods and systems for remote software update | |
| CN108228479A (en) | A kind of embedded flash data storage method and system | |
| CN112346771B (en) | Upgrade file generation method and device | |
| CN109542495A (en) | A kind of method for upgrading software and device | |
| WO2020107436A1 (en) | Program upgrade method and embedded device | |
| WO2019041891A1 (en) | Method and device for generating upgrade package | |
| CN111586170B (en) | Resource downloading method, device, equipment and computer readable storage medium | |
| CN105677579A (en) | Data access method and system in cache system | |
| US20120151005A1 (en) | Image file download method | |
| CN114356386A (en) | Block differential upgrading method, terminal equipment and computer readable storage medium | |
| CN118672635A (en) | System upgrading method and device for embedded equipment under small memory | |
| US8578359B2 (en) | Method and apparatus for reliable in-place update | |
| CN111399759B (en) | Method for reading data and writing data and object file system | |
| CN109669628B (en) | Data storage management method and device based on flash equipment | |
| CN117112004B (en) | Differential data determination method, differential restoration method, device, equipment and medium | |
| US10860533B1 (en) | File size as an indicator of file properties | |
| CN117851348A (en) | Method for efficiently exporting import file by RBD snapshot | |
| CN117098105A (en) | Firmware upgrading method, device and system for embedded equipment cluster |
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant | ||
| TR01 | Transfer of patent right | Effective date of registration:20250729 Address after:Rooms 602 and 605, No. 85 Xiangxue Avenue Middle, Huangpu District, Guangzhou City, Guangdong Province 510000 Patentee after:Guangzhou Gaohang Technology Transfer Co.,Ltd. Country or region after:China Address before:Hangzhou City, Zhejiang province 310051 Binjiang District Qianmo Road No. 555 Patentee before:Hangzhou Hikvision Digital Technology Co.,Ltd. Country or region before:China | |
| TR01 | Transfer of patent right |