Пример #1
0
void inquiry_standard(struct scsi_inquiry_standard *inq)
{
	int i;

	printf("Peripheral Qualifier:%s\n",
		scsi_devqualifier_to_str(inq->qualifier));
	printf("Peripheral Device Type:%s\n",
		scsi_devtype_to_str(inq->device_type));
	printf("Removable:%d\n", inq->rmb);
	printf("Version:%d %s\n", inq->version, scsi_version_to_str(inq->version));
	printf("NormACA:%d\n", inq->normaca);
	printf("HiSup:%d\n", inq->hisup);
	printf("ReponseDataFormat:%d\n", inq->response_data_format);
	printf("SCCS:%d\n", inq->sccs);
	printf("ACC:%d\n", inq->acc);
	printf("TPGS:%d\n", inq->tpgs);
	printf("3PC:%d\n", inq->threepc);
	printf("Protect:%d\n", inq->protect);
	printf("EncServ:%d\n", inq->encserv);
	printf("MultiP:%d\n", inq->multip);
	printf("SYNC:%d\n", inq->sync);
	printf("CmdQue:%d\n", inq->cmdque);
	printf("Vendor:%s\n", inq->vendor_identification);
	printf("Product:%s\n", inq->product_identification);
	printf("Revision:%s\n", inq->product_revision_level);

	for (i = 0; i < 8; i++) {
		if (inq->version_descriptor[i] == 0) {
			continue;
		}

		printf("Version Descriptor:%04x %s\n",
			inq->version_descriptor[i],
			scsi_version_descriptor_to_str(
				inq->version_descriptor[i]));
	}
}
Пример #2
0
void inquiry_device_identification(struct scsi_inquiry_device_identification *inq)
{
	struct scsi_inquiry_device_designator *dev;
	int i;

	printf("Peripheral Qualifier:%s\n",
		scsi_devqualifier_to_str(inq->qualifier));
	printf("Peripheral Device Type:%s\n",
		scsi_devtype_to_str(inq->device_type));
	printf("Page Code:(0x%02x) %s\n",
		inq->pagecode, scsi_inquiry_pagecode_to_str(inq->pagecode));

	for (i=0, dev = inq->designators; dev; i++, dev = dev->next) {
		printf("DEVICE DESIGNATOR #%d\n", i);
		if (dev->piv != 0) {
			printf("Device Protocol Identifier:(%d) %s\n", dev->protocol_identifier, scsi_protocol_identifier_to_str(dev->protocol_identifier));
		}
		printf("Code Set:(%d) %s\n", dev->code_set, scsi_codeset_to_str(dev->code_set));
		printf("PIV:%d\n", dev->piv);
		printf("Association:(%d) %s\n", dev->association, scsi_association_to_str(dev->association));
		printf("Designator Type:(%d) %s\n", dev->designator_type, scsi_designator_type_to_str(dev->designator_type));
		printf("Designator:[%s]\n", dev->designator);
	}
}
Пример #3
0
int T0400_inquiry_basic(const char *initiator, const char *url)
{
	struct iscsi_context *iscsi;
	struct scsi_task *task;
	struct scsi_inquiry_standard *inq;
	int ret, lun, i;
	int full_size;

	printf("0400_inquiry_basic:\n");
	printf("===================\n");
	if (show_info) {
		printf("Test the standard INQUIRY data format.\n");
		printf("1, Check we can read the standard INQUIRY data.\n");
		printf("2, Standard data must be at least 36 bytes in size.\n");
		printf("3, Device-type must be either of DISK/TAPE/CDROM.\n");
		printf("4, Check that peripheral-qualifier field is 0.\n");
		printf("5, Check that the version field is valid.\n");
		printf("6, Check that response-data-format is valid.\n");
		printf("7, Check that additional-length is valid.\n");
		printf("8, Verify HiSup flag is set.\n");
		printf("9, Verify vendor-identification is in ASCII.\n");
		printf("10, Verify product-identification is in ASCII.\n");
		printf("11, Verify product-revision-level is in ASCII.\n");
		printf("12, Verify AERC is clear in SPC-3 and later.\n");
		printf("13, Verify TrmTsk is clear in SPC-2 and later.\n");
		printf("\n");
		return 0;
	}

	iscsi = iscsi_context_login(initiator, url, &lun);
	if (iscsi == NULL) {
		printf("Failed to login to target\n");
		return -1;
	}


	ret = 0;



	printf("Read standard INQUIRY data ... ");
	/* See how big this inquiry data is */
	task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 255);
	if (task == NULL) {
		printf("[FAILED]\n");
		printf("Failed to send INQUIRY command : %s\n", iscsi_get_error(iscsi));
		ret = -1;
		goto finished;
	}
	if (task->status != SCSI_STATUS_GOOD) {
		printf("[FAILED]\n");
		printf("INQUIRY command failed : %s\n", iscsi_get_error(iscsi));
		scsi_free_scsi_task(task);
		ret = -1;
		goto finished;
	}
	full_size = scsi_datain_getfullsize(task);
	if (full_size > task->datain.size) {
		scsi_free_scsi_task(task);

		/* we need more data for the full list */
		if ((task = iscsi_inquiry_sync(iscsi, lun, 0, 0, full_size)) == NULL) {
			printf("[FAILED]\n");
			printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi));
			ret = -1;
			goto finished;
		}
	}
	inq = scsi_datain_unmarshall(task);
	if (inq == NULL) {
		printf("[FAILED]\n");
		printf("failed to unmarshall inquiry datain blob\n");
		scsi_free_scsi_task(task);
		ret = -1;
		goto finished;
	}
	printf("[OK]\n");

	printf("Check that standard data is >= 36 bytes in size ... ");
	if (full_size < 36) {
		printf("[FAILED]\n");
		printf("Standard INQUIRY data is less than 36 bytes.\n");
		scsi_free_scsi_task(task);
		ret = -1;
		goto finished;
	}
	printf("[OK]\n");

	printf("Check device-type is either of DISK, TAPE or CD/DVD  ... ");
	switch (inq->device_type) {
	case SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS:
	case SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_SEQUENTIAL_ACCESS:
	case SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_MMC:
		break;
	default:
		printf("[FAILED]\n");
		printf("Device-type is not DISK, TAPE or CD/DVD. Device reported:%s\n", scsi_devtype_to_str(inq->device_type));
		ret = -1;
		goto test4;
	}
	printf("[OK]\n");


