aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-01-16 13:02:12 -0600
committerRob Landley <rob@landley.net>2016-01-16 13:02:12 -0600
commit7279b849f48e2ceb1d35e82e53b14343b708d776 (patch)
tree9d77b9311d945dbc9de30fbe8b6aac113e1657a0
parent7d6f210aa38afe2a9a370f1e0f23edf72a1735bb (diff)
downloadtoybox-7279b849f48e2ceb1d35e82e53b14343b708d776.tar.gz
Add swapon -d (discard)
-rw-r--r--toys/other/swapon.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/toys/other/swapon.c b/toys/other/swapon.c
index 838d382a..0d65040a 100644
--- a/toys/other/swapon.c
+++ b/toys/other/swapon.c
@@ -2,15 +2,17 @@
*
* Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
-USE_SWAPON(NEWTOY(swapon, "<1>1p#<0>32767", TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
+USE_SWAPON(NEWTOY(swapon, "<1>1p#<0>32767d", TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
config SWAPON
bool "swapon"
default y
help
- usage: swapon [-p priority] filename
+ usage: swapon [-d] [-p priority] filename
Enable swapping on a given device/file.
+
+ -d Discard freed SSD pages
*/
#define FOR_swapon
@@ -22,10 +24,11 @@ GLOBALS(
void swapon_main(void)
{
- int flags = 0;
+ // 0x70000 = SWAP_FLAG_DISCARD|SWAP_FLAG_DISCARD_ONCE|SWAP_FLAG_DISCARD_PAGES
+ int flags = (toys.optflags&FLAG_d)*0x70000;
if (toys.optflags)
- flags = SWAP_FLAG_PREFER | (TT.priority << SWAP_FLAG_PRIO_SHIFT);
+ flags |= SWAP_FLAG_PREFER | (TT.priority << SWAP_FLAG_PRIO_SHIFT);
if (swapon(*toys.optargs, flags))
perror_exit("Couldn't swapon '%s'", *toys.optargs);