/*------------------------------------------------------------------------- * Function: H5FS_close * * Purpose: Destroy & deallocate free list structure, serializing sections * in the bins * * Return: Success: non-negative * * Failure: negative * * Programmer: Quincey Koziol * Tuesday, March 7, 2006 * *------------------------------------------------------------------------- */ herr_t H5FS_close(H5F_t *f, hid_t dxpl_id, H5FS_t *fspace) { herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_TAG(dxpl_id, H5AC__FREESPACE_TAG, FAIL) /* Check arguments. */ HDassert(f); HDassert(fspace); #ifdef H5FS_DEBUG HDfprintf(stderr, "%s: Entering, fspace = %p, fspace->addr = %a, fspace->sinfo = %p\n", FUNC, fspace, fspace->addr, fspace->sinfo); #endif /* H5FS_DEBUG */ /* Check if section info is valid */ /* (i.e. the header "owns" the section info and it's not in the cache) */ if(fspace->sinfo) { #ifdef H5FS_DEBUG HDfprintf(stderr, "%s: fspace->tot_sect_count = %Hu, fspace->serial_sect_count = %Hu, fspace->sect_addr = %a, fspace->rc = %u\n", FUNC, fspace->tot_sect_count, fspace->serial_sect_count, fspace->sect_addr, fspace->rc); HDfprintf(stderr, "%s: fspace->alloc_sect_size = %Hu, fspace->sect_size = %Hu\n", FUNC, fspace->alloc_sect_size, fspace->sect_size); #endif /* H5FS_DEBUG */ /* If there are sections to serialize, update them */ /* (if the free space manager is persistant) */ if(fspace->serial_sect_count > 0 && H5F_addr_defined(fspace->addr)) { #ifdef H5FS_DEBUG HDfprintf(stderr, "%s: Real sections to store in file\n", FUNC); #endif /* H5FS_DEBUG */ if(fspace->sinfo->dirty) { /* Check if the section info is "floating" */ if(!H5F_addr_defined(fspace->sect_addr)) { /* Sanity check */ HDassert(fspace->sect_size > 0); /* Allocate space for the section info in file */ if(H5F_USE_TMP_SPACE(f)) { if(HADDR_UNDEF == (fspace->sect_addr = H5MF_alloc_tmp(f, fspace->sect_size))) HGOTO_ERROR(H5E_FSPACE, H5E_NOSPACE, FAIL, "file allocation failed for free space sections") } /* end if */ else { if(HADDR_UNDEF == (fspace->sect_addr = H5MF_alloc(f, H5FD_MEM_FSPACE_SINFO, dxpl_id, fspace->sect_size))) HGOTO_ERROR(H5E_FSPACE, H5E_NOSPACE, FAIL, "file allocation failed for free space sections") } /* end if */ fspace->alloc_sect_size = (size_t)fspace->sect_size; /* Mark free space header as dirty */ if(H5AC_mark_entry_dirty(fspace) < 0) HGOTO_ERROR(H5E_FSPACE, H5E_CANTMARKDIRTY, FAIL, "unable to mark free space header as dirty") } /* 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)))