source: grub-pc/trunk/fuentes/util/garbage-gen.c @ 22

Last change on this file since 22 was 22, checked in by mabarracus, 4 years ago

updated version and apply net.ifnames=0 into debian/rules

File size: 1.8 KB
Line 
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
19/* Standard random generator is slow. For FS testing we need just some
20   garbage files, we don't need them to be high-quality random.
21 */
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <time.h>
26#include <sys/time.h>
27
28static unsigned long long buffer[1048576];
29
30int
31main (int argc, char **argv)
32{
33  unsigned long long high = 0, low = 1;
34  unsigned long i, j;
35  unsigned long long cnt = strtoull (argv[1], 0, 0);
36  struct timeval tv;
37  gettimeofday (&tv, NULL);
38  high = tv.tv_sec;
39  low = tv.tv_usec;
40  if (!high)
41    high = 1;
42  if (!low)
43    low = 2;
44
45  for (j = 0; j < (cnt + sizeof (buffer) - 1)  / sizeof (buffer); j++)
46    {
47      for (i = 0; i < sizeof (buffer) / sizeof (buffer[0]); i += 2)
48        {
49          int c1 = 0, c2 = 0;
50          buffer[i] = low;
51          buffer[i+1] = high;
52          if (low & (1ULL << 63))
53            c1 = 1;
54          low <<= 1;
55          if (high & (1ULL << 63))
56            c2 = 1;
57          high = (high << 1) | c1;
58          if (c2)
59            low ^= 0x87;
60        }
61      if (sizeof (buffer) < cnt - sizeof (buffer) * j)
62        fwrite (buffer, 1, sizeof (buffer), stdout);
63      else
64        fwrite (buffer, 1, cnt - sizeof (buffer) * j, stdout);
65    }
66  return 0;
67}
Note: See TracBrowser for help on using the repository browser.