Beispiel #1
0
void test_execute_Inquiry(char* path, int evpd, int page_code) {

  struct sg_io_hdr* p_hdr = init_io_hdr();

  set_xfer_data(p_hdr, data_buffer, BLOCK_LEN * 256);
  set_sense_data(p_hdr, sense_buffer, SENSE_LEN);

  int status = 0;

  int fd = open(path, O_RDWR);
  if (fd > 0) {
    status = execute_Inquiry(fd, page_code, evpd, p_hdr);
    printf("the return status is %d\n", status);
    if (status != 0) {
      show_sense_buffer(p_hdr);
    } else {
      show_vendor(p_hdr);
      show_product(p_hdr);
      show_product_rev(p_hdr);
    }
  } else {
    printf("failed to open sg file %s\n", path);
  }
  close(fd);
  destroy_io_hdr(p_hdr);
}
Beispiel #2
0
void show_serial_number(struct sg_io_hdr *hdr)
{
	unsigned char *buffer = hdr->dxferp;
	int i;
	printf("serial number: ");
	for (i=0x80, 
}
#endif

#define SENSE_LEN 32
#define BLOCK_LEN 1

unsigned char sense_buffer[SENSE_LEN];
unsigned char data_buffer[BLOCK_LEN*256];
void test_execute_Inquiry(char * path, int evpd, int page_code)
{
	struct sg_io_hdr * p_hdr = init_io_hdr();
	set_xfer_data(p_hdr, data_buffer, BLOCK_LEN*256);
	set_sense_data(p_hdr, sense_buffer, SENSE_LEN);
	int status = 0;
	int fd = open(path, O_RDWR);
	if (fd>0) {
		status = execute_Inquiry(fd, page_code, evpd, p_hdr);
		printf("the return status is %d\n", status);
		if (status!=0) {
			show_sense_buffer(p_hdr);
		} else{
			show_vendor(p_hdr);
			show_product(p_hdr);
			show_product_rev(p_hdr);
			show_xfer_data(p_hdr);
		}
	} else {
		printf("failed to open sg file %s\n", path);
	}
	close(fd);
	destroy_io_hdr(p_hdr);
}


void test_cmds(char *path, int evpd, int page_code)
{
	struct sg_io_hdr * p_hdr = init_io_hdr();
	set_xfer_data(p_hdr, data_buffer, BLOCK_LEN*256);
	set_sense_data(p_hdr, sense_buffer, SENSE_LEN);
	int status = 0;
	int fd = open(path, O_RDWR);
	if (fd>0) {
		status = execute_Inquiry(fd, page_code, evpd, p_hdr);
		printf("the return status is %d\n", status);
		//show_sense_buffer(p_hdr);
		show_xfer_data(p_hdr);
	} else {
		printf("failed to open sg file %s\n", path);
	}
	close(fd);
	destroy_io_hdr(p_hdr);
}

void get_rpm(char *path, int evpd, int page_code)
{
	struct sg_io_hdr * p_hdr = init_io_hdr();
	set_xfer_data(p_hdr, data_buffer, BLOCK_LEN*256);
	set_sense_data(p_hdr, sense_buffer, SENSE_LEN);
	int status = 0;
	unsigned char *xfer;
	int pdt, rpm;

	int fd = open(path, O_RDWR);
	if (fd>0) {
		status = execute_Inquiry(fd, page_code, evpd, p_hdr);
		printf("the return status is %d\n", status);
		//show_sense_buffer(p_hdr);
		//show_xfer_data(p_hdr);

		// 参考代码 sg3_utils: sg_vpd.c : decode_b1_vpd()
		xfer = p_hdr->dxferp;
		pdt = (int)xfer[0];
		switch (pdt)
		{
			case 0:
				if (p_hdr->dxfer_len < 64)
				{
					printf("xfer is too short!\n");
				}
				else
				{
					rpm = (xfer[4]<<8) | xfer[5];
					printf("rpm of %s: %d rpm\n", path, rpm);
				}
				break;
			default:
				printf("unknown pdt\n");
				break;
		}
	} else {
		printf("failed to open sg file %s\n", path);
	}
	close(fd);
	destroy_io_hdr(p_hdr);
}

int main(int argc, char * argv[])
{
	//test_execute_Inquiry(argv[1], 0, 0);

	//test_cmds(argv[1], 1, 0x86);
	get_rpm(argv[1], 1, 0xb1); // rpm
	// tested:
	// 0x80,0x83

	return 0;
}