summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5HF.c101
-rw-r--r--src/H5HFhdr.c2
-rw-r--r--src/H5HFint.c2
-rw-r--r--src/H5HFpkg.h29
-rw-r--r--test/fheap.c2
5 files changed, 96 insertions, 40 deletions
diff --git a/src/H5HF.c b/src/H5HF.c
index 55d3324..c241cac 100644
--- a/src/H5HF.c
+++ b/src/H5HF.c
@@ -400,8 +400,10 @@ herr_t
H5HF_get_obj_len(H5HF_t *fh, const void *_id, size_t *obj_len_p)
{
const uint8_t *id = (const uint8_t *)_id; /* Object ID */
+ uint8_t id_flags; /* Heap ID flag bits */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOFUNC(H5HF_get_obj_len)
+ FUNC_ENTER_NOAPI(H5HF_get_obj_len, FAIL)
/*
* Check arguments.
@@ -410,13 +412,28 @@ H5HF_get_obj_len(H5HF_t *fh, const void *_id, size_t *obj_len_p)
HDassert(id);
HDassert(obj_len_p);
- /* Skip over object offset */
- id += fh->hdr->heap_off_size;
+ /* Get the ID flags */
+ id_flags = *id++;
- /* Retrieve the entry length */
- UINT64DECODE_VAR(id, *obj_len_p, fh->hdr->heap_len_size);
+ /* Check for correct heap ID version */
+ if((id_flags & H5HF_ID_VERS_MASK) != H5HF_ID_VERS_CURR)
+ HGOTO_ERROR(H5E_HEAP, H5E_VERSION, FAIL, "incorrect heap ID version")
- FUNC_LEAVE_NOAPI(SUCCEED)
+ /* Check for managed object */
+ if((id_flags & H5HF_ID_TYPE_MASK) == H5HF_ID_TYPE_MAN) {
+ /* Skip over object offset */
+ id += fh->hdr->heap_off_size;
+
+ /* Retrieve the entry length */
+ UINT64DECODE_VAR(id, *obj_len_p, fh->hdr->heap_len_size);
+ } /* end if */
+ else {
+HDfprintf(stderr, "%s: Heap ID type not supported yet!\n", FUNC);
+HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, FAIL, "heap ID type not supported yet")
+ } /* end else */
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF_get_obj_len() */
@@ -436,11 +453,9 @@ H5HF_get_obj_len(H5HF_t *fh, const void *_id, size_t *obj_len_p)
herr_t
H5HF_read(H5HF_t *fh, hid_t dxpl_id, const void *_id, void *obj/*out*/)
{
- H5HF_hdr_t *hdr = NULL; /* The fractal heap header information */
const uint8_t *id = (const uint8_t *)_id; /* Object ID */
- hsize_t obj_off; /* Object's offset in heap */
- size_t obj_len; /* Object's length in heap */
- herr_t ret_value = SUCCEED;
+ uint8_t id_flags; /* Heap ID flag bits */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5HF_read, FAIL)
@@ -451,23 +466,32 @@ H5HF_read(H5HF_t *fh, hid_t dxpl_id, const void *_id, void *obj/*out*/)
HDassert(id);
HDassert(obj);
- /* Get the fractal heap header */
- hdr = fh->hdr;
+ /* Get the ID flags */
+ id_flags = *id++;
+
+ /* Check for correct heap ID version */
+ if((id_flags & H5HF_ID_VERS_MASK) != H5HF_ID_VERS_CURR)
+ HGOTO_ERROR(H5E_HEAP, H5E_VERSION, FAIL, "incorrect heap ID version")
+
+ /* Check for managed object */
+ if((id_flags & H5HF_ID_TYPE_MASK) == H5HF_ID_TYPE_MAN) {
+ hsize_t obj_off; /* Object's offset in heap */
+ size_t obj_len; /* Object's length in heap */
- /* Decode the object offset within the heap & it's length */
- H5HF_ID_DECODE(id, hdr, obj_off, obj_len);
+ /* Decode the object offset within the heap & it's length */
+ UINT64DECODE_VAR(id, obj_off, fh->hdr->heap_off_size);
+ UINT64DECODE_VAR(id, obj_len, fh->hdr->heap_len_size);
#ifdef QAK
HDfprintf(stderr, "%s: obj_off = %Hu, obj_len = %Zu\n", FUNC, obj_off, obj_len);
#endif /* QAK */
- /* Check for standalone object */
- if(obj_off & 0) {
-HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, FAIL, "standalone blocks not supported yet")
- } /* end if */
- else {
/* Read object from managed heap blocks */
- if(H5HF_man_read(hdr, dxpl_id, obj_off, obj_len, obj) < 0)
+ if(H5HF_man_read(fh->hdr, dxpl_id, obj_off, obj_len, obj) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't read object from fractal heap")
+ } /* end if */
+ else {
+HDfprintf(stderr, "%s: Heap ID type not supported yet!\n", FUNC);
+HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, FAIL, "heap ID type not supported yet")
} /* end else */
done:
@@ -492,9 +516,8 @@ herr_t
H5HF_remove(H5HF_t *fh, hid_t dxpl_id, const void *_id)
{
const uint8_t *id = (const uint8_t *)_id; /* Object ID */
- hsize_t obj_off; /* Object's offset in heap */
- size_t obj_len; /* Object's length in heap */
- herr_t ret_value = SUCCEED;
+ uint8_t id_flags; /* Heap ID flag bits */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5HF_remove, FAIL)
@@ -505,27 +528,39 @@ H5HF_remove(H5HF_t *fh, hid_t dxpl_id, const void *_id)
HDassert(fh->hdr);
HDassert(id);
- /* Decode the object offset within the heap & it's length */
+ /* Get the ID flags */
+ id_flags = *id++;
+
+ /* Check for correct heap ID version */
+ if((id_flags & H5HF_ID_VERS_MASK) != H5HF_ID_VERS_CURR)
+ HGOTO_ERROR(H5E_HEAP, H5E_VERSION, FAIL, "incorrect heap ID version")
+
+ /* Check for managed object */
+ if((id_flags & H5HF_ID_TYPE_MASK) == H5HF_ID_TYPE_MAN) {
+ hsize_t obj_off; /* Object's offset in heap */
+ size_t obj_len; /* Object's length in heap */
+
+ /* Decode the object offset within the heap & it's length */
#ifdef QAK
HDfprintf(stderr, "%s: fh->hdr->heap_off_size = %u, fh->hdr->heap_len_size = %u\n", FUNC, (unsigned)fh->hdr->heap_off_size, (unsigned)fh->hdr->heap_len_size);
#endif /* QAK */
- H5HF_ID_DECODE(id, fh->hdr, obj_off, obj_len);
+ UINT64DECODE_VAR(id, obj_off, fh->hdr->heap_off_size);
+ UINT64DECODE_VAR(id, obj_len, fh->hdr->heap_len_size);
#ifdef QAK
HDfprintf(stderr, "%s: obj_off = %Hu, obj_len = %Zu\n", FUNC, obj_off, obj_len);
#endif /* QAK */
- /* Sanity check parameters */
- HDassert(obj_off);
- HDassert(obj_len);
+ /* Sanity check parameters */
+ HDassert(obj_off);
+ HDassert(obj_len);
- /* Check for standalone object */
- if(obj_off & 0) {
-HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, FAIL, "standalone blocks not supported yet")
- } /* end if */
- else {
/* Remove object from managed heap blocks */
if(H5HF_man_remove(fh->hdr, dxpl_id, obj_off, obj_len) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTREMOVE, FAIL, "can't remove object from fractal heap")
+ } /* end if */
+ else {
+HDfprintf(stderr, "%s: Heap ID type not supported yet!\n", FUNC);
+HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, FAIL, "heap ID type not supported yet")
} /* end else */
done:
diff --git a/src/H5HFhdr.c b/src/H5HFhdr.c
index f9083f8..3628bd8 100644
--- a/src/H5HFhdr.c
+++ b/src/H5HFhdr.c
@@ -225,7 +225,7 @@ H5HF_hdr_finish_init(H5HF_hdr_t *hdr)
/* Set the size of heap IDs */
hdr->heap_len_size = MIN(hdr->man_dtable.max_dir_blk_off_size,
((H5V_log2_gen((hsize_t)hdr->standalone_size) + 7) / 8));
- hdr->id_len = hdr->heap_off_size + hdr->heap_len_size;
+ hdr->id_len = H5HF_ID_SIZE(hdr);
/* Set the free space in direct blocks */
for(u = 0; u < hdr->man_dtable.max_root_rows; u++) {
diff --git a/src/H5HFint.c b/src/H5HFint.c
index 8964c29..9274b4d 100644
--- a/src/H5HFint.c
+++ b/src/H5HFint.c
@@ -385,7 +385,7 @@ HDfprintf(stderr, "%s: blk_off = %Zu\n", FUNC, blk_off);
#ifdef QAK
HDfprintf(stderr, "%s: dblock->block_off = %Hu\n", FUNC, dblock->block_off);
#endif /* QAK */
- H5HF_ID_ENCODE(id, hdr, (dblock->block_off + blk_off), obj_size);
+ H5HF_MAN_ID_ENCODE(id, hdr, (dblock->block_off + blk_off), obj_size);
#ifdef QAK
HDfprintf(stderr, "%s: obj_off = %Hu, obj_len = %Zu\n", FUNC, (dblock->block_off + blk_off), obj_size);
#endif /* QAK */
diff --git a/src/H5HFpkg.h b/src/H5HFpkg.h
index 6f3025d..b3b0951 100644
--- a/src/H5HFpkg.h
+++ b/src/H5HFpkg.h
@@ -114,16 +114,37 @@
#define H5HF_SIZEOF_OFFSET_BITS(b) (((b) + 7) / 8)
#define H5HF_SIZEOF_OFFSET_LEN(l) H5HF_SIZEOF_OFFSET_BITS(H5V_log2_of2((unsigned)(l)))
-/* Encode a heap ID */
-#define H5HF_ID_ENCODE(i, h, o, l) \
+/* Heap ID bit flags */
+/* Heap ID version (2 bits: 6-7) */
+#define H5HF_ID_VERS_CURR 0x00 /* Current version of ID format */
+#define H5HF_ID_VERS_MASK 0xC0 /* Mask for getting the ID version from flags */
+/* Heap ID type (2 bits: 4-5) */
+#define H5HF_ID_TYPE_MAN 0x00 /* "Managed" object - stored in fractal heap blocks */
+#define H5HF_ID_TYPE_HUGE 0x10 /* "Huge" object - stored in file directly */
+#define H5HF_ID_TYPE_TINY 0x20 /* "Tiny" object - stored in heap ID directly */
+#define H5HF_ID_TYPE_RESERVED 0x30 /* "?" object - reserved for future use */
+#define H5HF_ID_TYPE_MASK 0x30 /* Mask for getting the ID type from flags */
+/* Heap ID bits 0-3 reserved for future use */
+
+/* Encode a "managed" heap ID */
+#define H5HF_MAN_ID_ENCODE(i, h, o, l) \
+ *(uint8_t *)i++ = H5HF_ID_VERS_CURR | H5HF_ID_TYPE_MAN; \
UINT64ENCODE_VAR((i), (o), (h)->heap_off_size); \
UINT64ENCODE_VAR((i), (l), (h)->heap_len_size)
-/* Decode a heap ID */
-#define H5HF_ID_DECODE(i, h, o, l) \
+/* Decode a "managed" heap ID */
+#define H5HF_MAN_ID_DECODE(i, h, f, o, l) \
+ f = *(uint8_t *)i++; \
UINT64DECODE_VAR((i), (o), (h)->heap_off_size); \
UINT64DECODE_VAR((i), (l), (h)->heap_len_size)
+/* Size of ID for heap */
+#define H5HF_ID_SIZE(h) ( \
+ 1 /* ID flag byte */ \
+ + (h)->heap_off_size /* Space for managed object offset */ \
+ + (h)->heap_len_size /* Space for managed object length */ \
+ )
+
/* Free space section types for fractal heap */
/* (values stored in free space data structures in file) */
#define H5HF_FSPACE_SECT_SINGLE 0 /* Section is a range of actual bytes in a direct block */
diff --git a/test/fheap.c b/test/fheap.c
index 43cff34..f3ffa9c 100644
--- a/test/fheap.c
+++ b/test/fheap.c
@@ -52,7 +52,7 @@
/* #define ALL_INSERT_TESTS */
/* Heap metadata macros */
-#define HEAP_ID_LEN 6 /* # of bytes to use for heap ID */
+#define HEAP_ID_LEN 7 /* # of bytes to use for heap ID */
#define HEAP_MAX_ROOT_ROWS(fh) H5HF_get_max_root_rows(fh) /* Max. # of rows in root indirect block */
#define DTABLE_WIDTH(fh) H5HF_get_dtable_width_test(fh) /* Width of doubling table for heap */
#define DTABLE_MAX_DROWS(fh) H5HF_get_dtable_max_drows_test(fh) /* Max. # of direct block rows in any indirect block */