标签:
/*******************************************************************//** Does a synchronous read operation in Posix. @return number of bytes read, -1 if error */ static ssize_t os_file_pread( /*==========*/ os_file_t file, /*!< in: handle to a file */ void* buf, /*!< in: buffer where to read */ ulint n, /*!< in: number of bytes to read */ ulint offset, /*!< in: least significant 32 bits of file offset from where to read */ ulint offset_high) /*!< in: most significant 32 bits of offset */ { off_t offs; #if defined(HAVE_PREAD) && !defined(HAVE_BROKEN_PREAD) ssize_t n_bytes; #endif /* HAVE_PREAD && !HAVE_BROKEN_PREAD */ ut_a((offset & 0xFFFFFFFFUL) == offset); /* If off_t is > 4 bytes in size, then we assume we can pass a 64-bit address */ if (sizeof(off_t) > 4) { offs = (off_t)offset + (((off_t)offset_high) << 32); } else { offs = (off_t)offset; if (offset_high > 0) { fprintf(stderr, "InnoDB: Error: file read at offset > 4 GB\n"); } } os_n_file_reads++; #if defined(HAVE_PREAD) && !defined(HAVE_BROKEN_PREAD) os_mutex_enter(os_file_count_mutex); os_file_n_pending_preads++; os_n_pending_reads++; os_mutex_exit(os_file_count_mutex); n_bytes = pread(file, buf, (ssize_t)n, offs); os_mutex_enter(os_file_count_mutex); os_file_n_pending_preads--; os_n_pending_reads--; os_mutex_exit(os_file_count_mutex); return(n_bytes); #else { off_t ret_offset; ssize_t ret; #ifndef UNIV_HOTBACKUP ulint i; #endif /* !UNIV_HOTBACKUP */ 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 */ ret_offset = lseek(file, offs, SEEK_SET); if (ret_offset < 0) { ret = -1; } else { ret = read(file, buf, (ssize_t)n); } #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); return(ret); } #endif }
标签:
原文地址:http://www.cnblogs.com/taek/p/4995835.html