fix cache->size calculation to not include the header
authorTero Marttila <terom@fixme.fi>
Sun, 24 Jan 2010 23:04:55 +0200
changeset 53 8a3165c604f8
parent 52 148a120ea7d5
child 54 4a25113cb2a4
fix cache->size calculation to not include the header
include/pngtile.h
src/lib/cache.c
--- 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;
 };
 
 /**
--- 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)))