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 version 2, see the file LICENSE in this tarball.
14 #if ENABLE_FEATURE_SWAPON_PRI
18 #define G (*(struct globals*)&bb_common_bufsiz1)
19 #define g_flags (G.flags)
24 static int swap_enable_disable(char *device)
33 if (S_ISREG(st.st_mode))
34 if (st.st_blocks * (off_t)512 < st.st_size)
35 bb_error_msg("warning: swap file has holes");
38 if (applet_name[5] == 'n')
39 status = swapon(device, g_flags);
41 status = swapoff(device);
44 bb_simple_perror_msg(device);
51 static int do_em_all(void)
57 f = setmntent("/etc/fstab", "r");
59 bb_perror_msg_and_die("/etc/fstab");
62 while ((m = getmntent(f)) != NULL)
63 if (strcmp(m->mnt_type, MNTTYPE_SWAP) == 0)
64 err += swap_enable_disable(m->mnt_fsname);
71 int swap_on_off_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
72 int swap_on_off_main(int argc UNUSED_PARAM, char **argv)
76 #if !ENABLE_FEATURE_SWAPON_PRI
77 ret = getopt32(argv, "a");
79 opt_complementary = "p+";
80 ret = getopt32(argv, (applet_name[5] == 'n') ? "ap:" : "a", &g_flags);
83 g_flags = SWAP_FLAG_PREFER |
84 ((g_flags & SWAP_FLAG_PRIO_MASK) << SWAP_FLAG_PRIO_SHIFT);
89 if (ret /* & 1: not needed */) // -a
96 /* ret = 0; redundant */
98 ret += swap_enable_disable(*argv);