diff options
author | Rob Landley <rob@landley.net> | 2013-02-24 12:51:40 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2013-02-24 12:51:40 -0600 |
commit | 53832006245010487d8d12599ce011d67bf19f94 (patch) | |
tree | 5194c129d58ce7ab021c6d06159a02203311cd5b | |
parent | 9559c2c4a0e99975782fa283c77f5a22a50e1bff (diff) | |
download | toybox-53832006245010487d8d12599ce011d67bf19f94.tar.gz |
Add readahead.
-rw-r--r-- | toys/other/readahead.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/toys/other/readahead.c b/toys/other/readahead.c new file mode 100644 index 00000000..4edd6516 --- /dev/null +++ b/toys/other/readahead.c @@ -0,0 +1,37 @@ +/* readahead.c - preload files into disk cache. + * + * Copyright 2013 Rob Landley <rob@landley.net> + * + * No standard. + +USE_READAHEAD(NEWTOY(readahead, NULL, TOYFLAG_BIN)) + +config READAHEAD + bool "readahead" + default y + help + usage: readahead FILE... + + Preload files into disk cache. +*/ + +#include "toys.h" + +#include <sys/syscall.h> + +static void do_readahead(int fd, char *name) +{ + int rc; + + // Since including fcntl.h doesn't give us the wrapper, use the syscall. + // 32 bits takes LO/HI offset (we don't care about endianness of 0). + if (sizeof(long) == 4) rc = syscall(__NR_readahead, fd, 0, 0, INT_MAX); + else rc = syscall(__NR_readahead, fd, 0, INT_MAX); + + if (rc) perror_msg("readahead: %s", name); +} + +void readahead_main(void) +{ + loopfiles(toys.optargs, do_readahead); +} |