title: How do the files in '/dev' match Linux's model of a device?
body: <p>Here is my understanding in opening to a file for reading/writing.</p>
  
  <p>In the application layer, I can invoke the <code>fopen()</code> function.</p>
  
  <p>The <code>fwrite()</code> function will invoke a system call <code>open()</code>.</p>
  
  <p>After the OS receives the <code>open()</code> call, it will pass the command to VFS(virtual file system). </p>
  
  <p>VFS looks up the file name, including any directories needed and does the necessary access checks. </p>
  
  <p>If this is in RAM cache then no disk access is needed. If not, the VFS sends a read request to the specific file system which is probably EXT4. </p>
  
  <p>Then the EXT4 file system driver will determine in what disk block that directory is located in. It will then send a read command to the disk device driver.</p>
  
  <hr>
  
  <p>So now let's say I want to read an <em>i2c device A</em> attached to the board. And the file directory is <em>/dev/i2c/A</em></p>
  
  <ul>
  <li><p>Is there a major number for all devices? For example, Linux OS  sets 180 as the major number for USB. So at the device side, is there a major number 180 in each USB device? </p></li>
  <li><p>If the answer to 1st question is NO, then how can the Linux OS determine which type of <em>device A</em> is, is it just according to the file directory? </p></li>
  <li><p>I think the answer to 2nd question maybe: at the boot initialization stage, there are some certain codes that have already mount that port to the file system using something like export()? So in fact, right after the booting stage, file directory <em>/dev/i2c/A</em> exists there and it is bind with a major number for i2c devices. So when I want to open dev/i2c/A, the OS will find the right i2c driver for me, not the SPI or USB driver.I'm not sure about this part, i need more information on this.</p></li>
  <li><p>The above situation happens when the device is mounted to the file system right after the booting stage. so what happened if I have a usb, how can this usb be mounted to the file system with the right major number 180 after it is plugged in? And I guess there is a irq when the usb is plugged in before the mounting stage starts?</p></li>
  </ul>