title: How to convert size_t to char* in kernel C?
body: <p>I use a <code>size_t</code> variable in my kernel module. when I want to write it to a file it must be cast to <code>char*</code> according to <code>vfs_write</code> signature:</p>
  
  <pre><code>extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
  </code></pre>
  
  <p>I use this function that uses <code>vfs_write</code> (I found it on internet):</p>
  
  <pre><code>int file_write(struct file *file, unsigned long long offset, unsigned 
  char *data, unsigned int size) 
  {
      mm_segment_t oldfs;
      int ret;
  
      oldfs = get_fs();
      set_fs(get_ds());
  
      ret = vfs_write(file, data, size, &amp;offset);
  
      set_fs(oldfs);
      return ret;
  }
  </code></pre>
  
  <p>the <code>nbytes</code> variable is <code>size_t</code> I try <code>(char *)</code> cast for convert <code>nbytes</code> to <code>char*</code> but the kernel immediately crashes. here is my code.</p>
  
  <pre><code>index_filename = "/home/rocket/Desktop/index_pool";
  index_file = file_open(index_filename,O_WRONLY | O_CREAT, 0644);
  if(index_file == NULL)
      printk(KERN_ALERT "index_file open error !!.\n");
  else{
      // file_write(index_file, 0, nbytes, nbytes); =&gt; this crashs also
      file_write(index_file, 0, (char*) nbytes, 100);
      file_close(index_file);
  }
  </code></pre>
  
  <p>Is there a way to safely convert <code>size_t</code> type to <code>char *</code> one in Kernel ?</p>