title: What does fget_light in Linux work?
body: <p>I'm studying about System Calls in Linux and I read the read() System Calls. </p>
  
  <pre><code>SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
  {
      struct file *file;
      ssize_t ret = -EBADF;
      int fput_needed;
  
      file = fget_light(fd, &amp;fput_needed);
      if (file) {
          loff_t pos = file_pos_read(file);
          ret = vfs_read(file, buf, count, &amp;pos);
          file_pos_write(file, pos);
          fput_light(file, fput_needed);
      }
  
      return ret;
  }
  </code></pre>
  
  <p>This is the definition of fget_light()</p>
  
  <pre><code>struct file *fget_light(unsigned int fd, int *fput_needed)
   {
           struct file *file;
           struct files_struct *files = current-&gt;files;
  
           *fput_needed = 0;
           if (likely((atomic_read(&amp;files-&gt;count) == 1))) {
                   file = fcheck_files(files, fd);
           } else {
                   rcu_read_lock();
                   file = fcheck_files(files, fd);
                   if (file) {
                           if (atomic_long_inc_not_zero(&amp;file-&gt;f_count))
                                   *fput_needed = 1;
                           else
                                   /* Didn't get the reference, someone's freed */
                                   file = NULL;
                   }
                   rcu_read_unlock();
           }
  
           return file;
   }
  </code></pre>
  
  <p>Can you explain me, what does fget_light do?</p>