Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # --*-- encoding: utf-8 -*-
- import argparse
- import os
- import struct
- class HostEntry(object):
- def __init__(self, logical_offset, physical_offset, length, pid):
- self.logical_offset = logical_offset
- self.physical_offset = physical_offset
- self.length = length
- self.pid = pid
- def __str__(self):
- delimter = ', '
- s = ''
- s += 'logical_offset: ' + str(self.logical_offset) + delimter
- s += 'physical_offset: ' + str(self.physical_offset) + delimter
- s += 'length: ' + str(self.length) + delimter
- s += 'pid: ' + str(self.pid) + '\n'
- return s
- def __repr__(self):
- return str(self)
- def parse(fn):
- ret = []
- ENTRY_SIZE = 48
- LOGICAL = 0
- PHYSICAL = 8
- LENGTH = 16
- PID = 40
- with open(fn, 'rb') as inp:
- bs = inp.read()
- for i in range(len(bs)/48):
- offset = i * ENTRY_SIZE
- logical_offset = struct.unpack("<LL", bs[offset+LOGICAL:offset+LOGICAL+8])[0]
- physical_offset = struct.unpack("<LL", bs[offset+PHYSICAL:offset+PHYSICAL+8])[0]
- length = struct.unpack("<LL", bs[offset+LENGTH:offset+LENGTH+8])[0]
- pid = struct.unpack("<L", bs[offset+PID:offset+PID+4])[0]
- ret.append(HostEntry(logical_offset, physical_offset, length, pid))
- # return sorted(ret, key=lambda x: x.pid)
- return sorted(ret, key=lambda x: x.logical_offset)
- def main(dirpath):
- idxs = []
- for dirpath, dirnames, filenames in os.walk(dirpath):
- for filename in filenames:
- if 'index' in filename:
- idxs.extend(parse(dirpath+'/'+filename))
- break
- print idxs
- if __name__ == '__main__':
- parser = argparse.ArgumentParser(description="Parse the index file of PLFS container")
- parser.add_argument('-i', type=str, default='/home/deng/fs/backend/poc/hostdir.26', help='输入文件夹')
- args = parser.parse_args()
- dirpath = args.i
- main(dirpath)
Add Comment
Please, Sign In to add comment