Reserving Space on Disk

Istvan Mohos istvan at hhb.UUCP
Thu Jul 19 00:10:17 AEST 1990



martin at mwtech.UUCP (Martin Weitzel) writes:
>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.

This, and the majority of the responses, focus on the merits of byte
copying.  The real issue is the lack of speed in physically accessing
the disk.  The program segments posted by others, or your algorithm
converted to C (with impending corrections from Conor P. Cahill :-)

#include <stdio.h>
#include <sys/file.h>
#define FOURMEG 4194304
#define DBLK    512
#define ITER    (FOURMEG/DBLK)
main()
{
    long lseek();
    char c = 0;
    register int fd, ri;

	if ((fd = open("foo", O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1)
		perror("can't write to"), exit (1);
    for (ri = ITER; --ri >= 0; write (fd, &c, 1))
        if (lseek (fd, (long)DBLK-1, 1) == -1)
    		perror("seek error"), exit (2);
    exit (0);
}

are all slower then writing 4 Meg in one disk access.
-- 
        Istvan Mohos
        ...uunet!pyrdc!pyrnj!hhb!istvan
        RACAL-REDAC/HHB 1000 Wyckoff Ave. Mahwah NJ 07430 201-848-8000
======================================================================



More information about the Comp.unix.wizards mailing list