このパッケージでは、ドライバをインストールします。
このケーススタディーでは、次の手法の実例を示します。
postinstall スクリプトを使用して、ドライバをインストールおよびロードする
preremove スクリプトを使用して、ドライバをアンロードする
これらのスクリプトの詳細については、「手続きスクリプトの書き込み」を参照してください。
request スクリプトを作成します。
request スクリプトは、管理者に対してドライバオブジェクトのインストール先を質問し、その答えを $KERNDIR パラメータに割り当てることで、ドライバオブジェクトのインストール先を決定します。
このスクリプトは、CLASSES および KERNDIR の 2 つのパラメータを、インストール環境と postinstall スクリプトで使用できるようにするルーチンを実行して終了します。
postinstall スクリプトを作成します。
postinstall スクリプトは、実際にはドライバのインストールを実行します。ドライバのインストールは、buffer と buffer.conf という 2 つのファイルがインストールされたあとに実行されます。この例で示した postinstall ファイルは、次のアクションを実行します。
add_drv コマンドを使用して、ドライバをシステムにロードします。
installf コマンドを使用して、デバイスのリンクを作成します。
installf -f コマンドを使用して、インストールをファイナライズします。
preremove スクリプトを作成します。
preremove スクリプトは rem_drv コマンドを使用して、システムからドライバをアンロードしたあと、リンク /dev/buffer0 を削除します。
PKG=bufdev NAME=Buffer Device CATEGORY=system BASEDIR=/ ARCH=INTEL VERSION=Software Issue #19 CLASSES=none |
インストール時にドライバをインストールするには、ドライバのオブジェクトおよび構成ファイルを prototype ファイルに含める必要があります。
この例では、ドライバの実行モジュールの名前は buffer です。add_drv コマンドは、このファイルに対して実行されます。カーネルは、構成ファイル buffer.conf をドライバの構成に利用します。
i pkginfo i request i postinstall i preremove f none $KERNDIR/buffer 444 root root f none $KERNDIR/buffer.conf 444 root root |
この例の prototype ファイルを見て、次の点に注意してください。
パッケージオブジェクトについて特別な処理は必要ないため、それらのオブジェクトは標準の none クラスに配置できます。pkginfo ファイルの CLASSES パラメータは none に設定されています。
buffer と buffer.conf のパス名が、変数 $KERNDIR で始まっています。この変数は request スクリプトで設定され、管理者はこの変数によってドライバファイルのインストール先を決定できます。デフォルトのディレクトリは /kernel/drv です。
postinstall スクリプト (ドライバのインストールを実行するスクリプト) のエントリが存在します。
trap 'exit 3' 15 # determine where driver object should be placed; location # must be an absolute path name that is an existing directory KERNDIR=`ckpath -aoy -d /kernel/drv -p \ “Where do you want the driver object installed”` || exit $? # make parameters available to installation service, and # so to any other packaging scripts cat >$1 <<! CLASSES='$CLASSES' KERNDIR='$KERNDIR' ! exit 0 |
# KERNDIR parameter provided by `request' script err_code=1 # an error is considered fatal # Load the module into the system cd $KERNDIR add_drv -m '* 0666 root sys' buffer || exit $err_code # Create a /dev entry for the character node installf $PKGINST /dev/buffer0=/devices/eisa/buffer*:0 s installf -f $PKGINST |
err_code=1 # an error is considered fatal # Unload the driver rem_drv buffer || exit $err_code # remove /dev file removef $PKGINST /dev/buffer0 ; rm /dev/buffer0 removef -f $PKGINST |