mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-22 18:03:03 +01:00
Fix for turning forced writes off
This commit is contained in:
parent
6c92c1f3b2
commit
e98988ae33
@ -303,47 +303,45 @@ void PIO_force_write(FIL file, USHORT flag)
|
||||
* Set (or clear) force write, if possible, for the database.
|
||||
*
|
||||
**************************************/
|
||||
HANDLE desc;
|
||||
|
||||
if (flag)
|
||||
const bool bOldForce = (file->fil_flags & FIL_force_write_init) != 0;
|
||||
|
||||
if ((flag && !bOldForce) ||
|
||||
(!flag && bOldForce))
|
||||
{
|
||||
if (!(file->fil_flags & FIL_force_write_init))
|
||||
SLONG& hOld = flag ? file->fil_desc : file->fil_force_write_desc;
|
||||
HANDLE& hNew = reinterpret_cast<HANDLE&>(flag ? file->fil_force_write_desc : file->fil_desc);
|
||||
|
||||
MaybeCloseFile(&hOld);
|
||||
hNew = CreateFile(file->fil_string,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
g_dwShareFlags,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL |
|
||||
g_dwExtraFlags |
|
||||
(flag ? FILE_FLAG_WRITE_THROUGH : 0),
|
||||
0);
|
||||
|
||||
if (hNew == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
/* TMN: Close the existing handle since we're now opening */
|
||||
/* the files for exclusive access */
|
||||
MaybeCloseFile(&file->fil_desc);
|
||||
desc = CreateFile(file->fil_string,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
g_dwShareFlags,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL |
|
||||
FILE_FLAG_WRITE_THROUGH |
|
||||
g_dwExtraFlags,
|
||||
0);
|
||||
|
||||
if (desc == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
ERR_post(isc_io_error,
|
||||
gds_arg_string,
|
||||
"CreateFile (force write)",
|
||||
gds_arg_cstring,
|
||||
file->fil_length,
|
||||
ERR_string(file->fil_string, file->fil_length),
|
||||
isc_arg_gds, isc_io_access_err,
|
||||
gds_arg_win32,
|
||||
GetLastError(),
|
||||
0);
|
||||
}
|
||||
|
||||
/* TMN: Take note! Assumes sizeof(long) == sizeof(void*) ! */
|
||||
file->fil_force_write_desc = reinterpret_cast<SLONG>(desc);
|
||||
ERR_post(isc_io_error,
|
||||
gds_arg_string,
|
||||
"CreateFile (force write)",
|
||||
gds_arg_cstring,
|
||||
file->fil_length,
|
||||
ERR_string(file->fil_string, file->fil_length),
|
||||
isc_arg_gds, isc_io_access_err,
|
||||
gds_arg_win32,
|
||||
GetLastError(),
|
||||
0);
|
||||
}
|
||||
|
||||
if (flag) {
|
||||
file->fil_flags |= (FIL_force_write | FIL_force_write_init);
|
||||
} else {
|
||||
file->fil_flags &= ~FIL_force_write;
|
||||
}
|
||||
file->fil_flags |= (FIL_force_write | FIL_force_write_init);
|
||||
}
|
||||
else
|
||||
{
|
||||
file->fil_flags &= ~FIL_force_write;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user