You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
984B

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <inttypes.h>
  5. int main(int argc, char** argv)
  6. {
  7. FILE *f;
  8. int count, maxburst, length;
  9. if (argc < 4){
  10. printf("USAGE: trasher <filename> <count> <maxburst>\n");
  11. return 1;
  12. }
  13. f= fopen(argv[1], "rb+");
  14. if (!f){
  15. perror(argv[1]);
  16. return 2;
  17. }
  18. count= atoi(argv[2]);
  19. maxburst= atoi(argv[3]);
  20. srand (time (0));
  21. fseek(f, 0, SEEK_END);
  22. length= ftell(f);
  23. fseek(f, 0, SEEK_SET);
  24. while(count--){
  25. int burst= 1 + random() * (uint64_t) (abs(maxburst)-1) / RAND_MAX;
  26. int pos= random() * (uint64_t) length / RAND_MAX;
  27. fseek(f, pos, SEEK_SET);
  28. if(maxburst<0) burst= -maxburst;
  29. if(pos + burst > length)
  30. continue;
  31. while(burst--){
  32. int val= random() * 256ULL / RAND_MAX;
  33. if(maxburst<0) val=0;
  34. fwrite(&val, 1, 1, f);
  35. }
  36. }
  37. return 0;
  38. }