summaryrefslogtreecommitdiff
path: root/swapon.c
blob: 78360a55f01ef1c034e115c7abd7cae61a6fdc29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <mntent.h>
#include <sys/swap.h>
#include "internal.h"

const char	swapon_usage[] = "swapon block-device\n"
"\n"
"\tSwap virtual memory pages on the given device.\n";

extern int
swapon_fn(const struct FileInfo * i)
{
	FILE *swapsTable;
	struct mntent m;

        if (!(swapon(i->source, 0))) {
		if ((swapsTable = setmntent("/etc/swaps", "a+"))) {
			/* Needs the cast to avoid warning about conversion from
			 * const char* to just  char*
			 */
			m.mnt_fsname = (char*)i->source;
			m.mnt_dir = "none";
			m.mnt_type = "swap";
			m.mnt_opts = "sw";
			m.mnt_freq = 0;
			m.mnt_passno = 0;
			addmntent(swapsTable, &m);
			endmntent(swapsTable);
		}
		return (0);
	}
	return (-1);
}