8 #include "sg_include.h"
10 #define FILE_NAME_SIZE 255
13 do_inq(int sg_fd, int cmddt, int evpd, unsigned int pg_op,
14 void *resp, int mx_resp_len, int noisy)
16 unsigned char inqCmdBlk[INQUIRY_CMDLEN] =
17 { INQUIRY_CMD, 0, 0, 0, 0, 0 };
18 unsigned char sense_b[SENSE_BUFF_LEN];
19 struct sg_io_hdr io_hdr;
25 inqCmdBlk[2] = (unsigned char) pg_op;
26 inqCmdBlk[4] = (unsigned char) mx_resp_len;
27 memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
28 io_hdr.interface_id = 'S';
29 io_hdr.cmd_len = sizeof (inqCmdBlk);
30 io_hdr.mx_sb_len = sizeof (sense_b);
31 io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
32 io_hdr.dxfer_len = mx_resp_len;
34 io_hdr.cmdp = inqCmdBlk;
36 io_hdr.timeout = DEF_TIMEOUT;
38 if (ioctl(sg_fd, SG_IO, &io_hdr) < 0) {
39 perror("SG_IO (inquiry) error");
43 /* treat SG_ERR here to get rid of sg_err.[ch] */
44 io_hdr.status &= 0x7e;
45 if ((0 == io_hdr.status) && (0 == io_hdr.host_status) &&
46 (0 == io_hdr.driver_status))
48 if ((SCSI_CHECK_CONDITION == io_hdr.status) ||
49 (SCSI_COMMAND_TERMINATED == io_hdr.status) ||
50 (SG_ERR_DRIVER_SENSE == (0xf & io_hdr.driver_status))) {
51 if (io_hdr.sbp && (io_hdr.sb_len_wr > 2)) {
53 unsigned char * sense_buffer = io_hdr.sbp;
54 if (sense_buffer[0] & 0x2)
55 sense_key = sense_buffer[1] & 0xf;
57 sense_key = sense_buffer[2] & 0xf;
58 if(RECOVERED_ERROR == sense_key)
66 get_lun_strings(char * vendor_id, char * product_id, char * rev, char * devname)
72 if ((fd = open(devname, O_RDONLY)) < 0)
74 if (0 != do_inq(fd, 0, 0, 0, buff, 36, 1))
76 memcpy(vendor_id, &buff[8], 8);
77 memcpy(product_id, &buff[16], 16);
78 memcpy(rev, &buff[32], 4);