1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
use std::mem;

pub use self::H5O_mcdt_search_ret_t::*;
pub use self::H5O_type_t::*;

use crate::internal_prelude::*;

pub const H5O_COPY_SHALLOW_HIERARCHY_FLAG: c_uint = 0x0001;
pub const H5O_COPY_EXPAND_SOFT_LINK_FLAG: c_uint = 0x0002;
pub const H5O_COPY_EXPAND_EXT_LINK_FLAG: c_uint = 0x0004;
pub const H5O_COPY_EXPAND_REFERENCE_FLAG: c_uint = 0x0008;
pub const H5O_COPY_WITHOUT_ATTR_FLAG: c_uint = 0x0010;
pub const H5O_COPY_PRESERVE_NULL_FLAG: c_uint = 0x0020;
#[cfg(not(hdf5_1_8_9))]
pub const H5O_COPY_ALL: c_uint = 0x003F;
#[cfg(hdf5_1_8_9)]
pub const H5O_COPY_MERGE_COMMITTED_DTYPE_FLAG: c_uint = 0x0040;
#[cfg(hdf5_1_8_9)]
pub const H5O_COPY_ALL: c_uint = 0x007F;

pub const H5O_SHMESG_NONE_FLAG: c_uint = 0x0000;
pub const H5O_SHMESG_SDSPACE_FLAG: c_uint = 1 << 0x0001;
pub const H5O_SHMESG_DTYPE_FLAG: c_uint = 1 << 0x0003;
pub const H5O_SHMESG_FILL_FLAG: c_uint = 1 << 0x0005;
pub const H5O_SHMESG_PLINE_FLAG: c_uint = 1 << 0x000b;
pub const H5O_SHMESG_ATTR_FLAG: c_uint = 1 << 0x000c;
pub const H5O_SHMESG_ALL_FLAG: c_uint = H5O_SHMESG_SDSPACE_FLAG
    | H5O_SHMESG_DTYPE_FLAG
    | H5O_SHMESG_FILL_FLAG
    | H5O_SHMESG_PLINE_FLAG
    | H5O_SHMESG_ATTR_FLAG;

pub const H5O_HDR_CHUNK0_SIZE: c_uint = 0x03;
pub const H5O_HDR_ATTR_CRT_ORDER_TRACKED: c_uint = 0x04;
pub const H5O_HDR_ATTR_CRT_ORDER_INDEXED: c_uint = 0x08;
pub const H5O_HDR_ATTR_STORE_PHASE_CHANGE: c_uint = 0x10;
pub const H5O_HDR_STORE_TIMES: c_uint = 0x20;
pub const H5O_HDR_ALL_FLAGS: c_uint = H5O_HDR_CHUNK0_SIZE
    | H5O_HDR_ATTR_CRT_ORDER_TRACKED
    | H5O_HDR_ATTR_CRT_ORDER_INDEXED
    | H5O_HDR_ATTR_STORE_PHASE_CHANGE
    | H5O_HDR_STORE_TIMES;

pub const H5O_SHMESG_MAX_NINDEXES: c_uint = 8;
pub const H5O_SHMESG_MAX_LIST_SIZE: c_uint = 5000;

#[cfg(hdf5_1_10_3)]
pub const H5O_INFO_BASIC: c_uint = 0x0001;
#[cfg(hdf5_1_10_3)]
pub const H5O_INFO_TIME: c_uint = 0x0002;
#[cfg(hdf5_1_10_3)]
pub const H5O_INFO_NUM_ATTRS: c_uint = 0x0004;
#[cfg(all(hdf5_1_10_3, not(hdf5_1_12_0)))]
pub const H5O_INFO_HDR: c_uint = 0x0008;
#[cfg(all(hdf5_1_10_3, not(hdf5_1_12_0)))]
pub const H5O_INFO_META_SIZE: c_uint = 0x0010;
#[cfg(all(hdf5_1_10_3, not(hdf5_1_12_0)))]
pub const H5O_INFO_ALL: c_uint =
    H5O_INFO_BASIC | H5O_INFO_TIME | H5O_INFO_NUM_ATTRS | H5O_INFO_HDR | H5O_INFO_META_SIZE;
#[cfg(hdf5_1_12_0)]
pub const H5O_INFO_ALL: c_uint = H5O_INFO_BASIC | H5O_INFO_TIME | H5O_INFO_NUM_ATTRS;

