Rob Landley | 0e4690d | 2006-08-20 22:12:18 +0000 | [diff] [blame] | 1 | /* 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 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 13 | #include "libbb.h" |
Rob Landley | 0e4690d | 2006-08-20 22:12:18 +0000 | [diff] [blame] | 14 | |
Denis Vlasenko | 06af216 | 2007-02-03 17:28:39 +0000 | [diff] [blame] | 15 | int readahead_main(int argc, char **argv); |
Rob Landley | 0e4690d | 2006-08-20 22:12:18 +0000 | [diff] [blame] | 16 | int readahead_main(int argc, char **argv) |
| 17 | { |
| 18 | FILE *f; |
Rob Landley | 0e4690d | 2006-08-20 22:12:18 +0000 | [diff] [blame] | 19 | int retval = EXIT_SUCCESS; |
| 20 | |
| 21 | if (argc == 1) bb_show_usage(); |
| 22 | |
| 23 | while (*++argv) { |
Denis Vlasenko | ddec5af | 2006-10-26 23:25:17 +0000 | [diff] [blame] | 24 | if ((f = fopen_or_warn(*argv, "r")) != NULL) { |
Rob Landley | 0e4690d | 2006-08-20 22:12:18 +0000 | [diff] [blame] | 25 | int r, fd=fileno(f); |
Denis Vlasenko | 9213a9e | 2006-09-17 16:28:10 +0000 | [diff] [blame] | 26 | |
Rob Landley | 0e4690d | 2006-08-20 22:12:18 +0000 | [diff] [blame] | 27 | r = readahead(fd, 0, fdlength(fd)); |
| 28 | fclose(f); |
| 29 | if (r >= 0) continue; |
| 30 | } |
| 31 | retval = EXIT_FAILURE; |
| 32 | } |
| 33 | |
| 34 | return retval; |
| 35 | } |