Exemplo n.º 1
0
/*-------------------------------------------------------------------------
 * Function:	H5G_traverse_link_ud
 *
 * Purpose:	Callback for user-defined link traversal.  Sets up a
 *              location ID and passes it to the user traversal callback.
 *
 * Return:	Non-negative on success/Negative on failure
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, September 13, 2005
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5G_traverse_ud(const H5G_loc_t *grp_loc/*in,out*/, const H5O_link_t *lnk,
    H5G_loc_t *obj_loc/*in,out*/, size_t *nlinks/*in,out*/, hid_t _lapl_id,
    hid_t dxpl_id)
{
    const H5L_class_t   *link_class;       /* User-defined link class */
    hid_t               cb_return = -1;         /* The ID the user-defined callback returned */
    H5G_loc_t           grp_loc_copy;
    H5G_name_t          grp_path_copy;
    H5O_loc_t           grp_oloc_copy;
    H5O_loc_t          *new_oloc = NULL;
    H5F_t              *temp_file = NULL;
    H5G_t              *grp;
    hid_t               lapl_id = (-1);         /* LAPL local to this routine */
    H5P_genplist_t     *lapl;                   /* LAPL with nlinks set */
    hid_t               cur_grp = (-1);
    herr_t              ret_value = SUCCEED;    /* Return value */

    FUNC_ENTER_NOAPI_NOINIT(H5G_traverse_ud)

    /* Sanity check */
    HDassert(grp_loc);
    HDassert(lnk);
    HDassert(lnk->type >= H5L_TYPE_UD_MIN);
    HDassert(obj_loc);
    HDassert(nlinks);
    HDassert(_lapl_id >= 0);

    /* Reset the object's path information, because we can't detect any changes
     * in the "path" the user-defined callback takes */
    H5G_name_free(obj_loc->path);

    /* Get the link class for this type of link. */
    if(NULL == (link_class = H5L_find_class(lnk->type)))
        HGOTO_ERROR(H5E_LINK, H5E_NOTREGISTERED, FAIL, "unable to get UD link class")

    /* Set up location for user-defined callback.  Use a copy of our current
     * grp_loc. */
    grp_loc_copy.path = &grp_path_copy;
    grp_loc_copy.oloc = &grp_oloc_copy;
    H5G_loc_reset(&grp_loc_copy);
    if(H5G_loc_copy(&grp_loc_copy, grp_loc, H5_COPY_DEEP) < 0)
        HGOTO_ERROR(H5E_FILE, H5E_CANTCOPY, FAIL, "unable to copy object location")

    /* Create a group to pass to the user-defined callback */
    if((grp = H5G_open(&grp_loc_copy, dxpl_id)) == NULL)
        HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open group")
    if((cur_grp = H5I_register(H5I_GROUP, grp)) < 0)
        HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register group")

    /* Check for generic default property list and use link access default if so */
    if(_lapl_id == H5P_DEFAULT) {
        HDassert(H5P_LINK_ACCESS_DEFAULT != -1);
        if(NULL == (lapl = H5I_object(H5P_LINK_ACCESS_DEFAULT)))
            HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "unable to get default property list")
    } /* end if */
Exemplo n.º 2
0
/*-------------------------------------------------------------------------
 * Function:	H5G__open_name
 *
 * Purpose:	Opens an existing group by name.
 *
 * Return:	Success:	Ptr to a new group.
 *		Failure:	NULL
 *
 * Programmer:	Quincey Koziol
 *		Monday, August	27, 2007
 *
 *-------------------------------------------------------------------------
 */
H5G_t *
H5G__open_name(const H5G_loc_t *loc, const char *name, hid_t gapl_id,
    hid_t dxpl_id)
{
    H5G_t      *grp = NULL;             /* Group to open */
    H5G_loc_t   grp_loc;                /* Location used to open group */
    H5G_name_t  grp_path;            	/* Opened object group hier. path */
    H5O_loc_t   grp_oloc;            	/* Opened object object location */
    hbool_t     loc_found = FALSE;      /* Location at 'name' found */
    H5O_type_t  obj_type;               /* Type of object at location */
    H5G_t *ret_value = NULL;            /* Return value */

    FUNC_ENTER_PACKAGE

    /* Check args */
    HDassert(loc);
    HDassert(name);

    /* Set up opened group location to fill in */
    grp_loc.oloc = &grp_oloc;
    grp_loc.path = &grp_path;
    H5G_loc_reset(&grp_loc);

    /* Find the group object using the gapl passed in */
    if(H5G_loc_find(loc, name, &grp_loc/*out*/, gapl_id, dxpl_id) < 0)
        HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, NULL, "group not found")
    loc_found = TRUE;

    /* Check that the object found is the correct type */
    if(H5O_obj_type(&grp_oloc, &obj_type, dxpl_id) < 0)
        HGOTO_ERROR(H5E_SYM, H5E_CANTGET, NULL, "can't get object type")
    if(obj_type != H5O_TYPE_GROUP)
        HGOTO_ERROR(H5E_SYM, H5E_BADTYPE, NULL, "not a group")

    /* Open the group */
    if((grp = H5G_open(&grp_loc, dxpl_id)) == NULL)
        HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, NULL, "unable to open group")

    /* Set return value */
    ret_value = grp;

