Read LSM scan information from file and return as Record.

def read_cz_lsm_scan_info(fd, byte_order):
    """Read LSM scan information from file and return as Record."""
    block = Record()
    blocks = [block]
    unpack = struct.unpack
    if 0x10000000 != struct.unpack(byte_order+"I", fd.read(4))[0]:
        raise ValueError("not a lsm_scan_info structure")
    fd.read(8)
    while True:
        entry, dtype, size = unpack(byte_order+"III", fd.read(12))
        if dtype == 2:
            value = stripnull(fd.read(size))
        elif dtype == 4:
            value = unpack(byte_order+"i", fd.read(4))[0]
        elif dtype == 5:
            value = unpack(byte_order+"d", fd.read(8))[0]
        else:
            value = 0
        if entry in CZ_LSM_SCAN_INFO_ARRAYS:
            blocks.append(block)
            name = CZ_LSM_SCAN_INFO_ARRAYS[entry]
            newobj = []
            setattr(block, name, newobj)
            block = newobj
        elif entry in CZ_LSM_SCAN_INFO_STRUCTS:
            blocks.append(block)
            newobj = Record()
            block.append(newobj)
            block = newobj
        elif entry in CZ_LSM_SCAN_INFO_ATTRIBUTES:
            name = CZ_LSM_SCAN_INFO_ATTRIBUTES[entry]
            setattr(block, name, value)
        elif entry == 0xffffffff:
            block = blocks.pop()
        else:
            setattr(block, "unknown_%x" % entry, value)
        if not blocks:
            break
    return block