/* mkallraw.c
 *
 * $Id: mkallraw.c,v 1.4 2000/12/15 23:48:16 alderman Exp $
 *
 * This makes a bunch of files in the raw partition.
 */
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>

#include "global.h"

/* Mod factor of 256 results in short repeats! */
#define MODFACTOR 25

int main(int argc, char *argv[]) {
        int fd, i, j, rv;
	char cksum;
	char *c;

	if((c = malloc(NUMBYTES))<= 0)
		fprintf(stderr, "Malloc fails.\n");

	srand(10245);

#ifdef __SOLARIS__
        fd = open64(RAWDEV, O_WRONLY | O_LARGEFILE);
#else
	fd = open(RAWDEV, O_WRONLY);
#endif

        if (fd < 1) {
                printf("error: fd %d\n",fd);
		exit(1);
        }
        for (i = 0; i < DISKSIZE ; i++) {
		cksum = 0;
		for(j = 0 ; j < NUMBYTES; j++) {
			rv = rand();
			c[j] = rv % MODFACTOR + 97;
			cksum ^= c[j];
		}
		if((rv = write(fd, c, NUMBYTES)) != NUMBYTES) {
			printf("oops: %d\n", rv);
			exit(1);
		}
		printf("Block: %d %d\n", i, cksum);
	}
	exit(0);
}
