# define os_file_read(file, buf, offset, offset_high, n) \ os_file_read_func(file, buf, offset, offset_high, n)
/*******************************************************************//** NOTE! Use the corresponding macro os_file_read(), not directly this function! Requests a synchronous positioned read operation. @return TRUE if request was successful, FALSE if fail */ UNIV_INTERN ibool os_file_read_func( /*==============*/ os_file_t file, /*!< in: handle to a file */ void* buf, /*!< in: buffer where to read */ ulint offset, /*!< in: least significant 32 bits of file offset where to read */ ulint offset_high, /*!< in: most significant 32 bits of offset */ ulint n) /*!< in: number of bytes to read */ { #ifdef __WIN__ BOOL ret; DWORD len; DWORD ret2; DWORD low; DWORD high; ibool retry; #ifndef UNIV_HOTBACKUP ulint i; #endif /* !UNIV_HOTBACKUP */ /* On 64-bit Windows, ulint is 64 bits. But offset and n should be no more than 32 bits. */ ut_a((offset & 0xFFFFFFFFUL) == offset); ut_a((n & 0xFFFFFFFFUL) == n); os_n_file_reads++; os_bytes_read_since_printout += n; try_again: ut_ad(file); ut_ad(buf); ut_ad(n > ); low = (DWORD) offset; high = (DWORD) offset_high; os_mutex_enter(os_file_count_mutex); os_n_pending_reads++; os_mutex_exit(os_file_count_mutex); #ifndef UNIV_HOTBACKUP /* Protect the seek / read operation with a mutex */ i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES; os_mutex_enter(os_file_seek_mutexes[i]); #endif /* !UNIV_HOTBACKUP */ ret2 = SetFilePointer(file, low, &high, FILE_BEGIN); if (ret2 == 0xFFFFFFFF && GetLastError() != NO_ERROR) { #ifndef UNIV_HOTBACKUP os_mutex_exit(os_file_seek_mutexes[i]); #endif /* !UNIV_HOTBACKUP */ os_mutex_enter(os_file_count_mutex); os_n_pending_reads--; os_mutex_exit(os_file_count_mutex); goto error_handling; } ret = ReadFile(file, buf, (DWORD) n, &len, NULL); #ifndef UNIV_HOTBACKUP os_mutex_exit(os_file_seek_mutexes[i]); #endif /* !UNIV_HOTBACKUP */ os_mutex_enter(os_file_count_mutex); os_n_pending_reads--; os_mutex_exit(os_file_count_mutex); if (ret && len == n) { return(TRUE); } #else /* __WIN__ */ ibool retry; ssize_t ret; os_bytes_read_since_printout += n; try_again: ret = os_file_pread(file, buf, n, offset, offset_high); //读取数据 详见 if ((ulint)ret == n) { return(TRUE); } fprintf(stderr, "InnoDB: Error: tried to read %lu bytes at offset %lu %lu.\n" "InnoDB: Was only able to read %ld.\n", (ulong)n, (ulong)offset_high, (ulong)offset, (long)ret); #endif /* __WIN__ */ #ifdef __WIN__ error_handling: #endif retry = os_file_handle_error(NULL, "read"); if (retry) { goto try_again; } fprintf(stderr, "InnoDB: Fatal error: cannot read from file." " OS error number %lu.\n", #ifdef __WIN__ (ulong) GetLastError() #else (ulong) errno #endif ); fflush(stderr); ut_error; return(FALSE); }