~ubuntu-branches/ubuntu/intrepid/sg3-utils/intrepid

« back to all changes in this revision

Viewing changes to examples/sg_err.h

  • Committer: Bazaar Package Importer
  • Author(s): Luk Claes
  • Date: 2006-11-05 17:23:29 UTC
  • mfrom: (1.1.4 upstream) (3.1.2 edgy)
  • Revision ID: james.westby@ubuntu.com-20061105172329-l4loha00sk36qz6k
* Non-maintainer upload.
* Fix FTBFS due to old syscall usage (Closes: #395512).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef SG_ERR_H
2
 
#define SG_ERR_H
3
 
 
4
 
/* Feel free to copy and modify this GPL-ed code into your applications. */
5
 
 
6
 
/* Version 0.97 (20040830) 
7
 
*/
8
 
 
9
 
 
10
 
/* Some of the following error/status codes are exchanged between the
11
 
   various layers of the SCSI sub-system in Linux and should never
12
 
   reach the user. They are placed here for completeness. What appears
13
 
   here is copied from drivers/scsi/scsi.h which is not visible in
14
 
   the user space. */
15
 
 
16
 
#ifndef SCSI_CHECK_CONDITION
17
 
/* Following are the "true" SCSI status codes. Linux has traditionally
18
 
   used a 1 bit right and masked version of these. So now CHECK_CONDITION
19
 
   and friends (in <scsi/scsi.h>) are deprecated. */
20
 
#define SCSI_CHECK_CONDITION 0x2
21
 
#define SCSI_CONDITION_MET 0x4
22
 
#define SCSI_BUSY 0x8
23
 
#define SCSI_IMMEDIATE 0x10
24
 
#define SCSI_IMMEDIATE_CONDITION_MET 0x14
25
 
#define SCSI_RESERVATION_CONFLICT 0x18
26
 
#define SCSI_COMMAND_TERMINATED 0x22
27
 
#define SCSI_TASK_SET_FULL 0x28
28
 
#define SCSI_ACA_ACTIVE 0x30
29
 
#define SCSI_TASK_ABORTED 0x40
30
 
#endif
31
 
 
32
 
/* The following are 'host_status' codes */
33
 
#ifndef DID_OK
34
 
#define DID_OK 0x00
35
 
#endif
36
 
#ifndef DID_NO_CONNECT
37
 
#define DID_NO_CONNECT 0x01     /* Unable to connect before timeout */
38
 
#define DID_BUS_BUSY 0x02       /* Bus remain busy until timeout */
39
 
#define DID_TIME_OUT 0x03       /* Timed out for some other reason */
40
 
#define DID_BAD_TARGET 0x04     /* Bad target (id?) */
41
 
#define DID_ABORT 0x05          /* Told to abort for some other reason */
42
 
#define DID_PARITY 0x06         /* Parity error (on SCSI bus) */
43
 
#define DID_ERROR 0x07          /* Internal error */
44
 
#define DID_RESET 0x08          /* Reset by somebody */
45
 
#define DID_BAD_INTR 0x09       /* Received an unexpected interrupt */
46
 
#define DID_PASSTHROUGH 0x0a    /* Force command past mid-level */
47
 
#define DID_SOFT_ERROR 0x0b     /* The low-level driver wants a retry */
48
 
#endif
49
 
 
50
 
/* These defines are to isolate applictaions from kernel define changes */
51
 
#define SG_ERR_DID_OK           DID_OK
52
 
#define SG_ERR_DID_NO_CONNECT   DID_NO_CONNECT
53
 
#define SG_ERR_DID_BUS_BUSY     DID_BUS_BUSY
54
 
#define SG_ERR_DID_TIME_OUT     DID_TIME_OUT
55
 
#define SG_ERR_DID_BAD_TARGET   DID_BAD_TARGET
56
 
#define SG_ERR_DID_ABORT        DID_ABORT
57
 
#define SG_ERR_DID_PARITY       DID_PARITY
58
 
#define SG_ERR_DID_ERROR        DID_ERROR
59
 
#define SG_ERR_DID_RESET        DID_RESET
60
 
#define SG_ERR_DID_BAD_INTR     DID_BAD_INTR
61
 
#define SG_ERR_DID_PASSTHROUGH  DID_PASSTHROUGH
62
 
#define SG_ERR_DID_SOFT_ERROR   DID_SOFT_ERROR
63
 
 
64
 
/* The following are 'driver_status' codes */
65
 
#ifndef DRIVER_OK
66
 
#define DRIVER_OK 0x00
67
 
#endif
68
 
#ifndef DRIVER_BUSY
69
 
#define DRIVER_BUSY 0x01
70
 
#define DRIVER_SOFT 0x02
71
 
#define DRIVER_MEDIA 0x03
72
 
#define DRIVER_ERROR 0x04
73
 
#define DRIVER_INVALID 0x05
74
 
#define DRIVER_TIMEOUT 0x06
75
 
#define DRIVER_HARD 0x07
76
 
#define DRIVER_SENSE 0x08       /* Sense_buffer has been set */
77
 
 
78
 
/* Following "suggests" are "or-ed" with one of previous 8 entries */
79
 
#define SUGGEST_RETRY 0x10
80
 
#define SUGGEST_ABORT 0x20
81
 
#define SUGGEST_REMAP 0x30
82
 
#define SUGGEST_DIE 0x40
83
 
#define SUGGEST_SENSE 0x80
84
 
#define SUGGEST_IS_OK 0xff
85
 
#endif
86
 
#ifndef DRIVER_MASK
87
 
#define DRIVER_MASK 0x0f
88
 
#endif
89
 
#ifndef SUGGEST_MASK
90
 
#define SUGGEST_MASK 0xf0
91
 
#endif
92
 
 
93
 
/* These defines are to isolate applictaions from kernel define changes */
94
 
#define SG_ERR_DRIVER_OK        DRIVER_OK
95
 
#define SG_ERR_DRIVER_BUSY      DRIVER_BUSY
96
 
#define SG_ERR_DRIVER_SOFT      DRIVER_SOFT
97
 
#define SG_ERR_DRIVER_MEDIA     DRIVER_MEDIA
98
 
#define SG_ERR_DRIVER_ERROR     DRIVER_ERROR
99
 
#define SG_ERR_DRIVER_INVALID   DRIVER_INVALID
100
 
#define SG_ERR_DRIVER_TIMEOUT   DRIVER_TIMEOUT
101
 
#define SG_ERR_DRIVER_HARD      DRIVER_HARD
102
 
#define SG_ERR_DRIVER_SENSE     DRIVER_SENSE
103
 
#define SG_ERR_SUGGEST_RETRY    SUGGEST_RETRY
104
 
#define SG_ERR_SUGGEST_ABORT    SUGGEST_ABORT
105
 
#define SG_ERR_SUGGEST_REMAP    SUGGEST_REMAP
106
 
#define SG_ERR_SUGGEST_DIE      SUGGEST_DIE
107
 
#define SG_ERR_SUGGEST_SENSE    SUGGEST_SENSE
108
 
#define SG_ERR_SUGGEST_IS_OK    SUGGEST_IS_OK
109
 
#define SG_ERR_DRIVER_MASK      DRIVER_MASK
110
 
#define SG_ERR_SUGGEST_MASK     SUGGEST_MASK
111
 
 
112
 
 
113
 
 
114
 
/* The following "print" functions send ACSII to stdout */
115
 
extern void sg_print_command(const unsigned char * command);
116
 
extern void sg_print_sense(const char * leadin,
117
 
                           const unsigned char * sense_buffer, int sb_len);
118
 
extern void sg_print_status(int masked_status);
119
 
extern void sg_print_scsi_status(int scsi_status);
120
 
extern void sg_print_host_status(int host_status);
121
 
extern void sg_print_driver_status(int driver_status);
122
 
 
123
 
/* sg_chk_n_print() returns 1 quietly if there are no errors/warnings
124
 
   else it prints to standard output and returns 0. */
125
 
extern int sg_chk_n_print(const char * leadin, int masked_status,
126
 
                          int host_status, int driver_status,
127
 
                          const unsigned char * sense_buffer, int sb_len);
128
 
 
129
 
/* This is a slightly stretched SCSI sense "descriptor" format header.
130
 
   The addition is to allow the 0x70 and 0x71 response codes. The idea
131
 
   is to place the salient data of both "fixed" and "descriptor" sense
132
 
   format into one structure to ease application processing.
133
 
   The original sense buffer should be kept around for those cases
134
 
   in which more information is required (e.g. the LBA of a MEDIUM ERROR). */
135
 
struct sg_scsi_sense_hdr {
136
 
    unsigned char response_code; /* permit: 0x0, 0x70, 0x71, 0x72, 0x73 */
137
 
    unsigned char sense_key;
138
 
    unsigned char asc;
139
 
    unsigned char ascq;
140
 
    unsigned char byte4;
141
 
    unsigned char byte5;
142
 
    unsigned char byte6;
143
 
    unsigned char additional_length;
144
 
};
145
 
 
146
 
/* Maps the salient data from a sense buffer which is in either fixed or
147
 
   descriptor format into a structure mimicking a descriptor format
148
 
   header (i.e. the first 8 bytes).
149
 
   If zero response code returns 0. Otherwise returns 1 and if 'sshp' is
150
 
   non-NULL then zero all fields and then set the appropriate fields in
151
 
   that structure. sshp::additional_length is always 0 for response
152
 
   codes 0x70 and 0x71 (fixed format). */
153
 
extern int sg_scsi_normalize_sense(const unsigned char * sensep, 
154
 
                                   int sense_len,
155
 
                                   struct sg_scsi_sense_hdr * sshp);
156
 
 
157
 
/* Attempt to find the first SCSI sense data descriptor that matches the
158
 
   given 'desc_type'. If found return pointer to start of sense data
159
 
   descriptor; otherwise (including fixed format sense data) returns NULL. */
160
 
extern const unsigned char * sg_scsi_sense_desc_find(
161
 
                const unsigned char * sensep, int sense_len, int desc_type);
162
 
 
163
 
/* The following function declaration is for the sg version 3 driver. 
164
 
   Only version 3 sg_err.c defines it. */
165
 
struct sg_io_hdr;
166
 
extern int sg_chk_n_print3(const char * leadin, struct sg_io_hdr * hp);
167
 
 
168
 
/* Calls sg_scsi_normalize_sense() after obtaining the sense buffer and
169
 
   its length from the struct sg_io_hdr pointer. If these cannot be
170
 
   obtained, 0 is returned. */
171
 
extern int sg_normalize_sense(const struct sg_io_hdr * hp, 
172
 
                              struct sg_scsi_sense_hdr * sshp);
173
 
 
174
 
 
175
 
/* The following "category" function returns one of the following */
176
 
#define SG_ERR_CAT_CLEAN 0      /* No errors or other information */
177
 
#define SG_ERR_CAT_MEDIA_CHANGED 1 /* interpreted from sense buffer */
178
 
#define SG_ERR_CAT_RESET 2      /* interpreted from sense buffer */
179
 
#define SG_ERR_CAT_TIMEOUT 3
180
 
#define SG_ERR_CAT_RECOVERED 4  /* Successful command after recovered err */
181
 
#define SG_ERR_CAT_SENSE 98     /* Something else is in the sense buffer */
182
 
#define SG_ERR_CAT_OTHER 99     /* Some other error/warning has occurred */
183
 
 
184
 
extern int sg_err_category(int masked_status, int host_status,
185
 
               int driver_status, const unsigned char * sense_buffer,
186
 
               int sb_len);
187
 
 
188
 
extern int sg_err_category_new(int scsi_status, int host_status,
189
 
               int driver_status, const unsigned char * sense_buffer,
190
 
               int sb_len);
191
 
 
192
 
/* The following function declaration is for the sg version 3 driver. 
193
 
   Only version 3 sg_err.c defines it. */
194
 
extern int sg_err_category3(struct sg_io_hdr * hp);
195
 
 
196
 
/* Returns length of SCSI command given the opcode (first byte). 
197
 
   Yields the wrong answer for variable length commands (opcode=0x7f)
198
 
   and potentially some vendor specific commands. */
199
 
extern int sg_get_command_size(unsigned char opcode);
200
 
 
201
 
/* Command name given pointer to command bytes. Certain command names
202
 
   depend on the service action within the command as well. */
203
 
extern void sg_get_command_name(const unsigned char * cmdp, int peri_type,
204
 
                                int buff_len, char * buff);
205
 
 
206
 
/* Opcode name given only the first byte (byte 0) of a command */
207
 
extern void sg_get_opcode_name(unsigned char cmd_byte0, int peri_type,
208
 
                               int buff_len, char * buff);
209
 
 
210
 
/* Command name given opcode (byte 0) and service action of a command */
211
 
extern void sg_get_opcode_sa_name(unsigned char cmd_byte0, int service_action,
212
 
                                  int peri_type, int buff_len, char * buff);
213
 
 
214
 
 
215
 
/* <<< General purpose (i.e. not SCSI specific) utility functions >>> */
216
 
 
217
 
/* Always returns valid string even if errnum is wild (or library problem) */
218
 
extern char * safe_strerror(int errnum);
219
 
 
220
 
 
221
 
/* Print (to stdout) 'str' of bytes in hex, 16 bytes per line optionally
222
 
   followed at the right hand side of the line with an ASCII interpretation.
223
 
   Each line is prefixed with an address, starting at 0 for str[0]..str[15].
224
 
   All output numbers are in hex. */
225
 
extern void dStrHex(const char* str, int len, int no_ascii);
226
 
 
227
 
#endif