diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2006-10-16 14:46:00 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2006-10-16 14:46:00 (GMT) |
commit | 9848ea0387c08ecffa4e97c5d880b4253e059dbc (patch) | |
tree | 4a4f3ca1e5e9a8893b9b52e2b8fc30f0685152f0 | |
parent | 10e8a68a0c380cc58d831e95271ccc8ce658ad20 (diff) | |
download | hdf5-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
-rw-r--r-- | src/H5O.c | 527 | ||||
-rw-r--r-- | src/H5Oattr.c | 24 | ||||
-rw-r--r-- | src/H5Ocache.c | 86 | ||||
-rw-r--r-- | src/H5Odtype.c | 102 | ||||
-rw-r--r-- | src/H5Opkg.h | 89 | ||||
-rw-r--r-- | src/H5Opline.c | 4 | ||||
-rw-r--r-- | tools/misc/h5debug.c | 2 |
7 files changed, 445 insertions, 389 deletions
@@ -23,10 +23,16 @@ *------------------------------------------------------------------------- */ +/****************/ +/* Module Setup */ +/****************/ + #define H5F_PACKAGE /*suppress error about including H5Fpkg */ #define H5O_PACKAGE /*suppress error about including H5Opkg */ - +/***********/ +/* Headers */ +/***********/ #include "H5private.h" /* Generic Functions */ #include "H5Dprivate.h" /* Datasets */ #include "H5Eprivate.h" /* Error handling */ @@ -43,7 +49,10 @@ #include <sys/time.h> #endif /* H5_HAVE_GETTIMEOFDAY */ -/* Local macros */ +/****************/ +/* Local Macros */ +/****************/ + #define H5O_MIN_SIZE 32 /*min obj header data size */ /* Load native information for a message, if it's not already present */ @@ -64,7 +73,10 @@ HGOTO_ERROR(H5E_OHDR, H5E_CANTDECODE, ERR, "unable to decode message") \ } /* end if */ -/* Private typedefs */ + +/******************/ +/* Local Typedefs */ +/******************/ /* User data for iteration while removing a message */ typedef struct { @@ -106,7 +118,71 @@ typedef struct H5O_addr_map_t { hsize_t inc_ref_count; /* Number of deferred increments to reference count */ } H5O_addr_map_t; -/* Package variables */ + +/********************/ +/* Package Typedefs */ +/********************/ + + +/********************/ +/* Local Prototypes */ +/********************/ + +static hid_t H5O_open_by_loc(H5G_loc_t *obj_loc, hid_t dxpl_id); +static H5O_loc_t * H5O_get_oloc(hid_t id); +static herr_t H5O_new(H5F_t *f, hid_t dxpl_id, size_t size_hint, + H5O_loc_t *loc/*out*/, haddr_t header); +static herr_t H5O_reset_real(const H5O_msg_class_t *type, void *native); +static void * H5O_copy_real(const H5O_msg_class_t *type, const void *mesg, + void *dst); +static int H5O_count_real(H5O_loc_t *loc, const H5O_msg_class_t *type, + hid_t dxpl_id); +static unsigned H5O_find_in_ohdr(H5F_t *f, hid_t dxpl_id, H5O_t *oh, + const H5O_msg_class_t **type_p, int sequence); +static int H5O_modify_real(H5O_loc_t *loc, const H5O_msg_class_t *type, + int overwrite, unsigned flags, unsigned update_flags, const void *mesg, + hid_t dxpl_id); +static int H5O_append_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh, + const H5O_msg_class_t *type, unsigned flags, const void *mesg, + unsigned * oh_flags_ptr); +static herr_t H5O_remove_real(const H5O_loc_t *loc, const H5O_msg_class_t *type, + int sequence, H5O_operator_t op, void *op_data, hbool_t adj_link, hid_t dxpl_id); +static unsigned H5O_alloc(H5F_t *f, hid_t dxpl_id, H5O_t *oh, + const H5O_msg_class_t *type, size_t size, hbool_t * oh_dirtied_ptr); +static herr_t H5O_alloc_msgs(H5O_t *oh, size_t min_alloc); +static htri_t H5O_move_msgs_forward(H5F_t *f, H5O_t *oh, hid_t dxpl_id); +static htri_t H5O_merge_null(H5O_t *oh); +static htri_t H5O_remove_empty_chunks(H5F_t *f, H5O_t *oh, hid_t dxpl_id); +static herr_t H5O_condense_header(H5F_t *f, H5O_t *oh, hid_t dxpl_id); +static htri_t H5O_alloc_extend_chunk(H5F_t *f, H5O_t *oh, + unsigned chunkno, size_t size, unsigned * msg_idx); +static unsigned H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, + size_t size); +static herr_t H5O_delete_oh(H5F_t *f, hid_t dxpl_id, H5O_t *oh); +static herr_t H5O_delete_mesg(H5F_t *f, hid_t dxpl_id, H5O_mesg_t *mesg, + hbool_t adj_link); +static unsigned H5O_new_mesg(H5F_t *f, H5O_t *oh, unsigned *flags, + const H5O_msg_class_t *orig_type, const void *orig_mesg, H5O_shared_t *sh_mesg, + const H5O_msg_class_t **new_type, const void **new_mesg, hid_t dxpl_id, + unsigned * oh_flags_ptr); +static herr_t H5O_write_mesg(H5O_t *oh, unsigned idx, const H5O_msg_class_t *type, + const void *mesg, unsigned flags, unsigned update_flags, + unsigned * oh_flags_ptr); +static herr_t H5O_iterate_real(const H5O_loc_t *loc, const H5O_msg_class_t *type, + H5AC_protect_t prot, hbool_t internal, H5O_mesg_operator_t op, void *op_data, hid_t dxpl_id); +static H5G_obj_t H5O_obj_type_real(H5O_t *oh); +static const H5O_obj_class_t *H5O_obj_class(H5O_t *oh); +static void * H5O_copy_mesg_file(const H5O_msg_class_t *type, H5F_t *file_src, void *mesg_src, + H5F_t *file_dst, hid_t dxpl_id, H5O_copy_t *cpy_info, void *udata); +static herr_t H5O_copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, + hid_t dxpl_id, H5O_copy_t *cpy_info); +static herr_t H5O_copy_free_addrmap_cb(void *item, void *key, void *op_data); +static herr_t H5O_copy_obj_by_ref(H5O_loc_t *src_oloc, hid_t dxpl_id, + H5O_loc_t *dst_oloc, H5G_loc_t *dst_root_loc, H5O_copy_t *cpy_info); + +/*********************/ +/* Package Variables */ +/*********************/ /* Header message ID to class mapping */ const H5O_msg_class_t *const H5O_msg_class_g[] = { @@ -159,9 +235,14 @@ H5FL_SEQ_DEFINE(H5O_chunk_t); /* Declare a free list to manage the chunk image information */ H5FL_BLK_DEFINE(chunk_image); -/* Library private variables */ +/*****************************/ +/* Library Private Variables */ +/*****************************/ + -/* Local variables */ +/*******************/ +/* Local Variables */ +/*******************/ /* Declare external the free list for time_t's */ H5FL_EXTERN(time_t); @@ -172,62 +253,6 @@ H5FL_EXTERN(H5O_cont_t); /* Declare a free list to manage the H5O_addr_map_t struct */ H5FL_DEFINE_STATIC(H5O_addr_map_t); -/* PRIVATE PROTOTYPES */ -static hid_t H5O_open_by_loc(H5G_loc_t *obj_loc, hid_t dxpl_id); -static H5O_loc_t * H5O_get_oloc(hid_t id); -static herr_t H5O_new(H5F_t *f, hid_t dxpl_id, size_t size_hint, - H5O_loc_t *loc/*out*/, haddr_t header); -static herr_t H5O_reset_real(const H5O_msg_class_t *type, void *native); -static void * H5O_copy_real(const H5O_msg_class_t *type, const void *mesg, - void *dst); -static int H5O_count_real(H5O_loc_t *loc, const H5O_msg_class_t *type, - hid_t dxpl_id); -#ifdef NOT_YET -static herr_t H5O_share(H5F_t *f, hid_t dxpl_id, const H5O_msg_class_t *type, const void *mesg, - H5HG_t *hobj/*out*/); -#endif /* NOT_YET */ -static unsigned H5O_find_in_ohdr(H5F_t *f, hid_t dxpl_id, H5O_t *oh, - const H5O_msg_class_t **type_p, int sequence); -static int H5O_modify_real(H5O_loc_t *loc, const H5O_msg_class_t *type, - int overwrite, unsigned flags, unsigned update_flags, const void *mesg, - hid_t dxpl_id); -static int H5O_append_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh, - const H5O_msg_class_t *type, unsigned flags, const void *mesg, - unsigned * oh_flags_ptr); -static herr_t H5O_remove_real(const H5O_loc_t *loc, const H5O_msg_class_t *type, - int sequence, H5O_operator_t op, void *op_data, hbool_t adj_link, hid_t dxpl_id); -static unsigned H5O_alloc(H5F_t *f, hid_t dxpl_id, H5O_t *oh, - const H5O_msg_class_t *type, size_t size, hbool_t * oh_dirtied_ptr); -static herr_t H5O_alloc_msgs(H5O_t *oh, size_t min_alloc); -static htri_t H5O_move_msgs_forward(H5F_t *f, H5O_t *oh, hid_t dxpl_id); -static htri_t H5O_merge_null(H5F_t *f, H5O_t *oh); -static htri_t H5O_remove_empty_chunks(H5F_t *f, H5O_t *oh, hid_t dxpl_id); -static herr_t H5O_condense_header(H5F_t *f, H5O_t *oh, hid_t dxpl_id); -static htri_t H5O_alloc_extend_chunk(H5F_t *f, H5O_t *oh, - unsigned chunkno, size_t size, unsigned * msg_idx); -static unsigned H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, - size_t size); -static herr_t H5O_delete_oh(H5F_t *f, hid_t dxpl_id, H5O_t *oh); -static herr_t H5O_delete_mesg(H5F_t *f, hid_t dxpl_id, H5O_mesg_t *mesg, - hbool_t adj_link); -static unsigned H5O_new_mesg(H5F_t *f, H5O_t *oh, unsigned *flags, - const H5O_msg_class_t *orig_type, const void *orig_mesg, H5O_shared_t *sh_mesg, - const H5O_msg_class_t **new_type, const void **new_mesg, hid_t dxpl_id, - unsigned * oh_flags_ptr); -static herr_t H5O_write_mesg(H5O_t *oh, unsigned idx, const H5O_msg_class_t *type, - const void *mesg, unsigned flags, unsigned update_flags, - unsigned * oh_flags_ptr); -static herr_t H5O_iterate_real(const H5O_loc_t *loc, const H5O_msg_class_t *type, - H5AC_protect_t prot, hbool_t internal, H5O_mesg_operator_t op, void *op_data, hid_t dxpl_id); -static H5G_obj_t H5O_obj_type_real(H5O_t *oh); -static const H5O_obj_class_t *H5O_obj_class(H5O_t *oh); -static void * H5O_copy_mesg_file(const H5O_msg_class_t *type, H5F_t *file_src, void *mesg_src, - H5F_t *file_dst, hid_t dxpl_id, H5O_copy_t *cpy_info, void *udata); -static herr_t H5O_copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, - hid_t dxpl_id, H5O_copy_t *cpy_info); -static herr_t H5O_copy_free_addrmap_cb(void *item, void *key, void *op_data); -static herr_t H5O_copy_obj_by_ref(H5O_loc_t *src_oloc, hid_t dxpl_id, - H5O_loc_t *dst_oloc, H5G_loc_t *dst_root_loc, H5O_copy_t *cpy_info); /*------------------------------------------------------------------------- @@ -664,11 +689,11 @@ H5O_create(H5F_t *f, hid_t dxpl_id, size_t size_hint, H5O_loc_t *loc/*out*/) 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)); + size_hint = H5O_ALIGN_F(f, MAX(H5O_MIN_SIZE, size_hint)); /* allocate disk space for header and first chunk */ if(HADDR_UNDEF == (header = H5MF_alloc(f, H5FD_MEM_OHDR, dxpl_id, - (hsize_t)H5O_SIZEOF_HDR(f) + size_hint))) + (hsize_t)H5O_SIZEOF_HDR_F(f) + size_hint))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "file allocation failed for object header header") /* initialize the object header */ @@ -718,7 +743,7 @@ H5O_new(H5F_t *f, hid_t dxpl_id, size_t size_hint, H5O_loc_t *loc/*out*/, if(NULL == (oh = H5FL_MALLOC(H5O_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") - oh->version = H5O_VERSION; + oh->version = H5O_VERSION_1; oh->nlink = 0; /* create the chunk list and initialize the first chunk */ @@ -729,7 +754,7 @@ H5O_new(H5F_t *f, hid_t dxpl_id, size_t size_hint, H5O_loc_t *loc/*out*/, HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") oh->chunk[0].dirty = TRUE; - oh->chunk[0].addr = loc->addr + (hsize_t)H5O_SIZEOF_HDR(f); + oh->chunk[0].addr = loc->addr + (hsize_t)H5O_SIZEOF_HDR_OH(oh); oh->chunk[0].size = size_hint; if(NULL == (oh->chunk[0].image = H5FL_BLK_CALLOC(chunk_image, size_hint))) @@ -745,8 +770,8 @@ H5O_new(H5F_t *f, hid_t dxpl_id, size_t size_hint, H5O_loc_t *loc/*out*/, oh->mesg[0].type = H5O_MSG_NULL; oh->mesg[0].dirty = TRUE; oh->mesg[0].native = NULL; - oh->mesg[0].raw = oh->chunk[0].image + H5O_SIZEOF_MSGHDR(f); - oh->mesg[0].raw_size = size_hint - H5O_SIZEOF_MSGHDR(f); + oh->mesg[0].raw = oh->chunk[0].image + H5O_SIZEOF_MSGHDR_OH(oh); + oh->mesg[0].raw_size = size_hint - H5O_SIZEOF_MSGHDR_OH(oh); oh->mesg[0].chunkno = 0; /* cache it */ @@ -1705,9 +1730,11 @@ H5O_modify_real(H5O_loc_t *loc, const H5O_msg_class_t *type, int overwrite, HDassert(mesg); HDassert(0 == (flags & ~H5O_FLAG_BITS)); + /* Check for write access on the file */ if(0 == (loc->file->intent & H5F_ACC_RDWR)) HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "no write intent on file") + /* Protect the object header */ if(NULL == (oh = H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_WRITE))) HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "unable to load object header") @@ -1865,24 +1892,24 @@ H5O_append(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned type_id, unsigned flags, const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ int ret_value; /* Return value */ - FUNC_ENTER_NOAPI(H5O_append,FAIL); + FUNC_ENTER_NOAPI(H5O_append, FAIL) /* check args */ - assert(f); - assert(oh); - assert(type_id < NELMTS(H5O_msg_class_g)); - type=H5O_msg_class_g[type_id]; /* map the type ID to the actual type object */ - assert(type); - assert(0==(flags & ~H5O_FLAG_BITS)); - assert(mesg); - assert(oh_flags_ptr); + HDassert(f); + HDassert(oh); + HDassert(type_id < NELMTS(H5O_msg_class_g)); + type = H5O_msg_class_g[type_id]; /* map the type ID to the actual type object */ + HDassert(type); + HDassert(0 == (flags & ~H5O_FLAG_BITS)); + HDassert(mesg); + HDassert(oh_flags_ptr); /* Call the "real" append routine */ - if((ret_value=H5O_append_real( f, dxpl_id, oh, type, flags, mesg, oh_flags_ptr)) < 0) + 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") done: - FUNC_LEAVE_NOAPI(ret_value); + FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_append() */ @@ -1909,31 +1936,31 @@ H5O_append_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh, const H5O_msg_class_t *type, { unsigned idx; /* Index of message to modify */ H5O_shared_t sh_mesg; - int ret_value = FAIL; + int ret_value; - FUNC_ENTER_NOAPI_NOINIT(H5O_append_real); + FUNC_ENTER_NOAPI_NOINIT(H5O_append_real) /* check args */ - assert(f); - assert(oh); - assert(type); - assert(0==(flags & ~H5O_FLAG_BITS)); - assert(mesg); - assert(oh_flags_ptr); + HDassert(f); + HDassert(oh); + HDassert(type); + HDassert(0 == (flags & ~H5O_FLAG_BITS)); + HDassert(mesg); + HDassert(oh_flags_ptr); /* Create a new message */ - if((idx=H5O_new_mesg(f,oh,&flags,type,mesg,&sh_mesg,&type,&mesg,dxpl_id,oh_flags_ptr))==UFAIL) + 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") /* Write the information to the message */ - if(H5O_write_mesg(oh,idx,type,mesg,flags,0,oh_flags_ptr) < 0) + 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") /* Set return value */ ret_value = idx; done: - FUNC_LEAVE_NOAPI(ret_value); + FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_append_real () */ @@ -1956,47 +1983,47 @@ H5O_new_mesg(H5F_t *f, H5O_t *oh, unsigned *flags, const H5O_msg_class_t *orig_t const void **new_mesg, hid_t dxpl_id, unsigned * oh_flags_ptr) { size_t size; /* Size of space allocated for object header */ - unsigned ret_value=UFAIL; /* Return value */ + unsigned ret_value = UFAIL; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5O_new_mesg); + FUNC_ENTER_NOAPI_NOINIT(H5O_new_mesg) /* check args */ - assert(f); - assert(oh); - assert(flags); - assert(orig_type); - assert(orig_mesg); - assert(sh_mesg); - assert(new_mesg); - assert(new_type); - assert(oh_flags_ptr); + HDassert(f); + HDassert(oh); + HDassert(flags); + HDassert(orig_type); + HDassert(orig_mesg); + HDassert(sh_mesg); + HDassert(new_mesg); + HDassert(new_type); + HDassert(oh_flags_ptr); /* Check for shared message */ - if (*flags & H5O_FLAG_SHARED) { - HDmemset(sh_mesg,0,sizeof(H5O_shared_t)); + if(*flags & H5O_FLAG_SHARED) { + HDmemset(sh_mesg, 0, sizeof(H5O_shared_t)); - if (NULL==orig_type->get_share) + if(NULL == orig_type->get_share) 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((orig_type->get_share)(f, orig_mesg, sh_mesg/*out*/) < 0) { /* * If the message isn't shared then turn off the shared bit * and treat it as an unshared message. */ - H5E_clear_stack (NULL); + H5E_clear_stack(NULL); *flags &= ~H5O_FLAG_SHARED; } else { /* Change type & message to use shared information */ - *new_type=H5O_MSG_SHARED; - *new_mesg=sh_mesg; + *new_type = H5O_MSG_SHARED; + *new_mesg = sh_mesg; } /* end else */ } /* end if */ else { - *new_type=orig_type; - *new_mesg=orig_mesg; + *new_type = orig_type; + *new_mesg = orig_mesg; } /* end else */ /* Compute the size needed to store the message on disk */ - if((size = ((*new_type)->raw_size)(f, *new_mesg)) >=H5O_MESG_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 */ @@ -2004,11 +2031,11 @@ H5O_new_mesg(H5F_t *f, H5O_t *oh, unsigned *flags, const H5O_msg_class_t *orig_t 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) + 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") done: - FUNC_LEAVE_NOAPI(ret_value); + FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_new_mesg() */ @@ -2081,21 +2108,19 @@ H5O_touch_oh(H5F_t *f, hbool_t force, unsigned * oh_flags_ptr) { - unsigned idx; - time_t now; - size_t size; - herr_t ret_value=SUCCEED; /* Return value */ + time_t now; /* Current time */ + unsigned idx; /* Index of modification time message to update */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5O_touch_oh); + FUNC_ENTER_NOAPI_NOINIT(H5O_touch_oh) - assert(oh); - assert(oh_flags_ptr); + HDassert(oh); + HDassert(oh_flags_ptr); /* Look for existing message */ - for (idx=0; idx < oh->nmesgs; idx++) { - if (H5O_MSG_MTIME==oh->mesg[idx].type || H5O_MSG_MTIME_NEW==oh->mesg[idx].type) + for(idx = 0; idx < oh->nmesgs; idx++) + if(H5O_MSG_MTIME == oh->mesg[idx].type || H5O_MSG_MTIME_NEW == oh->mesg[idx].type) break; - } #ifdef H5_HAVE_GETTIMEOFDAY { @@ -2108,28 +2133,35 @@ H5O_touch_oh(H5F_t *f, now = HDtime(NULL); #endif /* H5_HAVE_GETTIMEOFDAY */ - /* Create a new message */ + /* Create a new message, if necessary */ if(idx == oh->nmesgs) { + size_t size; /* New modification time message size */ + + /* If we have to create a new message, but we aren't 'forcing' it, get out now */ if(!force) - HGOTO_DONE(SUCCEED); /*nothing to do*/ - size = (H5O_MSG_MTIME_NEW->raw_size)(f, &now); + HGOTO_DONE(SUCCEED); /*nothing to do*/ + 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") } /* end if */ - /* Update the native part */ - if(NULL==oh->mesg[idx].native) { - if(NULL==(oh->mesg[idx].native = H5FL_MALLOC(time_t))) + /* Allocate 'native' space, if necessary */ + 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") - } + } /* end if */ + + /* Update the message */ *((time_t*)(oh->mesg[idx].native)) = now; + + /* Mark the message & object header as dirty */ oh->mesg[idx].dirty = TRUE; *oh_flags_ptr |= H5AC__DIRTIED_FLAG; done: - FUNC_LEAVE_NOAPI(ret_value); -} + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_touch_oh() */ /*------------------------------------------------------------------------- @@ -2619,7 +2651,7 @@ H5O_move_msgs_forward(H5F_t *f, H5O_t *oh, hid_t dxpl_id) for(v = 0, nonnull_msg = &oh->mesg[0]; v < oh->nmesgs; v++, nonnull_msg++) { /* Locate message that is immediately after the null message */ if((curr_msg->chunkno == nonnull_msg->chunkno) && - ((curr_msg->raw + curr_msg->raw_size) == (nonnull_msg->raw - H5O_SIZEOF_MSGHDR(f)))) { + ((curr_msg->raw + curr_msg->raw_size) == (nonnull_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh)))) { /* Don't swap messages if the second message is also a null message */ /* (We'll merge them together later, in another routine) */ if(H5O_NULL_ID != nonnull_msg->type->id) { @@ -2632,7 +2664,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_OH(oh); /* Mark messages dirty */ curr_msg->dirty = TRUE; @@ -2702,8 +2734,8 @@ H5O_move_msgs_forward(H5F_t *f, H5O_t *oh, hid_t dxpl_id) curr_msg->dirty = TRUE; /* Adjust null message's size & offset */ - null_msg->raw += curr_msg->raw_size + H5O_SIZEOF_MSGHDR(f); - null_msg->raw_size -= curr_msg->raw_size + H5O_SIZEOF_MSGHDR(f); + null_msg->raw += curr_msg->raw_size + H5O_SIZEOF_MSGHDR_OH(oh); + null_msg->raw_size -= curr_msg->raw_size + H5O_SIZEOF_MSGHDR_OH(oh); /* Mark null message dirty */ null_msg->dirty = TRUE; @@ -2772,7 +2804,7 @@ done: *------------------------------------------------------------------------- */ static htri_t -H5O_merge_null(H5F_t *f, H5O_t *oh) +H5O_merge_null(H5O_t *oh) { hbool_t merged_msg; /* Flag to indicate that messages were merged */ hbool_t did_merging = FALSE; /* Whether any messages were merged */ @@ -2805,18 +2837,18 @@ H5O_merge_null(H5F_t *f, H5O_t *oh) if(u != v && H5O_NULL_ID == curr_msg2->type->id && curr_msg->chunkno == curr_msg2->chunkno) { /* Check for second message after first message */ - if((curr_msg->raw + curr_msg->raw_size) == (curr_msg2->raw - H5O_SIZEOF_MSGHDR(f))) { + if((curr_msg->raw + curr_msg->raw_size) == (curr_msg2->raw - H5O_SIZEOF_MSGHDR_OH(oh))) { /* Extend first null message length to cover second null message */ - curr_msg->raw_size += (H5O_SIZEOF_MSGHDR(f) + curr_msg2->raw_size); + curr_msg->raw_size += (H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg2->raw_size); /* Message has been merged */ merged_msg = TRUE; } /* end if */ /* Check for second message befre first message */ - else if((curr_msg->raw - H5O_SIZEOF_MSGHDR(f)) == (curr_msg2->raw + curr_msg2->raw_size)) { + else if((curr_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh)) == (curr_msg2->raw + curr_msg2->raw_size)) { /* Adjust first message address and extend length to cover second message */ - curr_msg->raw -= (H5O_SIZEOF_MSGHDR(f) + curr_msg2->raw_size); - curr_msg->raw_size += (H5O_SIZEOF_MSGHDR(f) + curr_msg2->raw_size); + curr_msg->raw -= (H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg2->raw_size); + curr_msg->raw_size += (H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg2->raw_size); /* Message has been merged */ merged_msg = TRUE; @@ -2907,7 +2939,7 @@ H5O_remove_empty_chunks(H5F_t *f, H5O_t *oh, hid_t dxpl_id) * its not the "base" chunk), delete that chunk from object header */ if(H5O_NULL_ID == null_msg->type->id && null_msg->chunkno > 0 && - (H5O_SIZEOF_MSGHDR(f) + null_msg->raw_size) == oh->chunk[null_msg->chunkno].size) { + (H5O_SIZEOF_MSGHDR_OH(oh) + null_msg->raw_size) == oh->chunk[null_msg->chunkno].size) { H5O_mesg_t *curr_msg; /* Pointer to current message to operate on */ unsigned null_msg_no; /* Message # for null message */ unsigned deleted_chunkno; /* Chunk # to delete */ @@ -3016,11 +3048,6 @@ done: * * Purpose: Attempt to eliminate empty chunks from object header. * - * Currently, this just examines a chunk to see if it's empty - * and removes it from the object header. It's possible that - * a more sophiticated algorithm would repack messages from - * one chunk to another. - * * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol @@ -3054,7 +3081,7 @@ H5O_condense_header(H5F_t *f, H5O_t *oh, hid_t dxpl_id) rescan_header = TRUE; /* Scan for adjacent null messages & merge them */ - result = H5O_merge_null(f, oh); + result = H5O_merge_null(oh); if(result < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTPACK, FAIL, "can't pack null header messages") if(result > 0) @@ -3109,7 +3136,7 @@ H5O_alloc_extend_chunk(H5F_t *f, unsigned * msg_idx) { size_t delta; /* Change in chunk's size */ - size_t aligned_size = H5O_ALIGN(size); + size_t aligned_size = H5O_ALIGN_OH(oh, size); uint8_t *old_image; /* Old address of chunk's image in memory */ size_t old_size; /* Old size of chunk */ htri_t tri_result; /* Result from checking if chunk can be extended */ @@ -3146,10 +3173,10 @@ H5O_alloc_extend_chunk(H5F_t *f, if(extend_msg >= 0) delta = aligned_size - oh->mesg[extend_msg].raw_size; else - delta = aligned_size + H5O_SIZEOF_MSGHDR(f); - delta = H5O_ALIGN(delta); + delta = aligned_size + H5O_SIZEOF_MSGHDR_OH(oh); + delta = H5O_ALIGN_OH(oh, delta); - /* determine whether the chunk can be extended */ + /* Determine whether the chunk can be extended */ tri_result = H5MF_can_extend(f, H5FD_MEM_OHDR, oh->chunk[chunkno].addr, (hsize_t)(oh->chunk[chunkno].size), (hsize_t)delta); if(tri_result == FALSE) { /* can't extend -- we are done */ @@ -3162,7 +3189,7 @@ H5O_alloc_extend_chunk(H5F_t *f, if(H5MF_extend(f, H5FD_MEM_OHDR, oh->chunk[chunkno].addr, (hsize_t)(oh->chunk[chunkno].size), (hsize_t)delta) < 0 ) HGOTO_ERROR(H5E_RESOURCE, H5E_SYSTEM, FAIL, "can't extend chunk") - /* If we can extend an existing null message, take take of that */ + /* If we can extend an existing null message, take care of that */ if(extend_msg >= 0) { /* Adjust message size of existing null message */ oh->mesg[extend_msg].dirty = TRUE; @@ -3171,10 +3198,9 @@ H5O_alloc_extend_chunk(H5F_t *f, /* Create new null message for end of chunk */ else { /* Create a new null message */ - if(oh->nmesgs >= oh->alloc_nmesgs) { + if(oh->nmesgs >= oh->alloc_nmesgs) if(H5O_alloc_msgs(oh, (size_t)0) < 0) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate more space for messages") - } /* end if */ /* Set extension message */ extend_msg = oh->nmesgs++; @@ -3184,8 +3210,8 @@ H5O_alloc_extend_chunk(H5F_t *f, oh->mesg[extend_msg].dirty = TRUE; oh->mesg[extend_msg].native = NULL; oh->mesg[extend_msg].raw = oh->chunk[chunkno].image + - oh->chunk[chunkno].size + H5O_SIZEOF_MSGHDR(f); - oh->mesg[extend_msg].raw_size = delta - H5O_SIZEOF_MSGHDR(f); + oh->chunk[chunkno].size + H5O_SIZEOF_MSGHDR_OH(oh); + oh->mesg[extend_msg].raw_size = delta - H5O_SIZEOF_MSGHDR_OH(oh); oh->mesg[extend_msg].chunkno = chunkno; } /* end else */ @@ -3279,17 +3305,19 @@ H5O_alloc_new_chunk(H5F_t *f, /* check args */ HDassert(oh); HDassert(size > 0); - size = H5O_ALIGN(size); + size = H5O_ALIGN_OH(oh, size); /* * Find the smallest null message that will hold an object * continuation message. Failing that, find the smallest message * that could be moved to make room for the continuation message. + * * Don't ever move continuation message from one chunk to another. - * Prioritize attribute and link messages moving to later chunks, + * + * Prioritize moving attribute and link messages to later chunks, * instead of more "important" messages. */ - cont_size = H5O_ALIGN(H5F_SIZEOF_ADDR(f) + H5F_SIZEOF_SIZE(f)); + cont_size = H5O_ALIGN_OH(oh, 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 */ @@ -3338,7 +3366,7 @@ H5O_alloc_new_chunk(H5F_t *f, found_other = found_link; HDassert(found_other >= 0); - size += H5O_SIZEOF_MSGHDR(f) + oh->mesg[found_other].raw_size; + size += H5O_SIZEOF_MSGHDR_OH(oh) + oh->mesg[found_other].raw_size; } /* end if */ /* @@ -3346,8 +3374,8 @@ H5O_alloc_new_chunk(H5F_t *f, * for the message header. This must be at least some minimum and a * multiple of the alignment size. */ - size = MAX(H5O_MIN_SIZE, size + H5O_SIZEOF_MSGHDR(f)); - HDassert(size == H5O_ALIGN(size)); + size = MAX(H5O_MIN_SIZE, size + H5O_SIZEOF_MSGHDR_OH(oh)); + HDassert(size == H5O_ALIGN_OH(oh, size)); /* allocate space in file to hold the new chunk */ new_chunk_addr = H5MF_alloc(f, H5FD_MEM_OHDR, dxpl_id, (hsize_t)size); @@ -3371,17 +3399,16 @@ H5O_alloc_new_chunk(H5F_t *f, oh->chunk[chunkno].dirty = TRUE; oh->chunk[chunkno].addr = new_chunk_addr; oh->chunk[chunkno].size = size; - if (NULL==(oh->chunk[chunkno].image = p = H5FL_BLK_CALLOC(chunk_image,size))) + if(NULL == (oh->chunk[chunkno].image = p = H5FL_BLK_CALLOC(chunk_image, size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, UFAIL, "memory allocation failed") /* * Make sure we have enough space for all possible new messages * that could be generated below. */ - if(oh->nmesgs + 3 > oh->alloc_nmesgs) { + if(oh->nmesgs + 3 > oh->alloc_nmesgs) if(H5O_alloc_msgs(oh, (size_t)3) < 0) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, UFAIL, "can't allocate more space for messages") - } /* end if */ /* * Describe the messages of the new chunk. @@ -3397,20 +3424,20 @@ H5O_alloc_new_chunk(H5F_t *f, oh->mesg[found_other].dirty = TRUE; /* Copy the message to the new location */ - HDmemcpy(p + H5O_SIZEOF_MSGHDR(f), + HDmemcpy(p + H5O_SIZEOF_MSGHDR_OH(oh), oh->mesg[found_other].raw, oh->mesg[found_other].raw_size); - oh->mesg[found_other].raw = p + H5O_SIZEOF_MSGHDR(f); + oh->mesg[found_other].raw = p + H5O_SIZEOF_MSGHDR_OH(oh); oh->mesg[found_other].chunkno = chunkno; - p += H5O_SIZEOF_MSGHDR(f) + oh->mesg[found_other].raw_size; - size -= H5O_SIZEOF_MSGHDR(f) + oh->mesg[found_other].raw_size; + p += H5O_SIZEOF_MSGHDR_OH(oh) + oh->mesg[found_other].raw_size; + size -= H5O_SIZEOF_MSGHDR_OH(oh) + oh->mesg[found_other].raw_size; } /* end if */ idx = oh->nmesgs++; oh->mesg[idx].type = H5O_MSG_NULL; oh->mesg[idx].dirty = TRUE; oh->mesg[idx].native = NULL; - oh->mesg[idx].raw = p + H5O_SIZEOF_MSGHDR(f); - oh->mesg[idx].raw_size = size - H5O_SIZEOF_MSGHDR(f); + oh->mesg[idx].raw = p + H5O_SIZEOF_MSGHDR_OH(oh); + oh->mesg[idx].raw_size = size - H5O_SIZEOF_MSGHDR_OH(oh); oh->mesg[idx].chunkno = chunkno; /* @@ -3424,9 +3451,9 @@ 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_OH(oh)); oh->mesg[u].raw_size = oh->mesg[found_null].raw_size - - (cont_size + H5O_SIZEOF_MSGHDR(f)); + (cont_size + H5O_SIZEOF_MSGHDR_OH(oh)); oh->mesg[u].chunkno = oh->mesg[found_null].chunkno; oh->mesg[found_null].dirty = TRUE; @@ -3438,7 +3465,7 @@ H5O_alloc_new_chunk(H5F_t *f, */ oh->mesg[found_null].type = H5O_MSG_CONT; oh->mesg[found_null].dirty = TRUE; - if (NULL==(cont = H5FL_MALLOC(H5O_cont_t))) + if(NULL == (cont = H5FL_MALLOC(H5O_cont_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, UFAIL, "memory allocation failed") cont->addr = oh->chunk[chunkno].addr; cont->size = oh->chunk[chunkno].size; @@ -3477,7 +3504,7 @@ H5O_alloc(H5F_t *f, unsigned * oh_flags_ptr) { H5O_mesg_t *msg; /* Pointer to newly allocated message */ - size_t aligned_size = H5O_ALIGN(size); + size_t aligned_size = H5O_ALIGN_OH(oh, size); unsigned idx; /* Index of message which fits allocation */ unsigned ret_value; /* Return value */ @@ -3489,11 +3516,9 @@ H5O_alloc(H5F_t *f, HDassert(oh_flags_ptr); /* look for a null message which is large enough */ - for(idx = 0; idx < oh->nmesgs; idx++) { - if(H5O_NULL_ID == oh->mesg[idx].type->id && - oh->mesg[idx].raw_size >= aligned_size) + for(idx = 0; idx < oh->nmesgs; idx++) + if(H5O_NULL_ID == oh->mesg[idx].type->id && oh->mesg[idx].raw_size >= aligned_size) break; - } /* end for */ /* if we didn't find one, then allocate more header space */ if(idx >= oh->nmesgs) { @@ -3519,8 +3544,8 @@ H5O_alloc(H5F_t *f, HGOTO_ERROR(H5E_OHDR, H5E_SYSTEM, UFAIL, "H5O_alloc_extend_chunk failed unexpectedly") } /* end for */ - /* if idx is still UFAIL, we were not able to extend a chunk. - * Create a new one. + /* If idx is still UFAIL, we were not able to extend a chunk, + * create a new one. */ if(idx == UFAIL) if((idx = H5O_alloc_new_chunk(f, dxpl_id, oh, size)) == UFAIL) @@ -3533,9 +3558,9 @@ H5O_alloc(H5F_t *f, /* do we need to split the null message? */ if(msg->raw_size > aligned_size) { H5O_mesg_t *null_msg; /* Pointer to null message */ - size_t mesg_size = aligned_size + H5O_SIZEOF_MSGHDR(f); /* Total size of newly allocated message */ + size_t mesg_size = aligned_size + H5O_SIZEOF_MSGHDR_OH(oh); /* Total size of newly allocated message */ - HDassert(msg->raw_size - aligned_size >= H5O_SIZEOF_MSGHDR(f)); + HDassert(msg->raw_size - aligned_size >= H5O_SIZEOF_MSGHDR_OH(oh)); /* Check if we need to extend message table */ if(oh->nmesgs >= oh->alloc_nmesgs) { @@ -3560,6 +3585,7 @@ H5O_alloc(H5F_t *f, msg->dirty = TRUE; msg->native = NULL; + /* Mark the object header as modified */ *oh_flags_ptr |= H5AC__DIRTIED_FLAG; /* Set return value */ @@ -3569,59 +3595,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* H5O_alloc() */ -#ifdef NOT_YET - -/*------------------------------------------------------------------------- - * Function: H5O_share - * - * Purpose: Writes a message to the global heap. - * - * Return: Success: Non-negative, and HOBJ describes the global heap - * object. - * - * Failure: Negative - * - * Programmer: Robb Matzke - * Thursday, April 2, 1998 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -static herr_t -H5O_share (H5F_t *f, hid_t dxpl_id, const H5O_msg_class_t *type, const void *mesg, - H5HG_t *hobj/*out*/) -{ - size_t size; - void *buf = NULL; - herr_t ret_value=SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT(H5O_share); - - /* Check args */ - assert (f); - assert (type); - assert (mesg); - assert (hobj); - - /* 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") - if ((type->encode)(f, buf, mesg) < 0) - 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") - } - -done: - if(buf) - H5MM_xfree (buf); - - FUNC_LEAVE_NOAPI(ret_value); -} -#endif /* NOT_YET */ - /*------------------------------------------------------------------------- * Function: H5O_raw_size @@ -3668,6 +3641,9 @@ done: * Purpose: Calculate the final size of an encoded message in an object * header. * + * Note: This routine assumes that the message size will be used in the + * creation of a new object header. + * * Return: Size of message on success, 0 on failure * * Programmer: Quincey Koziol @@ -3700,10 +3676,10 @@ H5O_mesg_size(unsigned type_id, const H5F_t *f, const void *mesg, size_t extra_r ret_value += extra_raw; /* Adjust size for alignment, if necessary */ - ret_value = H5O_ALIGN(ret_value); + ret_value = H5O_ALIGN_F(f, ret_value); /* Add space for message header */ - ret_value += H5O_SIZEOF_MSGHDR(f); + ret_value += H5O_SIZEOF_MSGHDR_F(f); done: FUNC_LEAVE_NOAPI(ret_value) @@ -3839,7 +3815,7 @@ H5O_delete_oh(H5F_t *f, hid_t dxpl_id, H5O_t *oh) } /* end for */ /* Free main (first) object header "chunk" */ - if(H5MF_xfree(f, H5FD_MEM_OHDR, dxpl_id, (oh->chunk[0].addr - H5O_SIZEOF_HDR(f)), (hsize_t)(oh->chunk[0].size + H5O_SIZEOF_HDR(f))) < 0) + if(H5MF_xfree(f, H5FD_MEM_OHDR, dxpl_id, (oh->chunk[0].addr - H5O_SIZEOF_HDR_OH(oh)), (hsize_t)(oh->chunk[0].size + H5O_SIZEOF_HDR_OH(oh))) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTFREE, FAIL, "unable to free object header") done: @@ -3924,7 +3900,7 @@ H5O_get_info(H5O_loc_t *loc, H5O_stat_t *ostat, hid_t dxpl_id) unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(H5O_get_info,FAIL) + FUNC_ENTER_NOAPI(H5O_get_info, FAIL) /* Check args */ HDassert(loc); @@ -3935,15 +3911,15 @@ H5O_get_info(H5O_loc_t *loc, H5O_stat_t *ostat, hid_t dxpl_id) HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "unable to load object header") /* Iterate over all the messages, accumulating the total size & free space */ - total_size = H5O_SIZEOF_HDR(loc->file); + total_size = H5O_SIZEOF_HDR_OH(oh); free_space = 0; for(u = 0, curr_msg = &oh->mesg[0]; u < oh->nmesgs; u++, curr_msg++) { /* Accumulate the size for this message */ - total_size += H5O_SIZEOF_MSGHDR(loc->file) + curr_msg->raw_size; + total_size += H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg->raw_size; /* Check for this message being free space */ if(H5O_NULL_ID == curr_msg->type->id) - free_space+= H5O_SIZEOF_MSGHDR(loc->file) + curr_msg->raw_size; + free_space+= H5O_SIZEOF_MSGHDR_OH(oh) + curr_msg->raw_size; } /* end for */ /* Set the information for this object header */ @@ -4588,7 +4564,7 @@ H5O_copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* Initialize header information */ - oh_dst->version = H5O_VERSION; + oh_dst->version = oh_src->version; oh_dst->nlink = 0; /* Initialize size of chunk array */ @@ -4610,7 +4586,7 @@ H5O_copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, size_t hdr_size; /* get the size of the file header of the destination file */ - hdr_size = H5O_SIZEOF_HDR(oloc_dst->file); + hdr_size = H5O_SIZEOF_HDR_OH(oh_dst); /* 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))) @@ -5284,7 +5260,7 @@ H5O_debug_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh, haddr_t addr, FILE *stream, i oh->version); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Header size (in bytes):", - (unsigned) H5O_SIZEOF_HDR(f)); + (unsigned) H5O_SIZEOF_HDR_OH(oh)); HDfprintf(stream, "%*s%-*s %d\n", indent, "", fwidth, "Number of links:", oh->nlink); @@ -5296,7 +5272,7 @@ H5O_debug_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh, haddr_t addr, FILE *stream, i oh->nchunks, oh->alloc_nchunks); /* debug each chunk */ - for (i=0, chunk_total=0; i < oh->nchunks; i++) { + for(i = 0, chunk_total = 0; i < oh->nchunks; i++) { chunk_total += oh->chunk[i].size; HDfprintf(stream, "%*sChunk %d...\n", indent, "", i); @@ -5307,27 +5283,27 @@ H5O_debug_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh, haddr_t addr, FILE *stream, i HDfprintf(stream, "%*s%-*s %a\n", indent + 3, "", MAX(0, fwidth - 3), "Address:", oh->chunk[i].addr); - tmp_addr = addr + (hsize_t)H5O_SIZEOF_HDR(f); - if (0 == i && H5F_addr_ne(oh->chunk[i].addr, tmp_addr)) + tmp_addr = addr + (hsize_t)H5O_SIZEOF_HDR_OH(oh); + if(0 == i && H5F_addr_ne(oh->chunk[i].addr, tmp_addr)) HDfprintf(stream, "*** WRONG ADDRESS!\n"); HDfprintf(stream, "%*s%-*s %lu\n", indent + 3, "", MAX(0, fwidth - 3), "Size in bytes:", (unsigned long) (oh->chunk[i].size)); - } + } /* end for */ /* debug each message */ - if (NULL==(sequence = H5MM_calloc(NELMTS(H5O_msg_class_g)*sizeof(int)))) + if(NULL == (sequence = H5MM_calloc(NELMTS(H5O_msg_class_g) * sizeof(int)))) 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; + for(i = 0, mesg_total = 0; i < oh->nmesgs; i++) { + mesg_total += H5O_SIZEOF_MSGHDR_OH(oh) + oh->mesg[i].raw_size; HDfprintf(stream, "%*sMessage %d...\n", indent, "", i); /* check for bad message id */ - if (oh->mesg[i].type->id >= (int)NELMTS(H5O_msg_class_g)) { + if(oh->mesg[i].type->id >= (int)NELMTS(H5O_msg_class_g)) { HDfprintf(stream, "*** BAD MESSAGE ID 0x%04x\n", oh->mesg[i].type->id); continue; - } + } /* end if */ /* message name and size */ HDfprintf(stream, "%*s%-*s 0x%04x `%s' (%d)\n", @@ -5345,11 +5321,11 @@ H5O_debug_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh, haddr_t addr, FILE *stream, i HDfprintf(stream, "%*s%-*s %s\n", indent + 3, "", MAX(0, fwidth - 3), "Constant:", (oh->mesg[i].flags & H5O_FLAG_CONSTANT) ? "Yes" : "No"); - if (oh->mesg[i].flags & ~H5O_FLAG_BITS) { + if(oh->mesg[i].flags & ~H5O_FLAG_BITS) { HDfprintf (stream, "%*s%-*s 0x%02x\n", indent+3,"",MAX(0,fwidth-3), "*** ADDITIONAL UNKNOWN FLAGS --->", oh->mesg[i].flags & ~H5O_FLAG_BITS); - } + } /* end if */ HDfprintf(stream, "%*s%-*s %lu bytes\n", indent+3, "", MAX(0,fwidth-3), "Raw size in obj header:", (unsigned long) (oh->mesg[i].raw_size)); @@ -5357,54 +5333,53 @@ H5O_debug_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh, haddr_t addr, FILE *stream, i "Chunk number:", (int) (oh->mesg[i].chunkno)); chunkno = oh->mesg[i].chunkno; - if (chunkno >= oh->nchunks) + if(chunkno >= oh->nchunks) HDfprintf(stream, "*** BAD CHUNK NUMBER\n"); HDfprintf(stream, "%*s%-*s %u\n", indent + 3, "", MAX(0, fwidth - 3), "Raw data offset in chunk:", (unsigned) (oh->mesg[i].raw - oh->chunk[chunkno].image)); /* check the size */ - if ((oh->mesg[i].raw + oh->mesg[i].raw_size > + if((oh->mesg[i].raw + oh->mesg[i].raw_size > oh->chunk[chunkno].image + oh->chunk[chunkno].size) || - (oh->mesg[i].raw < oh->chunk[chunkno].image)) { + (oh->mesg[i].raw < oh->chunk[chunkno].image)) HDfprintf(stream, "*** BAD MESSAGE RAW ADDRESS\n"); - } /* decode the message */ - if (oh->mesg[i].flags & H5O_FLAG_SHARED) { + if(oh->mesg[i].flags & H5O_FLAG_SHARED) { decode = H5O_MSG_SHARED->decode; debug = H5O_MSG_SHARED->debug; } else { decode = oh->mesg[i].type->decode; debug = oh->mesg[i].type->debug; - } - if (NULL==oh->mesg[i].native && decode) + } /* end else */ + if(NULL==oh->mesg[i].native && decode) oh->mesg[i].native = (decode)(f, dxpl_id, oh->mesg[i].raw); - if (NULL==oh->mesg[i].native) + if(NULL == oh->mesg[i].native) debug = NULL; /* print the message */ HDfprintf(stream, "%*s%-*s\n", indent + 3, "", MAX(0, fwidth - 3), "Message Information:"); - if (debug) - (debug)(f, dxpl_id, oh->mesg[i].native, stream, indent+6, MAX(0, fwidth-6)); + if(debug) + (debug)(f, dxpl_id, oh->mesg[i].native, stream, indent + 6, MAX(0, fwidth - 6)); else HDfprintf(stream, "%*s<No info for this message>\n", indent + 6, ""); /* If the message is shared then also print the pointed-to message */ - if (oh->mesg[i].flags & H5O_FLAG_SHARED) { + if(oh->mesg[i].flags & H5O_FLAG_SHARED) { H5O_shared_t *shared = (H5O_shared_t*)(oh->mesg[i].native); - void *mesg = NULL; + void *mesg; mesg = H5O_read_real(&(shared->oloc), oh->mesg[i].type, 0, NULL, dxpl_id); - if (oh->mesg[i].type->debug) - (oh->mesg[i].type->debug)(f, dxpl_id, mesg, stream, indent+3, MAX (0, fwidth-3)); + if(oh->mesg[i].type->debug) + (oh->mesg[i].type->debug)(f, dxpl_id, mesg, stream, indent + 3, MAX (0, fwidth - 3)); H5O_free_real(oh->mesg[i].type, mesg); - } - } + } /* end if */ + } /* end for */ sequence = H5MM_xfree(sequence); - if (mesg_total != chunk_total) + if(mesg_total != chunk_total) HDfprintf(stream, "*** TOTAL SIZE DOES NOT MATCH ALLOCATED SIZE!\n"); done: diff --git a/src/H5Oattr.c b/src/H5Oattr.c index 02299d4..b939ba4 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -169,7 +169,7 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p) if(NULL == (attr->name = H5MM_strdup((const char *)p))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") if(version < H5O_ATTR_VERSION_2) - p += H5O_ALIGN(name_len); /* advance the memory pointer */ + p += H5O_ALIGN_OLD(name_len); /* advance the memory pointer */ else p += name_len; /* advance the memory pointer */ @@ -193,7 +193,7 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p) HGOTO_ERROR(H5E_ATTR, H5E_CANTDECODE, NULL, "can't decode attribute datatype") } /* end else */ if(version < H5O_ATTR_VERSION_2) - p += H5O_ALIGN(attr->dt_size); + p += H5O_ALIGN_OLD(attr->dt_size); else p += attr->dt_size; @@ -215,7 +215,7 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, NULL, "unable to set all selection") if(version < H5O_ATTR_VERSION_2) - p += H5O_ALIGN(attr->ds_size); + p += H5O_ALIGN_OLD(attr->ds_size); else p += attr->ds_size; @@ -337,8 +337,8 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg) HDmemcpy(p, attr->name, name_len); 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); + HDmemset(p + name_len, 0, H5O_ALIGN_OLD(name_len) - name_len); + p += H5O_ALIGN_OLD(name_len); } /* end if */ else p += name_len; @@ -364,8 +364,8 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg) HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL, "can't encode attribute datatype") } /* end else */ if(version < H5O_ATTR_VERSION_2) { - HDmemset(p + attr->dt_size, 0, H5O_ALIGN(attr->dt_size) - attr->dt_size); - p += H5O_ALIGN(attr->dt_size); + HDmemset(p + attr->dt_size, 0, H5O_ALIGN_OLD(attr->dt_size) - attr->dt_size); + p += H5O_ALIGN_OLD(attr->dt_size); } /* end if */ else p += attr->dt_size; @@ -374,8 +374,8 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg) if((H5O_MSG_SDSPACE->encode)(f, p, &(attr->ds->extent)) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL, "can't encode attribute dataspace") if(version < H5O_ATTR_VERSION_2) { - HDmemset(p + attr->ds_size, 0, H5O_ALIGN(attr->ds_size) - attr->ds_size); - p += H5O_ALIGN(attr->ds_size); + HDmemset(p + attr->ds_size, 0, H5O_ALIGN_OLD(attr->ds_size) - attr->ds_size); + p += H5O_ALIGN_OLD(attr->ds_size); } /* end if */ else p += attr->ds_size; @@ -490,9 +490,9 @@ H5O_attr_size(const H5F_t *f, const void *_mesg) /* Version-specific size information */ if(version == H5O_ATTR_VERSION_1) - ret_value += H5O_ALIGN(name_len) + /*attribute name */ - H5O_ALIGN(attr->dt_size) + /*data type */ - H5O_ALIGN(attr->ds_size) + /*data space */ + ret_value += H5O_ALIGN_OLD(name_len) + /*attribute name */ + H5O_ALIGN_OLD(attr->dt_size) + /*data type */ + H5O_ALIGN_OLD(attr->ds_size) + /*data space */ attr->data_size; /*the data itself */ else if(version == H5O_ATTR_VERSION_2) ret_value += name_len + /*attribute name */ 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++) diff --git a/src/H5Odtype.c b/src/H5Odtype.c index f768689..ef75b54 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -935,25 +935,27 @@ done: static void * H5O_dtype_decode(H5F_t *f, hid_t UNUSED dxpl_id, const uint8_t *p) { - H5T_t *dt = NULL; - void *ret_value; /* Return value */ + H5T_t *dt = NULL; + void *ret_value; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5O_dtype_decode); + FUNC_ENTER_NOAPI_NOINIT(H5O_dtype_decode) /* check args */ - assert(p); + HDassert(p); + /* Allocate datatype message */ if(NULL == (dt = H5T_alloc())) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - if (H5O_dtype_decode_helper(f, &p, dt) < 0) + /* Perform actual decode of message */ + if(H5O_dtype_decode_helper(f, &p, dt) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, NULL, "can't decode type"); /* Set return value */ - ret_value=dt; + ret_value = dt; done: - if(ret_value==NULL) { + if(ret_value == NULL) { if(dt != NULL) { if(dt->shared != NULL) H5FL_FREE(H5T_shared_t, dt->shared); @@ -961,8 +963,8 @@ done: } /* end if */ } /* end if */ - FUNC_LEAVE_NOAPI(ret_value); -} + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_dtype_decode() */ /*-------------------------------------------------------------------------- @@ -1216,13 +1218,13 @@ H5O_dtype_reset(void *_mesg) { H5T_t *dt = (H5T_t *) _mesg; - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_dtype_reset); + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_dtype_reset) - if (dt) + if(dt) H5T_free(dt); - FUNC_LEAVE_NOAPI(SUCCEED); -} + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5O_dtype_reset() */ /*------------------------------------------------------------------------- @@ -1240,17 +1242,17 @@ H5O_dtype_reset(void *_mesg) *------------------------------------------------------------------------- */ static herr_t -H5O_dtype_free (void *mesg) +H5O_dtype_free(void *mesg) { - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_dtype_free); + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_dtype_free) - assert (mesg); + HDassert(mesg); H5FL_FREE(H5T_shared_t, ((H5T_t *) mesg)->shared); H5FL_FREE(H5T_t,mesg); - FUNC_LEAVE_NOAPI(SUCCEED); -} + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5O_dtype_free() */ /*------------------------------------------------------------------------- @@ -1408,14 +1410,14 @@ H5O_dtype_debug(H5F_t *f, hid_t dxpl_id, const void *mesg, FILE *stream, unsigned i; size_t k; - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_dtype_debug); + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_dtype_debug) /* check args */ - assert(f); - assert(dt); - assert(stream); - assert(indent >= 0); - assert(fwidth >= 0); + HDassert(f); + HDassert(dt); + HDassert(stream); + HDassert(indent >= 0); + HDassert(fwidth >= 0); switch (dt->shared->type) { case H5T_INTEGER: @@ -1452,7 +1454,7 @@ H5O_dtype_debug(H5F_t *f, hid_t dxpl_id, const void *mesg, FILE *stream, s = "vlen"; break; default: - sprintf(buf, "H5T_CLASS_%d", (int) (dt->shared->type)); + sprintf(buf, "H5T_CLASS_%d", (int)(dt->shared->type)); s = buf; break; } @@ -1462,51 +1464,50 @@ H5O_dtype_debug(H5F_t *f, hid_t dxpl_id, const void *mesg, FILE *stream, fprintf(stream, "%*s%-*s %lu byte%s\n", indent, "", fwidth, "Size:", - (unsigned long)(dt->shared->size), 1==dt->shared->size?"":"s"); + (unsigned long)(dt->shared->size), 1 == dt->shared->size ? "" : "s"); if (H5T_COMPOUND == dt->shared->type) { fprintf(stream, "%*s%-*s %d\n", indent, "", fwidth, "Number of members:", dt->shared->u.compnd.nmembs); - for (i=0; i<dt->shared->u.compnd.nmembs; i++) { + for(i = 0; i < dt->shared->u.compnd.nmembs; i++) { sprintf(buf, "Member %d:", i); fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, buf, dt->shared->u.compnd.memb[i].name); fprintf(stream, "%*s%-*s %lu\n", indent+3, "", MAX(0, fwidth-3), "Byte offset:", - (unsigned long) (dt->shared->u.compnd.memb[i].offset)); + (unsigned long)(dt->shared->u.compnd.memb[i].offset)); H5O_dtype_debug(f, dxpl_id, dt->shared->u.compnd.memb[i].type, stream, - indent+3, MAX(0, fwidth - 3)); + indent + 3, MAX(0, fwidth - 3)); } - } else if (H5T_ENUM==dt->shared->type) { + } else if(H5T_ENUM == dt->shared->type) { fprintf(stream, "%*s%s\n", indent, "", "Base type:"); H5O_dtype_debug(f, dxpl_id, dt->shared->parent, stream, indent+3, MAX(0, fwidth-3)); fprintf(stream, "%*s%-*s %d\n", indent, "", fwidth, "Number of members:", dt->shared->u.enumer.nmembs); - for (i=0; i<dt->shared->u.enumer.nmembs; i++) { + for(i = 0; i < dt->shared->u.enumer.nmembs; i++) { sprintf(buf, "Member %d:", i); fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, buf, dt->shared->u.enumer.name[i]); fprintf(stream, "%*s%-*s 0x", indent, "", fwidth, "Raw bytes of value:"); - for (k=0; k<dt->shared->parent->shared->size; k++) { + for(k = 0; k < dt->shared->parent->shared->size; k++) fprintf(stream, "%02x", - dt->shared->u.enumer.value[i*dt->shared->parent->shared->size+k]); - } + dt->shared->u.enumer.value[i*dt->shared->parent->shared->size + k]); fprintf(stream, "\n"); - } + } /* end for */ - } else if (H5T_OPAQUE==dt->shared->type) { + } else if(H5T_OPAQUE == dt->shared->type) { fprintf(stream, "%*s%-*s \"%s\"\n", indent, "", fwidth, "Tag:", dt->shared->u.opaque.tag); - } else if (H5T_REFERENCE==dt->shared->type) { + } else if(H5T_REFERENCE == dt->shared->type) { fprintf(stream, "%*s%-*s\n", indent, "", fwidth, "Fix dumping reference types!"); - } else if (H5T_VLEN==dt->shared->type) { - switch (dt->shared->u.vlen.type) { + } else if(H5T_VLEN == dt->shared->type) { + switch(dt->shared->u.vlen.type) { case H5T_VLEN_SEQUENCE: s = "sequence"; break; @@ -1517,11 +1518,11 @@ H5O_dtype_debug(H5F_t *f, hid_t dxpl_id, const void *mesg, FILE *stream, sprintf(buf, "H5T_VLEN_%d", dt->shared->u.vlen.type); s = buf; break; - } + } /* end switch */ fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Vlen type:", s); - switch (dt->shared->u.vlen.loc) { + switch(dt->shared->u.vlen.loc) { case H5T_LOC_MEMORY: s = "memory"; break; @@ -1532,7 +1533,7 @@ H5O_dtype_debug(H5F_t *f, hid_t dxpl_id, const void *mesg, FILE *stream, sprintf(buf, "H5T_LOC_%d", dt->shared->u.vlen.loc); s = buf; break; - } + } /* end switch */ fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Location:", s); } else if(H5T_ARRAY == dt->shared->type) { @@ -1563,7 +1564,7 @@ H5O_dtype_debug(H5F_t *f, hid_t dxpl_id, const void *mesg, FILE *stream, sprintf(buf, "H5T_ORDER_%d", dt->shared->u.atomic.order); s = buf; break; - } + } /* end switch */ fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Byte order:", s); @@ -1588,7 +1589,7 @@ H5O_dtype_debug(H5F_t *f, hid_t dxpl_id, const void *mesg, FILE *stream, default: s = "pad?"; break; - } + } /* end switch */ fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Low pad type:", s); @@ -1602,7 +1603,7 @@ H5O_dtype_debug(H5F_t *f, hid_t dxpl_id, const void *mesg, FILE *stream, default: s = "pad?"; break; - } + } /* end switch */ fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "High pad type:", s); @@ -1622,7 +1623,7 @@ H5O_dtype_debug(H5F_t *f, hid_t dxpl_id, const void *mesg, FILE *stream, } s = buf; break; - } + } /* end switch */ fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Internal pad type:", s); @@ -1639,7 +1640,7 @@ H5O_dtype_debug(H5F_t *f, hid_t dxpl_id, const void *mesg, FILE *stream, default: sprintf(buf, "H5T_NORM_%d", (int) (dt->shared->u.atomic.u.f.norm)); s = buf; - } + } /* end switch */ fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Normalization:", s); @@ -1679,13 +1680,12 @@ H5O_dtype_debug(H5F_t *f, hid_t dxpl_id, const void *mesg, FILE *stream, sprintf(buf, "H5T_SGN_%d", (int) (dt->shared->u.atomic.u.i.sign)); s = buf; break; - } + } /* end switch */ fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Sign scheme:", s); - } } - FUNC_LEAVE_NOAPI(SUCCEED); -} + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5O_dtype_debug() */ diff --git a/src/H5Opkg.h b/src/H5Opkg.h index 62dc8ed..49a0cf9 100644 --- a/src/H5Opkg.h +++ b/src/H5Opkg.h @@ -25,38 +25,105 @@ /* Other private headers needed by this file */ #include "H5ACprivate.h" /* Metadata cache */ +/* Object header macros */ +#define H5O_NMESGS 8 /*initial number of messages */ +#define H5O_NCHUNKS 2 /*initial number of chunks */ + +/* Versions of object header structure */ + +/* Initial version of the object header format */ +#define H5O_VERSION_1 1 + +/* Revised version - leaves out reserved bytes and alignment padding, and adds + * magic number as prefix and checksum + */ +#define H5O_VERSION_2 2 + +/* The latest version of the format. Look through the 'flush' + * and 'size' callback for places to change when updating this. */ +#define H5O_VERSION_LATEST H5O_VERSION_1 + /* * Align messages on 8-byte boundaries because we would like to copy the * object header chunks directly into memory and operate on them there, even * on 64-bit architectures. This allows us to reduce the number of disk I/O * requests with a minimum amount of mem-to-mem copies. */ -#define H5O_ALIGN(X) (8*(((X)+8-1)/8)) - -/* Object header macros */ -#define H5O_NMESGS 8 /*initial number of messages */ -#define H5O_NCHUNKS 2 /*initial number of chunks */ - -/* Version of object header structure */ -#define H5O_VERSION 1 +/* + * Note: We no longer attempt to do this. + */ +#ifdef OLD_WAY +#define H5O_ALIGN(X) (8 * (((X) + 7) / 8)) +#else /* OLD_WAY */ +#define H5O_ALIGN_OLD(X) (8 * (((X) + 7) / 8)) +#define H5O_ALIGN_VERS(V, X) \ + (((V) == H5O_VERSION_1) ? \ + H5O_ALIGN_OLD(X) \ + : \ + (X) \ + ) +#define H5O_ALIGN_OH(O, X) \ + H5O_ALIGN_VERS((O)->version, X) +#define H5O_ALIGN_F(F, X) \ + H5O_ALIGN_VERS((H5F_USE_LATEST_FORMAT(F) ? H5O_VERSION_LATEST : H5O_VERSION_1), X) +#endif /* OLD_WAY */ /* - * Size of object header header. + * Size of object header prefix. */ +#ifdef OLD_WAY #define H5O_SIZEOF_HDR(F) \ H5O_ALIGN(1 + /*version number */ \ 1 + /*reserved */ \ 2 + /*number of messages */ \ 4 + /*reference count */ \ 4) /*header data size */ +#else /* OLD_WAY */ +#define H5O_SIZEOF_HDR_VERS(V) \ + (((V) == H5O_VERSION_1) ? \ + H5O_ALIGN_OLD(1 + /*version number */ \ + 1 + /*reserved */ \ + 2 + /*number of messages */ \ + 4 + /*reference count */ \ + 4) /*header data size */ \ + : \ + (4 + /*magic number */ \ + 1 + /*version number */ \ + 2 + /*number of messages */ \ + 4 + /*reference count */ \ + 4) /*header data size */ \ + ) +#define H5O_SIZEOF_HDR_OH(O) \ + H5O_SIZEOF_HDR_VERS((O)->version) +#define H5O_SIZEOF_HDR_F(F) \ + H5O_SIZEOF_HDR_VERS(H5F_USE_LATEST_FORMAT(F) ? H5O_VERSION_LATEST : H5O_VERSION_1) +#endif /* OLD_WAY */ /* - * Size of message header + * Size of object header message prefix */ +#ifdef OLD_WAY #define H5O_SIZEOF_MSGHDR(F) \ H5O_ALIGN(2 + /*message type */ \ 2 + /*sizeof message data */ \ - 4) /*reserved */ + 1 + /*flags */ \ + 3) /*reserved */ +#else /* OLD_WAY */ +#define H5O_SIZEOF_MSGHDR_VERS(V) \ + (((V) == H5O_VERSION_1) ? \ + H5O_ALIGN_OLD(2 + /*message type */ \ + 2 + /*sizeof message data */ \ + 1 + /*flags */ \ + 3) /*reserved */ \ + : \ + (2 + /*message type */ \ + 2) /*sizeof message data */ \ + ) +#define H5O_SIZEOF_MSGHDR_OH(O) \ + H5O_SIZEOF_MSGHDR_VERS((O)->version) +#define H5O_SIZEOF_MSGHDR_F(F) \ + H5O_SIZEOF_MSGHDR_VERS(H5F_USE_LATEST_FORMAT(F) ? H5O_VERSION_LATEST : H5O_VERSION_1) +#endif /* OLD_WAY */ struct H5O_msg_class_t { unsigned id; /*message type ID on disk */ diff --git a/src/H5Opline.c b/src/H5Opline.c index 5b0c065..0a6bab0 100644 --- a/src/H5Opline.c +++ b/src/H5Opline.c @@ -211,7 +211,7 @@ H5O_pline_encode (H5F_t UNUSED *f, uint8_t *p/*out*/, const void *mesg) /* Encode the filter */ UINT16ENCODE(p, pline->filter[i].id); - UINT16ENCODE(p, H5O_ALIGN(name_length)); + UINT16ENCODE(p, H5O_ALIGN_OLD(name_length)); UINT16ENCODE(p, pline->filter[i].flags); UINT16ENCODE(p, pline->filter[i].cd_nelmts); if (name_length>0) { @@ -350,7 +350,7 @@ H5O_pline_size (const H5F_t UNUSED *f, const void *mesg) 2 + /*name length */ 2 + /*flags */ 2 + /*number of client data values */ - H5O_ALIGN(name_len); /*length of the filter name */ + H5O_ALIGN_OLD(name_len); /*length of the filter name */ ret_value += pline->filter[i].cd_nelmts * 4; if (pline->filter[i].cd_nelmts % 2) diff --git a/tools/misc/h5debug.c b/tools/misc/h5debug.c index ad0960f..5b33c65 100644 --- a/tools/misc/h5debug.c +++ b/tools/misc/h5debug.c @@ -380,7 +380,7 @@ main(int argc, char *argv[]) status = H5FS_sects_debug(f, H5P_DATASET_XFER_DEFAULT, addr, stdout, 0, VCOL, extra, extra2); - } else if(sig[0] == H5O_VERSION) { + } else if(sig[0] == H5O_VERSION_1) { /* * This could be an object header. Since they don't have a signature * it's a somewhat "ify" detection. |