title: Using kernel_read & kernel_write to read input.txt's content & write it into output.txt
body: <p>I want to  read <code>input.txt</code>'s content &amp; write it into <code>output.txt</code></p>
  <p>This is my code, and it can makefile after all.</p>
  <p>Linux Kernel 15.11 version</p>
  <p>So it can't use <code>vfs_read</code> &amp; <code>vfs_write</code></p>
  <p>I think that I can store the content from <code>input.txt</code> with <code>ret</code></p>
  <p>And use <code>ret</code> to write the content with <code>kernel_write</code> into <code>output.txt</code></p>
  <p>But the type of <code>ret</code> is <code>ssize_t</code> &amp; <code>in_buf</code> is <code>size_t</code>
  So, it can't fit into the kernel_write function.</p>
  <p>The function for <code>kernel_write</code> &amp; <code>kernel_read</code> format is from the link</p>
  <p><a href="https://stackoverflow.com/questions/1184274/read-write-files-within-a-linux-kernel-module/53917617#53917617">Read/write files within a Linux kernel module</a></p>
  <pre><code>#include &lt;linux/module.h&gt;
  #include &lt;linux/init.h&gt;
  #include &lt;linux/fs.h&gt;
  #include &lt;asm/uaccess.h&gt;
  #include &lt;linux/kernel.h&gt;
  
  MODULE_LICENSE(&quot;GPL&quot;);
  MODULE_DESCRIPTION(&quot;Reversing text from Jackson&quot;);
  MODULE_VERSION(&quot;0.1&quot;);
  
  void *in_buf;
  const void *out_buf;
  
  static int __init test_start(void){
          struct file *i_fp, *o_fp;
          loff_t pos;
          size_t count1;
          ssize_t ret;
          printk(KERN_INFO &quot;start converting...\n&quot;);
          i_fp = filp_open(&quot;/home/j0000/Desktop/file/input.txt&quot;,O_RDWR | O_CREAT, 0644);
          o_fp = filp_open(&quot;/home/j0000/Desktop/file/output.txt&quot;,O_RDWR | O_CREAT, 0644);
          if (IS_ERR(i_fp)){
                  printk(KERN_INFO &quot;intput file open error/n&quot;);
                  return -1;
          }
          if (IS_ERR(o_fp)){
                  printk(KERN_INFO &quot;output file open error/n&quot;);
                  return -1;
          }
          pos = 0;
          ret = kernel_read(i_fp, in_buf, count1, &amp;pos);
          pos = 0;
          kernel_write(o_fp, ret, count1, &amp;pos);
          filp_close(i_fp, NULL);
          filp_close(o_fp, NULL);
          return 0;
  }
  
  static void __exit test_end(void){
          printk(KERN_INFO &quot;Ending~\n&quot;);
  }
  
  module_init(test_start);
  module_exit(test_end);
  </code></pre>