aboutsummaryrefslogtreecommitdiff
path: root/archive
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2007-06-27 03:00:59 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2007-06-27 03:00:59 +0000
commitfa6966ce2412a35c576cc0cd99efcdf9be9156fb (patch)
tree4b3ee1a26b3baa56162602ecfebb6abdcadd85a3 /archive
parent666c11696c2674af4e765ba20e33d04bf01a1770 (diff)
downloadsg3_utils-fa6966ce2412a35c576cc0cd99efcdf9be9156fb.tar.gz
Load sg3_utils-1.09 into trunk/.
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@43 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'archive')
-rw-r--r--archive/Makefile8
-rw-r--r--archive/README4
-rw-r--r--archive/scsi_devfs_scan.c6
-rw-r--r--archive/sg_bus_xfer.c49
-rw-r--r--archive/sg_dd2048.c59
-rw-r--r--archive/sg_dd512.c59
-rw-r--r--archive/sg_dd_old.c61
-rw-r--r--archive/sg_err.h227
l---------archive/sg_lib.h1
-rw-r--r--archive/sg_poll.c2
-rw-r--r--archive/sgq_dd.c75
-rw-r--r--archive/sgq_dd.c.orig65
-rw-r--r--archive/sgq_old_dd.c57
-rw-r--r--archive/sgs_dd.c57
14 files changed, 129 insertions, 601 deletions
diff --git a/archive/Makefile b/archive/Makefile
index a4bd5226..eabe5f9c 100644
--- a/archive/Makefile
+++ b/archive/Makefile
@@ -29,13 +29,13 @@ depend dep:
clean:
/bin/rm -f *.o $(EXECS) core .depend
-sg_poll: sg_poll.o ../sg_err.o
+sg_poll: sg_poll.o ../sg_lib.o
$(LD) -o $@ $(LDFLAGS) $^
-sgq_dd: sgq_dd.o ../sg_err.o ../llseek.o
+sgq_dd: sgq_dd.o ../sg_lib.o ../llseek.o
$(LD) -o $@ $(LDFLAGS) $^
-sg_bus_xfer: sg_bus_xfer.o ../sg_err.o
+sg_bus_xfer: sg_bus_xfer.o ../sg_lib.o
$(LD) -o $@ $(LDFLAGS) $^
sg_hold: sg_hold.o
@@ -44,7 +44,7 @@ sg_hold: sg_hold.o
isosize: isosize.o
$(LD) -o $@ $(LDFLAGS) $^
-scsi_devfs_scan: scsi_devfs_scan.o ../sg_err.o
+scsi_devfs_scan: scsi_devfs_scan.o ../sg_lib.o
$(LD) -o $@ $(LDFLAGS) $^
sg_debug: sg_debug.o
diff --git a/archive/README b/archive/README
index 0908e806..9732d3f9 100644
--- a/archive/README
+++ b/archive/README
@@ -19,7 +19,7 @@ been set up which builds:
- 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
+The sg_lib.h and llseek.h headers have simply been copied from the parent
directory.
The very useful rescan-scsi-bus.sh script from Kurt Garloff
@@ -32,4 +32,4 @@ to side step various buffer copies. See:
http://www.torque.net/sg/mem2disk.html
Doug Gilbert
-27th February 2002
+3rd September 2004
diff --git a/archive/scsi_devfs_scan.c b/archive/scsi_devfs_scan.c
index 24c99384..fdb13773 100644
--- a/archive/scsi_devfs_scan.c
+++ b/archive/scsi_devfs_scan.c
@@ -14,7 +14,7 @@
#include <errno.h>
#include <unistd.h>
#include "sg_include.h"
-#include "sg_err.h"
+#include "sg_lib.h"
/* Code for scanning for SCSI devices within a Linux device pseudo file
system.
@@ -131,8 +131,8 @@ static int do_inquiry(int sg_fd, void * resp, int mx_resp_len)
}
res = sg_err_category3(&io_hdr);
switch (res) {
- case SG_ERR_CAT_CLEAN:
- case SG_ERR_CAT_RECOVERED:
+ case SG_LIB_CAT_CLEAN:
+ case SG_LIB_CAT_RECOVERED:
return 0;
default:
sg_chk_n_print3("Failed INQUIRY", &io_hdr);
diff --git a/archive/sg_bus_xfer.c b/archive/sg_bus_xfer.c
index eaf6bcb5..e75ab84b 100644
--- a/archive/sg_bus_xfer.c
+++ b/archive/sg_bus_xfer.c
@@ -9,7 +9,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "sg_include.h"
-#include "sg_err.h"
+#include "sg_lib.h"
/* Test code for D. Gilbert's extensions to the Linux OS SCSI generic ("sg")
device driver.
@@ -54,43 +54,6 @@
/* #define SG_DEBUG */
-int get_num(char * buf)
-{
- int res, num;
- char c;
-
- res = sscanf(buf, "%d%c", &num, &c);
- if (0 == res)
- return -1;
- else if (1 == res)
- return num;
- else {
- switch (c) {
- case 'c':
- case 'C':
- return num;
- case 'b':
- case 'B':
- return num * 512;
- case 'k':
- return num * 1024;
- case 'K':
- return num * 1000;
- case 'm':
- return num * 1024 * 1024;
- case 'M':
- return num * 1000000;
- case 'g':
- return num * 1024 * 1024 * 1024;
- case 'G':
- return num * 1000000000;
- default:
- fprintf(stderr, "unrecognized multiplier\n");
- return -1;
- }
- }
-}
-
int main(int argc, char * argv[])
{
int sg_fd, res, j, m;
@@ -117,7 +80,7 @@ int main(int argc, char * argv[])
}
else if (0 == strncmp("-bs=", argv[j], 4)) {
m = 4;
- bs = get_num(argv[j] + m);
+ bs = sg_get_num(argv[j] + m);
if (-1 == bs) {
printf("Couldn't decode number after '-bs=' switch\n");
file_name = 0;
@@ -126,7 +89,7 @@ int main(int argc, char * argv[])
}
else if (0 == strncmp("-skip=", argv[j], 6)) {
m = 6;
- skip = get_num(argv[j] + m);
+ skip = sg_get_num(argv[j] + m);
if (-1 == skip) {
printf("Couldn't decode number after '-skip=' switch\n");
file_name = 0;
@@ -135,7 +98,7 @@ int main(int argc, char * argv[])
}
else if (0 == strncmp("-count=", argv[j], 7)) {
m = 7;
- count = get_num(argv[j] + m);
+ count = sg_get_num(argv[j] + m);
if (-1 == count) {
printf("Couldn't decode number after '-count=' switch\n");
file_name = 0;
@@ -218,9 +181,9 @@ int main(int argc, char * argv[])
/* now for the error processing */
switch (sg_err_category3(&io_hdr)) {
- case SG_ERR_CAT_CLEAN:
+ case SG_LIB_CAT_CLEAN:
break;
- case SG_ERR_CAT_RECOVERED:
+ case SG_LIB_CAT_RECOVERED:
printf("Recovered error, continuing\n");
break;
default: /* won't bother decoding other categories */
diff --git a/archive/sg_dd2048.c b/archive/sg_dd2048.c
index 0a833c45..4e02a0ad 100644
--- a/archive/sg_dd2048.c
+++ b/archive/sg_dd2048.c
@@ -9,7 +9,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "sg_include.h"
-#include "sg_err.h"
+#include "sg_lib.h"
/* Test code for D. Gilbert's extensions to the Linux OS SCSI generic ("sg")
device driver.
@@ -90,9 +90,9 @@ int read_capacity(int sg_fd, int * num_sect, int * sect_sz)
return -1;
}
res = sg_err_category3(&io_hdr);
- if (SG_ERR_CAT_MEDIA_CHANGED == res)
+ if (SG_LIB_CAT_MEDIA_CHANGED == res)
return 2; /* probably have another go ... */
- else if (SG_ERR_CAT_CLEAN != res) {
+ else if (SG_LIB_CAT_CLEAN != res) {
sg_chk_n_print3("read capacity", &io_hdr);
return -1;
}
@@ -150,13 +150,13 @@ int sg_read(int sg_fd, unsigned char * buff, int blocks, int from_block)
return -1;
}
switch (sg_err_category3(&io_hdr)) {
- case SG_ERR_CAT_CLEAN:
+ case SG_LIB_CAT_CLEAN:
break;
- case SG_ERR_CAT_RECOVERED:
+ case SG_LIB_CAT_RECOVERED:
printf("Recovered error while reading block=%d, num=%d\n",
from_block, blocks);
break;
- case SG_ERR_CAT_MEDIA_CHANGED:
+ case SG_LIB_CAT_MEDIA_CHANGED:
return 2;
default:
sg_chk_n_print3("reading", &io_hdr);
@@ -211,13 +211,13 @@ int sg_write(int sg_fd, unsigned char * buff, int blocks, int to_block)
return -1;
}
switch (sg_err_category3(&io_hdr)) {
- case SG_ERR_CAT_CLEAN:
+ case SG_LIB_CAT_CLEAN:
break;
- case SG_ERR_CAT_RECOVERED:
+ case SG_LIB_CAT_RECOVERED:
printf("Recovered error while writing block=%d, num=%d\n",
to_block, blocks);
break;
- case SG_ERR_CAT_MEDIA_CHANGED:
+ case SG_LIB_CAT_MEDIA_CHANGED:
return 2;
default:
sg_chk_n_print3("writing", &io_hdr);
@@ -226,33 +226,6 @@ int sg_write(int sg_fd, unsigned char * buff, int blocks, int to_block)
return 0;
}
-int get_num(char * buf)
-{
- int res, num;
- char c, cc;
-
- res = sscanf(buf, "%d%c", &num, &c);
- if (0 == res)
- return -1;
- else if (1 == res)
- return num;
- else {
- cc = (char)toupper(c);
- if ('B' == cc)
- return num * 512;
- else if ('C' == cc)
- return num;
- else if ('K' == cc)
- return num * 1024;
- else if ('M' == cc)
- return num * 1024 * 1024;
- else {
- printf("unrecognized multiplier\n");
- return -1;
- }
- }
-}
-
int main(int argc, char * argv[])
{
@@ -303,25 +276,25 @@ int main(int argc, char * argv[])
else if (strcmp(key,"of") == 0)
strcpy(outf, buf);
else if (0 == strcmp(key,"ibs")) {
- if (BLOCK_SIZE != get_num(buf))
+ if (BLOCK_SIZE != sg_get_num(buf))
bs_bad = 1;
}
else if (0 == strcmp(key,"obs")) {
- if (BLOCK_SIZE != get_num(buf))
+ if (BLOCK_SIZE != sg_get_num(buf))
bs_bad = 1;
}
else if (0 == strcmp(key,"bs")) {
- if (BLOCK_SIZE != get_num(buf))
+ if (BLOCK_SIZE != sg_get_num(buf))
bs_bad = 1;
}
else if (0 == strcmp(key,"skip"))
- skip = get_num(buf);
+ skip = sg_get_num(buf);
else if (0 == strcmp(key,"seek"))
- seek = get_num(buf);
+ seek = sg_get_num(buf);
else if (0 == strcmp(key,"count"))
- count = get_num(buf);
+ count = sg_get_num(buf);
else if (0 == strcmp(key,"tq"))
- tq = get_num(buf);
+ tq = sg_get_num(buf);
else {
printf("Unrecognized argument '%s'\n", key);
usage();
diff --git a/archive/sg_dd512.c b/archive/sg_dd512.c
index 18d0e452..8740ff0f 100644
--- a/archive/sg_dd512.c
+++ b/archive/sg_dd512.c
@@ -9,7 +9,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "sg_include.h"
-#include "sg_err.h"
+#include "sg_lib.h"
/* Test code for D. Gilbert's extensions to the Linux OS SCSI generic ("sg")
device driver.
@@ -90,9 +90,9 @@ int read_capacity(int sg_fd, int * num_sect, int * sect_sz)
return -1;
}
res = sg_err_category3(&io_hdr);
- if (SG_ERR_CAT_MEDIA_CHANGED == res)
+ if (SG_LIB_CAT_MEDIA_CHANGED == res)
return 2; /* probably have another go ... */
- else if (SG_ERR_CAT_CLEAN != res) {
+ else if (SG_LIB_CAT_CLEAN != res) {
sg_chk_n_print3("read capacity", &io_hdr);
return -1;
}
@@ -150,13 +150,13 @@ int sg_read(int sg_fd, unsigned char * buff, int blocks, int from_block)
return -1;
}
switch (sg_err_category3(&io_hdr)) {
- case SG_ERR_CAT_CLEAN:
+ case SG_LIB_CAT_CLEAN:
break;
- case SG_ERR_CAT_RECOVERED:
+ case SG_LIB_CAT_RECOVERED:
printf("Recovered error while reading block=%d, num=%d\n",
from_block, blocks);
break;
- case SG_ERR_CAT_MEDIA_CHANGED:
+ case SG_LIB_CAT_MEDIA_CHANGED:
return 2;
default:
sg_chk_n_print3("reading", &io_hdr);
@@ -211,13 +211,13 @@ int sg_write(int sg_fd, unsigned char * buff, int blocks, int to_block)
return -1;
}
switch (sg_err_category3(&io_hdr)) {
- case SG_ERR_CAT_CLEAN:
+ case SG_LIB_CAT_CLEAN:
break;
- case SG_ERR_CAT_RECOVERED:
+ case SG_LIB_CAT_RECOVERED:
printf("Recovered error while writing block=%d, num=%d\n",
to_block, blocks);
break;
- case SG_ERR_CAT_MEDIA_CHANGED:
+ case SG_LIB_CAT_MEDIA_CHANGED:
return 2;
default:
sg_chk_n_print3("writing", &io_hdr);
@@ -226,33 +226,6 @@ int sg_write(int sg_fd, unsigned char * buff, int blocks, int to_block)
return 0;
}
-int get_num(char * buf)
-{
- int res, num;
- char c, cc;
-
- res = sscanf(buf, "%d%c", &num, &c);
- if (0 == res)
- return -1;
- else if (1 == res)
- return num;
- else {
- cc = (char)toupper(c);
- if ('B' == cc)
- return num * 512;
- else if ('C' == cc)
- return num;
- else if ('K' == cc)
- return num * 1024;
- else if ('M' == cc)
- return num * 1024 * 1024;
- else {
- printf("unrecognized multiplier\n");
- return -1;
- }
- }
-}
-
int main(int argc, char * argv[])
{
@@ -303,25 +276,25 @@ int main(int argc, char * argv[])
else if (strcmp(key,"of") == 0)
strcpy(outf, buf);
else if (0 == strcmp(key,"ibs")) {
- if (BLOCK_SIZE != get_num(buf))
+ if (BLOCK_SIZE != sg_get_num(buf))
bs_bad = 1;
}
else if (0 == strcmp(key,"obs")) {
- if (BLOCK_SIZE != get_num(buf))
+ if (BLOCK_SIZE != sg_get_num(buf))
bs_bad = 1;
}
else if (0 == strcmp(key,"bs")) {
- if (BLOCK_SIZE != get_num(buf))
+ if (BLOCK_SIZE != sg_get_num(buf))
bs_bad = 1;
}
else if (0 == strcmp(key,"skip"))
- skip = get_num(buf);
+ skip = sg_get_num(buf);
else if (0 == strcmp(key,"seek"))
- seek = get_num(buf);
+ seek = sg_get_num(buf);
else if (0 == strcmp(key,"count"))
- count = get_num(buf);
+ count = sg_get_num(buf);
else if (0 == strcmp(key,"tq"))
- tq = get_num(buf);
+ tq = sg_get_num(buf);
else {
printf("Unrecognized argument '%s'\n", key);
usage();
diff --git a/archive/sg_dd_old.c b/archive/sg_dd_old.c
index 7ff9ad62..5553fc30 100644
--- a/archive/sg_dd_old.c
+++ b/archive/sg_dd_old.c
@@ -9,7 +9,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "sg_include.h"
-#include "sg_err.h"
+#include "sg_lib.h"
/* A utility program for the Linux OS SCSI generic ("sg") device driver.
* Copyright (C) 1999 D. Gilbert and P. Allworth
@@ -86,9 +86,9 @@ int read_capacity(int sg_fd, int * num_sect, int * sect_sz)
return -1;
}
res = sg_err_category3(&io_hdr);
- if (SG_ERR_CAT_MEDIA_CHANGED == res)
+ if (SG_LIB_CAT_MEDIA_CHANGED == res)
return 2; /* probably have another go ... */
- else if (SG_ERR_CAT_CLEAN != res) {
+ else if (SG_LIB_CAT_CLEAN != res) {
sg_chk_n_print3("read capacity", &io_hdr);
return -1;
}
@@ -151,13 +151,13 @@ int sg_read(int sg_fd, unsigned char * buff, int blocks, int from_block,
return -1;
}
switch (sg_err_category3(&io_hdr)) {
- case SG_ERR_CAT_CLEAN:
+ case SG_LIB_CAT_CLEAN:
break;
- case SG_ERR_CAT_RECOVERED:
+ case SG_LIB_CAT_RECOVERED:
printf("Recovered error while reading block=%d, num=%d\n",
from_block, blocks);
break;
- case SG_ERR_CAT_MEDIA_CHANGED:
+ case SG_LIB_CAT_MEDIA_CHANGED:
return 2;
default:
sg_chk_n_print3("reading", &io_hdr);
@@ -222,13 +222,13 @@ int sg_write(int sg_fd, unsigned char * buff, int blocks, int to_block,
return -1;
}
switch (sg_err_category3(&io_hdr)) {
- case SG_ERR_CAT_CLEAN:
+ case SG_LIB_CAT_CLEAN:
break;
- case SG_ERR_CAT_RECOVERED:
+ case SG_LIB_CAT_RECOVERED:
printf("Recovered error while writing block=%d, num=%d\n",
to_block, blocks);
break;
- case SG_ERR_CAT_MEDIA_CHANGED:
+ case SG_LIB_CAT_MEDIA_CHANGED:
return 2;
default:
sg_chk_n_print3("writing", &io_hdr);
@@ -240,33 +240,6 @@ int sg_write(int sg_fd, unsigned char * buff, int blocks, int to_block,
return 0;
}
-int get_num(char * buf)
-{
- int res, num;
- char c, cc;
-
- res = sscanf(buf, "%d%c", &num, &c);
- if (0 == res)
- return -1;
- else if (1 == res)
- return num;
- else {
- cc = (char)toupper(c);
- if ('B' == cc)
- return num * 512;
- else if ('C' == cc)
- return num;
- else if ('K' == cc)
- return num * 1024;
- else if ('M' == cc)
- return num * 1024 * 1024;
- else {
- printf("unrecognized multiplier\n");
- return -1;
- }
- }
-}
-
int main(int argc, char * argv[])
{
@@ -321,21 +294,21 @@ int main(int argc, char * argv[])
else if (strcmp(key,"of") == 0)
strcpy(outf, buf);
else if (0 == strcmp(key,"ibs"))
- ibs = get_num(buf);
+ ibs = sg_get_num(buf);
else if (0 == strcmp(key,"obs"))
- obs = get_num(buf);
+ obs = sg_get_num(buf);
else if (0 == strcmp(key,"bs"))
- bs = get_num(buf);
+ bs = sg_get_num(buf);
else if (0 == strcmp(key,"bpt"))
- bpt = get_num(buf);
+ bpt = sg_get_num(buf);
else if (0 == strcmp(key,"skip"))
- skip = get_num(buf);
+ skip = sg_get_num(buf);
else if (0 == strcmp(key,"seek"))
- seek = get_num(buf);
+ seek = sg_get_num(buf);
else if (0 == strcmp(key,"count"))
- count = get_num(buf);
+ count = sg_get_num(buf);
else if (0 == strcmp(key,"dio"))
- dio = get_num(buf);
+ dio = sg_get_num(buf);
else {
printf("Unrecognized argument '%s'\n", key);
usage();
diff --git a/archive/sg_err.h b/archive/sg_err.h
deleted file mode 100644
index 2cfabb70..00000000
--- a/archive/sg_err.h
+++ /dev/null
@@ -1,227 +0,0 @@
-#ifndef SG_ERR_H
-#define SG_ERR_H
-
-/* Feel free to copy and modify this GPL-ed code into your applications. */
-
-/* Version 0.97 (20040830)
-*/
-
-
-/* Some of the following error/status codes are exchanged between the
- various layers of the SCSI sub-system in Linux and should never
- reach the user. They are placed here for completeness. What appears
- here is copied from drivers/scsi/scsi.h which is not visible in
- the user space. */
-
-#ifndef SCSI_CHECK_CONDITION
-/* Following are the "true" SCSI status codes. Linux has traditionally
- used a 1 bit right and masked version of these. So now CHECK_CONDITION
- and friends (in <scsi/scsi.h>) are deprecated. */
-#define SCSI_CHECK_CONDITION 0x2
-#define SCSI_CONDITION_MET 0x4
-#define SCSI_BUSY 0x8
-#define SCSI_IMMEDIATE 0x10
-#define SCSI_IMMEDIATE_CONDITION_MET 0x14
-#define SCSI_RESERVATION_CONFLICT 0x18
-#define SCSI_COMMAND_TERMINATED 0x22
-#define SCSI_TASK_SET_FULL 0x28
-#define SCSI_ACA_ACTIVE 0x30
-#define SCSI_TASK_ABORTED 0x40
-#endif
-
-/* The following are 'host_status' codes */
-#ifndef DID_OK
-#define DID_OK 0x00
-#endif
-#ifndef DID_NO_CONNECT
-#define DID_NO_CONNECT 0x01 /* Unable to connect before timeout */
-#define DID_BUS_BUSY 0x02 /* Bus remain busy until timeout */
-#define DID_TIME_OUT 0x03 /* Timed out for some other reason */
-#define DID_BAD_TARGET 0x04 /* Bad target (id?) */
-#define DID_ABORT 0x05 /* Told to abort for some other reason */
-#define DID_PARITY 0x06 /* Parity error (on SCSI bus) */
-#define DID_ERROR 0x07 /* Internal error */
-#define DID_RESET 0x08 /* Reset by somebody */
-#define DID_BAD_INTR 0x09 /* Received an unexpected interrupt */
-#define DID_PASSTHROUGH 0x0a /* Force command past mid-level */
-#define DID_SOFT_ERROR 0x0b /* The low-level driver wants a retry */
-#endif
-
-/* These defines are to isolate applictaions from kernel define changes */
-#define SG_ERR_DID_OK DID_OK
-#define SG_ERR_DID_NO_CONNECT DID_NO_CONNECT
-#define SG_ERR_DID_BUS_BUSY DID_BUS_BUSY
-#define SG_ERR_DID_TIME_OUT DID_TIME_OUT
-#define SG_ERR_DID_BAD_TARGET DID_BAD_TARGET
-#define SG_ERR_DID_ABORT DID_ABORT
-#define SG_ERR_DID_PARITY DID_PARITY
-#define SG_ERR_DID_ERROR DID_ERROR
-#define SG_ERR_DID_RESET DID_RESET
-#define SG_ERR_DID_BAD_INTR DID_BAD_INTR
-#define SG_ERR_DID_PASSTHROUGH DID_PASSTHROUGH
-#define SG_ERR_DID_SOFT_ERROR DID_SOFT_ERROR
-
-/* The following are 'driver_status' codes */
-#ifndef DRIVER_OK
-#define DRIVER_OK 0x00
-#endif
-#ifndef DRIVER_BUSY
-#define DRIVER_BUSY 0x01
-#define DRIVER_SOFT 0x02
-#define DRIVER_MEDIA 0x03
-#define DRIVER_ERROR 0x04
-#define DRIVER_INVALID 0x05
-#define DRIVER_TIMEOUT 0x06
-#define DRIVER_HARD 0x07
-#define DRIVER_SENSE 0x08 /* Sense_buffer has been set */
-
-/* Following "suggests" are "or-ed" with one of previous 8 entries */
-#define SUGGEST_RETRY 0x10
-#define SUGGEST_ABORT 0x20
-#define SUGGEST_REMAP 0x30
-#define SUGGEST_DIE 0x40
-#define SUGGEST_SENSE 0x80
-#define SUGGEST_IS_OK 0xff
-#endif
-#ifndef DRIVER_MASK
-#define DRIVER_MASK 0x0f
-#endif
-#ifndef SUGGEST_MASK
-#define SUGGEST_MASK 0xf0
-#endif
-
-/* These defines are to isolate applictaions from kernel define changes */
-#define SG_ERR_DRIVER_OK DRIVER_OK
-#define SG_ERR_DRIVER_BUSY DRIVER_BUSY
-#define SG_ERR_DRIVER_SOFT DRIVER_SOFT
-#define SG_ERR_DRIVER_MEDIA DRIVER_MEDIA
-#define SG_ERR_DRIVER_ERROR DRIVER_ERROR
-#define SG_ERR_DRIVER_INVALID DRIVER_INVALID
-#define SG_ERR_DRIVER_TIMEOUT DRIVER_TIMEOUT
-#define SG_ERR_DRIVER_HARD DRIVER_HARD
-#define SG_ERR_DRIVER_SENSE DRIVER_SENSE
-#define SG_ERR_SUGGEST_RETRY SUGGEST_RETRY
-#define SG_ERR_SUGGEST_ABORT SUGGEST_ABORT
-#define SG_ERR_SUGGEST_REMAP SUGGEST_REMAP
-#define SG_ERR_SUGGEST_DIE SUGGEST_DIE
-#define SG_ERR_SUGGEST_SENSE SUGGEST_SENSE
-#define SG_ERR_SUGGEST_IS_OK SUGGEST_IS_OK
-#define SG_ERR_DRIVER_MASK DRIVER_MASK
-#define SG_ERR_SUGGEST_MASK SUGGEST_MASK
-
-
-
-/* The following "print" functions send ACSII to stdout */
-extern void sg_print_command(const unsigned char * command);
-extern void sg_print_sense(const char * leadin,
- const unsigned char * sense_buffer, int sb_len);
-extern void sg_print_status(int masked_status);
-extern void sg_print_scsi_status(int scsi_status);
-extern void sg_print_host_status(int host_status);
-extern void sg_print_driver_status(int driver_status);
-
-/* sg_chk_n_print() returns 1 quietly if there are no errors/warnings
- else it prints to standard output and returns 0. */
-extern int sg_chk_n_print(const char * leadin, int masked_status,
- int host_status, int driver_status,
- const unsigned char * sense_buffer, int sb_len);
-
-/* This is a slightly stretched SCSI sense "descriptor" format header.
- The addition is to allow the 0x70 and 0x71 response codes. The idea
- is to place the salient data of both "fixed" and "descriptor" sense
- format into one structure to ease application processing.
- The original sense buffer should be kept around for those cases
- in which more information is required (e.g. the LBA of a MEDIUM ERROR). */
-struct sg_scsi_sense_hdr {
- unsigned char response_code; /* permit: 0x0, 0x70, 0x71, 0x72, 0x73 */
- unsigned char sense_key;
- unsigned char asc;
- unsigned char ascq;
- unsigned char byte4;
- unsigned char byte5;
- unsigned char byte6;
- unsigned char additional_length;
-};
-
-/* Maps the salient data from a sense buffer which is in either fixed or
- descriptor format into a structure mimicking a descriptor format
- header (i.e. the first 8 bytes).
- If zero response code returns 0. Otherwise returns 1 and if 'sshp' is
- non-NULL then zero all fields and then set the appropriate fields in
- that structure. sshp::additional_length is always 0 for response
- codes 0x70 and 0x71 (fixed format). */
-extern int sg_scsi_normalize_sense(const unsigned char * sensep,
- int sense_len,
- struct sg_scsi_sense_hdr * sshp);
-
-/* Attempt to find the first SCSI sense data descriptor that matches the
- given 'desc_type'. If found return pointer to start of sense data
- descriptor; otherwise (including fixed format sense data) returns NULL. */
-extern const unsigned char * sg_scsi_sense_desc_find(
- const unsigned char * sensep, int sense_len, int desc_type);
-
-/* The following function declaration is for the sg version 3 driver.
- Only version 3 sg_err.c defines it. */
-struct sg_io_hdr;
-extern int sg_chk_n_print3(const char * leadin, struct sg_io_hdr * hp);
-
-/* Calls sg_scsi_normalize_sense() after obtaining the sense buffer and
- its length from the struct sg_io_hdr pointer. If these cannot be
- obtained, 0 is returned. */
-extern int sg_normalize_sense(const struct sg_io_hdr * hp,
- struct sg_scsi_sense_hdr * sshp);
-
-
-/* The following "category" function returns one of the following */
-#define SG_ERR_CAT_CLEAN 0 /* No errors or other information */
-#define SG_ERR_CAT_MEDIA_CHANGED 1 /* interpreted from sense buffer */
-#define SG_ERR_CAT_RESET 2 /* interpreted from sense buffer */
-#define SG_ERR_CAT_TIMEOUT 3
-#define SG_ERR_CAT_RECOVERED 4 /* Successful command after recovered err */
-#define SG_ERR_CAT_SENSE 98 /* Something else is in the sense buffer */
-#define SG_ERR_CAT_OTHER 99 /* Some other error/warning has occurred */
-
-extern int sg_err_category(int masked_status, int host_status,
- int driver_status, const unsigned char * sense_buffer,
- int sb_len);
-
-extern int sg_err_category_new(int scsi_status, int host_status,
- int driver_status, const unsigned char * sense_buffer,
- int sb_len);
-
-/* The following function declaration is for the sg version 3 driver.
- Only version 3 sg_err.c defines it. */
-extern int sg_err_category3(struct sg_io_hdr * hp);
-
-/* Returns length of SCSI command given the opcode (first byte).
- Yields the wrong answer for variable length commands (opcode=0x7f)
- and potentially some vendor specific commands. */
-extern int sg_get_command_size(unsigned char opcode);
-
-/* Command name given pointer to command bytes. Certain command names
- depend on the service action within the command as well. */
-extern void sg_get_command_name(const unsigned char * cmdp, int peri_type,
- int buff_len, char * buff);
-
-/* Opcode name given only the first byte (byte 0) of a command */
-extern void sg_get_opcode_name(unsigned char cmd_byte0, int peri_type,
- int buff_len, char * buff);
-
-/* Command name given opcode (byte 0) and service action of a command */
-extern void sg_get_opcode_sa_name(unsigned char cmd_byte0, int service_action,
- int peri_type, int buff_len, char * buff);
-
-
-/* <<< General purpose (i.e. not SCSI specific) utility functions >>> */
-
-/* Always returns valid string even if errnum is wild (or library problem) */
-extern char * safe_strerror(int errnum);
-
-
-/* Print (to stdout) 'str' of bytes in hex, 16 bytes per line optionally
- followed at the right hand side of the line with an ASCII interpretation.
- Each line is prefixed with an address, starting at 0 for str[0]..str[15].
- All output numbers are in hex. */
-extern void dStrHex(const char* str, int len, int no_ascii);
-
-#endif
diff --git a/archive/sg_lib.h b/archive/sg_lib.h
new file mode 120000
index 00000000..f6ce0761
--- /dev/null
+++ b/archive/sg_lib.h
@@ -0,0 +1 @@
+../sg_lib.h \ No newline at end of file
diff --git a/archive/sg_poll.c b/archive/sg_poll.c
index 8d3fe135..28957505 100644
--- a/archive/sg_poll.c
+++ b/archive/sg_poll.c
@@ -14,7 +14,7 @@
#include <sys/ipc.h>
#include <sys/sem.h>
#include "sg_include.h"
-#include "sg_err.h"
+#include "sg_lib.h"
/* Test code for D. Gilbert's extensions to the Linux OS SCSI generic ("sg")
device driver.
diff --git a/archive/sgq_dd.c b/archive/sgq_dd.c
index 064bd2a8..8dd95563 100644
--- a/archive/sgq_dd.c
+++ b/archive/sgq_dd.c
@@ -18,7 +18,7 @@
#include <sys/time.h>
typedef unsigned char u_char; /* horrible, for scsi.h */
#include "sg_include.h"
-#include "sg_err.h"
+#include "sg_lib.h"
#include "llseek.h"
/* A utility program for the Linux OS SCSI generic ("sg") device driver.
@@ -301,9 +301,9 @@ int read_capacity(int sg_fd, int * num_sect, int * sect_sz)
return -1;
}
res = sg_err_category3(&io_hdr);
- if (SG_ERR_CAT_MEDIA_CHANGED == res)
+ if (SG_LIB_CAT_MEDIA_CHANGED == res)
return 2; /* probably have another go ... */
- else if (SG_ERR_CAT_CLEAN != res) {
+ else if (SG_LIB_CAT_CLEAN != res) {
sg_chk_n_print3("read capacity", &io_hdr);
return -1;
}
@@ -522,13 +522,13 @@ int sg_finish_io(int wr, Rq_elem * rep)
hp = &rep->io_hdr;
switch (sg_err_category3(hp)) {
- case SG_ERR_CAT_CLEAN:
+ case SG_LIB_CAT_CLEAN:
break;
- case SG_ERR_CAT_RECOVERED:
+ case SG_LIB_CAT_RECOVERED:
fprintf(stderr, "Recovered error on block=%d, num=%d\n",
rep->blk, rep->num_blks);
break;
- case SG_ERR_CAT_MEDIA_CHANGED:
+ case SG_LIB_CAT_MEDIA_CHANGED:
return 1;
default:
{
@@ -704,43 +704,6 @@ int decider(Rq_coll * clp, int first_xfer, int * req_indexp)
return QS_IDLE;
}
-int get_num(char * buf)
-{
- int res, num;
- char c;
-
- res = sscanf(buf, "%d%c", &num, &c);
- if (0 == res)
- return -1;
- else if (1 == res)
- return num;
- else {
- switch (c) {
- case 'c':
- case 'C':
- return num;
- case 'b':
- case 'B':
- return num * 512;
- case 'k':
- return num * 1024;
- case 'K':
- return num * 1000;
- case 'm':
- return num * 1024 * 1024;
- case 'M':
- return num * 1000000;
- case 'g':
- return num * 1024 * 1024 * 1024;
- case 'G':
- return num * 1000000000;
- default:
- fprintf(stderr, "unrecognized multiplier\n");
- return -1;
- }
- }
-}
-
int main(int argc, char * argv[])
{
@@ -790,31 +753,31 @@ int main(int argc, char * argv[])
else if (strcmp(key,"of") == 0)
strncpy(outf, buf, INOUTF_SZ);
else if (0 == strcmp(key,"ibs"))
- ibs = get_num(buf);
+ ibs = sg_get_num(buf);
else if (0 == strcmp(key,"obs"))
- obs = get_num(buf);
+ obs = sg_get_num(buf);
else if (0 == strcmp(key,"bs"))
- rcoll.bs = get_num(buf);
+ rcoll.bs = sg_get_num(buf);
else if (0 == strcmp(key,"bpt"))
- rcoll.bpt = get_num(buf);
+ rcoll.bpt = sg_get_num(buf);
else if (0 == strcmp(key,"skip"))
- skip = get_num(buf);
+ skip = sg_get_num(buf);
else if (0 == strcmp(key,"seek"))
- seek = get_num(buf);
+ seek = sg_get_num(buf);
else if (0 == strcmp(key,"count"))
- dd_count = get_num(buf);
+ dd_count = sg_get_num(buf);
else if (0 == strcmp(key,"dio"))
- rcoll.dio = get_num(buf);
+ rcoll.dio = sg_get_num(buf);
else if (0 == strcmp(key,"thr"))
- num_threads = get_num(buf);
+ num_threads = sg_get_num(buf);
else if (0 == strcmp(key,"coe"))
- rcoll.coe = get_num(buf);
+ rcoll.coe = sg_get_num(buf);
else if (0 == strcmp(key,"gen"))
- gen = get_num(buf);
+ gen = sg_get_num(buf);
else if (0 == strncmp(key,"deb", 3))
- rcoll.debug = get_num(buf);
+ rcoll.debug = sg_get_num(buf);
else if (0 == strcmp(key,"time"))
- do_time = get_num(buf);
+ do_time = sg_get_num(buf);
else if (0 == strncmp(key, "--vers", 6)) {
fprintf(stderr, "sgq_dd for sg version 3 driver: %s\n",
version_str);
diff --git a/archive/sgq_dd.c.orig b/archive/sgq_dd.c.orig
index 17be0f43..644e9750 100644
--- a/archive/sgq_dd.c.orig
+++ b/archive/sgq_dd.c.orig
@@ -18,7 +18,7 @@
#include <sys/time.h>
typedef unsigned char u_char; /* horrible, for scsi.h */
#include "sg_include.h"
-#include "sg_err.h"
+#include "sg_lib.h"
#include "llseek.h"
/* A utility program for the Linux OS SCSI generic ("sg") device driver.
@@ -696,43 +696,6 @@ int decider(Rq_coll * clp, int first_xfer, int * req_indexp)
return QS_IDLE;
}
-int get_num(char * buf)
-{
- int res, num;
- char c;
-
- res = sscanf(buf, "%d%c", &num, &c);
- if (0 == res)
- return -1;
- else if (1 == res)
- return num;
- else {
- switch (c) {
- case 'c':
- case 'C':
- return num;
- case 'b':
- case 'B':
- return num * 512;
- case 'k':
- return num * 1024;
- case 'K':
- return num * 1000;
- case 'm':
- return num * 1024 * 1024;
- case 'M':
- return num * 1000000;
- case 'g':
- return num * 1024 * 1024 * 1024;
- case 'G':
- return num * 1000000000;
- default:
- fprintf(stderr, "unrecognized multiplier\n");
- return -1;
- }
- }
-}
-
int main(int argc, char * argv[])
{
@@ -782,31 +745,31 @@ int main(int argc, char * argv[])
else if (strcmp(key,"of") == 0)
strncpy(outf, buf, INOUTF_SZ);
else if (0 == strcmp(key,"ibs"))
- ibs = get_num(buf);
+ ibs = sg_get_num(buf);
else if (0 == strcmp(key,"obs"))
- obs = get_num(buf);
+ obs = sg_get_num(buf);
else if (0 == strcmp(key,"bs"))
- rcoll.bs = get_num(buf);
+ rcoll.bs = sg_get_num(buf);
else if (0 == strcmp(key,"bpt"))
- rcoll.bpt = get_num(buf);
+ rcoll.bpt = sg_get_num(buf);
else if (0 == strcmp(key,"skip"))
- skip = get_num(buf);
+ skip = sg_get_num(buf);
else if (0 == strcmp(key,"seek"))
- seek = get_num(buf);
+ seek = sg_get_num(buf);
else if (0 == strcmp(key,"count"))
- dd_count = get_num(buf);
+ dd_count = sg_get_num(buf);
else if (0 == strcmp(key,"dio"))
- rcoll.dio = get_num(buf);
+ rcoll.dio = sg_get_num(buf);
else if (0 == strcmp(key,"thr"))
- num_threads = get_num(buf);
+ num_threads = sg_get_num(buf);
else if (0 == strcmp(key,"coe"))
- rcoll.coe = get_num(buf);
+ rcoll.coe = sg_get_num(buf);
else if (0 == strcmp(key,"gen"))
- gen = get_num(buf);
+ gen = sg_get_num(buf);
else if (0 == strncmp(key,"deb", 3))
- rcoll.debug = get_num(buf);
+ rcoll.debug = sg_get_num(buf);
else if (0 == strcmp(key,"time"))
- do_time = get_num(buf);
+ do_time = sg_get_num(buf);
else if (0 == strncmp(key, "--vers", 6)) {
fprintf(stderr, "sgq_dd for sg version 3 driver: %s\n",
version_str);
diff --git a/archive/sgq_old_dd.c b/archive/sgq_old_dd.c
index 2ef041dd..dd20efe3 100644
--- a/archive/sgq_old_dd.c
+++ b/archive/sgq_old_dd.c
@@ -10,7 +10,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "sg_include.h"
-#include "sg_err.h"
+#include "sg_lib.h"
/* A utility program for the Linux OS SCSI generic ("sg") device driver.
* Copyright (C) 1999 D. Gilbert and P. Allworth
@@ -143,9 +143,9 @@ int read_capacity(int sg_fd, int * num_sect, int * sect_sz)
return -1;
}
res = sg_err_category3(&io_hdr);
- if (SG_ERR_CAT_MEDIA_CHANGED == res)
+ if (SG_LIB_CAT_MEDIA_CHANGED == res)
return 2; /* probably have another go ... */
- else if (SG_ERR_CAT_CLEAN != res) {
+ else if (SG_LIB_CAT_CLEAN != res) {
sg_chk_n_print3("read capacity", &io_hdr);
return -1;
}
@@ -253,13 +253,13 @@ int sg_finish_io(Rq_coll * clp, int wr, Rq_elem ** repp)
*repp = rep;
switch (sg_err_category3(hp)) {
- case SG_ERR_CAT_CLEAN:
+ case SG_LIB_CAT_CLEAN:
break;
- case SG_ERR_CAT_RECOVERED:
+ case SG_LIB_CAT_RECOVERED:
printf("Recovered error on block=%d, num=%d\n",
rep->blk, rep->num_blks);
break;
- case SG_ERR_CAT_MEDIA_CHANGED:
+ case SG_LIB_CAT_MEDIA_CHANGED:
return 1;
default:
sg_chk_n_print3(rep->wr ? "writing": "reading", hp);
@@ -295,33 +295,6 @@ int sz_reserve(int fd, int bs, int bpt)
return 0;
}
-int get_num(char * buf)
-{
- int res, num;
- char c, cc;
-
- res = sscanf(buf, "%d%c", &num, &c);
- if (0 == res)
- return -1;
- else if (1 == res)
- return num;
- else {
- cc = (char)toupper(c);
- if ('B' == cc)
- return num * 512;
- else if ('C' == cc)
- return num;
- else if ('K' == cc)
- return num * 1024;
- else if ('M' == cc)
- return num * 1024 * 1024;
- else {
- printf("unrecognized multiplier\n");
- return -1;
- }
- }
-}
-
void init_elems(Rq_coll * clp)
{
Rq_elem * rep;
@@ -648,23 +621,23 @@ int main(int argc, char * argv[])
else if (strcmp(key,"of") == 0)
strcpy(outf, buf);
else if (0 == strcmp(key,"ibs"))
- ibs = get_num(buf);
+ ibs = sg_get_num(buf);
else if (0 == strcmp(key,"obs"))
- obs = get_num(buf);
+ obs = sg_get_num(buf);
else if (0 == strcmp(key,"bs"))
- rcoll.bs = get_num(buf);
+ rcoll.bs = sg_get_num(buf);
else if (0 == strcmp(key,"bpt"))
- rcoll.bpt = get_num(buf);
+ rcoll.bpt = sg_get_num(buf);
else if (0 == strcmp(key,"skip"))
- skip = get_num(buf);
+ skip = sg_get_num(buf);
else if (0 == strcmp(key,"seek"))
- seek = get_num(buf);
+ seek = sg_get_num(buf);
else if (0 == strcmp(key,"count"))
- count = get_num(buf);
+ count = sg_get_num(buf);
else if (0 == strcmp(key,"dio"))
- rcoll.dio = get_num(buf);
+ rcoll.dio = sg_get_num(buf);
else if (0 == strcmp(key,"deb"))
- rcoll.debug = get_num(buf);
+ rcoll.debug = sg_get_num(buf);
else {
printf("Unrecognized argument '%s'\n", key);
usage();
diff --git a/archive/sgs_dd.c b/archive/sgs_dd.c
index ff329a33..ecac72de 100644
--- a/archive/sgs_dd.c
+++ b/archive/sgs_dd.c
@@ -14,7 +14,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "sg_include.h"
-#include "sg_err.h"
+#include "sg_lib.h"
/* Test code for the extensions to the Linux OS SCSI generic ("sg")
device driver.
@@ -166,9 +166,9 @@ int read_capacity(int sg_fd, int * num_sect, int * sect_sz)
return -1;
}
res = sg_err_category3(&io_hdr);
- if (SG_ERR_CAT_MEDIA_CHANGED == res)
+ if (SG_LIB_CAT_MEDIA_CHANGED == res)
return 2; /* probably have another go ... */
- else if (SG_ERR_CAT_CLEAN != res) {
+ else if (SG_LIB_CAT_CLEAN != res) {
sg_chk_n_print3("read capacity", &io_hdr);
return -1;
}
@@ -266,13 +266,13 @@ int sg_finish_io(Rq_coll * clp, int wr, Rq_elem ** repp)
*repp = rep;
switch (sg_err_category3(hp)) {
- case SG_ERR_CAT_CLEAN:
+ case SG_LIB_CAT_CLEAN:
break;
- case SG_ERR_CAT_RECOVERED:
+ case SG_LIB_CAT_RECOVERED:
printf("Recovered error on block=%d, num=%d\n",
rep->blk, rep->num_blks);
break;
- case SG_ERR_CAT_MEDIA_CHANGED:
+ case SG_LIB_CAT_MEDIA_CHANGED:
return 1;
default:
sg_chk_n_print3(rep->wr ? "writing": "reading", hp);
@@ -318,33 +318,6 @@ int sz_reserve(int fd, int bs, int bpt)
return 0;
}
-int get_num(char * buf)
-{
- int res, num;
- char c, cc;
-
- res = sscanf(buf, "%d%c", &num, &c);
- if (0 == res)
- return -1;
- else if (1 == res)
- return num;
- else {
- cc = (char)toupper(c);
- if ('B' == cc)
- return num * 512;
- else if ('C' == cc)
- return num;
- else if ('K' == cc)
- return num * 1024;
- else if ('M' == cc)
- return num * 1024 * 1024;
- else {
- printf("unrecognized multiplier\n");
- return -1;
- }
- }
-}
-
void init_elems(Rq_coll * clp)
{
Rq_elem * rep;
@@ -697,23 +670,23 @@ int main(int argc, char * argv[])
else if (strcmp(key,"of") == 0)
strncpy(outf, buf, INOUTF_SZ);
else if (0 == strcmp(key,"ibs"))
- ibs = get_num(buf);
+ ibs = sg_get_num(buf);
else if (0 == strcmp(key,"obs"))
- obs = get_num(buf);
+ obs = sg_get_num(buf);
else if (0 == strcmp(key,"bs"))
- rcoll.bs = get_num(buf);
+ rcoll.bs = sg_get_num(buf);
else if (0 == strcmp(key,"bpt"))
- rcoll.bpt = get_num(buf);
+ rcoll.bpt = sg_get_num(buf);
else if (0 == strcmp(key,"skip"))
- skip = get_num(buf);
+ skip = sg_get_num(buf);
else if (0 == strcmp(key,"seek"))
- seek = get_num(buf);
+ seek = sg_get_num(buf);
else if (0 == strcmp(key,"count"))
- count = get_num(buf);
+ count = sg_get_num(buf);
else if (0 == strcmp(key,"dio"))
- rcoll.dio = get_num(buf);
+ rcoll.dio = sg_get_num(buf);
else if (0 == strcmp(key,"deb"))
- rcoll.debug = get_num(buf);
+ rcoll.debug = sg_get_num(buf);
else {
printf("Unrecognized argument '%s'\n", key);
usage();