예제 #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 = 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']])
예제 #2
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")
예제 #3
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)
예제 #4
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
예제 #5
0
def init_device(dev, read_write=False):
    if dev[:5] == '/dev/':
        from pyscsi.pyscsi.scsi_device import SCSIDevice
        device = SCSIDevice(dev, read_write)
    elif dev[:8] == 'iscsi://':
        from pyscsi.pyiscsi.iscsi_device import ISCSIDevice
        device = ISCSIDevice(dev)
    else:
        raise NotImplementedError('No backend implemented for %s' % dev)
    return device
def without_init_device(device):
    """
    simple use case for a scsi device without the scsi helper. SCSIDevice has also a contextmanager so we can
    use the with statement but we need to take care of the initialization of a SCSICommand and the execution of the
    command with the device.
    """
    with SCSIDevice(device, False) as d:
        cmd = Read16(sbc.READ_16, blocksize=512, lba=1, tl=1)
        d.execute(cmd)
        print_output(cmd.datain)
예제 #7
0
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)
예제 #8
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)
예제 #9
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
예제 #10
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)
예제 #11
0
def main():
    swp_on = 0
    swp_off = 0
    i = 1
    while i < len(sys.argv):
        if sys.argv[i] == '--help':
            return usage()
        if sys.argv[i] == '--on':
            del sys.argv[i]
            swp_on = 1
            continue
        if sys.argv[i] == '--off':
            del sys.argv[i]
            swp_off = 1
            continue
        i += 1

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

    device = sys.argv[1]

    sd = SCSIDevice(device)
    s = SCSI(sd)
    i = s.modesense6(page_code=MODESENSE6.PAGE_CODE.CONTROL).result

    if swp_on:
        i['mode_pages'][0]['swp'] = 1
        s.modeselect6(i)
        print 'Set SWP ON'
        return

    if swp_off:
        i['mode_pages'][0]['swp'] = 0
        s.modeselect6(i)
        print 'Set SWP OFF'
        return

    print 'SWP is %s' % ("ON" if i['mode_pages'][0]['swp'] else "OFF")
예제 #12
0
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)
예제 #13
0
파일: mtx.py 프로젝트: jlutran/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)
예제 #14
0
 def __init__(self, device):
     self.device_name_ = device
     self.scsi_device_ = SCSIDevice(device, readwrite=True)
     self.scsi_ = SCSI(self.scsi_device_)
     self.scsi_.blocksize = _REGISTER_SIZE