#include #include #include #include #include #include void hexdump(unsigned char *b, int len) { int i; for (i = 0; i < len; i++) printf("%02x", b[i]); printf("\n"); } int do_getev(int fd) { unsigned char cdb[10] = { 0x4a, 1, 0, 0, 16, 0, 0, 0, 8, }; unsigned char buffer[8]; struct sg_io_hdr h; int ret; memset(buffer, 0, sizeof(buffer)); memset(&h, 0, sizeof(h)); h.interface_id = 'S'; h.cmd_len = sizeof(cdb); h.dxfer_direction = SG_DXFER_FROM_DEV; h.dxfer_len = sizeof(buffer); h.dxferp = buffer; h.cmdp = cdb; h.timeout = 5000; ret = ioctl(fd, SG_IO, &h); if (ret) { printf("SG_IO failed\n"); return -1; } printf("status %d\n", h.status); if (!h.status) hexdump(buffer, sizeof(buffer)); return h.status; } int main(int argc, char *argv[]) { int fd; if (argc < 2) { fprintf(stderr, "%s: device\n", argv[0]); return 1; } fd = open(argv[1], O_RDONLY | O_NONBLOCK); if (fd == -1) { perror("open"); return 1; } do_getev(fd); close(fd); return 0; }