diff --git a/src/jrd/winnt.cpp b/src/jrd/winnt.cpp index 2dbcc00ea4..d724cc4271 100644 --- a/src/jrd/winnt.cpp +++ b/src/jrd/winnt.cpp @@ -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(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(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; } }