summaryrefslogtreecommitdiffstats
path: root/src/H5Ocache.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2006-10-16 14:46:00 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2006-10-16 14:46:00 (GMT)
commit9848ea0387c08ecffa4e97c5d880b4253e059dbc (patch)
tree4a4f3ca1e5e9a8893b9b52e2b8fc30f0685152f0 /src/H5Ocache.c
parent10e8a68a0c380cc58d831e95271ccc8ce658ad20 (diff)
downloadhdf5-9848ea0387c08ecffa4e97c5d880b4253e059dbc.zip
hdf5-9848ea0387c08ecffa4e97c5d880b4253e059dbc.tar.gz
hdf5-9848ea0387c08ecffa4e97c5d880b4253e059dbc.tar.bz2
[svn-r12761] Description:
Refactor object header macros, in preparation for updating the format. Tested on: Mac OS/PPC 10.4.8 (amazon) FreeBSD/32 4.11 (sleipnir) w/thread-safe Linux/32 2.4 (heping) w/C++ & FORTRAN Linux/64 2.4 (mir) w/1.6 compat & build-all
Diffstat (limited to 'src/H5Ocache.c')
-rw-r--r--src/H5Ocache.c86
1 files changed, 50 insertions, 36 deletions
diff --git a/src/H5Ocache.c b/src/H5Ocache.c
index ceb6b5a..e3ce6ac 100644
--- a/src/H5Ocache.c
+++ b/src/H5Ocache.c
@@ -125,8 +125,9 @@ H5O_flush_msgs(H5F_t *f, H5O_t *oh)
/* Encode any dirty messages */
for(u = 0, curr_msg = &oh->mesg[0]; u < oh->nmesgs; u++, curr_msg++) {
if(curr_msg->dirty) {
- p = curr_msg->raw - H5O_SIZEOF_MSGHDR(f);
+ p = curr_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh);
+ /* Encode the message prefix */
id = curr_msg->type->id;
UINT16ENCODE(p, id);
HDassert(curr_msg->raw_size < H5O_MESG_MAX_SIZE);
@@ -136,6 +137,7 @@ H5O_flush_msgs(H5F_t *f, H5O_t *oh)
*p++ = 0; /*reserved*/
*p++ = 0; /*reserved*/
+ /* Encode the message itself */
if(curr_msg->native) {
HDassert(curr_msg->type->encode);
@@ -153,7 +155,7 @@ H5O_flush_msgs(H5F_t *f, H5O_t *oh)
* which is being shared.
*/
HDassert(curr_msg->raw >= oh->chunk[curr_msg->chunkno].image);
- HDassert(curr_msg->raw_size == H5O_ALIGN (curr_msg->raw_size));
+ HDassert(curr_msg->raw_size == H5O_ALIGN_OH(oh, curr_msg->raw_size));
HDassert(curr_msg->raw + curr_msg->raw_size <=
oh->chunk[curr_msg->chunkno].image + oh->chunk[curr_msg->chunkno].size);
if(curr_msg->flags & H5O_FLAG_SHARED)
@@ -281,7 +283,7 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * _udata1,
for(p = oh->chunk[chunkno].image; p < oh->chunk[chunkno].image + chunk_size; p += mesg_size) {
UINT16DECODE(p, id);
UINT16DECODE(p, mesg_size);
- HDassert(mesg_size==H5O_ALIGN (mesg_size));
+ HDassert(mesg_size == H5O_ALIGN_OH(mesg_size));
flags = *p++;
p += 3; /*reserved*/
@@ -418,41 +420,41 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * _udata1,
if(NULL == (oh = H5FL_CALLOC(H5O_t)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
- /* decode version */
+ /* Version */
oh->version = *p++;
- if(H5O_VERSION != oh->version)
+ if(H5O_VERSION_1 != oh->version)
HGOTO_ERROR(H5E_OHDR, H5E_VERSION, NULL, "bad object header version number")
- /* reserved */
+ /* Reserved */
p++;
- /* decode number of messages */
+ /* Number of messages */
UINT16DECODE(p, nmesgs);
- /* decode link count */
+ /* Link count */
UINT32DECODE(p, oh->nlink);
- /* decode first chunk size */
+ /* First chunk size */
UINT32DECODE(p, chunk_size);
- /* reserved */
+ /* Reserved */
p += 4;
/* Compute first chunk address */
prefix_size = (size_t)(p - read_buf);
chunk_addr = addr + (hsize_t)prefix_size;
- /* build the message array */
+ /* Allocate the message array */
oh->alloc_nmesgs = nmesgs;
if(NULL == (oh->mesg = H5FL_SEQ_MALLOC(H5O_mesg_t, oh->alloc_nmesgs)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
- /* read each chunk from disk */
+ /* Read each chunk from disk */
while(H5F_addr_defined(chunk_addr)) {
unsigned chunkno; /* Current chunk's index */
size_t mesg_size; /* Size of message read in */
- /* increase chunk array size */
+ /* Increase chunk array size, if necessary */
if(oh->nchunks >= oh->alloc_nchunks) {
unsigned na = oh->alloc_nchunks + H5O_NCHUNKS;
H5O_chunk_t *x = H5FL_SEQ_REALLOC(H5O_chunk_t, oh->chunk, (size_t)na);
@@ -480,7 +482,7 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * _udata1,
HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL, "unable to read object header data")
} /* end else */
- /* load messages from this chunk */
+ /* Load messages from this chunk */
for(p = oh->chunk[chunkno].image; p < oh->chunk[chunkno].image + chunk_size; p += mesg_size) {
unsigned mesgno; /* Current message to operate on */
unsigned id; /* ID (type) of current message */
@@ -488,7 +490,7 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * _udata1,
UINT16DECODE(p, id);
UINT16DECODE(p, mesg_size);
- HDassert(mesg_size==H5O_ALIGN (mesg_size));
+ HDassert(mesg_size == H5O_ALIGN_OH(oh, mesg_size));
flags = *p++;
p += 3; /*reserved*/
@@ -497,24 +499,27 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * _udata1,
HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "corrupt object header")
/* Skip header messages we don't know about */
- /* (Usually from future versions of the library */
+ /* (Usually from future versions of the library) */
if(id >= NELMTS(H5O_msg_class_g) || NULL == H5O_msg_class_g[id]) {
skipped_msgs++;
continue;
} /* end if */
+ /* Check for combining two adjacent 'null' messages */
if((H5F_get_intent(f) & H5F_ACC_RDWR) &&
H5O_NULL_ID == id && oh->nmesgs > 0 &&
H5O_NULL_ID == oh->mesg[oh->nmesgs - 1].type->id &&
oh->mesg[oh->nmesgs - 1].chunkno == chunkno) {
- /* combine adjacent null messages */
+
+ /* Combine adjacent null messages */
mesgno = oh->nmesgs - 1;
- oh->mesg[mesgno].raw_size += H5O_SIZEOF_MSGHDR(f) + mesg_size;
+ oh->mesg[mesgno].raw_size += H5O_SIZEOF_MSGHDR_OH(oh) + mesg_size;
oh->mesg[mesgno].dirty = TRUE;
merged_null_msgs++;
- } else {
- /* new message */
- if (oh->nmesgs >= nmesgs)
+ } /* end if */
+ else {
+ /* New message */
+ if(oh->nmesgs >= nmesgs)
HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "corrupt object header - too many messages")
mesgno = oh->nmesgs++;
oh->mesg[mesgno].type = H5O_msg_class_g[id];
@@ -529,16 +534,22 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * _udata1,
HDassert(p == oh->chunk[chunkno].image + chunk_size);
- /* decode next object header continuation message */
+ /* Check for another chunk to read in & parse */
for(chunk_addr = HADDR_UNDEF; !H5F_addr_defined(chunk_addr) && curmesg < oh->nmesgs; ++curmesg) {
+ /* Check if next message to examine is a continuation message */
if(H5O_CONT_ID == oh->mesg[curmesg].type->id) {
H5O_cont_t *cont;
- cont = (H5O_MSG_CONT->decode) (f, dxpl_id, oh->mesg[curmesg].raw);
+ /* Decode continuation message */
+ cont = (H5O_MSG_CONT->decode)(f, dxpl_id, oh->mesg[curmesg].raw);
+ cont->chunkno = oh->nchunks; /*the next chunk to allocate */
+
+ /* Save 'native' form of continuation message */
oh->mesg[curmesg].native = cont;
+
+ /* Set up to read in next chunk */
chunk_addr = cont->addr;
chunk_size = cont->size;
- cont->chunkno = oh->nchunks; /*the next chunk to allocate */
} /* end if */
} /* end for */
} /* end while */
@@ -619,15 +630,15 @@ H5O_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5O_t *oh)
UINT32ENCODE(p, oh->chunk[0].size);
/* zero to alignment */
- HDmemset(p, 0, (size_t)(H5O_SIZEOF_HDR(f)-12));
+ HDmemset(p, 0, (size_t)(H5O_SIZEOF_HDR_OH(oh) - 12));
/* write the object header prefix */
/* Check if we can combine the object header prefix & the first chunk into one I/O operation */
- if(oh->chunk[0].dirty && (addr + H5O_SIZEOF_HDR(f)) == oh->chunk[0].addr)
+ if(oh->chunk[0].dirty && (addr + H5O_SIZEOF_HDR_OH(oh)) == oh->chunk[0].addr)
combine = TRUE;
else {
- if(H5F_block_write(f, H5FD_MEM_OHDR, addr, (size_t)H5O_SIZEOF_HDR(f), dxpl_id, buf) < 0)
+ if(H5F_block_write(f, H5FD_MEM_OHDR, addr, (size_t)H5O_SIZEOF_HDR_OH(oh), dxpl_id, buf) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "unable to write object header hdr to disk")
} /* end else */
@@ -637,35 +648,39 @@ H5O_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5O_t *oh)
HDassert(H5F_addr_defined(oh->chunk[u].addr));
if(u == 0 && combine) {
/* Allocate space for the combined prefix and first chunk */
- if((p = H5FL_BLK_MALLOC(chunk_image, (H5O_SIZEOF_HDR(f) + oh->chunk[u].size))) == NULL)
+ if((p = H5FL_BLK_MALLOC(chunk_image, (H5O_SIZEOF_HDR_OH(oh) + oh->chunk[u].size))) == NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
/* Copy in the prefix */
- HDmemcpy(p, buf, (size_t)H5O_SIZEOF_HDR(f));
+ HDmemcpy(p, buf, (size_t)H5O_SIZEOF_HDR_OH(oh));
/* Copy in the first chunk */
- HDmemcpy(p + H5O_SIZEOF_HDR(f), oh->chunk[u].image, oh->chunk[u].size);
+ HDmemcpy(p + H5O_SIZEOF_HDR_OH(oh), oh->chunk[u].image, oh->chunk[u].size);
/* Write the combined prefix/chunk out */
if(H5F_block_write(f, H5FD_MEM_OHDR, addr,
- (H5O_SIZEOF_HDR(f) + oh->chunk[u].size), dxpl_id, p) < 0)
+ (H5O_SIZEOF_HDR_OH(oh) + oh->chunk[u].size), dxpl_id, p) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "unable to write object header data to disk")
/* Release the memory for the combined prefix/chunk */
- p = H5FL_BLK_FREE(chunk_image,p);
+ p = H5FL_BLK_FREE(chunk_image, p);
} /* end if */
else {
if(H5F_block_write(f, H5FD_MEM_OHDR, oh->chunk[u].addr,
(oh->chunk[u].size), dxpl_id, oh->chunk[u].image) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "unable to write object header data to disk")
} /* end else */
+
+ /* Mark chunk as clean now */
oh->chunk[u].dirty = FALSE;
} /* end if */
} /* end for */
+
+ /* Mark object header as clean now */
oh->cache_info.is_dirty = FALSE;
} /* end if */
- if (destroy) {
+ if(destroy) {
if(H5O_dest(f,oh) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTFREE, FAIL, "unable to destroy object header data")
} /* end if */
@@ -787,7 +802,7 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5O_size(const H5F_t *f, const H5O_t *oh, size_t *size_ptr)
+H5O_size(const H5F_t UNUSED *f, const H5O_t *oh, size_t *size_ptr)
{
size_t size; /* Running sum of the object header's size */
unsigned u; /* Local index variable */
@@ -795,12 +810,11 @@ H5O_size(const H5F_t *f, const H5O_t *oh, size_t *size_ptr)
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_size)
/* check args */
- HDassert(f);
HDassert(oh);
HDassert(size_ptr);
/* Size of object header "prefix" */
- size = H5O_SIZEOF_HDR(f);
+ size = H5O_SIZEOF_HDR_OH(oh);
/* Add sizes of all the chunks */
for(u = 0; u < oh->nchunks; u++)