Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!ucbvax!bloom-beacon!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.wizards Subject: Re: Reserving Space on Disk Message-ID: <1990Jul16.005912.7198@athena.mit.edu> Date: 16 Jul 90 00:59:12 GMT References: <563@hhb.UUCP> <1990Jul15.211608.26025@virtech.uucp> Sender: daemon@athena.mit.edu (Mr Background) Reply-To: jik@athena.mit.edu (Jonathan I. Kamens) Organization: Massachusetts Institute of Technology Lines: 75 In article , moss@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@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8495 Home: 617-782-0710 ------------------------------------------------------------------ #include 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); }