test4:
	printf("Check PREIPHERAL QUALIFIER FIELD is 0  ... ");
	if (inq->qualifier != 0) {
		printf("[FAILED]\n");
		printf("QUALIFIER was not 0, it was %d\n", inq->qualifier);
		ret = -1;
		goto test5;
	}
	printf("[OK]\n");

test5:
	printf("Check VERSION field is either 0x4, 0x5 or 0x6 ... ");
	switch (inq->version) {
	case 0x4: /* SPC-2 */
	case 0x5: /* SPC-3 */
	case 0x6: /* SPC-4 */
		break;
	default:
		printf("[FAILED]\n");
		printf("Invalid VERSION:%d. Should be 0x4, 0x5 or 0x6\n", inq->version);
		ret = -1;
		goto test6;
	}
	printf("[OK]\n");

test6:
	printf("Check RESPONSE DATA FORMAT is 2 ... ");
	if (inq->response_data_format != 2) {
		printf("[FAILED]\n");
		printf("Invalid RESPONSE_DATA_FORMAT:%d. Should be 2\n", inq->response_data_format);
		ret = -1;
		goto test7;
	}
	printf("[OK]\n");

test7:
	printf("Verify Additional-Length ... ");
	if (inq->additional_length + 5 != full_size) {
		printf("[FAILED]\n");
		printf("Invalid additional-length. Was %d but should be %d\n", inq->additional_length, full_size-5);
		ret = -1;
		goto test8;
	}
	printf("[OK]\n");

test8:
	printf("Verify HiSup is set ... ");
	if (!inq->hisup) {
		printf("[FAILED]\n");
		printf("HiSup flag is not set.\n");
		ret = -1;
		goto test9;
	}
	printf("[OK]\n");

test9:
	printf("Verify VENDOR_IDENTIFICATION is in ASCII ... ");
	for (i = 8; i < 16; i++) {
		/* SPC-4 4.4.1 only characters 0x00 and 0x20-0x7E allowed */
		if (task->datain.data[i] == 0) {
			continue;
		}
		if (task->datain.data[i] >= 0x20 && task->datain.data[i] <= 0x7e) {
			continue;
		}

		printf("[FAILED]\n");
		printf("VENDOR_IDENTIFICATION contains non-ASCII characters\n");
		ret = -1;
		goto test10;
	}
	printf("[OK]\n");

