コード例 #1
0
def main():
    i = 1
    lba = 0
    while i < len(sys.argv):
        if sys.argv[i] == '--help':
            return usage()
        if sys.argv[i] == '-l':
            del sys.argv[i]
            lba = int(sys.argv[i], 10)
            del sys.argv[i]
            continue
        i += 1

    if len(sys.argv) < 2:
        return usage()

    device = sys.argv[1]

    sd = init_device(device)
    s = SCSI(sd)

    r = s.readcapacity16().result
    if not r['lbpme']:
        print 'LUN is fully provisioned.'
        return

    r = s.getlbastatus(lba).result
    for i in range(len(r['lbas'])):
        print 'LBA:%d-%d %s' % (r['lbas'][i]['lba'], r['lbas'][i]['lba'] +
                                r['lbas'][i]['num_blocks'] - 1,
                                P_STATUS[r['lbas'][i]['p_status']])
コード例 #2
0
def main():
    dev = MockMoveMedium()
    dev.opcodes = smc
    s = SCSI(dev)
    s.device.opcodes = smc
    m = s.exchangemedium(15, 32, 64, 32, inv1=1)
    cdb = m.cdb
    assert cdb[0] == s.device.opcodes.EXCHANGE_MEDIUM.value
    assert cdb[1] == 0
    assert scsi_ba_to_int(cdb[2:4]) == 15
    assert scsi_ba_to_int(cdb[4:6]) == 32
    assert scsi_ba_to_int(cdb[6:8]) == 64
    assert scsi_ba_to_int(cdb[8:10]) == 32
    assert cdb[10] == 0x02
    cdb = m.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.EXCHANGE_MEDIUM.value
    assert cdb['medium_transport_address'] == 15
    assert cdb['source_address'] == 32
    assert cdb['first_destination_address'] == 64
    assert cdb['second_destination_address'] == 32
    assert cdb['inv1'] == 1
    assert cdb['inv2'] == 0

    d = ExchangeMedium.unmarshall_cdb(ExchangeMedium.marshall_cdb(cdb))
    assert d == cdb
コード例 #3
0
def main():
    dev = MockReadElementStatus()
    dev.opcodes = smc
    s = SCSI(dev)
    s.device.opcodes = smc
    # cdb for SMC: ReadElementStatus
    r = s.readelementstatus(300, 700, element_type=READELEMENTSTATUS.ELEMENT_TYPE.STORAGE, voltag=1, curdata=1, dvcid=1)
    cdb = r.cdb
    assert cdb[0] == s.device.opcodes.READ_ELEMENT_STATUS.value
    assert cdb[1] == 0x10 | READELEMENTSTATUS.ELEMENT_TYPE.STORAGE
    assert scsi_ba_to_int(cdb[2:4]) == 300
    assert scsi_ba_to_int(cdb[4:6]) == 700
    assert cdb[6] == 0x03
    assert scsi_ba_to_int(cdb[7:10]) == 16384
    cdb = r.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.READ_ELEMENT_STATUS.value
    assert cdb['voltag'] == 1
    assert cdb['element_type'] == READELEMENTSTATUS.ELEMENT_TYPE.STORAGE
    assert cdb['starting_element_address'] == 300
    assert cdb['num_elements'] == 700
    assert cdb['curdata'] == 1
    assert cdb['dvcid'] == 1
    assert cdb['alloc_len'] == 16384

    d = ReadElementStatus.unmarshall_cdb(ReadElementStatus.marshall_cdb(cdb))
    assert d == cdb
コード例 #4
0
def main():
    dev = MockReadElementStatus()
    dev.opcodes = smc
    s = SCSI(dev)
    s.device.opcodes = smc
    # cdb for SMC: ReadElementStatus
    r = s.readelementstatus(
        300,
        700,
        element_type=READELEMENTSTATUS.ELEMENT_TYPE.STORAGE,
        voltag=1,
        curdata=1,
        dvcid=1)
    cdb = r.cdb
    assert cdb[0] == s.device.opcodes.READ_ELEMENT_STATUS.value
    assert cdb[1] == 0x10 | READELEMENTSTATUS.ELEMENT_TYPE.STORAGE
    assert scsi_ba_to_int(cdb[2:4]) == 300
    assert scsi_ba_to_int(cdb[4:6]) == 700
    assert cdb[6] == 0x03
    assert scsi_ba_to_int(cdb[7:10]) == 16384
    cdb = r.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.READ_ELEMENT_STATUS.value
    assert cdb['voltag'] == 1
    assert cdb['element_type'] == READELEMENTSTATUS.ELEMENT_TYPE.STORAGE
    assert cdb['starting_element_address'] == 300
    assert cdb['num_elements'] == 700
    assert cdb['curdata'] == 1
    assert cdb['dvcid'] == 1
    assert cdb['alloc_len'] == 16384

    d = ReadElementStatus.unmarshall_cdb(ReadElementStatus.marshall_cdb(cdb))
    assert d == cdb
コード例 #5
0
def find_device(device, debug):
    if device is None:
        devices = glob.glob('/dev/sg[0-9]*')
    else:
        devices = [device]
    for device in devices:
        try:
            if debug:
                print("Trying", device, ' ', end='')
            sd = SCSIDevice(device)
            s = SCSI(sd)
            i = s.inquiry().result
            vendor = i['t10_vendor_identification'].decode(
                "latin1", "backslashreplace").strip()
            product = i['product_identification'].decode(
                "latin1", "backslashreplace").strip()
            if debug:
                print(vendor, product)
            if vendor == 'YULIN' and product == 'PROGRAMMER':
                print("Device", device)
                return sd
        except Exception as e:
            print("Exception", traceback.format_exc())
            pass
    raise BaseException("Cannot find JQ6500 (YULIN PROGRAMMER) device")
コード例 #6
0
def main():
    dev = MockMoveMedium()
    dev.opcodes = smc
    s = SCSI(dev)
    s.device.opcodes = smc
    m = s.exchangemedium(15, 32, 64, 32, inv1=1)
    cdb = m.cdb
    assert cdb[0] == s.device.opcodes.EXCHANGE_MEDIUM.value
    assert cdb[1] == 0
    assert scsi_ba_to_int(cdb[2:4]) == 15
    assert scsi_ba_to_int(cdb[4:6]) == 32
    assert scsi_ba_to_int(cdb[6:8]) == 64
    assert scsi_ba_to_int(cdb[8:10]) == 32
    assert cdb[10] == 0x02
    cdb = m.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.EXCHANGE_MEDIUM.value
    assert cdb['medium_transport_address'] == 15
    assert cdb['source_address'] == 32
    assert cdb['first_destination_address'] == 64
    assert cdb['second_destination_address'] == 32
    assert cdb['inv1'] == 1
    assert cdb['inv2'] == 0

    d = ExchangeMedium.unmarshall_cdb(ExchangeMedium.marshall_cdb(cdb))
    assert d == cdb
コード例 #7
0
def main():
    i = 1
    lba = 0
    while i < len(sys.argv):
        if sys.argv[i] == '--help':
            return usage()
        if sys.argv[i] == '-l':
            del sys.argv[i]
            lba = int(sys.argv[i], 10)
            del sys.argv[i]
            continue
        i += 1

    if len(sys.argv) < 2:
        return usage()

    device = sys.argv[1]

    sd = SCSIDevice(device)
    s = SCSI(sd)

    r = s.readcapacity16().result
    if not r['lbpme']:
        print 'LUN is fully provisioned.'
        return

    r = s.getlbastatus(lba).result
    for i in range(len(r['lbas'])):
        print 'LBA:%d-%d %s' % (
            r['lbas'][i]['lba'],
            r['lbas'][i]['lba'] + r['lbas'][i]['num_blocks'] - 1,
            P_STATUS[r['lbas'][i]['p_status']]
        )
