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 HDF.  The full HDF 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/HDF/releases/.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /* $Id$ */
15 
16 /*-----------------------------------------------------------------------------
17  * File:         hchunks.h
18  * Purpose:      Header file for Chunked elements
19  * Dependencies: tbbt.c mcache.c
20  * Invokes:      none
21  * Contents:     Structures & definitions for chunked elements
22  * Structure definitions: DIM_DEF, HCHUNK_DEF
23  * Constant definitions:
24  * Author: -GeorgeV -  9/3/96
25  *---------------------------------------------------------------------------*/
26 
27 /* avoid re-inclusion */
28 #ifndef __HCHUNKS_H
29 #define __HCHUNKS_H
30 
31 #include "H4api_adpt.h"
32 
33 /* required includes */
34 #include "hfile.h"  /* special info stuff */
35 
36 #ifdef   _HCHUNKS_MAIN_
37 /* Private to 'hchunks.c' */
38 
39 #include "tbbt.h"   /* TBBT stuff */
40 #include "mcache.h" /* caching routines */
41 #include "hcomp.h"  /* For Compression */
42 
43 /* Define class, class version and name(partial) for chunk table i.e. Vdata */
44 #if 0 /* moved definition of class of vdata to hlimits.h */
45 #define _HDF_CHK_TBL_CLASS "_HDF_CHK_TBL_" /* 13 bytes */
46 #define _HDF_CHK_TBL_CLASS_VER  0          /* zero version number for class */
47 #endif /* moved definition of class of vdata to hlimits.h */
48 #define _HDF_CHK_TBL_NAME  "_HDF_CHK_TBL_" /* 13 bytes */
49 
50 /* Define field name for each chunk record i.e. Vdata record */
51 #define _HDF_CHK_FIELD_1   "origin"  /* 6 bytes */
52 #define _HDF_CHK_FIELD_2   "chk_tag" /* 7 bytes */
53 #define _HDF_CHK_FIELD_3   "chk_ref" /* 7 bytes */
54 #define _HDF_CHK_FIELD_NAMES   "origin,chk_tag,chk_ref" /* 22 bytes */
55 
56 /* Define version number for chunked header format */
57 #define _HDF_CHK_HDR_VER   0  /* zero version for format header */
58 
59 #endif /* _HCHUNKS_MAIN_ */
60 
61 /* Public structures */
62 
63 /* Structure for each Data array dimension Defintion */
64 typedef struct dim_def_struct {
65     int32 dim_length;          /* length of this dimension */
66     int32 chunk_length;        /* chunk length along this dimension */
67     int32 distrib_type;        /* Data distribution along this dimension */
68 } DIM_DEF, * DIM_DEF_PTR;
69 
70 /* Structure for each Chunk Definition*/
71 typedef struct hchunk_def_struct {
72     int32    chunk_size;     /* size of this chunk*/
73     int32    nt_size;        /* number type size i.e. size of data type */
74     int32    num_dims;       /* number of actual dimensions */
75     DIM_DEF *pdims;          /* ptr to array of dimension records for this chunk*/
76     int32   chunk_flag;      /* multiply specialness? SPECIAL_COMP */
77 
78     /* For Compression info */
79     comp_coder_t comp_type;     /* Compression type */
80     comp_model_t model_type;    /* Compression model type */
81     comp_info  *cinfo;        /* Compression info struct */
82     model_info *minfo;        /* Compression model info struct */
83 }HCHUNK_DEF, * HCHUNK_DEF_PTR;
84 
85 /* Private structues */
86 #ifdef _HCHUNKS_MAIN_
87 /* Private to 'hchunks.c' */
88 
89 /* Structure for each Data array dimension */
90 typedef struct dim_rec_struct {
91     /* fields stored in chunked header */
92     int32 flag;                /* distrib_type(low 8 bits 0-7)
93                                   - Data distribution along this dimension
94                                   other(medium low 8 bits 8-15)
95                                   - regular/unlimited dimension? */
96     int32 dim_length;          /* length of this dimension */
97     int32 chunk_length;        /* chunk length along this dimension */
98 
99     /* info determined from 'flag' field */
100     int32 distrib_type;        /* Data distribution along this dimension */
101     int32 unlimited;           /* regular(0) or unlimited dimension(1) */
102 
103     /* computed fields */
104     int32 last_chunk_length;   /* last chunk length along this dimension */
105     int32 num_chunks;          /* i.e. "dim_length / chunk_length" */
106 } DIM_REC, * DIM_REC_PTR;
107 
108 /* Structure for each Chunk */
109 typedef struct chunk_rec_struct {
110     int32 chunk_number;      /* chunk number from coordinates i.e. origin */
111     int32 chk_vnum;          /* chunk vdata record number i.e. position in table*/
112 
113     /* chunk record fields stored in Vdata Table */
114     int32  *origin;          /* origin -> position of chunk */
115     uint16 chk_tag;          /* DFTAG_CHUNK or another Chunked element? */
116     uint16 chk_ref;          /* reference number of this chunk */
117 }CHUNK_REC, * CHUNK_REC_PTR;
118 
119 /* information on this special chunk data elt */
120 typedef struct chunkinfo_t
121 {
122     intn        attached;     /* how many access records refer to this elt */
123     int32       aid;          /* Access id of chunk table i.e. Vdata */
124 
125     /* chunked element format header  fields */
126     int32       sp_tag_header_len; /* length of the special element header */
127     uint8       version;      /* Version of this Chunked element */
128     int32       flag;         /* flag for multiply specialness ...*/
129     int32       length;       /* the actual length of the data elt */
130     int32       chunk_size;   /* the logical size of the chunks */
131     int32       nt_size;      /* number type size i.e. size of data type */
132     uint16      chktbl_tag;   /* DFTAG_VH - Vdata header */
133     uint16      chktbl_ref;   /* ref of the first chunk table structure(VDATA) */
134     uint16      sp_tag;       /* For future use.. */
135     uint16      sp_ref;       /* For future use.. */
136     int32       ndims;        /* number of dimensions of chunk */
137     DIM_REC     *ddims;       /* array of dimension records */
138     int32       fill_val_len; /* fill value number of bytes */
139     VOID        *fill_val;    /* fill value */
140     /* For each specialness, only one for now SPECIAL_COMP */
141     int32       comp_sp_tag_head_len; /* Compression header length */
142     VOID        *comp_sp_tag_header;  /* compression header */
143 
144     /* For Compression info */
145     comp_coder_t comp_type;            /* Compression type */
146     comp_model_t model_type;           /* Compression model type */
147     comp_info   *cinfo;               /* Compression info struct */
148     model_info  *minfo;               /* Compression model info struct */
149 
150     /* additional memory resident data structures to be used */
151     int32       *seek_chunk_indices; /* chunk array indicies relative
152                                         to the other chunks */
153     int32       *seek_pos_chunk;     /* postion within the current chunk */
154     int32       *seek_user_indices;  /* user postion within the element  */
155     TBBT_TREE   *chk_tree;    /* TBBT tree of all accessed table entries
156                                  i.e. CHUNK_REC's read/written/modified */
157     MCACHE      *chk_cache;   /* chunk cache */
158     int32       num_recs;     /* number of Table(Vdata) records */
159 }
160 chunkinfo_t;
161 #endif /* _HCHUNKS_MAIN_ */
162 
163 #if defined c_plusplus || defined __cplusplus
164 extern      "C"
165 {
166 #endif                          /* c_plusplus || __cplusplus */
167 
168 /*
169 ** from hchunks.c
170 */
171 
172 /* User Public */
173     HDFLIBAPI int32 HMCcreate
174         (int32 file_id,       /* IN: file to put linked chunk element in */
175          uint16 tag,          /* IN: tag of element */
176          uint16 ref,          /* IN: ref of element */
177          uint8 nlevels,       /* IN: number of levels of chunks */
178          int32 fill_val_len,  /* IN: fill value length in bytes */
179          VOID  *fill_val,     /* IN: fill value */
180          HCHUNK_DEF *chk_array /* IN: structure describing chunk distribution
181                                  can be an array? but we only handle 1 level */);
182 
183     HDFLIBAPI intn HMCgetcompress
184         (accrec_t* access_rec,    /* IN: access record */
185          comp_coder_t* comp_type, /* OUT: compression type */
186          comp_info* c_info        /* OUT: retrieved compression info */);
187 
188     HDFLIBAPI intn HMCgetcomptype
189         (int32 access_id,         /* IN: access record */
190          comp_coder_t* comp_type  /* OUT: compression type */);
191 
192     HDFLIBAPI intn HMCgetdatainfo
193         (int32 file_id,    /* IN: file in which element is located */
194          uint16 data_tag,
195          uint16 data_ref,
196 	 int32 *chk_coord, /* IN: chunk coord array or NULL for non-chunk SDS */
197          uintn start_block,/* IN: data block to start at, 0 base */
198          uintn info_count, /* IN: size of offset/length lists */
199          int32 *offsetarray,     /* OUT: array to hold offsets */
200          int32 *lengtharray);    /* OUT: array to hold lengths */
201 
202     HDFLIBAPI intn HMCgetdatasize
203         (int32 file_id,    /* IN: file in which element is located */
204          uint8 *p,         /* IN: buffer of special info header */
205          int32 *comp_size, /* OUT: size of compressed data */
206          int32 *orig_size  /* OUT: size of non-compressed data */);
207 
208     HDFLIBAPI int32 HMCsetMaxcache
209         (int32 access_id,  /* IN: access aid to mess with */
210          int32 maxcache,   /* IN: max number of pages to cache */
211          int32 flags       /* IN: flags = 0, HMC_PAGEALL */);
212 
213     HDFLIBAPI int32 HMCwriteChunk
214         (int32 access_id,  /* IN: access aid to mess with */
215          int32 *origin,    /* IN: origin of chunk to write */
216          const VOID *datap /* IN: buffer for data */);
217 
218     HDFLIBAPI int32 HMCreadChunk
219         (int32 access_id,  /* IN: access aid to mess with */
220          int32 *origin,    /* IN: origin of chunk to read */
221          VOID *datap       /* IN: buffer for data */);
222 
223     HDFLIBAPI int32 HMCPcloseAID
224         (accrec_t *access_rec /* IN:  access record of file to close */);
225 
226     HDFLIBAPI int32 HMCPgetnumrecs /* has to be here because used in hfile.c */
227         (accrec_t * access_rec, /* IN:  access record to return info about */
228          int32 *num_recs        /* OUT: length of the chunked elt */);
229 
230 /* Library Private */
231 #ifdef _HCHUNKS_MAIN_
232     /* tbbt.h helper routines */
233     intn chkcompare(void * k1,   /* IN: first key */
234            void * k2,   /* IN: second key */
235            intn cmparg /* IN: not sure? */);
236     void chkfreekey(void * key /*IN: chunk key */ );
237     void chkdestroynode(void * n /* IN: chunk record */ );
238 
239 /* Private to 'hchunks.c' */
240     extern int32 HMCPstread
241         (accrec_t *access_rec  /* IN: access record to fill in */);
242 
243     extern int32 HMCPstwrite
244         (accrec_t *access_rec  /* IN: access record to fill in */);
245 
246     extern int32 HMCPseek
247         (accrec_t *access_rec, /* IN: access record to mess with */
248          int32 offset,         /* IN: seek offset */
249          int   origin          /* IN: where we should calc the offset from */);
250 
251     extern int32 HMCPchunkread
252         (VOID  *cookie,    /* IN: access record to mess with */
253          int32 chunk_num,  /* IN: chunk to read */
254          VOID  *datap      /* OUT: buffer for data */);
255 
256     extern int32 HMCPread
257         (accrec_t * access_rec, /* IN: access record to mess with */
258          int32 length,          /* IN: number of bytes to read */
259          void * data             /* OUT: buffer for data */);
260 
261     extern int32 HMCPchunkwrite
262         (VOID  *cookie,    /* IN: access record to mess with */
263          int32 chunk_num,  /* IN: chunk number */
264          const VOID *datap /* IN: buffer for data */);
265 
266     extern int32 HMCPwrite
267         (accrec_t *access_rec, /* IN: access record to mess with */
268          int32 length,         /* IN: number of bytes to write */
269          const void * data      /* IN: buffer for data */);
270 
271     extern intn HMCPendaccess
272         (accrec_t *access_rec /* IN:  access record to close */);
273 
274     extern int32 HMCPinfo
275         (accrec_t *access_rec,       /* IN: access record of access elemement */
276          sp_info_block_t *info_chunk /* OUT: information about the special element */);
277 
278     extern int32 HMCPinquire
279         (accrec_t * access_rec, /* IN:  access record to return info about */
280          int32 *pfile_id,       /* OUT: file ID; */
281          uint16 *ptag,          /* OUT: tag of info record; */
282          uint16 *pref,          /* OUT: ref of info record; */
283          int32 *plength,        /* OUT: length of element; */
284          int32 *poffset,        /* OUT: offset of element -- meaningless */
285          int32 *pposn,          /* OUT: current position in element; */
286          int16 *paccess,        /* OUT: access mode; */
287          int16 *pspecial        /* OUT: special code; */);
288 
289 #endif /* _HCHUNKS_MAIN_ */
290 
291 #if defined c_plusplus || defined __cplusplus
292 }
293 #endif                          /* c_plusplus || __cplusplus */
294 
295 #ifndef _HCHUNKS_MAIN_
296 /* not in master file hchunk.c */
297 extern funclist_t chunked_funcs;  /* functions to perform chunking */
298 
299 #else /* in hchunks.c */
300 
301 /* the accessing special function table for chunks */
302 funclist_t  chunked_funcs =
303 {
304     HMCPstread,
305     HMCPstwrite,
306     HMCPseek,
307     HMCPinquire,
308     HMCPread,
309     HMCPwrite,
310     HMCPendaccess,
311     HMCPinfo,
312     NULL         /* no routine registerd */
313 };
314 
315 #endif
316 
317 #endif /* __HCHUNKS_H */
318