LIBPRIV: Add private includes for dfuife_curses.
[dragonfly.git] / sbin / hammer / test_dupkey.c
blob97b710a007c3034bb62e26dd7ebc43de703b2eeb
1 /*
2 * This is a really simple stupid standalone program which will find two
3 * filenames with the same CRC, used to test the directory iterator.
5 * cc -I /usr/src/sys test_dupkey.c /usr/src/sys/libkern/crc32.c \
6 * /usr/src/sys/libkern/icrc32.c -o test_dupkey
8 * $DragonFly: src/sbin/hammer/test_dupkey.c,v 1.1 2008/06/26 04:07:57 dillon Exp $
9 */
11 #include "hammer_util.h"
13 static uint32_t namekey(const char *name);
14 static void randomname(char *name);
16 uint32_t bitmap[0x80000000U / 32];
18 int
19 main(int ac, char **av)
21 char name[32];
22 uint32_t key;
23 uint32_t *ptr;
24 uint32_t mask;
25 uint32_t count;
26 uint32_t saved;
28 srandom(0); /* reproducable random sequence number */
29 count = 0;
30 for (;;) {
31 randomname(name);
32 key = namekey(name);
33 ptr = &bitmap[key / 32];
34 mask = 1 << (key & 31);
35 if (*ptr & mask) {
36 break;
38 *ptr |= mask;
39 ++count;
41 printf("duplicate found at count %d key %08x\n", count, key);
42 printf("'%s' and", name);
43 saved = key;
45 srandom(0);
46 count = 0;
47 for (;;) {
48 randomname(name);
49 key = namekey(name);
50 if (saved == key)
51 break;
52 ++count;
54 printf(" '%s'\n", name);
57 static
58 uint32_t
59 namekey(const char *name)
61 uint32_t key;
63 key = crc32(name, strlen(name)) & 0x7FFFFFFF;
64 if (key == 0)
65 key = 1;
66 return(key);
69 static
70 void
71 randomname(char *name)
73 int len = random() % 16 + 8;
74 int i;
76 for (i = 0; i < len; ++i)
77 name[i] = random() % 26 + 'a';
78 name[i] = 0;