done:
    if(!ret_value) {
        if(loc_found && H5G_loc_free(&grp_loc) < 0)
            HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, NULL, "can't free location")
    } /* end if */

    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G__open_name() */
Exemplo n.º 3
0
Arquivo: H5Rint.c Projeto: Kitware/ITK
/*--------------------------------------------------------------------------
 NAME
    H5R__dereference
 PURPOSE
    Opens the HDF5 object referenced.
 USAGE
    hid_t H5R__dereference(ref, oapl_id, ref_type, ref)
        H5F_t *file;        IN: File the object being dereferenced is within
        hid_t oapl_id;      IN: Object access property list ID
        H5R_type_t ref_type; IN: Type of reference
        void *ref;          IN: Reference to open.

 RETURNS
    Valid ID on success, Negative on failure
 DESCRIPTION
    Given a reference to some object, open that object and return an ID for
    that object.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
    Currently only set up to work with references to datasets
 EXAMPLES
 REVISION LOG
    Raymond Lu
    13 July 2011
    I added the OAPL_ID parameter for the object being referenced.  It only
    supports dataset access property list currently.

    M. Scot Breitenfeld
    3 March 2015
    Added a check for undefined reference pointer.
--------------------------------------------------------------------------*/
hid_t
H5R__dereference(H5F_t *file, hid_t oapl_id, H5R_type_t ref_type,
    const void *_ref)
{
    H5O_loc_t oloc;             /* Object location */
    H5G_name_t path;            /* Path of object */
    H5G_loc_t loc;              /* Group location */
    unsigned rc;		/* Reference count of object */
    H5O_type_t obj_type;        /* Type of object */
    hid_t ret_value = H5I_INVALID_HID;  /* Return value */

    FUNC_ENTER_PACKAGE_VOL

    HDassert(_ref);
    HDassert(ref_type > H5R_BADTYPE && ref_type < H5R_MAXTYPE);
    HDassert(file);

    /* Initialize the object location */
    H5O_loc_reset(&oloc);
    oloc.file = file;

    switch (ref_type) {
        case H5R_OBJECT:
        {
            oloc.addr = *(const hobj_ref_t *)_ref; /* Only object references currently supported */
            if (!H5F_addr_defined(oloc.addr) || oloc.addr == 0)
                HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "Undefined reference pointer")
            break;
        }

        case H5R_DATASET_REGION:
        {
            H5HG_t hobjid;  /* Heap object ID */
            uint8_t *buf;   /* Buffer to store serialized selection in */
            const uint8_t *p;           /* Pointer to OID to store */

            /* Get the heap ID for the dataset region */
            p = (const uint8_t *)_ref;
            H5F_addr_decode(oloc.file, &p, &(hobjid.addr));
            UINT32DECODE(p, hobjid.idx);

            if (!H5F_addr_defined(hobjid.addr) || hobjid.addr == 0)
                HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "Undefined reference pointer")

            /* Get the dataset region from the heap (allocate inside routine) */
            if(NULL == (buf = (uint8_t *)H5HG_read(oloc.file, &hobjid, NULL, NULL)))
                HGOTO_ERROR(H5E_REFERENCE, H5E_READERROR, H5I_INVALID_HID, "Unable to read dataset region information")

            /* Get the object oid for the dataset */
            p = buf;
            H5F_addr_decode(oloc.file, &p, &(oloc.addr));

            /* Free the buffer allocated in H5HG_read() */
            H5MM_xfree(buf);
            break;
        } /* end case H5R_DATASET_REGION */

        case H5R_BADTYPE:
        case H5R_MAXTYPE:
        default:
            HDassert("unknown reference type" && 0);
            HGOTO_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, H5I_INVALID_HID, "internal error (unknown reference type)")
    } /* end switch */

    /* Get the # of links for object, and its type
     * (To check to make certain that this object hasn't been deleted
     *  since the reference was created)
     */
    if(H5O_get_rc_and_type(&oloc, &rc, &obj_type) < 0 || 0 == rc)
        HGOTO_ERROR(H5E_REFERENCE, H5E_LINKCOUNT, H5I_INVALID_HID, "dereferencing deleted object")

    /* Construct a group location for opening the object */
    H5G_name_reset(&path);
    loc.oloc = &oloc;
    loc.path = &path;

    /* Open the object */
    switch (obj_type) {
        case H5O_TYPE_GROUP:
        {
            H5G_t *group;               /* Pointer to group to open */

            if(NULL == (group = H5G_open(&loc)))
                HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, H5I_INVALID_HID, "not found")

            /* Create an atom for the group */
            if((ret_value = H5I_register(H5I_GROUP, group, TRUE)) < 0) {
                H5G_close(group);
                HGOTO_ERROR(H5E_SYM, H5E_CANTREGISTER, H5I_INVALID_HID, "can't register group")
            } /* end if */

            break;
        }

        case H5O_TYPE_NAMED_DATATYPE:
        {
            H5T_t *type;                /* Pointer to datatype to open */

            if(NULL == (type = H5T_open(&loc)))
                HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, H5I_INVALID_HID, "not found")

            /* Create an atom for the datatype */
            if((ret_value = H5I_register(H5I_DATATYPE, type, TRUE)) < 0) {
                H5T_close(type);
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, H5I_INVALID_HID, "can't register datatype")
            } /* end if */

            break;
        }