title: How much information is actually stored in a file descriptor?
body: <p>This may sound like an odd question, but when I go and open a file:</p>
  
  <pre><code>int fd;
  fd = open("/dev/somedevice", O_RDWR);
  </code></pre>
  
  <p>What exactly am I getting back? I can see the man page says:<br>
  <code>The open() function shall return a file descriptor for the named file that is the lowest file descriptor not currently open for that process</code></p>
  
  <p>But is that it? Is it just an <code>int</code> or is there data attached to it behind the scenes? The reason I'm asking is I found some code (Linux/C) where we're opening the file from user space:</p>
  
  <pre><code>//User space code:
  int fdC;
  
  if ((fdC = open(DEVICE, O_RDWR)) &lt; 0) {
      printf("Error opening device %s (%s)\n", DEVICE, strerror(errno));
      goto error_exit;
  }
  while (!fQuit) {
      if ((nRet = read(fdC, &amp;rx_message, 1)) &gt; 0) {
  </code></pre>
  
  <p>then on the kernel end, the file operations for this module (which supplies the fd) map reads to the <code>n_read()</code> function:</p>
  
  <pre><code>struct file_operations can_fops = { 
      owner:      THIS_MODULE,
      lseek:  NULL, 
      read:   n_read,
  </code></pre>
  
  <p>Then the file descriptor is used in the <code>n_read()</code>, but it's being accessed to get data:</p>
  
  <pre><code>int n_read(struct file *file, char *buffer, size_t count, loff_t *loff)
  {
      data_t * dev;
  
      dev = (data_t*)file-&gt;private_data;
  </code></pre>
  
  <p>So... I figure what's happening here is either:</p>
  
  <p>A) a file descriptor returned from <code>open()</code> contains more data than just a descriptive integer value<br>
  Or<br>
  B)The mapping between a call to "read" in the user space isn't as simple as I'm making it out to be and there's some code missing in this equation.</p>
  
  <p>Any input that might help direct me?</p>