コード例 #8
0
def write_flash(sd, blocksize, offset, size, indata, debug=False):
    if size > MAX_BLOCKS:
        raise BaseException("Out of range (max " + str((MAX_BLOCKS) * 256) +
                            " bytes)")
    data = bytearray()
    data.extend(indata)
    while len(data) < size * 0x100:
        data.append(0)
    # Erase
    for i in range(0, size, 16):
        s = SCSI(sd, 0x0)
        r = erase_jq6500(
            s,
            (offset + i) * 0x100,
        )
        print("Erase flash", offset + i, '/', offset + size, "\r", end=' ')
        sys.stdout.flush()
        if debug:
            print("CMD", repr(r.cdb))
    print()
    # Write
    for i in range(0, size, 1):
        s = SCSI(sd, 0x100)
        d = data[(i * 0x100):((i + 1) * 0x100)]
        try:
            r = write_jq6500(s, (offset + i) * 0x100, 0x100, d)
        except Exception as e:
            print()
            print("Exception", repr(e))
            print((e.message))
            print("Retry")
            r = write_jq6500(s, (offset + i) * 0x100, 0x100, d)
        print("Write flash", offset + i, '/', offset + size, "\r", end=' ')
        sys.stdout.flush()
        if debug:
            print("CMD", repr(r.cdb))
    print()
    # Verify
    for i in range(0, size, 16):
        s = SCSI(sd, 0x4096)
        r = read_jq6500(
            s,
            (offset + i) * 0x100,
            16 * 0x100,
        )
        d1 = r.datain
        d2 = data[(i * 0x100):((i + 16) * 0x100)]
        print("Verify flash", offset + i, '/', offset + size, "\r", end=' ')
        sys.stdout.flush()
        if debug:
            print("CMD", repr(r.cdb))
        for j in range(len(d2)):
            if i + j / 256 >= size:
                continue
            assert d2[j] == d1[j], (
                "Verify failed, block %d, [%d] %x != %x" %
                (offset + i + j / 256, j & 0xff, d2[j], d1[j]))
    print()
コード例 #9
0
ファイル: inquiry.py プロジェクト: c-r-h/python-scsi
def main():
    i = 1
    page_code = 0
    evpd = 0
    while i < len(sys.argv):
        if sys.argv[i] == '--help':
            return usage()
        if sys.argv[i] == '-p':
            del sys.argv[i]
            page_code = int(sys.argv[i], 16)
            evpd = 1
            del sys.argv[i]
            continue
        i += 1

    if len(sys.argv) < 2:
        return usage()

    device = sys.argv[1]

    sd = SCSIDevice(device)
    s = SCSI(sd)

    i = s.testunitready()

    if not evpd:
        inquiry_standard(s)
        return

    if page_code == INQUIRY.VPD.SUPPORTED_VPD_PAGES:
        inquiry_supported_vpd_pages(s)
        return

    if page_code == INQUIRY.VPD.BLOCK_LIMITS:
        inquiry_block_limits(s)
        return

    if page_code == INQUIRY.VPD.BLOCK_DEVICE_CHARACTERISTICS:
        inquiry_block_dev_char(s)
        return

    if page_code == INQUIRY.VPD.LOGICAL_BLOCK_PROVISIONING:
        inquiry_logical_block_prov(s)
        return

    if page_code == INQUIRY.VPD.UNIT_SERIAL_NUMBER:
        inquiry_unit_serial_number(s)
        return

    if page_code == INQUIRY.VPD.DEVICE_IDENTIFICATION:
        inquiry_device_identification(s)
        return

    print 'No pretty print for this page, page_code=0x%02x' % page_code
    print '=============================================\n'
    i = s.inquiry(evpd=1, page_code=page_code).result
    for k, v in i.iteritems():
        print '%s - %s' % (k, v)
コード例 #10
0
def main():
    i = 1
    page_code = 0
    evpd = 0
    while i < len(sys.argv):
        if sys.argv[i] == '--help':
            return usage()
        if sys.argv[i] == '-p':
            del sys.argv[i]
            page_code = int(sys.argv[i], 16)
            evpd = 1
            del sys.argv[i]
            continue
        i += 1

    if len(sys.argv) < 2:
        return usage()

    device = sys.argv[1]

    sd = SCSIDevice(device)
    s = SCSI(sd)

    i = s.testunitready()

    if not evpd:
        inquiry_standard(s)
        return

    if page_code == INQUIRY.VPD.SUPPORTED_VPD_PAGES:
        inquiry_supported_vpd_pages(s)
        return

    if page_code == INQUIRY.VPD.BLOCK_LIMITS:
        inquiry_block_limits(s)
        return

    if page_code == INQUIRY.VPD.BLOCK_DEVICE_CHARACTERISTICS:
        inquiry_block_dev_char(s)
        return

    if page_code == INQUIRY.VPD.LOGICAL_BLOCK_PROVISIONING:
        inquiry_logical_block_prov(s)
        return

    if page_code == INQUIRY.VPD.UNIT_SERIAL_NUMBER:
        inquiry_unit_serial_number(s)
        return

    if page_code == INQUIRY.VPD.DEVICE_IDENTIFICATION:
        inquiry_device_identification(s)
        return

    print 'No pretty print for this page, page_code=0x%02x' % page_code
    print '=============================================\n'
    i = s.inquiry(evpd=1, page_code=page_code).result
    for k, v in i.iteritems():
        print '%s - %s' % (k, v)
コード例 #11
0
    def __init__(self, device):
        if not device:
            raise exceptions.CommandLineError(
                '--device parameter is required, should point to the disk '
                'device representing the meter.')

        self.device_name_ = device
        self.scsi_device_ = SCSIDevice(device, readwrite=True)
        self.scsi_ = SCSI(self.scsi_device_)
        self.scsi_.blocksize = _REGISTER_SIZE
コード例 #12
0
ファイル: reportluns.py プロジェクト: rosjat/python-scsi
def main(device):
    try:
        sd = SCSIDevice(device)
        s = SCSI(sd)
        print "ReportLuns"
        print "==========================================\n"
        r = s.reportluns().result
        for k, v in r.iteritems():
            print ("%s - %s" % (k, v))
    except Exception as e:
        print (e.message)
コード例 #13
0
ファイル: reportluns.py プロジェクト: jlutran/python-scsi
def main(device):
    try:
        sd = SCSIDevice(device)
        s = SCSI(sd)
        print 'ReportLuns'
        print '==========================================\n'
        r = s.reportluns().result
        for k, v in r.iteritems():
            print('%s - %s' % (k, v))
    except Exception as e:
        print (e.message)
コード例 #14
0
def main():
    dev = MockReadCapacity10()
    dev.opcodes = sbc
    s = SCSI(dev)

    i = s.readcapacity10().result
    assert i['returned_lba'] == 65536
    assert i['block_length'] == 4096

    d = ReadCapacity10.unmarshall_datain(ReadCapacity10.marshall_datain(i))
    assert d == i
