exhaust 2

Link to this paste: http://bugs.dragonflybsd.org/pastes/34

Added by tuxillo about 3 years ago.
Syntax: 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
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <err.h>

#define NFILES 500

int
main(int argc, char *argv[])
{

        int i;
        size_t size;
        long jump;
        int fd[NFILES];
        struct stat st[NFILES];
        char name[128];
        char *p[NFILES];

        for (i = 0; i <  NFILES; i++) {
                snprintf(name, 128, "tmpfiles/file%d", i);
                if ((fd[i] = open(name, O_RDWR)) < 1)
                        err(1, "open");

                if ((fstat(fd[i], &st[i])) == -1)
                        err(1, "fstat");

                size = st[i].st_size;
                p[i] = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd[i], 0);
                if (p[i] == MAP_FAILED)
                        err(1, "mmap");

                for (jump = 0; jump < size; jump += 65535) {
                        p[i][jump] = jump + i;
                }
                if ((msync(*p, MS_SYNC, 0)) == -1) {
                        printf("%s: %d %p\n", name, i, *p);
                        err(1, "msync");

                }
        }

        return 0;

}

Download