diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2007-06-27 02:58:56 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2007-06-27 02:58:56 +0000 |
commit | 0e9184cde6f3d1a0046c706051a4bd4b36a6aede (patch) | |
tree | f4ac79c282481f25f14efa9b7d85dce6001832c5 /archive | |
parent | 1f7410c00c57dcc2c6b0d64a33431e2298a7c87b (diff) | |
download | sg3_utils-0e9184cde6f3d1a0046c706051a4bd4b36a6aede.tar.gz |
Load sg3_utils-1.07 into trunk/.
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@39 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'archive')
-rw-r--r-- | archive/Makefile | 7 | ||||
-rw-r--r-- | archive/README | 4 | ||||
-rw-r--r-- | archive/isosize.8 | 2 | ||||
-rwxr-xr-x | archive/rescan-scsi-bus.sh | 2 | ||||
-rw-r--r-- | archive/scsi_devfs_scan.c | 242 | ||||
-rw-r--r-- | archive/sg_err.h | 29 |
6 files changed, 155 insertions, 131 deletions
diff --git a/archive/Makefile b/archive/Makefile index a19f92e5..e69fd42c 100644 --- a/archive/Makefile +++ b/archive/Makefile @@ -6,14 +6,14 @@ MANDIR=/usr/local/man CC = gcc LD = gcc -EXECS = sgq_dd sg_poll sg_bus_xfer sg_hold sg_debug isosize +EXECS = sgq_dd sg_poll sg_bus_xfer sg_hold sg_debug isosize scsi_devfs_scan COMMON = isosize MAN_PGS = isosize.8 MAN_PREF = man8 -CFLAGS = -g -O2 -Wall -D_REENTRANT +CFLAGS = -g -O2 -W -Wall -D_REENTRANT # CFLAGS = -g -O2 -Wall -pedantic -D_REENTRANT LDFLAGS = @@ -44,6 +44,9 @@ sg_hold: sg_hold.o isosize: isosize.o $(LD) -o $@ $(LDFLAGS) $^ +scsi_devfs_scan: scsi_devfs_scan.o ../sg_err.o + $(LD) -o $@ $(LDFLAGS) $^ + sg_debug: sg_debug.o $(LD) -o $@ $(LDFLAGS) $^ diff --git a/archive/README b/archive/README index dcb0b51f..0908e806 100644 --- a/archive/README +++ b/archive/README @@ -22,8 +22,8 @@ been set up which builds: The sg_err.h and llseek.h headers have simply been copied from the parent directory. -The very useful rescan-scsi-bus.sh script from Kurt Garloff<kurt@garloff.de> -is included in this directory. +The very useful rescan-scsi-bus.sh script from Kurt Garloff +<kurt at garloff dot de> is included in this directory. A test program called sg_bus_xfer.c exercises a patch that adds a SG_FLAG_BUS_ADDR capability. This allows a bus address (e.g. PCI diff --git a/archive/isosize.8 b/archive/isosize.8 index 4d25e66c..f9fb4180 100644 --- a/archive/isosize.8 +++ b/archive/isosize.8 @@ -30,7 +30,7 @@ image. .SH AUTHOR Written by Andries Brouwer .SH "REPORTING BUGS" -Report bugs to <Andries.Brouwer@cwi.nl>. +Report bugs to <Andries.Brouwer at cwi dot nl>. .SH COPYRIGHT Copyright \(co 2000 Andries Brouwer .br diff --git a/archive/rescan-scsi-bus.sh b/archive/rescan-scsi-bus.sh index 755bdadb..f40a1f47 100755 --- a/archive/rescan-scsi-bus.sh +++ b/archive/rescan-scsi-bus.sh @@ -1,7 +1,7 @@ #!/bin/bash # Skript to rescan SCSI bus, using the # scsi add-single-device mechanism -# (w) 98/03/19 Kurt Garloff <kurt@garloff.de> (c) GNU GPL +# (w) 98/03/19 Kurt Garloff <kurt at garloff dot de> (c) GNU GPL # Return hosts. /proc/scsi/HOSTADAPTER/? must exist findhosts () diff --git a/archive/scsi_devfs_scan.c b/archive/scsi_devfs_scan.c index 20f273d1..e663f381 100644 --- a/archive/scsi_devfs_scan.c +++ b/archive/scsi_devfs_scan.c @@ -29,7 +29,7 @@ void usage() { printf("Usage: 'scsi_devfs_scan [-d <dir>] [-i] [-ide] [-l [-x]] " - "[-q]'\n"); + "[-q]'\n"); printf(" where: -d <dir> location of devfs [default: /dev ]\n"); printf(" -i show INQUIRY data for each SCSI device\n"); printf(" -ide show scan of IDE devices after SCSI devices\n"); @@ -131,7 +131,7 @@ static int do_inquiry(int sg_fd, void * resp, int mx_resp_len) case SG_ERR_CAT_RECOVERED: return 0; default: - sg_chk_n_print3("Failed INQUIRY", &io_hdr); + sg_chk_n_print3("Failed INQUIRY", &io_hdr); return -1; } } @@ -142,94 +142,94 @@ void leaf_dir(const char * lf, unsigned int * larr) int res; if (do_quiet) { - printf("%u\t%u\t%u\t%u\n", larr[0], larr[1], larr[2], larr[3]); - return; + printf("%u\t%u\t%u\t%u\n", larr[0], larr[1], larr[2], larr[3]); + return; } printf("%u\t%u\t%u\t%u\t%s\n", larr[0], larr[1], larr[2], larr[3], lf); if (do_leaf) { - struct dirent * de_entry; - struct dirent * de_result; - DIR * sdir; - int outpos; + struct dirent * de_entry; + struct dirent * de_result; + DIR * sdir; + int outpos; - if (NULL == (sdir = opendir(lf))) { - fprintf(stderr, "leaf_dir: opendir of %s: failed\n", lf); - return; - } - de_entry = (struct dirent *)malloc(sizeof(struct dirent) + - NAME_LEN_MAX); - if (NULL == de_entry) - return; - res = 0; - printf("\t"); - outpos = 8; - while (1) { - res = readdir_r(sdir, de_entry, &de_result); - if (0 != res) { - fprintf(stderr, "leaf_dir: readdir_r of %s: %s\n", - lf, strerror(res)); - res = -2; - break; - } - if (de_result == NULL) - break; - strncpy(name, de_entry->d_name, NAME_LEN_MAX * 2); - if ((0 == strcmp("..", name)) ||(0 == strcmp(".", name))) - continue; - if (do_extra) { - struct stat st; - char devname[NAME_LEN_MAX * 2]; + if (NULL == (sdir = opendir(lf))) { + fprintf(stderr, "leaf_dir: opendir of %s: failed\n", lf); + return; + } + de_entry = (struct dirent *)malloc(sizeof(struct dirent) + + NAME_LEN_MAX); + if (NULL == de_entry) + return; + res = 0; + printf("\t"); + outpos = 8; + while (1) { + res = readdir_r(sdir, de_entry, &de_result); + if (0 != res) { + fprintf(stderr, "leaf_dir: readdir_r of %s: %s\n", + lf, strerror(res)); + res = -2; + break; + } + if (de_result == NULL) + break; + strncpy(name, de_entry->d_name, NAME_LEN_MAX * 2); + if ((0 == strcmp("..", name)) ||(0 == strcmp(".", name))) + continue; + if (do_extra) { + struct stat st; + char devname[NAME_LEN_MAX * 2]; - strncpy(devname, lf, NAME_LEN_MAX * 2); - strcat(devname, "/"); - strcat(devname, name); - if (stat(devname, &st) < 0) - return; - if (S_ISCHR(st.st_mode)) { - strcat(name, "(c "); - sprintf(name + strlen(name), "%d %d)", major(st.st_rdev), - minor(st.st_rdev)); - } - else if (S_ISBLK(st.st_mode)) { - strcat(name, "(b "); - sprintf(name + strlen(name), "%d %d)", major(st.st_rdev), - minor(st.st_rdev)); - } - } - res = strlen(name); - if ((outpos + res + 2) > 80) { - printf("\n\t"); - outpos = 8; - } - printf("%s ", name); - outpos += res + 2; - } - printf("\n"); + strncpy(devname, lf, NAME_LEN_MAX * 2); + strcat(devname, "/"); + strcat(devname, name); + if (stat(devname, &st) < 0) + return; + if (S_ISCHR(st.st_mode)) { + strcat(name, "(c "); + sprintf(name + strlen(name), "%d %d)", major(st.st_rdev), + minor(st.st_rdev)); + } + else if (S_ISBLK(st.st_mode)) { + strcat(name, "(b "); + sprintf(name + strlen(name), "%d %d)", major(st.st_rdev), + minor(st.st_rdev)); + } + } + res = strlen(name); + if ((outpos + res + 2) > 80) { + printf("\n\t"); + outpos = 8; + } + printf("%s ", name); + outpos += res + 2; + } + printf("\n"); } if (do_inq) { - int sg_fd; - char buff[64]; + int sg_fd; + char buff[64]; - memset(buff, 0, sizeof(buff)); - strncpy(name, lf, NAME_LEN_MAX * 2); - strcat(name, "/generic"); - if ((sg_fd = open(name, O_RDONLY)) < 0) { - if (! checked_sg) { - checked_sg = 1; - if ((sg_fd = open("/dev/sg0", O_RDONLY)) >= 0) - close(sg_fd); /* try and get sg module loaded */ - sg_fd = open(name, O_RDONLY); - } - if (sg_fd < 0) { - printf("Unable to open sg device: %s, %s\n", name, - strerror(errno)); - return; - } - } - if (0 != do_inquiry(sg_fd, buff, 64)) - return; - close(sg_fd); - dStrHex(buff, 64); + memset(buff, 0, sizeof(buff)); + strncpy(name, lf, NAME_LEN_MAX * 2); + strcat(name, "/generic"); + if ((sg_fd = open(name, O_RDONLY)) < 0) { + if (! checked_sg) { + checked_sg = 1; + if ((sg_fd = open("/dev/sg0", O_RDONLY)) >= 0) + close(sg_fd); /* try and get sg module loaded */ + sg_fd = open(name, O_RDONLY); + } + if (sg_fd < 0) { + printf("Unable to open sg device: %s, %s\n", name, + strerror(errno)); + return; + } + } + if (0 != do_inquiry(sg_fd, buff, 64)) + return; + close(sg_fd); + dStrHex(buff, 64); } } @@ -246,37 +246,37 @@ int hbtl_scan(const char * path, int level, unsigned int *larr) level_slen = strlen(level_arr[level]); if (NULL == (sdir = opendir(path))) { - fprintf(stderr, "hbtl_scan: opendir of %s: failed\n", path); - return -1; + fprintf(stderr, "hbtl_scan: opendir of %s: failed\n", path); + return -1; } de_entry = (struct dirent *)malloc(sizeof(struct dirent) + NAME_LEN_MAX); if (NULL == de_entry) - return -3; + return -3; res = 0; while (1) { - res = readdir_r(sdir, de_entry, &de_result); - if (0 != res) { - fprintf(stderr, "hbtl_scan: readdir_r of %s: %s\n", - path, strerror(res)); - res = -2; - break; - } - if (de_result == NULL) - break; - if (0 == strncmp(level_arr[level], de_entry->d_name, level_slen)) { - if (1 != sscanf(de_entry->d_name + level_slen, "%u", larr + level)) - larr[level] = UINT_MAX; - strncpy(new_path, path, NAME_LEN_MAX * 2); - strcat(new_path, "/"); - strcat(new_path, de_entry->d_name); - if ((level + 1) < LEVELS) { - res = hbtl_scan(new_path, level + 1, larr); - if (res < 0) - break; - } - else - leaf_dir(new_path, larr); - } + res = readdir_r(sdir, de_entry, &de_result); + if (0 != res) { + fprintf(stderr, "hbtl_scan: readdir_r of %s: %s\n", + path, strerror(res)); + res = -2; + break; + } + if (de_result == NULL) + break; + if (0 == strncmp(level_arr[level], de_entry->d_name, level_slen)) { + if (1 != sscanf(de_entry->d_name + level_slen, "%u", larr + level)) + larr[level] = UINT_MAX; + strncpy(new_path, path, NAME_LEN_MAX * 2); + strcat(new_path, "/"); + strcat(new_path, de_entry->d_name); + if ((level + 1) < LEVELS) { + res = hbtl_scan(new_path, level + 1, larr); + if (res < 0) + break; + } + else + leaf_dir(new_path, larr); + } } free(de_entry); closedir(sdir); @@ -307,11 +307,11 @@ int main(int argc, char * argv[]) else if (0 == strcmp("-q", argv[k])) do_quiet = 1; else if (0 == strncmp("-d", argv[k], 2)) { - if (strlen(argv[k]) > 2) - strncpy(ds_root, argv[k] + 2, D_ROOT_SZ); - else if (++k < argc) - strncpy(ds_root, argv[k], D_ROOT_SZ); - } + if (strlen(argv[k]) > 2) + strncpy(ds_root, argv[k] + 2, D_ROOT_SZ); + else if (++k < argc) + strncpy(ds_root, argv[k], D_ROOT_SZ); + } else if ((0 == strcmp("-?", argv[k])) || (0 == strncmp("-h", argv[k], 2))) { printf("Scan SCSI devices within a devfs tree\n\n"); @@ -332,23 +332,23 @@ int main(int argc, char * argv[]) strncpy(di_root, ds_root, D_ROOT_SZ); strcat(di_root, "/.devfsd"); if (stat(di_root, &st) < 0) - printf("Didn't find %s so perhaps devfs is not present," - " continuing ...\n", di_root); + printf("Didn't find %s so perhaps devfs is not present," + " continuing ...\n", di_root); strncpy(di_root, ds_root, D_ROOT_SZ); strcat(ds_root, "/scsi"); strcat(di_root, "/ide"); if (do_ide) - printf("SCSI scan:\n"); + printf("SCSI scan:\n"); res = hbtl_scan(ds_root, 0, larr); if (res < 0) - printf("main: scsi hbtl_scan res=%d\n", res); + printf("main: scsi hbtl_scan res=%d\n", res); do_inq = 0; /* won't try SCSI INQUIRY on IDE devices */ if (do_ide) { - printf("\nIDE scan:\n"); - res = hbtl_scan(di_root, 0, larr); - if (res < 0) - printf("main: ide hbtl_scan res=%d\n", res); + printf("\nIDE scan:\n"); + res = hbtl_scan(di_root, 0, larr); + if (res < 0) + printf("main: ide hbtl_scan res=%d\n", res); } return 0; } diff --git a/archive/sg_err.h b/archive/sg_err.h index ef57b5ce..886bac29 100644 --- a/archive/sg_err.h +++ b/archive/sg_err.h @@ -3,7 +3,7 @@ /* Feel free to copy and modify this GPL-ed code into your applications. */ -/* Version 0.90 (20030519) +/* Version 0.93 (20040708) */ @@ -131,6 +131,16 @@ extern int sg_chk_n_print(const char * leadin, int masked_status, struct sg_io_hdr; extern int sg_chk_n_print3(const char * leadin, struct sg_io_hdr * hp); +/* If no sense data returns 0 and places 0 in *response_code (if non-NULL) + and *sense_key (if non-NULL). If sense data found returns 1 and outputs + to *response_code, *sense_key, *asc and *ascq (those that are non-NULL). + Understands both descriptor and fixed sense data format. */ +extern int sg_decode_sense(const struct sg_io_hdr * hp, + unsigned char * response_code, + unsigned char * sense_key, + unsigned char * asc, + unsigned char * ascq); + /* The following "category" function returns one of the following */ #define SG_ERR_CAT_CLEAN 0 /* No errors or other information */ @@ -153,10 +163,21 @@ extern int sg_err_category_new(int scsi_status, int host_status, 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) */ +/* 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); -extern void sg_get_command_name(unsigned char opcode, int buff_len, - char * buff); +/* 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); #endif |