xref: /aosp_15_r20/external/toybox/toys/other/readahead.c (revision cf5a6c84e2b8763fc1a7db14496fd4742913b199)
1 /* readahead.c - preload files into disk cache.
2  *
3  * Copyright 2013 Rob Landley <[email protected]>
4  *
5  * No standard.
6 
7 USE_READAHEAD(NEWTOY(readahead, NULL, TOYFLAG_BIN))
8 
9 config READAHEAD
10   bool "readahead"
11   default y
12   help
13     usage: readahead FILE...
14 
15     Preload files into disk cache.
16 */
17 
18 #include "toys.h"
19 
do_readahead(int fd,char * name)20 static void do_readahead(int fd, char *name)
21 {
22   int rc;
23 
24   // Since including fcntl.h doesn't give us the wrapper, use the syscall.
25   // 32 bits takes LO/HI offset (we don't care about endianness of 0).
26   if (sizeof(long) == 4) rc = syscall(__NR_readahead, fd, 0, 0, INT_MAX);
27   else rc = syscall(__NR_readahead, fd, 0, INT_MAX);
28 
29   if (rc) perror_msg("readahead: %s", name);
30 }
31 
readahead_main(void)32 void readahead_main(void)
33 {
34   loopfiles(toys.optargs, do_readahead);
35 }
36