def load(self, f, pretty=False, no_payload=False): entries = [] gf = ghost_file_entry() buf = f.read(4) size, = struct.unpack('i', buf) gf.ParseFromString(f.read(size)) g_entry = pb2dict.pb2dict(gf, pretty) if gf.chunks: entries.append(g_entry) while True: gc = ghost_chunk_entry() buf = f.read(4) if buf == '': break size, = struct.unpack('i', buf) gc.ParseFromString(f.read(size)) entry = pb2dict.pb2dict(gc, pretty) if no_payload: f.seek(gc.len, os.SEEK_CUR) else: entry['extra'] = f.read(gc.len).encode('base64') entries.append(entry) else: if no_payload: f.seek(0, os.SEEK_END) else: g_entry['extra'] = f.read().encode('base64') entries.append(g_entry) return entries
def load(self, f, pretty = False, no_payload = False): entries = [] gf = ghost_file_entry() buf = f.read(4) size, = struct.unpack('i', buf) gf.ParseFromString(f.read(size)) g_entry = pb2dict.pb2dict(gf, pretty) if gf.chunks: entries.append(g_entry) while True: gc = ghost_chunk_entry() buf = f.read(4) if buf == '': break size, = struct.unpack('i', buf) gc.ParseFromString(f.read(size)) entry = pb2dict.pb2dict(gc, pretty) if no_payload: f.seek(gc.len, os.SEEK_CUR) else: entry['extra'] = f.read(gc.len).encode('base64') entries.append(entry) else: if no_payload: f.seek(0, os.SEEK_END) else: g_entry['extra'] = f.read().encode('base64') entries.append(g_entry) return entries
def load(self, f, pretty = False): """ Convert criu image entries from binary format to dict(json). Takes a file-like object and returnes a list with entries in dict(json) format. """ entries = [] while True: entry = {} # Read payload pb = self.payload() buf = f.read(4) if buf == '': break size, = struct.unpack('i', buf) pb.ParseFromString(f.read(size)) entry = pb2dict.pb2dict(pb, pretty) # Read extra if self.extra_handler: entry['extra'] = self.extra_handler.load(f, pb) entries.append(entry) return entries
def dump(self, extra, f, pb): entry = pb2dict.pb2dict(pb) size = entry['size'] data = extra.decode('base64') rounded = round_up(size, sizeof_u32) f.write(data[:size]) f.write('\0' * (rounded - size))
def load(self, f, pb): entry = pb2dict.pb2dict(pb) messages = [] for x in range(0, entry['qnum']): buf = f.read(4) if buf == '': break size, = struct.unpack('i', buf) msg = ipc_msg() msg.ParseFromString(f.read(size)) rounded = round_up(msg.msize, sizeof_u64) data = f.read(msg.msize) f.seek(rounded - msg.msize, 1) messages.append(pb2dict.pb2dict(msg)) messages.append(data.encode('base64')) return messages
def load(self, f, pb): entry = pb2dict.pb2dict(pb) size = entry['size'] data = f.read(size) rounded = round_up(size, sizeof_u32) f.seek(rounded - size, 1) return data.encode('base64')
def dump(self, extra, f, pb): entry = pb2dict.pb2dict(pb) size = entry["size"] data = extra.decode("base64") rounded = round_up(size, sizeof_u32) f.write(data[:size]) f.write("\0" * (rounded - size))
def load(self, f, pb): entry = pb2dict.pb2dict(pb) messages = [] for x in range (0, entry['qnum']): buf = f.read(4) if buf == '': break size, = struct.unpack('i', buf) msg = ipc_msg() msg.ParseFromString(f.read(size)) rounded = round_up(msg.msize, sizeof_u64) data = f.read(msg.msize) f.seek(rounded - msg.msize, 1) messages.append(pb2dict.pb2dict(msg)) messages.append(data.encode('base64')) return messages
def load(self, f, pb): entry = pb2dict.pb2dict(pb) size = sizeof_u16 * entry['nsems'] rounded = round_up(size, sizeof_u64) s = array.array('H') if s.itemsize != sizeof_u16: raise Exception("Array size mismatch") s.fromstring(f.read(size)) f.seek(rounded - size, 1) return s.tolist()
def dump(self, extra, f, pb): entry = pb2dict.pb2dict(pb) size = sizeof_u16 * entry['nsems'] rounded = round_up(size, sizeof_u64) s = array.array('H') if s.itemsize != sizeof_u16: raise Exception("Array size mismatch") s.fromlist(extra) if len(s) != entry['nsems']: raise Exception("Number of semaphores mismatch") f.write(s.tostring()) f.write('\0' * (rounded - size))
def dump(self, extra, f, pb): entry = pb2dict.pb2dict(pb) for i in range (0, len(extra), 2): msg = ipc_msg() pb2dict.dict2pb(extra[i], msg) msg_str = msg.SerializeToString() size = len(msg_str) f.write(struct.pack('i', size)) f.write(msg_str) rounded = round_up(msg.msize, sizeof_u64) data = extra[i + 1].decode('base64') f.write(data[:msg.msize]) f.write('\0' * (rounded - msg.msize))
def dump(self, extra, f, pb): entry = pb2dict.pb2dict(pb) for i in range(0, len(extra), 2): msg = ipc_msg() pb2dict.dict2pb(extra[i], msg) msg_str = msg.SerializeToString() size = len(msg_str) f.write(struct.pack('i', size)) f.write(msg_str) rounded = round_up(msg.msize, sizeof_u64) data = extra[i + 1].decode('base64') f.write(data[:msg.msize]) f.write('\0' * (rounded - msg.msize))
def load(self, f, pretty = False): entries = [] pb = pagemap_head() while True: buf = f.read(4) if buf == '': break size, = struct.unpack('i', buf) pb.ParseFromString(f.read(size)) entries.append(pb2dict.pb2dict(pb, pretty)) pb = pagemap_entry() return entries
def skip(self, f, pb): entry = pb2dict.pb2dict(pb) pl_len = 0 for x in range(0, entry['qnum']): buf = f.read(4) if buf == '': break size, = struct.unpack('i', buf) msg = ipc_msg() msg.ParseFromString(f.read(size)) rounded = round_up(msg.msize, sizeof_u64) f.seek(rounded, os.SEEK_CUR) pl_len += size + msg.msize return pl_len
def skip(self, f, pb): entry = pb2dict.pb2dict(pb) pl_len = 0 for x in range (0, entry['qnum']): buf = f.read(4) if buf == '': break size, = struct.unpack('i', buf) msg = ipc_msg() msg.ParseFromString(f.read(size)) rounded = round_up(msg.msize, sizeof_u64) f.seek(rounded, os.SEEK_CUR) pl_len += size + msg.msize return pl_len
def load(self, f, pretty=False, no_payload=False): """ Convert criu image entries from binary format to dict(json). Takes a file-like object and returnes a list with entries in dict(json) format. """ entries = [] while True: entry = {} # Read payload pb = self.payload() buf = f.read(4) if buf == '': break size, = struct.unpack('i', buf) pb.ParseFromString(f.read(size)) entry = pb2dict.pb2dict(pb, pretty) # Read extra if self.extra_handler: if no_payload: def human_readable(num): for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']: if num < 1024.0: if int(num) == num: return "%d%sB" % (num, unit) else: return "%.1f%sB" % (num, unit) num /= 1024.0 return "%.1fYB" % num pl_size = self.extra_handler.skip(f, pb) entry['extra'] = '... <%s>' % human_readable(pl_size) else: entry['extra'] = self.extra_handler.load(f, pb) entries.append(entry) return entries
def load(self, f, pretty = False, no_payload = False): """ Convert criu image entries from binary format to dict(json). Takes a file-like object and returnes a list with entries in dict(json) format. """ entries = [] while True: entry = {} # Read payload pb = self.payload() buf = f.read(4) if buf == '': break size, = struct.unpack('i', buf) pb.ParseFromString(f.read(size)) entry = pb2dict.pb2dict(pb, pretty) # Read extra if self.extra_handler: if no_payload: def human_readable(num): for unit in ['','K','M','G','T','P','E','Z']: if num < 1024.0: if int(num) == num: return "%d%sB" % (num, unit) else: return "%.1f%sB" % (num, unit) num /= 1024.0 return "%.1fYB" % num pl_size = self.extra_handler.skip(f, pb) entry['extra'] = '... <%s>' % human_readable(pl_size) else: entry['extra'] = self.extra_handler.load(f, pb) entries.append(entry) return entries
def skip(self, f, pb): entry = pb2dict.pb2dict(pb) size = entry['size'] rounded = round_up(size, sizeof_u32) f.seek(rounded, os.SEEK_CUR) return size
def skip(self, f, pb): entry = pb2dict.pb2dict(pb) size = sizeof_u16 * entry['nsems'] f.seek(round_up(size, sizeof_u64), os.SEEK_CUR) return size