diff options
Diffstat (limited to 'archive')
-rw-r--r-- | archive/Makefile | 9 | ||||
-rw-r--r-- | archive/README | 3 | ||||
-rw-r--r-- | archive/sg_simple0.c | 93 |
3 files changed, 101 insertions, 4 deletions
diff --git a/archive/Makefile b/archive/Makefile index 8f2b3b35..a0a0cdd6 100644 --- a/archive/Makefile +++ b/archive/Makefile @@ -6,11 +6,11 @@ MANDIR=/usr/local/man CC = gcc LD = gcc -EXECS = sgq_dd sg_poll sg_reset sg_bus_xfer sg_hold +EXECS = sgq_dd sg_poll sg_reset sg_bus_xfer sg_hold isosize -COMMON = +COMMON = isosize -MAN_PGS = +MAN_PGS = isosize.8 MAN_PREF = man8 CFLAGS = -g -O2 -Wall -D_REENTRANT @@ -44,6 +44,9 @@ sg_bus_xfer: sg_bus_xfer.o ../sg_err.o sg_hold: sg_hold.o $(LD) -o $@ $(LDFLAGS) $^ +isosize: isosize.o + $(LD) -o $@ $(LDFLAGS) $^ + install: $(EXECS) $(COMMON) install -d $(INSTDIR) for name in $^; \ diff --git a/archive/README b/archive/README index 70df7849..89fc88cd 100644 --- a/archive/README +++ b/archive/README @@ -19,6 +19,7 @@ been set up which builds: - sg_hold holds a sg device open and periodically sends a TEST UNIT READY command to the device - sg_poll [internal testing] + - isosize available in util-linux-2.10s and later The sg_err.h and llseek.h headers have simply been copied from the parent directory. @@ -30,4 +31,4 @@ to side step various buffer copies. See: http://www.torque.net/sg/mem2disk.html Doug Gilbert -22nd March 2001 +23rd December 2001 diff --git a/archive/sg_simple0.c b/archive/sg_simple0.c new file mode 100644 index 00000000..7e1d8db7 --- /dev/null +++ b/archive/sg_simple0.c @@ -0,0 +1,93 @@ +#include <unistd.h> +#include <fcntl.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <sys/ioctl.h> +#include <scsi/sg.h> /* take care: fetches glibc's /usr/include/scsi/sg.h */ + +/* This is a simple program executing a SCSI INQUIRY command using the + sg_io_hdr interface of the SCSI generic (sg) driver. + +* Copyright (C) 2001 D. Gilbert +* This program is free software. Version 1.00 (20011204) +*/ + +#define INQ_REPLY_LEN 96 +#define INQ_CMD_CODE 0x12 +#define INQ_CMD_LEN 6 + +int main(int argc, char * argv[]) +{ + int sg_fd, k; + unsigned char inqCmdBlk[INQ_CMD_LEN] = + {INQ_CMD_CODE, 0, 0, 0, INQ_REPLY_LEN, 0}; +/* This is a "standard" SCSI INQUIRY command. It is standard because the + * CMDDT and EVPD bits (in the second byte) are zero. All SCSI targets + * should respond promptly to a standard INQUIRY */ + unsigned char inqBuff[INQ_REPLY_LEN]; + unsigned char sense_buffer[32]; + sg_io_hdr_t io_hdr; + + if (2 != argc) { + printf("Usage: 'sg_simple0 <sg_device>'\n"); + return 1; + } + if ((sg_fd = open(argv[1], O_RDONLY)) < 0) { + perror("error opening given file name"); + return 1; + } + /* It is prudent to check we have a sg device by trying an ioctl */ + if ((ioctl(sg_fd, SG_GET_VERSION_NUM, &k) < 0) || (k < 30000)) { + printf("%s is not an sg device, or old sg driver\n", argv[1]); + return 1; + } + /* Prepare INQUIRY command */ + memset(&io_hdr, 0, sizeof(sg_io_hdr_t)); + io_hdr.interface_id = 'S'; + io_hdr.cmd_len = sizeof(inqCmdBlk); + /* io_hdr.iovec_count = 0; */ /* memset takes care of this */ + io_hdr.mx_sb_len = sizeof(sense_buffer); + io_hdr.dxfer_direction = SG_DXFER_FROM_DEV; + io_hdr.dxfer_len = INQ_REPLY_LEN; + io_hdr.dxferp = inqBuff; + io_hdr.cmdp = inqCmdBlk; + io_hdr.sbp = sense_buffer; + io_hdr.timeout = 20000; /* 20000 millisecs == 20 seconds */ + /* io_hdr.flags = 0; */ /* take defaults: indirect IO, etc */ + /* io_hdr.pack_id = 0; */ + /* io_hdr.usr_ptr = NULL; */ + + if (ioctl(sg_fd, SG_IO, &io_hdr) < 0) { + perror("sg_simple0: Inquiry SG_IO ioctl error"); + return 1; + } + + /* now for the error processing */ + if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK) { + if (io_hdr.sb_len_wr > 0) { + printf("INQUIRY sense data: "); + for (k = 0; k < io_hdr.sb_len_wr; ++k) { + if ((k > 0) && (0 == (k % 10))) + printf("\n "); + printf("0x%02x ", sense_buffer[k]); + } + printf("\n"); + } + if (io_hdr.masked_status) + printf("INQUIRY SCSI status=0x%x\n", io_hdr.status); + if (io_hdr.host_status) + printf("INQUIRY host_status=0x%x\n", io_hdr.host_status); + if (io_hdr.driver_status) + printf("INQUIRY driver_status=0x%x\n", io_hdr.driver_status); + } + else { /* assume INQUIRY response is present */ + char * p = (char *)inqBuff; + printf("Some of the INQUIRY command's response:\n"); + printf(" %.8s %.16s %.4s\n", p + 8, p + 16, p + 32); + printf("INQUIRY duration=%u millisecs, resid=%d\n", + io_hdr.duration, io_hdr.resid); + } + close(sg_fd); + return 0; +} |