garbage-gen.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2013 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* Standard random generator is slow. For FS testing we need just some
  19. garbage files, we don't need them to be high-quality random.
  20. */
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <time.h>
  24. #include <sys/time.h>
  25. static unsigned long long buffer[1048576];
  26. int
  27. main (int argc, char **argv)
  28. {
  29. unsigned long long high = 0, low = 1;
  30. unsigned long i, j;
  31. unsigned long long cnt = strtoull (argv[1], 0, 0);
  32. struct timeval tv;
  33. gettimeofday (&tv, NULL);
  34. high = tv.tv_sec;
  35. low = tv.tv_usec;
  36. if (!high)
  37. high = 1;
  38. if (!low)
  39. low = 2;
  40. for (j = 0; j < (cnt + sizeof (buffer) - 1) / sizeof (buffer); j++)
  41. {
  42. for (i = 0; i < sizeof (buffer) / sizeof (buffer[0]); i += 2)
  43. {
  44. int c1 = 0, c2 = 0;
  45. buffer[i] = low;
  46. buffer[i+1] = high;
  47. if (low & (1ULL << 63))
  48. c1 = 1;
  49. low <<= 1;
  50. if (high & (1ULL << 63))
  51. c2 = 1;
  52. high = (high << 1) | c1;
  53. if (c2)
  54. low ^= 0x87;
  55. }
  56. if (sizeof (buffer) < cnt - sizeof (buffer) * j)
  57. fwrite (buffer, 1, sizeof (buffer), stdout);
  58. else
  59. fwrite (buffer, 1, cnt - sizeof (buffer) * j, stdout);
  60. }
  61. return 0;
  62. }