2003-03-20 07:29:23 +08:00
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2007-02-07 22:56:24 +08:00
|
|
|
|
* Copyright by The HDF Group. *
|
2003-03-20 07:29:23 +08:00
|
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
|
* All rights reserved. *
|
|
|
|
|
* *
|
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
|
|
|
|
* the files COPYING and Copyright.html. COPYING can be found at the root *
|
|
|
|
|
* of the source code distribution tree; Copyright.html can be found at the *
|
|
|
|
|
* root level of an installed copy of the electronic HDF5 document set and *
|
|
|
|
|
* is linked from the top-level documents page. It can also be found at *
|
2007-02-07 22:56:24 +08:00
|
|
|
|
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
|
|
|
|
|
* access to either file, you may request a copy from help@hdfgroup.org. *
|
2003-03-20 07:29:23 +08:00
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Programmer: Robb Matzke <matzke@llnl.gov>
|
|
|
|
|
* Wednesday, October 22, 1997
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* Purpose: The C STDIO virtual file driver which only uses calls from stdio.h.
|
|
|
|
|
* This also serves as an example of coding a simple file driver,
|
|
|
|
|
* therefore, it should not use any non-public definitions.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* NOTE: This driver is not as well tested as the standard SEC2 driver
|
|
|
|
|
* and is not intended for production use!
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*/
|
|
|
|
|
#include <assert.h>
|
2012-03-31 05:42:47 +08:00
|
|
|
|
#include <stdio.h>
|
1999-10-21 01:51:03 +08:00
|
|
|
|
#include <stdlib.h>
|
2005-03-05 01:01:02 +08:00
|
|
|
|
#include <string.h>
|
1999-10-21 01:51:03 +08:00
|
|
|
|
#include <sys/stat.h>
|
1999-10-29 23:57:26 +08:00
|
|
|
|
|
2001-06-19 04:22:10 +08:00
|
|
|
|
#include "hdf5.h"
|
|
|
|
|
|
1999-11-17 03:08:14 +08:00
|
|
|
|
#ifdef H5_HAVE_UNISTD_H
|
1999-10-21 01:51:03 +08:00
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#endif
|
2001-06-08 00:03:02 +08:00
|
|
|
|
|
2011-09-07 00:50:32 +08:00
|
|
|
|
#ifdef H5_HAVE_WIN32_API
|
2012-03-29 06:00:41 +08:00
|
|
|
|
/* The following two defines must be before any windows headers are included */
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
|
|
|
|
|
#define NOGDI /* Exclude Graphic Display Interface macros */
|
|
|
|
|
|
2001-07-10 00:04:44 +08:00
|
|
|
|
#include <windows.h>
|
2001-06-30 03:49:53 +08:00
|
|
|
|
#include <io.h>
|
2003-08-26 23:03:03 +08:00
|
|
|
|
|
|
|
|
|
/* This is not defined in the Windows header files */
|
|
|
|
|
#ifndef F_OK
|
|
|
|
|
#define F_OK 00
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-07-03 22:49:03 +08:00
|
|
|
|
#endif
|
2001-06-22 04:04:36 +08:00
|
|
|
|
|
1999-10-21 01:51:03 +08:00
|
|
|
|
#ifdef MAX
|
|
|
|
|
#undef MAX
|
|
|
|
|
#endif /* MAX */
|
2011-09-07 00:50:32 +08:00
|
|
|
|
#define MAX(X,Y) ((X)>(Y)?(X):(Y))
|
2001-06-19 04:22:10 +08:00
|
|
|
|
|
1999-10-21 01:51:03 +08:00
|
|
|
|
/* The driver identification number, initialized at runtime */
|
|
|
|
|
static hid_t H5FD_STDIO_g = 0;
|
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* The maximum number of bytes which can be written in a single I/O operation */
|
|
|
|
|
static size_t H5_STDIO_MAX_IO_BYTES_g = (size_t)-1;
|
|
|
|
|
|
1999-10-21 01:51:03 +08:00
|
|
|
|
/* File operations */
|
|
|
|
|
typedef enum {
|
|
|
|
|
H5FD_STDIO_OP_UNKNOWN=0,
|
|
|
|
|
H5FD_STDIO_OP_READ=1,
|
|
|
|
|
H5FD_STDIO_OP_WRITE=2,
|
|
|
|
|
H5FD_STDIO_OP_SEEK=3
|
|
|
|
|
} H5FD_stdio_file_op;
|
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* The description of a file belonging to this driver. The 'eoa' and 'eof'
|
1999-10-21 01:51:03 +08:00
|
|
|
|
* determine the amount of hdf5 address space in use and the high-water mark
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* of the file (the current size of the underlying Unix file). The 'pos'
|
1999-10-21 01:51:03 +08:00
|
|
|
|
* value is used to eliminate file position updates when they would be a
|
|
|
|
|
* no-op. Unfortunately we've found systems that use separate file position
|
|
|
|
|
* indicators for reading and writing so the lseek can only be eliminated if
|
|
|
|
|
* the current operation is the same as the previous operation. When opening
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* a file the 'eof' will be set to the current file size, 'eoa' will be set
|
|
|
|
|
* to zero, 'pos' will be set to H5F_ADDR_UNDEF (as it is when an error
|
|
|
|
|
* occurs), and 'op' will be set to H5F_OP_UNKNOWN.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*/
|
|
|
|
|
typedef struct H5FD_stdio_t {
|
2012-03-31 05:42:47 +08:00
|
|
|
|
H5FD_t pub; /* public stuff, must be first */
|
|
|
|
|
FILE *fp; /* the file handle */
|
|
|
|
|
int fd; /* file descriptor (for truncate) */
|
|
|
|
|
haddr_t eoa; /* end of allocated region */
|
|
|
|
|
haddr_t eof; /* end of file; current file size */
|
|
|
|
|
haddr_t pos; /* current file I/O position */
|
|
|
|
|
unsigned write_access; /* Flag to indicate the file was opened with write access */
|
|
|
|
|
H5FD_stdio_file_op op; /* last operation */
|
2011-09-07 00:50:32 +08:00
|
|
|
|
#ifndef H5_HAVE_WIN32_API
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* On most systems the combination of device and i-node number uniquely
|
|
|
|
|
* identify a file. Note that Cygwin, MinGW and other Windows POSIX
|
|
|
|
|
* environments have the stat function (which fakes inodes)
|
|
|
|
|
* and will use the 'device + inodes' scheme as opposed to the
|
|
|
|
|
* Windows code further below.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*/
|
2012-03-31 05:42:47 +08:00
|
|
|
|
dev_t device; /* file device number */
|
|
|
|
|
#ifdef H5_VMS
|
|
|
|
|
ino_t inode[3]; /* file i-node number */
|
|
|
|
|
#else
|
|
|
|
|
ino_t inode; /* file i-node number */
|
|
|
|
|
#endif /* H5_VMS */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
#else
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Files in windows are uniquely identified by the volume serial
|
|
|
|
|
* number and the file index (both low and high parts).
|
|
|
|
|
*
|
|
|
|
|
* There are caveats where these numbers can change, especially
|
|
|
|
|
* on FAT file systems. On NTFS, however, a file should keep
|
|
|
|
|
* those numbers the same until renamed or deleted (though you
|
|
|
|
|
* can use ReplaceFile() on NTFS to keep the numbers the same
|
|
|
|
|
* while renaming).
|
|
|
|
|
*
|
|
|
|
|
* See the MSDN "BY_HANDLE_FILE_INFORMATION Structure" entry for
|
|
|
|
|
* more information.
|
|
|
|
|
*
|
|
|
|
|
* http://msdn.microsoft.com/en-us/library/aa363788(v=VS.85).aspx
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*/
|
2012-03-31 05:42:47 +08:00
|
|
|
|
DWORD nFileIndexLow;
|
|
|
|
|
DWORD nFileIndexHigh;
|
|
|
|
|
DWORD dwVolumeSerialNumber;
|
|
|
|
|
|
|
|
|
|
HANDLE hFile; /* Native windows file handle */
|
|
|
|
|
#endif /* H5_HAVE_WIN32_API */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
} H5FD_stdio_t;
|
|
|
|
|
|
2010-08-07 03:47:42 +08:00
|
|
|
|
/* Use similar structure as in H5private.h by defining Windows stuff first. */
|
2011-09-07 00:50:32 +08:00
|
|
|
|
#ifdef H5_HAVE_WIN32_API
|
2012-03-31 05:42:47 +08:00
|
|
|
|
#ifndef H5_HAVE_MINGW
|
|
|
|
|
#define file_fseek _fseeki64
|
|
|
|
|
#define file_offset_t __int64
|
|
|
|
|
#define file_ftruncate _chsize_s /* Supported in VS 2005 or newer */
|
|
|
|
|
#define file_ftell _ftelli64
|
|
|
|
|
#endif /* H5_HAVE_MINGW */
|
|
|
|
|
#endif /* H5_HAVE_WIN32_API */
|
2010-08-07 03:47:42 +08:00
|
|
|
|
|
|
|
|
|
/* Use file_xxx to indicate these are local macros, avoiding confusing
|
|
|
|
|
* with the global HD_xxx macros.
|
|
|
|
|
* Assume fseeko, which is POSIX standard, is always supported;
|
|
|
|
|
* but prefer to use fseeko64 if supported.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef file_fseek
|
|
|
|
|
#ifdef H5_HAVE_FSEEKO64
|
2012-03-31 05:42:47 +08:00
|
|
|
|
#define file_fseek fseeko64
|
|
|
|
|
#define file_offset_t off64_t
|
|
|
|
|
#define file_ftruncate ftruncate64
|
|
|
|
|
#define file_ftell ftello64
|
2010-08-07 03:47:42 +08:00
|
|
|
|
#else
|
2012-03-31 05:42:47 +08:00
|
|
|
|
#define file_fseek fseeko
|
|
|
|
|
#define file_offset_t off_t
|
|
|
|
|
#define file_ftruncate ftruncate
|
|
|
|
|
#define file_ftell ftello
|
|
|
|
|
#endif /* H5_HAVE_FSEEKO64 */
|
|
|
|
|
#endif /* file_fseek */
|
|
|
|
|
|
|
|
|
|
/* These macros check for overflow of various quantities. These macros
|
1999-10-21 01:51:03 +08:00
|
|
|
|
* assume that file_offset_t is signed and haddr_t and size_t are unsigned.
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* ADDR_OVERFLOW: Checks whether a file address of type `haddr_t'
|
|
|
|
|
* is too large to be represented by the second argument
|
|
|
|
|
* of the file seek function.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* SIZE_OVERFLOW: Checks whether a buffer size of type `hsize_t' is too
|
|
|
|
|
* large to be represented by the `size_t' type.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* REGION_OVERFLOW: Checks whether an address and size pair describe data
|
|
|
|
|
* which can be addressed entirely by the second
|
|
|
|
|
* argument of the file seek function.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*/
|
2000-12-23 02:54:16 +08:00
|
|
|
|
/* adding for windows NT filesystem support. */
|
2003-08-26 23:03:03 +08:00
|
|
|
|
#define MAXADDR (((haddr_t)1<<(8*sizeof(file_offset_t)-1))-1)
|
2011-09-07 00:50:32 +08:00
|
|
|
|
#define ADDR_OVERFLOW(A) (HADDR_UNDEF==(A) || ((A) & ~(haddr_t)MAXADDR))
|
|
|
|
|
#define SIZE_OVERFLOW(Z) ((Z) & ~(hsize_t)MAXADDR)
|
|
|
|
|
#define REGION_OVERFLOW(A,Z) (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || \
|
2003-08-26 23:03:03 +08:00
|
|
|
|
HADDR_UNDEF==(A)+(Z) || (file_offset_t)((A)+(Z))<(file_offset_t)(A))
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
|
|
|
|
/* Prototypes */
|
2011-04-21 21:55:52 +08:00
|
|
|
|
static herr_t H5FD_stdio_term(void);
|
1999-10-21 01:51:03 +08:00
|
|
|
|
static H5FD_t *H5FD_stdio_open(const char *name, unsigned flags,
|
|
|
|
|
hid_t fapl_id, haddr_t maxaddr);
|
|
|
|
|
static herr_t H5FD_stdio_close(H5FD_t *lf);
|
|
|
|
|
static int H5FD_stdio_cmp(const H5FD_t *_f1, const H5FD_t *_f2);
|
2000-09-01 03:33:58 +08:00
|
|
|
|
static herr_t H5FD_stdio_query(const H5FD_t *_f1, unsigned long *flags);
|
2007-04-05 03:59:00 +08:00
|
|
|
|
static haddr_t H5FD_stdio_alloc(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, hsize_t size);
|
2007-01-13 04:29:43 +08:00
|
|
|
|
static haddr_t H5FD_stdio_get_eoa(const H5FD_t *_file, H5FD_mem_t type);
|
|
|
|
|
static herr_t H5FD_stdio_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t addr);
|
2005-04-19 05:21:35 +08:00
|
|
|
|
static haddr_t H5FD_stdio_get_eof(const H5FD_t *_file);
|
2002-10-01 00:31:55 +08:00
|
|
|
|
static herr_t H5FD_stdio_get_handle(H5FD_t *_file, hid_t fapl, void** file_handle);
|
2000-10-25 02:18:09 +08:00
|
|
|
|
static herr_t H5FD_stdio_read(H5FD_t *lf, H5FD_mem_t type, hid_t fapl_id, haddr_t addr,
|
2001-07-11 05:19:18 +08:00
|
|
|
|
size_t size, void *buf);
|
2000-09-01 03:33:58 +08:00
|
|
|
|
static herr_t H5FD_stdio_write(H5FD_t *lf, H5FD_mem_t type, hid_t fapl_id, haddr_t addr,
|
2001-07-11 05:19:18 +08:00
|
|
|
|
size_t size, const void *buf);
|
2003-02-11 01:26:09 +08:00
|
|
|
|
static herr_t H5FD_stdio_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing);
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
static herr_t H5FD_stdio_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
|
|
|
|
static const H5FD_class_t H5FD_stdio_g = {
|
2012-03-31 05:42:47 +08:00
|
|
|
|
"stdio", /* name */
|
|
|
|
|
MAXADDR, /* maxaddr */
|
|
|
|
|
H5F_CLOSE_WEAK, /* fc_degree */
|
|
|
|
|
H5FD_stdio_term, /* terminate */
|
|
|
|
|
NULL, /* sb_size */
|
|
|
|
|
NULL, /* sb_encode */
|
|
|
|
|
NULL, /* sb_decode */
|
|
|
|
|
0, /* fapl_size */
|
|
|
|
|
NULL, /* fapl_get */
|
|
|
|
|
NULL, /* fapl_copy */
|
|
|
|
|
NULL, /* fapl_free */
|
|
|
|
|
0, /* dxpl_size */
|
|
|
|
|
NULL, /* dxpl_copy */
|
|
|
|
|
NULL, /* dxpl_free */
|
|
|
|
|
H5FD_stdio_open, /* open */
|
|
|
|
|
H5FD_stdio_close, /* close */
|
|
|
|
|
H5FD_stdio_cmp, /* cmp */
|
|
|
|
|
H5FD_stdio_query, /* query */
|
|
|
|
|
NULL, /* get_type_map */
|
|
|
|
|
H5FD_stdio_alloc, /* alloc */
|
|
|
|
|
NULL, /* free */
|
|
|
|
|
H5FD_stdio_get_eoa, /* get_eoa */
|
|
|
|
|
H5FD_stdio_set_eoa, /* set_eoa */
|
|
|
|
|
H5FD_stdio_get_eof, /* get_eof */
|
|
|
|
|
H5FD_stdio_get_handle, /* get_handle */
|
|
|
|
|
H5FD_stdio_read, /* read */
|
|
|
|
|
H5FD_stdio_write, /* write */
|
|
|
|
|
H5FD_stdio_flush, /* flush */
|
|
|
|
|
H5FD_stdio_truncate, /* truncate */
|
|
|
|
|
NULL, /* lock */
|
|
|
|
|
NULL, /* unlock */
|
2012-08-14 04:04:20 +08:00
|
|
|
|
H5FD_FLMAP_DICHOTOMY /* fl_map */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Function: H5FD_stdio_init
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Purpose: Initialize this driver by registering the driver with the
|
|
|
|
|
* library.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Return: Success: The driver ID for the stdio driver.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Failure: Negative.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Programmer: Robb Matzke
|
1999-10-21 01:51:03 +08:00
|
|
|
|
* Thursday, July 29, 1999
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
hid_t
|
|
|
|
|
H5FD_stdio_init(void)
|
|
|
|
|
{
|
1999-10-23 08:36:04 +08:00
|
|
|
|
/* Clear the error stack */
|
2007-04-12 09:59:45 +08:00
|
|
|
|
H5Eclear2(H5E_DEFAULT);
|
1999-10-23 08:36:04 +08:00
|
|
|
|
|
1999-10-21 01:51:03 +08:00
|
|
|
|
if (H5I_VFL!=H5Iget_type(H5FD_STDIO_g))
|
|
|
|
|
H5FD_STDIO_g = H5FDregister(&H5FD_stdio_g);
|
2012-03-31 05:42:47 +08:00
|
|
|
|
return H5FD_STDIO_g;
|
|
|
|
|
} /* end H5FD_stdio_init() */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
2004-01-31 23:19:48 +08:00
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Function: H5FD_stdio_term
|
2004-01-31 23:19:48 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Purpose: Shut down the VFD
|
2004-01-31 23:19:48 +08:00
|
|
|
|
*
|
2011-04-21 21:55:52 +08:00
|
|
|
|
* Returns: Non-negative on success or negative on failure
|
2004-01-31 23:19:48 +08:00
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* Friday, Jan 30, 2004
|
|
|
|
|
*
|
|
|
|
|
*---------------------------------------------------------------------------
|
|
|
|
|
*/
|
2011-04-21 21:55:52 +08:00
|
|
|
|
static herr_t
|
2004-01-31 23:19:48 +08:00
|
|
|
|
H5FD_stdio_term(void)
|
|
|
|
|
{
|
|
|
|
|
/* Reset VFL ID */
|
2012-03-31 05:42:47 +08:00
|
|
|
|
H5FD_STDIO_g = 0;
|
2004-01-31 23:19:48 +08:00
|
|
|
|
|
2011-04-21 21:55:52 +08:00
|
|
|
|
return 0;
|
2004-01-31 23:19:48 +08:00
|
|
|
|
} /* end H5FD_stdio_term() */
|
|
|
|
|
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Function: H5Pset_fapl_stdio
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Purpose: Modify the file access property list to use the H5FD_STDIO
|
|
|
|
|
* driver defined in this source file. There are no driver
|
|
|
|
|
* specific properties.
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* Thursday, February 19, 1998
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
herr_t
|
|
|
|
|
H5Pset_fapl_stdio(hid_t fapl_id)
|
|
|
|
|
{
|
2012-03-31 05:42:47 +08:00
|
|
|
|
static const char *func = "H5FDset_fapl_stdio"; /*for error reporting*/
|
1999-11-01 23:21:16 +08:00
|
|
|
|
|
|
|
|
|
/*NO TRACE*/
|
1999-10-23 08:36:04 +08:00
|
|
|
|
|
|
|
|
|
/* Clear the error stack */
|
2007-04-12 09:59:45 +08:00
|
|
|
|
H5Eclear2(H5E_DEFAULT);
|
1999-10-23 08:36:04 +08:00
|
|
|
|
|
2001-11-21 03:07:22 +08:00
|
|
|
|
if(0 == H5Pisa_class(fapl_id, H5P_FILE_ACCESS))
|
2003-08-26 23:03:03 +08:00
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_PLIST, H5E_BADTYPE, "not a file access property list", -1)
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
1999-11-01 23:21:16 +08:00
|
|
|
|
return H5Pset_driver(fapl_id, H5FD_STDIO, NULL);
|
2012-03-31 05:42:47 +08:00
|
|
|
|
} /* end H5Pset_fapl_stdio() */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Function: H5FD_stdio_open
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Purpose: Create and/or opens a Standard C file as an HDF5 file.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
|
|
|
|
* Errors:
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* IO CANTOPENFILE File doesn't exist and CREAT wasn't
|
|
|
|
|
* specified.
|
|
|
|
|
* IO CANTOPENFILE fopen() failed.
|
|
|
|
|
* IO FILEEXISTS File exists but CREAT and EXCL were
|
|
|
|
|
* specified.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* Return:
|
|
|
|
|
* Success: A pointer to a new file data structure. The
|
|
|
|
|
* public fields will be initialized by the
|
|
|
|
|
* caller, which is always H5FD_open().
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* Failure: NULL
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* Wednesday, October 22, 1997
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static H5FD_t *
|
|
|
|
|
H5FD_stdio_open( const char *name, unsigned flags, hid_t fapl_id,
|
|
|
|
|
haddr_t maxaddr)
|
|
|
|
|
{
|
2012-03-31 05:42:47 +08:00
|
|
|
|
FILE *f = NULL;
|
|
|
|
|
unsigned write_access = 0; /* File opened with write access? */
|
|
|
|
|
H5FD_stdio_t *file = NULL;
|
|
|
|
|
static const char *func = "H5FD_stdio_open"; /* Function Name for error reporting */
|
2011-09-07 00:50:32 +08:00
|
|
|
|
#ifdef H5_HAVE_WIN32_API
|
2012-03-31 05:42:47 +08:00
|
|
|
|
struct _BY_HANDLE_FILE_INFORMATION fileinfo;
|
2011-09-07 00:50:32 +08:00
|
|
|
|
#else /* H5_HAVE_WIN32_API */
|
2012-03-31 05:42:47 +08:00
|
|
|
|
struct stat sb;
|
2011-09-07 00:50:32 +08:00
|
|
|
|
#endif /* H5_HAVE_WIN32_API */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
2003-08-26 23:03:03 +08:00
|
|
|
|
/* Sanity check on file offsets */
|
2012-03-31 05:42:47 +08:00
|
|
|
|
assert(sizeof(file_offset_t) >= sizeof(size_t));
|
2003-08-26 23:03:03 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Quiet compiler */
|
|
|
|
|
fapl_id = fapl_id;
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
1999-10-23 08:36:04 +08:00
|
|
|
|
/* Clear the error stack */
|
2007-04-12 09:59:45 +08:00
|
|
|
|
H5Eclear2(H5E_DEFAULT);
|
1999-10-23 08:36:04 +08:00
|
|
|
|
|
1999-10-21 01:51:03 +08:00
|
|
|
|
/* Check arguments */
|
1999-10-23 08:36:04 +08:00
|
|
|
|
if (!name || !*name)
|
2003-08-26 23:03:03 +08:00
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_BADVALUE, "invalid file name", NULL)
|
2012-03-31 05:42:47 +08:00
|
|
|
|
if (0 == maxaddr || HADDR_UNDEF == maxaddr)
|
2003-08-26 23:03:03 +08:00
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_BADRANGE, "bogus maxaddr", NULL)
|
1999-10-23 08:36:04 +08:00
|
|
|
|
if (ADDR_OVERFLOW(maxaddr))
|
2003-08-26 23:03:03 +08:00
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_OVERFLOW, "maxaddr too large", NULL)
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
2013-02-09 04:36:31 +08:00
|
|
|
|
/* Tentatively open file in read-only mode, to check for existence */
|
|
|
|
|
if(flags & H5F_ACC_RDWR)
|
|
|
|
|
f = fopen(name, "rb+");
|
|
|
|
|
else
|
|
|
|
|
f = fopen(name, "rb");
|
|
|
|
|
|
|
|
|
|
if(!f) {
|
|
|
|
|
/* File doesn't exist */
|
|
|
|
|
if(flags & H5F_ACC_CREAT) {
|
|
|
|
|
assert(flags & H5F_ACC_RDWR);
|
1999-10-21 01:51:03 +08:00
|
|
|
|
f = fopen(name, "wb+");
|
2012-03-31 05:42:47 +08:00
|
|
|
|
write_access = 1; /* Note the write access */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
}
|
2003-08-26 23:03:03 +08:00
|
|
|
|
else
|
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_CANTOPENFILE, "file doesn't exist and CREAT wasn't specified", NULL)
|
2013-02-09 04:36:31 +08:00
|
|
|
|
} else if(flags & H5F_ACC_EXCL) {
|
|
|
|
|
/* File exists, but EXCL is passed. Fail. */
|
|
|
|
|
assert(flags & H5F_ACC_CREAT);
|
|
|
|
|
fclose(f);
|
2003-08-26 23:03:03 +08:00
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FILEEXISTS, "file exists but CREAT and EXCL were specified", NULL)
|
2013-02-09 04:36:31 +08:00
|
|
|
|
} else if(flags & H5F_ACC_RDWR) {
|
|
|
|
|
if(flags & H5F_ACC_TRUNC)
|
|
|
|
|
f = freopen(name, "wb+", f);
|
2012-03-31 05:42:47 +08:00
|
|
|
|
write_access = 1; /* Note the write access */
|
2013-02-09 04:36:31 +08:00
|
|
|
|
} /* end if */
|
|
|
|
|
/* Note there is no need to reopen if neither TRUNC nor EXCL are specified,
|
|
|
|
|
* as the tentative open will work */
|
|
|
|
|
|
|
|
|
|
if(!f)
|
2003-08-26 23:03:03 +08:00
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_CANTOPENFILE, "fopen failed", NULL)
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
|
|
|
|
/* Build the return value */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(NULL == (file = (H5FD_stdio_t *)calloc((size_t)1, sizeof(H5FD_stdio_t)))) {
|
|
|
|
|
fclose(f);
|
2003-08-26 23:03:03 +08:00
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_RESOURCE, H5E_NOSPACE, "memory allocation failed", NULL)
|
2009-12-13 13:28:30 +08:00
|
|
|
|
} /* end if */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
file->fp = f;
|
|
|
|
|
file->op = H5FD_STDIO_OP_SEEK;
|
|
|
|
|
file->pos = HADDR_UNDEF;
|
2012-03-31 05:42:47 +08:00
|
|
|
|
file->write_access = write_access; /* Note the write_access for later */
|
2010-08-07 03:47:42 +08:00
|
|
|
|
if(file_fseek(file->fp, (file_offset_t)0, SEEK_END) < 0) {
|
1999-10-21 01:51:03 +08:00
|
|
|
|
file->op = H5FD_STDIO_OP_UNKNOWN;
|
|
|
|
|
} else {
|
2012-03-31 05:42:47 +08:00
|
|
|
|
file_offset_t x = file_ftell(file->fp);
|
|
|
|
|
assert (x >= 0);
|
2003-08-26 23:03:03 +08:00
|
|
|
|
file->eof = (haddr_t)x;
|
1999-10-21 01:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Get the file descriptor (needed for truncate and some Windows information) */
|
2013-07-01 22:23:04 +08:00
|
|
|
|
#ifdef H5_HAVE_WIN32_API
|
|
|
|
|
file->fd = _fileno(file->fp);
|
|
|
|
|
#else /* H5_HAVE_WIN32_API */
|
2012-03-31 05:42:47 +08:00
|
|
|
|
file->fd = fileno(file->fp);
|
2013-07-01 22:23:04 +08:00
|
|
|
|
#endif /* H5_HAVE_WIN32_API */
|
2013-02-25 22:48:42 +08:00
|
|
|
|
if(file->fd < 0) {
|
|
|
|
|
free(file);
|
|
|
|
|
fclose(f);
|
2012-03-31 05:42:47 +08:00
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTOPENFILE, "unable to get file descriptor", NULL);
|
2013-02-25 22:48:42 +08:00
|
|
|
|
} /* end if */
|
2012-03-31 05:42:47 +08:00
|
|
|
|
|
|
|
|
|
|
2011-09-07 00:50:32 +08:00
|
|
|
|
#ifdef H5_HAVE_WIN32_API
|
2012-03-31 05:42:47 +08:00
|
|
|
|
file->hFile = (HANDLE)_get_osfhandle(file->fd);
|
2013-02-25 22:48:42 +08:00
|
|
|
|
if(INVALID_HANDLE_VALUE == file->hFile) {
|
|
|
|
|
free(file);
|
|
|
|
|
fclose(f);
|
2012-03-31 05:42:47 +08:00
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTOPENFILE, "unable to get Windows file handle", NULL);
|
2013-02-25 22:48:42 +08:00
|
|
|
|
} /* end if */
|
2012-03-31 05:42:47 +08:00
|
|
|
|
|
2013-02-25 22:48:42 +08:00
|
|
|
|
if(!GetFileInformationByHandle((HANDLE)file->hFile, &fileinfo)) {
|
|
|
|
|
free(file);
|
|
|
|
|
fclose(f);
|
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTOPENFILE, "unable to get Windows file descriptor information", NULL);
|
|
|
|
|
} /* end if */
|
2012-03-31 05:42:47 +08:00
|
|
|
|
|
|
|
|
|
file->nFileIndexHigh = fileinfo.nFileIndexHigh;
|
|
|
|
|
file->nFileIndexLow = fileinfo.nFileIndexLow;
|
|
|
|
|
file->dwVolumeSerialNumber = fileinfo.dwVolumeSerialNumber;
|
|
|
|
|
#else /* H5_HAVE_WIN32_API */
|
2013-02-25 22:48:42 +08:00
|
|
|
|
if(fstat(file->fd, &sb) < 0) {
|
|
|
|
|
free(file);
|
|
|
|
|
fclose(f);
|
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_BADFILE, "unable to fstat file", NULL)
|
|
|
|
|
} /* end if */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
file->device = sb.st_dev;
|
2012-03-31 05:42:47 +08:00
|
|
|
|
#ifdef H5_VMS
|
|
|
|
|
file->inode[0] = sb.st_ino[0];
|
|
|
|
|
file->inode[1] = sb.st_ino[1];
|
|
|
|
|
file->inode[2] = sb.st_ino[2];
|
|
|
|
|
#else /* H5_VMS */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
file->inode = sb.st_ino;
|
2012-03-31 05:42:47 +08:00
|
|
|
|
#endif /* H5_VMS */
|
|
|
|
|
#endif /* H5_HAVE_WIN32_API */
|
|
|
|
|
|
|
|
|
|
return (H5FD_t*)file;
|
|
|
|
|
} /* end H5FD_stdio_open() */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Function: H5F_stdio_close
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Purpose: Closes a file.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
|
|
|
|
* Errors:
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* IO CLOSEERROR Fclose failed.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* Wednesday, October 22, 1997
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
|
|
|
|
H5FD_stdio_close(H5FD_t *_file)
|
|
|
|
|
{
|
2011-09-07 00:50:32 +08:00
|
|
|
|
H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
|
2012-03-31 05:42:47 +08:00
|
|
|
|
static const char *func = "H5FD_stdio_close"; /* Function Name for error reporting */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
1999-10-23 08:36:04 +08:00
|
|
|
|
/* Clear the error stack */
|
2007-04-12 09:59:45 +08:00
|
|
|
|
H5Eclear2(H5E_DEFAULT);
|
1999-10-23 08:36:04 +08:00
|
|
|
|
|
1999-10-21 01:51:03 +08:00
|
|
|
|
if (fclose(file->fp) < 0)
|
2003-08-26 23:03:03 +08:00
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_CLOSEERROR, "fclose failed", -1)
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
|
|
|
|
free(file);
|
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
return 0;
|
|
|
|
|
} /* end H5FD_stdio_close() */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Function: H5FD_stdio_cmp
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Purpose: Compares two files belonging to this driver using an
|
|
|
|
|
* arbitrary (but consistent) ordering.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* Return:
|
|
|
|
|
* Success: A value like strcmp()
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* Failure: never fails (arguments were checked by the caller).
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Programmer: Robb Matzke
|
1999-10-21 01:51:03 +08:00
|
|
|
|
* Thursday, July 29, 1999
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
H5FD_stdio_cmp(const H5FD_t *_f1, const H5FD_t *_f2)
|
|
|
|
|
{
|
2011-09-07 00:50:32 +08:00
|
|
|
|
const H5FD_stdio_t *f1 = (const H5FD_stdio_t*)_f1;
|
|
|
|
|
const H5FD_stdio_t *f2 = (const H5FD_stdio_t*)_f2;
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
1999-10-23 08:36:04 +08:00
|
|
|
|
/* Clear the error stack */
|
2007-04-12 09:59:45 +08:00
|
|
|
|
H5Eclear2(H5E_DEFAULT);
|
1999-10-23 08:36:04 +08:00
|
|
|
|
|
2011-09-07 00:50:32 +08:00
|
|
|
|
#ifdef H5_HAVE_WIN32_API
|
2012-03-31 05:42:47 +08:00
|
|
|
|
if(f1->dwVolumeSerialNumber < f2->dwVolumeSerialNumber) return -1;
|
|
|
|
|
if(f1->dwVolumeSerialNumber > f2->dwVolumeSerialNumber) return 1;
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
if(f1->nFileIndexHigh < f2->nFileIndexHigh) return -1;
|
|
|
|
|
if(f1->nFileIndexHigh > f2->nFileIndexHigh) return 1;
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
if(f1->nFileIndexLow < f2->nFileIndexLow) return -1;
|
|
|
|
|
if(f1->nFileIndexLow > f2->nFileIndexLow) return 1;
|
|
|
|
|
#else /* H5_HAVE_WIN32_API */
|
2001-07-18 05:27:06 +08:00
|
|
|
|
#ifdef H5_DEV_T_IS_SCALAR
|
2012-03-31 05:42:47 +08:00
|
|
|
|
if(f1->device < f2->device) return -1;
|
|
|
|
|
if(f1->device > f2->device) return 1;
|
2001-07-18 05:27:06 +08:00
|
|
|
|
#else /* H5_DEV_T_IS_SCALAR */
|
|
|
|
|
/* If dev_t isn't a scalar value on this system, just use memcmp to
|
|
|
|
|
* determine if the values are the same or not. The actual return value
|
|
|
|
|
* shouldn't really matter...
|
|
|
|
|
*/
|
2012-03-31 05:42:47 +08:00
|
|
|
|
if(memcmp(&(f1->device),&(f2->device),sizeof(dev_t)) < 0) return -1;
|
|
|
|
|
if(memcmp(&(f1->device),&(f2->device),sizeof(dev_t)) > 0) return 1;
|
2001-07-18 05:27:06 +08:00
|
|
|
|
#endif /* H5_DEV_T_IS_SCALAR */
|
2012-03-31 05:42:47 +08:00
|
|
|
|
#ifdef H5_VMS
|
|
|
|
|
if(memcmp(&(f1->inode), &(f2->inode), 3 * sizeof(ino_t)) < 0) return -1;
|
|
|
|
|
if(memcmp(&(f1->inode), &(f2->inode), 3 * sizeof(ino_t)) > 0) return 1;
|
|
|
|
|
#else /* H5_VMS */
|
|
|
|
|
if(f1->inode < f2->inode) return -1;
|
|
|
|
|
if(f1->inode > f2->inode) return 1;
|
|
|
|
|
#endif /* H5_VMS */
|
|
|
|
|
#endif /* H5_HAVE_WIN32_API */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
2012-03-31 05:42:47 +08:00
|
|
|
|
} /* H5FD_stdio_cmp() */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
2000-09-01 03:33:58 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Function: H5FD_stdio_query
|
2000-09-01 03:33:58 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Purpose: Set the flags that this VFL driver is capable of supporting.
|
2000-12-30 02:35:27 +08:00
|
|
|
|
* (listed in H5FDpublic.h)
|
2000-09-01 03:33:58 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Return: Success: non-negative
|
2000-09-01 03:33:58 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Failure: negative
|
2000-09-01 03:33:58 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Programmer: Quincey Koziol
|
2000-09-01 03:33:58 +08:00
|
|
|
|
* Friday, August 25, 2000
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
|
|
|
|
H5FD_stdio_query(const H5FD_t *_f, unsigned long *flags /* out */)
|
|
|
|
|
{
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Quiet the compiler */
|
2000-09-20 05:08:15 +08:00
|
|
|
|
_f=_f;
|
2000-09-01 03:33:58 +08:00
|
|
|
|
|
|
|
|
|
/* Set the VFL feature flags that this driver supports */
|
|
|
|
|
if(flags) {
|
2000-12-30 02:35:27 +08:00
|
|
|
|
*flags = 0;
|
2000-09-01 03:33:58 +08:00
|
|
|
|
*flags|=H5FD_FEAT_AGGREGATE_METADATA; /* OK to aggregate metadata allocations */
|
|
|
|
|
*flags|=H5FD_FEAT_ACCUMULATE_METADATA; /* OK to accumulate metadata for faster writes */
|
2000-09-27 06:50:18 +08:00
|
|
|
|
*flags|=H5FD_FEAT_DATA_SIEVE; /* OK to perform data sieving for faster raw data reads & writes */
|
2002-06-05 23:23:20 +08:00
|
|
|
|
*flags|=H5FD_FEAT_AGGREGATE_SMALLDATA; /* OK to aggregate "small" raw data allocations */
|
2000-12-30 02:35:27 +08:00
|
|
|
|
}
|
2000-09-01 03:33:58 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
return 0;
|
|
|
|
|
} /* end H5FD_stdio_query() */
|
2000-09-01 03:33:58 +08:00
|
|
|
|
|
2007-04-05 03:59:00 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Function: H5FD_stdio_alloc
|
2007-04-05 03:59:00 +08:00
|
|
|
|
*
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* Purpose: Allocates file memory. If fseeko isn't available, makes
|
2008-09-16 23:52:51 +08:00
|
|
|
|
* sure the file size isn't bigger than 2GB because the
|
2007-04-05 03:59:00 +08:00
|
|
|
|
* parameter OFFSET of fseek is of the type LONG INT, limiting
|
|
|
|
|
* the file size to 2GB.
|
|
|
|
|
*
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* Return:
|
|
|
|
|
* Success: Address of new memory
|
2007-04-05 03:59:00 +08:00
|
|
|
|
*
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* Failure: HADDR_UNDEF
|
2007-04-05 03:59:00 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Programmer: Raymond Lu
|
2007-04-05 03:59:00 +08:00
|
|
|
|
* 30 March 2007
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static haddr_t
|
|
|
|
|
H5FD_stdio_alloc(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxpl_id, hsize_t size)
|
|
|
|
|
{
|
2012-03-31 05:42:47 +08:00
|
|
|
|
H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
|
|
|
|
|
haddr_t addr;
|
2007-04-05 03:59:00 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Quiet compiler */
|
2007-04-11 23:36:06 +08:00
|
|
|
|
type = type;
|
|
|
|
|
dxpl_id = dxpl_id;
|
|
|
|
|
|
2007-04-05 03:59:00 +08:00
|
|
|
|
/* Clear the error stack */
|
2007-04-12 09:59:45 +08:00
|
|
|
|
H5Eclear2(H5E_DEFAULT);
|
2007-04-05 03:59:00 +08:00
|
|
|
|
|
|
|
|
|
/* Compute the address for the block to allocate */
|
|
|
|
|
addr = file->eoa;
|
|
|
|
|
|
|
|
|
|
/* Check if we need to align this block */
|
2007-04-11 23:36:06 +08:00
|
|
|
|
if(size >= file->pub.threshold) {
|
2007-04-05 03:59:00 +08:00
|
|
|
|
/* Check for an already aligned block */
|
2007-04-11 23:36:06 +08:00
|
|
|
|
if((addr % file->pub.alignment) != 0)
|
|
|
|
|
addr = ((addr / file->pub.alignment) + 1) * file->pub.alignment;
|
2007-04-05 03:59:00 +08:00
|
|
|
|
} /* end if */
|
|
|
|
|
|
2007-04-11 23:36:06 +08:00
|
|
|
|
file->eoa = addr + size;
|
2007-04-05 03:59:00 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
return addr;
|
|
|
|
|
} /* end H5FD_stdio_alloc() */
|
2007-04-05 03:59:00 +08:00
|
|
|
|
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Function: H5FD_stdio_get_eoa
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Purpose: Gets the end-of-address marker for the file. The EOA marker
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* is the first address past the last byte allocated in the
|
|
|
|
|
* format address space.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Return: Success: The end-of-address marker.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Failure: HADDR_UNDEF
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Programmer: Robb Matzke
|
1999-10-21 01:51:03 +08:00
|
|
|
|
* Monday, August 2, 1999
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static haddr_t
|
2012-03-31 05:42:47 +08:00
|
|
|
|
H5FD_stdio_get_eoa(const H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type)
|
1999-10-21 01:51:03 +08:00
|
|
|
|
{
|
2012-03-31 05:42:47 +08:00
|
|
|
|
const H5FD_stdio_t *file = (const H5FD_stdio_t *)_file;
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
1999-10-23 08:36:04 +08:00
|
|
|
|
/* Clear the error stack */
|
2007-04-12 09:59:45 +08:00
|
|
|
|
H5Eclear2(H5E_DEFAULT);
|
1999-10-23 08:36:04 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Quiet compiler */
|
2007-02-07 04:03:06 +08:00
|
|
|
|
type = type;
|
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
return file->eoa;
|
|
|
|
|
} /* end H5FD_stdio_get_eoa() */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Function: H5FD_stdio_set_eoa
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Purpose: Set the end-of-address marker for the file. This function is
|
|
|
|
|
* called shortly after an existing HDF5 file is opened in order
|
|
|
|
|
* to tell the driver where the end of the HDF5 data is located.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Return: Success: 0
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* Failure: Does not fail
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Programmer: Robb Matzke
|
1999-10-21 01:51:03 +08:00
|
|
|
|
* Thursday, July 29, 1999
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
2012-03-31 05:42:47 +08:00
|
|
|
|
H5FD_stdio_set_eoa(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, haddr_t addr)
|
1999-10-21 01:51:03 +08:00
|
|
|
|
{
|
2011-09-07 00:50:32 +08:00
|
|
|
|
H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
1999-10-23 08:36:04 +08:00
|
|
|
|
/* Clear the error stack */
|
2007-04-12 09:59:45 +08:00
|
|
|
|
H5Eclear2(H5E_DEFAULT);
|
1999-10-23 08:36:04 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Quiet the compiler */
|
2007-02-07 04:03:06 +08:00
|
|
|
|
type = type;
|
|
|
|
|
|
1999-10-21 01:51:03 +08:00
|
|
|
|
file->eoa = addr;
|
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
return 0;
|
1999-10-21 01:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Function: H5FD_stdio_get_eof
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Purpose: Returns the end-of-file marker, which is the greater of
|
|
|
|
|
* either the Unix end-of-file or the HDF5 end-of-address
|
|
|
|
|
* markers.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Return: Success: End of file address, the first address past
|
|
|
|
|
* the end of the "file", either the Unix file
|
|
|
|
|
* or the HDF5 file.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Failure: HADDR_UNDEF
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Programmer: Robb Matzke
|
1999-10-21 01:51:03 +08:00
|
|
|
|
* Thursday, July 29, 1999
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static haddr_t
|
2005-04-19 05:21:35 +08:00
|
|
|
|
H5FD_stdio_get_eof(const H5FD_t *_file)
|
1999-10-21 01:51:03 +08:00
|
|
|
|
{
|
2011-09-07 00:50:32 +08:00
|
|
|
|
const H5FD_stdio_t *file = (const H5FD_stdio_t *)_file;
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
1999-10-23 08:36:04 +08:00
|
|
|
|
/* Clear the error stack */
|
2007-04-12 09:59:45 +08:00
|
|
|
|
H5Eclear2(H5E_DEFAULT);
|
1999-10-23 08:36:04 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
return MAX(file->eof, file->eoa);
|
|
|
|
|
} /* end H5FD_stdio_get_eof() */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
2002-10-01 00:31:55 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: H5FD_stdio_get_handle
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2002-10-01 00:31:55 +08:00
|
|
|
|
* Purpose: Returns the file handle of stdio file driver.
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2002-10-01 00:31:55 +08:00
|
|
|
|
* Returns: Non-negative if succeed or negative if fails.
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2002-10-01 00:31:55 +08:00
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* Sept. 16, 2002
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2002-10-01 00:31:55 +08:00
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
static herr_t
|
2002-10-01 00:31:55 +08:00
|
|
|
|
H5FD_stdio_get_handle(H5FD_t *_file, hid_t fapl, void** file_handle)
|
2005-08-14 04:53:35 +08:00
|
|
|
|
{
|
2002-10-01 00:31:55 +08:00
|
|
|
|
H5FD_stdio_t *file = (H5FD_stdio_t *)_file;
|
2012-03-31 05:42:47 +08:00
|
|
|
|
static const char *func = "H5FD_stdio_get_handle"; /* Function Name for error reporting */
|
2002-10-15 03:23:40 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Quiet the compiler */
|
|
|
|
|
fapl = fapl;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2002-10-01 00:31:55 +08:00
|
|
|
|
/* Clear the error stack */
|
2007-04-12 09:59:45 +08:00
|
|
|
|
H5Eclear2(H5E_DEFAULT);
|
2004-08-02 22:03:40 +08:00
|
|
|
|
|
2002-10-01 00:31:55 +08:00
|
|
|
|
*file_handle = &(file->fp);
|
2012-03-31 05:42:47 +08:00
|
|
|
|
if(*file_handle == NULL)
|
2003-08-26 23:03:03 +08:00
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "get handle failed", -1)
|
2012-03-31 05:42:47 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
} /* end H5FD_stdio_get_handle() */
|
2002-10-01 00:31:55 +08:00
|
|
|
|
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* Function: H5FD_stdio_read
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Purpose: Reads SIZE bytes beginning at address ADDR in file LF and
|
|
|
|
|
* places them in buffer BUF. Reading past the logical or
|
|
|
|
|
* physical end of file returns zeros instead of failing.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
|
|
|
|
* Errors:
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* IO READERROR fread failed.
|
|
|
|
|
* IO SEEKERROR fseek failed.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* Wednesday, October 22, 1997
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
2001-07-11 05:19:18 +08:00
|
|
|
|
H5FD_stdio_read(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t size,
|
1999-10-21 01:51:03 +08:00
|
|
|
|
void *buf/*out*/)
|
|
|
|
|
{
|
2011-09-07 00:50:32 +08:00
|
|
|
|
H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
|
2012-03-31 05:42:47 +08:00
|
|
|
|
static const char *func = "H5FD_stdio_read"; /* Function Name for error reporting */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Quiet the compiler */
|
|
|
|
|
type = type;
|
|
|
|
|
dxpl_id = dxpl_id;
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
1999-10-23 08:36:04 +08:00
|
|
|
|
/* Clear the error stack */
|
2007-04-12 09:59:45 +08:00
|
|
|
|
H5Eclear2(H5E_DEFAULT);
|
1999-10-23 08:36:04 +08:00
|
|
|
|
|
1999-10-21 01:51:03 +08:00
|
|
|
|
/* Check for overflow */
|
2005-08-14 04:53:35 +08:00
|
|
|
|
if (HADDR_UNDEF==addr)
|
2003-08-26 23:03:03 +08:00
|
|
|
|
H5Epush_ret (func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1)
|
1999-10-21 01:51:03 +08:00
|
|
|
|
if (REGION_OVERFLOW(addr, size))
|
2003-08-26 23:03:03 +08:00
|
|
|
|
H5Epush_ret (func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1)
|
[svn-r18650] Description:
Bring back various minor tweaks & cleanups from the revise_chunks
branch.
Tested on:
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x,
w/C++ & FORTRAN, w/threadsafe, in debug mode
Linux/64-amd64 2.6 (amani) w/Intel compilers, w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in debug mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2010-04-28 06:15:14 +08:00
|
|
|
|
if((addr + size) > file->eoa)
|
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1)
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
|
|
|
|
/* Check easy cases */
|
|
|
|
|
if (0 == size)
|
2012-03-31 05:42:47 +08:00
|
|
|
|
return 0;
|
2003-08-26 23:03:03 +08:00
|
|
|
|
if ((haddr_t)addr >= file->eof) {
|
2001-07-11 05:19:18 +08:00
|
|
|
|
memset(buf, 0, size);
|
2012-03-31 05:42:47 +08:00
|
|
|
|
return 0;
|
1999-10-21 01:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Seek to the correct file position. */
|
|
|
|
|
if (!(file->op == H5FD_STDIO_OP_READ || file->op == H5FD_STDIO_OP_SEEK) ||
|
1999-10-21 01:51:03 +08:00
|
|
|
|
file->pos != addr) {
|
2010-08-07 03:47:42 +08:00
|
|
|
|
if (file_fseek(file->fp, (file_offset_t)addr, SEEK_SET) < 0) {
|
1999-10-21 01:51:03 +08:00
|
|
|
|
file->op = H5FD_STDIO_OP_UNKNOWN;
|
|
|
|
|
file->pos = HADDR_UNDEF;
|
2003-08-26 23:03:03 +08:00
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "fseek failed", -1)
|
1999-10-21 01:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
file->pos = addr;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Read zeros past the logical end of file (physical is handled below) */
|
2003-08-26 23:03:03 +08:00
|
|
|
|
if (addr + size > file->eof) {
|
[svn-r5437]
Purpose:
eliminate warnings on win32
Description:
some conversion warnings were being issued
Solution:
added some type casts
Platforms tested:
w2000, linux
changed the HDmemset to include a cast in win32; this was just to eliminate a compiler
warning. probably the macro can also be used in unix
#ifdef WIN32
#define HDmemset(X,C,Z) memset((void*)(X),C,Z)
#else /* WIN32 */
#define HDmemset(X,C,Z) memset(X,C,Z)
#endif /* WIN32 */
the list of previous warnings was
D:\disk_w\hdf5\src\H5FDstdio.c(659) : warning C4244: 'initializing' : conversion from 'unsigned __int64 ' to 'unsigned int ', possible loss of data
D:\disk_w\hdf5\src\H5Fcontig.c(435) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned int ', possible loss of data
D:\disk_w\hdf5\src\H5Fcontig.c(497) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned int ', possible loss of data
D:\disk_w\hdf5\src\H5Fcontig.c(915) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned int ', possible loss of data
D:\disk_w\hdf5\src\H5Fcontig.c(982) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned int ', possible loss of data
D:\disk_w\hdf5\src\H5Shyper.c(912) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned int ', possible loss of data
D:\disk_w\hdf5\src\H5Shyper.c(995) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned int ', possible loss of data
D:\disk_w\hdf5\src\H5Shyper.c(1936) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned int ', possible loss of data
D:\disk_w\hdf5\src\H5Shyper.c(2019) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned int ', possible loss of data
D:\disk_w\hdf5\src\H5Shyper.c(2862) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned int ', possible loss of data
D:\disk_w\hdf5\src\H5Shyper.c(2864) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned int ', possible loss of data
D:\disk_w\hdf5\src\H5Shyper.c(2948) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned int ', possible loss of data
D:\disk_w\hdf5\src\H5Shyper.c(3690) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned int ', possible loss of data
D:\disk_w\hdf5\src\H5Shyper.c(3692) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned int ', possible loss of data
D:\disk_w\hdf5\src\H5Shyper.c(3776) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned int ', possible loss of data
D:\disk_w\hdf5\src\H5Shyper.c(5167) : warning C4244: '+=' : conversion from '__int64 ' to 'unsigned int ', possible loss of data
D:\disk_w\hdf5\src\H5Tvlen.c(371) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned int ', possible loss of data
2002-05-18 15:24:49 +08:00
|
|
|
|
size_t nbytes = (size_t) (addr + size - file->eof);
|
1999-10-21 01:51:03 +08:00
|
|
|
|
memset((unsigned char *)buf + size - nbytes, 0, nbytes);
|
|
|
|
|
size -= nbytes;
|
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Read the data. Since we're reading single-byte values, a partial read
|
2003-08-26 23:03:03 +08:00
|
|
|
|
* will advance the file position by N. If N is zero or an error
|
1999-10-21 01:51:03 +08:00
|
|
|
|
* occurs then the file position is undefined.
|
|
|
|
|
*/
|
2012-03-31 05:42:47 +08:00
|
|
|
|
while(size > 0) {
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
size_t bytes_in = 0; /* # of bytes to read */
|
|
|
|
|
size_t bytes_read = 0; /* # of bytes actually read */
|
|
|
|
|
size_t item_size = 1; /* size of items in bytes */
|
|
|
|
|
|
|
|
|
|
if(size > H5_STDIO_MAX_IO_BYTES_g)
|
|
|
|
|
bytes_in = H5_STDIO_MAX_IO_BYTES_g;
|
|
|
|
|
else
|
|
|
|
|
bytes_in = size;
|
|
|
|
|
|
|
|
|
|
bytes_read = fread(buf, item_size, bytes_in, file->fp);
|
|
|
|
|
|
|
|
|
|
if(0 == bytes_read && ferror(file->fp)) { /* error */
|
|
|
|
|
file->op = H5FD_STDIO_OP_UNKNOWN;
|
|
|
|
|
file->pos = HADDR_UNDEF;
|
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_READERROR, "fread failed", -1)
|
|
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
|
|
if(0 == bytes_read && feof(file->fp)) {
|
|
|
|
|
/* end of file but not end of format address space */
|
|
|
|
|
memset((unsigned char *)buf, 0, size);
|
|
|
|
|
break;
|
|
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
|
|
size -= bytes_read;
|
|
|
|
|
addr += (haddr_t)bytes_read;
|
|
|
|
|
buf = (char *)buf + bytes_read;
|
|
|
|
|
} /* end while */
|
|
|
|
|
|
|
|
|
|
/* Update the file position data. */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
file->op = H5FD_STDIO_OP_READ;
|
2012-03-31 05:42:47 +08:00
|
|
|
|
file->pos = addr;
|
|
|
|
|
|
|
|
|
|
return 0;
|
1999-10-21 01:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* Function: H5FD_stdio_write
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Purpose: Writes SIZE bytes from the beginning of BUF into file LF at
|
|
|
|
|
* file address ADDR.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
|
|
|
|
* Errors:
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* IO SEEKERROR fseek failed.
|
|
|
|
|
* IO WRITEERROR fwrite failed.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* Wednesday, October 22, 1997
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
2000-09-01 03:33:58 +08:00
|
|
|
|
H5FD_stdio_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr,
|
2011-09-07 00:50:32 +08:00
|
|
|
|
size_t size, const void *buf)
|
1999-10-21 01:51:03 +08:00
|
|
|
|
{
|
2011-09-07 00:50:32 +08:00
|
|
|
|
H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
|
2012-03-31 05:42:47 +08:00
|
|
|
|
static const char *func = "H5FD_stdio_write"; /* Function Name for error reporting */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Quiet the compiler */
|
|
|
|
|
dxpl_id = dxpl_id;
|
|
|
|
|
type = type;
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
1999-10-23 08:36:04 +08:00
|
|
|
|
/* Clear the error stack */
|
2007-04-12 09:59:45 +08:00
|
|
|
|
H5Eclear2(H5E_DEFAULT);
|
1999-10-23 08:36:04 +08:00
|
|
|
|
|
1999-10-21 01:51:03 +08:00
|
|
|
|
/* Check for overflow conditions */
|
2012-03-31 05:42:47 +08:00
|
|
|
|
if (HADDR_UNDEF == addr)
|
2003-08-26 23:03:03 +08:00
|
|
|
|
H5Epush_ret (func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1)
|
1999-10-21 01:51:03 +08:00
|
|
|
|
if (REGION_OVERFLOW(addr, size))
|
2003-08-26 23:03:03 +08:00
|
|
|
|
H5Epush_ret (func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1)
|
2012-03-31 05:42:47 +08:00
|
|
|
|
if (addr+size > file->eoa)
|
2003-08-26 23:03:03 +08:00
|
|
|
|
H5Epush_ret (func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1)
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Seek to the correct file position. */
|
2000-12-27 05:59:19 +08:00
|
|
|
|
if ((file->op != H5FD_STDIO_OP_WRITE && file->op != H5FD_STDIO_OP_SEEK) ||
|
1999-10-21 01:51:03 +08:00
|
|
|
|
file->pos != addr) {
|
2010-08-07 03:47:42 +08:00
|
|
|
|
if (file_fseek(file->fp, (file_offset_t)addr, SEEK_SET) < 0) {
|
1999-10-21 01:51:03 +08:00
|
|
|
|
file->op = H5FD_STDIO_OP_UNKNOWN;
|
|
|
|
|
file->pos = HADDR_UNDEF;
|
2003-08-26 23:03:03 +08:00
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "fseek failed", -1)
|
1999-10-21 01:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
file->pos = addr;
|
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Write the buffer. On successful return, the file position will be
|
|
|
|
|
* advanced by the number of bytes read. On failure, the file position is
|
|
|
|
|
* undefined.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*/
|
2012-03-31 05:42:47 +08:00
|
|
|
|
while(size > 0) {
|
|
|
|
|
|
|
|
|
|
size_t bytes_in = 0; /* # of bytes to write */
|
|
|
|
|
size_t bytes_wrote = 0; /* # of bytes written */
|
|
|
|
|
size_t item_size = 1; /* size of items in bytes */
|
|
|
|
|
|
|
|
|
|
if(size > H5_STDIO_MAX_IO_BYTES_g)
|
|
|
|
|
bytes_in = H5_STDIO_MAX_IO_BYTES_g;
|
|
|
|
|
else
|
|
|
|
|
bytes_in = size;
|
|
|
|
|
|
|
|
|
|
bytes_wrote = fwrite(buf, item_size, bytes_in, file->fp);
|
|
|
|
|
|
|
|
|
|
if(bytes_wrote != bytes_in || (0 == bytes_wrote && ferror(file->fp))) { /* error */
|
|
|
|
|
file->op = H5FD_STDIO_OP_UNKNOWN;
|
|
|
|
|
file->pos = HADDR_UNDEF;
|
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fwrite failed", -1)
|
|
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
|
|
assert(bytes_wrote > 0);
|
|
|
|
|
assert((size_t)bytes_wrote <= size);
|
|
|
|
|
|
|
|
|
|
size -= bytes_wrote;
|
|
|
|
|
addr += (haddr_t)bytes_wrote;
|
|
|
|
|
buf = (const char *)buf + bytes_wrote;
|
1999-10-21 01:51:03 +08:00
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Update seek optimizing data. */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
file->op = H5FD_STDIO_OP_WRITE;
|
2012-03-31 05:42:47 +08:00
|
|
|
|
file->pos = addr;
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
|
|
|
|
/* Update EOF if necessary */
|
2012-03-31 05:42:47 +08:00
|
|
|
|
if (file->pos > file->eof)
|
1999-10-21 01:51:03 +08:00
|
|
|
|
file->eof = file->pos;
|
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
return 0;
|
1999-10-21 01:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* Function: H5FD_stdio_flush
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Purpose: Makes sure that all data is on disk.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
|
|
|
|
* Errors:
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* IO SEEKERROR fseek failed.
|
|
|
|
|
* IO WRITEERROR fflush or fwrite failed.
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* Wednesday, October 22, 1997
|
1999-10-21 01:51:03 +08:00
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
2003-02-11 01:26:09 +08:00
|
|
|
|
H5FD_stdio_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing)
|
1999-10-21 01:51:03 +08:00
|
|
|
|
{
|
2011-09-07 00:50:32 +08:00
|
|
|
|
H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
static const char *func = "H5FD_stdio_flush"; /* Function Name for error reporting */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Quiet the compiler */
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
dxpl_id = dxpl_id;
|
|
|
|
|
|
|
|
|
|
/* Clear the error stack */
|
|
|
|
|
H5Eclear2(H5E_DEFAULT);
|
|
|
|
|
|
|
|
|
|
/* Only try to flush the file if we have write access */
|
|
|
|
|
if(file->write_access) {
|
|
|
|
|
if(!closing) {
|
|
|
|
|
if(fflush(file->fp) < 0)
|
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fflush failed", -1)
|
|
|
|
|
|
|
|
|
|
/* Reset last file I/O information */
|
|
|
|
|
file->pos = HADDR_UNDEF;
|
|
|
|
|
file->op = H5FD_STDIO_OP_UNKNOWN;
|
|
|
|
|
} /* end if */
|
|
|
|
|
} /* end if */
|
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
return 0;
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
} /* end H5FD_stdio_flush() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2012-03-31 05:42:47 +08:00
|
|
|
|
* Function: H5FD_stdio_truncate
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Purpose: Makes sure that the true file size is the same (or larger)
|
|
|
|
|
* than the end-of-address.
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
*
|
|
|
|
|
* Errors:
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* IO SEEKERROR fseek failed.
|
|
|
|
|
* IO WRITEERROR fflush or fwrite failed.
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
*
|
2011-09-07 00:50:32 +08:00
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* Thursday, January 31, 2008
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
|
|
|
|
H5FD_stdio_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing)
|
|
|
|
|
{
|
2011-09-07 00:50:32 +08:00
|
|
|
|
H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
static const char *func = "H5FD_stdio_truncate"; /* Function Name for error reporting */
|
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Quiet the compiler */
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
dxpl_id = dxpl_id;
|
|
|
|
|
closing = closing;
|
2003-02-13 01:04:40 +08:00
|
|
|
|
|
1999-10-23 08:36:04 +08:00
|
|
|
|
/* Clear the error stack */
|
2007-04-12 09:59:45 +08:00
|
|
|
|
H5Eclear2(H5E_DEFAULT);
|
1999-10-23 08:36:04 +08:00
|
|
|
|
|
1999-10-21 01:51:03 +08:00
|
|
|
|
/* Only try to flush the file if we have write access */
|
|
|
|
|
if(file->write_access) {
|
2003-04-17 03:24:05 +08:00
|
|
|
|
/* Makes sure that the true file size is the same as the end-of-address. */
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
if(file->eoa != file->eof) {
|
|
|
|
|
|
2011-09-07 00:50:32 +08:00
|
|
|
|
#ifdef H5_HAVE_WIN32_API
|
2012-03-31 05:42:47 +08:00
|
|
|
|
LARGE_INTEGER li; /* 64-bit (union) integer for SetFilePointer() call */
|
|
|
|
|
DWORD dwPtrLow; /* Low-order pointer bits from SetFilePointer()
|
|
|
|
|
* Only used as an error code here.
|
|
|
|
|
*/
|
|
|
|
|
DWORD dwError; /* DWORD error code from GetLastError() */
|
|
|
|
|
BOOL bError; /* Boolean error flag */
|
2003-04-17 03:24:05 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Reset seek offset to beginning of file, so that file isn't re-extended later */
|
2010-05-28 23:46:33 +08:00
|
|
|
|
rewind(file->fp);
|
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
/* Windows uses this odd QuadPart union for 32/64-bit portability */
|
|
|
|
|
li.QuadPart = (__int64)file->eoa;
|
|
|
|
|
|
|
|
|
|
/* Extend the file to make sure it's large enough.
|
|
|
|
|
*
|
|
|
|
|
* Since INVALID_SET_FILE_POINTER can technically be a valid return value
|
|
|
|
|
* from SetFilePointer(), we also need to check GetLastError().
|
|
|
|
|
*/
|
|
|
|
|
dwPtrLow = SetFilePointer(file->hFile, li.LowPart, &li.HighPart, FILE_BEGIN);
|
|
|
|
|
if(INVALID_SET_FILE_POINTER == dwPtrLow) {
|
|
|
|
|
dwError = GetLastError();
|
|
|
|
|
if(dwError != NO_ERROR )
|
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_FILEOPEN, "unable to set file pointer", -1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bError = SetEndOfFile(file->hFile);
|
|
|
|
|
if(0 == bError)
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "unable to truncate/extend file properly", -1)
|
2011-09-07 00:50:32 +08:00
|
|
|
|
#else /* H5_HAVE_WIN32_API */
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
/* Reset seek offset to beginning of file, so that file isn't re-extended later */
|
|
|
|
|
rewind(file->fp);
|
2003-08-26 23:03:03 +08:00
|
|
|
|
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
/* Truncate file to proper length */
|
2012-03-31 05:42:47 +08:00
|
|
|
|
if(-1 == file_ftruncate(file->fd, (file_offset_t)file->eoa))
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "unable to truncate/extend file properly", -1)
|
2011-09-07 00:50:32 +08:00
|
|
|
|
#endif /* H5_HAVE_WIN32_API */
|
2003-08-26 23:03:03 +08:00
|
|
|
|
|
2003-04-17 03:24:05 +08:00
|
|
|
|
/* Update the eof value */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
file->eof = file->eoa;
|
|
|
|
|
|
2003-04-17 03:24:05 +08:00
|
|
|
|
/* Reset last file I/O information */
|
|
|
|
|
file->pos = HADDR_UNDEF;
|
|
|
|
|
file->op = H5FD_STDIO_OP_UNKNOWN;
|
|
|
|
|
} /* end if */
|
|
|
|
|
} /* end if */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
else {
|
|
|
|
|
/* Double-check for problems */
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
if(file->eoa > file->eof)
|
2012-03-31 05:42:47 +08:00
|
|
|
|
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_TRUNCATED, "eoa > eof!", -1)
|
|
|
|
|
} /* end else */
|
1999-10-21 01:51:03 +08:00
|
|
|
|
|
2012-03-31 05:42:47 +08:00
|
|
|
|
return 0;
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
} /* end H5FD_stdio_truncate() */
|
2002-04-11 07:37:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _H5private_H
|
|
|
|
|
/*
|
|
|
|
|
* This is not related to the functionality of the driver code.
|
|
|
|
|
* It is added here to trigger warning if HDF5 private definitions are included
|
|
|
|
|
* by mistake. The code should use only HDF5 public API and definitions.
|
|
|
|
|
*/
|
|
|
|
|
#error "Do not use HDF5 private definitions"
|
|
|
|
|
#endif
|
[svn-r15800] Description:
Bring file free space branch changes through r15795 into trunk, which
includes a fair bit of code cleanup & rearrangement along with a couple of
bug fixes also.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-07 12:17:35 +08:00
|
|
|
|
|