title: concurrent access to file linux
body: <p>I was looking at how a syscall read/write was done in linux, and i found this : </p>
  
  <pre><code>....
  loff_t pos = file_pos_read(f.file);
  ret = vfs_read(f.file, buf, count, &amp;pos);
  file_pos_write(f.file, pos);
  fdput(f);
  ...`
  </code></pre>
  
  <p>My questions are :</p>
  
  <p>Where did the locking go? I would have imaginated something like :</p>
  
  <pre><code>....
  lock(f.file);  // &lt;-- lock file struct
  loff_t pos = file_pos_read(f.file);
  ret = vfs_read(f.file, buf, count, &amp;pos);
  file_pos_write(f.file, pos);
  fdput(f);
  unlock(f.file);  // &lt;-- unlock file struct
  ...
  </code></pre>
  
  <p>If multiple threads try to read/write at the same time, they could read/write at the same offset ?</p>
  
  <p>If my understanding is correct, linux doesn't use any locking mechanism to protect the offset, is this POSIX compliant ?</p>
  
  <p>I did look at the POSIX specification, and found nothing about this case.</p>