1 /* vi: set sw=4 ts=4: */
3 * Mini swapon/swapoff implementation for busybox
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7 * Licensed under the GPL v2, see the file LICENSE in this tarball.
16 #include <sys/mount.h>
21 static int swap_enable_disable(const char *device)
26 if (stat(device, &st) < 0)
27 bb_perror_msg_and_die("cannot stat %s", device);
30 if (S_ISREG(st.st_mode))
31 if (st.st_blocks * 512 < st.st_size)
32 bb_error_msg_and_die("swap file has holes");
34 if (bb_applet_name[5] == 'n')
35 status = swapon(device, 0);
37 status = swapoff(device);
40 bb_perror_msg("%s", device);
47 static int do_em_all(void)
53 f = setmntent("/etc/fstab", "r");
55 bb_perror_msg_and_die("/etc/fstab");
58 while ((m = getmntent(f)) != NULL)
59 if (strcmp(m->mnt_type, MNTTYPE_SWAP) == 0)
60 err += swap_enable_disable(m->mnt_fsname);
69 extern int swap_on_off_main(int argc, char **argv)
76 ret = bb_getopt_ulflags(argc, argv, "a");
82 ret += swap_enable_disable(*argv);