Bug report & file locking for Windows

*Bug report:*
H5FDsec2.c : line 337 is:
if((fd = HDopen(name, o_flags, 0666)) < 0)

The 0666 for the file permissions is not valid for MSVC std lib _open()
which is waht HDopen is defined as. It happens to hit the important bits,
but just by luck. It should be (_S_IREAD | _S_IWRITE) for MSVC. This could
be done in the HDopen macro with a 1 line change (assuming sys/stat.h is
included already).

*File locking on windows:*

I wanted files that are open for read-write to deny other writers. To do
this I replaced the HDopen() line in H5FDsec2.c with this:

#include <share.h>
int sh_flags = ((H5F_ACC_RDWR & flags) || (H5F_ACC_CREAT & flags)) ?
_SH_DENYWR : _SH_DENYNO;
if((fd = _sopen(name, o_flags|_O_BINARY, sh_flags, _S_IREAD|_S_IWRITE)) <
0) {

Hi David,

For the bug report, I'll create an issue for 1.8.17 and take a look at the flags.

For the file locking on Windows, I'll create a bug report (also for 1.8.17) and take a look at that functionality. It might also be useful for the single-writer/multiple-readers feature of HDF5 1.10.0.

Thanks for your report! I'll post back on the forum with any changes we'll be making but I probably won't get to it until the new year due to the holidays and 1.10.0 alpha release coming up.

Cheers,

Dana Robinson
Software Developer
The HDF Group

ยทยทยท

From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] On Behalf Of David
Sent: Thursday, December 10, 2015 3:24 AM
To: HDF Users Discussion List <hdf-forum@lists.hdfgroup.org>
Subject: [Hdf-forum] Bug report & file locking for Windows

Bug report:
H5FDsec2.c : line 337 is:
if((fd = HDopen(name, o_flags, 0666)) < 0)

The 0666 for the file permissions is not valid for MSVC std lib _open() which is waht HDopen is defined as. It happens to hit the important bits, but just by luck. It should be (_S_IREAD | _S_IWRITE) for MSVC. This could be done in the HDopen macro with a 1 line change (assuming sys/stat.h is included already).

File locking on windows:
I wanted files that are open for read-write to deny other writers. To do this I replaced the HDopen() line in H5FDsec2.c with this:

#include <share.h>
int sh_flags = ((H5F_ACC_RDWR & flags) || (H5F_ACC_CREAT & flags)) ? _SH_DENYWR : _SH_DENYNO;
if((fd = _sopen(name, o_flags|_O_BINARY, sh_flags, _S_IREAD|_S_IWRITE)) < 0) {
[Image removed by sender.]