Make swapon and swapoff individually selectable.

For example, without swapoff, code shrinks by 277 bytes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2016-11-14 17:30:50 +01:00
parent 1924e99ad3
commit f417ffd88f
4 changed files with 50 additions and 32 deletions

View File

@ -287,8 +287,6 @@ IF_STAT(APPLET(stat, BB_DIR_BIN, BB_SUID_DROP))
IF_STRINGS(APPLET(strings, BB_DIR_USR_BIN, BB_SUID_DROP))
IF_STTY(APPLET(stty, BB_DIR_BIN, BB_SUID_DROP))
IF_SUM(APPLET(sum, BB_DIR_USR_BIN, BB_SUID_DROP))
IF_SWAPONOFF(APPLET_ODDNAME(swapoff, swap_on_off, BB_DIR_SBIN, BB_SUID_DROP, swapoff))
IF_SWAPONOFF(APPLET_ODDNAME(swapon, swap_on_off, BB_DIR_SBIN, BB_SUID_DROP, swapon))
IF_SWITCH_ROOT(APPLET(switch_root, BB_DIR_SBIN, BB_SUID_DROP))
IF_BB_SYSCTL(APPLET(sysctl, BB_DIR_SBIN, BB_SUID_DROP))
IF_TAC(APPLET_NOEXEC(tac, tac, BB_DIR_USR_BIN, BB_SUID_DROP, tac))

View File

@ -489,34 +489,6 @@ config SCRIPTREPLAY
This program replays a typescript, using timing information
given by script -t.
config SWAPONOFF
bool "swaponoff"
default y
select PLATFORM_LINUX
help
This option enables both the 'swapon' and the 'swapoff' utilities.
Once you have created some swap space using 'mkswap', you also need
to enable your swap space with the 'swapon' utility. The 'swapoff'
utility is used, typically at system shutdown, to disable any swap
space. If you are not using any swap space, you can leave this
option disabled.
config FEATURE_SWAPON_DISCARD
bool "Support discard option -d"
default y
depends on SWAPONOFF
help
Enable support for discarding swap area blocks at swapon and/or as
the kernel frees them. This option enables both the -d option on
'swapon' and the 'discard' option for swap entries in /etc/fstab.
config FEATURE_SWAPON_PRI
bool "Support priority option -p"
default y
depends on SWAPONOFF
help
Enable support for setting swap device priority in swapon.
config SWITCH_ROOT
bool "switch_root"
default y

View File

@ -40,6 +40,5 @@ lib-$(CONFIG_READPROFILE) += readprofile.o
lib-$(CONFIG_RTCWAKE) += rtcwake.o
lib-$(CONFIG_SCRIPT) += script.o
lib-$(CONFIG_SCRIPTREPLAY) += scriptreplay.o
lib-$(CONFIG_SWAPONOFF) += swaponoff.o
lib-$(CONFIG_SWITCH_ROOT) += switch_root.o
lib-$(CONFIG_UMOUNT) += umount.o

View File

@ -7,6 +7,47 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config SWAPON
//config: bool "swapon"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This option enables the 'swapon' utility.
//config: Once you have created some swap space using 'mkswap', you also need
//config: to enable your swap space with the 'swapon' utility. The 'swapoff'
//config: utility is used, typically at system shutdown, to disable any swap
//config: space. If you are not using any swap space, you can leave this
//config: option disabled.
//config:
//config:config FEATURE_SWAPON_DISCARD
//config: bool "Support discard option -d"
//config: default y
//config: depends on SWAPON
//config: help
//config: Enable support for discarding swap area blocks at swapon and/or as
//config: the kernel frees them. This option enables both the -d option on
//config: 'swapon' and the 'discard' option for swap entries in /etc/fstab.
//config:
//config:config FEATURE_SWAPON_PRI
//config: bool "Support priority option -p"
//config: default y
//config: depends on SWAPON
//config: help
//config: Enable support for setting swap device priority in swapon.
//config:
//config:config SWAPOFF
//config: bool "swapoff"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This option enables the 'swapoff' utility.
//applet:IF_SWAPON(APPLET_ODDNAME(swapon, swap_on_off, BB_DIR_SBIN, BB_SUID_DROP, swapon))
//applet:IF_SWAPOFF(APPLET_ODDNAME(swapoff, swap_on_off, BB_DIR_SBIN, BB_SUID_DROP, swapoff))
//kbuild:lib-$(CONFIG_SWAPON) += swaponoff.o
//kbuild:lib-$(CONFIG_SWAPOFF) += swaponoff.o
//usage:#define swapon_trivial_usage
//usage: "[-a] [-e]" IF_FEATURE_SWAPON_DISCARD(" [-d[POL]]") IF_FEATURE_SWAPON_PRI(" [-p PRI]") " [DEVICE]"
//usage:#define swapon_full_usage "\n\n"
@ -74,7 +115,15 @@ struct globals {
#endif
#define INIT_G() do { setup_common_bufsiz(); } while (0)
#if ENABLE_SWAPOFF
# if ENABLE_SWAPON
# define do_swapoff (applet_name[5] == 'f')
# else
# define do_swapoff 1
# endif
#else
# define do_swapoff 0
#endif
/* Command line options */
enum {