#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/init.h>
static int save_data_to_file(const char* save_file_name, char *buff, int size)
{
struct file *fp = NULL;
mm_segment_t fs;
loff_t pos;
printk("save_file_name = %s!\n",save_file_name);
fp = filp_open(save_file_name, O_RDWR | O_CREAT, 0644);
if (IS_ERR(fp))
{
printk("create file error/n");
printk("%d\n", PTR_ERR(fp));
*buff=0;
return 0;
}
fs =get_fs();
set_fs(KERNEL_DS);
pos =0;
vfs_write(fp, buff, size, &pos);
filp_close(fp,NULL);
set_fs(fs);
return 0;
}
static int read_data_from_file(const char* save_file_name, char *buff, int size)
{
struct file *fp = NULL;
mm_segment_t fs;
loff_t pos;
printk("read file_name = %s!\n",save_file_name);
fp = filp_open(save_file_name, O_RDONLY, 0644);
if (IS_ERR(fp))
{
printk("create file error/n"); printk("%d\n", PTR_ERR(fp));
*buff=0;
return 0;
}
fs =get_fs();
set_fs(KERNEL_DS);
pos =0;
vfs_read(fp, buff, 1, &pos);
filp_close(fp,NULL);
set_fs(fs);
return 0;
}