source: MondoRescue/branches/2.2.5/mindi-busybox/util-linux/swaponoff.c@ 1765

Last change on this file since 1765 was 1765, checked in by Bruno Cornec, 16 years ago

Update to busybox 1.7.2

File size: 1.3 KB
RevLine 
[821]1/* vi: set sw=4 ts=4: */
2/*
3 * Mini swapon/swapoff implementation for busybox
4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 *
[1765]7 * Licensed under the GPL version 2, see the file LICENSE in this tarball.
[821]8 */
9
[1765]10#include "libbb.h"
[821]11#include <mntent.h>
12#include <sys/swap.h>
13
[1765]14static int swap_enable_disable(char *device)
[821]15{
16 int status;
17 struct stat st;
18
19 xstat(device, &st);
20
[1765]21#if ENABLE_DESKTOP
[821]22 /* test for holes */
23 if (S_ISREG(st.st_mode))
24 if (st.st_blocks * 512 < st.st_size)
[1765]25 bb_error_msg("warning: swap file has holes");
26#endif
[821]27
[1765]28 if (applet_name[5] == 'n')
[821]29 status = swapon(device, 0);
30 else
31 status = swapoff(device);
32
33 if (status != 0) {
34 bb_perror_msg("%s", device);
35 return 1;
36 }
37
38 return 0;
39}
40
41static int do_em_all(void)
42{
43 struct mntent *m;
44 FILE *f;
45 int err;
46
47 f = setmntent("/etc/fstab", "r");
48 if (f == NULL)
49 bb_perror_msg_and_die("/etc/fstab");
50
51 err = 0;
52 while ((m = getmntent(f)) != NULL)
53 if (strcmp(m->mnt_type, MNTTYPE_SWAP) == 0)
54 err += swap_enable_disable(m->mnt_fsname);
55
56 endmntent(f);
57
58 return err;
59}
60
[1765]61int swap_on_off_main(int argc, char **argv);
[821]62int swap_on_off_main(int argc, char **argv)
63{
64 int ret;
65
66 if (argc == 1)
67 bb_show_usage();
68
[1765]69 ret = getopt32(argv, "a");
70 if (ret)
[821]71 return do_em_all();
72
[1765]73 /* ret = 0; redundant */
[821]74 while (*++argv)
75 ret += swap_enable_disable(*argv);
76 return ret;
77}
Note: See TracBrowser for help on using the repository browser.