一、通过call_usermodehelper调用用户层脚本
env[0] = "HOME=/";
env[1] = "PATH=/sbin:/bin:/usr/bin:/system/bin";
env[2] = NULL;
argv[0] = "/bin/sh";
argv[1] = "/etc/write_data/wlan_file.sh";
argv[2] = NULL;
call_usermodehelper(argv[0], argv, env, UMH_NO_WAIT);
二、通过内核函数filp_open操作用户层文件
struct file *fd = NULL;
mm_segment_t fs;
loff_t pos = 20;
int bmp_size = 0;
struct kstat stat;
fs = get_fs();
set_fs(KERNEL_DS);
fd = filp_open("/data/test.bmp", O_RDONLY, 0);
if (IS_ERR(fd)) {
pr_info(
"open failed");
set_fs(fs);
return -1;
}
stat = vfs_stat("/data/test.bmp", &stat);
bmp_size = (int) stat.size;
vfs_read(fd, ptr, 1284800, &pos); //也可以用vfs_write、vfs_stat等一系列函数,定义在include/linux/fs.h
filp_close(fd, NULL);
fd = NULL;
set_fs(fs);