/* uuid_create -- generator a UUID */ int uuid_create(uuid_t * uuid) { uuid_time_t timestamp, last_time; unsigned16 clockseq; uuid_node_t node; uuid_node_t last_node; int f; /* acquire system wide lock so we're alone */ LOCK; /* get current time */ get_current_time(×tamp); /* get node ID */ get_ieee_node_identifier(&node); /* get saved state from NV storage */ f = read_state(&clockseq, &last_time, &last_node); /* if no NV state, or if clock went backwards, or node ID changed (e.g., net card swap) change clockseq */ if (!f || memcmp(&node, &last_node, sizeof(uuid_node_t))) clockseq = true_random(); else if (timestamp < last_time) clockseq++; /* stuff fields into the UUID */ format_uuid_v1(uuid, clockseq, timestamp, node); /* save the state for next time */ write_state(clockseq, timestamp, node); UNLOCK; return(1); };
/* dav_create_opaquelocktoken - generates a UUID version 1 token. * Clock_sequence and node_address set to pseudo-random * numbers during init. * * Should postpend pid to account for non-seralized creation? */ static int create_token(uuid_state *st, xuuid_t *u) { uuid_time_t timestamp; get_current_time(×tamp); format_uuid_v1(u, st->cs, timestamp, st->node); return 1; }