Symbolic links with relative path


#1

Hi,

I know that it is possible to set relative path to the target when creating soft link for example.
But what if the target is one level above in the hierarchy?
For example the target dataset is located /dset.
And the soft link are going to be placed to /group/dset_link.
What will be the relative path in that case? I ve tried to set it as ../dset but it seem not to work…

Also is there any restricted symbols for link names? Or is there some rules like the link name must not start with space…


#2

In HDF5 path names, .. does not have the meaning it does in a shell. .. is a legitimate link name. In the example below, two groups are created. The first is linked as .. under the root group, the second is linked as ... in the first group.

In HDF5, .. cannot have the meaning of “one level above in the hierarchy”, because we are dealing with multi-graphs. A node can have multiple (direct) parents, and the concept of level is meaningful only for tree-like structures.

Only the path separator / and the combination ./ and /./ are special. A single space or multiple spaces are legitimate link names.

G.

Example

#include "hdf5.h"
#include <stdlib.h>

int main()
{
  __label__ fail_group, fail_prop, fail_lcpl, fail_file;
  int ret_val = EXIT_SUCCESS;
  hid_t file, lcpl, group;
  char  fname[] = "g2.h5";
  char  path[]  = "./../...";

  if ((file = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) ==
      H5I_INVALID_HID) {
    ret_val = EXIT_FAILURE;
    goto fail_file;
  }

  if ((lcpl = H5Pcreate(H5P_LINK_CREATE)) == H5I_INVALID_HID) {
    ret_val = EXIT_FAILURE;
    goto fail_lcpl;
  }
  // ensure that intermediate groups are created automatically
  if (H5Pset_create_intermediate_group(lcpl, 1) < 0) {
    ret_val = EXIT_FAILURE;
    goto fail_prop;
  }
  // create two groups
  if ((group = H5Gcreate(file, path, lcpl, H5P_DEFAULT, H5P_DEFAULT)) ==
      H5I_INVALID_HID) {
    ret_val = EXIT_FAILURE;
    goto fail_group;
  }
  H5Gclose(group);
fail_group:
fail_prop:
  H5Pclose(lcpl);
fail_lcpl:
  H5Fclose(file);
fail_file:
  return ret_val;
}
$ h5dump g2.h5 
HDF5 "g2.h5" {
GROUP "/" {
   GROUP ".." {
      GROUP "..." {
      }
   }
}

#3

I forgot to mention that in HDF5 the ‘relative’ in ‘relative path’ always means relative to the accompanying handle loc_id, e.g., file handle, group handle, etc.

G.


#4

Thank you very much for such comprehensive answer.

Very interesting, good to know