File offset
A file offset is a byte position measured from the beginning of a file, used as a current I/O cursor or an explicit positional-access argument.
The current cursor belongs to the open file description. Duplicating a descriptor shares that cursor; opening the file separately creates a new open file description. A descriptor number and an offset therefore identify different parts of an I/O request. [1] [2]
For regular files, lseek can position the cursor beyond EOF without enlarging the file. SEEK_SET, SEEK_CUR and SEEK_END interpret the supplied displacement relative to the beginning, current position and file size respectively. A byte position does not describe physical allocation or a device-sector address. [3]
pread and pwrite supply an explicit position without advancing the current cursor. A separate lseek then read sequence needs coordination if another holder can move that cursor between calls. [4] [2]
Relations
- related
- Open file description, File descriptor, pread, pwrite, Short read, Sparse file, File truncation
Limitations
- Not a file length or a measure of consumed or allocated bytes.
- Independent cursors do not isolate readers from changes to file content.
Citations
- Linux man-pages 6.19: open(2), open file descriptions
- Linux man-pages 6.19: dup(2), shared cursor state
- Linux man-pages 6.19: lseek(2), origins and seeking beyond EOF
- Linux man-pages 6.19: pread(2), explicit-position I/O
Sources & caveats
- The byte-position concept is distinct from the open file description that stores a current cursor.