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 */
21 
22 #define HOW_BIG   1000000000ll
23 
24 #ifdef __GNUC__
25 #ifndef _GNU_SOURCE
26 #define _GNU_SOURCE
27 #endif
28 #ifndef _FILE_OFFSET_BITS
29 #define _FILE_OFFSET_BITS 64
30 #endif
31 #endif
32 
33 #include <stdio.h>
34 #include <unistd.h>
35 #include <string.h>
36 
main(int argc,char * const * argv)37 int main(int argc, char *const *argv)
38 {
39     FILE *fp = fopen("gigaslam.gif", "w");
40     char header[] = "<html>\n<table>\n<tr><td>\n";
41     char trailer[] = "</html>\n";
42     off_t howBig = HOW_BIG;
43 
44     fwrite(header, sizeof header, 1, fp);
45     fseeko(fp, howBig - strlen(trailer), 0);
46     fwrite(trailer, strlen(trailer), 1, fp);
47     fclose(fp);
48     return 0;
49 
50 }
51