diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2006-10-12 18:42:02 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2006-10-12 18:42:02 (GMT) |
commit | 6716ae8429b63b32623f1de1d0a6235c559e6e9c (patch) | |
tree | 946fece29fc5a7706a175a3acecbfe560cd2a9c0 | |
parent | 7da414109cf800ba11680dc25627571953fc268e (diff) | |
download | hdf5-6716ae8429b63b32623f1de1d0a6235c559e6e9c.zip hdf5-6716ae8429b63b32623f1de1d0a6235c559e6e9c.tar.gz hdf5-6716ae8429b63b32623f1de1d0a6235c559e6e9c.tar.bz2 |
[svn-r12756] Description:
Clean up some object header code in advance of more major changes in the
near future.
Fix small initialization error in attribute message name buffer copy.
Tweak down the default # of messages for new object headers.
Tested on:
FreeBSD/32 4.11 (sleipnir) w/threadsafe
Linux/32 2.4 (heping) w/FORTRAN & C++
Mac OS/32 10.4.8 (amazon)
-rw-r--r-- | src/H5D.c | 2 | ||||
-rw-r--r-- | src/H5Gobj.c | 4 | ||||
-rw-r--r-- | src/H5O.c | 104 | ||||
-rw-r--r-- | src/H5Oattr.c | 29 | ||||
-rw-r--r-- | src/H5Ocache.c | 61 | ||||
-rw-r--r-- | src/H5Opkg.h | 4 | ||||
-rw-r--r-- | src/H5Oprivate.h | 3 |
7 files changed, 94 insertions, 113 deletions
@@ -2515,7 +2515,7 @@ H5D_create(H5F_t *file, hid_t type_id, const H5S_t *space, /* Verify data size is smaller than maximum header message size * (64KB) minus other layout message fields. */ - comp_data_size=H5O_MAX_SIZE-H5O_layout_meta_size(file, &(new_dset->shared->layout)); + comp_data_size=H5O_MESG_MAX_SIZE-H5O_layout_meta_size(file, &(new_dset->shared->layout)); if(new_dset->shared->layout.u.compact.size > comp_data_size) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "compact dataset size is bigger than header message maximum size") diff --git a/src/H5Gobj.c b/src/H5Gobj.c index 4500ed4..b6abe4c 100644 --- a/src/H5Gobj.c +++ b/src/H5Gobj.c @@ -536,7 +536,7 @@ H5G_obj_insert(H5O_loc_t *grp_oloc, const char *name, H5O_link_t *obj_lnk, */ if(H5F_addr_defined(linfo.link_fheap_addr)) use_new_dense = TRUE; - else if(linfo.nlinks < ginfo.max_compact && link_msg_size < H5O_MAX_SIZE) + else if(linfo.nlinks < ginfo.max_compact && link_msg_size < H5O_MESG_MAX_SIZE) use_new_dense = FALSE; else { H5G_obj_oh_it_ud1_t udata; /* User data for iteration */ @@ -942,7 +942,7 @@ H5G_obj_remove(H5O_loc_t *oloc, const char *name, H5G_obj_t *obj_type, hid_t dxp * into an object header message) */ for(u = 0; u < linfo.nlinks; u++) - if(H5O_mesg_size(H5O_LINK_ID, oloc->file, &(ltable.lnks[u]), (size_t)0) >= H5O_MAX_SIZE) { + if(H5O_mesg_size(H5O_LINK_ID, oloc->file, &(ltable.lnks[u]), (size_t)0) >= H5O_MESG_MAX_SIZE) { can_convert = FALSE; break; } /* end if */ @@ -44,6 +44,7 @@ #endif /* H5_HAVE_GETTIMEOFDAY */ /* Local macros */ +#define H5O_MIN_SIZE 32 /*min obj header data size */ /* Load native information for a message, if it's not already present */ /* (Only works for messages with decode callback) */ @@ -653,7 +654,7 @@ done: herr_t H5O_create(H5F_t *f, hid_t dxpl_id, size_t size_hint, H5O_loc_t *loc/*out*/) { - haddr_t header; + haddr_t header; /* Address of object header */ herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_NOAPI(H5O_create, FAIL) @@ -662,6 +663,7 @@ H5O_create(H5F_t *f, hid_t dxpl_id, size_t size_hint, H5O_loc_t *loc/*out*/) HDassert(f); HDassert(loc); + /* Make certain we allocate at least a reasonable size for the object header */ size_hint = H5O_ALIGN(MAX(H5O_MIN_SIZE, size_hint)); /* allocate disk space for header and first chunk */ @@ -697,10 +699,10 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5O_new(H5F_t *f, hid_t dxpl_id, size_t size_hint, H5O_loc_t *loc/*out*/, haddr_t header) +H5O_new(H5F_t *f, hid_t dxpl_id, size_t size_hint, H5O_loc_t *loc/*out*/, + haddr_t header) { H5O_t *oh = NULL; - haddr_t tmp_addr; herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_NOAPI_NOINIT(H5O_new) @@ -709,7 +711,6 @@ H5O_new(H5F_t *f, hid_t dxpl_id, size_t size_hint, H5O_loc_t *loc/*out*/, haddr_ HDassert(f); HDassert(loc); - size_hint = H5O_ALIGN(MAX(H5O_MIN_SIZE, size_hint)); loc->file = f; loc->addr = header; @@ -727,9 +728,8 @@ H5O_new(H5F_t *f, hid_t dxpl_id, size_t size_hint, H5O_loc_t *loc/*out*/, haddr_ if(NULL == (oh->chunk = H5FL_SEQ_MALLOC(H5O_chunk_t, (size_t)oh->alloc_nchunks))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - tmp_addr = loc->addr + (hsize_t)H5O_SIZEOF_HDR(f); oh->chunk[0].dirty = TRUE; - oh->chunk[0].addr = tmp_addr; + oh->chunk[0].addr = loc->addr + (hsize_t)H5O_SIZEOF_HDR(f); oh->chunk[0].size = size_hint; if(NULL == (oh->chunk[0].image = H5FL_BLK_CALLOC(chunk_image, size_hint))) @@ -1077,7 +1077,7 @@ H5O_copy (unsigned type_id, const void *mesg, void *dst) /* Call the "real" copy routine */ if((ret_value=H5O_copy_real(type, mesg, dst))==NULL) - HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy object header message"); + HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy object header message") done: FUNC_LEAVE_NOAPI(ret_value); @@ -1565,7 +1565,7 @@ H5O_find_in_ohdr(H5F_t *f, hid_t dxpl_id, H5O_t *oh, const H5O_msg_class_t **typ } if (sequence >= 0) - HGOTO_ERROR(H5E_OHDR, H5E_NOTFOUND, UFAIL, "unable to find object header message"); + HGOTO_ERROR(H5E_OHDR, H5E_NOTFOUND, UFAIL, "unable to find object header message") /* * Decode the message if necessary. If the message is shared then decode @@ -1879,7 +1879,7 @@ H5O_append(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned type_id, unsigned flags, /* Call the "real" append routine */ if((ret_value=H5O_append_real( f, dxpl_id, oh, type, flags, mesg, oh_flags_ptr)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "unable to append to object header"); + HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "unable to append to object header") done: FUNC_LEAVE_NOAPI(ret_value); @@ -1923,11 +1923,11 @@ H5O_append_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh, const H5O_msg_class_t *type, /* Create a new message */ if((idx=H5O_new_mesg(f,oh,&flags,type,mesg,&sh_mesg,&type,&mesg,dxpl_id,oh_flags_ptr))==UFAIL) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to create new message"); + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to create new message") /* Write the information to the message */ if(H5O_write_mesg(oh,idx,type,mesg,flags,0,oh_flags_ptr) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to write message"); + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to write message") /* Set return value */ ret_value = idx; @@ -1976,7 +1976,7 @@ H5O_new_mesg(H5F_t *f, H5O_t *oh, unsigned *flags, const H5O_msg_class_t *orig_t HDmemset(sh_mesg,0,sizeof(H5O_shared_t)); if (NULL==orig_type->get_share) - HGOTO_ERROR(H5E_OHDR, H5E_UNSUPPORTED, UFAIL, "message class is not sharable"); + HGOTO_ERROR(H5E_OHDR, H5E_UNSUPPORTED, UFAIL, "message class is not sharable") if ((orig_type->get_share)(f, orig_mesg, sh_mesg/*out*/) < 0) { /* * If the message isn't shared then turn off the shared bit @@ -1996,16 +1996,16 @@ H5O_new_mesg(H5F_t *f, H5O_t *oh, unsigned *flags, const H5O_msg_class_t *orig_t } /* end else */ /* Compute the size needed to store the message on disk */ - if((size = ((*new_type)->raw_size)(f, *new_mesg)) >=H5O_MAX_SIZE) + if((size = ((*new_type)->raw_size)(f, *new_mesg)) >=H5O_MESG_MAX_SIZE) HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, UFAIL, "object header message is too large") /* Allocate space in the object headed for the message */ if((ret_value = H5O_alloc(f, dxpl_id, oh, orig_type, size, oh_flags_ptr)) == UFAIL) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, UFAIL, "unable to allocate space for message"); + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, UFAIL, "unable to allocate space for message") /* Increment any links in message */ if((*new_type)->link && ((*new_type)->link)(f,dxpl_id,(*new_mesg)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_LINKCOUNT, UFAIL, "unable to adjust shared object link count"); + HGOTO_ERROR(H5E_OHDR, H5E_LINKCOUNT, UFAIL, "unable to adjust shared object link count") done: FUNC_LEAVE_NOAPI(ret_value); @@ -2049,7 +2049,7 @@ H5O_write_mesg(H5O_t *oh, unsigned idx, const H5O_msg_class_t *type, /* Copy the native value for the message */ if (NULL == (idx_msg->native = (type->copy) (mesg, idx_msg->native, update_flags))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to copy message to object header"); + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to copy message to object header") idx_msg->flags = flags; idx_msg->dirty = TRUE; @@ -2115,13 +2115,13 @@ H5O_touch_oh(H5F_t *f, size = (H5O_MSG_MTIME_NEW->raw_size)(f, &now); if((idx = H5O_alloc(f, dxpl_id, oh, H5O_MSG_MTIME_NEW, size, oh_flags_ptr)) == UFAIL) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to allocate space for modification time message"); + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to allocate space for modification time message") } /* end if */ /* Update the native part */ if(NULL==oh->mesg[idx].native) { if(NULL==(oh->mesg[idx].native = H5FL_MALLOC(time_t))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "memory allocation failed for modification time message"); + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "memory allocation failed for modification time message") } *((time_t*)(oh->mesg[idx].native)) = now; oh->mesg[idx].dirty = TRUE; @@ -2632,7 +2632,7 @@ H5O_move_msgs_forward(H5F_t *f, H5O_t *oh, hid_t dxpl_id) /* Adjust null message's offset in chunk */ curr_msg->raw = nonnull_msg->raw + - nonnull_msg->raw_size + H5O_SIZEOF_MSGHDR(f); + nonnull_msg->raw_size + H5O_SIZEOF_MSGHDR(f); /* Mark messages dirty */ curr_msg->dirty = TRUE; @@ -3144,9 +3144,9 @@ H5O_alloc_extend_chunk(H5F_t *f, /* If we can extend an existing null message, adjust the delta appropriately */ if(extend_msg >= 0) - delta = MAX(H5O_MIN_SIZE, aligned_size - oh->mesg[extend_msg].raw_size); + delta = aligned_size - oh->mesg[extend_msg].raw_size; else - delta = MAX(H5O_MIN_SIZE, aligned_size + H5O_SIZEOF_MSGHDR(f)); + delta = aligned_size + H5O_SIZEOF_MSGHDR(f); delta = H5O_ALIGN(delta); /* determine whether the chunk can be extended */ @@ -3270,9 +3270,9 @@ H5O_alloc_new_chunk(H5F_t *f, uint8_t *p = NULL; /*ptr into new chunk */ H5O_cont_t *cont = NULL; /*native continuation message */ int chunkno; - unsigned u; haddr_t new_chunk_addr; - unsigned ret_value; /*return value */ + unsigned u; /* Local index variable */ + unsigned ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5O_alloc_new_chunk) @@ -3289,7 +3289,7 @@ H5O_alloc_new_chunk(H5F_t *f, * Prioritize attribute and link messages moving to later chunks, * instead of more "important" messages. */ - cont_size = H5O_ALIGN (H5F_SIZEOF_ADDR(f) + H5F_SIZEOF_SIZE(f)); + cont_size = H5O_ALIGN(H5F_SIZEOF_ADDR(f) + H5F_SIZEOF_SIZE(f)); for(u = 0; u < oh->nmesgs; u++) { int msg_id = oh->mesg[u].type->id; /* Temp. copy of message type ID */ @@ -3347,7 +3347,7 @@ H5O_alloc_new_chunk(H5F_t *f, * multiple of the alignment size. */ size = MAX(H5O_MIN_SIZE, size + H5O_SIZEOF_MSGHDR(f)); - HDassert(size == H5O_ALIGN (size)); + HDassert(size == H5O_ALIGN(size)); /* allocate space in file to hold the new chunk */ new_chunk_addr = H5MF_alloc(f, H5FD_MEM_OHDR, dxpl_id, (hsize_t)size); @@ -3424,8 +3424,7 @@ H5O_alloc_new_chunk(H5F_t *f, oh->mesg[u].dirty = TRUE; oh->mesg[u].native = NULL; oh->mesg[u].raw = oh->mesg[found_null].raw + - cont_size + - H5O_SIZEOF_MSGHDR(f); + cont_size + H5O_SIZEOF_MSGHDR(f); oh->mesg[u].raw_size = oh->mesg[found_null].raw_size - (cont_size + H5O_SIZEOF_MSGHDR(f)); oh->mesg[u].chunkno = oh->mesg[found_null].chunkno; @@ -3496,16 +3495,6 @@ H5O_alloc(H5F_t *f, break; } /* end for */ -#ifdef LATER - /* - * Perhaps if we join adjacent null messages we could make one - * large enough... we leave this as an exercise for future - * programmers :-) This isn't a high priority because when an - * object header is read from disk the null messages are combined - * anyway. - */ -#endif - /* if we didn't find one, then allocate more header space */ if(idx >= oh->nmesgs) { unsigned chunkno; @@ -3618,11 +3607,11 @@ H5O_share (H5F_t *f, hid_t dxpl_id, const H5O_msg_class_t *type, const void *mes /* Encode the message put it in the global heap */ if ((size = (type->raw_size)(f, mesg))>0) { if (NULL==(buf = H5MM_malloc (size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") if ((type->encode)(f, buf, mesg) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to encode message"); + HGOTO_ERROR(H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to encode message") if (H5HG_insert (f, dxpl_id, size, buf, hobj) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to store message in global heap"); + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to store message in global heap") } done: @@ -4003,7 +3992,7 @@ H5O_encode(H5F_t *f, unsigned char *buf, const void *obj, unsigned type_id) /* Encode */ if((type->encode)(f, buf, obj) < 0) - HGOTO_ERROR (H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to encode message") + HGOTO_ERROR(H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to encode message") done: FUNC_LEAVE_NOAPI(ret_value) @@ -4045,7 +4034,7 @@ H5O_decode(H5F_t *f, hid_t dxpl_id, const unsigned char *buf, unsigned type_id) /* decode */ if((ret_value = (type->decode)(f, dxpl_id, buf)) == NULL) - HGOTO_ERROR (H5E_OHDR, H5E_CANTDECODE, NULL, "unable to decode message") + HGOTO_ERROR(H5E_OHDR, H5E_CANTDECODE, NULL, "unable to decode message") done: FUNC_LEAVE_NOAPI(ret_value) @@ -4166,7 +4155,7 @@ H5O_iterate_real(const H5O_loc_t *loc, const H5O_msg_class_t *type, H5AC_protect /* Protect the object header to iterate over */ if (NULL == (oh = H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, prot))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "unable to load object header"); + HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "unable to load object header") /* Iterate over messages */ for(sequence = 0, idx = 0, idx_msg = &oh->mesg[0]; idx < oh->nmesgs && !ret_value; idx++, idx_msg++) { @@ -4493,7 +4482,7 @@ H5O_loc_free(H5O_loc_t *loc) loc->holding_file = FALSE; if(loc->file->nopen_objs <= 0) { if(H5F_try_close(loc->file) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "can't close file"); + HGOTO_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "can't close file") } } @@ -4561,7 +4550,6 @@ H5O_copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, H5O_t *oh_src = NULL; /* Object header for source object */ H5O_t *oh_dst = NULL; /* Object header for destination object */ unsigned chunkno = 0, mesgno = 0; - size_t hdr_size; haddr_t addr_new = HADDR_UNDEF; H5O_mesg_t *mesg_src; /* Message in source object header */ H5O_mesg_t *mesg_dst; /* Message in source object header */ @@ -4595,9 +4583,6 @@ H5O_copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, if(H5O_flush_msgs(oloc_src->file, oh_src) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTFLUSH, FAIL, "unable to flush object header messages") - /* get the size of the file header of the destination file */ - hdr_size = H5O_SIZEOF_HDR(oloc_dst->file); - /* Allocate the destination object header and fill in header fields */ if(NULL == (oh_dst = H5FL_MALLOC(H5O_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") @@ -4622,6 +4607,11 @@ H5O_copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, /* '0th' chunk is preceded by object header prefix */ if(0 == chunkno) { + size_t hdr_size; + + /* get the size of the file header of the destination file */ + hdr_size = H5O_SIZEOF_HDR(oloc_dst->file); + /* Allocate file space for the first chunk & object header prefix */ if(HADDR_UNDEF == (addr_new = H5MF_alloc(oloc_dst->file, H5FD_MEM_OHDR, dxpl_id, (hsize_t)hdr_size + chunk_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "file allocation failed for object header") @@ -5242,7 +5232,7 @@ H5O_debug_id(unsigned type_id, H5F_t *f, hid_t dxpl_id, const void *mesg, FILE * /* Call the debug method in the class */ if ((ret_value = (type->debug)(f, dxpl_id, mesg, stream, indent, fwidth)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_BADTYPE, FAIL, "unable to debug message"); + HGOTO_ERROR(H5E_OHDR, H5E_BADTYPE, FAIL, "unable to debug message") done: FUNC_LEAVE_NOAPI(ret_value); @@ -5289,21 +5279,21 @@ H5O_debug_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh, haddr_t addr, FILE *stream, i HDfprintf(stream, "%*s%-*s %d\n", indent, "", fwidth, "Dirty:", (int) (oh->cache_info.is_dirty)); - HDfprintf(stream, "%*s%-*s %d\n", indent, "", fwidth, + HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Version:", - (int) (oh->version)); + oh->version); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Header size (in bytes):", (unsigned) H5O_SIZEOF_HDR(f)); HDfprintf(stream, "%*s%-*s %d\n", indent, "", fwidth, "Number of links:", - (int) (oh->nlink)); - HDfprintf(stream, "%*s%-*s %u (%u)\n", indent, "", fwidth, + oh->nlink); + HDfprintf(stream, "%*s%-*s %Zu (%Zu)\n", indent, "", fwidth, "Number of messages (allocated):", - (unsigned) (oh->nmesgs), (unsigned) (oh->alloc_nmesgs)); - HDfprintf(stream, "%*s%-*s %u (%u)\n", indent, "", fwidth, + oh->nmesgs, oh->alloc_nmesgs); + HDfprintf(stream, "%*s%-*s %Zu (%Zu)\n", indent, "", fwidth, "Number of chunks (allocated):", - (unsigned) (oh->nchunks), (unsigned) (oh->alloc_nchunks)); + oh->nchunks, oh->alloc_nchunks); /* debug each chunk */ for (i=0, chunk_total=0; i < oh->nchunks; i++) { @@ -5327,7 +5317,7 @@ H5O_debug_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh, haddr_t addr, FILE *stream, i /* debug each message */ if (NULL==(sequence = H5MM_calloc(NELMTS(H5O_msg_class_g)*sizeof(int)))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") for (i=0, mesg_total=0; i < oh->nmesgs; i++) { mesg_total += H5O_SIZEOF_MSGHDR(f) + oh->mesg[i].raw_size; HDfprintf(stream, "%*sMessage %d...\n", indent, "", i); diff --git a/src/H5Oattr.c b/src/H5Oattr.c index 24e4769..02299d4 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -29,19 +29,19 @@ #include "H5Spkg.h" /* Dataspaces */ /* PRIVATE PROTOTYPES */ -static herr_t H5O_attr_encode (H5F_t *f, uint8_t *p, const void *mesg); -static void *H5O_attr_decode (H5F_t *f, hid_t dxpl_id, const uint8_t *p); -static void *H5O_attr_copy (const void *_mesg, void *_dest, unsigned update_flags); -static size_t H5O_attr_size (const H5F_t *f, const void *_mesg); -static herr_t H5O_attr_reset (void *_mesg); -static herr_t H5O_attr_free (void *mesg); -static herr_t H5O_attr_delete (H5F_t *f, hid_t dxpl_id, const void *_mesg, hbool_t adj_link); +static herr_t H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg); +static void *H5O_attr_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p); +static void *H5O_attr_copy(const void *_mesg, void *_dest, unsigned update_flags); +static size_t H5O_attr_size(const H5F_t *f, const void *_mesg); +static herr_t H5O_attr_reset(void *_mesg); +static herr_t H5O_attr_free(void *mesg); +static herr_t H5O_attr_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg, hbool_t adj_link); static herr_t H5O_attr_link(H5F_t *f, hid_t dxpl_id, const void *_mesg); static herr_t H5O_attr_pre_copy_file(H5F_t *file_src, const H5O_msg_class_t *type, void *mesg_src, hbool_t *deleted, const H5O_copy_t *cpy_info, void *udata); static void *H5O_attr_copy_file(H5F_t *file_src, void *native_src, H5F_t *file_dst, hid_t dxpl_id, H5O_copy_t *cpy_info, void *udata); -static herr_t H5O_attr_debug (H5F_t *f, hid_t dxpl_id, const void *_mesg, +static herr_t H5O_attr_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int indent, int fwidth); /* This message derives from H5O message class */ @@ -331,16 +331,15 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg) * Also add several "reserved" fields to pad to 16 bytes. */ if(version >= H5O_ATTR_VERSION_3) - *p++ = attr->encoding; + *p++ = attr->encoding; - /* - * Write the name including null terminator padded to the correct number - * of bytes. - */ + /* Write the name including null terminator */ HDmemcpy(p, attr->name, name_len); - HDmemset(p + name_len, 0, H5O_ALIGN(name_len) - name_len); - if(version < H5O_ATTR_VERSION_2) + if(version < H5O_ATTR_VERSION_2) { + /* Pad to the correct number of bytes */ + HDmemset(p + name_len, 0, H5O_ALIGN(name_len) - name_len); p += H5O_ALIGN(name_len); + } /* end if */ else p += name_len; diff --git a/src/H5Ocache.c b/src/H5Ocache.c index 23f714a..7970e70 100644 --- a/src/H5Ocache.c +++ b/src/H5Ocache.c @@ -40,7 +40,7 @@ static H5O_t *H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_udata void *_udata2); static herr_t H5O_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5O_t *oh); static herr_t H5O_clear(H5F_t *f, H5O_t *oh, hbool_t destroy); -static herr_t H5O_compute_size(const H5F_t *f, const H5O_t *oh, size_t *size_ptr); +static herr_t H5O_size(const H5F_t *f, const H5O_t *oh, size_t *size_ptr); /* H5O inherits cache-like properties from H5AC */ const H5AC_class_t H5AC_OHDR[1] = {{ @@ -49,7 +49,7 @@ const H5AC_class_t H5AC_OHDR[1] = {{ (H5AC_flush_func_t)H5O_flush, (H5AC_dest_func_t)H5O_dest, (H5AC_clear_func_t)H5O_clear, - (H5AC_size_func_t)H5O_compute_size, + (H5AC_size_func_t)H5O_size, }}; @@ -89,7 +89,7 @@ H5O_flush_msgs(H5F_t *f, H5O_t *oh) id = curr_msg->type->id; UINT16ENCODE(p, id); - HDassert(curr_msg->raw_size < H5O_MAX_SIZE); + HDassert(curr_msg->raw_size < H5O_MESG_MAX_SIZE); UINT16ENCODE(p, curr_msg->raw_size); *p++ = curr_msg->flags; *p++ = 0; /*reserved*/ @@ -181,19 +181,19 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * _udata1, /* allocate ohdr and init chunk list */ if (NULL==(oh = H5FL_CALLOC(H5O_t))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - /* read fixed-lenth part of object header */ + /* read fixed-length part of object header */ hdr_size = H5O_SIZEOF_HDR(f); assert(hdr_size<=sizeof(buf)); if (H5F_block_read(f, H5FD_MEM_OHDR, addr, hdr_size, dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL, "unable to read object header"); + HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL, "unable to read object header") p = buf; /* decode version */ oh->version = *p++; if (H5O_VERSION != oh->version) - HGOTO_ERROR(H5E_OHDR, H5E_VERSION, NULL, "bad object header version number"); + HGOTO_ERROR(H5E_OHDR, H5E_VERSION, NULL, "bad object header version number") /* reserved */ p++; @@ -210,8 +210,8 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * _udata1, /* build the message array */ oh->alloc_nmesgs = nmesgs; - if (NULL==(oh->mesg=H5FL_SEQ_CALLOC(H5O_mesg_t,(size_t)oh->alloc_nmesgs))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); + if (NULL==(oh->mesg=H5FL_SEQ_MALLOC(H5O_mesg_t,(size_t)oh->alloc_nmesgs))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* read each chunk from disk */ while(H5F_addr_defined(chunk_addr)) { @@ -221,7 +221,7 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * _udata1, H5O_chunk_t *x = H5FL_SEQ_REALLOC (H5O_chunk_t, oh->chunk, (size_t)na); if(!x) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") oh->alloc_nchunks = na; oh->chunk = x; } /* end if */ @@ -232,9 +232,9 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * _udata1, oh->chunk[chunkno].addr = chunk_addr; oh->chunk[chunkno].size = chunk_size; if(NULL==(oh->chunk[chunkno].image = H5FL_BLK_MALLOC(chunk_image, chunk_size))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") if(H5F_block_read(f, H5FD_MEM_OHDR, chunk_addr, chunk_size, dxpl_id, oh->chunk[chunkno].image) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL, "unable to read object header data"); + HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL, "unable to read object header data") /* load messages from this chunk */ for(p = oh->chunk[chunkno].image; p < oh->chunk[chunkno].image + chunk_size; p += mesg_size) { @@ -267,7 +267,7 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * _udata1, } else { /* new message */ if (oh->nmesgs >= nmesgs) - HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "corrupt object header - too many messages"); + 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]; oh->mesg[mesgno].dirty = FALSE; @@ -369,14 +369,13 @@ 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(f)-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(f)) == oh->chunk[0].addr) combine = TRUE; - } /* end if */ else { if(H5F_block_write(f, H5FD_MEM_OHDR, addr, (size_t)H5O_SIZEOF_HDR(f), dxpl_id, buf) < 0) HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "unable to write object header hdr to disk") @@ -388,7 +387,7 @@ 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(f) + oh->chunk[u].size))) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* Copy in the prefix */ @@ -516,7 +515,7 @@ H5O_clear(H5F_t *f, H5O_t *oh, hbool_t destroy) if (destroy) if (H5O_dest(f, oh) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTFREE, FAIL, "unable to destroy object header data"); + HGOTO_ERROR(H5E_OHDR, H5E_CANTFREE, FAIL, "unable to destroy object header data") done: FUNC_LEAVE_NOAPI(ret_value); @@ -524,18 +523,12 @@ done: /*------------------------------------------------------------------------- - * Function: H5O_compute_size + * Function: H5O_size * * Purpose: Compute the size in bytes of the specified instance of * H5O_t on disk, and return it in *len_ptr. On failure, * the value of *len_ptr is undefined. * - * The value returned will probably be low unless the object - * has just been flushed, as we simply total up the size of - * the header with the sizes of the chunks. Thus any message - * that has been added since the last flush will not be - * reflected in the total. - * * Return: Non-negative on success/Negative on failure * * Programmer: John Mainzer @@ -544,27 +537,27 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5O_compute_size(const H5F_t *f, const H5O_t *oh, size_t *size_ptr) +H5O_size(const H5F_t *f, const H5O_t *oh, size_t *size_ptr) { - unsigned u; - size_t size; + size_t size; /* Running sum of the object header's size */ + unsigned u; /* Local index variable */ - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_compute_size); + 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); - for (u = 0; u < oh->nchunks; u++) + /* Add sizes of all the chunks */ + for(u = 0; u < oh->nchunks; u++) size += oh->chunk[u].size; - HDassert(size >= H5O_SIZEOF_HDR(f)); - *size_ptr = size; - FUNC_LEAVE_NOAPI(SUCCEED); -} /* H5O_compute_size() */ + FUNC_LEAVE_NOAPI(SUCCEED) +} /* H5O_size() */ diff --git a/src/H5Opkg.h b/src/H5Opkg.h index 56353ed..62dc8ed 100644 --- a/src/H5Opkg.h +++ b/src/H5Opkg.h @@ -34,7 +34,7 @@ #define H5O_ALIGN(X) (8*(((X)+8-1)/8)) /* Object header macros */ -#define H5O_NMESGS 32 /*initial number of messages */ +#define H5O_NMESGS 8 /*initial number of messages */ #define H5O_NCHUNKS 2 /*initial number of chunks */ /* Version of object header structure */ @@ -45,7 +45,7 @@ */ #define H5O_SIZEOF_HDR(F) \ H5O_ALIGN(1 + /*version number */ \ - 1 + /*alignment */ \ + 1 + /*reserved */ \ 2 + /*number of messages */ \ 4 + /*reference count */ \ 4) /*header data size */ diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h index fd226f1..2912ff1 100644 --- a/src/H5Oprivate.h +++ b/src/H5Oprivate.h @@ -46,8 +46,7 @@ typedef struct H5O_msg_class_t H5O_msg_class_t; typedef struct H5O_t H5O_t; /* Object header macros */ -#define H5O_MIN_SIZE H5O_ALIGN(32) /*min obj header data size */ -#define H5O_MAX_SIZE 65536 /*max obj header data size */ +#define H5O_MESG_MAX_SIZE 65536 /*max obj header message size */ #define H5O_NEW_MESG (-1) /*new message */ #define H5O_ALL (-1) /* Operate on all messages of type */ #define H5O_FIRST (-2) /* Operate on first message of type */ |