-
Notifications
You must be signed in to change notification settings - Fork 0
/
diskbomb.c
68 lines (57 loc) · 1.3 KB
/
diskbomb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* diskbomb.c - allocate large files until write fails */
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
#define BLOCKSIZE 512
#define NBLOCKS 140
void
createfile(char *filename, char *buf, int blocksize, int count, int *totalblocks)
{
int fd;
int i;
int rv;
fd = open(filename, O_CREATE | O_WRONLY);
if (fd < 0) {
printf(1, "diskbomb: open() failed, exiting.\n");
exit();
}
for (i = 0; i < count; i++) {
rv = write(fd, buf, blocksize);
if (rv < 0) {
printf(1, "diskbomb: write() failed, exiting.\n");
exit();
}
*totalblocks += BLOCKSIZE;
printf(1, "diskbomb: total blocks written: %d\n", *totalblocks);
}
close(fd);
}
void
setfilename(char *filename, int i)
{
filename[0] = 'D';
filename[1] = 'B';
itoa(i, &filename[2], 10);
}
int
main(int argc, char *argv[])
{
int i = 0;
int totalblocks = 0;
int totalfiles = 0;
char filename[16];
char buf[BLOCKSIZE];
/* Initialize buf with 'a' */
for (i = 0; i < BLOCKSIZE; i++) {
buf[i] = 'a';
}
while(1) {
setfilename(filename, totalfiles);
printf(1, "diskbomb: creating %s\n", filename);
createfile(filename, buf, BLOCKSIZE, NBLOCKS, &totalblocks);
totalfiles += 1;
printf(1, "diskbomb: total files created: %d\n", totalfiles);
}
exit();
}