Bogofilter simulator.

Matthias Andree matthias.andree at gmx.de
Tue Feb 4 00:43:12 CET 2003


Here's the code I promised. I pressed y)es,send before a)ttach...

BTW, it poisons the page, so no cheating with holes in files...

-- 
Matthias Andree
-------------- next part --------------
#define _XOPEN_SOURCE 500
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>

#define PN "simbf"

void die(void)
{
    perror(PN);
    exit(EXIT_FAILURE);
}

int main(void)
{
    int fd = 1;

    /* seed PRNG */
    {
	struct timeval tv;
	if (gettimeofday(&tv, NULL)) die();
	srand(tv.tv_usec);
    }

    /* print pattern */
    {
	int i;
#define PAGES  ((double)5000)
#define WRITES ((double)500000)
#define PAGESIZE 4096
	char *p = calloc(PAGESIZE, 1);
	for (i = 0; i < WRITES ; i++) {
	    int j = PAGES/WRITES*i*rand()/(RAND_MAX+1.0);
	    *(long *)p = j; /* poison page */
	    if (pwrite(fd, p, PAGESIZE, j * PAGESIZE) != PAGESIZE) die();
	}
    }
    if (fsync(fd)) die();
    exit(EXIT_SUCCESS);
}



More information about the bogofilter-dev mailing list