xref: /aosp_15_r20/external/toybox/toys/other/swapon.c (revision cf5a6c84e2b8763fc1a7db14496fd4742913b199)
1 /* swapon.c - Enable region for swapping
2  *
3  * Copyright 2012 Elie De Brauwer <[email protected]>
4 
5 USE_SWAPON(NEWTOY(swapon, "<1>1p#<0>32767d", TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
6 
7 config SWAPON
8   bool "swapon"
9   default y
10   help
11     usage: swapon [-d] [-p priority] filename
12 
13     Enable swapping on a given device/file.
14 
15     -d	Discard freed SSD pages
16     -p	Priority (highest priority areas allocated first)
17 */
18 
19 #define FOR_swapon
20 #include "toys.h"
21 
GLOBALS(long p;)22 GLOBALS(
23   long p;
24 )
25 
26 void swapon_main(void)
27 {
28   // SWAP_FLAG_DISCARD|SWAP_FLAG_DISCARD_ONCE|SWAP_FLAG_DISCARD_PAGES
29   int flags = FLAG(d)*0x70000;
30 
31   if (FLAG(p)) flags |= SWAP_FLAG_PREFER | (TT.p << SWAP_FLAG_PRIO_SHIFT);
32   if (swapon(*toys.optargs, flags))
33     perror_exit("Couldn't swapon '%s'", *toys.optargs);
34 }
35