#[cfg(hdf5_1_12_0)]
pub const H5O_NATIVE_INFO_HDR: c_uint = 0x0008;
#[cfg(hdf5_1_12_0)]
pub const H5O_NATIVE_INFO_META_SIZE: c_uint = 0x0010;
#[cfg(hdf5_1_12_0)]
pub const H5O_NATIVE_INFO_ALL: c_uint = H5O_NATIVE_INFO_HDR | H5O_NATIVE_INFO_META_SIZE;

#[repr(C)]
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)]
pub enum H5O_type_t {
    H5O_TYPE_UNKNOWN = -1,
    H5O_TYPE_GROUP,
    H5O_TYPE_DATASET,
    H5O_TYPE_NAMED_DATATYPE,
    #[cfg(hdf5_1_12_0)]
    H5O_TYPE_MAP,
    H5O_TYPE_NTYPES,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct H5O_hdr_info_t {
    pub version: c_uint,
    pub nmesgs: c_uint,
    pub nchunks: c_uint,
    pub flags: c_uint,
    pub space: H5O_hdr_info_t__space,
    pub mesg: H5O_hdr_info_t__mesg,
}

impl Default for H5O_hdr_info_t {
    fn default() -> Self {
        unsafe { mem::zeroed() }
    }
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct H5O_hdr_info_t__space {
    pub total: hsize_t,
    pub meta: hsize_t,
    pub mesg: hsize_t,
    pub free: hsize_t,
}

impl Default for H5O_hdr_info_t__space {
    fn default() -> Self {
        unsafe { mem::zeroed() }
    }
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct H5O_hdr_info_t__mesg {
    pub present: uint64_t,
    pub shared: uint64_t,
}

impl Default for H5O_hdr_info_t__mesg {
    fn default() -> Self {
        unsafe { mem::zeroed() }
    }
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct H5O_info_t {
    pub fileno: c_ulong,
    pub addr: haddr_t,
    pub type_: H5O_type_t,
    pub rc: c_uint,
    pub atime: time_t,
    pub mtime: time_t,
    pub ctime: time_t,
    pub btime: time_t,
    pub num_attrs: hsize_t,
    pub hdr: H5O_hdr_info_t,
    pub meta_size: H5O_info_t__meta_size,
}

impl Default for H5O_info_t {
    fn default() -> Self {
        unsafe { mem::zeroed() }
    }
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct H5O_info_t__meta_size {
    pub obj: H5_ih_info_t,
    pub attr: H5_ih_info_t,
}

#[cfg(not(hdf5_1_12_0))]
impl Default for H5O_info_t__meta_size {
    fn default() -> Self {
        unsafe { mem::zeroed() }
    }
}

pub type H5O_msg_crt_idx_t = uint32_t;

pub type H5O_iterate_t = Option<
    extern "C" fn(
        obj: hid_t,
        name: *const c_char,
        info: *const H5O_info_t,
        op_data: *mut c_void,
    ) -> herr_t,
>;

#[cfg(hdf5_1_12_0)]
pub type H5O_iterate2_t = Option<
    extern "C" fn(
        obj: hid_t,
        name: *const c_char,
        info: *const H5O_info2_t,
        op_data: *mut c_void,
    ) -> herr_t,
>;

#[repr(C)]
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)]
pub enum H5O_mcdt_search_ret_t {
    H5O_MCDT_SEARCH_ERROR = -1,
    H5O_MCDT_SEARCH_CONT = 0,
    H5O_MCDT_SEARCH_STOP = 1,
}

#[cfg(hdf5_1_8_9)]
pub type H5O_mcdt_search_cb_t =
    Option<extern "C" fn(op_data: *mut c_void) -> H5O_mcdt_search_ret_t>;

#[cfg(not(hdf5_1_10_3))]
extern "C" {
    pub fn H5Oget_info(loc_id: hid_t, oinfo: *mut H5O_info_t) -> herr_t;
    pub fn H5Oget_info_by_name(
        loc_id: hid_t, name: *const c_char, oinfo: *mut H5O_info_t, lapl_id: hid_t,
    ) -> herr_t;
    pub fn H5Oget_info_by_idx(
        loc_id: hid_t, group_name: *const c_char, idx_type: H5_index_t, order: H5_iter_order_t,
        n: hsize_t, oinfo: *mut H5O_info_t, lapl_id: hid_t,
    ) -> herr_t;
    pub fn H5Ovisit(
        obj_id: hid_t, idx_type: H5_index_t, order: H5_iter_order_t, op: H5O_iterate_t,
        op_data: *mut c_void,
    ) -> herr_t;
    pub fn H5Ovisit_by_name(
        loc_id: hid_t, obj_name: *const c_char, idx_type: H5_index_t, order: H5_iter_order_t,
        op: H5O_iterate_t, op_data: *mut c_void, lapl_id: hid_t,
    ) -> herr_t;
}

extern "C" {
    pub fn H5Oopen(loc_id: hid_t, name: *const c_char, lapl_id: hid_t) -> hid_t;
    pub fn H5Oopen_by_addr(loc_id: hid_t, addr: haddr_t) -> hid_t;
    pub fn H5Oopen_by_idx(
        loc_id: hid_t, group_name: *const c_char, idx_type: H5_index_t, order: H5_iter_order_t,
        n: hsize_t, lapl_id: hid_t,
    ) -> hid_t;
    pub fn H5Olink(
        obj_id: hid_t, new_loc_id: hid_t, new_name: *const c_char, lcpl_id: hid_t, lapl_id: hid_t,
    ) -> herr_t;
    pub fn H5Oincr_refcount(object_id: hid_t) -> herr_t;
    pub fn H5Odecr_refcount(object_id: hid_t) -> herr_t;
    pub fn H5Ocopy(
        src_loc_id: hid_t, src_name: *const c_char, dst_loc_id: hid_t, dst_name: *const c_char,
        ocpypl_id: hid_t, lcpl_id: hid_t,
    ) -> herr_t;
    pub fn H5Oset_comment(obj_id: hid_t, comment: *const c_char) -> herr_t;
    pub fn H5Oset_comment_by_name(
        loc_id: hid_t, name: *const c_char, comment: *const c_char, lapl_id: hid_t,
    ) -> herr_t;
    pub fn H5Oget_comment(obj_id: hid_t, comment: *mut c_char, bufsize: size_t) -> ssize_t;
    pub fn H5Oget_comment_by_name(
        loc_id: hid_t, name: *const c_char, comment: *mut c_char, bufsize: size_t, lapl_id: hid_t,
    ) -> ssize_t;
    pub fn H5Oclose(object_id: hid_t) -> herr_t;
}

#[cfg(hdf5_1_8_5)]
use crate::h5::htri_t;

#[cfg(hdf5_1_8_5)]
extern "C" {
    pub fn H5Oexists_by_name(loc_id: hid_t, name: *const c_char, lapl_id: hid_t) -> htri_t;
}

#[cfg(hdf5_1_10_0)]
extern "C" {
    pub fn H5Odisable_mdc_flushes(object_id: hid_t) -> herr_t;
    pub fn H5Oenable_mdc_flushes(object_id: hid_t) -> herr_t;
    pub fn H5Oare_mdc_flushes_disabled(object_id: hid_t, are_disabled: *mut hbool_t) -> herr_t;
    pub fn H5Oflush(obj_id: hid_t) -> herr_t;
    pub fn H5Orefresh(oid: hid_t) -> herr_t;
}

#[cfg(hdf5_1_10_3)]
mod hdf5_1_10_3 {
    use super::*;

