8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 20:43:02 +01:00

Fix for turning forced writes off

This commit is contained in:
tamlin 2001-12-28 05:16:58 +00:00
parent 6c92c1f3b2
commit e98988ae33

View File

@ -303,47 +303,45 @@ void PIO_force_write(FIL file, USHORT flag)
* Set (or clear) force write, if possible, for the database. * 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 */ ERR_post(isc_io_error,
/* the files for exclusive access */ gds_arg_string,
MaybeCloseFile(&file->fil_desc); "CreateFile (force write)",
desc = CreateFile(file->fil_string, gds_arg_cstring,
GENERIC_READ | GENERIC_WRITE, file->fil_length,
g_dwShareFlags, ERR_string(file->fil_string, file->fil_length),
NULL, isc_arg_gds, isc_io_access_err,
OPEN_EXISTING, gds_arg_win32,
FILE_ATTRIBUTE_NORMAL | GetLastError(),
FILE_FLAG_WRITE_THROUGH | 0);
g_dwExtraFlags, }
0);
if (flag) {
if (desc == INVALID_HANDLE_VALUE) file->fil_flags |= (FIL_force_write | FIL_force_write_init);
{ } else {
ERR_post(isc_io_error, file->fil_flags &= ~FIL_force_write;
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);
} }
file->fil_flags |= (FIL_force_write | FIL_force_write_init);
}
else
{
file->fil_flags &= ~FIL_force_write;
} }
} }