2006-07-03 01:17:05 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2005-04-24 10:37:59 +05:30
|
|
|
/*
|
|
|
|
* uuid.c -- utility routines for manipulating UUID's.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2005-10-10 17:05:17 +05:30
|
|
|
#include "../ext2fs/ext2_types.h"
|
2005-04-24 10:37:59 +05:30
|
|
|
|
|
|
|
#include "e2p.h"
|
|
|
|
|
|
|
|
struct uuid {
|
|
|
|
__u32 time_low;
|
|
|
|
__u16 time_mid;
|
|
|
|
__u16 time_hi_and_version;
|
|
|
|
__u16 clock_seq;
|
|
|
|
__u8 node[6];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Returns 1 if the uuid is the NULL uuid */
|
|
|
|
int e2p_is_null_uuid(void *uu)
|
|
|
|
{
|
2006-01-25 05:38:53 +05:30
|
|
|
__u8 *cp;
|
2005-04-24 10:37:59 +05:30
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0, cp = uu; i < 16; i++)
|
|
|
|
if (*cp)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void e2p_unpack_uuid(void *in, struct uuid *uu)
|
|
|
|
{
|
|
|
|
__u8 *ptr = in;
|
|
|
|
__u32 tmp;
|
|
|
|
|
|
|
|
tmp = *ptr++;
|
|
|
|
tmp = (tmp << 8) | *ptr++;
|
|
|
|
tmp = (tmp << 8) | *ptr++;
|
|
|
|
tmp = (tmp << 8) | *ptr++;
|
|
|
|
uu->time_low = tmp;
|
|
|
|
|
|
|
|
tmp = *ptr++;
|
|
|
|
tmp = (tmp << 8) | *ptr++;
|
|
|
|
uu->time_mid = tmp;
|
2006-01-25 05:38:53 +05:30
|
|
|
|
2005-04-24 10:37:59 +05:30
|
|
|
tmp = *ptr++;
|
|
|
|
tmp = (tmp << 8) | *ptr++;
|
|
|
|
uu->time_hi_and_version = tmp;
|
|
|
|
|
|
|
|
tmp = *ptr++;
|
|
|
|
tmp = (tmp << 8) | *ptr++;
|
|
|
|
uu->clock_seq = tmp;
|
|
|
|
|
|
|
|
memcpy(uu->node, ptr, 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
void e2p_uuid_to_str(void *uu, char *out)
|
|
|
|
{
|
|
|
|
struct uuid uuid;
|
|
|
|
|
|
|
|
e2p_unpack_uuid(uu, &uuid);
|
|
|
|
sprintf(out,
|
|
|
|
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
|
|
|
uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
|
|
|
|
uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
|
|
|
|
uuid.node[0], uuid.node[1], uuid.node[2],
|
|
|
|
uuid.node[3], uuid.node[4], uuid.node[5]);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *e2p_uuid2str(void *uu)
|
|
|
|
{
|
|
|
|
static char buf[80];
|
|
|
|
if (e2p_is_null_uuid(uu))
|
|
|
|
return "<none>";
|
|
|
|
e2p_uuid_to_str(uu, buf);
|
|
|
|
return buf;
|
|
|
|
}
|