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 or later, see the file LICENSE in this tarball.
18 static int swap_enable_disable(char *device)
26 if (S_ISREG(st.st_mode))
27 if (st.st_blocks * 512 < st.st_size)
28 bb_error_msg_and_die("swap file has holes");
30 if (bb_applet_name[5] == 'n')
31 status = swapon(device, 0);
33 status = swapoff(device);
36 bb_perror_msg("%s", device);
43 static int do_em_all(void)
49 f = setmntent("/etc/fstab", "r");
51 bb_perror_msg_and_die("/etc/fstab");
54 while ((m = getmntent(f)) != NULL)
55 if (strcmp(m->mnt_type, MNTTYPE_SWAP) == 0)
56 err += swap_enable_disable(m->mnt_fsname);
65 int swap_on_off_main(int argc, char **argv)
72 ret = bb_getopt_ulflags(argc, argv, "a");
78 ret += swap_enable_disable(*argv);