Please, help us to better serve our user community by answering the following short survey: https://www.hdfgroup.org/website-survey/
HDF5  1.14.4.3
API Reference
 
Loading...
Searching...
No Matches
Link Access Properties

Detailed Description

Link access property list functions (H5P)
Function Purpose
H5Pset_elink_cb/H5Pget_elink_cb Sets/gets the external link traversal callback function.
H5Pset_elink_acc_flags/H5Pget_elink_acc_flags Sets/gets the external link traversal file access flag.
H5Pset_elink_fapl/H5Pget_elink_fapl Sets/gets a file access property list for use in accessing a file pointed to by an external link
H5Pset_elink_prefix/H5Pget_elink_prefix Sets/gets prefix to be applied to external link paths.
H5Pset_nlinks/H5Pget_nlinks Sets/gets maximum number of soft or user-defined link traversals.

Modules

 Dataset Access Properties
 
 Datatype Access Properties
 
 Group Access Properties
 

Functions

herr_t H5Pget_elink_acc_flags (hid_t lapl_id, unsigned *flags)
 Retrieves the external link traversal file access flag from the specified link access property list.
 
herr_t H5Pget_elink_cb (hid_t lapl_id, H5L_elink_traverse_t *func, void **op_data)
 Retrieves the external link traversal callback function from the specified link access property list.
 
hid_t H5Pget_elink_fapl (hid_t lapl_id)
 Retrieves the file access property list identifier associated with the link access property list.
 
ssize_t H5Pget_elink_prefix (hid_t plist_id, char *prefix, size_t size)
 Retrieves prefix applied to external link paths.
 
herr_t H5Pget_nlinks (hid_t plist_id, size_t *nlinks)
 Retrieves the maximum number of link traversals.
 
herr_t H5Pset_elink_acc_flags (hid_t lapl_id, unsigned flags)
 Sets the external link traversal file access flag in a link access property list.
 
herr_t H5Pset_elink_cb (hid_t lapl_id, H5L_elink_traverse_t func, void *op_data)
 Sets the external link traversal callback function in a link access property list.
 
herr_t H5Pset_elink_fapl (hid_t lapl_id, hid_t fapl_id)
 Sets a file access property list for use in accessing a file pointed to by an external link.
 
herr_t H5Pset_elink_prefix (hid_t plist_id, const char *prefix)
 Sets prefix to be applied to external link paths.
 
herr_t H5Pset_nlinks (hid_t plist_id, size_t nlinks)
 Sets maximum number of soft or user-defined link traversals.
 

Function Documentation

◆ H5Pget_elink_acc_flags()

herr_t H5Pget_elink_acc_flags ( hid_t  lapl_id,
unsigned *  flags 
)

Retrieves the external link traversal file access flag from the specified link access property list.

Parameters
[in]lapl_idLink access property list identifier
[out]flagsFile access flag for link traversal
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Pget_elink_acc_flags() retrieves the file access flag used to open an external link target file from the specified link access property list.

Valid values for flags include:

  • H5F_ACC_RDWR - Files opened through external links will be opened with write access
  • H5F_ACC_RDONLY - Files opened through external links will be opened with read-only access
  • H5F_ACC_DEFAULT - Files opened through external links will be opened with the same access flag as the parent file

The value returned, if it is not H5F_ACC_DEFAULT, will override the default access flag, which is the access flag used to open the parent file.

Example Usage: The following code retrieves the external link access flag settings on the link access property list lapl_id into a local variable:

        unsigned acc_flags;
        status = H5Pget_elink_acc_flags(lapl_id, &acc_flags);
      
Since
1.8.3

◆ H5Pget_elink_cb()

herr_t H5Pget_elink_cb ( hid_t  lapl_id,
H5L_elink_traverse_t func,
void **  op_data 
)

Retrieves the external link traversal callback function from the specified link access property list.

Parameters
[in]lapl_idLink access property list identifier
[out]funcUser-defined external link traversal callback function
[out]op_dataUser-defined input data for the callback function
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Pget_elink_cb() retrieves the user-defined external link traversal callback function defined in the specified link access property list.

The callback function may adjust the file access property list and file access flag to use when opening a file through an external link. The callback will be executed by the HDF5 library immediately before opening the target file.

