summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util-linux/mkswap.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c
index c4e30fd..5d1f6f0 100644
--- a/util-linux/mkswap.c
+++ b/util-linux/mkswap.c
@@ -53,10 +53,6 @@ static void mkswap_selinux_setcontext(int fd, const char *path)
#if ENABLE_DESKTOP
static void mkswap_generate_uuid(uint8_t *buf)
{
- pid_t pid;
- unsigned i;
- char uuid_string[32];
-
/* http://www.ietf.org/rfc/rfc4122.txt
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -64,7 +60,7 @@ static void mkswap_generate_uuid(uint8_t *buf)
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | time_mid | time_hi_and_version |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * |clk_seq__and_variant | node (0-1) |
+ * |clk_seq_and_variant | node (0-1) |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | node (2-5) |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -73,11 +69,11 @@ static void mkswap_generate_uuid(uint8_t *buf)
* uint16_t time_mid (big endian)
* uint16_t time_hi_and_version (big endian)
* version is a 4-bit field:
- * 1 Time-based version
- * 2 DCE Security version, with embedded POSIX UIDs
- * 3 Name-based version (MD5)
- * 4 Randomly generated version
- * 5 Name-based version (SHA-1)
+ * 1 Time-based
+ * 2 DCE Security, with embedded POSIX UIDs
+ * 3 Name-based (MD5)
+ * 4 Randomly generated
+ * 5 Name-based (SHA-1)
* uint16_t clk_seq_and_variant (big endian)
* variant is a 3-bit field:
* 0xx Reserved, NCS backward compatibility
@@ -90,6 +86,9 @@ static void mkswap_generate_uuid(uint8_t *buf)
* time_hi_and_version & 0x0fff | 0x4000
* clk_seq_and_variant & 0x3fff | 0x8000
*/
+ pid_t pid;
+ int i;
+ char uuid_string[32];
i = open("/dev/urandom", O_RDONLY);
if (i >= 0) {
@@ -110,8 +109,10 @@ static void mkswap_generate_uuid(uint8_t *buf)
pid = 0;
}
- buf[4 + 2 ] = (buf[4 + 2 ] & 0x0f) | 0x40; /* time_hi_and_version */
- buf[4 + 2 + 2] = (buf[4 + 2 + 2] & 0x3f) | 0x80; /* clk_seq_and_variant */
+ /* version = 4 */
+ buf[4 + 2 ] = (buf[4 + 2 ] & 0x0f) | 0x40;
+ /* variant = 10x */
+ buf[4 + 2 + 2] = (buf[4 + 2 + 2] & 0x3f) | 0x80;
bin2hex(uuid_string, (void*) buf, 16);
/* f.e. UUID=dfd9c173-be52-4d27-99a5-c34c6c2ff55f */