Reserving Space on Disk

Jonathan I. Kamens jik at athena.mit.edu
Mon Jul 16 10:59:12 AEST 1990


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);

  I wrote the short program below (which I call "fillspace") when I was
testing some bug fixes for bugs that would exhibit themselves only when
a disk partition was almost full.  I needed to be able to fill a
specific amount of disk space in order to get into that situation easily.

  I've found it useful in other situations as well.  How to use it is
fairly obvious from the usage message in the code.

Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710

------------------------------------------------------------------

#include <stdio.h>

extern char *malloc();

main(argc, argv)
int argc;
char *argv[];
{
     int k;
     char *garbage;
     int blocksize;
     int block;
     int i;
     
     if (argc < 2 || argc > 3) {
	  fprintf(stderr, "Usage: %s blocks [blocksize]\n", argv[0]);
	  exit(1);
     }

     if (argc == 3)
	  blocksize = atoi(argv[2]);
     else
	  blocksize = BUFSIZ;

     k = atoi(argv[1]) * blocksize;

     if (k <= 0 || blocksize <= 0) {
	  fprintf(stderr, "%s: blocks and blocksize must be positive\n",
		  argv[0]);
	  exit(1);
     }
     
     block = 4 * blocksize;
     garbage = malloc((unsigned) block);
     if (! garbage) {
	  perror("malloc");
	  exit(1);
     }

     for (i = 0; i < block; i++)
	  garbage[i] = 'a';

     while (k) {
	  while (k >= block) {
	       fwrite(garbage, 1, block, stdout);
	       k -= block;
	  }
	  block /= 2;
     }

     exit(0);
}



More information about the Comp.unix.wizards mailing list