From 7279b849f48e2ceb1d35e82e53b14343b708d776 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 16 Jan 2016 13:02:12 -0600 Subject: Add swapon -d (discard) --- toys/other/swapon.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'toys') 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 -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); -- cgit v1.2.3