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 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("warning: swap file has holes");
28 if (applet_name
[5] == 'n')
29 status
= swapon(device
, 0);
31 status
= swapoff(device
);
34 bb_simple_perror_msg(device
);
41 static int do_em_all(void)
47 f
= setmntent("/etc/fstab", "r");
49 bb_perror_msg_and_die("/etc/fstab");
52 while ((m
= getmntent(f
)) != NULL
)
53 if (strcmp(m
->mnt_type
, MNTTYPE_SWAP
) == 0)
54 err
+= swap_enable_disable(m
->mnt_fsname
);
61 int swap_on_off_main(int argc
, char **argv
) MAIN_EXTERNALLY_VISIBLE
;
62 int swap_on_off_main(int argc
, char **argv
)
69 ret
= getopt32(argv
, "a");
73 /* ret = 0; redundant */
75 ret
+= swap_enable_disable(*argv
);