1 /* vi: set sw=4 ts=4: */
2 /* mkswap.c - format swap device (Linux v1 only)
4 * Copyright 2006 Rob Landley <rob@landley.net>
6 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
11 int mkswap_main(int argc, char *argv[])
15 unsigned int hdr[129];
17 // No options supported.
19 if (argc!=2) bb_show_usage();
21 // Figure out how big the device is and announce our intentions.
23 fd = bb_xopen(argv[1],O_RDWR);
25 pagesize = getpagesize();
26 printf("Setting up swapspace version 1, size = %ld bytes\n", (long)(len-pagesize));
30 memset(hdr, 0, 129 * sizeof(unsigned int));
32 hdr[1] = (len / pagesize) - 1;
34 // Write the header. Sync to disk because some kernel versions check
35 // signature on disk (not in cache) during swapon.
37 xlseek(fd, 1024, SEEK_SET);
38 xwrite(fd, hdr, 129 * sizeof(unsigned int));
39 xlseek(fd, pagesize-10, SEEK_SET);
40 xwrite(fd, "SWAPSPACE2", 10);
43 if (ENABLE_FEATURE_CLEAN_UP) close(fd);