コード例 #15
0
def main(device):
    try:
        sd = SCSIDevice(device)
        s = SCSI(sd)
        print 'ReadCapacity10'
        print '==========================================\n'
        r = s.readcapacity10().result
        for k, v in r.iteritems():
            print '%s - %s' % (k, v)
    except Exception as e:
        print (e.message)
コード例 #16
0
def main(device):
    try:
        sd = SCSIDevice(device)
        s = SCSI(sd)
        print 'ReadCapacity10'
        print '==========================================\n'
        r = s.readcapacity10().result
        for k, v in r.iteritems():
            print '%s - %s' % (k, v)
    except Exception as e:
        print(e.message)
コード例 #17
0
def main():
    dev = MockReadCapacity10()
    dev.opcodes = sbc
    s = SCSI(dev)

    i = s.readcapacity10().result
    assert i["returned_lba"] == 65536
    assert i["block_length"] == 4096

    d = ReadCapacity10.unmarshall_datain(ReadCapacity10.marshall_datain(i))
    assert d == i
コード例 #18
0
    def __init__(self, device: Optional[str]) -> None:
        if not device:
            raise exceptions.CommandLineError(
                "--device parameter is required, should point to the disk "
                "device representing the meter.")

        super().__init__(device)

        self.device_name_ = device
        self.scsi_device_ = SCSIDevice(device, readwrite=True)
        self.scsi_ = SCSI(self.scsi_device_)
        self.scsi_.blocksize = _REGISTER_SIZE
コード例 #19
0
def main():
    dev = MockModeSense10()
    dev.opcodes = smc
    s = SCSI(dev)

    # cdb for SMC: ElementAddressAssignment
    m = s.modesense10(
        page_code=MODESENSE10.PAGE_CODE.ELEMENT_ADDRESS_ASSIGNMENT)
    cdb = m.cdb
    assert cdb[0] == s.device.opcodes.MODE_SENSE_10.value
    assert cdb[1] == 0
    assert cdb[2] == MODESENSE10.PAGE_CODE.ELEMENT_ADDRESS_ASSIGNMENT
    assert cdb[3] == 0
    assert cdb[4:6] == bytearray(2)
    assert scsi_ba_to_int(cdb[7:9]) == 96
    assert cdb[9] == 0
    cdb = m.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.MODE_SENSE_10.value
    assert cdb['dbd'] == 0
    assert cdb['llbaa'] == 0
    assert cdb['page_code'] == MODESENSE10.PAGE_CODE.ELEMENT_ADDRESS_ASSIGNMENT
    assert cdb['pc'] == 0
    assert cdb['sub_page_code'] == 0
    assert cdb['alloc_len'] == 96

    d = ModeSense10.unmarshall_cdb(ModeSense10.marshall_cdb(cdb))
    assert d == cdb

    m = s.modesense10(page_code=0,
                      sub_page_code=3,
                      llbaa=1,
                      dbd=1,
                      pc=MODESENSE10.PC.DEFAULT,
                      alloclen=90)
    cdb = m.cdb
    assert cdb[0] == s.device.opcodes.MODE_SENSE_10.value
    assert cdb[1] == 0x18
    assert cdb[2] == MODESENSE10.PC.DEFAULT << 6
    assert cdb[3] == 3
    assert scsi_ba_to_int(cdb[7:9]) == 90
    cdb = m.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.MODE_SENSE_10.value
    assert cdb['dbd'] == 1
    assert cdb['pc'] == MODESENSE10.PC.DEFAULT
    assert cdb['page_code'] == 0
    assert cdb['sub_page_code'] == 3
    assert cdb['alloc_len'] == 90
    assert cdb['llbaa'] == 1

    d = ModeSense10.unmarshall_cdb(ModeSense10.marshall_cdb(cdb))
    assert d == cdb
コード例 #20
0
def main():
    dev = MockReadCapacity10()
    dev.opcodes = sbc
    s = SCSI(dev)

    s.device.opcodes = sbc
    r = s.readcapacity10()
    cdb = r.cdb
    assert cdb[0] == s.device.opcodes.READ_CAPACITY_10.value
    assert cdb[1:10] == bytearray(9)
    cdb = r.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.READ_CAPACITY_10.value

    d = ReadCapacity10.unmarshall_cdb(ReadCapacity10.marshall_cdb(cdb))
    assert d == cdb
コード例 #21
0
def main():
    dev = MockPreventAllowMediumRemoval()
    dev.opcodes = smc
    s = SCSI(dev)
    s.device.opcodes = smc
    m = s.preventallowmediumremoval(prevent=3)
    cdb = m.cdb
    assert cdb[0] == s.device.opcodes.PREVENT_ALLOW_MEDIUM_REMOVAL.value
    assert cdb[8] == 0x03
    cdb = m.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.PREVENT_ALLOW_MEDIUM_REMOVAL.value
    assert cdb['prevent'] == 3

    d = PreventAllowMediumRemoval.unmarshall_cdb(PreventAllowMediumRemoval.marshall_cdb(cdb))
    assert d == cdb
コード例 #22
0
def main():
    dev = MockReadCapacity10()
    dev.opcodes = sbc
    s = SCSI(dev)

    s.device.opcodes = sbc
    r = s.readcapacity10()
    cdb = r.cdb
    assert cdb[0] == s.device.opcodes.READ_CAPACITY_10.value
    assert cdb[1:10] == bytearray(9)
    cdb = r.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.READ_CAPACITY_10.value

    d = ReadCapacity10.unmarshall_cdb(ReadCapacity10.marshall_cdb(cdb))
    assert d == cdb
コード例 #23
0
ファイル: trimall.py プロジェクト: jackeichen/python-scsi
def main():
    '''
    Now trim is must 4k aligned.
    '''
    ParaDict = handle_para()
    device = ParaDict["device"]
    with SCSI(device, 512) as s:
        capacity = s.readcapacity10().result
        LBAs = int(capacity['returned_lba'])
        print("Trim total LBA: %s" % LBAs)
        ##
        while 1:
            ret = input(
                "WARNING: Dangerous operation, will destroy all data in the disk, continue (y/n)? "
            )
            if ret.lower() == 'y':
                print('')
                print('issuing trimall command')
                print("%s:" % device._file_name)
                start_t = time.time()
                r = s.trimall(LBAs)
                print("Trim done, total used: %ss" % (time.time() - start_t))
                print('')
            elif ret.lower() == 'n':
                print("Exit...")
            else:
                print("Wrong input!")
                continue
            break
コード例 #24
0
def main(device):
    try:
        sd = SCSIDevice(device)
        s = SCSI(sd)
        s.testunitready()
    except Exception as e:
        print (e)
    else:
        print ('ReportPriority')
        print ('==========================================\n')
        try:
            r = s.reportpriority().result
            for k, v in r.iteritems():
                print('%s - %s' % (k, v))
        except Exception as e:
                print (e)
コード例 #25
0
def main():
    dev = MockPreventAllowMediumRemoval()
    dev.opcodes = smc
    s = SCSI(dev)
    s.device.opcodes = smc
    m = s.preventallowmediumremoval(prevent=3)
    cdb = m.cdb
    assert cdb[0] == s.device.opcodes.PREVENT_ALLOW_MEDIUM_REMOVAL.value
    assert cdb[8] == 0x03
    cdb = m.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.PREVENT_ALLOW_MEDIUM_REMOVAL.value
    assert cdb['prevent'] == 3

    d = PreventAllowMediumRemoval.unmarshall_cdb(
        PreventAllowMediumRemoval.marshall_cdb(cdb))
    assert d == cdb
