/*------------------------------------------------------------------------- * 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(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 */ H5_CHECKED_ASSIGN(ginfo.lheap_size_hint, uint32_t, size_hint, size_t); 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: H5D__single_idx_insert * * Purpose: Allocate space for the single chunk * * Return: Non-negative on success/Negative on failure * * Programmer: Vailin Choi; July 2011 * *------------------------------------------------------------------------- */ static herr_t H5D__single_idx_insert(const H5D_chk_idx_info_t *idx_info, H5D_chunk_ud_t *udata, const H5D_t *dset) { herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC /* Sanity checks */ HDassert(idx_info); HDassert(idx_info->f); HDassert(idx_info->pline); HDassert(idx_info->layout); HDassert(idx_info->storage); HDassert(idx_info->layout->nchunks == 1); HDassert(idx_info->layout->max_nchunks == 1); HDassert(udata); /* Set the address for the chunk */ HDassert(H5F_addr_defined(udata->chunk_block.offset)); idx_info->storage->idx_addr = udata->chunk_block.offset; if(idx_info->pline->nused > 0) { H5_CHECKED_ASSIGN(idx_info->storage->u.single.nbytes, uint32_t, udata->chunk_block.length, hsize_t); idx_info->storage->u.single.filter_mask = udata->filter_mask; } /* end if */ if(dset) { if(dset->shared->dcpl_cache.fill.alloc_time != H5D_ALLOC_TIME_EARLY || idx_info->pline->nused > 0) { /* Mark the layout dirty so that the address of the single chunk will be flushed later */ if(H5D__mark(dset, idx_info->dxpl_id, H5D_MARK_LAYOUT) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "unable to mark layout as dirty") } /* end if */ } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value) } /* H5D__single_idx_insert() */
/*------------------------------------------------------------------------- * Function: H5Tget_ebias * * Purpose: Retrieves the exponent bias of a floating-point type. * * Return: Success: The bias * * Failure: 0 * * Programmer: Robb Matzke * Wednesday, January 7, 1998 * *------------------------------------------------------------------------- */ size_t H5Tget_ebias(hid_t type_id) { H5T_t *dt; /* Datatype */ size_t ret_value; /* Return value */ FUNC_ENTER_API(0) H5TRACE1("z", "i", type_id); /* Check args */ if(NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not a datatype") while(dt->shared->parent) dt = dt->shared->parent; /*defer to parent*/ if(H5T_FLOAT != dt->shared->type) HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, 0, "operation not defined for datatype class") /* bias */ H5_CHECKED_ASSIGN(ret_value, size_t, dt->shared->u.atomic.u.f.ebias, uint64_t); done: FUNC_LEAVE_API(ret_value) } /* end H5Tget_ebias() */
/*------------------------------------------------------------------------- * Function: H5F__accum_read * * Purpose: Attempts to read some data from the metadata accumulator for * a file into a buffer. * * Note: We can't change (or add to) the metadata accumulator, because * this might be a speculative read and could possibly read raw * data into the metadata accumulator. * * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol * [email protected] * Jan 10 2008 * *------------------------------------------------------------------------- */ herr_t H5F__accum_read(H5F_t *f, H5FD_mem_t map_type, haddr_t addr, size_t size, void *buf/*out*/) { H5FD_t *file; /* File driver pointer */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE /* Sanity checks */ HDassert(f); HDassert(buf); /* Translate to file driver I/O info object */ file = f->shared->lf; /* Check if this information is in the metadata accumulator */ if((f->shared->feature_flags & H5FD_FEAT_ACCUMULATE_METADATA) && map_type != H5FD_MEM_DRAW) { H5F_meta_accum_t *accum; /* Alias for file's metadata accumulator */ /* Set up alias for file's metadata accumulator info */ accum = &f->shared->accum; if(size < H5F_ACCUM_MAX_SIZE) { /* Sanity check */ HDassert(!accum->buf || (accum->alloc_size >= accum->size)); /* Current read adjoins or overlaps with metadata accumulator */ if(H5F_addr_overlap(addr, size, accum->loc, accum->size) || ((addr + size) == accum->loc) || (accum->loc + accum->size) == addr) { size_t amount_before; /* Amount to read before current accumulator */ haddr_t new_addr; /* New address of the accumulator buffer */ size_t new_size; /* New size of the accumulator buffer */ /* Compute new values for accumulator */ new_addr = MIN(addr, accum->loc); new_size = (size_t)(MAX((addr + size), (accum->loc + accum->size)) - new_addr); /* Check if we need more buffer space */ if(new_size > accum->alloc_size) { size_t new_alloc_size; /* New size of accumulator */ /* Adjust the buffer size to be a power of 2 that is large enough to hold data */ new_alloc_size = (size_t)1 << (1 + H5VM_log2_gen((uint64_t)(new_size - 1))); /* Reallocate the metadata accumulator buffer */ if(NULL == (accum->buf = H5FL_BLK_REALLOC(meta_accum, accum->buf, new_alloc_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate metadata accumulator buffer") /* Note the new buffer size */ accum->alloc_size = new_alloc_size; /* Clear the memory */ HDmemset(accum->buf + accum->size, 0, (accum->alloc_size - accum->size)); } /* end if */ /* Read the part before the metadata accumulator */ if(addr < accum->loc) { /* Set the amount to read */ H5_CHECKED_ASSIGN(amount_before, size_t, (accum->loc - addr), hsize_t); /* Make room for the metadata to read in */ HDmemmove(accum->buf + amount_before, accum->buf, accum->size); /* Adjust dirty region tracking info, if present */ if(accum->dirty) accum->dirty_off += amount_before; /* Dispatch to driver */ if(H5FD_read(file, map_type, addr, amount_before, accum->buf) < 0) HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "driver read request failed") } /* end if */
/*------------------------------------------------------------------------- * Function: H5HF_man_dblock_create * * Purpose: Allocate & initialize a managed direct block * * Return: Pointer to new direct block on success, NULL on failure * * Programmer: Quincey Koziol * [email protected] * Feb 27 2006 * *------------------------------------------------------------------------- */ herr_t H5HF_man_dblock_create(hid_t dxpl_id, H5HF_hdr_t *hdr, H5HF_indirect_t *par_iblock, unsigned par_entry, haddr_t *addr_p, H5HF_free_section_t **ret_sec_node) { H5HF_free_section_t *sec_node; /* Pointer to free space section for block */ H5HF_direct_t *dblock = NULL; /* Pointer to direct block */ haddr_t dblock_addr; /* Direct block's address */ size_t free_space; /* Free space in new block */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT /* * Check arguments. */ HDassert(hdr); /* * Allocate file and memory data structures. */ if(NULL == (dblock = H5FL_MALLOC(H5HF_direct_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for fractal heap direct block") /* Reset the metadata cache info for the heap header */ HDmemset(&dblock->cache_info, 0, sizeof(H5AC_info_t)); /* Share common heap information */ dblock->hdr = hdr; if(H5HF_hdr_incr(hdr) < 0) HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, FAIL, "can't increment reference count on shared heap header") /* Set info for direct block */ if(par_iblock) { unsigned par_row = par_entry / hdr->man_dtable.cparam.width; /* Row for block */ /* Compute offset & size, based on parent's information */ dblock->block_off = par_iblock->block_off; dblock->block_off += hdr->man_dtable.row_block_off[par_row]; dblock->block_off += hdr->man_dtable.row_block_size[par_row] * (par_entry % hdr->man_dtable.cparam.width); H5_CHECKED_ASSIGN(dblock->size, size_t, hdr->man_dtable.row_block_size[par_row], hsize_t); } /* end if */ else { /* Must be the root direct block */ dblock->block_off = 0; dblock->size = hdr->man_dtable.cparam.start_block_size; } /* end else */ dblock->file_size = 0; free_space = dblock->size - H5HF_MAN_ABS_DIRECT_OVERHEAD(hdr); /* Allocate buffer for block */ /* XXX: Change to using free-list factories */ if((dblock->blk = H5FL_BLK_MALLOC(direct_block, dblock->size)) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") #ifdef H5_CLEAR_MEMORY HDmemset(dblock->blk, 0, dblock->size); #endif /* H5_CLEAR_MEMORY */ dblock->write_buf = NULL; dblock->write_size = 0; /* Allocate [temporary] space for the direct block on disk */ if(H5F_USE_TMP_SPACE(hdr->f)) { if(HADDR_UNDEF == (dblock_addr = H5MF_alloc_tmp(hdr->f, (hsize_t)dblock->size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "file allocation failed for fractal heap direct block") } /* end if */ else { if(HADDR_UNDEF == (dblock_addr = H5MF_alloc(hdr->f, H5FD_MEM_FHEAP_DBLOCK, dxpl_id, (hsize_t)dblock->size)))