diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-13 15:35:52 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-13 15:35:52 +0000 |
commit | 9d96af2e83a9519ac89ff0f8dae7f8478d33f581 (patch) | |
tree | 8c871ac1119b13a2c86ef1ebd544c1a0423aea3b | |
parent | 3b92eaac53e1557ea923d6a395f753224a73d676 (diff) | |
download | busybox-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
-rw-r--r-- | include/usage.h | 61 | ||||
-rw-r--r-- | util-linux/mkswap.c | 45 |
2 files changed, 72 insertions, 34 deletions
diff --git a/include/usage.h b/include/usage.h index 37cefeab1..df15dbb46 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -2335,14 +2335,17 @@ USE_FEATURE_BRCTL_FANCY("\n" \ | |||
2335 | "$ mknod -m 644 /tmp/pipe p\n" | 2335 | "$ mknod -m 644 /tmp/pipe p\n" |
2336 | 2336 | ||
2337 | #define mkswap_trivial_usage \ | 2337 | #define mkswap_trivial_usage \ |
2338 | "[-c] [-v0|-v1] device [block-count]" | 2338 | "DEVICE" |
2339 | #define mkswap_full_usage \ | 2339 | #define mkswap_full_usage \ |
2340 | "Prepare a disk partition to be used as swap partition" \ | 2340 | "Prepare block device to be used as swap partition" |
2341 | "\n\nOptions:\n" \ | 2341 | #if 0 |
2342 | " -c Check for read-ability\n" \ | 2342 | "[-c] [-v0|-v1] DEVICE [BLOCKS]" |
2343 | " -v0 Make version 0 swap [max 128 Megs]\n" \ | 2343 | "\n\nOptions:" |
2344 | " -v1 Make version 1 swap [big!] (default for kernels > 2.1.117)\n" \ | 2344 | "\n -c Check for readability" |
2345 | " block-count Number of block to use (default is entire partition)" | 2345 | "\n -v0 Make swap version 0 (max 128M)" |
2346 | "\n -v1 Make swap version 1 (default for kernels > 2.1.117)" | ||
2347 | "\n BLOCKS Number of blocks to use (default is entire partition)" | ||
2348 | #endif | ||
2346 | 2349 | ||
2347 | #define mktemp_trivial_usage \ | 2350 | #define mktemp_trivial_usage \ |
2348 | "[-dt] [-p DIR] TEMPLATE" | 2351 | "[-dt] [-p DIR] TEMPLATE" |
@@ -3312,34 +3315,36 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when | |||
3312 | 3315 | ||
3313 | #define sort_trivial_usage \ | 3316 | #define sort_trivial_usage \ |
3314 | "[-nru" \ | 3317 | "[-nru" \ |
3315 | USE_FEATURE_SORT_BIG("gMcszbdfimSTokt] [-o outfile] [-k start[.offset][opts][,end[.offset][opts]] [-t char") \ | 3318 | USE_FEATURE_SORT_BIG("gMcszbdfimSTokt] [-o FILE] [-k start[.offset][opts][,end[.offset][opts]] [-t CHAR") \ |
3316 | "] [FILE]..." | 3319 | "] [FILE]..." |
3317 | #define sort_full_usage \ | 3320 | #define sort_full_usage \ |
3318 | "Sort lines of text in the specified files" \ | 3321 | "Sort lines of text in the specified files" \ |
3319 | "\n\nOptions:\n" \ | 3322 | "\n\nOptions:" \ |
3320 | USE_FEATURE_SORT_BIG( \ | ||
3321 | " -b Ignore leading blanks\n" \ | ||
3322 | " -c Check whether input is sorted\n" \ | ||
3323 | " -d Dictionary order (blank or alphanumeric only)\n" \ | ||
3324 | " -f Ignore case\n" \ | ||
3325 | " -g General numerical sort\n" \ | ||
3326 | " -i Ignore unprintable characters\n" \ | ||
3327 | " -k Sort key\n" \ | ||
3328 | " -M Sort month\n") \ | ||
3329 | " -n Sort numbers\n" \ | ||
3330 | USE_FEATURE_SORT_BIG( \ | 3323 | USE_FEATURE_SORT_BIG( \ |
3331 | " -o Output to file\n" \ | 3324 | "\n -b Ignore leading blanks" \ |
3332 | " -k Sort by key\n" \ | 3325 | "\n -c Check whether input is sorted" \ |
3333 | " -t Use key separator other than whitespace\n") \ | 3326 | "\n -d Dictionary order (blank or alphanumeric only)" \ |
3334 | " -r Reverse sort order\n" \ | 3327 | "\n -f Ignore case" \ |
3328 | "\n -g General numerical sort" \ | ||
3329 | "\n -i Ignore unprintable characters" \ | ||
3330 | "\n -k Sort key" \ | ||
3331 | "\n -M Sort month" \ | ||
3332 | ) \ | ||
3333 | "\n -n Sort numbers" \ | ||
3335 | USE_FEATURE_SORT_BIG( \ | 3334 | USE_FEATURE_SORT_BIG( \ |
3336 | " -s Stable (don't sort ties alphabetically)\n") \ | 3335 | "\n -o Output to file" \ |
3337 | " -u Suppress duplicate lines" \ | 3336 | "\n -k Sort by key" \ |
3337 | "\n -t CHAR Key separator" \ | ||
3338 | ) \ | ||
3339 | "\n -r Reverse sort order" \ | ||
3338 | USE_FEATURE_SORT_BIG( \ | 3340 | USE_FEATURE_SORT_BIG( \ |
3339 | "\n -z Input terminated by nulls, not newlines\n") \ | 3341 | "\n -s Stable (don't sort ties alphabetically)" \ |
3342 | ) \ | ||
3343 | "\n -u Suppress duplicate lines" \ | ||
3340 | USE_FEATURE_SORT_BIG( \ | 3344 | USE_FEATURE_SORT_BIG( \ |
3341 | " -mST Ignored for GNU compatibility") \ | 3345 | "\n -z Lines are terminated by NUL, not newline" \ |
3342 | "" | 3346 | "\n -mST Ignored for GNU compatibility") \ |
3347 | |||
3343 | #define sort_example_usage \ | 3348 | #define sort_example_usage \ |
3344 | "$ echo -e \"e\\nf\\nb\\nd\\nc\\na\" | sort\n" \ | 3349 | "$ echo -e \"e\\nf\\nb\\nd\\nc\\na\" | sort\n" \ |
3345 | "a\n" \ | 3350 | "a\n" \ |
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 | */ | ||
61 | union 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 | |||
82 | struct 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 */ | ||
87 | static const char SWAPSPACE2[sizeof("SWAPSPACE2")-1] ALIGN1 = "SWAPSPACE2"; | ||
88 | |||
53 | int mkswap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 89 | int mkswap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
54 | int mkswap_main(int argc, char **argv) | 90 | int 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); |