コード例 #26
0
ファイル: reportpriority.py プロジェクト: jlutran/python-scsi
def main(device):
    try:
        sd = SCSIDevice(device)
        s = SCSI(sd)
        s.testunitready()
    except Exception as e:
        print(e)
    else:
        print('ReportPriority')
        print('==========================================\n')
        try:
            r = s.reportpriority().result
            for k, v in r.iteritems():
                print('%s - %s' % (k, v))
        except Exception as e:
            print(e)
コード例 #27
0
ファイル: readcapacity16.py プロジェクト: hrchu/python-scsi
def main(device):
    with SCSI(device) as s:
        print 'ReadCapacity16'
        print '==========================================\n'
        r = s.readcapacity16().result
        for k, v in r.iteritems():
            print '%s - %s' % (k, v)
コード例 #28
0
ファイル: IOtool.py プロジェクト: jackeichen/python-scsi
def main():
    dev = sys.argv[1]
    device = init_device(sys.argv[1])
    ##
    data = DataGen()
    t_interval = 1
    gc_cycle = 0
    print("Writing...")
    with SCSI(device, 512) as s:
        t_new = t_start = time.time()
        for i in range(0, 1000215215):
            cmd = s.write_DMA16(i, 1, data.gen_new_unit_data_write(i))
            t_current = time.time()
            if i % 100000 == 0:
                gc_cycle += 1
                gc.collect()
            if (t_current - t_new) >= t_interval:
                t_new = t_current
                total_write = i / 2048  # MB
                time_used = t_new - t_start
                print(
                    '[Total write: %.5fGB/%sGB, used time: %ds, rate: %.5f MB/s, gc cycles: %d]'
                    % (total_write / 1024, '512', time_used,
                       (total_write / time_used), gc_cycle),
                    end='\r')

    print('')
    print('')
    print('Total used: %ss' % (time.time() - t_start))
コード例 #29
0
def main():
    dev = MockInitializeElementStatus()
    dev.opcodes = smc
    s = SCSI(dev)
    # we need to reassign the right enum again because the MockDevice will return the wrong
    # peripheral_device_type and therefor assign the spc enum instead of smc.
    s.device.opcodes = smc

    r = s.initializeelementstatus()
    cdb = r.cdb
    assert cdb[0] == s.device.opcodes.INITIALIZE_ELEMENT_STATUS.value
    cdb = r.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.INITIALIZE_ELEMENT_STATUS.value

    d = InitializeElementStatus.unmarshall_cdb(InitializeElementStatus.marshall_cdb(cdb))
    assert d == cdb
コード例 #30
0
def main():
    dev = MockGetLBAStatus()
    dev.opcodes = sbc
    s = SCSI(dev)
    
    i = s.getlbastatus(0).result
    assert len(i['lbas']) == 2
    assert i['lbas'][0]['lba'] == 1023
    assert i['lbas'][0]['num_blocks'] == 27
    assert i['lbas'][0]['p_status'] == P_STATUS.MAPPED
    assert i['lbas'][1]['lba'] == 200000
    assert i['lbas'][1]['num_blocks'] == 9999
    assert i['lbas'][1]['p_status'] == P_STATUS.DEALLOCATED

    d = GetLBAStatus.unmarshall_datain(GetLBAStatus.marshall_datain(i))
    assert d == i
コード例 #31
0
def main(device):
    with SCSI(device, 512) as s:
        data = s.smart(SMART_KEY).result
        vs_smart = data.pop('smartInfo')
        general_smart = data

    print('General SMART Values:')
    print('=' * 100)
    for name, value in general_smart.items():
        dt = value[::-1]
        r = binascii.hexlify(dt)
        print('%34s: %-10d [0x%s]' % (name, int(r, 16), r.decode()))
    print('')
    print('Vendor Specific SMART Attributes with Thresholds:')
    print('=' * 100)
    print_fomrat = '%3s %-25s %-6s %-6s %-6s %-10s %-10s %-10s %-10s'
    print(print_fomrat % ('ID#', 'ATTRIBUTE_NAME', 'FLAG', 'VALUE', 'WORST',
                          'RAW_VALUE0', 'RAW_V_MIN', 'RAW_V_MAX', 'THRESHOLD'))
    print('-' * 100)
    for i in range(0, 359, 12):
        ID = str(vs_smart[i])
        if ID not in SMART_ATTR:
            continue
        print(print_fomrat % (
            ID,  # ID
            SMART_ATTR[ID],  # ATTRIBUTE_NAME
            vs_smart[i + 1],  # FLAG
            vs_smart[i + 3],  # VALUE
            vs_smart[i + 4],  # WORST
            bytearray2hex_l(vs_smart, i + 5, 2),  # RAW_VALUE0
            bytearray2hex_l(vs_smart, i + 7, 2),  # RAW_V_MIN
            bytearray2hex_l(vs_smart, i + 9, 2),  # RAW_V_MAX
            vs_smart[i + 11])  # THRESHOLD
              )
コード例 #32
0
def main(device):
    with SCSI(device) as s:
        print('ReportLuns')
        print('==========================================\n')
        r = s.reportluns().result
        for k, v in r.iteritems():
            print('%s - %s' % (k, v))
コード例 #33
0
def main():
    dev = MockGetLBAStatus()
    dev.opcodes = sbc
    s = SCSI(dev)

    i = s.getlbastatus(0).result
    assert len(i['lbas']) == 2
    assert i['lbas'][0]['lba'] == 1023
    assert i['lbas'][0]['num_blocks'] == 27
    assert i['lbas'][0]['p_status'] == P_STATUS.MAPPED
    assert i['lbas'][1]['lba'] == 200000
    assert i['lbas'][1]['num_blocks'] == 9999
    assert i['lbas'][1]['p_status'] == P_STATUS.DEALLOCATED

    d = GetLBAStatus.unmarshall_datain(GetLBAStatus.marshall_datain(i))
    assert d == i
コード例 #34
0
def main(device):
    with SCSI(device) as s:
        print('ReadCapacity10')
        print('==========================================\n')
        r = s.readcapacity10().result
        for k, v in r.iteritems():
            print('%s - %s' % (k, v))
コード例 #35
0
def download(dev, path):
    dev = init_device(dev)
    with open(path, 'r') as fp:
        data = fp.read()
    ## check fw if multiple of 512
    res = len(data) % 512
    if res != 0:
        data += (chr(0) * (512 - re))  #必须512的倍数,不足补齐
    ##
    lba = 0
    length = len(data) / 512
    #
    quotients = int(length / Transfer_Size)
    remainders = length % Transfer_Size
    ##
    data_size = 512 * Transfer_Size
    dataview = memoryview(data)
    with SCSI(dev, 512) as s:
        for i in range(0, quotients):
            s.download_microcode(lba, Transfer_Size,
                                 dataview[i * data_size:(i + 1) * data_size])
            lba += Transfer_Size
        if remainders != 0:
            s.download_microcode(lba, remainders,
                                 dataview[quotients * data_size:])
