… | |
… | |
39 | static const uint64 UUID_SKIP = 1<<19; |
39 | static const uint64 UUID_SKIP = 1<<19; |
40 | |
40 | |
41 | objectvec objects; |
41 | objectvec objects; |
42 | activevec actives; |
42 | activevec actives; |
43 | |
43 | |
44 | short freearr_x[SIZEOFFREE] = { 0, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, |
44 | short freearr_x[SIZEOFFREE] = { |
|
|
45 | 0, |
|
|
46 | 0, 1, 1, 1, 0, -1, -1, -1, |
|
|
47 | 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, |
45 | 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1 |
48 | 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1 |
46 | }; |
49 | }; |
47 | short freearr_y[SIZEOFFREE] = { 0, -1, -1, 0, 1, 1, 1, 0, -1, -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, |
50 | short freearr_y[SIZEOFFREE] = { |
|
|
51 | 0, |
|
|
52 | -1, -1, 0, 1, 1, 1, 0, -1, |
|
|
53 | -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, |
48 | -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3 |
54 | -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3 |
49 | }; |
55 | }; |
50 | int maxfree[SIZEOFFREE] = { 0, 9, 10, 13, 14, 17, 18, 21, 22, 25, 26, 27, 30, 31, 32, 33, 36, 37, 39, 39, 42, 43, 44, 45, |
56 | int maxfree[SIZEOFFREE] = { |
|
|
57 | 0, |
|
|
58 | 9, 10, 13, 14, 17, 18, 21, 22, |
|
|
59 | 25, 26, 27, 30, 31, 32, 33, 36, 37, 39, 39, 42, 43, 44, 45, 48, |
51 | 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49 |
60 | 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49 |
52 | }; |
61 | }; |
53 | int freedir[SIZEOFFREE] = { |
62 | int freedir[SIZEOFFREE] = { |
54 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7, 8, 8, 8, |
63 | 0, |
|
|
64 | 1, 2, 3, 4, 5, 6, 7, 8, |
|
|
65 | 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7, 8, 8, 8, |
55 | 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8 |
66 | 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8 |
56 | }; |
67 | }; |
57 | |
68 | |
58 | static void |
69 | static void |
59 | write_uuid (void) |
70 | write_uuid (uval64 skip, bool sync) |
60 | { |
71 | { |
61 | char filename1[MAX_BUF], filename2[MAX_BUF]; |
72 | CALL_BEGIN (2); |
62 | |
73 | CALL_ARG_SV (newSVval64 (skip)); |
63 | sprintf (filename1, "%s/uuid", settings.localdir); |
74 | CALL_ARG_SV (boolSV (sync)); |
64 | sprintf (filename2, "%s/uuid~", settings.localdir); |
75 | CALL_CALL ("cf::write_uuid", G_DISCARD); |
65 | |
76 | CALL_END; |
66 | FILE *fp; |
|
|
67 | |
|
|
68 | if (!(fp = fopen (filename2, "w"))) |
|
|
69 | { |
|
|
70 | LOG (llevError, "ERROR: cannot open %s for writing, unable to write UUID!\n", filename2); |
|
|
71 | return; |
|
|
72 | } |
|
|
73 | |
|
|
74 | fprintf (fp, "<1,%llx>\n", (unsigned long long)UUID::cur.seq + UUID_SKIP * 2); |
|
|
75 | fclose (fp); |
|
|
76 | rename (filename2, filename1); |
|
|
77 | } |
77 | } |
78 | |
78 | |
79 | static void |
79 | static void |
80 | read_uuid (void) |
80 | read_uuid (void) |
81 | { |
81 | { |
… | |
… | |
89 | { |
89 | { |
90 | if (errno == ENOENT) |
90 | if (errno == ENOENT) |
91 | { |
91 | { |
92 | LOG (llevInfo, "RESET uid to 1\n"); |
92 | LOG (llevInfo, "RESET uid to 1\n"); |
93 | UUID::cur.seq = 0; |
93 | UUID::cur.seq = 0; |
94 | write_uuid (); |
94 | write_uuid (UUID_SKIP, true); |
95 | return; |
95 | return; |
96 | } |
96 | } |
97 | |
97 | |
98 | LOG (llevError, "FATAL: cannot open %s for reading!\n", filename); |
98 | LOG (llevError, "FATAL: cannot open %s for reading!\n", filename); |
99 | _exit (1); |
99 | _exit (1); |
100 | } |
100 | } |
101 | |
101 | |
102 | int version; |
102 | UUID::BUF buf; |
103 | unsigned long long uid; |
103 | buf[0] = 0; |
104 | if (2 != fscanf (fp, "<%d,%llx>\n", &version, &uid) || version != 1) |
104 | fgets (buf, sizeof (buf), fp); |
|
|
105 | |
|
|
106 | if (!UUID::cur.parse (buf)) |
105 | { |
107 | { |
106 | LOG (llevError, "FATAL: error reading uid from %s!\n", filename); |
108 | LOG (llevError, "FATAL: error reading uid from %s (%s)!\n", filename, buf); |
107 | _exit (1); |
109 | _exit (1); |
108 | } |
110 | } |
109 | |
111 | |
110 | UUID::cur.seq = uid; |
112 | LOG (llevDebug, "read UUID: %s\n", UUID::cur.c_str ()); |
111 | write_uuid (); |
113 | |
112 | LOG (llevDebug, "read UID: %" PRId64 "\n", uid); |
114 | write_uuid (UUID_SKIP, true); |
113 | fclose (fp); |
115 | fclose (fp); |
114 | } |
116 | } |
115 | |
117 | |
116 | UUID |
118 | UUID |
117 | UUID::gen () |
119 | UUID::gen () |
118 | { |
120 | { |
119 | UUID uid; |
121 | UUID uid; |
120 | |
122 | |
121 | uid.seq = ++cur.seq; |
123 | uid.seq = ++cur.seq; |
122 | |
124 | |
123 | if (!(cur.seq & (UUID_SKIP - 1))) |
125 | if (expect_false (!(cur.seq & (UUID_SKIP - 1)))) |
124 | write_uuid (); |
126 | write_uuid (UUID_SKIP, false); |
125 | |
127 | |
126 | return uid; |
128 | return uid; |
127 | } |
129 | } |
128 | |
130 | |
129 | void |
131 | void |
… | |
… | |
2607 | { |
2609 | { |
2608 | char flagdesc[512]; |
2610 | char flagdesc[512]; |
2609 | char info2[256 * 4]; |
2611 | char info2[256 * 4]; |
2610 | char *p = info; |
2612 | char *p = info; |
2611 | |
2613 | |
2612 | p += snprintf (p, 512, "{cnt:%d,uuid:<1.%" PRIx64 ">,name:\"%s\"%s%s,flags:[%s],type:%d}", |
2614 | p += snprintf (p, 512, "{cnt:%d,uuid:%s,name:\"%s\"%s%s,flags:[%s],type:%d}", |
2613 | count, uuid.seq, |
2615 | count, |
|
|
2616 | uuid.c_str (), |
2614 | &name, |
2617 | &name, |
2615 | title ? "\",title:\"" : "", |
2618 | title ? "\",title:\"" : "", |
2616 | title ? (const char *)title : "", |
2619 | title ? (const char *)title : "", |
2617 | flag_desc (flagdesc, 512), type); |
2620 | flag_desc (flagdesc, 512), type); |
2618 | |
2621 | |