blob: 7d10df8d4ebaf3aba2274a742c860482260f082d (
plain)
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
|
#define _POSIX_C_SOURCE 200112L
#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
void usage() {
fputs("usage: nureadahead-preload DEVICE < file\n", stderr);
}
int main(int argc, char *argv[]) {
if (argc != 2 || argv[1][0] == '-' || argv[1][0] == '\0') {
usage();
exit(1);
}
int fd = open(argv[1], O_RDONLY);
if (fd == -1) {
perror("nureadahead-preload");
exit(1);
}
while (1) {
unsigned long long start, end;
switch (scanf("%llu %llu\n", &start, &end)) {
case 2:
if (posix_fadvise(fd, start * 512, (end - start + 1) * 512, POSIX_FADV_WILLNEED) == -1) {
perror("nureadahead-preload: readahead");
exit(1);
}
break;
case EOF:
exit(0);
default:
fputs("nureadahead-preload: invalid input\n", stderr);
}
}
}
|