Reserving Space on Disk
Martin Weitzel
martin at mwtech.UUCP
Tue Jul 17 06:09:43 AEST 1990
In article <13422 at ulysses.att.com> cjc at ulysses.att.com (Chris Calabrese[mav]) writes:
:In article <MOSS.90Jul15190502 at ibis.cs.umass.edu>, moss at cs.umass.edu (Eliot Moss) writes:
:> [ ... ]
:>
:> char buf[ONE_K];
:> int i;
:>
:> for (i = 0; i < FOUR_K; ++i)
:> write (fd, buf, ONE_K);
:> [ ... ]
:
:BTW, while reading the various ways to write some large space on the
:disk which have been passing by, I thought I'd pass a related tidbit
:along. On many machine architectures, byte copying from user space to
:kernel space is quite a bit faster if the buffer is word aligned.
:
:For this reason, it is better to use malloc to get your buffer than to
:allocate it off of the stack (as malloc always returns maximally
:aligned memory). Of course, this assumes that you'll use the buffer
:more than once, as the time to malloc() is around the same order as
:the time to deal with the non-aligned bytes at the beginning and end
:of the buffer.
What is wrong with the following approach (at least on non-BSD-ish
file systems)?
while file has not desired size
lseek(2) from current position forward
disk-block-size bytes minus 1 and write(2)
one byte
IMHO this should fill the disk and avoids much copying from user-space.
--
Martin Weitzel, email: martin at mwtech.UUCP, voice: 49-(0)6151-6 56 83
More information about the Comp.unix.wizards
mailing list