| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/di-set.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | - | |||||||||||||
| 9 | typedef size_t hashint; | - | ||||||||||||
| 10 | struct di_ent | - | ||||||||||||
| 11 | { | - | ||||||||||||
| 12 | dev_t dev; | - | ||||||||||||
| 13 | struct hash_table *ino_set; | - | ||||||||||||
| 14 | }; | - | ||||||||||||
| 15 | - | |||||||||||||
| 16 | - | |||||||||||||
| 17 | struct di_set | - | ||||||||||||
| 18 | { | - | ||||||||||||
| 19 | - | |||||||||||||
| 20 | struct hash_table *dev_map; | - | ||||||||||||
| 21 | - | |||||||||||||
| 22 | - | |||||||||||||
| 23 | - | |||||||||||||
| 24 | - | |||||||||||||
| 25 | struct ino_map *ino_map; | - | ||||||||||||
| 26 | - | |||||||||||||
| 27 | - | |||||||||||||
| 28 | - | |||||||||||||
| 29 | struct di_ent *probe; | - | ||||||||||||
| 30 | }; | - | ||||||||||||
| 31 | - | |||||||||||||
| 32 | - | |||||||||||||
| 33 | static size_t | - | ||||||||||||
| 34 | di_ent_hash (void const *x, size_t table_size) | - | ||||||||||||
| 35 | { | - | ||||||||||||
| 36 | struct di_ent const *p = x; | - | ||||||||||||
| 37 | dev_t dev = p->dev; | - | ||||||||||||
| 38 | - | |||||||||||||
| 39 | - | |||||||||||||
| 40 | - | |||||||||||||
| 41 | - | |||||||||||||
| 42 | size_t h = dev; | - | ||||||||||||
| 43 | unsigned int i; | - | ||||||||||||
| 44 | unsigned int n_words = sizeof dev / sizeof h + (sizeof dev % sizeof h != 0); | - | ||||||||||||
| 45 | for (i = 1; i < n_words
| 0-50 | ||||||||||||
| 46 | h ^= dev >> 8 * sizeof h * i; never executed: h ^= dev >> 8 * sizeof h * i; | 0 | ||||||||||||
| 47 | - | |||||||||||||
| 48 | return executed 50 times by 1 test: h % table_size;return h % table_size;Executed by:
executed 50 times by 1 test: return h % table_size;Executed by:
| 50 | ||||||||||||
| 49 | } | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | - | |||||||||||||
| 52 | static | - | ||||||||||||
| 53 | _Bool | - | ||||||||||||
| 54 | - | |||||||||||||
| 55 | di_ent_compare (void const *x, void const *y) | - | ||||||||||||
| 56 | { | - | ||||||||||||
| 57 | struct di_ent const *a = x; | - | ||||||||||||
| 58 | struct di_ent const *b = y; | - | ||||||||||||
| 59 | return executed 23 times by 1 test: a->dev == b->dev;return a->dev == b->dev;Executed by:
executed 23 times by 1 test: return a->dev == b->dev;Executed by:
| 23 | ||||||||||||
| 60 | } | - | ||||||||||||
| 61 | - | |||||||||||||
| 62 | - | |||||||||||||
| 63 | static void | - | ||||||||||||
| 64 | di_ent_free (void *v) | - | ||||||||||||
| 65 | { | - | ||||||||||||
| 66 | struct di_ent *a = v; | - | ||||||||||||
| 67 | hash_free (a->ino_set); | - | ||||||||||||
| 68 | free (a); | - | ||||||||||||
| 69 | } executed 27 times by 1 test: end of blockExecuted by:
| 27 | ||||||||||||
| 70 | - | |||||||||||||
| 71 | - | |||||||||||||
| 72 | struct di_set * | - | ||||||||||||
| 73 | di_set_alloc (void) | - | ||||||||||||
| 74 | { | - | ||||||||||||
| 75 | struct di_set *dis = malloc (sizeof *dis); | - | ||||||||||||
| 76 | if (dis
| 0-281 | ||||||||||||
| 77 | { | - | ||||||||||||
| 78 | enum { INITIAL_DEV_MAP_SIZE = 11 }; | - | ||||||||||||
| 79 | dis->dev_map = hash_initialize (INITIAL_DEV_MAP_SIZE, | - | ||||||||||||
| 80 | ((void *)0) | - | ||||||||||||
| 81 | , | - | ||||||||||||
| 82 | di_ent_hash, di_ent_compare, | - | ||||||||||||
| 83 | di_ent_free); | - | ||||||||||||
| 84 | if (! dis->dev_map
| 0-281 | ||||||||||||
| 85 | { | - | ||||||||||||
| 86 | free (dis); | - | ||||||||||||
| 87 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||
| 88 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
| 89 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 90 | } | - | ||||||||||||
| 91 | dis->ino_map = | - | ||||||||||||
| 92 | ((void *)0) | - | ||||||||||||
| 93 | ; | - | ||||||||||||
| 94 | dis->probe = | - | ||||||||||||
| 95 | ((void *)0) | - | ||||||||||||
| 96 | ; | - | ||||||||||||
| 97 | } executed 281 times by 1 test: end of blockExecuted by:
| 281 | ||||||||||||
| 98 | - | |||||||||||||
| 99 | return executed 281 times by 1 test: dis;return dis;Executed by:
executed 281 times by 1 test: return dis;Executed by:
| 281 | ||||||||||||
| 100 | } | - | ||||||||||||
| 101 | - | |||||||||||||
| 102 | - | |||||||||||||
| 103 | void | - | ||||||||||||
| 104 | di_set_free (struct di_set *dis) | - | ||||||||||||
| 105 | { | - | ||||||||||||
| 106 | hash_free (dis->dev_map); | - | ||||||||||||
| 107 | free (dis->ino_map); | - | ||||||||||||
| 108 | free (dis->probe); | - | ||||||||||||
| 109 | free (dis); | - | ||||||||||||
| 110 | } executed 281 times by 1 test: end of blockExecuted by:
| 281 | ||||||||||||
| 111 | - | |||||||||||||
| 112 | - | |||||||||||||
| 113 | static size_t | - | ||||||||||||
| 114 | di_ino_hash (void const *i, size_t table_size) | - | ||||||||||||
| 115 | { | - | ||||||||||||
| 116 | return executed 3630 times by 1 test: (hashint) i % table_size;return (hashint) i % table_size;Executed by:
executed 3630 times by 1 test: return (hashint) i % table_size;Executed by:
| 3630 | ||||||||||||
| 117 | } | - | ||||||||||||
| 118 | - | |||||||||||||
| 119 | - | |||||||||||||
| 120 | - | |||||||||||||
| 121 | static struct hash_table * | - | ||||||||||||
| 122 | map_device (struct di_set *dis, dev_t dev) | - | ||||||||||||
| 123 | { | - | ||||||||||||
| 124 | - | |||||||||||||
| 125 | struct di_ent *ent; | - | ||||||||||||
| 126 | struct di_ent *probe = dis->probe; | - | ||||||||||||
| 127 | if (probe
| 50-2557 | ||||||||||||
| 128 | { | - | ||||||||||||
| 129 | - | |||||||||||||
| 130 | if (probe->dev == dev
| 0-2557 | ||||||||||||
| 131 | return executed 2557 times by 1 test: probe->ino_set;return probe->ino_set;Executed by:
executed 2557 times by 1 test: return probe->ino_set;Executed by:
| 2557 | ||||||||||||
| 132 | } never executed: end of block | 0 | ||||||||||||
| 133 | else | - | ||||||||||||
| 134 | { | - | ||||||||||||
| 135 | dis->probe = probe = malloc (sizeof *probe); | - | ||||||||||||
| 136 | if (! probe
| 0-50 | ||||||||||||
| 137 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||
| 138 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
| 139 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 140 | } executed 50 times by 1 test: end of blockExecuted by:
| 50 | ||||||||||||
| 141 | - | |||||||||||||
| 142 | - | |||||||||||||
| 143 | probe->dev = dev; | - | ||||||||||||
| 144 | ent = hash_insert (dis->dev_map, probe); | - | ||||||||||||
| 145 | if (! ent
| 0-50 | ||||||||||||
| 146 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||
| 147 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
| 148 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 149 | - | |||||||||||||
| 150 | if (ent != probe
| 23-27 | ||||||||||||
| 151 | { | - | ||||||||||||
| 152 | - | |||||||||||||
| 153 | probe->ino_set = ent->ino_set; | - | ||||||||||||
| 154 | } executed 23 times by 1 test: end of blockExecuted by:
| 23 | ||||||||||||
| 155 | else | - | ||||||||||||
| 156 | { | - | ||||||||||||
| 157 | enum { INITIAL_INO_SET_SIZE = 1021 }; | - | ||||||||||||
| 158 | - | |||||||||||||
| 159 | - | |||||||||||||
| 160 | dis->probe = | - | ||||||||||||
| 161 | ((void *)0) | - | ||||||||||||
| 162 | ; | - | ||||||||||||
| 163 | - | |||||||||||||
| 164 | - | |||||||||||||
| 165 | probe->ino_set = hash_initialize (INITIAL_INO_SET_SIZE, | - | ||||||||||||
| 166 | ((void *)0) | - | ||||||||||||
| 167 | , | - | ||||||||||||
| 168 | di_ino_hash, | - | ||||||||||||
| 169 | ((void *)0) | - | ||||||||||||
| 170 | , | - | ||||||||||||
| 171 | ((void *)0) | - | ||||||||||||
| 172 | ); | - | ||||||||||||
| 173 | } executed 27 times by 1 test: end of blockExecuted by:
| 27 | ||||||||||||
| 174 | - | |||||||||||||
| 175 | return executed 50 times by 1 test: probe->ino_set;return probe->ino_set;Executed by:
executed 50 times by 1 test: return probe->ino_set;Executed by:
| 50 | ||||||||||||
| 176 | } | - | ||||||||||||
| 177 | - | |||||||||||||
| 178 | - | |||||||||||||
| 179 | - | |||||||||||||
| 180 | static hashint | - | ||||||||||||
| 181 | map_inode_number (struct di_set *dis, ino_t ino) | - | ||||||||||||
| 182 | { | - | ||||||||||||
| 183 | if (0 < ino
| 0-2607 | ||||||||||||
| 184 | return executed 2607 times by 1 test: ino;return ino;Executed by:
executed 2607 times by 1 test: return ino;Executed by:
| 2607 | ||||||||||||
| 185 | - | |||||||||||||
| 186 | if (! dis->ino_map
| 0 | ||||||||||||
| 187 | { | - | ||||||||||||
| 188 | dis->ino_map = ino_map_alloc ((((hashint) -1) / 2)); | - | ||||||||||||
| 189 | if (! dis->ino_map
| 0 | ||||||||||||
| 190 | return never executed: ((size_t) -1);return ((size_t) -1);never executed: return ((size_t) -1); | 0 | ||||||||||||
| 191 | } never executed: end of block | 0 | ||||||||||||
| 192 | - | |||||||||||||
| 193 | return never executed: ino_map_insert (dis->ino_map, ino);return ino_map_insert (dis->ino_map, ino);never executed: return ino_map_insert (dis->ino_map, ino); | 0 | ||||||||||||
| 194 | } | - | ||||||||||||
| 195 | - | |||||||||||||
| 196 | - | |||||||||||||
| 197 | - | |||||||||||||
| 198 | - | |||||||||||||
| 199 | - | |||||||||||||
| 200 | int | - | ||||||||||||
| 201 | di_set_insert (struct di_set *dis, dev_t dev, ino_t ino) | - | ||||||||||||
| 202 | { | - | ||||||||||||
| 203 | hashint i; | - | ||||||||||||
| 204 | - | |||||||||||||
| 205 | - | |||||||||||||
| 206 | struct hash_table *ino_set = map_device (dis, dev); | - | ||||||||||||
| 207 | if (! ino_set
| 0-2607 | ||||||||||||
| 208 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 209 | - | |||||||||||||
| 210 | - | |||||||||||||
| 211 | i = map_inode_number (dis, ino); | - | ||||||||||||
| 212 | if (i == ((size_t) -1)
| 0-2607 | ||||||||||||
| 213 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 214 | - | |||||||||||||
| 215 | - | |||||||||||||
| 216 | return executed 2607 times by 1 test: hash_insert_if_absent (ino_set, (void const *) i, return hash_insert_if_absent (ino_set, (void const *) i, ((void *)0) );Executed by:
executed 2607 times by 1 test: return hash_insert_if_absent (ino_set, (void const *) i, ((void *)0) );Executed by:
| 2607 | ||||||||||||
| 217 | ((void *)0) executed 2607 times by 1 test: return hash_insert_if_absent (ino_set, (void const *) i, ((void *)0) );Executed by:
| 2607 | ||||||||||||
| 218 | ); executed 2607 times by 1 test: return hash_insert_if_absent (ino_set, (void const *) i, ((void *)0) );Executed by:
| 2607 | ||||||||||||
| 219 | } | - | ||||||||||||
| 220 | - | |||||||||||||
| 221 | - | |||||||||||||
| 222 | - | |||||||||||||
| 223 | - | |||||||||||||
| 224 | int | - | ||||||||||||
| 225 | di_set_lookup (struct di_set *dis, dev_t dev, ino_t ino) | - | ||||||||||||
| 226 | { | - | ||||||||||||
| 227 | hashint i; | - | ||||||||||||
| 228 | - | |||||||||||||
| 229 | - | |||||||||||||
| 230 | struct hash_table *ino_set = map_device (dis, dev); | - | ||||||||||||
| 231 | if (! ino_set
| 0 | ||||||||||||
| 232 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 233 | - | |||||||||||||
| 234 | - | |||||||||||||
| 235 | i = map_inode_number (dis, ino); | - | ||||||||||||
| 236 | if (i == ((size_t) -1)
| 0 | ||||||||||||
| 237 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 238 | - | |||||||||||||
| 239 | - | |||||||||||||
| 240 | return never executed: !!hash_lookup (ino_set, (void const *) i);return !!hash_lookup (ino_set, (void const *) i);never executed: return !!hash_lookup (ino_set, (void const *) i); | 0 | ||||||||||||
| 241 | } | - | ||||||||||||
| Switch to Source code | Preprocessed file |