    extern "C" {
        pub fn H5Oget_info2(loc_id: hid_t, oinfo: *mut H5O_info_t, fields: c_uint) -> herr_t;
        pub fn H5Oget_info_by_name2(
            loc_id: hid_t, name: *const c_char, oinfo: *mut H5O_info_t, fields: c_uint,
            lapl_id: hid_t,
        ) -> herr_t;
        pub fn H5Oget_info_by_idx2(
            loc_id: hid_t, group_name: *const c_char, idx_type: H5_index_t, order: H5_iter_order_t,
            n: hsize_t, oinfo: *mut H5O_info_t, fields: c_uint, lapl_id: hid_t,
        ) -> herr_t;
        pub fn H5Ovisit2(
            obj_id: hid_t, idx_type: H5_index_t, order: H5_iter_order_t, op: H5O_iterate_t,
            op_data: *mut c_void, fields: c_uint,
        ) -> herr_t;
        pub fn H5Ovisit_by_name2(
            loc_id: hid_t, obj_name: *const c_char, idx_type: H5_index_t, order: H5_iter_order_t,
            op: H5O_iterate_t, op_data: *mut c_void, fields: c_uint, lapl_id: hid_t,
        ) -> herr_t;
        #[deprecated(note = "deprecated in HDF5 1.10.3, use H5Oget_info2()")]
        pub fn H5Oget_info1(loc_id: hid_t, oinfo: *mut H5O_info_t) -> herr_t;
        #[deprecated(note = "deprecated in HDF5 1.10.3, use H5Oget_info_by_name2()")]
        pub fn H5Oget_info_by_name1(
            loc_id: hid_t, name: *const c_char, oinfo: *mut H5O_info_t, lapl_id: hid_t,
        ) -> herr_t;
        #[deprecated(note = "deprecated in HDF5 1.10.3, use H5Oget_info_by_idx2()")]
        pub fn H5Oget_info_by_idx1(
            loc_id: hid_t, group_name: *const c_char, idx_type: H5_index_t, order: H5_iter_order_t,
            n: hsize_t, oinfo: *mut H5O_info_t, lapl_id: hid_t,
        ) -> herr_t;
        #[deprecated(note = "deprecated in HDF5 1.10.3, use H5Ovisit2()")]
        pub fn H5Ovisit1(
            obj_id: hid_t, idx_type: H5_index_t, order: H5_iter_order_t, op: H5O_iterate_t,
            op_data: *mut c_void,
        ) -> herr_t;
        #[deprecated(note = "deprecated in HDF5 1.10.3, use H5Ovisit_by_name2()")]
        pub fn H5Ovisit_by_name1(
            loc_id: hid_t, obj_name: *const c_char, idx_type: H5_index_t, order: H5_iter_order_t,
            op: H5O_iterate_t, op_data: *mut c_void, lapl_id: hid_t,
        ) -> herr_t;
    }

