Line | Count | Source |
1 | | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
2 | | * Copyright by The HDF Group. * |
3 | | * All rights reserved. * |
4 | | * * |
5 | | * This file is part of HDF5. The full HDF5 copyright notice, including * |
6 | | * terms governing use, modification, and redistribution, is contained in * |
7 | | * the LICENSE file, which can be found at the root of the source code * |
8 | | * distribution tree, or in https://www.hdfgroup.org/licenses. * |
9 | | * If you do not have access to either file, you may request a copy from * |
10 | | * help@hdfgroup.org. * |
11 | | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
12 | | |
13 | | #include "H5Zmodule.h" /* This source code file is part of the H5Z module */ |
14 | | |
15 | | #include "H5private.h" /* Generic Functions */ |
16 | | #include "H5Dprivate.h" /* Dataset functions */ |
17 | | #include "H5Eprivate.h" /* Error handling */ |
18 | | #include "H5Fprivate.h" /* File */ |
19 | | #include "H5Iprivate.h" /* IDs */ |
20 | | #include "H5MMprivate.h" /* Memory management */ |
21 | | #include "H5Oprivate.h" /* Object headers */ |
22 | | #include "H5Pprivate.h" /* Property lists */ |
23 | | #include "H5PLprivate.h" /* Plugins */ |
24 | | #include "H5Sprivate.h" /* Dataspace functions */ |
25 | | #include "H5Zpkg.h" /* Data filters */ |
26 | | |
27 | | #ifdef H5_HAVE_SZLIB_H |
28 | | #include "szlib.h" |
29 | | #endif |
30 | | |
31 | | /* This module can collect and optionally dump some simple filter statistics |
32 | | * to stdout. If you want to do this, you need to define H5Z_DEBUG and set |
33 | | * the DUMP_DEBUG_STATS_g flag to true. |
34 | | */ |
35 | | |
36 | | /* Local typedefs */ |
37 | | #ifdef H5Z_DEBUG |
38 | | typedef struct H5Z_stats_t { |
39 | | struct { |
40 | | hsize_t total; /* total number of bytes processed */ |
41 | | hsize_t errors; /* bytes of total attributable to errors */ |
42 | | H5_timevals_t times; /* execution time including errors */ |
43 | | } stats[2]; /* 0 = output, 1 = input */ |
44 | | } H5Z_stats_t; |
45 | | #endif /* H5Z_DEBUG */ |
46 | | |
47 | | typedef struct H5Z_object_t { |
48 | | H5Z_filter_t filter_id; /* ID of the filter we're looking for */ |
49 | | htri_t found; /* Whether we find an object using the filter */ |
50 | | #ifdef H5_HAVE_PARALLEL |
51 | | bool sanity_checked; /* Whether the sanity check for collectively calling H5Zunregister has been done */ |
52 | | #endif /* H5_HAVE_PARALLEL */ |
53 | | } H5Z_object_t; |
54 | | |
55 | | /* Enumerated type for dataset creation prelude callbacks */ |
56 | | typedef enum { |
57 | | H5Z_PRELUDE_CAN_APPLY, /* Call "can apply" callback */ |
58 | | H5Z_PRELUDE_SET_LOCAL /* Call "set local" callback */ |
59 | | } H5Z_prelude_type_t; |
60 | | |
61 | | /* Package initialization variable */ |
62 | | bool H5_PKG_INIT_VAR = false; |
63 | | |
64 | | /* Local variables */ |
65 | | static size_t H5Z_table_alloc_g = 0; |
66 | | static size_t H5Z_table_used_g = 0; |
67 | | static H5Z_class2_t *H5Z_table_g = NULL; |
68 | | #ifdef H5Z_DEBUG |
69 | | static H5Z_stats_t *H5Z_stat_table_g = NULL; |
70 | | /* Set to true if you want to dump compression statistics to stdout */ |
71 | | static const bool DUMP_DEBUG_STATS_g = false; |
72 | | #endif /* H5Z_DEBUG */ |
73 | | |
74 | | /* Local functions */ |
75 | | static int H5Z__find_idx(H5Z_filter_t id); |
76 | | static int H5Z__check_unregister_dset_cb(void *obj_ptr, hid_t obj_id, void *key); |
77 | | static int H5Z__check_unregister_group_cb(void *obj_ptr, hid_t obj_id, void *key); |
78 | | static int H5Z__flush_file_cb(void *obj_ptr, hid_t obj_id, void *key); |
79 | | |
80 | | /*------------------------------------------------------------------------- |
81 | | * Function: H5Z__init_package |
82 | | * |
83 | | * Purpose: Initializes the data filter layer. |
84 | | * |
85 | | * Return: Success: non-negative |
86 | | * Failure: negative |
87 | | *------------------------------------------------------------------------- |
88 | | */ |
89 | | herr_t |
90 | | H5Z__init_package(void) |
91 | 0 | { |
92 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
93 | |
|
94 | 0 | FUNC_ENTER_PACKAGE |
95 | | |
96 | | /* Internal filters */ |
97 | 0 | if (H5Z_register(H5Z_SHUFFLE) < 0) |
98 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register shuffle filter"); |
99 | 0 | if (H5Z_register(H5Z_FLETCHER32) < 0) |
100 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register fletcher32 filter"); |
101 | 0 | if (H5Z_register(H5Z_NBIT) < 0) |
102 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register nbit filter"); |
103 | 0 | if (H5Z_register(H5Z_SCALEOFFSET) < 0) |
104 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register scaleoffset filter"); |
105 | | |
106 | | /* External filters */ |
107 | 0 | #ifdef H5_HAVE_FILTER_DEFLATE |
108 | 0 | if (H5Z_register(H5Z_DEFLATE) < 0) |
109 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register deflate filter"); |
110 | 0 | #endif /* H5_HAVE_FILTER_DEFLATE */ |
111 | | #ifdef H5_HAVE_FILTER_SZIP |
112 | | { |
113 | | int encoder_enabled = SZ_encoder_enabled(); |
114 | | if (encoder_enabled < 0) |
115 | | HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "check for szip encoder failed"); |
116 | | |
117 | | H5Z_SZIP->encoder_present = (unsigned)encoder_enabled; |
118 | | if (H5Z_register(H5Z_SZIP) < 0) |
119 | | HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register szip filter"); |
120 | | } |
121 | | #endif /* H5_HAVE_FILTER_SZIP */ |
122 | | |
123 | 0 | done: |
124 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
125 | 0 | } /* end H5Z__init_package() */ |
126 | | |
127 | | /*------------------------------------------------------------------------- |
128 | | * Function: H5Z_term_package |
129 | | * |
130 | | * Purpose: Terminate the H5Z layer. |
131 | | * |
132 | | * Return: void |
133 | | *------------------------------------------------------------------------- |
134 | | */ |
135 | | int |
136 | | H5Z_term_package(void) |
137 | 6 | { |
138 | 6 | int n = 0; |
139 | | |
140 | 6 | FUNC_ENTER_NOAPI_NOINIT_NOERR |
141 | |
|
142 | 0 | if (H5_PKG_INIT_VAR) { |
143 | | #ifdef H5Z_DEBUG |
144 | | char comment[16], bandwidth[32]; |
145 | | int dir, nprint = 0; |
146 | | size_t i; |
147 | | |
148 | | if (DUMP_DEBUG_STATS_g) { |
149 | | for (i = 0; i < H5Z_table_used_g; i++) { |
150 | | for (dir = 0; dir < 2; dir++) { |
151 | | struct { |
152 | | char *user; |
153 | | char *system; |
154 | | char *elapsed; |
155 | | } timestrs = {H5_timer_get_time_string(H5Z_stat_table_g[i].stats[dir].times.user), |
156 | | H5_timer_get_time_string(H5Z_stat_table_g[i].stats[dir].times.system), |
157 | | H5_timer_get_time_string(H5Z_stat_table_g[i].stats[dir].times.elapsed)}; |
158 | | if (0 == H5Z_stat_table_g[i].stats[dir].total) |
159 | | goto next; |
160 | | |
161 | | if (0 == nprint++) { |
162 | | /* Print column headers */ |
163 | | fprintf(stdout, "H5Z: filter statistics " |
164 | | "accumulated over life of library:\n"); |
165 | | fprintf(stdout, " %-16s %10s %10s %8s %8s %8s %10s\n", "Filter", "Total", "Errors", |
166 | | "User", "System", "Elapsed", "Bandwidth"); |
167 | | fprintf(stdout, " %-16s %10s %10s %8s %8s %8s %10s\n", "------", "-----", "------", |
168 | | "----", "------", "-------", "---------"); |
169 | | } /* end if */ |
170 | | |
171 | | /* Truncate the comment to fit in the field */ |
172 | | strncpy(comment, H5Z_table_g[i].name, sizeof comment); |
173 | | comment[sizeof(comment) - 1] = '\0'; |
174 | | |
175 | | /* |
176 | | * Format bandwidth to have four significant digits and |
177 | | * units of `B/s', `kB/s', `MB/s', `GB/s', or `TB/s' or |
178 | | * the word `Inf' if the elapsed time is zero. |
179 | | */ |
180 | | H5_bandwidth(bandwidth, sizeof(bandwidth), (double)(H5Z_stat_table_g[i].stats[dir].total), |
181 | | H5Z_stat_table_g[i].stats[dir].times.elapsed); |
182 | | |
183 | | /* Print the statistics */ |
184 | | fprintf(stdout, " %s%-15s %10" PRIdHSIZE " %10" PRIdHSIZE " %8s %8s %8s %10s\n", |
185 | | (dir ? "<" : ">"), comment, H5Z_stat_table_g[i].stats[dir].total, |
186 | | H5Z_stat_table_g[i].stats[dir].errors, timestrs.user, timestrs.system, |
187 | | timestrs.elapsed, bandwidth); |
188 | | next: |
189 | | free(timestrs.user); |
190 | | free(timestrs.system); |
191 | | free(timestrs.elapsed); |
192 | | } /* end for */ |
193 | | } /* end for */ |
194 | | } /* end if */ |
195 | | #endif /* H5Z_DEBUG */ |
196 | | |
197 | | /* Free the table of filters */ |
198 | 0 | if (H5Z_table_g) { |
199 | 0 | H5Z_table_g = (H5Z_class2_t *)H5MM_xfree(H5Z_table_g); |
200 | |
|
201 | | #ifdef H5Z_DEBUG |
202 | | H5Z_stat_table_g = (H5Z_stats_t *)H5MM_xfree(H5Z_stat_table_g); |
203 | | #endif /* H5Z_DEBUG */ |
204 | 0 | H5Z_table_used_g = H5Z_table_alloc_g = 0; |
205 | |
|
206 | 0 | n++; |
207 | 0 | } /* end if */ |
208 | | |
209 | | /* Mark interface as closed */ |
210 | 0 | if (0 == n) |
211 | 0 | H5_PKG_INIT_VAR = false; |
212 | 0 | } /* end if */ |
213 | |
|
214 | 0 | FUNC_LEAVE_NOAPI(n) |
215 | 6 | } /* end H5Z_term_package() */ |
216 | | |
217 | | /*------------------------------------------------------------------------- |
218 | | * Function: H5Zregister |
219 | | * |
220 | | * Purpose: This function registers a new filter |
221 | | * |
222 | | * Return: Non-negative on success/Negative on failure |
223 | | *------------------------------------------------------------------------- |
224 | | */ |
225 | | herr_t |
226 | | H5Zregister(const void *cls) |
227 | 0 | { |
228 | 0 | const H5Z_class2_t *cls_real = (const H5Z_class2_t *)cls; /* "Real" class pointer */ |
229 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
230 | | #ifndef H5_NO_DEPRECATED_SYMBOLS |
231 | | H5Z_class2_t cls_new; /* Translated class struct */ |
232 | | #endif |
233 | |
|
234 | 0 | FUNC_ENTER_API(FAIL) |
235 | | |
236 | | /* Check args */ |
237 | 0 | if (cls_real == NULL) |
238 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid filter class"); |
239 | | |
240 | | /* Check H5Z_class_t version number; this is where a function to convert |
241 | | * from an outdated version should be called. |
242 | | * |
243 | | * If the version number is invalid, we assume that the target of cls is the |
244 | | * old style "H5Z_class1_t" structure, which did not contain a version |
245 | | * field. In this structure, the first field is the id. Since both version |
246 | | * and id are integers they will have the same value, and since id must be |
247 | | * at least 256, there should be no overlap and the version of the struct |
248 | | * can be determined by the value of the first field. |
249 | | */ |
250 | 0 | if (cls_real->version != H5Z_CLASS_T_VERS) { |
251 | | #ifndef H5_NO_DEPRECATED_SYMBOLS |
252 | | /* Assume it is an old "H5Z_class1_t" instead */ |
253 | | const H5Z_class1_t *cls_old = (const H5Z_class1_t *)cls; |
254 | | |
255 | | /* Translate to new H5Z_class2_t */ |
256 | | cls_new.version = H5Z_CLASS_T_VERS; |
257 | | cls_new.id = cls_old->id; |
258 | | cls_new.encoder_present = 1; |
259 | | cls_new.decoder_present = 1; |
260 | | cls_new.name = cls_old->name; |
261 | | cls_new.can_apply = cls_old->can_apply; |
262 | | cls_new.set_local = cls_old->set_local; |
263 | | cls_new.filter = cls_old->filter; |
264 | | |
265 | | /* Set cls_real to point to the translated structure */ |
266 | | cls_real = &cls_new; |
267 | | |
268 | | #else /* H5_NO_DEPRECATED_SYMBOLS */ |
269 | | /* Deprecated symbols not allowed, throw an error */ |
270 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid H5Z_class_t version number"); |
271 | 0 | #endif /* H5_NO_DEPRECATED_SYMBOLS */ |
272 | 0 | } /* end if */ |
273 | | |
274 | 0 | if (cls_real->id < 0 || cls_real->id > H5Z_FILTER_MAX) |
275 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid filter identification number"); |
276 | 0 | if (cls_real->id < H5Z_FILTER_RESERVED) |
277 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to modify predefined filters"); |
278 | 0 | if (cls_real->filter == NULL) |
279 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no filter function specified"); |
280 | | |
281 | | /* Do it */ |
282 | 0 | if (H5Z_register(cls_real) < 0) |
283 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register filter"); |
284 | | |
285 | 0 | done: |
286 | 0 | FUNC_LEAVE_API(ret_value) |
287 | 0 | } |
288 | | |
289 | | /*------------------------------------------------------------------------- |
290 | | * Function: H5Z_register |
291 | | * |
292 | | * Purpose: Same as the public version except this one allows filters |
293 | | * to be set for predefined method numbers < H5Z_FILTER_RESERVED |
294 | | * |
295 | | * Return: Non-negative on success |
296 | | * Negative on failure |
297 | | *------------------------------------------------------------------------- |
298 | | */ |
299 | | herr_t |
300 | | H5Z_register(const H5Z_class2_t *cls) |
301 | 0 | { |
302 | 0 | size_t i; |
303 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
304 | |
|
305 | 0 | FUNC_ENTER_NOAPI(FAIL) |
306 | |
|
307 | 0 | assert(cls); |
308 | 0 | assert(cls->id >= 0 && cls->id <= H5Z_FILTER_MAX); |
309 | | |
310 | | /* Is the filter already registered? */ |
311 | 0 | for (i = 0; i < H5Z_table_used_g; i++) |
312 | 0 | if (H5Z_table_g[i].id == cls->id) |
313 | 0 | break; |
314 | | |
315 | | /* Filter not already registered */ |
316 | 0 | if (i >= H5Z_table_used_g) { |
317 | 0 | if (H5Z_table_used_g >= H5Z_table_alloc_g) { |
318 | 0 | size_t n = MAX(H5Z_MAX_NFILTERS, 2 * H5Z_table_alloc_g); |
319 | 0 | H5Z_class2_t *table = (H5Z_class2_t *)H5MM_realloc(H5Z_table_g, n * sizeof(H5Z_class2_t)); |
320 | | #ifdef H5Z_DEBUG |
321 | | H5Z_stats_t *stat_table = (H5Z_stats_t *)H5MM_realloc(H5Z_stat_table_g, n * sizeof(H5Z_stats_t)); |
322 | | #endif /* H5Z_DEBUG */ |
323 | 0 | if (!table) |
324 | 0 | HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to extend filter table"); |
325 | 0 | H5Z_table_g = table; |
326 | | #ifdef H5Z_DEBUG |
327 | | if (!stat_table) |
328 | | HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to extend filter statistics table"); |
329 | | H5Z_stat_table_g = stat_table; |
330 | | #endif /* H5Z_DEBUG */ |
331 | 0 | H5Z_table_alloc_g = n; |
332 | 0 | } /* end if */ |
333 | | |
334 | | /* Initialize */ |
335 | 0 | i = H5Z_table_used_g++; |
336 | 0 | H5MM_memcpy(H5Z_table_g + i, cls, sizeof(H5Z_class2_t)); |
337 | | #ifdef H5Z_DEBUG |
338 | | memset(H5Z_stat_table_g + i, 0, sizeof(H5Z_stats_t)); |
339 | | #endif /* H5Z_DEBUG */ |
340 | 0 | } /* end if */ |
341 | | /* Filter already registered */ |
342 | 0 | else { |
343 | | /* Replace old contents */ |
344 | 0 | H5MM_memcpy(H5Z_table_g + i, cls, sizeof(H5Z_class2_t)); |
345 | 0 | } /* end else */ |
346 | | |
347 | 0 | done: |
348 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
349 | 0 | } |
350 | | |
351 | | /*------------------------------------------------------------------------- |
352 | | * Function: H5Zunregister |
353 | | * |
354 | | * Purpose: This function unregisters a filter. |
355 | | * |
356 | | * Return: Non-negative on success |
357 | | * Negative on failure |
358 | | *------------------------------------------------------------------------- |
359 | | */ |
360 | | herr_t |
361 | | H5Zunregister(H5Z_filter_t id) |
362 | 0 | { |
363 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
364 | |
|
365 | 0 | FUNC_ENTER_API(FAIL) |
366 | | |
367 | | /* Check args */ |
368 | 0 | if (id < 0 || id > H5Z_FILTER_MAX) |
369 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid filter identification number"); |
370 | 0 | if (id < H5Z_FILTER_RESERVED) |
371 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to modify predefined filters"); |
372 | | |
373 | | /* Do it */ |
374 | 0 | if (H5Z__unregister(id) < 0) |
375 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to unregister filter"); |
376 | | |
377 | 0 | done: |
378 | 0 | FUNC_LEAVE_API(ret_value) |
379 | 0 | } /* end H5Zunregister() */ |
380 | | |
381 | | /*------------------------------------------------------------------------- |
382 | | * Function: H5Z__unregister |
383 | | * |
384 | | * Purpose: Same as the public version except this one allows filters |
385 | | * to be unset for predefined method numbers <H5Z_FILTER_RESERVED |
386 | | * |
387 | | * Return: SUCCEED/FAIL |
388 | | * |
389 | | *------------------------------------------------------------------------- |
390 | | */ |
391 | | herr_t |
392 | | H5Z__unregister(H5Z_filter_t filter_id) |
393 | 0 | { |
394 | 0 | size_t filter_index; /* Local index variable for filter */ |
395 | 0 | H5Z_object_t object; /* Object to pass to callbacks */ |
396 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
397 | |
|
398 | 0 | FUNC_ENTER_PACKAGE |
399 | |
|
400 | 0 | assert(filter_id >= 0 && filter_id <= H5Z_FILTER_MAX); |
401 | | |
402 | | /* Is the filter already registered? */ |
403 | 0 | for (filter_index = 0; filter_index < H5Z_table_used_g; filter_index++) |
404 | 0 | if (H5Z_table_g[filter_index].id == filter_id) |
405 | 0 | break; |
406 | | |
407 | | /* Fail if filter not found */ |
408 | 0 | if (filter_index >= H5Z_table_used_g) |
409 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_NOTFOUND, FAIL, "filter is not registered"); |
410 | | |
411 | | /* Initialize the structure object for iteration */ |
412 | 0 | object.filter_id = filter_id; |
413 | 0 | object.found = false; |
414 | | #ifdef H5_HAVE_PARALLEL |
415 | | object.sanity_checked = false; |
416 | | #endif /* H5_HAVE_PARALLEL */ |
417 | | |
418 | | /* Iterate through all opened datasets, returns a failure if any of them uses the filter */ |
419 | 0 | if (H5I_iterate(H5I_DATASET, H5Z__check_unregister_dset_cb, &object, false) < 0) |
420 | 0 | HGOTO_ERROR(H5E_FILE, H5E_BADITER, FAIL, "iteration failed"); |
421 | | |
422 | 0 | if (object.found) |
423 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTRELEASE, FAIL, |
424 | 0 | "can't unregister filter because a dataset is still using it"); |
425 | | |
426 | | /* Iterate through all opened groups, returns a failure if any of them uses the filter */ |
427 | 0 | if (H5I_iterate(H5I_GROUP, H5Z__check_unregister_group_cb, &object, false) < 0) |
428 | 0 | HGOTO_ERROR(H5E_FILE, H5E_BADITER, FAIL, "iteration failed"); |
429 | | |
430 | 0 | if (object.found) |
431 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTRELEASE, FAIL, |
432 | 0 | "can't unregister filter because a group is still using it"); |
433 | | |
434 | | /* Iterate through all opened files and flush them */ |
435 | 0 | if (H5I_iterate(H5I_FILE, H5Z__flush_file_cb, &object, false) < 0) |
436 | 0 | HGOTO_ERROR(H5E_FILE, H5E_BADITER, FAIL, "iteration failed"); |
437 | | |
438 | | /* Remove filter from table */ |
439 | | /* Don't worry about shrinking table size (for now) */ |
440 | 0 | memmove(&H5Z_table_g[filter_index], &H5Z_table_g[filter_index + 1], |
441 | 0 | sizeof(H5Z_class2_t) * ((H5Z_table_used_g - 1) - filter_index)); |
442 | | #ifdef H5Z_DEBUG |
443 | | memmove(&H5Z_stat_table_g[filter_index], &H5Z_stat_table_g[filter_index + 1], |
444 | | sizeof(H5Z_stats_t) * ((H5Z_table_used_g - 1) - filter_index)); |
445 | | #endif /* H5Z_DEBUG */ |
446 | 0 | H5Z_table_used_g--; |
447 | |
|
448 | 0 | done: |
449 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
450 | 0 | } /* end H5Z__unregister() */ |
451 | | |
452 | | /*------------------------------------------------------------------------- |
453 | | * Function: H5Z__check_unregister |
454 | | * |
455 | | * Purpose: Check if an object uses the filter to be unregistered. |
456 | | * |
457 | | * Return: true if the object uses the filter |
458 | | * false if not |
459 | | * NEGATIVE on error |
460 | | * |
461 | | *------------------------------------------------------------------------- |
462 | | */ |
463 | | static htri_t |
464 | | H5Z__check_unregister(hid_t ocpl_id, H5Z_filter_t filter_id) |
465 | 0 | { |
466 | 0 | H5P_genplist_t *plist; /* Property list */ |
467 | 0 | htri_t ret_value = false; /* Return value */ |
468 | |
|
469 | 0 | FUNC_ENTER_PACKAGE |
470 | | |
471 | | /* Get the plist structure of object creation */ |
472 | 0 | if (NULL == (plist = H5P_object_verify(ocpl_id, H5P_OBJECT_CREATE, true))) |
473 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_BADID, FAIL, "can't find object for ID"); |
474 | | |
475 | | /* Check if the object creation property list uses the filter */ |
476 | 0 | if ((ret_value = H5P_filter_in_pline(plist, filter_id)) < 0) |
477 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "can't check filter in pipeline"); |
478 | | |
479 | 0 | done: |
480 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
481 | 0 | } /* end H5Z__check_unregister() */ |
482 | | |
483 | | /*------------------------------------------------------------------------- |
484 | | * Function: H5Z__check_unregister_group_cb |
485 | | * |
486 | | * Purpose: The callback function for H5Z__unregister. It iterates |
487 | | * through all opened objects. If the object is a dataset |
488 | | * or a group and it uses the filter to be unregistered, the |
489 | | * function returns true. |
490 | | * |
491 | | * Return: true if the object uses the filter |
492 | | * false if not |
493 | | * NEGATIVE on error |
494 | | * |
495 | | *------------------------------------------------------------------------- |
496 | | */ |
497 | | static int |
498 | | H5Z__check_unregister_group_cb(void H5_ATTR_UNUSED *obj_ptr, hid_t obj_id, void *key) |
499 | 0 | { |
500 | 0 | hid_t ocpl_id = -1; |
501 | 0 | H5Z_object_t *object = (H5Z_object_t *)key; |
502 | 0 | H5VL_object_t *vol_obj; /* Object for loc_id */ |
503 | 0 | H5VL_group_get_args_t vol_cb_args; /* Arguments to VOL callback */ |
504 | 0 | htri_t filter_in_pline = false; |
505 | 0 | int ret_value = false; /* Return value */ |
506 | |
|
507 | 0 | FUNC_ENTER_PACKAGE |
508 | | |
509 | | /* Get the group creation property */ |
510 | 0 | if (NULL == (vol_obj = (H5VL_object_t *)H5I_object_verify(obj_id, H5I_GROUP))) |
511 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid group identifier"); |
512 | | |
513 | | /* Set up VOL callback arguments */ |
514 | 0 | vol_cb_args.op_type = H5VL_GROUP_GET_GCPL; |
515 | 0 | vol_cb_args.args.get_gcpl.gcpl_id = H5I_INVALID_HID; |
516 | | |
517 | | /* Get the group creation property list */ |
518 | 0 | if (H5VL_group_get(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
519 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, H5I_INVALID_HID, "unable to get group creation properties"); |
520 | | |
521 | 0 | if ((ocpl_id = vol_cb_args.args.get_gcpl.gcpl_id) < 0) |
522 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "can't get group creation property list"); |
523 | | |
524 | | /* Check if the filter is in the group creation property list */ |
525 | 0 | if ((filter_in_pline = H5Z__check_unregister(ocpl_id, object->filter_id)) < 0) |
526 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "can't check filter in pipeline"); |
527 | | |
528 | | /* H5I_iterate expects true to stop the loop over objects. Stop the loop and |
529 | | * let H5Z__unregister return failure. |
530 | | */ |
531 | 0 | if (filter_in_pline) { |
532 | 0 | object->found = true; |
533 | 0 | ret_value = true; |
534 | 0 | } |
535 | |
|
536 | 0 | done: |
537 | 0 | if (ocpl_id > 0) |
538 | 0 | if (H5I_dec_app_ref(ocpl_id) < 0) |
539 | 0 | HDONE_ERROR(H5E_PLINE, H5E_CANTDEC, FAIL, "can't release plist"); |
540 | |
|
541 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
542 | 0 | } /* end H5Z__check_unregister_group_cb() */ |
543 | | |
544 | | /*------------------------------------------------------------------------- |
545 | | * Function: H5Z__check_unregister_dset_cb |
546 | | * |
547 | | * Purpose: The callback function for H5Z__unregister. It iterates |
548 | | * through all opened objects. If the object is a dataset |
549 | | * or a group and it uses the filter to be unregistered, the |
550 | | * function returns true. |
551 | | * |
552 | | * Return: true if the object uses the filter |
553 | | * false if not |
554 | | * NEGATIVE on error |
555 | | * |
556 | | *------------------------------------------------------------------------- |
557 | | */ |
558 | | static int |
559 | | H5Z__check_unregister_dset_cb(void H5_ATTR_UNUSED *obj_ptr, hid_t obj_id, void *key) |
560 | 0 | { |
561 | 0 | hid_t ocpl_id = -1; |
562 | 0 | H5Z_object_t *object = (H5Z_object_t *)key; |
563 | 0 | H5VL_object_t *vol_obj; /* Object for loc_id */ |
564 | 0 | H5VL_dataset_get_args_t vol_cb_args; /* Arguments to VOL callback */ |
565 | 0 | htri_t filter_in_pline = false; |
566 | 0 | int ret_value = false; /* Return value */ |
567 | |
|
568 | 0 | FUNC_ENTER_PACKAGE |
569 | | |
570 | | /* Get the dataset creation property */ |
571 | 0 | if (NULL == (vol_obj = (H5VL_object_t *)H5I_object_verify(obj_id, H5I_DATASET))) |
572 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid dataset identifier"); |
573 | | |
574 | | /* Set up VOL callback arguments */ |
575 | 0 | vol_cb_args.op_type = H5VL_DATASET_GET_DCPL; |
576 | 0 | vol_cb_args.args.get_dcpl.dcpl_id = H5I_INVALID_HID; |
577 | | |
578 | | /* Get the dataset creation property list */ |
579 | 0 | if (H5VL_dataset_get(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
580 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, H5I_INVALID_HID, "unable to get dataset creation properties"); |
581 | | |
582 | 0 | if ((ocpl_id = vol_cb_args.args.get_dcpl.dcpl_id) < 0) |
583 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "can't get dataset creation property list"); |
584 | | |
585 | | /* Check if the filter is in the dataset creation property list */ |
586 | 0 | if ((filter_in_pline = H5Z__check_unregister(ocpl_id, object->filter_id)) < 0) |
587 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "can't check filter in pipeline"); |
588 | | |
589 | | /* H5I_iterate expects true to stop the loop over objects. Stop the loop and |
590 | | * let H5Z__unregister return failure. |
591 | | */ |
592 | 0 | if (filter_in_pline) { |
593 | 0 | object->found = true; |
594 | 0 | ret_value = true; |
595 | 0 | } |
596 | |
|
597 | 0 | done: |
598 | 0 | if (ocpl_id > 0) |
599 | 0 | if (H5I_dec_app_ref(ocpl_id) < 0) |
600 | 0 | HDONE_ERROR(H5E_PLINE, H5E_CANTDEC, FAIL, "can't release plist"); |
601 | |
|
602 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
603 | 0 | } /* end H5Z__check_unregister_dset_cb() */ |
604 | | |
605 | | /*------------------------------------------------------------------------- |
606 | | * Function: H5Z__flush_file_cb |
607 | | * |
608 | | * Purpose: The callback function for H5Z__unregister. It iterates |
609 | | * through all opened files and flush them. |
610 | | * |
611 | | * Return: NON-NEGATIVE if finishes flushing and moves on |
612 | | * NEGATIVE if there is an error |
613 | | *------------------------------------------------------------------------- |
614 | | */ |
615 | | static int |
616 | | H5Z__flush_file_cb(void H5_ATTR_UNUSED *obj_ptr, hid_t obj_id, void H5_ATTR_PARALLEL_USED *key) |
617 | 0 | { |
618 | |
|
619 | | #ifdef H5_HAVE_PARALLEL |
620 | | H5Z_object_t *object = (H5Z_object_t *)key; |
621 | | #endif /* H5_HAVE_PARALLEL */ |
622 | 0 | int ret_value = false; /* Return value */ |
623 | 0 | H5VL_file_specific_args_t vol_cb_args_specific; /* Arguments to VOL callback */ |
624 | 0 | H5VL_object_t *vol_obj; /* File for file_id */ |
625 | 0 | H5VL_file_get_args_t vol_cb_args; /* Arguments to VOL callback */ |
626 | 0 | bool is_native_vol_obj = true; |
627 | 0 | unsigned int intent = 0; |
628 | |
|
629 | 0 | FUNC_ENTER_PACKAGE |
630 | | |
631 | | /* Sanity checks */ |
632 | 0 | assert(key); |
633 | | |
634 | | /* Get the internal file structure */ |
635 | 0 | if (NULL == (vol_obj = (H5VL_object_t *)H5I_object(obj_id))) |
636 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier"); |
637 | | |
638 | | /* Get intent */ |
639 | 0 | vol_cb_args.op_type = H5VL_FILE_GET_INTENT; |
640 | 0 | vol_cb_args.args.get_intent.flags = &intent; |
641 | | |
642 | | /* Get the flags */ |
643 | 0 | if (H5VL_file_get(vol_obj, &vol_cb_args, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) |
644 | 0 | HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to get file's intent flags"); |
645 | | |
646 | 0 | if (H5VL_object_is_native(vol_obj, &is_native_vol_obj) < 0) |
647 | 0 | HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, H5I_INVALID_HID, |
648 | 0 | "can't determine if VOL object is native connector object"); |
649 | | |
650 | | /* Do a global flush if the file is opened for write */ |
651 | 0 | if (H5F_ACC_RDWR & intent) { |
652 | |
|
653 | | #ifdef H5_HAVE_PARALLEL |
654 | | /* Checking MPI flag requires native VOL */ |
655 | | if (is_native_vol_obj) { |
656 | | H5F_t *f = (H5F_t *)obj_ptr; /* File object for native VOL operation */ |
657 | | |
658 | | /* Check if MPIO driver is used */ |
659 | | if (H5F_HAS_FEATURE(f, H5FD_FEAT_HAS_MPI)) { |
660 | | |
661 | | /* Sanity check for collectively calling H5Zunregister, if requested */ |
662 | | /* (Sanity check assumes that a barrier on one file's comm |
663 | | * is sufficient (i.e. that there aren't different comms for |
664 | | * different files). -QAK, 2018/02/14) |
665 | | */ |
666 | | if (H5_coll_api_sanity_check_g && !object->sanity_checked) { |
667 | | MPI_Comm mpi_comm; /* File's communicator */ |
668 | | |
669 | | /* Retrieve the file communicator */ |
670 | | if (H5F_mpi_retrieve_comm(obj_id, H5P_DEFAULT, &mpi_comm) < 0) |
671 | | HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "can't get MPI communicator"); |
672 | | |
673 | | /* Issue the barrier */ |
674 | | if (mpi_comm != MPI_COMM_NULL) |
675 | | MPI_Barrier(mpi_comm); |
676 | | |
677 | | /* Set the "sanity checked" flag */ |
678 | | object->sanity_checked = true; |
679 | | } /* end if */ |
680 | | } /* end if */ |
681 | | } |
682 | | #endif /* H5_HAVE_PARALLEL */ |
683 | | |
684 | | /* Call the flush routine for mounted file hierarchies */ |
685 | 0 | vol_cb_args_specific.op_type = H5VL_FILE_FLUSH; |
686 | 0 | vol_cb_args_specific.args.flush.obj_type = H5I_FILE; |
687 | 0 | vol_cb_args_specific.args.flush.scope = H5F_SCOPE_GLOBAL; |
688 | | |
689 | | /* Flush the object */ |
690 | 0 | if (H5VL_file_specific(vol_obj, &vol_cb_args_specific, H5P_DATASET_XFER_DEFAULT, NULL) < 0) |
691 | 0 | HGOTO_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL, "unable to flush file hierarchy"); |
692 | |
|
693 | 0 | } /* end if */ |
694 | | |
695 | 0 | done: |
696 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
697 | 0 | } /* end H5Z__flush_file_cb() */ |
698 | | |
699 | | /*------------------------------------------------------------------------- |
700 | | * Function: H5Zfilter_avail |
701 | | * |
702 | | * Purpose: Check if a filter is available |
703 | | * |
704 | | * Return: Non-negative (true/false) on success/Negative on failure |
705 | | *------------------------------------------------------------------------- |
706 | | */ |
707 | | htri_t |
708 | | H5Zfilter_avail(H5Z_filter_t id) |
709 | 0 | { |
710 | 0 | htri_t ret_value = false; /* Return value */ |
711 | |
|
712 | 0 | FUNC_ENTER_API(FAIL) |
713 | | |
714 | | /* Check args */ |
715 | 0 | if (id < 0 || id > H5Z_FILTER_MAX) |
716 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid filter identification number"); |
717 | | |
718 | 0 | if ((ret_value = H5Z_filter_avail(id)) < 0) |
719 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_NOTFOUND, FAIL, "unable to check the availability of the filter"); |
720 | | |
721 | 0 | done: |
722 | 0 | FUNC_LEAVE_API(ret_value) |
723 | 0 | } /* end H5Zfilter_avail() */ |
724 | | |
725 | | /*------------------------------------------------------------------------- |
726 | | * Function: H5Z_filter_avail |
727 | | * |
728 | | * Purpose: Private function to check if a filter is available |
729 | | * |
730 | | * Return: Non-negative (true/false) on success/Negative on failure |
731 | | *------------------------------------------------------------------------- |
732 | | */ |
733 | | htri_t |
734 | | H5Z_filter_avail(H5Z_filter_t id) |
735 | 0 | { |
736 | 0 | H5PL_key_t key; /* Key for finding a plugin */ |
737 | 0 | const H5Z_class2_t *filter_info; /* Filter information */ |
738 | 0 | size_t i; /* Local index variable */ |
739 | 0 | htri_t ret_value = false; /* Return value */ |
740 | |
|
741 | 0 | FUNC_ENTER_NOAPI(FAIL) |
742 | | |
743 | | /* Is the filter already registered? */ |
744 | 0 | for (i = 0; i < H5Z_table_used_g; i++) |
745 | 0 | if (H5Z_table_g[i].id == id) |
746 | 0 | HGOTO_DONE(true); |
747 | | |
748 | 0 | key.id = (int)id; |
749 | 0 | if (NULL != (filter_info = (const H5Z_class2_t *)H5PL_load(H5PL_TYPE_FILTER, &key))) { |
750 | 0 | if (H5Z_register(filter_info) < 0) |
751 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register loaded filter"); |
752 | 0 | HGOTO_DONE(true); |
753 | 0 | } /* end if */ |
754 | | |
755 | 0 | done: |
756 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
757 | 0 | } /* end H5Z_filter_avail() */ |
758 | | |
759 | | /*------------------------------------------------------------------------- |
760 | | * Function: H5Z__prelude_callback |
761 | | * |
762 | | * Purpose: Makes a dataset creation "prelude" callback for the "can_apply" |
763 | | * or "set_local" routines. |
764 | | * |
765 | | * Return: Non-negative on success/Negative on failure |
766 | | * |
767 | | * Notes: The chunk dimensions are used to create a dataspace, instead |
768 | | * of passing in the dataset's dataspace, since the chunk |
769 | | * dimensions are what the I/O filter will actually see |
770 | | *------------------------------------------------------------------------- |
771 | | */ |
772 | | static herr_t |
773 | | H5Z__prelude_callback(const H5O_pline_t *pline, hid_t dcpl_id, hid_t type_id, hid_t space_id, |
774 | | H5Z_prelude_type_t prelude_type) |
775 | 0 | { |
776 | 0 | H5Z_class2_t *fclass; /* Individual filter information */ |
777 | 0 | size_t u; /* Local index variable */ |
778 | 0 | htri_t ret_value = true; /* Return value */ |
779 | |
|
780 | 0 | FUNC_ENTER_PACKAGE |
781 | |
|
782 | 0 | assert(pline->nused > 0); |
783 | | |
784 | | /* Iterate over filters */ |
785 | 0 | for (u = 0; u < pline->nused; u++) { |
786 | | /* Get filter information, ignoring failure from optional filters */ |
787 | 0 | if (H5Z_find(pline->filter[u].flags & H5Z_FLAG_OPTIONAL, pline->filter[u].id, &fclass) < 0) |
788 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_NOTFOUND, FAIL, "required filter was not located"); |
789 | 0 | if (fclass) { |
790 | | /* Make correct callback */ |
791 | 0 | switch (prelude_type) { |
792 | 0 | case H5Z_PRELUDE_CAN_APPLY: |
793 | | /* Check if filter is configured to be able to encode */ |
794 | 0 | if (!fclass->encoder_present) |
795 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_NOENCODER, FAIL, |
796 | 0 | "Filter present but encoding is disabled."); |
797 | | |
798 | | /* Check if there is a "can apply" callback */ |
799 | 0 | if (fclass->can_apply) { |
800 | 0 | htri_t status; |
801 | | |
802 | | /* Don't prepare for a user callback if this is an internal filter */ |
803 | 0 | if (fclass->id < H5Z_FILTER_RESERVED) |
804 | | /* Make callback to filter's "can apply" function */ |
805 | 0 | status = (fclass->can_apply)(dcpl_id, type_id, space_id); |
806 | 0 | else { |
807 | | /* Prepare & restore library for user callback */ |
808 | 0 | H5_BEFORE_USER_CB(FAIL) |
809 | 0 | { |
810 | | /* Make callback to filter's "can apply" function */ |
811 | 0 | status = (fclass->can_apply)(dcpl_id, type_id, space_id); |
812 | 0 | } |
813 | 0 | H5_AFTER_USER_CB(FAIL) |
814 | 0 | } |
815 | | |
816 | | /* Indicate error during filter callback */ |
817 | 0 | if (status < 0) |
818 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANAPPLY, FAIL, "error during user callback"); |
819 | | |
820 | | /* Indicate filter can't apply to this combination of parameters. |
821 | | * If the filter is NOT optional, returns failure. */ |
822 | 0 | if (status == false && !(pline->filter[u].flags & H5Z_FLAG_OPTIONAL)) |
823 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANAPPLY, FAIL, "filter parameters not appropriate"); |
824 | 0 | } /* end if */ |
825 | 0 | break; |
826 | | |
827 | 0 | case H5Z_PRELUDE_SET_LOCAL: |
828 | | /* Check if there is a "set local" callback */ |
829 | 0 | if (fclass->set_local) { |
830 | 0 | herr_t status; |
831 | | |
832 | | /* Don't prepare for a user callback if this is an internal filter */ |
833 | 0 | if (fclass->id < H5Z_FILTER_RESERVED) |
834 | | /* Make callback to filter's "set local" function */ |
835 | 0 | status = (fclass->set_local)(dcpl_id, type_id, space_id); |
836 | 0 | else { |
837 | | /* Prepare & restore library for user callback */ |
838 | 0 | H5_BEFORE_USER_CB(FAIL) |
839 | 0 | { |
840 | | /* Make callback to filter's "set local" function */ |
841 | 0 | status = (fclass->set_local)(dcpl_id, type_id, space_id); |
842 | 0 | } |
843 | 0 | H5_AFTER_USER_CB(FAIL) |
844 | 0 | } |
845 | | |
846 | | /* Indicate error during filter callback */ |
847 | 0 | if (status < 0) |
848 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_SETLOCAL, FAIL, "error during user callback"); |
849 | 0 | } /* end if */ |
850 | 0 | break; |
851 | | |
852 | 0 | default: |
853 | 0 | assert("invalid prelude type" && 0); |
854 | 0 | } /* end switch */ |
855 | 0 | } /* end else */ |
856 | 0 | } /* end for */ |
857 | | |
858 | 0 | done: |
859 | |
|
860 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
861 | 0 | } /* end H5Z__prelude_callback() */ |
862 | | |
863 | | /*------------------------------------------------------------------------- |
864 | | * Function: H5Z__prepare_prelude_callback_dcpl |
865 | | * |
866 | | * Purpose: Prepares to make a dataset creation "prelude" callback |
867 | | * for the "can_apply" or "set_local" routines. |
868 | | * |
869 | | * Return: Non-negative on success/Negative on failure |
870 | | * |
871 | | * Notes: The chunk dimensions are used to create a dataspace, instead |
872 | | * of passing in the dataset's dataspace, since the chunk |
873 | | * dimensions are what the I/O filter will actually see |
874 | | *------------------------------------------------------------------------- |
875 | | */ |
876 | | static herr_t |
877 | | H5Z__prepare_prelude_callback_dcpl(hid_t dcpl_id, hid_t type_id, H5Z_prelude_type_t prelude_type) |
878 | 0 | { |
879 | 0 | hid_t space_id = -1; /* ID for dataspace describing chunk */ |
880 | 0 | H5O_layout_t *dcpl_layout = NULL; /* Dataset's layout information */ |
881 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
882 | |
|
883 | 0 | FUNC_ENTER_PACKAGE |
884 | |
|
885 | 0 | assert(H5I_GENPROP_LST == H5I_get_type(dcpl_id)); |
886 | 0 | assert(H5I_DATATYPE == H5I_get_type(type_id)); |
887 | | |
888 | | /* Check if the property list is non-default */ |
889 | 0 | if (dcpl_id != H5P_DATASET_CREATE_DEFAULT) { |
890 | 0 | H5P_genplist_t *dc_plist; /* Dataset creation property list object */ |
891 | | |
892 | | /* Get memory for the layout */ |
893 | 0 | if (NULL == (dcpl_layout = (H5O_layout_t *)H5MM_calloc(sizeof(H5O_layout_t)))) |
894 | 0 | HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate dcpl layout buffer"); |
895 | | |
896 | | /* Get dataset creation property list object */ |
897 | 0 | if (NULL == (dc_plist = (H5P_genplist_t *)H5I_object(dcpl_id))) |
898 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "can't get dataset creation property list"); |
899 | | |
900 | | /* Peek at the layout information */ |
901 | 0 | if (H5P_peek(dc_plist, H5D_CRT_LAYOUT_NAME, dcpl_layout) < 0) |
902 | 0 | HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't retrieve layout"); |
903 | | |
904 | | /* Check if the dataset is chunked */ |
905 | 0 | if (H5D_CHUNKED == dcpl_layout->type) { |
906 | 0 | H5O_pline_t dcpl_pline; /* Object's I/O pipeline information */ |
907 | | |
908 | | /* Get I/O pipeline information */ |
909 | 0 | if (H5P_peek(dc_plist, H5O_CRT_PIPELINE_NAME, &dcpl_pline) < 0) |
910 | 0 | HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't retrieve pipeline filter"); |
911 | | |
912 | | /* Check if the chunks have filters */ |
913 | 0 | if (dcpl_pline.nused > 0) { |
914 | 0 | hsize_t chunk_dims[H5O_LAYOUT_NDIMS]; /* Size of chunk dimensions */ |
915 | 0 | H5S_t *space; /* Dataspace describing chunk */ |
916 | 0 | size_t u; /* Local index variable */ |
917 | | |
918 | | /* Create a dataspace for a chunk & set the extent */ |
919 | 0 | for (u = 0; u < dcpl_layout->u.chunk.ndims; u++) |
920 | 0 | chunk_dims[u] = dcpl_layout->u.chunk.dim[u]; |
921 | 0 | if (NULL == (space = H5S_create_simple(dcpl_layout->u.chunk.ndims, chunk_dims, NULL))) |
922 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCREATE, FAIL, "can't create simple dataspace"); |
923 | | |
924 | | /* Get ID for dataspace to pass to filter routines */ |
925 | 0 | if ((space_id = H5I_register(H5I_DATASPACE, space, false)) < 0) { |
926 | 0 | (void)H5S_close(space); |
927 | 0 | HGOTO_ERROR(H5E_ID, H5E_CANTREGISTER, FAIL, "unable to register dataspace ID"); |
928 | 0 | } |
929 | | |
930 | | /* Make the callbacks */ |
931 | 0 | if (H5Z__prelude_callback(&dcpl_pline, dcpl_id, type_id, space_id, prelude_type) < 0) |
932 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANAPPLY, FAIL, "unable to apply filter"); |
933 | 0 | } |
934 | 0 | } |
935 | 0 | } |
936 | | |
937 | 0 | done: |
938 | 0 | if (space_id > 0 && H5I_dec_ref(space_id) < 0) |
939 | 0 | HDONE_ERROR(H5E_PLINE, H5E_CANTRELEASE, FAIL, "unable to close dataspace"); |
940 | |
|
941 | 0 | if (dcpl_layout) |
942 | 0 | dcpl_layout = (H5O_layout_t *)H5MM_xfree(dcpl_layout); |
943 | |
|
944 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
945 | 0 | } /* end H5Z__prepare_prelude_callback_dcpl() */ |
946 | | |
947 | | /*------------------------------------------------------------------------- |
948 | | * Function: H5Z_can_apply |
949 | | * |
950 | | * Purpose: Checks if all the filters defined in the dataset creation |
951 | | * property list can be applied to a particular combination of |
952 | | * datatype and dataspace for a dataset. |
953 | | * |
954 | | * Return: Non-negative on success |
955 | | * Negative on failure |
956 | | * |
957 | | * Notes: The chunk dimensions are used to create a dataspace, instead |
958 | | * of passing in the dataset's dataspace, since the chunk |
959 | | * dimensions are what the I/O filter will actually see |
960 | | *------------------------------------------------------------------------- |
961 | | */ |
962 | | herr_t |
963 | | H5Z_can_apply(hid_t dcpl_id, hid_t type_id) |
964 | 0 | { |
965 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
966 | |
|
967 | 0 | FUNC_ENTER_NOAPI(FAIL) |
968 | | |
969 | | /* Make "can apply" callbacks for filters in pipeline */ |
970 | 0 | if (H5Z__prepare_prelude_callback_dcpl(dcpl_id, type_id, H5Z_PRELUDE_CAN_APPLY) < 0) |
971 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANAPPLY, FAIL, "unable to apply filter"); |
972 | | |
973 | 0 | done: |
974 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
975 | 0 | } /* end H5Z_can_apply() */ |
976 | | |
977 | | /*------------------------------------------------------------------------- |
978 | | * Function: H5Z_set_local |
979 | | * |
980 | | * Purpose: Makes callbacks to modify dataset creation list property |
981 | | * settings for filters on a new dataset, based on the datatype |
982 | | * and dataspace of that dataset (chunk). |
983 | | * |
984 | | * Return: Non-negative on success |
985 | | * Negative on failure |
986 | | * |
987 | | * Notes: The chunk dimensions are used to create a dataspace, instead |
988 | | * of passing in the dataset's dataspace, since the chunk |
989 | | * dimensions are what the I/O filter will actually see |
990 | | *------------------------------------------------------------------------- |
991 | | */ |
992 | | herr_t |
993 | | H5Z_set_local(hid_t dcpl_id, hid_t type_id) |
994 | 0 | { |
995 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
996 | |
|
997 | 0 | FUNC_ENTER_NOAPI(FAIL) |
998 | | |
999 | | /* Make "set local" callbacks for filters in pipeline */ |
1000 | 0 | if (H5Z__prepare_prelude_callback_dcpl(dcpl_id, type_id, H5Z_PRELUDE_SET_LOCAL) < 0) |
1001 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_SETLOCAL, FAIL, "local filter parameters not set"); |
1002 | | |
1003 | 0 | done: |
1004 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1005 | 0 | } /* end H5Z_set_local() */ |
1006 | | |
1007 | | /*------------------------------------------------------------------------- |
1008 | | * Function: H5Z_can_apply_direct |
1009 | | * |
1010 | | * Purpose: Checks if all the filters defined in the pipeline can be |
1011 | | * applied to an opaque byte stream (currently only a group). |
1012 | | * The pipeline is assumed to have at least one filter. |
1013 | | * |
1014 | | * Return: Non-negative on success |
1015 | | * Negative on failure |
1016 | | *------------------------------------------------------------------------- |
1017 | | */ |
1018 | | herr_t |
1019 | | H5Z_can_apply_direct(const H5O_pline_t *pline) |
1020 | 0 | { |
1021 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1022 | |
|
1023 | 0 | FUNC_ENTER_NOAPI(FAIL) |
1024 | |
|
1025 | 0 | assert(pline->nused > 0); |
1026 | | |
1027 | | /* Make "can apply" callbacks for filters in pipeline */ |
1028 | 0 | if (H5Z__prelude_callback(pline, (hid_t)-1, (hid_t)-1, (hid_t)-1, H5Z_PRELUDE_CAN_APPLY) < 0) |
1029 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANAPPLY, FAIL, "unable to apply filter"); |
1030 | | |
1031 | 0 | done: |
1032 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1033 | 0 | } /* end H5Z_can_apply_direct() */ |
1034 | | |
1035 | | /*------------------------------------------------------------------------- |
1036 | | * Function: H5Z_set_local_direct |
1037 | | * |
1038 | | * Purpose: Makes callbacks to modify local settings for filters on a |
1039 | | * new opaque object. The pipeline is assumed to have at |
1040 | | * least one filter. |
1041 | | * |
1042 | | * Return: Non-negative on success |
1043 | | * Negative on failure |
1044 | | * |
1045 | | * Notes: This callback will almost certainly not do anything |
1046 | | * useful, other than to make certain that the filter will |
1047 | | * accept opaque data. |
1048 | | *------------------------------------------------------------------------- |
1049 | | */ |
1050 | | herr_t |
1051 | | H5Z_set_local_direct(const H5O_pline_t *pline) |
1052 | 0 | { |
1053 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1054 | |
|
1055 | 0 | FUNC_ENTER_NOAPI(FAIL) |
1056 | |
|
1057 | 0 | assert(pline->nused > 0); |
1058 | | |
1059 | | /* Make "set local" callbacks for filters in pipeline */ |
1060 | 0 | if (H5Z__prelude_callback(pline, (hid_t)-1, (hid_t)-1, (hid_t)-1, H5Z_PRELUDE_SET_LOCAL) < 0) |
1061 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_SETLOCAL, FAIL, "local filter parameters not set"); |
1062 | | |
1063 | 0 | done: |
1064 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1065 | 0 | } /* end H5Z_set_local_direct() */ |
1066 | | |
1067 | | /*------------------------------------------------------------------------- |
1068 | | * Function: H5Z_ignore_filters |
1069 | | * |
1070 | | * Purpose: Determine whether filters can be ignored. |
1071 | | * |
1072 | | * Description: |
1073 | | * When the filters are optional (i.e., H5Z_FLAG_OPTIONAL is provided), |
1074 | | * if any of the following conditions is met, the filters will be ignored: |
1075 | | * - dataspace is either H5S_NULL or H5S_SCALAR |
1076 | | * However, if any of these conditions exists and a filter is not |
1077 | | * optional, the function will produce an error. |
1078 | | * This function runs before the can_apply callback of the filters and |
1079 | | * its negated return value is effectively OR'ed to the return value |
1080 | | * of can_apply. |
1081 | | * |
1082 | | * Return: Non-negative(true/false) on success |
1083 | | * Negative on failure |
1084 | | * |
1085 | | *------------------------------------------------------------------------- |
1086 | | */ |
1087 | | htri_t |
1088 | | H5Z_ignore_filters(hid_t dcpl_id, const H5S_t *space) |
1089 | 0 | { |
1090 | 0 | H5P_genplist_t *dc_plist; /* Dataset creation property list object */ |
1091 | 0 | H5O_pline_t pline; /* Object's I/O pipeline information */ |
1092 | 0 | H5S_class_t space_class; /* To check class of space */ |
1093 | 0 | htri_t ret_value = false; /* true for ignoring filters */ |
1094 | |
|
1095 | 0 | FUNC_ENTER_NOAPI(FAIL) |
1096 | |
|
1097 | 0 | if (NULL == (dc_plist = (H5P_genplist_t *)H5I_object(dcpl_id))) |
1098 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "can't get dataset creation property list"); |
1099 | | |
1100 | | /* Get pipeline information */ |
1101 | 0 | if (H5P_peek(dc_plist, H5O_CRT_PIPELINE_NAME, &pline) < 0) |
1102 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "can't retrieve pipeline filter"); |
1103 | | |
1104 | | /* Get datatype and dataspace classes for quick access */ |
1105 | 0 | space_class = H5S_GET_EXTENT_TYPE(space); |
1106 | | |
1107 | | /* When these conditions occur, if there are required filters in pline, |
1108 | | then report a failure, otherwise, set flag that they can be ignored */ |
1109 | 0 | if (space_class == H5S_NULL || space_class == H5S_SCALAR) { |
1110 | 0 | size_t ii; |
1111 | 0 | if (pline.nused > 0) { |
1112 | 0 | for (ii = 0; ii < pline.nused; ii++) { |
1113 | 0 | if (!(pline.filter[ii].flags & H5Z_FLAG_OPTIONAL)) |
1114 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTFILTER, FAIL, "not suitable for filters"); |
1115 | 0 | } |
1116 | | |
1117 | | /* All filters are optional, we can ignore them */ |
1118 | 0 | ret_value = true; |
1119 | 0 | } |
1120 | 0 | } /* bad for filters */ |
1121 | | |
1122 | 0 | done: |
1123 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1124 | 0 | } /* end H5Z_ignore_filters() */ |
1125 | | |
1126 | | /*------------------------------------------------------------------------- |
1127 | | * Function: H5Z_modify |
1128 | | * |
1129 | | * Purpose: Modify filter parameters for specified pipeline. |
1130 | | * |
1131 | | * Return: Non-negative on success |
1132 | | * Negative on failure |
1133 | | *------------------------------------------------------------------------- |
1134 | | */ |
1135 | | herr_t |
1136 | | H5Z_modify(const H5O_pline_t *pline, H5Z_filter_t filter, unsigned flags, size_t cd_nelmts, |
1137 | | const unsigned int cd_values[/*cd_nelmts*/]) |
1138 | 0 | { |
1139 | 0 | size_t idx; /* Index of filter in pipeline */ |
1140 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1141 | |
|
1142 | 0 | FUNC_ENTER_NOAPI(FAIL) |
1143 | |
|
1144 | 0 | assert(pline); |
1145 | 0 | assert(filter >= 0 && filter <= H5Z_FILTER_MAX); |
1146 | 0 | assert(0 == (flags & ~((unsigned)H5Z_FLAG_DEFMASK))); |
1147 | 0 | assert(0 == cd_nelmts || cd_values); |
1148 | | |
1149 | | /* Locate the filter in the pipeline */ |
1150 | 0 | for (idx = 0; idx < pline->nused; idx++) |
1151 | 0 | if (pline->filter[idx].id == filter) |
1152 | 0 | break; |
1153 | | |
1154 | | /* Check if the filter was not already in the pipeline */ |
1155 | 0 | if (idx > pline->nused) |
1156 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_NOTFOUND, FAIL, "filter not in pipeline"); |
1157 | | |
1158 | | /* Change parameters for filter */ |
1159 | 0 | pline->filter[idx].flags = flags; |
1160 | 0 | pline->filter[idx].cd_nelmts = cd_nelmts; |
1161 | | |
1162 | | /* Free any existing parameters */ |
1163 | 0 | if (pline->filter[idx].cd_values != NULL && pline->filter[idx].cd_values != pline->filter[idx]._cd_values) |
1164 | 0 | H5MM_xfree(pline->filter[idx].cd_values); |
1165 | | |
1166 | | /* Set parameters */ |
1167 | 0 | if (cd_nelmts > 0) { |
1168 | 0 | size_t i; /* Local index variable */ |
1169 | | |
1170 | | /* Allocate memory or point at internal buffer */ |
1171 | 0 | if (cd_nelmts > H5Z_COMMON_CD_VALUES) { |
1172 | 0 | pline->filter[idx].cd_values = (unsigned *)H5MM_malloc(cd_nelmts * sizeof(unsigned)); |
1173 | 0 | if (NULL == pline->filter[idx].cd_values) |
1174 | 0 | HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, |
1175 | 0 | "memory allocation failed for filter parameters"); |
1176 | 0 | } /* end if */ |
1177 | 0 | else |
1178 | 0 | pline->filter[idx].cd_values = pline->filter[idx]._cd_values; |
1179 | | |
1180 | | /* Copy client data values */ |
1181 | 0 | for (i = 0; i < cd_nelmts; i++) |
1182 | 0 | pline->filter[idx].cd_values[i] = cd_values[i]; |
1183 | 0 | } /* end if */ |
1184 | 0 | else |
1185 | 0 | pline->filter[idx].cd_values = NULL; |
1186 | | |
1187 | 0 | done: |
1188 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1189 | 0 | } /* end H5Z_modify() */ |
1190 | | |
1191 | | /*------------------------------------------------------------------------- |
1192 | | * Function: H5Z_append |
1193 | | * |
1194 | | * Purpose: Append another filter to the specified pipeline. |
1195 | | * |
1196 | | * Return: Non-negative on success |
1197 | | * Negative on failure |
1198 | | *------------------------------------------------------------------------- |
1199 | | */ |
1200 | | herr_t |
1201 | | H5Z_append(H5O_pline_t *pline, H5Z_filter_t filter, unsigned flags, size_t cd_nelmts, |
1202 | | const unsigned int cd_values[/*cd_nelmts*/]) |
1203 | 0 | { |
1204 | 0 | size_t idx; |
1205 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1206 | |
|
1207 | 0 | FUNC_ENTER_NOAPI(FAIL) |
1208 | |
|
1209 | 0 | assert(pline); |
1210 | 0 | assert(filter >= 0 && filter <= H5Z_FILTER_MAX); |
1211 | 0 | assert(0 == (flags & ~((unsigned)H5Z_FLAG_DEFMASK))); |
1212 | 0 | assert(0 == cd_nelmts || cd_values); |
1213 | | |
1214 | | /* |
1215 | | * Check filter limit. We do it here for early warnings although we may |
1216 | | * decide to relax this restriction in the future. |
1217 | | */ |
1218 | 0 | if (pline->nused >= H5Z_MAX_NFILTERS) |
1219 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "too many filters in pipeline"); |
1220 | | |
1221 | | /* Check for freshly allocated filter pipeline */ |
1222 | 0 | if (pline->version == 0) |
1223 | 0 | pline->version = H5O_PLINE_VERSION_1; |
1224 | | |
1225 | | /* Allocate additional space in the pipeline if it's full */ |
1226 | 0 | if (pline->nused >= pline->nalloc) { |
1227 | 0 | H5O_pline_t x; |
1228 | 0 | size_t n; |
1229 | | |
1230 | | /* Each filter's data may be stored internally or may be |
1231 | | * a separate block of memory. |
1232 | | * For each filter, if cd_values points to the internal array |
1233 | | * _cd_values, the pointer will need to be updated when the |
1234 | | * filter struct is reallocated. Set these pointers to ~NULL |
1235 | | * so that we can reset them after reallocating the filters array. |
1236 | | */ |
1237 | 0 | for (n = 0; n < pline->nalloc; ++n) |
1238 | 0 | if (pline->filter[n].cd_values == pline->filter[n]._cd_values) |
1239 | 0 | pline->filter[n].cd_values = (unsigned *)((void *)~((size_t)NULL)); |
1240 | |
|
1241 | 0 | x.nalloc = MAX(H5Z_MAX_NFILTERS, 2 * pline->nalloc); |
1242 | 0 | x.filter = (H5Z_filter_info_t *)H5MM_realloc(pline->filter, x.nalloc * sizeof(x.filter[0])); |
1243 | 0 | if (NULL == x.filter) |
1244 | 0 | HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for filter pipeline"); |
1245 | | |
1246 | | /* Fix pointers in previous filters that need to point to their own |
1247 | | * internal data. |
1248 | | */ |
1249 | 0 | for (n = 0; n < pline->nalloc; ++n) |
1250 | 0 | if (x.filter[n].cd_values == (void *)~((size_t)NULL)) |
1251 | 0 | x.filter[n].cd_values = x.filter[n]._cd_values; |
1252 | | |
1253 | | /* Point to newly allocated buffer */ |
1254 | 0 | pline->nalloc = x.nalloc; |
1255 | 0 | pline->filter = x.filter; |
1256 | 0 | } /* end if */ |
1257 | | |
1258 | | /* Add the new filter to the pipeline */ |
1259 | 0 | idx = pline->nused; |
1260 | 0 | pline->filter[idx].id = filter; |
1261 | 0 | pline->filter[idx].flags = flags; |
1262 | 0 | pline->filter[idx].name = NULL; /*we'll pick it up later*/ |
1263 | 0 | pline->filter[idx].cd_nelmts = cd_nelmts; |
1264 | 0 | if (cd_nelmts > 0) { |
1265 | 0 | size_t i; /* Local index variable */ |
1266 | | |
1267 | | /* Allocate memory or point at internal buffer */ |
1268 | 0 | if (cd_nelmts > H5Z_COMMON_CD_VALUES) { |
1269 | 0 | pline->filter[idx].cd_values = (unsigned *)H5MM_malloc(cd_nelmts * sizeof(unsigned)); |
1270 | 0 | if (NULL == pline->filter[idx].cd_values) |
1271 | 0 | HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for filter"); |
1272 | 0 | } /* end if */ |
1273 | 0 | else |
1274 | 0 | pline->filter[idx].cd_values = pline->filter[idx]._cd_values; |
1275 | | |
1276 | | /* Copy client data values */ |
1277 | 0 | for (i = 0; i < cd_nelmts; i++) |
1278 | 0 | pline->filter[idx].cd_values[i] = cd_values[i]; |
1279 | 0 | } /* end if */ |
1280 | 0 | else |
1281 | 0 | pline->filter[idx].cd_values = NULL; |
1282 | | |
1283 | 0 | pline->nused++; |
1284 | |
|
1285 | 0 | done: |
1286 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1287 | 0 | } /* end H5Z_append() */ |
1288 | | |
1289 | | /*------------------------------------------------------------------------- |
1290 | | * Function: H5Z__find_idx |
1291 | | * |
1292 | | * Purpose: Given a filter ID return the offset in the global array |
1293 | | * that holds all the registered filters. |
1294 | | * |
1295 | | * Return: Success: Non-negative index of entry in global filter table. |
1296 | | * Failure: Negative |
1297 | | *------------------------------------------------------------------------- |
1298 | | */ |
1299 | | static int |
1300 | | H5Z__find_idx(H5Z_filter_t id) |
1301 | 0 | { |
1302 | 0 | size_t i; /* Local index variable */ |
1303 | 0 | int ret_value = FAIL; /* Return value */ |
1304 | |
|
1305 | 0 | FUNC_ENTER_PACKAGE_NOERR |
1306 | |
|
1307 | 0 | for (i = 0; i < H5Z_table_used_g; i++) |
1308 | 0 | if (H5Z_table_g[i].id == id) |
1309 | 0 | HGOTO_DONE((int)i); |
1310 | | |
1311 | 0 | done: |
1312 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1313 | 0 | } /* end H5Z__find_idx() */ |
1314 | | |
1315 | | /*------------------------------------------------------------------------- |
1316 | | * Function: H5Z_find |
1317 | | * |
1318 | | * Purpose: Given a filter ID return a pointer to a global struct that |
1319 | | * defines the filter. |
1320 | | * |
1321 | | * Return: Non-negative on success |
1322 | | * Negative on failure |
1323 | | *------------------------------------------------------------------------- |
1324 | | */ |
1325 | | herr_t |
1326 | | H5Z_find(bool try, H5Z_filter_t id, H5Z_class2_t **cls) |
1327 | 0 | { |
1328 | 0 | int idx; /* Filter index in global table */ |
1329 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1330 | |
|
1331 | 0 | FUNC_ENTER_NOAPI(FAIL) |
1332 | | |
1333 | | /* Get the index in the global table */ |
1334 | 0 | if ((idx = H5Z__find_idx(id)) < 0) { |
1335 | 0 | *cls = NULL; |
1336 | | |
1337 | | /* Don't push error on speculative lookup */ |
1338 | 0 | if (!try) |
1339 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_NOTFOUND, FAIL, "required filter %d is not registered", id); |
1340 | 0 | } |
1341 | 0 | else |
1342 | 0 | *cls = H5Z_table_g + idx; |
1343 | | |
1344 | 0 | done: |
1345 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1346 | 0 | } /* H5Z_find() */ |
1347 | | |
1348 | | /*------------------------------------------------------------------------- |
1349 | | * Function: H5Z_pipeline |
1350 | | * |
1351 | | * Purpose: Process data through the filter pipeline. The FLAGS argument |
1352 | | * is the filter invocation flags (definition flags come from |
1353 | | * the PLINE->filter[].flags). The filters are processed in |
1354 | | * definition order unless the H5Z_FLAG_REVERSE is set. The |
1355 | | * FILTER_MASK is a bit-mask to indicate which filters to skip |
1356 | | * and on exit will indicate which filters failed. Each |
1357 | | * filter has an index number in the pipeline and that index |
1358 | | * number is the filter's bit in the FILTER_MASK. NBYTES is the |
1359 | | * number of bytes of data to filter and on exit should be the |
1360 | | * number of resulting bytes while BUF_SIZE holds the total |
1361 | | * allocated size of the buffer, which is pointed to BUF. |
1362 | | * |
1363 | | * If the buffer must grow during processing of the pipeline |
1364 | | * then the pipeline function should free the original buffer |
1365 | | * and return a fresh buffer, adjusting BUF_SIZE accordingly. |
1366 | | * |
1367 | | * Return: Non-negative on success |
1368 | | * Negative on failure |
1369 | | *------------------------------------------------------------------------- |
1370 | | */ |
1371 | | herr_t |
1372 | | H5Z_pipeline(const H5O_pline_t *pline, unsigned flags, unsigned *filter_mask /*in,out*/, H5Z_EDC_t edc_read, |
1373 | | H5Z_cb_t cb_struct, size_t *nbytes /*in,out*/, size_t *buf_size /*in,out*/, |
1374 | | void **buf /*in,out*/) |
1375 | 0 | { |
1376 | 0 | size_t idx; |
1377 | 0 | size_t new_nbytes; |
1378 | 0 | int fclass_idx; /* Index of filter class in global table */ |
1379 | 0 | H5Z_class2_t *fclass = NULL; /* Filter class pointer */ |
1380 | | #ifdef H5Z_DEBUG |
1381 | | H5Z_stats_t *fstats = NULL; /* Filter stats pointer */ |
1382 | | H5_timer_t timer; /* Timer for filter operations */ |
1383 | | H5_timevals_t times; /* Elapsed time for each operation */ |
1384 | | #endif |
1385 | 0 | unsigned failed = 0; |
1386 | 0 | unsigned tmp_flags; |
1387 | 0 | size_t i; |
1388 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1389 | |
|
1390 | 0 | FUNC_ENTER_NOAPI(FAIL) |
1391 | |
|
1392 | 0 | assert(0 == (flags & ~((unsigned)H5Z_FLAG_INVMASK))); |
1393 | 0 | assert(filter_mask); |
1394 | 0 | assert(nbytes && *nbytes > 0); |
1395 | 0 | assert(buf_size && *buf_size > 0); |
1396 | 0 | assert(buf && *buf); |
1397 | 0 | assert(!pline || pline->nused < H5Z_MAX_NFILTERS); |
1398 | | |
1399 | | /* clang-format off */ |
1400 | |
|
1401 | | #ifdef H5Z_DEBUG |
1402 | | H5_timer_init(&timer); |
1403 | | #endif |
1404 | 0 | if (pline && (flags & H5Z_FLAG_REVERSE)) { /* Read */ |
1405 | 0 | for (i = pline->nused; i > 0; --i) { |
1406 | 0 | idx = i - 1; |
1407 | 0 | if (*filter_mask & ((unsigned)1 << idx)) { |
1408 | 0 | failed |= (unsigned)1 << idx; |
1409 | 0 | continue; /* filter excluded */ |
1410 | 0 | } |
1411 | | |
1412 | | /* If the filter isn't registered and the application doesn't |
1413 | | * indicate no plugin through HDF5_PRELOAD_PLUG (using the symbol "::"), |
1414 | | * try to load it dynamically and register it. Otherwise, return failure |
1415 | | */ |
1416 | 0 | if ((fclass_idx = H5Z__find_idx(pline->filter[idx].id)) < 0) { |
1417 | 0 | H5PL_key_t key; |
1418 | 0 | const H5Z_class2_t *filter_info; |
1419 | 0 | bool issue_error = false; |
1420 | | |
1421 | | /* Try loading the filter */ |
1422 | 0 | key.id = (int)(pline->filter[idx].id); |
1423 | 0 | if (NULL != (filter_info = (const H5Z_class2_t *)H5PL_load(H5PL_TYPE_FILTER, &key))) { |
1424 | | /* Register the filter we loaded */ |
1425 | 0 | if (H5Z_register(filter_info) < 0) |
1426 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to register filter"); |
1427 | | |
1428 | | /* Search in the table of registered filters again to find the dynamic filter just loaded |
1429 | | * and registered */ |
1430 | 0 | if ((fclass_idx = H5Z__find_idx(pline->filter[idx].id)) < 0) |
1431 | 0 | issue_error = true; |
1432 | 0 | } |
1433 | 0 | else |
1434 | 0 | issue_error = true; |
1435 | | |
1436 | | /* Check for error */ |
1437 | 0 | if (issue_error) { |
1438 | | /* Print out the filter name to give more info. But the name is optional for |
1439 | | * the filter */ |
1440 | 0 | if (pline->filter[idx].name) |
1441 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_READERROR, FAIL, "required filter '%s' is not registered", |
1442 | 0 | pline->filter[idx].name); |
1443 | 0 | else |
1444 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_READERROR, FAIL, |
1445 | 0 | "required filter (name unavailable) is not registered"); |
1446 | 0 | } |
1447 | 0 | } /* end if */ |
1448 | | |
1449 | 0 | fclass = &H5Z_table_g[fclass_idx]; |
1450 | |
|
1451 | | #ifdef H5Z_DEBUG |
1452 | | fstats = &H5Z_stat_table_g[fclass_idx]; |
1453 | | H5_timer_start(&timer); |
1454 | | #endif |
1455 | |
|
1456 | 0 | tmp_flags = flags | (pline->filter[idx].flags); |
1457 | 0 | tmp_flags |= (edc_read == H5Z_DISABLE_EDC) ? H5Z_FLAG_SKIP_EDC : 0; |
1458 | | |
1459 | | /* Pause errors if there's a callback defined */ |
1460 | 0 | if (cb_struct.func) |
1461 | 0 | H5E_PAUSE_ERRORS |
1462 | |
|
1463 | 0 | { |
1464 | | /* Don't prepare for a user callback if this is an internal filter */ |
1465 | 0 | if (fclass->id < H5Z_FILTER_RESERVED) |
1466 | | /* Invoke main "filter" callback */ |
1467 | 0 | new_nbytes = (fclass->filter)(tmp_flags, pline->filter[idx].cd_nelmts, pline->filter[idx].cd_values, *nbytes, buf_size, buf); |
1468 | 0 | else { |
1469 | | /* Prepare & restore library for user callback */ |
1470 | 0 | H5_BEFORE_USER_CB(FAIL) |
1471 | 0 | { |
1472 | | /* Invoke main "filter" callback */ |
1473 | 0 | new_nbytes = (fclass->filter)(tmp_flags, pline->filter[idx].cd_nelmts, |
1474 | 0 | pline->filter[idx].cd_values, *nbytes, buf_size, buf); |
1475 | 0 | } |
1476 | 0 | H5_AFTER_USER_CB(FAIL) |
1477 | 0 | } |
1478 | 0 | } |
1479 | | |
1480 | 0 | if (cb_struct.func) |
1481 | 0 | H5E_RESUME_ERRORS |
1482 | |
|
1483 | | #ifdef H5Z_DEBUG |
1484 | | H5_timer_stop(&timer); |
1485 | | H5_timer_get_times(timer, ×); |
1486 | | fstats->stats[1].times.elapsed += times.elapsed; |
1487 | | fstats->stats[1].times.system += times.system; |
1488 | | fstats->stats[1].times.user += times.user; |
1489 | | |
1490 | | fstats->stats[1].total += MAX(*nbytes, new_nbytes); |
1491 | | if (0 == new_nbytes) |
1492 | | fstats->stats[1].errors += *nbytes; |
1493 | | #endif |
1494 | |
|
1495 | 0 | if (0 == new_nbytes) { |
1496 | 0 | if (cb_struct.func) { |
1497 | 0 | H5Z_cb_return_t status; |
1498 | | |
1499 | | /* Prepare & restore library for user callback */ |
1500 | 0 | H5_BEFORE_USER_CB(FAIL) |
1501 | 0 | { |
1502 | | /* Invoke user callback */ |
1503 | 0 | status = cb_struct.func(pline->filter[idx].id, *buf, *buf_size, cb_struct.op_data); |
1504 | 0 | } |
1505 | 0 | H5_AFTER_USER_CB(FAIL) |
1506 | 0 | if (H5Z_CB_FAIL == status) |
1507 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_READERROR, FAIL, "filter returned failure during read"); |
1508 | 0 | } |
1509 | 0 | else |
1510 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_READERROR, FAIL, "filter returned failure during read"); |
1511 | | |
1512 | 0 | *nbytes = *buf_size; |
1513 | 0 | failed |= (unsigned)1 << idx; |
1514 | 0 | } |
1515 | 0 | else { |
1516 | | /* Make sure returned new_nbytes is consistent with the returned buffer size */ |
1517 | 0 | if (H5_UNLIKELY(*buf_size < new_nbytes)) |
1518 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_BADVALUE, FAIL, "buffer size is too small after filter callback"); |
1519 | | |
1520 | | /* Update nbytes */ |
1521 | 0 | *nbytes = new_nbytes; |
1522 | 0 | } |
1523 | 0 | } |
1524 | 0 | } |
1525 | 0 | else if (pline) |
1526 | 0 | { /* Write */ |
1527 | 0 | for (idx = 0; idx < pline->nused; idx++) { |
1528 | 0 | if (*filter_mask & ((unsigned)1 << idx)) { |
1529 | 0 | failed |= (unsigned)1 << idx; |
1530 | 0 | continue; /* filter excluded */ |
1531 | 0 | } |
1532 | 0 | if ((fclass_idx = H5Z__find_idx(pline->filter[idx].id)) < 0) { |
1533 | | /* Check if filter is optional -- If it isn't, then error */ |
1534 | 0 | if ((pline->filter[idx].flags & H5Z_FLAG_OPTIONAL) == 0) |
1535 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_WRITEERROR, FAIL, "required filter is not registered"); |
1536 | 0 | failed |= (unsigned)1 << idx; |
1537 | 0 | continue; /* filter excluded */ |
1538 | 0 | } /* end if */ |
1539 | | |
1540 | 0 | fclass = &H5Z_table_g[fclass_idx]; |
1541 | |
|
1542 | | #ifdef H5Z_DEBUG |
1543 | | fstats = &H5Z_stat_table_g[fclass_idx]; |
1544 | | H5_timer_start(&timer); |
1545 | | #endif |
1546 | | |
1547 | | /* Pause errors if the filter is optional or if there's a callback defined */ |
1548 | 0 | if ((pline->filter[idx].flags & H5Z_FLAG_OPTIONAL) || cb_struct.func) |
1549 | 0 | H5E_PAUSE_ERRORS |
1550 | |
|
1551 | 0 | { |
1552 | | /* Don't prepare for a user callback if this is an internal filter */ |
1553 | 0 | if (fclass->id < H5Z_FILTER_RESERVED) |
1554 | | /* Invoke main "filter" callback */ |
1555 | 0 | new_nbytes = (fclass->filter)(flags | (pline->filter[idx].flags), pline->filter[idx].cd_nelmts, pline->filter[idx].cd_values, *nbytes, buf_size, buf); |
1556 | 0 | else { |
1557 | | /* Prepare & restore library for user callback */ |
1558 | 0 | H5_BEFORE_USER_CB(FAIL) |
1559 | 0 | { |
1560 | | /* Invoke main "filter" callback */ |
1561 | 0 | new_nbytes = (fclass->filter)(flags | (pline->filter[idx].flags), pline->filter[idx].cd_nelmts, |
1562 | 0 | pline->filter[idx].cd_values, *nbytes, buf_size, buf); |
1563 | 0 | } |
1564 | 0 | H5_AFTER_USER_CB(FAIL) |
1565 | 0 | } |
1566 | 0 | } |
1567 | | |
1568 | 0 | if ((pline->filter[idx].flags & H5Z_FLAG_OPTIONAL) || cb_struct.func) |
1569 | 0 | H5E_RESUME_ERRORS |
1570 | |
|
1571 | | #ifdef H5Z_DEBUG |
1572 | | H5_timer_stop(&timer); |
1573 | | H5_timer_get_times(timer, ×); |
1574 | | fstats->stats[0].times.elapsed += times.elapsed; |
1575 | | fstats->stats[0].times.system += times.system; |
1576 | | fstats->stats[0].times.user += times.user; |
1577 | | |
1578 | | fstats->stats[0].total += MAX(*nbytes, new_nbytes); |
1579 | | if (0 == new_nbytes) |
1580 | | fstats->stats[0].errors += *nbytes; |
1581 | | #endif |
1582 | |
|
1583 | 0 | if (0 == new_nbytes) { |
1584 | 0 | if (0 == (pline->filter[idx].flags & H5Z_FLAG_OPTIONAL)) { |
1585 | 0 | if (cb_struct.func) { |
1586 | 0 | H5Z_cb_return_t status; |
1587 | | |
1588 | | /* Prepare & restore library for user callback */ |
1589 | 0 | H5_BEFORE_USER_CB(FAIL) |
1590 | 0 | { |
1591 | 0 | status = cb_struct.func(pline->filter[idx].id, *buf, *nbytes, cb_struct.op_data); |
1592 | 0 | } |
1593 | 0 | H5_AFTER_USER_CB(FAIL) |
1594 | 0 | if (H5Z_CB_FAIL == status) |
1595 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_WRITEERROR, FAIL, "filter returned failure"); |
1596 | 0 | } |
1597 | 0 | else |
1598 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_WRITEERROR, FAIL, "filter returned failure"); |
1599 | | |
1600 | 0 | *nbytes = *buf_size; |
1601 | 0 | } |
1602 | 0 | failed |= (unsigned)1 << idx; |
1603 | 0 | } |
1604 | 0 | else { |
1605 | | /* Make sure returned new_nbytes is consistent with the returned buffer size */ |
1606 | 0 | if (H5_UNLIKELY(*buf_size < new_nbytes)) |
1607 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_BADVALUE, FAIL, "buffer size is too small after filter callback"); |
1608 | | |
1609 | | /* Update nbytes */ |
1610 | 0 | *nbytes = new_nbytes; |
1611 | 0 | } |
1612 | 0 | } /* end for */ |
1613 | 0 | } |
1614 | | |
1615 | 0 | *filter_mask = failed; |
1616 | |
|
1617 | 0 | done: |
1618 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1619 | | |
1620 | | /* clang-format on */ |
1621 | 0 | } |
1622 | | |
1623 | | /*------------------------------------------------------------------------- |
1624 | | * Function: H5Z_filter_info |
1625 | | * |
1626 | | * Purpose: Get pointer to filter info for pipeline |
1627 | | * |
1628 | | * Return: Non-negative on success |
1629 | | * Negative on failure |
1630 | | *------------------------------------------------------------------------- |
1631 | | */ |
1632 | | H5Z_filter_info_t * |
1633 | | H5Z_filter_info(const H5O_pline_t *pline, H5Z_filter_t filter) |
1634 | 0 | { |
1635 | 0 | size_t idx; /* Index of filter in pipeline */ |
1636 | 0 | H5Z_filter_info_t *ret_value = NULL; /* Return value */ |
1637 | |
|
1638 | 0 | FUNC_ENTER_NOAPI(NULL) |
1639 | |
|
1640 | 0 | assert(pline); |
1641 | 0 | assert(filter >= 0 && filter <= H5Z_FILTER_MAX); |
1642 | | |
1643 | | /* Locate the filter in the pipeline */ |
1644 | 0 | for (idx = 0; idx < pline->nused; idx++) |
1645 | 0 | if (pline->filter[idx].id == filter) |
1646 | 0 | break; |
1647 | | |
1648 | | /* Check if the filter was not already in the pipeline */ |
1649 | 0 | if (idx >= pline->nused) |
1650 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_NOTFOUND, NULL, "filter not in pipeline"); |
1651 | | |
1652 | | /* Set return value */ |
1653 | 0 | ret_value = &pline->filter[idx]; |
1654 | |
|
1655 | 0 | done: |
1656 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1657 | 0 | } /* end H5Z_filter_info() */ |
1658 | | |
1659 | | /*------------------------------------------------------------------------- |
1660 | | * Function: H5Z_filter_in_pline |
1661 | | * |
1662 | | * Purpose: Check whether a filter is in the filter pipeline using the |
1663 | | * filter ID. This function is very similar to H5Z_filter_info |
1664 | | * |
1665 | | * Return: true - found filter |
1666 | | * false - not found |
1667 | | * FAIL - error |
1668 | | *------------------------------------------------------------------------- |
1669 | | */ |
1670 | | htri_t |
1671 | | H5Z_filter_in_pline(const H5O_pline_t *pline, H5Z_filter_t filter) |
1672 | 0 | { |
1673 | 0 | size_t idx; /* Index of filter in pipeline */ |
1674 | 0 | htri_t ret_value = true; /* Return value */ |
1675 | |
|
1676 | 0 | FUNC_ENTER_NOAPI(FAIL) |
1677 | |
|
1678 | 0 | assert(pline); |
1679 | 0 | assert(filter >= 0 && filter <= H5Z_FILTER_MAX); |
1680 | | |
1681 | | /* Locate the filter in the pipeline */ |
1682 | 0 | for (idx = 0; idx < pline->nused; idx++) |
1683 | 0 | if (pline->filter[idx].id == filter) |
1684 | 0 | break; |
1685 | | |
1686 | | /* Check if the filter was not already in the pipeline */ |
1687 | 0 | if (idx >= pline->nused) |
1688 | 0 | ret_value = false; |
1689 | |
|
1690 | 0 | done: |
1691 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1692 | 0 | } /* end H5Z_filter_in_pline() */ |
1693 | | |
1694 | | /*------------------------------------------------------------------------- |
1695 | | * Function: H5Z_all_filters_avail |
1696 | | * |
1697 | | * Purpose: Verify that all the filters in a pipeline are currently |
1698 | | * available (i.e. registered) |
1699 | | * |
1700 | | * Return: Non-negative (true/false) on success |
1701 | | * Negative on failure |
1702 | | *------------------------------------------------------------------------- |
1703 | | */ |
1704 | | htri_t |
1705 | | H5Z_all_filters_avail(const H5O_pline_t *pline) |
1706 | 0 | { |
1707 | 0 | size_t i, j; /* Local index variable */ |
1708 | 0 | htri_t ret_value = true; /* Return value */ |
1709 | |
|
1710 | 0 | FUNC_ENTER_NOAPI(FAIL) |
1711 | | |
1712 | | /* Check args */ |
1713 | 0 | assert(pline); |
1714 | | |
1715 | | /* Iterate through all the filters in pipeline */ |
1716 | 0 | for (i = 0; i < pline->nused; i++) { |
1717 | | /* Look for each filter in the list of registered filters */ |
1718 | 0 | for (j = 0; j < H5Z_table_used_g; j++) |
1719 | 0 | if (H5Z_table_g[j].id == pline->filter[i].id) |
1720 | 0 | break; |
1721 | | |
1722 | | /* Check if we didn't find the filter */ |
1723 | 0 | if (j == H5Z_table_used_g) |
1724 | 0 | HGOTO_DONE(false); |
1725 | 0 | } /* end for */ |
1726 | | |
1727 | 0 | done: |
1728 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1729 | 0 | } /* end H5Z_all_filters_avail() */ |
1730 | | |
1731 | | /*------------------------------------------------------------------------- |
1732 | | * Function: H5Z_delete |
1733 | | * |
1734 | | * Purpose: Delete filter FILTER from pipeline PLINE; |
1735 | | * deletes all filters if FILTER is H5Z_FILTER_ALL |
1736 | | * |
1737 | | * Return: Non-negative on success |
1738 | | * Negative on failure |
1739 | | *------------------------------------------------------------------------- |
1740 | | */ |
1741 | | herr_t |
1742 | | H5Z_delete(H5O_pline_t *pline, H5Z_filter_t filter) |
1743 | 0 | { |
1744 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1745 | |
|
1746 | 0 | FUNC_ENTER_NOAPI(FAIL) |
1747 | | |
1748 | | /* Check args */ |
1749 | 0 | assert(pline); |
1750 | 0 | assert(filter >= 0 && filter <= H5Z_FILTER_MAX); |
1751 | | |
1752 | | /* if the pipeline has no filters, just return */ |
1753 | 0 | if (pline->nused == 0) |
1754 | 0 | HGOTO_DONE(SUCCEED); |
1755 | | |
1756 | | /* Delete all filters */ |
1757 | 0 | if (H5Z_FILTER_ALL == filter) { |
1758 | 0 | if (H5O_msg_reset(H5O_PLINE_ID, pline) < 0) |
1759 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTFREE, FAIL, "can't release pipeline info"); |
1760 | 0 | } |
1761 | | /* Delete filter */ |
1762 | 0 | else { |
1763 | 0 | size_t idx; /* Index of filter in pipeline */ |
1764 | 0 | bool found = false; /* Indicate filter was found in pipeline */ |
1765 | | |
1766 | | /* Locate the filter in the pipeline */ |
1767 | 0 | for (idx = 0; idx < pline->nused; idx++) |
1768 | 0 | if (pline->filter[idx].id == filter) { |
1769 | 0 | found = true; |
1770 | 0 | break; |
1771 | 0 | } |
1772 | | |
1773 | | /* filter was not found in the pipeline */ |
1774 | 0 | if (!found) |
1775 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_NOTFOUND, FAIL, "filter not in pipeline"); |
1776 | | |
1777 | | /* Free information for deleted filter */ |
1778 | 0 | if (pline->filter[idx].name && pline->filter[idx].name != pline->filter[idx]._name) |
1779 | 0 | assert((strlen(pline->filter[idx].name) + 1) > H5Z_COMMON_NAME_LEN); |
1780 | 0 | if (pline->filter[idx].name != pline->filter[idx]._name) |
1781 | 0 | pline->filter[idx].name = (char *)H5MM_xfree(pline->filter[idx].name); |
1782 | 0 | if (pline->filter[idx].cd_values && pline->filter[idx].cd_values != pline->filter[idx]._cd_values) |
1783 | 0 | assert(pline->filter[idx].cd_nelmts > H5Z_COMMON_CD_VALUES); |
1784 | 0 | if (pline->filter[idx].cd_values != pline->filter[idx]._cd_values) |
1785 | 0 | pline->filter[idx].cd_values = (unsigned *)H5MM_xfree(pline->filter[idx].cd_values); |
1786 | | |
1787 | | /* Remove filter from pipeline array */ |
1788 | 0 | if ((idx + 1) < pline->nused) { |
1789 | | /* Copy filters down & fix up any client data value arrays using internal storage */ |
1790 | 0 | for (; (idx + 1) < pline->nused; idx++) { |
1791 | 0 | pline->filter[idx] = pline->filter[idx + 1]; |
1792 | 0 | if (pline->filter[idx].name && (strlen(pline->filter[idx].name) + 1) <= H5Z_COMMON_NAME_LEN) |
1793 | 0 | pline->filter[idx].name = pline->filter[idx]._name; |
1794 | 0 | if (pline->filter[idx].cd_nelmts <= H5Z_COMMON_CD_VALUES) |
1795 | 0 | pline->filter[idx].cd_values = pline->filter[idx]._cd_values; |
1796 | 0 | } |
1797 | 0 | } |
1798 | | |
1799 | | /* Decrement number of used filters */ |
1800 | 0 | pline->nused--; |
1801 | | |
1802 | | /* Reset information for previous last filter in pipeline */ |
1803 | 0 | memset(&pline->filter[pline->nused], 0, sizeof(H5Z_filter_info_t)); |
1804 | 0 | } /* end else */ |
1805 | | |
1806 | 0 | done: |
1807 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1808 | 0 | } /* end H5Z_delete() */ |
1809 | | |
1810 | | /*------------------------------------------------------------------------- |
1811 | | * Function: H5Zget_filter_info |
1812 | | * |
1813 | | * Purpose: Gets information about a pipeline data filter and stores it |
1814 | | * in filter_config_flags. |
1815 | | * |
1816 | | * Return: zero on success |
1817 | | * negative on failure |
1818 | | *------------------------------------------------------------------------- |
1819 | | */ |
1820 | | herr_t |
1821 | | H5Zget_filter_info(H5Z_filter_t filter, unsigned *filter_config_flags /*out*/) |
1822 | 0 | { |
1823 | 0 | herr_t ret_value = SUCCEED; |
1824 | |
|
1825 | 0 | FUNC_ENTER_API(FAIL) |
1826 | | |
1827 | | /* Get the filter info */ |
1828 | 0 | if (H5Z_get_filter_info(filter, filter_config_flags) < 0) |
1829 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "Filter info not retrieved"); |
1830 | | |
1831 | 0 | done: |
1832 | 0 | FUNC_LEAVE_API(ret_value) |
1833 | 0 | } /* end H5Zget_filter_info() */ |
1834 | | |
1835 | | /*------------------------------------------------------------------------- |
1836 | | * Function: H5Z_get_filter_info |
1837 | | * |
1838 | | * Purpose: Gets information about a pipeline data filter and stores it |
1839 | | * in filter_config_flags. |
1840 | | * |
1841 | | * Return: zero on success |
1842 | | * negative on failure |
1843 | | *------------------------------------------------------------------------- |
1844 | | */ |
1845 | | herr_t |
1846 | | H5Z_get_filter_info(H5Z_filter_t filter, unsigned int *filter_config_flags) |
1847 | 0 | { |
1848 | 0 | H5Z_class2_t *fclass = NULL; |
1849 | 0 | herr_t ret_value = SUCCEED; |
1850 | |
|
1851 | 0 | FUNC_ENTER_NOAPI(FAIL) |
1852 | | |
1853 | | /* Look up the filter class info */ |
1854 | 0 | if (H5Z_find(false, filter, &fclass) < 0) |
1855 | 0 | HGOTO_ERROR(H5E_PLINE, H5E_BADVALUE, FAIL, "Filter not defined"); |
1856 | | |
1857 | | /* Set the filter config flags for the application */ |
1858 | 0 | if (filter_config_flags != NULL) { |
1859 | 0 | *filter_config_flags = 0; |
1860 | |
|
1861 | 0 | if (fclass->encoder_present) |
1862 | 0 | *filter_config_flags |= H5Z_FILTER_CONFIG_ENCODE_ENABLED; |
1863 | 0 | if (fclass->decoder_present) |
1864 | 0 | *filter_config_flags |= H5Z_FILTER_CONFIG_DECODE_ENABLED; |
1865 | 0 | } /* end if */ |
1866 | |
|
1867 | 0 | done: |
1868 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1869 | 0 | } /* end H5Z_get_filter_info() */ |