1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group. *
3 * Copyright by the Board of Trustees of the University of Illinois. *
4 * All rights reserved. *
5 * *
6 * This file is part of HDF5. The full HDF5 copyright notice, including *
7 * terms governing use, modification, and redistribution, is contained in *
8 * the COPYING file, which can be found at the root of the source code *
9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
10 * If you do not have access to either file, you may request a copy from *
11 * help@hdfgroup.org. *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14
15 /* Programmer: James Laird <jlaird@hdfgroup.org>
16 * Monday, January 29, 2007
17 *
18 * Purpose: A message holding "implicitly shared object header message"
19 * information in the superblock extension.
20 */
21
22 #include "H5Omodule.h" /* This source code file is part of the H5O module */
23
24
25 #include "H5private.h" /* Generic Functions */
26 #include "H5Eprivate.h" /* Error handling */
27 #include "H5Opkg.h" /* Object headers */
28 #include "H5MMprivate.h" /* Memory management */
29
30 static void *H5O__shmesg_decode(H5F_t *f, H5O_t *open_oh, unsigned mesg_flags,
31 unsigned *ioflags, size_t p_size, const uint8_t *p);
32 static herr_t H5O_shmesg_encode(H5F_t *f, hbool_t disable_shared, uint8_t *p, const void *_mesg);
33 static void *H5O_shmesg_copy(const void *_mesg, void *_dest);
34 static size_t H5O_shmesg_size(const H5F_t *f, hbool_t disable_shared, const void *_mesg);
35 static herr_t H5O__shmesg_debug(H5F_t *f, const void *_mesg, FILE *stream,
36 int indent, int fwidth);
37
38 /* This message derives from H5O message class */
39 const H5O_msg_class_t H5O_MSG_SHMESG[1] = {{
40 H5O_SHMESG_ID, /*message id number */
41 "shared message table", /*message name for debugging */
42 sizeof(H5O_shmesg_table_t), /*native message size */
43 0, /* messages are sharable? */
44 H5O__shmesg_decode, /*decode message */
45 H5O_shmesg_encode, /*encode message */
46 H5O_shmesg_copy, /*copy the native value */
47 H5O_shmesg_size, /*raw message size */
48 NULL, /*free internal memory */
49 NULL, /* free method */
50 NULL, /* file delete method */
51 NULL, /* link method */
52 NULL, /* set share method */
53 NULL, /*can share method */
54 NULL, /* pre copy native value to file */
55 NULL, /* copy native value to file */
56 NULL, /* post copy native value to file */
57 NULL, /* get creation index */
58 NULL, /* set creation index */
59 H5O__shmesg_debug /*debug the message */
60 }};
61
62
63 /*-------------------------------------------------------------------------
64 * Function: H5O__shmesg_decode
65 *
66 * Purpose: Decode a shared message table message and return a pointer
67 * to a newly allocated H5O_shmesg_table_t struct.
68 *
69 * Return: Success: Ptr to new message in native struct.
70 * Failure: NULL
71 *
72 * Programmer: James Laird
73 * Jan 29, 2007
74 *
75 *-------------------------------------------------------------------------
76 */
77 static void *
H5O__shmesg_decode(H5F_t * f,H5O_t H5_ATTR_UNUSED * open_oh,unsigned H5_ATTR_UNUSED mesg_flags,unsigned H5_ATTR_UNUSED * ioflags,size_t H5_ATTR_UNUSED p_size,const uint8_t * p)78 H5O__shmesg_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh,
79 unsigned H5_ATTR_UNUSED mesg_flags, unsigned H5_ATTR_UNUSED *ioflags,
80 size_t H5_ATTR_UNUSED p_size, const uint8_t *p)
81 {
82 H5O_shmesg_table_t *mesg; /* Native message */
83 void *ret_value = NULL; /* Return value */
84
85 FUNC_ENTER_STATIC
86
87 /* Sanity check */
88 HDassert(f);
89 HDassert(p);
90
91 if(NULL == (mesg = (H5O_shmesg_table_t *)H5MM_calloc(sizeof(H5O_shmesg_table_t))))
92 HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for shared message table message")
93
94 /* Retrieve version, table address, and number of indexes */
95 mesg->version = *p++;
96 H5F_addr_decode(f, &p, &(mesg->addr));
97 mesg->nindexes = *p++;
98
99 /* Set return value */
100 ret_value = (void *)mesg;
101
102 done:
103 FUNC_LEAVE_NOAPI(ret_value)
104 } /* end H5O__shmesg_decode() */
105
106
107 /*-------------------------------------------------------------------------
108 * Function: H5O_shmesg_encode
109 *
110 * Purpose: Encode a shared message table message.
111 *
112 * Return: Non-negative on success/Negative on failure
113 *
114 * Programmer: James Laird
115 * Jan 29, 2007
116 *
117 *-------------------------------------------------------------------------
118 */
119 static herr_t
H5O_shmesg_encode(H5F_t * f,hbool_t H5_ATTR_UNUSED disable_shared,uint8_t * p,const void * _mesg)120 H5O_shmesg_encode(H5F_t *f, hbool_t H5_ATTR_UNUSED disable_shared, uint8_t *p, const void *_mesg)
121 {
122 const H5O_shmesg_table_t *mesg = (const H5O_shmesg_table_t *)_mesg;
123
124 FUNC_ENTER_NOAPI_NOINIT_NOERR
125
126 /* Sanity check */
127 HDassert(f);
128 HDassert(p);
129 HDassert(mesg);
130
131 /* Store version, table address, and number of indexes */
132 *p++ = (uint8_t)mesg->version;
133 H5F_addr_encode(f, &p, mesg->addr);
134 *p++ = (uint8_t)mesg->nindexes;
135
136 FUNC_LEAVE_NOAPI(SUCCEED)
137 } /* end H5O_shmesg_encode() */
138
139
140 /*-------------------------------------------------------------------------
141 * Function: H5O_shmesg_copy
142 *
143 * Purpose: Copies a message from _MESG to _DEST, allocating _DEST if
144 * necessary.
145 *
146 * Return: Success: Ptr to _DEST
147 * Failure: NULL
148 *
149 * Programmer: James Laird
150 * Jan 29, 2007
151 *
152 *-------------------------------------------------------------------------
153 */
154 static void *
H5O_shmesg_copy(const void * _mesg,void * _dest)155 H5O_shmesg_copy(const void *_mesg, void *_dest)
156 {
157 const H5O_shmesg_table_t *mesg = (const H5O_shmesg_table_t *)_mesg;
158 H5O_shmesg_table_t *dest = (H5O_shmesg_table_t *)_dest;
159 void *ret_value = NULL; /* Return value */
160
161 FUNC_ENTER_NOAPI_NOINIT
162
163 /* Sanity check */
164 HDassert(mesg);
165
166 if(!dest && NULL == (dest = (H5O_shmesg_table_t *)H5MM_malloc(sizeof(H5O_shmesg_table_t))))
167 HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for shared message table message")
168
169 /* All this message requires is a shallow copy */
170 *dest = *mesg;
171
172 /* Set return value */
173 ret_value = dest;
174
175 done:
176 FUNC_LEAVE_NOAPI(ret_value)
177 } /* end H5O_shmesg_copy() */
178
179
180 /*-------------------------------------------------------------------------
181 * Function: H5O_shmesg_size
182 *
183 * Purpose: Returns the size of the raw message in bytes not counting the
184 * message type or size fields, but only the data fields.
185 *
186 * Return: Success: Message data size in bytes w/o alignment.
187 * Failure: 0
188 *
189 * Programmer: James Laird
190 * Jan 29, 2007
191 *
192 *-------------------------------------------------------------------------
193 */
194 static size_t
H5O_shmesg_size(const H5F_t * f,hbool_t H5_ATTR_UNUSED disable_shared,const void H5_ATTR_UNUSED * _mesg)195 H5O_shmesg_size(const H5F_t *f, hbool_t H5_ATTR_UNUSED disable_shared, const void H5_ATTR_UNUSED *_mesg)
196 {
197 size_t ret_value = 0; /* Return value */
198
199 FUNC_ENTER_NOAPI_NOINIT_NOERR
200
201 /* Sanity check */
202 HDassert(f);
203
204 ret_value = (size_t)(1 + /* Version number */
205 H5F_SIZEOF_ADDR(f) + /* Table address */
206 1); /* Number of indexes */
207
208 FUNC_LEAVE_NOAPI(ret_value)
209 } /* end H5O_shmesg_size() */
210
211
212 /*-------------------------------------------------------------------------
213 * Function: H5O__shmesg_debug
214 *
215 * Purpose: Prints debugging info for the message.
216 *
217 * Return: Non-negative on success/Negative on failure
218 *
219 * Programmer: James Laird
220 * Jan 29, 2007
221 *
222 *-------------------------------------------------------------------------
223 */
224 static herr_t
H5O__shmesg_debug(H5F_t H5_ATTR_UNUSED * f,const void * _mesg,FILE * stream,int indent,int fwidth)225 H5O__shmesg_debug(H5F_t H5_ATTR_UNUSED *f, const void *_mesg, FILE *stream,
226 int indent, int fwidth)
227 {
228 const H5O_shmesg_table_t *mesg = (const H5O_shmesg_table_t *)_mesg;
229
230 FUNC_ENTER_STATIC_NOERR
231
232 /* Sanity check */
233 HDassert(f);
234 HDassert(mesg);
235 HDassert(stream);
236 HDassert(indent >= 0);
237 HDassert(fwidth >= 0);
238
239 HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
240 "Version:", mesg->version);
241 HDfprintf(stream, "%*s%-*s %a (rel)\n", indent, "", fwidth,
242 "Shared message table address:", mesg->addr);
243 HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
244 "Number of indexes:", mesg->nindexes);
245
246 FUNC_LEAVE_NOAPI(SUCCEED)
247 } /* end H5O__shmesg_debug() */
248
249