seeking into /dev/{null,zero}

John Baldwin jhb at
Tue Feb 22 17:51:36 UTC 2011

On Tuesday, February 22, 2011 11:46:05 am Garrett Cooper wrote:
> (Please bottom post)
> On Tue, Feb 22, 2011 at 8:31 AM, Andrew Duane <aduane at> wrote:
> > I thought seeking past EOF was valid; writing something creates a file 
with a hole in it. I always assumed that was standard semantics.
>     That's with SET_HOLE/SET_DATA though, correct? If so, outside of
> that functionality I would assume relatively standard POSIX semantics.

Err, no, you can always seek past EOF and then call write(2) to extend a file 
(it does an implicit ftruncate(2)).  SEEK_HOLE and SEEK_DATA are different, 
they are just used to discover sparse regions within a file.

From the manpage:

     The lseek() system call allows the file offset to be set beyond the end
     of the existing end-of-file of the file.  If data is later written at
     this point, subsequent reads of the data in the gap return bytes of zeros
     (until data is actually written into the gap).

John Baldwin

More information about the freebsd-hackers mailing list