10f66f451Sopenharmony_ci/* readahead.c - preload files into disk cache. 20f66f451Sopenharmony_ci * 30f66f451Sopenharmony_ci * Copyright 2013 Rob Landley <rob@landley.net> 40f66f451Sopenharmony_ci * 50f66f451Sopenharmony_ci * No standard. 60f66f451Sopenharmony_ci 70f66f451Sopenharmony_ciUSE_READAHEAD(NEWTOY(readahead, NULL, TOYFLAG_BIN)) 80f66f451Sopenharmony_ci 90f66f451Sopenharmony_ciconfig READAHEAD 100f66f451Sopenharmony_ci bool "readahead" 110f66f451Sopenharmony_ci default y 120f66f451Sopenharmony_ci help 130f66f451Sopenharmony_ci usage: readahead FILE... 140f66f451Sopenharmony_ci 150f66f451Sopenharmony_ci Preload files into disk cache. 160f66f451Sopenharmony_ci*/ 170f66f451Sopenharmony_ci 180f66f451Sopenharmony_ci#include "toys.h" 190f66f451Sopenharmony_ci 200f66f451Sopenharmony_ci#include <sys/syscall.h> 210f66f451Sopenharmony_ci 220f66f451Sopenharmony_cistatic void do_readahead(int fd, char *name) 230f66f451Sopenharmony_ci{ 240f66f451Sopenharmony_ci int rc; 250f66f451Sopenharmony_ci 260f66f451Sopenharmony_ci // Since including fcntl.h doesn't give us the wrapper, use the syscall. 270f66f451Sopenharmony_ci // 32 bits takes LO/HI offset (we don't care about endianness of 0). 280f66f451Sopenharmony_ci if (sizeof(long) == 4) rc = syscall(__NR_readahead, fd, 0, 0, INT_MAX); 290f66f451Sopenharmony_ci else rc = syscall(__NR_readahead, fd, 0, INT_MAX); 300f66f451Sopenharmony_ci 310f66f451Sopenharmony_ci if (rc) perror_msg("readahead: %s", name); 320f66f451Sopenharmony_ci} 330f66f451Sopenharmony_ci 340f66f451Sopenharmony_civoid readahead_main(void) 350f66f451Sopenharmony_ci{ 360f66f451Sopenharmony_ci loopfiles(toys.optargs, do_readahead); 370f66f451Sopenharmony_ci} 38