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 | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 15 | int readahead_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Rob Landley | 0e4690d | 2006-08-20 22:12:18 +0000 | [diff] [blame] | 16 | int readahead_main(int argc, char **argv) |
| 17 | { |
Rob Landley | 0e4690d | 2006-08-20 22:12:18 +0000 | [diff] [blame] | 18 | int retval = EXIT_SUCCESS; |
| 19 | |
| 20 | if (argc == 1) bb_show_usage(); |
| 21 | |
| 22 | while (*++argv) { |
Denis Vlasenko | 6bef3d1 | 2007-11-06 03:05:54 +0000 | [diff] [blame] | 23 | int fd = open_or_warn(*argv, O_RDONLY); |
| 24 | if (fd >= 0) { |
Denis Vlasenko | b5c60fc | 2008-01-27 23:41:34 +0000 | [diff] [blame] | 25 | off_t len; |
| 26 | int r; |
| 27 | |
| 28 | /* fdlength was reported to be unreliable - use seek */ |
| 29 | len = xlseek(fd, 0, SEEK_END); |
| 30 | xlseek(fd, 0, SEEK_SET); |
| 31 | r = readahead(fd, 0, len); |
Denis Vlasenko | 6bef3d1 | 2007-11-06 03:05:54 +0000 | [diff] [blame] | 32 | close(fd); |
Denis Vlasenko | b5c60fc | 2008-01-27 23:41:34 +0000 | [diff] [blame] | 33 | if (r >= 0) |
| 34 | continue; |
Rob Landley | 0e4690d | 2006-08-20 22:12:18 +0000 | [diff] [blame] | 35 | } |
| 36 | retval = EXIT_FAILURE; |
| 37 | } |
| 38 | |
| 39 | return retval; |
| 40 | } |