引用该博客的文章: http://my.oschina.net/toyandong/blog/123617
想在内核太读写文件,还没尝试是否成功
01 | static void filewrite( char * filename, char * data) |
02 | { |
03 | struct file *filp; |
04 | mm_segment_t fs; |
05 | filp = filp_open(filename, O_RDWR| O_APPEND| O_CREAT, 0644); |
06 | if (IS_ERR(filp)) |
07 | { |
08 | printk( "open error...\n" ); |
09 | return ; |
10 | } |
11 | fs=get_fs(); |
12 | set_fs(KERNEL_DS); |
13 | filp->f_op->write(filp, data, strlen (data),&filp->f_pos); |
14 | set_fs(fs); |
15 | filp_close(filp,NULL); |
16 | } |