diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2026-02-03 07:23:13 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2026-02-03 09:10:25 +0100 |
| commit | 3e8010196325c49537fdcfddf58a1b68ae84945b (patch) | |
| tree | c1890cc4d07b55976217f01d5bc48e75bae03be4 /util-linux | |
| parent | 4855fbe6a84ae151be66d82f4b0dcb4601ac457e (diff) | |
| download | busybox-w32-3e8010196325c49537fdcfddf58a1b68ae84945b.tar.gz busybox-w32-3e8010196325c49537fdcfddf58a1b68ae84945b.tar.bz2 busybox-w32-3e8010196325c49537fdcfddf58a1b68ae84945b.zip | |
uuidgen: move UUID formatting to libbb
function old new delta
format_uuid_DCE_37_chars - 94 +94
uuidgen_main 71 53 -18
.rodata 107089 107066 -23
mkswap_main 278 253 -25
volume_id_set_uuid 258 178 -80
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/4 up/down: 94/-146) Total: -52 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
| -rw-r--r-- | util-linux/fdisk_gpt.c | 6 | ||||
| -rw-r--r-- | util-linux/mkswap.c | 16 | ||||
| -rw-r--r-- | util-linux/uuidgen.c | 9 | ||||
| -rw-r--r-- | util-linux/volume_id/util.c | 8 |
4 files changed, 13 insertions, 26 deletions
diff --git a/util-linux/fdisk_gpt.c b/util-linux/fdisk_gpt.c index 60c7c1570..ec8818ec3 100644 --- a/util-linux/fdisk_gpt.c +++ b/util-linux/fdisk_gpt.c | |||
| @@ -59,9 +59,9 @@ gpt_print_guid(uint8_t *buf) | |||
| 59 | { | 59 | { |
| 60 | printf( | 60 | printf( |
| 61 | "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", | 61 | "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
| 62 | buf[3], buf[2], buf[1], buf[0], | 62 | buf[3], buf[2], buf[1], buf[0], /* GPT byteswaps... */ |
| 63 | buf[5], buf[4], | 63 | buf[5], buf[4], /* ...these */ |
| 64 | buf[7], buf[6], | 64 | buf[7], buf[6], /* ...fields */ |
| 65 | buf[8], buf[9], | 65 | buf[8], buf[9], |
| 66 | buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]); | 66 | buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]); |
| 67 | } | 67 | } |
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c index f80457a31..bca3de199 100644 --- a/util-linux/mkswap.c +++ b/util-linux/mkswap.c | |||
| @@ -91,7 +91,7 @@ struct swap_header_v1 { | |||
| 91 | uint32_t version; /* second kbyte, word 0 */ | 91 | uint32_t version; /* second kbyte, word 0 */ |
| 92 | uint32_t last_page; /* 1 */ | 92 | uint32_t last_page; /* 1 */ |
| 93 | uint32_t nr_badpages; /* 2 */ | 93 | uint32_t nr_badpages; /* 2 */ |
| 94 | char sws_uuid[16]; /* 3,4,5,6 */ | 94 | uint8_t sws_uuid[16]; /* 3,4,5,6 */ |
| 95 | char sws_volume[16]; /* 7,8,9,10 */ | 95 | char sws_volume[16]; /* 7,8,9,10 */ |
| 96 | uint32_t padding[117]; /* 11..127 */ | 96 | uint32_t padding[117]; /* 11..127 */ |
| 97 | uint32_t badpages[1]; /* 128 */ | 97 | uint32_t badpages[1]; /* 128 */ |
| @@ -148,17 +148,11 @@ int mkswap_main(int argc UNUSED_PARAM, char **argv) | |||
| 148 | hdr->last_page = (uoff_t)len / pagesize; | 148 | hdr->last_page = (uoff_t)len / pagesize; |
| 149 | 149 | ||
| 150 | if (ENABLE_FEATURE_MKSWAP_UUID) { | 150 | if (ENABLE_FEATURE_MKSWAP_UUID) { |
| 151 | char uuid_string[32]; | 151 | char uuid_string37[37]; |
| 152 | generate_uuid((void*)hdr->sws_uuid); | ||
| 153 | bin2hex(uuid_string, hdr->sws_uuid, 16); | ||
| 154 | /* f.e. UUID=dfd9c173-be52-4d27-99a5-c34c6c2ff55f */ | 152 | /* f.e. UUID=dfd9c173-be52-4d27-99a5-c34c6c2ff55f */ |
| 155 | printf("UUID=%.8s" "-%.4s-%.4s-%.4s-%.12s\n", | 153 | generate_uuid(hdr->sws_uuid); |
| 156 | uuid_string, | 154 | format_uuid_DCE_37_chars(uuid_string37, hdr->sws_uuid); |
| 157 | uuid_string+8, | 155 | printf("UUID=%s\n", uuid_string37); |
| 158 | uuid_string+8+4, | ||
| 159 | uuid_string+8+4+4, | ||
| 160 | uuid_string+8+4+4+4 | ||
| 161 | ); | ||
| 162 | } | 156 | } |
| 163 | safe_strncpy(hdr->sws_volume, label, 16); | 157 | safe_strncpy(hdr->sws_volume, label, 16); |
| 164 | 158 | ||
diff --git a/util-linux/uuidgen.c b/util-linux/uuidgen.c index c2e1dd4da..96d7cd1db 100644 --- a/util-linux/uuidgen.c +++ b/util-linux/uuidgen.c | |||
| @@ -36,22 +36,21 @@ | |||
| 36 | * Otherwise, it will choose a time-based UUID." | 36 | * Otherwise, it will choose a time-based UUID." |
| 37 | */ | 37 | */ |
| 38 | #include "libbb.h" | 38 | #include "libbb.h" |
| 39 | #include "volume_id/volume_id_internal.h" | ||
| 40 | 39 | ||
| 41 | /* This is a NOFORK applet. Be very careful! */ | 40 | /* This is a NOFORK applet. Be very careful! */ |
| 42 | 41 | ||
| 43 | int uuidgen_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 42 | int uuidgen_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 44 | int uuidgen_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | 43 | int uuidgen_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
| 45 | { | 44 | { |
| 46 | struct volume_id id; | 45 | char str37[37]; |
| 47 | uint8_t uuid[16]; | 46 | uint8_t uuid[16]; |
| 48 | 47 | ||
| 49 | /* support/ignore -r (--random) */ | 48 | /* support/ignore -r (--random) */ |
| 50 | getopt32(argv, "^" "r" "\0" "=0"/* no args!*/); | 49 | getopt32(argv, "^" "r" "\0" "=0"/* no args!*/); |
| 51 | 50 | ||
| 52 | generate_uuid(uuid); | 51 | generate_uuid(uuid); |
| 53 | volume_id_set_uuid(&id, uuid, UUID_DCE); | 52 | format_uuid_DCE_37_chars(str37, uuid); |
| 54 | puts(id.uuid); | 53 | puts(str37); |
| 55 | 54 | ||
| 56 | return 0; | 55 | fflush_stdout_and_exit_SUCCESS(); |
| 57 | } | 56 | } |
diff --git a/util-linux/volume_id/util.c b/util-linux/volume_id/util.c index 061545fde..ddfe98d50 100644 --- a/util-linux/volume_id/util.c +++ b/util-linux/volume_id/util.c | |||
| @@ -158,13 +158,7 @@ set: | |||
| 158 | buf[3], buf[2], buf[1], buf[0]); | 158 | buf[3], buf[2], buf[1], buf[0]); |
| 159 | break; | 159 | break; |
| 160 | case UUID_DCE: | 160 | case UUID_DCE: |
| 161 | sprintf(id->uuid, | 161 | format_uuid_DCE_37_chars(id->uuid, buf); |
| 162 | "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", | ||
| 163 | buf[0], buf[1], buf[2], buf[3], | ||
| 164 | buf[4], buf[5], | ||
| 165 | buf[6], buf[7], | ||
| 166 | buf[8], buf[9], | ||
| 167 | buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]); | ||
| 168 | break; | 162 | break; |
| 169 | case UUID_DCE_STRING: | 163 | case UUID_DCE_STRING: |
| 170 | memcpy(id->uuid, buf, count); | 164 | memcpy(id->uuid, buf, count); |
