aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-02-13 15:35:52 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-02-13 15:35:52 +0000
commit9d96af2e83a9519ac89ff0f8dae7f8478d33f581 (patch)
tree8c871ac1119b13a2c86ef1ebd544c1a0423aea3b /util-linux
parent3b92eaac53e1557ea923d6a395f753224a73d676 (diff)
downloadbusybox-w32-9d96af2e83a9519ac89ff0f8dae7f8478d33f581.tar.gz
busybox-w32-9d96af2e83a9519ac89ff0f8dae7f8478d33f581.tar.bz2
busybox-w32-9d96af2e83a9519ac89ff0f8dae7f8478d33f581.zip
mkswap: fix help text to not lie about supported options.
mkswap: use uint32, not int, to match kernel. mkswap: optimization: use pre-zeroed buffer
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/mkswap.c45
1 files changed, 39 insertions, 6 deletions
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c
index 31d577315..bf0d7b074 100644
--- a/util-linux/mkswap.c
+++ b/util-linux/mkswap.c
@@ -50,12 +50,47 @@ static void mkswap_selinux_setcontext(int fd, const char *path)
50#define mkswap_selinux_setcontext(fd, path) ((void)0) 50#define mkswap_selinux_setcontext(fd, path) ((void)0)
51#endif 51#endif
52 52
53#if 0 /* from Linux 2.6.23 */
54/*
55 * Magic header for a swap area. The first part of the union is
56 * what the swap magic looks like for the old (limited to 128MB)
57 * swap area format, the second part of the union adds - in the
58 * old reserved area - some extra information. Note that the first
59 * kilobyte is reserved for boot loader or disk label stuff...
60 */
61union swap_header {
62 struct {
63 char reserved[PAGE_SIZE - 10];
64 char magic[10]; /* SWAP-SPACE or SWAPSPACE2 */
65 } magic;
66 struct {
67 char bootbits[1024]; /* Space for disklabel etc. */
68 __u32 version; /* second kbyte, word 0 */
69 __u32 last_page; /* 1 */
70 __u32 nr_badpages; /* 2 */
71 unsigned char sws_uuid[16]; /* 3,4,5,6 */
72 unsigned char sws_volume[16]; /* 7,8,9,10 */
73 __u32 padding[117]; /* 11..127 */
74 __u32 badpages[1]; /* 128, total 129 32-bit words */
75 } info;
76};
77#endif
78
79#define NWORDS 129
80#define hdr ((uint32_t*)(&bb_common_bufsiz1))
81
82struct BUG_bufsiz1_is_too_small {
83 char BUG_bufsiz1_is_too_small[COMMON_BUFSIZE < (NWORDS * 4) ? -1 : 1];
84};
85
86/* Stored without terminating NUL */
87static const char SWAPSPACE2[sizeof("SWAPSPACE2")-1] ALIGN1 = "SWAPSPACE2";
88
53int mkswap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 89int mkswap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
54int mkswap_main(int argc, char **argv) 90int mkswap_main(int argc, char **argv)
55{ 91{
56 int fd, pagesize; 92 int fd, pagesize;
57 off_t len; 93 off_t len;
58 unsigned int hdr[129];
59 94
60 // No options supported. 95 // No options supported.
61 96
@@ -74,9 +109,7 @@ int mkswap_main(int argc, char **argv)
74 len - pagesize); 109 len - pagesize);
75 mkswap_selinux_setcontext(fd, argv[1]); 110 mkswap_selinux_setcontext(fd, argv[1]);
76 111
77 // Make a header. 112 // Make a header. hdr is zero-filled so far...
78
79 memset(hdr, 0, sizeof(hdr));
80 hdr[0] = 1; 113 hdr[0] = 1;
81 hdr[1] = (len / pagesize) - 1; 114 hdr[1] = (len / pagesize) - 1;
82 115
@@ -84,9 +117,9 @@ int mkswap_main(int argc, char **argv)
84 // signature on disk (not in cache) during swapon. 117 // signature on disk (not in cache) during swapon.
85 118
86 xlseek(fd, 1024, SEEK_SET); 119 xlseek(fd, 1024, SEEK_SET);
87 xwrite(fd, hdr, sizeof(hdr)); 120 xwrite(fd, hdr, NWORDS * 4);
88 xlseek(fd, pagesize - 10, SEEK_SET); 121 xlseek(fd, pagesize - 10, SEEK_SET);
89 xwrite(fd, "SWAPSPACE2", 10); 122 xwrite(fd, SWAPSPACE2, 10);
90 fsync(fd); 123 fsync(fd);
91 124
92 if (ENABLE_FEATURE_CLEAN_UP) close(fd); 125 if (ENABLE_FEATURE_CLEAN_UP) close(fd);