Failure Modes: H5Pget_elink_cb() will fail if the link access property list identifier, lapl_id, is invalid.

An invalid function pointer or data pointer, func or op_data respectively, may cause a segmentation fault or an invalid memory access.

Example Usage: The following code retrieves the external link callback settings on the link access property list lapl_id into local variables:

      H5L_elink_traverse_t elink_callback_func;
      void *elink_callback_udata;
      status = H5Pget_elink_cb (lapl_id, &elink_callback_func,
                                &elink_callback_udata);
      
Since
1.8.3

◆ H5Pget_elink_fapl()

hid_t H5Pget_elink_fapl ( hid_t  lapl_id)

Retrieves the file access property list identifier associated with the link access property list.

Parameters
[in]lapl_idLink access property list identifier
Returns
Returns a file access property list identifier if successful; otherwise returns H5I_INVALID_HID.

H5Pget_elink_fapl() retrieves the file access property list identifier that is set for the link access property list identifier, lapl_id. The library uses this file access property list identifier to open the target file for the external link access. When no such identifier is set, this routine returns H5P_DEFAULT.

See also
H5Pset_elink_fapl() and H5Lcreate_external().
Since
1.8.0

◆ H5Pget_elink_prefix()

ssize_t H5Pget_elink_prefix ( hid_t  plist_id,
char *  prefix,
size_t  size 
)

Retrieves prefix applied to external link paths.

Parameters
[in]plist_idLink access property list identifier
[out]prefixPrefix applied to external link paths
[in]sizeSize of prefix, including null terminator
Returns
If successful, returns a non-negative value specifying the size in bytes of the prefix without the NULL terminator; otherwise returns a negative value.

H5Pget_elink_prefix() retrieves the prefix applied to the path of any external links traversed.

When an external link is traversed, the prefix is retrieved from the link access property list plist_id, returned in the user-allocated buffer pointed to by prefix, and prepended to the filename stored in the external link.

The size in bytes of the prefix, including the NULL terminator, is specified in size. If size is unknown, a preliminary H5Pget_elink_prefix() call with the pointer prefix set to NULL will return the size of the prefix without the NULL terminator.

Since
1.8.0

◆ H5Pget_nlinks()

herr_t H5Pget_nlinks ( hid_t  plist_id,
size_t *  nlinks 
)

Retrieves the maximum number of link traversals.

Parameters
[in]plist_idLink access property list identifier
[out]nlinksMaximum number of links to traverse
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Pget_nlinks() retrieves the maximum number of soft or user-defined link traversals allowed, nlinks, before the library assumes it has found a cycle and aborts the traversal. This value is retrieved from the link access property list plist_id.

The limit on the number of soft or user-defined link traversals is designed to terminate link traversal if one or more links form a cycle. User control is provided because some files may have legitimate paths formed of large numbers of soft or user-defined links. This property can be used to allow traversal of as many links as desired.

Since
1.8.0

◆ H5Pset_elink_acc_flags()

herr_t H5Pset_elink_acc_flags ( hid_t  lapl_id,
unsigned  flags 
)

Sets the external link traversal file access flag in a link access property list.

Parameters
[in]lapl_idLink access property list identifier
[in]flagsThe access flag for external link traversal
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Pset_elink_acc_flags() specifies the file access flag to use to open the target file of an external link. This allows read-only access of files reached through an external link in a file opened with write access, or vice-versa.

Valid values for flags include:

  • H5F_ACC_RDWR - Causes files opened through external links to be opened with write access
  • H5F_ACC_RDONLY - Causes files opened through external links to be opened with read-only access
  • H5F_ACC_DEFAULT - Removes any external link file access flag setting from lapl_id, causing the file access flag setting to be taken from the parent file

The library will normally use the file access flag used to open the parent file as the file access flag for the target file. This function provides a way to override that behavior. The external link traversal callback function set by H5Pset_elink_cb() can override the setting from H5Pset_elink_acc_flags().

Motivation: H5Pset_elink_acc_flags() is used to adjust the file access flag used to open files reached through external links. This may be useful to, for example, prevent modifying files accessed through an external link. Otherwise, the target file is opened with whatever flag was used to open the parent.

