uuidgen: move UUID formatting to libbb
No binary (build failed)
gcc -Wp,-MD,applets/.usage.d -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -Iinclude -Iinclude -o applets/usage applets/usage.c
(log yok)
| @@ -1152,6 +1152,7 @@ void FAST_FUNC xorbuf16(void* buf, const void* mask); | |
| /* Generate a UUID */ | |
| void generate_uuid(uint8_t *buf) FAST_FUNC; | |
| + | void FAST_FUNC format_uuid_DCE_37_chars(char *dst37, const uint8_t *buf16); |
| /* Last element is marked by mult == 0 */ | |
| struct suffix_mult { | |
| @@ -685,6 +685,19 @@ void FAST_FUNC generate_uuid(uint8_t *buf) | |
| buf[4 + 2 + 2] = (buf[4 + 2 + 2] & 0x3f) | 0x80; | |
| } | |
| + | void FAST_FUNC format_uuid_DCE_37_chars(char *dst37, const uint8_t *buf) |
| + | { |
| + | /* 37 = 16*2 hexdigits + 4 dashes + 1 NUL */ |
| + | sprintf(dst37, |
| + | "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
| + | buf[0], buf[1], buf[2], buf[3], |
| + | buf[4], buf[5], |
| + | buf[6], buf[7], |
| + | buf[8], buf[9], |
| + | buf[10], buf[11], buf[12], buf[13], buf[14], buf[15] |
| + | ); |
| + | } |
| + | |
| #if BB_MMU | |
| pid_t FAST_FUNC xfork(void) | |
| { | |
| @@ -59,9 +59,9 @@ gpt_print_guid(uint8_t *buf) | |
| { | |
| printf( | |
| "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", | |
| - | buf[3], buf[2], buf[1], buf[0], |
| - | buf[5], buf[4], |
| - | buf[7], buf[6], |
| + | buf[3], buf[2], buf[1], buf[0], /* GPT byteswaps... */ |
| + | buf[5], buf[4], /* ...these */ |
| + | buf[7], buf[6], /* ...fields */ |
| buf[8], buf[9], | |
| buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]); | |
| } | |
| @@ -91,7 +91,7 @@ struct swap_header_v1 { | |
| uint32_t version; /* second kbyte, word 0 */ | |
| uint32_t last_page; /* 1 */ | |
| uint32_t nr_badpages; /* 2 */ | |
| - | char sws_uuid[16]; /* 3,4,5,6 */ |
| + | uint8_t sws_uuid[16]; /* 3,4,5,6 */ |
| char sws_volume[16]; /* 7,8,9,10 */ | |
| uint32_t padding[117]; /* 11..127 */ | |
| uint32_t badpages[1]; /* 128 */ | |
| @@ -148,17 +148,11 @@ int mkswap_main(int argc UNUSED_PARAM, char **argv) | |
| hdr->last_page = (uoff_t)len / pagesize; | |
| if (ENABLE_FEATURE_MKSWAP_UUID) { | |
| - | char uuid_string[32]; |
| - | generate_uuid((void*)hdr->sws_uuid); |
| - | bin2hex(uuid_string, hdr->sws_uuid, 16); |
| + | char uuid_string37[37]; |
| /* f.e. UUID=dfd9c173-be52-4d27-99a5-c34c6c2ff55f */ | |
| - | printf("UUID=%.8s" "-%.4s-%.4s-%.4s-%.12s\n", |
| - | uuid_string, |
| - | uuid_string+8, |
| - | uuid_string+8+4, |
| - | uuid_string+8+4+4, |
| - | uuid_string+8+4+4+4 |
| - | ); |
| + | generate_uuid(hdr->sws_uuid); |
| + | format_uuid_DCE_37_chars(uuid_string37, hdr->sws_uuid); |
| + | printf("UUID=%s\n", uuid_string37); |
| } | |
| safe_strncpy(hdr->sws_volume, label, 16); | |
| @@ -36,22 +36,21 @@ | |
| * Otherwise, it will choose a time-based UUID." | |
| */ | |
| #include "libbb.h" | |
| - | #include "volume_id/volume_id_internal.h" |
| /* This is a NOFORK applet. Be very careful! */ | |
| int uuidgen_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |
| int uuidgen_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |
| { | |
| - | struct volume_id id; |
| + | char str37[37]; |
| uint8_t uuid[16]; | |
| /* support/ignore -r (--random) */ | |
| getopt32(argv, "^" "r" "\0" "=0"/* no args!*/); | |
| generate_uuid(uuid); | |
| - | volume_id_set_uuid(&id, uuid, UUID_DCE); |
| - | puts(id.uuid); |
| + | format_uuid_DCE_37_chars(str37, uuid); |
| + | puts(str37); |
| - | return 0; |
| + | fflush_stdout_and_exit_SUCCESS(); |
| } | |
| @@ -158,13 +158,7 @@ set: | |
| buf[3], buf[2], buf[1], buf[0]); | |
| break; | |
| case UUID_DCE: | |
| - | sprintf(id->uuid, |
| - | "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
| - | buf[0], buf[1], buf[2], buf[3], |
| - | buf[4], buf[5], |
| - | buf[6], buf[7], |
| - | buf[8], buf[9], |
| - | buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]); |
| + | format_uuid_DCE_37_chars(id->uuid, buf); |
| break; | |
| case UUID_DCE_STRING: | |
| memcpy(id->uuid, buf, count); | |