10f66f451Sopenharmony_ci/* swapon.c - Enable region for swapping 20f66f451Sopenharmony_ci * 30f66f451Sopenharmony_ci * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com> 40f66f451Sopenharmony_ci 50f66f451Sopenharmony_ciUSE_SWAPON(NEWTOY(swapon, "<1>1p#<0>32767d", TOYFLAG_SBIN|TOYFLAG_NEEDROOT)) 60f66f451Sopenharmony_ci 70f66f451Sopenharmony_ciconfig SWAPON 80f66f451Sopenharmony_ci bool "swapon" 90f66f451Sopenharmony_ci default y 100f66f451Sopenharmony_ci help 110f66f451Sopenharmony_ci usage: swapon [-d] [-p priority] filename 120f66f451Sopenharmony_ci 130f66f451Sopenharmony_ci Enable swapping on a given device/file. 140f66f451Sopenharmony_ci 150f66f451Sopenharmony_ci -d Discard freed SSD pages 160f66f451Sopenharmony_ci -p Priority (highest priority areas allocated first) 170f66f451Sopenharmony_ci*/ 180f66f451Sopenharmony_ci 190f66f451Sopenharmony_ci#define FOR_swapon 200f66f451Sopenharmony_ci#include "toys.h" 210f66f451Sopenharmony_ci 220f66f451Sopenharmony_ciGLOBALS( 230f66f451Sopenharmony_ci long p; 240f66f451Sopenharmony_ci) 250f66f451Sopenharmony_ci 260f66f451Sopenharmony_civoid swapon_main(void) 270f66f451Sopenharmony_ci{ 280f66f451Sopenharmony_ci // 0x70000 = SWAP_FLAG_DISCARD|SWAP_FLAG_DISCARD_ONCE|SWAP_FLAG_DISCARD_PAGES 290f66f451Sopenharmony_ci int flags = (toys.optflags&FLAG_d)*0x70000; 300f66f451Sopenharmony_ci 310f66f451Sopenharmony_ci if (toys.optflags) 320f66f451Sopenharmony_ci flags |= SWAP_FLAG_PREFER | (TT.p << SWAP_FLAG_PRIO_SHIFT); 330f66f451Sopenharmony_ci 340f66f451Sopenharmony_ci if (swapon(*toys.optargs, flags)) 350f66f451Sopenharmony_ci perror_exit("Couldn't swapon '%s'", *toys.optargs); 360f66f451Sopenharmony_ci} 37