kx]c@sddlZddlZddlZddlZddlZddlmZddlmZddlmZde ekrej e_ ej e_ ndZdZd Zd Zd efd YZd d`dYZddadYZddbdYZddcdYZddddYZddedYZddfdYZddgdYZddhdYZi;eejd6eejd 6eejd!6eej d"6eej!d#6eej"d$6eej#d%6ed&6eej$d'6eej%d(6eej&ed)6eej'd*6ed+6eej(d,6eej)d-6eej*d.6eej+d/6eej,d06eej-d16eej.d26eej/d36eej0d46eej1d56eej2d66eej3d76eej4d86eej5d96eej6d:6eej7d;6eej8d<6eej9d=6eej:d>6eej;d?6eej<d@6eej=dA6eej>dB6eej?dC6eej@dD6eejAdE6eejBdF6eejCdG6eejDdH6eejEdI6eejFdJ6eejGdK6eejHdL6eejIdM6eejJedN6eejJedO6eejKedP6eejLedQ6eejMedR6eejNedS6eejOdT6eejPdU6eejQdV6eejRdW6eejSdX6eejTdY6ZUdZZVeWeWd[ZXd\ZYeWd]ZZd^Z[d_Z\dS(iiNi(tmagic(tpb(tpb2dictt encodebytesiiicCs|d|dBdS(Ni((txty((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pytround_up>stMagicExceptioncBseZdZRS(cCs ||_dS(N(R(tselfR((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyt__init__Cs(t__name__t __module__R (((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyRBst entry_handlercBsPeZdZddZeedZedZdZdZ dZ RS(sp Generic class to handle loading/dumping criu images entries from/to bin format to/from dict(json). cCs||_||_dS(s= Sets payload class and extra handler class. N(tpayloadt extra_handler(RR R((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR Os c Csg}xtri}|j}|jd}|dkr@Pntjd|\}|j|j|tj||}|jr|rd} |jj||} d| | |dtextra( tTrueR treadtstructtunpacktParseFromStringRRtskiptloadtappend( Rtftprettyt no_payloadtentriestentrytpbufftbuftsizeRtpl_size((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR#Vs$     cCstj|}|j||S(sD Same as load(), but takes a string as an argument. (tiotBytesIOR#(RtsR&R%((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pytloadsscCsx|D]}|jdd}|j}tj|||j}t|}|jtj d||j||j r|r|j j |||qqWdS(s Convert criu image entries from dict(json) format to binary. Takes a list of entries and a file-like object to write entries in binary format to. RRN( tpoptNoneR Rtdict2pbtSerializeToStringtlentwriteRtpackRtdump(RR(R%R)RR*tpb_strR,((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR9s     cCs)tjd}|j|||jS(sf Same as dump(), but doesn't take file-like object and just returns a string. R(R.R/R9R(RR(R%((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pytdumpsscCsed}xXtr`|jd}|dkr.Pntjd|\}|j|d|d7}q W|S(sI Counts the number of top-level object in the image file iiRRi(RRRR tseek(RR%R(R+R,((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pytcounts  N( R R t__doc__R3R tFalseR#R1R9R;R=(((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR Is +   tpagemap_handlercBsDeZdZeedZedZdZdZdZRS(s Special entry handler for pagemap.img, which is unique in a way that it has a header of pagemap_head type followed by entries of pagemap_entry type. cCsg}tj}xytr|jd}|dkr:Pntjd|\}|j|j||jtj||tj }qW|S(NiRR( Rt pagemap_headRRRR R!R$Rt pagemap_entry(RR%R&R'R(R*R+R,((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR#s   cCstj|}|j||S(N(R.R/R#(RR0R&R%((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR1scCs{tj}xh|D]`}tj|||j}t|}|jtjd||j|tj }qWdS(NR( RRARR4R5R6R7RR8RB(RR(R%R*titemR:R,((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR9s     cCs)tjd}|j|||jS(NR(R.R/R9R(RR(R%((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR;scCstdj|dS(Ni(R R3R=(RR%((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR=s( R R R>R?R#R1R9R;R=(((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR@s   tghost_file_handlercBs5eZeedZedZdZdZRS(c Cs}g}tj}|jd}tjd|\}|j|j|tj||}|jr7|j|xt r3tj } |jd}|dkrPntjd|\}| j|j|tj| |} |r|j | j t jntj|j| j | d<|j| qwWnB|rS|j dt jntj|j|d<|j||S(NiRRRi(Rtghost_file_entryRRR R!RtchunksR$Rtghost_chunk_entryR<R6tostSEEK_CURtbase64RtSEEK_END( RR%R&R'R(tgfR+R,tg_entrytgcR)((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR#s2       cCstj|}|j||S(N(R.R/R#(RR0R&R%((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR1 scCstj}|jd}tj|||j}t|}|jtj d||j||j rx|D]z}tj }tj|||j}t|}|jtj d||j||jt j |dqyWn|jt j |ddS(NiRR(RRER2RR4R5R6R7RR8RFRGRJt decodebytes(RR(R%R*RCR:R,((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR9s"          !cCs)tjd}|j|||jS(NR(R.R/R9R(RR(R%((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR;#s(R R R?R#R1R9R;(((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyRDs!  tpipes_data_extra_handlercBs#eZdZdZdZRS(cCs%|j}|j|}tj|S(N(tbytesRRJR(RR%tploadR,tdata((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR#0s cCs tj|}|j|dS(N(RJROR7(RRR%RRRS((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR95scCs|j|jtj|jS(N(R<RQRHRI(RR%RR((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR"9s(R R R#R9R"(((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyRP/s  tsk_queues_extra_handlercBs#eZdZdZdZRS(cCs%|j}|j|}tj|S(N(tlengthRRJR(RR%RRR,RS((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR#?s cCs tj|}|j|dS(N(RJROR7(RRR%t_unusedRS((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR9DscCs|j|jtj|jS(N(R<RURHRI(RR%RR((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyR"Hs(R R R#R9R"(((s8/usr/lib/python2.7/site-packages/pycriu/images/images.pyRT>s  ttcp_stream_extra_handlercBs#eZdZdZdZRS(cCsTi}|j|j}|j|j}tj||d(s       o0G 1