annotate toys/mkswap.c @ 562:4d802d438983

Match uint64_t with PRIu64 to avoid warnings on 64 bit builds.
author Rob Landley <rob@landley.net>
date Sat, 14 Apr 2012 21:27:00 -0500
parents d51be130fda2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
340
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* vi: set sw=4 ts=4:
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * mkswap.c - Format swap device.
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 * Copyright 2009 Rob Landley <rob@landley.net>
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 *
395
32c7b6af5b29 Whitespace/wordwrap changes.
Rob Landley <rob@landley.net>
parents: 340
diff changeset
7 * Not in SUSv4.
340
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
8
481
e1b9a8579ddb mkswap helpstring and argument string
Elie De Brauwer <eliedebrauwer@gmail.com>
parents: 395
diff changeset
9 USE_MKSWAP(NEWTOY(mkswap, "<1>1", TOYFLAG_SBIN))
340
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
10
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 config MKSWAP
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 bool "mkswap"
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 default y
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
14 help
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
15 usage: mkswap DEVICE
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
16
481
e1b9a8579ddb mkswap helpstring and argument string
Elie De Brauwer <eliedebrauwer@gmail.com>
parents: 395
diff changeset
17 Sets up a Linux swap area on a device or file.
340
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
18 */
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
19
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 #include "toys.h"
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
21
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 void mkswap_main(void)
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 {
535
d51be130fda2 More stabs at getting #includes right, and moving off of deprecated functions.
Rob Landley <rob@landley.net>
parents: 481
diff changeset
24 int fd = xopen(*toys.optargs, O_RDWR), pagesize = sysconf(_SC_PAGE_SIZE);
340
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
25 off_t len = fdlength(fd);
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
26 unsigned int pages = (len/pagesize)-1, *swap = (unsigned int *)toybuf;
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
27
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
28 // Write header. Note that older kernel versions checked signature
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
29 // on disk (not in cache) during swapon, so sync after writing.
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
30
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
31 swap[0] = 1;
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
32 swap[1] = pages;
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
33 xlseek(fd, 1024, SEEK_SET);
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
34 xwrite(fd, swap, 129*sizeof(unsigned int));
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
35 xlseek(fd, pagesize-10, SEEK_SET);
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
36 xwrite(fd, "SWAPSPACE2", 10);
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
37 fsync(fd);
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
38
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
39 if (CFG_TOYBOX_FREE) close(fd);
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
40
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
41 printf("Swapspace size: %luk\n", pages*(unsigned long)(pagesize/1024));
6e03d6a8df23 Add mkswap.
Rob Landley <rob@landley.net>
parents:
diff changeset
42 }