summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2002-04-26 20:34:46 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2002-04-26 20:34:46 (GMT)
commit94f11385a6ad93d66df9458bb9dfeec05c7c2a45 (patch)
tree8389590bcde56d8ccc2a8e0364af0e88cdf9f7cf
parent124979bfc261386070516a81f26e7a28417c56d3 (diff)
downloadhdf5-94f11385a6ad93d66df9458bb9dfeec05c7c2a45.zip
hdf5-94f11385a6ad93d66df9458bb9dfeec05c7c2a45.tar.gz
hdf5-94f11385a6ad93d66df9458bb9dfeec05c7c2a45.tar.bz2
[svn-r5273]
Purpose: New feature Description: Allow H5Glink and H5Gmove to handle links across different locations. Solution: Added H5Glink2 and H5Gmove2 functions with new parameter of destination location. Platforms tested: Linux 2.2(eirene)
-rw-r--r--release_docs/RELEASE.txt3
-rw-r--r--src/H5G.c124
-rw-r--r--src/H5Gprivate.h10
-rw-r--r--src/H5Gpublic.h12
-rw-r--r--test/links.c231
-rw-r--r--test/unlink.c167
6 files changed, 500 insertions, 47 deletions
diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt
index 87ccd8f..ea44517 100644
--- a/release_docs/RELEASE.txt
+++ b/release_docs/RELEASE.txt
@@ -159,6 +159,9 @@ Documentation
New Features
============
+ * New functions H5Glink2 and H5Gmove2 were added to allow link and move to
+ be in different locations in the same file. The old functions H5Glink
+ and H5Gmove remain valid. SLU - 2002/04/26
* Fill-value's behaviors for contiguous dataset have been redefined.
Basicly, dataset won't allocate space until it's necessary. Full details
are available at http://hdf.ncsa.uiuc.edu/RFC/Fill_Value, at this moment.
diff --git a/src/H5G.c b/src/H5G.c
index f110800..bfbd9df 100644
--- a/src/H5G.c
+++ b/src/H5G.c
@@ -343,12 +343,13 @@ H5Giterate(hid_t loc_id, const char *name, int *idx,
/*-------------------------------------------------------------------------
- * Function: H5Gmove
+ * Function: H5Gmove2
*
* Purpose: Renames an object within an HDF5 file. The original name SRC
* is unlinked from the group graph and the new name DST is
* inserted as an atomic operation. Both names are interpreted
- * relative to LOC_ID which is either a file ID or a group ID.
+ * relative to SRC_LOC_ID and DST_LOC_ID, which are either a file
+ * ID or a group ID.
*
* Return: Non-negative on success/Negative on failure
*
@@ -357,29 +358,52 @@ H5Giterate(hid_t loc_id, const char *name, int *idx,
*
* Modifications:
*
+ * Raymond Lu
+ * Thursday, April 18, 2002
+ *
*-------------------------------------------------------------------------
*/
herr_t
-H5Gmove(hid_t loc_id, const char *src, const char *dst)
+H5Gmove2(hid_t src_loc_id, const char *src_name, hid_t dst_loc_id,
+ const char *dst_name)
{
- H5G_entry_t *loc=NULL;
-
- FUNC_ENTER (H5Gmove, FAIL);
- H5TRACE3("e","iss",loc_id,src,dst);
+ H5G_entry_t *src_loc=NULL;
+ H5G_entry_t *dst_loc=NULL;
- if (NULL==(loc=H5G_loc(loc_id))) {
+ FUNC_ENTER (H5Gmove2, FAIL);
+ H5TRACE4("e","isis",src_loc_id,src_name,dst_loc_id,dst_name);
+
+ if (src_loc_id != H5G_SAME_LOC && NULL==(src_loc=H5G_loc(src_loc_id))) {
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location");
}
- if (!src || !*src) {
+ if (dst_loc_id != H5G_SAME_LOC && NULL==(dst_loc=H5G_loc(dst_loc_id))) {
+ HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location");
+ }
+ if (!src_name || !*src_name) {
HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
"no current name specified");
}
- if (!dst || !*dst) {
+ if (!dst_name || !*dst_name) {
HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
"no new name specified");
}
- if (H5G_move(loc, src, dst)<0) {
+ if(src_loc_id == H5G_SAME_LOC && dst_loc_id == H5G_SAME_LOC) {
+ HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
+ "source and destination should not be both H5G_SAME_LOC");
+ }
+ else if(src_loc_id == H5G_SAME_LOC) {
+ src_loc = dst_loc;
+ }
+ else if(dst_loc_id == H5G_SAME_LOC) {
+ dst_loc = src_loc;
+ }
+ else if(src_loc->file != dst_loc->file) {
+ HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
+ "source and destination should be in the same file.");
+ }
+
+ if (H5G_move(src_loc, src_name, dst_loc, dst_name)<0) {
HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL,
"unable to change object name");
}
@@ -389,14 +413,15 @@ H5Gmove(hid_t loc_id, const char *src, const char *dst)
/*-------------------------------------------------------------------------
- * Function: H5Glink
+ * Function: H5Glink2
*
* Purpose: Creates a link of the specified type from NEW_NAME to
* CUR_NAME.
*
* If TYPE is H5G_LINK_HARD then CUR_NAME must name an existing
- * object and both names are interpreted relative to LOC_ID
- * which is either a file ID or a group ID.
+ * object. CUR_NAME and NEW_NAME are interpreted relative to
+ * CUR_LOC_ID and NEW_LOC_ID, which is either a file ID or a
+ * group ID.
*
* If TYPE is H5G_LINK_SOFT then CUR_NAME can be anything and is
* interpreted at lookup time relative to the group which
@@ -415,18 +440,22 @@ H5Gmove(hid_t loc_id, const char *src, const char *dst)
*-------------------------------------------------------------------------
*/
herr_t
-H5Glink(hid_t loc_id, H5G_link_t type, const char *cur_name,
- const char *new_name)
+H5Glink2(hid_t cur_loc_id, const char *cur_name, H5G_link_t type,
+ hid_t new_loc_id, const char *new_name)
{
- H5G_entry_t *loc = NULL;
-
- FUNC_ENTER (H5Glink, FAIL);
- H5TRACE4("e","iGlss",loc_id,type,cur_name,new_name);
+ H5G_entry_t *cur_loc = NULL;
+ H5G_entry_t *new_loc = NULL;
+
+ FUNC_ENTER (H5Glink2, FAIL);
+ H5TRACE5("e","isGlis",cur_loc_id,cur_name,type,new_loc_id,new_name);
/* Check arguments */
- if (NULL==(loc=H5G_loc (loc_id))) {
+ if (cur_loc_id != H5G_SAME_LOC && NULL==(cur_loc=H5G_loc(cur_loc_id))) {
HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a location");
}
+ if (new_loc_id != H5G_SAME_LOC && NULL==(new_loc=H5G_loc(new_loc_id))) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a location");
+ }
if (type!=H5G_LINK_HARD && type!=H5G_LINK_SOFT) {
HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "unrecognized link type");
}
@@ -438,7 +467,24 @@ H5Glink(hid_t loc_id, H5G_link_t type, const char *cur_name,
HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,
"no new name specified");
}
- if (H5G_link (loc, type, cur_name, new_name, H5G_TARGET_NORMAL)<0) {
+
+ if(cur_loc_id == H5G_SAME_LOC && new_loc_id == H5G_SAME_LOC) {
+ HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
+ "source and destination should not be both H5G_SAME_LOC");
+ }
+ else if(cur_loc_id == H5G_SAME_LOC) {
+ cur_loc = new_loc;
+ }
+ else if(new_loc_id == H5G_SAME_LOC) {
+ new_loc = cur_loc;
+ }
+ else if(cur_loc->file != new_loc->file) {
+ HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
+ "source and destination should be in the same file.");
+ }
+
+ if (H5G_link(cur_loc, cur_name, new_loc, new_name, type, H5G_TARGET_NORMAL)
+ <0) {
HRETURN_ERROR (H5E_SYM, H5E_LINK, FAIL, "unable to create link");
}
@@ -1866,8 +1912,8 @@ H5G_loc (hid_t loc_id)
*-------------------------------------------------------------------------
*/
herr_t
-H5G_link (H5G_entry_t *loc, H5G_link_t type, const char *cur_name,
- const char *new_name, unsigned namei_flags)
+H5G_link (H5G_entry_t *cur_loc, const char *cur_name, H5G_entry_t *new_loc,
+ const char *new_name, H5G_link_t type, unsigned namei_flags)
{
H5G_entry_t cur_obj; /*entry for the link tail */
H5G_entry_t grp_ent; /*ent for grp containing link hd*/
@@ -1880,7 +1926,8 @@ H5G_link (H5G_entry_t *loc, H5G_link_t type, const char *cur_name,
FUNC_ENTER (H5G_link, FAIL);
/* Check args */
- assert (loc);
+ assert (cur_loc);
+ assert (new_loc);
assert (cur_name && *cur_name);
assert (new_name && *new_name);
@@ -1890,8 +1937,8 @@ H5G_link (H5G_entry_t *loc, H5G_link_t type, const char *cur_name,
* Lookup the the new_name so we can get the group which will contain
* the new entry. The entry shouldn't exist yet.
*/
- if (H5G_namei (loc, new_name, &rest, &grp_ent, NULL, H5G_TARGET_NORMAL,
- NULL)>=0) {
+ if (H5G_namei (new_loc, new_name, &rest, &grp_ent, NULL,
+ H5G_TARGET_NORMAL, NULL)>=0) {
HRETURN_ERROR (H5E_SYM, H5E_EXISTS, FAIL, "already exists");
}
H5E_clear (); /*it's okay that we didn't find it*/
@@ -1956,12 +2003,12 @@ H5G_link (H5G_entry_t *loc, H5G_link_t type, const char *cur_name,
break;
case H5G_LINK_HARD:
- if (H5G_namei(loc, cur_name, NULL, NULL, &cur_obj, namei_flags,
+ if (H5G_namei(cur_loc, cur_name, NULL, NULL, &cur_obj, namei_flags,
NULL)<0) {
HRETURN_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL,
"source object not found");
}
- if (H5G_insert (loc, new_name, &cur_obj)<0) {
+ if (H5G_insert (new_loc, new_name, &cur_obj)<0) {
HRETURN_ERROR (H5E_SYM, H5E_CANTINIT, FAIL,
"unable to create new name/link for object");
}
@@ -2323,21 +2370,26 @@ H5G_unlink(H5G_entry_t *loc, const char *name)
*
* Modifications:
*
+ * Raymond Lu
+ * Thursday, April 18, 2002
+ *
*-------------------------------------------------------------------------
*/
herr_t
-H5G_move(H5G_entry_t *loc, const char *src_name, const char *dst_name)
+H5G_move(H5G_entry_t *src_loc, const char *src_name, H5G_entry_t *dst_loc,
+ const char *dst_name)
{
H5G_stat_t sb;
char *linkval=NULL;
size_t lv_size=32;
FUNC_ENTER(H5G_move, FAIL);
- assert(loc);
+ assert(src_loc);
+ assert(dst_loc);
assert(src_name && *src_name);
assert(dst_name && *dst_name);
- if (H5G_get_objinfo(loc, src_name, FALSE, &sb)<0) {
+ if (H5G_get_objinfo(src_loc, src_name, FALSE, &sb)<0) {
HRETURN_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "object not found");
}
if (H5G_LINK==sb.type) {
@@ -2352,12 +2404,12 @@ H5G_move(H5G_entry_t *loc, const char *src_name, const char *dst_name)
"value");
}
linkval[lv_size-1] = '\0';
- if (H5G_linkval(loc, src_name, lv_size, linkval)<0) {
+ if (H5G_linkval(src_loc, src_name, lv_size, linkval)<0) {
HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL,
"unable to read symbolic link value");
}
} while (linkval[lv_size-1]);
- if (H5G_link(loc, H5G_LINK_SOFT, linkval, dst_name,
+ if (H5G_link(src_loc, linkval, dst_loc, dst_name, H5G_LINK_SOFT,
H5G_TARGET_NORMAL)<0) {
HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL,
"unable to rename symbolic link");
@@ -2368,7 +2420,7 @@ H5G_move(H5G_entry_t *loc, const char *src_name, const char *dst_name)
/*
* Rename the object.
*/
- if (H5G_link(loc, H5G_LINK_HARD, src_name, dst_name,
+ if (H5G_link(src_loc, src_name, dst_loc, dst_name, H5G_LINK_HARD,
H5G_TARGET_MOUNT)<0) {
HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL,
"unable to register new name for object");
@@ -2376,7 +2428,7 @@ H5G_move(H5G_entry_t *loc, const char *src_name, const char *dst_name)
}
/* Remove the old name */
- if (H5G_unlink(loc, src_name)<0) {
+ if (H5G_unlink(src_loc, src_name)<0) {
HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL,
"unable to deregister old object name");
}
diff --git a/src/H5Gprivate.h b/src/H5Gprivate.h
index 7590597..1d9df9d 100644
--- a/src/H5Gprivate.h
+++ b/src/H5Gprivate.h
@@ -125,9 +125,9 @@ __DLL__ H5G_t *H5G_reopen(H5G_t *grp);
__DLL__ herr_t H5G_close(H5G_t *grp);
__DLL__ H5G_t *H5G_rootof(H5F_t *f);
__DLL__ htri_t H5G_isa(H5G_entry_t *ent);
-__DLL__ herr_t H5G_link(H5G_entry_t *loc, H5G_link_t type,
- const char *cur_name, const char *new_name,
- unsigned namei_flags);
+__DLL__ herr_t H5G_link(H5G_entry_t *cur_loc, const char *cur_name,
+ H5G_entry_t *new_loc, const char *new_name,
+ H5G_link_t type, unsigned namei_flags);
__DLL__ int H5G_get_type(H5G_entry_t *ent);
__DLL__ herr_t H5G_get_objinfo(H5G_entry_t *loc, const char *name,
hbool_t follow_link,
@@ -140,8 +140,8 @@ __DLL__ int H5G_get_comment(H5G_entry_t *loc, const char *name,
size_t bufsize, char *buf);
__DLL__ herr_t H5G_insert(H5G_entry_t *loc, const char *name,
H5G_entry_t *ent);
-__DLL__ herr_t H5G_move(H5G_entry_t *loc, const char *src_name,
- const char *dst_name);
+__DLL__ herr_t H5G_move(H5G_entry_t *src_loc, const char *src_name,
+ H5G_entry_t *dst_loc, const char *dst_name);
__DLL__ herr_t H5G_unlink(H5G_entry_t *loc, const char *name);
__DLL__ herr_t H5G_find(H5G_entry_t *loc, const char *name,
H5G_entry_t *grp_ent/*out*/, H5G_entry_t *ent/*out*/);
diff --git a/src/H5Gpublic.h b/src/H5Gpublic.h
index 2071b26..943aaa5 100644
--- a/src/H5Gpublic.h
+++ b/src/H5Gpublic.h
@@ -67,6 +67,11 @@ typedef struct H5G_stat_t {
size_t linklen; /*symbolic link value length */
} H5G_stat_t;
+#define H5G_SAME_LOC 0
+#define H5Glink(cur_loc_id, type, cur_name, new_name) \
+ H5Glink2(cur_loc_id, cur_name, type, H5G_SAME_LOC, new_name)
+#define H5Gmove(src_loc_id, src_name, dst_name) \
+ H5Gmove2(src_loc_id, src_name, H5G_SAME_LOC, dst_name)
typedef herr_t (*H5G_iterate_t)(hid_t group, const char *name,
void *op_data);
@@ -76,9 +81,10 @@ __DLL__ hid_t H5Gopen(hid_t loc_id, const char *name);
__DLL__ herr_t H5Gclose(hid_t group_id);
__DLL__ herr_t H5Giterate(hid_t loc_id, const char *name, int *idx,
H5G_iterate_t op, void *op_data);
-__DLL__ herr_t H5Gmove(hid_t loc_id, const char *src, const char *dst);
-__DLL__ herr_t H5Glink(hid_t loc_id, H5G_link_t type, const char *cur_name,
- const char *new_name);
+__DLL__ herr_t H5Gmove2(hid_t src_loc, const char *src, hid_t dst_loc,
+ const char *dst);
+__DLL__ herr_t H5Glink2(hid_t src_loc, const char *cur_name, H5G_link_t type,
+ hid_t dst_loc, const char *new_name);
__DLL__ herr_t H5Gunlink(hid_t loc_id, const char *name);
__DLL__ herr_t H5Gget_objinfo(hid_t loc_id, const char *name,
hbool_t follow_link, H5G_stat_t *statbuf/*out*/);
diff --git a/test/links.c b/test/links.c
index c88b22f..1d99a73 100644
--- a/test/links.c
+++ b/test/links.c
@@ -1,4 +1,4 @@
-/*
+ /*
* Copyright (C) 1998 NCSA
* All rights reserved.
*
@@ -10,7 +10,9 @@
#include "h5test.h"
const char *FILENAME[] = {
- "links",
+ "links1",
+ "links2",
+ "links3",
NULL
};
@@ -85,6 +87,132 @@ mklinks(hid_t fapl)
/*-------------------------------------------------------------------------
+ * Function: new_links
+ *
+ * Purpose: Build a file with assorted links for different locations.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Raymond Lu
+ * Friday, April 19, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+new_links(hid_t fapl)
+{
+ hid_t file_a, file_b;
+ hid_t grp1_a, grp1_b, grp2_a, grp2_b;
+ hid_t scalar;
+ hid_t dset1, dset2;
+ char filename[1024];
+ static hsize_t size[1] = {1};
+ H5G_stat_t sb_soft2;
+
+ TESTING("H5Glink2 function");
+
+ /* Create two files */
+ h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
+ if ((file_a=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) {
+ goto error;
+ }
+ h5_fixname(FILENAME[2], fapl, filename, sizeof filename);
+ if ((file_b=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) {
+ goto error;
+ }
+ if ((scalar=H5Screate_simple (1, size, size))<0) goto error;
+
+ /* Create two groups in each file */
+ if ((grp1_a=H5Gcreate (file_a, "grp1", 0))<0) goto error;
+ if ((grp2_a=H5Gcreate (file_a, "grp2", 0))<0) goto error;
+ if ((grp1_b=H5Gcreate (file_b, "grp1", 0))<0) goto error;
+ if ((grp2_b=H5Gcreate (file_b, "grp2", 0))<0) goto error;
+
+ /* Create datasets */
+ if((dset1=H5Dcreate(file_a, "dataset1", H5T_NATIVE_INT, scalar,
+ H5P_DEFAULT))<0) {
+ goto error;
+ }
+ if((dset2=H5Dcreate(grp1_a, "dataset2", H5T_NATIVE_INT, scalar,
+ H5P_DEFAULT))<0) {
+ goto error;
+ }
+
+ /* Create links within a file. Both of source and destination use
+ * H5G_SAME_LOC. Both hard and soft links should fail. */
+ H5E_BEGIN_TRY {
+ if(H5Glink2(H5G_SAME_LOC, "dataset1", H5G_LINK_HARD , H5G_SAME_LOC,
+ "hard")!=FAIL) goto error;
+ } H5E_END_TRY;
+ H5E_BEGIN_TRY {
+ if(H5Glink2(H5G_SAME_LOC, "dataset1", H5G_LINK_SOFT , H5G_SAME_LOC,
+ "soft")!=FAIL) goto error;
+ } H5E_END_TRY;
+
+ /* Create links across files. Both hard and soft links should fail. */
+ H5E_BEGIN_TRY {
+ if(H5Glink2(file_a, "dataset1", H5G_LINK_HARD , file_b,
+ "hard")!=FAIL) goto error;
+ } H5E_END_TRY;
+ H5E_BEGIN_TRY {
+ if(H5Glink2(file_a, "dataset1", H5G_LINK_SOFT, file_b, "soft")!=FAIL)
+ goto error;
+ } H5E_END_TRY;
+
+ /* Create links to test H5G_SAME_LOC, H5G_LINK_HARD, H5G_LINK_SOFT. */
+ if(H5Glink2(grp1_a, "dataset2", H5G_LINK_HARD , H5G_SAME_LOC,
+ "hard1")<0) {
+ goto error;
+ }
+ if(H5Glink2(H5G_SAME_LOC, "dataset2", H5G_LINK_SOFT , grp1_a,
+ "soft1")<0) {
+ goto error;
+ }
+
+ /* Create links to test H5G_LINK_HARD, H5G_LINK_SOFT across different
+ * locations. */
+ if(H5Glink2(grp1_a, "dataset2", H5G_LINK_HARD, grp2_a, "hard2")<0) {
+ goto error;
+ }
+ if(H5Glink2(grp1_a, "/grp1/dataset2", H5G_LINK_SOFT , grp2_a, "soft2")<0) {
+ goto error;
+ }
+
+ /* Close dataspace and files */
+ if (H5Sclose (scalar)<0) goto error;
+ if (H5Dclose(dset1)<0) goto error;
+ if (H5Dclose(dset2)<0) goto error;
+ if (H5Gclose (grp1_a)<0) goto error;
+ if (H5Gclose (grp2_a)<0) goto error;
+ if (H5Gclose (grp1_b)<0) goto error;
+ if (H5Gclose (grp2_b)<0) goto error;
+ if (H5Fclose (file_a)<0) goto error;
+ if (H5Fclose (file_b)<0) goto error;
+
+ PASSED();
+ return 0;
+
+ error:
+ H5E_BEGIN_TRY {
+ H5Sclose (scalar);
+ H5Dclose (dset1);
+ H5Dclose (dset2);
+ H5Gclose (grp1_a);
+ H5Gclose (grp2_a);
+ H5Gclose (grp1_b);
+ H5Gclose (grp2_b);
+ H5Fclose (file_a);
+ H5Fclose (file_b);
+ } H5E_END_TRY;
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
* Function: cklinks
*
* Purpose: Open the file created in the first step and check that the
@@ -214,6 +342,103 @@ cklinks(hid_t fapl)
/*-------------------------------------------------------------------------
+ * Function: ck_new_links
+ *
+ * Purpose: Open the file created in the first step and check that the
+ * links look correct.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Raymond Lu
+ * Thursday, April 25, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+ck_new_links(hid_t fapl)
+{
+ hid_t file, dset, grp2;
+ H5G_stat_t sb_dset, sb_hard1, sb_hard2, sb_soft1, sb_soft2;
+ char filename[1024];
+ char linkval[1024];
+
+ TESTING("new link queries");
+
+ /* Open the file */
+ h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
+ if ((file=H5Fopen(filename, H5F_ACC_RDONLY, fapl))<0) {
+ goto error;
+ }
+
+ /* Get hard link info */
+ if(H5Gget_objinfo(file, "/grp1/dataset2", TRUE, &sb_dset)<0)
+ goto error;
+ if(H5Gget_objinfo(file, "/grp1/hard1", TRUE, &sb_hard1)<0)
+ goto error;
+ if(H5Gget_objinfo(file, "/grp2/hard2", TRUE, &sb_hard2)<0)
+ goto error;
+
+ /* Check hard links */
+ if(H5G_DATASET!=sb_hard1.type || H5G_DATASET!=sb_hard2.type) {
+ H5_FAILED();
+ puts(" Unexpected object type, should have been a dataset");
+ goto error;
+ }
+ if( sb_dset.objno[0]!=sb_hard1.objno[0] ||
+ sb_dset.objno[1]!=sb_hard1.objno[1] ||
+ sb_dset.objno[0]!=sb_hard2.objno[0] ||
+ sb_dset.objno[1]!=sb_hard2.objno[1] ) {
+ H5_FAILED();
+ puts(" Hard link test failed. Link seems not to point to the ");
+ puts(" expected file location.");
+ goto error;
+ }
+
+ /* Get soft link info */
+ if(H5Gget_objinfo(file, "/grp1/soft1", TRUE, &sb_soft1)<0) goto error;
+ if(H5Gget_objinfo(file, "/grp2/soft2", TRUE, &sb_soft2)<0) goto error;
+
+ /* Check soft links */
+ if(H5G_DATASET!=sb_soft1.type || H5G_DATASET!=sb_soft2.type) {
+ H5_FAILED();
+ puts(" Unexpected object type, should have been a dataset");
+ goto error;
+ }
+
+ if( sb_dset.objno[0]!=sb_soft1.objno[0] ||
+ sb_dset.objno[1]!=sb_soft1.objno[1] ||
+ sb_dset.objno[0]!=sb_soft2.objno[0] ||
+ sb_dset.objno[1]!=sb_soft2.objno[1] ) {
+ H5_FAILED();
+ puts(" Soft link test failed. Link seems not to point to the ");
+ puts(" expected file location.");
+ goto error;
+ }
+
+ if (H5Gget_linkval(file, "grp2/soft2", sizeof linkval, linkval)<0) {
+ goto error;
+ }
+ if (strcmp(linkval, "/grp1/dataset2")) {
+ H5_FAILED();
+ puts(" Soft link test failed. Wrong link value");
+ goto error;
+ }
+
+ /* Cleanup */
+ if(H5Fclose(file)<0) goto error;
+ PASSED();
+ return 0;
+
+ error:
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
* Function: main
*
* Purpose: Test links
@@ -240,7 +465,9 @@ main(void)
/* The tests... */
nerrors += mklinks(fapl) < 0 ? 1 : 0;
+ nerrors += new_links(fapl) < 0 ? 1 : 0;
nerrors += cklinks(fapl) < 0 ? 1 : 0;
+ nerrors += ck_new_links(fapl) < 0 ? 1 : 0;
/* Results */
if (nerrors) {
diff --git a/test/unlink.c b/test/unlink.c
index 66c2b82..c31643f 100644
--- a/test/unlink.c
+++ b/test/unlink.c
@@ -11,6 +11,8 @@
const char *FILENAME[] = {
"unlink",
+ "new_move_a",
+ "new_move_b",
NULL
};
@@ -275,7 +277,168 @@ test_rename(hid_t file)
} H5E_END_TRY;
return 1;
}
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_new_move
+ *
+ * Purpose: Tests H5Gmove2()
+ *
+ * Return: Success: 0
+ *
+ * Failure: number of errors
+ *
+ * Programmer: Raymond Lu
+ * Thursday, April 25, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+test_new_move(void)
+{
+ hid_t fapl, file_a, file_b;
+ hid_t grp1, grp2, grp_move, moved_grp;
+ char filename[1024];
+
+ TESTING("new move");
+
+ /* Create a second file */
+ fapl = h5_fileaccess();
+ h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
+ if ((file_a=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
+ goto error;
+ h5_fixname(FILENAME[2], fapl, filename, sizeof filename);
+ if ((file_b=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
+ goto error;
+
+ /* Create groups in first file */
+ if((grp1=H5Gcreate(file_a, "group1", 0))<0) goto error;
+ if((grp2=H5Gcreate(file_a, "group2", 0))<0) goto error;
+ if((grp_move=H5Gcreate(grp1, "group_move", 0))<0) goto error;
+
+ /* Create hard and soft links. */
+ if(H5Glink2(grp1, "group_move", H5G_LINK_HARD, H5G_SAME_LOC, "hard")<0)
+ goto error;
+ if(H5Glink2(grp1, "/group1/group_move", H5G_LINK_SOFT, grp2, "soft")<0)
+ goto error;
+
+ /* Move a group within the file. Both of source and destination use
+ * H5G_SAME_LOC. Should fail. */
+ H5E_BEGIN_TRY {
+ if(H5Gmove2(H5G_SAME_LOC, "group_move", H5G_SAME_LOC, "group_new_name")
+ !=FAIL) goto error;
+ } H5E_END_TRY;
+
+ /* Move a group across files. Should fail. */
+ H5E_BEGIN_TRY {
+ if(H5Gmove2(grp1, "group_move", file_b, "group_new_name")!=FAIL)
+ goto error;
+ } H5E_END_TRY;
+ /* Move a group across groups in the same file. */
+ if(H5Gmove2(grp1, "group_move", grp2, "group_new_name")<0)
+ goto error;
+
+ /* Open the group just moved to the new location. */
+ if((moved_grp = H5Gopen(grp2, "group_new_name"))<0)
+ goto error;
+
+ H5Gclose(grp1);
+ H5Gclose(grp2);
+ H5Gclose(grp_move);
+ H5Gclose(moved_grp);
+ H5Fclose(file_a);
+ H5Fclose(file_b);
+
+ PASSED();
+ return 0;
+
+ error:
+ H5E_BEGIN_TRY {
+ H5Gclose(grp1);
+ H5Gclose(grp2);
+ H5Gclose(grp_move);
+ H5Gclose(moved_grp);
+ H5Fclose(file_a);
+ H5Fclose(file_b);
+ } H5E_END_TRY;
+ return 1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: check_new_move
+ *
+ * Purpose: Checks result of H5Gmove2()
+ *
+ * Return: Success: 0
+ *
+ * Failure: number of errors
+ *
+ * Programmer: Raymond Lu
+ * Thursday, April 25, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+check_new_move(void)
+{
+ hid_t fapl, file;
+ H5G_stat_t sb_hard1, sb_hard2, sb_soft;
+ char filename[1024];
+ char linkval[1024];
+
+ TESTING("check new move function");
+
+ /* Open file */
+ fapl = h5_fileaccess();
+ h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
+ if ((file=H5Fopen(filename, H5F_ACC_RDONLY, fapl))<0) {
+ goto error;
+ }
+
+ /* Get hard link info */
+ if(H5Gget_objinfo(file, "/group2/group_new_name", TRUE, &sb_hard1)<0)
+ goto error;
+ if(H5Gget_objinfo(file, "/group1/hard", TRUE, &sb_hard2)<0)
+ goto error;
+
+ /* Check hard links */
+ if(H5G_GROUP!=sb_hard1.type || H5G_GROUP!=sb_hard2.type) {
+ H5_FAILED();
+ puts(" Unexpected object type, should have been a group");
+ goto error;
+ }
+ if( sb_hard1.objno[0]!=sb_hard2.objno[0] ||
+ sb_hard1.objno[1]!=sb_hard2.objno[1] ) {
+ H5_FAILED();
+ puts(" Hard link test failed. Link seems not to point to the ");
+ puts(" expected file location.");
+ goto error;
+ }
+
+ /* Check soft links */
+ if (H5Gget_linkval(file, "group2/soft", sizeof linkval, linkval)<0) {
+ goto error;
+ }
+ if (strcmp(linkval, "/group1/group_move")) {
+ H5_FAILED();
+ puts(" Soft link test failed. Wrong link value");
+ goto error;
+ }
+
+ /* Cleanup */
+ if(H5Fclose(file)<0) goto error;
+ PASSED();
+ return 0;
+
+ error:
+ return -1;
+}
/*-------------------------------------------------------------------------
@@ -313,7 +476,9 @@ main(void)
nerrors += test_many(file);
nerrors += test_symlink(file);
nerrors += test_rename(file);
-
+ nerrors += test_new_move();
+ nerrors += check_new_move();
+
/* Close */
if (H5Fclose(file)<0) goto error;
if (nerrors) {