おもちゃのファイル システム モジュールで ioctl 関数を呼び出そうとしています。この ioctl に、呼び出し元から渡される変数を設定させたいだけです。ここまでで、ioctl 呼び出しを可能にする ioctl インフラストラクチャーをセットアップしました。私のモジュールには、ioctl を処理するためのこの関数があります。
int ospfs_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
{
if(cmd == OSPFSIOCRASH)
{
eprintk("crash: %ld\n", arg);
return 0;
}
else
return -ENOTTY;
}
そして、私のテスト関数は次のようになります。
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#define OSPFSIOCRASH 42
int main()
{
int fd = open("/tmp/cs111/lab3-thief/test/hello.txt", O_RDWR);
printf("ioctl call: %d\n", ioctl(fd, OSPFSIOCRASH, 100));
close(fd);
}
出力が
crash: 100
ioctl call: 0
しかし、出力は実際には
crash: 0
ioctl call: 0
私は単純な間違ったことをしているに違いない。誰かが助けて、問題が何であるかを指摘してもらえますか? よろしくお願いします。