diff --git a/src/jrd/jrd.cpp b/src/jrd/jrd.cpp index 96c40b9566..a95cedffd5 100644 --- a/src/jrd/jrd.cpp +++ b/src/jrd/jrd.cpp @@ -812,7 +812,7 @@ ISC_STATUS GDS_ATTACH_DATABASE(ISC_STATUS* user_status, dbb->dbb_flags |= DBB_lck_init_done; INI_init(); dbb->dbb_file = - PIO_open(dbb, expanded_name, options.dpb_trace != 0, NULL, file_name); + PIO_open(dbb, expanded_name, options.dpb_trace != 0, NULL, file_name, false); SHUT_init(dbb); PAG_header_init(); INI_init2(); @@ -1946,7 +1946,7 @@ ISC_STATUS GDS_CREATE_DATABASE(ISC_STATUS* user_status, try { // try to create with overwrite = false - dbb->dbb_file = PIO_create(dbb, expanded_name, false); + dbb->dbb_file = PIO_create(dbb, expanded_name, false, false); } catch (Firebird::status_exception) { @@ -1976,7 +1976,7 @@ ISC_STATUS GDS_CREATE_DATABASE(ISC_STATUS* user_status, { // file is a database and the user (SYSDBA or owner) has right to overwrite dbb->dbb_file = - PIO_create(dbb, expanded_name, options.dpb_overwrite); + PIO_create(dbb, expanded_name, options.dpb_overwrite, false); } else { diff --git a/src/jrd/nbak.cpp b/src/jrd/nbak.cpp index 03f197a599..0ee7b6caba 100644 --- a/src/jrd/nbak.cpp +++ b/src/jrd/nbak.cpp @@ -567,7 +567,7 @@ void BackupManager::begin_backup(thread_db* tdbb) } // Create file NBAK_TRACE(("Creating difference file %s", diff_name)); - diff_file = PIO_create(database, diff_name, true); + diff_file = PIO_create(database, diff_name, true, true); #ifdef UNIX // adjust difference file access rights to make it match main DB ones if (diff_file && geteuid() == 0) { @@ -1193,7 +1193,7 @@ bool BackupManager::actualize_state(thread_db* tdbb) throw() #endif try { NBAK_TRACE(("Open difference file")); - diff_file = PIO_open(database, diff_name, false, NULL, diff_name); + diff_file = PIO_open(database, diff_name, false, NULL, diff_name, true); } catch(const std::exception& ex) { #ifdef SUPERSERVER adjust_state_lock->leave(); diff --git a/src/jrd/os/pio_proto.h b/src/jrd/os/pio_proto.h index 5f804c0d09..9fc500a3f5 100644 --- a/src/jrd/os/pio_proto.h +++ b/src/jrd/os/pio_proto.h @@ -36,7 +36,7 @@ struct blk; int PIO_add_file(Jrd::Database*, Jrd::jrd_file*, const Firebird::PathName&, SLONG); void PIO_close(Jrd::jrd_file*); -Jrd::jrd_file* PIO_create(Jrd::Database*, const Firebird::PathName&, bool); +Jrd::jrd_file* PIO_create(Jrd::Database*, const Firebird::PathName&, bool, bool); int PIO_connection(const Firebird::PathName&); int PIO_expand(const TEXT*, USHORT, TEXT*, size_t); void PIO_flush(Jrd::jrd_file*); @@ -45,7 +45,7 @@ void PIO_header(Jrd::Database*, SCHAR*, int); SLONG PIO_max_alloc(Jrd::Database*); SLONG PIO_act_alloc(Jrd::Database*); Jrd::jrd_file* PIO_open(Jrd::Database*, const Firebird::PathName&, bool, - blk*, const Firebird::PathName&); + blk*, const Firebird::PathName&, bool); bool PIO_read(Jrd::jrd_file*, Jrd::BufferDesc*, Ods::pag*, ISC_STATUS*); #ifdef SUPERSERVER_V2 diff --git a/src/jrd/os/posix/unix.cpp b/src/jrd/os/posix/unix.cpp index 84a39a9873..5c77e7a774 100644 --- a/src/jrd/os/posix/unix.cpp +++ b/src/jrd/os/posix/unix.cpp @@ -159,7 +159,7 @@ int PIO_add_file(Database* dbb, jrd_file* main_file, const Firebird::PathName& f * have been locked before entry. * **************************************/ - jrd_file* new_file = PIO_create(dbb, file_name, false); + jrd_file* new_file = PIO_create(dbb, file_name, false, false); if (!new_file) return 0; @@ -227,7 +227,7 @@ int PIO_connection(const Firebird::PathName& file_name) } -jrd_file* PIO_create(Database* dbb, const Firebird::PathName& string, bool overwrite) +jrd_file* PIO_create(Database* dbb, const Firebird::PathName& string, bool overwrite, bool share_delete) { /************************************** * @@ -558,7 +558,8 @@ jrd_file* PIO_open(Database* dbb, const Firebird::PathName& string, bool trace_flag, blk* connection, - const Firebird::PathName& file_name) + const Firebird::PathName& file_name, + bool share_delete) { /************************************** * diff --git a/src/jrd/os/win32/winnt.cpp b/src/jrd/os/win32/winnt.cpp index 0593dfbd6c..fb5fa5b18f 100644 --- a/src/jrd/os/win32/winnt.cpp +++ b/src/jrd/os/win32/winnt.cpp @@ -108,7 +108,7 @@ int PIO_add_file(Database* dbb, jrd_file* main_file, const Firebird::PathName& f * sequence of 0. * **************************************/ - jrd_file* new_file = PIO_create(dbb, file_name, false); + jrd_file* new_file = PIO_create(dbb, file_name, false, false); if (!new_file) { return 0; } @@ -181,7 +181,7 @@ int PIO_connection(const Firebird::PathName& file_name) -jrd_file* PIO_create(Database* dbb, const Firebird::PathName& string, bool overwrite) +jrd_file* PIO_create(Database* dbb, const Firebird::PathName& string, bool overwrite, bool share_delete) { /************************************** * @@ -195,9 +195,12 @@ jrd_file* PIO_create(Database* dbb, const Firebird::PathName& string, bool overw **************************************/ const TEXT* file_name = string.c_str(); + if (!ISC_is_WinNT()) + share_delete = false; + const HANDLE desc = CreateFile(file_name, GENERIC_READ | GENERIC_WRITE, - g_dwShareFlags, + g_dwShareFlags | (share_delete ? FILE_SHARE_DELETE : 0), NULL, (overwrite ? CREATE_ALWAYS : CREATE_NEW), FILE_ATTRIBUTE_NORMAL | @@ -478,7 +481,8 @@ jrd_file* PIO_open(Database* dbb, const Firebird::PathName& string, bool trace_flag, blk* connection, - const Firebird::PathName& file_name) + const Firebird::PathName& file_name, + bool share_delete) { /************************************** * @@ -494,9 +498,12 @@ jrd_file* PIO_open(Database* dbb, **************************************/ const TEXT* ptr = (string.hasData() ? string : file_name).c_str(); + if (!ISC_is_WinNT()) + share_delete = false; + HANDLE desc = CreateFile(ptr, GENERIC_READ | GENERIC_WRITE, - g_dwShareFlags, + g_dwShareFlags | (share_delete ? FILE_SHARE_DELETE : 0), NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | @@ -1070,18 +1077,19 @@ static jrd_file* setup_file(Database* dbb, if (!LCK_lock(NULL, lock, LCK_EX, LCK_NO_WAIT)) { dbb->dbb_flags &= ~DBB_exclusive; thread_db* tdbb = JRD_get_thread_data(); - + while (!LCK_lock(tdbb, lock, LCK_SW, -1)) { tdbb->tdbb_status_vector[0] = 0; // Clean status vector from lock manager error code // If we are in a single-threaded maintenance mode then clean up and stop waiting - SCHAR spare_memory[MIN_PAGE_SIZE*2]; - SCHAR *header_page_buffer = (SCHAR*) FB_ALIGN((IPTR)spare_memory, MIN_PAGE_SIZE); - + SCHAR spare_memory[MIN_PAGE_SIZE * 2]; + SCHAR *header_page_buffer = (SCHAR*) FB_ALIGN((IPTR) spare_memory, MIN_PAGE_SIZE); + Ods::header_page* header = reinterpret_cast(header_page_buffer); + try { dbb->dbb_file = file; PIO_header(dbb, header_page_buffer, MIN_PAGE_SIZE); - if ((reinterpret_cast(header_page_buffer)->hdr_flags & Ods::hdr_shutdown_mask) == Ods::hdr_shutdown_single) - ERR_post(isc_shutdown, isc_arg_cstring, file_name.length(), ERR_cstring(file_name), 0); + if ((header->hdr_flags & Ods::hdr_shutdown_mask) == Ods::hdr_shutdown_single) + ERR_post(isc_shutdown, isc_arg_string, ERR_string(file_name), 0); dbb->dbb_file = NULL; // Will be set again later by the caller } catch(const std::exception&) { delete dbb->dbb_lock; diff --git a/src/jrd/pag.cpp b/src/jrd/pag.cpp index dfbda4b131..2ca4f09b1a 100644 --- a/src/jrd/pag.cpp +++ b/src/jrd/pag.cpp @@ -1496,7 +1496,7 @@ void PAG_init2(USHORT shadow_number) isc_arg_end); } - file->fil_next = PIO_open(dbb, file_name, false, 0, file_name); + file->fil_next = PIO_open(dbb, file_name, false, 0, file_name, false); file->fil_max_page = last_page; file = file->fil_next; if (dbb->dbb_flags & DBB_force_write) diff --git a/src/jrd/sdw.cpp b/src/jrd/sdw.cpp index 40feb76874..9363c99ced 100644 --- a/src/jrd/sdw.cpp +++ b/src/jrd/sdw.cpp @@ -92,7 +92,7 @@ void SDW_add(const TEXT* file_name, USHORT shadow_number, USHORT file_flags) isc_arg_end); } - jrd_file* shadow_file = PIO_create(dbb, file_name, false); + jrd_file* shadow_file = PIO_create(dbb, file_name, false, false); if (dbb->dbb_flags & DBB_force_write) PIO_force_write(shadow_file, true); @@ -973,8 +973,7 @@ void SDW_start(const TEXT* file_name, try { - shadow_file = - PIO_open(dbb, expanded_name, false, 0, file_name); + shadow_file = PIO_open(dbb, expanded_name, false, 0, file_name, false); if (dbb->dbb_flags & DBB_force_write) { PIO_force_write(shadow_file, true); @@ -1234,7 +1233,7 @@ static bool check_for_file(const SCHAR* name, USHORT length) // This use of PIO_open is NOT checked against DatabaseAccess configuration // parameter. It's not required, because here we only check for presence of // existing file, never really use (or create) it. - jrd_file* temp_file = PIO_open(dbb, path, false, 0, path); + jrd_file* temp_file = PIO_open(dbb, path, false, 0, path, false); PIO_close(temp_file); } // try catch (const std::exception& ex) {