- 论坛徽章:
- 0
|
回复 2# folklore
不好意思,我在改一下,主要就是在display的Probe裡呼叫read file的function
,這個function經過測試單獨寫成一個driver Probe是可以執行的,但是我現在把它變成function的方式就會卡在開機畫面,謝謝- mm_segment_t oldfs;
-
- struct file *openFile(char *path,int flag,int mode)
- {
- struct file *fp;
-
- fp=filp_open(path, flag, 0);
- if (fp) return fp;
- else return NULL;
- }
-
- int readFile(struct file *fp,char *buf,int readlen)
- {
- if (fp->f_op && fp->f_op->read)
- return fp->f_op->read(fp,buf,readlen, &fp->f_pos);
- else
- return -1;
- }
-
- int closeFile(struct file *fp)
- {
- filp_close(fp,NULL);
- return 0;
- }
-
- void initKernelEnv(void)
- {
- oldfs = get_fs();
- set_fs(KERNEL_DS);
- }
-
- int readfile(void)
- {
- char buf[1024];
- struct file *fp;
- int ret;
-
- initKernelEnv();
- fp=openFile("/system/abc.txt",O_RDONLY,0);
- if (fp!=NULL)
- {
- memset(buf,0,1024);
- if ((ret=readFile(fp,buf,1024))>0)
- printk("buf:%s\n",buf);
- else printk("read file error %d\n",ret);
-
- closeFile(fp);
- }
- set_fs(oldfs);
- return 0;
- }
-
- void main() //假設為display的主程式(Probe)
- {
- int ret;
-
- ret=readfile(); 這是我呼叫上面的function
- }
复制代码 |
|