コード例 #1
0
ファイル: h5trav.c プロジェクト: GATB/gatb-core
/*-------------------------------------------------------------------------
 * Function: trav_print_visit_lnk
 *
 * Purpose:  Callback for visiting link, when printing info
 *
 * Return:   0 on success,
 *          -1 on failure
 *-------------------------------------------------------------------------
 */
static int
trav_print_visit_lnk(const char *path, const H5L_info_t *linfo, void *udata)
{
    trav_print_udata_t *print_udata = (trav_print_udata_t *)udata;

    /* Print appropriate information for the type of link */
    switch(linfo->type) {
        case H5L_TYPE_SOFT:
            if(linfo->u.val_size > 0) {
                char *targbuf = (char*)HDmalloc(linfo->u.val_size + 1);
                if(targbuf) {
                    if(H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT) < 0)
                        targbuf[0] = 0;
                    printf(" %-10s %s -> %s\n", "link", path, targbuf);
                    HDfree(targbuf);
                }
            } /* end if */
            else
                printf(" %-10s %s ->\n", "link", path);
            break;

        case H5L_TYPE_EXTERNAL:
            if(linfo->u.val_size > 0) {
                char *targbuf = NULL;
                const char *filename = NULL;
                const char *objname = NULL;

                targbuf = (char*)HDmalloc(linfo->u.val_size + 1);
                if(targbuf) {
                    if(H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT) < 0)
                        targbuf[0] = 0;
                    if(H5Lunpack_elink_val(targbuf, linfo->u.val_size, NULL, &filename, &objname) >= 0)
                        printf(" %-10s %s -> %s %s\n", "ext link", path, filename, objname);
                    HDfree(targbuf);
                }
            } /* end if */
            else
                printf(" %-10s %s ->\n", "ext link", path);
            break;

        case H5L_TYPE_HARD:
            /* Should be handled elsewhere */
            return(-1);

        case H5L_TYPE_ERROR:
        case H5L_TYPE_MAX:
        default:
            printf(" %-10s %s -> ???\n", "unknown type of UD link", path);
            break;
    } /* end switch() */

    return(0);
} /* end trav_print_visit_lnk() */
コード例 #2
0
ファイル: h5trav.c プロジェクト: FilipeMaia/hdf5
/*-------------------------------------------------------------------------
 * Function: trav_print_visit_lnk
 *
 * Purpose: Callback for visiting link, when printing info
 *
 * Return: 0 on success, -1 on failure
 *
 * Programmer: Quincey Koziol, [email protected]
 *
 * Date: September 6, 2007
 *
 *-------------------------------------------------------------------------
 */
