I want to read input.txt
's content & write it into output.txt
This is my code, and it can makefile after all.
Linux Kernel 15.11 version
So it can't use vfs_read
& vfs_write
I think that I can store the content from input.txt
with ret
And use ret
to write the content with kernel_write
into output.txt
But the type of ret
is ssize_t
& in_buf
is size_t
So, it can't fit into the kernel_write function.
The function for kernel_write
& kernel_read
format is from the link
Read/write files within a Linux kernel module
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <linux/kernel.h>
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Reversing text from Jackson");
MODULE_VERSION("0.1");
void *in_buf;
const void *out_buf;
static int __init test_start(void){
struct file *i_fp, *o_fp;
loff_t pos;
size_t count1;
ssize_t ret;
printk(KERN_INFO "start converting...\n");
i_fp = filp_open("/home/j0000/Desktop/file/input.txt",O_RDWR | O_CREAT, 0644);
o_fp = filp_open("/home/j0000/Desktop/file/output.txt",O_RDWR | O_CREAT, 0644);
if (IS_ERR(i_fp)){
printk(KERN_INFO "intput file open error/n");
return -1;
}
if (IS_ERR(o_fp)){
printk(KERN_INFO "output file open error/n");
return -1;
}
pos = 0;
ret = kernel_read(i_fp, in_buf, count1, &pos);
pos = 0;
kernel_write(o_fp, ret, count1, &pos);
filp_close(i_fp, NULL);
filp_close(o_fp, NULL);
return 0;
}
static void __exit test_end(void){
printk(KERN_INFO "Ending~\n");
}
module_init(test_start);
module_exit(test_end);