
「hello」というカーネルモジュールがあるとしましょう。
たとえば、
static struct file_operations hello_fops = {
.open = hello_open,
.read = hello_read,
.release = hello_release,
};
static ssize_t hello_read(struct file *f, char *buf, size_t len, loff_t *offset){
// some code here
}
/dev/hello
文字デバイスファイルからデータを読み取ると関数がhello_read
呼び出されますが、関数のパラメータはどこから来ますか?
答え1
パラメーターは、読み取りを引き起こしたシステム呼び出しから取得されます。
- プログラム呼び出し
read
、ファイル記述子、バッファへのポインタ、および数を渡します。 - システムコールはプロセッサ
ksys_read
、struct file
対応するファイル記述子とファイルの現在位置を決定します。呼ぶvfs_read
; vfs_read
通話struct file_operations
関連read
機能。
でも同様のルートがありますpread
、読み取るファイルの場所も提供します。プロセッサksys_pread64
。