aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-08-20 22:12:18 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-08-20 22:12:18 +0000
commite184a1bcb88200d7a3b81a134ce95c1c0621d47d (patch)
tree1eac13023c328f3956a00f3e741eb1cda45696d0
parentfd7b9651c47665c3d575f27493e698efb4713f4a (diff)
downloadbusybox-w32-e184a1bcb88200d7a3b81a134ce95c1c0621d47d.tar.gz
busybox-w32-e184a1bcb88200d7a3b81a134ce95c1c0621d47d.tar.bz2
busybox-w32-e184a1bcb88200d7a3b81a134ce95c1c0621d47d.zip
Michael Opdenacker contributed a readahead applet.
git-svn-id: svn://busybox.net/trunk/busybox@15854 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--include/applets.h1
-rw-r--r--include/usage.h6
-rw-r--r--miscutils/Config.in16
-rw-r--r--miscutils/Makefile.in1
-rw-r--r--miscutils/readahead.c36
5 files changed, 60 insertions, 0 deletions
diff --git a/include/applets.h b/include/applets.h
index a8b480b80..0bb257b6d 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -219,6 +219,7 @@ USE_PRINTF(APPLET(printf, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
219USE_PS(APPLET(ps, _BB_DIR_BIN, _BB_SUID_NEVER)) 219USE_PS(APPLET(ps, _BB_DIR_BIN, _BB_SUID_NEVER))
220USE_PWD(APPLET(pwd, _BB_DIR_BIN, _BB_SUID_NEVER)) 220USE_PWD(APPLET(pwd, _BB_DIR_BIN, _BB_SUID_NEVER))
221USE_RDATE(APPLET(rdate, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) 221USE_RDATE(APPLET(rdate, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
222USE_READAHEAD(APPLET(readahead, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
222USE_READLINK(APPLET(readlink, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) 223USE_READLINK(APPLET(readlink, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
223USE_READPROFILE(APPLET(readprofile, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) 224USE_READPROFILE(APPLET(readprofile, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
224USE_REALPATH(APPLET(realpath, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) 225USE_REALPATH(APPLET(realpath, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
diff --git a/include/usage.h b/include/usage.h
index 5bc82dc22..ced9f68c7 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -2385,6 +2385,12 @@ USE_FEATURE_MDEV_CONFIG( \
2385 "\t-s\tSet the system date and time (default)\n" \ 2385 "\t-s\tSet the system date and time (default)\n" \
2386 "\t-p\tPrint the date and time" 2386 "\t-p\tPrint the date and time"
2387 2387
2388#define readahead_trivial_usage \
2389 "[FILE]..."
2390#define readahead_full_usage \
2391 "Preloads FILE(s) in RAM cache so that subsequent reads for those" \
2392 "files do not block on disk I/O."
2393
2388#ifdef CONFIG_FEATURE_READLINK_FOLLOW 2394#ifdef CONFIG_FEATURE_READLINK_FOLLOW
2389#define USAGE_READLINK_FOLLOW(a) a 2395#define USAGE_READLINK_FOLLOW(a) a
2390#else 2396#else
diff --git a/miscutils/Config.in b/miscutils/Config.in
index 4296b54ea..9ad342151 100644
--- a/miscutils/Config.in
+++ b/miscutils/Config.in
@@ -276,6 +276,22 @@ config CONFIG_MT
276 to advance or rewind a tape past a specified number of archive 276 to advance or rewind a tape past a specified number of archive
277 files on the tape. 277 files on the tape.
278 278
279config CONFIG_READAHEAD
280 bool "readahead"
281 default n
282 help
283 Preload the files listed on the command line into RAM cache so that
284 subsequent reads on these files will not block on disk I/O.
285
286 This applet just calls the readahead(2) system call on each file.
287 It is mainly useful in system startup scripts to preload files
288 or executables before they are used. When used at the right time
289 (in particular when a CPU boundprocess is running) it can
290 significantly speed up system startup.
291
292 As readahead(2) blocks until each file has been read, it is best to
293 run this applet as a background job.
294
279config CONFIG_RUNLEVEL 295config CONFIG_RUNLEVEL
280 bool "runlevel" 296 bool "runlevel"
281 default n 297 default n
diff --git a/miscutils/Makefile.in b/miscutils/Makefile.in
index a0b6b7233..25143c10b 100644
--- a/miscutils/Makefile.in
+++ b/miscutils/Makefile.in
@@ -24,6 +24,7 @@ MISCUTILS-${CONFIG_LESS} += less.o
24MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o 24MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o
25MISCUTILS-$(CONFIG_MOUNTPOINT) += mountpoint.o 25MISCUTILS-$(CONFIG_MOUNTPOINT) += mountpoint.o
26MISCUTILS-$(CONFIG_MT) += mt.o 26MISCUTILS-$(CONFIG_MT) += mt.o
27MISCUTILS-$(CONFIG_READAHEAD) += readahead.o
27MISCUTILS-$(CONFIG_RUNLEVEL) += runlevel.o 28MISCUTILS-$(CONFIG_RUNLEVEL) += runlevel.o
28MISCUTILS-$(CONFIG_RX) += rx.o 29MISCUTILS-$(CONFIG_RX) += rx.o
29MISCUTILS-$(CONFIG_SETSID) += setsid.o 30MISCUTILS-$(CONFIG_SETSID) += setsid.o
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
15int 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}