関数 open, ioctl, write および read は
エラーを報告する可能性があります。この場合、関数の返り値は -1 で
大域変数 errno にエラー番号が与えられます。
errno の値は /usr/include/errno.h において定義されています。
以下のような値をとりえます:
関数     | エラー       | 解説
=========|==============|=============================================
open     | ENXIO        | デバイスが無効
         | EACCES       | アクセスモードがread/write(O_RDWR)でない 
         | EBUSY        | デバイスに対しブロックしないアクセスが要求
         |              | されたが、現在はビジー状態。
         | ERESTARTSYS  | これは内部のエラーを示す。再現可能にして
         |              | SCSI チャンネルに報せられたい(バグ報告の詳細
         |              | は Drew Eckhardts による SCSI-HOWTO をみよ)
ioctl    | ENXIO        | デバイスが無効
read     | EAGAIN       | デバイスがブロックしようとする。後で再試行を。
         | ERESTARTSYS  | これが内部のエラーを示す。再現可能にして
         |              | SCSI チャンネルに報せられたい(バグ報告の詳細
         |              | は Drew Eckhardts による SCSI-HOWTO をみよ)
write    | EIO          | 長さが短かすぎ (共通ヘッダ構造体より小さい)。
         |              | 警告: 現在の所、長さ超過の確認はない。
         | EAGAIN       | デバイスがブロックしようとする。後で再試行を。
         | ENOMEM       | この要求に必要なメモリを割当てできなかった。
         |              | 最大伝送サイズを超えていないならば後で再試行
         |              | を(上をみよ)。
select   |              | なし
close    |              | なし
read/write の正の返り値は例によって伝送に成功したバイト数を示してい ます。これは要求したバイト数と等しいべきです。
 
さらにより詳細な報告がカーネルの hd_status と デバイスの
sense_buffer によってなされます(
sec-sensebuff
章をみてく
ださい)。いずれも共通ヘッダ構造体にあります。
hd_status の意味は drivers/scsi/scsi.h で提供されます:
この unsigned int は異なる部分から構成されています。
  lsb  |    ...    |    ...    | msb
=======|===========|===========|============
status | sense key | host code | driver byte
drivers/scsi/scsi.hでこれらのマクロを手に入れることができ
るのですが、不幸にして摩可不思議なヘッダファイルの相互依存のために
簡単には使えません。ここをきれいにしないといけません。
       マクロ          | 解説
=======================|====================================================
status_byte(hd_status) | SCSI 装置の状態。ステータスコードの章をみよ。
msg_byte(hd_status)    | 装置より。SCSI sense keys の章をみよ。
host_byte(hd_status)   | カーネルより。 Hostcodes の章をみよ。
driver_byte(hd_status) | カーネルより。. midlevel codes の章をみよ。
以下のSCSI 装置から返されるステータスコードが(scsi/scsi.hで定
義されています)利用可能です。
 値   | シンボル
======|=====================
0x00  | GOOD
0x01  | CHECK_CONDITION
0x02  | CONDITION_GOOD
0x04  | BUSY
0x08  | INTERMEDIATE_GOOD
0x0a  | INTERMEDIATE_C_GOOD
0x0c  | RESERVATION_CONFLICT
これらのシンボルの値は右に一つシフトされていることに注意して ください。ステータスが CHECK_CONDITION のときならば、センスバッファ 内のセンスデータは有効です(特に追加的なセンスコードと追加的なセンス コードクオリファイアを確認してください)。
これらの値には SCSI-2 仕様書によると次のような意味があります。
                           Table 27: Status Byte Code
