summaryrefslogtreecommitdiff
path: root/nureadahead-preload.c
diff options
context:
space:
mode:
Diffstat (limited to 'nureadahead-preload.c')
-rw-r--r--nureadahead-preload.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/nureadahead-preload.c b/nureadahead-preload.c
new file mode 100644
index 0000000..7d10df8
--- /dev/null
+++ b/nureadahead-preload.c
@@ -0,0 +1,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);
+ }
+ }
+}