source: MondoRescue/branches/3.2/mindi-busybox/miscutils/readahead.c@ 3232

Last change on this file since 3232 was 3232, checked in by Bruno Cornec, 10 years ago
  • Update mindi-busybox to 1.21.1
  • Property svn:eol-style set to native
File size: 1.0 KB
RevLine 
[1765]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 *
[2725]10 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
[1765]11 */
12
[3232]13//usage:#define readahead_trivial_usage
14//usage: "[FILE]..."
15//usage:#define readahead_full_usage "\n\n"
16//usage: "Preload FILEs to RAM"
17
[1765]18#include "libbb.h"
19
[2725]20int readahead_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
21int readahead_main(int argc UNUSED_PARAM, char **argv)
[1765]22{
23 int retval = EXIT_SUCCESS;
24
[2725]25 if (!argv[1]) {
26 bb_show_usage();
27 }
[1765]28
29 while (*++argv) {
[2725]30 int fd = open_or_warn(*argv, O_RDONLY);
31 if (fd >= 0) {
32 off_t len;
33 int r;
[1765]34
[2725]35 /* fdlength was reported to be unreliable - use seek */
36 len = xlseek(fd, 0, SEEK_END);
37 xlseek(fd, 0, SEEK_SET);
38 r = readahead(fd, 0, len);
39 close(fd);
40 if (r >= 0)
41 continue;
[1765]42 }
43 retval = EXIT_FAILURE;
44 }
45
46 return retval;
47}
Note: See TracBrowser for help on using the repository browser.