内核写文件

来源:互联网 发布:怎么开淘宝直播间 编辑:程序博客网 时间:2024/06/10 22:04
#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);
0 0
原创粉丝点击