/* fraggle - Fragment file system * Copyright (C) 2000, 2001 Martin K. Petersen * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include static char const rcsid[] = "$Id: fraggle.c,v 1.5 2001/11/19 04:16:29 mkp Exp $"; /* Put 256 files in each dir. Linear structures suck! */ #define FPD 256 static void barf (const char *s) { fprintf (stderr, "\n"); fprintf (stderr, s); fprintf (stderr, "\n\nThe trash heap has spoken. Nyeah...\n\n"); fflush (stderr); exit (EXIT_FAILURE); } static void usage (void) { fprintf (stderr, "Fraggle - Fragment file system\n\n"); fprintf (stderr, "Written by Martin K. Petersen \n\n"); fprintf (stderr, "Usage:\n"); fprintf (stderr, " fraggle []\n\n"); fprintf (stderr, " where and are file sizes in blocks.\n\n"); fprintf (stderr, " If is specified, fraggle will create randomly\n"); fprintf (stderr, " sized files between and the given value.\n"); fflush (stderr); exit (EXIT_SUCCESS); } int main (int argc, char *argv[]) { static struct statfs sfs; static char dir[128]; static char path[256]; static long inodes; static long blocks; static long i = 0; static long j = 0; static long dirs = 0; static long file = 0; static int min = 0; static int max = 0; if (argc < 2 || argc > 3) usage(); min = atoi (argv[1]); if (argc == 3) max = atoi (argv[2]); if (min < 0) barf ("Minimum file size is 0 KB!"); if (max < 1 || max < min) max = min; if (mkdir ("FRAGGLE", 0755)) barf ("Can't create FRAGGLE directory!"); if (chdir ("FRAGGLE")) barf ("Can't cd to FRAGGLE directory!"); if (statfs (".", &sfs)) barf ("Can't statfs() device!"); inodes = sfs.f_ffree; blocks = sfs.f_bavail; printf ("Creating files...\n"); /* While we have enough inodes and blocks ... */ while (sfs.f_ffree > 4 && sfs.f_bavail > max) { static int fd; static int numios; int io = 0; /* Create a new directory once in a while */ if (i % FPD == 0) { if (! snprintf (dir, 127, "dir%08ld", dirs)) barf ("Can't snprintf dir name!"); if (mkdir (dir, 0755)) barf ("Can't create subdirectory!"); dirs++; file = 0; } /* Creat file */ if (! snprintf (path, 255, "%s/file%08ld", dir, file)) barf ("Can't snprintf file name!"); if ((fd = open (path, O_CREAT|O_RDWR)) < 0) barf ("Can't open file!"); /* File size */ if (max > min) numios = min + (int) ((float) max * rand() / (RAND_MAX + 1.0)); else numios = min; printf ("IO: %d - Numios: %d\n", io, numios); /* Fill 'er up - We have to write on all block * boundaries to actually allocate blocks */ while (io < numios) { if (lseek (fd, sfs.f_bsize, SEEK_CUR) < sfs.f_bsize) barf ("Seek failed!"); if (write (fd, "X", 1) < 1) barf ("Write failed!"); io++; } close (fd); /* Check inode/block availability */ if (statfs (".", &sfs)) barf ("Can't statfs() device!"); i++; file++; printf ("\r%8ld/%8ld - %8ld/%8ld", sfs.f_ffree, inodes, sfs.f_bavail, blocks); } printf ("\nUnlinking half of them...\n"); dirs = 0; for ( j=0 ; j