Example Usage: The following code sets the link access property list lapl_id to open external link target files with read-only access:

        status = H5Pset_elink_acc_flags(lapl_id, H5F_ACC_RDONLY);
       
Since
1.8.3

◆ H5Pset_elink_cb()

herr_t H5Pset_elink_cb ( hid_t  lapl_id,
H5L_elink_traverse_t  func,
void *  op_data 
)

Sets the external link traversal callback function in a link access property list.

Parameters
[in]lapl_idLink access property list identifier
[in]funcUser-defined external link traversal callback function
[in]op_dataUser-defined input data for the callback function
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Pset_elink_cb() sets a user-defined external link traversal callback function in the link access property list lapl_id. The callback function func must conform to the prototype specified in H5L_elink_traverse_t.

The callback function may adjust the file access property list and file access flags to use when opening a file through an external link. The callback will be executed by the HDF5 library immediately before opening the target file.

The callback will be made after the file access property list set by H5Pset_elink_fapl() and the file access flag set by H5Pset_elink_acc_flags() are applied, so changes made by this callback function will take precedence.

Attention
A file close degree property setting (H5Pset_fclose_degree()) in this callback function or an associated property list will be ignored. A file opened by means of traversing an external link is always opened with the weak file close degree property setting, H5F_CLOSE_WEAK.

Motivation: H5Pset_elink_cb() is used to specify a callback function that is executed by the HDF5 library when traversing an external link. This provides a mechanism to set specific access permissions, modify the file access property list, modify the parent or target file, or take any other user-defined action. This callback function is used in situations where the HDF5 library's default behavior is not suitable.

Failure Modes: H5Pset_elink_cb() will fail if the link access property list identifier, lapl_id, is invalid or if the function pointer, func, is NULL.

An invalid function pointer, func, will cause a segmentation fault or other failure when an attempt is subsequently made to traverse an external link.

Example Usage: This example defines a callback function that prints the name of the target file every time an external link is followed, and sets this callback function on lapl_id.

         herr_t elink_callback(const char *parent_file_name, const char
                *parent_group_name, const char *child_file_name, const char
                *child_object_name, unsigned *acc_flags, hid_t fapl_id, void *op_data) {
             puts(child_file_name);
             return 0;
         }
         int main(void) {
             hid_t lapl_id = H5Pcreate(H5P_LINK_ACCESS);
             H5Pset_elink_cb(lapl_id, elink_callback, NULL);
               ...
         }
         
Since
1.8.3

◆ H5Pset_elink_fapl()

herr_t H5Pset_elink_fapl ( hid_t  lapl_id,
hid_t  fapl_id 
)

Sets a file access property list for use in accessing a file pointed to by an external link.

Parameters
[in]lapl_idLink access property list identifier
[in]fapl_idFile access property list identifier
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Pset_elink_fapl() sets the file access property list, fapl_id, to be used when accessing the target file of an external link associated with lapl_id.

Since
1.8.0

◆ H5Pset_elink_prefix()

herr_t H5Pset_elink_prefix ( hid_t  plist_id,
const char *  prefix 
)

Sets prefix to be applied to external link paths.

Parameters
[in]plist_idLink access property list identifier
[in]prefixPrefix to be applied to external link paths
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Pset_elink_prefix() sets the prefix to be applied to the path of any external links traversed. The prefix is prepended to the filename stored in the external link.

The prefix is specified in the user-allocated buffer prefix and set in the link access property list plist_id. The buffer should not be freed until the property list has been closed.

Since
1.8.0

◆ H5Pset_nlinks()

herr_t H5Pset_nlinks ( hid_t  plist_id,
size_t  nlinks 
)

Sets maximum number of soft or user-defined link traversals.

Parameters
[in]plist_idLink access property list identifier
[in]nlinksMaximum number of links to traverse
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Pset_nlinks() sets the maximum number of soft or user-defined link traversals allowed, nlinks, before the library assumes it has found a cycle and aborts the traversal. This value is set in the link access property list plist_id.

The limit on the number of soft or user-defined link traversals is designed to terminate link traversal if one or more links form a cycle. User control is provided because some files may have legitimate paths formed of large numbers of soft or user-defined links. This property can be used to allow traversal of as many links as desired.

Since
1.8.0