Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>"loff_t" is a "long offset", i.e., a seek position that unifies the crazy diversity of <code>off_t</code>, <code>off64_t</code>, and so on, so that drivers can just use loff_t and not worry about it.</p> <p>The pointer itself, at the time you get into the driver, points to the offset provided by the user (assuming it's user code doing the driver access—technically the kernel can provide its own, but the user case is the one to think about) via <code>lseek</code> or <code>llseek</code> or <code>lseek64</code>, etc., and then by ordinary read and write operations. Consider the case of a regular on-disk file: when you first <code>open</code> the file, you (as a user) get the kernel to provide a data structure that keeps track of your current position in the file, so that if you <code>read</code> or <code>write</code> some bytes, the next <code>read</code> or <code>write</code> picks up from where you left off.</p> <p>Furthermore, if you <code>dup</code> the file descriptor, or do the equivalent by (e.g.) <code>fork</code> and <code>exec</code> in terms of running a sequence of commands, that seek-position is shared by all the inheriting processes. Hence, at the shell prompt, the command:</p> <pre><code>(prog1; prog2; prog3) &gt; outputfile </code></pre> <p>creates an output file, then <code>dup</code>s the descriptor to the three programs, so that output that <code>prog2</code> writes goes into the file immediately after the output from <code>prog1</code>, and output from <code>prog3</code> follows the other two—all because all three separate processes share the same underlying kernel data structure with the same internal <code>loff_t</code>.</p> <p>The same applies to device driver files. When your read and write functions are called, you receive the "current offset" as provided by the user, and you can (and should) update it as needed ... assuming there is any need (e.g., you want to provide users with the appearance of a regular file, including the fact that seek offsets move as you read and write). If the device has some logical application of the seek offset, you can use that here.</p> <p>Of course, there's a lot more to device drivers, which is why there are entire book-chapters on this stuff (q.v.). :-)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload