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.
15 static int swap_enable_disable(char *device)
23 if (S_ISREG(st.st_mode))
24 if (st.st_blocks * 512 < st.st_size)
25 bb_error_msg_and_die("swap file has holes");
27 if (applet_name[5] == 'n')
28 status = swapon(device, 0);
30 status = swapoff(device);
33 bb_perror_msg("%s", device);
40 static int do_em_all(void)
46 f = setmntent("/etc/fstab", "r");
48 bb_perror_msg_and_die("/etc/fstab");
51 while ((m = getmntent(f)) != NULL)
52 if (strcmp(m->mnt_type, MNTTYPE_SWAP) == 0)
53 err += swap_enable_disable(m->mnt_fsname);
62 int swap_on_off_main(int argc, char **argv)
69 ret = getopt32(argc, argv, "a");
75 ret += swap_enable_disable(*argv);