+=================================-==============================+
|       Bits of Status Byte       |  Status                      |
|  7   6   5   4   3   2   1   0  |                              |
|---------------------------------+------------------------------|
|  R   R   0   0   0   0   0   R  |  GOOD                        |
|  R   R   0   0   0   0   1   R  |  CHECK CONDITION             |
|  R   R   0   0   0   1   0   R  |  CONDITION MET               |
|  R   R   0   0   1   0   0   R  |  BUSY                        |
|  R   R   0   1   0   0   0   R  |  INTERMEDIATE                |
|  R   R   0   1   0   1   0   R  |  INTERMEDIATE-CONDITION MET  |
|  R   R   0   1   1   0   0   R  |  RESERVATION CONFLICT        |
|  R   R   1   0   0   0   1   R  |  COMMAND TERMINATED          |
|  R   R   1   0   1   0   0   R  |  QUEUE FULL                  |
|                                 |                              |
|       All Other Codes           |  Reserved                    |
|----------------------------------------------------------------|
|  Key: R = Reserved bit                                         |
+================================================================+
GOOD.  この状態はターゲットがコマンドの実行に成功したことを示す。
CHECK CONDITION.  この状態は contingent allegiance condition が発生した
ことを示す。(6.6をみよ)。
CONDITION MET.  この状態もしくは INTERMEDIATE-CONDITION MET は要求した
操作が達成されたときにはいつでも返される。(SEARCH DATA 及び PRE-FETCH
コマンドをみよ)。
BUSY.  この状態はターゲットがビジーであることを示す。この状態はターゲット
がコマンドをその他の受付可能なイニシエータ(すなわち保留できない衝突)からの
コマンドを受け付けることができないときはいつでも返されるであろう。推奨され
るイニシエータの回復動作は後の時点で再びコマンドを発行することである。
INTERMEDIATE. この状態もしくは INTERMEDIATE-CONDITION MET は、コマンドが
CHECK CONDITION, RESERVATION CONFLICT もしくは COMMAND TERMINATED ステータス
によっては終了しなかった場合に、一つながりの連結したコマンド群(最後のコマン
ドを除く)において各コマンドの実行に成功したときに返される。もし INTERMEDIATE
あるいは INTERMEDIATE-CONDITION MET ステータスが返されないならば、その連結し
たコマンド列は終了して入出力操作は終えられている。
INTERMEDIATE-CONDITION MET.  この状態は CONDITON MET と INTERMEDIATE ステータ
スが組合さったものである。
RESERVATION CONFLICT.  この状態はイニシエータが別の SCSI 装置に対して衝突保留
予約型として指定されているロジカルユニットもしくはロジカルユニット内部の程度
[?? extent ??]にアクセスを試みた場合に必ず返される。推奨されるイニシエータの回復
動作は後の時点で再度コマンドを発行することである。
COMMAND TERMINATED.  この状態は TERMINATE I/O PROCESS メッセージ(5.6.22 をみよ)
を受け取ったあとでターゲットが現在の入出力操作を終了させる場合に返される。この
状態はまた contingent allegiance condition が発生したことも示している(6.6 をみよ)。
QUEUE FULL.  この状態はタグ付けされたキュー操作が実装されている場合に実装される
とする。この状態は SIMPLE QUEUE TAG, ORDERED QUEUE TAG もしくは HEAD OF QUEUE TAG
メッセージが受け取られコマンドキューがいっぱいであるときに返される。入出力操作
はコマンドキュー内に配置されない。
 
これらのカーネルシンボル(scsi/scsi.hより)があらかじめ定義
されています。
Value | Symbol
======|================
0x00  | NO_SENSE
0x01  | RECOVERED_ERROR
0x02  | NOT_READY
0x03  | MEDIUM_ERROR
0x04  | HARDWARE_ERROR
0x05  | ILLEGAL_REQUEST
0x06  | UNIT_ATTENTION
0x07  | DATA_PROTECT
0x08  | BLANK_CHECK
0x0a  | COPY_ABORTED
0x0b  | ABORTED_COMMAND
0x0d  | VOLUME_OVERFLOW
0x0e  | MISCOMPARE
SCSI-2 文書にあるリストそのままは以下の通りです(7.2.14.3 章より)。
                    Table 69: Sense Key (0h-7h) Descriptions
+========-====================================================================+
| Sense  |  Description                                                       |
|  Key   |                                                                    |
|--------+--------------------------------------------------------------------|
|   0h   |  NO SENSE.  Indicates that there is no specific sense key          |
|        |  information to be reported for the designated logical unit.  This |
|        |  would be the case for a successful command or a command that      |
|        |  received CHECK CONDITION or COMMAND TERMINATED status because one |
|        |  of the filemark, EOM, or ILI bits is set to one.                  |
|--------+--------------------------------------------------------------------|
|   1h   |  RECOVERED ERROR.  Indicates that the last command completed       |
|        |  successfully with some recovery action performed by the target.   |
|        |  Details may be determinable by examining the additional sense     |
|        |  bytes and the information field.  When multiple recovered errors  |
|        |  occur during one command, the choice of which error to report     |
|        |  (first, last, most severe, etc.) is device specific.              |
|--------+--------------------------------------------------------------------|
|   2h   |  NOT READY.  Indicates that the logical unit addressed cannot be   |
|        |  accessed.  Operator intervention may be required to correct this  |
|        |  condition.                                                        |
|--------+--------------------------------------------------------------------|
|   3h   |  MEDIUM ERROR.  Indicates that the command terminated with a non-  |
|        |  recovered error condition that was probably caused by a flaw in   |
|        |  the medium or an error in the recorded data.  This sense key may  |
|        |  also be returned if the target is unable to distinguish between a |
|        |  flaw in the medium and a specific hardware failure (sense key 4h).|
|--------+--------------------------------------------------------------------|
|   4h   |  HARDWARE ERROR.  Indicates that the target detected a non-        |
|        |  recoverable hardware failure (for example, controller failure,    |
|        |  device failure, parity error, etc.) while performing the command  |
|        |  or during a self test.                                            |
|--------+--------------------------------------------------------------------|
|   5h   |  ILLEGAL REQUEST.  Indicates that there was an illegal parameter in|
|        |  the command descriptor block or in the additional parameters      |
|        |  supplied as data for some commands (FORMAT UNIT, SEARCH DATA,     |
|        |  etc.).  If the target detects an invalid parameter in the command |
|        |  descriptor block, then it shall terminate the command without     |
|        |  altering the medium.  If the target detects an invalid parameter  |
|        |  in the additional parameters supplied as data, then the target may|
|        |  have already altered the medium.  This sense key may also indicate|
|        |  that an invalid IDENTIFY message was received (5.6.7).            |
|--------+--------------------------------------------------------------------|
|   6h   |  UNIT ATTENTION.  Indicates that the removable medium may have been|
|        |  changed or the target has been reset.  See 6.9 for more detailed  |
|        |  information about the unit attention condition.                   |
|--------+--------------------------------------------------------------------|
|   7h   |  DATA PROTECT.  Indicates that a command that reads or writes the  |
|        |  medium was attempted on a block that is protected from this       |
|        |  operation.  The read or write operation is not performed.         |
+=============================================================================+
                    Table 70: Sense Key (8h-Fh) Descriptions
