Re: Undefined behavior? Or just a feature?

Randall R Schulz (rrschulz@cris.com)
Sat, 14 Aug 1999 22:33:53 -0700


Hello,

Well, the "feature" doesn't often get used deliberately, but it has
been an aspect of the UNIX file system since at least Version 6
PDP-11 Unix. I believe its primary motivation was to save disk space.
High-performance applications like DBMSs usually need more control
over file allocation than conventional Unix file systems provide and
Unix sparse files are a severe monkey wrench in the gears.

If you write anything, zeroes or not, aligned or not, in any size
granularity, the blocks get allocated. Only when you seek past the
end of the file and then write does a file with holes (a "sparse"
file) result.

That, for example, is why you need to take special care when creating
a swap file (not a swap partition)--all the blocks that logically
comprise the file must be allocated to that file before it can be
activated as a swap file.

Copying /dev/zero is one way to do create a file full of zeroes with
all its blocks actually allocated. Using dd with the seek=n argument
will create a file with holes. Naturally, one can always write C and
other programs with low-enough level access to the file-related
system calls to exert control over this aspect of the file system
behavior.

Randy Schulz
Mountain View, CA USA

At 00:01 -0400 8/15/99, Paradox wrote:
>Hmm, is this feature used often? Would it work the same way if one wrote a
>bunch of '\0's into the file or does it only work when you seek to a far
>position and then start writing?
>
>
>Regards, Dave
>
>----- Original Message -----
>From: Alan Cox <alan@lxorguk.ukuu.org.uk>
>To: Paradox <paradox3@maine.rr.com>
>Sent: Saturday, August 14, 1999 7:00 PM
>Subject: Re: Undefined behavior? Or just a feature?
>
> > Linux only stores the blocks actually containing data. Its a feature

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/