title: How Linux system calls interact with filesystem
body: <p>Lately I faced this excercise:</p>
  
  <blockquote>
    <p>Given this sequence of system calls in a Linux C language program:</p>
  </blockquote>
  
  <pre><code>fd = open("f123", O_RDWRT | O_CREAT, 0777);
  lseek(fd, 0x1000000L, 0);
  write(fd, &amp;fd, sizeof(int));
  </code></pre>
  
  <blockquote>
    <p>draw the file system data structures and <strong>disk blocks</strong> that are modified by these operations, considering a 4 KByte block size, and index block pointers of 4 bytes.</p>
  </blockquote>
  
  <p>For the first system call (<code>open</code>) I realized how it works and schematized it in this way:
  <a href="https://i.stack.imgur.com/YXRcM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YXRcM.png" alt="open system call"></a></p>
  
  <p>Now, skipping the <em>draw</em> part (I realize it would make difficult to answer), I'd like to understand how <code>lseek</code> and <code>write</code> works in term of inodes and index blocks (whatever they are).</p>
  
  <p>I tried figuring that <code>lseek</code> computes the correct inode (as block size is known), but still no clue on how it actually works.</p>