test10:
	printf("Verify PRODUCT_IDENTIFICATION is in ASCII ... ");
	for (i = 16; i < 32; i++) {
		/* SPC-4 4.4.1 only characters 0x00 and 0x20-0x7E allowed */
		if (task->datain.data[i] == 0) {
			continue;
		}
		if (task->datain.data[i] >= 0x20 && task->datain.data[i] <= 0x7e) {
			continue;
		}

		printf("[FAILED]\n");
		printf("PRODUCT_IDENTIFICATION contains non-ASCII characters\n");
		ret = -1;
		goto test11;
	}
	printf("[OK]\n");

test11:
	printf("Verify PRODUCT_REVISION_LEVEL is in ASCII ... ");
	for (i = 32; i < 36; i++) {
		/* SPC-4 4.4.1 only characters 0x00 and 0x20-0x7E allowed */
		if (task->datain.data[i] == 0) {
			continue;
		}
		if (task->datain.data[i] >= 0x20 && task->datain.data[i] <= 0x7e) {
			continue;
		}

		printf("[FAILED]\n");
		printf("PRODUCT_REVISION_LEVEL contains non-ASCII characters\n");
		ret = -1;
		goto test12;
	}
	printf("[OK]\n");

test12:
	printf("Verify AERC is clear in SPC-3 and later ... ");
	if (task->datain.data[3] & 0x80 && inq->version >= 5) {
		printf("[FAILED]\n");
		printf("AERC is set but this device reports SPC-3 or later\n");
		ret = -1;
		goto test13;
	}
	printf("[OK]\n");

test13:
	printf("Verify TrmTsk is clear in SPC-2 and later ... ");
	if (task->datain.data[3] & 0x40 && inq->version >= 4) {
		printf("[FAILED]\n");
		printf("TrmTsk is set but this device reports SPC-2 or later\n");
		ret = -1;
		goto test14;
	}
	printf("[OK]\n");

test14:



	scsi_free_scsi_task(task);


finished:
	iscsi_logout_sync(iscsi);
	iscsi_destroy_context(iscsi);
	return ret;
}
Пример #4
0
void show_lun(struct iscsi_context *iscsi, int lun)
{
	struct scsi_task *task;
	struct scsi_inquiry_standard *inq;
	int type;
	long long size = 0;
	int size_pf = 0;
	static const char sf[] = {' ', 'k', 'M', 'G', 'T' };

	/* check we can talk to the lun */
tur_try_again:
	if ((task = iscsi_testunitready_sync(iscsi, lun)) == NULL) {
		fprintf(stderr, "testunitready failed\n");
		exit(10);
	}
	if (task->status == SCSI_STATUS_CHECK_CONDITION) {
		if (task->sense.key == SCSI_SENSE_UNIT_ATTENTION && task->sense.ascq == SCSI_SENSE_ASCQ_BUS_RESET) {
			scsi_free_scsi_task(task);
			goto tur_try_again;
		}
	}
	if (task->status != SCSI_STATUS_GOOD) {
		fprintf(stderr, "TESTUNITREADY failed with %s\n", iscsi_get_error(iscsi));
		exit(10);
	}
	scsi_free_scsi_task(task);



	/* check what type of lun we have */
	task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64);
	if (task == NULL || task->status != SCSI_STATUS_GOOD) {
		fprintf(stderr, "failed to send inquiry command : %s\n", iscsi_get_error(iscsi));
		exit(10);
	}
	inq = scsi_datain_unmarshall(task);
	if (inq == NULL) {
		fprintf(stderr, "failed to unmarshall inquiry datain blob\n");
		exit(10);
	}
	type = inq->periperal_device_type;
	scsi_free_scsi_task(task);



	if (type == SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) {
		struct scsi_readcapacity10 *rc10;

		task = iscsi_readcapacity10_sync(iscsi, lun, 0, 0);
		if (task == NULL || task->status != SCSI_STATUS_GOOD) {
			fprintf(stderr, "failed to send readcapacity command\n");
			exit(10);
		}

		rc10 = scsi_datain_unmarshall(task);
		if (rc10 == NULL) {
			fprintf(stderr, "failed to unmarshall readcapacity10 data\n");
			exit(10);
		}

		size  = rc10->block_size;
		size *= rc10->lba;

		for (size_pf=0; size_pf<4 && size > 1024; size_pf++) {
			size /= 1024;
		}

		scsi_free_scsi_task(task);
	}


	printf("Lun:%-4d Type:%s", lun, scsi_devtype_to_str(type));
	if (type == SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) {
		printf(" (Size:%lld%c)", size, sf[size_pf]);
	}
	printf("\n");
}