annotate toys/swapon.c @ 483:26db0cd433f3

Minor tweaks.
author Rob Landley <rob@landley.net>
date Sun, 19 Feb 2012 17:37:49 -0600
parents b4a9fd8773d6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
482
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
1 /* vi: set sw=4 ts=4:
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
2 *
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
3 * swapon.c - Enable region for swapping
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
4 *
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
5 * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
6 *
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
7 * Not in SUSv4.
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
8
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
9 USE_SWAPON(NEWTOY(swapon, "<1>1p#<0>32767", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
10
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
11 config SWAPON
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
12 bool "swapon"
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
13 default y
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
14 help
483
26db0cd433f3 Minor tweaks.
Rob Landley <rob@landley.net>
parents: 482
diff changeset
15 usage: swapon [-p priority] filename
482
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
16
483
26db0cd433f3 Minor tweaks.
Rob Landley <rob@landley.net>
parents: 482
diff changeset
17 Enable swapping on a given device/file.
482
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
18 */
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
19
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
20 #include "toys.h"
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
21
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
22 DEFINE_GLOBALS(
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
23 long priority;
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
24 )
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
25
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
26 #define TT this.swapon
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
27
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
28 void swapon_main(void)
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
29 {
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
30 int flags = 0;
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
31
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
32 if (toys.optflags & 1)
483
26db0cd433f3 Minor tweaks.
Rob Landley <rob@landley.net>
parents: 482
diff changeset
33 flags = SWAP_FLAG_PREFER | (TT.priority << SWAP_FLAG_PRIO_SHIFT);
482
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
34
483
26db0cd433f3 Minor tweaks.
Rob Landley <rob@landley.net>
parents: 482
diff changeset
35 if (swapon(*toys.optargs, flags))
26db0cd433f3 Minor tweaks.
Rob Landley <rob@landley.net>
parents: 482
diff changeset
36 perror_exit("Couldn't swapon '%s'", *toys.optargs);
482
b4a9fd8773d6 Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
37 }