mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-12-21 08:39:46 +08:00
4636584d5b
re: https://github.com/Unidata/netcdf-c/issues/1154 Inadvertently, the behavior of NC_DISKLESS with nc_create() was changed in release 4.6.1. Previously, the NC_WRITE flag needed to be explicitly used with NC_DISKLESS in order to cause the created file to be persisted to disk. Additional analyis indicated that the current NC_DISKLESS implementation was seriously flawed. This PR attempts to clean up and regularize the situation with respect to NC_DISKLESS control. One important aspect of diskless operation is that there are two different notions of write. 1. The file is read-write vs read-only when using the netcdf API. 2. The file is persisted or not to disk at nc_close(). Previously, these two were conflated. The rules now are as follows. 1. NC_DISKLESS + NC_WRITE means that the file is read/write using the netcdf API 2. NC_DISKLESS + NC_PERSIST means that the file is persisted to a disk file at nc_close. 3. NC_DISKLESS + NC_PERSIST + NC_WRITE means both 1 and 2. The NC_PERSIST flag is new and takes over the obsolete NC_MPIPOSIX flag. NC_MPIPOSIX is still defined, but is now an alias for the NC_MPIIO flag. It is also now the case that for netcdf-4, NC_DISKLESS is independent of NC_INMEMORY and in fact it is an error to specify both flags simultaneously. Finally, the MMAP code was fixed to use NC_PERSIST as well. Also marked MMAP as deprecated. Also added a test case to test various combinations of NC_DISKLESS, NC_PERSIST, and NC_WRITE. This PR affects a number of files and especially test cases that used NC_DISKLESS. Misc. Unrelated fixes 1. fixed some warnings in ncdump/dumplib.c
144 lines
4.4 KiB
C
144 lines
4.4 KiB
C
/*
|
|
* Copyright 1996, University Corporation for Atmospheric Research
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
*/
|
|
|
|
#if HAVE_CONFIG_H
|
|
#include <config.h>
|
|
#endif
|
|
|
|
#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_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);
|
|
|
|
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)
|
|
{
|
|
if(fIsSet(ioflags,NC_DISKLESS)) {
|
|
return memio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
} else if(fIsSet(ioflags,NC_INMEMORY)) {
|
|
return memio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
}
|
|
# ifdef USE_MMAP
|
|
else if(fIsSet(ioflags,NC_MMAP)) {
|
|
return mmapio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
}
|
|
# endif /*USE_MMAP*/
|
|
|
|
#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 or 5
|
|
*/
|
|
if(fIsSet(ioflags,NC_DISKLESS)) {
|
|
return memio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
}
|
|
if(fIsSet(ioflags,NC_INMEMORY)) {
|
|
return memio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
}
|
|
# ifdef USE_MMAP
|
|
if(fIsSet(ioflags,NC_MMAP)) {
|
|
return mmapio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
}
|
|
# endif /*USE_MMAP*/
|
|
#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;
|
|
}
|