Sei sulla pagina 1di 2

File: /home/n/fragile/prog/unix/raid_magic/checkraid.

py
#!/usr/bin/python """ Linux RAID superblock format detailed at: https://raid.wiki.kernel.org/index.php/RAID_superblock_formats """ import binascii, struct, sys, datetime, os def check_raid_superblock(f, offset=0): f.seek(offset) # start of superblock data = f.read(256) # read superblock (magic, major_version, feature_map, pad, set_uuid, set_name, ctime, level, layout, size, chunksize, raid_disks, bitmap_offset # note: signed little-endian integer "i" not "I" ) = struct.unpack_from("<4I16s32sQ2IQ2Ii", data, 0) print "\n\n-----------------------------" print "at offset %d magic 0x%08x" % (offset, magic) if magic != 0xa92b4efc: print " <unknown>" return print print print print " " " " major_version: feature_map: UUID: set_name: ", ", ", ", hex(major_version) hex(feature_map) binascii.hexlify(set_uuid) set_name

Page 1 of 2

ctime_secs = ctime & 0xFFFFFFFFFF # we only care about the seconds, so mask off the microseconds print " ctime: ", datetime.datetime.fromtimestamp(ctime_secs)

level_names = { -4: "Multi-Path", -1: "Linear", 0: "RAID-0 (Striped)", 1: "RAID-1 (Mirrored)", 4: "RAID-4 (Striped with 5: "RAID-5 (Striped with 6: "RAID-6 (Striped with 0xa: "RAID-10 (Mirror of } if level in level_names: print " level: else: print " level:

Dedicated Block-Level Parity)", Distributed Parity)", Dual Parity)", stripes)"

", level_names[level] ", level, "(unknown)"

layout_names = { 0: "left asymmetric", 1: "right asymmetric", 2: "left symmetric (default)", 3: "right symmetric", 0x01020100: "raid-10 offset2" } if layout in layout_names: print " layout: ", layout_names[layout] else: print " layout: ", layout, "(unknown)"

File: /home/n/fragile/prog/unix/raid_magic/checkraid.py
print print print print " " " " used size: chunksize: raid_disks: bitmap_offset: ", ", ", ", size/2, "kbytes" chunksize/2, "kbytes" raid_disks bitmap_offset

Page 2 of 2

if __name__ == "__main__": if os.geteuid()!=0: print "warning: you might want to run this as root" if len(sys.argv) != 2: print "usage: %s path_to_device" % sys.argv[0] sys.exit(1) filehandle = open(sys.argv[1], 'r') check_raid_superblock(filehandle, 0x0) check_raid_superblock(filehandle, 0x1000) # at the beginning # 4kbytes from the beginning

Potrebbero piacerti anche