title: How does device_open in file_operations work?
body: <p>I saw <a href="http://www.tldp.org/LDP/lkmpg/2.4/html/c577.htm" rel="nofollow noreferrer">this</a> example online that shows how to create a character device in linux, and I'm trying to understand how calling open by the user affects the device_open function. </p>
  
  <p>The file_operations struct is define as follows:</p>
  
  <pre><code>static struct file_operations Fops = {
   .read = device_read,
   .write = device_write,
   .open = device_open,
   .release = device_release,};
  </code></pre>
  
  <p>And the device_open function receives the following arguments: </p>
  
  <p><code>static int device_open(struct inode *inode, struct file *file)</code></p>
  
  <p>After creating a device file with mknod, the user can open the device file name: </p>
  
  <pre><code>fd = open(DEVICE_FILENAME, 0);
  </code></pre>
  
  <p>What I don't understand is how this call to open makes device_open receive the inode and file it needs.</p>
  
  <p>Thank you!</p>