File Copy using filp_open

2019-06-02 02:50发布

问题:

I want to make the syscall using filp_open!!

purpose is file copy!!

but a problem is that i can't find end of file.

opersting system is redhat9 and kernel version is 2.6.32!!

i want to help to me 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;

}