mkswap: fix help text to not lie about supported options.

mkswap: use uint32, not int, to match kernel.
mkswap: optimization: use pre-zeroed buffer
This commit is contained in:
Denis Vlasenko 2008-02-13 15:35:52 +00:00
parent 3b92eaac53
commit 9d96af2e83
2 changed files with 72 additions and 34 deletions

View File

@ -2335,14 +2335,17 @@ USE_FEATURE_BRCTL_FANCY("\n" \
"$ mknod -m 644 /tmp/pipe p\n" "$ mknod -m 644 /tmp/pipe p\n"
#define mkswap_trivial_usage \ #define mkswap_trivial_usage \
"[-c] [-v0|-v1] device [block-count]" "DEVICE"
#define mkswap_full_usage \ #define mkswap_full_usage \
"Prepare a disk partition to be used as swap partition" \ "Prepare block device to be used as swap partition"
"\n\nOptions:\n" \ #if 0
" -c Check for read-ability\n" \ "[-c] [-v0|-v1] DEVICE [BLOCKS]"
" -v0 Make version 0 swap [max 128 Megs]\n" \ "\n\nOptions:"
" -v1 Make version 1 swap [big!] (default for kernels > 2.1.117)\n" \ "\n -c Check for readability"
" block-count Number of block to use (default is entire partition)" "\n -v0 Make swap version 0 (max 128M)"
"\n -v1 Make swap version 1 (default for kernels > 2.1.117)"
"\n BLOCKS Number of blocks to use (default is entire partition)"
#endif
#define mktemp_trivial_usage \ #define mktemp_trivial_usage \
"[-dt] [-p DIR] TEMPLATE" "[-dt] [-p DIR] TEMPLATE"
@ -3312,34 +3315,36 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
#define sort_trivial_usage \ #define sort_trivial_usage \
"[-nru" \ "[-nru" \
USE_FEATURE_SORT_BIG("gMcszbdfimSTokt] [-o outfile] [-k start[.offset][opts][,end[.offset][opts]] [-t char") \ USE_FEATURE_SORT_BIG("gMcszbdfimSTokt] [-o FILE] [-k start[.offset][opts][,end[.offset][opts]] [-t CHAR") \
"] [FILE]..." "] [FILE]..."
#define sort_full_usage \ #define sort_full_usage \
"Sort lines of text in the specified files" \ "Sort lines of text in the specified files" \
"\n\nOptions:\n" \ "\n\nOptions:" \
USE_FEATURE_SORT_BIG( \ USE_FEATURE_SORT_BIG( \
" -b Ignore leading blanks\n" \ "\n -b Ignore leading blanks" \
" -c Check whether input is sorted\n" \ "\n -c Check whether input is sorted" \
" -d Dictionary order (blank or alphanumeric only)\n" \ "\n -d Dictionary order (blank or alphanumeric only)" \
" -f Ignore case\n" \ "\n -f Ignore case" \
" -g General numerical sort\n" \ "\n -g General numerical sort" \
" -i Ignore unprintable characters\n" \ "\n -i Ignore unprintable characters" \
" -k Sort key\n" \ "\n -k Sort key" \
" -M Sort month\n") \ "\n -M Sort month" \
" -n Sort numbers\n" \ ) \
"\n -n Sort numbers" \
USE_FEATURE_SORT_BIG( \ USE_FEATURE_SORT_BIG( \
" -o Output to file\n" \ "\n -o Output to file" \
" -k Sort by key\n" \ "\n -k Sort by key" \
" -t Use key separator other than whitespace\n") \ "\n -t CHAR Key separator" \
" -r Reverse sort order\n" \ ) \
"\n -r Reverse sort order" \
USE_FEATURE_SORT_BIG( \ USE_FEATURE_SORT_BIG( \
" -s Stable (don't sort ties alphabetically)\n") \ "\n -s Stable (don't sort ties alphabetically)" \
" -u Suppress duplicate lines" \ ) \
"\n -u Suppress duplicate lines" \
USE_FEATURE_SORT_BIG( \ USE_FEATURE_SORT_BIG( \
"\n -z Input terminated by nulls, not newlines\n") \ "\n -z Lines are terminated by NUL, not newline" \
USE_FEATURE_SORT_BIG( \ "\n -mST Ignored for GNU compatibility") \
" -mST Ignored for GNU compatibility") \
""
#define sort_example_usage \ #define sort_example_usage \
"$ echo -e \"e\\nf\\nb\\nd\\nc\\na\" | sort\n" \ "$ echo -e \"e\\nf\\nb\\nd\\nc\\na\" | sort\n" \
"a\n" \ "a\n" \

View File

@ -50,12 +50,47 @@ static void mkswap_selinux_setcontext(int fd, const char *path)
#define mkswap_selinux_setcontext(fd, path) ((void)0) #define mkswap_selinux_setcontext(fd, path) ((void)0)
#endif #endif
#if 0 /* from Linux 2.6.23 */
/*
* Magic header for a swap area. The first part of the union is
* what the swap magic looks like for the old (limited to 128MB)
* swap area format, the second part of the union adds - in the
* old reserved area - some extra information. Note that the first
* kilobyte is reserved for boot loader or disk label stuff...
*/
union swap_header {
struct {
char reserved[PAGE_SIZE - 10];
char magic[10]; /* SWAP-SPACE or SWAPSPACE2 */
} magic;
struct {
char bootbits[1024]; /* Space for disklabel etc. */
__u32 version; /* second kbyte, word 0 */
__u32 last_page; /* 1 */
__u32 nr_badpages; /* 2 */
unsigned char sws_uuid[16]; /* 3,4,5,6 */
unsigned char sws_volume[16]; /* 7,8,9,10 */
__u32 padding[117]; /* 11..127 */
__u32 badpages[1]; /* 128, total 129 32-bit words */
} info;
};
#endif
#define NWORDS 129
#define hdr ((uint32_t*)(&bb_common_bufsiz1))
struct BUG_bufsiz1_is_too_small {
char BUG_bufsiz1_is_too_small[COMMON_BUFSIZE < (NWORDS * 4) ? -1 : 1];
};
/* Stored without terminating NUL */
static const char SWAPSPACE2[sizeof("SWAPSPACE2")-1] ALIGN1 = "SWAPSPACE2";
int mkswap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int mkswap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int mkswap_main(int argc, char **argv) int mkswap_main(int argc, char **argv)
{ {
int fd, pagesize; int fd, pagesize;
off_t len; off_t len;
unsigned int hdr[129];
// No options supported. // No options supported.
@ -74,9 +109,7 @@ int mkswap_main(int argc, char **argv)
len - pagesize); len - pagesize);
mkswap_selinux_setcontext(fd, argv[1]); mkswap_selinux_setcontext(fd, argv[1]);
// Make a header. // Make a header. hdr is zero-filled so far...
memset(hdr, 0, sizeof(hdr));
hdr[0] = 1; hdr[0] = 1;
hdr[1] = (len / pagesize) - 1; hdr[1] = (len / pagesize) - 1;
@ -84,9 +117,9 @@ int mkswap_main(int argc, char **argv)
// signature on disk (not in cache) during swapon. // signature on disk (not in cache) during swapon.
xlseek(fd, 1024, SEEK_SET); xlseek(fd, 1024, SEEK_SET);
xwrite(fd, hdr, sizeof(hdr)); xwrite(fd, hdr, NWORDS * 4);
xlseek(fd, pagesize - 10, SEEK_SET); xlseek(fd, pagesize - 10, SEEK_SET);
xwrite(fd, "SWAPSPACE2", 10); xwrite(fd, SWAPSPACE2, 10);
fsync(fd); fsync(fd);
if (ENABLE_FEATURE_CLEAN_UP) close(fd); if (ENABLE_FEATURE_CLEAN_UP) close(fd);