OpenCoverage

di-set.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/di-set.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9typedef size_t hashint;-
10struct di_ent-
11{-
12 dev_t dev;-
13 struct hash_table *ino_set;-
14};-
15-
16-
17struct 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-
33static size_t-
34di_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
i < n_wordsDescription
TRUEnever evaluated
FALSEevaluated 50 times by 1 test
Evaluated by:
  • du
; i++)
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: return h % table_size;
Executed by:
  • du
h % table_size;
executed 50 times by 1 test: return h % table_size;
Executed by:
  • du
50
49}-
50-
51-
52static -
53 _Bool-
54-
55di_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: return a->dev == b->dev;
Executed by:
  • du
a->dev == b->dev;
executed 23 times by 1 test: return a->dev == b->dev;
Executed by:
  • du
23
60}-
61-
62-
63static void-
64di_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 block
Executed by:
  • du
27
70-
71-
72struct di_set *-
73di_set_alloc (void)-
74{-
75 struct di_set *dis = malloc (sizeof *dis);-
76 if (dis
disDescription
TRUEevaluated 281 times by 1 test
Evaluated by:
  • du
FALSEnever evaluated
)
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
! dis->dev_mapDescription
TRUEnever evaluated
FALSEevaluated 281 times by 1 test
Evaluated by:
  • du
)
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 block
Executed by:
  • du
281
98-
99 return
executed 281 times by 1 test: return dis;
Executed by:
  • du
dis;
executed 281 times by 1 test: return dis;
Executed by:
  • du
281
100}-
101-
102-
103void-
104di_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 block
Executed by:
  • du
281
111-
112-
113static size_t-
114di_ino_hash (void const *i, size_t table_size)-
115{-
116 return
executed 3630 times by 1 test: return (hashint) i % table_size;
Executed by:
  • du
(hashint) i % table_size;
executed 3630 times by 1 test: return (hashint) i % table_size;
Executed by:
  • du
3630
117}-
118-
119-
120-
121static struct hash_table *-
122map_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
probeDescription
TRUEevaluated 2557 times by 1 test
Evaluated by:
  • du
FALSEevaluated 50 times by 1 test
Evaluated by:
  • du
)
50-2557
128 {-
129-
130 if (probe->dev == dev
probe->dev == devDescription
TRUEevaluated 2557 times by 1 test
Evaluated by:
  • du
FALSEnever evaluated
)
0-2557
131 return
executed 2557 times by 1 test: return probe->ino_set;
Executed by:
  • du
probe->ino_set;
executed 2557 times by 1 test: return probe->ino_set;
Executed by:
  • du
2557
132 }
never executed: end of block
0
133 else-
134 {-
135 dis->probe = probe = malloc (sizeof *probe);-
136 if (! probe
! probeDescription
TRUEnever evaluated
FALSEevaluated 50 times by 1 test
Evaluated by:
  • du
)
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 block
Executed by:
  • du
50
141-
142-
143 probe->dev = dev;-
144 ent = hash_insert (dis->dev_map, probe);-
145 if (! ent
! entDescription
TRUEnever evaluated
FALSEevaluated 50 times by 1 test
Evaluated by:
  • du
)
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
ent != probeDescription
TRUEevaluated 23 times by 1 test
Evaluated by:
  • du
FALSEevaluated 27 times by 1 test
Evaluated by:
  • du
)
23-27
151 {-
152-
153 probe->ino_set = ent->ino_set;-
154 }
executed 23 times by 1 test: end of block
Executed by:
  • du
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 block
Executed by:
  • du
27
174-
175 return
executed 50 times by 1 test: return probe->ino_set;
Executed by:
  • du
probe->ino_set;
executed 50 times by 1 test: return probe->ino_set;
Executed by:
  • du
50
176}-
177-
178-
179-
180static hashint-
181map_inode_number (struct di_set *dis, ino_t ino)-
182{-
183 if (0 < ino
0 < inoDescription
TRUEevaluated 2607 times by 1 test
Evaluated by:
  • du
FALSEnever evaluated
&& ino < (((hashint) -1) / 2)
ino < (((hashint) -1) / 2)Description
TRUEevaluated 2607 times by 1 test
Evaluated by:
  • du
FALSEnever evaluated
)
0-2607
184 return
executed 2607 times by 1 test: return ino;
Executed by:
  • du
ino;
executed 2607 times by 1 test: return ino;
Executed by:
  • du
2607
185-
186 if (! dis->ino_map
! dis->ino_mapDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
187 {-
188 dis->ino_map = ino_map_alloc ((((hashint) -1) / 2));-
189 if (! dis->ino_map
! dis->ino_mapDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
190 return
never executed: return ((size_t) -1);
((size_t) -1);
never executed: return ((size_t) -1);
0
191 }
never executed: end of block
0
192-
193 return
never executed: return ino_map_insert (dis->ino_map, ino);
ino_map_insert (dis->ino_map, ino);
never executed: return ino_map_insert (dis->ino_map, ino);
0
194}-
195-
196-
197-
198-
199-
200int-
201di_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
! ino_setDescription
TRUEnever evaluated
FALSEevaluated 2607 times by 1 test
Evaluated by:
  • du
)
0-2607
208 return
never executed: return -1;
-1;
never executed: return -1;
0
209-
210-
211 i = map_inode_number (dis, ino);-
212 if (i == ((size_t) -1)
i == ((size_t) -1)Description
TRUEnever evaluated
FALSEevaluated 2607 times by 1 test
Evaluated by:
  • du
)
0-2607
213 return
never executed: return -1;
-1;
never executed: return -1;
0
214-
215-
216 return
executed 2607 times by 1 test: return hash_insert_if_absent (ino_set, (void const *) i, ((void *)0) );
Executed by:
  • du
hash_insert_if_absent (ino_set, (void const *) i,
executed 2607 times by 1 test: return hash_insert_if_absent (ino_set, (void const *) i, ((void *)0) );
Executed by:
  • du
2607
217 ((void *)0)
executed 2607 times by 1 test: return hash_insert_if_absent (ino_set, (void const *) i, ((void *)0) );
Executed by:
  • du
2607
218 );
executed 2607 times by 1 test: return hash_insert_if_absent (ino_set, (void const *) i, ((void *)0) );
Executed by:
  • du
2607
219}-
220-
221-
222-
223-
224int-
225di_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
! ino_setDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
232 return
never executed: return -1;
-1;
never executed: return -1;
0
233-
234-
235 i = map_inode_number (dis, ino);-
236 if (i == ((size_t) -1)
i == ((size_t) -1)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
237 return
never executed: return -1;
-1;
never executed: return -1;
0
238-
239-
240 return
never executed: return !!hash_lookup (ino_set, (void const *) i);
!!hash_lookup (ino_set, (void const *) i);
never executed: return !!hash_lookup (ino_set, (void const *) i);
0
241}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.1.2