コード例 #36
0
def main(device):
    r = None
    with SCSI(device, 512) as s:
        print('issuing get accessible max address')
        print("%s:" % device._file_name)
        cmd = s.GetAccessibleMaxAddress()
        sense_data = SenseData(cmd.sense)
        LBA = sense_data.ATAStatusReturnDescriptor.LBA.value
        extend = sense_data.ATAStatusReturnDescriptor.ExtendByte.Extend
        # print (sense_data.value)
        # print (sense_data.ATAStatusReturnDescriptor.value)
        # print (sense_data.ATAStatusReturnDescriptor.ExtendByte.value)
        # print (LBA, extend)
        ##
        LBA_h = bytearray(6)
        #
        LBA_h[3] = LBA[5]
        LBA_h[4] = LBA[3]
        LBA_h[5] = LBA[1]
        if extend:  # extend = 1
            LBA_h[0] = LBA[4]
            LBA_h[1] = LBA[2]
            LBA_h[2] = LBA[0]
        ##
        LBA_max = int.from_bytes(LBA_h, byteorder='big', signed=False)
        print("Max LBA address: %s" % LBA_max)
    print('')
    return LBA_max
コード例 #37
0
def main():
    dev = MockWrite12()
    dev.opcodes = sbc
    s = SCSI(dev)
    s.blocksize = 512

    data = bytearray(27 * 512)

    w = s.write12(1024, 27, data)
    cdb = w.cdb
    assert cdb[0] == s.device.opcodes.WRITE_12.value
    assert cdb[1] == 0
    assert scsi_ba_to_int(cdb[2:6]) == 1024
    assert scsi_ba_to_int(cdb[6:10]) == 27
    assert cdb[10] == 0
    assert cdb[11] == 0
    cdb = w.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.WRITE_12.value
    assert cdb['wrprotect'] == 0
    assert cdb['dpo'] == 0
    assert cdb['fua'] == 0
    assert cdb['lba'] == 1024
    assert cdb['group'] == 0
    assert cdb['tl'] == 27

    d = Write12.unmarshall_cdb(Write12.marshall_cdb(cdb))
    assert d == cdb

    w = s.write12(65536, 27, data, wrprotect=2, dpo=1, fua=1, group=19)
    cdb = w.cdb
    assert cdb[0] == s.device.opcodes.WRITE_12.value
    assert cdb[1] == 0x58
    assert scsi_ba_to_int(cdb[2:6]) == 65536
    assert scsi_ba_to_int(cdb[6:10]) == 27
    assert cdb[10] == 0x13
    assert cdb[11] == 0
    cdb = w.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.WRITE_12.value
    assert cdb['wrprotect'] == 2
    assert cdb['dpo'] == 1
    assert cdb['fua'] == 1
    assert cdb['lba'] == 65536
    assert cdb['group'] == 19
    assert cdb['tl'] == 27

    d = Write12.unmarshall_cdb(Write12.marshall_cdb(cdb))
    assert d == cdb
コード例 #38
0
def main():
    dev = MockModeSense6()
    dev.opcodes = spc
    s = SCSI(dev)

    # cdb for SMC: ElementAddressAssignment
    m = s.modesense6(page_code=MODESENSE6.PAGE_CODE.ELEMENT_ADDRESS_ASSIGNMENT)
    cdb = m.cdb
    assert cdb[0] == s.device.opcodes.MODE_SENSE_6.value
    assert cdb[1] == 0
    assert cdb[2] == MODESENSE6.PAGE_CODE.ELEMENT_ADDRESS_ASSIGNMENT
    assert cdb[3] == 0
    assert cdb[4] == 96
    assert cdb[5] == 0
    cdb = m.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.MODE_SENSE_6.value
    assert cdb['dbd'] == 0
    assert cdb['pc'] == 0
    assert cdb['page_code'] == MODESENSE6.PAGE_CODE.ELEMENT_ADDRESS_ASSIGNMENT
    assert cdb['sub_page_code'] == 0
    assert cdb['alloc_len'] == 96

    d = ModeSense6.unmarshall_cdb(ModeSense6.marshall_cdb(cdb))
    assert d == cdb

    m = s.modesense6(page_code=0,
                     sub_page_code=3,
                     dbd=1,
                     pc=MODESENSE6.PC.DEFAULT,
                     alloclen=90)
    cdb = m.cdb
    assert cdb[0] == s.device.opcodes.MODE_SENSE_6.value
    assert cdb[1] == 0x08
    assert cdb[2] == MODESENSE6.PC.DEFAULT << 6
    assert cdb[3] == 3
    assert cdb[4] == 90
    assert cdb[5] == 0
    cdb = m.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.MODE_SENSE_6.value
    assert cdb['dbd'] == 1
    assert cdb['pc'] == MODESENSE6.PC.DEFAULT
    assert cdb['page_code'] == 0
    assert cdb['sub_page_code'] == 3
    assert cdb['alloc_len'] == 90

    d = ModeSense6.unmarshall_cdb(ModeSense6.marshall_cdb(cdb))
    assert d == cdb
コード例 #39
0
def main():
    dev = MockWrite12()
    dev.opcodes = sbc
    s = SCSI(dev)
    s.blocksize = 512

    data = bytearray(27 * 512)

    w = s.write12(1024, 27, data)
    cdb = w.cdb
    assert cdb[0] == s.device.opcodes.WRITE_12.value
    assert cdb[1] == 0
    assert scsi_ba_to_int(cdb[2:6]) == 1024
    assert scsi_ba_to_int(cdb[6:10]) == 27
    assert cdb[10] == 0
    assert cdb[11] == 0
    cdb = w.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.WRITE_12.value
    assert cdb['wrprotect'] == 0
    assert cdb['dpo'] == 0
    assert cdb['fua'] == 0
    assert cdb['lba'] == 1024
    assert cdb['group'] == 0
    assert cdb['tl'] == 27

    d = Write12.unmarshall_cdb(Write12.marshall_cdb(cdb))
    assert d == cdb

    w = s.write12(65536, 27, data, wrprotect=2, dpo=1, fua=1, group=19)
    cdb = w.cdb
    assert cdb[0] == s.device.opcodes.WRITE_12.value
    assert cdb[1] == 0x58
    assert scsi_ba_to_int(cdb[2:6]) == 65536
    assert scsi_ba_to_int(cdb[6:10]) == 27
    assert cdb[10] == 0x13
    assert cdb[11] == 0
    cdb = w.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.WRITE_12.value
    assert cdb['wrprotect'] == 2
    assert cdb['dpo'] == 1
    assert cdb['fua'] == 1
    assert cdb['lba'] == 65536
    assert cdb['group'] == 19
    assert cdb['tl'] == 27

    d = Write12.unmarshall_cdb(Write12.marshall_cdb(cdb))
    assert d == cdb
コード例 #40
0
def main():
    dev = MockRead16()
    dev.opcodes = sbc
    s = SCSI(dev)
    s.blocksize = 512

    r = s.read16(1024, 27)
    cdb = r.cdb
    assert cdb[0] == s.device.opcodes.READ_16.value
    assert cdb[1] == 0
    assert scsi_ba_to_int(cdb[2:10]) == 1024
    assert scsi_ba_to_int(cdb[10:14]) == 27
    assert cdb[14] == 0
    assert cdb[15] == 0
    cdb = r.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.READ_16.value
    assert cdb['rdprotect'] == 0
    assert cdb['dpo'] == 0
    assert cdb['fua'] == 0
    assert cdb['rarc'] == 0
    assert cdb['lba'] == 1024
    assert cdb['group'] == 0
    assert cdb['tl'] == 27

    d = Read16.unmarshall_cdb(Read16.marshall_cdb(cdb))
    assert d == cdb

    r = s.read16(1024, 27, rdprotect=2, dpo=1, fua=1, rarc=1, group=19)
    cdb = r.cdb
    assert cdb[0] == s.device.opcodes.READ_16.value
    assert cdb[1] == 0x5c
    assert scsi_ba_to_int(cdb[2:10]) == 1024
    assert scsi_ba_to_int(cdb[10:14]) == 27
    assert cdb[14] == 0x13
    assert cdb[15] == 0
    cdb = r.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.READ_16.value
    assert cdb['rdprotect'] == 2
    assert cdb['dpo'] == 1
    assert cdb['fua'] == 1
    assert cdb['rarc'] == 1
    assert cdb['lba'] == 1024
    assert cdb['group'] == 19
    assert cdb['tl'] == 27

    d = Read16.unmarshall_cdb(Read16.marshall_cdb(cdb))
    assert d == cdb
