2012-03-26 09:34:32 +08:00
|
|
|
/*
|
|
|
|
* 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 */
|
2015-05-29 05:03:02 +08:00
|
|
|
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);
|
2012-03-26 09:34:32 +08:00
|
|
|
|
2015-08-20 07:14:13 +08:00
|
|
|
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);
|
|
|
|
|
2012-04-13 10:41:00 +08:00
|
|
|
#ifdef USE_FFIO
|
2015-05-29 05:03:02 +08:00
|
|
|
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);
|
2012-04-13 10:41:00 +08:00
|
|
|
#endif
|
|
|
|
|
2012-05-15 11:13:08 +08:00
|
|
|
#ifdef USE_DISKLESS
|
|
|
|
# ifdef USE_MMAP
|
2015-05-29 05:03:02 +08:00
|
|
|
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);
|
2012-06-24 03:25:49 +08:00
|
|
|
# endif
|
2015-05-29 05:03:02 +08:00
|
|
|
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);
|
2012-04-13 10:41:00 +08:00
|
|
|
#endif
|
2012-03-26 09:34:32 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
ncio_create(const char *path, int ioflags, size_t initialsz,
|
|
|
|
off_t igeto, size_t igetsz, size_t *sizehintp,
|
2015-05-29 05:03:02 +08:00
|
|
|
void* parameters,
|
2012-03-26 09:34:32 +08:00
|
|
|
ncio** iopp, void** const mempp)
|
|
|
|
{
|
2012-05-15 11:13:08 +08:00
|
|
|
#ifdef USE_DISKLESS
|
2012-06-24 03:25:49 +08:00
|
|
|
if(fIsSet(ioflags,NC_DISKLESS)) {
|
2012-05-15 11:13:08 +08:00
|
|
|
# ifdef USE_MMAP
|
2012-06-24 03:25:49 +08:00
|
|
|
if(fIsSet(ioflags,NC_MMAP))
|
2015-05-29 05:03:02 +08:00
|
|
|
return mmapio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
2012-06-24 03:25:49 +08:00
|
|
|
else
|
|
|
|
# endif /*USE_MMAP*/
|
2015-05-29 05:03:02 +08:00
|
|
|
return memio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
2012-06-24 03:25:49 +08:00
|
|
|
}
|
2012-04-13 10:41:00 +08:00
|
|
|
#endif
|
|
|
|
|
2015-08-20 07:14:13 +08:00
|
|
|
#ifdef USE_STDIO
|
|
|
|
return stdio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
|
|
#elif defined(USE_FFIO)
|
2015-05-29 05:03:02 +08:00
|
|
|
return ffio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
2012-03-26 09:34:32 +08:00
|
|
|
#else
|
2015-05-29 05:03:02 +08:00
|
|
|
return posixio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
2012-03-26 09:34:32 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ncio_open(const char *path, int ioflags,
|
|
|
|
off_t igeto, size_t igetsz, size_t *sizehintp,
|
2015-05-29 05:03:02 +08:00
|
|
|
void* parameters,
|
2012-03-26 09:34:32 +08:00
|
|
|
ncio** iopp, void** const mempp)
|
|
|
|
{
|
2012-04-09 06:47:38 +08:00
|
|
|
/* Diskless open has the following constraints:
|
|
|
|
1. file must be classic version 1 or 2
|
|
|
|
*/
|
2012-05-15 11:13:08 +08:00
|
|
|
#ifdef USE_DISKLESS
|
2012-04-09 06:47:38 +08:00
|
|
|
if(fIsSet(ioflags,NC_DISKLESS)) {
|
2012-05-15 11:13:08 +08:00
|
|
|
# ifdef USE_MMAP
|
2012-06-24 03:25:49 +08:00
|
|
|
if(fIsSet(ioflags,NC_MMAP))
|
2015-05-29 05:03:02 +08:00
|
|
|
return mmapio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
2012-06-24 03:25:49 +08:00
|
|
|
else
|
|
|
|
# endif /*USE_MMAP*/
|
2015-05-29 05:03:02 +08:00
|
|
|
return memio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
2012-04-09 06:47:38 +08:00
|
|
|
}
|
2012-05-15 11:13:08 +08:00
|
|
|
#endif
|
2015-08-20 07:14:13 +08:00
|
|
|
#ifdef USE_STDIO
|
|
|
|
return stdio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
|
|
#elif defined(USE_FFIO)
|
2015-05-29 05:03:02 +08:00
|
|
|
return ffio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
2012-03-26 09:34:32 +08:00
|
|
|
#else
|
2015-05-29 05:03:02 +08:00
|
|
|
return posixio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
2012-03-26 09:34:32 +08:00
|
|
|
#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 *nciop, off_t *filesizep)
|
|
|
|
{
|
|
|
|
return nciop->filesize(nciop,filesizep);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ncio_pad_length(ncio* nciop, off_t length)
|
|
|
|
{
|
|
|
|
return nciop->pad_length(nciop,length);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ncio_close(ncio *nciop, int doUnlink)
|
|
|
|
{
|
|
|
|
/* close and release all resources associated
|
|
|
|
with nciop, including nciop
|
|
|
|
*/
|
|
|
|
int status = nciop->close(nciop,doUnlink);
|
|
|
|
return status;
|
|
|
|
}
|