    #[cfg(not(hdf5_1_10_5))]
    pub use self::{
        H5Oget_info1 as H5Oget_info, H5Oget_info_by_idx1 as H5Oget_info_by_idx,
        H5Oget_info_by_name1 as H5Oget_info_by_name, H5Ovisit1 as H5Ovisit,
        H5Ovisit_by_name1 as H5Ovisit_by_name,
    };
}

#[cfg(hdf5_1_10_3)]
pub use self::hdf5_1_10_3::*;

#[cfg(hdf5_1_10_5)]
extern "C" {
    // They've messed up when introducing compatibility macros which broke ABI compatibility;
    // in 1.10.5 those APIs were copied over to old names in order to be compatible with
    // older library versions - so we can link to them directly again.
    #[deprecated(note = "deprecated in HDF5 1.10.3, use H5Oget_info2()")]
    pub fn H5Oget_info(loc_id: hid_t, oinfo: *mut H5O_info_t) -> herr_t;
    #[deprecated(note = "deprecated in HDF5 1.10.3, use H5Oget_info_by_name2()")]
    pub fn H5Oget_info_by_name(
        loc_id: hid_t, name: *const c_char, oinfo: *mut H5O_info_t, lapl_id: hid_t,
    ) -> herr_t;
    #[deprecated(note = "deprecated in HDF5 1.10.3, use H5Oget_info_by_idx2()")]
    pub fn H5Oget_info_by_idx(
        loc_id: hid_t, group_name: *const c_char, idx_type: H5_index_t, order: H5_iter_order_t,
        n: hsize_t, oinfo: *mut H5O_info_t, lapl_id: hid_t,
    ) -> herr_t;
    #[deprecated(note = "deprecated in HDF5 1.10.3, use H5Ovisit2()")]
    pub fn H5Ovisit(
        obj_id: hid_t, idx_type: H5_index_t, order: H5_iter_order_t, op: H5O_iterate_t,
        op_data: *mut c_void,
    ) -> herr_t;
    #[deprecated(note = "deprecated in HDF5 1.10.3, use H5Ovisit_by_name2()")]
    pub fn H5Ovisit_by_name(
        loc_id: hid_t, obj_name: *const c_char, idx_type: H5_index_t, order: H5_iter_order_t,
        op: H5O_iterate_t, op_data: *mut c_void, lapl_id: hid_t,
    ) -> herr_t;
}

#[cfg(hdf5_1_12_0)]
pub const H5O_MAX_TOKEN_SIZE: usize = 16;

#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[cfg(hdf5_1_12_0)]
pub struct H5O_token_t {
    __data: [u8; H5O_MAX_TOKEN_SIZE],
}

#[cfg(hdf5_1_12_0)]
impl Default for H5O_token_t {
    fn default() -> Self {
        *H5O_TOKEN_UNDEF
    }
}

#[cfg(hdf5_1_12_0)]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct H5O_info2_t {
    fileno: c_ulong,
    token: H5O_token_t,
    type_: H5O_type_t,
    rc: c_uint,
    atime: time_t,
    mtime: time_t,
    ctime: time_t,
    btime: time_t,
    num_attrs: hsize_t,
}

#[cfg(hdf5_1_12_0)]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct H5O_native_info_meta_size_t {
    obj: H5_ih_info_t,
    attr: H5_ih_info_t,
}

#[cfg(hdf5_1_12_0)]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct H5O_native_info_t {
    hdf: H5O_hdr_info_t,
    meta_size: H5O_native_info_meta_size_t,
}