static int
trav_print_visit_lnk(const char *path, const H5L_info_t *linfo, void *udata)
{
    trav_print_udata_t *print_udata = (trav_print_udata_t *)udata;

    /* Print appropriate information for the type of link */
    switch(linfo->type) {
        case H5L_TYPE_SOFT:
            if(linfo->u.val_size > 0) {
                char *targbuf = (char*)HDmalloc(linfo->u.val_size + 1);
                HDassert(targbuf);

                H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT);
                printf(" %-10s %s -> %s\n", "link", path, targbuf);
                HDfree(targbuf);
            } /* end if */
            else
                printf(" %-10s %s ->\n", "link", path);
            break;

        case H5L_TYPE_EXTERNAL:
            if(linfo->u.val_size > 0) {
                char *targbuf;
                const char *filename;
                const char *objname;

                targbuf = (char*)HDmalloc(linfo->u.val_size + 1);
                HDassert(targbuf);

                H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT);
                H5Lunpack_elink_val(targbuf, linfo->u.val_size, NULL, &filename, &objname);
                printf(" %-10s %s -> %s %s\n", "ext link", path, filename, objname);
                HDfree(targbuf);
            } /* end if */
            else
                printf(" %-10s %s ->\n", "ext link", path);
            break;

        default:
            printf(" %-10s %s -> ???\n", "unknown type of UD link", path);
            break;
    } /* end switch() */

    return(0);
} /* end trav_print_visit_lnk() */
コード例 #3
0
int VsFilter::visitLinks(hid_t locId, const char* name,
    const H5L_info_t *linfo, void* opdata) {
  VsLog::debugLog() <<"VsFilter::visitLinks() - looking at object " <<name <<std::endl;
  
  switch (linfo->type) {
    case H5L_TYPE_HARD: {

      H5O_info_t objinfo;

      /* Stat the object */
      if(H5Oget_info_by_name(locId, name, &objinfo, H5P_DEFAULT) < 0) {
        VsLog::errorLog() <<"VsFilter::visitLinks() - unable to open object with name " <<name <<std::endl;
        VsLog::errorLog() <<"VsFilter::visitLinks() - this object and all children will be dropped." <<std::endl;
        return 0;
      }

      switch(objinfo.type)
      {
        case H5O_TYPE_GROUP:
        return visitGroup( locId, name, opdata );
        break;
        case H5O_TYPE_DATASET:
        return visitDataset( locId, name, opdata );
        break;

        default:
        VsLog::debugLog() << "VsFilter::visitLinks: node '" << name <<
        "' has an unknown type " << objinfo.type << std::endl;
        break;
      }
    }
    break;
    //end of case H5L_TYPE_HARD
    case H5L_TYPE_EXTERNAL: {

      char *targbuf = (char*) malloc( linfo->u.val_size );

      if (H5Lget_val(locId, name, targbuf, linfo->u.val_size, H5P_DEFAULT) < 0) {
        VsLog::errorLog() <<"VsFilter::visitLinks() - unable to open external link with name " <<targbuf <<std::endl;
        VsLog::errorLog() <<"VsFilter::visitLinks() - this object and all children will be dropped." <<std::endl;
        return 0;
      }
      
      const char *filename;
      const char *targname;

      if (H5Lunpack_elink_val(targbuf, linfo->u.val_size, 0, &filename, &targname) < 0) {
        VsLog::errorLog() <<"VsFilter::visitLinks() - unable to open external file with name " <<filename <<std::endl;
        VsLog::errorLog() <<"VsFilter::visitLinks() - this object and all children will be dropped." <<std::endl;
        return 0;
      }
      
      VsLog::debugLog() << "VsFilter::visitLinks(): node '" << name << "' is an external link." << std::endl;
      VsLog::debugLog() << "VsFilter::visitLinks(): node '" << targname << "' is an external target group." << std::endl;

      free(targbuf);
      targbuf = NULL;
      
      // Get info of the linked object.
      H5O_info_t objinfo;
#ifndef H5_USE_16_API
      hid_t obj_id = H5Oopen(locId, name, H5P_DEFAULT);
#else
      hid_t obj_id = H5Oopen(locId, name);        
#endif
      
      if (obj_id < 0) {
        VsLog::errorLog() <<"VsFilter::visitLinks() - unable to get id for external object " <<name <<std::endl;
        VsLog::errorLog() <<"VsFilter::visitLinks() - this object and all children will be dropped." <<std::endl;
        return 0;
      }

      //Test-open the linked object
      if (H5Oget_info (obj_id, &objinfo) < 0) {
        VsLog::errorLog() <<"VsFilter::visitLinks() - unable to open external object " <<name <<std::endl;
        VsLog::errorLog() <<"VsFilter::visitLinks() - this object and all children will be dropped." <<std::endl;
        return 0;
      }
      
      //Close the linked object to release hdf5 id
      H5Oclose( obj_id );

      //Finally, decide what to do depending on what type of object this is
      switch(objinfo.type)
      {
        case H5O_TYPE_GROUP:
        return visitGroup( locId, name, opdata );
        break;
        case H5O_TYPE_DATASET:
        return visitDataset( locId, name, opdata );
        break;

        default:
          VsLog::debugLog() << "VsFilter::visitLinks: node '" << name <<
        "' has an unknown type " << objinfo.type << std::endl;
        break;
      }
    }
    break;
      //END OF CASE H5L_TYPE_EXTERNAL
    
    default:
    VsLog::debugLog() << "VsFilter::visitLinks: node '" << name <<
    "' has an unknown object type " << linfo->type << std::endl;
    break;
  }

  return 0;
}
コード例 #4
0
/* "Windows to Unix" traversal function for external links
 *
 * Translates a filename stored in Unix format to Windows format by replacing
 * forward slashes with backslashes.
 * Makes no attempt to handle Windows drive names (e.g., "C:\"), spaces within
 * file names, quotes, etc.  These are left as an exercise for the user. :)
 * Note that this may not be necessary on your system; many Windows systems can
 * understand Unix paths.
 */
