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 GPL version 2, 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 = xopen(argv[1], O_RDWR);
25 pagesize = getpagesize();
26 printf("Setting up swapspace version 1, size = %"OFF_FMT"d bytes\n",
31 memset(hdr, 0, sizeof(hdr));
33 hdr[1] = (len / pagesize) - 1;
35 // Write the header. Sync to disk because some kernel versions check
36 // signature on disk (not in cache) during swapon.
38 xlseek(fd, 1024, SEEK_SET);
39 xwrite(fd, hdr, sizeof(hdr));
40 xlseek(fd, pagesize-10, SEEK_SET);
41 xwrite(fd, "SWAPSPACE2", 10);
44 if (ENABLE_FEATURE_CLEAN_UP) close(fd);