2 * uuid_time.c --- Interpret the time field from a uuid
4 * Copyright (C) 1998 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
15 #include <sys/types.h>
18 #include <linux/ext2_fs.h>
22 time_t uuid_time(uuid_t uu, struct timeval *ret_tv)
27 unsigned long long clock_reg;
29 uuid_unpack(uu, &uuid);
31 high = uuid.time_mid | ((uuid.time_hi_and_version & 0xFFF) << 16);
32 clock_reg = uuid.time_low | ((unsigned long long) high << 32);
34 clock_reg -= (((unsigned long long) 0x01B21DD2) << 32) + 0x13814000;
35 tv.tv_sec = clock_reg / 10000000;
36 tv.tv_usec = (clock_reg % 10000000) / 10;
46 main(int argc, char **argv)
53 fprintf(stderr, "Usage: %s uuid\n", argv[0]);
56 if (uuid_parse(argv[1], buf)) {
57 fprintf(stderr, "Invalid UUID: %s\n", argv[1]);
60 time_reg = uuid_time(buf, &tv);
62 printf("UUID time is: (%d, %d): %s\n", tv.tv_sec, tv.tv_usec,