Ë B”JÒçx†hãó\—dZddlZddlmZddlmZdZdZGd„d e«Z Gd „d e «Z y) aÕ This module implements the block map (bmap) creation functionality and provides the corresponding API in form of the 'BmapCreate' class. The idea is that while images files may generally be very large (e.g., 4GiB), they may nevertheless contain only little real data, e.g., 512MiB. This data are files, directories, file-system meta-data, partition table, etc. When copying the image to the target device, you do not have to copy all the 4GiB of data, you can copy only 512MiB of it, which is 4 times less, so copying should presumably be 4 times faster. The block map file is an XML file which contains a list of blocks which have to be copied to the target device. The other blocks are not used and there is no need to copy them. The XML file also contains some additional information like block size, image size, count of mapped blocks, etc. There are also many commentaries, so it is human-readable. The image has to be a sparse file. Generally, this means that when you generate this image file, you should start with a huge sparse file which contains a single hole spanning the entire file. Then you should partition it, write all the data (probably by means of loop-back mounting the image or parts of it), etc. The end result should be a sparse file where mapped areas represent useful parts of the image and holes represent useless parts of the image, which do not have to be copied when copying the image to the target device. This module uses the FIEMAP ioctl to detect holes. éNé)Ú human_size)ÚFilemapz2.0a· %u %u %u có—eZdZdZy)ÚErrorzÁ A class for exceptions generated by this module. We currently support only one type of exceptions, and we basically throw human-readable problem description in case of errors. N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©óú8/usr/lib/python3.12/site-packages/bmaptool/BmapCreate.pyrrhs „ñð  r rcóD—eZdZdZd d„Zd„Zd„Zd„Zd„Zd„Z d„Z d d „Z y ) Ú BmapCreateaÒ This class implements the bmap creation functionality. To generate a bmap for an image (which is supposedly a sparse file), you should first create an instance of 'BmapCreate' and provide: * full path or a file-like object of the image to create bmap for * full path or a file object to use for writing the results to Then you should invoke the 'generate()' method of this class. It will use the FIEMAP ioctl to generate the bmap. cóž—d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ |j«|_ tt!j"|j«j%««|_t-|d«r||_|j0|_n||_|j5«t-|d«r||_|j0|_n||_|j;« t=j>|j.«|_|j>j|_tC|j«|_|jdk(rt+d |j2z«‚|j>j|_|j>j|_y#t($r }t+d|j›d|›�«‚d}~wwxYw#t<j*t<j@f$r }t+d|j2›d|›�«‚d}~wwxYw) a� Initialize a class instance: * image - full path or a file-like object of the image to create bmap for * bmap - full path or a file object to use for writing the resulting bmap to * chksum - type of the check sum to use in the bmap file (all checksum types which python's "hashlib" module supports are allowed). NFz!cannot initialize hash function "z": Úreadzcannot generate bmap for file 'ú': rz3cannot generate bmap for zero-sized image file '%s')"Ú image_sizeÚimage_size_humanÚ block_sizeÚ blocks_cntÚ mapped_cntÚ mapped_sizeÚmapped_size_humanÚmapped_percentÚ_mapped_count_pos1Ú_mapped_count_pos2Ú _chksum_posÚ_f_image_needs_closeÚ_f_bmap_needs_closeÚlowerÚ_cs_typeÚlenÚhashlibÚnewÚ hexdigestÚ_cs_lenÚ ValueErrorrÚhasattrÚ_f_imageÚnameÚ _image_pathÚ_open_image_fileÚ_f_bmapÚ _bmap_pathÚ_open_bmap_filerÚfilemapÚ ErrorNotSuppr)ÚselfÚimageÚbmapÚ chksum_typeÚerrs rÚ__init__zBmapCreate.__init__sð€ðˆŒØ $ˆÔ؈ŒØˆŒØˆŒØˆÔØ!%ˆÔØ"ˆÔà"&ˆÔØ"&ˆÔ؈Ôà$)ˆÔ!Ø#(ˆÔ à#×)Ñ)Ó+ˆŒ ð ÜœwŸ{™{¨4¯=©=Ó9×CÑCÓEÓFˆDŒLô �5˜&Ô !Ø!ˆDŒMØ$Ÿz™zˆDÕ à$ˆDÔ Ø × !Ñ !Ô #ä �4˜Ô ؈DŒLØ"Ÿi™iˆD�Oà"ˆDŒOØ × Ñ Ô "ð Ü"Ÿ?™?¨4¯=©=Ó9ˆDŒLð Ÿ,™,×1Ñ1ˆŒÜ *¨4¯?©?Ó ;ˆÔØ �?‰?˜aÒ ÜØEÈ×HXÑHXÑXóð ðŸ,™,×1Ñ1ˆŒØŸ,™,×1Ñ1ˆ�øôEò ÝØ>B¿m»mÉSÐQóð ûð ûô*— ‘ œw×3Ñ3Ð4ò ÝØ<@×r/r.r?rr r@s rr0zBmapCreate._open_bmap_fileÑsL€ð SÜ §¡°Ó6ˆDŒLð$(ˆÕ øôò SݸD¿O»OÉSÐQÓRÐ Rûð SúrAcóR—tt|j|j|j|j fz}|dz }|j j|«|j j«|_ dt|j«z›ddtd«z›d�}|dz }|j j|«|j j«|_ ddtt|j ««zz}|dz }|d |jzz }|d z }|d z }|d z }|j j|«|j j«|_d |jzdz}|dz }|dz }|dz }|dz }|j j|«y)z™ A helper function which generates the starting contents of the block map file: the header comment, image size, block size, etc. z! z z%s z0 z' %s zM z Ú0z zH z N)Ú_BMAP_START_TEMPLATEÚSUPPORTED_BMAP_VERSIONrrrrr.ÚwriteÚtellrr#rÚstrr"rr')r3Úxmls rÚ_bmap_file_startzBmapCreate._bmap_file_startÚs¢€ô#Ü "Ø × !Ñ !Ø �O‰OØ �O‰OØ �O‰Oð & ñ ˆð Ð2Ñ2ˆà � ‰ ×ј3ÔØ"&§,¡,×"3Ñ"3Ó"5ˆÔð ”#�d×+Ñ+Ó,Ó ,Ø ”#�h“-Ó ð ˆð Ð)Ñ)ˆà � ‰ ×ј3ÔØ"&§,¡,×"3Ñ"3Ó"5ˆÔà+¨s´S¼¸T¿_¹_Ó9MÓ5NÑ/NÑOˆð ÐBÑBˆØ Ð:¸T¿]¹]ÑJÑJˆà Ð_Ñ_ˆØ ÐUÑUˆØ Ð(Ñ(ˆà � ‰ ×ј3ÔØŸ<™<×,Ñ,Ó.ˆÔà�D—L‘LÑ Ð#=Ñ=ˆØ Ø Wñ ˆð ÐUÑUˆØ ÐRÑRˆØ Ð!Ñ!ˆð � ‰ ×ј3Õr có—d}|dz }|jj|«|jj|j«|jjd|j|j fz«|jj|j «|jjd|jz«|jjd«tj|j«}|j|jj«j««|j«}|jj|j«|jjd|z«y)z± A helper function which generates the final parts of the block map file: the ending tags and the information about the amount of mapped blocks. z z z %s or %.1f%%z%urz%sN)r.rHÚseekrrrrrr$r%r"ÚupdaterÚencoder&r)r3rKÚhash_objÚchksums rÚ_bmap_file_endzBmapCreate._bmap_file_ends€ð"ˆØ ˆ{шà � ‰ ×ј3Ôà � ‰ ×ј$×1Ñ1Ô2Ø � ‰ ×ÑØ ˜d×4Ñ4°d×6IÑ6IÐJÑ Jô ð � ‰ ×ј$×1Ñ1Ô2Ø � ‰ ×ј4 $§/¡/Ñ1Ô2à � ‰ ×ј!ÔÜ—;‘;˜tŸ}™}Ó-ˆØ�‰˜Ÿ ™ ×)Ñ)Ó+×2Ñ2Ó4Ô5Ø×#Ñ#Ó%ˆØ � ‰ ×ј$×*Ñ*Ô+Ø � ‰ ×ј4 &™=Õ)r có|—||jz}|dz|jz}|jj|«tj|j «}d}||z }d}||krD||z|kDr||z }|jj |«} |j| «||z }||krŒD|j«S)z” A helper function which calculates checksum for the range of blocks of the image file: from block 'first' to block 'last'. rir) rr*rNr$r%r"rrOr&) r3ÚfirstÚlastÚstartÚendrQÚ chunk_sizeÚto_readrÚchunks rÚ_calculate_chksumzBmapCreate._calculate_chksum,s¼€ð ˜Ÿ™Ñ'ˆØ�a‰x˜4Ÿ?™?Ñ*ˆà � ‰ ×ј5Ô!Ü—;‘;˜tŸ}™}Ó-ˆà ˆ ؘ‘+ˆØˆà�WŠnØ�jÑ  7Ò*Ø$ t™^� Ø—M‘M×&Ñ& zÓ2ˆEØ �O‰O˜EÔ "Ø �JÑ ˆDð �W‹nð×!Ñ!Ó#Ð#r c ó`—|jj«}|j«d|_|jj d|j «D]‰\}}|xj||z dzz c_|r|j||«}d|z}nd}||k7r&|jjd|›d|›d|›d�«Œh|jjd|›d|›d�«Œ‹|j|jz|_ t|j«|_ |jd z|j z |_|j« |jj!«|jj)|«y #t"$r }t%d |j&›d |›�«‚d }~wwxYw) z‡ Generate bmap for the image file. If 'include_checksums' is 'True', also generate checksums for block ranges. rrz chksum="%s"Úz Ú-z gY@zcannot flush the bmap file 'rN)r*rIrLrr1Úget_mapped_rangesrr\r.rHrrrrrrSÚflushr?rr/rN)r3Úinclude_checksumsÚ image_posrUrVrRr7s rÚgeneratezBmapCreate.generateEsj€ð—M‘M×&Ñ&Ó(ˆ à ×ÑÔðˆŒØŸ<™<×9Ñ9¸!¸T¿_¹_ÖM‰KˆE�4Ø �OŠO˜t e™|¨aÑ/Ñ /�OÙ Ø×/Ñ/°°tÓ<�Ø'¨&Ñ0‘à�à˜Š}Ø— ‘ ×"Ò"ÚrisAðñ"óBÝ#ÝðÐð!ÐôH ˆIô ô{&�õ{&r