jrd_file* PIO_create(Database* dbb, const Firebird::PathName& string, const bool overwrite, const bool temporary, const bool share_delete) { /************************************** * * P I O _ c r e a t e * ************************************** * * Functional description * Create a new database file. * **************************************/ adjustFsCacheOnce.init(); const TEXT* file_name = string.c_str(); DWORD dwShareMode = (temporary ? g_dwShareTempFlags : g_dwShareFlags); if (share_delete) dwShareMode |= FILE_SHARE_DELETE; DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL | g_dwExtraFlags; if (temporary) dwFlagsAndAttributes |= g_dwExtraTempFlags; const HANDLE desc = CreateFile(file_name, GENERIC_READ | GENERIC_WRITE, dwShareMode, NULL, (overwrite ? CREATE_ALWAYS : CREATE_NEW), dwFlagsAndAttributes, 0); if (desc == INVALID_HANDLE_VALUE) { ERR_post(Arg::Gds(isc_io_error) << Arg::Str("CreateFile (create)") << Arg::Str(string) << Arg::Gds(isc_io_create_err) << Arg::Windows(GetLastError())); } // File open succeeded. Now expand the file name. // workspace is the expanded name here Firebird::PathName workspace(string); ISC_expand_filename(workspace, false); return setup_file(dbb, workspace, desc, false); }
jrd_file* PIO_open(Database* dbb, const Firebird::PathName& string, const Firebird::PathName& file_name) { /************************************** * * P I O _ o p e n * ************************************** * * Functional description * Open a database file. * **************************************/ const TEXT* const ptr = (string.hasData() ? string : file_name).c_str(); bool readOnly = false; const bool shareMode = dbb->dbb_config->getSharedDatabase(); adjustFsCacheOnce.init(); HANDLE desc = CreateFile(ptr, GENERIC_READ | GENERIC_WRITE, getShareFlags(shareMode), NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | g_dwExtraFlags, 0); if (desc == INVALID_HANDLE_VALUE) { // Try opening the database file in ReadOnly mode. // The database file could be on a RO medium (CD-ROM etc.). // If this fileopen fails, return error. desc = CreateFile(ptr, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | g_dwExtraFlags, 0); if (desc == INVALID_HANDLE_VALUE) { ERR_post(Arg::Gds(isc_io_error) << Arg::Str("CreateFile (open)") << Arg::Str(file_name) << Arg::Gds(isc_io_open_err) << Arg::Windows(GetLastError())); } else { // If this is the primary file, set Database flag to indicate that it is // being opened ReadOnly. This flag will be used later to compare with // the Header Page flag setting to make sure that the database is set ReadOnly. readOnly = true; PageSpace* pageSpace = dbb->dbb_page_manager.findPageSpace(DB_PAGE_SPACE); if (!pageSpace->file) dbb->dbb_flags |= DBB_being_opened_read_only; } } return setup_file(dbb, string, desc, readOnly, shareMode); }