source: MondoRescue/branches/2.2.5/mindi-busybox/util-linux/mkswap.c@ 1765

Last change on this file since 1765 was 1765, checked in by Bruno Cornec, 16 years ago

Update to busybox 1.7.2

File size: 1.1 KB
RevLine 
[821]1/* vi: set sw=4 ts=4: */
[1765]2/* mkswap.c - format swap device (Linux v1 only)
[821]3 *
[1765]4 * Copyright 2006 Rob Landley <rob@landley.net>
[821]5 *
[1765]6 * Licensed under GPL version 2, see file LICENSE in this tarball for details.
[821]7 */
8
[1765]9#include "libbb.h"
[821]10
[1765]11int mkswap_main(int argc, char **argv);
[821]12int mkswap_main(int argc, char **argv)
13{
[1765]14 int fd, pagesize;
15 off_t len;
16 unsigned int hdr[129];
[821]17
[1765]18 // No options supported.
[821]19
[1765]20 if (argc != 2) bb_show_usage();
[821]21
[1765]22 // Figure out how big the device is and announce our intentions.
[821]23
[1765]24 fd = xopen(argv[1], O_RDWR);
25 len = fdlength(fd);
26 pagesize = getpagesize();
27 printf("Setting up swapspace version 1, size = %"OFF_FMT"d bytes\n",
28 len - pagesize);
[821]29
[1765]30 // Make a header.
[821]31
[1765]32 memset(hdr, 0, sizeof(hdr));
33 hdr[0] = 1;
34 hdr[1] = (len / pagesize) - 1;
[821]35
[1765]36 // Write the header. Sync to disk because some kernel versions check
37 // signature on disk (not in cache) during swapon.
[821]38
[1765]39 xlseek(fd, 1024, SEEK_SET);
40 xwrite(fd, hdr, sizeof(hdr));
41 xlseek(fd, pagesize-10, SEEK_SET);
42 xwrite(fd, "SWAPSPACE2", 10);
43 fsync(fd);
[821]44
[1765]45 if (ENABLE_FEATURE_CLEAN_UP) close(fd);
[821]46
[1765]47 return 0;
[821]48}
Note: See TracBrowser for help on using the repository browser.