From 06ba931a9500d52c3170ebda6a805da9b8f95378 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Mon, 4 Dec 2006 09:34:10 -0500 Subject: [svn-r13016] Description: Finish moving object header message routines into their own source code module, along with renaming them to have "H5O_msg_" prefix... Tested on: Mac OS X/32 10.4.8 (amazon) FreeBSD/32 4.11 (sleipnir) Linux/32 2.4 (heping) AIX/32 5.? (copper) --- src/H5A.c | 26 +- src/H5Adeprec.c | 2 +- src/H5Dio.c | 2 +- src/H5Doh.c | 4 +- src/H5G.c | 8 +- src/H5Gbtree2.c | 2 +- src/H5Gcompact.c | 8 +- src/H5Gdense.c | 14 +- src/H5Gdeprec.c | 2 +- src/H5Gobj.c | 16 +- src/H5Goh.c | 4 +- src/H5Gtest.c | 28 +- src/H5HFcache.c | 4 +- src/H5HFhdr.c | 2 +- src/H5O.c | 1510 ++++++++---------------------------------------------- src/H5Oattr.c | 50 +- src/H5Ocopy.c | 2 +- src/H5Odtype.c | 10 +- src/H5Ofill.c | 16 +- src/H5Omessage.c | 1353 +++++++++++++++++++++++++++++++++++++++++------- src/H5Opkg.h | 15 +- src/H5Opline.c | 14 +- src/H5Oprivate.h | 43 +- src/H5Osdspace.c | 20 +- src/H5Oshared.c | 14 +- src/H5S.c | 60 +-- src/H5SM.c | 173 ++++--- src/H5T.c | 6 +- src/H5Tcommit.c | 2 +- src/H5Toh.c | 2 +- test/ohdr.c | 4 +- 31 files changed, 1646 insertions(+), 1770 deletions(-) diff --git a/src/H5A.c b/src/H5A.c index 01ccb95..8eede77 100644 --- a/src/H5A.c +++ b/src/H5A.c @@ -302,12 +302,12 @@ H5A_create(const H5G_loc_t *loc, const char *name, const H5T_t *type, HDassert(space); /* Reset shared message information */ - HDmemset(&sh_mesg,0,sizeof(H5O_shared_t)); + HDmemset(&sh_mesg, 0, sizeof(H5O_shared_t)); /* Iterate over the existing attributes to check for duplicates */ cb.name = name; cb.idx = (-1); - if((ret_value = H5O_iterate(loc->oloc, H5O_ATTR_ID, H5A_find_idx_by_name, &cb, dxpl_id)) < 0) + if((ret_value = H5O_msg_iterate(loc->oloc, H5O_ATTR_ID, H5A_find_idx_by_name, &cb, dxpl_id)) < 0) HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL, "error iterating over attributes") if(ret_value > 0) HGOTO_ERROR(H5E_ATTR, H5E_ALREADYEXISTS, FAIL, "attribute already exists") @@ -372,37 +372,37 @@ H5A_create(const H5G_loc_t *loc, const char *name, const H5T_t *type, * datatype and dataspace messages themselves, or the size of the "shared" * messages if either or both of them are shared. */ - if((tri_ret = H5O_is_shared(H5O_DTYPE_ID, attr->dt)) == FALSE) + if((tri_ret = H5O_msg_is_shared(H5O_DTYPE_ID, attr->dt)) == FALSE) { /* Message wasn't shared after all. Use size of normal datatype * message. */ - attr->dt_size = H5O_raw_size(H5O_DTYPE_ID, attr->oloc.file, attr->dt); + attr->dt_size = H5O_msg_raw_size(attr->oloc.file, H5O_DTYPE_ID, attr->dt); } else if(tri_ret > 0) { /* Message is shared. Use size of shared message */ - if(H5O_get_share(H5O_DTYPE_ID, attr->oloc.file, attr->dt, &sh_mesg) < 0) + if(H5O_msg_get_share(H5O_DTYPE_ID, attr->dt, &sh_mesg) < 0) HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "couldn't get size of shared message") - attr->dt_size = H5O_raw_size(H5O_SHARED_ID, attr->oloc.file, &sh_mesg); + attr->dt_size = H5O_msg_raw_size(attr->oloc.file, H5O_SHARED_ID, &sh_mesg); } else HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "couldn't determine if dataspace is shared") /* Perform the same test for the dataspace message */ - if((tri_ret = H5O_is_shared(H5O_SDSPACE_ID, attr->ds)) == FALSE) + if((tri_ret = H5O_msg_is_shared(H5O_SDSPACE_ID, attr->ds)) == FALSE) { /* Message wasn't shared after all. Use size of normal dataspace * message. */ - attr->ds_size = H5O_raw_size(H5O_SDSPACE_ID, attr->oloc.file, attr->ds); + attr->ds_size = H5O_msg_raw_size(attr->oloc.file, H5O_SDSPACE_ID, attr->ds); } else if(tri_ret > 0) { /* Message is shared. Use size of shared message */ - if(H5O_get_share(H5O_SDSPACE_ID, attr->oloc.file, attr->ds, &sh_mesg) < 0) + if(H5O_msg_get_share(H5O_SDSPACE_ID, attr->ds, &sh_mesg) < 0) HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "couldn't get size of shared message") - attr->ds_size = H5O_raw_size(H5O_SHARED_ID, attr->oloc.file, &sh_mesg); + attr->ds_size = H5O_msg_raw_size(attr->oloc.file, H5O_SHARED_ID, &sh_mesg); } else HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "couldn't determine if datatype is shared") @@ -512,7 +512,7 @@ H5A_get_index(H5O_loc_t *loc, const char *name, hid_t dxpl_id) udata.name = name; udata.idx = (-1); - if((ret_value = H5O_iterate(loc, H5O_ATTR_ID, H5A_find_idx_by_name, &udata, dxpl_id)) < 0) + if((ret_value = H5O_msg_iterate(loc, H5O_ATTR_ID, H5A_find_idx_by_name, &udata, dxpl_id)) < 0) HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL, "error iterating over attributes") if(ret_value > 0) ret_value = udata.idx; @@ -1451,7 +1451,7 @@ H5Aiterate(hid_t loc_id, unsigned *attr_num, H5A_operator_t op, void *op_data) start_idx = idx = (attr_num ? (int)*attr_num : 0); if(idx < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid index specified") - if(idx < H5O_count(loc.oloc, H5O_ATTR_ID, H5AC_dxpl_id)) { + if(idx < H5O_msg_count(loc.oloc, H5O_ATTR_ID, H5AC_dxpl_id)) { while(H5O_msg_read(loc.oloc, H5O_ATTR_ID, idx++, &found_attr, H5AC_dxpl_id) != NULL) { /* * Compare found attribute name to new attribute name reject @@ -1520,7 +1520,7 @@ H5Adelete(hid_t loc_id, const char *name) HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL, "attribute not found") /* Delete the attribute from the location */ - if((ret_value = H5O_remove(loc.oloc, H5O_ATTR_ID, found, TRUE, H5AC_dxpl_id)) < 0) + if((ret_value = H5O_msg_remove(loc.oloc, H5O_ATTR_ID, found, TRUE, H5AC_dxpl_id)) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTDELETE, FAIL, "unable to delete attribute header message") done: diff --git a/src/H5Adeprec.c b/src/H5Adeprec.c index b2c0b01..22ca0e3 100644 --- a/src/H5Adeprec.c +++ b/src/H5Adeprec.c @@ -155,7 +155,7 @@ H5Aget_num_attrs(hid_t loc_id) } /*lint !e788 All appropriate cases are covered */ /* Look up the # of attributes for the object */ - if((ret_value = H5O_count(loc, H5O_ATTR_ID, H5AC_ind_dxpl_id)) < 0) + if((ret_value = H5O_msg_count(loc, H5O_ATTR_ID, H5AC_ind_dxpl_id)) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTCOUNT, FAIL, "can't get attribute count for object") done: diff --git a/src/H5Dio.c b/src/H5Dio.c index 269161f..13fcffd 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -898,7 +898,7 @@ H5D_write(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, * Update modification time. We have to do this explicitly because * writing to a dataset doesn't necessarily change the object header. */ - if (H5O_touch(&(dataset->oloc), FALSE, dxpl_id) < 0) + if(H5O_touch(&(dataset->oloc), FALSE, dxpl_id) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to update modification time") #endif /* OLD_WAY */ diff --git a/src/H5Doh.c b/src/H5Doh.c index e25a0ae..5c8797e 100644 --- a/src/H5Doh.c +++ b/src/H5Doh.c @@ -177,13 +177,13 @@ H5O_dset_isa(H5O_t *oh) HDassert(oh); /* Datatype */ - if((exists = H5O_exists_oh(oh, H5O_DTYPE_ID, 0)) < 0) + if((exists = H5O_msg_exists_oh(oh, H5O_DTYPE_ID, 0)) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to read object header") else if(!exists) HGOTO_DONE(FALSE) /* Layout */ - if((exists = H5O_exists_oh(oh, H5O_SDSPACE_ID, 0)) < 0) + if((exists = H5O_msg_exists_oh(oh, H5O_SDSPACE_ID, 0)) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to read object header") else if(!exists) HGOTO_DONE(FALSE) diff --git a/src/H5G.c b/src/H5G.c index 3f1cc08..ae8afee 100644 --- a/src/H5G.c +++ b/src/H5G.c @@ -539,7 +539,7 @@ H5Gget_create_plist(hid_t group_id) HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't get object creation info") /* Check for the group having a group info message */ - if((ginfo_exists = H5O_exists(&(grp->oloc), H5O_GINFO_ID, 0, H5AC_ind_dxpl_id)) < 0) + if((ginfo_exists = H5O_msg_exists(&(grp->oloc), H5O_GINFO_ID, 0, H5AC_ind_dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") if(ginfo_exists) { H5O_ginfo_t ginfo; /* Group info message */ @@ -554,7 +554,7 @@ H5Gget_create_plist(hid_t group_id) } /* end if */ /* Check for the group having a link info message */ - if((linfo_exists = H5O_exists(&(grp->oloc), H5O_LINFO_ID, 0, H5AC_ind_dxpl_id)) < 0) + if((linfo_exists = H5O_msg_exists(&(grp->oloc), H5O_LINFO_ID, 0, H5AC_ind_dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") if(linfo_exists) { H5O_linfo_t linfo; /* Link info message */ @@ -1285,8 +1285,8 @@ H5G_open_oid(H5G_t *grp, hid_t dxpl_id) obj_opened = TRUE; /* Check if this object has the right message(s) to be treated as a group */ - if((H5O_exists(&(grp->oloc), H5O_STAB_ID, 0, dxpl_id) <= 0) - && (H5O_exists(&(grp->oloc), H5O_LINFO_ID, 0, dxpl_id) <= 0)) + if((H5O_msg_exists(&(grp->oloc), H5O_STAB_ID, 0, dxpl_id) <= 0) + && (H5O_msg_exists(&(grp->oloc), H5O_LINFO_ID, 0, dxpl_id) <= 0)) HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "not a group") done: diff --git a/src/H5Gbtree2.c b/src/H5Gbtree2.c index 2812513..ed909c3 100644 --- a/src/H5Gbtree2.c +++ b/src/H5Gbtree2.c @@ -163,7 +163,7 @@ H5G_dense_fh_name_cmp(const void *obj, size_t UNUSED obj_len, void *_udata) FUNC_ENTER_NOAPI_NOINIT(H5G_dense_fh_name_cmp) /* Decode link information */ - if(NULL == (lnk = H5O_decode(udata->f, udata->dxpl_id, obj, H5O_LINK_ID))) + if(NULL == (lnk = H5O_msg_decode(udata->f, udata->dxpl_id, H5O_LINK_ID, obj))) HGOTO_ERROR(H5E_SYM, H5E_CANTDECODE, FAIL, "can't decode link") /* Compare the string values */ diff --git a/src/H5Gcompact.c b/src/H5Gcompact.c index 5229a9a..b33f7d1 100644 --- a/src/H5Gcompact.c +++ b/src/H5Gcompact.c @@ -151,7 +151,7 @@ H5G_compact_build_table(const H5O_loc_t *oloc, hid_t dxpl_id, const H5O_linfo_t udata.curr_lnk = 0; /* Iterate through the link messages, adding them to the table */ - if(H5O_iterate(oloc, H5O_LINK_ID, H5G_compact_build_table_cb, &udata, dxpl_id) < 0) + if(H5O_msg_iterate(oloc, H5O_LINK_ID, H5G_compact_build_table_cb, &udata, dxpl_id) < 0) HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "error iterating over link messages") /* Sort link table in correct iteration order */ @@ -394,7 +394,7 @@ H5G_compact_remove(const H5O_loc_t *oloc, hid_t dxpl_id, H5RS_str_t *grp_full_pa udata.name = name; /* Iterate over the link messages to delete the right one */ - if(H5O_remove_op(oloc, H5O_LINK_ID, H5O_FIRST, H5G_compact_remove_common_cb, &udata, TRUE, dxpl_id) < 0) + if(H5O_msg_remove_op(oloc, H5O_LINK_ID, H5O_FIRST, H5G_compact_remove_common_cb, &udata, TRUE, dxpl_id) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTDELETE, FAIL, "unable to delete link message") done: @@ -443,7 +443,7 @@ H5G_compact_remove_by_idx(const H5O_loc_t *oloc, hid_t dxpl_id, udata.name = ltable.lnks[n].name; /* Iterate over the link messages to delete the right one */ - if(H5O_remove_op(oloc, H5O_LINK_ID, H5O_FIRST, H5G_compact_remove_common_cb, &udata, TRUE, dxpl_id) < 0) + if(H5O_msg_remove_op(oloc, H5O_LINK_ID, H5O_FIRST, H5G_compact_remove_common_cb, &udata, TRUE, dxpl_id) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTDELETE, FAIL, "unable to delete link message") done: @@ -578,7 +578,7 @@ H5G_compact_lookup(H5O_loc_t *oloc, const char *name, H5O_link_t *lnk, udata.found = FALSE; /* Iterate through the link messages, adding them to the table */ - if(H5O_iterate(oloc, H5O_LINK_ID, H5G_compact_lookup_cb, &udata, dxpl_id) < 0) + if(H5O_msg_iterate(oloc, H5O_LINK_ID, H5G_compact_lookup_cb, &udata, dxpl_id) < 0) HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "error iterating over link messages") /* Check if we found the link we were looking for */ diff --git a/src/H5Gdense.c b/src/H5Gdense.c index 214f5fc..899e833 100644 --- a/src/H5Gdense.c +++ b/src/H5Gdense.c @@ -394,7 +394,7 @@ HDfprintf(stderr, "%s: linfo->name_bt2_addr = %a\n", FUNC, linfo->name_bt2_addr) #endif /* QAK */ /* Find out the size of buffer needed for serialized link */ - if((link_size = H5O_raw_size(H5O_LINK_ID, f, lnk)) == 0) + if((link_size = H5O_msg_raw_size(f, H5O_LINK_ID, lnk)) == 0) HGOTO_ERROR(H5E_SYM, H5E_CANTGETSIZE, FAIL, "can't get link size") #ifdef QAK HDfprintf(stderr, "%s: HDstrlen(lnk->name) = %Zu, link_size = %Zu\n", FUNC, HDstrlen(lnk->name), link_size); @@ -409,7 +409,7 @@ HDfprintf(stderr, "%s: HDstrlen(lnk->name) = %Zu, link_size = %Zu\n", FUNC, HDst link_ptr = link_buf; /* Create serialized form of link */ - if(H5O_encode(f, link_ptr, lnk, H5O_LINK_ID) < 0) + if(H5O_msg_encode(f, H5O_LINK_ID, link_ptr, lnk) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTENCODE, FAIL, "can't encode link") /* Open the fractal heap */ @@ -577,7 +577,7 @@ H5G_dense_lookup_by_idx_fh_cb(const void *obj, size_t UNUSED obj_len, void *_uda FUNC_ENTER_NOAPI_NOINIT(H5G_dense_lookup_by_idx_fh_cb) /* Decode link information & keep a copy */ - if(NULL == (tmp_lnk = H5O_decode(udata->f, udata->dxpl_id, obj, H5O_LINK_ID))) + if(NULL == (tmp_lnk = H5O_msg_decode(udata->f, udata->dxpl_id, H5O_LINK_ID, obj))) HGOTO_ERROR(H5E_SYM, H5E_CANTDECODE, FAIL, "can't decode link") /* Copy link information */ @@ -869,7 +869,7 @@ H5G_dense_iterate_fh_cb(const void *obj, size_t UNUSED obj_len, void *_udata) * HDF5 routine, it could attempt to re-protect that direct block for the * heap, causing the HDF5 routine called to fail) */ - if(NULL == (udata->lnk = H5O_decode(udata->f, udata->dxpl_id, obj, H5O_LINK_ID))) + if(NULL == (udata->lnk = H5O_msg_decode(udata->f, udata->dxpl_id, H5O_LINK_ID, obj))) HGOTO_ERROR(H5E_SYM, H5E_CANTDECODE, FAIL, "can't decode link") done: @@ -1058,7 +1058,7 @@ H5G_dense_get_name_by_idx_fh_cb(const void *obj, size_t UNUSED obj_len, void *_u FUNC_ENTER_NOAPI_NOINIT(H5G_dense_get_name_by_idx_fh_cb) /* Decode link information */ - if(NULL == (lnk = H5O_decode(udata->f, udata->dxpl_id, obj, H5O_LINK_ID))) + if(NULL == (lnk = H5O_msg_decode(udata->f, udata->dxpl_id, H5O_LINK_ID, obj))) HGOTO_ERROR(H5E_SYM, H5E_CANTDECODE, FAIL, "can't decode link") /* Get the length of the name */ @@ -1332,7 +1332,7 @@ H5G_dense_remove_fh_cb(const void *obj, size_t UNUSED obj_len, void *_udata) FUNC_ENTER_NOAPI_NOINIT(H5G_dense_remove_fh_cb) /* Decode link information */ - if(NULL == (lnk = H5O_decode(udata->f, udata->dxpl_id, obj, H5O_LINK_ID))) + if(NULL == (lnk = H5O_msg_decode(udata->f, udata->dxpl_id, H5O_LINK_ID, obj))) HGOTO_ERROR(H5E_SYM, H5E_CANTDECODE, H5_ITER_ERROR, "can't decode link") /* Check for removing the link from the creation order index */ @@ -1501,7 +1501,7 @@ H5G_dense_remove_by_idx_fh_cb(const void *obj, size_t UNUSED obj_len, void *_uda FUNC_ENTER_NOAPI_NOINIT(H5G_dense_remove_by_idx_fh_cb) /* Decode link information */ - if(NULL == (udata->lnk = H5O_decode(udata->f, udata->dxpl_id, obj, H5O_LINK_ID))) + if(NULL == (udata->lnk = H5O_msg_decode(udata->f, udata->dxpl_id, H5O_LINK_ID, obj))) HGOTO_ERROR(H5E_SYM, H5E_CANTDECODE, H5_ITER_ERROR, "can't decode link") /* Can't operate on link here because the fractal heap block is locked */ diff --git a/src/H5Gdeprec.c b/src/H5Gdeprec.c index 4d665ab..6ffc3f4 100644 --- a/src/H5Gdeprec.c +++ b/src/H5Gdeprec.c @@ -612,7 +612,7 @@ H5G_set_comment(H5G_loc_t *loc, const char *name, const char *buf, hid_t dxpl_id loc_valid = TRUE; /* Remove the previous comment message if any */ - if(H5O_remove(obj_loc.oloc, H5O_NAME_ID, 0, TRUE, dxpl_id) < 0) + if(H5O_msg_remove(obj_loc.oloc, H5O_NAME_ID, 0, TRUE, dxpl_id) < 0) H5E_clear_stack(NULL); /* Add the new message */ diff --git a/src/H5Gobj.c b/src/H5Gobj.c index c1d1fd3..bf656e5 100644 --- a/src/H5Gobj.c +++ b/src/H5Gobj.c @@ -162,17 +162,17 @@ H5G_obj_create(H5F_t *f, hid_t dxpl_id, const H5O_ginfo_t *ginfo, size_t link_size; /* Size of a link message */ /* Calculate message size infomation, for creating group's object header */ - linfo_size = H5O_mesg_size(H5O_LINFO_ID, f, linfo, (size_t)0); + linfo_size = H5O_msg_mesg_size(f, H5O_LINFO_ID, linfo, (size_t)0); HDassert(linfo_size); - ginfo_size = H5O_mesg_size(H5O_GINFO_ID, f, ginfo, (size_t)0); + ginfo_size = H5O_msg_mesg_size(f, H5O_GINFO_ID, ginfo, (size_t)0); HDassert(ginfo_size); lnk.type = H5L_TYPE_HARD; lnk.corder = 0; lnk.corder_valid = ginfo->track_corder; lnk.name = &null_char; - link_size = H5O_mesg_size(H5O_LINK_ID, f, &lnk, (size_t)ginfo->est_name_len); + link_size = H5O_msg_mesg_size(f, H5O_LINK_ID, &lnk, (size_t)ginfo->est_name_len); HDassert(link_size); /* Compute size of header to use for creation */ @@ -434,7 +434,7 @@ H5G_obj_insert(H5O_loc_t *grp_oloc, const char *name, H5O_link_t *obj_lnk, } /* end if */ /* Get the link's message size */ - if((link_msg_size = H5O_raw_size(H5O_LINK_ID, grp_oloc->file, obj_lnk)) == 0) + if((link_msg_size = H5O_msg_raw_size(grp_oloc->file, H5O_LINK_ID, obj_lnk)) == 0) HGOTO_ERROR(H5E_SYM, H5E_CANTGETSIZE, FAIL, "can't get link size") /* If there's still a small enough number of links, use the 'link' message */ @@ -458,11 +458,11 @@ H5G_obj_insert(H5O_loc_t *grp_oloc, const char *name, H5O_link_t *obj_lnk, udata.linfo = &linfo; /* Iterate over the 'link' messages, inserting them into the dense link storage */ - if(H5O_iterate(grp_oloc, H5O_LINK_ID, H5G_obj_compact_to_dense_cb, &udata, dxpl_id) < 0) + if(H5O_msg_iterate(grp_oloc, H5O_LINK_ID, H5G_obj_compact_to_dense_cb, &udata, dxpl_id) < 0) HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "error iterating over links") /* Remove all the 'link' messages */ - if(H5O_remove(grp_oloc, H5O_LINK_ID, H5O_ALL, FALSE, dxpl_id) < 0) + if(H5O_msg_remove(grp_oloc, H5O_LINK_ID, H5O_ALL, FALSE, dxpl_id) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTDELETE, FAIL, "unable to delete link messages") use_new_dense = TRUE; @@ -502,7 +502,7 @@ H5G_obj_insert(H5O_loc_t *grp_oloc, const char *name, H5O_link_t *obj_lnk, HGOTO_ERROR(H5E_SYM, H5E_CANTNEXT, FAIL, "error iterating over old format links") /* Remove the symbol table message from the group */ - if(H5O_remove(grp_oloc, H5O_STAB_ID, 0, FALSE, dxpl_id) < 0) + if(H5O_msg_remove(grp_oloc, H5O_STAB_ID, 0, FALSE, dxpl_id) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTDELETE, FAIL, "unable to delete old format link storage") /* Recursively call this routine to insert the new link, since the @@ -899,7 +899,7 @@ H5G_obj_remove_update_linfo(H5O_loc_t *oloc, H5O_linfo_t *linfo, hid_t dxpl_id) * 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_MESG_MAX_SIZE) { + if(H5O_msg_mesg_size(oloc->file, H5O_LINK_ID, &(ltable.lnks[u]), (size_t)0) >= H5O_MESG_MAX_SIZE) { can_convert = FALSE; break; } /* end if */ diff --git a/src/H5Goh.c b/src/H5Goh.c index 853dc7c..2b51d0a 100644 --- a/src/H5Goh.c +++ b/src/H5Goh.c @@ -99,9 +99,9 @@ H5O_group_isa(struct H5O_t *oh) HDassert(oh); /* Check for any of the messages that indicate a group */ - if((stab_exists = H5O_exists_oh(oh, H5O_STAB_ID, 0)) < 0) + if((stab_exists = H5O_msg_exists_oh(oh, H5O_STAB_ID, 0)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") - if((linfo_exists = H5O_exists_oh(oh, H5O_LINFO_ID, 0)) < 0) + if((linfo_exists = H5O_msg_exists_oh(oh, H5O_LINFO_ID, 0)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") ret_value = (stab_exists > 0 || linfo_exists > 0); diff --git a/src/H5Gtest.c b/src/H5Gtest.c index a179ea8..8852adf 100644 --- a/src/H5Gtest.c +++ b/src/H5Gtest.c @@ -107,11 +107,11 @@ H5G_is_empty_test(hid_t gid) /* "New format" checks */ /* Check if the group has any link messages */ - if((msg_exists = H5O_exists(&(grp->oloc), H5O_LINK_ID, 0, H5AC_dxpl_id)) < 0) + if((msg_exists = H5O_msg_exists(&(grp->oloc), H5O_LINK_ID, 0, H5AC_dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") if(msg_exists > 0) { /* Sanity check that new group format shouldn't have old messages */ - if((msg_exists = H5O_exists(&(grp->oloc), H5O_STAB_ID, 0, H5AC_dxpl_id)) < 0) + if((msg_exists = H5O_msg_exists(&(grp->oloc), H5O_STAB_ID, 0, H5AC_dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") if(msg_exists > 0) HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "both symbol table and link messages found") @@ -120,13 +120,13 @@ H5G_is_empty_test(hid_t gid) } /* end if */ /* Check for a link info message */ - if((linfo_exists = H5O_exists(&(grp->oloc), H5O_LINFO_ID, 0, H5AC_dxpl_id)) < 0) + if((linfo_exists = H5O_msg_exists(&(grp->oloc), H5O_LINFO_ID, 0, H5AC_dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") if(linfo_exists > 0) { H5O_linfo_t linfo; /* Link info message */ /* Sanity check that new group format shouldn't have old messages */ - if((msg_exists = H5O_exists(&(grp->oloc), H5O_STAB_ID, 0, H5AC_dxpl_id)) < 0) + if((msg_exists = H5O_msg_exists(&(grp->oloc), H5O_STAB_ID, 0, H5AC_dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") if(msg_exists > 0) HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "both symbol table and link info messages found") @@ -151,7 +151,7 @@ H5G_is_empty_test(hid_t gid) /* "Old format" checks */ /* Check if the group has a symbol table message */ - if((msg_exists = H5O_exists(&(grp->oloc), H5O_STAB_ID, 0, H5AC_dxpl_id)) < 0) + if((msg_exists = H5O_msg_exists(&(grp->oloc), H5O_STAB_ID, 0, H5AC_dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") if(msg_exists > 0) { H5O_stab_t stab; /* Info about local heap & B-tree */ @@ -160,7 +160,7 @@ H5G_is_empty_test(hid_t gid) /* Sanity check that old group format shouldn't have new messages */ if(linfo_exists > 0) HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "both symbol table and link info messages found") - if((msg_exists = H5O_exists(&(grp->oloc), H5O_GINFO_ID, 0, H5AC_dxpl_id)) < 0) + if((msg_exists = H5O_msg_exists(&(grp->oloc), H5O_GINFO_ID, 0, H5AC_dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") if(msg_exists > 0) HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "both symbol table and group info messages found") @@ -216,13 +216,13 @@ H5G_has_links_test(hid_t gid, unsigned *nmsgs) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group") /* Check if the group has any link messages */ - if((msg_exists = H5O_exists(&(grp->oloc), H5O_LINK_ID, 0, H5AC_dxpl_id)) < 0) + if((msg_exists = H5O_msg_exists(&(grp->oloc), H5O_LINK_ID, 0, H5AC_dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") if(msg_exists == 0) HGOTO_DONE(FALSE) /* Check if the group has a symbol table message */ - if((msg_exists = H5O_exists(&(grp->oloc), H5O_STAB_ID, 0, H5AC_dxpl_id)) < 0) + if((msg_exists = H5O_msg_exists(&(grp->oloc), H5O_STAB_ID, 0, H5AC_dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") if(msg_exists > 0) HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "both symbol table and link messages found") @@ -232,7 +232,7 @@ H5G_has_links_test(hid_t gid, unsigned *nmsgs) int msg_count; /* Number of messages of a type */ /* Check how many link messages there are */ - if((msg_count = H5O_count(&(grp->oloc), H5O_LINK_ID, H5AC_dxpl_id)) < 0) + if((msg_count = H5O_msg_count(&(grp->oloc), H5O_LINK_ID, H5AC_dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTCOUNT, FAIL, "unable to count link messages") *nmsgs = (unsigned)msg_count; } /* end if */ @@ -274,13 +274,13 @@ H5G_has_stab_test(hid_t gid) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group") /* Check if the group has a symbol table message */ - if((msg_exists = H5O_exists(&(grp->oloc), H5O_STAB_ID, 0, H5AC_dxpl_id)) < 0) + if((msg_exists = H5O_msg_exists(&(grp->oloc), H5O_STAB_ID, 0, H5AC_dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") if(msg_exists == 0) HGOTO_DONE(FALSE) /* Check if the group has any link messages */ - if((msg_exists = H5O_exists(&(grp->oloc), H5O_LINK_ID, 0, H5AC_dxpl_id)) < 0) + if((msg_exists = H5O_msg_exists(&(grp->oloc), H5O_LINK_ID, 0, H5AC_dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") if(msg_exists > 0) HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "both symbol table and link messages found") @@ -324,19 +324,19 @@ H5G_is_new_dense_test(hid_t gid) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group") /* Check if the group has a symbol table message */ - if((msg_exists = H5O_exists(&(grp->oloc), H5O_STAB_ID, 0, H5AC_dxpl_id)) < 0) + if((msg_exists = H5O_msg_exists(&(grp->oloc), H5O_STAB_ID, 0, H5AC_dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") if(msg_exists > 0) HGOTO_DONE(FALSE) /* Check if the group has any link messages */ - if((msg_exists = H5O_exists(&(grp->oloc), H5O_LINK_ID, 0, H5AC_dxpl_id)) < 0) + if((msg_exists = H5O_msg_exists(&(grp->oloc), H5O_LINK_ID, 0, H5AC_dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") if(msg_exists > 0) HGOTO_DONE(FALSE) /* Check if the group has link info message */ - if((msg_exists = H5O_exists(&(grp->oloc), H5O_LINFO_ID, 0, H5AC_dxpl_id)) < 0) + if((msg_exists = H5O_msg_exists(&(grp->oloc), H5O_LINFO_ID, 0, H5AC_dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to read object header") if(msg_exists > 0) { H5O_linfo_t linfo; /* Link info message */ diff --git a/src/H5HFcache.c b/src/H5HFcache.c index e3c07c4..880c36d 100644 --- a/src/H5HFcache.c +++ b/src/H5HFcache.c @@ -374,7 +374,7 @@ HDfprintf(stderr, "%s: Load heap header, addr = %a\n", FUNC, addr); UINT32DECODE(p, hdr->pline_root_direct_filter_mask); /* Decode I/O filter information */ - if(NULL == (pline = H5O_decode(hdr->f, dxpl_id, p, H5O_PLINE_ID))) + if(NULL == (pline = H5O_msg_decode(hdr->f, dxpl_id, H5O_PLINE_ID, p))) HGOTO_ERROR(H5E_HEAP, H5E_CANTDECODE, NULL, "can't decode I/O pipeline filters") p += hdr->filter_len; @@ -528,7 +528,7 @@ HDfprintf(stderr, "%s: Flushing heap header, addr = %a, destroy = %u\n", FUNC, a UINT32ENCODE(p, hdr->pline_root_direct_filter_mask); /* Encode I/O filter information */ - if(H5O_encode(hdr->f, p, &(hdr->pline), H5O_PLINE_ID) < 0) + if(H5O_msg_encode(hdr->f, H5O_PLINE_ID, p, &(hdr->pline)) < 0) HGOTO_ERROR(H5E_HEAP, H5E_CANTENCODE, FAIL, "can't encode I/O pipeline fiters") p += hdr->filter_len; } /* end if */ diff --git a/src/H5HFhdr.c b/src/H5HFhdr.c index 8bcea64..4b61063 100644 --- a/src/H5HFhdr.c +++ b/src/H5HFhdr.c @@ -424,7 +424,7 @@ H5HF_hdr_create(H5F_t *f, hid_t dxpl_id, const H5HF_create_t *cparam) HGOTO_ERROR(H5E_HEAP, H5E_CANTCOPY, HADDR_UNDEF, "can't copy I/O filter pipeline") /* Compute the I/O filters' encoded size */ - if(0 == (hdr->filter_len = H5O_raw_size(H5O_PLINE_ID, hdr->f, &(hdr->pline)))) + if(0 == (hdr->filter_len = H5O_msg_raw_size(hdr->f, H5O_PLINE_ID, &(hdr->pline)))) HGOTO_ERROR(H5E_HEAP, H5E_CANTGETSIZE, HADDR_UNDEF, "can't get I/O filter pipeline size") #ifdef QAK HDfprintf(stderr, "%s: hdr->filter_len = %u\n", FUNC, hdr->filter_len); diff --git a/src/H5O.c b/src/H5O.c index e57f4c0..6b5c853 100644 --- a/src/H5O.c +++ b/src/H5O.c @@ -39,10 +39,10 @@ #include "H5FLprivate.h" /* Free lists */ #include "H5Iprivate.h" /* IDs */ #include "H5MFprivate.h" /* File memory management */ -#include "H5MMprivate.h" /* Memory management */ #include "H5Opkg.h" /* Object headers */ #include "H5SMprivate.h" /* Shared object header messages */ + /****************/ /* Local Macros */ /****************/ @@ -52,38 +52,6 @@ /* Local Typedefs */ /******************/ -/* User data for iteration while removing a message */ -typedef struct { - H5F_t *f; /* Pointer to file for insertion */ - hid_t dxpl_id; /* DXPL during iteration */ - int sequence; /* Sequence # to search for */ - unsigned nfailed; /* # of failed message removals */ - H5O_operator_t op; /* Callback routine for removal operations */ - void *op_data; /* Callback data for removal operations */ - hbool_t adj_link; /* Whether to adjust links when removing messages */ -} H5O_iter_ud1_t; - -/* Typedef for "internal library" iteration operations */ -typedef herr_t (*H5O_lib_operator_t)(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, - unsigned sequence, unsigned *oh_flags_ptr/*out*/, void *operator_data/*in,out*/); - -/* Some syntactic sugar to make the compiler happy with two different kinds of iterator callbacks */ -typedef union { - H5O_operator_t app_op; /* Application callback for each message */ - H5O_lib_operator_t lib_op; /* Library internal callback for each message */ -} H5O_mesg_operator_t; - -/* - * This table contains a list of object types, descriptions, and the - * functions that determine if some object is a particular type. The table - * is allocated dynamically. - */ -typedef struct H5O_typeinfo_t { - H5G_obj_t type; /*one of the public H5G_* types */ - htri_t (*isa)(H5O_t*); /*function to determine type */ - char *desc; /*description of object type */ -} H5O_typeinfo_t; - /********************/ /* Package Typedefs */ @@ -95,17 +63,14 @@ typedef struct H5O_typeinfo_t { /********************/ 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 H5O_loc_t * H5O_get_loc(hid_t id); static herr_t H5O_new(H5F_t *f, hid_t dxpl_id, haddr_t header, size_t chunk_size, hid_t ocpl_id, H5O_loc_t *loc/*out*/); -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 herr_t H5O_delete_oh(H5F_t *f, hid_t dxpl_id, H5O_t *oh); -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 const H5O_obj_class_t *H5O_obj_class(H5O_loc_t *loc, hid_t dxpl_id); static herr_t H5O_obj_type_real(H5O_t *oh, H5O_type_t *obj_type); + /*********************/ /* Package Variables */ /*********************/ @@ -161,18 +126,19 @@ H5FL_SEQ_DEFINE(H5O_chunk_t); /* Declare a free list to manage the chunk image information */ H5FL_BLK_DEFINE(chunk_image); + /*****************************/ /* Library Private Variables */ /*****************************/ +/* Declare external the free list for time_t's */ +H5FL_EXTERN(time_t); + /*******************/ /* Local Variables */ /*******************/ -/* Declare external the free list for time_t's */ -H5FL_EXTERN(time_t); - /*------------------------------------------------------------------------- @@ -391,54 +357,6 @@ done: /*------------------------------------------------------------------------- - * Function: H5Oclose - * - * Purpose: Close an open file object. - * - * This is the companion to H5Oopen. It is used to close any - * open object in an HDF5 file (but not IDs are that not file - * objects, such as property lists and dataspaces). It has - * the same effect as calling H5Gclose, H5Dclose, or H5Tclose. - * - * Return: Success: Non-negative - * Failure: Negative - * - * Programmer: James Laird - * July 14 2006 - * - *------------------------------------------------------------------------- - */ -herr_t -H5Oclose(hid_t object_id) -{ - herr_t ret_value = SUCCEED; - - FUNC_ENTER_API(H5Oclose, FAIL) - H5TRACE1("e","i",object_id); - - /* Get the type of the object and close it in the correct way */ - switch(H5I_get_type(object_id)) - { - case(H5I_GROUP): - case(H5I_DATATYPE): - case(H5I_DATASET): - if(H5I_object(object_id) == NULL) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a valid object") - if(H5I_dec_ref(object_id) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTRELEASE, FAIL, "unable to close object") - break; - - default: - HGOTO_ERROR(H5E_ARGS, H5E_CANTRELEASE, FAIL, "not a valid file object ID (dataset, group, or datatype)") - break; - } /* end switch */ - -done: - FUNC_LEAVE_API(ret_value) -} /* end H5Oclose() */ - - -/*------------------------------------------------------------------------- * Function: H5Oincr_refcount * * Purpose: Warning! This function is EXTREMELY DANGEROUS! @@ -468,7 +386,7 @@ H5Oincr_refcount(hid_t object_id) H5TRACE1("e","i",object_id); /* Get the object's oloc so we can adjust its link count */ - if((oloc = H5O_get_oloc(object_id)) == NULL) + if((oloc = H5O_get_loc(object_id)) == NULL) HGOTO_ERROR(H5E_ATOM, H5E_BADVALUE, FAIL, "unable to get object location from ID") if(H5O_link(oloc, 1, H5AC_dxpl_id) < 0) @@ -509,7 +427,7 @@ H5Odecr_refcount(hid_t object_id) H5TRACE1("e","i",object_id); /* Get the object's oloc so we can adjust its link count */ - if((oloc = H5O_get_oloc(object_id)) == NULL) + if((oloc = H5O_get_loc(object_id)) == NULL) HGOTO_ERROR(H5E_ATOM, H5E_BADVALUE, FAIL, "unable to get object location from ID") if(H5O_link(oloc, -1, H5AC_dxpl_id) < 0) @@ -631,86 +549,51 @@ done: /*------------------------------------------------------------------------- - * Function: H5O_open_by_loc - * - * Purpose: Opens an object and returns an ID given its group loction. - * - * Return: Success: Open object identifier - * Failure: Negative - * - * Programmer: James Laird - * July 25 2006 + * Function: H5Oclose * - *------------------------------------------------------------------------- - */ -static hid_t -H5O_open_by_loc(H5G_loc_t *obj_loc, hid_t dxpl_id) -{ - const H5O_obj_class_t *obj_class; /* Class of object for location */ - hid_t ret_value; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT(H5O_open_by_loc) - - HDassert(obj_loc); - - /* Get the object class for this location */ - if(NULL == (obj_class = H5O_obj_class(obj_loc->oloc, dxpl_id))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, FAIL, "unable to determine object class") - - /* Call the object class's 'open' routine */ - HDassert(obj_class->open); - if((ret_value = obj_class->open(obj_loc, dxpl_id)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTOPENOBJ, FAIL, "unable to open object") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_open_by_loc() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_get_oloc + * Purpose: Close an open file object. * - * Purpose: Gets the oloc for an object given its ID. + * This is the companion to H5Oopen. It is used to close any + * open object in an HDF5 file (but not IDs are that not file + * objects, such as property lists and dataspaces). It has + * the same effect as calling H5Gclose, H5Dclose, or H5Tclose. * - * Return: Success: Pointer to H5O_loc_t - * Failure: NULL + * Return: Success: Non-negative + * Failure: Negative * * Programmer: James Laird - * July 25 2006 + * July 14 2006 * *------------------------------------------------------------------------- */ -static H5O_loc_t * -H5O_get_oloc(hid_t object_id) +herr_t +H5Oclose(hid_t object_id) { - H5O_loc_t *ret_value; /* Return value */ + herr_t ret_value = SUCCEED; - FUNC_ENTER_NOAPI_NOINIT(H5O_get_oloc) + FUNC_ENTER_API(H5Oclose, FAIL) + H5TRACE1("e","i",object_id); + /* Get the type of the object and close it in the correct way */ switch(H5I_get_type(object_id)) { case(H5I_GROUP): - if(NULL == (ret_value = H5O_OBJ_GROUP->get_oloc(object_id))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, NULL, "unable to get object location from group ID") - break; - - case(H5I_DATASET): - if(NULL == (ret_value = H5O_OBJ_DATASET->get_oloc(object_id))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, NULL, "unable to get object location from dataset ID") - break; - case(H5I_DATATYPE): - if(NULL == (ret_value = H5O_OBJ_DATATYPE->get_oloc(object_id))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, NULL, "unable to get object location from datatype ID") + case(H5I_DATASET): + if(H5I_object(object_id) == NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a valid object") + if(H5I_dec_ref(object_id) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTRELEASE, FAIL, "unable to close object") break; default: - HGOTO_ERROR(H5E_OHDR, H5E_BADTYPE, NULL, "invalid object type") + HGOTO_ERROR(H5E_ARGS, H5E_CANTRELEASE, FAIL, "not a valid file object ID (dataset, group, or datatype)") + break; } /* end switch */ done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_get_oloc() */ + FUNC_LEAVE_API(ret_value) +} /* end H5Oclose() */ /*------------------------------------------------------------------------- @@ -938,6 +821,43 @@ H5O_open(const H5O_loc_t *loc) /*------------------------------------------------------------------------- + * Function: H5O_open_by_loc + * + * Purpose: Opens an object and returns an ID given its group loction. + * + * Return: Success: Open object identifier + * Failure: Negative + * + * Programmer: James Laird + * July 25 2006 + * + *------------------------------------------------------------------------- + */ +static hid_t +H5O_open_by_loc(H5G_loc_t *obj_loc, hid_t dxpl_id) +{ + const H5O_obj_class_t *obj_class; /* Class of object for location */ + hid_t ret_value; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5O_open_by_loc) + + HDassert(obj_loc); + + /* Get the object class for this location */ + if(NULL == (obj_class = H5O_obj_class(obj_loc->oloc, dxpl_id))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, FAIL, "unable to determine object class") + + /* Call the object class's 'open' routine */ + HDassert(obj_class->open); + if((ret_value = obj_class->open(obj_loc, dxpl_id)) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTOPENOBJ, FAIL, "unable to open object") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_open_by_loc() */ + + +/*------------------------------------------------------------------------- * Function: H5O_close * * Purpose: Closes an object header that was previously open. @@ -1077,7 +997,7 @@ H5O_link(const H5O_loc_t *loc, int adjust, hid_t dxpl_id) ret_value = oh->nlink; done: - if (oh && H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, oh_flags) < 0) + if(oh && H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, oh_flags) < 0) HDONE_ERROR(H5E_OHDR, H5E_PROTECT, FAIL, "unable to release object header") FUNC_LEAVE_NOAPI(ret_value) @@ -1085,261 +1005,112 @@ done: /*------------------------------------------------------------------------- - * Function: H5O_count + * Function: H5O_protect * - * Purpose: Counts the number of messages in an object header which are a - * certain type. + * Purpose: Wrapper around H5AC_protect for use during a H5O_protect-> + * H5O_msg_append->...->H5O_msg_append->H5O_unprotect sequence of calls + * during an object's creation. * - * Return: Success: Number of messages of specified type. + * Return: Success: Pointer to the object header structure for the + * object. * - * Failure: Negative + * Failure: NULL * - * Programmer: Robb Matzke - * Tuesday, April 21, 1998 + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Dec 31 2002 * *------------------------------------------------------------------------- */ -int -H5O_count(H5O_loc_t *loc, unsigned type_id, hid_t dxpl_id) +H5O_t * +H5O_protect(H5O_loc_t *loc, hid_t dxpl_id) { - H5O_t *oh = NULL; /* Object header to operate on */ - const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ - int acc; /* Count of the message type found */ - unsigned u; /* Local index variable */ - int ret_value; /* Return value */ + H5O_t *ret_value; /* Return value */ - FUNC_ENTER_NOAPI(H5O_count, FAIL) + FUNC_ENTER_NOAPI(H5O_protect, NULL) - /* Check args */ + /* check args */ HDassert(loc); HDassert(loc->file); HDassert(H5F_addr_defined(loc->addr)); - 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); - - /* Load the object header */ - if(NULL == (oh = H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "unable to load object header") - /* Loop over all messages, counting the ones of the type looked for */ - for(u = acc = 0; u < oh->nmesgs; u++) - if(oh->mesg[u].type == type) - acc++; + /* Check for write access on the file */ + if(0 == (H5F_INTENT(loc->file) & H5F_ACC_RDWR)) + HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, NULL, "no write intent on file") - /* Set return value */ - ret_value = acc; + /* Lock the object header into the cache */ + if(NULL == (ret_value = H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_WRITE))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "unable to load object header") done: - if(oh && H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, H5AC__NO_FLAGS_SET) < 0) - HDONE_ERROR(H5E_OHDR, H5E_PROTECT, FAIL, "unable to release object header") - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_count() */ +} /* end H5O_protect() */ /*------------------------------------------------------------------------- - * Function: H5O_exists + * Function: H5O_unprotect * - * Purpose: Determines if a particular message exists in an object - * header without trying to decode the message. + * Purpose: Wrapper around H5AC_unprotect for use during a H5O_protect-> + * H5O_msg_append->...->H5O_msg_append->H5O_unprotect sequence of calls + * during an object's creation. * - * Return: Success: FALSE if the message does not exist; TRUE if - * th message exists. + * Return: Success: Non-negative * - * Failure: FAIL if the existence of the message could - * not be determined due to some error such as - * not being able to read the object header. + * Failure: Negative * - * Programmer: Robb Matzke - * Monday, November 2, 1998 + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Dec 31 2002 * *------------------------------------------------------------------------- */ -htri_t -H5O_exists(H5O_loc_t *loc, unsigned type_id, int sequence, hid_t dxpl_id) +herr_t +H5O_unprotect(H5O_loc_t *loc, H5O_t *oh, hid_t dxpl_id, unsigned oh_flags) { - H5O_t *oh = NULL; /* Object header for location */ - htri_t ret_value; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(H5O_exists, FAIL) + FUNC_ENTER_NOAPI(H5O_unprotect, FAIL) + /* check args */ HDassert(loc); HDassert(loc->file); - HDassert(type_id < NELMTS(H5O_msg_class_g)); - HDassert(sequence >= 0); - - /* Load the object header */ - if(NULL == (oh = H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "unable to load object header") + HDassert(H5F_addr_defined(loc->addr)); + HDassert(oh); - /* Call the "real" exists routine */ - if((ret_value = H5O_exists_oh(oh, type_id, sequence)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_READERROR, FAIL, "unable to verify object header message") + /* Release the object header from the cache */ + if(H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, oh_flags) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_PROTECT, FAIL, "unable to release object header") done: - if(oh && H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, H5AC__NO_FLAGS_SET) != SUCCEED) - HDONE_ERROR(H5E_OHDR, H5E_PROTECT, FAIL, "unable to release object header") - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_exists() */ +} /* end H5O_unprotect() */ /*------------------------------------------------------------------------- - * Function: H5O_exists_oh - * - * Purpose: Determines if a particular message exists in an object - * header without trying to decode the message. + * Function: H5O_touch_oh * - * Return: Success: FALSE if the message does not exist; TRUE if - * th message exists. + * Purpose: If FORCE is non-zero then create a modification time message + * unless one already exists. Then update any existing + * modification time message with the current time. * - * Failure: FAIL if the existence of the message could - * not be determined due to some error such as - * not being able to read the object header. + * Return: Non-negative on success/Negative on failure * * Programmer: Robb Matzke - * Monday, November 2, 1998 + * Monday, July 27, 1998 * *------------------------------------------------------------------------- */ -htri_t -H5O_exists_oh(H5O_t *oh, unsigned type_id, int sequence) +herr_t +H5O_touch_oh(H5F_t *f, + hid_t dxpl_id, + H5O_t *oh, + hbool_t force, + unsigned * oh_flags_ptr) { - const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ - unsigned u; /* Local index variable */ - htri_t ret_value; /* Return value */ + time_t now; /* Current time */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_exists_oh) - - 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(sequence >= 0); - - /* Scan through the messages looking for the right one */ - for(u = 0; u < oh->nmesgs; u++) { - if(type->id != oh->mesg[u].type->id) - continue; - if(--sequence < 0) - break; - } /* end for */ - - /* Set return value */ - ret_value = (sequence < 0); - - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_exists_oh() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_protect - * - * Purpose: Wrapper around H5AC_protect for use during a H5O_protect-> - * H5O_msg_append->...->H5O_msg_append->H5O_unprotect sequence of calls - * during an object's creation. - * - * Return: Success: Pointer to the object header structure for the - * object. - * - * Failure: NULL - * - * Programmer: Quincey Koziol - * koziol@ncsa.uiuc.edu - * Dec 31 2002 - * - *------------------------------------------------------------------------- - */ -H5O_t * -H5O_protect(H5O_loc_t *loc, hid_t dxpl_id) -{ - H5O_t *ret_value; /* Return value */ - - FUNC_ENTER_NOAPI(H5O_protect, NULL) - - /* check args */ - HDassert(loc); - HDassert(loc->file); - HDassert(H5F_addr_defined(loc->addr)); - - /* Check for write access on the file */ - if(0 == (H5F_INTENT(loc->file) & H5F_ACC_RDWR)) - HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, NULL, "no write intent on file") - - /* Lock the object header into the cache */ - if(NULL == (ret_value = H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_WRITE))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "unable to load object header") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_protect() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_unprotect - * - * Purpose: Wrapper around H5AC_unprotect for use during a H5O_protect-> - * H5O_msg_append->...->H5O_msg_append->H5O_unprotect sequence of calls - * during an object's creation. - * - * Return: Success: Non-negative - * - * Failure: Negative - * - * Programmer: Quincey Koziol - * koziol@ncsa.uiuc.edu - * Dec 31 2002 - * - *------------------------------------------------------------------------- - */ -herr_t -H5O_unprotect(H5O_loc_t *loc, H5O_t *oh, hid_t dxpl_id, unsigned oh_flags) -{ - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI(H5O_unprotect, FAIL) - - /* check args */ - HDassert(loc); - HDassert(loc->file); - HDassert(H5F_addr_defined(loc->addr)); - HDassert(oh); - - /* Release the object header from the cache */ - if(H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, oh_flags) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_PROTECT, FAIL, "unable to release object header") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_unprotect() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_touch_oh - * - * Purpose: If FORCE is non-zero then create a modification time message - * unless one already exists. Then update any existing - * modification time message with the current time. - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Robb Matzke - * Monday, July 27, 1998 - * - *------------------------------------------------------------------------- - */ -herr_t -H5O_touch_oh(H5F_t *f, - hid_t dxpl_id, - H5O_t *oh, - hbool_t force, - unsigned * oh_flags_ptr) -{ - time_t now; /* Current time */ - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT(H5O_touch_oh) + FUNC_ENTER_NOAPI_NOINIT(H5O_touch_oh) HDassert(oh); HDassert(oh_flags_ptr); @@ -1480,567 +1251,70 @@ H5O_bogus_oh(H5F_t *f, hid_t dxpl_id, H5O_t *oh, hbool_t * oh_flags_ptr) if((idx = H5O_alloc(f, dxpl_id, oh, H5O_MSG_BOGUS, size, oh_flags_ptr)) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to allocate space for 'bogus' message") - /* Allocate the native message in memory */ - if(NULL == (oh->mesg[idx].native = H5MM_malloc(sizeof(H5O_bogus_t)))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "memory allocation failed for 'bogus' message") - - /* Update the native part */ - ((H5O_bogus_t *)(oh->mesg[idx].native))->u = H5O_BOGUS_VALUE; - - /* Mark the message and object header as dirty */ - *oh_flags_ptr = TRUE; - oh->mesg[idx].dirty = TRUE; - oh->dirty = TRUE; - } /* end if */ - -done: - FUNC_LEAVE(ret_value) -} /* end H5O_bogus_oh() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_bogus - * - * Purpose: Create a "bogus" message in an object. - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Quincey Koziol - * - * Tuesday, January 21, 2003 - * - *------------------------------------------------------------------------- - */ -herr_t -H5O_bogus(H5O_loc_t *loc, hid_t dxpl_id) -{ - H5O_t *oh = NULL; - unsigned oh_flags = H5AC__NO_FLAGS_SET; - herr_t ret_value = SUCCEED; - - FUNC_ENTER(H5O_bogus, FAIL) - - /* check args */ - HDassert(loc); - HDassert(loc->file); - HDassert(H5F_addr_defined(loc->addr)); - - /* Verify write access to the file */ - if(0 == (H5F_INTENT(loc->file) & H5F_ACC_RDWR)) - HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "no write intent on file") - - /* Get 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") - - /* Create the "bogus" message */ - if(H5O_bogus_oh(ent->file, dxpl_id, oh, &oh_flags) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to update object 'bogus' message") - -done: - if(oh && H5AC_unprotect(ent->file, dxpl_id, H5AC_OHDR, ent->header, oh, oh_flags) < 0) - HDONE_ERROR(H5E_OHDR, H5E_PROTECT, FAIL, "unable to release object header") - - FUNC_LEAVE(ret_value) -} /* end H5O_bogus() */ -#endif /* H5O_ENABLE_BOGUS */ - - -/*------------------------------------------------------------------------- - * Function: H5O_remove - * - * Purpose: Removes the specified message from the object header. - * If sequence is H5O_ALL (-1) then all messages of the - * specified type are removed. Removing a message causes - * the sequence numbers to change for subsequent messages of - * the same type. - * - * No attempt is made to join adjacent free areas of the - * object header into a single larger free area. - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Robb Matzke - * matzke@llnl.gov - * Aug 28 1997 - * - * Modifications: - * - * Robb Matzke, 7 Jan 1998 - * Does not remove constant messages. - * - * Changed to use IDs for types, instead of type objects, then - * call "real" routine. - * Quincey Koziol - * Feb 14 2003 - * - *------------------------------------------------------------------------- - */ -herr_t -H5O_remove(H5O_loc_t *loc, unsigned type_id, int sequence, hbool_t adj_link, hid_t dxpl_id) -{ - const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ - herr_t ret_value; /* Return value */ - - FUNC_ENTER_NOAPI(H5O_remove, FAIL) - - /* check args */ - HDassert(loc); - HDassert(loc->file); - HDassert(H5F_addr_defined(loc->addr)); - 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); - - /* Call the "real" remove routine */ - if((ret_value = H5O_remove_real(loc, type, sequence, NULL, NULL, adj_link, dxpl_id)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, FAIL, "unable to remove object header message") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_remove() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_remove_op - * - * Purpose: Removes messages from the object header that a callback - * routine indicates should be removed. - * - * No attempt is made to join adjacent free areas of the - * object header into a single larger free area. - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Quincey Koziol - * koziol@ncsa.uiuc.edu - * Sep 6 2005 - * - *------------------------------------------------------------------------- - */ -herr_t -H5O_remove_op(const H5O_loc_t *loc, unsigned type_id, int sequence, - H5O_operator_t op, void *op_data, hbool_t adj_link, hid_t dxpl_id) -{ - const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ - herr_t ret_value; /* Return value */ - - FUNC_ENTER_NOAPI(H5O_remove_op, FAIL) - - /* check args */ - HDassert(loc); - HDassert(loc->file); - HDassert(H5F_addr_defined(loc->addr)); - 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); - - /* Call the "real" remove routine */ - if((ret_value = H5O_remove_real(loc, type, sequence, op, op_data, adj_link, dxpl_id)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, FAIL, "unable to remove object header message") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_remove_op() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_remove_cb - * - * Purpose: Object header iterator callback routine to remove messages - * of a particular type that match a particular sequence number, - * or all messages if the sequence number is H5O_ALL (-1). - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Quincey Koziol - * koziol@ncsa.uiuc.edu - * Sep 6 2005 - * - *------------------------------------------------------------------------- - */ -static herr_t -H5O_remove_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, - unsigned sequence, unsigned *oh_flags_ptr, void *_udata/*in,out*/) -{ - H5O_iter_ud1_t *udata = (H5O_iter_ud1_t *)_udata; /* Operator user data */ - htri_t try_remove = FALSE; /* Whether to try removing a message */ - herr_t ret_value = H5_ITER_CONT; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT(H5O_remove_cb) - - /* check args */ - HDassert(mesg); - - /* Check for callback routine */ - if(udata->op) { - /* Call the iterator callback */ - if((try_remove = (udata->op)(mesg->native, sequence, udata->op_data)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, H5_ITER_ERROR, "object header message deletion callback failed") - } /* end if */ - else { - /* If there's no callback routine, does the sequence # match? */ - if((int)sequence == udata->sequence || H5O_ALL == udata->sequence) - try_remove = H5_ITER_STOP; - } /* end else */ - - /* Try removing the message, if indicated */ - if(try_remove) { - /* - * Keep track of how many times we failed trying to remove constant - * messages. - */ - if(mesg->flags & H5O_MSG_FLAG_CONSTANT) - udata->nfailed++; - else { - /* Convert message into a null message */ - if(H5O_release_mesg(udata->f, udata->dxpl_id, oh, mesg, TRUE, udata->adj_link) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, H5_ITER_ERROR, "unable to convert into null message") - - /* Indicate that the object header was modified */ - *oh_flags_ptr |= H5AC__DIRTIED_FLAG; - } /* end else */ - - /* Break out now, if we've found the correct message */ - if(udata->sequence == H5O_FIRST || udata->sequence != H5O_ALL) - HGOTO_DONE(H5_ITER_STOP) - } /* end if */ - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_remove_cb() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_remove_real - * - * Purpose: Removes the specified message from the object header. - * If sequence is H5O_ALL (-1) then all messages of the - * specified type are removed. Removing a message causes - * the sequence numbers to change for subsequent messages of - * the same type. - * - * No attempt is made to join adjacent free areas of the - * object header into a single larger free area. - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Robb Matzke - * matzke@llnl.gov - * Aug 28 1997 - * - *------------------------------------------------------------------------- - */ -static herr_t -H5O_remove_real(const H5O_loc_t *loc, const H5O_msg_class_t *type, int sequence, - H5O_operator_t app_op, void *op_data, hbool_t adj_link, hid_t dxpl_id) -{ - H5O_iter_ud1_t udata; /* User data for iterator */ - H5O_mesg_operator_t op; /* Wrapper for operator */ - herr_t ret_value=SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT(H5O_remove_real) - - /* check args */ - HDassert(loc); - HDassert(loc->file); - HDassert(type); - - /* Make certain we are allowed to modify the file */ - if(0 == (H5F_INTENT(loc->file) & H5F_ACC_RDWR)) - HGOTO_ERROR(H5E_HEAP, H5E_WRITEERROR, FAIL, "no write intent on file") - - /* Set up iterator operator data */ - udata.f = loc->file; - udata.dxpl_id = dxpl_id; - udata.sequence = sequence; - udata.nfailed = 0; - udata.op = app_op; - udata.op_data = op_data; - udata.adj_link = adj_link; - - /* Iterate over the messages, deleting appropriate one(s) */ - op.lib_op = H5O_remove_cb; - if(H5O_iterate_real(loc, type, H5AC_WRITE, TRUE, op, &udata, dxpl_id) < 0) - HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "error iterating over messages") - - /* Fail if we tried to remove any constant messages */ - if(udata.nfailed) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to remove constant message(s)") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_remove_real() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_raw_size - * - * Purpose: Call the 'raw_size' method for a - * particular class of object header. - * - * Return: Size of message on success, 0 on failure - * - * Programmer: Quincey Koziol - * koziol@ncsa.uiuc.edu - * Feb 13 2003 - * - *------------------------------------------------------------------------- - */ -size_t -H5O_raw_size(unsigned type_id, const H5F_t *f, const void *mesg) -{ - const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ - size_t ret_value; /* Return value */ - - FUNC_ENTER_NOAPI(H5O_raw_size, 0) - - /* Check args */ - 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(type->raw_size); - HDassert(f); - HDassert(mesg); - - /* Compute the raw data size for the mesg */ - if((ret_value = (type->raw_size)(f, mesg)) == 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTCOUNT, 0, "unable to determine size of message") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_raw_size() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_mesg_size - * - * 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 - * koziol@ncsa.uiuc.edu - * Sep 6 2005 - * - *------------------------------------------------------------------------- - */ -size_t -H5O_mesg_size(unsigned type_id, const H5F_t *f, const void *mesg, size_t extra_raw) -{ - const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ - size_t ret_value; /* Return value */ - - FUNC_ENTER_NOAPI(H5O_mesg_size, 0) - - /* Check args */ - 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(type->raw_size); - HDassert(f); - HDassert(mesg); - - /* Compute the raw data size for the mesg */ - if((ret_value = (type->raw_size)(f, mesg)) == 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTCOUNT, 0, "unable to determine size of message") - - /* Add in "extra" raw space */ - ret_value += extra_raw; - - /* Adjust size for alignment, if necessary */ - ret_value = H5O_ALIGN_F(f, ret_value); - - /* Add space for message header */ - ret_value += H5O_SIZEOF_MSGHDR_F(f); - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_mesg_size() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_get_share - * - * Purpose: Call the 'get_share' method for a - * particular class of object header. - * - * Return: Success: Non-negative, and SHARE describes the shared - * object. - * - * Failure: Negative - * - * Programmer: Quincey Koziol - * koziol@ncsa.uiuc.edu - * Oct 2 2003 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -herr_t -H5O_get_share(unsigned type_id, H5F_t *f, const void *mesg, H5O_shared_t *share) -{ - const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ - herr_t ret_value; /* Return value */ - - FUNC_ENTER_NOAPI(H5O_get_share,FAIL) - - /* Check args */ - 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(type->get_share); - HDassert(f); - HDassert(mesg); - HDassert(share); - - /* Get shared data for the mesg */ - if((ret_value = (type->get_share)(f, mesg, share)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, FAIL, "unable to retrieve shared message information") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_get_share() */ - - - -/*------------------------------------------------------------------------- - * Function: H5O_is_shared - * - * Purpose: Call the 'is_shared' method for a - * particular class of object header. - * - * Return: Object is shared: TRUE - * Object is not shared: FALSE - * - * Programmer: James Laird - * jlaird@ncsa.uiuc.edu - * April 5 2006 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -htri_t -H5O_is_shared(unsigned type_id, const void *mesg) -{ - const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ - htri_t ret_value; - - FUNC_ENTER_NOAPI_NOFUNC(H5O_is_shared) - - /* Check args */ - 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(mesg); - - HDassert(type_id != H5O_SHARED_ID); /* JAMES: check for this mistake elsewhere, too */ - - /* If there is no is_shared function, then obviously it's not a shared message! */ - if( !(type->is_shared)) - ret_value = FALSE; - else - ret_value = (type->is_shared)(mesg); - - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_is_shared() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_set_share - * - * Purpose: Set the shared information for an object header message. - * - * Return: Success: Non-negative - * Failure: Negative - * - * Programmer: James Laird - * jlaird@hdfgroup.org - * November 1 2006 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -herr_t -H5O_set_share(H5F_t *f, H5O_shared_t *share, unsigned type_id, void *mesg) -{ - const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ - herr_t ret_value; /* Return value */ - - FUNC_ENTER_NOAPI(H5O_set_share,FAIL) + /* Allocate the native message in memory */ + if(NULL == (oh->mesg[idx].native = H5MM_malloc(sizeof(H5O_bogus_t)))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "memory allocation failed for 'bogus' message") - /* Check args */ - HDassert(f); - HDassert(share); - 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(type->set_share); - HDassert(mesg); - HDassert(share->flags != H5O_NOT_SHARED); - - /* Set this message as the shared message for the message, wiping out - * any information that was there before - */ - if((ret_value = (type->set_share)(f, mesg, share)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTSET, FAIL, "unable to set shared message information") + /* Update the native part */ + ((H5O_bogus_t *)(oh->mesg[idx].native))->u = H5O_BOGUS_VALUE; + + /* Mark the message and object header as dirty */ + *oh_flags_ptr = TRUE; + oh->mesg[idx].dirty = TRUE; + oh->dirty = TRUE; + } /* end if */ done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_set_share() */ + FUNC_LEAVE(ret_value) +} /* end H5O_bogus_oh() */ /*------------------------------------------------------------------------- - * Function: H5O_reset_share - * - * Purpose: Reset the shared information for an object header message. + * Function: H5O_bogus * - * Return: Success: Non-negative - * Failure: Negative + * Purpose: Create a "bogus" message in an object. * - * Programmer: James Laird - * jlaird@hdfgroup.org - * Oct 17 2006 + * Return: Non-negative on success/Negative on failure * - * Modifications: + * Programmer: Quincey Koziol + * + * Tuesday, January 21, 2003 * *------------------------------------------------------------------------- */ herr_t -H5O_reset_share(H5F_t *f, unsigned type_id, void *mesg) +H5O_bogus(H5O_loc_t *loc, hid_t dxpl_id) { - const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ - H5O_shared_t sh_mesg; /* Shared message */ - herr_t ret_value; /* Return value */ + H5O_t *oh = NULL; + unsigned oh_flags = H5AC__NO_FLAGS_SET; + herr_t ret_value = SUCCEED; + + FUNC_ENTER(H5O_bogus, FAIL) - FUNC_ENTER_NOAPI(H5O_reset_share,FAIL) + /* check args */ + HDassert(loc); + HDassert(loc->file); + HDassert(H5F_addr_defined(loc->addr)); - /* Check args */ - 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(type->set_share); - HDassert(mesg); + /* Verify write access to the file */ + if(0 == (H5F_INTENT(loc->file) & H5F_ACC_RDWR)) + HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "no write intent on file") - /* Initialize the shared message to zero. */ - HDmemset(&sh_mesg, 0, sizeof(H5O_shared_t)); + /* Get 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") - /* Set this message as the shared message for the message, wiping out - * any information that was there before - */ - if((ret_value = (type->set_share)(f, mesg, &sh_mesg)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTSET, FAIL, "unable to reset shared message information") + /* Create the "bogus" message */ + if(H5O_bogus_oh(ent->file, dxpl_id, oh, &oh_flags) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to update object 'bogus' message") done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_reset_share() */ + if(oh && H5AC_unprotect(ent->file, dxpl_id, H5AC_OHDR, ent->header, oh, oh_flags) < 0) + HDONE_ERROR(H5E_OHDR, H5E_PROTECT, FAIL, "unable to release object header") + + FUNC_LEAVE(ret_value) +} /* end H5O_bogus() */ +#endif /* H5O_ENABLE_BOGUS */ /*------------------------------------------------------------------------- @@ -2136,347 +1410,6 @@ done: /*------------------------------------------------------------------------- - * Function: H5O_delete_mesg - * - * Purpose: Internal function to: - * Delete an object header message from a file. This frees the file - * space used for anything referred to in the object header message. - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Quincey Koziol - * koziol@ncsa.uiuc.edu - * September 26 2003 - * - *------------------------------------------------------------------------- - */ -herr_t -H5O_delete_mesg(H5F_t *f, hid_t dxpl_id, H5O_mesg_t *mesg, hbool_t adj_link) -{ - const H5O_msg_class_t *type; /* Type of object to free */ - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI(H5O_delete_mesg, FAIL) - - /* Check args */ - HDassert(f); - HDassert(mesg); - - /* Get the message to free's type */ - if(mesg->flags & H5O_MSG_FLAG_SHARED) - type = H5O_MSG_SHARED; - else - type = mesg->type; - - /* Check if there is a file space deletion callback for this type of message */ - if(type->del) { - /* Decode the message if necessary. */ - if(NULL == mesg->native) { - HDassert(type->decode); - if(NULL == (mesg->native = (type->decode)(f, dxpl_id, mesg->raw))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTDECODE, FAIL, "unable to decode message") - } /* end if */ - - /* Check if this message needs to be removed from the SOHM table */ - /* JAMES: there should be a callback, maybe in H5O_shared_delete, to fiddle w/ the ref. count. - * We shouldn't need to do a search in the SOHM table on delete. */ - if(type == H5O_MSG_SHARED) - { - /* The native message here is actually a shared message. */ - if(H5SM_try_delete(f, dxpl_id, mesg->type->id, mesg->native) < 0) - HGOTO_ERROR (H5E_OHDR, H5E_CANTFREE, FAIL, "unable to delete message from SOHM table") - } - - if((type->del)(f, dxpl_id, mesg->native, adj_link) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, FAIL, "unable to delete file space for object header message") - } /* end if */ - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_delete_msg() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_encode - * - * Purpose: Encode an object(data type and simple data space only) - * description into a buffer. - * - * Return: Success: Non-negative - * - * Failure: Negative - * - * Programmer: Raymond Lu - * slu@ncsa.uiuc.edu - * July 13, 2004 - * - *------------------------------------------------------------------------- - */ -herr_t -H5O_encode(H5F_t *f, unsigned char *buf, const void *obj, unsigned type_id) -{ - const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI(H5O_encode,FAIL) - - /* check args */ - HDassert(f); - 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); - - /* Encode */ - if((type->encode)(f, buf, obj) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to encode message") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_encode() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_decode - * - * Purpose: Decode a binary object description and return a new - * object handle. - * - * Note: This routine is not guaranteed to work with all possible - * header messages, use with care. - * - * Return: Success: Pointer to object(data type or space) - * - * Failure: NULL - * - * Programmer: Raymond Lu - * slu@ncsa.uiuc.edu - * July 14, 2004 - * - *------------------------------------------------------------------------- - */ -void * -H5O_decode(H5F_t *f, hid_t dxpl_id, const unsigned char *buf, unsigned type_id) -{ - const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ - void *ret_value; /* Return value */ - - FUNC_ENTER_NOAPI(H5O_decode, NULL) - - /* check args */ - HDassert(f); - 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); - - /* decode */ - if((ret_value = (type->decode)(f, dxpl_id, buf)) == NULL) - HGOTO_ERROR(H5E_OHDR, H5E_CANTDECODE, NULL, "unable to decode message") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_decode() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_iterate - * - * Purpose: Iterate through object headers of a certain type. - * - * Return: Returns a negative value if something is wrong, the return - * value of the last operator if it was non-zero, or zero if all - * object headers were processed. - * - * Programmer: Quincey Koziol - * koziol@ncsa.uiuc.edu - * Nov 19 2004 - * - * Description: - * This function interates over the object headers of an object - * specified with 'ent' of type 'type_id'. For each object header of the - * object, the 'op_data' and some additional information (specified below) are - * passed to the 'op' function. - * The operation receives a pointer to the object header message for the - * object being iterated over ('mesg'), and the pointer to the operator data - * passed in to H5O_iterate ('op_data'). The return values from an operator - * are: - * A. Zero causes the iterator to continue, returning zero when all - * object headers of that type have been processed. - * B. Positive causes the iterator to immediately return that positive - * value, indicating short-circuit success. - * C. Negative causes the iterator to immediately return that value, - * indicating failure. - * - *------------------------------------------------------------------------- - */ -herr_t -H5O_iterate(const H5O_loc_t *loc, unsigned type_id, H5O_operator_t app_op, - void *op_data, hid_t dxpl_id) -{ - const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ - H5O_mesg_operator_t op; /* Wrapper for operator */ - herr_t ret_value; /* Return value */ - - FUNC_ENTER_NOAPI(H5O_iterate, FAIL) - - /* check args */ - HDassert(loc); - HDassert(loc->file); - HDassert(H5F_addr_defined(loc->addr)); - 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); - - /* Call the "real" iterate routine */ - op.app_op = app_op; - if((ret_value = H5O_iterate_real(loc, type, H5AC_READ, FALSE, op, op_data, dxpl_id)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_BADITER, FAIL, "unable to iterate over object header messages") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_iterate() */ - - -/*------------------------------------------------------------------------- - * Function: H5O_iterate_real - * - * Purpose: Iterate through object headers of a certain type. - * - * Return: Returns a negative value if something is wrong, the return - * value of the last operator if it was non-zero, or zero if all - * object headers were processed. - * - * Programmer: Quincey Koziol - * koziol@ncsa.uiuc.edu - * Sep 6 2005 - * - * Description: - * This function interates over the object headers of an object - * specified with 'ent' of type 'type_id'. For each object header of the - * object, the 'op_data' and some additional information (specified below) are - * passed to the 'op' function. - * The operation receives a pointer to the object header message for the - * object being iterated over ('mesg'), and the pointer to the operator data - * passed in to H5O_iterate ('op_data'). The return values from an operator - * are: - * A. Zero causes the iterator to continue, returning zero when all - * object headers of that type have been processed. - * B. Positive causes the iterator to immediately return that positive - * value, indicating short-circuit success. - * C. Negative causes the iterator to immediately return that value, - * indicating failure. - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -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) -{ - H5O_t *oh = NULL; /* Pointer to actual object header */ - unsigned oh_flags = H5AC__NO_FLAGS_SET; /* Start iteration with no flags set on object header */ - unsigned idx; /* Absolute index of current message in all messages */ - unsigned sequence; /* Relative index of current message for messages of type */ - H5O_mesg_t *idx_msg; /* Pointer to current message */ - void *native_mesg; /* Native, readable message */ - hbool_t native_mesg_alloc = FALSE; /* True if native_mesg needs to be freed */ - - herr_t ret_value = H5_ITER_CONT; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT(H5O_iterate_real) - - /* check args */ - HDassert(loc); - HDassert(loc->file); - HDassert(H5F_addr_defined(loc->addr)); - HDassert(type); - HDassert(op.app_op); - - /* 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") - - /* Iterate over messages */ - for(sequence = 0, idx = 0, idx_msg = &oh->mesg[0]; idx < oh->nmesgs && !ret_value; idx++, idx_msg++) { - if(type->id == idx_msg->type->id) { - - /* - * Decode the message if necessary. - */ - H5O_LOAD_NATIVE(loc->file, dxpl_id, idx_msg, FAIL) - - /* Check for making an "internal" (i.e. within the H5O package) callback */ - if(internal) { - /* Call the "internal" iterator callback */ - if((ret_value = (op.lib_op)(oh, idx_msg, sequence, &oh_flags, op_data)) != 0) - break; - } /* end if */ - else { - /* If the message is shared, get the real message it points to */ - /* JAMES: test */ - if(idx_msg->flags & H5O_MSG_FLAG_SHARED) { - if(NULL == (native_mesg = H5O_shared_read(loc->file, dxpl_id, - idx_msg->native, idx_msg->type, NULL))) - HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "unable to read shared message"); - native_mesg_alloc = TRUE; - } - else { - native_mesg = idx_msg->native; - } - - /* Call the iterator callback */ - if((ret_value = (op.app_op)(native_mesg, sequence, op_data)) != 0) - break; - - /* Free the "real" message if it was allocated */ - if(native_mesg_alloc) { - H5O_msg_free(idx_msg->type->id, native_mesg); - native_mesg_alloc = FALSE; - } - } /* end else */ - - /* Check for error from iterator */ - if(ret_value < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "iterator function failed") - - /* Increment sequence value for message type */ - sequence++; - } /* end if */ - } /* end for */ - -done: - /* Free the native message if it was allocated */ - if(native_mesg_alloc) { - H5O_msg_free(idx_msg->type->id, native_mesg); - native_mesg_alloc = FALSE; - } - - if(oh) { - /* Check if object header was modified */ - if(oh_flags & H5AC__DIRTIED_FLAG) { - /* Shouldn't be able to modify object header if we don't have write access */ - HDassert(prot == H5AC_WRITE); - - /* Try to condense object header info */ - /* (Since this routine is invoked when a message is removed from - * an object header, the header will be condensed after each - * message removal) - */ - if(H5O_condense_header(loc->file, oh, dxpl_id) < 0) - HDONE_ERROR(H5E_OHDR, H5E_CANTPACK, FAIL, "can't pack object header") - - H5O_touch_oh(loc->file, dxpl_id, oh, FALSE, &oh_flags); - } /* end if */ - - if(H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, oh_flags) < 0) - HDONE_ERROR(H5E_OHDR, H5E_PROTECT, FAIL, "unable to release object header") - } /* end if */ - - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_iterate_real() */ - - -/*------------------------------------------------------------------------- * Function: H5O_obj_type * * Purpose: Retrieves the type of object pointed to by `loc'. @@ -2631,6 +1564,52 @@ done: /*------------------------------------------------------------------------- + * Function: H5O_get_loc + * + * Purpose: Gets the object location for an object given its ID. + * + * Return: Success: Pointer to H5O_loc_t + * Failure: NULL + * + * Programmer: James Laird + * July 25 2006 + * + *------------------------------------------------------------------------- + */ +static H5O_loc_t * +H5O_get_loc(hid_t object_id) +{ + H5O_loc_t *ret_value; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5O_get_loc) + + switch(H5I_get_type(object_id)) + { + case(H5I_GROUP): + if(NULL == (ret_value = H5O_OBJ_GROUP->get_oloc(object_id))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, NULL, "unable to get object location from group ID") + break; + + case(H5I_DATASET): + if(NULL == (ret_value = H5O_OBJ_DATASET->get_oloc(object_id))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, NULL, "unable to get object location from dataset ID") + break; + + case(H5I_DATATYPE): + if(NULL == (ret_value = H5O_OBJ_DATATYPE->get_oloc(object_id))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, NULL, "unable to get object location from datatype ID") + break; + + default: + HGOTO_ERROR(H5E_OHDR, H5E_BADTYPE, NULL, "invalid object type") + } /* end switch */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_get_loc() */ + + +/*------------------------------------------------------------------------- * Function: H5O_loc_reset * * Purpose: Reset a object location to an empty state @@ -2770,15 +1749,14 @@ H5O_loc_free(H5O_loc_t *loc) HDassert(loc); /* If this location is holding its file open try to close the file. */ - if(loc->holding_file) - { + if(loc->holding_file) { loc->file->nopen_objs--; 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") - } - } + if(H5F_try_close(loc->file) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "can't close file") + } /* end if */ + } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -2786,46 +1764,6 @@ done: /*------------------------------------------------------------------------- - * Function: H5O_copy_mesg_file - * - * Purpose: Copies a message to file. If MESG is is the null pointer then a null - * pointer is returned with no error. - * - * Return: Success: Ptr to the new message - * - * Failure: NULL - * - * Programmer: Peter Cao - * June 4, 2005 - * - *------------------------------------------------------------------------- - */ -void * -H5O_copy_mesg_file(const H5O_msg_class_t *copy_type, const H5O_msg_class_t *mesg_type, H5F_t *file_src, void *native_src, - H5F_t *file_dst, hid_t dxpl_id, H5O_copy_t *cpy_info, void *udata) -{ - void *ret_value; - - FUNC_ENTER_NOAPI_NOINIT(H5O_copy_mesg_file) - - /* check args */ - HDassert(copy_type); - HDassert(mesg_type); - HDassert(copy_type->copy_file); - HDassert(file_src); - HDassert(native_src); - HDassert(file_dst); - HDassert(cpy_info); - - if(NULL == (ret_value = (copy_type->copy_file)(file_src, mesg_type, native_src, file_dst, dxpl_id, cpy_info, udata))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "unable to copy object header message to file") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_copy_mesg_file() */ - - -/*------------------------------------------------------------------------- * Function: H5O_get_info * * Purpose: Retrieve the information for an object @@ -3006,5 +1944,5 @@ done: HDONE_ERROR(H5E_OHDR, H5E_PROTECT, FAIL, "unable to release object header") FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_get_info() */ +} /* end H5O_get_create_plist() */ diff --git a/src/H5Oattr.c b/src/H5Oattr.c index 05fb4b9..fa104a9 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -43,10 +43,8 @@ static herr_t H5O_attr_pre_copy_file(H5F_t *file_src, const H5O_msg_class_t *typ static void *H5O_attr_copy_file(H5F_t *file_src, const H5O_msg_class_t *mesg_type, void *native_src, H5F_t *file_dst, hid_t dxpl_id, H5O_copy_t *cpy_info, void *udata); -static herr_t H5O_attr_get_share(H5F_t *f, const void *_mesg, - H5O_shared_t *sh); -static herr_t H5O_attr_set_share(H5F_t *f, void *_mesg, - const H5O_shared_t *sh); +static herr_t H5O_attr_get_share(const void *_mesg, H5O_shared_t *sh); +static herr_t H5O_attr_set_share(void *_mesg, const H5O_shared_t *sh); static htri_t H5O_attr_is_shared(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); @@ -306,7 +304,7 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg) { const H5A_t *attr = (const H5A_t *) mesg; size_t name_len; /* Attribute name length */ - htri_t is_shared_ret; /* Return value from H5O_is_shared */ + htri_t is_shared_ret; /* Return value from H5O_msg_is_shared */ unsigned version; /* Attribute version */ hbool_t type_shared; /* Flag to indicate that a shared datatype is used for this attribute */ hbool_t space_shared; /* Flag to indicate that a shared dataspace is used for this attribute */ @@ -326,14 +324,14 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg) use_latest_format = H5F_USE_LATEST_FORMAT(f); /* Check whether datatype and dataspace are shared */ - if((is_shared_ret = H5O_is_shared(H5O_DTYPE_ID, attr->dt)) < 0) + if((is_shared_ret = H5O_msg_is_shared(H5O_DTYPE_ID, attr->dt)) < 0) HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "can't determine if datatype is shared") else if(is_shared_ret) type_shared = TRUE; else type_shared = FALSE; - if((is_shared_ret = H5O_is_shared(H5O_SDSPACE_ID, attr->ds)) < 0) + if((is_shared_ret = H5O_msg_is_shared(H5O_SDSPACE_ID, attr->ds)) < 0) HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "can't determine if dataspace is shared") else if(is_shared_ret) space_shared = TRUE; @@ -399,7 +397,7 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg) HDmemset(&sh_mesg, 0, sizeof(H5O_shared_t)); /* Get shared message information from datatype */ - if((H5O_MSG_DTYPE->get_share)(f, attr->dt, &sh_mesg/*out*/) < 0) + if((H5O_MSG_DTYPE->get_share)(attr->dt, &sh_mesg/*out*/) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL, "can't encode shared attribute datatype") /* Encode shared message information for datatype */ @@ -425,7 +423,7 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg) HDmemset(&sh_mesg, 0, sizeof(H5O_shared_t)); /* Get shared message information from dataspace */ - if((H5O_MSG_SDSPACE->get_share)(f, attr->ds, &sh_mesg/*out*/) < 0) + if((H5O_MSG_SDSPACE->get_share)(attr->ds, &sh_mesg/*out*/) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL, "can't encode shared attribute dataspace") /* Encode shared message information for dataspace */ @@ -531,12 +529,12 @@ H5O_attr_size(const H5F_t *f, const void *_mesg) use_latest_format = H5F_USE_LATEST_FORMAT(f); /* Check whether datatype and dataspace are shared */ - if(H5O_is_shared(H5O_DTYPE_ID, attr->dt) > 0) + if(H5O_msg_is_shared(H5O_DTYPE_ID, attr->dt) > 0) type_shared = TRUE; else type_shared = FALSE; - if(H5O_is_shared(H5O_SDSPACE_ID, attr->ds) > 0) + if(H5O_msg_is_shared(H5O_SDSPACE_ID, attr->ds) > 0) space_shared = TRUE; else space_shared = FALSE; @@ -671,21 +669,21 @@ H5O_attr_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg, hbool_t adj_link) /* Remove both the datatype and dataspace from the SOHM heap if they're * shared there. */ - if((tri_ret = H5O_is_shared(H5O_DTYPE_ID, attr->dt)) < 0) + if((tri_ret = H5O_msg_is_shared(H5O_DTYPE_ID, attr->dt)) < 0) HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "can't tell if datatype is shared") if(tri_ret > 0) { - if(H5O_get_share(H5O_DTYPE_ID, f, attr->dt, &sh_mesg) < 0) + if(H5O_msg_get_share(H5O_DTYPE_ID, attr->dt, &sh_mesg) < 0) HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "can't get shared message from datatype") if(H5SM_try_delete(f, H5AC_dxpl_id, H5O_DTYPE_ID, &sh_mesg) < 0) HGOTO_ERROR(H5E_SOHM, H5E_CANTREMOVE, FAIL, "can't remove datatype from SOHM heap") } - if((tri_ret =H5O_is_shared(H5O_SDSPACE_ID, attr->ds)) < 0) + if((tri_ret =H5O_msg_is_shared(H5O_SDSPACE_ID, attr->ds)) < 0) HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "can't tell if dataspace is shared") if(tri_ret > 0) { - if(H5O_get_share(H5O_SDSPACE_ID, f, attr->ds, &sh_mesg) < 0) + if(H5O_msg_get_share(H5O_SDSPACE_ID, attr->ds, &sh_mesg) < 0) HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "can't get shared message from dataspace") if(H5SM_try_delete(f, H5AC_dxpl_id, H5O_SDSPACE_ID, &sh_mesg) < 0) HGOTO_ERROR(H5E_OHDR, H5E_SOHM, FAIL, "can't remove dataspace from SOHM heap") @@ -873,14 +871,14 @@ H5O_attr_copy_file(H5F_t *file_src, const H5O_msg_class_t UNUSED *mesg_type, HDmemset(&sh_mesg, 0, sizeof(H5O_shared_t)); /* Get shared message information for datatype */ - if(H5O_get_share(H5O_DTYPE_ID, file_dst, attr_src->dt, &sh_mesg/*out*/) < 0) + if(H5O_msg_get_share(H5O_DTYPE_ID, attr_src->dt, &sh_mesg/*out*/) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, NULL, "unable to get shared message") /* Compute shared message size for datatype */ - attr_dst->dt_size = H5O_raw_size(H5O_SHARED_ID, file_dst, &sh_mesg); + attr_dst->dt_size = H5O_msg_raw_size(file_dst, H5O_SHARED_ID, &sh_mesg); } /* end if */ else - attr_dst->dt_size = H5O_raw_size(H5O_DTYPE_ID, file_dst, attr_src->dt); + attr_dst->dt_size = H5O_msg_raw_size(file_dst, H5O_DTYPE_ID, attr_src->dt); HDassert(attr_dst->dt_size > 0); attr_dst->ds_size = H5S_raw_size(file_dst, attr_src->ds); HDassert(attr_dst->ds_size > 0); @@ -1056,13 +1054,10 @@ done: * Programmer: James Laird * Tuesday, October 17, 2006 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t -H5O_attr_get_share(H5F_t UNUSED *f, const void *_mesg, - H5O_shared_t *sh /*out*/) +H5O_attr_get_share(const void *_mesg, H5O_shared_t *sh /*out*/) { const H5A_t *mesg = (const H5A_t *)_mesg; herr_t ret_value = SUCCEED; @@ -1076,7 +1071,7 @@ H5O_attr_get_share(H5F_t UNUSED *f, const void *_mesg, ret_value = FAIL; FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5O_attr_get_share() */ /*------------------------------------------------------------------------- @@ -1089,13 +1084,10 @@ H5O_attr_get_share(H5F_t UNUSED *f, const void *_mesg, * Programmer: James Laird * Tuesday, October 10, 2006 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t -H5O_attr_set_share(H5F_t UNUSED *f, void *_mesg/*in,out*/, - const H5O_shared_t *sh) +H5O_attr_set_share(void *_mesg/*in,out*/, const H5O_shared_t *sh) { H5A_t *mesg = (H5A_t *)_mesg; herr_t ret_value = SUCCEED; @@ -1109,7 +1101,7 @@ H5O_attr_set_share(H5F_t UNUSED *f, void *_mesg/*in,out*/, ret_value = FAIL; FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5O_attr_set_share() */ /*------------------------------------------------------------------------- @@ -1212,7 +1204,7 @@ H5O_attr_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int in HDmemset(&sh_mesg, 0, sizeof(H5O_shared_t)); /* Get shared message information from datatype */ - if((H5O_MSG_DTYPE->get_share)(f, mesg->dt, &sh_mesg/*out*/) < 0) + if((H5O_MSG_DTYPE->get_share)(mesg->dt, &sh_mesg/*out*/) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL, "can't retrieve shared message information") debug = H5O_MSG_SHARED->debug; diff --git a/src/H5Ocopy.c b/src/H5Ocopy.c index 38f4f43..9048d25 100644 --- a/src/H5Ocopy.c +++ b/src/H5Ocopy.c @@ -500,7 +500,7 @@ H5O_copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, } /* end if (NULL == mesg_src->native) */ /* Copy the source message */ - if((mesg_dst->native = H5O_copy_mesg_file(copy_type, mesg_dst->type, + if((mesg_dst->native = H5O_msg_copy_file(copy_type, mesg_dst->type, oloc_src->file, mesg_src->native, oloc_dst->file, dxpl_id, cpy_info, udata)) == NULL) HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, FAIL, "unable to copy object header message") diff --git a/src/H5Odtype.c b/src/H5Odtype.c index 32f01f5..eff0d24 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -33,8 +33,8 @@ static void *H5O_dtype_copy(const void *_mesg, void *_dest, unsigned update_flag static size_t H5O_dtype_size(const H5F_t *f, const void *_mesg); static herr_t H5O_dtype_reset(void *_mesg); static herr_t H5O_dtype_free(void *_mesg); -static herr_t H5O_dtype_get_share(H5F_t *f, const void *_mesg, H5O_shared_t *sh); -static herr_t H5O_dtype_set_share(H5F_t *f, void *_mesg, const H5O_shared_t *sh); +static herr_t H5O_dtype_get_share(const void *_mesg, H5O_shared_t *sh); +static herr_t H5O_dtype_set_share(void *_mesg, const H5O_shared_t *sh); static herr_t H5O_dtype_is_shared(const void *_mesg); static herr_t H5O_dtype_pre_copy_file(H5F_t *file_src, const H5O_msg_class_t *type, const void *mesg_src, hbool_t *deleted, const H5O_copy_t *cpy_info, void *_udata); @@ -1269,8 +1269,7 @@ H5O_dtype_free(void *mesg) *------------------------------------------------------------------------- */ static herr_t -H5O_dtype_get_share(H5F_t UNUSED *f, const void *_mesg, - H5O_shared_t *sh/*out*/) +H5O_dtype_get_share(const void *_mesg, H5O_shared_t *sh/*out*/) { const H5T_t *dt = (const H5T_t *)_mesg; herr_t ret_value = SUCCEED; /* Return value */ @@ -1312,8 +1311,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5O_dtype_set_share(H5F_t UNUSED *f, void *_mesg/*in,out*/, - const H5O_shared_t *sh) +H5O_dtype_set_share(void *_mesg/*in,out*/, const H5O_shared_t *sh) { H5T_t *dt = (H5T_t *)_mesg; herr_t ret_value = SUCCEED; diff --git a/src/H5Ofill.c b/src/H5Ofill.c index 9ad1b84..fedbfd2 100644 --- a/src/H5Ofill.c +++ b/src/H5Ofill.c @@ -45,10 +45,8 @@ static void *H5O_fill_copy(const void *_mesg, void *_dest, unsigned update_flag static size_t H5O_fill_size(const H5F_t *f, const void *_mesg); static herr_t H5O_fill_reset(void *_mesg); static herr_t H5O_fill_free(void *_mesg); -static herr_t H5O_fill_new_get_share(H5F_t *f, const void *_mesg, - H5O_shared_t *sh); -static herr_t H5O_fill_new_set_share(H5F_t *f, void *_mesg, - const H5O_shared_t *sh); +static herr_t H5O_fill_new_get_share(const void *_mesg, H5O_shared_t *sh); +static herr_t H5O_fill_new_set_share(void *_mesg, const H5O_shared_t *sh); static htri_t H5O_fill_new_is_shared(const void *_mesg); static herr_t H5O_fill_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE *stream, int indent, int fwidth); @@ -680,13 +678,10 @@ H5O_fill_free (void *mesg) * Programmer: James Laird * Tuesday, October 10, 2006 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t -H5O_fill_new_get_share(H5F_t UNUSED *f, const void *_mesg, - H5O_shared_t *sh /*out*/) +H5O_fill_new_get_share(const void *_mesg, H5O_shared_t *sh /*out*/) { const H5O_fill_new_t *mesg = (const H5O_fill_new_t *)_mesg; herr_t ret_value = SUCCEED; @@ -713,13 +708,10 @@ H5O_fill_new_get_share(H5F_t UNUSED *f, const void *_mesg, * Programmer: James Laird * Tuesday, October 10, 2006 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t -H5O_fill_new_set_share(H5F_t UNUSED *f, void *_mesg/*in,out*/, - const H5O_shared_t *sh) +H5O_fill_new_set_share(void *_mesg/*in,out*/, const H5O_shared_t *sh) { H5O_fill_new_t *mesg = (H5O_fill_new_t *)_mesg; herr_t ret_value = SUCCEED; diff --git a/src/H5Omessage.c b/src/H5Omessage.c index c244899..27c0c02 100644 --- a/src/H5Omessage.c +++ b/src/H5Omessage.c @@ -49,6 +49,27 @@ /* Local Typedefs */ /******************/ +/* User data for iteration while removing a message */ +typedef struct { + H5F_t *f; /* Pointer to file for insertion */ + hid_t dxpl_id; /* DXPL during iteration */ + int sequence; /* Sequence # to search for */ + unsigned nfailed; /* # of failed message removals */ + H5O_operator_t op; /* Callback routine for removal operations */ + void *op_data; /* Callback data for removal operations */ + hbool_t adj_link; /* Whether to adjust links when removing messages */ +} H5O_iter_ud1_t; + +/* Typedef for "internal library" iteration operations */ +typedef herr_t (*H5O_lib_operator_t)(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, + unsigned sequence, unsigned *oh_flags_ptr/*out*/, void *operator_data/*in,out*/); + +/* Some syntactic sugar to make the compiler happy with two different kinds of iterator callbacks */ +typedef union { + H5O_operator_t app_op; /* Application callback for each message */ + H5O_lib_operator_t lib_op; /* Library internal callback for each message */ +} H5O_mesg_operator_t; + /********************/ /* Package Typedefs */ @@ -68,6 +89,12 @@ static herr_t H5O_msg_write_real(H5O_loc_t *loc, const H5O_msg_class_t *type, static herr_t H5O_msg_reset_real(const H5O_msg_class_t *type, void *native); static void *H5O_msg_copy_real(const H5O_msg_class_t *type, const void *mesg, void *dst); +static herr_t H5O_msg_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 herr_t H5O_msg_remove_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, + unsigned sequence, unsigned *oh_flags_ptr, void *_udata/*in,out*/); +static herr_t H5O_msg_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 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 unsigned H5O_new_mesg(H5F_t *f, H5O_t *oh, unsigned *flags, @@ -190,7 +217,7 @@ H5O_msg_append(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned type_id, unsigned me /* Mark the message as shared */ mesg_flags |= H5O_MSG_FLAG_SHARED; else if(shared_mesg < 0) - HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "error determining if message should be shared"); + HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "error determining if message should be shared") if(H5O_msg_append_real(f, dxpl_id, oh, type, mesg_flags, update_flags, mesg, oh_flags_ptr) < 0) HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "unable to append to object header") @@ -253,73 +280,6 @@ done: /*------------------------------------------------------------------------- - * Function: H5O_msg_hash - * - * Purpose: Returns a hash value for an object header message. - * - * Return: Non-H5O_HASH_UNDEF hash value on success - * H5O_HASH_UNDEF on failure - * - * Programmer: James Laird - * April 13 2006 - * - *------------------------------------------------------------------------- - */ -uint32_t -H5O_msg_hash(unsigned type_id, H5F_t *f, const void *mesg) -{ - size_t buf_size; - unsigned char * buf = NULL; /* Buffer to be hashed */ - uint32_t hash; - uint32_t ret_value; - - FUNC_ENTER_NOAPI(H5O_msg_hash, H5O_HASH_UNDEF) - - /* Check args */ - HDassert(type_id < NELMTS(H5O_msg_class_g)); - HDassert(mesg); - HDassert(f); - - /* Find out the size of buffer needed */ - if((buf_size = H5O_raw_size(type_id, f, mesg)) <= 0) - HGOTO_ERROR(H5E_OHDR, H5E_BADSIZE, H5O_HASH_UNDEF, "can't find message size"); - - /* JAMES: revisit this! Some messages don't use as much space as they say - * they need. Quincey may have fixed this. - */ - if((buf = H5MM_calloc(buf_size)) == NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5O_HASH_UNDEF, "can't allocate buffer for message"); - - /* Encode message into temporary buffer */ - if(H5O_encode(f, buf, mesg, type_id) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTENCODE, H5O_HASH_UNDEF, "can't encode OH message"); - - /* - * Compute the hash value for this message. type_id is used here to - * initialize the hash algorithm, and affects the resulting value. - */ - hash = H5_checksum_lookup3(buf, buf_size, type_id); - - /* JAMES: this is a pretty good hash function. Do we need to version it? - * If so, we'd do so here. */ - - /* A hash value of H5O_HASH_UNDEF indicates failure. If we naturally - * generated this value, reset it to some valid value. */ - if(hash == H5O_HASH_UNDEF) - hash = (uint32_t) 1; - - /* Set return value */ - ret_value = hash; - -done: - if(buf) - HDfree(buf); - - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_msg_hash() */ - - -/*------------------------------------------------------------------------- * Function: H5O_msg_write * * Purpose: Modifies an existing message or creates a new message. @@ -371,7 +331,7 @@ H5O_msg_write(H5O_loc_t *loc, unsigned type_id, unsigned overwrite, /* Mark the message as shared */ mesg_flags |= H5O_MSG_FLAG_SHARED; else if(shared_mesg < 0) - HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "error while trying to share message"); + HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "error while trying to share message") /* Call the "real" modify routine */ if(H5O_msg_write_real(loc, type, overwrite, mesg_flags, update_flags, mesg, dxpl_id) < 0) @@ -460,7 +420,7 @@ H5O_msg_write_real(H5O_loc_t *loc, const H5O_msg_class_t *type, unsigned overwri * First, make sure it's not a committed message; these can't ever * be modified. */ - if(((H5O_shared_t*)oh->mesg[idx].native)->flags & H5O_COMMITTED_FLAG) + if(((H5O_shared_t *)oh->mesg[idx].native)->flags & H5O_COMMITTED_FLAG) HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "unable to modify committed message") /* Remove the old message from the SOHM index */ @@ -475,10 +435,10 @@ H5O_msg_write_real(H5O_loc_t *loc, const H5O_msg_class_t *type, unsigned overwri * JAMES: will this break if a shared message is overwritten with a larger * non-shared message? */ - HDassert(H5O_is_shared(type->id, mesg) > 0); /* JAMES: this should work with + HDassert(H5O_msg_is_shared(type->id, mesg) > 0); /* JAMES: this should work with * replacement messages that aren't shared, too. */ - if(H5O_get_share(type->id, loc->file, mesg, &sh_mesg) < 0) + if(H5O_msg_get_share(type->id, mesg, &sh_mesg) < 0) HGOTO_ERROR (H5E_OHDR, H5E_BADMESG, FAIL, "can't get shared message") /* Instead of writing the original message, write a shared message */ @@ -885,187 +845,1141 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_msg_copy_real() */ - /*------------------------------------------------------------------------- - * Function: H5O_find_in_ohdr + * Function: H5O_msg_count * - * Purpose: Find a message in the object header without consulting - * a symbol table entry. + * Purpose: Counts the number of messages in an object header which are a + * certain type. * - * Return: Success: Index number of message. - * Failure: Negative + * Return: Success: Number of messages of specified type. * - * Programmer: Robb Matzke - * matzke@llnl.gov - * Aug 6 1997 + * Failure: Negative * - * Modifications: - * Robb Matzke, 1999-07-28 - * The ADDR argument is passed by value. + * Programmer: Robb Matzke + * Tuesday, April 21, 1998 * - * Bill Wendling, 2003-09-30 - * Modified so that the object header needs to be AC_protected - * before calling this function. *------------------------------------------------------------------------- */ -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) +int +H5O_msg_count(H5O_loc_t *loc, unsigned type_id, hid_t dxpl_id) { - unsigned u; - unsigned ret_value; + H5O_t *oh = NULL; /* Object header to operate on */ + const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ + int acc; /* Count of the message type found */ + unsigned u; /* Local index variable */ + int ret_value; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5O_find_in_ohdr) + FUNC_ENTER_NOAPI(H5O_msg_count, FAIL) /* Check args */ - HDassert(f); + HDassert(loc); + HDassert(loc->file); + HDassert(H5F_addr_defined(loc->addr)); + 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); + + /* Load the object header */ + if(NULL == (oh = H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "unable to load object header") + + /* Loop over all messages, counting the ones of the type looked for */ + for(u = acc = 0; u < oh->nmesgs; u++) + if(oh->mesg[u].type == type) + acc++; + + /* Set return value */ + ret_value = acc; + +done: + if(oh && H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, H5AC__NO_FLAGS_SET) < 0) + HDONE_ERROR(H5E_OHDR, H5E_PROTECT, FAIL, "unable to release object header") + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_msg_count() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_msg_exists + * + * Purpose: Determines if a particular message exists in an object + * header without trying to decode the message. + * + * Return: Success: FALSE if the message does not exist; TRUE if + * th message exists. + * + * Failure: FAIL if the existence of the message could + * not be determined due to some error such as + * not being able to read the object header. + * + * Programmer: Robb Matzke + * Monday, November 2, 1998 + * + *------------------------------------------------------------------------- + */ +htri_t +H5O_msg_exists(H5O_loc_t *loc, unsigned type_id, int sequence, hid_t dxpl_id) +{ + H5O_t *oh = NULL; /* Object header for location */ + htri_t ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_msg_exists, FAIL) + + HDassert(loc); + HDassert(loc->file); + HDassert(type_id < NELMTS(H5O_msg_class_g)); + HDassert(sequence >= 0); + + /* Load the object header */ + if(NULL == (oh = H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "unable to load object header") + + /* Call the "real" exists routine */ + if((ret_value = H5O_msg_exists_oh(oh, type_id, sequence)) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_READERROR, FAIL, "unable to verify object header message") + +done: + if(oh && H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, H5AC__NO_FLAGS_SET) != SUCCEED) + HDONE_ERROR(H5E_OHDR, H5E_PROTECT, FAIL, "unable to release object header") + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_msg_exists() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_msg_exists_oh + * + * Purpose: Determines if a particular message exists in an object + * header without trying to decode the message. + * + * Return: Success: FALSE if the message does not exist; TRUE if + * th message exists. + * + * Failure: FAIL if the existence of the message could + * not be determined due to some error such as + * not being able to read the object header. + * + * Programmer: Robb Matzke + * Monday, November 2, 1998 + * + *------------------------------------------------------------------------- + */ +htri_t +H5O_msg_exists_oh(H5O_t *oh, unsigned type_id, int sequence) +{ + const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ + unsigned u; /* Local index variable */ + htri_t ret_value; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_msg_exists_oh) + HDassert(oh); - HDassert(type_p); + 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(sequence >= 0); /* Scan through the messages looking for the right one */ for(u = 0; u < oh->nmesgs; u++) { - if(*type_p && (*type_p)->id != oh->mesg[u].type->id) + if(type->id != oh->mesg[u].type->id) continue; if(--sequence < 0) break; } /* end for */ - if(sequence >= 0) - 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 - * a shared message, ignoring the message type. - */ - H5O_LOAD_NATIVE(f, dxpl_id, &(oh->mesg[u]), UFAIL) - - /* - * Return the message type. If this is a shared message then return the - * pointed-to type. - */ - *type_p = oh->mesg[u].type; - /* Set return value */ - ret_value = u; + ret_value = (sequence < 0); -done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_find_in_ohdr() */ +} /* end H5O_msg_exists_oh() */ /*------------------------------------------------------------------------- - * Function: H5O_new_mesg + * Function: H5O_msg_remove * - * Purpose: Create a new message in an object header + * Purpose: Removes the specified message from the object header. + * If sequence is H5O_ALL (-1) then all messages of the + * specified type are removed. Removing a message causes + * the sequence numbers to change for subsequent messages of + * the same type. * - * Return: Success: Index of message - * Failure: Negative + * No attempt is made to join adjacent free areas of the + * object header into a single larger free area. * - * Programmer: Quincey Koziol - * Friday, September 3, 2003 + * Return: Non-negative on success/Negative on failure + * + * Programmer: Robb Matzke + * matzke@llnl.gov + * Aug 28 1997 + * + * Modifications: + * + * Robb Matzke, 7 Jan 1998 + * Does not remove constant messages. + * + * Changed to use IDs for types, instead of type objects, then + * call "real" routine. + * Quincey Koziol + * Feb 14 2003 * *------------------------------------------------------------------------- */ -static unsigned -H5O_new_mesg(H5F_t *f, H5O_t *oh, unsigned *mesg_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) +herr_t +H5O_msg_remove(H5O_loc_t *loc, unsigned type_id, int sequence, hbool_t adj_link, hid_t dxpl_id) { - size_t size; /* Size of space allocated for object header */ - htri_t is_shared; /* Is this a shared message? */ - unsigned ret_value = UFAIL; /* Return value */ + const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ + herr_t ret_value; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5O_new_mesg) + FUNC_ENTER_NOAPI(H5O_msg_remove, FAIL) /* check args */ - HDassert(f); - HDassert(oh); - HDassert(mesg_flags); - HDassert(orig_type); - HDassert(orig_mesg); - HDassert(sh_mesg); - HDassert(new_mesg); - HDassert(new_type); - HDassert(oh_flags_ptr); + HDassert(loc); + HDassert(loc->file); + HDassert(H5F_addr_defined(loc->addr)); + 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); - /* Check for shared message */ - if(*mesg_flags & H5O_MSG_FLAG_SHARED) { - if((NULL == orig_type->is_shared) || (NULL == orig_type->get_share)) - HGOTO_ERROR(H5E_OHDR, H5E_UNSUPPORTED, UFAIL, "message class is not sharable") - if((is_shared = (orig_type->is_shared)(orig_mesg)) == FALSE) { - /* - * If the message isn't shared then turn off the shared bit - * and treat it as an unshared message. - */ - *mesg_flags &= ~H5O_MSG_FLAG_SHARED; - *new_type = orig_type; - *new_mesg = orig_mesg; - } else if(is_shared > 0) { - /* Message is shared. Get shared message, change message type, - * and use shared information */ - HDmemset(sh_mesg, 0, sizeof(H5O_shared_t)); - if((orig_type->get_share)(f, orig_mesg, sh_mesg/*out*/) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, UFAIL, "can't get shared message") + /* Call the "real" remove routine */ + if((ret_value = H5O_msg_remove_real(loc, type, sequence, NULL, NULL, adj_link, dxpl_id)) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, FAIL, "unable to remove object header message") - *new_type = H5O_MSG_SHARED; - *new_mesg = sh_mesg; - } else { - HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, UFAIL, "can't determine if message is shared") - }/* end else */ - } /* end if */ - else { - *new_type = orig_type; - *new_mesg = orig_mesg; - } /* end else */ +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_msg_remove() */ - /* Compute the size needed to store the message on disk */ - 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") + +/*------------------------------------------------------------------------- + * Function: H5O_msg_remove_op + * + * Purpose: Removes messages from the object header that a callback + * routine indicates should be removed. + * + * No attempt is made to join adjacent free areas of the + * object header into a single larger free area. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Sep 6 2005 + * + *------------------------------------------------------------------------- + */ +herr_t +H5O_msg_remove_op(const H5O_loc_t *loc, unsigned type_id, int sequence, + H5O_operator_t op, void *op_data, hbool_t adj_link, hid_t dxpl_id) +{ + const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ + herr_t ret_value; /* Return value */ - /* Allocate space in the object header 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") + FUNC_ENTER_NOAPI(H5O_msg_remove_op, FAIL) - /* 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") + /* check args */ + HDassert(loc); + HDassert(loc->file); + HDassert(H5F_addr_defined(loc->addr)); + 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); + + /* Call the "real" remove routine */ + if((ret_value = H5O_msg_remove_real(loc, type, sequence, op, op_data, adj_link, dxpl_id)) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, FAIL, "unable to remove object header message") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_new_mesg() */ +} /* end H5O_msg_remove_op() */ /*------------------------------------------------------------------------- - * Function: H5O_write_mesg + * Function: H5O_msg_remove_cb * - * Purpose: Write message to object header + * Purpose: Object header iterator callback routine to remove messages + * of a particular type that match a particular sequence number, + * or all messages if the sequence number is H5O_ALL (-1). * * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol - * Friday, September 3, 2003 + * koziol@ncsa.uiuc.edu + * Sep 6 2005 * *------------------------------------------------------------------------- */ static herr_t -H5O_write_mesg(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned idx, - const H5O_msg_class_t *type, const void *mesg, unsigned mesg_flags, - unsigned update_flags, unsigned *oh_flags_ptr) +H5O_msg_remove_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, + unsigned sequence, unsigned *oh_flags_ptr, void *_udata/*in,out*/) { - H5O_mesg_t *idx_msg; /* Pointer to message to modify */ - herr_t ret_value = SUCCEED; /* Return value */ + H5O_iter_ud1_t *udata = (H5O_iter_ud1_t *)_udata; /* Operator user data */ + htri_t try_remove = FALSE; /* Whether to try removing a message */ + herr_t ret_value = H5_ITER_CONT; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5O_write_mesg) + FUNC_ENTER_NOAPI_NOINIT(H5O_msg_remove_cb) /* check args */ - HDassert(f); - HDassert(oh); - HDassert(type); HDassert(mesg); - HDassert(oh_flags_ptr); - /* Set pointer to the correct message */ - idx_msg = &oh->mesg[idx]; + /* Check for callback routine */ + if(udata->op) { + /* Call the iterator callback */ + if((try_remove = (udata->op)(mesg->native, sequence, udata->op_data)) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, H5_ITER_ERROR, "object header message deletion callback failed") + } /* end if */ + else { + /* If there's no callback routine, does the sequence # match? */ + if((int)sequence == udata->sequence || H5O_ALL == udata->sequence) + try_remove = H5_ITER_STOP; + } /* end else */ + + /* Try removing the message, if indicated */ + if(try_remove) { + /* + * Keep track of how many times we failed trying to remove constant + * messages. + */ + if(mesg->flags & H5O_MSG_FLAG_CONSTANT) + udata->nfailed++; + else { + /* Convert message into a null message */ + if(H5O_release_mesg(udata->f, udata->dxpl_id, oh, mesg, TRUE, udata->adj_link) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, H5_ITER_ERROR, "unable to convert into null message") + + /* Indicate that the object header was modified */ + *oh_flags_ptr |= H5AC__DIRTIED_FLAG; + } /* end else */ + + /* Break out now, if we've found the correct message */ + if(udata->sequence == H5O_FIRST || udata->sequence != H5O_ALL) + HGOTO_DONE(H5_ITER_STOP) + } /* end if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_msg_remove_cb() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_msg_remove_real + * + * Purpose: Removes the specified message from the object header. + * If sequence is H5O_ALL (-1) then all messages of the + * specified type are removed. Removing a message causes + * the sequence numbers to change for subsequent messages of + * the same type. + * + * No attempt is made to join adjacent free areas of the + * object header into a single larger free area. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Robb Matzke + * matzke@llnl.gov + * Aug 28 1997 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5O_msg_remove_real(const H5O_loc_t *loc, const H5O_msg_class_t *type, int sequence, + H5O_operator_t app_op, void *op_data, hbool_t adj_link, hid_t dxpl_id) +{ + H5O_iter_ud1_t udata; /* User data for iterator */ + H5O_mesg_operator_t op; /* Wrapper for operator */ + herr_t ret_value=SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5O_msg_remove_real) + + /* check args */ + HDassert(loc); + HDassert(loc->file); + HDassert(type); + + /* Make certain we are allowed to modify the file */ + if(0 == (H5F_INTENT(loc->file) & H5F_ACC_RDWR)) + HGOTO_ERROR(H5E_HEAP, H5E_WRITEERROR, FAIL, "no write intent on file") + + /* Set up iterator operator data */ + udata.f = loc->file; + udata.dxpl_id = dxpl_id; + udata.sequence = sequence; + udata.nfailed = 0; + udata.op = app_op; + udata.op_data = op_data; + udata.adj_link = adj_link; + + /* Iterate over the messages, deleting appropriate one(s) */ + op.lib_op = H5O_msg_remove_cb; + if(H5O_msg_iterate_real(loc, type, H5AC_WRITE, TRUE, op, &udata, dxpl_id) < 0) + HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "error iterating over messages") + + /* Fail if we tried to remove any constant messages */ + if(udata.nfailed) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to remove constant message(s)") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_msg_remove_real() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_msg_iterate + * + * Purpose: Iterate through object headers of a certain type. + * + * Return: Returns a negative value if something is wrong, the return + * value of the last operator if it was non-zero, or zero if all + * object headers were processed. + * + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Nov 19 2004 + * + * Description: + * This function interates over the object headers of an object + * specified with 'ent' of type 'type_id'. For each object header of the + * object, the 'op_data' and some additional information (specified below) are + * passed to the 'op' function. + * The operation receives a pointer to the object header message for the + * object being iterated over ('mesg'), and the pointer to the operator data + * passed in to H5O_msg_iterate ('op_data'). The return values from an operator + * are: + * A. Zero causes the iterator to continue, returning zero when all + * object headers of that type have been processed. + * B. Positive causes the iterator to immediately return that positive + * value, indicating short-circuit success. + * C. Negative causes the iterator to immediately return that value, + * indicating failure. + * + *------------------------------------------------------------------------- + */ +herr_t +H5O_msg_iterate(const H5O_loc_t *loc, unsigned type_id, H5O_operator_t app_op, + void *op_data, hid_t dxpl_id) +{ + const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ + H5O_mesg_operator_t op; /* Wrapper for operator */ + herr_t ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_msg_iterate, FAIL) + + /* check args */ + HDassert(loc); + HDassert(loc->file); + HDassert(H5F_addr_defined(loc->addr)); + 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); + + /* Call the "real" iterate routine */ + op.app_op = app_op; + if((ret_value = H5O_msg_iterate_real(loc, type, H5AC_READ, FALSE, op, op_data, dxpl_id)) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_BADITER, FAIL, "unable to iterate over object header messages") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_msg_iterate() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_msg_iterate_real + * + * Purpose: Iterate through object headers of a certain type. + * + * Return: Returns a negative value if something is wrong, the return + * value of the last operator if it was non-zero, or zero if all + * object headers were processed. + * + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Sep 6 2005 + * + * Description: + * This function interates over the object headers of an object + * specified with 'ent' of type 'type_id'. For each object header of the + * object, the 'op_data' and some additional information (specified below) are + * passed to the 'op' function. + * The operation receives a pointer to the object header message for the + * object being iterated over ('mesg'), and the pointer to the operator data + * passed in to H5O_msg_iterate ('op_data'). The return values from an operator + * are: + * A. Zero causes the iterator to continue, returning zero when all + * object headers of that type have been processed. + * B. Positive causes the iterator to immediately return that positive + * value, indicating short-circuit success. + * C. Negative causes the iterator to immediately return that value, + * indicating failure. + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +H5O_msg_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) +{ + H5O_t *oh = NULL; /* Pointer to actual object header */ + unsigned oh_flags = H5AC__NO_FLAGS_SET; /* Start iteration with no flags set on object header */ + unsigned idx; /* Absolute index of current message in all messages */ + unsigned sequence; /* Relative index of current message for messages of type */ + H5O_mesg_t *idx_msg; /* Pointer to current message */ + void *native_mesg; /* Native, readable message */ + hbool_t native_mesg_alloc = FALSE; /* True if native_mesg needs to be freed */ + + herr_t ret_value = H5_ITER_CONT; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5O_msg_iterate_real) + + /* check args */ + HDassert(loc); + HDassert(loc->file); + HDassert(H5F_addr_defined(loc->addr)); + HDassert(type); + HDassert(op.app_op); + + /* 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") + + /* Iterate over messages */ + for(sequence = 0, idx = 0, idx_msg = &oh->mesg[0]; idx < oh->nmesgs && !ret_value; idx++, idx_msg++) { + if(type->id == idx_msg->type->id) { + + /* + * Decode the message if necessary. + */ + H5O_LOAD_NATIVE(loc->file, dxpl_id, idx_msg, FAIL) + + /* Check for making an "internal" (i.e. within the H5O package) callback */ + if(internal) { + /* Call the "internal" iterator callback */ + if((ret_value = (op.lib_op)(oh, idx_msg, sequence, &oh_flags, op_data)) != 0) + break; + } /* end if */ + else { + /* If the message is shared, get the real message it points to */ + /* JAMES: test */ + if(idx_msg->flags & H5O_MSG_FLAG_SHARED) { + if(NULL == (native_mesg = H5O_shared_read(loc->file, dxpl_id, + idx_msg->native, idx_msg->type, NULL))) + HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "unable to read shared message") + native_mesg_alloc = TRUE; + } + else { + native_mesg = idx_msg->native; + } + + /* Call the iterator callback */ + if((ret_value = (op.app_op)(native_mesg, sequence, op_data)) != 0) + break; + + /* Free the "real" message if it was allocated */ + if(native_mesg_alloc) { + H5O_msg_free(idx_msg->type->id, native_mesg); + native_mesg_alloc = FALSE; + } + } /* end else */ + + /* Check for error from iterator */ + if(ret_value < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "iterator function failed") + + /* Increment sequence value for message type */ + sequence++; + } /* end if */ + } /* end for */ + +done: + /* Free the native message if it was allocated */ + if(native_mesg_alloc) { + H5O_msg_free(idx_msg->type->id, native_mesg); + native_mesg_alloc = FALSE; + } + + if(oh) { + /* Check if object header was modified */ + if(oh_flags & H5AC__DIRTIED_FLAG) { + /* Shouldn't be able to modify object header if we don't have write access */ + HDassert(prot == H5AC_WRITE); + + /* Try to condense object header info */ + /* (Since this routine is invoked when a message is removed from + * an object header, the header will be condensed after each + * message removal) + */ + if(H5O_condense_header(loc->file, oh, dxpl_id) < 0) + HDONE_ERROR(H5E_OHDR, H5E_CANTPACK, FAIL, "can't pack object header") + + H5O_touch_oh(loc->file, dxpl_id, oh, FALSE, &oh_flags); + } /* end if */ + + if(H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, oh_flags) < 0) + HDONE_ERROR(H5E_OHDR, H5E_PROTECT, FAIL, "unable to release object header") + } /* end if */ + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_msg_iterate_real() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_msg_raw_size + * + * Purpose: Call the 'raw_size' method for a + * particular class of object header. + * + * Return: Size of message on success, 0 on failure + * + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Feb 13 2003 + * + *------------------------------------------------------------------------- + */ +size_t +H5O_msg_raw_size(const H5F_t *f, unsigned type_id, const void *mesg) +{ + const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ + size_t ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_msg_raw_size, 0) + + /* Check args */ + 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(type->raw_size); + HDassert(f); + HDassert(mesg); + + /* Compute the raw data size for the mesg */ + if((ret_value = (type->raw_size)(f, mesg)) == 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTCOUNT, 0, "unable to determine size of message") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_msg_raw_size() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_msg_mesg_size + * + * 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 + * koziol@ncsa.uiuc.edu + * Sep 6 2005 + * + *------------------------------------------------------------------------- + */ +size_t +H5O_msg_mesg_size(const H5F_t *f, unsigned type_id, const void *mesg, size_t extra_raw) +{ + const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ + size_t ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_msg_mesg_size, 0) + + /* Check args */ + 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(type->raw_size); + HDassert(f); + HDassert(mesg); + + /* Compute the raw data size for the mesg */ + if((ret_value = (type->raw_size)(f, mesg)) == 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTCOUNT, 0, "unable to determine size of message") + + /* Add in "extra" raw space */ + ret_value += extra_raw; + + /* Adjust size for alignment, if necessary */ + ret_value = H5O_ALIGN_F(f, ret_value); + + /* Add space for message header */ + ret_value += H5O_SIZEOF_MSGHDR_F(f); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_msg_mesg_size() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_msg_get_share + * + * Purpose: Call the 'get_share' method for a + * particular class of object header. + * + * Return: Success: Non-negative, and SHARE describes the shared + * object. + * + * Failure: Negative + * + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Oct 2 2003 + * + *------------------------------------------------------------------------- + */ +herr_t +H5O_msg_get_share(unsigned type_id, const void *mesg, H5O_shared_t *share) +{ + const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ + herr_t ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_msg_get_share, FAIL) + + /* Check args */ + 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(type->get_share); + HDassert(mesg); + HDassert(share); + + /* Get shared data for the mesg */ + if((ret_value = (type->get_share)(mesg, share)) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, FAIL, "unable to retrieve shared message information") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_msg_get_share() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_msg_is_shared + * + * Purpose: Call the 'is_shared' method for a + * particular class of object header. + * + * Return: Object is shared: TRUE + * Object is not shared: FALSE + * + * Programmer: James Laird + * jlaird@ncsa.uiuc.edu + * April 5 2006 + * + *------------------------------------------------------------------------- + */ +htri_t +H5O_msg_is_shared(unsigned type_id, const void *mesg) +{ + const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ + htri_t ret_value; + + FUNC_ENTER_NOAPI_NOFUNC(H5O_msg_is_shared) + + /* Check args */ + 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(mesg); + + HDassert(type_id != H5O_SHARED_ID); /* JAMES: check for this mistake elsewhere, too */ + + /* If there is no is_shared function, then obviously it's not a shared message! */ + if(!(type->is_shared)) + ret_value = FALSE; + else + ret_value = (type->is_shared)(mesg); + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_msg_is_shared() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_msg_set_share + * + * Purpose: Set the shared information for an object header message. + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: James Laird + * jlaird@hdfgroup.org + * November 1 2006 + * + *------------------------------------------------------------------------- + */ +herr_t +H5O_msg_set_share(unsigned type_id, H5O_shared_t *share, void *mesg) +{ + const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ + herr_t ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_msg_set_share, FAIL) + + /* Check args */ + HDassert(share); + 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(type->set_share); + HDassert(mesg); + HDassert(share->flags != H5O_NOT_SHARED); + + /* Set this message as the shared message for the message, wiping out + * any information that was there before + */ + if((ret_value = (type->set_share)(mesg, share)) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTSET, FAIL, "unable to set shared message information") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_msg_set_share() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_msg_reset_share + * + * Purpose: Reset the shared information for an object header message. + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: James Laird + * jlaird@hdfgroup.org + * Oct 17 2006 + * + *------------------------------------------------------------------------- + */ +herr_t +H5O_msg_reset_share(unsigned type_id, void *mesg) +{ + const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ + H5O_shared_t sh_mesg; /* Shared message */ + herr_t ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_msg_reset_share, FAIL) + + /* Check args */ + 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(type->set_share); + HDassert(mesg); + + /* Initialize the shared message to zero. */ + HDmemset(&sh_mesg, 0, sizeof(H5O_shared_t)); + + /* Set this message as the shared message for the message, wiping out + * any information that was there before + */ + if((ret_value = (type->set_share)(mesg, &sh_mesg)) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTSET, FAIL, "unable to reset shared message information") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_msg_reset_share() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_msg_encode + * + * Purpose: Encode an object(data type and simple data space only) + * description into a buffer. + * + * Return: Success: Non-negative + * + * Failure: Negative + * + * Programmer: Raymond Lu + * slu@ncsa.uiuc.edu + * July 13, 2004 + * + *------------------------------------------------------------------------- + */ +herr_t +H5O_msg_encode(H5F_t *f, unsigned type_id, unsigned char *buf, const void *mesg) +{ + const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_msg_encode,FAIL) + + /* check args */ + HDassert(f); + 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); + + /* Encode */ + if((type->encode)(f, buf, mesg) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to encode message") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_msg_encode() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_msg_decode + * + * Purpose: Decode a binary object description and return a new + * object handle. + * + * Note: This routine is not guaranteed to work with all possible + * header messages, use with care. + * + * Return: Success: Pointer to object(data type or space) + * + * Failure: NULL + * + * Programmer: Raymond Lu + * slu@ncsa.uiuc.edu + * July 14, 2004 + * + *------------------------------------------------------------------------- + */ +void * +H5O_msg_decode(H5F_t *f, hid_t dxpl_id, unsigned type_id, const unsigned char *buf) +{ + const H5O_msg_class_t *type; /* Actual H5O class type for the ID */ + void *ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_msg_decode, NULL) + + /* check args */ + HDassert(f); + 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); + + /* decode */ + if((ret_value = (type->decode)(f, dxpl_id, buf)) == NULL) + HGOTO_ERROR(H5E_OHDR, H5E_CANTDECODE, NULL, "unable to decode message") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_msg_decode() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_msg_copy_file + * + * Purpose: Copies a message to file. If MESG is is the null pointer then a null + * pointer is returned with no error. + * + * Return: Success: Ptr to the new message + * + * Failure: NULL + * + * Programmer: Peter Cao + * June 4, 2005 + * + *------------------------------------------------------------------------- + */ +void * +H5O_msg_copy_file(const H5O_msg_class_t *copy_type, const H5O_msg_class_t *mesg_type, H5F_t *file_src, void *native_src, + H5F_t *file_dst, hid_t dxpl_id, H5O_copy_t *cpy_info, void *udata) +{ + void *ret_value; + + FUNC_ENTER_NOAPI_NOINIT(H5O_msg_copy_file) + + /* check args */ + HDassert(copy_type); + HDassert(mesg_type); + HDassert(copy_type->copy_file); + HDassert(file_src); + HDassert(native_src); + HDassert(file_dst); + HDassert(cpy_info); + + if(NULL == (ret_value = (copy_type->copy_file)(file_src, mesg_type, native_src, file_dst, dxpl_id, cpy_info, udata))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "unable to copy object header message to file") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_msg_copy_file() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_find_in_ohdr + * + * Purpose: Find a message in the object header without consulting + * a symbol table entry. + * + * Return: Success: Index number of message. + * Failure: Negative + * + * Programmer: Robb Matzke + * matzke@llnl.gov + * Aug 6 1997 + * + * Modifications: + * Robb Matzke, 1999-07-28 + * The ADDR argument is passed by value. + * + * Bill Wendling, 2003-09-30 + * Modified so that the object header needs to be AC_protected + * before calling this function. + *------------------------------------------------------------------------- + */ +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) +{ + unsigned u; + unsigned ret_value; + + FUNC_ENTER_NOAPI_NOINIT(H5O_find_in_ohdr) + + /* Check args */ + HDassert(f); + HDassert(oh); + HDassert(type_p); + + /* Scan through the messages looking for the right one */ + for(u = 0; u < oh->nmesgs; u++) { + if(*type_p && (*type_p)->id != oh->mesg[u].type->id) + continue; + if(--sequence < 0) + break; + } /* end for */ + + if(sequence >= 0) + 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 + * a shared message, ignoring the message type. + */ + H5O_LOAD_NATIVE(f, dxpl_id, &(oh->mesg[u]), UFAIL) + + /* + * Return the message type. If this is a shared message then return the + * pointed-to type. + */ + *type_p = oh->mesg[u].type; + + /* Set return value */ + ret_value = u; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_find_in_ohdr() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_new_mesg + * + * Purpose: Create a new message in an object header + * + * Return: Success: Index of message + * Failure: Negative + * + * Programmer: Quincey Koziol + * Friday, September 3, 2003 + * + *------------------------------------------------------------------------- + */ +static unsigned +H5O_new_mesg(H5F_t *f, H5O_t *oh, unsigned *mesg_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) +{ + size_t size; /* Size of space allocated for object header */ + htri_t is_shared; /* Is this a shared message? */ + unsigned ret_value = UFAIL; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5O_new_mesg) + + /* check args */ + HDassert(f); + HDassert(oh); + HDassert(mesg_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(*mesg_flags & H5O_MSG_FLAG_SHARED) { + if((NULL == orig_type->is_shared) || (NULL == orig_type->get_share)) + HGOTO_ERROR(H5E_OHDR, H5E_UNSUPPORTED, UFAIL, "message class is not sharable") + if((is_shared = (orig_type->is_shared)(orig_mesg)) == FALSE) { + /* + * If the message isn't shared then turn off the shared bit + * and treat it as an unshared message. + */ + *mesg_flags &= ~H5O_MSG_FLAG_SHARED; + *new_type = orig_type; + *new_mesg = orig_mesg; + } else if(is_shared > 0) { + /* Message is shared. Get shared message, change message type, + * and use shared information */ + HDmemset(sh_mesg, 0, sizeof(H5O_shared_t)); + if((orig_type->get_share)(orig_mesg, sh_mesg/*out*/) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, UFAIL, "can't get shared message") + + *new_type = H5O_MSG_SHARED; + *new_mesg = sh_mesg; + } else { + HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, UFAIL, "can't determine if message is shared") + }/* end else */ + } /* end if */ + else { + *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) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, UFAIL, "object header message is too large") + + /* Allocate space in the object header 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") + + /* 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") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_new_mesg() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_write_mesg + * + * Purpose: Write message to object header + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Friday, September 3, 2003 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5O_write_mesg(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned idx, + const H5O_msg_class_t *type, const void *mesg, unsigned mesg_flags, + unsigned update_flags, unsigned *oh_flags_ptr) +{ + H5O_mesg_t *idx_msg; /* Pointer to message to modify */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5O_write_mesg) + + /* check args */ + HDassert(f); + HDassert(oh); + HDassert(type); + HDassert(mesg); + HDassert(oh_flags_ptr); + + /* Set pointer to the correct message */ + idx_msg = &oh->mesg[idx]; /* Reset existing native information */ if(!(update_flags & H5O_UPDATE_DATA_ONLY)) @@ -1090,3 +2004,64 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_write_mesg() */ + +/*------------------------------------------------------------------------- + * Function: H5O_delete_mesg + * + * Purpose: Internal function to: + * Delete an object header message from a file. This frees the file + * space used for anything referred to in the object header message. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * September 26 2003 + * + *------------------------------------------------------------------------- + */ +herr_t +H5O_delete_mesg(H5F_t *f, hid_t dxpl_id, H5O_mesg_t *mesg, hbool_t adj_link) +{ + const H5O_msg_class_t *type; /* Type of object to free */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_delete_mesg, FAIL) + + /* Check args */ + HDassert(f); + HDassert(mesg); + + /* Get the message to free's type */ + if(mesg->flags & H5O_MSG_FLAG_SHARED) + type = H5O_MSG_SHARED; + else + type = mesg->type; + + /* Check if there is a file space deletion callback for this type of message */ + if(type->del) { + /* Decode the message if necessary. */ + if(NULL == mesg->native) { + HDassert(type->decode); + if(NULL == (mesg->native = (type->decode)(f, dxpl_id, mesg->raw))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTDECODE, FAIL, "unable to decode message") + } /* end if */ + + /* Check if this message needs to be removed from the SOHM table */ + /* JAMES: there should be a callback, maybe in H5O_shared_delete, to fiddle w/ the ref. count. + * We shouldn't need to do a search in the SOHM table on delete. */ + if(type == H5O_MSG_SHARED) + { + /* The native message here is actually a shared message. */ + if(H5SM_try_delete(f, dxpl_id, mesg->type->id, mesg->native) < 0) + HGOTO_ERROR (H5E_OHDR, H5E_CANTFREE, FAIL, "unable to delete message from SOHM table") + } + + if((type->del)(f, dxpl_id, mesg->native, adj_link) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, FAIL, "unable to delete file space for object header message") + } /* end if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_delete_msg() */ + diff --git a/src/H5Opkg.h b/src/H5Opkg.h index 0471d5f..a23b311 100644 --- a/src/H5Opkg.h +++ b/src/H5Opkg.h @@ -176,14 +176,14 @@ struct H5O_msg_class_t { void *(*decode)(H5F_t*, hid_t, const uint8_t*); herr_t (*encode)(H5F_t*, uint8_t*, const void*); void *(*copy)(const void*, void*, unsigned); /*copy native value */ - size_t (*raw_size)(const H5F_t*, const void*);/*sizeof raw val */ + size_t (*raw_size)(const H5F_t*, const void*);/*sizeof encoded message */ herr_t (*reset)(void *); /*free nested data structs */ herr_t (*free)(void *); /*free main data struct */ herr_t (*del)(H5F_t *, hid_t, const void *, hbool_t); /* Delete space in file referenced by this message */ herr_t (*link)(H5F_t *, hid_t, const void *); /* Increment any links in file reference by this message */ - herr_t (*get_share)(H5F_t*, const void*, struct H5O_shared_t*); /* Get shared information */ - herr_t (*set_share)(H5F_t*, void*, const struct H5O_shared_t*); /* Set shared information */ - htri_t (*is_shared)(const void*); /* Is message shared? */ + herr_t (*get_share)(const void*, struct H5O_shared_t*); /* Get shared information */ + herr_t (*set_share)(void*, const struct H5O_shared_t*); /* Set shared information */ + htri_t (*is_shared)(const void*); /* Is message shared? */ herr_t (*pre_copy_file)(H5F_t *, const H5O_msg_class_t *, const void *, hbool_t *, const H5O_copy_t *, void *); /*"pre copy" action when copying native value to file */ void *(*copy_file)(H5F_t *, const H5O_msg_class_t *, void *, H5F_t *, hid_t, H5O_copy_t *, void *); /*copy native value to file */ herr_t (*post_copy_file)(const H5O_loc_t *, const void *, H5O_loc_t *, void *, hid_t, H5O_copy_t *); /*"post copy" action when copying native value to file */ @@ -394,9 +394,6 @@ H5_DLLVAR const H5O_obj_class_t H5O_OBJ_DATATYPE[1]; H5_DLL herr_t H5O_flush_msgs(H5F_t *f, H5O_t *oh); H5_DLL herr_t H5O_delete_mesg(H5F_t *f, hid_t dxpl_id, H5O_mesg_t *mesg, hbool_t adj_link); -H5_DLL void * H5O_copy_mesg_file(const H5O_msg_class_t *copy_type, - const H5O_msg_class_t *mesg_type, H5F_t *file_src, void *mesg_src, - H5F_t *file_dst, hid_t dxpl_id, H5O_copy_t *cpy_info, void *udata); H5_DLL const H5O_obj_class_t *H5O_obj_class_real(H5O_t *oh); /* Object header message routines */ @@ -404,6 +401,10 @@ H5_DLL void *H5O_msg_read_real(H5F_t *f, H5O_t *oh, unsigned type_id, int sequence, void *mesg, hid_t dxpl_id); H5_DLL void *H5O_msg_free_real(const H5O_msg_class_t *type, void *mesg); H5_DLL herr_t H5O_msg_free_mesg(H5O_mesg_t *mesg); +H5_DLL htri_t H5O_msg_exists_oh(struct H5O_t *oh, unsigned type_id, int sequence); +H5_DLL void * H5O_msg_copy_file(const H5O_msg_class_t *copy_type, + const H5O_msg_class_t *mesg_type, H5F_t *file_src, void *mesg_src, + H5F_t *file_dst, hid_t dxpl_id, H5O_copy_t *cpy_info, void *udata); /* Object header allocation routines */ H5_DLL unsigned H5O_alloc(H5F_t *f, hid_t dxpl_id, H5O_t *oh, diff --git a/src/H5Opline.c b/src/H5Opline.c index e95863b..0c7f754 100644 --- a/src/H5Opline.c +++ b/src/H5Opline.c @@ -35,10 +35,8 @@ static void *H5O_pline_copy(const void *_mesg, void *_dest, unsigned update_flag static size_t H5O_pline_size(const H5F_t *f, const void *_mesg); static herr_t H5O_pline_reset(void *_mesg); static herr_t H5O_pline_free(void *_mesg); -static herr_t H5O_pline_get_share (H5F_t *f, const void *_mesg, - H5O_shared_t *sh); -static herr_t H5O_pline_set_share (H5F_t *f, void *_mesg, - const H5O_shared_t *sh); +static herr_t H5O_pline_get_share(const void *_mesg, H5O_shared_t *sh); +static herr_t H5O_pline_set_share(void *_mesg, const H5O_shared_t *sh); static htri_t H5O_pline_is_shared(const void *_mesg); static herr_t H5O_pline_pre_copy_file(H5F_t *file_src, const H5O_msg_class_t *type, const void *mesg_src, hbool_t *deleted, const H5O_copy_t *cpy_info, void *_udata); @@ -606,13 +604,10 @@ done: * Programmer: James Laird * Tuesday, October 10, 2006 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t -H5O_pline_get_share(H5F_t UNUSED *f, const void *_mesg, - H5O_shared_t *sh /*out*/) +H5O_pline_get_share(const void *_mesg, H5O_shared_t *sh /*out*/) { const H5O_pline_t *mesg = (const H5O_pline_t *)_mesg; herr_t ret_value = SUCCEED; @@ -644,8 +639,7 @@ H5O_pline_get_share(H5F_t UNUSED *f, const void *_mesg, *------------------------------------------------------------------------- */ static herr_t -H5O_pline_set_share(H5F_t UNUSED *f, void *_mesg/*in,out*/, - const H5O_shared_t *sh) +H5O_pline_set_share(void *_mesg/*in,out*/, const H5O_shared_t *sh) { H5O_pline_t *mesg = (H5O_pline_t *)_mesg; herr_t ret_value = SUCCEED; diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h index cd821db..2248962 100644 --- a/src/H5Oprivate.h +++ b/src/H5Oprivate.h @@ -377,17 +377,13 @@ struct H5P_genplist_t; struct H5SL_t; struct H5O_t; -/* General message operators */ +/* Object header routines */ H5_DLL herr_t H5O_init(void); H5_DLL herr_t H5O_create(H5F_t *f, hid_t dxpl_id, size_t size_hint, hid_t ocpl_id, H5O_loc_t *loc/*out*/); H5_DLL herr_t H5O_open(const H5O_loc_t *loc); H5_DLL herr_t H5O_close(H5O_loc_t *loc); H5_DLL int H5O_link(const H5O_loc_t *loc, int adjust, hid_t dxpl_id); -H5_DLL int H5O_count(H5O_loc_t *loc, unsigned type_id, hid_t dxpl_id); -H5_DLL htri_t H5O_exists(H5O_loc_t *loc, unsigned type_id, int sequence, - hid_t dxpl_id); -H5_DLL htri_t H5O_exists_oh(struct H5O_t *oh, unsigned type_id, int sequence); H5_DLL struct H5O_t *H5O_protect(H5O_loc_t *loc, hid_t dxpl_id); H5_DLL herr_t H5O_unprotect(H5O_loc_t *loc, struct H5O_t *oh, hid_t dxpl_id, unsigned oh_flags); @@ -399,25 +395,8 @@ H5_DLL herr_t H5O_bogus(H5O_loc_t *loc, hid_t dxpl_id); H5_DLL herr_t H5O_bogus_oh(H5F_t *f, hid_t dxpl_id, struct H5O_t *oh, unsigned * oh_flags_ptr); #endif /* H5O_ENABLE_BOGUS */ -H5_DLL herr_t H5O_remove(H5O_loc_t *loc, unsigned type_id, int sequence, - hbool_t adj_link, hid_t dxpl_id); -H5_DLL herr_t H5O_remove_op(const H5O_loc_t *loc, unsigned type_id, int sequence, - H5O_operator_t op, void *op_data, hbool_t adj_link, hid_t dxpl_id); -H5_DLL herr_t H5O_encode(H5F_t *f, unsigned char *buf, const void *obj, unsigned type_id); -H5_DLL void* H5O_decode(H5F_t *f, hid_t dxpl_id, const unsigned char *buf, - unsigned type_id); -H5_DLL size_t H5O_raw_size(unsigned type_id, const H5F_t *f, const void *mesg); -H5_DLL size_t H5O_mesg_size(unsigned type_id, const H5F_t *f, const void *mesg, - size_t extra_raw); -H5_DLL herr_t H5O_get_share(unsigned type_id, H5F_t *f, const void *mesg, H5O_shared_t *share); H5_DLL herr_t H5O_delete(H5F_t *f, hid_t dxpl_id, haddr_t addr); -H5_DLL htri_t H5O_is_shared(unsigned type_id, const void *mesg); -H5_DLL herr_t H5O_set_share(H5F_t *f, H5O_shared_t *share, unsigned type_id, - void *mesg); -H5_DLL herr_t H5O_reset_share(H5F_t *f, unsigned type_id, void *mesg); H5_DLL herr_t H5O_get_info(H5O_loc_t *oloc, H5O_info_t *oinfo, hid_t dxpl_id); -H5_DLL herr_t H5O_iterate(const H5O_loc_t *loc, unsigned type_id, H5O_operator_t op, - void *op_data, hid_t dxpl_id); H5_DLL herr_t H5O_obj_type(const H5O_loc_t *loc, H5O_type_t *obj_type, hid_t dxpl_id); H5_DLL herr_t H5O_get_create_plist(const H5O_loc_t *loc, hid_t dxpl_id, struct H5P_genplist_t *oc_plist); @@ -434,7 +413,25 @@ H5_DLL void *H5O_msg_read(const H5O_loc_t *loc, unsigned type_id, int sequence, H5_DLL herr_t H5O_msg_reset(unsigned type_id, void *native); H5_DLL void *H5O_msg_free(unsigned type_id, void *mesg); H5_DLL void *H5O_msg_copy(unsigned type_id, const void *mesg, void *dst); -H5_DLL uint32_t H5O_msg_hash(unsigned type_id, H5F_t *f, const void *mesg); +H5_DLL int H5O_msg_count(H5O_loc_t *loc, unsigned type_id, hid_t dxpl_id); +H5_DLL htri_t H5O_msg_exists(H5O_loc_t *loc, unsigned type_id, int sequence, + hid_t dxpl_id); +H5_DLL herr_t H5O_msg_remove(H5O_loc_t *loc, unsigned type_id, int sequence, + hbool_t adj_link, hid_t dxpl_id); +H5_DLL herr_t H5O_msg_remove_op(const H5O_loc_t *loc, unsigned type_id, int sequence, + H5O_operator_t op, void *op_data, hbool_t adj_link, hid_t dxpl_id); +H5_DLL herr_t H5O_msg_iterate(const H5O_loc_t *loc, unsigned type_id, H5O_operator_t op, + void *op_data, hid_t dxpl_id); +H5_DLL size_t H5O_msg_raw_size(const H5F_t *f, unsigned type_id, const void *mesg); +H5_DLL size_t H5O_msg_mesg_size(const H5F_t *f, unsigned type_id, const void *mesg, + size_t extra_raw); +H5_DLL herr_t H5O_msg_get_share(unsigned type_id, const void *mesg, H5O_shared_t *share); +H5_DLL htri_t H5O_msg_is_shared(unsigned type_id, const void *mesg); +H5_DLL herr_t H5O_msg_set_share(unsigned type_id, H5O_shared_t *share, void *mesg); +H5_DLL herr_t H5O_msg_reset_share(unsigned type_id, void *mesg); +H5_DLL herr_t H5O_msg_encode(H5F_t *f, unsigned type_id, unsigned char *buf, const void *obj); +H5_DLL void* H5O_msg_decode(H5F_t *f, hid_t dxpl_id, unsigned type_id, + const unsigned char *buf); /* Object copying routines */ H5_DLL herr_t H5O_copy_header_map(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, diff --git a/src/H5Osdspace.c b/src/H5Osdspace.c index 750ad4a..7287f50 100644 --- a/src/H5Osdspace.c +++ b/src/H5Osdspace.c @@ -31,11 +31,9 @@ static void *H5O_sdspace_copy(const void *_mesg, void *_dest, unsigned update_fl static size_t H5O_sdspace_size(const H5F_t *f, const void *_mesg); static herr_t H5O_sdspace_reset(void *_mesg); static herr_t H5O_sdspace_free (void *_mesg); -static herr_t H5O_sdspace_get_share (H5F_t *f, const void *_mesg, - H5O_shared_t *sh); -static herr_t H5O_sdspace_set_share (H5F_t *f, void *_mesg, - const H5O_shared_t *sh); -static htri_t H5O_sdspace_is_shared (const void *_mesg); +static herr_t H5O_sdspace_get_share(const void *_mesg, H5O_shared_t *sh); +static herr_t H5O_sdspace_set_share(void *_mesg, const H5O_shared_t *sh); +static htri_t H5O_sdspace_is_shared(const void *_mesg); static herr_t H5O_sdspace_pre_copy_file(H5F_t *file_src, const H5O_msg_class_t *type, const void *mesg_src, hbool_t *deleted, const H5O_copy_t *cpy_info, void *_udata); static herr_t H5O_sdspace_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, @@ -459,13 +457,10 @@ H5O_sdspace_free (void *mesg) * Programmer: James Laird * Tuesday, October 10, 2006 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t -H5O_sdspace_get_share(H5F_t UNUSED *f, const void *_mesg, - H5O_shared_t *sh /*out*/) +H5O_sdspace_get_share(const void *_mesg, H5O_shared_t *sh /*out*/) { const H5S_extent_t *mesg = (const H5S_extent_t *)_mesg; herr_t ret_value = SUCCEED; @@ -492,13 +487,10 @@ H5O_sdspace_get_share(H5F_t UNUSED *f, const void *_mesg, * Programmer: James Laird * Tuesday, October 10, 2006 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t -H5O_sdspace_set_share(H5F_t UNUSED *f, void *_mesg/*in,out*/, - const H5O_shared_t *sh) +H5O_sdspace_set_share(void *_mesg/*in,out*/, const H5O_shared_t *sh) { H5S_extent_t *mesg = (H5S_extent_t *)_mesg; herr_t ret_value = SUCCEED; @@ -512,7 +504,7 @@ H5O_sdspace_set_share(H5F_t UNUSED *f, void *_mesg/*in,out*/, ret_value = FAIL; FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5O_sdspace_set_share() */ /*------------------------------------------------------------------------- diff --git a/src/H5Oshared.c b/src/H5Oshared.c index 1a1ca21..f84fde6 100644 --- a/src/H5Oshared.c +++ b/src/H5Oshared.c @@ -38,10 +38,10 @@ #include "H5HFprivate.h" /* Fractal heap */ #include "H5SMprivate.h" /*JAMES: for H5SM_get_fheap_addr. Change this? */ -static void *H5O_shared_decode (H5F_t*, hid_t dxpl_id, const uint8_t*); -static herr_t H5O_shared_encode (H5F_t*, uint8_t*, const void*); +static void *H5O_shared_decode(H5F_t*, hid_t dxpl_id, const uint8_t*); +static herr_t H5O_shared_encode(H5F_t*, uint8_t*, const void*); static void *H5O_shared_copy(const void *_mesg, void *_dest, unsigned update_flags); -static size_t H5O_shared_size (const H5F_t*, const void *_mesg); +static size_t H5O_shared_size(const H5F_t*, const void *_mesg); static herr_t H5O_shared_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg, hbool_t adj_link); static herr_t H5O_shared_link(H5F_t *f, hid_t dxpl_id, const void *_mesg); @@ -49,7 +49,7 @@ static herr_t H5O_shared_pre_copy_file(H5F_t *file_src, const H5O_msg_class_t *t const void *mesg_src, hbool_t *deleted, const H5O_copy_t *cpy_info, void *_udata); static void *H5O_shared_copy_file(H5F_t *file_src, const H5O_msg_class_t *mesg_type, void *native_src, H5F_t *file_dst, hid_t dxpl_id, H5O_copy_t *cpy_info, void *udata); -static herr_t H5O_shared_debug (H5F_t*, hid_t dxpl_id, const void*, FILE*, int, int); +static herr_t H5O_shared_debug(H5F_t*, hid_t dxpl_id, const void*, FILE*, int, int); /* This message derives from H5O message class */ const H5O_msg_class_t H5O_MSG_SHARED[1] = {{ @@ -151,7 +151,7 @@ H5O_shared_read(H5F_t *f, hid_t dxpl_id, const H5O_shared_t *shared, HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, NULL, "can't read message from fractal heap.") /* Decode the message */ - if(NULL == (native_mesg = H5O_decode(f, dxpl_id, buf, type->id))) + if(NULL == (native_mesg = H5O_msg_decode(f, dxpl_id, type->id, buf))) HGOTO_ERROR(H5E_OHDR, H5E_CANTDECODE, NULL, "can't decode shared message.") /* Copy this message to the user's buffer */ @@ -167,7 +167,7 @@ H5O_shared_read(H5F_t *f, hid_t dxpl_id, const H5O_shared_t *shared, } /* end else */ /* Mark the message as shared */ - if(type->set_share && (type->set_share)(f, ret_value, shared) < 0) + if(type->set_share && (type->set_share)(ret_value, shared) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "unable to set sharing information") done: @@ -706,7 +706,7 @@ H5O_shared_copy_file(H5F_t *file_src, const H5O_msg_class_t *mesg_type, if(mesg_type->copy_file) { /* Copy the original, un-shared message and return it */ - ret_value = H5O_copy_mesg_file(mesg_type, mesg_type, file_src, dst_mesg, file_dst, dxpl_id, cpy_info, udata); + ret_value = H5O_msg_copy_file(mesg_type, mesg_type, file_src, dst_mesg, file_dst, dxpl_id, cpy_info, udata); H5MM_xfree(dst_mesg); } else { diff --git a/src/H5S.c b/src/H5S.c index 42c70ca..6547281 100644 --- a/src/H5S.c +++ b/src/H5S.c @@ -1493,62 +1493,56 @@ done: * Programmer: Robb Matzke * Friday, January 30, 1998 * - * Modifications: - * *------------------------------------------------------------------------- */ int -H5S_extend (H5S_t *space, const hsize_t *size) +H5S_extend(H5S_t *space, const hsize_t *size) { - int ret_value=0; unsigned u; + int ret_value = 0; - FUNC_ENTER_NOAPI(H5S_extend, FAIL); + FUNC_ENTER_NOAPI(H5S_extend, FAIL) /* Check args */ - assert (space && H5S_SIMPLE==H5S_GET_EXTENT_TYPE(space)); - assert (size); + HDassert(space && H5S_SIMPLE == H5S_GET_EXTENT_TYPE(space)); + HDassert(size); /* Check through all the dimensions to see if modifying the dataspace is allowed */ - for (u=0; uextent.rank; u++) { - if (space->extent.size[u]extent.max && - H5S_UNLIMITED!=space->extent.max[u] && + for(u = 0; u < space->extent.rank; u++) { + if(space->extent.size[u]extent.max && H5S_UNLIMITED!=space->extent.max[u] && space->extent.max[u]extent.rank; u++) { - if (space->extent.size[u]extent.rank; u++) { + if(space->extent.size[u] < size[u]) space->extent.size[u] = size[u]; - nelem*=space->extent.size[u]; - } + nelem *= space->extent.size[u]; + } /* end for */ space->extent.nelem = nelem; /* If the selection is 'all', update the number of elements selected */ - if(H5S_GET_SELECT_TYPE(space)==H5S_SEL_ALL) - if(H5S_select_all(space, FALSE)<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection"); + if(H5S_GET_SELECT_TYPE(space) == H5S_SEL_ALL) + if(H5S_select_all(space, FALSE) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection") /* Mark the dataspace as no longer shared if it was before */ - /* JAMES: passes in NULL for the file because the file has nothing to do with it. - * can I eliminate the file completely from sharing? - */ - if(H5O_reset_share(NULL, H5O_SDSPACE_ID, space) < 0) + if(H5O_msg_reset_share(H5O_SDSPACE_ID, space) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTRESET, FAIL, "can't stop sharing dataspace") - } + } /* end if */ done: - FUNC_LEAVE_NOAPI(ret_value); -} + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S_extend() */ /*------------------------------------------------------------------------- @@ -1738,7 +1732,7 @@ H5S_encode(H5S_t *obj, unsigned char *buf, size_t *nalloc) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate fake file struct") /* Find out the size of buffer needed for extent */ - if((extent_size = H5O_raw_size(H5O_SDSPACE_ID, f, obj)) == 0) + if((extent_size = H5O_msg_raw_size(f, H5O_SDSPACE_ID, obj)) == 0) HGOTO_ERROR(H5E_DATASPACE, H5E_BADSIZE, FAIL, "can't find dataspace size") /* Find out the size of buffer needed for selection */ @@ -1764,7 +1758,7 @@ H5S_encode(H5S_t *obj, unsigned char *buf, size_t *nalloc) UINT32ENCODE(buf, extent_size); /* Encode the extent part of dataspace */ - if(H5O_encode(f, buf, obj, H5O_SDSPACE_ID) < 0) + if(H5O_msg_encode(f, H5O_SDSPACE_ID, buf, obj) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTENCODE, FAIL, "can't encode extent space") buf += extent_size; @@ -1870,7 +1864,7 @@ H5S_decode(const unsigned char *buf) /* Decode the extent part of dataspace */ /* (pass mostly bogus file pointer and bogus DXPL) */ - if((extent = H5O_decode(f, H5P_DEFAULT, buf, H5O_SDSPACE_ID))==NULL) + if((extent = H5O_msg_decode(f, H5P_DEFAULT, H5O_SDSPACE_ID, buf))==NULL) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDECODE, NULL, "can't decode object") buf += extent_size; @@ -1923,7 +1917,7 @@ H5S_raw_size(const H5F_t *f, const H5S_t *space) FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_raw_size) /* Return the size of buffer needed for extent */ - FUNC_LEAVE_NOAPI(H5O_raw_size(H5O_SDSPACE_ID, f, &(space->extent))) + FUNC_LEAVE_NOAPI(H5O_msg_raw_size(f, H5O_SDSPACE_ID, &(space->extent))) } /* end H5S_raw_size() */ diff --git a/src/H5SM.c b/src/H5SM.c index 38b8c75..e84490b 100755 --- a/src/H5SM.c +++ b/src/H5SM.c @@ -19,19 +19,20 @@ #define H5SM_PACKAGE /*suppress error about including H5SMpkg */ #define H5F_PACKAGE /*suppress error about including H5Fpkg */ + /***********/ /* Headers */ /***********/ #include "H5private.h" /* Generic Functions */ #include "H5ACprivate.h" /* Metadata cache */ #include "H5Eprivate.h" /* Error handling */ +#include "H5Fpkg.h" /* File access */ #include "H5FLprivate.h" /* Free Lists */ #include "H5MFprivate.h" /* File memory management */ #include "H5MMprivate.h" /* Memory management */ - -#include "H5Fpkg.h" /* File access */ #include "H5SMpkg.h" /* Shared object header messages */ + /****************/ /* Local Macros */ /****************/ @@ -44,10 +45,12 @@ #define H5SM_FHEAP_CHECKSUM_DBLOCKS TRUE #define H5SM_FHEAP_MAX_MAN_SIZE (4 * 1024) + /******************/ /* Local Typedefs */ /******************/ + /********************/ /* Local Prototypes */ /********************/ @@ -71,10 +74,12 @@ H5FL_ARR_DEFINE(H5SM_index_header_t, H5SM_MAX_INDEXES); H5FL_DEFINE(H5SM_list_t); H5FL_ARR_DEFINE(H5SM_sohm_t, H5SM_MAX_LIST_ELEMS); + /*****************************/ /* Library Private Variables */ /*****************************/ + /*******************/ /* Local Variables */ /*******************/ @@ -138,10 +143,9 @@ H5SM_init(H5F_t *f, H5P_genplist_t * fc_plist, hid_t dxpl_id) /* Check that type flags weren't duplicated anywhere */ type_flags_used = 0; - for(x=0; xshared->sohm_addr, NULL, NULL, H5AC_WRITE))) + if(NULL == (table = H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_WRITE))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, HADDR_UNDEF, "unable to load SOHM master table") /* JAMES! */ @@ -316,9 +322,9 @@ done: HGOTO_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, HADDR_UNDEF, "unable to close SOHM master table") FUNC_LEAVE_NOAPI(ret_value) -} - +} /* end H5SM_get_fheap_addr() */ + /*------------------------------------------------------------------------- * Function: H5SM_create_index * @@ -393,9 +399,8 @@ H5SM_create_index(H5F_t *f, H5SM_index_header_t *header, hid_t dxpl_id) done: /* Close the fractal heap if one has been created */ - if(fheap) - if(H5HF_close(fheap, dxpl_id) < 0) - HDONE_ERROR(H5E_HEAP, H5E_CLOSEERROR, FAIL, "can't close fractal heap") + if(fheap && H5HF_close(fheap, dxpl_id) < 0) + HDONE_ERROR(H5E_HEAP, H5E_CLOSEERROR, FAIL, "can't close fractal heap") FUNC_LEAVE_NOAPI(ret_value) } /* end H5SM_create_index */ @@ -458,28 +463,26 @@ H5SM_create_list(H5F_t *f, H5SM_index_header_t * header, hid_t dxpl_id) if(H5AC_set(f, dxpl_id, H5AC_SOHM_LIST, addr, list, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_CACHE, H5E_CANTINS, HADDR_UNDEF, "can't add SOHM list to cache") + /* Set return value */ ret_value = addr; + done: if(ret_value == HADDR_UNDEF) { - if(list != NULL) - { - if(list->messages != NULL) - H5FL_ARR_FREE(H5SM_sohm_t, list->messages); - H5FL_FREE(H5SM_list_t, list); - - } - if(addr != HADDR_UNDEF) - { - H5MF_xfree(f, H5FD_MEM_SOHM, dxpl_id, addr, size); - } + if(list != NULL) + { + if(list->messages != NULL) + H5FL_ARR_FREE(H5SM_sohm_t, list->messages); + H5FL_FREE(H5SM_list_t, list); + } + if(addr != HADDR_UNDEF) + H5MF_xfree(f, H5FD_MEM_SOHM, dxpl_id, addr, size); } FUNC_LEAVE_NOAPI(ret_value) } /* end H5SM_create_list */ - /*------------------------------------------------------------------------- * Function: H5SM_try_share * @@ -510,6 +513,7 @@ H5SM_try_share(H5F_t *f, hid_t dxpl_id, unsigned type_id, void *mesg) unsigned cache_flags = H5AC__NO_FLAGS_SET; ssize_t index_num; herr_t ret_value = TRUE; + FUNC_ENTER_NOAPI(H5SM_try_share, FAIL) /* Check whether this message ought to be shared or not */ @@ -554,7 +558,7 @@ H5SM_try_share(H5F_t *f, hid_t dxpl_id, unsigned type_id, void *mesg) HGOTO_DONE(FALSE); /* If the message isn't big enough, don't bother sharing it */ - if(0 == (mesg_size = H5O_mesg_size(type_id, f, mesg, 0))) + if(0 == (mesg_size = H5O_msg_mesg_size(f, type_id, mesg, 0))) HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "unable to get OH message size") if(mesg_size < table->indexes[index_num].min_mesg_size) HGOTO_DONE(FALSE); @@ -579,7 +583,7 @@ done: HDONE_ERROR(H5E_CACHE, H5E_CANTRELEASE, FAIL, "unable to close SOHM master table") FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5SM_try_share() */ /*------------------------------------------------------------------------- @@ -614,6 +618,7 @@ H5SM_write_mesg(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, size_t buf_size; /* Size of the encoded message */ void * encoding_buf=NULL; /* Buffer for encoded message */ herr_t ret_value = SUCCEED; + FUNC_ENTER_NOAPI(H5SM_write_mesg, FAIL) HDassert(cache_flags_ptr); @@ -627,17 +632,15 @@ H5SM_write_mesg(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, shared.flags = H5O_SHARED_IN_HEAP_FLAG; /* Encode the message to be written */ - if((buf_size = H5O_raw_size(type_id, f, mesg)) <= 0) - HGOTO_ERROR(H5E_OHDR, H5E_BADSIZE, FAIL, "can't find message size"); - + if((buf_size = H5O_msg_raw_size(f, type_id, mesg)) <= 0) + HGOTO_ERROR(H5E_OHDR, H5E_BADSIZE, FAIL, "can't find message size") if(NULL == (encoding_buf = H5MM_calloc(buf_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate buffer for encoding"); - - if(H5O_encode(f, encoding_buf, mesg, type_id) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTENCODE, FAIL, "can't encode message to be shared"); + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate buffer for encoding") + if(H5O_msg_encode(f, type_id, encoding_buf, mesg) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTENCODE, FAIL, "can't encode message to be shared") /* Open the fractal heap for this index */ - if(NULL == (fheap=H5HF_open(f, dxpl_id, header->heap_addr))) + if(NULL == (fheap = H5HF_open(f, dxpl_id, header->heap_addr))) HGOTO_ERROR(H5E_HEAP, H5E_CANTOPENOBJ, FAIL, "unable to open fractal heap") /* Set up a key for the message to be written */ @@ -660,7 +663,7 @@ H5SM_write_mesg(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, /* JAMES: not very effecient (gets hash value twice, searches list twice). Refactor. */ /* See if the message is already in the index and get its location */ /* JAMES: should return a pointer to the message */ - list_pos=H5SM_find_in_list(f, list, &key); + list_pos = H5SM_find_in_list(f, list, &key); if(list_pos != UFAIL) { /* The message was in the index. Increment its reference count. */ @@ -678,9 +681,7 @@ H5SM_write_mesg(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, /* If this returns failure, it means that the message wasn't found. */ /* If it succeeds, the heap_id in the shared struct will be set */ if(H5B2_modify(f, dxpl_id, H5SM_INDEX, header->index_addr, &key, H5SM_incr_ref, &shared.u.heap_id) >= 0) - { found = TRUE; - } } /* If the message isn't in the list, add it */ @@ -692,7 +693,7 @@ H5SM_write_mesg(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, /* JAMES: wrap this in a function call? */ /* Encode the message and get its size */ /* JAMES: already have this */ - if((mesg_size = H5O_raw_size(type_id, f, mesg)) == 0) + if((mesg_size = H5O_msg_raw_size(f, type_id, mesg)) == 0) HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "unable to get size of message") /* JAMES: fix memory problem */ @@ -772,14 +773,13 @@ H5SM_write_mesg(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, } /* Change the original message passed in to reflect that it's now shared */ - if(H5O_set_share(f, &shared, type_id, mesg) < 0) + if(H5O_msg_set_share(type_id, &shared, mesg) < 0) HGOTO_ERROR (H5E_OHDR, H5E_BADMESG, FAIL, "unable to set sharing information") done: /* Release the fractal heap if we opened it */ - if(fheap) - if(H5HF_close(fheap, dxpl_id) < 0) - HDONE_ERROR(H5E_HEAP, H5E_CLOSEERROR, FAIL, "can't close fractal heap") + if(fheap && H5HF_close(fheap, dxpl_id) < 0) + HDONE_ERROR(H5E_HEAP, H5E_CLOSEERROR, FAIL, "can't close fractal heap") /* If we got a list out of the cache, release it (it is always dirty after writing a message) */ if(list && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, list, H5AC__DIRTIED_FLAG) < 0) @@ -789,8 +789,7 @@ done: H5MM_free(encoding_buf); FUNC_LEAVE_NOAPI(ret_value) -} - +} /* end H5SM_write_mesg() */ /*------------------------------------------------------------------------- @@ -814,6 +813,7 @@ H5SM_try_delete(H5F_t *f, hid_t dxpl_id, unsigned type_id, const H5O_shared_t *s unsigned cache_flags = H5AC__NO_FLAGS_SET; ssize_t index_num; herr_t ret_value = SUCCEED; + FUNC_ENTER_NOAPI(H5SM_try_delete, FAIL) HDassert(f); @@ -826,7 +826,7 @@ H5SM_try_delete(H5F_t *f, hid_t dxpl_id, unsigned type_id, const H5O_shared_t *s HDassert(f->shared->sohm_addr != HADDR_UNDEF); /* Look up the master SOHM table */ - if (NULL == (table = H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_WRITE))) + if(NULL == (table = H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_WRITE))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM master table") /* Find the correct index and try to delete from it */ @@ -839,11 +839,11 @@ H5SM_try_delete(H5F_t *f, hid_t dxpl_id, unsigned type_id, const H5O_shared_t *s done: /* Release the master SOHM table */ - if (table && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, table, cache_flags) < 0) + if(table && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, table, cache_flags) < 0) HDONE_ERROR(H5E_CACHE, H5E_CANTRELEASE, FAIL, "unable to close SOHM master table") FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5SM_try_delete() */ /*------------------------------------------------------------------------- @@ -871,7 +871,7 @@ H5SM_find_in_list(H5F_t *f, H5SM_list_t *list, const H5SM_mesg_key_t *key) HDassert(list); HDassert(key); - for(x=0; xheader->list_to_btree; x++) + for(x = 0; x < list->header->list_to_btree; x++) { if(0 == H5SM_message_compare(key, &(list->messages[x]))) { @@ -909,6 +909,7 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, uns hsize_t list_pos; /* Position of the message in the list */ H5HF_t *fheap=NULL; /* Fractal heap that contains the message */ herr_t ret_value = SUCCEED; + FUNC_ENTER_NOAPI(H5SM_delete_from_index, FAIL) HDassert(header); @@ -926,8 +927,8 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, uns HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't get message size from fractal heap.") /* Allocate a buffer to hold the message */ - if(NULL == (buf = HDmalloc(buf_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "couldn't allocate memory"); + if(NULL == (buf = H5MM_malloc(buf_size))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "couldn't allocate memory") /* Read the message to get its hash value */ if(H5HF_read(fheap, dxpl_id, &(mesg->u.heap_id), buf) < 0) @@ -953,6 +954,7 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, uns HGOTO_ERROR(H5E_SOHM, H5E_NOTFOUND, FAIL, "message not in index") --(list->messages[list_pos].ref_count); + /* Copy the message */ message = list->messages[list_pos]; } @@ -1016,7 +1018,7 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, uns HGOTO_ERROR(H5E_SOHM, H5E_CANTINIT, FAIL, "unable to create shared message list") HDassert(NULL == list); - if (NULL == (list = H5AC_protect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, NULL, header, H5AC_WRITE))) + if(NULL == (list = H5AC_protect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, NULL, header, H5AC_WRITE))) HGOTO_ERROR(H5E_SOHM, H5E_CANTPROTECT, FAIL, "unable to load SOHM index") /* Delete the B-tree and have messages copy themselves to the @@ -1024,25 +1026,24 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, uns */ if(H5B2_delete(f, dxpl_id, H5SM_INDEX, temp_header.index_addr, H5SM_convert_to_list_op, list) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTDELETE, FAIL, "unable to delete B-tree") - } - } + } /* end if */ + } /* end if */ done: /* Free the message buffer */ if(buf) - HDfree(buf); + H5MM_xfree(buf); /* Release the SOHM list */ - if (list && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, list, H5AC__DIRTIED_FLAG) < 0) + if(list && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, list, H5AC__DIRTIED_FLAG) < 0) HDONE_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, FAIL, "unable to close SOHM index") /* Release the fractal heap if we opened it */ - if(fheap) - if(H5HF_close(fheap, dxpl_id) < 0) - HDONE_ERROR(H5E_HEAP, H5E_CLOSEERROR, FAIL, "can't close fractal heap") + if(fheap && H5HF_close(fheap, dxpl_id) < 0) + HDONE_ERROR(H5E_HEAP, H5E_CLOSEERROR, FAIL, "can't close fractal heap") FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5SM_delete_from_index() */ /*------------------------------------------------------------------------- @@ -1058,13 +1059,15 @@ done: * *------------------------------------------------------------------------- */ -herr_t H5SM_get_info(H5F_t *f, unsigned *index_flags, unsigned *minsizes, - size_t *list_to_btree, size_t *btree_to_list, hid_t dxpl_id) +herr_t +H5SM_get_info(H5F_t *f, unsigned *index_flags, unsigned *minsizes, + size_t *list_to_btree, size_t *btree_to_list, hid_t dxpl_id) { H5SM_master_table_t *table = NULL; haddr_t table_addr; uint8_t i; herr_t ret_value = SUCCEED; + FUNC_ENTER_NOAPI(H5SM_get_info, FAIL) HDassert(f); @@ -1102,5 +1105,5 @@ done: HGOTO_ERROR(H5E_CACHE, H5E_CANTRELEASE, FAIL, "unable to close SOHM master table") FUNC_LEAVE_NOAPI(ret_value) -} - +} /* end H5SM_get_info() */ + diff --git a/src/H5T.c b/src/H5T.c index 76619b1..08cdc7e 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -2843,7 +2843,7 @@ H5T_encode(H5T_t *obj, unsigned char *buf, size_t *nalloc) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "can't allocate fake file struct") /* Find out the size of buffer needed */ - if((buf_size = H5O_raw_size(H5O_DTYPE_ID, f, obj)) == 0) + if((buf_size = H5O_msg_raw_size(f, H5O_DTYPE_ID, obj)) == 0) HGOTO_ERROR(H5E_DATATYPE, H5E_BADSIZE, FAIL, "can't find datatype size") /* Don't encode if buffer size isn't big enough or buffer is empty */ @@ -2857,7 +2857,7 @@ H5T_encode(H5T_t *obj, unsigned char *buf, size_t *nalloc) *buf++ = H5T_ENCODE_VERSION; /* Encode into user's buffer */ - if(H5O_encode(f, buf, obj, H5O_DTYPE_ID) < 0) + if(H5O_msg_encode(f, H5O_DTYPE_ID, buf, obj) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "can't encode object") } /* end else */ @@ -2907,7 +2907,7 @@ H5T_decode(const unsigned char *buf) HGOTO_ERROR(H5E_DATATYPE, H5E_VERSION, NULL, "unknown version of encoded datatype") /* Decode the serialized datatype message */ - if((ret_value = H5O_decode(f, H5AC_dxpl_id, buf, H5O_DTYPE_ID)) == NULL) + if((ret_value = H5O_msg_decode(f, H5AC_dxpl_id, H5O_DTYPE_ID, buf)) == NULL) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, NULL, "can't decode object") done: diff --git a/src/H5Tcommit.c b/src/H5Tcommit.c index 1417638..2c1cf5b 100644 --- a/src/H5Tcommit.c +++ b/src/H5Tcommit.c @@ -272,7 +272,7 @@ H5T_commit(H5F_t *file, H5T_t *type, hid_t dxpl_id, hid_t tcpl_id, hid_t UNUSED loc_init = TRUE; /* Calculate message size infomation, for creating object header */ - dtype_size = H5O_mesg_size(H5O_DTYPE_ID, file, type, (size_t)0); + dtype_size = H5O_msg_mesg_size(file, H5O_DTYPE_ID, type, (size_t)0); HDassert(dtype_size); /* diff --git a/src/H5Toh.c b/src/H5Toh.c index 2137a8a..f6854e9 100644 --- a/src/H5Toh.c +++ b/src/H5Toh.c @@ -98,7 +98,7 @@ H5O_dtype_isa(struct H5O_t *oh) HDassert(oh); - if((ret_value = H5O_exists_oh(oh, H5O_DTYPE_ID, 0)) < 0) + if((ret_value = H5O_msg_exists_oh(oh, H5O_DTYPE_ID, 0)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to read object header") done: diff --git a/test/ohdr.c b/test/ohdr.c index 366da04..67d07a6 100644 --- a/test/ohdr.c +++ b/test/ohdr.c @@ -251,12 +251,12 @@ main(void) * Delete all time messages. */ TESTING("message deletion"); - if (H5O_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT)<0) { + if (H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT)<0) { H5_FAILED(); H5Eprint_stack(H5E_DEFAULT, stdout); goto error; } - if (H5O_remove(&oh_loc, H5O_MTIME_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT)<0) { + if (H5O_msg_remove(&oh_loc, H5O_MTIME_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT)<0) { H5_FAILED(); H5Eprint_stack(H5E_DEFAULT, stdout); goto error; -- cgit v0.12