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
18    cnone.c
19    HDF none encoding I/O routines
20 
21    REMARKS
22    These routines are only included for completeness and are not
23    actually expected to be used.
24 
25    DESIGN
26 
27    EXPORTED ROUTINES
28    None of these routines are designed to be called by other users except
29    for the modeling layer of the compression routines.
30 
31    AUTHOR
32    Quincey Koziol
33 
34    MODIFICATION HISTORY
35    4/25/94     Starting writing specs & coding prototype.
36  */
37 
38 /* General HDF includes */
39 #include "hdf.h"
40 
41 #define CNONE_MASTER
42 #define CODER_CLIENT
43 /* HDF compression includes */
44 #include "hcompi.h"     /* Internal definitions for compression */
45 
46 /* declaration of the functions provided in this module */
47 PRIVATE int32 HCIcnone_staccess
48             (accrec_t * access_rec, int16 acc_mode);
49 
50 /*--------------------------------------------------------------------------
51  NAME
52     HCIcnone_staccess -- Start accessing a RLE compressed data element.
53 
54  USAGE
55     int32 HCIcnone_staccess(access_rec, access)
56     accrec_t *access_rec;   IN: the access record of the data element
57     int16 access;           IN: the type of access wanted
58 
59  RETURNS
60     Returns SUCCEED or FAIL
61 
62  DESCRIPTION
63     Common code called by HCIcnone_stread and HCIcnone_stwrite
64 
65  GLOBAL VARIABLES
66  COMMENTS, BUGS, ASSUMPTIONS
67  EXAMPLES
68  REVISION LOG
69 --------------------------------------------------------------------------*/
70 PRIVATE int32
HCIcnone_staccess(accrec_t * access_rec,int16 acc_mode)71 HCIcnone_staccess(accrec_t * access_rec, int16 acc_mode)
72 {
73     CONSTR(FUNC, "HCIcnone_staccess");
74     compinfo_t *info;           /* special element information */
75 
76     info = (compinfo_t *) access_rec->special_info;
77 
78     if (acc_mode == DFACC_READ)
79         info->aid = Hstartread(access_rec->file_id, DFTAG_COMPRESSED,
80                                info->comp_ref);
81     else
82         info->aid = Hstartwrite(access_rec->file_id, DFTAG_COMPRESSED,
83                                 info->comp_ref, info->length);
84 
85     if (info->aid == FAIL)
86         HRETURN_ERROR(DFE_DENIED, FAIL);
87     if ((acc_mode&DFACC_WRITE) && Happendable(info->aid) == FAIL)
88         HRETURN_ERROR(DFE_DENIED, FAIL);
89     return (SUCCEED);
90 }   /* end HCIcnone_staccess() */
91 
92 /*--------------------------------------------------------------------------
93  NAME
94     HCPcnone_stread -- start read access for compressed file
95 
96  USAGE
97     int32 HCPcnone_stread(access_rec)
98     accrec_t *access_rec;   IN: the access record of the data element
99 
100  RETURNS
101     Returns SUCCEED or FAIL
102 
103  DESCRIPTION
104     Start read access on a compressed data element using no compression.
105 
106  GLOBAL VARIABLES
107  COMMENTS, BUGS, ASSUMPTIONS
108  EXAMPLES
109  REVISION LOG
110 --------------------------------------------------------------------------*/
111 int32
HCPcnone_stread(accrec_t * access_rec)112 HCPcnone_stread(accrec_t * access_rec)
113 {
114     CONSTR(FUNC, "HCPcnone_stread");
115     int32       ret;
116 
117     if ((ret = HCIcnone_staccess(access_rec, DFACC_READ)) == FAIL)
118         HRETURN_ERROR(DFE_CINIT, FAIL);
119     return (ret);
120 }   /* HCPcnone_stread() */
121 
122 /*--------------------------------------------------------------------------
123  NAME
124     HCPcnone_stwrite -- start write access for compressed file
125 
126  USAGE
127     int32 HCPcnone_stwrite(access_rec)
128     accrec_t *access_rec;   IN: the access record of the data element
129 
130  RETURNS
131     Returns SUCCEED or FAIL
132 
133  DESCRIPTION
134     Start write access on a compressed data element using no compression.
135 
136  GLOBAL VARIABLES
137  COMMENTS, BUGS, ASSUMPTIONS
138  EXAMPLES
139  REVISION LOG
140 --------------------------------------------------------------------------*/
141 int32
HCPcnone_stwrite(accrec_t * access_rec)142 HCPcnone_stwrite(accrec_t * access_rec)
143 {
144     CONSTR(FUNC, "HCPcnone_stwrite");
145     int32       ret;
146 
147     if ((ret = HCIcnone_staccess(access_rec, DFACC_WRITE)) == FAIL)
148         HRETURN_ERROR(DFE_CINIT, FAIL);
149     return (ret);
150 }   /* HCPcnone_stwrite() */
151 
152 /*--------------------------------------------------------------------------
153  NAME
154     HCPcnone_seek -- Seek to offset within the data element
155 
156  USAGE
157     int32 HCPcnone_seek(access_rec,offset,origin)
158     accrec_t *access_rec;   IN: the access record of the data element
159     int32 offset;       IN: the offset in bytes from the origin specified
160     intn origin;        IN: the origin to seek from [UNUSED!]
161 
162  RETURNS
163     Returns SUCCEED or FAIL
164 
165  DESCRIPTION
166     Seek to a position with a compressed data element.  The 'origin'
167     calculations have been taken care of at a higher level, it is an
168     un-used parameter.  The 'offset' is used as an absolute offset
169     because of this.
170 
171  GLOBAL VARIABLES
172  COMMENTS, BUGS, ASSUMPTIONS
173  EXAMPLES
174  REVISION LOG
175 --------------------------------------------------------------------------*/
176 int32
HCPcnone_seek(accrec_t * access_rec,int32 offset,int origin)177 HCPcnone_seek(accrec_t * access_rec, int32 offset, int origin)
178 {
179     CONSTR(FUNC, "HCPcnone_seek");
180     compinfo_t *info;           /* special element information */
181 
182     info = (compinfo_t *) access_rec->special_info;
183 
184     if (Hseek(info->aid, offset, origin) == FAIL)
185         HRETURN_ERROR(DFE_CSEEK, FAIL);
186 
187     return (SUCCEED);
188 }   /* HCPcnone_seek() */
189 
190 /*--------------------------------------------------------------------------
191  NAME
192     HCPcnone_read -- Read in a portion of data from a compressed data element.
193 
194  USAGE
195     int32 HCPcnone_read(access_rec,length,data)
196     accrec_t *access_rec;   IN: the access record of the data element
197     int32 length;           IN: the number of bytes to read
198     void * data;             OUT: the buffer to place the bytes read
199 
200  RETURNS
201     Returns the number of bytes read or FAIL
202 
203  DESCRIPTION
204     Read in a number of bytes from a RLE compressed data element.
205 
206  GLOBAL VARIABLES
207  COMMENTS, BUGS, ASSUMPTIONS
208  EXAMPLES
209  REVISION LOG
210 --------------------------------------------------------------------------*/
211 int32
HCPcnone_read(accrec_t * access_rec,int32 length,void * data)212 HCPcnone_read(accrec_t * access_rec, int32 length, void * data)
213 {
214     CONSTR(FUNC, "HCPcnone_read");
215     compinfo_t *info;           /* special element information */
216 
217     info = (compinfo_t *) access_rec->special_info;
218 
219     if (Hread(info->aid, length, data) == FAIL)
220         HRETURN_ERROR(DFE_CDECODE, FAIL);
221 
222     return (length);
223 }   /* HCPcnone_read() */
224 
225 /*--------------------------------------------------------------------------
226  NAME
227     HCPcnone_write -- Write out a portion of data from a compressed data element.
228 
229  USAGE
230     int32 HCPwrite(access_rec,length,data)
231     accrec_t *access_rec;   IN: the access record of the data element
232     int32 length;           IN: the number of bytes to write
233     void * data;             IN: the buffer to retrieve the bytes written
234 
235  RETURNS
236     Returns the number of bytes written or FAIL
237 
238  DESCRIPTION
239     Write out a number of bytes to a data element (w/ no compression).
240 
241  GLOBAL VARIABLES
242  COMMENTS, BUGS, ASSUMPTIONS
243  EXAMPLES
244  REVISION LOG
245 --------------------------------------------------------------------------*/
246 int32
HCPcnone_write(accrec_t * access_rec,int32 length,const void * data)247 HCPcnone_write(accrec_t * access_rec, int32 length, const void * data)
248 {
249     CONSTR(FUNC, "HCPcnone_write");
250     compinfo_t *info;           /* special element information */
251 
252     info = (compinfo_t *) access_rec->special_info;
253 
254     if (Hwrite(info->aid, length, data) == FAIL)
255         HRETURN_ERROR(DFE_CENCODE, FAIL);
256 
257     return (length);
258 }   /* HCPcnone_write() */
259 
260 /*--------------------------------------------------------------------------
261  NAME
262     HCPcnone_inquire -- Inquire information about the access record and data element.
263 
264  USAGE
265     int32 HCPcnone_inquire(access_rec,pfile_id,ptag,pref,plength,poffset,pposn,
266             paccess,pspecial)
267     accrec_t *access_rec;   IN: the access record of the data element
268     int32 *pfile_id;        OUT: ptr to file id
269     uint16 *ptag;           OUT: ptr to tag of information
270     uint16 *pref;           OUT: ptr to ref of information
271     int32 *plength;         OUT: ptr to length of data element
272     int32 *poffset;         OUT: ptr to offset of data element
273     int32 *pposn;           OUT: ptr to position of access in element
274     int16 *paccess;         OUT: ptr to access mode
275     int16 *pspecial;        OUT: ptr to special code
276 
277  RETURNS
278     Returns SUCCEED or FAIL
279 
280  DESCRIPTION
281     Inquire information about the access record and data element.
282     [Currently a NOP].
283 
284  GLOBAL VARIABLES
285  COMMENTS, BUGS, ASSUMPTIONS
286  EXAMPLES
287  REVISION LOG
288 --------------------------------------------------------------------------*/
289 int32
HCPcnone_inquire(accrec_t * access_rec,int32 * pfile_id,uint16 * ptag,uint16 * pref,int32 * plength,int32 * poffset,int32 * pposn,int16 * paccess,int16 * pspecial)290 HCPcnone_inquire(accrec_t * access_rec, int32 *pfile_id, uint16 *ptag,
291                  uint16 *pref, int32 *plength, int32 *poffset,
292                  int32 *pposn, int16 *paccess, int16 *pspecial)
293 {
294     /* shut compiler up */
295     access_rec = access_rec;
296     pfile_id = pfile_id;
297     ptag = ptag;
298     pref = pref;
299     plength = plength;
300     poffset = poffset;
301     pposn = pposn;
302     paccess = paccess;
303     pspecial = pspecial;
304 
305     return (SUCCEED);
306 }   /* HCPcnone_inquire() */
307 
308 /*--------------------------------------------------------------------------
309  NAME
310     HCPcnone_endaccess -- Close the compressed data element
311 
312  USAGE
313     int32 HCPcnone_endaccess(access_rec)
314     accrec_t *access_rec;   IN: the access record of the data element
315 
316  RETURNS
317     Returns SUCCEED or FAIL
318 
319  DESCRIPTION
320     Close the compressed data element and free modelling info.
321 
322  GLOBAL VARIABLES
323  COMMENTS, BUGS, ASSUMPTIONS
324  EXAMPLES
325  REVISION LOG
326 --------------------------------------------------------------------------*/
327 intn
HCPcnone_endaccess(accrec_t * access_rec)328 HCPcnone_endaccess(accrec_t * access_rec)
329 {
330     CONSTR(FUNC, "HCPcnone_endaccess");
331     compinfo_t *info;           /* special element information */
332 
333     info = (compinfo_t *) access_rec->special_info;
334 
335     /* close the compressed data AID */
336     if (Hendaccess(info->aid) == FAIL)
337         HRETURN_ERROR(DFE_CANTCLOSE, FAIL);
338 
339     return (SUCCEED);
340 }   /* HCPcnone_endaccess() */
341