コード例 #41
0
ファイル: test_cdb_read10.py プロジェクト: c-r-h/python-scsi
def main():
    dev = MockRead10()
    dev.opcodes = sbc
    s = SCSI(dev)

    r = s.read10(1024, 27)
    cdb = r.cdb
    assert cdb[0] == s.device.opcodes.READ_10.value
    assert cdb[1] == 0
    assert scsi_ba_to_int(cdb[2:6]) == 1024
    assert cdb[6] == 0
    assert scsi_ba_to_int(cdb[7:9]) == 27
    assert cdb[9] == 0
    cdb = r.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.READ_10.value
    assert cdb['rdprotect'] == 0
    assert cdb['dpo'] == 0
    assert cdb['fua'] == 0
    assert cdb['rarc'] == 0
    assert cdb['lba'] == 1024
    assert cdb['group'] == 0
    assert cdb['tl'] == 27

    d = Read10.unmarshall_cdb(Read10.marshall_cdb(cdb))
    assert d == cdb

    r = s.read10(1024, 27, rdprotect=2, dpo=1, fua=1, rarc=1, group=19)
    cdb = r.cdb
    assert cdb[0] == s.device.opcodes.READ_10.value
    assert cdb[1] == 0x5c
    assert scsi_ba_to_int(cdb[2:6]) == 1024
    assert cdb[6] == 0x13
    assert scsi_ba_to_int(cdb[7:9]) == 27
    assert cdb[9] == 0
    cdb = r.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.READ_10.value
    assert cdb['rdprotect'] == 2
    assert cdb['dpo'] == 1
    assert cdb['fua'] == 1
    assert cdb['rarc'] == 1
    assert cdb['lba'] == 1024
    assert cdb['group'] == 19
    assert cdb['tl'] == 27

    d = Read10.unmarshall_cdb(Read10.marshall_cdb(cdb))
    assert d == cdb
def main():
    dev = MockOpenCloseImportExportElement()
    dev.opcodes = smc
    s = SCSI(dev)
    s.device.opcodes = smc
    m = s.opencloseimportexportelement(32, s.device.opcodes.OPEN_CLOSE_IMPORT_EXPORT_ELEMENT.serviceaction.CLOSE_IMPORTEXPORT_ELEMENT)
    cdb = m.cdb
    assert cdb[0] == s.device.opcodes.OPEN_CLOSE_IMPORT_EXPORT_ELEMENT.value
    assert scsi_ba_to_int(cdb[2:4]) == 32
    assert cdb[4] == 0x01
    cdb = m.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.OPEN_CLOSE_IMPORT_EXPORT_ELEMENT.value
    assert cdb['element_address'] == 32
    assert cdb['action_code'] == s.device.opcodes.OPEN_CLOSE_IMPORT_EXPORT_ELEMENT.serviceaction.CLOSE_IMPORTEXPORT_ELEMENT

    d = OpenCloseImportExportElement.unmarshall_cdb(OpenCloseImportExportElement.marshall_cdb(cdb))
    assert d == cdb
コード例 #43
0
ファイル: DiskWrite.py プロジェクト: jackeichen/python-scsi
def main():
    GetOptions()
    device = init_device(dev)
    with SCSI(device, options.bs) as s:
        print('issuing write command')
        print("%s:" % device._file_name)
        cmd = s.write_DMA16(options.slba, options.nlb, options.data)
        print('')
コード例 #44
0
def main(device):
    with SCSI(device) as s:
        s.testunitready()
        print ('ReportPriority')
        print ('==========================================\n')
        r = s.reportpriority().result
        for k, v in r.items():
            print('%s - %s' % (k, v))
コード例 #45
0
def main():
    dev = MockInitializeElementStatus()
    dev.opcodes = smc
    s = SCSI(dev)
    # we need to reassign the right enum again because the MockDevice will return the wrong
    # peripheral_device_type and therefor assign the spc enum instead of smc.
    s.device.opcodes = smc

    r = s.initializeelementstatus()
    cdb = r.cdb
    assert cdb[0] == s.device.opcodes.INITIALIZE_ELEMENT_STATUS.value
    cdb = r.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.INITIALIZE_ELEMENT_STATUS.value

    d = InitializeElementStatus.unmarshall_cdb(
        InitializeElementStatus.marshall_cdb(cdb))
    assert d == cdb
コード例 #46
0
def main():
    dev = MockModeSense10()
    dev.opcodes = smc
    s = SCSI(dev)

    # cdb for SMC: ElementAddressAssignment
    m = s.modesense10(page_code=MODESENSE10.PAGE_CODE.ELEMENT_ADDRESS_ASSIGNMENT)
    cdb = m.cdb
    assert cdb[0] == s.device.opcodes.MODE_SENSE_10.value
    assert cdb[1] == 0
    assert cdb[2] == MODESENSE10.PAGE_CODE.ELEMENT_ADDRESS_ASSIGNMENT
    assert cdb[3] == 0
    assert cdb[4:6] == bytearray(2)
    assert scsi_ba_to_int(cdb[7:9]) == 96
    assert cdb[9] == 0
    cdb = m.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.MODE_SENSE_10.value
    assert cdb['dbd'] == 0
    assert cdb['llbaa'] == 0
    assert cdb['page_code'] == MODESENSE10.PAGE_CODE.ELEMENT_ADDRESS_ASSIGNMENT
    assert cdb['pc'] == 0
    assert cdb['sub_page_code'] == 0
    assert cdb['alloc_len'] == 96

    d = ModeSense10.unmarshall_cdb(ModeSense10.marshall_cdb(cdb))
    assert d == cdb

    m = s.modesense10(page_code=0, sub_page_code=3, llbaa=1, dbd=1, pc=MODESENSE10.PC.DEFAULT, alloclen=90)
    cdb = m.cdb
    assert cdb[0] == s.device.opcodes.MODE_SENSE_10.value
    assert cdb[1] == 0x18
    assert cdb[2] == MODESENSE10.PC.DEFAULT << 6
    assert cdb[3] == 3
    assert scsi_ba_to_int(cdb[7:9]) == 90
    cdb = m.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.MODE_SENSE_10.value
    assert cdb['dbd'] == 1
    assert cdb['pc'] == MODESENSE10.PC.DEFAULT
    assert cdb['page_code'] == 0
    assert cdb['sub_page_code'] == 3
    assert cdb['alloc_len'] == 90
    assert cdb['llbaa'] == 1

    d = ModeSense10.unmarshall_cdb(ModeSense10.marshall_cdb(cdb))
    assert d == cdb
