1 /*
2  *	Copyright 1996, University Corporation for Atmospheric Research
3  *	See netcdf/COPYRIGHT file for copying and redistribution conditions.
4  */
5 /* $Id: ncio.h,v 1.27 2006/01/03 04:56:28 russ Exp $ */
6 
7 #ifndef _NCIO_H_
8 #define _NCIO_H_
9 
10 #include <stddef.h>	/* size_t */
11 #include <sys/types.h>	/* off_t */
12 #include "xxxnetcdf.h"
13 
14 typedef struct ncio ncio;	/* forward reference */
15 
16 /*
17  * A value which is an invalid off_t
18  */
19 #define OFF_NONE  ((off_t)(-1))
20 
21 /*
22  * Flags used by the region layer,
23  *  'rflags' argument to ncio.rel() and ncio.get().
24  */
25 #define RGN_NOLOCK	0x1	/* Don't lock region.
26 				 * Used when contention control handled
27 				 * elsewhere.
28 				 */
29 #define RGN_NOWAIT	0x2	/* return immediate if can't lock, else wait */
30 
31 #define RGN_WRITE	0x4	/* we intend to modify, else read only */
32 
33 #define RGN_MODIFIED	0x8	/* we did modify, else, discard */
34 
35 
36 /*
37  * The next four typedefs define the signatures
38  * of function pointers in struct ncio below.
39  * They are not used outside of this file and ncio.h,
40  * They just make some casts in the ncio.c more readable.
41  */
42 	/*
43 	 * Indicate that you are done with the region which begins
44 	 * at offset. Only reasonable flag value is RGN_MODIFIED.
45 	 */
46 typedef int ncio_relfunc(ncio *const nciop,
47 		 off_t offset, int rflags);
48 
49 	/*
50 	 * Request that the region (offset, extent)
51 	 * be made available through *vpp.
52 	 */
53 typedef int ncio_getfunc(ncio *const nciop,
54 			off_t offset, size_t extent,
55 			int rflags,
56 			void **const vpp);
57 
58 	/*
59 	 * Like memmove(), safely move possibly overlapping data.
60 	 * Only reasonable flag value is RGN_NOLOCK.
61 	 */
62 typedef int ncio_movefunc(ncio *const nciop, off_t to, off_t from,
63 			size_t nbytes, int rflags);
64 
65 	/*
66 	 * Write out any dirty buffers to disk and
67 	 * ensure that next read will get data from disk.
68 	 */
69 typedef int ncio_syncfunc(ncio *const nciop);
70 
71 	/*
72 	 * Don't call this.
73 	 * Internal function called at close to
74 	 * free up anything hanging off pvt;
75 	 */
76 typedef void ncio_freefunc(void *const pvt);
77 
78 /* Get around cplusplus "const xxx in class ncio without constructor" error */
79 #if defined(__cplusplus)
80 #define NCIO_CONST
81 #else
82 #define NCIO_CONST const
83 #endif
84 
85 /*
86  * netcdf i/o abstraction
87  */
88 struct ncio {
89 	/*
90 	 * A copy of the ioflags argument passed in to ncio_open()
91 	 * or ncio_create().
92 	 */
93 	int ioflags;
94 
95 	/*
96 	 * The file descriptor of the netcdf file.
97 	 * This gets handed to the user as the netcdf id.
98 	 */
99 	NCIO_CONST int fd;
100 
101 	/* member functions do the work */
102 
103 	ncio_relfunc *NCIO_CONST rel;
104 
105 	ncio_getfunc *NCIO_CONST get;
106 
107 	ncio_movefunc *NCIO_CONST move;
108 
109 	ncio_syncfunc *NCIO_CONST sync;
110 
111 	ncio_freefunc *NCIO_CONST free; /* Implementation private */
112 
113 	/*
114 	 * A copy of the 'path' argument passed in to ncio_open()
115 	 * or ncio_create(). Used by ncabort() to remove (unlink)
116 	 * the file and by error messages.
117 	 */
118 	const char *path;
119 
120 	/* implementation private stuff */
121 	void *NCIO_CONST pvt;
122 };
123 
124 #undef NCIO_CONST
125 
126 extern int
127 ncio_create(const char *path, int ioflags,
128 	size_t initialsz,
129 	off_t igeto, size_t igetsz, size_t *sizehintp,
130 	ncio **nciopp, void **const igetvpp);
131 
132 extern int
133 ncio_open(const char *path,
134 	int ioflags,
135 	off_t igeto, size_t igetsz, size_t *sizehintp,
136 	ncio **nciopp, void **const igetvpp);
137 
138 extern int
139 ncio_close(ncio *nciop, int doUnlink);
140 
141 extern int
142 ncio_filesize(ncio *nciop, off_t *filesizep);
143 
144 extern int
145 ncio_pad_length(ncio *nciop, off_t length);
146 
147 #endif /* _NCIO_H_ */
148