/*------------------------------------------------------------------------- * Function: test_3 * * Purpose: Creates a few global heap objects and then removes them all. * The collection should also be removed. * * Return: Success: 0 * * Failure: number of errors * * Programmer: Robb Matzke * Tuesday, March 31, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static int test_3 (hid_t fapl) { hid_t file = -1; H5F_t *f = NULL; H5HG_t obj[1024]; uint8_t out[1024]; int i; size_t size; herr_t status; int nerrors = 0; char filename[1024]; TESTING("complete object removal"); /* Open a clean file */ h5_fixname(FILENAME[2], fapl, filename, sizeof filename); if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) goto error; if(NULL == (f = (H5F_t *)H5I_object(file))) { H5_FAILED(); puts(" Unable to create file"); goto error; } /* Create some stuff */ for (i=0; i<1024; i++) { size = i%30+100; memset (out, 'A'+i%26, size); H5Eclear2(H5E_DEFAULT); status = H5HG_insert (f, H5P_DATASET_XFER_DEFAULT, size, out, obj+i); if (status<0) { H5_FAILED(); puts(" Unable to insert object into global heap"); nerrors++; } } /* Remove everything */ for (i=0; i<1024; i++) { status = H5HG_remove (f, H5P_DATASET_XFER_DEFAULT, obj+i); if (status<0) { H5_FAILED(); puts(" Unable to remove object"); nerrors++; } } if (H5Fclose(file)<0) goto error; if (nerrors) goto error; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Fclose(file); } H5E_END_TRY; return MAX(1, nerrors); }
/*------------------------------------------------------------------------- * 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 */
/*------------------------------------------------------------------------- * Function: H5Gcreate1 * * Purpose: Creates a new group relative to LOC_ID and gives it the * specified NAME. The group is opened for write access * and it's object ID is returned. * * The optional SIZE_HINT specifies how much file space to * reserve to store the names that will appear in this * group. If a non-positive value is supplied for the SIZE_HINT * then a default size is chosen. * * Note: Deprecated in favor of H5Gcreate2 * * Return: Success: The object ID of a new, empty group open for * writing. Call H5Gclose() when finished with * the group. * * Failure: FAIL * * Programmer: Robb Matzke * Wednesday, September 24, 1997 * *------------------------------------------------------------------------- */ hid_t H5Gcreate1(hid_t loc_id, const char *name, size_t size_hint) { H5G_loc_t loc; /* Location to create group */ H5G_t *grp = NULL; /* New group created */ hid_t tmp_gcpl = (-1); /* Temporary group creation property list */ hid_t ret_value; /* Return value */ FUNC_ENTER_API(H5Gcreate1, FAIL) H5TRACE3("i", "i*sz", loc_id, name, size_hint); /* Check arguments */ if(H5G_loc(loc_id, &loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location") if(!name || !*name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name given") /* Check if we need to create a non-standard GCPL */ if(size_hint > 0) { H5P_genplist_t *gc_plist; /* Property list created */ H5O_ginfo_t ginfo; /* Group info property */ /* Get the default property list */ if(NULL == (gc_plist = (H5P_genplist_t *)H5I_object(H5P_GROUP_CREATE_DEFAULT))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list") /* Make a copy of the default property list */ if((tmp_gcpl = H5P_copy_plist(gc_plist, FALSE)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "unable to copy the creation property list") /* Get pointer to the copied property list */ if(NULL == (gc_plist = (H5P_genplist_t *)H5I_object(tmp_gcpl))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list") /* Get the group info property */ if(H5P_get(gc_plist, H5G_CRT_GROUP_INFO_NAME, &ginfo) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get group info") /* Set the non-default local heap size hint */ ginfo.lheap_size_hint = size_hint; if(H5P_set(gc_plist, H5G_CRT_GROUP_INFO_NAME, &ginfo) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set group info") } /* end if */
/*------------------------------------------------------------------------- * Function: H5Iget_type * * Purpose: The public version of H5I_get_type(), obtains a group number * (type) when given an ID. The ID need not be the ID of an * object which currently exists because the group number is * encoded as part of the ID. * * Return: Success: Group number (type) * * Failure: H5I_BADID, a negative value * * Programmer: * * Modifications: * Robb Matzke, 1999-08-23 * Also fails if the ID has a valid group but no longer exists * in the ID tables. *------------------------------------------------------------------------- */ H5I_type_t H5Iget_type(hid_t id) { H5I_type_t ret_value = H5I_BADID; FUNC_ENTER_API(H5Iget_type, H5I_BADID); H5TRACE1("It","i",id); ret_value = H5I_get_type(id); if (ret_value <= H5I_BADID || ret_value >= H5I_NGROUPS || NULL==H5I_object(id)) HGOTO_DONE(H5I_BADID); done: FUNC_LEAVE_API(ret_value); }
/*------------------------------------------------------------------------- * Function: H5Fget_info1 * * Purpose: Gets general information about the file, including: * 1. Get storage size for superblock extension if there is one. * 2. Get the amount of btree and heap storage for entries * in the SOHM table if there is one. * 3. The amount of free space tracked in the file. * * Return: Success: non-negative on success * Failure: Negative * * Programmer: Vailin Choi * July 11, 2007 * *------------------------------------------------------------------------- */ herr_t H5Fget_info1(hid_t obj_id, H5F_info1_t *finfo) { H5F_t *f; /* Top file in mount hierarchy */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE2("e", "i*x", obj_id, finfo); /* Check args */ if(!finfo) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no info struct") /* For file IDs, get the file object directly */ /* (This prevents the H5G_loc() call from returning the file pointer for * the top file in a mount hierarchy) */ if(H5I_get_type(obj_id) == H5I_FILE ) { if(NULL == (f = (H5F_t *)H5I_object(obj_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file") } /* end if */ else {
/*------------------------------------------------------------------------- * Function: H5F_debug * * Purpose: Prints a file header to the specified stream. Each line * is indented and the field name occupies the specified width * number of characters. * * Errors: * * Return: Non-negative on success/Negative on failure * * Programmer: Robb Matzke * [email protected] * Aug 1 1997 * * Modifications: * Robb Matzke, 1999-07-28 * The ADDR argument is passed by value. * * Raymond Lu, 2001-10-14 * Changed to the new generic property list. * *------------------------------------------------------------------------- */ herr_t H5F_debug(H5F_t *f, hid_t dxpl_id, FILE * stream, int indent, int fwidth) { hsize_t userblock_size; int super_vers, freespace_vers, obj_dir_vers, share_head_vers; H5P_genplist_t *plist; /* Property list */ herr_t ret_value=SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5F_debug, FAIL) /* check args */ assert(f); assert(stream); assert(indent >= 0); assert(fwidth >= 0); /* Get property list */ if(NULL == (plist = H5I_object(f->shared->fcpl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list") if(H5P_get(plist, H5F_CRT_USER_BLOCK_NAME, &userblock_size)<0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get user block size") if(H5P_get(plist, H5F_CRT_SUPER_VERS_NAME, &super_vers)<0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get super block version") if(H5P_get(plist, H5F_CRT_FREESPACE_VERS_NAME, &freespace_vers)<0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get super block version") if(H5P_get(plist, H5F_CRT_OBJ_DIR_VERS_NAME, &obj_dir_vers)<0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get object directory version") if(H5P_get(plist, H5F_CRT_SHARE_HEAD_VERS_NAME, &share_head_vers)<0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get shared-header format version") /* debug */ HDfprintf(stream, "%*sFile Super Block...\n", indent, ""); HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "File name:", f->name); HDfprintf(stream, "%*s%-*s 0x%08x\n", indent, "", fwidth, "File access flags", (unsigned) (f->shared->flags)); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "File open reference count:", (unsigned) (f->shared->nrefs)); HDfprintf(stream, "%*s%-*s %a (abs)\n", indent, "", fwidth, "Address of super block:", f->shared->super_addr); HDfprintf(stream, "%*s%-*s %lu bytes\n", indent, "", fwidth, "Size of user block:", (unsigned long) userblock_size); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Super block version number:", (unsigned) super_vers); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Free list version number:", (unsigned) freespace_vers); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Root group symbol table entry version number:", (unsigned) obj_dir_vers); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Shared header version number:", (unsigned) share_head_vers); HDfprintf(stream, "%*s%-*s %u bytes\n", indent, "", fwidth, "Size of file offsets (haddr_t type):", (unsigned) f->shared->sizeof_addr); HDfprintf(stream, "%*s%-*s %u bytes\n", indent, "", fwidth, "Size of file lengths (hsize_t type):", (unsigned) f->shared->sizeof_size); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Symbol table leaf node 1/2 rank:", f->shared->sym_leaf_k); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Symbol table internal node 1/2 rank:", f->shared->btree_k[H5B_SNODE_ID]); HDfprintf(stream, "%*s%-*s 0x%08lx\n", indent, "", fwidth, "File consistency flags:", (unsigned long) (f->shared->consist_flags)); HDfprintf(stream, "%*s%-*s %a (abs)\n", indent, "", fwidth, "Base address:", f->shared->base_addr); HDfprintf(stream, "%*s%-*s %a (rel)\n", indent, "", fwidth, "Free list address:", f->shared->freespace_addr); HDfprintf(stream, "%*s%-*s %a (rel)\n", indent, "", fwidth, "Address of driver information block:", f->shared->driver_addr); HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Root group symbol table entry:", f->shared->root_grp ? "" : "(none)"); if (f->shared->root_grp) { H5G_ent_debug(f, dxpl_id, H5G_entof(f->shared->root_grp), stream, indent+3, MAX(0, fwidth-3), HADDR_UNDEF); } done: FUNC_LEAVE_NOAPI(ret_value) }
/*------------------------------------------------------------------------- * Function: H5F_sblock_load * * Purpose: Loads the superblock from the file, and deserializes * its information into the H5F_super_t structure. * * Return: Success: SUCCEED * Failure: NULL * * Programmer: Mike McGreevy * [email protected] * April 8, 2009 * *------------------------------------------------------------------------- */ static H5F_super_t * H5F_sblock_load(H5F_t *f, hid_t dxpl_id, haddr_t UNUSED addr, void *_udata) { H5F_super_t *sblock = NULL; /* File's superblock */ haddr_t base_addr = HADDR_UNDEF; /* Base address of file */ uint8_t sbuf[H5F_MAX_SUPERBLOCK_SIZE]; /* Buffer for superblock */ H5P_genplist_t *dxpl; /* DXPL object */ H5P_genplist_t *c_plist; /* File creation property list */ H5F_file_t *shared; /* shared part of `file' */ H5FD_t *lf; /* file driver part of `shared' */ haddr_t stored_eoa; /*relative end-of-addr in file */ haddr_t eof; /*end of file address */ uint8_t sizeof_addr; /* Size of offsets in the file (in bytes) */ uint8_t sizeof_size; /* Size of lengths in the file (in bytes) */ const size_t fixed_size = H5F_SUPERBLOCK_FIXED_SIZE; /*fixed sizeof superblock */ size_t variable_size; /*variable sizeof superblock */ uint8_t *p; /* Temporary pointer into encoding buffer */ unsigned super_vers; /* Superblock version */ hbool_t *dirtied = (hbool_t *)_udata; /* Set up dirtied out value */ H5F_super_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT /* check arguments */ HDassert(f); HDassert(H5F_addr_eq(addr, 0)); HDassert(dirtied); /* Short cuts */ shared = f->shared; lf = shared->lf; /* Get the shared file creation property list */ if(NULL == (c_plist = (H5P_genplist_t *)H5I_object(shared->fcpl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "can't get property list") /* Get the base address for the file in the VFD */ if(HADDR_UNDEF == (base_addr = H5FD_get_base_addr(lf))) HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "failed to get base address for file driver") /* Allocate space for the superblock */ if(NULL == (sblock = H5FL_CALLOC(H5F_super_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Get the DXPL plist object for DXPL ID */ if(NULL == (dxpl = (H5P_genplist_t *)H5I_object(dxpl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "can't get property list") /* Read fixed-size portion of the superblock */ p = sbuf; H5_CHECK_OVERFLOW(fixed_size, size_t, haddr_t); if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, (haddr_t)fixed_size) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "set end of space allocation request failed") if(H5FD_read(lf, dxpl, H5FD_MEM_SUPER, (haddr_t)0, fixed_size, p) < 0) HGOTO_ERROR(H5E_FILE, H5E_READERROR, NULL, "unable to read superblock") /* Skip over signature (already checked when locating the superblock) */ p += H5F_SIGNATURE_LEN; /* Superblock version */ super_vers = *p++; if(super_vers > HDF5_SUPERBLOCK_VERSION_LATEST) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad superblock version number") if(H5P_set(c_plist, H5F_CRT_SUPER_VERS_NAME, &super_vers) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set superblock version") /* Record the superblock version */ sblock->super_vers = super_vers; /* Sanity check */ HDassert(((size_t)(p - sbuf)) == fixed_size); /* Determine the size of the variable-length part of the superblock */ variable_size = (size_t)H5F_SUPERBLOCK_VARLEN_SIZE(super_vers, f); HDassert(variable_size > 0); HDassert(fixed_size + variable_size <= sizeof(sbuf)); /* Read in variable-sized portion of superblock */ if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, (haddr_t)(fixed_size + variable_size)) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "set end of space allocation request failed") if(H5FD_read(lf, dxpl, H5FD_MEM_SUPER, (haddr_t)fixed_size, variable_size, p) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to read superblock") /* Check for older version of superblock format */ if(super_vers < HDF5_SUPERBLOCK_VERSION_2) { uint32_t status_flags; /* File status flags */ unsigned btree_k[H5B_NUM_BTREE_ID]; /* B-tree internal node 'K' values */ unsigned sym_leaf_k; /* Symbol table leaf node's 'K' value */ /* Freespace version (hard-wired) */ if(HDF5_FREESPACE_VERSION != *p++) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad free space version number") /* Root group version number (hard-wired) */ if(HDF5_OBJECTDIR_VERSION != *p++) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad object directory version number") /* Skip over reserved byte */ p++; /* Shared header version number (hard-wired) */ if(HDF5_SHAREDHEADER_VERSION != *p++) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad shared-header format version number") /* Size of file addresses */ sizeof_addr = *p++; if(sizeof_addr != 2 && sizeof_addr != 4 && sizeof_addr != 8 && sizeof_addr != 16 && sizeof_addr != 32) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad byte number in an address") if(H5P_set(c_plist, H5F_CRT_ADDR_BYTE_NUM_NAME, &sizeof_addr) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set byte number in an address") shared->sizeof_addr = sizeof_addr; /* Keep a local copy also */ /* Size of file sizes */ sizeof_size = *p++; if(sizeof_size != 2 && sizeof_size != 4 && sizeof_size != 8 && sizeof_size != 16 && sizeof_size != 32) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad byte number for object size") if(H5P_set(c_plist, H5F_CRT_OBJ_BYTE_NUM_NAME, &sizeof_size) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set byte number for object size") shared->sizeof_size = sizeof_size; /* Keep a local copy also */ /* Skip over reserved byte */ p++; /* Various B-tree sizes */ UINT16DECODE(p, sym_leaf_k); if(sym_leaf_k == 0) HGOTO_ERROR(H5E_FILE, H5E_BADRANGE, NULL, "bad symbol table leaf node 1/2 rank") if(H5P_set(c_plist, H5F_CRT_SYM_LEAF_NAME, &sym_leaf_k) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set rank for symbol table leaf nodes") sblock->sym_leaf_k = sym_leaf_k; /* Keep a local copy also */ /* Need 'get' call to set other array values */ if(H5P_get(c_plist, H5F_CRT_BTREE_RANK_NAME, btree_k) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "unable to get rank for btree internal nodes") UINT16DECODE(p, btree_k[H5B_SNODE_ID]); if(btree_k[H5B_SNODE_ID] == 0) HGOTO_ERROR(H5E_FILE, H5E_BADRANGE, NULL, "bad 1/2 rank for btree internal nodes") /* * Delay setting the value in the property list until we've checked * for the indexed storage B-tree internal 'K' value later. */ /* File status flags (not really used yet) */ UINT32DECODE(p, status_flags); HDassert(status_flags <= 255); sblock->status_flags = (uint8_t)status_flags; if(sblock->status_flags & ~H5F_SUPER_ALL_FLAGS) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad flag value for superblock") /* * If the superblock version # is greater than 0, read in the indexed * storage B-tree internal 'K' value */ if(super_vers > HDF5_SUPERBLOCK_VERSION_DEF) { UINT16DECODE(p, btree_k[H5B_CHUNK_ID]); /* Reserved bytes are present only in version 1 */ if(super_vers == HDF5_SUPERBLOCK_VERSION_1) p += 2; /* reserved */ } /* end if */ else btree_k[H5B_CHUNK_ID] = HDF5_BTREE_CHUNK_IK_DEF; /* Set the B-tree internal node values, etc */ if(H5P_set(c_plist, H5F_CRT_BTREE_RANK_NAME, btree_k) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set rank for btree internal nodes") HDmemcpy(sblock->btree_k, btree_k, sizeof(unsigned) * (size_t)H5B_NUM_BTREE_ID); /* Keep a local copy also */ /* Remainder of "variable-sized" portion of superblock */ H5F_addr_decode(f, (const uint8_t **)&p, &sblock->base_addr/*out*/); H5F_addr_decode(f, (const uint8_t **)&p, &sblock->ext_addr/*out*/); H5F_addr_decode(f, (const uint8_t **)&p, &stored_eoa/*out*/); H5F_addr_decode(f, (const uint8_t **)&p, &sblock->driver_addr/*out*/); /* Allocate space for the root group symbol table entry */ HDassert(!sblock->root_ent); if(NULL == (sblock->root_ent = (H5G_entry_t *)H5MM_calloc(sizeof(H5G_entry_t)))) HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, NULL, "can't allocate space for root group symbol table entry") /* decode the root group symbol table entry */ if(H5G_ent_decode(f, (const uint8_t **)&p, sblock->root_ent) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTDECODE, NULL, "can't decode root group symbol table entry") /* Set the root group address to the correct value */ sblock->root_addr = sblock->root_ent->header; /* * Check if superblock address is different from base address and * adjust base address and "end of address" address if so. */ if(!H5F_addr_eq(base_addr, sblock->base_addr)) { /* Check if the superblock moved earlier in the file */ if(H5F_addr_lt(base_addr, sblock->base_addr)) stored_eoa -= (sblock->base_addr - base_addr); else /* The superblock moved later in the file */ stored_eoa += (base_addr - sblock->base_addr); /* Adjust base address for offsets of the HDF5 data in the file */ sblock->base_addr = base_addr; /* Set the base address for the file in the VFD now */ if(H5FD_set_base_addr(lf, sblock->base_addr) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTSET, NULL, "failed to set base address for file driver") /* Indicate that the superblock should be marked dirty */ *dirtied = TRUE; } /* end if */ /* This step is for h5repart tool only. If user wants to change file driver * from family to sec2 while using h5repart, set the driver address to * undefined to let the library ignore the family driver information saved * in the superblock. */ if(H5F_HAS_FEATURE(f, H5FD_FEAT_IGNORE_DRVRINFO)) { /* Eliminate the driver info */ sblock->driver_addr = HADDR_UNDEF; /* Indicate that the superblock should be marked dirty */ *dirtied = TRUE; } /* end if */ /* Decode the optional driver information block */ if(H5F_addr_defined(sblock->driver_addr)) { uint8_t dbuf[H5F_MAX_DRVINFOBLOCK_SIZE]; /* Buffer for driver info block */ char drv_name[9]; /* Name of driver */ unsigned drv_vers; /* Version of driver info block */ size_t drv_variable_size; /* Size of variable-length portion of driver info block, in bytes */ /* Read in fixed-sized portion of driver info block */ p = dbuf; if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, sblock->driver_addr + H5F_DRVINFOBLOCK_HDR_SIZE) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "set end of space allocation request failed") if(H5FD_read(lf, dxpl, H5FD_MEM_SUPER, sblock->driver_addr, (size_t)H5F_DRVINFOBLOCK_HDR_SIZE, p) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to read driver information block") /* Version number */ drv_vers = *p++; if(drv_vers != HDF5_DRIVERINFO_VERSION_0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "bad driver information block version number") p += 3; /* reserved bytes */ /* Driver info size */ UINT32DECODE(p, drv_variable_size); /* Sanity check */ HDassert(H5F_DRVINFOBLOCK_HDR_SIZE + drv_variable_size <= sizeof(dbuf)); /* Driver name and/or version */ HDstrncpy(drv_name, (const char *)p, (size_t)8); drv_name[8] = '\0'; p += 8; /* advance past name/version */ /* Check if driver matches driver information saved. Unfortunately, we can't push this * function to each specific driver because we're checking if the driver is correct. */ if(!HDstrncmp(drv_name, "NCSAfami", (size_t)8) && HDstrcmp(lf->cls->name, "family")) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "family driver should be used") if(!HDstrncmp(drv_name, "NCSAmult", (size_t)8) && HDstrcmp(lf->cls->name, "multi")) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "multi driver should be used") /* Read in variable-sized portion of driver info block */ if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, sblock->driver_addr + H5F_DRVINFOBLOCK_HDR_SIZE + drv_variable_size) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "set end of space allocation request failed") if(H5FD_read(lf, dxpl, H5FD_MEM_SUPER, sblock->driver_addr + H5F_DRVINFOBLOCK_HDR_SIZE, drv_variable_size, p) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to read file driver information") /* Decode driver information */ if(H5FD_sb_decode(lf, drv_name, p) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to decode driver information") } /* end if */
/*-------------------------------------------------------------------------- NAME H5G_user_path_test PURPOSE Retrieve the user path for an ID USAGE herr_t H5G_user_path_test(obj_id, user_path, user_path_len) hid_t obj_id; IN: ID to check char *user_path; OUT: Pointer to buffer for User path size_t *user_path_len; OUT: Size of user path unsigned *obj_hidden; OUT: Whether object is hidden RETURNS Non-negative on success, negative on failure DESCRIPTION Retrieves the user path for an ID. A zero for the length is returned in the case of no user path. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS DO NOT USE THIS FUNCTION FOR ANYTHING EXCEPT TESTING EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ herr_t H5G_user_path_test(hid_t obj_id, char *user_path, size_t *user_path_len, unsigned *obj_hidden) { void *obj_ptr; /* Pointer to object for ID */ H5G_entry_t *obj_ent; /* Pointer to symbol table entry for obj */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5G_user_path_test, FAIL) /* Sanity check */ HDassert(user_path_len); HDassert(obj_hidden); /* Get pointer to object for ID */ if(NULL == (obj_ptr = H5I_object(obj_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "can't get object for ID") /* Get the symbol table entry */ switch(H5I_get_type(obj_id)) { case H5I_GROUP: obj_ent = H5G_entof((H5G_t *)obj_ptr); break; case H5I_DATASET: obj_ent = H5D_entof((H5D_t *)obj_ptr); break; case H5I_DATATYPE: /* Avoid non-named datatypes */ if(!H5T_is_named((H5T_t *)obj_ptr)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a named datatype") obj_ent = H5T_entof((H5T_t *)obj_ptr); break; default: HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "unknown data object type") } /* end switch */ HDassert(obj_ent); /* Retrieve a copy of the user path and put it into the buffer */ if(obj_ent->user_path_r) { size_t len = H5RS_len(obj_ent->user_path_r); /* Set the user path, if given */ if(user_path) HDstrcpy(user_path, H5RS_get_str(obj_ent->user_path_r)); /* Set the length of the path */ *user_path_len = len; /* Set the user path hidden flag */ *obj_hidden = obj_ent->obj_hidden; } /* end if */ else { *user_path_len = 0; *obj_hidden = 0; } /* end else */ done: FUNC_LEAVE_NOAPI(ret_value) } /* H5G_user_path_test() */
/*------------------------------------------------------------------------- * Function: main * * Purpose: Exercise private object header behavior and routines * * Return: Success: 0 * Failure: 1 * * Programmer: Robb Matzke * Tuesday, November 24, 1998 * *------------------------------------------------------------------------- */ int main(void) { hid_t fapl = -1, file = -1; hid_t dset = -1; H5F_t *f = NULL; char filename[1024]; H5O_hdr_info_t hdr_info; /* Object info */ H5O_loc_t oh_loc, oh_loc2; /* Object header locations */ time_t time_new, ro; int chunkno; /* Chunk index for message */ int i; /* Local index variable */ hbool_t b; /* Index for "new format" loop */ herr_t ret; /* Generic return value */ /* Reset library */ h5_reset(); fapl = h5_fileaccess(); h5_fixname(FILENAME[0], fapl, filename, sizeof filename); /* Loop over old & new formats */ for(b = FALSE; b <= TRUE; b++) { /* Display info about testing */ if(b) HDputs("Using new file format:"); else HDputs("Using default file format:"); /* Set the format to use for the file */ if(H5Pset_libver_bounds(fapl, (b ? H5F_LIBVER_LATEST : H5F_LIBVER_EARLIEST), H5F_LIBVER_LATEST) < 0) FAIL_STACK_ERROR /* test on object continuation block */ if(test_cont(filename, fapl) < 0) FAIL_STACK_ERROR /* Create the file to operate on */ if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR if(NULL == (f = (H5F_t *)H5I_object(file))) FAIL_STACK_ERROR if (H5AC_ignore_tags(f) < 0) { H5_FAILED(); H5Eprint2(H5E_DEFAULT, stdout); goto error; } /* * Test object header creation * (using default group creation property list only because it's convenient) */ TESTING("object header creation"); HDmemset(&oh_loc, 0, sizeof(oh_loc)); if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0) FAIL_STACK_ERROR PASSED(); /* create a new message */ TESTING("message creation"); time_new = 11111111; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0) FAIL_STACK_ERROR if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(ro != time_new) TEST_ERROR PASSED(); /* * Test modification of an existing message. */ TESTING("message modification"); time_new = 33333333; if(H5O_msg_write(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0) FAIL_STACK_ERROR if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(ro != time_new) TEST_ERROR /* Make certain that chunk #0 in the object header can be encoded with a 1-byte size */ if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0) FAIL_STACK_ERROR if(hdr_info.space.total >=256) TEST_ERROR PASSED(); /* * Test creation of a bunch of messages one after another to see * what happens when the object header overflows in core. * (Use 'old' MTIME message here, because it is large enough to be * replaced with a continuation message (the new one is too small) * and the library doesn't understand how to migrate more than one * message from an object header currently - QAK - 10/8/03) */ TESTING("object header overflow in memory"); for(i = 0; i < 40; i++) { time_new = (i + 1) * 1000 + 1000000; if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR } /* end for */ if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0) FAIL_STACK_ERROR /* Make certain that chunk #0 in the object header will be encoded with a 2-byte size */ if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0) FAIL_STACK_ERROR if(hdr_info.space.total < 256) TEST_ERROR PASSED(); /* Close & re-open file & object header */ /* (makes certain that an object header in the new format that transitions * between 1-byte chunk #0 size encoding and 2-byte chunk #0 size encoding * works correctly - QAK) */ TESTING("close & re-open object header"); if(H5O_close(&oh_loc) < 0) FAIL_STACK_ERROR if(H5Fclose(file) < 0) FAIL_STACK_ERROR if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) FAIL_STACK_ERROR if(NULL == (f = (H5F_t *)H5I_object(file))) FAIL_STACK_ERROR if (H5AC_ignore_tags(f) < 0) FAIL_STACK_ERROR oh_loc.file = f; if(H5O_open(&oh_loc) < 0) FAIL_STACK_ERROR PASSED(); /* * Test creation of a bunch of messages one after another to see * what happens when the object header overflows on disk. */ TESTING("object header overflow on disk"); for(i = 0; i < 10; i++) { time_new = (i + 1) * 1000 + 10; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0) FAIL_STACK_ERROR } /* end for */ PASSED(); /* * Delete all time messages. */ TESTING("message deletion"); if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_remove(&oh_loc, H5O_MTIME_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(H5O_msg_read(&oh_loc, H5O_MTIME_ID, &ro, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR PASSED(); /* * Constant message handling. * (can't write to them, but should be able to remove them) */ TESTING("constant message handling"); time_new = 22222222; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, H5O_MSG_FLAG_CONSTANT, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0) FAIL_STACK_ERROR if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(ro != time_new) TEST_ERROR time_new = 33333333; H5E_BEGIN_TRY { ret = H5O_msg_write(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT); } H5E_END_TRY; if(ret >= 0) TEST_ERROR if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR PASSED(); /* release resources */ TESTING("object header closing"); if(H5O_close(&oh_loc) < 0) FAIL_STACK_ERROR PASSED(); /* * Test moving message to first chunk */ TESTING("locking messages"); HDmemset(&oh_loc, 0, sizeof(oh_loc)); if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR /* Create second object header, to guarantee that first object header uses multiple chunks */ HDmemset(&oh_loc2, 0, sizeof(oh_loc2)); if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc2/*out*/) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_loc2, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR /* Fill object header with messages, creating multiple chunks */ for(i = 0; i < 10; i++) { time_new = (i + 1) * 1000 + 10; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR } /* end for */ /* Get # of object header chunks */ if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0) FAIL_STACK_ERROR if(hdr_info.nchunks != 2) TEST_ERROR /* Add message to lock to object header */ time_new = 11111111; if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Verify chunk index for message */ if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0) FAIL_STACK_ERROR if(chunkno != 1) TEST_ERROR /* Lock the message into the chunk */ if(H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Attempt to lock the message twice */ H5E_BEGIN_TRY { ret = H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT); } H5E_END_TRY; if(ret >= 0) TEST_ERROR /* Delete all the other messages, which would move the message into * chunk #0, if it wasn't locked */ if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Verify chunk index for message */ if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0) FAIL_STACK_ERROR if(chunkno != 1) TEST_ERROR /* Unlock the message */ if(H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Attempt to unlock the message twice */ H5E_BEGIN_TRY { ret = H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT); } H5E_END_TRY; if(ret >= 0) TEST_ERROR /* Close object headers */ if(H5O_close(&oh_loc2) < 0) FAIL_STACK_ERROR if(H5O_close(&oh_loc) < 0) FAIL_STACK_ERROR /* Open first object header */ HDmemset(&oh_loc, 0, sizeof(oh_loc)); if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR /* Create second object header, to guarantee that first object header uses multiple chunks */ HDmemset(&oh_loc2, 0, sizeof(oh_loc2)); if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc2/*out*/) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_loc2, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR /* Add message to move to object header */ time_new = 11111111; if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Verify chunk index for message */ if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0) FAIL_STACK_ERROR if(chunkno != 0) TEST_ERROR /* Lock the message into the chunk */ if(H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Fill object header with messages, creating multiple chunks */ /* (would normally move locked message to new chunk) */ for(i = 0; i < 10; i++) { time_new = (i + 1) * 1000 + 10; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR } /* end for */ /* Get # of object header chunks */ if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0) FAIL_STACK_ERROR if(hdr_info.nchunks != 2) TEST_ERROR /* Verify chunk index for message */ if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0) FAIL_STACK_ERROR if(chunkno != 0) TEST_ERROR /* Unlock the message */ if(H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Close object headers */ if(H5O_close(&oh_loc2) < 0) FAIL_STACK_ERROR if(H5O_close(&oh_loc) < 0) FAIL_STACK_ERROR PASSED(); /* Test reading datasets with undefined object header messages * and the various "fail/mark if unknown" object header message flags */ HDputs("Accessing objects with unknown header messages:"); { hid_t file2; /* File ID for 'bogus' object file */ hid_t sid; /* Dataspace ID */ hid_t aid; /* Attribute ID */ const char *testfile = H5_get_srcdir_filename(FILE_BOGUS); TESTING("object with unknown header message and no flags set"); /* Open the file with objects that have unknown header messages (generated with gen_bogus.c) */ if((file2 = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) TEST_ERROR /* Open the dataset with the unknown header message, but no extra flags */ if((dset = H5Dopen2(file2, "/Dataset1", H5P_DEFAULT)) < 0) TEST_ERROR if(H5Dclose(dset) < 0) TEST_ERROR PASSED(); TESTING("object in r/o file with unknown header message & 'fail if unknown and open for write' flag set"); /* Open the dataset with the unknown header message, and "fail if unknown and open for write" flag */ if((dset = H5Dopen2(file2, "/Dataset2", H5P_DEFAULT)) < 0) TEST_ERROR if(H5Dclose(dset) < 0) TEST_ERROR PASSED(); TESTING("object in r/o file with unknown header message & 'fail if unknown always' flag set"); /* Attempt to open the dataset with the unknown header message, and "fail if unknown always" flag */ H5E_BEGIN_TRY { dset = H5Dopen2(file2, "/Dataset3", H5P_DEFAULT); } H5E_END_TRY; if(dset >= 0) { H5Dclose(dset); TEST_ERROR } /* end if */ PASSED(); TESTING("object with unknown header message & 'mark if unknown' flag set"); /* Copy object with "mark if unknown" flag on message into file that can be modified */ if(H5Ocopy(file2, "/Dataset4", file, "/Dataset4", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR /* Close the file we created (to flush changes to file) */ if(H5Fclose(file) < 0) TEST_ERROR /* Re-open the file created, with read-only permissions */ if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR /* Open the dataset with the "mark if unknown" message */ if((dset = H5Dopen2(file, "/Dataset4", H5P_DEFAULT)) < 0) TEST_ERROR /* Check that the "unknown" message was _NOT_ marked */ if(H5O_check_msg_marked_test(dset, FALSE) < 0) FAIL_STACK_ERROR /* Close the dataset */ if(H5Dclose(dset) < 0) TEST_ERROR /* Close the file we created (to flush change to object header) */ if(H5Fclose(file) < 0) TEST_ERROR /* Re-open the file created */ if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR /* Open the dataset with the "mark if unknown" message */ if((dset = H5Dopen2(file, "/Dataset4", H5P_DEFAULT)) < 0) TEST_ERROR /* Create data space */ if((sid = H5Screate(H5S_SCALAR)) < 0) FAIL_STACK_ERROR /* Create an attribute, to get the object header into write access */ if((aid = H5Acreate2(dset, "Attr", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR /* Close dataspace */ if(H5Sclose(sid) < 0) FAIL_STACK_ERROR /* Close attribute */ if(H5Aclose(aid) < 0) FAIL_STACK_ERROR /* Close the dataset */ if(H5Dclose(dset) < 0) TEST_ERROR /* Close the file we created (to flush change to object header) */ if(H5Fclose(file) < 0) TEST_ERROR /* Re-open the file created */ if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR /* Re-open the dataset with the "mark if unknown" message */ if((dset = H5Dopen2(file, "/Dataset4", H5P_DEFAULT)) < 0) TEST_ERROR /* Check that the "unknown" message was marked */ if(H5O_check_msg_marked_test(dset, TRUE) < 0) FAIL_STACK_ERROR /* Close the dataset */ if(H5Dclose(dset) < 0) TEST_ERROR /* Close the file with the bogus objects */ if(H5Fclose(file2) < 0) TEST_ERROR PASSED(); /* Open the file with objects that have unknown header messages (generated with gen_bogus.c) with RW intent this time */ if((file2 = H5Fopen(testfile, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) TEST_ERROR TESTING("object in r/w file with unknown header message & 'fail if unknown and open for write' flag set"); /* Attempt to open the dataset with the unknown header message, and "fail if unknown and open for write" flag */ H5E_BEGIN_TRY { dset = H5Dopen2(file2, "/Dataset2", H5P_DEFAULT); } H5E_END_TRY; if(dset >= 0) { H5Dclose(dset); TEST_ERROR } /* end if */ PASSED(); TESTING("object in r/w file with unknown header message & 'fail if unknown always' flag set"); /* Attempt to open the dataset with the unknown header message, and "fail if unknown always" flag */ H5E_BEGIN_TRY { dset = H5Dopen2(file2, "/Dataset3", H5P_DEFAULT); } H5E_END_TRY; if(dset >= 0) { H5Dclose(dset); TEST_ERROR } /* end if */
/*------------------------------------------------------------------------- * Function: H5F_debug * * Purpose: Prints a file header to the specified stream. Each line * is indented and the field name occupies the specified width * number of characters. * * Return: Non-negative on success/Negative on failure * * Programmer: Robb Matzke * [email protected] * Aug 1 1997 * *------------------------------------------------------------------------- */ herr_t H5F_debug(H5F_t *f, FILE *stream, int indent, int fwidth) { H5P_genplist_t *plist; /* File creation property list */ hsize_t userblock_size; /* Userblock size */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5F_debug, FAIL) /* check args */ HDassert(f); HDassert(stream); HDassert(indent >= 0); HDassert(fwidth >= 0); /* Get property list */ if(NULL == (plist = (H5P_genplist_t *)H5I_object(f->shared->fcpl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list") /* Retrieve file creation properties */ if(H5P_get(plist, H5F_CRT_USER_BLOCK_NAME, &userblock_size) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get userblock size") /* debug */ HDfprintf(stream, "%*sFile Super Block...\n", indent, ""); HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "File name:", f->name); HDfprintf(stream, "%*s%-*s 0x%08x\n", indent, "", fwidth, "File access flags", f->shared->flags); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "File open reference count:", f->shared->nrefs); HDfprintf(stream, "%*s%-*s %a (abs)\n", indent, "", fwidth, "Address of super block:", f->shared->sblock->base_addr); HDfprintf(stream, "%*s%-*s %Hu bytes\n", indent, "", fwidth, "Size of userblock:", userblock_size); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Superblock version number:", f->shared->sblock->super_vers); /* Hard-wired versions */ HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Free list version number:", (unsigned)HDF5_FREESPACE_VERSION); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Root group symbol table entry version number:", (unsigned)HDF5_OBJECTDIR_VERSION); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Shared header version number:", (unsigned)HDF5_SHAREDHEADER_VERSION); HDfprintf(stream, "%*s%-*s %u bytes\n", indent, "", fwidth, "Size of file offsets (haddr_t type):", (unsigned) f->shared->sizeof_addr); HDfprintf(stream, "%*s%-*s %u bytes\n", indent, "", fwidth, "Size of file lengths (hsize_t type):", (unsigned) f->shared->sizeof_size); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Symbol table leaf node 1/2 rank:", f->shared->sblock->sym_leaf_k); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Symbol table internal node 1/2 rank:", f->shared->sblock->btree_k[H5B_SNODE_ID]); HDfprintf(stream, "%*s%-*s 0x%02x\n", indent, "", fwidth, "File status flags:", (unsigned)(f->shared->sblock->status_flags)); HDfprintf(stream, "%*s%-*s %a (rel)\n", indent, "", fwidth, "Superblock extension address:", f->shared->sblock->ext_addr); HDfprintf(stream, "%*s%-*s %a (rel)\n", indent, "", fwidth, "Shared object header message table address:", f->shared->sohm_addr); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Shared object header message version number:", (unsigned) f->shared->sohm_vers); HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Number of shared object header message indexes:", (unsigned) f->shared->sohm_nindexes); HDfprintf(stream, "%*s%-*s %a (rel)\n", indent, "", fwidth, "Address of driver information block:", f->shared->sblock->driver_addr); HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Root group symbol table entry:", f->shared->root_grp ? "" : "(none)"); if(f->shared->root_grp) { if(f->shared->sblock->root_ent) /* Use real root group symbol table entry */ H5G_ent_debug(f, f->shared->sblock->root_ent, stream, indent + 3, MAX(0, fwidth - 3), NULL); else { H5O_loc_t *root_oloc; /* Root object location */ H5G_entry_t root_ent; /* Constructed root symbol table entry */ /* Reset the root group entry */ H5G_ent_reset(&root_ent); /* Build up a simulated root group symbol table entry */ root_oloc = H5G_oloc(f->shared->root_grp); HDassert(root_oloc); root_ent.type = H5G_NOTHING_CACHED; root_ent.header = root_oloc->addr; root_ent.file = f; /* Display root group symbol table entry info */ H5G_ent_debug(f, &root_ent, stream, indent + 3, MAX(0, fwidth - 3), NULL); } /* end else */ } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5F_debug() */
/*------------------------------------------------------------------------- * Function: H5F_read_superblock * * Purpose: Reads the superblock from the file or from the BUF. If * ADDR is a valid address, then it reads it from the file. * If not, then BUF must be non-NULL for it to read from the * BUF. * * Return: Success: SUCCEED * Failure: FAIL * * Programmer: Bill Wendling * [email protected] * Sept 12, 2003 * * Modifications: * *------------------------------------------------------------------------- */ herr_t H5F_read_superblock(H5F_t *f, hid_t dxpl_id, H5G_entry_t *root_ent) { haddr_t stored_eoa; /*relative end-of-addr in file */ haddr_t eof; /*end of file address */ uint8_t *q; /*ptr into temp I/O buffer */ size_t sizeof_addr = 0; size_t sizeof_size = 0; const size_t fixed_size = 24; /*fixed sizeof superblock */ unsigned sym_leaf_k = 0; size_t variable_size; /*variable sizeof superblock */ unsigned btree_k[H5B_NUM_BTREE_ID]; /* B-tree internal node 'K' values */ H5F_file_t *shared = NULL; /* shared part of `file' */ H5FD_t *lf = NULL; /* file driver part of `shared' */ uint8_t *p; /* Temporary pointer into encoding buffers */ unsigned i; /* Index variable */ unsigned chksum; /* Checksum temporary variable */ size_t driver_size; /* Size of driver info block, in bytes */ char driver_name[9]; /* Name of driver, for driver info block */ unsigned super_vers; /* Super block version */ unsigned freespace_vers; /* Freespace info version */ unsigned obj_dir_vers; /* Object header info version */ unsigned share_head_vers; /* Shared header info version */ uint8_t buf[H5F_SUPERBLOCK_SIZE]; /* Local buffer */ H5P_genplist_t *c_plist; /* File creation property list */ herr_t ret_value = SUCCEED; /* Decoding */ FUNC_ENTER_NOAPI(H5F_read_superblock, FAIL) /* Short cuts */ shared = f->shared; lf = shared->lf; /* Get the shared file creation property list */ if (NULL == (c_plist = H5I_object(shared->fcpl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "can't get property list") /* Read the superblock if it hasn't been read before. */ if (HADDR_UNDEF == (shared->super_addr=H5F_locate_signature(lf,dxpl_id))) HGOTO_ERROR(H5E_FILE, H5E_NOTHDF5, FAIL, "unable to find file signature") if (H5FD_set_eoa(lf, shared->super_addr + fixed_size) < 0 || H5FD_read(lf, H5FD_MEM_SUPER, dxpl_id, shared->super_addr, fixed_size, buf) < 0) HGOTO_ERROR(H5E_FILE, H5E_READERROR, FAIL, "unable to read superblock") /* Signature, already checked */ p = buf + H5F_SIGNATURE_LEN; /* Superblock version */ super_vers = *p++; if (super_vers > HDF5_SUPERBLOCK_VERSION_MAX) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "bad superblock version number") if (H5P_set(c_plist, H5F_CRT_SUPER_VERS_NAME, &super_vers) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set superblock version") /* Freespace version */ freespace_vers = *p++; if (HDF5_FREESPACE_VERSION != freespace_vers) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "bad free space version number") if (H5P_set(c_plist, H5F_CRT_FREESPACE_VERS_NAME, &freespace_vers) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to free space version") /* Root group version number */ obj_dir_vers = *p++; if (HDF5_OBJECTDIR_VERSION != obj_dir_vers) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "bad object directory version number") if (H5P_set(c_plist, H5F_CRT_OBJ_DIR_VERS_NAME, &obj_dir_vers) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set object directory version") /* Skip over reserved byte */ p++; /* Shared header version number */ share_head_vers = *p++; if (HDF5_SHAREDHEADER_VERSION != share_head_vers) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "bad shared-header format version number") if (H5P_set(c_plist, H5F_CRT_SHARE_HEAD_VERS_NAME, &share_head_vers) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set shared-header format version") /* Size of file addresses */ sizeof_addr = *p++; if (sizeof_addr != 2 && sizeof_addr != 4 && sizeof_addr != 8 && sizeof_addr != 16 && sizeof_addr != 32) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "bad byte number in an address") if (H5P_set(c_plist, H5F_CRT_ADDR_BYTE_NUM_NAME,&sizeof_addr) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set byte number in an address") shared->sizeof_addr = sizeof_addr; /* Keep a local copy also */ /* Size of file sizes */ sizeof_size = *p++; if (sizeof_size != 2 && sizeof_size != 4 && sizeof_size != 8 && sizeof_size != 16 && sizeof_size != 32) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "bad byte number for object size") if (H5P_set(c_plist, H5F_CRT_OBJ_BYTE_NUM_NAME, &sizeof_size) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set byte number for object size") shared->sizeof_size = sizeof_size; /* Keep a local copy also */ /* Skip over reserved byte */ p++; /* Various B-tree sizes */ UINT16DECODE(p, sym_leaf_k); if (sym_leaf_k == 0) HGOTO_ERROR(H5E_FILE, H5E_BADRANGE, FAIL, "bad symbol table leaf node 1/2 rank") if (H5P_set(c_plist, H5F_CRT_SYM_LEAF_NAME, &sym_leaf_k) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set rank for symbol table leaf nodes") shared->sym_leaf_k = sym_leaf_k; /* Keep a local copy also */ /* Need 'get' call to set other array values */ if (H5P_get(c_plist, H5F_CRT_BTREE_RANK_NAME, btree_k) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get rank for btree internal nodes") UINT16DECODE(p, btree_k[H5B_SNODE_ID]); if (btree_k[H5B_SNODE_ID] == 0) HGOTO_ERROR(H5E_FILE, H5E_BADRANGE, FAIL, "bad 1/2 rank for btree internal nodes") /* * Delay setting the value in the property list until we've checked * for the indexed storage B-tree internal 'K' value later. */ /* File consistency flags. Not really used yet */ UINT32DECODE(p, shared->consist_flags); assert(((size_t)(p - buf)) == fixed_size); /* Decode the variable-length part of the superblock... */ variable_size = (super_vers>0 ? 4 : 0) + /* Potential indexed storage B-tree internal 'K' value */ H5F_SIZEOF_ADDR(f) + /*base addr*/ H5F_SIZEOF_ADDR(f) + /*global free list*/ H5F_SIZEOF_ADDR(f) + /*end-of-address*/ H5F_SIZEOF_ADDR(f) + /*reserved address*/ H5G_SIZEOF_ENTRY(f); /*root group ptr*/ assert(fixed_size + variable_size <= sizeof(buf)); if (H5FD_set_eoa(lf, shared->super_addr + fixed_size+variable_size) < 0 || H5FD_read(lf, H5FD_MEM_SUPER, dxpl_id, shared->super_addr + fixed_size, variable_size, p) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to read superblock") /* * If the superblock version # is greater than 0, read in the indexed * storage B-tree internal 'K' value */ if (super_vers > 0) { UINT16DECODE(p, btree_k[H5B_ISTORE_ID]); p += 2; /* reserved */ } else btree_k[H5B_ISTORE_ID] = HDF5_BTREE_ISTORE_IK_DEF; /* Set the B-tree internal node values, etc */ if (H5P_set(c_plist, H5F_CRT_BTREE_RANK_NAME, btree_k) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set rank for btree internal nodes") HDmemcpy(shared->btree_k, btree_k, sizeof(unsigned) * (size_t)H5B_NUM_BTREE_ID); /* Keep a local copy also */ H5F_addr_decode(f, (const uint8_t **)&p, &shared->base_addr/*out*/); H5F_addr_decode(f, (const uint8_t **)&p, &shared->freespace_addr/*out*/); H5F_addr_decode(f, (const uint8_t **)&p, &stored_eoa/*out*/); H5F_addr_decode(f, (const uint8_t **)&p, &shared->driver_addr/*out*/); if (H5G_ent_decode(f, (const uint8_t **)&p, root_ent/*out*/) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to read root symbol entry") /* * Check if superblock address is different from base address and * adjust base address and "end of address" address if so. */ if (!H5F_addr_eq(shared->super_addr,shared->base_addr)) { /* Check if the superblock moved earlier in the file */ if (H5F_addr_lt(shared->super_addr, shared->base_addr)) stored_eoa -= (shared->base_addr - shared->super_addr); else /* The superblock moved later in the file */ stored_eoa += (shared->super_addr - shared->base_addr); shared->base_addr = shared->super_addr; } /* end if */ /* Compute super block checksum */ assert(sizeof(chksum) == sizeof(shared->super_chksum)); for (q = (uint8_t *)&chksum, chksum = 0, i = 0; i < fixed_size + variable_size; ++i) q[i % sizeof(shared->super_chksum)] ^= buf[i]; /* Set the super block checksum */ shared->super_chksum = chksum; /* Decode the optional driver information block */ if (H5F_addr_defined(shared->driver_addr)) { haddr_t drv_addr = shared->base_addr + shared->driver_addr; uint8_t dbuf[H5F_DRVINFOBLOCK_SIZE]; /* Local buffer */ if (H5FD_set_eoa(lf, drv_addr + 16) < 0 || H5FD_read(lf, H5FD_MEM_SUPER, dxpl_id, drv_addr, (size_t)16, dbuf) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to read driver information block") p = dbuf; /* Version number */ if (HDF5_DRIVERINFO_VERSION != *p++) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "bad driver information block version number") p += 3; /* reserved */ /* Driver info size */ UINT32DECODE(p, driver_size); /* Driver name and/or version */ HDstrncpy(driver_name, (const char *)p, (size_t)8); driver_name[8] = '\0'; p += 8; /* advance past name/version */ /* Read driver information and decode */ assert((driver_size + 16) <= sizeof(dbuf)); if (H5FD_set_eoa(lf, drv_addr + 16 + driver_size) < 0 || H5FD_read(lf, H5FD_MEM_SUPER, dxpl_id, drv_addr+16, driver_size, p) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to read file driver information") if (H5FD_sb_decode(lf, driver_name, p) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to decode driver information") /* Compute driver info block checksum */ assert(sizeof(chksum) == sizeof(shared->drvr_chksum)); for (q = (uint8_t *)&chksum, chksum = 0, i = 0; i < (driver_size + 16); ++i) q[i % sizeof(shared->drvr_chksum)] ^= dbuf[i]; /* Set the driver info block checksum */ shared->drvr_chksum = chksum; } /* end if */
/*------------------------------------------------------------------------- * Function: test_1 * * Purpose: Writes a sequence of objects to the global heap where each * object is larger than the one before. * * Return: Success: 0 * * Failure: number of errors * * Programmer: Robb Matzke * Tuesday, March 31, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static int test_1 (hid_t fapl) { hid_t file = -1; H5F_t *f = NULL; H5HG_t obj[1024]; uint8_t out[1024]; uint8_t in[1024]; int i; size_t size; herr_t status; int nerrors = 0; char filename[1024]; TESTING("monotonically increasing lengths"); /* Open a clean file */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) goto error; if(NULL == (f = (H5F_t *)H5I_object(file))) { H5_FAILED(); puts(" Unable to create file"); goto error; } /* * Write the objects, monotonically increasing in length. Since this is * a clean file, the addresses allocated for the collections should also * be monotonically increasing. */ for(i = 0; i < 1024; i++) { size = i + 1; HDmemset(out, 'A' + i % 26, size); H5Eclear2(H5E_DEFAULT); status = H5HG_insert(f, H5P_DATASET_XFER_DEFAULT, size, out, obj + i); if(status < 0) { H5_FAILED(); puts(" Unable to insert object into global heap"); nerrors++; } else if(i && H5F_addr_gt(obj[i - 1].addr, obj[i].addr)) { H5_FAILED(); puts(" Collection addresses are not monotonically increasing"); nerrors++; } } /* * Now try to read each object back. */ for(i = 0; i < 1024; i++) { size = i + 1; HDmemset(out, 'A' + i % 26, size); H5Eclear2(H5E_DEFAULT); if(NULL == H5HG_read(f, H5P_DATASET_XFER_DEFAULT, obj + i, in, NULL)) { H5_FAILED(); puts(" Unable to read object"); nerrors++; } else if(HDmemcmp(in, out, size)) { H5_FAILED(); puts(" Value read doesn't match value written"); nerrors++; } } if(H5Fclose(file) < 0) goto error; if(nerrors) goto error; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Fclose(file); } H5E_END_TRY; return MAX(1, nerrors); }
/*------------------------------------------------------------------------- * Function: test_ooo_indices * * Purpose: Tests that indices can be stored out of order. This can * happen when the indices "wrap around" due to many * insertions and deletions (for example, from rewriting a * VL dataset). * * Return: Success: 0 * * Failure: number of errors * * Programmer: Neil Fortner * Monday, October 26, 2009 * * Modifications: * *------------------------------------------------------------------------- */ static int test_ooo_indices(hid_t fapl) { hid_t file = -1; H5F_t *f = NULL; unsigned i, j; H5HG_t *obj = NULL; herr_t status; int nerrors=0; char filename[1024]; TESTING("out of order indices"); if(NULL == (obj = (H5HG_t *)HDmalloc(2000 * sizeof(*obj)))) goto error; /* Open a clean file */ h5_fixname(FILENAME[4], fapl, filename, sizeof filename); if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) goto error; if(NULL == (f = (H5F_t *)H5I_object(file))) { H5_FAILED(); puts(" Unable to create file"); goto error; } /* end if */ /* Alternately insert 1000 entries and remove the previous group of 1000 * entries, until the indices wrap around */ for(i=0; i<66; i++) { /* Insert 1000 entries. The index into the obj array will alternate up * and down by 1000 so the previous set of insertions is preserved and * can be deleted. */ for(j=1000*((~i&1)); j<1000*((~i&1)+1); j++) { H5Eclear2(H5E_DEFAULT); status = H5HG_insert(f, H5P_DATASET_XFER_DEFAULT, sizeof(j), &j, &obj[j]); if (status<0) GHEAP_REPEATED_ERR(" Unable to insert object into global heap") /* Check that the index is as expected */ if(obj[j].idx != ((1000 * i) + j - (1000 * ((~i & 1)))) % ((1u << 16) - 1) + 1) GHEAP_REPEATED_ERR(" Unexpected global heap index"); } /* end for */ /* Remove the previous 1000 entries */ if(i>0) for(j=1000*(i&1); j<1000*((i&1)+1); j++) { H5Eclear2(H5E_DEFAULT); status = H5HG_remove(f, H5P_DATASET_XFER_DEFAULT, &obj[j]); if (status<0) GHEAP_REPEATED_ERR(" Unable to remove object from global heap"); } /* end for */ } /* end for */ /* The indices should have "wrapped around" on the last iteration */ HDassert(obj[534].idx == 65535); HDassert(obj[535].idx == 1); /* Reopen the file */ if (H5Fclose(file)<0) goto error; if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) goto error; if(NULL == (f = (H5F_t *)H5I_object(file))) { H5_FAILED(); puts(" Unable to open file"); goto error; } /* end if */ /* Read the objects to make sure the heap is still readable */ for(i=0; i<1000; i++) { if(NULL == H5HG_read(f, H5P_DATASET_XFER_DEFAULT, &obj[i], &j, NULL)) goto error; if(i != j) { H5_FAILED(); puts(" Incorrect read value"); goto error; } /* end if */ } /* end for */ if (H5Fclose(file)<0) goto error; if (nerrors) goto error; HDfree(obj); obj = NULL; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Fclose(file); } H5E_END_TRY; if(obj) HDfree(obj); return MAX(1, nerrors); } /* end test_ooo_indices */
/*------------------------------------------------------------------------- * Function: test_4 * * Purpose: Tests the H5HG_remove() feature by writing lots of objects * and occassionally removing some. When we're done they're all * removed. * * Return: Success: 0 * * Failure: number of errors * * Programmer: Robb Matzke * Tuesday, March 31, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static int test_4 (hid_t fapl) { hid_t file = -1; H5F_t *f = NULL; H5HG_t obj[1024]; uint8_t out[1024]; int i; size_t size; herr_t status; int nerrors = 0; char filename[1024]; TESTING("partial object removal"); /* Open a clean file */ h5_fixname(FILENAME[3], fapl, filename, sizeof filename); if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) goto error; if(NULL == (f = (H5F_t *)H5I_object(file))) { H5_FAILED(); puts(" Unable to create file"); goto error; } for (i=0; i<1024; i++) { /* Insert */ size = i%30+100; memset (out, 'A'+i%26, size); H5Eclear2(H5E_DEFAULT); status = H5HG_insert (f, H5P_DATASET_XFER_DEFAULT, size, out, obj+i); if (status<0) { H5_FAILED(); puts(" Unable to insert object into global heap"); nerrors++; } /* * Remove every third one beginning with the second, but after the * next one has already been inserted. That is, insert A, B, C; * remove B, insert D, E, F; remove E; etc. */ if (1==i%3) { H5Eclear2(H5E_DEFAULT); status = H5HG_remove (f, H5P_DATASET_XFER_DEFAULT, obj+i-1); if (status<0) { H5_FAILED(); puts(" Unable to remove object"); nerrors++; } memset (obj+i-1, 0, sizeof *obj); } } if (H5Fclose(file)<0) goto error; if (nerrors) goto error; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Fclose(file); } H5E_END_TRY; return MAX(1, nerrors); }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Tests indexed storage stuff. * * Return: Success: exit(0) * * Failure: exit(non-zero) * * Programmer: Robb Matzke * Wednesday, October 15, 1997 * * Modifications: * *------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { hid_t fapl=-1, file=-1, fcpl=-1; herr_t status; int nerrors = 0; unsigned size_of_test; unsigned u; /* Local index variable */ char filename[1024]; /* Parse arguments or assume these tests (`small', `medium' ) */ if (1 == argc) { size_of_test = TEST_SMALL; } else { int i; for (i = 1, size_of_test = 0; i < argc; i++) { if (!strcmp(argv[i], "small")) { size_of_test |= TEST_SMALL; } else if (!strcmp(argv[i], "medium")) { size_of_test |= TEST_MEDIUM; } else if (!strcmp(argv[i], "large")) { size_of_test |= TEST_LARGE; } else { printf("unrecognized argument: %s\n", argv[i]); #if 0 exit(1); #endif } } } printf("Test sizes: "); if (size_of_test & TEST_SMALL) printf(" SMALL"); if (size_of_test & TEST_MEDIUM) printf(" MEDIUM"); if (size_of_test & TEST_LARGE) printf(" LARGE"); printf("\n"); /* Set the random # seed */ HDsrandom((unsigned long)HDtime(NULL)); /* Reset library */ h5_reset(); fapl = h5_fileaccess(); /* Use larger file addresses... */ fcpl = H5Pcreate(H5P_FILE_CREATE); H5Pset_sizes(fcpl, 8, 0); /* Create the test file */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl))<0) { printf("Cannot create file %s; test aborted\n", filename); exit(1); } /* * For testing file families, fool the library into thinking it already * allocated a whole bunch of data. */ if (H5FD_FAMILY==H5Pget_driver(fapl)) { haddr_t addr; H5F_t *f; addr = 8 * ((uint64_t)1<<30); /*8 GB */ f=H5I_object(file); if (H5FDset_eoa(f->shared->lf, addr)<0) { printf("Cannot create large file family\n"); exit(1); } } /* Initialize chunk dimensions */ for (u = 0; u < H5O_LAYOUT_NDIMS; u++) chunk_dims[u]=TEST_CHUNK_SIZE; /* * Creation test: Creates empty objects with various raw data sizes * and alignments. */ status = test_create(file, "create"); nerrors += status < 0 ? 1 : 0; if (size_of_test & TEST_SMALL) { status = test_extend(file, "extend", 10, 0, 0); nerrors += status < 0 ? 1 : 0; status = test_extend(file, "extend", 10, 10, 0); nerrors += status < 0 ? 1 : 0; status = test_extend(file, "extend", 10, 10, 10); nerrors += status < 0 ? 1 : 0; } if (size_of_test & TEST_MEDIUM) { status = test_extend(file, "extend", 10000, 0, 0); nerrors += status < 0 ? 1 : 0; status = test_extend(file, "extend", 2500, 10, 0); nerrors += status < 0 ? 1 : 0; status = test_extend(file, "extend", 10, 400, 10); nerrors += status < 0 ? 1 : 0; } if (size_of_test & TEST_SMALL) { status = test_sparse(file, "sparse", 100, 5, 0, 0); nerrors += status < 0 ? 1 : 0; status = test_sparse(file, "sparse", 100, 3, 4, 0); nerrors += status < 0 ? 1 : 0; status = test_sparse(file, "sparse", 100, 2, 3, 4); nerrors += status < 0 ? 1 : 0; } if (size_of_test & TEST_MEDIUM) { status = test_sparse(file, "sparse", 1000, 30, 0, 0); nerrors += status < 0 ? 1 : 0; status = test_sparse(file, "sparse", 2000, 7, 3, 0); nerrors += status < 0 ? 1 : 0; status = test_sparse(file, "sparse", 2000, 4, 2, 3); nerrors += status < 0 ? 1 : 0; } if (size_of_test & TEST_LARGE) { status = test_sparse(file, "sparse", 800, 50, 50, 50); nerrors += status < 0 ? 1 : 0; } /* Close the test file and exit */ H5Pclose(fcpl); H5Fclose(file); if (nerrors) { printf("***** %d I-STORE TEST%s FAILED! *****\n", nerrors, 1 == nerrors ? "" : "S"); exit(1); } printf("All i-store tests passed.\n"); h5_cleanup(FILENAME, fapl); return 0; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Create a file, create a local heap, write data into the local * heap, close the file, open the file, read data out of the * local heap, close the file. * * Return: Success: zero * * Failure: non-zero * * Programmer: Robb Matzke * Tuesday, November 24, 1998 * * Modifications: * *------------------------------------------------------------------------- */ int main(void) { hid_t fapl=H5P_DEFAULT; /*file access properties */ hid_t file=-1; /*hdf5 file */ H5F_t *f=NULL; /*hdf5 file pointer */ char filename[1024]; /*file name */ haddr_t heap_addr; /*local heap address */ H5HL_t *heap = NULL; /*local heap */ size_t obj[NOBJS]; /*offsets within the heap */ int i, j; /*miscellaneous counters */ char buf[1024]; /*the value to store */ const char *s; /*value to read */ /* Reset library */ h5_reset(); fapl = h5_fileaccess(); /* * Test writing to the heap... */ TESTING("local heap write"); h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) goto error; if(NULL == (f = H5I_object(file))) { H5_FAILED(); H5Eprint2(H5E_DEFAULT, stdout); goto error; } if(H5HL_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)0, &heap_addr/*out*/) < 0) { H5_FAILED(); H5Eprint2(H5E_DEFAULT, stdout); goto error; } if (NULL == (heap = H5HL_protect(f, H5P_DATASET_XFER_DEFAULT, heap_addr, H5AC_WRITE))) { H5_FAILED(); H5Eprint2(H5E_DEFAULT, stdout); goto error; } for(i = 0; i < NOBJS; i++) { sprintf(buf, "%03d-", i); for (j=4; j<i; j++) buf[j] = '0' + j%10; if (j>4) buf[j] = '\0'; if ((size_t)(-1)==(obj[i]=H5HL_insert(f, H5P_DATASET_XFER_DEFAULT, heap, strlen(buf)+1, buf))) { H5_FAILED(); H5Eprint2(H5E_DEFAULT, stdout); goto error; } } if (H5HL_unprotect(f, H5P_DATASET_XFER_DEFAULT, heap, heap_addr) < 0) { H5_FAILED(); H5Eprint2(H5E_DEFAULT, stdout); goto error; } if (H5Fclose(file)<0) goto error; PASSED(); /* * Test reading from the heap... */ TESTING("local heap read"); h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if ((file=H5Fopen(filename, H5F_ACC_RDONLY, fapl))<0) goto error; if (NULL==(f=H5I_object(file))) { H5_FAILED(); H5Eprint2(H5E_DEFAULT, stdout); goto error; } for (i=0; i<NOBJS; i++) { sprintf(buf, "%03d-", i); for (j=4; j<i; j++) buf[j] = '0' + j%10; if (j>4) buf[j] = '\0'; if (NULL == (heap = H5HL_protect(f, H5P_DATASET_XFER_DEFAULT, heap_addr, H5AC_READ))) { H5_FAILED(); H5Eprint2(H5E_DEFAULT, stdout); goto error; } if (NULL == (s = H5HL_offset_into(f, heap, obj[i]))) { H5_FAILED(); H5Eprint2(H5E_DEFAULT, stdout); goto error; } if (strcmp(s, buf)) { H5_FAILED(); printf(" i=%d, heap offset=%lu\n", i, (unsigned long)(obj[i])); printf(" got: \"%s\"\n", s); printf(" ans: \"%s\"\n", buf); goto error; } if (H5HL_unprotect(f, H5P_DATASET_XFER_DEFAULT, heap, heap_addr) < 0) { H5_FAILED(); H5Eprint2(H5E_DEFAULT, stdout); goto error; } } if (H5Fclose(file)<0) goto error; PASSED(); puts("All local heap tests passed."); h5_cleanup(FILENAME, fapl); return 0; error: puts("*** TESTS FAILED ***"); H5E_BEGIN_TRY { H5Fclose(file); } H5E_END_TRY; return 1; }
/* * Verify that object headers are held in the cache until they are linked * to a location in the graph, or assigned an ID. This is done by * creating an object header, then forcing it out of the cache by creating * local heaps until the object header is evicted from the cache, then * modifying the object header. The refcount on the object header is * checked as verifying that the object header has remained in the cache. */ static herr_t test_ohdr_cache(char *filename, hid_t fapl) { hid_t file = -1; /* File ID */ hid_t my_fapl; /* FAPL ID */ hid_t my_dxpl; /* DXPL ID */ H5AC_cache_config_t mdc_config; /* Metadata cache configuration info */ H5F_t *f = NULL; /* File handle */ H5HL_t *lheap, *lheap2, *lheap3; /* Pointer to local heaps */ haddr_t lheap_addr, lheap_addr2, lheap_addr3; /* Local heap addresses */ H5O_loc_t oh_loc; /* Object header location */ time_t time_new; /* Time value for modification time message */ unsigned rc; /* Refcount for object */ TESTING("object header creation in cache"); /* Make a copy of the FAPL */ if((my_fapl = H5Pcopy(fapl)) < 0) FAIL_STACK_ERROR /* Tweak down the size of the metadata cache to only 64K */ mdc_config.version = H5AC__CURR_CACHE_CONFIG_VERSION; if(H5Pget_mdc_config(my_fapl, &mdc_config) < 0) FAIL_STACK_ERROR mdc_config.set_initial_size = TRUE; mdc_config.initial_size = 32 * 1024; mdc_config.max_size = 64 * 1024; mdc_config.min_size = 8 * 1024; if(H5Pset_mdc_config(my_fapl, &mdc_config) < 0) FAIL_STACK_ERROR /* Make a copy of the default DXPL */ if((my_dxpl = H5Pcopy(H5P_DATASET_XFER_DEFAULT)) < 0) FAIL_STACK_ERROR /* Create the file to operate on */ if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) FAIL_STACK_ERROR if(H5Pclose(my_fapl) < 0) FAIL_STACK_ERROR if(NULL == (f = (H5F_t *)H5I_object(file))) FAIL_STACK_ERROR if(H5AC_ignore_tags(f) < 0) FAIL_STACK_ERROR /* Create object (local heap) that occupies most of cache */ if(H5HL_create(f, my_dxpl, (31 * 1024), &lheap_addr) < 0) FAIL_STACK_ERROR /* Protect local heap (which actually pins it in the cache) */ if(NULL == (lheap = H5HL_protect(f, my_dxpl, lheap_addr, H5AC__READ_ONLY_FLAG))) FAIL_STACK_ERROR /* Create an object header */ HDmemset(&oh_loc, 0, sizeof(oh_loc)); if(H5O_create(f, my_dxpl, (size_t)2048, (size_t)1, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0) FAIL_STACK_ERROR /* Query object header information */ rc = 0; if(H5O_get_rc(&oh_loc, my_dxpl, &rc) < 0) FAIL_STACK_ERROR if(0 != rc) TEST_ERROR /* Create object (local heap) that occupies most of cache */ if(H5HL_create(f, my_dxpl, (31 * 1024), &lheap_addr2) < 0) FAIL_STACK_ERROR /* Protect local heap (which actually pins it in the cache) */ if(NULL == (lheap2 = H5HL_protect(f, my_dxpl, lheap_addr2, H5AC__READ_ONLY_FLAG))) FAIL_STACK_ERROR /* Unprotect local heap (which actually unpins it from the cache) */ if(H5HL_unprotect(lheap2) < 0) FAIL_STACK_ERROR /* Create object header message in new object header */ time_new = 11111111; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, my_dxpl) < 0) FAIL_STACK_ERROR /* Create object (local heap) that occupies most of cache */ if(H5HL_create(f, my_dxpl, (31 * 1024), &lheap_addr3) < 0) FAIL_STACK_ERROR /* Protect local heap (which actually pins it in the cache) */ if(NULL == (lheap3 = H5HL_protect(f, my_dxpl, lheap_addr3, H5AC__READ_ONLY_FLAG))) FAIL_STACK_ERROR /* Unprotect local heap (which actually unpins it from the cache) */ if(H5HL_unprotect(lheap3) < 0) FAIL_STACK_ERROR /* Query object header information */ /* (Note that this is somewhat of a weak test, since it doesn't actually * verify that the object header was evicted from the cache, but it's * very difficult to verify when an entry is evicted from the cache in * a non-invasive way -QAK) */ rc = 0; if(H5O_get_rc(&oh_loc, my_dxpl, &rc) < 0) FAIL_STACK_ERROR if(0 != rc) TEST_ERROR /* Decrement reference count o object header */ if(H5O_dec_rc_by_loc(&oh_loc, my_dxpl) < 0) FAIL_STACK_ERROR /* Close object header created */ if(H5O_close(&oh_loc) < 0) FAIL_STACK_ERROR /* Unprotect local heap (which actually unpins it from the cache) */ if(H5HL_unprotect(lheap) < 0) FAIL_STACK_ERROR if(H5Pclose(my_dxpl) < 0) FAIL_STACK_ERROR if(H5Fclose(file) < 0) FAIL_STACK_ERROR PASSED(); return 0; error: H5E_BEGIN_TRY { H5Fclose(file); } H5E_END_TRY; return -1; } /* test_ohdr_cache() */
/*------------------------------------------------------------------------- * Function: main * * Usage: debug FILENAME [OFFSET] * * Return: Success: exit (0) * * Failure: exit (non-zero) * * Programmer: Robb Matzke * [email protected] * Jul 18 1997 * *------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { hid_t fid, fapl, dxpl; H5F_t *f; haddr_t addr = 0, extra = 0, extra2 = 0, extra3 = 0, extra4 = 0; uint8_t sig[H5F_SIGNATURE_LEN]; size_t u; H5E_auto2_t func; void *edata; herr_t status = SUCCEED; if(argc == 1) { HDfprintf(stderr, "Usage: %s filename [signature-addr [extra]]\n", argv[0]); HDexit(1); } /* end if */ /* Initialize the library */ if(H5open() < 0) { HDfprintf(stderr, "cannot initialize the library\n"); HDexit(1); } /* end if */ /* Disable error reporting */ H5Eget_auto2(H5E_DEFAULT, &func, &edata); H5Eset_auto2(H5E_DEFAULT, NULL, NULL); /* * Open the file and get the file descriptor. */ dxpl = H5AC_ind_read_dxpl_id; if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) { HDfprintf(stderr, "cannot create file access property list\n"); HDexit(1); } /* end if */ if(HDstrchr(argv[1], '%')) if(H5Pset_fapl_family (fapl, (hsize_t)0, H5P_DEFAULT) < 0) { fprintf(stderr, "cannot set file access property list\n"); HDexit(1); } if((fid = H5Fopen(argv[1], H5F_ACC_RDONLY, fapl)) < 0) { HDfprintf(stderr, "cannot open file\n"); HDexit(1); } /* end if */ if(NULL == (f = (H5F_t *)H5I_object(fid))) { HDfprintf(stderr, "cannot obtain H5F_t pointer\n"); HDexit(2); } /* end if */ /* Ignore metadata tags while using h5debug */ if(H5AC_ignore_tags(f) < 0) { HDfprintf(stderr, "cannot ignore metadata tags\n"); HDexit(1); } /* * Parse command arguments. */ if(argc > 2) addr = (haddr_t)HDstrtoll(argv[2], NULL, 0); if(argc > 3) extra = (haddr_t)HDstrtoll(argv[3], NULL, 0); if(argc > 4) extra2 = (haddr_t)HDstrtoll(argv[4], NULL, 0); if(argc > 5) extra3 = (haddr_t)HDstrtoll(argv[5], NULL, 0); if(argc > 6) extra4 = (haddr_t)HDstrtoll(argv[6], NULL, 0); /* * Read the signature at the specified file position. */ HDfprintf(stdout, "Reading signature at address %a (rel)\n", addr); if(H5F_block_read(f, H5FD_MEM_SUPER, addr, sizeof(sig), dxpl, sig) < 0) { HDfprintf(stderr, "cannot read signature\n"); HDexit(3); } if(!HDmemcmp(sig, H5F_SIGNATURE, (size_t)H5F_SIGNATURE_LEN)) { /* * Debug the file's super block. */ status = H5F_debug(f, stdout, 0, VCOL); } else if(!HDmemcmp(sig, H5HL_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug a local heap. */ status = H5HL_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL); } else if(!HDmemcmp (sig, H5HG_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug a global heap collection. */ status = H5HG_debug (f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL); } else if(!HDmemcmp(sig, H5G_NODE_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug a symbol table node. */ /* Check for extra parameters */ if(extra == 0) { HDfprintf(stderr, "\nWarning: Providing the group's local heap address will give more information\n"); HDfprintf(stderr, "Symbol table node usage:\n"); HDfprintf(stderr, "\th5debug <filename> <Symbol table node address> <address of local heap>\n\n"); } /* end if */ status = H5G_node_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, extra); } else if(!HDmemcmp(sig, H5B_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug a B-tree. B-trees are debugged through the B-tree * subclass. The subclass identifier is the byte immediately * after the B-tree signature. */ H5B_subid_t subtype = (H5B_subid_t)sig[H5_SIZEOF_MAGIC]; unsigned ndims; uint32_t dim[H5O_LAYOUT_NDIMS]; switch(subtype) { case H5B_SNODE_ID: /* Check for extra parameters */ if(extra == 0) { HDfprintf(stderr, "\nWarning: Providing the group's local heap address will give more information\n"); HDfprintf(stderr, "B-tree symbol table node usage:\n"); HDfprintf(stderr, "\th5debug <filename> <B-tree node address> <address of local heap>\n\n"); HDexit(4); } /* end if */ status = H5G_node_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, extra); break; case H5B_CHUNK_ID: /* Check for extra parameters */ if(extra == 0) { HDfprintf(stderr, "ERROR: Need number of dimensions of chunk in order to dump chunk B-tree node\n"); HDfprintf(stderr, "B-tree chunked storage node usage:\n"); HDfprintf(stderr, "\th5debug <filename> <B-tree node address> <# of dimensions> <slowest chunk dim>...<fastest chunk dim>\n"); HDexit(4); } /* end if */ /* Build array of chunk dimensions */ ndims = (unsigned)extra; dim[0] = (uint32_t)extra2; if(ndims > 1) dim[1] = (uint32_t)extra3; if(ndims > 2) dim[2] = (uint32_t)extra4; /* Check for dimension error */ if(ndims > 3) { HDfprintf(stderr, "ERROR: Only 3 dimensions support currently (fix h5debug)\n"); HDfprintf(stderr, "B-tree chunked storage node usage:\n"); HDfprintf(stderr, "\th5debug <filename> <B-tree node address> <# of dimensions> <slowest chunk dim>...<fastest chunk dim>\n"); HDexit(4); } /* end for */ for(u = 0; u < ndims; u++) if(0 == dim[u]) { HDfprintf(stderr, "ERROR: Chunk dimensions should be >0\n"); HDfprintf(stderr, "B-tree chunked storage node usage:\n"); HDfprintf(stderr, "\th5debug <filename> <B-tree node address> <# of dimensions> <slowest chunk dim>...<fastest chunk dim>\n"); HDexit(4); } /* end if */ /* Set the last dimension (the element size) to zero */ dim[ndims] = 0; status = H5D_btree_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, ndims, dim); break; case H5B_NUM_BTREE_ID: default: HDfprintf(stderr, "Unknown v1 B-tree subtype %u\n", (unsigned)(subtype)); HDexit(4); } } else if(!HDmemcmp(sig, H5B2_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug a v2 B-tree header. */ const H5B2_class_t *cls = get_H5B2_class(sig); HDassert(cls); if((cls == H5D_BT2 || cls == H5D_BT2_FILT) && extra == 0) { HDfprintf(stderr, "ERROR: Need v2 B-tree header address and object header address containing the layout message in order to dump header\n"); HDfprintf(stderr, "v2 B-tree hdr usage:\n"); HDfprintf(stderr, "\th5debug <filename> <v2 B-tree header address> <object header address>\n"); HDexit(4); } /* end if */ status = H5B2__hdr_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, (haddr_t)extra); } else if(!HDmemcmp(sig, H5B2_INT_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug a v2 B-tree internal node. */ const H5B2_class_t *cls = get_H5B2_class(sig); HDassert(cls); /* Check for enough valid parameters */ if((cls == H5D_BT2 || cls == H5D_BT2_FILT) && (extra == 0 || extra2 == 0 || extra3 == 0 || extra4 == 0)) { fprintf(stderr, "ERROR: Need v2 B-tree header address, the node's number of records, depth, and object header address containing the layout message in order to dump internal node\n"); fprintf(stderr, "NOTE: Leaf nodes are depth 0, the internal nodes above them are depth 1, etc.\n"); fprintf(stderr, "v2 B-tree internal node usage:\n"); fprintf(stderr, "\th5debug <filename> <internal node address> <v2 B-tree header address> <number of records> <depth> <object header address>\n"); HDexit(4); } else if(extra == 0 || extra2 == 0 || extra3 == 0) { HDfprintf(stderr, "ERROR: Need v2 B-tree header address and the node's number of records and depth in order to dump internal node\n"); HDfprintf(stderr, "NOTE: Leaf nodes are depth 0, the internal nodes above them are depth 1, etc.\n"); HDfprintf(stderr, "v2 B-tree internal node usage:\n"); HDfprintf(stderr, "\th5debug <filename> <internal node address> <v2 B-tree header address> <number of records> <depth>\n"); HDexit(4); } /* end if */ status = H5B2__int_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, extra, (unsigned)extra2, (unsigned)extra3, (haddr_t)extra4); } else if(!HDmemcmp(sig, H5B2_LEAF_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug a v2 B-tree leaf node. */ const H5B2_class_t *cls = get_H5B2_class(sig); HDassert(cls); /* Check for enough valid parameters */ if((cls == H5D_BT2 || cls == H5D_BT2_FILT) && (extra == 0 || extra2 == 0 || extra3 == 0 )) { fprintf(stderr, "ERROR: Need v2 B-tree header address, number of records, and object header address containing the layout message in order to dump leaf node\n"); fprintf(stderr, "v2 B-tree leaf node usage:\n"); fprintf(stderr, "\th5debug <filename> <leaf node address> <v2 B-tree header address> <number of records> <object header address>\n"); HDexit(4); } else if(extra == 0 || extra2 == 0) { HDfprintf(stderr, "ERROR: Need v2 B-tree header address and number of records in order to dump leaf node\n"); HDfprintf(stderr, "v2 B-tree leaf node usage:\n"); HDfprintf(stderr, "\th5debug <filename> <leaf node address> <v2 B-tree header address> <number of records>\n"); HDexit(4); } /* end if */ status = H5B2__leaf_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, extra, (unsigned)extra2, (haddr_t)extra3); } else if(!HDmemcmp(sig, H5HF_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug a fractal heap header. */ status = H5HF_hdr_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL); } else if(!HDmemcmp(sig, H5HF_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug a fractal heap direct block. */ /* Check for enough valid parameters */ if(extra == 0 || extra2 == 0) { HDfprintf(stderr, "ERROR: Need fractal heap header address and size of direct block in order to dump direct block\n"); HDfprintf(stderr, "Fractal heap direct block usage:\n"); HDfprintf(stderr, "\th5debug <filename> <direct block address> <heap header address> <size of direct block>\n"); HDexit(4); } /* end if */ status = H5HF_dblock_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, extra, (size_t)extra2); } else if(!HDmemcmp(sig, H5HF_IBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug a fractal heap indirect block. */ /* Check for enough valid parameters */ if(extra == 0 || extra2 == 0) { HDfprintf(stderr, "ERROR: Need fractal heap header address and number of rows in order to dump indirect block\n"); HDfprintf(stderr, "Fractal heap indirect block usage:\n"); HDfprintf(stderr, "\th5debug <filename> <indirect block address> <heap header address> <number of rows>\n"); HDexit(4); } /* end if */ status = H5HF_iblock_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, extra, (unsigned)extra2); } else if(!HDmemcmp(sig, H5FS_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug a free space header. */ status = H5FS_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL); } else if(!HDmemcmp(sig, H5FS_SINFO_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug free space serialized sections. */ /* Check for enough valid parameters */ if(extra == 0 || extra2 == 0) { HDfprintf(stderr, "ERROR: Need free space header address and client address in order to dump serialized sections\n"); HDfprintf(stderr, "Free space serialized sections usage:\n"); HDfprintf(stderr, "\th5debug <filename> <serialized sections address> <free space header address> <client address>\n"); HDexit(4); } /* end if */ status = H5FS_sects_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, extra, extra2); } else if(!HDmemcmp(sig, H5SM_TABLE_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug shared message master table. */ status = H5SM_table_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, (unsigned) UFAIL, (unsigned) UFAIL); } else if(!HDmemcmp(sig, H5SM_LIST_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug shared message list index. */ /* Check for enough valid parameters */ if(extra == 0) { HDfprintf(stderr, "ERROR: Need shared message header address in order to shared message list\n"); HDfprintf(stderr, "Shared message list usage:\n"); HDfprintf(stderr, "\th5debug <filename> <shared message list address> <shared message header address>\n"); HDexit(4); } /* end if */ status = H5SM_list_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, (haddr_t)extra); } else if(!HDmemcmp(sig, H5EA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug an extensible aray header. */ const H5EA_class_t *cls = get_H5EA_class(sig); HDassert(cls); /* Check for enough valid parameters */ if(extra == 0) { HDfprintf(stderr, "ERROR: Need object header address containing the layout message in order to dump header\n"); HDfprintf(stderr, "Extensible array header block usage:\n"); HDfprintf(stderr, "\th5debug <filename> <Extensible Array header address> <object header address>\n"); HDexit(4); } /* end if */ status = H5EA__hdr_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, extra); } else if(!HDmemcmp(sig, H5EA_IBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug an extensible aray index block. */ const H5EA_class_t *cls = get_H5EA_class(sig); HDassert(cls); /* Check for enough valid parameters */ if(extra == 0 || extra2 == 0) { HDfprintf(stderr, "ERROR: Need extensible array header address and object header address containing the layout message in order to dump index block\n"); HDfprintf(stderr, "Extensible array index block usage:\n"); HDfprintf(stderr, "\th5debug <filename> <index block address> <array header address> <object header address\n"); HDexit(4); } /* end if */ status = H5EA__iblock_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, extra, extra2); } else if(!HDmemcmp(sig, H5EA_SBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug an extensible aray super block. */ const H5EA_class_t *cls = get_H5EA_class(sig); HDassert(cls); /* Check for enough valid parameters */ if(extra == 0 || extra2 == 0 || extra3 == 0) { HDfprintf(stderr, "ERROR: Need extensible array header address, super block index and object header address containing the layout message in order to dump super block\n"); HDfprintf(stderr, "Extensible array super block usage:\n"); HDfprintf(stderr, "\th5debug <filename> <super block address> <array header address> <super block index> <object header address>\n"); HDexit(4); } /* end if */ status = H5EA__sblock_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, extra, (unsigned)extra2, extra3); } else if(!HDmemcmp(sig, H5EA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug an extensible aray data block. */ const H5EA_class_t *cls = get_H5EA_class(sig); HDassert(cls); /* Check for enough valid parameters */ if(extra == 0 || extra2 == 0 || extra3 == 0) { HDfprintf(stderr, "ERROR: Need extensible array header address, # of elements in data block and object header address containing the layout message in order to dump data block\n"); HDfprintf(stderr, "Extensible array data block usage:\n"); HDfprintf(stderr, "\th5debug <filename> <data block address> <array header address> <# of elements in data block> <object header address\n"); HDexit(4); } /* end if */ status = H5EA__dblock_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, extra, (size_t)extra2, extra3); } else if(!HDmemcmp(sig, H5FA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug a fixed array header. */ const H5FA_class_t *cls = get_H5FA_class(sig); HDassert(cls); /* Check for enough valid parameters */ if(extra == 0) { HDfprintf(stderr, "ERROR: Need object header address containing the layout message in order to dump header\n"); HDfprintf(stderr, "Fixed array header block usage:\n"); HDfprintf(stderr, "\th5debug <filename> <Fixed Array header address> <object header address>\n"); HDexit(4); } /* end if */ status = H5FA__hdr_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, extra); } else if(!HDmemcmp(sig, H5FA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug a fixed array data block. */ const H5FA_class_t *cls = get_H5FA_class(sig); HDassert(cls); /* Check for enough valid parameters */ if(extra == 0 || extra2 == 0) { HDfprintf(stderr, "ERROR: Need fixed array header address and object header address containing the layout message in order to dump data block\n"); HDfprintf(stderr, "fixed array data block usage:\n"); HDfprintf(stderr, "\th5debug <filename> <data block address> <array header address> <object header address>\n"); HDexit(4); } /* end if */ status = H5FA__dblock_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, extra, extra2); } else if(!HDmemcmp(sig, H5O_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* * Debug v2 object header (which have signatures). */ status = H5O_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL); } else if(sig[0] == H5O_VERSION_1) { /* * This could be a v1 object header. Since they don't have a signature * it's a somewhat "ify" detection. */ status = H5O_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL); } else { /* * Got some other unrecognized signature. */ printf("%-*s ", VCOL, "Signature:"); for (u = 0; u < sizeof(sig); u++) { if (sig[u] > ' ' && sig[u] <= '~' && '\\' != sig[u]) HDputchar(sig[u]); else if ('\\' == sig[u]) { HDputchar('\\'); HDputchar('\\'); } else printf("\\%03o", sig[u]); } HDputchar('\n'); HDfprintf(stderr, "unknown signature\n"); HDexit(4); } /* end else */ /* Check for an error when dumping information */ if(status < 0) { HDfprintf(stderr, "An error occurred!\n"); H5Eprint2(H5E_DEFAULT, stderr); HDexit(5); } /* end if */ H5Pclose(fapl); H5Fclose(fid); H5Eset_auto2(H5E_DEFAULT, func, edata); return 0; } /* main() */
/* * Verify that messages are moved forward into a "continuation message": * Create an object header with several continuation chunks * Remove a message in the last chunk * The remaining message(s) in the last chunk should be moved forward into the continuation message * The process will repeat when the continuation message is big enough to hold all the * messages in the last chunk. * Result: the number of chunks should be reduced */ static herr_t test_cont(char *filename, hid_t fapl) { hid_t file=-1; H5F_t *f = NULL; H5O_hdr_info_t hdr_info; H5O_loc_t oh_locA, oh_locB; time_t time_new; const char *short_name = "T"; const char *long_name = "This is the message"; size_t nchunks; TESTING("object header continuation block"); HDmemset(&oh_locA, 0, sizeof(oh_locA)); HDmemset(&oh_locB, 0, sizeof(oh_locB)); /* Create the file to operate on */ if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR if(NULL == (f = (H5F_t *)H5I_object(file))) FAIL_STACK_ERROR if (H5AC_ignore_tags(f) < 0) { H5_FAILED(); H5Eprint2(H5E_DEFAULT, stdout); goto error; } if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)H5O_MIN_SIZE, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_locA/*out*/) < 0) FAIL_STACK_ERROR if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)H5O_MIN_SIZE, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_locB/*out*/) < 0) FAIL_STACK_ERROR time_new = 11111111; if(H5O_msg_create(&oh_locA, H5O_NAME_ID, 0, 0, &long_name, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_create(&oh_locB, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_create(&oh_locB, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_create(&oh_locB, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_create(&oh_locA, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_create(&oh_locB, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_create(&oh_locA, H5O_NAME_ID, 0, 0, &short_name, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_locA, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(1 != H5O_link(&oh_locB, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_expunge_chunks_test(&oh_locA, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_get_hdr_info(&oh_locA, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0) FAIL_STACK_ERROR nchunks = hdr_info.nchunks; /* remove the 1st H5O_NAME_ID message */ if(H5O_msg_remove(&oh_locA, H5O_NAME_ID, 0, FALSE, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_get_hdr_info(&oh_locA, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0) FAIL_STACK_ERROR if(hdr_info.nchunks >= nchunks) TEST_ERROR if(H5O_close(&oh_locA) < 0) FAIL_STACK_ERROR if(H5O_close(&oh_locB) < 0) FAIL_STACK_ERROR if(H5Fclose(file) < 0) FAIL_STACK_ERROR PASSED(); return 0; error: H5E_BEGIN_TRY { H5O_close(&oh_locA); H5O_close(&oh_locB); H5Fclose(file); } H5E_END_TRY; return -1; } /* test_cont() */
/*------------------------------------------------------------------------- * Function: test_2 * * Purpose: Writes a sequence of objects to the global heap where each * object is smaller than the one before. * * Return: Success: 0 * * Failure: number of errors * * Programmer: Robb Matzke * Tuesday, March 31, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static int test_2 (hid_t fapl) { hid_t file = -1; H5F_t *f = NULL; H5HG_t obj[1024]; uint8_t out[1024]; uint8_t in[1024]; int i; size_t size; int nerrors = 0; char filename[1024]; TESTING("monotonically decreasing lengths"); /* Open a clean file */ h5_fixname(FILENAME[1], fapl, filename, sizeof filename); if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) goto error; if(NULL == (f = (H5F_t *)H5I_object(file))) { H5_FAILED(); puts(" Unable to create file"); goto error; } /* * Write the objects, monotonically decreasing in length. */ for (i=0; i<1024; i++) { size = 1024-i; memset (out, 'A'+i%26, size); H5Eclear2(H5E_DEFAULT); if (H5HG_insert (f, H5P_DATASET_XFER_DEFAULT, size, out, obj+i)<0) { H5_FAILED(); puts(" Unable to insert object into global heap"); nerrors++; } } /* * Now try to read each object back. */ for (i=0; i<1024; i++) { size = 1024-i; memset (out, 'A'+i%26, size); H5Eclear2(H5E_DEFAULT); if (NULL==H5HG_read (f, H5P_DATASET_XFER_DEFAULT, obj+i, in, NULL)) { H5_FAILED(); puts(" Unable to read object"); nerrors++; } else if (memcmp (in, out, size)) { H5_FAILED(); puts(" Value read doesn't match value written"); nerrors++; } } if (H5Fclose(file)<0) goto error; if (nerrors) goto error; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Fclose(file); } H5E_END_TRY; return MAX(1, nerrors); }