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://support.hdfgroup.org/ftp/HDF5/releases.  *
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:		H5Pgcpl.c
17  *			August 29 2006
18  *			Quincey Koziol <koziol@ncsa.uiuc.edu>
19  *
20  * Purpose:		Group creation property list class routines
21  *
22  *-------------------------------------------------------------------------
23  */
24 
25 /****************/
26 /* Module Setup */
27 /****************/
28 #define H5P_PACKAGE		/*suppress error about including H5Ppkg	  */
29 
30 /***********/
31 /* Headers */
32 /***********/
33 #include "H5private.h"		/* Generic Functions			*/
34 #include "H5Eprivate.h"		/* Error handling		  	*/
35 #include "H5Gprivate.h"         /* Groups                               */
36 #include "H5Iprivate.h"		/* IDs			  		*/
37 #include "H5Oprivate.h"		/* Object headers		  	*/
38 #include "H5Ppkg.h"		/* Property lists		  	*/
39 
40 
41 /****************/
42 /* Local Macros */
43 /****************/
44 
45 
46 /******************/
47 /* Local Typedefs */
48 /******************/
49 
50 
51 /********************/
52 /* Package Typedefs */
53 /********************/
54 
55 
56 /********************/
57 /* Local Prototypes */
58 /********************/
59 
60 /* Property class callbacks */
61 static herr_t H5P__gcrt_reg_prop(H5P_genclass_t *pclass);
62 
63 
64 /*********************/
65 /* Package Variables */
66 /*********************/
67 
68 /* Group creation property list class library initialization object */
69 const H5P_libclass_t H5P_CLS_GCRT[1] = {{
70     "group create",		/* Class name for debugging     */
71     H5P_TYPE_GROUP_CREATE,      /* Class type                   */
72 
73     &H5P_CLS_OBJECT_CREATE_g,	/* Parent class                 */
74     &H5P_CLS_GROUP_CREATE_g,	/* Pointer to class             */
75     &H5P_CLS_GROUP_CREATE_ID_g,	/* Pointer to class ID          */
76     &H5P_LST_GROUP_CREATE_ID_g,	/* Pointer to default property list ID */
77     H5P__gcrt_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 /*****************************/
89 /* Library Private Variables */
90 /*****************************/
91 
92 
93 /*******************/
94 /* Local Variables */
95 /*******************/
96 
97 
98 
99 /*-------------------------------------------------------------------------
100  * Function:    H5P__gcrt_reg_prop
101  *
102  * Purpose:     Initialize the group creation property list class
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__gcrt_reg_prop(H5P_genclass_t * pclass)111 H5P__gcrt_reg_prop(H5P_genclass_t *pclass)
112 {
113     H5O_ginfo_t ginfo = H5G_CRT_GROUP_INFO_DEF;     /* Default group info settings */
114     H5O_linfo_t linfo = H5G_CRT_LINK_INFO_DEF;      /* Default link info settings */
115     herr_t ret_value = SUCCEED;         /* Return value */
116 
117     FUNC_ENTER_STATIC
118 
119     /* Register group info property */
120     if(H5P_register_real(pclass, H5G_CRT_GROUP_INFO_NAME, H5G_CRT_GROUP_INFO_SIZE, &ginfo, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0)
121         HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class")
122 
123     /* Register link info property */
124     if(H5P_register_real(pclass, H5G_CRT_LINK_INFO_NAME, H5G_CRT_LINK_INFO_SIZE, &linfo, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0)
125         HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class")
126 
127 done:
128     FUNC_LEAVE_NOAPI(ret_value)
129 } /* end H5P__gcrt_reg_prop() */
130 
131 
132 /*-------------------------------------------------------------------------
133  * Function:    H5Pset_local_heap_size_hint
134  *
135  * Purpose:     Set the "size hint" for creating local heaps for a group.
136  *
137  * Return:      Non-negative on success/Negative on failure
138  *
139  * Programmer:  Quincey Koziol
140  *              August 29, 2005
141  *-------------------------------------------------------------------------
142  */
143 herr_t
H5Pset_local_heap_size_hint(hid_t plist_id,size_t size_hint)144 H5Pset_local_heap_size_hint(hid_t plist_id, size_t size_hint)
145 {
146     H5P_genplist_t *plist;      /* Property list pointer */
147     H5O_ginfo_t ginfo;          /* Group information structure */
148     herr_t ret_value = SUCCEED;       /* Return value */
149 
150     FUNC_ENTER_API(FAIL)
151     H5TRACE2("e", "iz", plist_id, size_hint);
152 
153     /* Get the plist structure */
154     if(NULL == (plist = H5P_object_verify(plist_id, H5P_GROUP_CREATE)))
155         HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
156 
157     /* Get value */
158     if(H5P_get(plist, H5G_CRT_GROUP_INFO_NAME, &ginfo) < 0)
159         HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get group info")
160 
161     /* Update field */
162     H5_CHECKED_ASSIGN(ginfo.lheap_size_hint, uint32_t, size_hint, size_t);
163 
164     /* Set value */
165     if(H5P_set(plist, H5G_CRT_GROUP_INFO_NAME, &ginfo) < 0)
166         HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set group info")
167 
168 done:
169     FUNC_LEAVE_API(ret_value)
170 } /* end H5Pset_local_heap_size_hint() */
171 
172 
173 /*-------------------------------------------------------------------------
174  * Function:    H5Pget_local_heap_size_hint
175  *
176  * Purpose:     Returns the local heap size hint, which is used for creating
177  *              groups
178  *
179  * Return:      Non-negative on success/Negative on failure
180  *
181  * Programmer:  Quincey Koziol
182  *              August 29, 2005
183  *-------------------------------------------------------------------------
184  */
185 herr_t
H5Pget_local_heap_size_hint(hid_t plist_id,size_t * size_hint)186 H5Pget_local_heap_size_hint(hid_t plist_id, size_t *size_hint /*out*/)
187 {
188     herr_t ret_value = SUCCEED;   /* return value */
189 
190     FUNC_ENTER_API(FAIL)
191     H5TRACE2("e", "ix", plist_id, size_hint);
192 
193     if(size_hint) {
194         H5P_genplist_t *plist;      /* Property list pointer */
195         H5O_ginfo_t ginfo;          /* Group information structure */
196 
197         /* Get the plist structure */
198         if(NULL == (plist = H5P_object_verify(plist_id, H5P_GROUP_CREATE)))
199             HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
200 
201         /* Get value */
202         if(H5P_get(plist, H5G_CRT_GROUP_INFO_NAME, &ginfo) < 0)
203             HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get group info")
204 
205         /* Update field */
206         *size_hint = ginfo.lheap_size_hint;
207     } /* end if */
208 
209 done:
210     FUNC_LEAVE_API(ret_value)
211 } /* end H5Pget_local_heap_size_hint() */
212 
213 
214 /*-------------------------------------------------------------------------
215  * Function:    H5Pset_link_phase_change
216  *
217  * Purpose:     Set the maximum # of links to store "compactly" and the
218  *              minimum # of links to store "densely".  (These should
219  *              overlap).
220  *
221  * Note:        Currently both of these must be updated at the same time.
222  *
223  * Note:        Come up with better name & description! -QAK
224  *
225  * Return:      Non-negative on success/Negative on failure
226  *
227  * Programmer:  Quincey Koziol
228  *              August 29, 2005
229  *-------------------------------------------------------------------------
230  */
231 herr_t
H5Pset_link_phase_change(hid_t plist_id,unsigned max_compact,unsigned min_dense)232 H5Pset_link_phase_change(hid_t plist_id, unsigned max_compact, unsigned min_dense)
233 {
234     H5P_genplist_t *plist;              /* Property list pointer */
235     H5O_ginfo_t ginfo;                  /* Group information structure */
236     herr_t ret_value = SUCCEED;         /* Return value */
237 
238     FUNC_ENTER_API(FAIL)
239     H5TRACE3("e", "iIuIu", plist_id, max_compact, min_dense);
240 
241     /* Range check values */
242     if(max_compact < min_dense)
243         HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "max compact value must be >= min dense value")
244     if(max_compact > 65535)
245         HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "max compact value must be < 65536")
246     if(min_dense > 65535)
247         HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "min dense value must be < 65536")
248 
249     /* Get the plist structure */
250     if(NULL == (plist = H5P_object_verify(plist_id, H5P_GROUP_CREATE)))
251         HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
252 
253     /* Get group info */
254     if(H5P_get(plist, H5G_CRT_GROUP_INFO_NAME, &ginfo) < 0)
255         HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get group info")
256 
257     /* Update fields */
258     if(max_compact != H5G_CRT_GINFO_MAX_COMPACT || min_dense != H5G_CRT_GINFO_MIN_DENSE)
259         ginfo.store_link_phase_change = TRUE;
260     else
261         ginfo.store_link_phase_change = FALSE;
262     ginfo.max_compact = (uint16_t)max_compact;
263     ginfo.min_dense = (uint16_t)min_dense;
264 
265     /* Set group info */
266     if(H5P_set(plist, H5G_CRT_GROUP_INFO_NAME, &ginfo) < 0)
267         HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set group info")
268 
269 done:
270     FUNC_LEAVE_API(ret_value)
271 } /* end H5Pset_link_phase_change() */
272 
273 
274 /*-------------------------------------------------------------------------
275  * Function:    H5Pget_link_phase_change
276  *
277  * Purpose:     Returns the max. # of compact links & the min. # of dense
278  *              links, which are used for storing groups
279  *
280  * Return:      Non-negative on success/Negative on failure
281  *
282  * Programmer:  Quincey Koziol
283  *              August 29, 2005
284  *-------------------------------------------------------------------------
285  */
286 herr_t
H5Pget_link_phase_change(hid_t plist_id,unsigned * max_compact,unsigned * min_dense)287 H5Pget_link_phase_change(hid_t plist_id, unsigned *max_compact /*out*/, unsigned *min_dense /*out*/)
288 {
289     herr_t ret_value = SUCCEED;   /* return value */
290 
291     FUNC_ENTER_API(FAIL)
292     H5TRACE3("e", "ixx", plist_id, max_compact, min_dense);
293 
294     /* Get values */
295     if(max_compact || min_dense) {
296         H5P_genplist_t *plist;      /* Property list pointer */
297         H5O_ginfo_t ginfo;          /* Group information structure */
298 
299         /* Get the plist structure */
300         if(NULL == (plist = H5P_object_verify(plist_id, H5P_GROUP_CREATE)))
301             HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
302 
303         /* Get group info */
304         if(H5P_get(plist, H5G_CRT_GROUP_INFO_NAME, &ginfo) < 0)
305             HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get group info")
306 
307         if(max_compact)
308             *max_compact = ginfo.max_compact;
309         if(min_dense)
310             *min_dense = ginfo.min_dense;
311     } /* end if */
312 
313 done:
314     FUNC_LEAVE_API(ret_value)
315 } /* end H5Pget_link_phase_change() */
316 
317 
318 /*-------------------------------------------------------------------------
319  * Function:    H5Pset_est_link_info
320  *
321  * Purpose:     Set the estimates for the number of entries and length of each
322  *              entry name in a group.
323  *
324  * Note:        Currently both of these must be updated at the same time.
325  *
326  * Note:        EST_NUM_ENTRIES applies only when the number of entries is less
327  *              than the MAX_COMPACT # of entries (from H5Pset_link_phase_change).
328  *
329  * Note:        Come up with better name & description? -QAK
330  *
331  * Return:      Non-negative on success/Negative on failure
332  *
333  * Programmer:  Quincey Koziol
334  *              September  6, 2005
335  *-------------------------------------------------------------------------
336  */
337 herr_t
H5Pset_est_link_info(hid_t plist_id,unsigned est_num_entries,unsigned est_name_len)338 H5Pset_est_link_info(hid_t plist_id, unsigned est_num_entries, unsigned est_name_len)
339 {
340     H5P_genplist_t *plist;              /* Property list pointer */
341     H5O_ginfo_t ginfo;                  /* Group information structure */
342     herr_t ret_value = SUCCEED;         /* Return value */
343 
344     FUNC_ENTER_API(FAIL)
345     H5TRACE3("e", "iIuIu", plist_id, est_num_entries, est_name_len);
346 
347     /* Range check values */
348     if(est_num_entries > 65535)
349         HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "est. number of entries must be < 65536")
350     if(est_name_len > 65535)
351         HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "est. name length must be < 65536")
352 
353     /* Get the plist structure */
354     if(NULL == (plist = H5P_object_verify(plist_id, H5P_GROUP_CREATE)))
355         HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
356 
357     /* Get group info */
358     if(H5P_get(plist, H5G_CRT_GROUP_INFO_NAME, &ginfo) < 0)
359         HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get group info")
360 
361     /* Update fields */
362     if(est_num_entries != H5G_CRT_GINFO_EST_NUM_ENTRIES || est_name_len != H5G_CRT_GINFO_EST_NAME_LEN)
363         ginfo.store_est_entry_info = TRUE;
364     else
365         ginfo.store_est_entry_info = FALSE;
366     ginfo.est_num_entries = (uint16_t)est_num_entries;
367     ginfo.est_name_len = (uint16_t)est_name_len;
368 
369     /* Set group info */
370     if(H5P_set(plist, H5G_CRT_GROUP_INFO_NAME, &ginfo) < 0)
371         HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set group info")
372 
373 done:
374     FUNC_LEAVE_API(ret_value)
375 } /* end H5Pset_est_link_info() */
376 
377 
378 /*-------------------------------------------------------------------------
379  * Function:    H5Pget_est_link_info
380  *
381  * Purpose:     Returns the est. # of links in a group & the est. length of
382  *              the name of each link.
383  *
384  * Return:      Non-negative on success/Negative on failure
385  *
386  * Programmer:  Quincey Koziol
387  *              September  6, 2005
388  *-------------------------------------------------------------------------
389  */
390 herr_t
H5Pget_est_link_info(hid_t plist_id,unsigned * est_num_entries,unsigned * est_name_len)391 H5Pget_est_link_info(hid_t plist_id, unsigned *est_num_entries /*out*/, unsigned *est_name_len /*out*/)
392 {
393     herr_t ret_value = SUCCEED;   /* return value */
394 
395     FUNC_ENTER_API(FAIL)
396     H5TRACE3("e", "ixx", plist_id, est_num_entries, est_name_len);
397 
398     /* Get values */
399     if(est_num_entries || est_name_len) {
400         H5P_genplist_t *plist;      /* Property list pointer */
401         H5O_ginfo_t ginfo;          /* Group information structure */
402 
403         /* Get the plist structure */
404         if(NULL == (plist = H5P_object_verify(plist_id, H5P_GROUP_CREATE)))
405             HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
406 
407         /* Get group info */
408         if(H5P_get(plist, H5G_CRT_GROUP_INFO_NAME, &ginfo) < 0)
409             HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get group info")
410 
411         if(est_num_entries)
412             *est_num_entries = ginfo.est_num_entries;
413         if(est_name_len)
414             *est_name_len = ginfo.est_name_len;
415     } /* end if */
416 
417 done:
418     FUNC_LEAVE_API(ret_value)
419 } /* end H5Pget_est_link_info() */
420 
421 
422 /*-------------------------------------------------------------------------
423  * Function:    H5Pset_link_creation_order
424  *
425  * Purpose:     Set the flags for creation order of links in a group
426  *
427  * Return:      Non-negative on success/Negative on failure
428  *
429  * Programmer:  Quincey Koziol
430  *              September 12, 2006
431  *-------------------------------------------------------------------------
432  */
433 herr_t
H5Pset_link_creation_order(hid_t plist_id,unsigned crt_order_flags)434 H5Pset_link_creation_order(hid_t plist_id, unsigned crt_order_flags)
435 {
436     H5P_genplist_t *plist;              /* Property list pointer */
437     H5O_linfo_t linfo;                  /* Link information structure */
438     herr_t ret_value = SUCCEED;         /* Return value */
439 
440     FUNC_ENTER_API(FAIL)
441     H5TRACE2("e", "iIu", plist_id, crt_order_flags);
442 
443         /* Check for bad combination of flags */
444     if(!(crt_order_flags & H5P_CRT_ORDER_TRACKED) && (crt_order_flags & H5P_CRT_ORDER_INDEXED))
445         HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "tracking creation order is required for index")
446 
447     /* Get the plist structure */
448     if(NULL == (plist = H5P_object_verify(plist_id, H5P_GROUP_CREATE)))
449         HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
450 
451     /* Get link info */
452     if(H5P_get(plist, H5G_CRT_LINK_INFO_NAME, &linfo) < 0)
453         HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get link info")
454 
455     /* Update fields */
456     linfo.track_corder = (hbool_t)((crt_order_flags & H5P_CRT_ORDER_TRACKED) ? TRUE : FALSE);
457     linfo.index_corder = (hbool_t)((crt_order_flags & H5P_CRT_ORDER_INDEXED) ? TRUE : FALSE);
458 
459     /* Set link info */
460     if(H5P_set(plist, H5G_CRT_LINK_INFO_NAME, &linfo) < 0)
461         HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set link info")
462 
463 done:
464     FUNC_LEAVE_API(ret_value)
465 } /* end H5Pset_link_creation_order() */
466 
467 
468 /*-------------------------------------------------------------------------
469  * Function:    H5Pget_link_creation_order
470  *
471  * Purpose:     Returns the flag indicating that creation order is tracked
472  *              for links in a group.
473  *
474  * Return:      Non-negative on success/Negative on failure
475  *
476  * Programmer:  Quincey Koziol
477  *              September 12, 2006
478  *-------------------------------------------------------------------------
479  */
480 herr_t
H5Pget_link_creation_order(hid_t plist_id,unsigned * crt_order_flags)481 H5Pget_link_creation_order(hid_t plist_id, unsigned *crt_order_flags /*out*/)
482 {
483     herr_t ret_value = SUCCEED;   /* return value */
484 
485     FUNC_ENTER_API(FAIL)
486     H5TRACE2("e", "ix", plist_id, crt_order_flags);
487 
488     /* Get values */
489     if(crt_order_flags) {
490         H5P_genplist_t *plist;      /* Property list pointer */
491         H5O_linfo_t linfo;          /* Link information structure */
492 
493         /* Reset the value to return */
494         *crt_order_flags = 0;
495 
496         /* Get the plist structure */
497         if(NULL == (plist = H5P_object_verify(plist_id, H5P_GROUP_CREATE)))
498             HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
499 
500         /* Get link info */
501         if(H5P_get(plist, H5G_CRT_LINK_INFO_NAME, &linfo) < 0)
502             HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get link info")
503 
504         *crt_order_flags |= linfo.track_corder ? H5P_CRT_ORDER_TRACKED : 0;
505         *crt_order_flags |= linfo.index_corder ? H5P_CRT_ORDER_INDEXED : 0;
506     } /* end if */
507 
508 done:
509     FUNC_LEAVE_API(ret_value)
510 } /* end H5Pget_link_creation_order() */
511 
512