# HG changeset patch # User Rob Landley # Date 1361731900 21600 # Node ID 5aa90a446d528f30d0008e1bd75c26aa7cd123db # Parent bbec26ccb40c877aa82eb3fdf643cdae6bd50785 Add readahead. diff -r bbec26ccb40c -r 5aa90a446d52 toys/other/readahead.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/toys/other/readahead.c Sun Feb 24 12:51:40 2013 -0600 @@ -0,0 +1,37 @@ +/* readahead.c - preload files into disk cache. + * + * Copyright 2013 Rob Landley + * + * 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 + +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); +}