COHERENT manpages

This page displays the COHERENT manpage for chsize() [Change the size of a file].

List of available manpages
Index


chsize() -- System Call (libc)

Change the size of a file
int chsize(fd, size);
int fd; long size;

The COHERENT  system call chsize() changes the size  of the file associated
with the  file descriptor  fd to  be exactly size  bytes long.  If  size is
larger than the  file's initial size, then chsize() pads  the file with the
appropriate number  of extra  bytes.  If size  is smaller than  the initial
size, then  chsize() frees all  allocated disk blocks between  size and the
initial size.   The maximum file  size as set  by ulimit() is  in force for
calls to chsize().

With a  successful call, chsize()  returns 0; otherwise, it  returns -1 and
sets errno to an appropriate value.

See Also

libc,
open(),
ulimit()

Notes

When you  use chsize() to  shorten a file,  COHERENT frees all  disk blocks
beyond the new  end-of-file mark.  However, it does not  zero out the bytes
beyond the new  end-of-file in the last allocated disk  block.  If you wish
to obliterate a file, simply using  chsize() to reset its size to zero will
not do the trick.

When you use chsize() to lengthen  a file, the new bytes beyond the initial
size are  simply those bytes that  were in the final  disk block beyond the
original end-of-file  marker.  All additional  bytes beyond that  point are
zeroes.   The file  system will  not actually allocate  new disk  blocks to
accomodate the  new file size,  but rather will  create one or  more sparse
blocks.

The term sparse block refers to  the fact that in the COHERENT file system,
a disk  block that  would be all  zeroes need not  take up a  physical disk
block.  Rather, COHERENT marks the i-node to indicate that the block is all
zeroes, but  does not allocate a  physical block.  This saves  space on the
disk.

A sparse file, is a file that contains one or more sparse blocks.  The file
system handles sparse files correctly; however, the command fsck may return
the error message

    Possible File Size Error

for them.

If you lengthen  a file with chsize(), you may  create a sparse file, which
may in turn cause fsck to complain.