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 * Programmer: Robb Matzke <matzke@llnl.gov>
16 * Wednesday, April 15, 1998
17 *
18 * Purpose: Data filter pipeline message.
19 */
20
21 #define H5O_PACKAGE /*suppress error about including H5Opkg */
22 #define H5Z_PACKAGE /*suppress error about including H5Zpkg */
23
24 #include "H5private.h" /* Generic Functions */
25 #include "H5Dprivate.h" /* Datasets */
26 #include "H5Eprivate.h" /* Error handling */
27 #include "H5FLprivate.h" /* Free Lists */
28 #include "H5MMprivate.h" /* Memory management */
29 #include "H5Opkg.h" /* Object headers */
30 #include "H5Zpkg.h" /* Data filters */
31
32
33 /* PRIVATE PROTOTYPES */
34 static herr_t H5O_pline_encode(H5F_t *f, uint8_t *p, const void *mesg);
35 static void *H5O_pline_decode(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh,
36 unsigned mesg_flags, unsigned *ioflags, size_t p_size, const uint8_t *p);
37 static void *H5O_pline_copy(const void *_mesg, void *_dest);
38 static size_t H5O_pline_size(const H5F_t *f, const void *_mesg);
39 static herr_t H5O_pline_reset(void *_mesg);
40 static herr_t H5O_pline_free(void *_mesg);
41 static herr_t H5O_pline_pre_copy_file(H5F_t *file_src,
42 const void *mesg_src, hbool_t *deleted, const H5O_copy_t *cpy_info, void *_udata);
43 static herr_t H5O_pline_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg,
44 FILE * stream, int indent, int fwidth);
45
46 /* Set up & include shared message "interface" info */
47 #define H5O_SHARED_TYPE H5O_MSG_PLINE
48 #define H5O_SHARED_DECODE H5O_pline_shared_decode
49 #define H5O_SHARED_DECODE_REAL H5O_pline_decode
50 #define H5O_SHARED_ENCODE H5O_pline_shared_encode
51 #define H5O_SHARED_ENCODE_REAL H5O_pline_encode
52 #define H5O_SHARED_SIZE H5O_pline_shared_size
53 #define H5O_SHARED_SIZE_REAL H5O_pline_size
54 #define H5O_SHARED_DELETE H5O_pline_shared_delete
55 #undef H5O_SHARED_DELETE_REAL
56 #define H5O_SHARED_LINK H5O_pline_shared_link
57 #undef H5O_SHARED_LINK_REAL
58 #define H5O_SHARED_COPY_FILE H5O_pline_shared_copy_file
59 #undef H5O_SHARED_COPY_FILE_REAL
60 #define H5O_SHARED_POST_COPY_FILE H5O_pline_shared_post_copy_file
61 #undef H5O_SHARED_POST_COPY_FILE_REAL
62 #undef H5O_SHARED_POST_COPY_FILE_UPD
63 #define H5O_SHARED_DEBUG H5O_pline_shared_debug
64 #define H5O_SHARED_DEBUG_REAL H5O_pline_debug
65 #include "H5Oshared.h" /* Shared Object Header Message Callbacks */
66
67 /* This message derives from H5O message class */
68 const H5O_msg_class_t H5O_MSG_PLINE[1] = {{
69 H5O_PLINE_ID, /* message id number */
70 "filter pipeline", /* message name for debugging */
71 sizeof(H5O_pline_t), /* native message size */
72 H5O_SHARE_IS_SHARABLE|H5O_SHARE_IN_OHDR, /* messages are sharable? */
73 H5O_pline_shared_decode, /* decode message */
74 H5O_pline_shared_encode, /* encode message */
75 H5O_pline_copy, /* copy the native value */
76 H5O_pline_shared_size, /* size of raw message */
77 H5O_pline_reset, /* reset method */
78 H5O_pline_free, /* free method */
79 H5O_pline_shared_delete, /* file delete method */
80 H5O_pline_shared_link, /* link method */
81 NULL, /* set share method */
82 NULL, /*can share method */
83 H5O_pline_pre_copy_file, /* pre copy native value to file */
84 H5O_pline_shared_copy_file, /* copy native value to file */
85 H5O_pline_shared_post_copy_file, /* post copy native value to file */
86 NULL, /* get creation index */
87 NULL, /* set creation index */
88 H5O_pline_shared_debug /* debug the message */
89 }};
90
91
92 /* Declare a free list to manage the H5O_pline_t struct */
93 H5FL_DEFINE(H5O_pline_t);
94
95
96 /*-------------------------------------------------------------------------
97 * Function: H5O_pline_decode
98 *
99 * Purpose: Decodes a filter pipeline message.
100 *
101 * Return: Success: Ptr to the native message.
102 * Failure: NULL
103 *
104 * Programmer: Robb Matzke
105 * Wednesday, April 15, 1998
106 *
107 *-------------------------------------------------------------------------
108 */
109 static void *
H5O_pline_decode(H5F_t H5_ATTR_UNUSED * f,hid_t H5_ATTR_UNUSED dxpl_id,H5O_t H5_ATTR_UNUSED * open_oh,unsigned H5_ATTR_UNUSED mesg_flags,unsigned H5_ATTR_UNUSED * ioflags,size_t p_size,const uint8_t * p)110 H5O_pline_decode(H5F_t H5_ATTR_UNUSED *f, hid_t H5_ATTR_UNUSED dxpl_id, H5O_t H5_ATTR_UNUSED *open_oh,
111 unsigned H5_ATTR_UNUSED mesg_flags, unsigned H5_ATTR_UNUSED *ioflags,
112 size_t p_size, const uint8_t *p)
113 {
114 H5O_pline_t *pline = NULL; /* Pipeline message */
115 H5Z_filter_info_t *filter; /* Filter to decode */
116 size_t name_length; /* Length of filter name */
117 size_t i; /* Local index variable */
118 const uint8_t *p_end = p + p_size - 1; /* End of the p buffer */
119 void *ret_value = NULL; /* Return value */
120
121 FUNC_ENTER_NOAPI_NOINIT
122
123 /* check args */
124 HDassert(p);
125
126 /* Allocate space for I/O pipeline message */
127 if(NULL == (pline = H5FL_CALLOC(H5O_pline_t)))
128 HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
129
130 /* Version */
131 pline->version = *p++;
132 if(pline->version < H5O_PLINE_VERSION_1 || pline->version > H5O_PLINE_VERSION_LATEST)
133 HGOTO_ERROR(H5E_PLINE, H5E_CANTLOAD, NULL, "bad version number for filter pipeline message")
134
135 /* Number of filters */
136 pline->nused = *p++;
137 if(pline->nused > H5Z_MAX_NFILTERS) {
138
139 /* Reset the number of filters used to avoid array traversal in error
140 * handling code.
141 */
142 pline->nused = 0;
143
144 HGOTO_ERROR(H5E_PLINE, H5E_CANTLOAD, NULL, "filter pipeline message has too many filters")
145 }
146
147 /* Reserved */
148 if(pline->version == H5O_PLINE_VERSION_1)
149 p += 6;
150
151 /* Allocate array for filters */
152 pline->nalloc = pline->nused;
153 if(NULL == (pline->filter = (H5Z_filter_info_t *)H5MM_calloc(pline->nalloc * sizeof(pline->filter[0]))))
154 HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
155
156 /* Decode filters */
157 for(i = 0, filter = &pline->filter[0]; i < pline->nused; i++, filter++) {
158 /* Filter ID */
159 UINT16DECODE(p, filter->id);
160
161 /* Length of filter name */
162 if(pline->version > H5O_PLINE_VERSION_1 && filter->id < H5Z_FILTER_RESERVED)
163 name_length = 0;
164 else {
165 UINT16DECODE(p, name_length);
166 if(pline->version == H5O_PLINE_VERSION_1 && name_length % 8)
167 HGOTO_ERROR(H5E_PLINE, H5E_CANTLOAD, NULL, "filter name length is not a multiple of eight")
168 } /* end if */
169
170 /* Filter flags */
171 UINT16DECODE(p, filter->flags);
172
173 /* Number of filter parameters ("client data elements") */
174 UINT16DECODE(p, filter->cd_nelmts);
175
176 /* Filter name, if there is one */
177 if(name_length) {
178 size_t actual_name_length; /* Actual length of name */
179
180 /* Determine actual name length (without padding, but with null terminator) */
181 actual_name_length = HDstrlen((const char *)p) + 1;
182 HDassert(actual_name_length <= name_length);
183
184 /* Allocate space for the filter name, or use the internal buffer */
185 if(actual_name_length > H5Z_COMMON_NAME_LEN) {
186 filter->name = (char *)H5MM_malloc(actual_name_length);
187 if(NULL == filter->name)
188 HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for filter name")
189 } /* end if */
190 else
191 filter->name = filter->_name;
192
193 HDstrncpy(filter->name, (const char *)p, actual_name_length);
194 p += name_length;
195 } /* end if */
196
197 /* Filter parameters */
198 if(filter->cd_nelmts) {
199 size_t j; /* Local index variable */
200
201 /* Allocate space for the client data elements, or use the internal buffer */
202 if(filter->cd_nelmts > H5Z_COMMON_CD_VALUES) {
203 filter->cd_values = (unsigned *)H5MM_malloc(filter->cd_nelmts * sizeof(unsigned));
204 if(NULL == filter->cd_values)
205 HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for client data")
206 } /* end if */
207 else
208 filter->cd_values = filter->_cd_values;
209
210 /*
211 * Read the client data values and the padding
212 */
213 for (j = 0; j < filter->cd_nelmts; j++) {
214 if (p + 4 - 1 <= p_end)
215 UINT32DECODE(p, filter->cd_values[j])
216 else
217 HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "ran off the end of the buffer: current p = %p, p_size = %zu, p_end = %p", p, p_size, p_end)
218 }
219
220 if(pline->version == H5O_PLINE_VERSION_1)
221 if(filter->cd_nelmts % 2)
222 p += 4; /*padding*/
223 } /* end if */
224 } /* end for */
225
226 /* Set return value */
227 ret_value = pline;
228
229 done:
230 if(NULL == ret_value && pline) {
231 H5O_pline_reset(pline);
232 H5O_pline_free(pline);
233 } /* end if */
234
235 FUNC_LEAVE_NOAPI(ret_value)
236 } /* end H5O_pline_decode() */
237
238
239 /*-------------------------------------------------------------------------
240 * Function: H5O_pline_encode
241 *
242 * Purpose: Encodes message MESG into buffer P.
243 *
244 * Return: Non-negative on success/Negative on failure
245 *
246 * Programmer: Robb Matzke
247 * Wednesday, April 15, 1998
248 *
249 *-------------------------------------------------------------------------
250 */
251 static herr_t
H5O_pline_encode(H5F_t H5_ATTR_UNUSED * f,uint8_t * p,const void * mesg)252 H5O_pline_encode(H5F_t H5_ATTR_UNUSED *f, uint8_t *p/*out*/, const void *mesg)
253 {
254 const H5O_pline_t *pline = (const H5O_pline_t*)mesg; /* Pipeline message to encode */
255 const H5Z_filter_info_t *filter; /* Filter to encode */
256 size_t i, j; /* Local index variables */
257
258 FUNC_ENTER_NOAPI_NOINIT_NOERR
259
260 /* Check args */
261 HDassert(p);
262 HDassert(mesg);
263
264 /* Message header */
265 *p++ = (uint8_t)pline->version;
266 *p++ = (uint8_t)(pline->nused);
267 if(pline->version == H5O_PLINE_VERSION_1) {
268 *p++ = 0; /*reserved 1*/
269 *p++ = 0; /*reserved 2*/
270 *p++ = 0; /*reserved 3*/
271 *p++ = 0; /*reserved 4*/
272 *p++ = 0; /*reserved 5*/
273 *p++ = 0; /*reserved 6*/
274 } /* end if */
275
276 /* Encode filters */
277 for(i = 0, filter = &pline->filter[0]; i < pline->nused; i++, filter++) {
278 const char *name; /* Filter name */
279 size_t name_length; /* Length of filter name */
280
281 /* Filter ID */
282 UINT16ENCODE(p, filter->id);
283
284 /* Skip writing the name length & name if the filter is an internal filter */
285 if(pline->version > H5O_PLINE_VERSION_1 && filter->id < H5Z_FILTER_RESERVED) {
286 name_length = 0;
287 name = NULL;
288 } /* end if */
289 else {
290 H5Z_class2_t *cls; /* Filter class */
291
292 /*
293 * Get the filter name. If the pipeline message has a name in it then
294 * use that one. Otherwise try to look up the filter and get the name
295 * as it was registered.
296 */
297 if(NULL == (name = filter->name) && (cls = H5Z_find(filter->id)))
298 name = cls->name;
299 name_length = name ? HDstrlen(name) + 1 : 0;
300
301 /* Filter name length */
302 UINT16ENCODE(p, pline->version == H5O_PLINE_VERSION_1 ? H5O_ALIGN_OLD(name_length) : name_length);
303 } /* end else */
304
305 /* Filter flags */
306 UINT16ENCODE(p, filter->flags);
307
308 /* # of filter parameters */
309 UINT16ENCODE(p, filter->cd_nelmts);
310
311 /* Encode name, if there is one to encode */
312 if(name_length > 0) {
313 /* Store name, with null terminator */
314 HDmemcpy(p, name, name_length);
315 p += name_length;
316
317 /* Pad out name to alignment, in older versions */
318 if(pline->version == H5O_PLINE_VERSION_1)
319 while(name_length++ % 8)
320 *p++ = 0;
321 } /* end if */
322
323 /* Filter parameters */
324 for(j = 0; j < filter->cd_nelmts; j++)
325 UINT32ENCODE(p, filter->cd_values[j]);
326
327 /* Align the parameters for older versions of the format */
328 if(pline->version == H5O_PLINE_VERSION_1)
329 if(filter->cd_nelmts % 2)
330 UINT32ENCODE(p, 0);
331 } /* end for */
332
333 FUNC_LEAVE_NOAPI(SUCCEED)
334 } /* end H5O_pline_encode() */
335
336
337 /*-------------------------------------------------------------------------
338 * Function: H5O_pline_copy
339 *
340 * Purpose: Copies a filter pipeline message from SRC to DST allocating
341 * DST if necessary. If DST is already allocated then we assume
342 * that it isn't initialized.
343 *
344 * Return: Success: Ptr to DST or allocated result.
345 *
346 * Failure: NULL
347 *
348 * Programmer: Robb Matzke
349 * Wednesday, April 15, 1998
350 *
351 *-------------------------------------------------------------------------
352 */
353 static void *
H5O_pline_copy(const void * _src,void * _dst)354 H5O_pline_copy(const void *_src, void *_dst/*out*/)
355 {
356 const H5O_pline_t *src = (const H5O_pline_t *)_src; /* Source pipeline message */
357 H5O_pline_t *dst = (H5O_pline_t *)_dst; /* Destination pipeline message */
358 size_t i; /* Local index variable */
359 H5O_pline_t *ret_value; /* Return value */
360
361 FUNC_ENTER_NOAPI_NOINIT
362
363 /* Allocate pipeline message, if not provided */
364 if(!dst && NULL == (dst = H5FL_MALLOC(H5O_pline_t)))
365 HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
366
367 /* Shallow copy basic fields */
368 *dst = *src;
369
370 /* Copy over filters, if any */
371 dst->nalloc = dst->nused;
372 if(dst->nalloc) {
373 /* Allocate array to hold filters */
374 if(NULL == (dst->filter = (H5Z_filter_info_t *)H5MM_calloc(dst->nalloc * sizeof(dst->filter[0]))))
375 HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
376
377 /* Deep-copy filters */
378 for(i = 0; i < src->nused; i++) {
379 /* Basic filter information */
380 dst->filter[i] = src->filter[i];
381
382 /* Filter name */
383 if(src->filter[i].name) {
384 size_t namelen; /* Length of source filter name, including null terminator */
385
386 namelen = HDstrlen(src->filter[i].name) + 1;
387
388 /* Allocate space for the filter name, or use the internal buffer */
389 if(namelen > H5Z_COMMON_NAME_LEN) {
390 dst->filter[i].name = (char *)H5MM_strdup(src->filter[i].name);
391 if(NULL == dst->filter[i].name)
392 HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for filter name")
393 } /* end if */
394 else
395 dst->filter[i].name = dst->filter[i]._name;
396 } /* end if */
397
398 /* Filter parameters */
399 if(src->filter[i].cd_nelmts > 0) {
400 /* Allocate space for the client data elements, or use the internal buffer */
401 if(src->filter[i].cd_nelmts > H5Z_COMMON_CD_VALUES) {
402 if(NULL == (dst->filter[i].cd_values = (unsigned *)H5MM_malloc(src->filter[i].cd_nelmts* sizeof(unsigned))))
403 HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
404
405 HDmemcpy(dst->filter[i].cd_values, src->filter[i].cd_values,
406 src->filter[i].cd_nelmts * sizeof(unsigned));
407 } /* end if */
408 else
409 dst->filter[i].cd_values = dst->filter[i]._cd_values;
410 } /* end if */
411 } /* end for */
412 } /* end if */
413 else
414 dst->filter = NULL;
415
416 /* Set return value */
417 ret_value = dst;
418
419 done:
420 if(!ret_value && dst) {
421 H5O_pline_reset(dst);
422 if(!_dst)
423 H5O_pline_free(dst);
424 } /* end if */
425
426 FUNC_LEAVE_NOAPI(ret_value)
427 } /* end H5O_pline_copy() */
428
429
430 /*-------------------------------------------------------------------------
431 * Function: H5O_pline_size
432 *
433 * Purpose: Determines the size of a raw filter pipeline message.
434 *
435 * Return: Success: Size of message.
436 *
437 * Failure: zero
438 *
439 * Programmer: Robb Matzke
440 * Wednesday, April 15, 1998
441 *
442 *-------------------------------------------------------------------------
443 */
444 static size_t
H5O_pline_size(const H5F_t H5_ATTR_UNUSED * f,const void * mesg)445 H5O_pline_size(const H5F_t H5_ATTR_UNUSED *f, const void *mesg)
446 {
447 const H5O_pline_t *pline = (const H5O_pline_t*)mesg; /* Pipeline message */
448 size_t i; /* Local index variable */
449 size_t ret_value; /* Return value */
450
451 FUNC_ENTER_NOAPI_NOINIT_NOERR
452
453 /* Message header */
454 ret_value = 1 + /*version */
455 1 + /*number of filters */
456 (pline->version == H5O_PLINE_VERSION_1 ? 6 : 0); /*reserved */
457
458 /* Calculate size of each filter in pipeline */
459 for(i = 0; i < pline->nused; i++) {
460 size_t name_len; /* Length of filter name */
461 const char *name; /* Filter name */
462
463 /* Don't write the name length & name if the filter is an internal filter */
464 if(pline->version > H5O_PLINE_VERSION_1 && pline->filter[i].id < H5Z_FILTER_RESERVED)
465 name_len = 0;
466 else {
467 H5Z_class2_t *cls; /* Filter class */
468
469 /* Get the name of the filter, same as done with H5O_pline_encode() */
470 if(NULL == (name = pline->filter[i].name) && (cls = H5Z_find(pline->filter[i].id)))
471 name = cls->name;
472 name_len = name ? HDstrlen(name) + 1 : 0;
473 } /* end else */
474
475 ret_value += 2 + /*filter identification number */
476 (size_t)((pline->version == H5O_PLINE_VERSION_1 || pline->filter[i].id >= H5Z_FILTER_RESERVED) ? 2 : 0) + /*name length */
477 2 + /*flags */
478 2 + /*number of client data values */
479 (pline->version == H5O_PLINE_VERSION_1 ? (size_t)H5O_ALIGN_OLD(name_len) : name_len); /*length of the filter name */
480
481 ret_value += pline->filter[i].cd_nelmts * 4;
482 if(pline->version == H5O_PLINE_VERSION_1)
483 if(pline->filter[i].cd_nelmts % 2)
484 ret_value += 4;
485 } /* end for */
486
487 FUNC_LEAVE_NOAPI(ret_value)
488 } /* end H5O_pline_size() */
489
490
491 /*-------------------------------------------------------------------------
492 * Function: H5O_pline_reset
493 *
494 * Purpose: Resets a filter pipeline message by clearing all filters.
495 * The MESG buffer is not freed.
496 *
497 * Return: Non-negative on success/Negative on failure
498 *
499 * Programmer: Robb Matzke
500 * Wednesday, April 15, 1998
501 *
502 *-------------------------------------------------------------------------
503 */
504 static herr_t
H5O_pline_reset(void * mesg)505 H5O_pline_reset(void *mesg)
506 {
507 H5O_pline_t *pline = (H5O_pline_t*)mesg; /* Pipeline message */
508 size_t i; /* Local index variable */
509
510 FUNC_ENTER_NOAPI_NOINIT_NOERR
511
512 /* NOTE: This function can be called during error processing from
513 * other API calls so DO NOT ASSUME THAT ANY VALUES ARE SANE.
514 */
515
516 HDassert(pline);
517
518 /* Free the filter information and array */
519 if (pline->filter) {
520
521 /* Free information for each filter */
522 for(i = 0; i < pline->nused; i++) {
523 if(pline->filter[i].name && pline->filter[i].name != pline->filter[i]._name)
524 HDassert((HDstrlen(pline->filter[i].name) + 1) > H5Z_COMMON_NAME_LEN);
525 if(pline->filter[i].name != pline->filter[i]._name)
526 pline->filter[i].name = (char *)H5MM_xfree(pline->filter[i].name);
527 if(pline->filter[i].cd_values && pline->filter[i].cd_values != pline->filter[i]._cd_values)
528 HDassert(pline->filter[i].cd_nelmts > H5Z_COMMON_CD_VALUES);
529 if(pline->filter[i].cd_values != pline->filter[i]._cd_values)
530 pline->filter[i].cd_values = (unsigned *)H5MM_xfree(pline->filter[i].cd_values);
531 } /* end for */
532
533 /* Free filter array */
534 pline->filter = (H5Z_filter_info_t *)H5MM_xfree(pline->filter);
535 }
536
537 /* Reset # of filters */
538 pline->nused = pline->nalloc = 0;
539
540 /* Reset version # of pipeline message */
541 pline->version = H5O_PLINE_VERSION_1;
542
543 FUNC_LEAVE_NOAPI(SUCCEED)
544 } /* end H5O_pline_reset() */
545
546
547 /*-------------------------------------------------------------------------
548 * Function: H5O_pline_free
549 *
550 * Purpose: Free's the message
551 *
552 * Return: Non-negative on success/Negative on failure
553 *
554 * Programmer: Quincey Koziol
555 * Saturday, March 11, 2000
556 *
557 *-------------------------------------------------------------------------
558 */
559 static herr_t
H5O_pline_free(void * mesg)560 H5O_pline_free(void *mesg)
561 {
562 FUNC_ENTER_NOAPI_NOINIT_NOERR
563
564 HDassert(mesg);
565
566 mesg = H5FL_FREE(H5O_pline_t, mesg);
567
568 FUNC_LEAVE_NOAPI(SUCCEED)
569 } /* end H5O_pline_free() */
570
571
572 /*-------------------------------------------------------------------------
573 * Function: H5O_pline_pre_copy_file
574 *
575 * Purpose: Perform any necessary actions before copying message between
576 * files
577 *
578 * Return: Success: Non-negative
579 *
580 * Failure: Negative
581 *
582 * Programmer: Peter Cao
583 * December 27, 2005
584 *
585 *-------------------------------------------------------------------------
586 */
587 static herr_t
H5O_pline_pre_copy_file(H5F_t H5_ATTR_UNUSED * file_src,const void * mesg_src,hbool_t H5_ATTR_UNUSED * deleted,const H5O_copy_t H5_ATTR_UNUSED * cpy_info,void * _udata)588 H5O_pline_pre_copy_file(H5F_t H5_ATTR_UNUSED *file_src, const void *mesg_src,
589 hbool_t H5_ATTR_UNUSED *deleted, const H5O_copy_t H5_ATTR_UNUSED *cpy_info, void *_udata)
590 {
591 const H5O_pline_t *pline_src = (const H5O_pline_t *)mesg_src; /* Source datatype */
592 H5O_copy_file_ud_common_t *udata = (H5O_copy_file_ud_common_t *)_udata; /* Object copying user data */
593 herr_t ret_value = SUCCEED; /* Return value */
594
595 FUNC_ENTER_NOAPI_NOINIT
596
597 /* check args */
598 HDassert(pline_src);
599
600 /* If the user data is non-NULL, assume we are copying a dataset or group
601 * and make a copy of the filter pipeline for later in
602 * the object copying process.
603 */
604 if(udata)
605 if(NULL == (udata->src_pline = (H5O_pline_t *)H5O_pline_copy(pline_src, NULL)))
606 HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to copy")
607
608 done:
609 FUNC_LEAVE_NOAPI(ret_value)
610 } /* end H5O_pline_pre_copy_file() */
611
612
613 /*-------------------------------------------------------------------------
614 * Function: H5O_pline_debug
615 *
616 * Purpose: Prints debugging information for filter pipeline message MESG
617 * on output stream STREAM. Each line is indented INDENT
618 * characters and the field name takes up FWIDTH characters.
619 *
620 * Return: Non-negative on success/Negative on failure
621 *
622 * Programmer: Robb Matzke
623 * Wednesday, April 15, 1998
624 *
625 *-------------------------------------------------------------------------
626 */
627 static herr_t
H5O_pline_debug(H5F_t H5_ATTR_UNUSED * f,hid_t H5_ATTR_UNUSED dxpl_id,const void * mesg,FILE * stream,int indent,int fwidth)628 H5O_pline_debug(H5F_t H5_ATTR_UNUSED *f, hid_t H5_ATTR_UNUSED dxpl_id, const void *mesg, FILE *stream,
629 int indent, int fwidth)
630 {
631 const H5O_pline_t *pline = (const H5O_pline_t *)mesg;
632 size_t i, j;
633
634 FUNC_ENTER_NOAPI_NOINIT_NOERR
635
636 /* check args */
637 HDassert(f);
638 HDassert(pline);
639 HDassert(stream);
640 HDassert(indent >= 0);
641 HDassert(fwidth >= 0);
642
643 HDfprintf(stream, "%*s%-*s %Zu/%Zu\n", indent, "", fwidth,
644 "Number of filters:",
645 pline->nused,
646 pline->nalloc);
647
648 /* Loop over all the filters */
649 for(i = 0; i < pline->nused; i++) {
650 char name[32];
651
652 HDsnprintf(name, sizeof(name), "Filter at position %u", (unsigned)i);
653 HDfprintf(stream, "%*s%-*s\n", indent, "", fwidth, name);
654 HDfprintf(stream, "%*s%-*s 0x%04x\n", indent + 3, "", MAX(0, fwidth - 3),
655 "Filter identification:",
656 (unsigned)(pline->filter[i].id));
657 if(pline->filter[i].name)
658 HDfprintf(stream, "%*s%-*s \"%s\"\n", indent + 3, "", MAX(0, fwidth - 3),
659 "Filter name:",
660 pline->filter[i].name);
661 else
662 HDfprintf(stream, "%*s%-*s NONE\n", indent + 3, "", MAX(0, fwidth - 3),
663 "Filter name:");
664 HDfprintf(stream, "%*s%-*s 0x%04x\n", indent + 3, "", MAX(0, fwidth - 3),
665 "Flags:",
666 pline->filter[i].flags);
667 HDfprintf(stream, "%*s%-*s %Zu\n", indent + 3, "", MAX(0, fwidth - 3),
668 "Num CD values:",
669 pline->filter[i].cd_nelmts);
670
671 /* Filter parameters */
672 for(j = 0; j < pline->filter[i].cd_nelmts; j++) {
673 char field_name[32];
674
675 HDsnprintf(field_name, sizeof(field_name), "CD value %lu", (unsigned long)j);
676 HDfprintf(stream, "%*s%-*s %u\n", indent + 6, "", MAX(0, fwidth - 6),
677 field_name,
678 pline->filter[i].cd_values[j]);
679 } /* end for */
680 } /* end for */
681
682 FUNC_LEAVE_NOAPI(SUCCEED)
683 } /* end H5O_pline_debug() */
684
685
686 /*-------------------------------------------------------------------------
687 * Function: H5O_pline_set_latest_version
688 *
689 * Purpose: Set the encoding for a I/O filter pipeline to the latest version.
690 *
691 * Return: Non-negative on success/Negative on failure
692 *
693 * Programmer: Quincey Koziol
694 * Tuesday, July 24, 2007
695 *
696 *-------------------------------------------------------------------------
697 */
698 herr_t
H5O_pline_set_latest_version(H5O_pline_t * pline)699 H5O_pline_set_latest_version(H5O_pline_t *pline)
700 {
701 FUNC_ENTER_NOAPI_NOINIT_NOERR
702
703 /* Sanity check */
704 HDassert(pline);
705
706 /* Set encoding of I/O pipeline to latest version */
707 pline->version = H5O_PLINE_VERSION_LATEST;
708
709 FUNC_LEAVE_NOAPI(SUCCEED)
710 } /* end H5O_pline_set_latest_version() */
711
712