diff options
Diffstat (limited to 'src/H5O.c')
-rw-r--r-- | src/H5O.c | 92 |
1 files changed, 63 insertions, 29 deletions
@@ -1393,9 +1393,9 @@ done: /*------------------------------------------------------------------------- - * Function: H5O_link + * Function: H5O_link_oh * - * Purpose: Adjust the link count for an object header by adding + * Purpose: Adjust the link count for an open object header by adding * ADJUST to the link count. * * Return: Success: New link count @@ -1409,24 +1409,12 @@ done: *------------------------------------------------------------------------- */ int -H5O_link(const H5O_loc_t *loc, int adjust, hid_t dxpl_id) +H5O_link_oh(H5F_t *f, int adjust, hid_t dxpl_id, H5O_t *oh, unsigned *oh_flags) { - H5O_t *oh = NULL; - H5AC_protect_t oh_acc; /* Access mode for protecting object header */ - unsigned oh_flags = H5AC__NO_FLAGS_SET; /* Whether the object was deleted */ + haddr_t addr = H5O_OH_GET_ADDR(oh); /* Object header address */ int ret_value; /* Return value */ - FUNC_ENTER_NOAPI(H5O_link, FAIL) - - /* check args */ - HDassert(loc); - HDassert(loc->file); - HDassert(H5F_addr_defined(loc->addr)); - - /* get header */ - oh_acc = adjust ? H5AC_WRITE : H5AC_READ; - if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, oh_acc))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "unable to load object header") + FUNC_ENTER_NOAPI(H5O_link_oh, FAIL) /* Check for adjusting link count */ if(adjust) { @@ -1435,38 +1423,38 @@ H5O_link(const H5O_loc_t *loc, int adjust, hid_t dxpl_id) if((unsigned)(-adjust) > oh->nlink) HGOTO_ERROR(H5E_OHDR, H5E_LINKCOUNT, FAIL, "link count would be negative") oh->nlink += adjust; - oh_flags |= H5AC__DIRTIED_FLAG; + *oh_flags |= H5AC__DIRTIED_FLAG; /* Check if the object should be deleted */ if(oh->nlink == 0) { /* Check if the object is still open by the user */ - if(H5FO_opened(loc->file, loc->addr) != NULL) { + if(H5FO_opened(f, addr) != NULL) { /* Flag the object to be deleted when it's closed */ - if(H5FO_mark(loc->file, loc->addr, TRUE) < 0) + if(H5FO_mark(f, addr, TRUE) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, FAIL, "can't mark object for deletion") } /* end if */ else { /* Delete object right now */ - if(H5O_delete_oh(loc->file, dxpl_id, oh) < 0) + if(H5O_delete_oh(f, dxpl_id, oh) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, FAIL, "can't delete object from file") /* Mark the object header as deleted */ - oh_flags = H5AC__DELETED_FLAG | H5AC__FREE_FILE_SPACE_FLAG; + *oh_flags = H5AC__DELETED_FLAG | H5AC__FREE_FILE_SPACE_FLAG; } /* end else */ } /* end if */ } else { /* A new object, or one that will be deleted */ if(oh->nlink == 0) { /* Check if the object is current open, but marked for deletion */ - if(H5FO_marked(loc->file, loc->addr) > 0) { + if(H5FO_marked(f, addr) > 0) { /* Remove "delete me" flag on the object */ - if(H5FO_mark(loc->file, loc->addr, FALSE) < 0) + if(H5FO_mark(f, addr, FALSE) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTDELETE, FAIL, "can't mark object for deletion") } /* end if */ } /* end if */ oh->nlink += adjust; - oh_flags |= H5AC__DIRTIED_FLAG; + *oh_flags |= H5AC__DIRTIED_FLAG; } /* end if */ /* Check for operations on refcount message */ @@ -1475,7 +1463,7 @@ H5O_link(const H5O_loc_t *loc, int adjust, hid_t dxpl_id) if(oh->has_refcount_msg) { /* Check for removing refcount message */ if(oh->nlink <= 1) { - if(H5O_msg_remove_real(loc->file, oh, H5O_MSG_REFCOUNT, H5O_ALL, NULL, NULL, TRUE, dxpl_id) < 0) + if(H5O_msg_remove_real(f, oh, H5O_MSG_REFCOUNT, H5O_ALL, NULL, NULL, TRUE, dxpl_id) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTDELETE, FAIL, "unable to delete refcount message") oh->has_refcount_msg = FALSE; } /* end if */ @@ -1483,7 +1471,7 @@ H5O_link(const H5O_loc_t *loc, int adjust, hid_t dxpl_id) else { H5O_refcount_t refcount = oh->nlink; - if(H5O_msg_write_real(loc->file, dxpl_id, oh, H5O_MSG_REFCOUNT, H5O_MSG_FLAG_DONTSHARE, 0, &refcount) < 0) + if(H5O_msg_write_real(f, dxpl_id, oh, H5O_MSG_REFCOUNT, H5O_MSG_FLAG_DONTSHARE, 0, &refcount) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTUPDATE, FAIL, "unable to update refcount message") } /* end else */ } /* end if */ @@ -1492,7 +1480,7 @@ H5O_link(const H5O_loc_t *loc, int adjust, hid_t dxpl_id) if(oh->nlink > 1) { H5O_refcount_t refcount = oh->nlink; - if(H5O_msg_append_real(loc->file, dxpl_id, oh, H5O_MSG_REFCOUNT, H5O_MSG_FLAG_DONTSHARE, 0, &refcount) < 0) + if(H5O_msg_append_real(f, dxpl_id, oh, H5O_MSG_REFCOUNT, H5O_MSG_FLAG_DONTSHARE, 0, &refcount) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTINSERT, FAIL, "unable to create new refcount message") oh->has_refcount_msg = TRUE; } /* end if */ @@ -1504,6 +1492,51 @@ H5O_link(const H5O_loc_t *loc, int adjust, hid_t dxpl_id) ret_value = oh->nlink; done: + FUNC_LEAVE_NOAPI(ret_value); +} /* end H5O_link_oh() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_link + * + * Purpose: Adjust the link count for an object header by adding + * ADJUST to the link count. + * + * Return: Success: New link count + * + * Failure: Negative + * + * Programmer: Robb Matzke + * matzke@llnl.gov + * Aug 5 1997 + * + *------------------------------------------------------------------------- + */ +int +H5O_link(const H5O_loc_t *loc, int adjust, hid_t dxpl_id) +{ + H5O_t *oh = NULL; + H5AC_protect_t oh_acc; /* Access mode for protecting object header */ + unsigned oh_flags = H5AC__NO_FLAGS_SET; /* Whether the object was deleted */ + int ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_link, FAIL) + + /* check args */ + HDassert(loc); + HDassert(loc->file); + HDassert(H5F_addr_defined(loc->addr)); + + /* get header */ + oh_acc = adjust ? H5AC_WRITE : H5AC_READ; + if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, oh_acc))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "unable to load object header") + + /* Call the "real" link routine */ + if((ret_value = H5O_link_oh(loc->file, adjust, dxpl_id, oh, &oh_flags)) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_LINKCOUNT, FAIL, "unable to adjust object link count") + +done: 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") @@ -2383,7 +2416,8 @@ H5O_get_info(H5O_loc_t *oloc, hid_t dxpl_id, hbool_t want_ih_info, H5O_info_t *o } /* end for */ /* Retrieve # of attributes */ - oinfo->num_attrs = H5O_attr_count_real(oloc->file, dxpl_id, oh); + if(H5O_attr_count_real(oloc->file, dxpl_id, oh, &oinfo->num_attrs) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't retrieve attribute count") /* Get B-tree & heap metadata storage size, if requested */ if(want_ih_info) { |