summaryrefslogtreecommitdiff
path: root/nureadahead-preload.c
diff options
context:
space:
mode:
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2020-04-04 20:23:21 -0400
committerAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2020-04-04 20:23:21 -0400
commit5db227b05ba316713d6793e728b21366e8337721 (patch)
tree8001f1fba5ec3c1fa37ad1aa6c55fe748880823a /nureadahead-preload.c
downloadnureadahead-5db227b05ba316713d6793e728b21366e8337721.tar.xz
nureadahead-5db227b05ba316713d6793e728b21366e8337721.zip
Initial commitHEADmaster
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);
+ }
+ }
+}