ncio.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. #ifndef _NCIO_H_
  7. #define _NCIO_H_
  8. #include <stddef.h> /* size_t */
  9. #include <sys/types.h> /* off_t */
  10. #include "netcdf.h"
  11. typedef struct ncio ncio; /* forward reference */
  12. /*
  13. * A value which is an invalid off_t
  14. */
  15. #define OFF_NONE ((off_t)(-1))
  16. /*
  17. * Flags used by the region layer,
  18. * 'rflags' argument to ncio.rel() and ncio.get().
  19. */
  20. #define RGN_NOLOCK 0x1 /* Don't lock region.
  21. * Used when contention control handled
  22. * elsewhere.
  23. */
  24. #define RGN_NOWAIT 0x2 /* return immediate if can't lock, else wait */
  25. #define RGN_WRITE 0x4 /* we intend to modify, else read only */
  26. #define RGN_MODIFIED 0x8 /* we did modify, else, discard */
  27. /*
  28. * The next four typedefs define the signatures
  29. * of function pointers in struct ncio below.
  30. * They are not used outside of this file and ncio.h,
  31. * They just make some casts in the ncio.c more readable.
  32. */
  33. /*
  34. * Indicate that you are done with the region which begins
  35. * at offset. Only reasonable flag value is RGN_MODIFIED.
  36. */
  37. typedef int ncio_relfunc(ncio *const nciop,
  38. off_t offset, int rflags);
  39. /*
  40. * Request that the region (offset, extent)
  41. * be made available through *vpp.
  42. */
  43. typedef int ncio_getfunc(ncio *const nciop,
  44. off_t offset, size_t extent,
  45. int rflags,
  46. void **const vpp);
  47. /*
  48. * Like memmove(), safely move possibly overlapping data.
  49. * Only reasonable flag value is RGN_NOLOCK.
  50. */
  51. typedef int ncio_movefunc(ncio *const nciop, off_t to, off_t from,
  52. size_t nbytes, int rflags);
  53. /*
  54. * Write out any dirty buffers to disk and
  55. * ensure that next read will get data from disk.
  56. */
  57. typedef int ncio_syncfunc(ncio *const nciop);
  58. /*
  59. * Sync any changes to disk, then truncate or extend file so its size
  60. * is length. This is only intended to be called before close, if the
  61. * file is open for writing and the actual size does not match the
  62. * calculated size, perhaps as the result of having been previously
  63. * written in NOFILL mode.
  64. */
  65. typedef int ncio_pad_lengthfunc(ncio* nciop, off_t length);
  66. /*
  67. * Get file size in bytes.
  68. */
  69. typedef int ncio_filesizefunc(ncio *nciop, off_t *filesizep);
  70. /* Write out any dirty buffers and
  71. ensure that next read will not get cached data.
  72. Sync any changes, then close the open file associated with the ncio
  73. struct, and free its memory.
  74. nciop - pointer to ncio to close.
  75. doUnlink - if true, unlink file
  76. */
  77. typedef int ncio_closefunc(ncio *nciop, int doUnlink);
  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. * netcdf i/o abstraction
  86. */
  87. struct ncio {
  88. /*
  89. * A copy of the ioflags argument passed in to ncio_open()
  90. * or ncio_create().
  91. */
  92. int ioflags;
  93. /*
  94. * The file descriptor of the netcdf file.
  95. * This gets handed to the user as the netcdf id.
  96. */
  97. NCIO_CONST int fd;
  98. /* member functions do the work */
  99. ncio_relfunc *NCIO_CONST rel;
  100. ncio_getfunc *NCIO_CONST get;
  101. ncio_movefunc *NCIO_CONST move;
  102. ncio_syncfunc *NCIO_CONST sync;
  103. ncio_pad_lengthfunc *NCIO_CONST pad_length;
  104. ncio_filesizefunc *NCIO_CONST filesize;
  105. ncio_closefunc *NCIO_CONST close;
  106. /*
  107. * A copy of the 'path' argument passed in to ncio_open()
  108. * or ncio_create(). Used by ncabort() to remove (unlink)
  109. * the file and by error messages.
  110. */
  111. const char *path;
  112. /* implementation private stuff */
  113. void *pvt;
  114. };
  115. #undef NCIO_CONST
  116. /* Define wrappers around the ncio dispatch table */
  117. extern int ncio_rel(ncio* const, off_t, int);
  118. extern int ncio_get(ncio* const, off_t, size_t, int, void** const);
  119. extern int ncio_move(ncio* const, off_t, off_t, size_t, int);
  120. extern int ncio_sync(ncio* const);
  121. extern int ncio_filesize(ncio* const, off_t*);
  122. extern int ncio_pad_length(ncio* const, off_t);
  123. extern int ncio_close(ncio* const, int);
  124. extern int ncio_create(const char *path, int ioflags, size_t initialsz,
  125. off_t igeto, size_t igetsz, size_t *sizehintp,
  126. ncio** nciopp, void** const mempp);
  127. extern int ncio_open(const char *path, int ioflags,
  128. off_t igeto, size_t igetsz, size_t *sizehintp,
  129. ncio** nciopp, void** const mempp);
  130. /* With the advent of diskless io, we need to provide
  131. for multiple ncio packages at the same time,
  132. so we have multiple versions of ncio_create.
  133. If you create a new package, the you must do the following.
  134. 1. add an extern definition for it in ncio.c
  135. 2. modify ncio_create and ncio_open in ncio.c to invoke
  136. the new package when appropriate.
  137. */
  138. #endif /* _NCIO_H_ */