netcdf-c/libsrc/ncio.c
Dennis Heimbigner 3db4f013bf Primary change: add dap4 support
Specific changes:
1. Add dap4 code: libdap4 and dap4_test.
   Note that until the d4ts server problem is solved, dap4 is turned off.
2. Modify various files to support dap4 flags:
	configure.ac, Makefile.am, CMakeLists.txt, etc.
3. Add nc_test/test_common.sh. This centralizes
   the handling of the locations of various
   things in the build tree: e.g. where is
   ncgen.exe located. See nc_test/test_common.sh
   for details.
4. Modify .sh files to use test_common.sh
5. Obsolete separate oc2 by moving it to be part of
   netcdf-c. This means replacing code with netcdf-c
   equivalents.
5. Add --with-testserver to configure.ac to allow
   override of the servers to be used for --enable-dap-remote-tests.
6. There were multiple versions of nctypealignment code. Try to
   centralize in libdispatch/doffset.c and include/ncoffsets.h
7. Add a unit test for the ncuri code because of its complexity.
8. Move the findserver code out of libdispatch and into
   a separate, self contained program in ncdap_test and dap4_test.
9. Move the dispatch header files (nc{3,4}dispatch.h) to
   .../include because they are now shared by modules.
10. Revamp the handling of TOPSRCDIR and TOPBUILDDIR for shell scripts.
11. Make use of MREMAP if available
12. Misc. minor changes e.g.
	- #include <config.h> -> #include "config.h"
	- Add some no-install headers to /include
	- extern -> EXTERNL and vice versa as needed
	- misc header cleanup
	- clean up checking for misc. unix vs microsoft functions
13. Change copyright decls in some files to point to LICENSE file.
14. Add notes to RELEASENOTES.md
2017-03-08 17:01:10 -07:00

142 lines
4.2 KiB
C

/*
* Copyright 1996, University Corporation for Atmospheric Research
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
*/
#include "config.h"
#include <stdlib.h>
#include "netcdf.h"
#include "ncio.h"
#include "fbits.h"
/* With the advent of diskless io, we need to provide
for multiple ncio packages at the same time,
so we have multiple versions of ncio_create.
*/
/* Define known ncio packages */
extern int posixio_create(const char*,int,size_t,off_t,size_t,size_t*,void*,ncio**,void** const);
extern int posixio_open(const char*,int,off_t,size_t,size_t*,void*,ncio**,void** const);
extern int stdio_create(const char*,int,size_t,off_t,size_t,size_t*,void*,ncio**,void** const);
extern int stdio_open(const char*,int,off_t,size_t,size_t*,void*,ncio**,void** const);
#ifdef USE_FFIO
extern int ffio_create(const char*,int,size_t,off_t,size_t,size_t*,void*,ncio**,void** const);
extern int ffio_open(const char*,int,off_t,size_t,size_t*,void*,ncio**,void** const);
#endif
#ifdef USE_DISKLESS
# ifdef USE_MMAP
extern int mmapio_create(const char*,int,size_t,off_t,size_t,size_t*,void*,ncio**,void** const);
extern int mmapio_open(const char*,int,off_t,size_t,size_t*,void*,ncio**,void** const);
# endif
extern int memio_create(const char*,int,size_t,off_t,size_t,size_t*,void*,ncio**,void** const);
extern int memio_open(const char*,int,off_t,size_t,size_t*,void*,ncio**,void** const);
#endif
int
ncio_create(const char *path, int ioflags, size_t initialsz,
off_t igeto, size_t igetsz, size_t *sizehintp,
void* parameters,
ncio** iopp, void** const mempp)
{
#ifdef USE_DISKLESS
if(fIsSet(ioflags,NC_DISKLESS)) {
# ifdef USE_MMAP
if(fIsSet(ioflags,NC_MMAP))
return mmapio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
else
# endif /*USE_MMAP*/
return memio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
}
#endif
#ifdef USE_STDIO
return stdio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
#elif defined(USE_FFIO)
return ffio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
#else
return posixio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
#endif
}
int
ncio_open(const char *path, int ioflags,
off_t igeto, size_t igetsz, size_t *sizehintp,
void* parameters,
ncio** iopp, void** const mempp)
{
/* Diskless open has the following constraints:
1. file must be classic version 1 or 2
*/
#ifdef USE_DISKLESS
if(fIsSet(ioflags,NC_DISKLESS)) {
# ifdef USE_MMAP
if(fIsSet(ioflags,NC_MMAP))
return mmapio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
else
# endif /*USE_MMAP*/
return memio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
}
#endif
#ifdef USE_STDIO
return stdio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
#elif defined(USE_FFIO)
return ffio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
#else
return posixio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
#endif
}
/**************************************************/
/* wrapper functions for the ncio dispatch table */
int
ncio_rel(ncio* const nciop, off_t offset, int rflags)
{
return nciop->rel(nciop,offset,rflags);
}
int
ncio_get(ncio* const nciop, off_t offset, size_t extent,
int rflags, void **const vpp)
{
return nciop->get(nciop,offset,extent,rflags,vpp);
}
int
ncio_move(ncio* const nciop, off_t to, off_t from, size_t nbytes, int rflags)
{
return nciop->move(nciop,to,from,nbytes,rflags);
}
int
ncio_sync(ncio* const nciop)
{
return nciop->sync(nciop);
}
int
ncio_filesize(ncio* const nciop, off_t *filesizep)
{
return nciop->filesize(nciop,filesizep);
}
int
ncio_pad_length(ncio* const nciop, off_t length)
{
return nciop->pad_length(nciop,length);
}
int
ncio_close(ncio* const nciop, int doUnlink)
{
/* close and release all resources associated
with nciop, including nciop
*/
int status = nciop->close(nciop,doUnlink);
return status;
}