static hid_t elink_unix2win_trav(const char *link_name, hid_t cur_group,
    const void *udata, size_t udata_size, hid_t lapl_id)
{
    hid_t         fid;
    const char   *file_name;
    const char   *obj_name;
    char         *new_fname = NULL;     /* Buffer allocated to hold Unix file path */
    ssize_t       prefix_len;           /* External link prefix length */
    size_t        fname_len;
    size_t        start_pos;            /* Initial position in new_fname buffer */
    size_t        x;                    /* Counter variable */
    hid_t         ret_value = -1;

    printf("Converting Unix path to Windows path.\n");

    if(H5Lunpack_elink_val(udata, udata_size, NULL, &file_name, &obj_name) < 0)
        goto error;
    fname_len = strlen(file_name);

    /* See if the external link prefix property is set */
    if((prefix_len = H5Pget_elink_prefix(lapl_id, NULL, 0)) < 0)
        goto error;

    /* If so, prepend it to the filename.  We assume that the prefix
     * is in the correct format for the current file system.
     */
    if(prefix_len > 0)
    {
        /* Allocate a buffer to hold the filename plus prefix */
        new_fname = malloc(prefix_len + fname_len + 1);

        /* Copy the prefix into the buffer */
        if(H5Pget_elink_prefix(lapl_id, new_fname, (size_t)(prefix_len + 1)) < 0)
            goto error;

        start_pos = prefix_len;
    }
    else
    {
        /* Allocate a buffer to hold just the filename */
        new_fname = malloc(fname_len + 1);
        start_pos = 0;
    }

    /* We should now copy file_name into new_fname starting at position pos.
     * We'll convert '/' characters into '\' characters as we go.
     */
    for(x=0; file_name[x] != '\0'; x++)
    {
        if(file_name[x] == '/')
            new_fname[x + start_pos] = '\\';
        else
            new_fname[x + start_pos] = file_name[x];
    }
    new_fname[x + start_pos] = '\0';

    /* Now open the file and object within it */
    if((fid = H5Fopen(new_fname, H5F_ACC_RDWR, H5P_DEFAULT)) < 0)
        goto error;
    ret_value = H5Oopen(fid, obj_name, lapl_id); /* If this fails, our return value will be negative. */
    if(H5Fclose(fid) < 0)
        goto error;

    /* Free file name if it's been allocated */
    if(new_fname)
        free(new_fname);

    return ret_value;

error:
    /* Free file name if it's been allocated */
    if(new_fname)
        free(new_fname);
    return -1;
}
コード例 #5
0
ファイル: h5lImp.c プロジェクト: Starlink/hdf5
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Lget_value_by_idx
 * Signature: (JLjava/lang/String;IIJ[Ljava/lang/String;J)I
 */
JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Lget_1value_1by_1idx
    (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jint index_field, jint order,
        jlong link_n, jobjectArray link_value, jlong access_id)
{
    herr_t      status;
    size_t      buf_size;
    H5L_info_t  infobuf;
    const char *lName;
    void       *lValue;
    const char *file_name;
    const char *obj_name;
    jstring     str;

    infobuf.type = -1;
    PIN_JAVA_STRING(name, lName);
    if (lName != NULL) {
        /* get the length of the link valuee */
        status = H5Lget_info_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, &infobuf, (hid_t)access_id);
        if(status < 0) {
            h5libraryError(env);
        } /* end if */
        else {
            buf_size = infobuf.u.val_size;
            if(buf_size == 0) {
                h5libraryError(env);
            } /* end if */
            else {
                lValue = (void*)HDmalloc(buf_size);
                if (lValue == NULL) {
                    h5outOfMemory(env, "H5Lget_val_by_idx:  malloc failed ");
                } /* end if */
                else {
                    status = H5Lget_val_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (void*)lValue, (size_t)buf_size, (hid_t)access_id);

                    if (status < 0) {
                        h5libraryError(env);
                    } /* end if */
                    else if(infobuf.type == H5L_TYPE_EXTERNAL) {
                        status = H5Lunpack_elink_val((char*)lValue, (size_t)infobuf.u.val_size, (unsigned*)NULL, (const char**)&file_name, (const char**)&obj_name);
                        if (status < 0) {
                            h5libraryError(env);
                        } /* end if */
                        else {
                            str = ENVPTR->NewStringUTF(ENVPAR obj_name);
                            if (str == NULL) {
                                h5JNIFatalError(env, "H5Lget_val_by_idx:  return string not created");
                            } /* end if */
                            else {
                                ENVPTR->SetObjectArrayElement(ENVPAR link_value, 0, str);

                                str = ENVPTR->NewStringUTF(ENVPAR file_name);
                                if (str == NULL) {
                                    h5JNIFatalError(env, "H5Lget_val_by_idx:  return string not created");
                                } /* end if */
                                else {
                                    ENVPTR->SetObjectArrayElement(ENVPAR link_value, 1, str);
                                } /* end else */
                            } /* end else */
                        } /* end else */
                    } /* end else if */
                    else {
                        str = ENVPTR->NewStringUTF(ENVPAR (char *)lValue);
                        if (str == NULL) {
                            h5JNIFatalError(env, "H5Lget_val_by_idx:  return string not created");
                        } /* end if */
                        else {
                            ENVPTR->SetObjectArrayElement(ENVPAR link_value, 0, str);
                        } /* end else */
                    } /* end else */
                    HDfree(lValue);
                } /* end else */
            } /* end else */
        } /* end else */
        UNPIN_JAVA_STRING(name, lName);
    }

    return infobuf.type;
} /* end Java_hdf_hdf5lib_H5_H5Lget_1val_1by_1idx */
コード例 #6
0
ファイル: h5lImp.c プロジェクト: Starlink/hdf5
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Lget_value
 * Signature: (JLjava/lang/String;[Ljava/lang/String;J)I
 */
JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Lget_1value
    (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jobjectArray link_value, jlong access_id)
{
    size_t      buf_size;
    herr_t      status;
    H5L_info_t  infobuf;
    const char *lName;
    char       *lValue;
    const char *file_name;
    const char *obj_name;
    jstring     str;

    infobuf.type = -1;
    PIN_JAVA_STRING(name, lName);
    if (lName != NULL) {
        /* get the length of the link val */
        status = H5Lget_info((hid_t)loc_id, lName, &infobuf, H5P_DEFAULT);
        if(status < 0) {
            h5libraryError(env);
        } /* end if */
        else {
            buf_size = infobuf.u.val_size + 1;/* add extra space for the null terminator */

            if(infobuf.type == H5L_TYPE_HARD) {
                h5JNIFatalError(env, "H5Lget_val:  link is hard type");
            } /* end if */
            else {
                lValue = (char*)HDmalloc(sizeof(char) * buf_size);
                if (lValue == NULL) {
                    h5outOfMemory(env, "H5Lget_val:  malloc failed");
                } /* end if */
                else {
                    status = H5Lget_val((hid_t)loc_id, lName, (void*)lValue, buf_size, (hid_t)access_id);

                    if (status < 0) {
                        h5libraryError(env);
                    } /* end if */
                    else if(infobuf.type == H5L_TYPE_EXTERNAL) {
                        status = H5Lunpack_elink_val(lValue, (size_t)infobuf.u.val_size, (unsigned*)NULL, &file_name, &obj_name);
                        if (status < 0) {
                            h5libraryError(env);
                        } /* end if */
                        else {
                            str = ENVPTR->NewStringUTF(ENVPAR obj_name);
                            if (str == NULL) {
                                h5JNIFatalError(env, "H5Lget_val:  return string not created");
                            } /* end if */
                            else {
                                ENVPTR->SetObjectArrayElement(ENVPAR link_value, 0, str);

                                str = ENVPTR->NewStringUTF(ENVPAR file_name);
                                if (str == NULL) {
                                    h5JNIFatalError(env, "H5Lget_val:  return string not created");
                                } /* end if */
                                else {
                                    ENVPTR->SetObjectArrayElement(ENVPAR link_value, 1, str);
                                } /* end else */
                            } /* end else */
                        } /* end else */
                    } /* end else if */
                    else {
                        str = ENVPTR->NewStringUTF(ENVPAR lValue);
                        if (str == NULL) {
                            /* exception -- fatal JNI error */
                            h5JNIFatalError(env, "H5Lget_val:  return string not created");
                        } /* end if */
                        else {
                            ENVPTR->SetObjectArrayElement(ENVPAR link_value, 0, str);
                        } /* end else */
                    } /* end else */
                    HDfree(lValue);
                } /* end else */
            } /* end else */
        } /* end else */
        UNPIN_JAVA_STRING(name, lName);
    }

    return infobuf.type;
} /* end Java_hdf_hdf5lib_H5_H5Lget_1val */