1/* swapon.c - Enable region for swapping
2 *
3 * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
4
5USE_SWAPON(NEWTOY(swapon, "<1>1p#<0>32767d", TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
6
7config 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*/
17
18#define FOR_swapon
19#include "toys.h"
20
21GLOBALS(
22  long priority;
23)
24
25void swapon_main(void)
26{
27  // 0x70000 = SWAP_FLAG_DISCARD|SWAP_FLAG_DISCARD_ONCE|SWAP_FLAG_DISCARD_PAGES
28  int flags = (toys.optflags&FLAG_d)*0x70000;
29
30  if (toys.optflags)
31    flags |= SWAP_FLAG_PREFER | (TT.priority << SWAP_FLAG_PRIO_SHIFT);
32
33  if (swapon(*toys.optargs, flags))
34    perror_exit("Couldn't swapon '%s'", *toys.optargs);
35}
36