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 COPYING file, which can be found at the root of the source code *
8 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
9 * If you do not have access to either file, you may request a copy from *
10 * help@hdfgroup.org. *
11 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12 /*
13 * Purpose: Tests the plugin module (H5PL)
14 */
15
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include "H5PLextern.h"
19
20 #define H5Z_FILTER_DYNLIBUD 300
21 #define MULTIPLIER 3
22
23 static size_t H5Z_filter_dynlibud(unsigned int flags, size_t cd_nelmts,
24 const unsigned int *cd_values, size_t nbytes, size_t *buf_size, void **buf);
25
26 /* This message derives from H5Z */
27 const H5Z_class2_t H5Z_DYNLIBUD[1] = {{
28 H5Z_CLASS_T_VERS, /* H5Z_class_t version */
29 H5Z_FILTER_DYNLIBUD, /* Filter id number */
30 1, 1, /* Encoding and decoding enabled */
31 "dynlibud", /* Filter name for debugging */
32 NULL, /* The "can apply" callback */
33 NULL, /* The "set local" callback */
34 (H5Z_func_t)H5Z_filter_dynlibud, /* The actual filter function */
35 }};
36
H5PLget_plugin_type(void)37 H5PL_type_t H5PLget_plugin_type(void) {return H5PL_TYPE_FILTER;}
H5PLget_plugin_info(void)38 const void *H5PLget_plugin_info(void) {return H5Z_DYNLIBUD;}
39
40 /*-------------------------------------------------------------------------
41 * Function: H5Z_filter_dynlibud
42 *
43 * Purpose: A dynlib2 filter method that multiplies the original value
44 * during write and divide the original value during read. It
45 * will be built as a shared library. plugin.c test will load
46 * and use this filter library.
47 *
48 * Return: Success: Data chunk size
49 *
50 * Failure: 0
51 *-------------------------------------------------------------------------
52 */
53 static size_t
H5Z_filter_dynlibud(unsigned int flags,size_t cd_nelmts,const unsigned int * cd_values,size_t nbytes,size_t * buf_size,void ** buf)54 H5Z_filter_dynlibud(unsigned int flags, size_t cd_nelmts,
55 const unsigned int *cd_values, size_t nbytes,
56 size_t *buf_size, void **buf)
57 {
58 char *int_ptr = (char *)*buf; /* Pointer to the data values */
59 size_t buf_left = *buf_size; /* Amount of data buffer left to process */
60
61 /* Check for the correct number of parameters */
62 if(cd_nelmts > 0)
63 return(0);
64
65 /* Assignment to eliminate unused parameter warning. */
66 cd_values = cd_values;
67
68 if(flags & H5Z_FLAG_REVERSE) { /*read*/
69 /* Subtract the original value with MULTIPLIER */
70 while(buf_left > 0) {
71 char temp = *int_ptr;
72 *int_ptr = temp - MULTIPLIER;
73 int_ptr++;
74 buf_left -= sizeof(*int_ptr);
75 } /* end while */
76 } /* end if */
77 else { /*write*/
78 /* Add the original value with MULTIPLIER */
79 while(buf_left > 0) {
80 char temp = *int_ptr;
81 *int_ptr = temp + MULTIPLIER;
82 int_ptr++;
83 buf_left -= sizeof(*int_ptr);
84 } /* end while */
85 } /* end else */
86
87 return nbytes;
88 } /* end H5Z_filter_dynlibud() */
89
90