/src/hdf5/src/H5VLnative_blob.c
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 | | /* |
14 | | * Purpose: Blob callbacks for the native VOL connector |
15 | | */ |
16 | | |
17 | | /***********/ |
18 | | /* Headers */ |
19 | | /***********/ |
20 | | #include "H5private.h" /* Generic Functions */ |
21 | | #include "H5Eprivate.h" /* Error handling */ |
22 | | #include "H5Fprivate.h" /* File access */ |
23 | | #include "H5HGprivate.h" /* Global Heaps */ |
24 | | #include "H5VLnative_private.h" /* Native VOL connector */ |
25 | | |
26 | | /****************/ |
27 | | /* Local Macros */ |
28 | | /****************/ |
29 | | |
30 | | /******************/ |
31 | | /* Local Typedefs */ |
32 | | /******************/ |
33 | | |
34 | | /********************/ |
35 | | /* Local Prototypes */ |
36 | | /********************/ |
37 | | |
38 | | /*********************/ |
39 | | /* Package Variables */ |
40 | | /*********************/ |
41 | | |
42 | | /*****************************/ |
43 | | /* Library Private Variables */ |
44 | | /*****************************/ |
45 | | |
46 | | /*******************/ |
47 | | /* Local Variables */ |
48 | | /*******************/ |
49 | | |
50 | | /*------------------------------------------------------------------------- |
51 | | * Function: H5VL__native_blob_put |
52 | | * |
53 | | * Purpose: Handles the blob 'put' callback |
54 | | * |
55 | | * Return: SUCCEED / FAIL |
56 | | * |
57 | | *------------------------------------------------------------------------- |
58 | | */ |
59 | | herr_t |
60 | | H5VL__native_blob_put(void *obj, const void *buf, size_t size, void *blob_id, void H5_ATTR_UNUSED *ctx) |
61 | 0 | { |
62 | 0 | H5F_t *f = (H5F_t *)obj; /* Retrieve file pointer */ |
63 | 0 | uint8_t *id = (uint8_t *)blob_id; /* Pointer to blob ID */ |
64 | 0 | H5HG_t hobjid; /* New VL sequence's heap ID */ |
65 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
66 | |
|
67 | 0 | FUNC_ENTER_PACKAGE |
68 | | |
69 | | /* Check parameters */ |
70 | 0 | assert(f); |
71 | 0 | assert(size == 0 || buf); |
72 | 0 | assert(id); |
73 | | |
74 | | /* Write the VL information to disk (allocates space also) */ |
75 | 0 | if (H5HG_insert(f, size, buf, &hobjid) < 0) |
76 | 0 | HGOTO_ERROR(H5E_VOL, H5E_WRITEERROR, FAIL, "unable to write blob information"); |
77 | | |
78 | | /* Encode the heap information */ |
79 | 0 | H5F_addr_encode(f, &id, hobjid.addr); |
80 | 0 | UINT32ENCODE(id, hobjid.idx); |
81 | |
|
82 | 0 | done: |
83 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
84 | 0 | } /* end H5VL__native_blob_put() */ |
85 | | |
86 | | /*------------------------------------------------------------------------- |
87 | | * Function: H5VL__native_blob_get |
88 | | * |
89 | | * Purpose: Handles the blob 'get' callback |
90 | | * |
91 | | * Return: SUCCEED / FAIL |
92 | | * |
93 | | *------------------------------------------------------------------------- |
94 | | */ |
95 | | herr_t |
96 | | H5VL__native_blob_get(void *obj, const void *blob_id, void *buf, size_t size, void H5_ATTR_UNUSED *ctx) |
97 | 3.04k | { |
98 | 3.04k | H5F_t *f = (H5F_t *)obj; /* Retrieve file pointer */ |
99 | 3.04k | const uint8_t *id = (const uint8_t *)blob_id; /* Pointer to the disk blob ID */ |
100 | 3.04k | H5HG_t hobjid; /* Global heap ID for sequence */ |
101 | 3.04k | size_t hobj_size = 0; /* Global heap object size returned from H5HG_read() */ |
102 | 3.04k | herr_t ret_value = SUCCEED; /* Return value */ |
103 | | |
104 | 3.04k | FUNC_ENTER_PACKAGE |
105 | | |
106 | | /* Sanity check */ |
107 | 3.04k | assert(f); |
108 | 3.04k | assert(id); |
109 | 3.04k | assert(buf); |
110 | | |
111 | | /* Get the heap information */ |
112 | 3.04k | H5F_addr_decode(f, &id, &hobjid.addr); |
113 | 3.04k | UINT32DECODE(id, hobjid.idx); |
114 | | |
115 | | /* Check if this sequence actually has any data */ |
116 | 3.04k | if (hobjid.addr > 0) { |
117 | | /* Verify the size is correct */ |
118 | 3.04k | if (H5HG_get_obj_size(f, &hobjid, &hobj_size) < 0) |
119 | 108 | HGOTO_ERROR(H5E_VOL, H5E_CANTGETSIZE, FAIL, "can't get object size"); |
120 | 2.93k | if (hobj_size != size) |
121 | 5 | HGOTO_ERROR(H5E_VOL, H5E_BADSIZE, FAIL, "Expected global heap object size does not match"); |
122 | | |
123 | | /* Read the VL information from disk */ |
124 | 2.92k | if (NULL == H5HG_read(f, &hobjid, buf, &hobj_size)) |
125 | 0 | HGOTO_ERROR(H5E_VOL, H5E_READERROR, FAIL, "unable to read VL information"); |
126 | 2.92k | } |
127 | | |
128 | 3.04k | done: |
129 | 3.04k | FUNC_LEAVE_NOAPI(ret_value) |
130 | 3.04k | } /* end H5VL__native_blob_get() */ |
131 | | |
132 | | /*------------------------------------------------------------------------- |
133 | | * Function: H5VL__native_blob_specific |
134 | | * |
135 | | * Purpose: Handles the blob 'specific' callback |
136 | | * |
137 | | * Return: SUCCEED / FAIL |
138 | | * |
139 | | *------------------------------------------------------------------------- |
140 | | */ |
141 | | herr_t |
142 | | H5VL__native_blob_specific(void *obj, void *blob_id, H5VL_blob_specific_args_t *args) |
143 | 3.04k | { |
144 | 3.04k | H5F_t *f = (H5F_t *)obj; /* Retrieve file pointer */ |
145 | 3.04k | herr_t ret_value = SUCCEED; /* Return value */ |
146 | | |
147 | 3.04k | FUNC_ENTER_PACKAGE |
148 | | |
149 | | /* Sanity check */ |
150 | 3.04k | assert(f); |
151 | 3.04k | assert(blob_id); |
152 | | |
153 | 3.04k | switch (args->op_type) { |
154 | 3.04k | case H5VL_BLOB_ISNULL: { |
155 | 3.04k | const uint8_t *id = (const uint8_t *)blob_id; /* Pointer to the blob ID */ |
156 | 3.04k | haddr_t addr; /* Sequence's heap address */ |
157 | | |
158 | | /* Get the heap address */ |
159 | 3.04k | H5F_addr_decode(f, &id, &addr); |
160 | | |
161 | | /* Check if heap address is 'nil' */ |
162 | 3.04k | *args->args.is_null.isnull = (addr == 0 ? true : false); |
163 | | |
164 | 3.04k | break; |
165 | 0 | } |
166 | | |
167 | 0 | case H5VL_BLOB_SETNULL: { |
168 | 0 | uint8_t *id = (uint8_t *)blob_id; /* Pointer to the blob ID */ |
169 | | |
170 | | /* Encode the 'nil' heap pointer information */ |
171 | 0 | H5F_addr_encode(f, &id, (haddr_t)0); |
172 | 0 | UINT32ENCODE(id, 0); |
173 | |
|
174 | 0 | break; |
175 | 0 | } |
176 | | |
177 | 0 | case H5VL_BLOB_DELETE: { |
178 | 0 | const uint8_t *id = (const uint8_t *)blob_id; /* Pointer to the blob ID */ |
179 | 0 | H5HG_t hobjid; /* VL sequence's heap ID */ |
180 | | |
181 | | /* Get heap information */ |
182 | 0 | H5F_addr_decode(f, &id, &hobjid.addr); |
183 | 0 | UINT32DECODE(id, hobjid.idx); |
184 | | |
185 | | /* Free heap object */ |
186 | 0 | if (hobjid.addr > 0) |
187 | 0 | if (H5HG_remove(f, &hobjid) < 0) |
188 | 0 | HGOTO_ERROR(H5E_VOL, H5E_CANTREMOVE, FAIL, "unable to remove heap object"); |
189 | | |
190 | 0 | break; |
191 | 0 | } |
192 | | |
193 | 0 | default: |
194 | 0 | HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "invalid specific operation"); |
195 | 3.04k | } /* end switch */ |
196 | | |
197 | 3.04k | done: |
198 | 3.04k | FUNC_LEAVE_NOAPI(ret_value) |
199 | 3.04k | } /* end H5VL__native_blob_specific() */ |