summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/H5AC.c1
-rw-r--r--src/H5ACprivate.h1
-rw-r--r--src/H5Cpkg.h2
-rw-r--r--src/H5F.c87
-rw-r--r--src/H5FD.c18
-rw-r--r--src/H5FDfamily.c44
-rw-r--r--src/H5FDmulti.c2
-rw-r--r--src/H5FDpkg.h4
-rw-r--r--src/H5FDprivate.h11
-rw-r--r--src/H5FDpublic.h14
-rw-r--r--src/H5FDsec2.c42
-rw-r--r--src/H5FDspace.c142
-rw-r--r--src/H5Fdbg.c22
-rw-r--r--src/H5Fpkg.h89
-rw-r--r--src/H5Fprivate.h9
-rw-r--r--src/H5Fquery.c9
-rw-r--r--src/H5Fsuper.c889
-rw-r--r--src/H5Fsuper_cache.c854
-rw-r--r--src/H5Ftest.c2
-rw-r--r--src/H5Gent.c133
-rw-r--r--src/H5Gprivate.h7
-rw-r--r--src/H5Groot.c155
-rw-r--r--src/H5MF.c7
-rw-r--r--src/H5MFaggr.c31
-rw-r--r--src/H5MFsection.c5
-rwxr-xr-xsrc/Makefile.am2
-rw-r--r--src/Makefile.in60
27 files changed, 1529 insertions, 1113 deletions
diff --git a/src/H5AC.c b/src/H5AC.c
index d613991..9bfc32a 100644
--- a/src/H5AC.c
+++ b/src/H5AC.c
@@ -499,6 +499,7 @@ static const char * H5AC_entry_type_names[H5AC_NTYPES] =
"fixed array headers",
"fixed array data block",
"fixed array data block pages",
+ "superblock",
"test entry" /* for testing only -- not used for actual files */
};
diff --git a/src/H5ACprivate.h b/src/H5ACprivate.h
index 17ee012..99231ca 100644
--- a/src/H5ACprivate.h
+++ b/src/H5ACprivate.h
@@ -70,6 +70,7 @@ typedef enum {
H5AC_FARRAY_HDR_ID, /*fixed array header */
H5AC_FARRAY_DBLOCK_ID, /*fixed array data block */
H5AC_FARRAY_DBLK_PAGE_ID, /*fixed array data block page */
+ H5AC_SUPERBLOCK_ID, /* file superblock */
H5AC_TEST_ID, /*test entry -- not used for actual files */
H5AC_NTYPES /* Number of types, must be last */
} H5AC_type_t;
diff --git a/src/H5Cpkg.h b/src/H5Cpkg.h
index 08a903a..4bc105d 100644
--- a/src/H5Cpkg.h
+++ b/src/H5Cpkg.h
@@ -857,7 +857,7 @@
****************************************************************************/
#define H5C__H5C_T_MAGIC 0x005CAC0E
-#define H5C__MAX_NUM_TYPE_IDS 24
+#define H5C__MAX_NUM_TYPE_IDS 25
#define H5C__PREFIX_LEN 32
struct H5C_t
diff --git a/src/H5F.c b/src/H5F.c
index 1cb8cdf..85ad71d 100644
--- a/src/H5F.c
+++ b/src/H5F.c
@@ -861,23 +861,20 @@ H5F_new(H5F_file_t *shared, hid_t fcpl_id, hid_t fapl_id, H5FD_t *lf)
f->shared = shared;
} /* end if */
else {
- unsigned super_vers = HDF5_SUPERBLOCK_VERSION_DEF; /* Superblock version for file */
H5P_genplist_t *plist; /* Property list */
size_t u; /* Local index variable */
HDassert(lf != NULL);
if(NULL == (f->shared = H5FL_CALLOC(H5F_file_t)))
HGOTO_ERROR(H5E_FILE, H5E_NOSPACE, NULL, "can't allocate shared file structure")
- f->shared->base_addr = HADDR_UNDEF;
- f->shared->extension_addr = HADDR_UNDEF;
+
+ f->shared->super_addr = HADDR_UNDEF;
f->shared->sohm_addr = HADDR_UNDEF;
f->shared->sohm_vers = HDF5_SHAREDHEADER_VERSION;
for(u = 0; u < NELMTS(f->shared->fs_addr); u++)
f->shared->fs_addr[u] = HADDR_UNDEF;
- f->shared->driver_addr = HADDR_UNDEF;
f->shared->accum.loc = HADDR_UNDEF;
f->shared->lf = lf;
- f->shared->root_addr = HADDR_UNDEF;
/*
* Copy the file creation and file access property lists into the
@@ -893,10 +890,6 @@ H5F_new(H5F_file_t *shared, hid_t fcpl_id, hid_t fapl_id, H5FD_t *lf)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get byte number for address")
if(H5P_get(plist, H5F_CRT_OBJ_BYTE_NUM_NAME, &f->shared->sizeof_size) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get byte number for object size")
- if(H5P_get(plist, H5F_CRT_SYM_LEAF_NAME, &f->shared->sym_leaf_k) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get byte number for object size")
- if(H5P_get(plist, H5F_CRT_BTREE_RANK_NAME, &f->shared->btree_k[0]) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "unable to get rank for btree internal nodes")
if(H5P_get(plist, H5F_CRT_SHMSG_NINDEXES_NAME, &f->shared->sohm_nindexes)<0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get number of SOHM indexes")
HDassert(f->shared->sohm_nindexes < 255);
@@ -951,29 +944,6 @@ H5F_new(H5F_file_t *shared, hid_t fcpl_id, hid_t fapl_id, H5FD_t *lf)
*/
f->shared->use_tmp_space = !(IS_H5FD_MPI(f));
- /* Bump superblock version if we are to use the latest version of the format */
- if(f->shared->latest_format)
- super_vers = HDF5_SUPERBLOCK_VERSION_LATEST;
- /* Bump superblock version to create superblock extension for SOHM info */
- else if(f->shared->sohm_nindexes > 0)
- super_vers = HDF5_SUPERBLOCK_VERSION_2;
- /* Check for non-default indexed storage B-tree internal 'K' value
- * and set the version # of the superblock to 1 if it is a non-default
- * value.
- */
- else if(f->shared->btree_k[H5B_CHUNK_ID] != HDF5_BTREE_CHUNK_IK_DEF)
- super_vers = HDF5_SUPERBLOCK_VERSION_1;
-
- /* If a newer superblock version is required, set it here */
- if(super_vers != HDF5_SUPERBLOCK_VERSION_DEF) {
- H5P_genplist_t *c_plist; /* Property list */
-
- if(NULL == (c_plist = (H5P_genplist_t *)H5I_object(f->shared->fcpl_id)))
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not property list")
- 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")
- } /* end if */
-
/*
* Create a metadata cache with the specified number of elements.
* The cache might be created with a different number of elements and
@@ -1050,8 +1020,20 @@ H5F_dest(H5F_t *f, hid_t dxpl_id)
H5AC_stats(f);
#endif /* H5AC_DUMP_STATS_ON_CLOSE */
- /* Flush and invalidate all caches */
- if(H5F_flush(f, dxpl_id, H5F_SCOPE_LOCAL, H5F_FLUSH_INVALIDATE | H5F_FLUSH_CLOSING) < 0)
+ /* Flush all caches and indicate we are closing the file */
+ if(H5F_flush(f, dxpl_id, H5F_SCOPE_LOCAL, H5F_FLUSH_CLOSING) < 0)
+ /* Push error, but keep going*/
+ HDONE_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "unable to flush cache")
+
+ /* Unpin the superblock, since we're about to destroy the cache */
+ if(H5AC_unpin_entry(f, f->shared->sblock) < 0)
+ /* Push error, but keep going*/
+ HDONE_ERROR(H5E_FSPACE, H5E_CANTUNPIN, FAIL, "unable to unpin superblock")
+ f->shared->sblock = NULL;
+
+ /* Flush all caches and indicate all cached objects should be invalidated */
+ /* (The caches should already be clean and we should just be invalidating objects) */
+ if(H5F_flush(f, dxpl_id, H5F_SCOPE_LOCAL, H5F_FLUSH_INVALIDATE) < 0)
/* Push error, but keep going*/
HDONE_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "unable to flush cache")
} /* end if */
@@ -1110,9 +1092,6 @@ H5F_dest(H5F_t *f, hid_t dxpl_id)
f->shared->mtab.child = (H5F_mount_t *)H5MM_xfree(f->shared->mtab.child);
f->shared->mtab.nalloc = 0;
- /* Free root group symbol table entry, if any */
- f->shared->root_ent = (H5G_entry_t *)H5MM_xfree(f->shared->root_ent);
-
/* Destroy shared file struct */
f->shared = (H5F_file_t *)H5FL_FREE(H5F_file_t, f->shared);
@@ -1293,22 +1272,6 @@ H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, hid_t d
file->intent = flags;
file->name = H5MM_xstrdup(name);
- /* Get the file access property list, for future queries */
- if(NULL == (a_plist = (H5P_genplist_t *)H5I_object(fapl_id)))
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not file access property list")
-
- /* This step is for h5repart tool only. If user wants to change file driver from
- * family to sec2 while using h5repart, this private property should be set so that
- * in the later step, the library can ignore the family driver information saved
- * in the superblock.
- */
- if(H5P_exist_plist(a_plist, H5F_ACS_FAMILY_TO_SEC2_NAME) > 0) {
- if(H5P_get(a_plist, H5F_ACS_FAMILY_TO_SEC2_NAME, &shared->fam_to_sec2) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get property of changing family to sec2")
- } /* end if */
- else
- shared->fam_to_sec2 = FALSE;
-
/*
* Read or write the file superblock, depending on whether the file is
* empty or not.
@@ -1330,13 +1293,6 @@ H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, hid_t d
*/
if(H5G_mkroot(file, dxpl_id, TRUE) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "unable to create/open root group")
-
- /* Write the superblock to the file */
- /* (This must be after the root group is created, since the root
- * group's symbol table entry is part of the superblock)
- */
- if(H5F_super_write(file, dxpl_id) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "unable to write file superblock")
} else if (1 == shared->nrefs) {
/* Read the superblock if it hasn't been read before. */
if(H5F_super_read(file, dxpl_id) < 0)
@@ -1347,6 +1303,10 @@ H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, hid_t d
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to read root group")
} /* end if */
+ /* Get the file access property list, for future queries */
+ if(NULL == (a_plist = (H5P_genplist_t *)H5I_object(fapl_id)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not file access property list")
+
/*
* Decide the file close degree. If it's the first time to open the
* file, set the degree to access property list value; if it's the
@@ -1722,13 +1682,6 @@ H5F_flush(H5F_t *f, hid_t dxpl_id, H5F_scope_t scope, unsigned flags)
if(H5FD_truncate(f->shared->lf, dxpl_id, (unsigned)((flags & H5F_FLUSH_CLOSING) > 0)) < 0)
HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "low level truncate failed")
- /* Write the superblock to disk */
- /* (needs to happen before metadata flush (H5AC_flush), since the information
- * in the superblock extension may be updated - 2008/10/14, QAK)
- */
- if(H5F_super_write(f, dxpl_id) < 0)
- HGOTO_ERROR(H5E_CACHE, H5E_WRITEERROR, FAIL, "unable to write superblock to file")
-
/* Flush (and invalidate, if requested) the entire metadata cache */
H5AC_flags = 0;
if((flags & H5F_FLUSH_INVALIDATE) != 0 )
diff --git a/src/H5FD.c b/src/H5FD.c
index aaa866b..967017f 100644
--- a/src/H5FD.c
+++ b/src/H5FD.c
@@ -555,7 +555,6 @@ done:
* Purpose: Decodes the driver information block.
*
* Return: Success: Non-negative
- *
* Failure: Negative
*
* Programmer: Robb Matzke
@@ -566,18 +565,17 @@ done:
herr_t
H5FD_sb_decode(H5FD_t *file, const char *name, const uint8_t *buf)
{
- herr_t ret_value=SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5FD_sb_decode, FAIL)
- assert(file && file->cls);
- if(file->cls->sb_decode &&
- (file->cls->sb_decode)(file, name, buf) < 0)
+ HDassert(file && file->cls);
+ if(file->cls->sb_decode && (file->cls->sb_decode)(file, name, buf) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "driver sb_decode request failed")
done:
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5FD_sb_decode() */
/*-------------------------------------------------------------------------
@@ -1407,10 +1405,6 @@ done:
* Programmer: Robb Matzke
* Tuesday, July 27, 1999
*
- * Modifications:
- * Vailin Choi, 29th July 2008
- * Two more parameters were added to H5FD_alloc() for handling alignment
- *
*-------------------------------------------------------------------------
*/
haddr_t
@@ -1435,7 +1429,7 @@ H5FDalloc(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, hsize_t size)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, HADDR_UNDEF, "not a data transfer property list")
/* Do the real work */
- if(HADDR_UNDEF == (ret_value = H5FD_alloc(file, dxpl_id, type, size, NULL, NULL)))
+ if(HADDR_UNDEF == (ret_value = H5FD_alloc_real(file, dxpl_id, type, size, NULL, NULL)))
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, HADDR_UNDEF, "unable to allocate file memory")
/* (Note compensating for base address subtraction in internal routine) */
@@ -1488,7 +1482,7 @@ H5FDfree(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, hsize_t siz
/* Do the real work */
/* (Note compensating for base address addition in internal routine) */
- if(H5FD_free(file, dxpl_id, type, addr - file->base_addr, size) < 0)
+ if(H5FD_free_real(file, dxpl_id, type, addr - file->base_addr, size) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTFREE, FAIL, "file deallocation request failed")
done:
diff --git a/src/H5FDfamily.c b/src/H5FDfamily.c
index e259a4e..9817270 100644
--- a/src/H5FDfamily.c
+++ b/src/H5FDfamily.c
@@ -61,14 +61,19 @@ typedef struct H5FD_family_t {
hid_t memb_fapl_id; /*file access property list for members */
hsize_t memb_size; /*actual size of each member file */
hsize_t pmem_size; /*member size passed in from property */
- hsize_t mem_newsize; /*new member size passed in as private
- *property. It's used only by h5repart */
unsigned nmembs; /*number of family members */
unsigned amembs; /*number of member slots allocated */
H5FD_t **memb; /*dynamic array of member pointers */
haddr_t eoa; /*end of allocated addresses */
char *name; /*name generator printf format */
unsigned flags; /*flags for opening additional members */
+
+ /* Information from properties set by 'h5repart' tool */
+ hsize_t mem_newsize; /*new member size passed in as private
+ * property. It's used only by h5repart */
+ hbool_t repart_members; /* Whether to mark the superblock dirty
+ * when it is loaded, so that the family
+ * member sizes can be re-encoded */
} H5FD_family_t;
/* Driver-specific file access properties */
@@ -741,9 +746,7 @@ H5FD_family_open(const char *name, unsigned flags, hid_t fapl_id,
H5FD_t *ret_value=NULL;
char memb_name[4096], temp[4096];
hsize_t eof=HADDR_UNDEF;
- hsize_t fam_newsize = 0;
unsigned t_flags = flags & ~H5F_ACC_CREAT;
- H5P_genplist_t *plist; /* Property list pointer */
FUNC_ENTER_NOAPI(H5FD_family_open, NULL)
@@ -765,6 +768,7 @@ H5FD_family_open(const char *name, unsigned flags, hid_t fapl_id,
file->mem_newsize = 0; /*New member size used by h5repart only */
} /* end if */
else {
+ H5P_genplist_t *plist; /* Property list pointer */
H5FD_family_fapl_t *fa;
if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id)))
@@ -772,11 +776,19 @@ H5FD_family_open(const char *name, unsigned flags, hid_t fapl_id,
fa = (H5FD_family_fapl_t *)H5P_get_driver_info(plist);
HDassert(fa);
- /* New family file size. It's used by h5repart only. */
- if(H5P_exist_plist(plist, H5F_ACS_FAMILY_NEWSIZE_NAME) > 0)
+ /* Check for new family file size. It's used by h5repart only. */
+ if(H5P_exist_plist(plist, H5F_ACS_FAMILY_NEWSIZE_NAME) > 0) {
+ hsize_t fam_newsize = 0; /* New member size, when repartitioning */
+
+ /* Get the new family file size */
if(H5P_get(plist, H5F_ACS_FAMILY_NEWSIZE_NAME, &fam_newsize) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get new family member size")
+ /* Store information for later */
+ file->mem_newsize = fam_newsize; /* New member size passed in through property */
+ file->repart_members = TRUE;
+ } /* end if */
+
if(fa->memb_fapl_id==H5P_FILE_ACCESS_DEFAULT) {
if(H5I_inc_ref(fa->memb_fapl_id, FALSE)<0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINC, NULL, "unable to increment ref count on VFL driver")
@@ -789,7 +801,6 @@ H5FD_family_open(const char *name, unsigned flags, hid_t fapl_id,
} /* end else */
file->memb_size = fa->memb_size; /* Actual member size to be updated later */
file->pmem_size = fa->memb_size; /* Member size passed in through property */
- file->mem_newsize = fam_newsize; /* New member size passed in through property */
} /* end else */
file->name = H5MM_strdup(name);
file->flags = flags;
@@ -797,8 +808,7 @@ H5FD_family_open(const char *name, unsigned flags, hid_t fapl_id,
/* Check that names are unique */
sprintf(memb_name, name, 0);
sprintf(temp, name, 1);
-
- if (!strcmp(memb_name, temp))
+ if(!HDstrcmp(memb_name, temp))
HGOTO_ERROR(H5E_FILE, H5E_FILEEXISTS, NULL, "file names not unique")
/* Open all the family members */
@@ -968,23 +978,20 @@ done:
* (listed in H5FDpublic.h)
*
* Return: Success: non-negative
- *
* Failure: negative
*
* Programmer: Quincey Koziol
* Friday, August 25, 2000
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
/* ARGSUSED */
static herr_t
-H5FD_family_query(const H5FD_t UNUSED * _f, unsigned long *flags /* out */)
+H5FD_family_query(const H5FD_t * _file, unsigned long *flags /* out */)
{
- herr_t ret_value = SUCCEED;
+ const H5FD_family_t *file = (const H5FD_family_t*)_file; /* Family VFD info */
- FUNC_ENTER_NOAPI(H5FD_family_query, FAIL)
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FD_family_query)
/* Set the VFL feature flags that this driver supports */
if(flags) {
@@ -993,10 +1000,13 @@ H5FD_family_query(const H5FD_t UNUSED * _f, unsigned long *flags /* out */)
*flags |= H5FD_FEAT_ACCUMULATE_METADATA; /* OK to accumulate metadata for faster writes. */
*flags |= H5FD_FEAT_DATA_SIEVE; /* OK to perform data sieving for faster raw data reads & writes */
*flags |= H5FD_FEAT_AGGREGATE_SMALLDATA; /* OK to aggregate "small" raw data allocations */
+
+ /* Check for flags that are set by h5repart */
+ if(file->repart_members)
+ *flags |= H5FD_FEAT_DIRTY_SBLK_LOAD; /* Mark the superblock dirty when it is loaded (so the family member sizes are rewritten) */
} /* end if */
-done:
- FUNC_LEAVE_NOAPI(ret_value)
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5FD_family_query() */
diff --git a/src/H5FDmulti.c b/src/H5FDmulti.c
index e0421a7..328b530 100644
--- a/src/H5FDmulti.c
+++ b/src/H5FDmulti.c
@@ -837,8 +837,6 @@ H5FD_multi_sb_encode(H5FD_t *_file, char *name/*out*/,
* Programmer: Robb Matzke
* Monday, August 16, 1999
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
diff --git a/src/H5FDpkg.h b/src/H5FDpkg.h
index 9401b52..7c0988e 100644
--- a/src/H5FDpkg.h
+++ b/src/H5FDpkg.h
@@ -53,6 +53,10 @@
/* Package Private Prototypes */
/******************************/
H5_DLL herr_t H5FD_init(void);
+H5_DLL haddr_t H5FD_alloc_real(H5FD_t *file, hid_t dxpl_id, H5FD_mem_t type,
+ hsize_t size, haddr_t *align_addr, hsize_t *align_size);
+H5_DLL herr_t H5FD_free_real(H5FD_t *file, hid_t dxpl_id, H5FD_mem_t type,
+ haddr_t addr, hsize_t size);
/* Testing routines */
diff --git a/src/H5FDprivate.h b/src/H5FDprivate.h
index 25b2f24..6b2e4fe 100644
--- a/src/H5FDprivate.h
+++ b/src/H5FDprivate.h
@@ -35,6 +35,7 @@
/* Forward declarations for prototype arguments */
struct H5P_genplist_t;
+struct H5F_t;
/* Prototypes */
H5_DLL int H5FD_term_interface(void);
@@ -55,10 +56,12 @@ H5_DLL H5FD_t *H5FD_open(const char *name, unsigned flags, hid_t fapl_id,
H5_DLL herr_t H5FD_close(H5FD_t *file);
H5_DLL int H5FD_cmp(const H5FD_t *f1, const H5FD_t *f2);
H5_DLL int H5FD_query(const H5FD_t *f, unsigned long *flags/*out*/);
-H5_DLL haddr_t H5FD_alloc(H5FD_t *file, hid_t dxpl_id, H5FD_mem_t type, hsize_t size, haddr_t *align_addr, hsize_t *align_size);
-H5_DLL herr_t H5FD_free(H5FD_t *file, hid_t dxpl_id, H5FD_mem_t type, haddr_t addr, hsize_t size);
-H5_DLL htri_t H5FD_try_extend(H5FD_t *file, H5FD_mem_t type, haddr_t blk_end,
- hsize_t extra_requested);
+H5_DLL haddr_t H5FD_alloc(H5FD_t *file, hid_t dxpl_id, H5FD_mem_t type, struct H5F_t *f,
+ hsize_t size, haddr_t *align_addr, hsize_t *align_size);
+H5_DLL herr_t H5FD_free(H5FD_t *file, hid_t dxpl_id, H5FD_mem_t type, struct H5F_t *f,
+ haddr_t addr, hsize_t size);
+H5_DLL htri_t H5FD_try_extend(H5FD_t *file, H5FD_mem_t type, struct H5F_t *f,
+ haddr_t blk_end, hsize_t extra_requested);
H5_DLL haddr_t H5FD_get_eoa(const H5FD_t *file, H5FD_mem_t type);
H5_DLL herr_t H5FD_set_eoa(H5FD_t *file, H5FD_mem_t type, haddr_t addr);
H5_DLL haddr_t H5FD_get_eof(const H5FD_t *file);
diff --git a/src/H5FDpublic.h b/src/H5FDpublic.h
index fde8556..ed24506 100644
--- a/src/H5FDpublic.h
+++ b/src/H5FDpublic.h
@@ -190,6 +190,20 @@ typedef enum H5F_mem_t H5FD_mem_t;
* and then sub-allocate "small" raw data requests from that larger block.
*/
#define H5FD_FEAT_AGGREGATE_SMALLDATA 0x00000010
+ /*
+ * Defining the H5FD_FEAT_IGNORE_DRVRINFO for a VFL driver means that
+ * the library will ignore the driver info that is encoded in the file
+ * for the VFL driver. (This will cause the driver info to be eliminated
+ * from the file when it is flushed/closed, if the file is opened R/W).
+ */
+#define H5FD_FEAT_IGNORE_DRVRINFO 0x00000020
+ /*
+ * Defining the H5FD_FEAT_DIRTY_SBLK_LOAD for a VFL driver means that
+ * the library will mark the superblock dirty when the file is opened
+ * R/W. This will cause the driver info to be re-encoded when the file
+ * is flushed/closed.
+ */
+#define H5FD_FEAT_DIRTY_SBLK_LOAD 0x00000040
/* Forward declaration */
diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c
index 35ade20..0b4632d 100644
--- a/src/H5FDsec2.c
+++ b/src/H5FDsec2.c
@@ -90,6 +90,10 @@ typedef struct H5FD_sec2_t {
DWORD fileindexlo;
DWORD fileindexhi;
#endif
+
+ /* Information from properties set by 'h5repart' tool */
+ hbool_t fam_to_sec2; /* Whether to eliminate the family driver info
+ * and convert this file to a single file */
} H5FD_sec2_t;
@@ -325,8 +329,7 @@ done:
*/
/* ARGSUSED */
static H5FD_t *
-H5FD_sec2_open(const char *name, unsigned flags, hid_t UNUSED fapl_id,
- haddr_t maxaddr)
+H5FD_sec2_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
{
int o_flags;
int fd=(-1);
@@ -388,8 +391,26 @@ H5FD_sec2_open(const char *name, unsigned flags, hid_t UNUSED fapl_id,
#endif
+ /* Check for non-default FAPL */
+ if(H5P_FILE_ACCESS_DEFAULT != fapl_id) {
+ H5P_genplist_t *plist; /* Property list pointer */
+
+ /* Get the FAPL */
+ if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list")
+
+ /* This step is for h5repart tool only. If user wants to change file driver from
+ * family to sec2 while using h5repart, this private property should be set so that
+ * in the later step, the library can ignore the family driver information saved
+ * in the superblock.
+ */
+ if(H5P_exist_plist(plist, H5F_ACS_FAMILY_TO_SEC2_NAME) > 0)
+ if(H5P_get(plist, H5F_ACS_FAMILY_TO_SEC2_NAME, &file->fam_to_sec2) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get property of changing family to sec2")
+ } /* end if */
+
/* Set return value */
- ret_value=(H5FD_t*)file;
+ ret_value = (H5FD_t*)file;
done:
if(ret_value==NULL) {
@@ -398,7 +419,7 @@ done:
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5FD_sec2_open() */
/*-------------------------------------------------------------------------
@@ -516,11 +537,11 @@ done:
*/
/* ARGSUSED */
static herr_t
-H5FD_sec2_query(const H5FD_t UNUSED * _f, unsigned long *flags /* out */)
+H5FD_sec2_query(const H5FD_t *_file, unsigned long *flags /* out */)
{
- herr_t ret_value = SUCCEED; /* Return value */
+ const H5FD_sec2_t *file = (const H5FD_sec2_t*)_file; /* sec2 VFD info */
- FUNC_ENTER_NOAPI(H5FD_sec2_query, FAIL)
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FD_sec2_query)
/* Set the VFL feature flags that this driver supports */
if(flags) {
@@ -529,10 +550,13 @@ H5FD_sec2_query(const H5FD_t UNUSED * _f, unsigned long *flags /* out */)
*flags |= H5FD_FEAT_ACCUMULATE_METADATA; /* OK to accumulate metadata for faster writes */
*flags |= H5FD_FEAT_DATA_SIEVE; /* OK to perform data sieving for faster raw data reads & writes */
*flags |= H5FD_FEAT_AGGREGATE_SMALLDATA; /* OK to aggregate "small" raw data allocations */
+
+ /* Check for flags that are set by h5repart */
+ if(file->fam_to_sec2)
+ *flags |= H5FD_FEAT_IGNORE_DRVRINFO; /* Ignore the driver info when file is opened (which eliminates it) */
} /* end if */
-done:
- FUNC_LEAVE_NOAPI(ret_value)
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5FD_sec2_query() */
diff --git a/src/H5FDspace.c b/src/H5FDspace.c
index 0fadc1e..5526b03 100644
--- a/src/H5FDspace.c
+++ b/src/H5FDspace.c
@@ -42,7 +42,6 @@
#include "H5Fprivate.h" /* File access */
#include "H5FDpkg.h" /* File Drivers */
#include "H5FDmulti.h" /* Usage-partitioned file family */
-#include "H5MMprivate.h" /* Memory management */
/****************/
@@ -122,10 +121,6 @@ H5FD_space_init_interface(void)
* Programmer: Bill Wendling
* Wednesday, 04. December, 2002
*
- * Modifications:
- * Vailin Choi, 29th July 2008
- * Add 2 more parameters for handling alignment: address and size of the fragment
- *
*-------------------------------------------------------------------------
*/
static haddr_t
@@ -180,9 +175,9 @@ done:
/*-------------------------------------------------------------------------
- * Function: H5FD_alloc
+ * Function: H5FD_alloc_real
*
- * Purpose: Private version of H5FDalloc().
+ * Purpose: Allocate space in the file with the VFD
*
* Return: Success: The format address of the new file memory.
* Failure: The undefined address HADDR_UNDEF
@@ -190,18 +185,14 @@ done:
* Programmer: Robb Matzke
* Wednesday, August 4, 1999
*
- * Modification:
- * Vailin Choi, 29th July 2008
- * Add two more parameters () for handling alignment: address & size of the fragment
- *
*-------------------------------------------------------------------------
*/
haddr_t
-H5FD_alloc(H5FD_t *file, hid_t dxpl_id, H5FD_mem_t type, hsize_t size, haddr_t *frag_addr, hsize_t *frag_size)
+H5FD_alloc_real(H5FD_t *file, hid_t dxpl_id, H5FD_mem_t type, hsize_t size, haddr_t *frag_addr, hsize_t *frag_size)
{
- haddr_t ret_value = HADDR_UNDEF;
+ haddr_t ret_value; /* Return value */
- FUNC_ENTER_NOAPI(H5FD_alloc, HADDR_UNDEF)
+ FUNC_ENTER_NOAPI(H5FD_alloc_real, HADDR_UNDEF)
#ifdef H5FD_ALLOC_DEBUG
HDfprintf(stderr, "%s: type = %u, size = %Hu\n", FUNC, (unsigned)type, size);
#endif /* H5FD_ALLOC_DEBUG */
@@ -230,13 +221,59 @@ done:
HDfprintf(stderr, "%s: ret_value = %a\n", FUNC, ret_value);
#endif /* H5FD_ALLOC_DEBUG */
FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5FD_alloc_real() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD_alloc
+ *
+ * Purpose: Wrapper for H5FD_alloc, to make certain EOA changes are
+ * reflected in superblock.
+ *
+ * Note: When the metadata cache routines are updated to allow
+ * marking an entry dirty without a H5F_t*, this routine should
+ * be changed to take a H5F_super_t* directly.
+ *
+ * Return: Success: The format address of the new file memory.
+ * Failure: The undefined address HADDR_UNDEF
+ *
+ * Programmer: Quincey Koziol
+ * Friday, August 14, 2009
+ *
+ *-------------------------------------------------------------------------
+ */
+haddr_t
+H5FD_alloc(H5FD_t *file, hid_t dxpl_id, H5FD_mem_t type, H5F_t *f, hsize_t size,
+ haddr_t *frag_addr, hsize_t *frag_size)
+{
+ haddr_t ret_value; /* Return value */
+
+ FUNC_ENTER_NOAPI(H5FD_alloc, HADDR_UNDEF)
+
+ /* check args */
+ HDassert(file);
+ HDassert(file->cls);
+ HDassert(type >= H5FD_MEM_DEFAULT && type < H5FD_MEM_NTYPES);
+ HDassert(size > 0);
+
+ /* Call the real 'alloc' routine */
+ ret_value = H5FD_alloc_real(file, dxpl_id, type, size, frag_addr, frag_size);
+ if(!H5F_addr_defined(ret_value))
+ HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, HADDR_UNDEF, "real 'alloc' request failed")
+
+ /* Mark superblock dirty in cache, so change to EOA will get encoded */
+ if(H5F_super_dirty(f) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTMARKDIRTY, HADDR_UNDEF, "unable to mark superblock as dirty")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_alloc() */
/*-------------------------------------------------------------------------
- * Function: H5FD_free
+ * Function: H5FD_free_real
*
- * Purpose: Private version of H5FDfree()
+ * Purpose: Release space back to the VFD
*
* Return: Success: Non-negative
* Failure: Negative
@@ -247,11 +284,11 @@ HDfprintf(stderr, "%s: ret_value = %a\n", FUNC, ret_value);
*-------------------------------------------------------------------------
*/
herr_t
-H5FD_free(H5FD_t *file, hid_t dxpl_id, H5FD_mem_t type, haddr_t addr, hsize_t size)
+H5FD_free_real(H5FD_t *file, hid_t dxpl_id, H5FD_mem_t type, haddr_t addr, hsize_t size)
{
herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI(H5FD_free, FAIL)
+ FUNC_ENTER_NOAPI_NOINIT(H5FD_free_real)
/* Check args */
HDassert(file);
@@ -265,14 +302,14 @@ HDfprintf(stderr, "%s: type = %u, addr = %a, size = %Hu\n", FUNC, (unsigned)type
/* Sanity checking */
if(!H5F_addr_defined(addr))
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid file offset")
+ HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "invalid file offset")
/* Convert address to absolute file offset */
addr += file->base_addr;
/* More sanity checking */
if(addr > file->maxaddr || H5F_addr_overflow(addr, size) || (addr + size) > file->maxaddr)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid file free space region to free")
+ HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "invalid file free space region to free")
/* Check for file driver 'free' callback and call it if available */
if(file->cls->free) {
@@ -309,6 +346,51 @@ HDfprintf(stderr, "%s: LEAKED MEMORY!!! type = %u, addr = %a, size = %Hu\n", FUN
done:
FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5FD_free_real() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD_free
+ *
+ * Purpose: Wrapper for H5FD_free_real, to make certain EOA changes are
+ * reflected in superblock.
+ *
+ * Note: When the metadata cache routines are updated to allow
+ * marking an entry dirty without a H5F_t*, this routine should
+ * be changed to take a H5F_super_t* directly.
+ *
+ * Return: Success: Non-negative
+ * Failure: Negative
+ *
+ * Programmer: Quincey Koziol
+ * Friday, August 14, 2009
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5FD_free(H5FD_t *file, hid_t dxpl_id, H5FD_mem_t type, H5F_t *f, haddr_t addr,
+ hsize_t size)
+{
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI(H5FD_free, FAIL)
+
+ /* Check args */
+ HDassert(file);
+ HDassert(file->cls);
+ HDassert(type >= H5FD_MEM_DEFAULT && type < H5FD_MEM_NTYPES);
+ HDassert(size > 0);
+
+ /* Call the real 'free' routine */
+ if(H5FD_free_real(file, dxpl_id, type, addr, size) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTFREE, FAIL, "real 'free' request failed")
+
+ /* Mark superblock dirty in cache, so change to EOA will get encoded */
+ if(H5F_super_dirty(f) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTMARKDIRTY, FAIL, "unable to mark superblock as dirty")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_free() */
@@ -317,6 +399,10 @@ done:
*
* Purpose: Extend a block at the end of the file, if possible.
*
+ * Note: When the metadata cache routines are updated to allow
+ * marking an entry dirty without a H5F_t*, this routine should
+ * be changed to take a H5F_super_t* directly.
+ *
* Return: Success: TRUE(1) - Block was extended
* FALSE(0) - Block could not be extended
* Failure: FAIL
@@ -324,14 +410,11 @@ done:
* Programmer: Quincey Koziol
* Thursday, 17. January, 2008
*
- * Modification:
- * Vailin Choi, 29th July 2008
- * Two more parameters were added to FD_extend() for handling alignment
- *
*-------------------------------------------------------------------------
*/
htri_t
-H5FD_try_extend(H5FD_t *file, H5FD_mem_t type, haddr_t blk_end, hsize_t extra_requested)
+H5FD_try_extend(H5FD_t *file, H5FD_mem_t type, H5F_t *f, haddr_t blk_end,
+ hsize_t extra_requested)
{
haddr_t eoa; /* End of allocated space in file */
htri_t ret_value = FALSE; /* Return value */
@@ -343,10 +426,11 @@ H5FD_try_extend(H5FD_t *file, H5FD_mem_t type, haddr_t blk_end, hsize_t extra_re
HDassert(file->cls);
HDassert(type >= H5FD_MEM_DEFAULT && type < H5FD_MEM_NTYPES);
HDassert(extra_requested > 0);
+ HDassert(f);
/* Retrieve the end of the address space */
if(HADDR_UNDEF == (eoa = file->cls->get_eoa(file, type)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGET, FAIL, "driver get_eoa request failed")
+ HGOTO_ERROR(H5E_VFL, H5E_CANTGET, FAIL, "driver get_eoa request failed")
/* Adjust block end by base address of the file, to create absolute address */
blk_end += file->base_addr;
@@ -355,7 +439,11 @@ H5FD_try_extend(H5FD_t *file, H5FD_mem_t type, haddr_t blk_end, hsize_t extra_re
if(H5F_addr_eq(blk_end, eoa)) {
/* Extend the object by extending the underlying file */
if(HADDR_UNDEF == H5FD_extend(file, type, FALSE, extra_requested, NULL, NULL))
- HGOTO_ERROR(H5E_RESOURCE, H5E_CANTEXTEND, FAIL, "driver extend request failed")
+ HGOTO_ERROR(H5E_VFL, H5E_CANTEXTEND, FAIL, "driver extend request failed")
+
+ /* Mark superblock dirty in cache, so change to EOA will get encoded */
+ if(H5F_super_dirty(f) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTMARKDIRTY, FAIL, "unable to mark superblock as dirty")
/* Indicate success */
HGOTO_DONE(TRUE)
diff --git a/src/H5Fdbg.c b/src/H5Fdbg.c
index b570516..5f14357 100644
--- a/src/H5Fdbg.c
+++ b/src/H5Fdbg.c
@@ -51,7 +51,6 @@ 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 */
- unsigned super_vers; /* Superblock version # */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5F_debug, FAIL)
@@ -61,6 +60,7 @@ H5F_debug(H5F_t *f, FILE *stream, int indent, int fwidth)
HDassert(stream);
HDassert(indent >= 0);
HDassert(fwidth >= 0);
+ HDassert(f->shared->super_addr != HADDR_UNDEF);
/* Get property list */
if(NULL == (plist = (H5P_genplist_t *)H5I_object(f->shared->fcpl_id)))
@@ -69,8 +69,6 @@ H5F_debug(H5F_t *f, FILE *stream, int indent, int fwidth)
/* 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")
- if(H5P_get(plist, H5F_CRT_SUPER_VERS_NAME, &super_vers) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get superblock version")
/* debug */
HDfprintf(stream, "%*sFile Super Block...\n", indent, "");
@@ -82,12 +80,12 @@ H5F_debug(H5F_t *f, FILE *stream, int indent, int fwidth)
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->base_addr);
+ "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:", super_vers);
+ "Superblock version number:", f->shared->sblock->super_vers);
/* Hard-wired versions */
HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
@@ -102,13 +100,13 @@ H5F_debug(H5F_t *f, FILE *stream, int indent, int fwidth)
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);
+ "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->btree_k[H5B_SNODE_ID]);
+ "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->status_flags));
+ "File status flags:", (unsigned)(f->shared->sblock->status_flags));
HDfprintf(stream, "%*s%-*s %a (rel)\n", indent, "", fwidth,
- "Superblock extension address:", f->shared->extension_addr);
+ "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,
@@ -117,14 +115,14 @@ H5F_debug(H5F_t *f, FILE *stream, int indent, int 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->driver_addr);
+ "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->root_ent) /* Use real root group symbol table entry */
- H5G_ent_debug(f, f->shared->root_ent, stream, indent + 3,
+ 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 */
diff --git a/src/H5Fpkg.h b/src/H5Fpkg.h
index c7ac1fa..84bab35 100644
--- a/src/H5Fpkg.h
+++ b/src/H5Fpkg.h
@@ -71,6 +71,58 @@
/* Macro to abstract checking whether file is using a free space manager */
#define H5F_HAVE_FREE_SPACE_MANAGER(F) TRUE /* Currently always have a free space manager */
+/* Macros for encoding/decoding superblock */
+#define H5F_MAX_DRVINFOBLOCK_SIZE 1024 /* Maximum size of superblock driver info buffer */
+#define H5F_DRVINFOBLOCK_HDR_SIZE 16 /* Size of superblock driver info header */
+
+/* Superblock sizes for various versions */
+#define H5F_SIZEOF_CHKSUM 4 /* Checksum size in the file */
+
+/* Fixed-size portion at the beginning of all superblocks */
+#define H5F_SUPERBLOCK_FIXED_SIZE ( H5F_SIGNATURE_LEN \
+ + 1) /* superblock version */
+
+/* Macros for computing variable-size superblock size */
+#define H5F_SUPERBLOCK_VARLEN_SIZE_COMMON \
+ (2 /* freespace, and root group versions */ \
+ + 1 /* reserved */ \
+ + 3 /* shared header vers, size of address, size of lengths */ \
+ + 1 /* reserved */ \
+ + 4 /* group leaf k, group internal k */ \
+ + 4) /* consistency flags */
+#define H5F_SUPERBLOCK_VARLEN_SIZE_V0(f) \
+ ( H5F_SUPERBLOCK_VARLEN_SIZE_COMMON /* Common variable-length info */ \
+ + H5F_SIZEOF_ADDR(f) /* base address */ \
+ + H5F_SIZEOF_ADDR(f) /* <unused> */ \
+ + H5F_SIZEOF_ADDR(f) /* EOF address */ \
+ + H5F_SIZEOF_ADDR(f) /* driver block address */ \
+ + H5G_SIZEOF_ENTRY(f)) /* root group ptr */
+#define H5F_SUPERBLOCK_VARLEN_SIZE_V1(f) \
+ ( H5F_SUPERBLOCK_VARLEN_SIZE_COMMON /* Common variable-length info */ \
+ + 2 /* indexed B-tree internal k */ \
+ + 2 /* reserved */ \
+ + H5F_SIZEOF_ADDR(f) /* base address */ \
+ + H5F_SIZEOF_ADDR(f) /* <unused> */ \
+ + H5F_SIZEOF_ADDR(f) /* EOF address */ \
+ + H5F_SIZEOF_ADDR(f) /* driver block address */ \
+ + H5G_SIZEOF_ENTRY(f)) /* root group ptr */
+#define H5F_SUPERBLOCK_VARLEN_SIZE_V2(f) \
+ ( 2 /* size of address, size of lengths */ \
+ + 1 /* consistency flags */ \
+ + H5F_SIZEOF_ADDR(f) /* base address */ \
+ + H5F_SIZEOF_ADDR(f) /* superblock extension address */ \
+ + H5F_SIZEOF_ADDR(f) /* EOF address */ \
+ + H5F_SIZEOF_ADDR(f) /* root group object header address */ \
+ + H5F_SIZEOF_CHKSUM) /* superblock checksum (keep this last) */
+#define H5F_SUPERBLOCK_VARLEN_SIZE(v, f) ( \
+ (v == 0 ? H5F_SUPERBLOCK_VARLEN_SIZE_V0(f) : 0) \
+ + (v == 1 ? H5F_SUPERBLOCK_VARLEN_SIZE_V1(f) : 0) \
+ + (v == 2 ? H5F_SUPERBLOCK_VARLEN_SIZE_V2(f) : 0))
+
+/* Total size of superblock, depends on superblock version */
+#define H5F_SUPERBLOCK_SIZE(v, f) ( H5F_SUPERBLOCK_FIXED_SIZE \
+ + H5F_SUPERBLOCK_VARLEN_SIZE(v, f))
+
/* Structure for metadata & "small [raw] data" block aggregation fields */
struct H5F_blk_aggr_t {
@@ -113,6 +165,23 @@ typedef struct H5F_mtab_t {
H5F_mount_t *child; /* An array of mount records */
} H5F_mtab_t;
+/* Structure specifically to store superblock. This was originally
+ * maintained entirely within H5F_file_t, but is now extracted
+ * here because the superblock is now handled by the cache */
+typedef struct H5F_super_t {
+ H5AC_info_t cache_info; /* Cache entry information structure */
+ unsigned super_vers; /* Superblock version */
+ uint8_t status_flags; /* File status flags */
+ unsigned sym_leaf_k; /* Size of leaves in symbol tables */
+ unsigned btree_k[H5B_NUM_BTREE_ID]; /* B-tree key values for each type */
+ haddr_t base_addr; /* Absolute base address for rel.addrs. */
+ /* (superblock for file is at this offset) */
+ haddr_t ext_addr; /* Relative address of superblock extension */
+ haddr_t driver_addr; /* File driver information block address */
+ haddr_t root_addr; /* Root group address */
+ H5G_entry_t *root_ent; /* Root group symbol table entry */
+} H5F_super_t;
+
/*
* Define the structure to store the file information for HDF5 files. One of
* these structures is allocated per file, not per H5Fopen(). That is, set of
@@ -122,23 +191,18 @@ typedef struct H5F_mtab_t {
*/
typedef struct H5F_file_t {
H5FD_t *lf; /* Lower level file handle for I/O */
+ H5F_super_t *sblock; /* Pointer to (pinned) superblock for file */
+ haddr_t super_addr; /* Address of superblock signature */
unsigned nrefs; /* Ref count for times file is opened */
- uint8_t status_flags; /* File status flags */
unsigned flags; /* Access Permissions for file */
H5F_mtab_t mtab; /* File mount table */
/* Cached values from FCPL/superblock */
- unsigned sym_leaf_k; /* Size of leaves in symbol tables */
- unsigned btree_k[H5B_NUM_BTREE_ID]; /* B-tree key values for each type */
size_t sizeof_addr; /* Size of addresses in file */
size_t sizeof_size; /* Size of offsets in file */
- haddr_t base_addr; /* Absolute base address for rel.addrs. */
- /* (superblock for file is at this offset) */
- haddr_t extension_addr; /* Relative address of superblock extension */
haddr_t sohm_addr; /* Relative address of shared object header message table */
unsigned sohm_vers; /* Version of shared message table on disk */
unsigned sohm_nindexes; /* Number of shared messages indexes in the table */
- haddr_t driver_addr; /* File driver information block address*/
unsigned long feature_flags; /* VFL Driver feature Flags */
haddr_t maxaddr; /* Maximum address for file */
@@ -159,12 +223,9 @@ typedef struct H5F_file_t {
unsigned gc_ref; /* Garbage-collect references? */
hbool_t latest_format; /* Always use the latest format? */
hbool_t store_msg_crt_idx; /* Store creation index for object header messages? */
- hbool_t fam_to_sec2; /* Is h5repart changing driver from family to sec2? */
int ncwfs; /* Num entries on cwfs list */
struct H5HG_heap_t **cwfs; /* Global heap cache */
struct H5G_t *root_grp; /* Open root group */
- H5G_entry_t *root_ent; /* Root group symbol table entry */
- haddr_t root_addr; /* Root group address */
H5FO_t *open_objs; /* Open objects in file */
H5RC_t *grp_btree_shared; /* Ref-counted group B-tree node info */
@@ -217,6 +278,8 @@ H5FL_EXTERN(H5F_t);
/* Declare a free list to manage the H5F_file_t struct */
H5FL_EXTERN(H5F_file_t);
+H5_DLLVAR const H5AC_class_t H5AC_SUPERBLOCK[1];
+
/******************************/
/* Package Private Prototypes */
@@ -233,10 +296,14 @@ H5_DLL herr_t H5F_mount_count_ids(H5F_t *f, unsigned *nopen_files, unsigned *nop
/* Superblock related routines */
H5_DLL herr_t H5F_super_init(H5F_t *f, hid_t dxpl_id);
-H5_DLL herr_t H5F_super_write(H5F_t *f, hid_t dxpl_id);
H5_DLL herr_t H5F_super_read(H5F_t *f, hid_t dxpl_id);
H5_DLL herr_t H5F_super_size(H5F_t *f, hid_t dxpl_id, hsize_t *super_size, hsize_t *super_ext_size);
+/* Superblock extension related routines */
+H5_DLL herr_t H5F_super_ext_open(H5F_t *f, haddr_t ext_addr, H5O_loc_t *ext_ptr);
+H5_DLL herr_t H5F_super_ext_write_msg(H5F_t *f, hid_t dxpl_id, void *mesg, unsigned id, hbool_t may_create);
+H5_DLL herr_t H5F_super_ext_close(H5F_t *f, H5O_loc_t *ext_ptr);
+
/* Metadata accumulator routines */
H5_DLL htri_t H5F_accum_read(const H5F_t *f, hid_t dxpl_id, H5FD_mem_t type,
haddr_t addr, size_t size, void *buf);
diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h
index 2323936..11f3008 100644
--- a/src/H5Fprivate.h
+++ b/src/H5Fprivate.h
@@ -248,12 +248,12 @@ typedef struct H5F_blk_aggr_t H5F_blk_aggr_t;
#define H5F_FCPL(F) ((F)->shared->fcpl_id)
#define H5F_SIZEOF_ADDR(F) ((F)->shared->sizeof_addr)
#define H5F_SIZEOF_SIZE(F) ((F)->shared->sizeof_size)
-#define H5F_SYM_LEAF_K(F) ((F)->shared->sym_leaf_k)
-#define H5F_KVALUE(F,T) ((F)->shared->btree_k[(T)->id])
+#define H5F_SYM_LEAF_K(F) ((F)->shared->sblock->sym_leaf_k)
+#define H5F_KVALUE(F,T) ((F)->shared->sblock->btree_k[(T)->id])
#define H5F_RDCC_NSLOTS(F) ((F)->shared->rdcc_nslots)
#define H5F_RDCC_NBYTES(F) ((F)->shared->rdcc_nbytes)
#define H5F_RDCC_W0(F) ((F)->shared->rdcc_w0)
-#define H5F_BASE_ADDR(F) ((F)->shared->base_addr)
+#define H5F_BASE_ADDR(F) ((F)->shared->sblock->base_addr)
#define H5F_GRP_BTREE_SHARED(F) ((F)->shared->grp_btree_shared)
#define H5F_SIEVE_BUF_SIZE(F) ((F)->shared->sieve_buf_size)
#define H5F_GC_REF(F) ((F)->shared->gc_ref)
@@ -534,6 +534,9 @@ H5_DLL herr_t H5F_sfile_assert_num(unsigned n);
H5_DLL H5F_t *H5F_fake_alloc(size_t sizeof_size);
H5_DLL herr_t H5F_fake_free(H5F_t *f);
+/* Superblock related routines */
+H5_DLL herr_t H5F_super_dirty(H5F_t *f);
+
/* Parallel I/O (i.e. MPI) related routines */
#ifdef H5_HAVE_PARALLEL
H5_DLL int H5F_mpi_get_rank(const H5F_t *f);
diff --git a/src/H5Fquery.c b/src/H5Fquery.c
index 564a088..93f2d6e 100644
--- a/src/H5Fquery.c
+++ b/src/H5Fquery.c
@@ -261,8 +261,9 @@ H5F_sym_leaf_k(const H5F_t *f)
HDassert(f);
HDassert(f->shared);
+ HDassert(f->shared->sblock);
- FUNC_LEAVE_NOAPI(f->shared->sym_leaf_k)
+ FUNC_LEAVE_NOAPI(f->shared->sblock->sym_leaf_k)
} /* end H5F_sym_leaf_k() */
@@ -292,9 +293,10 @@ H5F_Kvalue(const H5F_t *f, const H5B_class_t *type)
HDassert(f);
HDassert(f->shared);
+ HDassert(f->shared->sblock);
HDassert(type);
- FUNC_LEAVE_NOAPI(f->shared->btree_k[type->id])
+ FUNC_LEAVE_NOAPI(f->shared->sblock->btree_k[type->id])
} /* end H5F_Kvalue() */
@@ -413,8 +415,9 @@ H5F_get_base_addr(const H5F_t *f)
HDassert(f);
HDassert(f->shared);
+ HDassert(f->shared->sblock);
- FUNC_LEAVE_NOAPI(f->shared->base_addr)
+ FUNC_LEAVE_NOAPI(f->shared->sblock->base_addr)
} /* end H5F_get_base_addr() */
diff --git a/src/H5Fsuper.c b/src/H5Fsuper.c
index f5973e9..b0096cb 100644
--- a/src/H5Fsuper.c
+++ b/src/H5Fsuper.c
@@ -26,14 +26,13 @@
/***********/
/* Headers */
/***********/
-#include "H5private.h" /* Generic Functions */
-#include "H5Eprivate.h" /* Error handling */
-#include "H5Fpkg.h" /* File access */
-#include "H5FDprivate.h" /* File drivers */
-#include "H5Iprivate.h" /* IDs */
-#include "H5MFprivate.h" /* File memory management */
-#include "H5MMprivate.h" /* Memory management */
-#include "H5Pprivate.h" /* Property lists */
+#include "H5private.h" /* Generic Functions */
+#include "H5ACprivate.h" /* Metadata cache */
+#include "H5Eprivate.h" /* Error handling */
+#include "H5Fpkg.h" /* File access */
+#include "H5FDprivate.h" /* File drivers */
+#include "H5Iprivate.h" /* IDs */
+#include "H5Pprivate.h" /* Property lists */
#include "H5SMprivate.h" /* Shared Object Header Messages */
@@ -41,61 +40,6 @@
/* Local Macros */
/****************/
-/* Superblock sizes for various versions */
-#define H5F_SIZEOF_CHKSUM 4 /* Checksum size in the file */
-
-/* Fixed-size portion at the beginning of all superblocks */
-#define H5F_SUPERBLOCK_FIXED_SIZE ( H5F_SIGNATURE_LEN \
- + 1) /* superblock version */
-
-/* Macros for computing variable-size superblock size */
-#define H5F_SUPERBLOCK_VARLEN_SIZE_COMMON \
- (2 /* freespace, and root group versions */ \
- + 1 /* reserved */ \
- + 3 /* shared header vers, size of address, size of lengths */ \
- + 1 /* reserved */ \
- + 4 /* group leaf k, group internal k */ \
- + 4) /* consistency flags */
-#define H5F_SUPERBLOCK_VARLEN_SIZE_V0(f) \
- ( H5F_SUPERBLOCK_VARLEN_SIZE_COMMON /* Common variable-length info */ \
- + H5F_SIZEOF_ADDR(f) /* base address */ \
- + H5F_SIZEOF_ADDR(f) /* <unused> */ \
- + H5F_SIZEOF_ADDR(f) /* EOF address */ \
- + H5F_SIZEOF_ADDR(f) /* driver block address */ \
- + H5G_SIZEOF_ENTRY(f)) /* root group ptr */
-#define H5F_SUPERBLOCK_VARLEN_SIZE_V1(f) \
- ( H5F_SUPERBLOCK_VARLEN_SIZE_COMMON /* Common variable-length info */ \
- + 2 /* indexed B-tree internal k */ \
- + 2 /* reserved */ \
- + H5F_SIZEOF_ADDR(f) /* base address */ \
- + H5F_SIZEOF_ADDR(f) /* <unused> */ \
- + H5F_SIZEOF_ADDR(f) /* EOF address */ \
- + H5F_SIZEOF_ADDR(f) /* driver block address */ \
- + H5G_SIZEOF_ENTRY(f)) /* root group ptr */
-#define H5F_SUPERBLOCK_VARLEN_SIZE_V2(f) \
- ( 2 /* size of address, size of lengths */ \
- + 1 /* consistency flags */ \
- + H5F_SIZEOF_ADDR(f) /* base address */ \
- + H5F_SIZEOF_ADDR(f) /* superblock extension address */ \
- + H5F_SIZEOF_ADDR(f) /* EOF address */ \
- + H5F_SIZEOF_ADDR(f) /* root group object header address */ \
- + H5F_SIZEOF_CHKSUM) /* superblock checksum (keep this last) */
-#define H5F_SUPERBLOCK_VARLEN_SIZE(v, f) ( \
- (v == 0 ? H5F_SUPERBLOCK_VARLEN_SIZE_V0(f) : 0) \
- + (v == 1 ? H5F_SUPERBLOCK_VARLEN_SIZE_V1(f) : 0) \
- + (v == 2 ? H5F_SUPERBLOCK_VARLEN_SIZE_V2(f) : 0))
-
-/* Total size of superblock, depends on superblock version */
-#define H5F_SUPERBLOCK_SIZE(v, f) ( H5F_SUPERBLOCK_FIXED_SIZE \
- + H5F_SUPERBLOCK_VARLEN_SIZE(v, f))
-
-/* Driver info block macros */
-#define H5F_DRVINFOBLOCK_HDR_SIZE 16
-
-/* Maximum size of super-block buffers */
-#define H5F_MAX_SUPERBLOCK_SIZE 134
-#define H5F_MAX_DRVINFOBLOCK_SIZE 1024
-
/******************/
/* Local Typedefs */
@@ -111,9 +55,6 @@
/* Local Prototypes */
/********************/
static herr_t H5F_super_ext_create(H5F_t *f, hid_t dxpl_id, H5O_loc_t *ext_ptr);
-static herr_t H5F_super_ext_open(H5F_t *f, H5O_loc_t *ext_ptr);
-static herr_t H5F_super_ext_write_msg(H5F_t *f, hid_t dxpl_id, void *mesg, unsigned id, hbool_t may_create);
-static herr_t H5F_super_ext_close(H5F_t *f, H5O_loc_t *ext_ptr);
/*********************/
@@ -125,6 +66,9 @@ static herr_t H5F_super_ext_close(H5F_t *f, H5O_loc_t *ext_ptr);
/* Library Private Variables */
/*****************************/
+/* Declare a free list to manage the H5F_super_t struct */
+H5FL_DEFINE(H5F_super_t);
+
/*******************/
/* Local Variables */
@@ -238,15 +182,17 @@ H5F_super_ext_create(H5F_t *f, hid_t dxpl_id, H5O_loc_t *ext_ptr)
/* Sanity check */
HDassert(f);
+ HDassert(f->shared);
+ HDassert(f->shared->sblock);
+ HDassert(!H5F_addr_defined(f->shared->sblock->ext_addr));
HDassert(ext_ptr);
- HDassert(!H5F_addr_defined(f->shared->extension_addr));
H5O_loc_reset(ext_ptr);
if(H5O_create(f, dxpl_id, 0, H5P_GROUP_CREATE_DEFAULT, ext_ptr) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTCREATE, FAIL, "unable to create superblock extension")
/* Record the address of the superblock extension */
- f->shared->extension_addr = ext_ptr->addr;
+ f->shared->sblock->ext_addr = ext_ptr->addr;
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -265,8 +211,8 @@ done:
*
*-------------------------------------------------------------------------
*/
-static herr_t
-H5F_super_ext_open(H5F_t *f, H5O_loc_t *ext_ptr)
+herr_t
+H5F_super_ext_open(H5F_t *f, haddr_t ext_addr, H5O_loc_t *ext_ptr)
{
herr_t ret_value = SUCCEED; /* Return value */
@@ -274,17 +220,17 @@ H5F_super_ext_open(H5F_t *f, H5O_loc_t *ext_ptr)
/* Sanity check */
HDassert(f);
+ HDassert(H5F_addr_defined(ext_addr));
HDassert(ext_ptr);
- HDassert(H5F_addr_defined(f->shared->extension_addr));
/* Set up "fake" object location for superblock extension */
H5O_loc_reset(ext_ptr);
ext_ptr->file = f;
- ext_ptr->addr = f->shared->extension_addr;
+ ext_ptr->addr = ext_addr;
/* Open the superblock extension object header */
if(H5O_open(ext_ptr) < 0)
- HGOTO_ERROR(H5E_OHDR, H5E_CANTOPENFILE, FAIL, "unable to open superblock extension")
+ HGOTO_ERROR(H5E_OHDR, H5E_CANTOPENOBJ, FAIL, "unable to open superblock extension")
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -303,7 +249,7 @@ done:
*
*-------------------------------------------------------------------------
*/
-static herr_t
+herr_t
H5F_super_ext_close(H5F_t *f, H5O_loc_t *ext_ptr)
{
herr_t ret_value = SUCCEED; /* Return value */
@@ -317,7 +263,7 @@ H5F_super_ext_close(H5F_t *f, H5O_loc_t *ext_ptr)
/* Twiddle the number of open objects to avoid closing the file. */
f->nopen_objs++;
if(H5O_close(ext_ptr) < 0)
- HGOTO_ERROR(H5E_OHDR, H5E_CANTRELEASE, FAIL, "unable to close superblock extension")
+ HGOTO_ERROR(H5E_OHDR, H5E_CANTCLOSEOBJ, FAIL, "unable to close superblock extension")
f->nopen_objs--;
done:
@@ -345,421 +291,44 @@ done:
herr_t
H5F_super_read(H5F_t *f, hid_t dxpl_id)
{
- uint8_t sbuf[H5F_MAX_SUPERBLOCK_SIZE]; /* Buffer for superblock */
- 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 abs_super_addr; /* Absolute offset of superblock in file */
- haddr_t stored_eoa; /*relative end-of-addr in file */
- haddr_t eof; /*end of file address */
- size_t sizeof_addr; /* Size of offsets in the file (in bytes) */
- size_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 */
- herr_t ret_value = SUCCEED;
+ H5F_super_t * sblock = NULL; /* superblock structure */
+ unsigned sblock_flags = H5AC__NO_FLAGS_SET; /* flags used in superblock unprotect call */
+ H5AC_protect_t rw; /* read/write permissions for file */
+ hbool_t dirtied = FALSE; /* Bool for sblock protect call */
+ herr_t ret_value = SUCCEED; /* return value */
FUNC_ENTER_NOAPI(H5F_super_read, FAIL)
- /* 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, FAIL, "can't get property list")
-
/* Find the superblock */
- if(HADDR_UNDEF == (abs_super_addr = H5F_locate_signature(lf, dxpl_id)))
+ if(HADDR_UNDEF == (f->shared->super_addr = H5F_locate_signature(f->shared->lf, dxpl_id)))
HGOTO_ERROR(H5E_FILE, H5E_NOTHDF5, FAIL, "unable to find file signature")
- /* Read fixed-size portion of the superblock */
- p = sbuf;
- if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, abs_super_addr + fixed_size) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "set end of space allocation request failed")
- if(H5FD_read(lf, dxpl_id, H5FD_MEM_SUPER, abs_super_addr, fixed_size, p) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_READERROR, FAIL, "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, 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")
-
- /* Sanity check */
- HDassert(((size_t)(p - sbuf)) == fixed_size);
-
- /* Determine the size of the variable-length part of the superblock */
- variable_size = 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, abs_super_addr + fixed_size + variable_size) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "set end of space allocation request failed")
- if(H5FD_read(lf, dxpl_id, H5FD_MEM_SUPER, abs_super_addr + fixed_size, variable_size, p) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "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, FAIL, "bad free space version number")
-
- /* Root group version number (hard-wired) */
- if(HDF5_OBJECTDIR_VERSION != *p++)
- HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "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, FAIL, "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, 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 status flags (not really used yet) */
- UINT32DECODE(p, status_flags);
- HDassert(status_flags <= 255);
- shared->status_flags = (uint8_t)status_flags;
- if(shared->status_flags & ~H5F_SUPER_ALL_FLAGS)
- HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "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, 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 */
-
- /* Remainder of "variable-sized" portion of superblock */
- H5F_addr_decode(f, (const uint8_t **)&p, &shared->base_addr/*out*/);
- H5F_addr_decode(f, (const uint8_t **)&p, &shared->extension_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*/);
-
- /* Decode the symbol table entry */
- if(H5G_root_ent_decode(f, (const uint8_t **)&p) < 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(abs_super_addr, shared->base_addr)) {
- /* Check if the superblock moved earlier in the file */
- if(H5F_addr_lt(abs_super_addr, shared->base_addr))
- stored_eoa -= (shared->base_addr - abs_super_addr);
- else
- /* The superblock moved later in the file */
- stored_eoa += (abs_super_addr - shared->base_addr);
-
- shared->base_addr = abs_super_addr;
- } /* end if */
-
- /* Set the base address for the file in the VFD now, after adjusting
- * space for possible offsets of the HDF5 data in the file.
- */
- if(H5FD_set_base_addr(lf, shared->base_addr) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "failed to set base address for file driver")
-
- /* 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(shared->fam_to_sec2)
- shared->driver_addr = HADDR_UNDEF;
-
- /* Decode the optional driver information block */
- if(H5F_addr_defined(shared->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, shared->driver_addr + H5F_DRVINFOBLOCK_HDR_SIZE) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "set end of space allocation request failed")
- if(H5FD_read(lf, dxpl_id, H5FD_MEM_SUPER, shared->driver_addr, (size_t)H5F_DRVINFOBLOCK_HDR_SIZE, p) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to read driver information block")
-
- /* Version number */
- drv_vers = *p++;
- if(drv_vers != HDF5_DRIVERINFO_VERSION_0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "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, FAIL, "family driver should be used")
- if(!HDstrncmp(drv_name, "NCSAmult", (size_t)8) && HDstrcmp(lf->cls->name, "multi"))
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "multi driver should be used")
-
- /* Read in variable-sized portion of driver info block */
- if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, shared->driver_addr + H5F_DRVINFOBLOCK_HDR_SIZE + drv_variable_size) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "set end of space allocation request failed")
- if(H5FD_read(lf, dxpl_id, H5FD_MEM_SUPER, shared->driver_addr + H5F_DRVINFOBLOCK_HDR_SIZE, drv_variable_size, p) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to read file driver information")
-
- /* Decode driver information */
- if(H5FD_sb_decode(lf, drv_name, p) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to decode driver information")
- } /* end if */
- } /* end if */
- else {
- uint32_t computed_chksum; /* Computed checksum */
- uint32_t read_chksum; /* Checksum read from file */
-
- /* 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 */
-
- /* File status flags (not really used yet) */
- shared->status_flags = *p++;
- if(shared->status_flags & ~H5F_SUPER_ALL_FLAGS)
- HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "bad flag value for superblock")
-
- /* Base, superblock extension, end of file & root group object header addresses */
- H5F_addr_decode(f, (const uint8_t **)&p, &shared->base_addr/*out*/);
- H5F_addr_decode(f, (const uint8_t **)&p, &shared->extension_addr/*out*/);
- H5F_addr_decode(f, (const uint8_t **)&p, &stored_eoa/*out*/);
- H5F_addr_decode(f, (const uint8_t **)&p, &shared->root_addr/*out*/);
-
- /* Compute checksum for superblock */
- computed_chksum = H5_checksum_metadata(sbuf, (size_t)(p - sbuf), 0);
-
- /* Decode checksum */
- UINT32DECODE(p, read_chksum);
-
- /* Verify correct checksum */
- if(read_chksum != computed_chksum)
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "bad checksum on driver information block")
-
- /*
- * Check if superblock address is different from base address and
- * adjust base address and "end of address" address if so.
- */
- if(!H5F_addr_eq(abs_super_addr, shared->base_addr)) {
- /* Check if the superblock moved earlier in the file */
- if(H5F_addr_lt(abs_super_addr, shared->base_addr))
- stored_eoa -= (shared->base_addr - abs_super_addr);
- else
- /* The superblock moved later in the file */
- stored_eoa += (abs_super_addr - shared->base_addr);
-
- shared->base_addr = abs_super_addr;
- } /* end if */
-
- /* Set the base address for the file in the VFD now, after adjusting
- * space for possible offsets of the HDF5 data in the file.
- */
- if(H5FD_set_base_addr(lf, shared->base_addr) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "failed to set base address for file driver")
- } /* end else */
-
- /*
- * The user-defined data is the area of the file before the base
- * address.
- */
- if(H5P_set(c_plist, H5F_CRT_USER_BLOCK_NAME, &shared->base_addr) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set userblock size")
-
- /*
- * Make sure that the data is not truncated. One case where this is
- * possible is if the first file of a family of files was opened
- * individually.
- */
- if(HADDR_UNDEF == (eof = H5FD_get_eof(lf)))
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to determine file size")
- /* (Account for the stored EOA being absolute offset -QAK) */
- if((eof + H5F_BASE_ADDR(f)) < stored_eoa)
- HGOTO_ERROR(H5E_FILE, H5E_TRUNCATED, FAIL, "truncated file")
-
- /*
- * Tell the file driver how much address space has already been
- * allocated so that it knows how to allocate additional memory.
- */
- /* (Account for the stored EOA being absolute offset -NAF) */
- if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, stored_eoa - H5F_BASE_ADDR(f)) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to set end-of-address marker for file")
-
- /* Read the file's superblock extension, if there is one. */
- if(H5F_addr_defined(shared->extension_addr)) {
- H5O_loc_t ext_loc; /* "Object location" for superblock extension */
- H5O_btreek_t btreek; /* v1 B-tree 'K' value message from superblock extension */
- H5O_drvinfo_t drvinfo; /* Driver info message from superblock extension */
- htri_t status; /* Status for message existing */
-
- /* Sanity check - superblock extension should only be defined for
- * superblock version >= 2.
- */
- HDassert(super_vers >= HDF5_SUPERBLOCK_VERSION_2);
-
- /* Check for superblock extension being located "outside" the stored
- * 'eoa' value, which can occur with the split/multi VFD.
- */
- if(H5F_addr_gt(shared->extension_addr, stored_eoa)) {
- /* Set the 'eoa' for the object header memory type large enough
- * to give some room for a reasonably sized superblock extension.
- * (This is _rather_ a kludge -QAK)
- */
- if(H5FD_set_eoa(lf, H5FD_MEM_OHDR, (haddr_t)(shared->extension_addr + 1024)) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to set end-of-address marker for file")
- } /* end if */
+ /* Determine file intent for superblock protect */
+ if(H5F_INTENT(f) & H5F_ACC_RDWR)
+ rw = H5AC_WRITE;
+ else
+ rw = H5AC_READ;
- /* Open the superblock extension */
- if(H5F_super_ext_open(f, &ext_loc) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENOBJ, FAIL, "unable to start file's superblock extension")
-
- /* Check for the extension having a 'driver info' message */
- if((status = H5O_msg_exists(&ext_loc, H5O_DRVINFO_ID, dxpl_id)) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to read object header")
- if(status) {
- /* Retrieve the 'driver info' structure */
- if(NULL == H5O_msg_read(&ext_loc, H5O_DRVINFO_ID, &drvinfo, dxpl_id))
- HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "driver info message not present")
-
- /* 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(drvinfo.name, "NCSAfami", (size_t)8) && HDstrcmp(lf->cls->name, "family"))
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "family driver should be used")
- if(!HDstrncmp(drvinfo.name, "NCSAmult", (size_t)8) && HDstrcmp(lf->cls->name, "multi"))
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "multi driver should be used")
-
- /* Decode driver information */
- if(H5FD_sb_decode(lf, drvinfo.name, drvinfo.buf) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to decode driver information")
-
- /* Reset driver info message */
- H5O_msg_reset(H5O_DRVINFO_ID, &drvinfo);
- } /* end if */
+ /* Look up the superblock */
+ if(NULL == (sblock = (H5F_super_t *)H5AC_protect(f, dxpl_id, H5AC_SUPERBLOCK, f->shared->super_addr, NULL, &dirtied, rw)))
+ HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load superblock")
+
+ /* Mark the superblock dirty if it was modified during loading or VFD indicated to do so */
+ if((H5AC_WRITE == rw) && (dirtied || H5F_HAS_FEATURE(f, H5FD_FEAT_DIRTY_SBLK_LOAD)))
+ sblock_flags |= H5AC__DIRTIED_FLAG;
- /* Read in the shared OH message information if there is any */
- if(H5SM_get_info(&ext_loc, c_plist, dxpl_id) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to read SOHM table information")
-
- /* Check for the extension having a 'v1 B-tree "K"' message */
- if((status = H5O_msg_exists(&ext_loc, H5O_BTREEK_ID, dxpl_id)) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to read object header")
- if(status) {
- /* Retrieve the 'v1 B-tree "K"' structure */
- if(NULL == H5O_msg_read(&ext_loc, H5O_BTREEK_ID, &btreek, dxpl_id))
- HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "v1 B-tree 'K' info message not present")
-
- /* Set non-default v1 B-tree 'K' value info from file */
- shared->btree_k[H5B_CHUNK_ID] = btreek.btree_k[H5B_CHUNK_ID];
- shared->btree_k[H5B_SNODE_ID] = btreek.btree_k[H5B_SNODE_ID];
- shared->sym_leaf_k = btreek.sym_leaf_k;
-
- /* Set non-default v1 B-tree 'K' values in the property list */
- if(H5P_set(c_plist, H5F_CRT_BTREE_RANK_NAME, btreek.btree_k) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set rank for btree internal nodes")
- if(H5P_set(c_plist, H5F_CRT_SYM_LEAF_NAME, &btreek.sym_leaf_k) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set rank for symbol table leaf nodes")
- } /* end if */
- else {
- /* No non-default v1 B-tree 'K' value info in file, use defaults */
- shared->btree_k[H5B_CHUNK_ID] = HDF5_BTREE_CHUNK_IK_DEF;
- shared->btree_k[H5B_SNODE_ID] = HDF5_BTREE_SNODE_IK_DEF;
- shared->sym_leaf_k = H5F_CRT_SYM_LEAF_DEF;
- } /* end if */
+ /* Pin the superblock in the cache */
+ if(H5AC_pin_protected_entry(f, sblock) < 0)
+ HGOTO_ERROR(H5E_FSPACE, H5E_CANTPIN, FAIL, "unable to pin superblock")
- /* Close superblock extension */
- if(H5F_super_ext_close(f, &ext_loc) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTRELEASE, FAIL, "unable to close file's superblock extension")
- } /* end if */
+ /* Set the pointer to the pinned superblock */
+ f->shared->sblock = sblock;
done:
+ /* Release the superblock */
+ if(sblock && H5AC_unprotect(f, dxpl_id, H5AC_SUPERBLOCK, f->shared->super_addr, sblock, sblock_flags) < 0)
+ HDONE_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, FAIL, "unable to close superblock")
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_super_read() */
@@ -783,21 +352,64 @@ done:
herr_t
H5F_super_init(H5F_t *f, hid_t dxpl_id)
{
- H5P_genplist_t *plist; /* File creation property list */
- hsize_t userblock_size; /* Size of userblock, in bytes */
- hsize_t superblock_size; /* Size of superblock, in bytes */
- size_t driver_size; /* Size of driver info block (bytes) */
- unsigned super_vers; /* Superblock version */
- haddr_t super_addr; /* Address of superblock */
+ H5F_super_t *sblock = NULL; /* Superblock cache structure */
+ hbool_t sblock_in_cache = FALSE; /* Whether the superblock has been inserted into the metadata cache */
+ H5P_genplist_t *plist; /* File creation property list */
+ hsize_t userblock_size; /* Size of userblock, in bytes */
+ hsize_t superblock_size; /* Size of superblock, in bytes */
+ size_t driver_size; /* Size of driver info block (bytes) */
+ unsigned super_vers = HDF5_SUPERBLOCK_VERSION_DEF; /* Superblock version for file */
+ haddr_t super_addr; /* Address of superblock */
hbool_t need_ext; /* Whether the superblock extension is needed */
- herr_t ret_value = SUCCEED;
+ herr_t ret_value = SUCCEED; /* Return Value */
FUNC_ENTER_NOAPI(H5F_super_init, FAIL)
+ /* Allocate space for the superblock */
+ if(NULL == (sblock = H5FL_CALLOC(H5F_super_t)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+
+ /* Initialize various address information */
+ sblock->base_addr = HADDR_UNDEF;
+ sblock->ext_addr = HADDR_UNDEF;
+ sblock->driver_addr = HADDR_UNDEF;
+ sblock->root_addr = HADDR_UNDEF;
+
/* Get the shared file creation 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")
+ /* Initialize sym_leaf_k */
+ if(H5P_get(plist, H5F_CRT_SYM_LEAF_NAME, &sblock->sym_leaf_k) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get byte number for object size")
+
+ /* Initialize btree_k */
+ if(H5P_get(plist, H5F_CRT_BTREE_RANK_NAME, &sblock->btree_k[0]) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get rank for btree internal nodes")
+
+ /* Bump superblock version if we are to use the latest version of the format */
+ if(f->shared->latest_format)
+ super_vers = HDF5_SUPERBLOCK_VERSION_LATEST;
+ /* Bump superblock version to create superblock extension for SOHM info */
+ else if(f->shared->sohm_nindexes > 0)
+ super_vers = HDF5_SUPERBLOCK_VERSION_2;
+ /* Check for non-default indexed storage B-tree internal 'K' value
+ * and set the version # of the superblock to 1 if it is a non-default
+ * value.
+ */
+ else if(sblock->btree_k[H5B_CHUNK_ID] != HDF5_BTREE_CHUNK_IK_DEF)
+ super_vers = HDF5_SUPERBLOCK_VERSION_1;
+
+ /* If a newer superblock version is required, set it here */
+ if(super_vers != HDF5_SUPERBLOCK_VERSION_DEF) {
+ H5P_genplist_t *c_plist; /* Property list */
+
+ if(NULL == (c_plist = (H5P_genplist_t *)H5I_object(f->shared->fcpl_id)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not property list")
+ 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")
+ } /* end if */
+
/*
* The superblock starts immediately after the user-defined
* header, which we have already insured is a proper size. The
@@ -806,8 +418,9 @@ H5F_super_init(H5F_t *f, hid_t dxpl_id)
*/
if(H5P_get(plist, H5F_CRT_USER_BLOCK_NAME, &userblock_size) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to get userblock size")
- f->shared->base_addr = userblock_size;
- f->shared->status_flags = 0;
+
+ sblock->base_addr = userblock_size;
+ sblock->status_flags = 0;
/* Reserve space for the userblock */
if(H5FD_set_eoa(f->shared->lf, H5FD_MEM_SUPER, userblock_size) < 0)
@@ -816,12 +429,11 @@ H5F_super_init(H5F_t *f, hid_t dxpl_id)
/* Set the base address for the file in the VFD now, after allocating
* space for userblock.
*/
- if(H5FD_set_base_addr(f->shared->lf, f->shared->base_addr) < 0)
+ if(H5FD_set_base_addr(f->shared->lf, sblock->base_addr) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "failed to set base address for file driver")
- /* Grab superblock version from property list */
- if(H5P_get(plist, H5F_CRT_SUPER_VERS_NAME, &super_vers) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get superblock version")
+ /* Save a local copy of the superblock version number */
+ sblock->super_vers = super_vers;
/* Compute the size of the superblock */
superblock_size = H5F_SUPERBLOCK_SIZE(super_vers, f);
@@ -835,7 +447,7 @@ H5F_super_init(H5F_t *f, hid_t dxpl_id)
* The file driver information block begins immediately after the
* superblock. (relative to base address in file)
*/
- f->shared->driver_addr = superblock_size;
+ sblock->driver_addr = superblock_size;
} /* end if */
/*
@@ -846,11 +458,22 @@ H5F_super_init(H5F_t *f, hid_t dxpl_id)
*/
if(super_vers < HDF5_SUPERBLOCK_VERSION_2)
superblock_size += driver_size;
- super_addr = H5MF_alloc(f, H5FD_MEM_SUPER, dxpl_id, superblock_size);
- if(HADDR_UNDEF == super_addr)
- HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to allocate file space for userblock and/or superblock")
- if(0 != super_addr)
- HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "file driver failed to allocate userblock and/or superblock at address zero")
+
+ /* Reserve space in the file for the superblock, instead of allocating it */
+ if(H5FD_set_eoa(f->shared->lf, H5FD_MEM_SUPER, superblock_size) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to set EOA value for superblock")
+
+ /* Set the superblock's address, it must be immediately after any userblock */
+ super_addr = (haddr_t)0;
+
+ /* Insert superblock into cache, pinned */
+ if(H5AC_set(f, dxpl_id, H5AC_SUPERBLOCK, super_addr, sblock, H5AC__PIN_ENTRY_FLAG) < 0)
+ HGOTO_ERROR(H5E_CACHE, H5E_CANTINS, FAIL, "can't add superblock to cache")
+ sblock_in_cache = TRUE;
+
+ /* Keep a copy of the superblock info */
+ f->shared->sblock = sblock;
+ f->shared->super_addr = super_addr;
/*
* Determine if we will need a superblock extension
@@ -867,9 +490,9 @@ H5F_super_init(H5F_t *f, hid_t dxpl_id)
*/
else if(super_vers >= HDF5_SUPERBLOCK_VERSION_2) {
/* Check for non-default v1 B-tree 'K' values to store */
- if(f->shared->btree_k[H5B_SNODE_ID] != HDF5_BTREE_SNODE_IK_DEF ||
- f->shared->btree_k[H5B_CHUNK_ID] != HDF5_BTREE_CHUNK_IK_DEF ||
- f->shared->sym_leaf_k != H5F_CRT_SYM_LEAF_DEF)
+ if(sblock->btree_k[H5B_SNODE_ID] != HDF5_BTREE_SNODE_IK_DEF ||
+ sblock->btree_k[H5B_CHUNK_ID] != HDF5_BTREE_CHUNK_IK_DEF ||
+ sblock->sym_leaf_k != H5F_CRT_SYM_LEAF_DEF)
need_ext = TRUE;
/* Check for driver info to store */
else if(driver_size > 0)
@@ -905,15 +528,15 @@ H5F_super_init(H5F_t *f, hid_t dxpl_id)
} /* end if */
/* Check for non-default v1 B-tree 'K' values to store */
- if(f->shared->btree_k[H5B_SNODE_ID] != HDF5_BTREE_SNODE_IK_DEF ||
- f->shared->btree_k[H5B_CHUNK_ID] != HDF5_BTREE_CHUNK_IK_DEF ||
- f->shared->sym_leaf_k != H5F_CRT_SYM_LEAF_DEF) {
+ if(sblock->btree_k[H5B_SNODE_ID] != HDF5_BTREE_SNODE_IK_DEF ||
+ sblock->btree_k[H5B_CHUNK_ID] != HDF5_BTREE_CHUNK_IK_DEF ||
+ sblock->sym_leaf_k != H5F_CRT_SYM_LEAF_DEF) {
H5O_btreek_t btreek; /* v1 B-tree 'K' value message for superblock extension */
/* Write v1 B-tree 'K' value information to the superblock extension */
- btreek.btree_k[H5B_CHUNK_ID] = f->shared->btree_k[H5B_CHUNK_ID];
- btreek.btree_k[H5B_SNODE_ID] = f->shared->btree_k[H5B_SNODE_ID];
- btreek.sym_leaf_k = f->shared->sym_leaf_k;
+ btreek.btree_k[H5B_CHUNK_ID] = sblock->btree_k[H5B_CHUNK_ID];
+ btreek.btree_k[H5B_SNODE_ID] = sblock->btree_k[H5B_SNODE_ID];
+ btreek.sym_leaf_k = sblock->sym_leaf_k;
if(H5O_msg_create(&ext_loc, H5O_BTREEK_ID, H5O_MSG_FLAG_CONSTANT | H5O_MSG_FLAG_DONTSHARE, H5O_UPDATE_TIME, &btreek, dxpl_id) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to update v1 B-tree 'K' value header message")
} /* end if */
@@ -943,194 +566,66 @@ H5F_super_init(H5F_t *f, hid_t dxpl_id)
} /* end if */
done:
+ /* Cleanup on failure */
+ if(ret_value < 0) {
+ /* Check if the superblock has been allocated yet */
+ if(sblock) {
+ /* Check if we've cached it already */
+ if(sblock_in_cache) {
+ /* Unpin superblock in cache */
+ if(H5AC_unpin_entry(f, sblock) < 0)
+ HDONE_ERROR(H5E_FILE, H5E_CANTUNPIN, FAIL, "unable to unpin superblock")
+
+ /* Evict the superblock from the cache */
+ if(H5AC_expunge_entry(f, dxpl_id, H5AC_SUPERBLOCK, super_addr, H5AC__NO_FLAGS_SET) < 0)
+ HDONE_ERROR(H5E_FILE, H5E_CANTEXPUNGE, FAIL, "unable to expunge superblock")
+ } /* end if */
+ else
+ /* Free superblock */
+ sblock = (H5F_super_t *)H5FL_FREE(H5F_super_t, sblock);
+
+ /* Reset variables in file structure */
+ f->shared->sblock = NULL;
+ f->shared->super_addr = HADDR_UNDEF;
+ } /* end if */
+ } /* end if */
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_super_init() */
/*-------------------------------------------------------------------------
- * Function: H5F_super_write
+ * Function: H5F_super_dirty
*
- * Purpose: Writes the superblock for the file.
+ * Purpose: Mark the file's superblock dirty
*
- * Return: Success: SUCCEED
- * Failure: FAIL
+ * Return: Success: non-negative on success
+ * Failure: Negative
*
- * Programmer: Bill Wendling
- * wendling@ncsa.uiuc.edu
- * Sept 12, 2003
+ * Programmer: Quincey Koziol
+ * August 14, 2009
*
*-------------------------------------------------------------------------
*/
herr_t
-H5F_super_write(H5F_t *f, hid_t dxpl_id)
+H5F_super_dirty(H5F_t *f)
{
- H5P_genplist_t *plist; /* File creation property list */
- uint8_t buf[H5F_MAX_SUPERBLOCK_SIZE + H5F_MAX_DRVINFOBLOCK_SIZE]; /* Superblock & driver info blockencoding buffer */
- uint8_t *p; /* Ptr into encoding buffer */
- haddr_t rel_eoa; /* Relative EOA for file */
- size_t superblock_size; /* Size of superblock, in bytes */
- size_t driver_size; /* Size of driver info block (bytes)*/
- unsigned super_vers; /* Superblock version */
- herr_t ret_value = SUCCEED;
-
- FUNC_ENTER_NOAPI(H5F_super_write, FAIL)
-
- /* Get the shared file creation 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")
-
- /* Grab values from property list */
- if(H5P_get(plist, H5F_CRT_SUPER_VERS_NAME, &super_vers) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get superblock version")
-
- /* Encode the common portion of the file superblock for all versions */
- p = buf;
- HDmemcpy(p, H5F_SIGNATURE, (size_t)H5F_SIGNATURE_LEN);
- p += H5F_SIGNATURE_LEN;
- *p++ = (uint8_t)super_vers;
-
- /* Check for older version of superblock format */
- if(super_vers < HDF5_SUPERBLOCK_VERSION_2) {
- *p++ = (uint8_t)HDF5_FREESPACE_VERSION; /* (hard-wired) */
- *p++ = (uint8_t)HDF5_OBJECTDIR_VERSION; /* (hard-wired) */
- *p++ = 0; /* reserved*/
-
- *p++ = (uint8_t)HDF5_SHAREDHEADER_VERSION; /* (hard-wired) */
- HDassert(H5F_SIZEOF_ADDR(f) <= 255);
- *p++ = (uint8_t)H5F_SIZEOF_ADDR(f);
- HDassert(H5F_SIZEOF_SIZE(f) <= 255);
- *p++ = (uint8_t)H5F_SIZEOF_SIZE(f);
- *p++ = 0; /* reserved */
-
- UINT16ENCODE(p, f->shared->sym_leaf_k);
- UINT16ENCODE(p, f->shared->btree_k[H5B_SNODE_ID]);
- UINT32ENCODE(p, (uint32_t)f->shared->status_flags);
-
- /*
- * Versions of the superblock >0 have the indexed storage B-tree
- * internal 'K' value stored
- */
- if(super_vers > HDF5_SUPERBLOCK_VERSION_DEF) {
- UINT16ENCODE(p, f->shared->btree_k[H5B_CHUNK_ID]);
- *p++ = 0; /*reserved */
- *p++ = 0; /*reserved */
- } /* end if */
-
- H5F_addr_encode(f, &p, f->shared->base_addr);
- H5F_addr_encode(f, &p, f->shared->extension_addr);
- rel_eoa = H5FD_get_eoa(f->shared->lf, H5FD_MEM_SUPER);
- H5F_addr_encode(f, &p, (rel_eoa + f->shared->base_addr));
- H5F_addr_encode(f, &p, f->shared->driver_addr);
-
- /* Encode the root group object entry, including the cached stab info */
- if(H5G_root_ent_encode(f, &p) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to encode root group information")
-
- /* Encode the driver information block. */
- H5_ASSIGN_OVERFLOW(driver_size, H5FD_sb_size(f->shared->lf), hsize_t, size_t);
-
- /* Checking whether driver block address is defined here is to handle backward
- * compatibility. If the file was created with v1.6 library or earlier and no
- * driver info block was written in the superblock, we don't write it either even
- * though there's some driver info. Otherwise, the driver block extended will
- * overwrite the (meta)data right after the superblock. This situation happens to
- * the family driver particularly. SLU - 2009/3/24
- */
- if(driver_size > 0 && H5F_addr_defined(f->shared->driver_addr)) {
- char driver_name[9]; /* Name of driver, for driver info block */
- uint8_t *dbuf = p; /* Pointer to beginning of driver info */
-
- /* Encode the driver information block */
- *p++ = HDF5_DRIVERINFO_VERSION_0; /* Version */
- *p++ = 0; /* reserved */
- *p++ = 0; /* reserved */
- *p++ = 0; /* reserved */
-
- /* Driver info size, excluding header */
- UINT32ENCODE(p, driver_size);
-
- /* Encode driver-specific data */
- if(H5FD_sb_encode(f->shared->lf, driver_name, dbuf + H5F_DRVINFOBLOCK_HDR_SIZE) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to encode driver information")
-
- /* Store driver name (set in 'H5FD_sb_encode' call above) */
- HDmemcpy(p, driver_name, (size_t)8);
-
- /* Advance buffer pointer past name & variable-sized portion of driver info */
- /* (for later use in computing the superblock size) */
- p += 8 + driver_size;
- } /* end if */
- } /* end if */
- else {
- uint32_t chksum; /* Checksum temporary variable */
- H5O_loc_t *root_oloc; /* Pointer to root group's object location */
-
- /* Size of file addresses & offsets, and status flags */
- HDassert(H5F_SIZEOF_ADDR(f) <= 255);
- *p++ = (uint8_t)H5F_SIZEOF_ADDR(f);
- HDassert(H5F_SIZEOF_SIZE(f) <= 255);
- *p++ = (uint8_t)H5F_SIZEOF_SIZE(f);
- *p++ = f->shared->status_flags;
-
- /* Base, superblock extension & end of file addresses */
- H5F_addr_encode(f, &p, f->shared->base_addr);
- H5F_addr_encode(f, &p, f->shared->extension_addr);
- rel_eoa = H5FD_get_eoa(f->shared->lf, H5FD_MEM_SUPER);
- H5F_addr_encode(f, &p, (rel_eoa + f->shared->base_addr));
-
- /* Retrieve information for root group */
- if(NULL == (root_oloc = H5G_oloc(f->shared->root_grp)))
- HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to retrieve root group information")
-
- /* Encode address of root group's object header */
- H5F_addr_encode(f, &p, root_oloc->addr);
-
- /* Compute superblock checksum */
- chksum = H5_checksum_metadata(buf, (H5F_SUPERBLOCK_SIZE(super_vers, f) - H5F_SIZEOF_CHKSUM), 0);
-
- /* Superblock checksum */
- UINT32ENCODE(p, chksum);
-
- /* Sanity check */
- HDassert((size_t)(p - buf) == H5F_SUPERBLOCK_SIZE(super_vers, f));
- } /* end else */
-
- /* Retrieve the total size of the superblock info */
- H5_ASSIGN_OVERFLOW(superblock_size, (p - buf), int, size_t);
-
- /* Double check we didn't overrun the block (unlikely) */
- HDassert(superblock_size <= sizeof(buf));
-
- /* Write superblock (always at relative offset 0) */
- if(H5FD_write(f->shared->lf, dxpl_id, H5FD_MEM_SUPER, (haddr_t)0, superblock_size, buf) < 0)
- HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "unable to write superblock")
-
- /* Check for newer version of superblock format & superblock extension */
- if(super_vers >= HDF5_SUPERBLOCK_VERSION_2 && H5F_addr_defined(f->shared->extension_addr)) {
- /* Check for driver info message */
- H5_ASSIGN_OVERFLOW(driver_size, H5FD_sb_size(f->shared->lf), hsize_t, size_t);
- if(driver_size > 0) {
- H5O_drvinfo_t drvinfo; /* Driver info */
- uint8_t dbuf[H5F_MAX_DRVINFOBLOCK_SIZE]; /* Driver info block encoding buffer */
+ herr_t ret_value = SUCCEED; /* Return value */
- /* Sanity check */
- HDassert(driver_size <= H5F_MAX_DRVINFOBLOCK_SIZE);
+ FUNC_ENTER_NOAPI(H5F_super_dirty, FAIL)
- /* Encode driver-specific data */
- if(H5FD_sb_encode(f->shared->lf, drvinfo.name, dbuf) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to encode driver information")
+ /* Sanity check */
+ HDassert(f);
+ HDassert(f->shared);
+ HDassert(f->shared->sblock);
- /* Write driver info information to the superblock extension */
- drvinfo.len = driver_size;
- drvinfo.buf = dbuf;
- if(H5F_super_ext_write_msg(f, dxpl_id, &drvinfo, H5O_DRVINFO_ID, FALSE) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_WRITEERROR, FAIL, "unable to update driver info header message")
- } /* end if */
- } /* end if */
+ /* Mark superblock dirty in cache, so change to EOA will get encoded */
+ if(H5AC_mark_pinned_or_protected_entry_dirty(f, f->shared->sblock) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTMARKDIRTY, FAIL, "unable to mark superblock as dirty")
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5F_super_write() */
+} /* H5F_super_dirty() */
/*-------------------------------------------------------------------------
@@ -1143,6 +638,7 @@ done:
*
* Programmer: Vailin Choi
* July 11, 2007
+ *
*-------------------------------------------------------------------------
*/
herr_t
@@ -1154,34 +650,23 @@ H5F_super_size(H5F_t *f, hid_t dxpl_id, hsize_t *super_size, hsize_t *super_ext_
/* Sanity check */
HDassert(f);
+ HDassert(f->shared);
+ HDassert(f->shared->sblock);
/* Set the superblock size */
- if(super_size) {
- H5P_genplist_t *plist; /* File creation property list */
- unsigned super_vers; /* Superblock version */
-
- /* Get the shared file creation 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")
-
- /* Grab values from property list */
- if(H5P_get(plist, H5F_CRT_SUPER_VERS_NAME, &super_vers) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get superblock version")
-
- /* Set the superblock size */
- *super_size = H5F_SUPERBLOCK_SIZE(super_vers, f);
- } /* end if */
+ if(super_size)
+ *super_size = H5F_SUPERBLOCK_SIZE(f->shared->sblock->super_vers, f);
/* Set the superblock extension size */
if(super_ext_size) {
- if(H5F_addr_defined(f->shared->extension_addr)) {
+ if(H5F_addr_defined(f->shared->sblock->ext_addr)) {
H5O_loc_t ext_loc; /* "Object location" for superblock extension */
H5O_info_t oinfo; /* Object info for superblock extension */
/* Set up "fake" object location for superblock extension */
H5O_loc_reset(&ext_loc);
ext_loc.file = f;
- ext_loc.addr = f->shared->extension_addr;
+ ext_loc.addr = f->shared->sblock->ext_addr;
/* Get object header info for superblock extension */
if(H5O_get_info(&ext_loc, dxpl_id, FALSE, &oinfo) < 0)
@@ -1211,24 +696,31 @@ done:
*
*-------------------------------------------------------------------------
*/
-static herr_t
+herr_t
H5F_super_ext_write_msg(H5F_t *f, hid_t dxpl_id, void *mesg, unsigned id, hbool_t may_create)
{
+ hbool_t sblock_dirty = FALSE; /* Whether superblock was dirtied */
H5O_loc_t ext_loc; /* "Object location" for superblock extension */
htri_t status; /* Indicate whether the message exists or not */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5F_super_ext_write_msg)
+ /* Sanity checks */
+ HDassert(f);
+ HDassert(f->shared);
+ HDassert(f->shared->sblock);
+
/* Open/create the superblock extension object header */
- if(H5F_addr_defined(f->shared->extension_addr)) {
- if(H5F_super_ext_open(f, &ext_loc) < 0)
+ if(H5F_addr_defined(f->shared->sblock->ext_addr)) {
+ if(H5F_super_ext_open(f, f->shared->sblock->ext_addr, &ext_loc) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENOBJ, FAIL, "unable to open file's superblock extension")
} /* end if */
else {
HDassert(may_create);
if(H5F_super_ext_create(f, dxpl_id, &ext_loc) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTCREATE, FAIL, "unable to create file's superblock extension")
+ sblock_dirty = TRUE;
} /* end else */
HDassert(H5F_addr_defined(ext_loc.addr));
@@ -1259,6 +751,11 @@ H5F_super_ext_write_msg(H5F_t *f, hid_t dxpl_id, void *mesg, unsigned id, hbool_
HGOTO_ERROR(H5E_FILE, H5E_CANTRELEASE, FAIL, "unable to close file's superblock extension")
done:
+ /* Mark superblock dirty in cache, if necessary */
+ if(sblock_dirty)
+ if(H5AC_mark_pinned_or_protected_entry_dirty(f, f->shared->sblock) < 0)
+ HDONE_ERROR(H5E_FILE, H5E_CANTMARKDIRTY, FAIL, "unable to mark superblock as dirty")
+
FUNC_LEAVE_NOAPI(ret_value)
} /* H5F_super_ext_write_msg() */
diff --git a/src/H5Fsuper_cache.c b/src/H5Fsuper_cache.c
new file mode 100644
index 0000000..7df8f31
--- /dev/null
+++ b/src/H5Fsuper_cache.c
@@ -0,0 +1,854 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * Copyright by the Board of Trustees of the University of Illinois. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the files COPYING and Copyright.html. COPYING can be found at the root *
+ * of the source code distribution tree; Copyright.html can be found at the *
+ * root level of an installed copy of the electronic HDF5 document set and *
+ * is linked from the top-level documents page. It can also be found at *
+ * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
+ * access to either file, you may request a copy from help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/****************/
+/* Module Setup */
+/****************/
+
+#define H5F_PACKAGE /*suppress error about including H5Fpkg */
+#define H5G_PACKAGE /*suppress error about including H5Gpkg */
+
+
+/***********/
+/* Headers */
+/***********/
+#include "H5private.h" /* Generic Functions */
+#include "H5Eprivate.h" /* Error handling */
+#include "H5Fpkg.h" /* File access */
+#include "H5FDprivate.h" /* File drivers */
+#include "H5FLprivate.h" /* Free Lists */
+#include "H5Gpkg.h" /* Groups */
+#include "H5Iprivate.h" /* IDs */
+#include "H5MMprivate.h" /* Memory management */
+#include "H5Pprivate.h" /* Property lists */
+#include "H5SMprivate.h" /* Shared Object Header Messages */
+
+
+/****************/
+/* Local Macros */
+/****************/
+
+/* Maximum size of super-block buffers */
+#define H5F_MAX_SUPERBLOCK_SIZE 134
+
+
+/******************/
+/* Local Typedefs */
+/******************/
+
+
+/********************/
+/* Package Typedefs */
+/********************/
+
+
+/********************/
+/* Local Prototypes */
+/********************/
+
+/* Metadata cache (H5AC) callbacks */
+static H5F_super_t *H5F_sblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *udata1, void *udata2);
+static herr_t H5F_sblock_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5F_super_t *sblock);
+static herr_t H5F_sblock_dest(H5F_t *f, H5F_super_t * sblock);
+static herr_t H5F_sblock_clear(H5F_t *f, H5F_super_t *sblock, hbool_t destroy);
+static herr_t H5F_sblock_size(const H5F_t *f, const H5F_super_t *sblock, size_t *size_ptr);
+
+
+/*********************/
+/* Package Variables */
+/*********************/
+
+/* H5F inherits cache-like properties from H5AC */
+const H5AC_class_t H5AC_SUPERBLOCK[1] = {{
+ H5AC_SUPERBLOCK_ID,
+ (H5AC_load_func_t)H5F_sblock_load,
+ (H5AC_flush_func_t)H5F_sblock_flush,
+ (H5AC_dest_func_t)H5F_sblock_dest,
+ (H5AC_clear_func_t)H5F_sblock_clear,
+ (H5AC_notify_func_t)NULL,
+ (H5AC_size_func_t)H5F_sblock_size,
+}};
+
+/*****************************/
+/* Library Private Variables */
+/*****************************/
+
+/* Declare extern the free list to manage the H5F_super_t struct */
+H5FL_EXTERN(H5F_super_t);
+
+
+/*******************/
+/* Local Variables */
+/*******************/
+
+
+
+/*-------------------------------------------------------------------------
+ * 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
+ * mamcgree@hdfgroup.org
+ * April 8, 2009
+ *
+ *-------------------------------------------------------------------------
+ */
+static H5F_super_t *
+H5F_sblock_load(H5F_t *f, hid_t dxpl_id, haddr_t UNUSED addr, const void UNUSED *udata1, void *udata2/*out*/)
+{
+ H5F_super_t *sblock = NULL; /* File's superblock */
+ uint8_t sbuf[H5F_MAX_SUPERBLOCK_SIZE]; /* Buffer for superblock */
+ 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 */
+ size_t sizeof_addr; /* Size of offsets in the file (in bytes) */
+ size_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 *)udata2; /* Set up dirtied out value */
+ H5F_super_t *ret_value; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5F_sblock_load)
+
+ /* 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")
+
+ /* Allocate space for the superblock */
+ if(NULL == (sblock = H5FL_CALLOC(H5F_super_t)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
+
+ /* Read fixed-size portion of the superblock */
+ p = sbuf;
+ if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, f->shared->super_addr + fixed_size) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "set end of space allocation request failed")
+ if(H5FD_read(lf, dxpl_id, H5FD_MEM_SUPER, f->shared->super_addr, 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 = 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, f->shared->super_addr + fixed_size + variable_size) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "set end of space allocation request failed")
+ if(H5FD_read(lf, dxpl_id, H5FD_MEM_SUPER, f->shared->super_addr + 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(f->shared->super_addr, sblock->base_addr)) {
+ /* Check if the superblock moved earlier in the file */
+ if(H5F_addr_lt(f->shared->super_addr, sblock->base_addr))
+ stored_eoa -= (sblock->base_addr - f->shared->super_addr);
+ else
+ /* The superblock moved later in the file */
+ stored_eoa += (f->shared->super_addr - sblock->base_addr);
+
+ sblock->base_addr = f->shared->super_addr;
+ } /* end if */
+
+ /* Set the base address for the file in the VFD now, after adjusting
+ * space for possible offsets of the HDF5 data in the file.
+ */
+ if(H5FD_set_base_addr(lf, sblock->base_addr) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "failed to set base address for file driver")
+
+ /* 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_id, 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_id, 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 */
+ } /* end if */
+ else {
+ uint32_t computed_chksum; /* Computed checksum */
+ uint32_t read_chksum; /* Checksum read from file */
+
+ /* 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 */
+
+ /* File status flags (not really used yet) */
+ sblock->status_flags = *p++;
+ if(sblock->status_flags & ~H5F_SUPER_ALL_FLAGS)
+ HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad flag value for superblock")
+
+ /* Base, superblock extension, end of file & root group object header addresses */
+ 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->root_addr/*out*/);
+
+ /* Compute checksum for superblock */
+ computed_chksum = H5_checksum_metadata(sbuf, (size_t)(p - sbuf), 0);
+
+ /* Decode checksum */
+ UINT32DECODE(p, read_chksum);
+
+ /* Verify correct checksum */
+ if(read_chksum != computed_chksum)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "bad checksum on driver information block")
+
+ /*
+ * Check if superblock address is different from base address and
+ * adjust base address and "end of address" address if so.
+ */
+ if(!H5F_addr_eq(f->shared->super_addr, sblock->base_addr)) {
+ /* Check if the superblock moved earlier in the file */
+ if(H5F_addr_lt(f->shared->super_addr, sblock->base_addr))
+ stored_eoa -= (sblock->base_addr - f->shared->super_addr);
+ else
+ /* The superblock moved later in the file */
+ stored_eoa += (f->shared->super_addr - sblock->base_addr);
+
+ sblock->base_addr = f->shared->super_addr;
+ } /* end if */
+
+ /* Set the base address for the file in the VFD now, after adjusting
+ * space for possible offsets of the HDF5 data in the file.
+ */
+ if(H5FD_set_base_addr(lf, sblock->base_addr) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "failed to set base address for file driver")
+
+ /* Get the B-tree internal node values, etc */
+ if(H5P_get(c_plist, H5F_CRT_BTREE_RANK_NAME, sblock->btree_k) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "unable to get rank for btree internal nodes")
+ } /* end else */
+
+ /*
+ * The user-defined data is the area of the file before the base
+ * address.
+ */
+ if(H5P_set(c_plist, H5F_CRT_USER_BLOCK_NAME, &sblock->base_addr) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set userblock size")
+
+ /*
+ * Make sure that the data is not truncated. One case where this is
+ * possible is if the first file of a family of files was opened
+ * individually.
+ */
+ if(HADDR_UNDEF == (eof = H5FD_get_eof(lf)))
+ HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to determine file size")
+
+ /* (Account for the stored EOA being absolute offset -QAK) */
+ if((eof + sblock->base_addr) < stored_eoa)
+ HGOTO_ERROR(H5E_FILE, H5E_TRUNCATED, NULL, "truncated file")
+
+ /*
+ * Tell the file driver how much address space has already been
+ * allocated so that it knows how to allocate additional memory.
+ */
+ /* (Account for the stored EOA being absolute offset -NAF) */
+ if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, stored_eoa - sblock->base_addr) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to set end-of-address marker for file")
+
+ /* Read the file's superblock extension, if there is one. */
+ if(H5F_addr_defined(sblock->ext_addr)) {
+ H5O_loc_t ext_loc; /* "Object location" for superblock extension */
+ H5O_btreek_t btreek; /* v1 B-tree 'K' value message from superblock extension */
+ H5O_drvinfo_t drvinfo; /* Driver info message from superblock extension */
+ htri_t status; /* Status for message existing */
+
+ /* Sanity check - superblock extension should only be defined for
+ * superblock version >= 2.
+ */
+ HDassert(super_vers >= HDF5_SUPERBLOCK_VERSION_2);
+
+ /* Check for superblock extension being located "outside" the stored
+ * 'eoa' value, which can occur with the split/multi VFD.
+ */
+ if(H5F_addr_gt(sblock->ext_addr, stored_eoa)) {
+ /* Set the 'eoa' for the object header memory type large enough
+ * to give some room for a reasonably sized superblock extension.
+ * (This is _rather_ a kludge -QAK)
+ */
+ if(H5FD_set_eoa(lf, H5FD_MEM_OHDR, (haddr_t)(sblock->ext_addr + 1024)) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to set end-of-address marker for file")
+ } /* end if */
+
+ /* Open the superblock extension */
+ if(H5F_super_ext_open(f, sblock->ext_addr, &ext_loc) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTOPENOBJ, NULL, "unable to open file's superblock extension")
+
+ /* Check for the extension having a 'driver info' message */
+ if((status = H5O_msg_exists(&ext_loc, H5O_DRVINFO_ID, dxpl_id)) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "unable to read object header")
+ if(status) {
+ /* Check for ignoring the driver info for this file */
+ if(H5F_HAS_FEATURE(f, H5FD_FEAT_IGNORE_DRVRINFO)) {
+ /* Indicate that the superblock should be marked dirty */
+ *dirtied = TRUE;
+ } /* end if */
+ else {
+ /* Retrieve the 'driver info' structure */
+ if(NULL == H5O_msg_read(&ext_loc, H5O_DRVINFO_ID, &drvinfo, dxpl_id))
+ HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "driver info message not present")
+
+ /* 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(drvinfo.name, "NCSAfami", (size_t)8) && HDstrcmp(lf->cls->name, "family"))
+ HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "family driver should be used")
+ if(!HDstrncmp(drvinfo.name, "NCSAmult", (size_t)8) && HDstrcmp(lf->cls->name, "multi"))
+ HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "multi driver should be used")
+
+ /* Decode driver information */
+ if(H5FD_sb_decode(lf, drvinfo.name, drvinfo.buf) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to decode driver information")
+
+ /* Reset driver info message */
+ H5O_msg_reset(H5O_DRVINFO_ID, &drvinfo);
+ } /* end else */
+ } /* end if */
+
+ /* Read in the shared OH message information if there is any */
+ if(H5SM_get_info(&ext_loc, c_plist, dxpl_id) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to read SOHM table information")
+
+ /* Check for the extension having a 'v1 B-tree "K"' message */
+ if((status = H5O_msg_exists(&ext_loc, H5O_BTREEK_ID, dxpl_id)) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "unable to read object header")
+ if(status) {
+ /* Retrieve the 'v1 B-tree "K"' structure */
+ if(NULL == H5O_msg_read(&ext_loc, H5O_BTREEK_ID, &btreek, dxpl_id))
+ HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "v1 B-tree 'K' info message not present")
+
+ /* Set non-default v1 B-tree 'K' value info from file */
+ sblock->btree_k[H5B_CHUNK_ID] = btreek.btree_k[H5B_CHUNK_ID];
+ sblock->btree_k[H5B_SNODE_ID] = btreek.btree_k[H5B_SNODE_ID];
+ sblock->sym_leaf_k = btreek.sym_leaf_k;
+
+ /* Set non-default v1 B-tree 'K' values in the property list */
+ if(H5P_set(c_plist, H5F_CRT_BTREE_RANK_NAME, btreek.btree_k) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set rank for btree internal nodes")
+ if(H5P_set(c_plist, H5F_CRT_SYM_LEAF_NAME, &btreek.sym_leaf_k) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set rank for symbol table leaf nodes")
+ } /* end if */
+ else {
+ /* No non-default v1 B-tree 'K' value info in file, use defaults */
+ sblock->btree_k[H5B_CHUNK_ID] = HDF5_BTREE_CHUNK_IK_DEF;
+ sblock->btree_k[H5B_SNODE_ID] = HDF5_BTREE_SNODE_IK_DEF;
+ sblock->sym_leaf_k = H5F_CRT_SYM_LEAF_DEF;
+ } /* end if */
+
+ /* Close superblock extension */
+ if(H5F_super_ext_close(f, &ext_loc) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTRELEASE, NULL, "unable to close file's superblock extension")
+ } /* end if */
+
+ /* Set return value */
+ ret_value = sblock;
+
+done:
+
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5F_sblock_load() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5F_sblock_flush
+ *
+ * Purpose: Flushes the superblock.
+ *
+ * Return: Success: SUCCEED
+ * Failure: NULL
+ *
+ * Programmer: Mike McGreevy
+ * mamcgree@hdfgroup.org
+ * April 8, 2009
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5F_sblock_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5F_super_t *sblock)
+{
+ herr_t ret_value = SUCCEED;
+
+ FUNC_ENTER_NOAPI_NOINIT(H5F_sblock_flush)
+
+ /* check arguments */
+ HDassert(f);
+ HDassert(sblock);
+
+ if(sblock->cache_info.is_dirty) {
+ uint8_t buf[H5F_MAX_SUPERBLOCK_SIZE + H5F_MAX_DRVINFOBLOCK_SIZE]; /* Superblock & driver info blockencoding buffer */
+ uint8_t *p; /* Ptr into encoding buffer */
+ haddr_t rel_eoa; /* Relative EOA for file */
+ size_t superblock_size; /* Size of superblock, in bytes */
+ size_t driver_size; /* Size of driver info block (bytes)*/
+
+ /* Encode the common portion of the file superblock for all versions */
+ p = buf;
+ HDmemcpy(p, H5F_SIGNATURE, (size_t)H5F_SIGNATURE_LEN);
+ p += H5F_SIGNATURE_LEN;
+ *p++ = (uint8_t)sblock->super_vers;
+
+ /* Check for older version of superblock format */
+ if(sblock->super_vers < HDF5_SUPERBLOCK_VERSION_2) {
+ *p++ = (uint8_t)HDF5_FREESPACE_VERSION; /* (hard-wired) */
+ *p++ = (uint8_t)HDF5_OBJECTDIR_VERSION; /* (hard-wired) */
+ *p++ = 0; /* reserved*/
+
+ *p++ = (uint8_t)HDF5_SHAREDHEADER_VERSION; /* (hard-wired) */
+ HDassert(H5F_SIZEOF_ADDR(f) <= 255);
+ *p++ = (uint8_t)H5F_SIZEOF_ADDR(f);
+ HDassert(H5F_SIZEOF_SIZE(f) <= 255);
+ *p++ = (uint8_t)H5F_SIZEOF_SIZE(f);
+ *p++ = 0; /* reserved */
+
+ UINT16ENCODE(p, sblock->sym_leaf_k);
+ UINT16ENCODE(p, sblock->btree_k[H5B_SNODE_ID]);
+ UINT32ENCODE(p, (uint32_t)sblock->status_flags);
+
+ /*
+ * Versions of the superblock >0 have the indexed storage B-tree
+ * internal 'K' value stored
+ */
+ if(sblock->super_vers > HDF5_SUPERBLOCK_VERSION_DEF) {
+ UINT16ENCODE(p, sblock->btree_k[H5B_CHUNK_ID]);
+ *p++ = 0; /*reserved */
+ *p++ = 0; /*reserved */
+ } /* end if */
+
+ H5F_addr_encode(f, &p, sblock->base_addr);
+ H5F_addr_encode(f, &p, sblock->ext_addr);
+ rel_eoa = H5FD_get_eoa(f->shared->lf, H5FD_MEM_SUPER);
+ H5F_addr_encode(f, &p, (rel_eoa + sblock->base_addr));
+ H5F_addr_encode(f, &p, sblock->driver_addr);
+
+ /* Encode the root group object entry, including the cached stab info */
+ if(H5G_ent_encode(f, &p, sblock->root_ent) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTENCODE, FAIL, "can't encode root group symbol table entry")
+
+ /* Encode the driver information block. */
+ H5_ASSIGN_OVERFLOW(driver_size, H5FD_sb_size(f->shared->lf), hsize_t, size_t);
+
+ /* Checking whether driver block address is defined here is to handle backward
+ * compatibility. If the file was created with v1.6 library or earlier and no
+ * driver info block was written in the superblock, we don't write it either even
+ * though there's some driver info. Otherwise, the driver block extended will
+ * overwrite the (meta)data right after the superblock. This situation happens to
+ * the family driver particularly. SLU - 2009/3/24
+ */
+ if(driver_size > 0 && H5F_addr_defined(sblock->driver_addr)) {
+ char driver_name[9]; /* Name of driver, for driver info block */
+ uint8_t *dbuf = p; /* Pointer to beginning of driver info */
+
+ /* Encode the driver information block */
+ *p++ = HDF5_DRIVERINFO_VERSION_0; /* Version */
+ *p++ = 0; /* reserved */
+ *p++ = 0; /* reserved */
+ *p++ = 0; /* reserved */
+
+ /* Driver info size, excluding header */
+ UINT32ENCODE(p, driver_size);
+
+ /* Encode driver-specific data */
+ if(H5FD_sb_encode(f->shared->lf, driver_name, dbuf + H5F_DRVINFOBLOCK_HDR_SIZE) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to encode driver information")
+
+ /* Store driver name (set in 'H5FD_sb_encode' call above) */
+ HDmemcpy(p, driver_name, (size_t)8);
+
+ /* Advance buffer pointer past name & variable-sized portion of driver info */
+ /* (for later use in computing the superblock size) */
+ p += 8 + driver_size;
+ } /* end if */
+ } /* end if */
+ else {
+ uint32_t chksum; /* Checksum temporary variable */
+ H5O_loc_t *root_oloc; /* Pointer to root group's object location */
+
+ /* Size of file addresses & offsets, and status flags */
+ HDassert(H5F_SIZEOF_ADDR(f) <= 255);
+ *p++ = (uint8_t)H5F_SIZEOF_ADDR(f);
+ HDassert(H5F_SIZEOF_SIZE(f) <= 255);
+ *p++ = (uint8_t)H5F_SIZEOF_SIZE(f);
+ *p++ = sblock->status_flags;
+
+ /* Base, superblock extension & end of file addresses */
+ H5F_addr_encode(f, &p, sblock->base_addr);
+ H5F_addr_encode(f, &p, sblock->ext_addr);
+ rel_eoa = H5FD_get_eoa(f->shared->lf, H5FD_MEM_SUPER);
+ H5F_addr_encode(f, &p, (rel_eoa + sblock->base_addr));
+
+ /* Retrieve information for root group */
+ if(NULL == (root_oloc = H5G_oloc(f->shared->root_grp)))
+ HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to retrieve root group information")
+
+ /* Encode address of root group's object header */
+ H5F_addr_encode(f, &p, root_oloc->addr);
+
+ /* Compute superblock checksum */
+ chksum = H5_checksum_metadata(buf, (H5F_SUPERBLOCK_SIZE(sblock->super_vers, f) - H5F_SIZEOF_CHKSUM), 0);
+
+ /* Superblock checksum */
+ UINT32ENCODE(p, chksum);
+
+ /* Sanity check */
+ HDassert((size_t)(p - buf) == H5F_SUPERBLOCK_SIZE(sblock->super_vers, f));
+ } /* end else */
+
+ /* Retrieve the total size of the superblock info */
+ H5_ASSIGN_OVERFLOW(superblock_size, (p - buf), int, size_t);
+
+ /* Double check we didn't overrun the block (unlikely) */
+ HDassert(superblock_size <= sizeof(buf));
+
+ /* Write superblock */
+ /* (always at relative address 0) */
+ if(H5FD_write(f->shared->lf, dxpl_id, H5FD_MEM_SUPER, (haddr_t)0, superblock_size, buf) < 0)
+ HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "unable to write superblock")
+
+ /* Check for newer version of superblock format & superblock extension */
+ if(sblock->super_vers >= HDF5_SUPERBLOCK_VERSION_2 && H5F_addr_defined(sblock->ext_addr)) {
+ /* Check for ignoring the driver info for this file */
+ if(!H5F_HAS_FEATURE(f, H5FD_FEAT_IGNORE_DRVRINFO)) {
+ /* Check for driver info message */
+ H5_ASSIGN_OVERFLOW(driver_size, H5FD_sb_size(f->shared->lf), hsize_t, size_t);
+ if(driver_size > 0) {
+ H5O_drvinfo_t drvinfo; /* Driver info */
+ uint8_t dbuf[H5F_MAX_DRVINFOBLOCK_SIZE]; /* Driver info block encoding buffer */
+
+ /* Sanity check */
+ HDassert(driver_size <= H5F_MAX_DRVINFOBLOCK_SIZE);
+
+ /* Encode driver-specific data */
+ if(H5FD_sb_encode(f->shared->lf, drvinfo.name, dbuf) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to encode driver information")
+
+ /* Write driver info information to the superblock extension */
+ drvinfo.len = driver_size;
+ drvinfo.buf = dbuf;
+ if(H5F_super_ext_write_msg(f, dxpl_id, &drvinfo, H5O_DRVINFO_ID, FALSE) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_WRITEERROR, FAIL, "unable to update driver info header message")
+ } /* end if */
+ } /* end if */
+ } /* end if */
+
+ /* Reset the dirty flag. */
+ sblock->cache_info.is_dirty = FALSE;
+ } /* end if */
+
+ if(destroy)
+ if(H5F_sblock_dest(f, sblock) < 0)
+ HGOTO_ERROR(H5E_FSPACE, H5E_CLOSEERROR, FAIL, "can't close superblock")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5F_sblock_flush() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5F_sblock_dest
+ *
+ * Purpose: Frees memory used by the superblock.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Mike McGreevy
+ * April 8, 2009
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5F_sblock_dest(H5F_t UNUSED *f, H5F_super_t* sblock)
+{
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5F_sblock_dest)
+
+ /* Sanity check */
+ HDassert(sblock);
+
+ /* Free root group symbol table entry, if any */
+ sblock->root_ent = (H5G_entry_t *)H5MM_xfree(sblock->root_ent);
+
+ /* Free superblock */
+ sblock = (H5F_super_t *)H5FL_FREE(H5F_super_t, sblock);
+
+ FUNC_LEAVE_NOAPI(SUCCEED)
+} /* end H5F_sblock_dest() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5F_sblock_clear
+ *
+ * Purpose: Mark the superblock as no longer being dirty.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Mike McGreevy
+ * April 8, 2009
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5F_sblock_clear(H5F_t *f, H5F_super_t *sblock, hbool_t destroy)
+{
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5F_sblock_clear)
+
+ /*
+ * Check arguments.
+ */
+ HDassert(sblock);
+
+ /* Reset the dirty flag. */
+ sblock->cache_info.is_dirty = FALSE;
+
+ if(destroy)
+ if(H5F_sblock_dest(f, sblock) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTFREE, FAIL, "unable to delete superblock")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5F_sblock_clear() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5F_sblock_size
+ *
+ * Purpose: Returns the size of the superblock encoded on disk.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Mike McGreevy
+ * April 8, 2009
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5F_sblock_size(const H5F_t *f, const H5F_super_t *sblock, size_t *size_ptr)
+{
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5F_sblock_size)
+
+ /* check arguments */
+ HDassert(f);
+ HDassert(sblock);
+ HDassert(size_ptr);
+
+ /* Set size value */
+ *size_ptr = H5F_SUPERBLOCK_SIZE(sblock->super_vers, f);
+
+ FUNC_LEAVE_NOAPI(SUCCEED)
+} /* end H5F_sblock_size() */
+
diff --git a/src/H5Ftest.c b/src/H5Ftest.c
index 72fee96..e2ee606 100644
--- a/src/H5Ftest.c
+++ b/src/H5Ftest.c
@@ -146,7 +146,7 @@ H5F_check_cached_stab_test(hid_t file_id)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
/* Verify the cached stab info */
- if(H5G_verify_cached_stab_test(H5G_oloc(file->shared->root_grp), file->shared->root_ent) < 0)
+ if(H5G_verify_cached_stab_test(H5G_oloc(file->shared->root_grp), file->shared->sblock->root_ent) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to verify cached symbol table info")
done:
diff --git a/src/H5Gent.c b/src/H5Gent.c
index 7a9e9e5..65f302c 100644
--- a/src/H5Gent.c
+++ b/src/H5Gent.c
@@ -28,15 +28,10 @@
#include "H5FLprivate.h" /* Free Lists */
#include "H5Gpkg.h" /* Groups */
#include "H5HLprivate.h" /* Local Heaps */
-#include "H5Iprivate.h" /* IDs */
-#include "H5MMprivate.h" /* Memory Management */
/* Private macros */
/* Private prototypes */
-static herr_t H5G_ent_encode(H5F_t *f, uint8_t **pp, const H5G_entry_t *ent);
-static herr_t H5G_ent_decode(H5F_t *f, const uint8_t **pp,
- H5G_entry_t *ent/*out*/);
/* Declare extern the PQ free list for the wrapped strings */
H5FL_BLK_EXTERN(str_buf);
@@ -48,9 +43,6 @@ H5FL_BLK_EXTERN(str_buf);
* Purpose: Same as H5G_ent_decode() except it does it for an array of
* symbol table entries.
*
- * Errors:
- * SYM CANTDECODE Can't decode.
- *
* Return: Success: Non-negative, with *pp pointing to the first byte
* after the last symbol.
*
@@ -60,31 +52,29 @@ H5FL_BLK_EXTERN(str_buf);
* matzke@llnl.gov
* Jul 18 1997
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
herr_t
H5G_ent_decode_vec(H5F_t *f, const uint8_t **pp, H5G_entry_t *ent, unsigned n)
{
- unsigned u;
- herr_t ret_value=SUCCEED; /* Return value */
+ unsigned u; /* Local index variable */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI(H5G_ent_decode_vec, FAIL);
+ FUNC_ENTER_NOAPI(H5G_ent_decode_vec, FAIL)
/* check arguments */
- assert(f);
- assert(pp);
- assert(ent);
+ HDassert(f);
+ HDassert(pp);
+ HDassert(ent);
/* decode entries */
- for (u = 0; u < n; u++)
- if (H5G_ent_decode(f, pp, ent + u) < 0)
+ for(u = 0; u < n; u++)
+ if(H5G_ent_decode(f, pp, ent + u) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTDECODE, FAIL, "can't decode")
done:
- FUNC_LEAVE_NOAPI(ret_value);
-}
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5G_ent_decode_vec() */
/*-------------------------------------------------------------------------
@@ -92,8 +82,6 @@ done:
*
* Purpose: Decodes a symbol table entry pointed to by `*pp'.
*
- * Errors:
- *
* Return: Success: Non-negative with *pp pointing to the first byte
* following the symbol table entry.
*
@@ -103,25 +91,23 @@ done:
* matzke@llnl.gov
* Jul 18 1997
*
- * Modifications:
- * Robb Matzke, 17 Jul 1998
- * Added a 4-byte padding field for alignment and future expansion.
- *
*-------------------------------------------------------------------------
*/
-static herr_t
+herr_t
H5G_ent_decode(H5F_t *f, const uint8_t **pp, H5G_entry_t *ent)
{
const uint8_t *p_ret = *pp;
uint32_t tmp;
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_ent_decode)
+ FUNC_ENTER_NOAPI(H5G_ent_decode, FAIL)
/* check arguments */
HDassert(f);
HDassert(pp);
HDassert(ent);
+ /* Set the entry's file pointer */
ent->file = f;
/* decode header */
@@ -129,31 +115,31 @@ H5G_ent_decode(H5F_t *f, const uint8_t **pp, H5G_entry_t *ent)
H5F_addr_decode(f, pp, &(ent->header));
UINT32DECODE(*pp, tmp);
*pp += 4; /*reserved*/
- ent->type=(H5G_cache_type_t)tmp;
+ ent->type = (H5G_cache_type_t)tmp;
/* decode scratch-pad */
- switch (ent->type) {
+ switch(ent->type) {
case H5G_NOTHING_CACHED:
break;
case H5G_CACHED_STAB:
- assert(2 * H5F_SIZEOF_ADDR(f) <= H5G_SIZEOF_SCRATCH);
+ HDassert(2 * H5F_SIZEOF_ADDR(f) <= H5G_SIZEOF_SCRATCH);
H5F_addr_decode(f, pp, &(ent->cache.stab.btree_addr));
H5F_addr_decode(f, pp, &(ent->cache.stab.heap_addr));
break;
case H5G_CACHED_SLINK:
- UINT32DECODE (*pp, ent->cache.slink.lval_offset);
+ UINT32DECODE(*pp, ent->cache.slink.lval_offset);
break;
default:
- /* Error or unknown type. Bail out. */
- return -1;
- }
+ HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "unknown symbol table entry cache type")
+ } /* end switch */
*pp = p_ret + H5G_SIZEOF_ENTRY(f);
- FUNC_LEAVE_NOAPI(SUCCEED)
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_ent_decode() */
@@ -163,9 +149,6 @@ H5G_ent_decode(H5F_t *f, const uint8_t **pp, H5G_entry_t *ent)
* Purpose: Same as H5G_ent_encode() except it does it for an array of
* symbol table entries.
*
- * Errors:
- * SYM CANTENCODE Can't encode.
- *
* Return: Success: Non-negative, with *pp pointing to the first byte
* after the last symbol.
*
@@ -175,31 +158,29 @@ H5G_ent_decode(H5F_t *f, const uint8_t **pp, H5G_entry_t *ent)
* matzke@llnl.gov
* Jul 18 1997
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
herr_t
H5G_ent_encode_vec(H5F_t *f, uint8_t **pp, const H5G_entry_t *ent, unsigned n)
{
- unsigned u;
- herr_t ret_value=SUCCEED; /* Return value */
+ unsigned u; /* Local index variable */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI(H5G_ent_encode_vec, FAIL);
+ FUNC_ENTER_NOAPI(H5G_ent_encode_vec, FAIL)
/* check arguments */
- assert(f);
- assert(pp);
- assert(ent);
+ HDassert(f);
+ HDassert(pp);
+ HDassert(ent);
/* encode entries */
- for (u = 0; u < n; u++)
- if (H5G_ent_encode(f, pp, ent + u) < 0)
- HGOTO_ERROR(H5E_SYM, H5E_CANTENCODE, FAIL, "can't encode");
+ for(u = 0; u < n; u++)
+ if(H5G_ent_encode(f, pp, ent + u) < 0)
+ HGOTO_ERROR(H5E_SYM, H5E_CANTENCODE, FAIL, "can't encode")
done:
- FUNC_LEAVE_NOAPI(ret_value);
-}
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* H5G_ent_encode_vec() */
/*-------------------------------------------------------------------------
@@ -208,8 +189,6 @@ done:
* Purpose: Encodes the specified symbol table entry into the buffer
* pointed to by *pp.
*
- * Errors:
- *
* Return: Success: Non-negative, with *pp pointing to the first byte
* after the symbol table entry.
*
@@ -219,26 +198,22 @@ done:
* matzke@llnl.gov
* Jul 18 1997
*
- * Modifications:
- *
- * Robb Matzke, 8 Aug 1997
- * Writes zeros for the bytes that aren't used so the file doesn't
- * contain junk.
- *
*-------------------------------------------------------------------------
*/
-static herr_t
-H5G_ent_encode(H5F_t *f, uint8_t **pp, const H5G_entry_t *ent)
+herr_t
+H5G_ent_encode(const H5F_t *f, uint8_t **pp, const H5G_entry_t *ent)
{
- uint8_t *p_ret = *pp + H5G_SIZEOF_ENTRY(f);
+ uint8_t *p_ret = *pp + H5G_SIZEOF_ENTRY(f);
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_ent_encode);
+ FUNC_ENTER_NOAPI(H5G_ent_encode, FAIL)
/* check arguments */
- assert(f);
- assert(pp);
+ HDassert(f);
+ HDassert(pp);
- if (ent) {
+ /* Check for actual entry to encode */
+ if(ent) {
/* encode header */
H5F_ENCODE_LENGTH(f, *pp, ent->name_off);
H5F_addr_encode(f, pp, ent->header);
@@ -246,37 +221,39 @@ H5G_ent_encode(H5F_t *f, uint8_t **pp, const H5G_entry_t *ent)
UINT32ENCODE(*pp, 0); /*reserved*/
/* encode scratch-pad */
- switch (ent->type) {
+ switch(ent->type) {
case H5G_NOTHING_CACHED:
break;
case H5G_CACHED_STAB:
- assert(2 * H5F_SIZEOF_ADDR(f) <= H5G_SIZEOF_SCRATCH);
+ HDassert(2 * H5F_SIZEOF_ADDR(f) <= H5G_SIZEOF_SCRATCH);
H5F_addr_encode(f, pp, ent->cache.stab.btree_addr);
H5F_addr_encode(f, pp, ent->cache.stab.heap_addr);
break;
case H5G_CACHED_SLINK:
- UINT32ENCODE (*pp, ent->cache.slink.lval_offset);
+ UINT32ENCODE(*pp, ent->cache.slink.lval_offset);
break;
default:
- /* Unknown cached type. Bail out. */
- return -1;
- }
- } else {
+ HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "unknown symbol table entry cache type")
+ } /* end switch */
+ } /* end if */
+ else {
H5F_ENCODE_LENGTH(f, *pp, 0);
H5F_addr_encode(f, pp, HADDR_UNDEF);
UINT32ENCODE(*pp, H5G_NOTHING_CACHED);
UINT32ENCODE(*pp, 0); /*reserved*/
- }
+ } /* end else */
/* fill with zero */
- while (*pp < p_ret) *(*pp)++ = 0;
+ while(*pp < p_ret)
+ *(*pp)++ = 0;
*pp = p_ret;
- FUNC_LEAVE_NOAPI(SUCCEED);
-}
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5G_ent_encode() */
/*-------------------------------------------------------------------------
diff --git a/src/H5Gprivate.h b/src/H5Gprivate.h
index 7f001e0..ff20fe6 100644
--- a/src/H5Gprivate.h
+++ b/src/H5Gprivate.h
@@ -129,10 +129,8 @@ typedef struct {
} H5G_name_t;
/* Forward declarations (for prototypes & struct definitions) */
-struct H5P_genplist_t;
struct H5O_loc_t;
struct H5O_link_t;
-struct H5O_t;
/*
* The "location" of an object in a group hierarchy. This points to an object
@@ -181,8 +179,9 @@ H5_DLL herr_t H5G_node_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream
/*
* These functions operate on group object locations.
*/
-H5_DLL herr_t H5G_root_ent_decode(H5F_t *f, const uint8_t **pp);
-H5_DLL herr_t H5G_root_ent_encode(H5F_t *f, uint8_t **pp);
+H5_DLL herr_t H5G_ent_encode(const H5F_t *f, uint8_t **pp,
+ const H5G_entry_t *ent);
+H5_DLL herr_t H5G_ent_decode(H5F_t *f, const uint8_t **pp, H5G_entry_t *ent/*out*/);
/*
* These functions operate on group hierarchy names.
diff --git a/src/H5Groot.c b/src/H5Groot.c
index 9d3fc6f..5d07142 100644
--- a/src/H5Groot.c
+++ b/src/H5Groot.c
@@ -76,99 +76,6 @@ H5G_rootof(H5F_t *f)
/*-------------------------------------------------------------------------
- * Function: H5G_root_ent_decode
- *
- * Purpose: Decodes the root group symbol table entry into the file
- * structure, and updates the root group address in the file
- * structure.
- *
- * Return: Success: Non-negative with *pp pointing to the first byte
- * following the symbol table entry.
- *
- * Failure: Negative
- *
- * Programmer: Quincey Koziol
- * koziol@ncsa.uiuc.edu
- * Sep 26 2005
- *
- *-------------------------------------------------------------------------
- */
-herr_t
-H5G_root_ent_decode(H5F_t *f, const uint8_t **pp)
-{
- const uint8_t *p_ret = *pp + H5G_SIZEOF_ENTRY(f);
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_NOAPI(H5G_root_ent_decode, FAIL)
-
- /* check arguments */
- HDassert(f);
- HDassert(pp);
-
- /* Allocate space for the root group symbol table entry */
- HDassert(!f->shared->root_ent);
- if(NULL == (f->shared->root_ent = (H5G_entry_t *)H5MM_calloc(sizeof(H5G_entry_t))))
- HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "can't allocate space for symbol table entry")
-
- /* decode the root group symbol table entry */
- if(H5G_ent_decode_vec(f, pp, f->shared->root_ent, 1) < 0)
- HGOTO_ERROR(H5E_SYM, H5E_CANTDECODE, FAIL, "can't decode symbol table entry")
-
- /* Set the root group address to the correct value */
- f->shared->root_addr = f->shared->root_ent->header;
-
- /* Set decode pointer */
- *pp = p_ret;
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5G_root_ent_decode() */
-
-
-/*-------------------------------------------------------------------------
- * Function: H5G_root_ent_encode
- *
- * Purpose: Encodes the root group symbol table entry into the buffer
- * pointed to by *pp.
- *
- * Return: Success: Non-negative, with *pp pointing to the first byte
- * after the symbol table entry.
- *
- * Failure: Negative
- *
- * Programmer: Quincey Koziol
- * koziol@ncsa.uiuc.edu
- * Sep 26 2005
- *
- *-------------------------------------------------------------------------
- */
-herr_t
-H5G_root_ent_encode(H5F_t *f, uint8_t **pp)
-{
- uint8_t *p_ret = *pp + H5G_SIZEOF_ENTRY(f);
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_NOAPI(H5G_root_ent_encode, FAIL)
-
- /* check arguments */
- HDassert(f);
- HDassert(f->shared);
- HDassert(f->shared->root_ent);
- HDassert(pp);
-
- /* Encode entry */
- if(H5G_ent_encode_vec(f, pp, f->shared->root_ent, 1) < 0)
- HGOTO_ERROR(H5E_SYM, H5E_CANTENCODE, FAIL, "can't encode symbol table entry")
-
- /* Set encode pointer */
- *pp = p_ret;
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5G_root_ent_encode() */
-
-
-/*-------------------------------------------------------------------------
* Function: H5G_mkroot
*
* Purpose: Creates a root group in an empty file and opens it. If a
@@ -191,12 +98,15 @@ H5G_mkroot(H5F_t *f, hid_t dxpl_id, hbool_t create_root)
{
H5G_loc_t root_loc; /* Root location information */
htri_t stab_exists = -1; /* Whether the symbol table exists */
- herr_t ret_value = SUCCEED; /* Return value */
+ hbool_t sblock_dirty = FALSE; /* Whether superblock was dirtied */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5G_mkroot, FAIL)
/* check args */
HDassert(f);
+ HDassert(f->shared);
+ HDassert(f->shared->sblock);
/* Check if the root group is already initialized */
if(f->shared->root_grp)
@@ -230,7 +140,6 @@ H5G_mkroot(H5F_t *f, hid_t dxpl_id, hbool_t create_root)
H5P_genplist_t *fc_plist; /* File creation property list */
H5O_ginfo_t ginfo; /* Group info parameters */
H5O_linfo_t linfo; /* Link info parameters */
- unsigned super_vers; /* Superblock version */
/* Get the file creation property list */
/* (Which is a sub-class of the group creation property class) */
@@ -245,34 +154,33 @@ H5G_mkroot(H5F_t *f, hid_t dxpl_id, hbool_t create_root)
if(H5P_get(fc_plist, H5G_CRT_LINK_INFO_NAME, &linfo) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get link info")
- /* Get the superblock version */
- if(H5P_get(fc_plist, H5F_CRT_SUPER_VERS_NAME, &super_vers) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get superblock version")
-
/* Create root group */
if(H5G_obj_create(f, dxpl_id, &ginfo, &linfo, f->shared->fcpl_id, root_loc.oloc/*out*/) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create group entry")
if(1 != H5O_link(root_loc.oloc, 1, dxpl_id))
HGOTO_ERROR(H5E_SYM, H5E_LINKCOUNT, FAIL, "internal error (wrong link count)")
+ /* Mark superblock dirty, so root group info is flushed */
+ sblock_dirty = TRUE;
+
/* Create the root group symbol table entry */
- HDassert(!f->shared->root_ent);
- if(super_vers < HDF5_SUPERBLOCK_VERSION_2) {
+ HDassert(!f->shared->sblock->root_ent);
+ if(f->shared->sblock->super_vers < HDF5_SUPERBLOCK_VERSION_2) {
/* Allocate space for the root group symbol table entry */
- if(NULL == (f->shared->root_ent = (H5G_entry_t *) H5MM_calloc(sizeof(H5G_entry_t))))
+ if(NULL == (f->shared->sblock->root_ent = (H5G_entry_t *)H5MM_calloc(sizeof(H5G_entry_t))))
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "can't allocate space for symbol table entry")
/* Initialize the root group symbol table entry */
- f->shared->root_ent->dirty = TRUE;
- f->shared->root_ent->type = H5G_NOTHING_CACHED; /* We will cache the stab later */
- f->shared->root_ent->name_off = 0; /* No name (yet) */
- f->shared->root_ent->header = root_loc.oloc->addr;
- f->shared->root_ent->file = root_loc.oloc->file;
+ f->shared->sblock->root_ent->dirty = TRUE;
+ f->shared->sblock->root_ent->type = H5G_NOTHING_CACHED; /* We will cache the stab later */
+ f->shared->sblock->root_ent->name_off = 0; /* No name (yet) */
+ f->shared->sblock->root_ent->header = root_loc.oloc->addr;
+ f->shared->sblock->root_ent->file = root_loc.oloc->file;
} /* end if */
} /* end if */
else {
/* Create root group object location from f */
- root_loc.oloc->addr = f->shared->root_addr;
+ root_loc.oloc->addr = f->shared->sblock->root_addr;
root_loc.oloc->file = f;
/*
@@ -282,7 +190,7 @@ H5G_mkroot(H5F_t *f, hid_t dxpl_id, hbool_t create_root)
HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open root group")
/* Actions to take if the symbol table information is cached */
- if(f->shared->root_ent && f->shared->root_ent->type == H5G_CACHED_STAB) {
+ if(f->shared->sblock->root_ent && f->shared->sblock->root_ent->type == H5G_CACHED_STAB) {
/* Check for the situation where the symbol table is cached but does
* not exist. This can happen if, for example, an external link is
* added to the root group. */
@@ -291,7 +199,7 @@ H5G_mkroot(H5F_t *f, hid_t dxpl_id, hbool_t create_root)
/* Remove the cache if the stab does not exist */
if(!stab_exists)
- f->shared->root_ent->type = H5G_NOTHING_CACHED;
+ f->shared->sblock->root_ent->type = H5G_NOTHING_CACHED;
#ifndef H5_STRICT_FORMAT_CHECKS
/* If symbol table information is cached, check if we should replace the
* symbol table message with the cached symbol table information */
@@ -299,8 +207,8 @@ H5G_mkroot(H5F_t *f, hid_t dxpl_id, hbool_t create_root)
H5O_stab_t cached_stab;
/* Retrieve the cached symbol table information */
- cached_stab.btree_addr = f->shared->root_ent->cache.stab.btree_addr;
- cached_stab.heap_addr = f->shared->root_ent->cache.stab.heap_addr;
+ cached_stab.btree_addr = f->shared->sblock->root_ent->cache.stab.btree_addr;
+ cached_stab.heap_addr = f->shared->sblock->root_ent->cache.stab.heap_addr;
/* Check if the symbol table message is valid, and replace with the
* cached symbol table if necessary */
@@ -316,8 +224,8 @@ H5G_mkroot(H5F_t *f, hid_t dxpl_id, hbool_t create_root)
* present, so we don't need to check the superblock version. We do this if
* we have write access, the root entry has been allocated (i.e.
* super_vers < 2) and the stab info is not already cached. */
- if((H5F_INTENT(f) & H5F_ACC_RDWR) && stab_exists != FALSE && f->shared->root_ent
- && f->shared->root_ent->type != H5G_CACHED_STAB) {
+ if((H5F_INTENT(f) & H5F_ACC_RDWR) && stab_exists != FALSE && f->shared->sblock->root_ent
+ && f->shared->sblock->root_ent->type != H5G_CACHED_STAB) {
H5O_stab_t stab; /* Symbol table */
/* Check if the stab message exists. It's possible for the root group
@@ -332,9 +240,12 @@ H5G_mkroot(H5F_t *f, hid_t dxpl_id, hbool_t create_root)
HGOTO_ERROR(H5E_SYM, H5E_BADMESG, FAIL, "unable to read symbol table message")
/* Update the root group symbol table entry */
- f->shared->root_ent->type = H5G_CACHED_STAB;
- f->shared->root_ent->cache.stab.btree_addr = stab.btree_addr;
- f->shared->root_ent->cache.stab.heap_addr = stab.heap_addr;
+ f->shared->sblock->root_ent->type = H5G_CACHED_STAB;
+ f->shared->sblock->root_ent->cache.stab.btree_addr = stab.btree_addr;
+ f->shared->sblock->root_ent->cache.stab.heap_addr = stab.heap_addr;
+
+ /* Mark superblock dirty, so root group info is flushed */
+ sblock_dirty = TRUE;
} /* end if */
} /* end if */
@@ -347,7 +258,7 @@ H5G_mkroot(H5F_t *f, hid_t dxpl_id, hbool_t create_root)
* in the number of open objects in the file.
*/
HDassert((1 == f->nopen_objs) ||
- (2 == f->nopen_objs && HADDR_UNDEF != f->shared->extension_addr));
+ (2 == f->nopen_objs && HADDR_UNDEF != f->shared->sblock->ext_addr));
f->nopen_objs--;
done:
@@ -359,10 +270,16 @@ done:
f->shared->root_grp->shared = H5FL_FREE(H5G_shared_t, f->shared->root_grp->shared);
f->shared->root_grp = H5FL_FREE(H5G_t, f->shared->root_grp);
} /* end if */
- f->shared->root_ent = (H5G_entry_t *) H5MM_xfree(f->shared->root_ent);
+ if(f->shared->sblock)
+ f->shared->sblock->root_ent = (H5G_entry_t *)H5MM_xfree(f->shared->sblock->root_ent);
H5G_name_free(root_loc.path);
} /* end if */
+ /* Mark superblock dirty in cache, if necessary */
+ if(sblock_dirty)
+ if(H5AC_mark_pinned_or_protected_entry_dirty(f, f->shared->sblock) < 0)
+ HDONE_ERROR(H5E_FILE, H5E_CANTMARKDIRTY, FAIL, "unable to mark superblock as dirty")
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_mkroot() */
diff --git a/src/H5MF.c b/src/H5MF.c
index dfd1547..639a65f 100644
--- a/src/H5MF.c
+++ b/src/H5MF.c
@@ -719,11 +719,15 @@ H5MF_try_extend(H5F_t *f, hid_t dxpl_id, H5FD_mem_t alloc_type, haddr_t addr,
HDfprintf(stderr, "%s: Entering: alloc_type = %u, addr = %a, size = %Hu, extra_requested = %Hu\n", FUNC, (unsigned)alloc_type, addr, size, extra_requested);
#endif /* H5MF_ALLOC_DEBUG */
+ /* Sanity check */
+ HDassert(f);
+ HDassert(H5F_INTENT(f) & H5F_ACC_RDWR);
+
/* Compute end of block to extend */
end = addr + size;
/* Check if the block is exactly at the end of the file */
- if((ret_value = H5FD_try_extend(f->shared->lf, alloc_type, end, extra_requested)) < 0)
+ if((ret_value = H5FD_try_extend(f->shared->lf, alloc_type, f, end, extra_requested)) < 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTEXTEND, FAIL, "error extending file")
else if(ret_value == FALSE) {
H5F_blk_aggr_t *aggr; /* Aggregator to use */
@@ -757,6 +761,7 @@ HDfprintf(stderr, "%s: Leaving: ret_value = %t\n", FUNC, ret_value);
#ifdef H5MF_ALLOC_DEBUG_DUMP
H5MF_sects_dump(f, dxpl_id, stderr);
#endif /* H5MF_ALLOC_DEBUG_DUMP */
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5MF_try_extend() */
diff --git a/src/H5MFaggr.c b/src/H5MFaggr.c
index 616d705..0b1bc91 100644
--- a/src/H5MFaggr.c
+++ b/src/H5MFaggr.c
@@ -155,8 +155,7 @@ H5MF_aggr_alloc(H5F_t *f, hid_t dxpl_id, H5F_blk_aggr_t *aggr,
hsize_t alignment = 0, mis_align = 0;
haddr_t frag_addr = 0, eoa_frag_addr = 0;
hsize_t frag_size = 0, eoa_frag_size = 0;
- haddr_t eoa = 0, new_space = 0;
- htri_t extended = 0;
+ haddr_t eoa = 0; /* Initial EOA for the file */
H5FD_mem_t alloc_type, other_alloc_type;
haddr_t ret_value; /* Return value */
@@ -202,6 +201,7 @@ HDfprintf(stderr, "%s: aggr = {%a, %Hu, %Hu}\n", FUNC, aggr->addr, aggr->tot_siz
/* Check if the space requested is larger than the space left in the block */
if((size + frag_size) > aggr->size) {
+ htri_t extended = FALSE; /* Whether the file was extended */
/* Check if the block asked for is too large for 'normal' aggregator block */
if(size >= aggr->alloc_size) {
@@ -211,7 +211,7 @@ HDfprintf(stderr, "%s: aggr = {%a, %Hu, %Hu}\n", FUNC, aggr->addr, aggr->tot_siz
if(H5F_addr_gt((aggr->addr + aggr->size + ext_size), f->shared->tmp_addr))
HGOTO_ERROR(H5E_RESOURCE, H5E_BADRANGE, HADDR_UNDEF, "'normal' file space allocation request will overlap into 'temporary' file space")
- if ((aggr->addr > 0) && (extended = H5FD_try_extend(f->shared->lf, alloc_type, aggr->addr + aggr->size, ext_size)) < 0)
+ if ((aggr->addr > 0) && (extended = H5FD_try_extend(f->shared->lf, alloc_type, f, aggr->addr + aggr->size, ext_size)) < 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, HADDR_UNDEF, "can't extending space")
else if (extended) {
/* aggr->size is unchanged */
@@ -226,7 +226,7 @@ HDfprintf(stderr, "%s: aggr = {%a, %Hu, %Hu}\n", FUNC, aggr->addr, aggr->tot_siz
if ((other_aggr->size > 0) && (H5F_addr_eq((other_aggr->addr + other_aggr->size), eoa)) &&
((other_aggr->tot_size - other_aggr->size) >= other_aggr->alloc_size)) {
- if(H5FD_free(f->shared->lf, dxpl_id, other_alloc_type, other_aggr->addr, other_aggr->size) < 0)
+ if(H5FD_free(f->shared->lf, dxpl_id, other_alloc_type, f, other_aggr->addr, other_aggr->size) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTFREE, HADDR_UNDEF, "can't free aggregation block")
other_aggr->addr = 0;
@@ -235,11 +235,8 @@ HDfprintf(stderr, "%s: aggr = {%a, %Hu, %Hu}\n", FUNC, aggr->addr, aggr->tot_siz
} /* end if */
/* Allocate space from the VFD (i.e. at the end of the file) */
- if(HADDR_UNDEF == (new_space = H5FD_alloc(f->shared->lf, dxpl_id, type, size, &eoa_frag_addr, &eoa_frag_size)))
+ if(HADDR_UNDEF == (ret_value = H5FD_alloc(f->shared->lf, dxpl_id, type, f, size, &eoa_frag_addr, &eoa_frag_size)))
HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, HADDR_UNDEF, "can't allocate aggregation block")
-
- /* Use the new space allocated, leaving the old block */
- ret_value = new_space;
} /* end else */
} /* end if */
else {
@@ -257,13 +254,15 @@ HDfprintf(stderr, "%s: Allocating block\n", FUNC);
if(H5F_addr_gt((aggr->addr + aggr->size + ext_size), f->shared->tmp_addr))
HGOTO_ERROR(H5E_RESOURCE, H5E_BADRANGE, HADDR_UNDEF, "'normal' file space allocation request will overlap into 'temporary' file space")
- if((aggr->addr > 0) && (extended = H5FD_try_extend(f->shared->lf, alloc_type, aggr->addr + aggr->size, ext_size)) < 0)
+ if((aggr->addr > 0) && (extended = H5FD_try_extend(f->shared->lf, alloc_type, f, aggr->addr + aggr->size, ext_size)) < 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, HADDR_UNDEF, "can't extending space")
else if (extended) {
aggr->addr += frag_size;
aggr->size += (ext_size - frag_size);
aggr->tot_size += ext_size;
} else {
+ haddr_t new_space; /* Address of new space allocated */
+
/* Check for overlapping into file's temporary allocation space */
if(H5F_addr_gt((eoa + aggr->alloc_size), f->shared->tmp_addr))
HGOTO_ERROR(H5E_RESOURCE, H5E_BADRANGE, HADDR_UNDEF, "'normal' file space allocation request will overlap into 'temporary' file space")
@@ -271,7 +270,7 @@ HDfprintf(stderr, "%s: Allocating block\n", FUNC);
if((other_aggr->size > 0) && (H5F_addr_eq((other_aggr->addr + other_aggr->size), eoa)) &&
((other_aggr->tot_size - other_aggr->size) >= other_aggr->alloc_size)) {
- if(H5FD_free(f->shared->lf, dxpl_id, other_alloc_type, other_aggr->addr, other_aggr->size) < 0)
+ if(H5FD_free(f->shared->lf, dxpl_id, other_alloc_type, f, other_aggr->addr, other_aggr->size) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTFREE, HADDR_UNDEF, "can't free aggregation block")
other_aggr->addr = 0;
other_aggr->tot_size = 0;
@@ -279,7 +278,7 @@ HDfprintf(stderr, "%s: Allocating block\n", FUNC);
} /* end if */
/* Allocate space from the VFD (i.e. at the end of the file) */
- if(HADDR_UNDEF == (new_space = H5FD_alloc(f->shared->lf, dxpl_id, alloc_type, aggr->alloc_size, &eoa_frag_addr, &eoa_frag_size)))
+ if(HADDR_UNDEF == (new_space = H5FD_alloc(f->shared->lf, dxpl_id, alloc_type, f, aggr->alloc_size, &eoa_frag_addr, &eoa_frag_size)))
HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, HADDR_UNDEF, "can't allocate aggregation block")
/* Return the unused portion of the block to a free list */
@@ -327,8 +326,9 @@ HDfprintf(stderr, "%s: Allocating block\n", FUNC);
HGOTO_ERROR(H5E_RESOURCE, H5E_BADRANGE, HADDR_UNDEF, "'normal' file space allocation request will overlap into 'temporary' file space")
/* Allocate data from the file */
- if(HADDR_UNDEF == (ret_value = H5FD_alloc(f->shared->lf, dxpl_id, type, size, &eoa_frag_addr, &eoa_frag_size)))
+ if(HADDR_UNDEF == (ret_value = H5FD_alloc(f->shared->lf, dxpl_id, type, f, size, &eoa_frag_addr, &eoa_frag_size)))
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, HADDR_UNDEF, "can't allocate file space")
+
/* Check if fragment was generated */
if(eoa_frag_size)
/* Put fragment on the free list */
@@ -343,6 +343,7 @@ done:
#ifdef H5MF_AGGR_DEBUG
HDfprintf(stderr, "%s: ret_value = %a\n", FUNC, ret_value);
#endif /* H5MF_AGGR_DEBUG */
+
if(alignment)
HDassert(!(ret_value % alignment));
FUNC_LEAVE_NOAPI(ret_value)
@@ -386,7 +387,7 @@ H5MF_aggr_try_extend(const H5F_t *f, H5F_blk_aggr_t *aggr, H5FD_mem_t type,
/* If the aggregator block is at the end of the file, extend the
* file and "bubble" the aggregator up
*/
- if((ret_value = H5FD_try_extend(f->shared->lf, type, (aggr->addr + aggr->size), extra_requested)) < 0)
+ if((ret_value = H5FD_try_extend(f->shared->lf, type, f, (aggr->addr + aggr->size), extra_requested)) < 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTEXTEND, FAIL, "error extending file")
else if(ret_value == TRUE) {
/* Shift the aggregator block by the extra requested */
@@ -638,8 +639,8 @@ HDfprintf(stderr, "%s: tmp_addr = %a, tmp_size = %Hu\n", FUNC, tmp_addr, tmp_siz
aggr->size = 0;
/* Return the unused portion of the metadata block to the file */
- if(tmp_size > 0)
- if(H5FD_free(f->shared->lf, dxpl_id, alloc_type, tmp_addr, tmp_size) < 0)
+ if(tmp_size > 0 && (H5F_INTENT(f) & H5F_ACC_RDWR))
+ if(H5FD_free(f->shared->lf, dxpl_id, alloc_type, f, tmp_addr, tmp_size) < 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTFREE, FAIL, "can't free space")
} /* end if */
diff --git a/src/H5MFsection.c b/src/H5MFsection.c
index 0dc43c3..d10b6b1 100644
--- a/src/H5MFsection.c
+++ b/src/H5MFsection.c
@@ -404,8 +404,11 @@ H5MF_sect_simple_shrink(H5FS_section_info_t **_sect, void *_udata)
/* Check for shrinking file */
if(H5MF_SHRINK_EOA == udata->shrink) {
+ /* Sanity check */
+ HDassert(H5F_INTENT(udata->f) & H5F_ACC_RDWR);
+
/* Release section's space at EOA with file driver */
- if(H5FD_free(udata->f->shared->lf, udata->dxpl_id, udata->alloc_type, (*sect)->sect_info.addr, (*sect)->sect_info.size) < 0)
+ if(H5FD_free(udata->f->shared->lf, udata->dxpl_id, udata->alloc_type, udata->f, (*sect)->sect_info.addr, (*sect)->sect_info.size) < 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTFREE, FAIL, "driver free request failed")
} /* end if */
else {
diff --git a/src/Makefile.am b/src/Makefile.am
index eb264f2..fb73bbf 100755
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -54,7 +54,7 @@ libhdf5_la_SOURCES= H5.c H5checksum.c H5dbg.c H5system.c H5timer.c H5trace.c \
H5EA.c H5EAcache.c H5EAdbg.c H5EAdblkpage.c H5EAdblock.c H5EAhdr.c \
H5EAiblock.c H5EAint.c H5EAsblock.c H5EAstat.c H5EAtest.c \
H5F.c H5Faccum.c H5Fdbg.c H5Ffake.c H5Fio.c H5Fmount.c H5Fmpi.c H5Fquery.c \
- H5Fsfile.c H5Fsuper.c H5Ftest.c \
+ H5Fsfile.c H5Fsuper.c H5Fsuper_cache.c H5Ftest.c \
H5FA.c H5FAcache.c H5FAdbg.c H5FAdblock.c H5FAdblkpage.c H5FAhdr.c \
H5FAstat.c H5FAtest.c \
H5FD.c H5FDcore.c \
diff --git a/src/Makefile.in b/src/Makefile.in
index 3126c7b..cc096cf 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -107,34 +107,35 @@ am_libhdf5_la_OBJECTS = H5.lo H5checksum.lo H5dbg.lo H5system.lo \
H5EAdblkpage.lo H5EAdblock.lo H5EAhdr.lo H5EAiblock.lo \
H5EAint.lo H5EAsblock.lo H5EAstat.lo H5EAtest.lo H5F.lo \
H5Faccum.lo H5Fdbg.lo H5Ffake.lo H5Fio.lo H5Fmount.lo \
- H5Fmpi.lo H5Fquery.lo H5Fsfile.lo H5Fsuper.lo H5Ftest.lo \
- H5FA.lo H5FAcache.lo H5FAdbg.lo H5FAdblock.lo H5FAdblkpage.lo \
- H5FAhdr.lo H5FAstat.lo H5FAtest.lo H5FD.lo H5FDcore.lo \
- H5FDdirect.lo H5FDfamily.lo H5FDint.lo H5FDlog.lo H5FDmpi.lo \
- H5FDmpio.lo H5FDmpiposix.lo H5FDmulti.lo H5FDsec2.lo \
- H5FDspace.lo H5FDstdio.lo H5FL.lo H5FO.lo H5FS.lo H5FScache.lo \
- H5FSdbg.lo H5FSsection.lo H5FSstat.lo H5FStest.lo H5G.lo \
- H5Gbtree2.lo H5Gcache.lo H5Gcompact.lo H5Gdense.lo \
- H5Gdeprec.lo H5Gent.lo H5Gint.lo H5Glink.lo H5Gloc.lo \
- H5Gname.lo H5Gnode.lo H5Gobj.lo H5Goh.lo H5Groot.lo H5Gstab.lo \
- H5Gtest.lo H5Gtraverse.lo H5HF.lo H5HFbtree2.lo H5HFcache.lo \
- H5HFdbg.lo H5HFdblock.lo H5HFdtable.lo H5HFhdr.lo H5HFhuge.lo \
- H5HFiblock.lo H5HFiter.lo H5HFman.lo H5HFsection.lo \
- H5HFspace.lo H5HFstat.lo H5HFtest.lo H5HFtiny.lo H5HG.lo \
- H5HGcache.lo H5HGdbg.lo H5HL.lo H5HLcache.lo H5HLdbg.lo \
- H5HP.lo H5I.lo H5L.lo H5Lexternal.lo H5MF.lo H5MFaggr.lo \
- H5MFdbg.lo H5MFsection.lo H5MM.lo H5MP.lo H5MPtest.lo H5O.lo \
- H5Oainfo.lo H5Oalloc.lo H5Oattr.lo H5Oattribute.lo H5Obogus.lo \
- H5Obtreek.lo H5Ocache.lo H5Ocont.lo H5Ocopy.lo H5Odbg.lo \
- H5Odrvinfo.lo H5Odtype.lo H5Oefl.lo H5Ofill.lo H5Oginfo.lo \
- H5Olayout.lo H5Olinfo.lo H5Olink.lo H5Omessage.lo H5Omtime.lo \
- H5Oname.lo H5Onull.lo H5Opline.lo H5Orefcount.lo H5Osdspace.lo \
- H5Oshared.lo H5Ostab.lo H5Oshmesg.lo H5Otest.lo H5Ounknown.lo \
- H5P.lo H5Pacpl.lo H5Pdapl.lo H5Pdcpl.lo H5Pdeprec.lo \
- H5Pdxpl.lo H5Pfapl.lo H5Pfcpl.lo H5Pfmpl.lo H5Pgcpl.lo \
- H5Pint.lo H5Plapl.lo H5Plcpl.lo H5Pocpl.lo H5Pocpypl.lo \
- H5Pstrcpl.lo H5Ptest.lo H5R.lo H5Rdeprec.lo H5RC.lo H5RS.lo \
- H5S.lo H5Sall.lo H5Sdbg.lo H5Shyper.lo H5Smpio.lo H5Snone.lo \
+ H5Fmpi.lo H5Fquery.lo H5Fsfile.lo H5Fsuper.lo \
+ H5Fsuper_cache.lo H5Ftest.lo H5FA.lo H5FAcache.lo H5FAdbg.lo \
+ H5FAdblock.lo H5FAdblkpage.lo H5FAhdr.lo H5FAstat.lo \
+ H5FAtest.lo H5FD.lo H5FDcore.lo H5FDdirect.lo H5FDfamily.lo \
+ H5FDint.lo H5FDlog.lo H5FDmpi.lo H5FDmpio.lo H5FDmpiposix.lo \
+ H5FDmulti.lo H5FDsec2.lo H5FDspace.lo H5FDstdio.lo H5FL.lo \
+ H5FO.lo H5FS.lo H5FScache.lo H5FSdbg.lo H5FSsection.lo \
+ H5FSstat.lo H5FStest.lo H5G.lo H5Gbtree2.lo H5Gcache.lo \
+ H5Gcompact.lo H5Gdense.lo H5Gdeprec.lo H5Gent.lo H5Gint.lo \
+ H5Glink.lo H5Gloc.lo H5Gname.lo H5Gnode.lo H5Gobj.lo H5Goh.lo \
+ H5Groot.lo H5Gstab.lo H5Gtest.lo H5Gtraverse.lo H5HF.lo \
+ H5HFbtree2.lo H5HFcache.lo H5HFdbg.lo H5HFdblock.lo \
+ H5HFdtable.lo H5HFhdr.lo H5HFhuge.lo H5HFiblock.lo H5HFiter.lo \
+ H5HFman.lo H5HFsection.lo H5HFspace.lo H5HFstat.lo H5HFtest.lo \
+ H5HFtiny.lo H5HG.lo H5HGcache.lo H5HGdbg.lo H5HL.lo \
+ H5HLcache.lo H5HLdbg.lo H5HP.lo H5I.lo H5L.lo H5Lexternal.lo \
+ H5MF.lo H5MFaggr.lo H5MFdbg.lo H5MFsection.lo H5MM.lo H5MP.lo \
+ H5MPtest.lo H5O.lo H5Oainfo.lo H5Oalloc.lo H5Oattr.lo \
+ H5Oattribute.lo H5Obogus.lo H5Obtreek.lo H5Ocache.lo \
+ H5Ocont.lo H5Ocopy.lo H5Odbg.lo H5Odrvinfo.lo H5Odtype.lo \
+ H5Oefl.lo H5Ofill.lo H5Oginfo.lo H5Olayout.lo H5Olinfo.lo \
+ H5Olink.lo H5Omessage.lo H5Omtime.lo H5Oname.lo H5Onull.lo \
+ H5Opline.lo H5Orefcount.lo H5Osdspace.lo H5Oshared.lo \
+ H5Ostab.lo H5Oshmesg.lo H5Otest.lo H5Ounknown.lo H5P.lo \
+ H5Pacpl.lo H5Pdapl.lo H5Pdcpl.lo H5Pdeprec.lo H5Pdxpl.lo \
+ H5Pfapl.lo H5Pfcpl.lo H5Pfmpl.lo H5Pgcpl.lo H5Pint.lo \
+ H5Plapl.lo H5Plcpl.lo H5Pocpl.lo H5Pocpypl.lo H5Pstrcpl.lo \
+ H5Ptest.lo H5R.lo H5Rdeprec.lo H5RC.lo H5RS.lo H5S.lo \
+ H5Sall.lo H5Sdbg.lo H5Shyper.lo H5Smpio.lo H5Snone.lo \
H5Spoint.lo H5Sselect.lo H5Stest.lo H5SL.lo H5SM.lo \
H5SMbtree2.lo H5SMcache.lo H5SMtest.lo H5ST.lo H5T.lo \
H5Tarray.lo H5Tbit.lo H5Tcommit.lo H5Tcompound.lo H5Tconv.lo \
@@ -460,7 +461,7 @@ libhdf5_la_SOURCES = H5.c H5checksum.c H5dbg.c H5system.c H5timer.c H5trace.c \
H5EA.c H5EAcache.c H5EAdbg.c H5EAdblkpage.c H5EAdblock.c H5EAhdr.c \
H5EAiblock.c H5EAint.c H5EAsblock.c H5EAstat.c H5EAtest.c \
H5F.c H5Faccum.c H5Fdbg.c H5Ffake.c H5Fio.c H5Fmount.c H5Fmpi.c H5Fquery.c \
- H5Fsfile.c H5Fsuper.c H5Ftest.c \
+ H5Fsfile.c H5Fsuper.c H5Fsuper_cache.c H5Ftest.c \
H5FA.c H5FAcache.c H5FAdbg.c H5FAdblock.c H5FAdblkpage.c H5FAhdr.c \
H5FAstat.c H5FAtest.c \
H5FD.c H5FDcore.c \
@@ -736,6 +737,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Fquery.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Fsfile.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Fsuper.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Fsuper_cache.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Ftest.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5G.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Gbtree2.Plo@am__quote@