comparison toys/other/mkswap.c @ 653:2986aa63a021

Move commands into "posix", "lsb", and "other" menus/directories.
author Rob Landley <rob@landley.net>
date Sat, 25 Aug 2012 14:25:22 -0500
parents toys/mkswap.c@d51be130fda2
children 6df4ccc0acbe
comparison
equal deleted inserted replaced
652:2d7c56913fda 653:2986aa63a021
1 /* vi: set sw=4 ts=4:
2 *
3 * mkswap.c - Format swap device.
4 *
5 * Copyright 2009 Rob Landley <rob@landley.net>
6 *
7 * Not in SUSv4.
8
9 USE_MKSWAP(NEWTOY(mkswap, "<1>1", TOYFLAG_SBIN))
10
11 config MKSWAP
12 bool "mkswap"
13 default y
14 help
15 usage: mkswap DEVICE
16
17 Sets up a Linux swap area on a device or file.
18 */
19
20 #include "toys.h"
21
22 void mkswap_main(void)
23 {
24 int fd = xopen(*toys.optargs, O_RDWR), pagesize = sysconf(_SC_PAGE_SIZE);
25 off_t len = fdlength(fd);
26 unsigned int pages = (len/pagesize)-1, *swap = (unsigned int *)toybuf;
27
28 // Write header. Note that older kernel versions checked signature
29 // on disk (not in cache) during swapon, so sync after writing.
30
31 swap[0] = 1;
32 swap[1] = pages;
33 xlseek(fd, 1024, SEEK_SET);
34 xwrite(fd, swap, 129*sizeof(unsigned int));
35 xlseek(fd, pagesize-10, SEEK_SET);
36 xwrite(fd, "SWAPSPACE2", 10);
37 fsync(fd);
38
39 if (CFG_TOYBOX_FREE) close(fd);
40
41 printf("Swapspace size: %luk\n", pages*(unsigned long)(pagesize/1024));
42 }