diff options
author | Rob Landley <rob@landley.net> | 2006-08-20 22:12:18 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-08-20 22:12:18 +0000 |
commit | 0e4690d4ef9fe55ccf6db371c826112809e162f9 (patch) | |
tree | 1eac13023c328f3956a00f3e741eb1cda45696d0 /miscutils/readahead.c | |
parent | 289e86a0a5b2482fc1b6a442d3acd749639e4d64 (diff) | |
download | busybox-w32-0e4690d4ef9fe55ccf6db371c826112809e162f9.tar.gz busybox-w32-0e4690d4ef9fe55ccf6db371c826112809e162f9.tar.bz2 busybox-w32-0e4690d4ef9fe55ccf6db371c826112809e162f9.zip |
Michael Opdenacker contributed a readahead applet.
Diffstat (limited to 'miscutils/readahead.c')
-rw-r--r-- | miscutils/readahead.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/miscutils/readahead.c b/miscutils/readahead.c new file mode 100644 index 000000000..9f1bb47be --- /dev/null +++ b/miscutils/readahead.c | |||
@@ -0,0 +1,36 @@ | |||
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 | |||
13 | #include "busybox.h" | ||
14 | |||
15 | int readahead_main(int argc, char **argv) | ||
16 | { | ||
17 | FILE *f; | ||
18 | struct stat stat_buf; | ||
19 | int retval = EXIT_SUCCESS; | ||
20 | |||
21 | if (argc == 1) bb_show_usage(); | ||
22 | |||
23 | while (*++argv) { | ||
24 | if ((f = bb_wfopen(*argv, "r")) != NULL) { | ||
25 | int r, fd=fileno(f); | ||
26 | |||
27 | xstat(*argv, &stat_buf); | ||
28 | r = readahead(fd, 0, fdlength(fd)); | ||
29 | fclose(f); | ||
30 | if (r >= 0) continue; | ||
31 | } | ||
32 | retval = EXIT_FAILURE; | ||
33 | } | ||
34 | |||
35 | return retval; | ||
36 | } | ||