コード例 #47
0
def main():
    dev = MockReadCapacity16()
    dev.opcodes = sbc
    s = SCSI(dev)

    i = s.readcapacity16().result
    assert i['returned_lba'] == 281474976710656
    assert i['block_length'] == 4096
    assert i['p_type'] == 4
    assert i['prot_en'] == 1
    assert i['p_i_exponent'] == 8
    assert i['lbppbe'] == 8
    assert i['lbpme'] == 1
    assert i['lbprz'] == 1
    assert i['lowest_aligned_lba'] == 8193

    d = ReadCapacity16.unmarshall_datain(ReadCapacity16.marshall_datain(i))
    assert d == i
コード例 #48
0
def main():
    dev = MockTestUnitReady()
    dev.opcodes = sbc
    s = SCSI(dev)

    w = s.testunitready()
    cdb = w.cdb
    assert cdb[0] == s.device.opcodes.TEST_UNIT_READY.value
    assert cdb[1] == 0
    assert cdb[2] == 0
    assert cdb[3] == 0
    assert cdb[4] == 0
    assert cdb[5] == 0
    cdb = w.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.TEST_UNIT_READY.value

    d = TestUnitReady.unmarshall_cdb(TestUnitReady.marshall_cdb(cdb))
    assert d == cdb
コード例 #49
0
def main():
    dev = MockReadCapacity16()
    dev.opcodes = sbc
    s = SCSI(dev)

    r = s.readcapacity16(alloclen=37)
    cdb = r.cdb
    assert cdb[0] == s.device.opcodes.SBC_OPCODE_9E.value
    assert cdb[1] == s.device.opcodes.SBC_OPCODE_9E.serviceaction.READ_CAPACITY_16
    assert cdb[2:10] == bytearray(8)
    assert scsi_ba_to_int(cdb[10:14]) == 37
    assert cdb[14:16] == bytearray(2)
    cdb = r.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.SBC_OPCODE_9E.value
    assert cdb['service_action'] == s.device.opcodes.SBC_OPCODE_9E.serviceaction.READ_CAPACITY_16
    assert cdb['alloc_len'] == 37

    d = ReadCapacity16.unmarshall_cdb(ReadCapacity16.marshall_cdb(cdb))
    assert d == cdb
コード例 #50
0
def main():
    dev = MockModeSense6()
    dev.opcodes = spc
    s = SCSI(dev)

    # cdb for SMC: ElementAddressAssignment
    m = s.modesense6(page_code=MODESENSE6.PAGE_CODE.ELEMENT_ADDRESS_ASSIGNMENT)
    cdb = m.cdb
    assert cdb[0] == s.device.opcodes.MODE_SENSE_6.value
    assert cdb[1] == 0
    assert cdb[2] == MODESENSE6.PAGE_CODE.ELEMENT_ADDRESS_ASSIGNMENT
    assert cdb[3] == 0
    assert cdb[4] == 96
    assert cdb[5] == 0
    cdb = m.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.MODE_SENSE_6.value
    assert cdb['dbd'] == 0
    assert cdb['pc'] == 0
    assert cdb['page_code'] == MODESENSE6.PAGE_CODE.ELEMENT_ADDRESS_ASSIGNMENT
    assert cdb['sub_page_code'] == 0
    assert cdb['alloc_len'] == 96

    d = ModeSense6.unmarshall_cdb(ModeSense6.marshall_cdb(cdb))
    assert d == cdb

    m = s.modesense6(page_code=0, sub_page_code=3, dbd=1, pc=MODESENSE6.PC.DEFAULT, alloclen=90)
    cdb = m.cdb
    assert cdb[0] == s.device.opcodes.MODE_SENSE_6.value
    assert cdb[1] == 0x08
    assert cdb[2] == MODESENSE6.PC.DEFAULT << 6
    assert cdb[3] == 3
    assert cdb[4] == 90
    assert cdb[5] == 0
    cdb = m.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.MODE_SENSE_6.value
    assert cdb['dbd'] == 1
    assert cdb['pc'] == MODESENSE6.PC.DEFAULT
    assert cdb['page_code'] == 0
    assert cdb['sub_page_code'] == 3
    assert cdb['alloc_len'] == 90

    d = ModeSense6.unmarshall_cdb(ModeSense6.marshall_cdb(cdb))
    assert d == cdb
コード例 #51
0
    def __init__(self, device):
        if not device:
            raise exceptions.CommandLineError(
                '--device parameter is required, should point to the disk '
                'device representing the meter.')

        self.device_name_ = device
        self.scsi_device_ = SCSIDevice(device, readwrite=True)
        self.scsi_ = SCSI(self.scsi_device_)
        self.scsi_.blocksize = _REGISTER_SIZE
コード例 #52
0
def main():
    dev = MockGetLBAStatus()
    dev.opcodes = sbc
    s = SCSI(dev)

    r = s.getlbastatus(19938722, alloclen=1112527)
    cdb = r.cdb
    assert cdb[0] == s.device.opcodes.SBC_OPCODE_9E.value
    assert cdb[1] == s.device.opcodes.SBC_OPCODE_9E.serviceaction.GET_LBA_STATUS
    assert scsi_ba_to_int(cdb[2:10]) == 19938722
    assert scsi_ba_to_int(cdb[10:14]) == 1112527
    assert cdb[14:16] == bytearray(2)
    cdb = r.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.SBC_OPCODE_9E.value
    assert cdb['service_action'] == s.device.opcodes.SBC_OPCODE_9E.serviceaction.GET_LBA_STATUS
    assert cdb['lba'] == 19938722
    assert cdb['alloc_len'] == 1112527

    d = GetLBAStatus.unmarshall_cdb(GetLBAStatus.marshall_cdb(cdb))
    assert d == cdb
コード例 #53
0
def main():
    dev = MockReportPriority()
    dev.opcodes = spc
    s = SCSI(dev)
    s.device.opcodes = spc
    r = s.reportpriority(priority=0x00, alloclen=1112527)
    cdb = r.cdb
    assert cdb[0] == s.device.opcodes.SPC_OPCODE_A3.value
    assert cdb[1] == s.device.opcodes.SPC_OPCODE_A3.serviceaction.REPORT_PRIORITY
    assert cdb[2] == 0
    assert scsi_ba_to_int(cdb[6:10]) == 1112527
    assert cdb[10:12] == bytearray(2)
    cdb = r.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.SPC_OPCODE_A3.value
    assert cdb['service_action'] == s.device.opcodes.SPC_OPCODE_A3.serviceaction.REPORT_PRIORITY
    assert cdb['priority_reported'] == 0
    assert cdb['alloc_len'] == 1112527

    d = ReportPriority.unmarshall_cdb(ReportPriority.marshall_cdb(cdb))
    assert d == cdb
コード例 #54
0
def main():
    dev = MockPositionToElement()
    dev.opcodes = smc
    s = SCSI(dev)
    s.device.opcodes = smc
    m = s.positiontoelement(15, 32, invert=1)
    cdb = m.cdb
    assert cdb[0] == s.device.opcodes.POSITION_TO_ELEMENT.value
    assert cdb[1] == 0
    assert scsi_ba_to_int(cdb[2:4]) == 15
    assert scsi_ba_to_int(cdb[4:6]) == 32
    assert cdb[8] == 0x01
    cdb = m.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.POSITION_TO_ELEMENT.value
    assert cdb['medium_transport_address'] == 15
    assert cdb['destination_address'] == 32
    assert cdb['invert'] == 1

    d = PositionToElement.unmarshall_cdb(PositionToElement.marshall_cdb(cdb))
    assert d == cdb
