파일을 커널에서 어떻게 다루죠? 소스좀 고쳐주실래요?
글쓴이: jyj9782 / 작성시간: 목, 2005/02/10 - 4:34오후
움, 커널 2.4.25 에서 작업중입니다..모듈로 올리는데요..
파일을 열어서 출력하는 간단한 프로그램이요..
#include <linux/kernel.h> #include <linux/module.h> #include <linux/vmalloc.h> #include <linux/fs.h> #include <linux/mm.h> #include <linux/slab.h> #include <asm/uaccess.h> #include <linux/fcntl.h> #include <linux/file.h> void myfile(){ struct file* filp; long size; char *data; loff_t pos; filp = filp_open("/tmp/cmd", 0, 0); size = filp->f_dentry->d_inode->i_size; data = vmalloc(size); memset(data, 0, sizeof(size)); generic_file_read(filp, data, size, &pos); printk("/tmp/cmd found : %s\n", data); vfree(data); filp_close(filp, current->files); ...
근데,, 오류는 없는데, 파일내용이 비었네요.
vfs_read 는 익스포트되어 있지도 않아서..
찾다가 generic_file_read 를 따라서 사용해봤는데..
잘 안되는군요..
뭐가 잘못된건지 바른 가이드를 제시해주시면 정말 고맙겠습니다.
(_ _) //
Forums:
자문자답하게 되는군요.. 이틀만에..
하하 .. ^^
문제는 pos 문제였어요.
&pos 대신에..
&filp->f_pos 를 줘야 제대로 된 값이 들어가는걸..
또 함수는 저걸 안써도 이미 링크되어 있기 때문에..
filp->f_op->read(...); 써도 될거 같구요..
힘내세요.
댓글 달기