[409] | 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 "netcdf.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 | * Sync any changes to disk, then truncate or extend file so its size |
---|
| 73 | * is length. This is only intended to be called before close, if the |
---|
| 74 | * file is open for writing and the actual size does not match the |
---|
| 75 | * calculated size, perhaps as the result of having been previously |
---|
| 76 | * written in NOFILL mode. |
---|
| 77 | */ |
---|
| 78 | typedef int ncio_pad_lengthfunc(ncio* nciop, off_t length); |
---|
| 79 | |
---|
| 80 | /* |
---|
| 81 | * Get file size in bytes. |
---|
| 82 | */ |
---|
| 83 | typedef int ncio_filesizefunc(ncio *nciop, off_t *filesizep); |
---|
| 84 | |
---|
| 85 | /* Write out any dirty buffers and |
---|
| 86 | ensure that next read will not get cached data. |
---|
| 87 | Sync any changes, then close the open file associated with the ncio |
---|
| 88 | struct, and free its memory. |
---|
| 89 | nciop - pointer to ncio to close. |
---|
| 90 | doUnlink - if true, unlink file |
---|
| 91 | */ |
---|
| 92 | typedef int ncio_closefunc(ncio *nciop, int doUnlink); |
---|
| 93 | |
---|
| 94 | /* Get around cplusplus "const xxx in class ncio without constructor" error */ |
---|
| 95 | #if defined(__cplusplus) |
---|
| 96 | #define NCIO_CONST |
---|
| 97 | #else |
---|
| 98 | #define NCIO_CONST const |
---|
| 99 | #endif |
---|
| 100 | |
---|
| 101 | /* |
---|
| 102 | * netcdf i/o abstraction |
---|
| 103 | */ |
---|
| 104 | struct ncio { |
---|
| 105 | /* |
---|
| 106 | * A copy of the ioflags argument passed in to ncio_open() |
---|
| 107 | * or ncio_create(). |
---|
| 108 | */ |
---|
| 109 | int ioflags; |
---|
| 110 | |
---|
| 111 | /* |
---|
| 112 | * The file descriptor of the netcdf file. |
---|
| 113 | * This gets handed to the user as the netcdf id. |
---|
| 114 | */ |
---|
| 115 | NCIO_CONST int fd; |
---|
| 116 | |
---|
| 117 | /* member functions do the work */ |
---|
| 118 | |
---|
| 119 | ncio_relfunc *NCIO_CONST rel; |
---|
| 120 | |
---|
| 121 | ncio_getfunc *NCIO_CONST get; |
---|
| 122 | |
---|
| 123 | ncio_movefunc *NCIO_CONST move; |
---|
| 124 | |
---|
| 125 | ncio_syncfunc *NCIO_CONST sync; |
---|
| 126 | |
---|
| 127 | ncio_pad_lengthfunc *NCIO_CONST pad_length; |
---|
| 128 | |
---|
| 129 | ncio_filesizefunc *NCIO_CONST filesize; |
---|
| 130 | |
---|
| 131 | ncio_closefunc *NCIO_CONST close; |
---|
| 132 | |
---|
| 133 | /* |
---|
| 134 | * A copy of the 'path' argument passed in to ncio_open() |
---|
| 135 | * or ncio_create(). Used by ncabort() to remove (unlink) |
---|
| 136 | * the file and by error messages. |
---|
| 137 | */ |
---|
| 138 | const char *path; |
---|
| 139 | |
---|
| 140 | /* implementation private stuff */ |
---|
| 141 | void *pvt; |
---|
| 142 | }; |
---|
| 143 | |
---|
| 144 | #undef NCIO_CONST |
---|
| 145 | |
---|
| 146 | /* Define wrappers around the ncio dispatch table */ |
---|
| 147 | |
---|
| 148 | extern int ncio_rel(ncio* const, off_t, int); |
---|
| 149 | extern int ncio_get(ncio* const, off_t, size_t, int, void** const); |
---|
| 150 | extern int ncio_move(ncio* const, off_t, off_t, size_t, int); |
---|
| 151 | extern int ncio_sync(ncio* const); |
---|
| 152 | extern int ncio_filesize(ncio* const, off_t*); |
---|
| 153 | extern int ncio_pad_length(ncio* const, off_t); |
---|
| 154 | extern int ncio_close(ncio* const, int); |
---|
| 155 | |
---|
| 156 | extern int ncio_create(const char *path, int ioflags, size_t initialsz, |
---|
| 157 | off_t igeto, size_t igetsz, size_t *sizehintp, |
---|
| 158 | ncio** nciopp, void** const mempp); |
---|
| 159 | |
---|
| 160 | extern int ncio_open(const char *path, int ioflags, |
---|
| 161 | off_t igeto, size_t igetsz, size_t *sizehintp, |
---|
| 162 | ncio** nciopp, void** const mempp); |
---|
| 163 | |
---|
| 164 | /* With the advent of diskless io, we need to provide |
---|
| 165 | for multiple ncio packages at the same time, |
---|
| 166 | so we have multiple versions of ncio_create. |
---|
| 167 | If you create a new package, the you must do the following. |
---|
| 168 | 1. add an extern definition for it in ncio.c |
---|
| 169 | 2. modify ncio_create and ncio_open in ncio.c to invoke |
---|
| 170 | the new package when appropriate. |
---|
| 171 | */ |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | |
---|
| 175 | #endif /* _NCIO_H_ */ |
---|