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)
29 if (S_ISREG(st.st_mode))
30 if (st.st_blocks * 512 < st.st_size)
31 bb_error_msg_and_die("swap file has holes");
33 if (bb_applet_name[5] == 'n')
34 status = swapon(device, 0);
36 status = swapoff(device);
39 bb_perror_msg("%s", device);
46 static int do_em_all(void)
52 f = setmntent("/etc/fstab", "r");
54 bb_perror_msg_and_die("/etc/fstab");
57 while ((m = getmntent(f)) != NULL)
58 if (strcmp(m->mnt_type, MNTTYPE_SWAP) == 0)
59 err += swap_enable_disable(m->mnt_fsname);
68 int swap_on_off_main(int argc, char **argv)
75 ret = bb_getopt_ulflags(argc, argv, "a");
81 ret += swap_enable_disable(*argv);