blob: 49cd7fd09da42a67b52856c39ad51c2682bc4f13 [file] [log] [blame]
Rob Landley0e4690d2006-08-20 22:12:18 +00001/* vi: set sw=4 ts=4: */
2/*
3 * readahead implementation for busybox
4 *
5 * Preloads the given files in RAM, to reduce access time.
6 * Does this by calling the readahead(2) system call.
7 *
8 * Copyright (C) 2006 Michael Opdenacker <michael@free-electrons.com>
9 *
10 * Licensed under GPLv2 or later, see file License in this tarball for details.
11 */
12
13#include "busybox.h"
14
15int readahead_main(int argc, char **argv)
16{
17 FILE *f;
Rob Landley0e4690d2006-08-20 22:12:18 +000018 int retval = EXIT_SUCCESS;
19
20 if (argc == 1) bb_show_usage();
21
22 while (*++argv) {
23 if ((f = bb_wfopen(*argv, "r")) != NULL) {
24 int r, fd=fileno(f);
Denis Vlasenko9213a9e2006-09-17 16:28:10 +000025
Rob Landley0e4690d2006-08-20 22:12:18 +000026 r = readahead(fd, 0, fdlength(fd));
27 fclose(f);
28 if (r >= 0) continue;
29 }
30 retval = EXIT_FAILURE;
31 }
32
33 return retval;
34}