我想使用filp_open !!
进行系统调用目的是文件复制!!
但问题是我无法找到文件结尾。
操作系统是redhat9,内核版本是2.6.32 !!
我想帮助我PLZ !!!!
#include <linux/kernel.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#define BUF_SIZE 4096
asmlinkage int sys_forensiccopy(char *src, char *dst)
{
struct file *input_fd;
struct file *output_fd;
size_t ret_in, ret_out; /* Number of bytes returned by read() and write() */
char buffer[BUF_SIZE]={0,}; /* Character buffer */
int ret;
int i;
mm_segment_t old_fs;
/* Create input file descriptor */
input_fd = filp_open(src, O_RDONLY, 0);
if (input_fd == -1) {
printk ("[!] Can not open the src file");
return 2;
}
/* Create output file descriptor */
output_fd = filp_open(dst, O_WRONLY|O_CREAT, 0644);
if(output_fd == -1){
printk("[!] Can't crate the dstfile");
return 3;
}
old_fs=get_fs();
set_fs(get_ds());
printk("%d\n", input_fd->f_op->read(input_fd,buffer,BUF_SIZE,&input_fd->f_pos));
set_fs(old_fs);
/* Close file descriptors */
filp_close(input_fd,0);
filp_close(output_fd,0);
return 0;
}