Skip to main content

ログ取得ツール (移転先予定地)

Pythonでデバイスドライバ

Pythonでブロックデバイスドライバを書く方法。

fusd(circlemud.org)を使う。これでキャラクタデバイスを書けるかどうかはわからん。まあ受け口となるカーネルモジュールとコールバックなりなんなりでコードを実行するためのユーザライブラリという組み合わせはfuse(sourceforge.net)などでもおなじみであるので、Pythonのモジュールを用意してくれちゃうというのもまあ、王道と言えるだろう。

Pythonのモジュール自体はけっこうちゃんと作ってあるように見える。open/closeでprint文が入ってしまうがまあこれはopen()/close()をオーバーライドすればよい話みたい。

#! /usr/bin/python

import fusd

class myclass(fusd.OpenFile): def do_read(self, req): print dir(req) print “len=",req.length, “flag=",req.flags print “pid=",req.pid, “uid=",req.uid, “offset=",req.offset req.setdata(req.offset, “Hello”) req.finish(“Hello”.count(””)-1)

dev=fusd.Device(“device-name”, 0666) dev.openFileClass=myclass fusd.run()

みたいな感じで。