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);
12 int mkswap_main(int argc, char **argv)
16 unsigned int hdr[129];
18 // No options supported.
20 if (argc != 2) bb_show_usage();
22 // Figure out how big the device is and announce our intentions.
24 fd = xopen(argv[1], O_RDWR);
26 pagesize = getpagesize();
27 printf("Setting up swapspace version 1, size = %"OFF_FMT"d bytes\n",
32 memset(hdr, 0, sizeof(hdr));
34 hdr[1] = (len / pagesize) - 1;
36 // Write the header. Sync to disk because some kernel versions check
37 // signature on disk (not in cache) during swapon.
39 xlseek(fd, 1024, SEEK_SET);
40 xwrite(fd, hdr, sizeof(hdr));
41 xlseek(fd, pagesize-10, SEEK_SET);
42 xwrite(fd, "SWAPSPACE2", 10);
45 if (ENABLE_FEATURE_CLEAN_UP) close(fd);