summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/H5HFcache.c12
-rw-r--r--src/H5checksum.c35
-rw-r--r--src/H5private.h1
3 files changed, 42 insertions, 6 deletions
diff --git a/src/H5HFcache.c b/src/H5HFcache.c
index ddf8e0c..5da8197 100644
--- a/src/H5HFcache.c
+++ b/src/H5HFcache.c
@@ -396,7 +396,7 @@ HDfprintf(stderr, "%s: Load heap header, addr = %a\n", FUNC, addr);
/* Compute checksum on entire header */
/* (including the filter information, if present) */
- computed_chksum = H5_fletcher32(buf, (hdr->heap_size - H5HF_SIZEOF_CHKSUM));
+ computed_chksum = H5_checksum_metadata(buf, (hdr->heap_size - H5HF_SIZEOF_CHKSUM));
/* Verify checksum */
if(stored_chksum != computed_chksum)
@@ -525,7 +525,7 @@ HDfprintf(stderr, "%s: Flushing heap header, addr = %a, destroy = %u\n", FUNC, a
} /* end if */
/* Compute metadata checksum */
- metadata_chksum = H5_fletcher32(buf, hdr->heap_size - H5HF_SIZEOF_CHKSUM);
+ metadata_chksum = H5_checksum_metadata(buf, hdr->heap_size - H5HF_SIZEOF_CHKSUM);
/* Metadata checksum */
UINT32ENCODE(p, metadata_chksum);
@@ -826,7 +826,7 @@ HDfprintf(stderr, "%s: iblock->ents[%Zu] = {%a}\n", FUNC, u, iblock->ents[u].add
HDassert((size_t)(p - buf) == iblock->size);
/* Compute checksum on indirect block */
- computed_chksum = H5_fletcher32(buf, (iblock->size - H5HF_SIZEOF_CHKSUM));
+ computed_chksum = H5_checksum_metadata(buf, (iblock->size - H5HF_SIZEOF_CHKSUM));
/* Verify checksum */
if(stored_chksum != computed_chksum)
@@ -973,7 +973,7 @@ HDfprintf(stderr, "%s: iblock->filt_ents[%Zu] = {%Zu, %x}\n", FUNC, u, iblock->f
} /* end for */
/* Compute checksum */
- metadata_chksum = H5_fletcher32(buf, iblock->size - H5HF_SIZEOF_CHKSUM);
+ metadata_chksum = H5_checksum_metadata(buf, iblock->size - H5HF_SIZEOF_CHKSUM);
/* Metadata checksum */
UINT32ENCODE(p, metadata_chksum);
@@ -1235,7 +1235,7 @@ HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, NULL, "I/O filters not supported yet")
HDmemset((uint8_t *)p - H5HF_SIZEOF_CHKSUM, 0, (size_t)H5HF_SIZEOF_CHKSUM);
/* Compute checksum on entire direct block */
- computed_chksum = H5_fletcher32(dblock->blk, dblock->size);
+ computed_chksum = H5_checksum_metadata(dblock->blk, dblock->size);
/* Verify checksum */
if(stored_chksum != computed_chksum)
@@ -1314,7 +1314,7 @@ H5HF_cache_dblock_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr,
HDmemset(p, 0, (size_t)H5HF_SIZEOF_CHKSUM);
/* Compute checksum on entire direct block */
- metadata_chksum = H5_fletcher32(dblock->blk, dblock->size);
+ metadata_chksum = H5_checksum_metadata(dblock->blk, dblock->size);
/* Metadata checksum */
UINT32ENCODE(p, metadata_chksum);
diff --git a/src/H5checksum.c b/src/H5checksum.c
index 9ad575d..4a1e5de 100644
--- a/src/H5checksum.c
+++ b/src/H5checksum.c
@@ -136,3 +136,38 @@ H5_fletcher32(const void *_data, size_t _len)
FUNC_LEAVE_NOAPI((sum2 << 16) | sum1)
} /* end H5_fletcher32() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5_checksum_metadata
+ *
+ * Purpose: Provide a more abstract routine for checksumming metadata
+ * in a file, where the policy of which algorithm to choose
+ * is centralized.
+ *
+ * Return: checksum of input buffer (can't fail)
+ *
+ * Programmer: Quincey Koziol
+ * Tuesday, August 22, 2006
+ *
+ *-------------------------------------------------------------------------
+ */
+uint32_t
+H5_checksum_metadata(const void *data, size_t len)
+{
+ uint32_t chksum; /* Checksum value to return */
+
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5_checksum_metadata)
+
+ /* Sanity check */
+ HDassert(data);
+ HDassert(len > 0);
+
+ /* Choose the appropriate checksum routine */
+ /* (use fletcher32 for everything right now, but will probably go
+ * with a CRC algorithm for "shorter" pieces of metadata eventually)
+ */
+ chksum = H5_fletcher32(data, len);
+
+ FUNC_LEAVE_NOAPI(chksum)
+} /* end H5_checksum_metadata() */
+
diff --git a/src/H5private.h b/src/H5private.h
index f3bae08..28c72c8 100644
--- a/src/H5private.h
+++ b/src/H5private.h
@@ -1448,6 +1448,7 @@ H5_DLL int H5Z_term_interface(void);
/* Checksum functions */
H5_DLL uint32_t H5_fletcher32(const void *data, size_t len);
+H5_DLL uint32_t H5_checksum_metadata(const void *data, size_t len);
/* Functions for debugging */
H5_DLL herr_t H5_buffer_dump(FILE *stream, int indent, uint8_t *buf,