File Copy using filp_open

耗尽温柔 提交于 2019-12-23 03:09:48

问题


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;

}

来源:https://stackoverflow.com/questions/23858801/file-copy-using-filp-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!