0
我想寫在/ dev/simulator文件上。未能打開設備
- # mknod /dev/simulator c 60 0
- # chmod 666 /dev/simulator
- # ls -l /dev/simulator
- crw-rw-rw- 1 root root 60, 0 2012-05-22 19:22 /dev/simulator
我試圖打開此設備和寫的東西就可以了,但得到一個錯誤: 我以創建該設備
這是由我的條件定義application: Simulator opening failed
,但爲什麼我無法進入設備? 這裏是我的代碼:
/*
* Some Other Code *
*/
static int simDev;
simDev = open("/dev/simulator", O_RDWR);
if(simDev<0) {
printf("application: Simulator opening failed.\n");
exit (1);
}
else
printf("Device opened successfully.");
signal(SIGIO, signal_handler);
pid_t pid;
pid = getpid();
write(simDev, &pid, 4);
/*
* Some Other Code *
*/
close(simDev);
任何人都可以請幫我改正我的錯誤?
內核模塊也編寫並編譯好。 – Raheel
struct file_operations sim_fops = { write:sim_write, release:sim_release, open:sim_open, }; int sim_open(struct inode * inode,struct file * filp) {*} *成功*/ return 0; } int sim_release(struct inode * inode,struct file * filp){*} * * * * * * * * * return 0; } ssize_t sim_write(struct file * filp,char * buf,size_t count,loff_t * f_pos)int * id; pid = copy_from_user(&id,buf,sizeof(id));如果(pid <0) printk(「在訪問用戶pid%d時失敗」,pid); else printk(「從用戶複製的pid:%d」,pid); 返回計數; } – Raheel
如果我使用cat/dev/simulator ----來檢查設備,那麼它會給我這樣的輸出:cat:/ dev/simulator:沒有這樣的設備或地址 – Raheel