Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 1 Feb 2016 07:57:40 -0800
From:      Maxim Sobolev <sobomax@FreeBSD.org>
To:        freebsd-fs@freebsd.org, Kirk McKusick <mckusick@mckusick.com>, kib@freebsd.org
Subject:   Inconsistency between lseek(SEEK_HOLE) and lseek(SEEK_DATA)
Message-ID:  <CAH7qZfuZNZ%2BJDPC4D1sjXj2tFxZKBiYVyTp-Y3UUUoq9er%2BWYQ@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hi,

I've noticed that lseek() behaved inconsistently with regards to SEEK_HOLE
and SEEK_DATA operations. The SEEK_HOLE on a data-only file returns st_size
(i.e. EOF + 1), while the SEEK_DATA on a hole-only file returns -1 and sets
errno to ENXIO. The latter seems to be a documented way to indicate that
the file has no more data sections past this point.

My first idea was that somehow most files has a hole attached to its end to
fill up the FS block, but that does not seem to be a case. Trying to
SEEK_HOLE past the end of any of those data-only files produces an error
(i.e. lseek(fd, st_size, SEEK_HOLE) == -1).

In short, for some reason I cannot get proper ENXIO from the SEEK_HOLE.
What currently returned implies that there is 1-byte hole attached to each
file past its EOF and that does not smell right.

All tests are done on UFS, fairly recent 11-current.

-Max



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAH7qZfuZNZ%2BJDPC4D1sjXj2tFxZKBiYVyTp-Y3UUUoq9er%2BWYQ>