linux下读写文件如果加上O_DIRECT标记的话会返回错误(bad address),但是去掉的话就没问题,有人遇到过吗
static int __init init(void)
{
struct file *fp = NULL;
int i = 100;
loff_t pos = 0;
char *buf = NULL;
size_t rwsize = PAGE_SIZE;
struct page *pages = NULL;
fp = filp_open("/share/file", O_RDWR | O_DIRECT, 0);
if(fp == NULL){
printk("filp_open error\n");
return 0;
}
// buf = kmalloc(rwsize, GFP_ATOMIC);
pages = alloc_page(GFP_ATOMIC);
if(!pages){
return 0;
}
buf = kmap_atomic(pages);
memset((char *)buf, 'A', rwsize);
printk("hintsoft:begin %p %d\n",(void *)buf, (int)PAGE_SIZE);
while(i--){
ssize_t size = kernel_write(fp, buf, rwsize, pos);
printk("hintsoft:writesize = %d\n",(int)size);
vfs_llseek(fp, 0, SEEK_SET);
}
filp_close(fp,NULL);
//kfree(buf);
kunmap_atomic(buf);
return 0;
}
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)