static void soft_link_example(void) { hid_t file_id; hid_t group_id; /* Define the link class that we'll use to register "user-defined soft * links" using the callbacks we defined above. * A link class can have NULL for any callback except its traverse * callback. */ const H5L_class_t UD_soft_class[1] = {{ H5L_LINK_CLASS_T_VERS, /* Version number for this struct. * This field is always H5L_LINK_CLASS_T_VERS */ (H5L_type_t)UD_SOFT_CLASS, /* Link class id number. This can be any * value between H5L_TYPE_UD_MIN (64) and * H5L_TYPE_MAX (255). It should be a * value that isn't already being used by * another kind of link. We'll use 65. */ "UD_soft_link", /* Link class name for debugging */ NULL, /* Creation callback */ NULL, /* Move callback */ NULL, /* Copy callback */ UD_soft_traverse, /* The actual traversal function */ NULL, /* Deletion callback */ NULL /* Query callback */ }}; /* First, create a file and an object within the file for the link to * point to. */ file_id = H5Fcreate(SOFT_LINK_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); group_id = H5Gcreate2(file_id, TARGET_GROUP, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Gclose(group_id); /* This is how we create a normal soft link to the group. */ H5Lcreate_soft(TARGET_GROUP, file_id, SOFT_LINK_NAME, H5P_DEFAULT, H5P_DEFAULT); /* To do the same thing using a user-defined link, we first have to * register the link class we defined. */ H5Lregister(UD_soft_class); /* Now create a user-defined link. We give it the path to the group * as its udata.1 */ H5Lcreate_ud(file_id, UD_SOFT_LINK_NAME, (H5L_type_t)UD_SOFT_CLASS, TARGET_GROUP, strlen(TARGET_GROUP) + 1, H5P_DEFAULT, H5P_DEFAULT); /* We can access the group through the UD soft link like we would through * a normal soft link. This link will still dangle if the object's * original name is changed or unlinked. */ group_id = H5Gopen2(file_id, UD_SOFT_LINK_NAME, H5P_DEFAULT); /* The group is now open normally. Don't forget to close it! */ H5Gclose(group_id); H5Fclose(file_id); }
/* * Class: hdf_hdf5lib_H5 * Method: H5Lcreate_soft * Signature: (Ljava/lang/String;JLjava/lang/String;JJ)V */ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Lcreate_1soft (JNIEnv *env, jclass clss, jstring cur_name, jlong dst_loc_id, jstring dst_name, jlong create_id, jlong access_id) { herr_t status = -1; const char *lCurName; const char *lDstName; PIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); if (lCurName != NULL && lDstName != NULL) { status = H5Lcreate_soft(lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); if (status < 0) h5libraryError(env); } } /* end Java_hdf_hdf5lib_H5_H5Lcreate_1soft */
CXI_Data_Reference * cxi_create_data_link(CXI_Entry * entry, CXI_Dataset * data){ if(!entry || ! data){ return NULL; } if(entry->handle <= 0 || data->handle <= 0){ return NULL; } CXI_Data * root_data = calloc(sizeof(CXI_Data),1); CXI_Data_Reference * data_ref = cxi_create_data(entry->handle,root_data); if(!data_ref) return NULL; char path[1024]; if(H5Iget_name(data->handle, path, 1024) <= 0){ return NULL; } if(H5Lcreate_soft(path, root_data->handle, "data", H5P_DEFAULT, H5P_DEFAULT) < 0){ return NULL; } return data_ref; }
//-------------------------------------------------------------------------- // Function: CommonFG::link ///\brief Creates a link of the specified type from \a new_name to /// \a curr_name. ///\param link_type - IN: Link type; possible values are /// \li \c H5G_LINK_HARD /// \li \c H5G_LINK_SOFT ///\param curr_name - IN: Name of the existing object if link is a hard /// link; can be anything for the soft link ///\param new_name - IN: New name for the object ///\exception H5::FileIException or H5::GroupIException ///\par Description /// Note that both names are interpreted relative to the /// specified location. /// For information on creating hard link and soft link, please /// refer to the C layer Reference Manual at: /// http://hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-CreateHard and /// http://hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-CreateSoft // Programmer Binh-Minh Ribler - 2000 // Modification // 2007: QAK modified to use H5L APIs - BMR //-------------------------------------------------------------------------- void CommonFG::link( H5L_type_t link_type, const char* curr_name, const char* new_name ) const { herr_t ret_value = -1; switch(link_type) { case H5L_TYPE_HARD: ret_value = H5Lcreate_hard( getLocId(), curr_name, H5L_SAME_LOC, new_name, H5P_DEFAULT, H5P_DEFAULT ); break; case H5L_TYPE_SOFT: ret_value = H5Lcreate_soft( curr_name, getLocId(), new_name, H5P_DEFAULT, H5P_DEFAULT ); break; default: throwException("link", "unknown link type"); break; } /* end switch */ if( ret_value < 0 ) { throwException("link", "creating link failed"); } }
/**************************************************************** ** ** test_links(): Test soft and hard link iteration ** ****************************************************************/ static void test_links(hid_t fapl) { hid_t file; /* File ID */ char obj_name[NAMELEN]; /* Names of the object in group */ ssize_t name_len; /* Length of object's name */ hid_t gid, gid1; H5G_info_t ginfo; /* Buffer for querying object's info */ hsize_t i; herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing Soft and Hard Link Iteration Functionality\n")); /* Create the test file with the datasets */ file = H5Fcreate(DATAFILE, H5F_ACC_TRUNC, H5P_DEFAULT, fapl); CHECK(file, FAIL, "H5Fcreate"); /* create groups */ gid = H5Gcreate2(file, "/g1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(gid, FAIL, "H5Gcreate2"); gid1 = H5Gcreate2(file, "/g1/g1.1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(gid1, FAIL, "H5Gcreate2"); /* create soft and hard links to the group "/g1". */ ret = H5Lcreate_soft("something", gid, "softlink", H5P_DEFAULT, H5P_DEFAULT); CHECK(ret, FAIL, "H5Lcreate_soft"); ret = H5Lcreate_hard(gid, "/g1", H5L_SAME_LOC, "hardlink", H5P_DEFAULT, H5P_DEFAULT); CHECK(ret, FAIL, "H5Lcreate_hard"); ret = H5Gget_info(gid, &ginfo); CHECK(ret, FAIL, "H5Gget_info"); VERIFY(ginfo.nlinks, 3, "H5Gget_info"); /* Test these two functions, H5Oget_info_by_idx and H5Lget_name_by_idx */ for(i = 0; i < ginfo.nlinks; i++) { H5O_info_t oinfo; /* Object info */ H5L_info_t linfo; /* Link info */ /* Get link name */ name_len = H5Lget_name_by_idx(gid, ".", H5_INDEX_NAME, H5_ITER_INC, i, obj_name, (size_t)NAMELEN, H5P_DEFAULT); CHECK(name_len, FAIL, "H5Lget_name_by_idx"); /* Get link type */ ret = H5Lget_info_by_idx(gid, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)i, &linfo, H5P_DEFAULT); CHECK(ret, FAIL, "H5Lget_info_by_idx"); /* Get object type */ if(linfo.type == H5L_TYPE_HARD) { ret = H5Oget_info_by_idx(gid, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)i, &oinfo, H5P_DEFAULT); CHECK(ret, FAIL, "H5Oget_info_by_idx"); } /* end if */ if(!HDstrcmp(obj_name, "g1.1")) VERIFY(oinfo.type, H5O_TYPE_GROUP, "H5Lget_name_by_idx"); else if(!HDstrcmp(obj_name, "hardlink")) VERIFY(oinfo.type, H5O_TYPE_GROUP, "H5Lget_name_by_idx"); else if(!HDstrcmp(obj_name, "softlink")) VERIFY(linfo.type, H5L_TYPE_SOFT, "H5Lget_name_by_idx"); else CHECK(0, 0, "unknown object name"); } /* end for */ ret = H5Gclose(gid); CHECK(ret, FAIL, "H5Gclose"); ret = H5Gclose(gid1); CHECK(ret, FAIL, "H5Gclose"); ret = H5Fclose(file); CHECK(ret, FAIL, "H5Fclose"); } /* test_links() */
static void gent_ub(const char * filename, size_t ub_size, size_t ub_fill) { hid_t fid, group, attr, dataset, space; hid_t create_plist; hsize_t dims[2]; int data[2][2], dset1[10][10], dset2[20]; char buf[BUF_SIZE]; int i, j; size_t u; float dset2_1[10], dset2_2[3][5]; int fd; char *bp; if(ub_size > 0) { create_plist = H5Pcreate(H5P_FILE_CREATE); H5Pset_userblock(create_plist, (hsize_t)ub_size); fid = H5Fcreate(filename, H5F_ACC_TRUNC, create_plist, H5P_DEFAULT); } else { fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); } /* create groups */ group = H5Gcreate2(fid, "/g1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Gclose(group); group = H5Gcreate2(fid, "/g2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Gclose(group); group = H5Gcreate2(fid, "/g1/g1.1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Gclose(group); group = H5Gcreate2(fid, "/g1/g1.2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Gclose(group); group = H5Gcreate2(fid, "/g1/g1.2/g1.2.1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Gclose(group); /* root attributes */ group = H5Gopen2(fid, "/", H5P_DEFAULT); dims[0] = 10; space = H5Screate_simple(1, dims, NULL); attr = H5Acreate2(group, "attr1", H5T_STD_I8BE, space, H5P_DEFAULT, H5P_DEFAULT); sprintf(buf, "abcdefghi"); H5Awrite(attr, H5T_NATIVE_SCHAR, buf); H5Sclose(space); H5Aclose(attr); dims[0] = 2; dims[1] = 2; space = H5Screate_simple(2, dims, NULL); attr = H5Acreate2(group, "attr2", H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT); data[0][0] = 0; data[0][1] = 1; data[1][0] = 2; data[1][1] = 3; H5Awrite(attr, H5T_NATIVE_INT, data); H5Sclose(space); H5Aclose(attr); H5Gclose(group); group = H5Gopen2(fid, "/g1/g1.1", H5P_DEFAULT); /* dset1.1.1 */ dims[0] = 10; dims[1] = 10; space = H5Screate_simple(2, dims, NULL); dataset = H5Dcreate2(group, "dset1.1.1", H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) dset1[i][j] = j*i; H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset1); H5Sclose(space); /* attributes of dset1.1.1 */ dims[0] = 27; space = H5Screate_simple(1, dims, NULL); attr = H5Acreate2(dataset, "attr1", H5T_STD_I8BE, space, H5P_DEFAULT, H5P_DEFAULT); sprintf(buf, "1st attribute of dset1.1.1"); H5Awrite(attr, H5T_NATIVE_SCHAR, buf); H5Sclose(space); H5Aclose(attr); dims[0] = 27; space = H5Screate_simple(1, dims, NULL); attr = H5Acreate2(dataset, "attr2", H5T_STD_I8BE, space, H5P_DEFAULT, H5P_DEFAULT); sprintf(buf, "2nd attribute of dset1.1.1"); H5Awrite(attr, H5T_NATIVE_SCHAR, buf); H5Sclose(space); H5Aclose(attr); H5Dclose(dataset); /* dset1.1.2 */ dims[0] = 20; space = H5Screate_simple(1, dims, NULL); dataset = H5Dcreate2(group, "dset1.1.2", H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); for (i = 0; i < 20; i++) dset2[i] = i; H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2); H5Sclose(space); H5Dclose(dataset); H5Gclose(group); /* external link */ H5Lcreate_external("somefile", "somepath", fid, "/g1/g1.2/extlink", H5P_DEFAULT, H5P_DEFAULT); /* soft link */ group = H5Gopen2(fid, "/g1/g1.2/g1.2.1", H5P_DEFAULT); H5Lcreate_soft("somevalue", group, "slink", H5P_DEFAULT, H5P_DEFAULT); H5Gclose(group); group = H5Gopen2(fid, "/g2", H5P_DEFAULT); /* dset2.1 */ dims[0] = 10; space = H5Screate_simple(1, dims, NULL); dataset = H5Dcreate2(group, "dset2.1", H5T_IEEE_F32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); for (i = 0; i < 10; i++) dset2_1[i] = (float)((float)i * 0.1F + 1.0F); H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2_1); H5Sclose(space); H5Dclose(dataset); /* dset2.2 */ dims[0] = 3; dims[1] = 5; space = H5Screate_simple(2, dims, NULL); dataset = H5Dcreate2(group, "dset2.2", H5T_IEEE_F32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); for (i = 0; i < 3; i++) for (j = 0; j < 5; j++) dset2_2[i][j] = (float)(((float)i + 1.0F) * (float)j * 0.1F); H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2_2); H5Sclose(space); H5Dclose(dataset); H5Gclose(group); /* user-defined link */ H5Lregister(UD_link_class); H5Lcreate_ud(fid, "/g2/udlink", (H5L_type_t)MY_LINKCLASS, NULL, (size_t)0, H5P_DEFAULT, H5P_DEFAULT); H5Fclose(fid); /* If a user block is being used, write to it here */ if(ub_size > 0) { ssize_t nbytes; HDassert(ub_size <= BUF_SIZE); fd = HDopen(filename, O_RDWR); HDassert(fd >= 0); /* fill buf with pattern */ HDmemset(buf, '\0', ub_size); bp = buf; for (u = 0; u < ub_fill; u++) *bp++ = pattern[u % 10]; nbytes = HDwrite(fd, buf, ub_size); HDassert(nbytes >= 0); HDclose(fd); } }
/* * Actually save the powder pattern to file */ void savePowderPattern(cGlobal *global, int detIndex, int powderClass) { // Dereference common variables cPixelDetectorCommon *detector = &(global->detector[detIndex]); long nframes = detector->nPowderFrames[powderClass]; // Define buffer variables double *powderBuffer; double *powderSquaredBuffer; double *powderSigmaBuffer; double *bufferPeaks; char sBuffer[1024]; /* * Filename */ char filename[1024]; char filenamebase[1024]; sprintf(filenamebase,"r%04u-detector%ld-class%d", global->runNumber, global->detector[detIndex].detectorID, powderClass); sprintf(filename,"%s-sum.h5",filenamebase); printf("%s\n",filename); /* * Mess of stuff for writing the compound HDF5 file */ #ifdef H5F_ACC_SWMR_WRITE pthread_mutex_lock(&global->swmr_mutex); #endif hid_t fh, gh, sh, dh; /* File, group, dataspace and data handles */ //herr_t r; hsize_t size[2]; //hsize_t max_size[2]; hid_t h5compression; // Create file fh = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); if ( fh < 0 ) { ERROR("Couldn't create HDF5 file: %s\n", filename); } gh = H5Gcreate(fh, "data", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if ( gh < 0 ) { ERROR("Couldn't create HDF5 group\n"); H5Fclose(fh); } // Setting compression level if (global->h5compress) { h5compression = H5Pcreate(H5P_DATASET_CREATE); } else { h5compression = H5P_DEFAULT; } FOREACH_DATAFORMAT_T(i_f, cDataVersion::DATA_FORMATS) { if (isBitOptionSet(global->detector[detIndex].powderFormat, *i_f)) { cDataVersion dataV(NULL, &global->detector[detIndex], global->detector[detIndex].powderVersion, *i_f); while (dataV.next()) { if (*i_f != cDataVersion::DATA_FORMAT_RADIAL_AVERAGE) { // size for 2D data size[0] = dataV.pix_ny; size[1] = dataV.pix_nx; sh = H5Screate_simple(2, size, NULL); // Compression for 1D if (global->h5compress) { H5Pset_chunk(h5compression, 2, size); H5Pset_deflate(h5compression, global->h5compress); // Compression levels are 0 (none) to 9 (max) } } else { // size for 1D data (radial average) size[0] = dataV.pix_nn; size[1] = 0; sh = H5Screate_simple(1, size, NULL); // Compression for 1D h5compression = H5P_DEFAULT; } double *powder = dataV.getPowder(powderClass); double *powder_squared = dataV.getPowderSquared(powderClass); long *powder_counter = dataV.getPowderCounter(powderClass); pthread_mutex_t *mutex = dataV.getPowderMutex(powderClass); // Copy powder pattern to buffer powderBuffer = (double*) calloc(dataV.pix_nn, sizeof(double)); if (global->threadSafetyLevel > 0) pthread_mutex_lock(mutex); memcpy(powderBuffer, powder, dataV.pix_nn*sizeof(double)); if (global->threadSafetyLevel > 0) pthread_mutex_unlock(mutex); // Masked powders require a per-pixel correction if(global->detector[detIndex].savePowderMasked != 0 && powder_counter != NULL) { for (long i=0; i<dataV.pix_nn; i++) { if(powder_counter[i] != 0) powderBuffer[i] /= powder_counter[i]; else powderBuffer[i] = 0; } } // Write powder to dataset dh = H5Dcreate(gh, dataV.name, H5T_NATIVE_DOUBLE, sh, H5P_DEFAULT, h5compression, H5P_DEFAULT); if (dh < 0) ERROR("Could not create dataset.\n"); H5Dwrite(dh, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, powderBuffer); H5Dclose(dh); // Fluctuations (sigma) powderSquaredBuffer = (double*) calloc(dataV.pix_nn, sizeof(double)); powderSigmaBuffer = (double*) calloc(dataV.pix_nn, sizeof(double)); if (global->threadSafetyLevel > 0) pthread_mutex_lock(mutex); memcpy(powderSquaredBuffer, powder_squared, dataV.pix_nn*sizeof(double)); if (global->threadSafetyLevel > 0) pthread_mutex_unlock(mutex); // Masked powders require a per-pixel correction if(global->detector[detIndex].savePowderMasked != 0 && powder_counter != NULL) { for (long i=0; i<dataV.pix_nn; i++) { if(powder_counter[i] != 0) powderSigmaBuffer[i] = sqrt(powderSquaredBuffer[i]/powder_counter[i] - powderBuffer[i]*powderBuffer[i]); } } else { for (long i=0; i<dataV.pix_nn; i++) { powderSigmaBuffer[i] = sqrt(powderSquaredBuffer[i]/nframes - (powderBuffer[i]/nframes)*(powderBuffer[i]/nframes)); } } // Write to data set sprintf(sBuffer,"%s_sigma",dataV.name); dh = H5Dcreate(gh, sBuffer, H5T_NATIVE_DOUBLE, sh, H5P_DEFAULT, h5compression, H5P_DEFAULT); if (dh < 0) ERROR("Could not create dataset.\n"); H5Dwrite(dh, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, powderSigmaBuffer); H5Dclose(dh); // Soft link if main data set if (dataV.isMainDataset) { // Create symbolic link if this is the main dataset sprintf(sBuffer,"/data/%s",dataV.name); H5Lcreate_soft(sBuffer, fh, "/data/data",0,0); H5Lcreate_soft(sBuffer, fh, "/data/correcteddata",0,0); } free(powderBuffer); free(powderSquaredBuffer); free(powderSigmaBuffer); H5Sclose(sh); } } } // Peak powder size[0] = detector->pix_ny; size[1] = detector->pix_nx; sh = H5Screate_simple(2, size, NULL); bufferPeaks = (double*) calloc(detector->pix_nn, sizeof(double)); pthread_mutex_lock(&detector->powderPeaks_mutex[powderClass]); memcpy(bufferPeaks, detector->powderPeaks[powderClass], detector->pix_nn*sizeof(double)); pthread_mutex_unlock(&detector->powderPeaks_mutex[powderClass]); dh = H5Dcreate(gh, "peakpowder", H5T_NATIVE_DOUBLE, sh, H5P_DEFAULT, h5compression, H5P_DEFAULT); if (dh < 0) ERROR("Could not create dataset.\n"); H5Dwrite(dh, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, bufferPeaks); H5Dclose(dh); H5Sclose(sh); free(bufferPeaks); // Save frame count size[0] = 1; sh = H5Screate_simple(1, size, NULL ); dh = H5Dcreate(gh, "nframes", H5T_NATIVE_LONG, sh, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if (dh < 0) ERROR("Could not create dataset.\n"); H5Dwrite(dh, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, &detector->nPowderFrames[powderClass] ); H5Dclose(dh); H5Sclose(sh); // Clean up stale HDF5 links H5Gclose(gh); int n_ids; hid_t ids[256]; n_ids = H5Fget_obj_ids(fh, H5F_OBJ_ALL, 256, ids); for ( int i=0; i<n_ids; i++ ) { hid_t id; H5I_type_t type; id = ids[i]; type = H5Iget_type(id); if ( type == H5I_GROUP ) H5Gclose(id); if ( type == H5I_DATASET ) H5Dclose(id); if ( type == H5I_DATATYPE ) H5Tclose(id); if ( type == H5I_DATASPACE ) H5Sclose(id); if ( type == H5I_ATTR ) H5Aclose(id); } H5Fclose(fh); #ifdef H5F_ACC_SWMR_WRITE pthread_mutex_unlock(&global->swmr_mutex); #endif /* * Clean up stuff */ for(long i=0; i<global->nPowderClasses; i++) { fflush(global->powderlogfp[i]); fflush(global->framelist[i]); } }
/*------------------------------------------------------------------------- * Function: main * * Generate an HDF5 file with groups, datasets and symbolic links. * After the file is generated, write bad offset values to * the heap at 3 locations in the file: * (A) Open the file: * fd = HDopen(TESTFILE, O_RDWR, 0663); * (B) Position the file at: * (1) HDlseek(fd, (HDoff_t)880, SEEK_SET); * "/group1/group2": replace heap offset "8" by bad offset * (2) HDlseek(fd, (HDoff_t)1512, SEEK_SET); * "/dsetA": replace name offset into private heap "72" by bad offset * (3) HDlseek(fd, (HDoff_t)1616, SEEK_SET); * /soft_one: replace link value offset in the scratch pad "32" by bad offset * (C) Write the bad offset value to the file for (1), (2) and (3): * write(fd, &val, sizeof(val)); * * Note: if the groups/datasets/symbolic links are changed in the file, * the above locations need to be adjusted accordingly. * * Return: EXIT_SUCCESS/EXIT_FAILURE * *------------------------------------------------------------------------- */ int main(void) { hid_t fid = -1, gid1 = -1, gid2 = -1; /* File and group IDs */ hid_t did = -1, sid = -1; /* Dataset and dataspace IDs */ int fd = -1; /* File descriptor */ int64_t val = 999; /* Bad offset value */ /* Create the test file */ if((fid = H5Fcreate(TESTFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR /* Create two groups */ if((gid1 = H5Gcreate2(fid, GRP1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR if((gid2 = H5Gcreate2(gid1, GRP2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR /* Close the groups */ if(H5Gclose(gid1) < 0) FAIL_STACK_ERROR if(H5Gclose(gid2) < 0) FAIL_STACK_ERROR /* Create soft links to the groups */ if(H5Lcreate_soft("/group1", fid, SOFT1, H5P_DEFAULT, H5P_DEFAULT) < 0) FAIL_STACK_ERROR if(H5Lcreate_soft("/group1/group2", fid, SOFT2, H5P_DEFAULT, H5P_DEFAULT) < 0) FAIL_STACK_ERROR /* Create a dataset */ if((sid = H5Screate(H5S_SCALAR)) < 0) FAIL_STACK_ERROR if((did = H5Dcreate2(fid, DSET, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR /* Close the dataset */ if(H5Dclose(did) < 0) FAIL_STACK_ERROR /* Close the dataspace */ if(H5Sclose(sid) < 0) FAIL_STACK_ERROR /* Close the file */ if(H5Fclose(fid) < 0) FAIL_STACK_ERROR /* * Write bad offset values at 3 locations in the file */ /* Open the file */ if((fd = HDopen(TESTFILE, O_RDWR, 0663)) < 0) FAIL_STACK_ERROR /* Position the file for /group1/group2: replace heap offset "8" by bad offset */ if(HDlseek(fd, (HDoff_t)880, SEEK_SET) < 0) FAIL_STACK_ERROR /* Write the bad offset value to the file */ if(HDwrite(fd, &val, sizeof(val)) < 0) FAIL_STACK_ERROR /* Position the file for /dsetA: replace name offset into private heap "72" by bad offset */ if(HDlseek(fd, (HDoff_t)1512, SEEK_SET) < 0) FAIL_STACK_ERROR /* Write the bad offset value to the file */ if(HDwrite(fd, &val, sizeof(val)) < 0) FAIL_STACK_ERROR /* Position the file for /soft_one: replace link value offset in the scratch pad "32" by bad offset */ if(HDlseek(fd, (HDoff_t)1616, SEEK_SET) < 0) FAIL_STACK_ERROR /* Write the bad offset value to the file */ if(HDwrite(fd, &val, sizeof(val)) < 0) FAIL_STACK_ERROR /* Close the file */ if(HDclose(fd) < 0) FAIL_STACK_ERROR return EXIT_SUCCESS; error: H5E_BEGIN_TRY { H5Gclose(gid1); H5Gclose(gid2); H5Dclose(did); H5Sclose(sid); H5Fclose(fid); } H5E_END_TRY; return EXIT_FAILURE; } /* end main() */