Releasing blocks from a file

Chris Torek chris at mimsy.UUCP
Sat May 20 00:47:13 AEST 1989


In article <461 at anvil.oz> michi at anvil.oz (Michael Henning) writes:
>I would like to know why this has not been generalised to allow
>*any* block of a file to be released.

That task is harder (but not impossible; and truncating to an arbitrary
size is harder than truncating to zero).  It might be worth trying.
However:

>... system call something like:
>
>	release(fd, offset, num_blocks)
>	int fd;
>	off_t offset;
>	unsigned num_blocks;

File system calls should always be specified in bytes, not blocks.

>The idea is to specify that num_blocks are to be released beginning at
>the specified offset (which must be aligned on a file system block boundary).

The call should really `zero out' the part of the file from the
given offset to the end of offset+size:

	int wzero(int fd, int offset, size_t size)

where the zeroing would be done by freeing allocated blocks whenever
this region spans full blocks; the system call itself is then immune
to changes in the file system representation (would work over extents,
e.g.).

You could then reduce this system call to

	lseek(fd, offset, 0), write(fd, buffer_containing_zeroes, size)

by simply making write() notice blocks of zeroes.  (But you then have
to fix /etc/restore :-) )
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.wizards mailing list