summaryrefslogtreecommitdiffstats
path: root/src/H5G.c
diff options
context:
space:
mode:
authorRobb Matzke <matzke@llnl.gov>1998-01-06 03:07:15 (GMT)
committerRobb Matzke <matzke@llnl.gov>1998-01-06 03:07:15 (GMT)
commit1d17defdfc977c063c7ff20b5868bef9a76e5d9a (patch)
tree718aad3e93d1406d4a97a0fcafeb3f7acd8720db /src/H5G.c
parentdfff2572ca834f41d27510244d2886170626b265 (diff)
downloadhdf5-1d17defdfc977c063c7ff20b5868bef9a76e5d9a.zip
hdf5-1d17defdfc977c063c7ff20b5868bef9a76e5d9a.tar.gz
hdf5-1d17defdfc977c063c7ff20b5868bef9a76e5d9a.tar.bz2
[svn-r150] Changes since 19971219
---------------------- ./src/H5private.h Changed HDF5_MAJOR_VERSION to 5 ./src/H5Aprivate.h ./src/H5Apublic.h Added group atoms. ./src/H5D.c ./src/H5P.c ./test/istore.c ./test/tohdr.c ./test/tstab.c Updated for symbol table interface changes. ./src/H5F.c ./src/H5Fprivate.h Simpler handling of special case files: empty files and files with a single object. ./src/H5G.c ./src/H5Gent.c ./src/H5Gnode.c ./src/H5Gpkg.h ./src/H5Gprivate.h ./src/H5Gpublic.h ./src/H5Gshad.c (DELETED) ./src/H5Gstab.c ./src/Makefile.in Removed shadows, simplifying code. Symbol table entries are allowed to cache only constant meta data. Fixed naming. ./src/H5O.c ./src/H5Oprivate.h Access to object headers is always done through a symbol table entry instead of a file address. Added stubs for opening and closing object headers to be used when deletion is implemented.
Diffstat (limited to 'src/H5G.c')
-rw-r--r--src/H5G.c1143
1 files changed, 583 insertions, 560 deletions
diff --git a/src/H5G.c b/src/H5G.c
index 25c5fc4..167de09 100644
--- a/src/H5G.c
+++ b/src/H5G.c
@@ -28,15 +28,13 @@
* Robb Matzke, 30 Aug 1997
* Added `Errors:' field to function prologues.
*
- * Robb Matzke, 18 Sep 1997
- * Added shadow entry support.
- *
*-------------------------------------------------------------------------
*/
#define H5G_PACKAGE /*suppress error message about including H5Gpkg.h*/
/* Packages needed by this file... */
#include <H5private.h>
+#include <H5Aprivate.h>
#include <H5Bprivate.h>
#include <H5Eprivate.h>
#include <H5Gpkg.h>
@@ -45,37 +43,38 @@
#include <H5Oprivate.h>
#define H5G_INIT_HEAP 8192
+#define H5G_RESERVED_ATOMS 0
#define PABLO_MASK H5G_mask
/* Interface initialization */
static hbool_t interface_initialize_g = FALSE;
-#define INTERFACE_INIT NULL
+#define INTERFACE_INIT H5G_init_interface
+static herr_t H5G_init_interface (void);
+static void H5G_term_interface (void);
+
+static H5G_entry_t *H5G_getcwg (H5F_t *f);
/*-------------------------------------------------------------------------
- * Function: H5Gnew
+ * Function: H5Gcreate
*
* Purpose: Creates a new group in FILE and gives it the specified
* NAME. Unless NAME begins with `/' it is relative to the
- * current working group.
+ * current working group. The group is opened for write access
+ * and it's object ID is returned.
*
* The optional SIZE_HINT specifies how much file space to
* reserve to store the names that will appear in this
- * group (an even number of characters, counting the null
- * terminator, is allocated for each name). If a non-positive
- * value is supplied for the SIZE_HINT then a default size is
- * chosen.
+ * group. If a non-positive value is supplied for the SIZE_HINT
+ * then a default size is chosen.
*
* See also: H5Gset(), H5Gpush(), H5Gpop()
*
* Errors:
- * ARGS BADTYPE Not a file atom.
- * ARGS BADVALUE No name given.
- * ATOM BADATOM Can't unatomize file.
- * SYM CANTINIT Can't close handle.
- * SYM CANTINIT Can't create group.
*
- * Return: Success: SUCCEED
+ * Return: Success: The object ID of a new, empty group open for
+ * writing. Call H5Gclose() when finished with
+ * the group.
*
* Failure: FAIL
*
@@ -86,47 +85,139 @@ static hbool_t interface_initialize_g = FALSE;
*
*-------------------------------------------------------------------------
*/
-herr_t
-H5Gnew (hid_t file, const char *name, size_t size_hint)
+hid_t
+H5Gcreate (hid_t file_id, const char *name, size_t size_hint)
{
- H5F_t *f=NULL;
- H5G_entry_t *grp_handle=NULL;
+ H5F_t *f = NULL;
+ H5G_t *grp;
+ hid_t ret_value = FAIL;
- FUNC_ENTER (H5Gnew, FAIL);
+ FUNC_ENTER (H5Gcreate, FAIL);
+ H5ECLEAR;
- /* Check/fix arguments */
+ /* Check arguments */
+ if (H5_FILE!=H5Aatom_group (file_id) ||
+ NULL==(f=H5Aatom_object (file_id))) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a file");
+ }
if (!name || !*name) {
HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "no name given");
}
- if (H5_FILE!=H5Aatom_group (file)) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a file atom");
+
+ /* Create the group */
+ if (NULL==(grp=H5G_create (f, name, size_hint))) {
+ HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL, "unable to create group");
}
- if (NULL==(f=H5Aatom_object (file))) {
- HRETURN_ERROR (H5E_ATOM, H5E_BADATOM, FAIL, "can't unatomize file");
+
+ if ((ret_value = H5Aregister_atom (H5_GROUP, grp))<0) {
+ H5G_close (grp);
+ HRETURN_ERROR (H5E_ATOM, H5E_CANTREGISTER, FAIL,
+ "unable to register group");
}
+
+ FUNC_LEAVE (ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5Gopen
+ *
+ * Purpose: Opens an existing group for modification. When finished,
+ * call H5Gclose() to close it and release resources.
+ *
+ * Errors:
+ *
+ * Return: Success: Object ID of the group.
+ *
+ * Failure: FAIL
+ *
+ * Programmer: Robb Matzke
+ * Wednesday, December 31, 1997
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+hid_t
+H5Gopen (hid_t file_id, const char *name)
+{
+ hid_t ret_value = FAIL;
+ H5F_t *f = NULL;
+ H5G_t *grp = NULL;
- /* Create the group */
- if (NULL==(grp_handle=H5G_new (f, name, size_hint))) {
- HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL,
- "can't create group");
+ FUNC_ENTER (H5Gopen, FAIL);
+ H5ECLEAR;
+
+ /* Check args */
+ if (H5_FILE!=H5Aatom_group (file_id) ||
+ NULL==(f=H5Aatom_object (file_id))) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a file");
+ }
+ if (!name || !*name) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "no name");
}
- /* Close the group handle */
- if (H5G_close (f, grp_handle)<0) {
- HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL, "can't close handle");
+ /* Open the group */
+ if (NULL==(grp=H5G_open (f, name))) {
+ HRETURN_ERROR (H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open group");
}
- FUNC_LEAVE (SUCCEED);
+ /* Register an atom for the group */
+ if ((ret_value=H5Aregister_atom (H5_GROUP, grp))<0) {
+ H5G_close (grp);
+ HRETURN_ERROR (H5E_ATOM, H5E_CANTREGISTER, FAIL,
+ "unable to register group");
+ }
+
+ FUNC_LEAVE (ret_value);
}
+
+/*-------------------------------------------------------------------------
+ * Function: H5Gclose
+ *
+ * Purpose: Closes the specified group. The group ID will no longer be
+ * valid for accessing the group.
+ *
+ * Return: Success: SUCCEED
+ *
+ * Failure: FAIL
+ *
+ * Programmer: Robb Matzke
+ * Wednesday, December 31, 1997
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5Gclose (hid_t grp_id)
+{
+ H5G_t *grp = NULL;
+
+ FUNC_ENTER (H5Gclose, FAIL);
+ H5ECLEAR;
+
+ /* Check args */
+ if (H5_GROUP!=H5Aatom_group (grp_id) ||
+ NULL==(grp=H5Aatom_object (grp_id))) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a group");
+ }
+
+ /* close it */
+ if (H5G_close (grp)<0) {
+ HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL, "unable to close group");
+ }
+
+ FUNC_LEAVE (SUCCEED);
+}
/*-------------------------------------------------------------------------
* Function: H5Gset
*
* Purpose: Sets the working group for file handle FILE to the
- * specified NAME. Unless NAME begins with a `/' it is
- * interpretted relative to the current working group.
+ * specified group.
*
* Each file handle maintains its own notion of the current
* working group. That is, if a single file is opened with
@@ -137,10 +228,6 @@ H5Gnew (hid_t file, const char *name, size_t size_hint)
* See also: H5Gpush(), H5Gpop()
*
* Errors:
- * ARGS BADTYPE Not a file atom.
- * ARGS BADVALUE No name given.
- * ATOM BADATOM Can't unatomize file.
- * SYM CANTINIT Can't change current working group.
*
* Return: Success: SUCCEED
*
@@ -154,32 +241,33 @@ H5Gnew (hid_t file, const char *name, size_t size_hint)
*-------------------------------------------------------------------------
*/
herr_t
-H5Gset (hid_t file, const char *name)
+H5Gset (hid_t file_id, hid_t grp_id)
{
H5F_t *f=NULL;
+ H5G_t *grp;
FUNC_ENTER (H5Gset, FAIL);
+ H5ECLEAR;
/* Check/fix arguments */
- if (!name || !*name) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "no name given");
- }
- if (H5_FILE!=H5Aatom_group (file)) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a file atom");
+ if (H5_FILE!=H5Aatom_group (file_id) ||
+ NULL==(f=H5Aatom_object (file_id))) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a file");
}
- if (NULL==(f=H5Aatom_object (file))) {
- HRETURN_ERROR (H5E_ATOM, H5E_BADATOM, FAIL, "can't unatomize file");
+ if (H5_GROUP!=H5Aatom_group (grp_id) ||
+ NULL==(grp=H5Aatom_object (grp_id))) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a group");
}
- if (H5G_set (f, name)<0) {
+ /* Set the current working group */
+ if (H5G_set (f, grp)<0) {
HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL,
- "can't change current working group");
+ "unable to change current working group");
}
FUNC_LEAVE (SUCCEED);
}
-
/*-------------------------------------------------------------------------
* Function: H5Gpush
@@ -196,10 +284,6 @@ H5Gset (hid_t file, const char *name)
* See also: H5Gset(), H5Gpop()
*
* Errors:
- * ARGS BADTYPE Not a file atom.
- * ARGS BADVALUE No name given.
- * ATOM BADATOM Can't unatomize file.
- * SYM CANTINIT Can't change current working group.
*
* Return: Success: SUCCEED
*
@@ -213,24 +297,26 @@ H5Gset (hid_t file, const char *name)
*-------------------------------------------------------------------------
*/
herr_t
-H5Gpush (hid_t file, const char *name)
+H5Gpush (hid_t file_id, hid_t grp_id)
{
H5F_t *f=NULL;
+ H5G_t *grp;
FUNC_ENTER (H5Gpush, FAIL);
+ H5ECLEAR;
- /* Check/fix arguments */
- if (!name || !*name) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "no name given");
+ /* Check arguments */
+ if (H5_FILE!=H5Aatom_group (file_id) ||
+ NULL==(f=H5Aatom_object (file_id))) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a file");
}
- if (H5_FILE!=H5Aatom_group (file)) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a file atom");
+ if (H5_GROUP!=H5Aatom_group (grp_id) ||
+ NULL==(grp=H5Aatom_object (grp_id))) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a group");
}
- if (NULL==(f=H5Aatom_object (file))) {
- HRETURN_ERROR (H5E_ATOM, H5E_BADATOM, FAIL, "can't unatomize file");
- }
-
- if (H5G_push (f, name)<0) {
+
+ /* Push group onto stack */
+ if (H5G_push (f, grp)<0) {
HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL,
"can't change current working group");
}
@@ -238,7 +324,6 @@ H5Gpush (hid_t file, const char *name)
FUNC_LEAVE (SUCCEED);
}
-
/*-------------------------------------------------------------------------
* Function: H5Gpop
@@ -255,9 +340,6 @@ H5Gpush (hid_t file, const char *name)
* See also: H5Gset(), H5Gpush()
*
* Errors:
- * ARGS BADTYPE Not a file atom.
- * ATOM BADATOM Can't unatomize file.
- * SYM CANTINIT Stack is empty.
*
* Return: Success: SUCCEED
*
@@ -273,20 +355,20 @@ H5Gpush (hid_t file, const char *name)
*-------------------------------------------------------------------------
*/
herr_t
-H5Gpop (hid_t file)
+H5Gpop (hid_t file_id)
{
H5F_t *f=NULL;
FUNC_ENTER (H5Gpop, FAIL);
-
- /* Check/fix arguments */
- if (H5_FILE!=H5Aatom_group (file)) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a file atom");
- }
- if (NULL==(f=H5Aatom_object (file))) {
- HRETURN_ERROR (H5E_ATOM, H5E_BADATOM, FAIL, "can't unatomize file");
+ H5ECLEAR;
+
+ /* Check arguments */
+ if (H5_FILE!=H5Aatom_group (file_id) ||
+ NULL==(f=H5Aatom_object (file_id))) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a file");
}
+ /* pop */
if (H5G_pop (f)<0) {
HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL,
"stack is empty");
@@ -307,9 +389,59 @@ H5Gpop (hid_t file)
*/
+
+/*-------------------------------------------------------------------------
+ * Function: H5G_init_interface
+ *
+ * Purpose: Initializes the H5G interface.
+ *
+ * Return: Success: SUCCEED
+ *
+ * Failure: FAIL
+ *
+ * Programmer: Robb Matzke
+ * Monday, January 5, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5G_init_interface (void)
+{
+ FUNC_ENTER (H5G_init_interface, FAIL);
+ /* Initialize the atom group for the group IDs */
+ if (H5Ainit_group (H5_GROUP, H5A_GROUPID_HASHSIZE, H5G_RESERVED_ATOMS,
+ (herr_t (*)(void*))H5G_close)<0 ||
+ H5_add_exit (H5G_term_interface)<0) {
+ HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL,
+ "unable to initialize interface");
+ }
+
+ FUNC_LEAVE (SUCCEED);
+}
-
+
+/*-------------------------------------------------------------------------
+ * Function: H5G_term_interface
+ *
+ * Purpose: Terminates the H5G interface
+ *
+ * Return: void
+ *
+ * Programmer: Robb Matzke
+ * Monday, January 5, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+H5G_term_interface (void)
+{
+ H5Adestroy_group (H5_GROUP);
+}
/*-------------------------------------------------------------------------
@@ -348,57 +480,58 @@ H5G_component (const char *name, size_t *size_p)
/*-------------------------------------------------------------------------
* Function: H5G_namei
*
- * Purpose: (Partially) translates a name to a symbol table entry.
- *
- * Given a name (absolute or relative) return the symbol table
- * entry for that name and for the group that contains the
- * base name. These entries (GRP_ENT and BASE_ENT) are returned
- * through memory passed into the function by the caller. Either
- * or both pointers may be null. Absolute names are looked up
- * relative to the root group of file F while relative
- * names are traversed beginning at the CWG argument.
- *
- * Consecutive slash characters are treated like single
- * slash characters. Trailing slashes are ignored. The
- * component `.' is recognized as the current group
- * during the traversal (initially CWG), but the component
- * `..' is not internally recognized (it is recognized if
- * such a name appears in the symbol table).
- *
- * If the name cannot be fully resolved, then REST will
- * point to the part of NAME where the traversal failed
- * (REST will always point to a relative name) and this
- * function will return null. GRP_ENT will be initialized with
- * information about the group (or other object) at which
- * the traversal failed. However, if the name can be fully
- * resolved, then REST points to the null terminator of NAME.
- *
- * As a special case, if the NAME is the name `/' (or
- * equivalent) then GRP_ENT is initialized to all zero
- * and an invalid header address and a pointer to the root
- * symbol table entry is returned.
- *
- * As a special case, if the NAME is the string `/foo' (or
- * equivalent) and the root symbol table entry points to a
- * non-group object with a name message with the value
- * `foo' then GRP_ENT is initialized to all zero (except for an
- * invalid header address) and a pointer to the root symbol
- * table entry is returned.
- *
+ * Purpose: Translates a name to a symbol table entry.
+ *
+ * If the specified name can be fully resolved, then this
+ * function returns the symbol table entry for the named object
+ * through the OBJ_ENT argument. The symbol table entry for the
+ * group containing the named object is returned through the
+ * GRP_ENT argument if it is non-null. However, if the name
+ * refers to the root object then the GRP_ENT will be
+ * initialized with an undefined object header address. The
+ * REST argument, if present, will point to the null terminator
+ * of NAME.
+ *
+ * If the specified name cannot be fully resolved, then OBJ_ENT
+ * is initialized with the undefined object header address. The
+ * REST argument will point into the NAME argument to the start
+ * of the component that could not be located. The GRP_ENT will
+ * contain the entry for the symbol table that was being
+ * searched at the time of the failure and will have an
+ * undefined object header address if the search failed at the
+ * root object. For instance, if NAME is `/foo/bar/baz' and the
+ * root directory exists and contains an entry for `foo', and
+ * foo is a group that contains an entry for baz, but baz is not
+ * a group, then the results will be that REST points to `baz',
+ * GRP_ENT has an undefined object header address, and GRP_ENT
+ * is the symbol table entry for `bar' in `/foo'.
+ *
+ * If a file contains more than one object, then `/' is the name
+ * of the root object which is a group. Otherwise, a file can
+ * consist of a single object, not necessarily a group, whose
+ * name is `/foo' where `foo' is the value of the name messsage
+ * in the object header. A file can also contain no objects in
+ * which case the function returns so REST points to the
+ * beginning of NAME and OBJ_ENT and GRP_ENT contain undefined
+ * header addresses.
+ *
+ * Components of a name are separated from one another by one or
+ * more slashes (/). Slashes at the end of a name are ignored.
+ * If the name begins with a slash then the search begins at the
+ * root object, otherwise it begins at the group CWG, otherwise
+ * it begins at the current working group of file F. The
+ * component `.' is a no-op, but `..' is not understood by this
+ * function (unless it appears as an entry in the symbol table).
+ *
* Errors:
- * SYM COMPLEN Component is too long.
- * SYM NOTFOUND Component not found.
- * SYM NOTFOUND No root group.
- * SYM NOTFOUND Root not found.
*
- * Return: Success: Pointer to a cached symbol table entry if the
- * name can be fully resolved. The pointer is
- * valid until one of the H5AC (cache) functions
- * is called.
+ * Return: Success: SUCCEED if name can be fully resolved. See
+ * above for values of REST, GRP_ENT, and
+ * OBJ_ENT.
*
- * Failure: Null if the name could not be fully resolved.
- * REST and GRP_ENT are initialized (possibly to
- * zero if the failure occurred soon enough).
+ * Failure: FAIL if the name could not be fully resolved.
+ * See above for values of REST, GRP_ENT, and
+ * OBJ_ENT.
*
* Programmer: Robb Matzke
* matzke@llnl.gov
@@ -408,46 +541,52 @@ H5G_component (const char *name, size_t *size_p)
*
*-------------------------------------------------------------------------
*/
-static H5G_entry_t *
+static herr_t
H5G_namei (H5F_t *f, H5G_entry_t *cwg, const char *name,
- const char **rest/*out*/, H5G_entry_t *grp_ent/*out*/)
+ const char **rest/*out*/, H5G_entry_t *grp_ent/*out*/,
+ H5G_entry_t *obj_ent/*out*/)
{
- H5G_entry_t grp; /*entry for current group */
+ H5G_entry_t _grp_ent; /*entry for current group */
+ H5G_entry_t _obj_ent; /*entry found */
size_t nchars; /*component name length */
char comp[1024]; /*component name buffer */
hbool_t aside = FALSE; /*did we look at a name message?*/
- H5G_entry_t *ret_value=NULL; /*return value */
/* clear output args before FUNC_ENTER() in case it fails */
if (rest) *rest = name;
- if (grp_ent) {
- memset (grp_ent, 0, sizeof(H5G_entry_t));
- H5F_addr_undef (&(grp_ent->header));
- }
+ if (!grp_ent) grp_ent = &_grp_ent;
+ if (!obj_ent) obj_ent = &_obj_ent;
+ memset (grp_ent, 0, sizeof(H5G_entry_t));
+ H5F_addr_undef (&(grp_ent->header));
+ memset (obj_ent, 0, sizeof(H5G_entry_t));
+ H5F_addr_undef (&(obj_ent->header));
- FUNC_ENTER (H5G_namei, NULL);
+ FUNC_ENTER (H5G_namei, FAIL);
/* check args */
assert (f);
- assert (f->shared->root_sym);
assert (name && *name);
- assert (cwg || '/'==*name);
+ /* If the file contains no objects then return failure */
+ if (!f->shared->root_ent) {
+ HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "no root group");
+ }
+
/* starting point */
if ('/'==*name) {
- if (!H5F_addr_defined (&(f->shared->root_sym->header))) {
- HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, NULL,
- "no root group");
- }
- ret_value = f->shared->root_sym;
- grp = *(f->shared->root_sym);
+ *obj_ent = *(f->shared->root_ent);
+ } else if (cwg) {
+ *obj_ent = *cwg;
+ } else if ((cwg=H5G_getcwg (f))) {
+ *obj_ent = *cwg;
} else {
- ret_value = cwg;
- grp = *cwg;
+ HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "no current working group");
}
+ assert (H5F_addr_defined (&(obj_ent->header)));
/* traverse the name */
while ((name=H5G_component (name, &nchars)) && *name) {
+ if (rest) *rest = name;
/*
* The special name `.' is a no-op.
@@ -457,67 +596,51 @@ H5G_namei (H5F_t *f, H5G_entry_t *cwg, const char *name,
/*
* Advance to the next component of the name.
*/
- grp = *ret_value;
- ret_value = NULL;
- if (rest) *rest = name;
+ *grp_ent = *obj_ent;
+ HDmemset (obj_ent, 0, sizeof(H5G_entry_t));
+ H5F_addr_undef (&(obj_ent->header));
/*
* Copy the component name into a null-terminated buffer so
* we can pass it down to the other symbol table functions.
*/
if (nchars+1 > sizeof(comp)) {
- if (grp_ent) *grp_ent = grp;
- HRETURN_ERROR (H5E_SYM, H5E_COMPLEN, NULL, "component is too long");
+ HRETURN_ERROR (H5E_SYM, H5E_COMPLEN, FAIL, "component is too long");
}
HDmemcpy (comp, name, nchars);
comp[nchars] = '\0';
- if (NULL==(ret_value=H5G_stab_find (f, NO_ADDR, &grp, comp))) {
+ if (H5G_stab_find (f, grp_ent, comp, obj_ent/*out*/)<0) {
/*
* Component was not found in the current symbol table, possibly
- * because GRP isn't a symbol table. If it is the root symbol then
- * see if it has the appropriate name field. The ASIDE variable
- * prevents us from saying `/foo/foo' where the root object has
- * the name `foo'.
+ * because GRP_ENT isn't a symbol table. If it is the root symbol
+ * then see if it has the appropriate name field. The ASIDE
+ * variable prevents us from saying `/foo/foo' where the root object
+ * has the name `foo'.
*/
H5O_name_t mesg={0};
if (!aside &&
- H5F_addr_defined (&(grp.header)) &&
- H5F_addr_defined (&(f->shared->root_sym->header)) &&
- H5F_addr_eq (&(grp.header), &(f->shared->root_sym->header)) &&
- H5O_read (f, &(grp.header), &grp, H5O_NAME, 0, &mesg) &&
+ H5F_addr_eq (&(grp_ent->header),
+ &(f->shared->root_ent->header)) &&
+ H5O_read (f, grp_ent, H5O_NAME, 0, &mesg) &&
!HDstrcmp (mesg.s, comp)) {
H5O_reset (H5O_NAME, &mesg);
- ret_value = f->shared->root_sym;
+ *obj_ent = *grp_ent;
+ HDmemset (grp_ent, 0, sizeof(H5G_entry_t));
+ H5F_addr_undef (&(grp_ent->header));
aside = TRUE;
} else {
H5O_reset (H5O_NAME, &mesg);
- if (grp_ent) *grp_ent = grp;
- HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, NULL, "component not found");
+ HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "component not found");
}
}
/* next component */
name += nchars;
}
-
- /* output parameters */
if (rest) *rest = name; /*final null*/
- if (grp_ent) {
- if (H5F_addr_eq (&(ret_value->header), &(f->shared->root_sym->header))) {
- HDmemset (grp_ent, 0, sizeof(H5G_entry_t)); /*root has no parent*/
- H5F_addr_undef (&(grp_ent->header));
- } else {
- *grp_ent = grp;
- }
- }
- /* Perhaps the root object doesn't even exist! */
- if (!H5F_addr_defined (&(ret_value->header))) {
- HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, NULL, "root not found");
- }
-
- FUNC_LEAVE (ret_value);
+ FUNC_LEAVE (SUCCEED);
}
@@ -532,16 +655,8 @@ H5G_namei (H5F_t *f, H5G_entry_t *cwg, const char *name,
* is removed). If the root object doesn't have a name message
* then the name `Root Object' is used.
*
- * Warning: This function has a few subtleties. Be warned!
- *
* Errors:
- * SYM CANTINIT Can't open root object.
- * SYM CANTINIT Can't reinsert old root object.
- * SYM CANTINIT Cant create root.
- * SYM EXISTS Root group already exists.
- * SYM LINK Bad link count on old root object.
- * SYM LINK Cant create root.
- *
+ *
* Return: Success: SUCCEED
*
* Failure: FAIL. This function returns -2 if the
@@ -559,71 +674,50 @@ H5G_namei (H5F_t *f, H5G_entry_t *cwg, const char *name,
static herr_t
H5G_mkroot (H5F_t *f, size_t size_hint)
{
- H5G_entry_t *handle=NULL; /*handle to open object */
herr_t ret_value=FAIL; /*return value */
H5O_name_t name={NULL}; /*object name */
H5O_stab_t stab; /*symbol table message */
- H5G_entry_t *ent_ptr=NULL; /*pointer to a symbol table entry*/
+ H5G_entry_t new_root; /*new root object */
const char *obj_name=NULL; /*name of old root object */
FUNC_ENTER (H5G_mkroot, FAIL);
+ /* check args */
+ assert (f);
+
/*
- * Make sure that the file descriptor has the latest info -- someone might
- * have the root object open.
- */
- H5G_shadow_sync (f->shared->root_sym);
-
- /*
- * If we already have a root object, then open it and get it's name. The
- * root object had better not already be a group. Once the old root
- * object is opened and we have a HANDLE, set the dirty bit on the handle.
- * This causes the handle data to be written back into f->root_sym by
- * H5G_close() if something goes wrong before the old root object is
- * re-inserted back into the group directed graph. We might leak file
- * memory, but at least we don't loose the original root object.
+ * If we already have a root object, then get it's name.
*/
- if (H5F_addr_defined (&(f->shared->root_sym->header))) {
- if (H5O_read (f, NO_ADDR, f->shared->root_sym, H5O_STAB, 0, &stab)) {
- HGOTO_ERROR (H5E_SYM, H5E_EXISTS, -2,
- "root group already exists");
- } else if (NULL==(handle=H5G_shadow_open (f, NULL,
- f->shared->root_sym))) {
- HGOTO_ERROR (H5E_SYM, H5E_CANTINIT, FAIL,
- "can't open root object");
- } else if (NULL==H5O_read (f, NO_ADDR, handle, H5O_NAME, 0, &name)) {
+ if (f->shared->root_ent) {
+ if (H5O_read (f, f->shared->root_ent, H5O_STAB, 0, &stab)) {
+ HGOTO_ERROR (H5E_SYM, H5E_EXISTS, -2, "root group already exists");
+ } else if (NULL==H5O_read (f, f->shared->root_ent, H5O_NAME, 0, &name)) {
obj_name = "Root Object";
} else {
obj_name = name.s; /*don't reset message until the end!*/
}
- handle->dirty = TRUE;
}
/*
- * Create the new root group directly into the file descriptor. If
- * something goes wrong at this step, closing the `handle' will rewrite
- * info back into f->root_sym because we set the dirty bit.
+ * Create the new root group. Set the link count to 1.
*/
- if (H5G_stab_create (f, f->shared->root_sym, size_hint)<0) {
+ if (H5G_stab_create (f, size_hint, &new_root/*out*/)<0) {
HGOTO_ERROR (H5E_SYM, H5E_CANTINIT, FAIL, "cant create root");
}
- if (1!=H5O_link (f, f->shared->root_sym, 1)) {
+ if (1!=H5O_link (f, &new_root, 1)) {
HGOTO_ERROR (H5E_SYM, H5E_LINK, FAIL,
"internal error (wrong link count)");
}
/*
* If there was a previous root object then insert it into the new root
- * symbol table with the specified name. Inserting the object will update
- * the handle to point to the new symbol table slot instead of f->root_sym.
+ * symbol table with the specified name. Then make the root object the
+ * new symbol table.
*/
- if (obj_name) {
- if (1!=H5O_link (f, handle, 0)) {
- HGOTO_ERROR (H5E_SYM, H5E_LINK, FAIL,
- "bad link count on old root object");
- }
- if (NULL==(ent_ptr=H5G_stab_insert (f, f->shared->root_sym, obj_name,
- handle))) {
+ if (f->shared->root_ent) {
+ assert (1==H5O_link (f, f->shared->root_ent, 0));
+
+ if (H5G_stab_insert (f, &new_root, obj_name, f->shared->root_ent)<0) {
HGOTO_ERROR (H5E_SYM, H5E_CANTINIT, FAIL,
"can't reinsert old root object");
}
@@ -633,33 +727,31 @@ H5G_mkroot (H5F_t *f, size_t size_hint)
* a name message should ever appear is to give the root object a name,
* but the old root object is no longer the root object.
*/
- H5O_remove (f, NO_ADDR, handle, H5O_NAME, H5O_ALL);
+ H5O_remove (f, f->shared->root_ent, H5O_NAME, H5O_ALL);
H5ECLEAR; /*who really cares?*/
+
+ *(f->shared->root_ent) = new_root;
+
+ } else {
+ f->shared->root_ent = H5MM_xmalloc (sizeof(H5G_entry_t));
+ *(f->shared->root_ent) = new_root;
}
-
+
+ H5O_close (f, &new_root);
ret_value = SUCCEED;
done:
- /*
- * If the handle is closed before the H5G_stab_insert() call that
- * reinserts the root object into the group directed graph, then
- * H5G_close() will reset f->root_sym to point to the old root symbol and
- * the new root group (if it was created) will be unlinked from the
- * group directed graph (and memory leaked).
- */
- if (handle) H5G_close (f, handle);
H5O_reset (H5O_NAME, &name);
-
FUNC_LEAVE (ret_value);
}
/*-------------------------------------------------------------------------
- * Function: H5G_new
+ * Function: H5G_create
*
- * Purpose: Creates a new empty group with the specified name,
- * opening it as an object. The name is either an absolute name
- * or is relative to the current working group.
+ * Purpose: Creates a new empty group with the specified name. The name
+ * is either an absolute name or is relative to the current
+ * working group.
*
* A root group is created implicitly by this function
* when necessary. Calling this function with the name "/"
@@ -667,16 +759,10 @@ H5G_mkroot (H5F_t *f, size_t size_hint)
* failure.
*
* Errors:
- * SYM CANTINIT Can't create grp.
- * SYM CANTINIT Can't create root group.
- * SYM CANTINIT Can't insert.
- * SYM CANTINIT Can't open.
- * SYM COMPLEN Component is too long.
- * SYM EXISTS Already exists.
- * SYM NOTFOUND Missing component.
*
- * Return: Success: A handle to the open group. Please call
- * H5G_close() when you're done with it.
+ * Return: Success: A handle for the group. The group is opened
+ * and should eventually be close by calling
+ * H5G_close().
*
* Failure: NULL
*
@@ -688,57 +774,46 @@ H5G_mkroot (H5F_t *f, size_t size_hint)
*
*-------------------------------------------------------------------------
*/
-H5G_entry_t *
-H5G_new (H5F_t *f, const char *name, size_t size_hint)
+H5G_t *
+H5G_create (H5F_t *f, const char *name, size_t size_hint)
{
const char *rest=NULL; /*the base name */
- H5G_entry_t *cwg=NULL; /*current working group */
H5G_entry_t grp_ent; /*group containing new group */
- H5G_entry_t ent; /*new group entry */
- H5G_entry_t *ent_ptr=NULL; /*ptr to new group entry */
- H5G_entry_t *ret_value=NULL; /*handle return value */
char _comp[1024]; /*name component */
size_t nchars; /*number of characters in compon*/
herr_t status; /*function return status */
+ H5G_t *grp = NULL; /*new group */
- FUNC_ENTER (H5G_new, NULL);
+ FUNC_ENTER (H5G_create, NULL);
/* check args */
assert (f);
assert (name && *name);
-#ifndef LATER
- /* Get current working group */
- H5G_shadow_sync (f->shared->root_sym);
- cwg = f->shared->root_sym;
-#endif
- assert (cwg || '/'==*name);
/*
* Try to create the root group. Ignore the error if this function
* fails because the root group already exists.
*/
if ((status=H5G_mkroot (f, H5G_SIZE_HINT))<0 && -2!=status) {
- HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, NULL,
- "can't create root group");
+ HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, NULL, "can't create root group");
}
H5ECLEAR;
/* lookup name */
- if (H5G_namei (f, cwg, name, &rest, &grp_ent)) {
+ if (0==H5G_namei (f, NULL, name, &rest, &grp_ent, NULL)) {
HRETURN_ERROR (H5E_SYM, H5E_EXISTS, NULL, "already exists");
}
H5ECLEAR; /*it's OK that we didn't find it*/
+ assert (H5F_addr_defined (&(grp_ent.header)));
/* should be one null-terminated component left */
rest = H5G_component (rest, &nchars);
assert (rest && *rest);
if (rest[nchars]) {
if (H5G_component (rest+nchars, NULL)) {
- HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, NULL,
- "missing component");
+ HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, NULL, "missing component");
} else if (nchars+1 > sizeof _comp) {
- HRETURN_ERROR (H5E_SYM, H5E_COMPLEN, NULL,
- "component is too long");
+ HRETURN_ERROR (H5E_SYM, H5E_COMPLEN, NULL, "component is too long");
} else {
/* null terminate */
HDmemcpy (_comp, rest, nchars);
@@ -747,35 +822,154 @@ H5G_new (H5F_t *f, const char *name, size_t size_hint)
}
}
- /* create group */
- if (H5G_stab_create (f, &ent, size_hint)<0) {
+ /* create and open group */
+ grp = H5MM_xcalloc (1, sizeof(H5G_t));
+ grp->file = f;
+ if (H5G_stab_create (f, size_hint, &(grp->ent)/*out*/)<0) {
+ grp = H5MM_xfree (grp);
HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, NULL, "can't create grp");
}
/* insert child name into parent */
- if (NULL==(ent_ptr=H5G_stab_insert (f, &grp_ent, rest, &ent))) {
+ if (H5G_stab_insert (f, &grp_ent, rest, &(grp->ent))<0) {
+ H5O_close (f, &(grp->ent));
+ grp = H5MM_xfree (grp);
HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, NULL, "can't insert");
}
- /* open the group */
- if (NULL==(ret_value=H5G_shadow_open (f, &grp_ent, ent_ptr))) {
- HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, NULL, "can't open");
+ grp->nref = 1;
+ FUNC_LEAVE (grp);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5G_open
+ *
+ * Purpose: Opens an existing group. The group should eventually be
+ * closed by calling H5G_close().
+ *
+ * Return: Success: Ptr to a new group.
+ *
+ * Failure: NULL
+ *
+ * Programmer: Robb Matzke
+ * Monday, January 5, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+H5G_t *
+H5G_open (H5F_t *f, const char *name)
+{
+ H5G_t *grp = NULL;
+ H5G_t *ret_value = NULL;
+
+ FUNC_ENTER (H5G_open, NULL);
+
+ /* Check args */
+ assert (f);
+ assert (name && *name);
+
+ /* Open the group */
+ grp = H5MM_xcalloc (1, sizeof(H5G_t));
+ if (H5G_find (f, name, NULL, &(grp->ent))<0) {
+ HGOTO_ERROR (H5E_SYM, H5E_NOTFOUND, NULL, "group not found");
+ }
+ if (H5O_open (f, &(grp->ent))<0) {
+ HGOTO_ERROR (H5E_SYM, H5E_CANTOPENOBJ, NULL, "unable to open group");
+ }
+ grp->file = f;
+ grp->nref = 1;
+ ret_value = grp;
+
+ done:
+ if (!ret_value && grp) {
+ H5MM_xfree (grp);
}
FUNC_LEAVE (ret_value);
}
+
+/*-------------------------------------------------------------------------
+ * Function: H5G_reopen
+ *
+ * Purpose: Reopens a group by incrementing the open count.
+ *
+ * Return: Success: The GRP argument.
+ *
+ * Failure: NULL
+ *
+ * Programmer: Robb Matzke
+ * Monday, January 5, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+H5G_t *
+H5G_reopen (H5G_t *grp)
+{
+ FUNC_ENTER (H5G_reopen, NULL);
+
+ assert (grp);
+ assert (grp->nref>0);
+
+ grp->nref++;
+
+ FUNC_LEAVE (grp);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5G_close
+ *
+ * Purpose: Closes the specified group.
+ *
+ * Return: Success: SUCCEED
+ *
+ * Failure: FAIL
+ *
+ * Programmer: Robb Matzke
+ * Monday, January 5, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5G_close (H5G_t *grp)
+{
+ FUNC_ENTER (H5G_close, FAIL);
+
+ /* Check args */
+ assert (grp);
+ assert (grp->nref>0);
+
+ if (1==grp->nref) {
+ if (H5O_close (grp->file, &(grp->ent))<0) {
+ HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL, "unable to close");
+ }
+ }
+ --grp->nref;
+
+ FUNC_LEAVE (SUCCEED);
+}
/*-------------------------------------------------------------------------
* Function: H5G_set
*
- * Purpose: Sets the current working group to be the specified name.
+ * Purpose: Sets the current working group to be the specified group.
* This affects only the top item on the group stack for the
* specified file as accessed through this file handle. If the
* file is opened multiple times, then the current working group
* for this file handle is the only one that is changed.
*
+ * Note: The group is re-opened and held open until it is removed from
+ * the current working group stack.
+ *
* Errors:
* SYM CWG Can't open group.
* SYM CWG Couldn't close previous c.w.g.
@@ -793,19 +987,20 @@ H5G_new (H5F_t *f, const char *name, size_t size_hint)
*-------------------------------------------------------------------------
*/
herr_t
-H5G_set (H5F_t *f, const char *name)
+H5G_set (H5F_t *f, H5G_t *grp)
{
- H5G_entry_t *handle=NULL;
- H5O_stab_t stab_mesg;
- herr_t ret_value=FAIL;
-
FUNC_ENTER (H5G_set, FAIL);
- if (NULL==(handle=H5G_open (f, name))) {
- HGOTO_ERROR (H5E_SYM, H5E_CWG, FAIL, "can't open group");
- }
- if (NULL==H5O_read (f, NO_ADDR, handle, H5O_NAME, 0, &stab_mesg)) {
- HGOTO_ERROR (H5E_SYM, H5E_CWG, FAIL, "not a group");
+ /* check args */
+ assert (f);
+ assert (grp);
+
+ /*
+ * Are the group and file compatible?
+ */
+ if (grp->file->shared!=f->shared) {
+ HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL,
+ "group is not compatible with file");
}
/*
@@ -814,36 +1009,27 @@ H5G_set (H5F_t *f, const char *name)
*/
if (!f->cwg_stack) {
f->cwg_stack = H5MM_xcalloc (1, sizeof(H5G_cwgstk_t));
- f->cwg_stack->handle = handle;
- } else {
- if (H5G_close (f, f->cwg_stack->handle)<0) {
- HGOTO_ERROR (H5E_SYM, H5E_CWG, FAIL,
- "couldn't close previous c.w.g.");
- }
- f->cwg_stack->handle = handle;
+ } else if (H5G_close (f->cwg_stack->grp)<0) {
+ HRETURN_ERROR (H5E_SYM, H5E_CWG, FAIL, "couldn't close previous c.w.g.");
}
- ret_value = SUCCEED;
+ f->cwg_stack->grp = H5G_reopen (grp);
- done:
- if (ret_value<0 && handle) {
- H5G_close (f, handle);
- }
-
- FUNC_LEAVE (ret_value);
+ FUNC_LEAVE (SUCCEED);
}
-
/*-------------------------------------------------------------------------
* Function: H5G_getcwg
*
- * Purpose: Returns a handle for the current working group. If there
- * is no current working group then a pointer to the root
- * symbol is returned but that object is not opened (and it
- * might not even be a group).
+ * Purpose: Returns a ptr to the symbol table entry for the current
+ * working group. If there is no current working group then a
+ * pointer to the root symbol is returned. If there is no root
+ * symbol then the null pointer is returned.
*
- * Return: Success: Ptr to open group handle with exceptions
- * noted above.
+ * Return: Success: Ptr to the current working group or root
+ * object. The pointer is valid only until the
+ * root object changes or the current working
+ * group changes.
*
* Failure: NULL
*
@@ -857,26 +1043,29 @@ H5G_set (H5F_t *f, const char *name)
static H5G_entry_t *
H5G_getcwg (H5F_t *f)
{
- H5G_entry_t *handle=NULL;
+ H5G_entry_t *ret_value=NULL;
FUNC_ENTER (H5G_getcwg, NULL);
+
+ /* check args */
+ assert (f);
- if (f->cwg_stack && f->cwg_stack->handle) {
- handle = f->cwg_stack->handle;
+ /* return a pointer directly into the stack */
+ if (f->cwg_stack && f->cwg_stack->grp) {
+ ret_value = &(f->cwg_stack->grp->ent);
} else {
- H5G_shadow_sync (f->shared->root_sym);
- handle = f->shared->root_sym;
+ ret_value = f->shared->root_ent;
}
- FUNC_LEAVE (handle);
+ FUNC_LEAVE (ret_value);
}
-
/*-------------------------------------------------------------------------
* Function: H5G_push
*
- * Purpose: Pushes a new current working group onto the stack.
+ * Purpose: Pushes a new current working group onto the stack. The GRP
+ * is reopened and held open until it is removed from the stack.
*
* Errors:
* SYM CWG Can't open group.
@@ -894,35 +1083,31 @@ H5G_getcwg (H5F_t *f)
*-------------------------------------------------------------------------
*/
herr_t
-H5G_push (H5F_t *f, const char *name)
+H5G_push (H5F_t *f, H5G_t *grp)
{
- H5G_entry_t *handle=NULL;
H5G_cwgstk_t *stack=NULL;
- H5O_stab_t stab_mesg;
- herr_t ret_value = FAIL;
FUNC_ENTER (H5G_push, FAIL);
- if (NULL==(handle=H5G_open (f, name))) {
- HGOTO_ERROR (H5E_SYM, H5E_CWG, FAIL, "can't open group");
- }
- if (NULL==H5O_read (f, NO_ADDR, handle, H5O_NAME, 0, &stab_mesg)) {
- HGOTO_ERROR (H5E_SYM, H5E_CWG, FAIL, "not a group");
- }
+ /* check args */
+ assert (f);
+ assert (grp);
/*
+ * Are the group and file compatible?
+ */
+ if (grp->file->shared!=f->shared) {
+ HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL,
+ "group is not compatible with file");
+ }
+
+ /*
* Push a new entry onto the stack.
*/
stack = H5MM_xcalloc (1, sizeof(H5G_cwgstk_t));
- stack->handle = handle;
+ stack->grp = H5G_reopen (grp);
stack->next = f->cwg_stack;
f->cwg_stack = stack;
- ret_value = SUCCEED;
-
- done:
- if (ret_value<0 && handle) {
- H5G_close (f, handle);
- }
FUNC_LEAVE (SUCCEED);
}
@@ -955,13 +1140,16 @@ H5G_pop (H5F_t *f)
FUNC_ENTER (H5G_pop, FAIL);
+ /* check args */
+ assert (f);
+
if ((stack=f->cwg_stack)) {
- if (H5G_close (f, stack->handle)<0) {
+ if (H5G_close (stack->grp)<0) {
HRETURN_ERROR (H5E_SYM, H5E_CWG, FAIL,
"can't close current working group");
}
f->cwg_stack = stack->next;
- stack->handle = NULL;
+ stack->grp = NULL;
H5MM_xfree (stack);
} else {
HRETURN_ERROR (H5E_SYM, H5E_CWG, FAIL, "stack is empty");
@@ -972,30 +1160,13 @@ H5G_pop (H5F_t *f)
/*-------------------------------------------------------------------------
- * Function: H5G_create
+ * Function: H5G_insert
*
- * Purpose: Creates a new empty object header, gives it a name, opens
- * the object for modification, and returns a handle to the
- * object. The initial size of the object header can be
- * supplied with the OHDR_HINT argument.
+ * Purpose: Inserts a symbol table entry into the group graph.
*
* Errors:
- * SYM CANTINIT Bad link count.
- * SYM CANTINIT Can't create header.
- * SYM CANTINIT Can't create root group.
- * SYM CANTINIT Can't insert.
- * SYM CANTINIT Can't open object.
- * SYM CANTINIT Cannot add/change name message.
- * SYM CANTINIT Create the object header.
- * SYM COMPLEN Component is too long.
- * SYM EXISTS Already exists.
- * SYM EXISTS Root exists.
- * SYM LINK Bad link count.
- * SYM LINK Link inc failure.
- * SYM NOTFOUND Component not found.
- *
- * Return: Success: A handle for the object. Be sure to
- * eventually close it.
+ *
+ * Return: Success: SUCCEED
*
* Failure: FAIL
*
@@ -1006,35 +1177,28 @@ H5G_pop (H5F_t *f)
*
*-------------------------------------------------------------------------
*/
-H5G_entry_t *
-H5G_create (H5F_t *f, const char *name, size_t ohdr_hint)
+herr_t
+H5G_insert (H5F_t *f, const char *name, H5G_entry_t *ent)
{
- H5G_entry_t ent; /*entry data for the new object */
- H5G_entry_t *ent_ptr; /*ptr into symbol node for entry*/
- H5G_entry_t *cwg=NULL; /*ptr to c.w.g. handle */
const char *rest = NULL; /*part of name not existing yet */
H5G_entry_t grp; /*entry for group to contain obj*/
- H5G_entry_t *ret_value=NULL; /*the object handle */
size_t nchars; /*number of characters in name */
char _comp[1024]; /*name component */
+ hbool_t update_grp;
+ herr_t status;
- FUNC_ENTER (H5G_create, NULL);
+ FUNC_ENTER (H5G_insert, FAIL);
/* Check args. */
assert (f);
assert (name && *name);
- HDmemset (&ent, 0, sizeof(H5G_entry_t));
-
- /*
- * Get the current working group.
- */
- cwg = H5G_getcwg (f);
+ assert (ent);
/*
* Look up the name -- it shouldn't exist yet.
*/
- if (H5G_namei (f, cwg, name, &rest, &grp)) {
- HRETURN_ERROR (H5E_SYM, H5E_EXISTS, NULL, "already exists");
+ if (H5G_namei (f, NULL, name, &rest, &grp, NULL)>=0) {
+ HRETURN_ERROR (H5E_SYM, H5E_EXISTS, FAIL, "already exists");
}
H5ECLEAR; /*it's OK that we didn't find it*/
rest = H5G_component (rest, &nchars);
@@ -1045,22 +1209,16 @@ H5G_create (H5F_t *f, const char *name, size_t ohdr_hint)
* doesn't have a name or we shouldn't interfere with the name
* it already has as a message.
*/
- if (H5F_addr_defined (&(f->shared->root_sym->header))) {
- HRETURN_ERROR (H5E_SYM, H5E_EXISTS, NULL, "root exists");
+ if (f->shared->root_ent) {
+ HRETURN_ERROR (H5E_SYM, H5E_EXISTS, FAIL, "root exists");
}
- if (H5O_create (f, 0, ohdr_hint, &(ent.header)/*out*/)<0) {
- HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, NULL,
- "can't create header");
+ if (1!=H5O_link (f, ent, 1)) {
+ HRETURN_ERROR (H5E_SYM, H5E_LINK, FAIL, "bad link count");
}
- if (1!=H5O_link (f, &ent, 1)) {
- HRETURN_ERROR (H5E_SYM, H5E_LINK, NULL, "bad link count");
- }
- *(f->shared->root_sym) = ent;
- if (NULL==(ret_value=H5G_shadow_open (f, NULL, f->shared->root_sym))) {
- HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, NULL,
- "can't open root object");
- }
- HRETURN (ret_value);
+ f->shared->root_ent = H5MM_xmalloc (sizeof(H5G_entry_t));
+ ent->name_off = 0;
+ *(f->shared->root_ent) = *ent;
+ HRETURN (SUCCEED);
}
/*
@@ -1069,11 +1227,9 @@ H5G_create (H5F_t *f, const char *name, size_t ohdr_hint)
*/
if (rest[nchars]) {
if (H5G_component (rest+nchars, NULL)) {
- HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, NULL,
- "component not found");
+ HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "component not found");
} else if (nchars+1 > sizeof _comp) {
- HRETURN_ERROR (H5E_SYM, H5E_COMPLEN, NULL,
- "component is too long");
+ HRETURN_ERROR (H5E_SYM, H5E_COMPLEN, FAIL, "component is too long");
} else {
/* null terminate */
HDmemcpy (_comp, rest, nchars);
@@ -1082,166 +1238,50 @@ H5G_create (H5F_t *f, const char *name, size_t ohdr_hint)
}
}
- /*
- * Create the object header.
- */
- if (H5O_create (f, 0, ohdr_hint, &(ent.header)/*out*/)<0) {
- HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, NULL,
- "can't create object header");
- }
-
-
- if (!H5F_addr_defined (&(f->shared->root_sym->header))) {
+ if (!f->shared->root_ent) {
/*
* This will be the only object in the file. Insert it as the root
* object and add a name messaage to the object header (or modify
- * the first one we find). Although the header exists we can guarantee
- * that it isn't open since it has no name.
+ * the first one we find).
*/
H5O_name_t name_mesg;
name_mesg.s = rest;
- if (H5O_modify (f, NO_ADDR, &ent, H5O_NAME, 0, &name_mesg)<0) {
- HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, NULL,
+ if (H5O_modify (f, ent, H5O_NAME, 0, &name_mesg)<0) {
+ HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL,
"cannot add/change name message");
}
- if (1!=H5O_link (f, &ent, 1)) {
- HRETURN_ERROR (H5E_SYM, H5E_LINK, NULL, "bad link count");
- }
- *(f->shared->root_sym) = ent;
- if (NULL==(ret_value=H5G_shadow_open (f, &grp, f->shared->root_sym))) {
- HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, NULL,
- "can't open root object");
+ if (1!=H5O_link (f, ent, 1)) {
+ HRETURN_ERROR (H5E_SYM, H5E_LINK, FAIL, "bad link count");
}
- HRETURN (ret_value);
- } else {
- /*
- * Make sure the root group exists. Ignore the failure if it's
- * because the group already exists.
- */
- hbool_t update_grp = H5F_addr_eq (&(grp.header),
- &(f->shared->root_sym->header));
- herr_t status = H5G_mkroot (f, H5G_SIZE_HINT);
- if (status<0 && -2!=status) {
- HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, NULL,
- "can't create root group");
- }
- H5ECLEAR;
- if (update_grp) grp = *(f->shared->root_sym);
+ f->shared->root_ent = H5MM_xmalloc (sizeof(H5G_entry_t));
+ *(f->shared->root_ent) = *ent;
+ HRETURN (SUCCEED);
}
-
+
/*
- * This is the normal case. The object is just being inserted as a normal
- * entry into a symbol table.
+ * Make sure the root group exists. Ignore the failure if it's
+ * because the group already exists.
*/
- if (H5O_link (f, &ent, 1)<0) {
- HRETURN_ERROR (H5E_SYM, H5E_LINK, NULL, "link inc failure");
- }
- if (NULL==(ent_ptr=H5G_stab_insert (f, &grp, rest, &ent))) {
- HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, NULL, "can't insert");
- }
- if (NULL==(ret_value=H5G_shadow_open (f, &grp, ent_ptr))) {
- HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, NULL, "can't open object");
+ update_grp = H5F_addr_eq (&(grp.header),
+ &(f->shared->root_ent->header));
+ if ((status=H5G_mkroot (f, H5G_SIZE_HINT))<0 && -2!=status) {
+ HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL, "can't create root group");
}
- FUNC_LEAVE (ret_value);
-}
+ H5ECLEAR;
+ if (update_grp) grp = *(f->shared->root_ent);
-
-/*-------------------------------------------------------------------------
- * Function: H5G_open
- *
- * Purpose: Opens an object. That is, it prepares the object for
- * modification by returning a handle to the object
- * symbol table entry. Opening an object twice with the
- * same name (or more precisely, through the same final
- * symbol table entry) will return pointers to the same
- * H5G_entry_t struct. But opening an object through
- * different final H5G_entry_t structs (which implies
- * different names) returns pointers to different
- * structs. The structs that are returned should be
- * released by calling H5G_close().
- *
- * Errors:
- * SYM BADVALUE Check args.
- * SYM CANTOPENOBJ Can't open obj.
- * SYM NOTFOUND Object not found.
- *
- * Return: Success: Ptr to a handle for the object.
- *
- * Failure: NULL
- *
- * Programmer: Robb Matzke
- * Wednesday, September 17, 1997
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-H5G_entry_t *
-H5G_open (H5F_t *f, const char *name)
-{
- H5G_entry_t *ent=NULL;
- H5G_entry_t *ret_value=NULL;
- H5G_entry_t grp;
- H5G_entry_t *cwg=NULL;
- FUNC_ENTER (H5G_open, NULL);
-
- /* check args */
- assert (f);
- if (!name || !*name) {
- HRETURN_ERROR (H5E_SYM, H5E_BADVALUE, NULL, "no name");
- }
-
- /* Get CWG */
- cwg = H5G_getcwg (f);
- assert (cwg || '/'==*name);
-
- if (!H5F_addr_defined (&(f->shared->root_sym->header))) {
- HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, NULL, "object not found");
- }
- if (NULL==(ent=H5G_namei (f, cwg, name, NULL, &grp))) {
- HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, NULL, "object not found");
+ /*
+ * This is the normal case. The object is just being inserted as a normal
+ * entry into a symbol table.
+ */
+ if (H5O_link (f, ent, 1)<0) {
+ HRETURN_ERROR (H5E_SYM, H5E_LINK, FAIL, "link inc failure");
}
- if (NULL==(ret_value=H5G_shadow_open (f, &grp, ent))) {
- HRETURN_ERROR (H5E_SYM, H5E_CANTOPENOBJ, NULL, "can't open obj");
+ if (H5G_stab_insert (f, &grp, rest, ent)<0) {
+ HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL, "can't insert");
}
- FUNC_LEAVE (ret_value);
-}
-
-
-
-/*-------------------------------------------------------------------------
- * Function: H5G_close
- *
- * Purpose: Closes an object that was open for modification.
- *
- * Errors:
- * SYM CANTFLUSH Can't close object.
- *
- * Return: Success: SUCCEED
- *
- * Failure: FAIL
- *
- * Programmer: Robb Matzke
- * Thursday, September 18, 1997
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-herr_t
-H5G_close (H5F_t *f, H5G_entry_t *ent)
-{
- FUNC_ENTER (H5G_close, FAIL);
-
- assert (f);
-
- if (ent && H5G_shadow_close (f, ent)<0) {
- HRETURN_ERROR (H5E_SYM, H5E_CANTFLUSH, FAIL,
- "can't close object");
- }
-
FUNC_LEAVE (SUCCEED);
}
@@ -1254,25 +1294,19 @@ H5G_close (H5F_t *f, H5G_entry_t *ent)
* to the current working group. On successful return,
* GRP_ENT (if non-null) will be initialized with the symbol
* table information for the group in which the object
- * appears (or all zero if the returned object is the root
- * object) and ENT will be initialized with the symbol table
- * entry for the object (ENT is optional when the caller is
- * interested only in the existence of the object).
+ * appears (it will have an undefined object header address if
+ * the object is the root object) and OBJ_ENT will be
+ * initialized with the symbol table entry for the object
+ * (OBJ_ENT is optional when the caller is interested only in
+ * the existence of the object).
*
- * This function will fail if the root object is
- * requested and there is none.
+ * This function will fail if the root object is requested and
+ * there is none.
*
* Errors:
- * SYM NOTFOUND Object not found.
*
- * Return: Success: SUCCEED with GRP_ENT and ENT initialized. ENT
- * is intended for immediate read-only access.
- * If the object that ENT refers to is open
- * through the ENT entry (see H5G_open()) then
- * the returned ENT will contain the latest
- * information. However, subsequent changes to
- * the symbol table entry will not be reflected
- * in ENT since it is a copy of the symbol table.
+ * Return: Success: SUCCEED, see above for values of GRP_ENT and
+ * OBJ_ENT.
*
* Failure: FAIL
*
@@ -1286,28 +1320,17 @@ H5G_close (H5F_t *f, H5G_entry_t *ent)
*/
herr_t
H5G_find (H5F_t *f, const char *name,
- H5G_entry_t *grp_ent/*out*/, H5G_entry_t *ent/*out*/)
+ H5G_entry_t *grp_ent/*out*/, H5G_entry_t *obj_ent/*out*/)
{
- H5G_entry_t *ent_p = NULL;
- H5G_entry_t *cwg = NULL;
-
FUNC_ENTER (H5G_find, FAIL);
/* check args */
assert (f);
assert (name && *name);
- cwg = H5G_getcwg (f);
- assert (cwg || '/'==*name);
- if (!H5F_addr_defined (&(f->shared->root_sym->header))) {
+ if (H5G_namei (f, NULL, name, NULL, grp_ent, obj_ent)<0) {
HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "object not found");
}
- if (NULL==(ent_p=H5G_namei (f, cwg, name, NULL, grp_ent))) {
- HRETURN_ERROR (H5E_SYM, H5E_NOTFOUND, FAIL, "object not found");
- }
-
- if (ent) *ent = *ent_p;
FUNC_LEAVE (SUCCEED);
}
-