1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://www.hdfgroup.org/licenses.               *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /*-------------------------------------------------------------------------
15  *
16  * Created:     H5Plcpl.c
17  *
18  * Purpose:     Link creation property list class routines
19  *
20  *-------------------------------------------------------------------------
21  */
22 
23 /****************/
24 /* Module Setup */
25 /****************/
26 
27 #include "H5Pmodule.h" /* This source code file is part of the H5P module */
28 
29 /***********/
30 /* Headers */
31 /***********/
32 #include "H5private.h"  /* Generic Functions                        */
33 #include "H5Eprivate.h" /* Error handling                           */
34 #include "H5Iprivate.h" /* IDs                                      */
35 #include "H5Lprivate.h" /* Links                                    */
36 #include "H5Ppkg.h"     /* Property lists                           */
37 
38 /****************/
39 /* Local Macros */
40 /****************/
41 
42 /* ========  Link creation properties ======== */
43 /* Definitions for create intermediate groups flag */
44 #define H5L_CRT_INTERMEDIATE_GROUP_SIZE sizeof(unsigned)
45 #define H5L_CRT_INTERMEDIATE_GROUP_DEF  0
46 #define H5L_CRT_INTERMEDIATE_GROUP_ENC  H5P__encode_unsigned
47 #define H5L_CRT_INTERMEDIATE_GROUP_DEC  H5P__decode_unsigned
48 
49 /******************/
50 /* Local Typedefs */
51 /******************/
52 
53 /********************/
54 /* Package Typedefs */
55 /********************/
56 
57 /********************/
58 /* Local Prototypes */
59 /********************/
60 
61 /* Property class callbacks */
62 static herr_t H5P__lcrt_reg_prop(H5P_genclass_t *pclass);
63 
64 /*********************/
65 /* Package Variables */
66 /*********************/
67 
68 /* Link creation property list class library initialization object */
69 const H5P_libclass_t H5P_CLS_LCRT[1] = {{
70     "link create",        /* Class name for debugging     */
71     H5P_TYPE_LINK_CREATE, /* Class type                   */
72 
73     &H5P_CLS_STRING_CREATE_g,  /* Parent class                 */
74     &H5P_CLS_LINK_CREATE_g,    /* Pointer to class             */
75     &H5P_CLS_LINK_CREATE_ID_g, /* Pointer to class ID          */
76     &H5P_LST_LINK_CREATE_ID_g, /* Pointer to default property list ID */
77     H5P__lcrt_reg_prop,        /* Default property registration routine */
78 
79     NULL, /* Class creation callback      */
80     NULL, /* Class creation callback info */
81     NULL, /* Class copy callback          */
82     NULL, /* Class copy callback info     */
83     NULL, /* Class close callback         */
84     NULL  /* Class close callback info    */
85 }};
86 
87 /*****************************/
88 /* Library Private Variables */
89 /*****************************/
90 
91 /*******************/
92 /* Local Variables */
93 /*******************/
94 
95 /* Property value defaults */
96 static const unsigned H5L_def_intmd_group_g =
97     H5L_CRT_INTERMEDIATE_GROUP_DEF; /* Default setting for creating intermediate groups */
98 
99 /*-------------------------------------------------------------------------
100  * Function:    H5P__lcrt_reg_prop
101  *
102  * Purpose:     Register the dataset creation property list class's properties
103  *
104  * Return:      Non-negative on success/Negative on failure
105  *
106  * Programmer:  Quincey Koziol
107  *              October 31, 2006
108  *-------------------------------------------------------------------------
109  */
110 static herr_t
H5P__lcrt_reg_prop(H5P_genclass_t * pclass)111 H5P__lcrt_reg_prop(H5P_genclass_t *pclass)
112 {
113     herr_t ret_value = SUCCEED; /* Return value */
114 
115     FUNC_ENTER_STATIC
116 
117     /* Register create intermediate groups property */
118     if (H5P__register_real(pclass, H5L_CRT_INTERMEDIATE_GROUP_NAME, H5L_CRT_INTERMEDIATE_GROUP_SIZE,
119                            &H5L_def_intmd_group_g, NULL, NULL, NULL, H5L_CRT_INTERMEDIATE_GROUP_ENC,
120                            H5L_CRT_INTERMEDIATE_GROUP_DEC, NULL, NULL, NULL, NULL) < 0)
121         HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class")
122 
123 done:
124     FUNC_LEAVE_NOAPI(ret_value)
125 } /* end H5P__lcrt_reg_prop() */
126 
127 /*-------------------------------------------------------------------------
128  * Function:    H5Pset_create_intermediate_group
129  *
130  * Purpose:     set crt_intmd_group so that H5Lcreate_*, H5Olink, etc.
131  *              will create missing groups along the given path "name"
132  *
133  * Note:        XXX: This property should really be an access property. -QAK
134  *
135  * Return:      Non-negative on success/Negative on failure
136  *
137  * Programmer:  Peter Cao
138  *              May 08, 2005
139  *-------------------------------------------------------------------------
140  */
141 herr_t
H5Pset_create_intermediate_group(hid_t plist_id,unsigned crt_intmd_group)142 H5Pset_create_intermediate_group(hid_t plist_id, unsigned crt_intmd_group)
143 {
144     H5P_genplist_t *plist;               /* Property list pointer */
145     herr_t          ret_value = SUCCEED; /* Return value */
146 
147     FUNC_ENTER_API(FAIL)
148     H5TRACE2("e", "iIu", plist_id, crt_intmd_group);
149 
150     /* Get the plist structure */
151     if (NULL == (plist = H5P_object_verify(plist_id, H5P_LINK_CREATE)))
152         HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
153 
154     /* Set value */
155     crt_intmd_group = (unsigned)(crt_intmd_group > 0 ? 1 : 0);
156     if (H5P_set(plist, H5L_CRT_INTERMEDIATE_GROUP_NAME, &crt_intmd_group) < 0)
157         HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set intermediate group creation flag")
158 
159 done:
160     FUNC_LEAVE_API(ret_value)
161 } /* end H5Pset_create_intermediate_group() */
162 
163 /*-------------------------------------------------------------------------
164  * Function:    H5Pget_create_intermediate_group
165  *
166  * Purpose:     Returns the crt_intmd_group, which is set to create missing
167  *              groups during H5Olink, etc.
168  *
169  * Return:      Non-negative on success/Negative on failure
170  *
171  * Programmer:  Peter Cao
172  *              May 08, 2005
173  *-------------------------------------------------------------------------
174  */
175 herr_t
H5Pget_create_intermediate_group(hid_t plist_id,unsigned * crt_intmd_group)176 H5Pget_create_intermediate_group(hid_t plist_id, unsigned *crt_intmd_group /*out*/)
177 {
178     H5P_genplist_t *plist;               /* Property list pointer */
179     herr_t          ret_value = SUCCEED; /* return value */
180 
181     FUNC_ENTER_API(FAIL)
182     H5TRACE2("e", "ix", plist_id, crt_intmd_group);
183 
184     /* Get the plist structure */
185     if (NULL == (plist = H5P_object_verify(plist_id, H5P_LINK_CREATE)))
186         HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
187 
188     /* Get values */
189     if (crt_intmd_group)
190         if (H5P_get(plist, H5L_CRT_INTERMEDIATE_GROUP_NAME, crt_intmd_group) < 0)
191             HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get intermediate group creation flag")
192 
193 done:
194     FUNC_LEAVE_API(ret_value)
195 } /* end H5Pget_create_intermediate_group() */
196