]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/tools/grow.c
Tweak fix MySQL quoting again :-(
[bacula/bacula] / bacula / src / tools / grow.c
1 /*
2     By John Walker written ages ago.
3
4     Create a sparse file.
5
6     Beat denial of service floggers to death by persuading
7     them to download a HOW_BIG pseudo GIF file which is actually
8     a holey file occupying trivial space on our server.
9
10     Make:  make gigaslam            
11     Run:   ./gigaslam
12     Output: a file named gigaslam.gif that contains something like
13             16K bytes (i.e. 2-8K blocks), but appears to be 1GB in 
14             length because the second block is written at a 1GB 
15             address.
16
17     Be careful what you do with this file as not all programs know
18     how to deal with sparse files.
19
20     Tweaked by Kern Sibbald, July 2007 to grow a file to a specified
21     size.
22     
23 */
24
25 #ifdef __GNUC__
26 #ifndef _GNU_SOURCE
27 #define _GNU_SOURCE
28 #endif
29 #ifndef _FILE_OFFSET_BITS
30 #define _FILE_OFFSET_BITS 64
31 #endif
32 #endif
33
34 #include "bacula.h"
35
36 int main(int argc, char *argv[])
37 {
38    off_t howBig;
39    FILE *fp;
40
41    if (argc != 3) {
42       Pmsg0(0, "Calling sequence: grow <filename> <size>\n");
43       exit(1);
44    }
45    howBig = str_to_int64(argv[2]);
46    fp = fopen(argv[1], "r+");
47    if (!fp) {
48       berrno be;
49       Pmsg2(0, "Could not open %s for write. ERR=%s\n", argv[1], be.bstrerror());
50       exit(1);
51    }
52    char trailer[] = "xxxxxxx\n";
53
54    fseeko(fp, howBig - strlen(trailer), SEEK_SET);
55    fwrite(trailer, strlen(trailer), 1, fp);
56    fclose(fp);
57    return 0;
58 }