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 | |
| parent | 289e86a0a5b2482fc1b6a442d3acd749639e4d64 (diff) | |
| download | busybox-w32-0e4690d4ef9fe55ccf6db371c826112809e162f9.tar.gz busybox-w32-0e4690d4ef9fe55ccf6db371c826112809e162f9.tar.bz2 busybox-w32-0e4690d4ef9fe55ccf6db371c826112809e162f9.zip | |
Michael Opdenacker contributed a readahead applet.
| -rw-r--r-- | include/applets.h | 1 | ||||
| -rw-r--r-- | include/usage.h | 6 | ||||
| -rw-r--r-- | miscutils/Config.in | 16 | ||||
| -rw-r--r-- | miscutils/Makefile.in | 1 | ||||
| -rw-r--r-- | miscutils/readahead.c | 36 |
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)) | |||
| 219 | USE_PS(APPLET(ps, _BB_DIR_BIN, _BB_SUID_NEVER)) | 219 | USE_PS(APPLET(ps, _BB_DIR_BIN, _BB_SUID_NEVER)) |
| 220 | USE_PWD(APPLET(pwd, _BB_DIR_BIN, _BB_SUID_NEVER)) | 220 | USE_PWD(APPLET(pwd, _BB_DIR_BIN, _BB_SUID_NEVER)) |
| 221 | USE_RDATE(APPLET(rdate, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) | 221 | USE_RDATE(APPLET(rdate, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) |
| 222 | USE_READAHEAD(APPLET(readahead, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | ||
| 222 | USE_READLINK(APPLET(readlink, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 223 | USE_READLINK(APPLET(readlink, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
| 223 | USE_READPROFILE(APPLET(readprofile, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) | 224 | USE_READPROFILE(APPLET(readprofile, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) |
| 224 | USE_REALPATH(APPLET(realpath, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 225 | USE_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 | ||
| 279 | config 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 | |||
| 279 | config CONFIG_RUNLEVEL | 295 | config 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 | |||
| 24 | MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o | 24 | MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o |
| 25 | MISCUTILS-$(CONFIG_MOUNTPOINT) += mountpoint.o | 25 | MISCUTILS-$(CONFIG_MOUNTPOINT) += mountpoint.o |
| 26 | MISCUTILS-$(CONFIG_MT) += mt.o | 26 | MISCUTILS-$(CONFIG_MT) += mt.o |
| 27 | MISCUTILS-$(CONFIG_READAHEAD) += readahead.o | ||
| 27 | MISCUTILS-$(CONFIG_RUNLEVEL) += runlevel.o | 28 | MISCUTILS-$(CONFIG_RUNLEVEL) += runlevel.o |
| 28 | MISCUTILS-$(CONFIG_RX) += rx.o | 29 | MISCUTILS-$(CONFIG_RX) += rx.o |
| 29 | MISCUTILS-$(CONFIG_SETSID) += setsid.o | 30 | MISCUTILS-$(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 | |||
| 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 | } | ||
