diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2007-06-27 02:59:37 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2007-06-27 02:59:37 +0000 |
commit | 666c11696c2674af4e765ba20e33d04bf01a1770 (patch) | |
tree | 6d08590913d6a23546b42489cf236379bbc445de /archive | |
parent | 0e9184cde6f3d1a0046c706051a4bd4b36a6aede (diff) | |
download | sg3_utils-666c11696c2674af4e765ba20e33d04bf01a1770.tar.gz |
Load sg3_utils-1.08 into trunk/.
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@41 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'archive')
-rw-r--r-- | archive/Makefile | 2 | ||||
-rw-r--r-- | archive/scsi_devfs_scan.c | 8 | ||||
-rw-r--r-- | archive/sg_err.h | 64 | ||||
-rw-r--r-- | archive/sg_include.h | 16 |
4 files changed, 76 insertions, 14 deletions
diff --git a/archive/Makefile b/archive/Makefile index e69fd42c..a4bd5226 100644 --- a/archive/Makefile +++ b/archive/Makefile @@ -14,7 +14,7 @@ MAN_PGS = isosize.8 MAN_PREF = man8 CFLAGS = -g -O2 -W -Wall -D_REENTRANT -# CFLAGS = -g -O2 -Wall -pedantic -D_REENTRANT +# CFLAGS = -g -O2 -Wall -pedantic -std=c99 -D_REENTRANT LDFLAGS = diff --git a/archive/scsi_devfs_scan.c b/archive/scsi_devfs_scan.c index e663f381..24c99384 100644 --- a/archive/scsi_devfs_scan.c +++ b/archive/scsi_devfs_scan.c @@ -1,9 +1,13 @@ +#define _XOPEN_SOURCE 500 +#define _GNU_SOURCE + #include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <fcntl.h> #include <sys/types.h> +#include <sys/sysmacros.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <dirent.h> @@ -55,7 +59,7 @@ static int do_extra = 0; static int do_quiet = 0; static int checked_sg = 0; -static void dStrHex(const char* str, int len) +static void ddStrHex(const char* str, int len) { const char* p = str; unsigned char c; @@ -229,7 +233,7 @@ void leaf_dir(const char * lf, unsigned int * larr) if (0 != do_inquiry(sg_fd, buff, 64)) return; close(sg_fd); - dStrHex(buff, 64); + ddStrHex(buff, 64); } } diff --git a/archive/sg_err.h b/archive/sg_err.h index 886bac29..2cfabb70 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.93 (20040708) +/* Version 0.97 (20040830) */ @@ -126,20 +126,50 @@ 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); -/* 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); +/* 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 */ @@ -180,4 +210,18 @@ extern void sg_get_opcode_name(unsigned char cmd_byte0, int peri_type, /* 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_include.h b/archive/sg_include.h index 5baca3cc..b7310ec0 100644 --- a/archive/sg_include.h +++ b/archive/sg_include.h @@ -1,4 +1,9 @@ +#ifndef SG_INCLUDES_H +#define SG_INCLUDES_H + #ifdef SG_KERNEL_INCLUDES + #define __user + typedef unsigned char u8; #include "/usr/src/linux/include/scsi/sg.h" #include "/usr/src/linux/include/scsi/scsi.h" #else @@ -11,6 +16,13 @@ #endif #endif +#ifdef BLKGETSIZE64 + #ifndef u64 + #include <stdint.h> /* C99 header for exact integer types */ + typedef uint64_t u64; /* problems with BLKGETSIZE64 ioctl in lk 2.4 */ + #endif +#endif + /* Getting the correct include files for the sg interface can be an ordeal. In a perfect world, one would just write: @@ -38,5 +50,7 @@ Sorry about the inconvenience. Typically neither SG_KERNEL_INCLUDES nor SG_TRICK_GNU_INCLUDES is defined. - dpg 20010415 + dpg 20010415, 20030522 */ + +#endif |