ncio.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright 1996, University Corporation for Atmospheric Research
  3. * See netcdf/COPYRIGHT file for copying and redistribution conditions.
  4. */
  5. #include <config.h>
  6. #include <stdlib.h>
  7. #include "netcdf.h"
  8. #include "ncio.h"
  9. #include "fbits.h"
  10. /* With the advent of diskless io, we need to provide
  11. for multiple ncio packages at the same time,
  12. so we have multiple versions of ncio_create.
  13. */
  14. /* Define known ncio packages */
  15. extern int posixio_create(const char*,int,size_t,off_t,size_t,size_t*,ncio**,void** const);
  16. extern int posixio_open(const char*,int,off_t,size_t,size_t*,ncio**,void** const);
  17. #ifdef USE_FFIO
  18. extern int ffio_create(const char*,int,size_t,off_t,size_t,size_t*,ncio**,void** const);
  19. extern int ffio_open(const char*,int,off_t,size_t,size_t*,ncio**,void** const);
  20. #endif
  21. #ifdef USE_DISKLESS
  22. # ifdef USE_MMAP
  23. extern int mmapio_create(const char*,int,size_t,off_t,size_t,size_t*,ncio**,void** const);
  24. extern int mmapio_open(const char*,int,off_t,size_t,size_t*,ncio**,void** const);
  25. # endif
  26. extern int memio_create(const char*,int,size_t,off_t,size_t,size_t*,ncio**,void** const);
  27. extern int memio_open(const char*,int,off_t,size_t,size_t*,ncio**,void** const);
  28. #endif
  29. int
  30. ncio_create(const char *path, int ioflags, size_t initialsz,
  31. off_t igeto, size_t igetsz, size_t *sizehintp,
  32. ncio** iopp, void** const mempp)
  33. {
  34. #ifdef USE_DISKLESS
  35. if(fIsSet(ioflags,NC_DISKLESS)) {
  36. # ifdef USE_MMAP
  37. if(fIsSet(ioflags,NC_MMAP))
  38. return mmapio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,iopp,mempp);
  39. else
  40. # endif /*USE_MMAP*/
  41. return memio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,iopp,mempp);
  42. }
  43. #endif
  44. #ifdef USE_FFIO
  45. return ffio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,iopp,mempp);
  46. #else
  47. return posixio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,iopp,mempp);
  48. #endif
  49. }
  50. int
  51. ncio_open(const char *path, int ioflags,
  52. off_t igeto, size_t igetsz, size_t *sizehintp,
  53. ncio** iopp, void** const mempp)
  54. {
  55. /* Diskless open has the following constraints:
  56. 1. file must be classic version 1 or 2
  57. */
  58. #ifdef USE_DISKLESS
  59. if(fIsSet(ioflags,NC_DISKLESS)) {
  60. # ifdef USE_MMAP
  61. if(fIsSet(ioflags,NC_MMAP))
  62. return mmapio_open(path,ioflags,igeto,igetsz,sizehintp,iopp,mempp);
  63. else
  64. # endif /*USE_MMAP*/
  65. return memio_open(path,ioflags,igeto,igetsz,sizehintp,iopp,mempp);
  66. }
  67. #endif
  68. #ifdef USE_FFIO
  69. return ffio_open(path,ioflags,igeto,igetsz,sizehintp,iopp,mempp);
  70. #else
  71. return posixio_open(path,ioflags,igeto,igetsz,sizehintp,iopp,mempp);
  72. #endif
  73. }
  74. /**************************************************/
  75. /* wrapper functions for the ncio dispatch table */
  76. int
  77. ncio_rel(ncio *const nciop, off_t offset, int rflags)
  78. {
  79. return nciop->rel(nciop,offset,rflags);
  80. }
  81. int
  82. ncio_get(ncio *const nciop, off_t offset, size_t extent,
  83. int rflags, void **const vpp)
  84. {
  85. return nciop->get(nciop,offset,extent,rflags,vpp);
  86. }
  87. int
  88. ncio_move(ncio *const nciop, off_t to, off_t from, size_t nbytes, int rflags)
  89. {
  90. return nciop->move(nciop,to,from,nbytes,rflags);
  91. }
  92. int
  93. ncio_sync(ncio *const nciop)
  94. {
  95. return nciop->sync(nciop);
  96. }
  97. int
  98. ncio_filesize(ncio *nciop, off_t *filesizep)
  99. {
  100. return nciop->filesize(nciop,filesizep);
  101. }
  102. int
  103. ncio_pad_length(ncio* nciop, off_t length)
  104. {
  105. return nciop->pad_length(nciop,length);
  106. }
  107. int
  108. ncio_close(ncio *nciop, int doUnlink)
  109. {
  110. /* close and release all resources associated
  111. with nciop, including nciop
  112. */
  113. int status = nciop->close(nciop,doUnlink);
  114. return status;
  115. }