Lines Matching full:data
32 static __inline odb_descr_t * odb_to_descr(odb_data_t * data)
34 return (odb_descr_t *)(((char*)data->base_memory) + data->sizeof_header);
38 static __inline odb_node_t * odb_to_node_base(odb_data_t * data)
40 return (odb_node_t *)(((char *)data->base_memory) + data->offset_node);
44 static __inline odb_index_t * odb_to_hash_base(odb_data_t * data)
46 return (odb_index_t *)(((char *)data->base_memory) +
47 data->offset_node +
48 (data->descr->size * sizeof(odb_node_t)));
55 static unsigned int tables_size(odb_data_t const * data, odb_node_nr_t node_nr)
61 size += data->offset_node;
67 int odb_grow_hashtable(odb_data_t * data)
74 old_file_size = tables_size(data, data->descr->size);
75 new_file_size = tables_size(data, data->descr->size * 2);
77 if (ftruncate(data->fd, new_file_size))
80 new_map = mremap(data->base_memory,
86 data->base_memory = new_map;
87 data->descr = odb_to_descr(data);
88 data->descr->size *= 2;
89 data->node_base = odb_to_node_base(data);
90 data->hash_base = odb_to_hash_base(data);
91 data->hash_mask = (data->descr->size * BUCKET_FACTOR) - 1;
109 for (pos = 0 ; pos < data->descr->size*BUCKET_FACTOR ; ++pos)
110 data->hash_base[pos] = 0;
113 for (pos = 1; pos < data->descr->current_size; ++pos) {
114 odb_node_t * node = &data->node_base[pos];
115 size_t index = odb_do_hash(data, node->key);
116 node->next = data->hash_base[index];
117 data->hash_base[index] = pos;
126 odb->data = NULL;
171 odb_data_t * data;
179 data = find_samples_data(hash, filename);
180 if (data) {
181 odb->data = data;
182 data->ref_count++;
186 data = xmalloc(sizeof(odb_data_t));
187 memset(data, '\0', sizeof(odb_data_t));
188 list_init(&data->list);
189 data->offset_node = sizeof_header + sizeof(odb_descr_t);
190 data->sizeof_header = sizeof_header;
191 data->ref_count = 1;
192 data->filename = xstrdup(filename);
194 data->fd = open(filename, flags, 0644);
195 if (data->fd < 0) {
200 if (fstat(data->fd, &stat_buf)) {
213 nr_node = DEFAULT_NODE_NR(data->offset_node);
215 file_size = tables_size(data, nr_node);
216 if (ftruncate(data->fd, file_size)) {
222 nr_node = (stat_buf.st_size - data->offset_node) /
226 data->base_memory = mmap(0, tables_size(data, nr_node), mmflags,
227 MAP_SHARED, data->fd, 0);
229 if (data->base_memory == MAP_FAILED) {
234 data->descr = odb_to_descr(data);
237 data->descr->size = nr_node;
239 data->descr->current_size = 1;
242 if (nr_node != data->descr->size) {
248 data->hash_base = odb_to_hash_base(data);
249 data->node_base = odb_to_node_base(data);
250 data->hash_mask = (data->descr->size * BUCKET_FACTOR) - 1;
252 list_add(&data->list, &files_hash[hash]);
253 odb->data = data;
257 munmap(data->base_memory, tables_size(data, nr_node));
259 close(data->fd);
260 free(data->filename);
261 free(data);
262 odb->data = NULL;
269 odb_data_t * data = odb->data;
271 if (data) {
272 data->ref_count--;
273 if (data->ref_count == 0) {
274 size_t size = tables_size(data, data->descr->size);
275 list_del(&data->list);
276 munmap(data->base_memory, size);
277 if (data->fd >= 0)
278 close(data->fd);
279 free(data->filename);
280 free(data);
281 odb->data = NULL;
289 if (!odb->data)
291 return odb->data->ref_count;
297 return odb->data->base_memory;
303 odb_data_t * data = odb->data;
306 if (!data)
309 size = tables_size(data, data->descr->size);
310 msync(data->base_memory, size, MS_ASYNC);