toybox/toys/other/readahead.c
<<
>>
Prefs
   1/* readahead.c - preload files into disk cache.
   2 *
   3 * Copyright 2013 Rob Landley <rob@landley.net>
   4 *
   5 * No standard.
   6
   7USE_READAHEAD(NEWTOY(readahead, NULL, TOYFLAG_BIN))
   8
   9config 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
  20static 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
  32void readahead_main(void)
  33{
  34  loopfiles(toys.optargs, do_readahead);
  35}
  36