stのヘルプ・マニュアル
日本語 英語
st --help
man st
ST(4) Linux Programmer’s Manual ST(4)
名前
st - SCSI テープデバイス
書式
#include
int ioctl(int fd, int request [, (void *)arg3]);
int ioctl(int fd, MTIOCTOP, (struct mtop *)mt_cmd);
int ioctl(int fd, MTIOCGET, (struct mtget *)mt_status);
int ioctl(int fd, MTIOCPOS, (struct mtpos *)mt_pos);
説明
st ドライバーは様々な SCSI テープデバイスのインターフェイスを提供する。
現在では、ドライバーは検出された全ての “シーケンシャルアクセス (sequen-
tial-access) ” タイプのデバイスへの制御を行う。 st ドライバーはメジャー
デバイス番号 9 を用いる。
それぞれのデバイスは 8 つのマイナーデバイス番号を使う。マイナー番号の低
位 側の 5 ビットは、検出された順に割り当てられる。カーネル 2.6 では、低
位側 8 ビットよりも上位にあるビット群がこの 5 ビットに 連 結 (concate-
nate) され、テーブ番号となる。マイナー番号は、それぞれ 4 つの数字からな
る二つのセットにグループ分けされる。基本 (自動巻き戻し) デバイス番号 n
、 および “非巻き戻し (no-rewind) ” デバイス番号 (n + 128). である。基
本デバイス番号を用いてオープンされたデバイスには、クロー ズ す る 時 に
REWIND コマンドが送られる。 “非巻き戻し” デバイス番号を用いてオープンさ
れた場合は REWIND コマンドは送られない (自動巻き戻しデバイスをテープ の
位 置 決めに (例えば mt で) 用いても、望む結果は得られない。テープは mt
コマンドの後で巻き戻され、次のコマンドはテープの先頭から始まってしまう)
。
そ れぞれのグループで、異なった特性 (ブロックサイズ・圧縮・密度など) の
デバイスを定義するために 4 つのマイナー番号が利用できる。システムが起動
したときには、最初のデバイスだけが使える。他の 3 つはデフォルトの特性が
定義されて初めて使えるようになる (後述)。 (コンパイル時の定数を変更する
こ とによって、テープドライブの最大数と、それぞれのドライブに割り当てら
れるマイナー番号の個数とを調整できる。デフォルトの割り当てでは 32 台 ま
で のテープドライブを制御できる。例えば 64 台までのテープドライブを、異
なったオプションを持つ二つのマイナー番号で制御するようにもできる。)
デバイスは普通次のように作られる:
mknod -m 666 /dev/st0 c 9 0
mknod -m 666 /dev/st0l c 9 32
mknod -m 666 /dev/st0m c 9 64
mknod -m 666 /dev/st0a c 9 96
mknod -m 666 /dev/nst0 c 9 128
mknod -m 666 /dev/nst0l c 9 160
mknod -m 666 /dev/nst0m c 9 192
mknod -m 666 /dev/nst0a c 9 224
これらには対応するブロックデバイスは存在しない。
ドライバは内部バッファを使い、その大きさは少なくともテープの 1 ブロック
を保持できるように取られる。 2.1.121 以前のカーネルでは、バッファは連続
する一つのブロックとして割り当てられる。この方法だと、ブロックサイズ の
最 大値はカーネルの割り当て可能な連続メモリブロックに制限される。この制
限は 32 ビットアーキテクチャでは 128 kB、 64 ビットアーキテクチャ で は
256 kB である。これ以降のカーネルでは、ドライバは必要に応じていくつかに
わかれたバッファを割り当てる。デフォルトでは 16 個までの部分に分割で き
る 。すなわちブロックサイズの最大値は非常に大きい (128 kB のブロック 16
個の割り当てに成功すれば 2 MB となる)。
ドライバの内部バッファのサイズはコンパイル時の定数で定義される。これ は
カ ーネルの起動時オプションによって上書き可能である。さらにドライバは実
行時にも、必要に応じてより大きな一時バッファを割り当てようとする。し か
し 実行時に大きな連続メモリブロックを割り当てようとすると失敗することが
あるので、 2.1.121 以前のカーネルでは、動的なバッファ割り当てはあまりあ
てにしないほうが良い (これは kerneld や kmod によるドライバのデマンドロ
ードに関しても当てはまる)。
ドライバはドライブのメーカやモデルを特定してサポートするわけではない 。
シ ステムが起動すると、テープデバイスのオプションがドライブのファームウ
ェアによって定義される。例えば、ドライブのファームウェアが固定長ブロ ッ
ク モードを選択すれば、テープデバイスは固定長ブロックモードを使うことに
なる。このオプションは ioctl(2) コールを明示的に使えば変更でき、その 変
更 はデバイスがクローズされて再びオープンされたときも残る。オプションの
設定は、自動巻き戻しデバイスと非巻き戻しデバイスの両方に影響する。
4 つのサブグループそれぞれのデバイスに対して異なるオプションを与える こ
と ができる。オプションはデバイスがオープンされたときに効力を発揮する。
例えば、システム管理者はあるデバイスを適当なブロックサイズの固定長ブ ロ
ッ クモードで書き込むように定義し、別のデバイスを可変長ブロックモードで
書き込むようにできる (ドライブが両方のモードをサポートしていれば)。
このドライバは、 テープのパーティションをサポートしている (ドライブがサ
ポートしている場合)。 (テープのパーティションはディスクパーティションと
はなんの関係もない。パーティション化されたテープは、一つのメディアに 複
数 の論理テープが存在するかのように見える。) パーティションのサポートは
ioctl(2) によって有効にできる。パーティションが変更されると、テープの位
置 は そ れぞれのパーティション内部で保存される。パーティションの選択は
ioctl(2) で行う。それ以降のテープ操作の対象は、そのパーティションになる
。 パーティションの切り替えは、次のテープ操作と同時に行われ、不必要なテ
ープ移動をしなくてすむようになっている。一つのテープにおけるパーティ シ
ョンの最大数はコンパイル時の定数によって定義される (通常は 4)。ドライバ
には、テープの 1 つまたは 2 つのパーティションをフォーマットできるよ う
な ioctl(2) が用意されている。
通 常、システムのデフォルトのテープデバイスに対するハードリンクまたはソ
フトリンクとして、デバイス /dev/tape が作成される。
カーネル 2.6.2 以降では、この ド ラ イ バ は sysfs デ ィ レ ク ト リ
/sys/class/scsi_tape に、アタッチしたデバイスとそのデバイスに割当てたパ
ラメータをエクスポートする。
データ転送
このドライバは固定長ブロックモードと可変長ブロックモードの両方をサポ ー
トしている (ドライブがサポートしていれば)。固定長ブロックモードでは、ド
ライブは決まったサイズのブロックを (複数個) 書き込む。このブロックサ イ
ズは write システムコールのバイト数によらない。可変長ブロックモードでは
、 write コールごとに一つのテープブロックに書き込みが行われる。したがっ
て バイト数が対応するテープブロックのサイズを決める。テープ上のブロック
には、書き込みモードの情報は一切含まれない。読み込みのときに重要なこ と
は 、テープのブロックサイズを受け入れるコマンドを使うかどうかだけである
。
可変長ブロックモードでは、読み込みバイト数はテープのブロックサイズと 必
ず しも一致していなくても良い。バイト数がテープの次のブロックよりも大き
ければ、ドライバはそのデータを返し、関数は実際のブロックサイズを返す 。
ブ ロックサイズがバイト数よりも大きければ、要求された分のデータがブロッ
クの先頭から読み込まれて返され、ブロックの残りは破棄される。
固定長ブロックモードでは、バッファリングが有効になっていれば読み込み バ
イ ト数は任意の大きさでよい。バッファリングが無効の場合は、テープのブロ
ックサイズの整数倍でなければならない。 2.1.121 以前のカーネルでは、バッ
フ ァリングが有効な場合には任意のバイト数の書き込みができる。その他の場
合すべて (2.1.121 以前のカーネルでバッファが無効な場合と、新しいカー ネ
ル の場合) では、書き込みバイト数はテープブロックサイズの整数倍でなけれ
ばならない。
2.6 カーネルでは、このドライバはユーザバッファとデバイス間で、データ の
直接転送 (direct transfer) を試みる。これが不可能な場合は、ドライバの内
部バッファを用いる。直接転送ができない理由としては、ユーザバッファの ア
ラ インメントが適切でない (デフォルトは 512 バイトだが HBA ドライバによ
って変更されている可能性がある)、ユーザバッファのページのどれかが SCSI
アダプタから見えない、などが考えられる。
テ ープをクローズする直前のテープ操作命令が書き込みであれば、ファイルマ
ークが自動的にテープへ書き込まれる。
読み込み時にファイルマークに出会うと、以下が実行される。ファイルマー ク
が 見付かったときにバッファにデータが残っていると、バッファのデータが返
される。次の読み込み操作は 0 バイトを返す。その次の読み込みは次のファイ
ルからのデータを返す。記録データの末尾は、読み込み操作が二回続けて 0 バ
イトを返して来るかたちで通知される。三回目の読み込みはエラーを返す。
ioctl
ドライバは 3 つの ioctl(2) 要求をサポートしている。 st ドライバによって
認 識 さ れ な か っ た 要 求は SCSI ドライバにわたされる。以下の定義は
/usr/include/linux/mtio.h による。
MTIOCTOP — テープ操作の実行
この要求は (struct mtop *) 型の引数をとる。全てのドライブが全ての操作を
サ ポ ー トしているわけではない。ドライブが操作を拒否すると、ドライバは
EIO エラーを返す。
/* Structure for MTIOCTOP - mag tape op command: */
struct mtop {
short mt_op; /* operations defined below */
int mt_count; /* how many of them */
};
通常のテープ利用のための磁気テープ操作:
MTBSF mt_count 個のファイルマーク (filemark) 分の後方スペ ー ス
(backward space)。
MTBSFM mt_count 個のファイルマーク分の後方スペース。テープの位置
を最後のファイルマークの EOT 側に変更する。
MTBSR mt_count 個のレコード (テープブロック) 分の後方スペース。
MTBSS mt_count 個のセットマーク分の後方スペース。
MTCOMPRESSION mt_count が 0 以外なら、ドライブのデータ圧縮を有効にする
。 0 なら圧縮を無効にする。このコマンドは MODE ページ 15
を用いる。これはほとんどの DAT でサポートされている。
MTEOM (ファイルを追加するために) メディアの記録部分の最後まで進
める。
MTERASE テープの内容を消去する。 2.6 カーネルでは、引数が 0 な ら
ば short erase (テープが空だと印をつける) を行う。それ以
外の場合は long erase (全体を消去する) を行う。
MTFSF mt_count 個のファイルマーク分の前方 ス ペ ー ス (forward
space)。
MTFSFM mt_count 個のファイルマーク分の前方スペース。テープの位置
は最後のファイルマークの BOT 側変更される。
MTFSR mt_count 個のレコード (テープブロック) 分の前方スペース。
MTFSS mt_count 個のセットマーク分の前方スペース。
MTLOAD SCSI ロードコマンドを実行する。 HP オートローダに限って利
用できる。 mt_count が定数 MT_ST_HPLOADER_OFFSET とある数
値 の和である場合、その数値がドライブに送られ、オートロー
ダの制御に用いられる。
MTLOCK テープドライブの扉をロックする。
MTMKPART テープを 1 または 2 パーティションにフォーマット す る 。
mt_count が 0 でなければ、これが最初のパーティションのサ
イズを与え、二番目のパーティションがテープの残りになる 。
mt_count が 0 の場合は、テープは一つのパーティションとし
てフォーマットされる。このコマンドは、パーティションの サ
ポ ー ト が有効にされたドライブでなければ使えない (以下の
MT_ST_CAN_PARTITIONS を見よ)。
MTNOP 何も操作を行わない。- 副次的な効果として、ドライバーの バ
ッ ファをフラッシュする。 MTIOCGET を使って状態を読み出す
前にはこの操作を行うべきである。
MTOFFL 巻き戻し (rewind) を行い、ドライブをオフライン (off line)
にする。
MTRESET ドライブをリセットする。
MTRETEN テープをリテンション (re-tension) する (テープを最後まで
巻いた後、最初まで巻き戻す)。
MTREW 巻き戻し。
MTSEEK mt_count で指定されたテープブロック番号をシークする。この
操 作が行えるのは、 LOCATE コマンド (デバイス固有のアドレ
ス) をサポートする SCSI-2 ドライブか、あるい は Tandberg
互 換 の SCSI-1 ド ラ イ ブ (Tandberg, Archive, Viper,
Wangtek,…) である。デバイス固有のアドレスが利用されて い
る 場合は、ブロック番号は以前に MTIOCPOS によって返された
ものにすべきである。
MTSETBLK mt_count の値をドライブのブロック長 (block length) として
セットする。ブロック長を 0 にするとドライブは可変長ブロッ
クサイズモードにセットされる。
MTSETDENSITY テープ密度 (tape density) を mt_count で示されるコード に
変 更する。ドライブでサポートされている密度コードについて
は、ドライブの文書に書いてあるだろう。
MTSETPART アクティブなパーティションを第 mt_count 番目に切り替え る
。パーティションは 0 から数える。このコマンドは、パーティ
ションのサポートが有効にされたドライブでなければ使えな い
(以下の MT_ST_CAN_PARTITIONS を見よ)。
MTUNLOAD SCSI unload コマンドを実行する (テープのイジェクトは行わ
ない)。
MTUNLOCK テープドライブの扉のロックを解除する。
MTWEOF mt_count 個のファイルマークを書き込む。
MTWSM mt_count 個のセットマークを書き込む。
デバイスオプションの設定のための (スーパーユーザによる) 磁気テープ操作:
MTSETDRVBUFFER
い ろいろなドライブとドライバーのオプションを mt_count にエンコ
ードされた各ビットに従って設定する。オプションには、ドライブ の
バ ッファリングモード、ブール値のドライバオプションの集合、バッ
ファの書き込み閾値 (デフォルトはブロックサイズと密度)、タイムア
ウ ト値が含まれる (カーネル 2.1 以降)。一回の操作で変えられるの
は、上記のリストのどれか一つだけである (複数のブール値はまと め
て一つと勘定される)。
高位の4ビットがゼロである値は、ドライブのバッファリングモードの
設定に使われる。バッファリングモードは以下の通り:
0 ドライブはライトコマンドに対し、データブロックが実際 に
媒体に書き込まれるまで GOOD のステータスを返さない。
1 ドライブはライトコマンドに対し、すべてのデータがドライ
ブの内部バッファに転送されるとすぐに、 GOOD のステー タ
スを返すことができる。
2 ライトコマンドに対し、以下の 2 つの条件がそろった場合、
ドライブはすぐに GOOD ステータスを返す事ができる。 (a)
す べ て のデータがドライブの内部バッファに転送された。
(b) 別々のイニシエーターから来たバッファデータが、す べ
て媒体へ問題なく書き込まれた。
書 き 込 み 閾 値 を 制 御 す る に は 、 mt_count には、定数
MT_ST_WRITE_THRESHOLD とブロックカウントの論理和 (OR) をとっ た
値 を 下位の 28ビットに含まねばならない。このブロックカウントは
1024 バイトブロックを単位としたもので、テープの物理ブロックサイ
ズ を単位としたものではない。また、閾値はドライバの内部バッファ
(上記の説明参照) のサイズを越える事はできない。
ブール値のフラグを設定・解除す る に は 、 mt_count の 値 は
MT_ST_BOOLEANS, MT_ST_SETBOOLEANS, MT_ST_CLEARBOOLEANS,
MT_ST_DEFBOOLEANS のいずれか一つの値に、以下のオプションの任 意
の 組 み 合 わ せ に 対 し て 論 理 和 を取ったものを指定する。
MT_ST_BOOLEANSを用いると、オプションを対応するビットに対して 定
義 されている値に設定できる。 MT_ST_SETBOOLEANSを用いると、オプ
ションは選択的に設定され、 MT_ST_DEFBOOLEANSを用いると選択的 に
解除される。
テープデバイスのデフォルトのオプションは MT_ST_DEFBOOLEANS によ
って設定される。アクティブでないテープデバイス (例: マイナー 番
号 が 32 や 160 のデバイス) は、それらに対するデフォルトのオプ
ションが最初に定義されたときにアクティブになる。アクティブに さ
れ たデバイスは、起動時にアクティブにされたデバイスから、明示的
に指定されなかったオプションを継承する。
ブール値のオプションは以下の通り:
MT_ST_BUFFER_WRITES (デフォルト: 真)
固定長ブロックモードにおけるすべての書き込み操作をバッフ
ァリングする。このオプションが偽であり、かつドライブが固
定長ブロックサイズの時は、すべての書き込み操作はブロック
サイズの倍数の大きさで行わなければならない。信頼性のある
マルチボリュームアーカイブを書き込むためには、このオプシ
ョ ン は 偽 に 設 定 さ れ て い な け れ ば な らない。
MT_ST_ASYNC_WRITES (デフォルト: 真) このオプションが真の
時には、データがドライバのバッファに収まる時にはデータが
ドライブに転送されるのを待たずに、すぐに書き込み操作が返
って来る。バッファがどのくらい空いたら次の SCSI write コ
マンドを発行できるかは、書き込み閾値によって決まる。ドラ
イブが返すすべてのエラーは、次の操作まで保存される。信頼
性のあるマルチボリュームアーカイブを書き込むためには、こ
のオプションは偽に設定されていなければならない。
MT_ST_READ_AHEAD (デフォルト: 真)
このオプションを指定すると、ドライバは固定長ブロックモー
ドで読み込みバッファリングと先読みをするようになる。この
オプションが偽であり、かつドライブが固定長ブロックサイズ
の時は、すべての読み込み操作はブロックサイズの倍数の大き
さで行わなければならない。
MT_ST_TWO_FM (デフォルト: 偽)
このオプションはファイルがクローズされた時のドライバーの
振舞いを変更する。一つのファイルマークを書き込むのが通常
の動作である。このオプションが真の時には、ドライバーは 2
つのファイルマークを書き込んで、 2 つめのファイルマー ク
のところに戻る。
注意: QICテープドライブはファイルマークに上書きすること
ができないので、このオプションを真にしてはならない。これ
らのドライブは記録データの末尾の検知に、ファイルマークが
2つ続けてあるかではなく、ブランクテープかどうかのテス ト
を用いる。現在の他のほとんどのドライブも、記録データの末
尾を検知する。 2 つのファイルマークが必要になるのは、 他
のシステムとテープをやりとりする場合である。
MT_ST_DEBUGGING (デフォルト: 偽)
このオプションを真にすると、ドライバはいろいろなデバッグ
用メッセージを出すようになる (DEBUG を非ゼロに定義してド
ライバをコンパイルしている時のみ有効)。
MT_ST_FAST_EOM (デフォルト: 偽)
こ のオプションを真にすると、 MTEOM 操作が直接ドライブに
送られるようになる。操作が早くなるはずだが、ドライバが現
在 のファイル番号を見失うことになる (これは通常なら MTI-
OCGET リクエストによって返される)。 MT_ST_FAST_EOM が 偽
の 時には、ドライバは MTEOM リクエストに応えるとき、前方
にファイルを一つ一つ進めていく。
MT_ST_AUTO_LOCK (デフォルト: 偽)
このオプションが真の時には、デバイスがオープンされるとド
ライブの扉がロックされ、クローズされるとアンロックされる
。
MT_ST_DEF_WRITES (デフォルト: 偽)
テープオプション (ブロックサイズ、モード、圧縮など) があ
るドライブにリンクされたデバイスで変更されると、その同じ
ドライブにリンクされた他のデバイスでも変更されることがあ
る (そのデバイスの定義による)。このオプションは、ドライ
バによる変更をいつ SCSI コマンドによって反映させるかと、
ドライブの自動検知機能がいつ信頼して良いのかを定義する。
このオプションを偽にしておくと、デバイスの変更があるとド
ラ イ バ は すぐに SCSI コマンドを送る。真にしておくと、
SCSI コマンドは書き込みが要求されるまで送られない。後 者
の場合は、読み込みの際にドライブのファームウェアによって
テープ構造の検知が行える。また SCSI コマンドは、テープが
正しい指定に沿って書き込まれているかどうかの確認のためだ
けに用いられる。
MT_ST_CAN_BSR (デフォルト: 偽)
先読みを使うと、テープをクローズするときに、場合によって
はテープを正しい位置に逆戻ししなければならないことがある
。これには、レコードを越えて逆戻しする SCSI コマンドが用
いられる。古いドライブでは、このコマンド処理の信頼性が低
いことがあるが、このオプションを指定すると、ドライバにこ
のコマンドの利用を禁止することができる。先読みと固定長ブ
ロックモードを用いていると、最終的な結果として、デバイス
の ク ローズ時にテープが正しい位置にならないことがある。
2.6 カーネルでは、SCSI-3 をサポートしているドライブに 対
して、この値のデフォルトは真となる。
MT_ST_NO_BLKLIMS (デフォルト: 偽)
ドライブによっては READ BLOCK LIMITS SCSI コマンドを受け
つけないことがある。このオプションを用いると、ドライバは
このコマンドを用いない。欠点は、指定したブロックサイズが
ドライブに受理されてしまうと、ドライバのコマンド送信前チ
ェックができなくなる点である。
MT_ST_CAN_PARTITIONS (デフォルト: 偽)
このオプションは、一つのテープに複数パーティションを置く
ことをサポートするかどうかを決める。このオプションはドラ
イブにリンクされた全てのデバイスに適用される。
このオプションは、
seek お よび tell 操作 (両者とも MTSEEK
・MTIOCPOS コマンドを伴い、テープ位置を変
更 するとき) の際に、 SCSI-2 の標準で定義
されている論理ブロックアドレスを用いる か
ど うかをドライバに伝える。偽だとデバイス
固有のアドレスが用いられる。ドライブが 論
理 アドレスをサポートしているときは、この
オプションをセットすることを強く勧める 。
こ のモードではファイルマークもカウントす
るからである。論理ブロックアドレスしか サ
ポ ートしないドライブもいくつか存在してい
る。
MT_ST_SYSV (デフォルト: 偽)
このオプションが真になっていると、テー プ
デバイスは SystemV のルールを用いる。偽だ
と BSD のルールを用いる。これらのルール間
の 最も大きな違いは、読み込みを行っていた
デバイスがクローズされたときの振舞いで あ
る 。 System V のルールでは、テープは次の
ファイルマークを越えて移動する (デバイ ス
の利用時にこれが行われなかった場合)。 BSD
のルールではテープ位置は変更されない。
MT_NO_WAIT (デフォルト: 偽)
即時モード (immediate mode; コマンドの 終
了 を 待 た な い) を、ある種のコマンド
(rewind など) に対して有効にする。
例:
struct mtop mt_cmd;
mt_cmd.mt_op = MTSETDRVBUFFER;
mt_cmd.mt_count = MT_ST_BOOLEANS |
MT_ST_BUFFER_WRITES | MT_ST_ASYNC_WRITES;
ioctl(fd, MTIOCTOP, mt_cmd);
デバイスのデフォル ト の ブ ロ ッ ク サ イ ズ は
MT_ST_DEF_BLKSIZE によって設定でき、デフォルトの
密度コードは MT_ST_DEFDENSITY によって設定できる
。これらのパラメータの値は操作コードと OR して与
える。
2.1.x 以降のカーネルでは、タイムアウト値の設定は
、 サブコマンド MT_ST_SET_TIMEOUT に秒単位のタイ
ムアウト値を OR して与えることによって行え る 。
long タイムアウト (巻き戻しなど、長い時間がかか
る コ マ ン ド に 対 し て 用 い ら れ る) は
MT_ST_SET_LONG_TIMEOUT で設定できる。カーネルの
デフォルトは非常に長く、どのドライブでも成功して
いるコマンドが決してタイムアウトしないようになっ
ている。したがって、ドライバはタイムアウトを待っ
ているだけなのに、刺さった (stuck した) ように見
えることがある。これらのコマンドを使えば、特定の
ドライブに対してもう少し実際的な値に設定すること
ができる。一つのデバイスに設定したタイムアウト値
は、それと同じドライブにリンクした全てのデバイス
に適用される。
2.4.19 および 2.5.43 以降のカーネルでは、この ド
ライバはドライブのクリーニングが必要かどうかを示
す状態ビットをサポートする。ドライブがクリーニン
グ 情報を返させるかどうかは、 MT_ST_SEL_CLN サブ
コマンドによって設定できる。この値が 0 だと、 ク
リーニングビットは常に 0 となる。値を 1 にすると
、SCSI-3 標準で規定されている TapeAlert データが
用 い られる (まだ実装されていない) 値としては 2
から 17 が予約されている。低位側の 8 ビットが 18
以 上 だと、拡張状態データ (extended sense data)
が用いられる。第 9-16 ビットは注目すべきビットを
選 択するためのマスクを指定し、第 17-23 ビットは
探すべきビットパターンを指定する。このビットパタ
ー ンが 0 のときは、マスク下のビット (群) がクリ
ーニング要求を示す。パターンが 0 でなければ、 こ
のパターンがマスク後の状態データバイトにマッチし
なければならない。
MTIOCGET — ステータスの取得
このリクエストは (struct mtget *) という型の引数をとる。
/* structure for MTIOCGET - mag tape get status command */
struct mtget {
long mt_type;
long mt_resid;
/* the following registers are device dependent */
long mt_dsreg;
long mt_gstat;
long mt_erreg;
/* The next two fields are not always used */
daddr_t mt_fileno;
daddr_t mt_blkno;
};
mt_type ヘッダファイル中には多くの mt_type の値が定義
されているが、現行のドライバは汎用のタイプ で
あ る MT_ISSCSI1 (汎用 SCSI-1 テープ) および
MT_ISSCSI2 (汎用 SCSI-2 テープ) のみを返す。
mt_resid 現在のテープ位置番号。
mt_dsreg ドライブのブロックサイズと密度の現在の設定 を
報 告する (下位 24 ビットがブロックサイズ、上
位 8 ビットが密度)。これらのフィール ド は 、
MT_ST_BLKSIZE_SHIFT, MT_ST_BLKSIZE_MASK,
MT_ST_DENSITY_SHIFT, MT_ST_DENSITY_MASK で 定
義されている。
mt_gstat 汎用の (デバイスに依存しない) ステータスを報
告する。これらのステータスビットをテストす る
た めのマクロがヘッダファイルで定義されている
。
GMT_EOF(x): テープはファイルマークの直後に 位
置している。 (MTSEEK 操作の後では常に偽)
GMT_BOT(x): テープは最初のファイルの先頭に位
置している。 (MTSEEK 操作の後では常に偽)
GMT_EOT(x): テープ操作はテープの物理的な終 点
に達した。
GMT_SM(x): テープは現在セットマークに位置して
いる。 (MTSEEK 操作の後では常に偽)
GMT_EOD(x): テープは記録データの末尾に位置 し
ている。
GMT_WR_PROT(x): ドライブはライトプロテクトさ
れている。これはドライブによっては、ド ラ
イ ブが現在のメディアタイプへの書き込みを
サポートしていない事を意味する場合もあ る
。
GMT_ONLINE(x): もっとも最近の open(2) が、テ
ープが入っていて操作の準備ができている ド
ライブを検知した。
GMT_D_6250(x), GMT_D_1600(x), GMT_D_800(x):
この「汎用」のステータス情報は、 9-トラッ
ク ½" テープドライブの場合にのみ、現在の
密度の設定を報告する。
GMT_DR_OPEN(x): ドライブにテープが入ってい な
い。
GMT_IM_REP_EN(x): 即時報告モード。 write コー
ルが戻ったとき、テープに対して物理的な 書
き 込みが行われたかどうかを保証できない場
合に、このビットがセットされる。ドライ バ
が データをバッファリングせず、ドライブも
データをバッファリングしない場合に限っ て
、この値は 0 にセットされる。
GMT_CLN(x): ドライブがクリーニングを要求して
いる。カーネル 2.4.19 および 2.5.43 以 降
で実装された。
mt_erreg mt_erreg で定義されているフィールドは一つだけ
で、下位の 16 ビットがエラーをリカバーした 回
数 である (MT_ST_SOFTERR_SHIFT と MT_ST_SOFT-
ERR_MASK で定義されている)。ドライブの報告 す
る エラーリカバー数と矛盾することがあるので、
この数はほとんどの場合維持されない (ほとん ど
の ドライブでは、デフォルトではソフトエラーを
報告しない。しかしこれは SCSI MODE SELECT コ
マンドによって変更できる)。
mt_fileno (ゼロから数えた) 現在のファイル番号を報告する
。ファイル番号がわからない時 (例えば MTBSS や
MTSEEK の後など) には -1 にセットされる。
mt_blkno 現在のファイル中の(ゼロから数えた)ブロック番
号を報告する。ブロック番号がわからない時 ( 例
え ば MTBSF, MTBSS, MTSEEK の後など) には -1
にセットされる。
MTIOCPOS — テープ位置の取得
このリクエストは (struct mtpos *) 型の引数をとり、ドライ
ブが保持している現在のテープブロック番号を報告する。これ
は、 MTIOCGET により返される mt_blkno と同じではない。ド
ラ イ ブは READ POSITION コマンド (デバイス固有アドレス)
をサポートする SCSI-2ドライブか、 Tandberg 互換の SCSI-1
ド ライブ (Tandberg, Archive, Viper, Wangtek, ... ) でな
ければならない。
/* structure for MTIOCPOS - mag tape get position command */
struct mtpos {
long mt_blkno; /* current block number */
};
返り値
EACCES 書き込み保護されているテープに書 き
込 みまたは消去を行おうとした。 (こ
のエラーは open(2) 中には検知されな
い。)
EBUSY デバイスがすでに使われているか、ド
ライバがバッファを割当てられなか っ
た。
EFAULT コマンドの引数が、呼びだしプロセス
に属していないメモリ位置を指して い
る。
EINVAL ioctl(2) の引数が不正であるか、要求
したブロックサイズが不正。
EIO 14 要求された操作が最後まで行えなか っ
た。
ENOMEM read(2) のバイト数が、テープにある
次の物理ブロックより小さい (2.2.18
および 2.4.0-test6 以前では、黙って
余分のバイトを無視していた)。
ENOSPC メディアの終点に達したため、書き 込
み操作が完了しなかった。
ENOSYS 不明な ioctl(2)。
ENXIO オープンする時にテープデバイスが存
在しなかった。
EOVERFLOW ドライバの内部バッファより大きい サ
イ ズの可変長ブロックを読み書きしよ
うとした。
EROFS ドライブに入っているテープがライ ト
プ ロ テ ク ト さ れ ている場合に、
O_WRONLY または O_RDWR で open を行
おうとした。
ファイル
/dev/st* 自動巻き戻しの SCSI テープデバイス。
/dev/nst* 巻き戻しをしない SCSI テープデバイス
。
注意
1. 異なるシステムでデータを相互にやりとりする 場
合 、両方のシステムで物理的なテープブロックサ
イズを一致させる必要がある。起動直後のドラ イ
ブ のパラメータは、大多数の OS がそのデバイス
に対して用いている値と異なっていることもよ く
あ る。多くのシステムは、ドライブが対応してい
れば可変長ブロックモードを用いる。 DAT、 8mm
ヘリカルスキャンドライブ、 DLT などの最近のド
ライブのほとんどは可変長ブロックモードに対 応
し ているから。これらのドライブは (少なくとも
他のシステムとのデータ交換がある 場 合 は) 、
Linux でも可変長ブロックモードで使うほうが良
いかもしれない (つまりシステムの起動時のモ ー
ド 設 定に MTSETBLK または MTSETDEFBLK を用い
る)。欠点としては、比較的大きなテープブロック
サ イズを用いなければ、 SCSI バス上で満足のい
く転送速度が得られないことである。
2. 多くのプログラム (tar(1) など) では、コマンド
ラ インからユーザがブロック関連の値を指定でき
る。この値によってテープ上の物理的なブロッ ク
サ イズを決定できるのは、可変長ブロックモード
に限られることに注意。
3. SCSI テープドライブを用いるには、基本の SCSI
ド ライバ、 SCSI アダプタのドライバ、 SCSI テ
ープドライバのすべてがカーネルに組み込まれ て
い るか、あるいはモジュールとしてロードされて
いる必要がある。 SCSI テープドライバがない と
、 ドライブは認識されるが、このページで記述さ
れているテープのサポートは利用できない。
4. ドライバはエラーメッセージをコンソールとロ グ
と に 書 き 出す。カーネル設定で verbose SCSI
messages が有効にされていると、 SENSE コー ド
が 自動的にテキストに変換されて、いくつかのメ
ッセージに書きだされる。
5. このドライバの内部バッファリングは、固定ブ ロ
ックモードなら read(2) や write(2) のバイト数
が小さくても良いスループットを出す。直接転 送
で はこれは不可能なので、2.6 カーネルに移行し
たときに驚くかもしれない。解決法としては、 ソ
フ トウェアにより大きな転送を行うよう伝える (
たいていはより大きなブロックを使わせる) こ と
で ある。これが不可能なら、直接転送を無効にす
ることもできる。
関連項目
mt(1)
カーネルソースの drivers/scsi/README.st や Docu-
mentation/scsi/st.txt (カーネル 2.6 以降) の各フ
ァイルには、ドライバに関するより新しい情報や、 そ
の設定可能な範囲に関する内容が含まれている。
Linux 2007-12-16 ST(4)
ST(4) Linux Programmer’s Manual ST(4)
NAME
st - SCSI tape device
SYNOPSIS
#include
int ioctl(int fd, int request [, (void *)arg3]);
int ioctl(int fd, MTIOCTOP, (struct mtop *)mt_cmd);
int ioctl(int fd, MTIOCGET, (struct mtget *)mt_status);
int ioctl(int fd, MTIOCPOS, (struct mtpos *)mt_pos);
DESCRIPTION
The st driver provides the interface to a variety of SCSI tape devices.
Currently, the driver takes control of all detected devices of type
“sequential-access”. The st driver uses major device number 9.
Each device uses eight minor device numbers. The lowermost five bits
in the minor numbers are assigned sequentially in the order of detec-
tion. In the 2.6 kernel, the bits above the eight lowermost bits are
concatenated to the five lowermost bits to form the tape number. The
minor numbers can be grouped into two sets of four numbers: the princi-
pal (auto-rewind) minor device numbers, n, and the “no-rewind” device
numbers, (n + 128). Devices opened using the principal device number
will be sent a REWIND command when they are closed. Devices opened
using the “no-rewind” device number will not. (Note that using an
auto-rewind device for positioning the tape with, for instance, mt does
not lead to the desired result: the tape is rewound after the mt com-
mand and the next command starts from the beginning of the tape).
Within each group, four minor numbers are available to define devices
with different characteristics (block size, compression, density, etc.)
When the system starts up, only the first device is available. The
other three are activated when the default characteristics are defined
(see below). (By changing compile-time constants, it is possible to
change the balance between the maximum number of tape drives and the
number of minor numbers for each drive. The default allocation allows
control of 32 tape drives. For instance, it is possible to control up
to 64 tape drives with two minor numbers for different options.)
Devices are typically created by:
mknod -m 666 /dev/st0 c 9 0
mknod -m 666 /dev/st0l c 9 32
mknod -m 666 /dev/st0m c 9 64
mknod -m 666 /dev/st0a c 9 96
mknod -m 666 /dev/nst0 c 9 128
mknod -m 666 /dev/nst0l c 9 160
mknod -m 666 /dev/nst0m c 9 192
mknod -m 666 /dev/nst0a c 9 224
There is no corresponding block device.
The driver uses an internal buffer that has to be large enough to hold
at least one tape block. In kernels before 2.1.121, the buffer is
allocated as one contiguous block. This limits the block size to the
largest contiguous block of memory the kernel allocator can provide.
The limit is currently 128 kB for 32-bit architectures and 256 kB for
64-bit architectures. In newer kernels the driver allocates the buffer
in several parts if necessary. By default, the maximum number of parts
is 16. This means that the maximum block size is very large (2 MB if
allocation of 16 blocks of 128 kB succeeds).
The driver’s internal buffer size is determined by a compile-time con-
stant which can be overridden with a kernel startup option. In addi-
tion to this, the driver tries to allocate a larger temporary buffer at
run time if necessary. However, run-time allocation of large contigu-
ous blocks of memory may fail and it is advisable not to rely too much
on dynamic buffer allocation with kernels older than 2.1.121 (this
applies also to demand-loading the driver with kerneld or kmod).
The driver does not specifically support any tape drive brand or model.
After system start-up the tape device options are defined by the drive
firmware. For example, if the drive firmware selects fixed-block mode,
the tape device uses fixed-block mode. The options can be changed with
explicit ioctl(2) calls and remain in effect when the device is closed
and reopened. Setting the options affects both the auto-rewind and the
non-rewind device.
Different options can be specified for the different devices within the
subgroup of four. The options take effect when the device is opened.
For example, the system administrator can define one device that writes
in fixed-block mode with a certain block size, and one which writes in
variable-block mode (if the drive supports both modes).
The driver supports tape partitions if they are supported by the drive.
(Note that the tape partitions have nothing to do with disk partitions.
A partitioned tape can be seen as several logical tapes within one
medium.) Partition support has to be enabled with an ioctl(2). The
tape location is preserved within each partition across partition
changes. The partition used for subsequent tape operations is selected
with an ioctl(2). The partition switch is executed together with the
next tape operation in order to avoid unnecessary tape movement. The
maximum number of partitions on a tape is defined by a compile-time
constant (originally four). The driver contains an ioctl(2) that can
format a tape with either one or two partitions.
Device /dev/tape is usually created as a hard or soft link to the
default tape device on the system.
Starting from kernel 2.6.2, the driver exports in the sysfs directory
/sys/class/scsi_tape the attached devices and some parameters assigned
to the devices.
Data Transfer
The driver supports operation in both fixed-block mode and variable-
block mode (if supported by the drive). In fixed-block mode the drive
writes blocks of the specified size and the block size is not dependent
on the byte counts of the write system calls. In variable-block mode
one tape block is written for each write call and the byte count deter-
mines the size of the corresponding tape block. Note that the blocks
on the tape don’t contain any information about the writing mode: when
reading, the only important thing is to use commands that accept the
block sizes on the tape.
In variable-block mode the read byte count does not have to match the
tape block size exactly. If the byte count is larger than the next
block on tape, the driver returns the data and the function returns the
actual block size. If the block size is larger than the byte count,
the requested amount of data from the start of the block is returned
and the rest of the block is discarded.
In fixed-block mode the read byte counts can be arbitrary if buffering
is enabled, or a multiple of the tape block size if buffering is dis-
abled. Kernels before 2.1.121 allow writes with arbitrary byte count
if buffering is enabled. In all other cases (kernel before 2.1.121
with buffering disabled or newer kernel) the write byte count must be a
multiple of the tape block size.
In the 2.6 kernel, the driver tries to use direct transfers between the
user buffer and the device. If this is not possible, the driver’s
internal buffer is used. The reasons for not using direct transfers
include improper alignment of the user buffer (default is 512 bytes but
this can be changed by the HBA driver), one of more pages of the user
buffer not reachable by the SCSI adapter, etc.
A filemark is automatically written to tape if the last tape operation
before close was a write.
When a filemark is encountered while reading, the following happens.
If there are data remaining in the buffer when the filemark is found,
the buffered data is returned. The next read returns zero bytes. The
following read returns data from the next file. The end of recorded
data is signaled by returning zero bytes for two consecutive read
calls. The third read returns an error.
Ioctls
The driver supports three ioctl(2) requests. Requests not recognized
by the st driver are passed to the SCSI driver. The definitions below
are from /usr/include/linux/mtio.h:
MTIOCTOP — Perform a tape operation
This request takes an argument of type (struct mtop *). Not all drives
support all operations. The driver returns an EIO error if the drive
rejects an operation.
/* Structure for MTIOCTOP - mag tape op command: */
struct mtop {
short mt_op; /* operations defined below */
int mt_count; /* how many of them */
};
Magnetic Tape operations for normal tape use:
MTBSF Backward space over mt_count filemarks.
MTBSFM Backward space over mt_count filemarks. Reposition the
tape to the EOT side of the last filemark.
MTBSR Backward space over mt_count records (tape blocks).
MTBSS Backward space over mt_count setmarks.
MTCOMPRESSION Enable compression of tape data within the drive if
mt_count is non-zero and disable compression if mt_count
is zero. This command uses the MODE page 15 supported by
most DATs.
MTEOM Go to the end of the recorded media (for appending
files).
MTERASE Erase tape. With 2.6 kernel, short erase (mark tape
empty) is performed if the argument is zero. Otherwise
long erase (erase all) is done.
MTFSF Forward space over mt_count filemarks.
MTFSFM Forward space over mt_count filemarks. Reposition the
tape to the BOT side of the last filemark.
MTFSR Forward space over mt_count records (tape blocks).
MTFSS Forward space over mt_count setmarks.
MTLOAD Execute the SCSI load command. A special case is avail-
able for some HP autoloaders. If mt_count is the
constant MT_ST_HPLOADER_OFFSET plus a number, the number
is sent to the drive to control the autoloader.
MTLOCK Lock the tape drive door.
MTMKPART Format the tape into one or two partitions. If mt_count
is non-zero, it gives the size of the first partition and
the second partition contains the rest of the tape. If
mt_count is zero, the tape is formatted into one parti-
tion. This command is not allowed for a drive unless the
partition support is enabled for the drive (see
MT_ST_CAN_PARTITIONS below).
MTNOP No op — flushes the driver’s buffer as a side effect.
Should be used before reading status with MTIOCGET.
MTOFFL Rewind and put the drive off line.
MTRESET Reset drive.
MTRETEN Re-tension tape.
MTREW Rewind.
MTSEEK Seek to the tape block number specified in mt_count.
This operation requires either a SCSI-2 drive that sup-
ports the LOCATE command (device-specific address) or a
Tandberg-compatible SCSI-1 drive (Tandberg, Archive
Viper, Wangtek, ...). The block number should be one
that was previously returned by MTIOCPOS if device-spe-
cific addresses are used.
MTSETBLK Set the drive’s block length to the value specified in
mt_count. A block length of zero sets the drive to vari-
able block size mode.
MTSETDENSITY Set the tape density to the code in mt_count. The den-
sity codes supported by a drive can be found from the
drive documentation.
MTSETPART The active partition is switched to mt_count. The parti-
tions are numbered from zero. This command is not
allowed for a drive unless the partition support is
enabled for the drive (see MT_ST_CAN_PARTITIONS below).
MTUNLOAD Execute the SCSI unload command (does not eject the
tape).
MTUNLOCK Unlock the tape drive door.
MTWEOF Write mt_count filemarks.
MTWSM Write mt_count setmarks.
Magnetic Tape operations for setting of device options (by the supe-
ruser):
MTSETDRVBUFFER
Set various drive and driver options according to bits encoded
in mt_count. These consist of the drive’s buffering mode, a
set of Boolean driver options, the buffer write threshold,
defaults for the block size and density, and timeouts (only in
kernels 2.1 and later). A single operation can affect only one
item in the list above (the Booleans counted as one item.)
A value having zeros in the high-order 4 bits will be used to
set the drive’s buffering mode. The buffering modes are:
0 The drive will not report GOOD status on write commands
until the data blocks are actually written to the
medium.
1 The drive may report GOOD status on write commands as
soon as all the data has been transferred to the
drive’s internal buffer.
2 The drive may report GOOD status on write commands as
soon as (a) all the data has been transferred to the
drive’s internal buffer, and (b) all buffered data from
different initiators has been successfully written to
the medium.
To control the write threshold the value in mt_count must
include the constant MT_ST_WRITE_THRESHOLD logically ORed with
a block count in the low 28 bits. The block count refers to
1024-byte blocks, not the physical block size on the tape. The
threshold cannot exceed the driver’s internal buffer size (see
DESCRIPTION, above).
To set and clear the Boolean options the value in mt_count must
include one of the constants MT_ST_BOOLEANS, MT_ST_SETBOOLEANS,
MT_ST_CLEARBOOLEANS, or MT_ST_DEFBOOLEANS logically or’ed with
whatever combination of the following options is desired.
Using MT_ST_BOOLEANS the options can be set to the values
defined in the corresponding bits. With MT_ST_SETBOOLEANS the
options can be selectively set and with MT_ST_DEFBOOLEANS
selectively cleared.
The default options for a tape device are set with MT_ST_DEF-
BOOLEANS. A non-active tape device (e.g., device with minor 32
or 160) is activated when the default options for it are
defined the first time. An activated device inherits from the
device activated at start-up the options not set explicitly.
The Boolean options are:
MT_ST_BUFFER_WRITES (Default: true)
Buffer all write operations in fixed-block mode. If
this option is false and the drive uses a fixed block
size, then all write operations must be for a multiple
of the block size. This option must be set false to
write reliable multi-volume archives.
MT_ST_ASYNC_WRITES (Default: true) When this option is
true, write operations return immediately without wait-
ing for the data to be transferred to the drive if the
data fits into the driver’s buffer. The write threshold
determines how full the buffer must be before a new SCSI
write command is issued. Any errors reported by the
drive will be held until the next operation. This
option must be set false to write reliable multi-volume
archives.
MT_ST_READ_AHEAD (Default: true)
This option causes the driver to provide read buffering
and read-ahead in fixed-block mode. If this option is
false and the drive uses a fixed block size, then all
read operations must be for a multiple of the block
size.
MT_ST_TWO_FM (Default: false)
This option modifies the driver behavior when a file is
closed. The normal action is to write a single file-
mark. If the option is true the driver will write two
filemarks and backspace over the second one.
Note: This option should not be set true for QIC tape
drives since they are unable to overwrite a filemark.
These drives detect the end of recorded data by testing
for blank tape rather than two consecutive filemarks.
Most other current drives also detect the end of
recorded data and using two filemarks is usually neces-
sary only when interchanging tapes with some other sys-
tems.
MT_ST_DEBUGGING (Default: false)
This option turns on various debugging messages from the
driver (effective only if the driver was compiled with
DEBUG defined non-zero).
MT_ST_FAST_EOM (Default: false)
This option causes the MTEOM operation to be sent
directly to the drive, potentially speeding up the oper-
ation but causing the driver to lose track of the cur-
rent file number normally returned by the MTIOCGET
request. If MT_ST_FAST_EOM is false the driver will
respond to an MTEOM request by forward spacing over
files.
MT_ST_AUTO_LOCK (Default: false)
When this option is true, the drive door is locked when
the device is opened and unlocked when it is closed.
MT_ST_DEF_WRITES (Default: false)
The tape options (block size, mode, compression, etc.)
may change when changing from one device linked to a
drive to another device linked to the same drive depend-
ing on how the devices are defined. This option defines
when the changes are enforced by the driver using SCSI-
commands and when the drives auto-detection capabilities
are relied upon. If this option is false, the driver
sends the SCSI-commands immediately when the device is
changed. If the option is true, the SCSI-commands are
not sent until a write is requested. In this case the
drive firmware is allowed to detect the tape structure
when reading and the SCSI-commands are used only to make
sure that a tape is written according to the correct
specification.
MT_ST_CAN_BSR (Default: false)
When read-ahead is used, the tape must sometimes be
spaced backward to the correct position when the device
is closed and the SCSI command to space backwards over
records is used for this purpose. Some older drives
can’t process this command reliably and this option can
be used to instruct the driver not to use the command.
The end result is that, with read-ahead and fixed-block
mode, the tape may not be correctly positioned within a
file when the device is closed. With 2.6 kernel, the
default is true for drives supporting SCSI-3.
MT_ST_NO_BLKLIMS (Default: false)
Some drives don’t accept the READ BLOCK LIMITS SCSI com-
mand. If this is used, the driver does not use the com-
mand. The drawback is that the driver can’t check
before sending commands if the selected block size is
acceptable to the drive.
MT_ST_CAN_PARTITIONS (Default: false)
This option enables support for several partitions
within a tape. The option applies to all devices linked
to a drive.
MT_ST_SCSI2LOGICAL (Default: false)
This option instructs the driver to use the logical
block addresses defined in the SCSI-2 standard when per-
forming the seek and tell operations (both with MTSEEK
and MTIOCPOS commands and when changing tape partition).
Otherwise the device-specific addresses are used. It is
highly advisable to set this option if the drive sup-
ports the logical addresses because they count also
filemarks. There are some drives that only support the
logical block addresses.
MT_ST_SYSV (Default: false)
When this option is enabled, the tape devices use the
SystemV semantics. Otherwise the BSD semantics are
used. The most important difference between the seman-
tics is what happens when a device used for reading is
closed: in System V semantics the tape is spaced forward
past the next filemark if this has not happened while
using the device. In BSD semantics the tape position is
not changed.
MT_NO_WAIT (Default: false)
Enables immediate mode (i.e., don’t wait for the command
to finish) for some commands (e.g., rewind).
An example:
struct mtop mt_cmd;
mt_cmd.mt_op = MTSETDRVBUFFER;
mt_cmd.mt_count = MT_ST_BOOLEANS |
MT_ST_BUFFER_WRITES | MT_ST_ASYNC_WRITES;
ioctl(fd, MTIOCTOP, mt_cmd);
The default block size for a device can be set with
MT_ST_DEF_BLKSIZE and the default density code can be set with
MT_ST_DEFDENSITY. The values for the parameters are or’ed with
the operation code.
With kernels 2.1.x and later, the timeout values can be set
with the subcommand MT_ST_SET_TIMEOUT ORed with the timeout in
seconds. The long timeout (used for rewinds and other commands
that may take a long time) can be set with MT_ST_SET_LONG_TIME-
OUT. The kernel defaults are very long to make sure that a
successful command is not timed out with any drive. Because of
this the driver may seem stuck even if it is only waiting for
the timeout. These commands can be used to set more practical
values for a specific drive. The timeouts set for one device
apply for all devices linked to the same drive.
Starting from kernels 2.4.19 and 2.5.43, the driver supports a
status bit which indicates whether the drive requests cleaning.
The method used by the drive to return cleaning information is
set using the MT_ST_SEL_CLN subcommand. If the value is zero,
the cleaning bit is always zero. If the value is one, the
TapeAlert data defined in the SCSI-3 standard is used (not yet
implemented). Values 2-17 are reserved. If the lowest eight
bits are >= 18, bits from the extended sense data are used.
The bits 9-16 specify a mask to select the bits to look at and
the bits 17-23 specify the bit pattern to look for. If the bit
pattern is zero, one or more bits under the mask indicate the
cleaning request. If the pattern is non-zero, the pattern must
match the masked sense data byte.
MTIOCGET — Get status
This request takes an argument of type (struct mtget *).
/* structure for MTIOCGET - mag tape get status command */
struct mtget {
long mt_type;
long mt_resid;
/* the following registers are device dependent */
long mt_dsreg;
long mt_gstat;
long mt_erreg;
/* The next two fields are not always used */
daddr_t mt_fileno;
daddr_t mt_blkno;
};
mt_type The header file defines many values for mt_type, but the
current driver reports only the generic types MT_ISSCSI1
(Generic SCSI-1 tape) and MT_ISSCSI2 (Generic SCSI-2 tape).
mt_resid contains the current tape partition number.
mt_dsreg reports the drive’s current settings for block size (in the
low 24 bits) and density (in the high 8 bits). These fields
are defined by MT_ST_BLKSIZE_SHIFT, MT_ST_BLKSIZE_MASK,
MT_ST_DENSITY_SHIFT, and MT_ST_DENSITY_MASK.
mt_gstat reports generic (device independent) status information.
The header file defines macros for testing these status
bits:
GMT_EOF(x): The tape is positioned just after a filemark
(always false after an MTSEEK operation).
GMT_BOT(x): The tape is positioned at the beginning of the
first file (always false after an MTSEEK operation).
GMT_EOT(x): A tape operation has reached the physical End Of
Tape.
GMT_SM(x): The tape is currently positioned at a setmark
(always false after an MTSEEK operation).
GMT_EOD(x): The tape is positioned at the end of recorded
data.
GMT_WR_PROT(x): The drive is write-protected. For some
drives this can also mean that the drive does not sup-
port writing on the current medium type.
GMT_ONLINE(x): The last open(2) found the drive with a tape
in place and ready for operation.
GMT_D_6250(x), GMT_D_1600(x), GMT_D_800(x): This “generic”
status information reports the current density setting
for 9-track ½" tape drives only.
GMT_DR_OPEN(x): The drive does not have a tape in place.
GMT_IM_REP_EN(x): Immediate report mode. This bit is set if
there are no guarantees that the data has been physi-
cally written to the tape when the write call returns.
It is set zero only when the driver does not buffer data
and the drive is set not to buffer data.
GMT_CLN(x): The drive has requested cleaning. Implemented
in kernels since 2.4.19 and 2.5.43.
mt_erreg The only field defined in mt_erreg is the recovered error
count in the low 16 bits (as defined by MT_ST_SOFTERR_SHIFT
and MT_ST_SOFTERR_MASK. Due to inconsistencies in the way
drives report recovered errors, this count is often not
maintained (most drives do not by default report soft errors
but this can be changed with a SCSI MODE SELECT command).
mt_fileno reports the current file number (zero-based). This value is
set to -1 when the file number is unknown (e.g., after MTBSS
or MTSEEK).
mt_blkno reports the block number (zero-based) within the current
file. This value is set to -1 when the block number is
unknown (e.g., after MTBSF, MTBSS, or MTSEEK).
MTIOCPOS — Get tape position
This request takes an argument of type (struct mtpos *) and reports the
drive’s notion of the current tape block number, which is not the same
as mt_blkno returned by MTIOCGET. This drive must be a SCSI-2 drive
that supports the READ POSITION command (device-specific address) or a
Tandberg-compatible SCSI-1 drive (Tandberg, Archive Viper, Wangtek, ...
).
/* structure for MTIOCPOS - mag tape get position command */
struct mtpos {
long mt_blkno; /* current block number */
};
RETURN VALUE
EACCES An attempt was made to write or erase a write-pro-
tected tape. (This error is not detected during
open(2).)
EBUSY The device is already in use or the driver was
unable to allocate a buffer.
EFAULT The command parameters point to memory not belong-
ing to the calling process.
EINVAL An ioctl(2) had an invalid argument, or a
requested block size was invalid.
EIO The requested operation could not be completed.
ENOMEM The byte count in read(2) is smaller than the next
physical block on the tape. (Before 2.2.18 and
2.4.0-test6 the extra bytes have been silently
ignored.)
ENOSPC A write operation could not be completed because
the tape reached end-of-medium.
ENOSYS Unknown ioctl(2).
ENXIO During opening, the tape device does not exist.
EOVERFLOW An attempt was made to read or write a variable-
length block that is larger than the driver’s
internal buffer.
EROFS Open is attempted with O_WRONLY or O_RDWR when the
tape in the drive is write-protected.
FILES
/dev/st* the auto-rewind SCSI tape devices
/dev/nst* the non-rewind SCSI tape devices
NOTES
1. When exchanging data between systems, both systems have to
agree on the physical tape block size. The parameters of a
drive after startup are often not the ones most operating
systems use with these devices. Most systems use drives in
variable-block mode if the drive supports that mode. This
applies to most modern drives, including DATs, 8mm helical
scan drives, DLTs, etc. It may be advisable to use these
drives in variable-block mode also in Linux (i.e., use
MTSETBLK or MTSETDEFBLK at system startup to set the mode),
at least when exchanging data with a foreign system. The
drawback of this is that a fairly large tape block size has
to be used to get acceptable data transfer rates on the SCSI
bus.
2. Many programs (e.g., tar(1)) allow the user to specify the
blocking factor on the command line. Note that this deter-
mines the physical block size on tape only in variable-block
mode.
3. In order to use SCSI tape drives, the basic SCSI driver, a
SCSI-adapter driver and the SCSI tape driver must be either
configured into the kernel or loaded as modules. If the
SCSI-tape driver is not present, the drive is recognized but
the tape support described in this page is not available.
4. The driver writes error messages to the console/log. The
SENSE codes written into some messages are automatically
translated to text if verbose SCSI messages are enabled in
kernel configuration.
5. The driver’s internal buffering allows good throughput in
fixed-block mode also with small read(2) and write(2) byte
counts. With direct transfers this is not possible and may
cause a surprise when moving to the 2.6 kernel. The solu-
tion is to tell the software to use larger transfers (often
telling it to use larger blocks). If this is not possible,
direct transfers can be disabled.
SEE ALSO
mt(1)
The file drivers/scsi/README.st or Documentation/scsi/st.txt
(kernel >= 2.6) in the kernel sources contains the most recent
information about the driver and its configuration possibili-
ties.
COLOPHON
This page is part of release 3.22 of the Linux man-pages
project. A description of the project, and information about
reporting bugs, can be found at http://www.kernel.org/doc/man-
pages/.
Linux 2007-12-16 ST(4)