2 * Mini swapon/swapoff implementation for busybox
5 * Copyright (C) 1999 by Lineo, inc.
6 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <sys/mount.h>
35 static const char* appName;
37 static const char swapoff_usage[] =
39 "\nStop swapping virtual memory pages on the given device.\n";
40 static const char swapon_usage[] =
42 "\nStart swapping virtual memory pages on the given device.\n";
50 swap_enable_disable( char *device)
53 if ( whichApp == SWAPON_APP )
54 status = swapon(device, 0);
56 status = swapoff(device);
68 char swapName[NAME_MAX];
69 FILE *f = setmntent ("/etc/fstab", "r");
75 while ((m = getmntent (f)) != NULL) {
76 if (!strstr (m->mnt_type, "swap")) {
77 swap_enable_disable( swapName);
86 swap_on_off_main(int argc, char * * argv)
89 if (stat("/etc/fstab", &statBuf) < 0)
90 fprintf(stderr, "/etc/fstab file missing -- Please install one.\n\n");
92 if (strcmp(*argv, "swapon")==0) {
94 whichApp = SWAPON_APP;
98 whichApp = SWAPOFF_APP;
106 /* Parse any options */
107 while (**argv == '-') {
108 while (*++(*argv)) switch (**argv) {
116 swap_enable_disable(*argv);
120 usage( (whichApp==SWAPON_APP)? swapon_usage : swapoff_usage);