Subject: Re: lseek() extension for spare files
To: Jason Thorpe <>
From: Bill Studenmund <>
List: tech-kern
Date: 09/21/2006 17:07:38
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Sep 21, 2006 at 01:51:28PM -0700, Jason Thorpe wrote:
> On Sep 20, 2006, at 6:44 PM, Reinoud Zandijk wrote:
> So, it looks like these new whence arguments are essentially designed =20
> to enumerate the holes or filled regions of the file.
> I don't see anything particularly wrong with having it (note I have =20
> not yet reviewed the actual patch), but what's the application usage?

Ok, I'm assuming Jason understands why we want to know about holes and=20
was asking more how the application would use it, not why it would use=20
it. :-)

I expect that how you'd use it is something like (warning, pseudo-code,=20
lots of stuff glossed over):

	fd =3D open("the/file", O_RDONLY, 0);

	fstat(fd, &statblock);  /* Now know file's size */

	if (statblock.st_size =3D=3D 0) {
		/* Handle a zero-length file */

	o_data =3D lseek(fd, 0, SEEK_DATA);

	if (o_data) {
		/* We started with a hole */
		o_hole =3D 0;
	} else {
		/* We started with data */
		o_hole =3D lseek(fd, 0, SEEK_HOLE);

	o =3D 0;

	while (o < statblock.st_size) {
		if (o =3D=3D o_data) {
			/* o through o_hole is a run of data */;
			o =3D o_hole;
			o_data =3D lseek(fd, o_hole, SEEK_DATA);
		} else {
			/* o through o_data is a hole */
			o =3D o_data;
			o_hole =3D lseek(fd, o_data, SEEK_HOLE);

I wrote all the above out to make sure I understand how this is supposed=20
to be used, and, assuming I'm right, to hopefully explain it to others.=20

The above's pseudo-code, and there are other ways we could have handled=20
the hopping between holes and data runs.

Take care,


Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.4.3 (NetBSD)