+========-====================================================================+
| Sense  |  Description                                                       |
|  Key   |                                                                    |
|--------+--------------------------------------------------------------------|
|   8h   |  BLANK CHECK.  Indicates that a write-once device or a sequential- |
|        |  access device encountered blank medium or format-defined end-of-  |
|        |  data indication while reading or a write-once device encountered a|
|        |  non-blank medium while writing.                                   |
|--------+--------------------------------------------------------------------|
|   9h   |  Vendor Specific.  This sense key is available for reporting vendor|
|        |  specific conditions.                                              |
|--------+--------------------------------------------------------------------|
|   Ah   |  COPY ABORTED.  Indicates a COPY, COMPARE, or COPY AND VERIFY      |
|        |  command was aborted due to an error condition on the source       |
|        |  device, the destination device, or both.  (See 7.2.3.2 for        |
|        |  additional information about this sense key.)                     |
|--------+--------------------------------------------------------------------|
|   Bh   |  ABORTED COMMAND.  Indicates that the target aborted the command.  |
|        |  The initiator may be able to recover by trying the command again. |
|--------+--------------------------------------------------------------------|
|   Ch   |  EQUAL.  Indicates a SEARCH DATA command has satisfied an equal    |
|        |  comparison.                                                       |
|--------+--------------------------------------------------------------------|
|   Dh   |  VOLUME OVERFLOW.  Indicates that a buffered peripheral device has |
|        |  reached the end-of-partition and data may remain in the buffer    |
|        |  that has not been written to the medium.  A RECOVER BUFFERED DATA |
|        |  command(s) may be issued to read the unwritten data from the      |
|        |  buffer.                                                           |
|--------+--------------------------------------------------------------------|
|   Eh   |  MISCOMPARE.  Indicates that the source data did not match the data|
|        |  read from the medium.                                             |
|--------+--------------------------------------------------------------------|
|   Fh   |  RESERVED.                                                         |
+=============================================================================+
 
以下の host code は drivers/scsi/scsi.h において定義されています。
これらはカーネルドライバによりセットされます。
Value | Symbol         | Description
======|================|========================================
0x00  | DID_OK         | No error
0x01  | DID_NO_CONNECT | Couldn't connect before timeout period
0x02  | DID_BUS_BUSY   | BUS stayed busy through time out period
0x03  | DID_TIME_OUT   | TIMED OUT for other reason
0x04  | DID_BAD_TARGET | BAD target
0x05  | DID_ABORT      | Told to abort for some other reason
0x06  | DID_PARITY     | Parity error
0x07  | DID_ERROR      | internal error
0x08  | DID_RESET      | Reset by somebody
0x09  | DID_BAD_INTR   | Got an interrupt we weren't expecting
中間層のドライバは装置からのセンスキーに基づいて低水準ドライバから 返された状態を類別します。さらに再試行、中止あるいは再マップといった とるべきいくつかの動作を示唆します。
Value | Symbol         | Description of Driver status
======|================|========================================
0x00  | DRIVER_OK      | No error
0x01  | DRIVER_BUSY    | not used
0x02  | DRIVER_SOFT    | not used
0x03  | DRIVER_MEDIA   | not used
0x04  | DRIVER_ERROR   | internal driver error
0x05  | DRIVER_INVALID | finished (DID_BAD_TARGET or DID_ABORT)
0x06  | DRIVER_TIMEOUT | finished with timeout
0x07  | DRIVER_HARD    | finished with fatal error
0x08  | DRIVER_SENSE   | had sense information available
Value | Symbol         | Description of suggestion
======|================|========================================
0x10  | SUGGEST_RETRY  | retry the SCSI request
0x20  | SUGGEST_ABORT  | abort the request
0x30  | SUGGEST_REMAP  | remap the block (not yet implemented)
0x40  | SUGGEST_DIE    | let the kernel panic
0x80  | SUGGEST_SENSE  | get sense information from the device
0xff  | SUGGEST_IS_OK  | nothing to be done