1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group. *
3 * Copyright by the Board of Trustees of the University of Illinois. *
4 * All rights reserved. *
5 * *
6 * This file is part of HDF5. The full HDF5 copyright notice, including *
7 * terms governing use, modification, and redistribution, is contained in *
8 * the COPYING file, which can be found at the root of the source code *
9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
10 * If you do not have access to either file, you may request a copy from *
11 * help@hdfgroup.org. *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14 /*-------------------------------------------------------------------------
15 *
16 * Created: H5Obogus.c
17 * Jan 21 2003
18 * Quincey Koziol <koziol@ncsa.uiuc.edu>
19 *
20 * Purpose: "bogus" message. This message is guaranteed to never
21 * be found in a valid HDF5 file and is only used to
22 * generate a test file which verifies the library's
23 * correct operation when parsing unknown object header
24 * messages.
25 *
26 *-------------------------------------------------------------------------
27 */
28
29 #include "H5Omodule.h" /* This source code file is part of the H5O module */
30
31
32 #include "H5private.h" /* Generic Functions */
33 #include "H5Eprivate.h" /* Error handling */
34 #include "H5MMprivate.h" /* Memory management */
35 #include "H5Opkg.h" /* Object headers */
36
37 #ifdef H5O_ENABLE_BOGUS
38
39 /* PRIVATE PROTOTYPES */
40 static void *H5O_bogus_decode(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh,
41 unsigned mesg_flags, unsigned *ioflags, const uint8_t *p);
42 static herr_t H5O_bogus_encode(H5F_t *f, hbool_t disable_shared, uint8_t *p, const void *_mesg);
43 static size_t H5O_bogus_size(const H5F_t *f, hbool_t disable_shared, const void *_mesg);
44 static herr_t H5O_bogus_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream,
45 int indent, int fwidth);
46
47 /* This message derives from H5O message class */
48 const H5O_msg_class_t H5O_MSG_BOGUS_VALID[1] = {{
49 H5O_BOGUS_VALID_ID, /*message id number */
50 "bogus valid", /*message name for debugging */
51 0, /*native message size */
52 0, /* messages are sharable? */
53 H5O_bogus_decode, /*decode message */
54 H5O_bogus_encode, /*encode message */
55 NULL, /*copy the native value */
56 H5O_bogus_size, /*raw message size */
57 NULL, /*free internal memory */
58 NULL, /*free method */
59 NULL, /* file delete method */
60 NULL, /* link method */
61 NULL, /*set share method */
62 NULL, /*can share method */
63 NULL, /* pre copy native value to file */
64 NULL, /* copy native value to file */
65 NULL, /* post copy native value to file */
66 NULL, /* get creation index */
67 NULL, /* set creation index */
68 H5O_bogus_debug /*debug the message */
69 }};
70
71 /* This message derives from H5O message class */
72 const H5O_msg_class_t H5O_MSG_BOGUS_INVALID[1] = {{
73 H5O_BOGUS_INVALID_ID, /*message id number */
74 "bogus invalid", /*message name for debugging */
75 0, /*native message size */
76 0, /* messages are sharable? */
77 H5O_bogus_decode, /*decode message */
78 H5O_bogus_encode, /*encode message */
79 NULL, /*copy the native value */
80 H5O_bogus_size, /*raw message size */
81 NULL, /*free internal memory */
82 NULL, /*free method */
83 NULL, /* file delete method */
84 NULL, /* link method */
85 NULL, /*set share method */
86 NULL, /*can share method */
87 NULL, /* pre copy native value to file */
88 NULL, /* copy native value to file */
89 NULL, /* post copy native value to file */
90 NULL, /* get creation index */
91 NULL, /* set creation index */
92 H5O_bogus_debug /*debug the message */
93 }};
94
95
96 /*-------------------------------------------------------------------------
97 * Function: H5O_bogus_decode
98 *
99 * Purpose: Decode a "bogus" message and return a pointer to a new
100 * native message struct.
101 *
102 * Return: Success: Ptr to new message in native struct.
103 *
104 * Failure: NULL
105 *
106 * Programmer: Quincey Koziol
107 * koziol@ncsa.uiuc.edu
108 * Jan 21 2003
109 *
110 *-------------------------------------------------------------------------
111 */
112 static void *
H5O_bogus_decode(H5F_t * 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,const uint8_t * p)113 H5O_bogus_decode(H5F_t *f, hid_t H5_ATTR_UNUSED dxpl_id, H5O_t H5_ATTR_UNUSED *open_oh,
114 unsigned H5_ATTR_UNUSED mesg_flags, unsigned H5_ATTR_UNUSED *ioflags, const uint8_t *p)
115 {
116 H5O_bogus_t *mesg = NULL;
117 void *ret_value; /* Return value */
118
119 FUNC_ENTER_NOAPI_NOINIT
120
121 /* check args */
122 HDassert(f);
123 HDassert(p);
124
125 /* Allocate the bogus message */
126 if(NULL == (mesg = (H5O_bogus_t *)H5MM_calloc(sizeof(H5O_bogus_t))))
127 HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
128
129 /* decode */
130 UINT32DECODE(p, mesg->u);
131
132 /* Validate the bogus info */
133 if(mesg->u != H5O_BOGUS_VALUE)
134 HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, NULL, "invalid bogus value :-)")
135
136 /* Set return value */
137 ret_value = mesg;
138
139 done:
140 if(ret_value == NULL && mesg != NULL)
141 H5MM_xfree(mesg);
142
143 FUNC_LEAVE_NOAPI(ret_value)
144 } /* end H5O_bogus_decode() */
145
146
147 /*-------------------------------------------------------------------------
148 * Function: H5O_bogus_encode
149 *
150 * Purpose: Encodes a "bogus" message.
151 *
152 * Return: Non-negative on success/Negative on failure
153 *
154 * Programmer: Quincey Koziol
155 * koziol@ncsa.uiuc.edu
156 * Jan 21 2003
157 *
158 *-------------------------------------------------------------------------
159 */
160 static herr_t
H5O_bogus_encode(H5F_t H5_ATTR_UNUSED * f,hbool_t H5_ATTR_UNUSED disable_shared,uint8_t * p,const void H5_ATTR_UNUSED * mesg)161 H5O_bogus_encode(H5F_t H5_ATTR_UNUSED *f, hbool_t H5_ATTR_UNUSED disable_shared, uint8_t *p, const void H5_ATTR_UNUSED *mesg)
162 {
163 FUNC_ENTER_NOAPI_NOINIT_NOERR
164
165 /* check args */
166 HDassert(f);
167 HDassert(p);
168 HDassert(mesg);
169
170 /* encode */
171 UINT32ENCODE(p, H5O_BOGUS_VALUE);
172
173 FUNC_LEAVE_NOAPI(SUCCEED)
174 } /* end H5O_bogus_encode() */
175
176
177 /*-------------------------------------------------------------------------
178 * Function: H5O_bogus_size
179 *
180 * Purpose: Returns the size of the raw message in bytes not
181 * counting the message typ or size fields, but only the data
182 * fields. This function doesn't take into account
183 * alignment.
184 *
185 * Return: Success: Message data size in bytes w/o alignment.
186 *
187 * Failure: Negative
188 *
189 * Programmer: Quincey Koziol
190 * koziol@ncsa.uiuc.edu
191 * Jan 21 2003
192 *
193 *-------------------------------------------------------------------------
194 */
195 static size_t
H5O_bogus_size(const H5F_t H5_ATTR_UNUSED * f,hbool_t H5_ATTR_UNUSED disable_shared,const void H5_ATTR_UNUSED * mesg)196 H5O_bogus_size(const H5F_t H5_ATTR_UNUSED *f, hbool_t H5_ATTR_UNUSED disable_shared, const void H5_ATTR_UNUSED *mesg)
197 {
198 FUNC_ENTER_NOAPI_NOINIT_NOERR
199
200 FUNC_LEAVE_NOAPI(4)
201 } /* end H5O_bogus_size() */
202
203
204 /*-------------------------------------------------------------------------
205 * Function: H5O_bogus_debug
206 *
207 * Purpose: Prints debugging info for the message.
208 *
209 * Return: Non-negative on success/Negative on failure
210 *
211 * Programmer: Quincey Koziol
212 * koziol@ncsa.uiuc.edu
213 * Jan 21 2003
214 *
215 * Modifications:
216 *
217 *-------------------------------------------------------------------------
218 */
219 static herr_t
H5O_bogus_debug(H5F_t H5_ATTR_UNUSED * f,hid_t H5_ATTR_UNUSED dxpl_id,const void * _mesg,FILE * stream,int indent,int fwidth)220 H5O_bogus_debug(H5F_t H5_ATTR_UNUSED *f, hid_t H5_ATTR_UNUSED dxpl_id, const void *_mesg, FILE *stream,
221 int indent, int fwidth)
222 {
223 const H5O_bogus_t *mesg = (const H5O_bogus_t *)_mesg;
224
225 FUNC_ENTER_NOAPI_NOINIT_NOERR
226
227 /* check args */
228 HDassert(f);
229 HDassert(mesg);
230 HDassert(stream);
231 HDassert(indent >= 0);
232 HDassert(fwidth >= 0);
233
234 HDfprintf(stream, "%*s%-*s `%u'\n", indent, "", fwidth,
235 "Bogus Value:", mesg->u);
236
237 FUNC_LEAVE_NOAPI(SUCCEED)
238 } /* end H5O_bogus_debug() */
239 #endif /* H5O_ENABLE_BOGUS */
240
241