equal
deleted
inserted
replaced
225 |
225 |
226 |
226 |
227 /** |
227 /** |
228 * Mmap the pt_cache_file using sizeof(struct pt_cache_file) + data_size |
228 * Mmap the pt_cache_file using sizeof(struct pt_cache_file) + data_size |
229 */ |
229 */ |
230 static int pt_cache_open_mmap (struct pt_cache *cache, void **addr_ptr, size_t data_size, bool readonly) |
230 static int pt_cache_open_mmap (struct pt_cache *cache, struct pt_cache_file **file_ptr, size_t data_size, bool readonly) |
231 { |
231 { |
232 int prot = 0; |
232 int prot = 0; |
233 void *addr; |
233 void *addr; |
234 |
234 |
235 // determine prot |
235 // determine prot |
244 // mmap() the full file including header |
244 // mmap() the full file including header |
245 if ((addr = mmap(NULL, sizeof(struct pt_cache_file) + data_size, prot, MAP_SHARED, cache->fd, 0)) == MAP_FAILED) |
245 if ((addr = mmap(NULL, sizeof(struct pt_cache_file) + data_size, prot, MAP_SHARED, cache->fd, 0)) == MAP_FAILED) |
246 RETURN_ERROR(PT_ERR_CACHE_MMAP); |
246 RETURN_ERROR(PT_ERR_CACHE_MMAP); |
247 |
247 |
248 // ok |
248 // ok |
249 *addr_ptr = addr; |
249 *file_ptr = addr; |
250 |
250 |
251 return 0; |
251 return 0; |
252 } |
252 } |
253 |
253 |
254 int pt_cache_open (struct pt_cache *cache) |
254 int pt_cache_open (struct pt_cache *cache) |
271 // check version |
271 // check version |
272 if (header.version != PT_CACHE_VERSION) |
272 if (header.version != PT_CACHE_VERSION) |
273 JUMP_SET_ERROR(err, PT_ERR_CACHE_VERSION); |
273 JUMP_SET_ERROR(err, PT_ERR_CACHE_VERSION); |
274 |
274 |
275 // mmap the header + data |
275 // mmap the header + data |
276 if ((err = pt_cache_open_mmap(cache, (void **) &cache->file, header.data_size, true))) |
276 if ((err = pt_cache_open_mmap(cache, &cache->file, header.data_size, true))) |
277 JUMP_ERROR(err); |
277 JUMP_ERROR(err); |
278 |
278 |
279 // done |
279 // done |
280 return 0; |
280 return 0; |
281 |
281 |
337 // grow file |
337 // grow file |
338 if (ftruncate(cache->fd, sizeof(struct pt_cache_file) + header->data_size) < 0) |
338 if (ftruncate(cache->fd, sizeof(struct pt_cache_file) + header->data_size) < 0) |
339 JUMP_SET_ERROR(err, PT_ERR_CACHE_TRUNC); |
339 JUMP_SET_ERROR(err, PT_ERR_CACHE_TRUNC); |
340 |
340 |
341 // mmap header and data |
341 // mmap header and data |
342 if ((err = pt_cache_open_mmap(cache, (void **) &cache->file, header->data_size, false))) |
342 if ((err = pt_cache_open_mmap(cache, &cache->file, header->data_size, false))) |
343 JUMP_ERROR(err); |
343 JUMP_ERROR(err); |
344 |
344 |
345 // done |
345 // done |
346 return 0; |
346 return 0; |
347 |
347 |