title: File Copy using filp_open
body: <p>I want to make the syscall using filp_open!!</p>
  
  <p>purpose is file copy!!</p>
  
  <p>but a problem is that i can't find end of file.</p>
  
  <p>opersting system is redhat9 and kernel version is 2.6.32!!</p>
  
  <p>i want to help to me plz!!!!</p>
  
  <pre><code>#include &lt;linux/kernel.h&gt;
  #include &lt;linux/fs.h&gt;
  #include &lt;asm/uaccess.h&gt;
  
  #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-&gt;f_op-&gt;read(input_fd,buffer,BUF_SIZE,&amp;input_fd-&gt;f_pos));
  
  
  set_fs(old_fs);
  
  /* Close file descriptors */
  filp_close(input_fd,0);
  filp_close(output_fd,0);
  
      return 0;
  
  }
  </code></pre>