• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* swapon.c - Enable region for swapping
2  *
3  * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
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   // 0x70000 = SWAP_FLAG_DISCARD|SWAP_FLAG_DISCARD_ONCE|SWAP_FLAG_DISCARD_PAGES
29   int flags = (toys.optflags&FLAG_d)*0x70000;
30 
31   if (toys.optflags)
32     flags |= SWAP_FLAG_PREFER | (TT.p << SWAP_FLAG_PRIO_SHIFT);
33 
34   if (swapon(*toys.optargs, flags))
35     perror_exit("Couldn't swapon '%s'", *toys.optargs);
36 }
37