# HG changeset patch # User Tero Marttila # Date 1264367095 -7200 # Node ID 8a3165c604f8738e25b76df1c5d33e562d4efccb # Parent 148a120ea7d59d2a1a62bdd94208177f381a0ec0 fix cache->size calculation to not include the header diff -r 148a120ea7d5 -r 8a3165c604f8 include/pngtile.h --- a/include/pngtile.h Sun Jan 24 23:03:12 2010 +0200 +++ b/include/pngtile.h Sun Jan 24 23:04:55 2010 +0200 @@ -50,6 +50,15 @@ struct pt_image_info { /** Dimensions of image */ size_t width, height; + + /** Size of image file in bytes */ + size_t image_bytes; + + /** Size of cache file in bytes */ + size_t cache_bytes; + + /** Size of cache file in blocks (for sparse cache files) */ + size_t cache_blocks; }; /** diff -r 148a120ea7d5 -r 8a3165c604f8 src/lib/cache.c --- a/src/lib/cache.c Sun Jan 24 23:03:12 2010 +0200 +++ b/src/lib/cache.c Sun Jan 24 23:04:55 2010 +0200 @@ -160,7 +160,7 @@ prot |= PROT_WRITE; } - // perform mmap() from second page on + // mmap() the full file including header if ((addr = mmap(NULL, PT_CACHE_HEADER_SIZE + cache->size, prot, MAP_SHARED, cache->fd, 0)) == MAP_FAILED) RETURN_ERROR(PT_ERR_CACHE_MMAP); @@ -245,7 +245,7 @@ return err; // calculate data size - cache->size = sizeof(*header) + header->height * header->row_bytes; + cache->size = header->height * header->row_bytes; // grow file if (ftruncate(cache->fd, PT_CACHE_HEADER_SIZE + cache->size) < 0) @@ -311,7 +311,7 @@ JUMP_ERROR(err); // calculate data size - cache->size = sizeof(header) + header.height * header.row_bytes; + cache->size = header.height * header.row_bytes; // mmap header and data if ((err = pt_cache_open_mmap(cache, &base, true)))