我想在我的玩具文件系統模塊中調用ioctl函數。我只想讓這個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
我敢打賭,我在做一些簡單的錯誤。有人能幫忙指出問題是什麼嗎?非常感謝你。
您定位的是哪個平臺? 86? – jleahy 2013-03-08 20:57:33
你如何設置OSPFSIOCRASH?它需要編碼參數的方向和大小,可能通過'_IOW(type,nr,unsigned long)' – 2013-03-08 20:58:02
這是一個運行Debian 2.6.18-6-486的x86模擬器(QEMU)。如果這有什麼區別。你如何設置_IOW(type,nr,unsigned long)? – user1174472 2013-03-08 20:59:45