00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <inttypes.h>
00024 #include <errno.h>
00025 #include <string.h>
00026
00027 static uint32_t state;
00028 static uint32_t ran(void)
00029 {
00030 return state = state * 1664525 + 1013904223;
00031 }
00032
00033 int main(int argc, char **argv)
00034 {
00035 FILE *f;
00036 int count, maxburst, length;
00037
00038 if (argc < 5) {
00039 printf("USAGE: trasher <filename> <count> <maxburst> <seed>\n");
00040 return 1;
00041 }
00042
00043 f = fopen(argv[1], "rb+");
00044 if (!f) {
00045 perror(argv[1]);
00046 return 2;
00047 }
00048 count = atoi(argv[2]);
00049 maxburst = atoi(argv[3]);
00050 state = atoi(argv[4]);
00051
00052 fseek(f, 0, SEEK_END);
00053 length = ftell(f);
00054 fseek(f, 0, SEEK_SET);
00055
00056 while (count--) {
00057 int burst = 1 + ran() * (uint64_t) (abs(maxburst) - 1) / UINT32_MAX;
00058 int pos = ran() * (uint64_t) length / UINT32_MAX;
00059 fseek(f, pos, SEEK_SET);
00060
00061 if (maxburst < 0)
00062 burst = -maxburst;
00063
00064 if (pos + burst > length)
00065 continue;
00066
00067 while (burst--) {
00068 int val = ran() * 256ULL / UINT32_MAX;
00069
00070 if (maxburst < 0)
00071 val = 0;
00072
00073 fwrite(&val, 1, 1, f);
00074 }
00075 }
00076
00077 return 0;
00078 }