#include <linux/fs.h>
#include <linux/uaccess.h>
struct file *fp;
char p_buf[12]="run here!!\n",*string;
mm_segment_t fs;
int len;
loff_t pos;
fp =filp_open("/var/test.txt",O_RDWR | O_CREAT|O_TRUNC ,0666);
if (IS_ERR(fp)){
printk("create file error/n");
goto here;
}
fs =get_fs();
set_fs(KERNEL_DS);
pos =0;
vfs_write(fp,p_buf, strlen(p_buf), &pos);
filp_close(fp,NULL);
内核写文件
最新推荐文章于 2024-04-21 06:15:00 发布