Copying a file with filp_open

I want to do syscall using filp_open !!

The goal is to copy the file.

but the problem is I can't find the end of the file.

the control system is redhat9 and the kernel version is 2.6.32!

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

}

      

+1


source to share





All Articles