#[cfg(hdf5_1_12_0)]
extern "C" {
    pub fn H5Oget_info3(loc_id: hid_t, oinfo: *mut H5O_info2_t, fields: c_uint) -> herr_t;
    pub fn H5Oget_info_by_idx3(
        loc_id: hid_t, group_name: *const c_char, idx_type: H5_index_t, order: H5_iter_order_t,
        n: hsize_t, oinfo: *mut H5O_info2_t, fields: c_uint, lapl_id: hid_t,
    ) -> herr_t;
    pub fn H5Oget_info_by_name3(
        loc_id: hid_t, name: *const c_char, oinfo: *mut H5O_info2_t, fields: c_uint, lapl_id: hid_t,
    ) -> herr_t;
    pub fn H5Oget_native_info(
        loc_id: hid_t, oinfor: *mut H5O_native_info_t, fields: c_uint,
    ) -> herr_t;
    pub fn H5Oget_native_info_by_idx(
        loc_id: hid_t, group_name: *const c_char, idx_type: H5_index_t, order: H5_iter_order_t,
        n: hsize_t, oinfo: *mut H5O_native_info_t, fields: c_uint, lapl_id: hid_t,
    ) -> herr_t;
    pub fn H5Oget_native_info_by_name(
        loc_id: hid_t, name: *const c_char, oinfo: *mut H5O_native_info_t, fields: c_uint,
        lapl_id: hid_t,
    ) -> herr_t;
    pub fn H5Oopen_by_token(loc_id: hid_t, token: H5O_token_t) -> hid_t;
    pub fn H5Otoken_cmp(
        loc_id: hid_t, token1: *const H5O_token_t, token2: *const H5O_token_t,
        cmp_value: *mut c_int,
    ) -> herr_t;
    pub fn H5Otoken_from_str(
        loc_id: hid_t, token_str: *const c_char, token: *mut H5O_token_t,
    ) -> herr_t;
    pub fn H5Otoken_to_str(
        loc_id: hid_t, token: *const H5O_token_t, token_str: *mut *mut c_char,
    ) -> herr_t;
    pub fn H5Ovisit3(
        obj_id: hid_t, idx_type: H5_index_t, order: H5_iter_order_t, op: H5O_iterate2_t,
        op_data: *mut c_void, fields: c_uint,
    ) -> herr_t;
    pub fn H5Ovisit_by_name3(
        loc_id: hid_t, obj_name: *const c_char, idx_type: H5_index_t, order: H5_iter_order_t,
        op: H5O_iterate2_t, op_data: *mut c_void, fields: c_uint, lapl_id: hid_t,
    ) -> herr_t;
}

#[cfg(hdf5_1_12_0)]
pub use self::globals::*;

#[cfg(all(not(all(target_env = "msvc", not(feature = "static"))), hdf5_1_12_0))]
mod globals {
    use super::H5O_token_t as id_t;
    extern_static!(H5O_TOKEN_UNDEF, H5O_TOKEN_UNDEF_g);
}

#[cfg(all(target_env = "msvc", not(feature = "static"), hdf5_1_12_0))]
mod globals {
    // TODO: special DLL handling?
    use super::H5O_token_t as id_t;
    extern_static!(H5O_TOKEN_UNDEF, __imp_H5O_TOKEN_UNDEF_g);
}