latest and greatest.
[oweals/busybox.git] / swapon.c
1 #include <stdio.h>
2 #include <mntent.h>
3 #include <sys/swap.h>
4 #include "internal.h"
5
6 const char      swapon_usage[] = "swapon block-device\n"
7 "\n"
8 "\tSwap virtual memory pages on the given device.\n";
9
10 extern int
11 swapon_fn(const struct FileInfo * i)
12 {
13         FILE *swapsTable;
14         struct mntent m;
15
16         if (!(swapon(i->source, 0))) {
17                 if ((swapsTable = setmntent("/etc/swaps", "a+"))) {
18                         /* Needs the cast to avoid warning about conversion from
19                          * const char* to just  char*
20                          */
21                         m.mnt_fsname = (char*)i->source;
22                         m.mnt_dir = "none";
23                         m.mnt_type = "swap";
24                         m.mnt_opts = "sw";
25                         m.mnt_freq = 0;
26                         m.mnt_passno = 0;
27                         addmntent(swapsTable, &m);
28                         endmntent(swapsTable);
29                 }
30                 return (0);
31         }
32         return (-1);
33 }
34