コード例 #55
0
ファイル: read16.py プロジェクト: Katana-Steel/python-scsi
def main(device):
    try:
        sd = SCSIDevice(device)
        s = SCSI(sd, 512)
        r = s.read16(1, 1,).datain
        print 'Read16 - GPT Header'
        print '==========================================\n'
        print('signature: %s' % r[:8])
        print('revision: %.1f' % float(ba_to_int(r[8:12])))
        print('header size: %s byte' % ba_to_int(r[12:16]))
        print('crc32 of header: %s' % ba_to_hex(r[16:20]))
        print('reserved: %s' % ba_to_int(r[20:24]))
        print('current LBA: %s' % ba_to_int(r[24:32]))
        print('backup LBA: %s' % ba_to_int(r[32:40]))
        print('first usable LBA for partitions: %s' % ba_to_int(r[40:48]))
        print('last usable LBA: %s' % ba_to_int(r[48:56]))
        print('Disk GUID: %s' % ba_to_hex(r[56:72]))
        print('Starting LBA of array of partition entries: %s' % ba_to_int(r[72:80]))
        print('number of partition entries in array: %s' % ba_to_int(r[80:84]))
        print('size of a single partition entry: %s' % ba_to_int(r[84:88]))
        print('crc32 of header: %s' % ba_to_hex(r[88:92]))
    except Exception as e:
        print (e.message)
コード例 #56
0
def main():
    dev = MockInquiry()
    dev.opcodes = spc
    s = SCSI(dev)

    # cdb for standard page request
    i = s.inquiry(alloclen=128)
    cdb = i.cdb
    assert cdb[0] == s.device.opcodes.INQUIRY.value
    assert cdb[1:3] == bytearray(2)
    assert scsi_ba_to_int(cdb[3:5]) == 128
    assert cdb[5] == 0
    cdb = i.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.INQUIRY.value
    assert cdb['evpd'] == 0
    assert cdb['page_code'] == 0
    assert cdb['alloc_len'] == 128

    d = Inquiry.unmarshall_cdb(Inquiry.marshall_cdb(cdb))
    assert d == cdb

    # supported vpd pages
    i = s.inquiry(evpd=1, page_code=0x88, alloclen=300)
    cdb = i.cdb
    assert cdb[0] == s.device.opcodes.INQUIRY.value
    assert cdb[1] == 0x01
    assert cdb[2] == 0x88
    assert scsi_ba_to_int(cdb[3:5]) == 300
    assert cdb[5] == 0
    cdb = i.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.INQUIRY.value
    assert cdb['evpd'] == 1
    assert cdb['page_code'] == 0x88
    assert cdb['alloc_len'] == 300

    d = Inquiry.unmarshall_cdb(Inquiry.marshall_cdb(cdb))
    assert d == cdb
コード例 #57
0
def main():
    dev = MockInitializeElementStatusWithRange()
    dev.opcodes = smc
    s = SCSI(dev)
    # we need to reassign the right enum again because the MockDevice will return the wrong
    # peripheral_device_type and therefor assign the spc enum instead of smc.
    s.device.opcodes = smc

    r = s.initializeelementstatuswithrange(15, 3, rng=1, fast=1)
    cdb = r.cdb
    assert cdb[0] == s.device.opcodes.INITIALIZE_ELEMENT_STATUS_WITH_RANGE.value
    assert cdb[1] == 0x03
    assert scsi_ba_to_int(cdb[2:4]) == 15
    assert scsi_ba_to_int(cdb[6:8]) == 3

    cdb = r.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.INITIALIZE_ELEMENT_STATUS_WITH_RANGE.value
    assert cdb['starting_element_address'] == 15
    assert cdb['number_of_elements'] == 3
    assert cdb['fast'] == 1
    assert cdb['range'] == 1

    d = InitializeElementStatusWithRange.unmarshall_cdb(InitializeElementStatusWithRange.marshall_cdb(cdb))
    assert d == cdb
コード例 #58
0
ファイル: mtx.py プロジェクト: c-r-h/python-scsi
def main():
    device = ''
    for i in range(len(sys.argv)):
        if sys.argv[i] == '-f':
            del sys.argv[i]
            device = sys.argv[i]
            del sys.argv[i]
            break

    if not device:
        usage()
        exit(1)

    scsi = SCSI(SCSIDevice(device))
    i = scsi.inquiry().result
    if i['peripheral_device_type'] != INQUIRY.DEVICE_TYPE.MEDIA_CHANGER_DEVICE:
        print '%s is not a MediaChanger device' % device
        exit(1)

    eaa = scsi.modesense6(page_code=MODESENSE6.PAGE_CODE.ELEMENT_ADDRESS_ASSIGNMENT).result['mode_pages'][0]

    # get the data transfer elements
    dte = scsi.readelementstatus(
        start=eaa['first_data_transfer_element_address'],
        num=eaa['num_data_transfer_elements'],
        element_type=READELEMENTSTATUS.ELEMENT_TYPE.DATA_TRANSFER,
        voltag=1, curdata=1, dvcid=1,
        alloclen=16384).result['element_status_pages'][0]['element_descriptors']

    # get all the storage elements
    se = scsi.readelementstatus(
        start=eaa['first_storage_element_address'],
        num=eaa['num_storage_elements'],
        element_type=READELEMENTSTATUS.ELEMENT_TYPE.STORAGE,
        voltag=1, curdata=1, dvcid=1,
        alloclen=16384).result['element_status_pages'][0]['element_descriptors']

    # get all the medium transport elements
    mte = scsi.readelementstatus(
        start=eaa['first_medium_transport_element_address'],
        num=eaa['num_medium_transport_elements'],
        element_type=READELEMENTSTATUS.ELEMENT_TYPE.MEDIUM_TRANSPORT,
        voltag=1, curdata=1, dvcid=1,
        alloclen=16384).result['element_status_pages'][0]['element_descriptors']

    if sys.argv[1] == 'status':
        return status(scsi, dte, se)

    if sys.argv[1] == 'load':
        return load(scsi, mte, dte, se, int(sys.argv[2]), int(sys.argv[3]))

    if sys.argv[1] == 'unload':
        return unload(scsi, mte, dte, se, int(sys.argv[2]), int(sys.argv[3]))

    usage()
    exit(1)
コード例 #59
0
def main():
    dev = MockMoveMedium()
    dev.opcodes = smc
    s = SCSI(dev)
    s.device.opcodes = smc
    m = s.movemedium(15, 32, 64, invert=1)
    cdb = m.cdb
    assert cdb[0] == s.device.opcodes.MOVE_MEDIUM.value
    assert cdb[1] == 0
    assert scsi_ba_to_int(cdb[2:4]) == 15
    assert scsi_ba_to_int(cdb[4:6]) == 32
    assert scsi_ba_to_int(cdb[6:8]) == 64
    assert cdb[8] == 0
    assert cdb[9] == 0
    assert cdb[10] == 0x01
    cdb = m.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.MOVE_MEDIUM.value
    assert cdb['medium_transport_address'] == 15
    assert cdb['source_address'] == 32
    assert cdb['destination_address'] == 64
    assert cdb['invert'] == 1

    d = MoveMedium.unmarshall_cdb(MoveMedium.marshall_cdb(cdb))
    assert d == cdb