# 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);
}

宏os_file_read_func的更多相关文章

  1. Visual Studio 宏的高级用法

    因为自 Visual Studio 2012 开始,微软已经取消了对宏的支持,所以本篇文章所述内容只适用于 Visual Studio 2010 或更早期版本的 VS. 在上一篇中,我已经介绍了如何编 ...

  2. VC 中与字符串相关的宏 _T、TEXT,_TEXT、L 的作用

    CSDN原博文:http://blog.csdn.net/houkai363/article/details/8134787 遇到了:不能将参数 1 从“const char [5]”转换为“LPCT ...

  3. 【转】linux内核中writesb(), writesw(), writesl() 宏函数

    writesb(), writesw(), writesl() 宏函数 功能 : writesb()    I/O 上写入 8 位数据流数据 (1字节) writesw()   I/O  上写入 16 ...

  4. c++宏定义命令

    在程序开始以#开头的命令,他们是预编译命令.有三类预编译命令:宏定义命令.文件包含命令.条件编译命令:今天聊聊宏定义: 宏定义命令将一个标识符定义为一个字符串,源程序中的该标识符均以指定的字符串来代替 ...

  5. dll导入导出宏定义,出现“不允许 dllimport 函数 的定义”的问题分析

    建立dll项目后,在头文件中,定义API宏 #ifndef API_S_H #define API_S_H ...... #ifndef DLL_S_20160424 #define API _dec ...

  6. VC++/MFC 最常用宏和指令

    1.#include指令  包含指定的文件,最基本的最熟悉的指令,编程中不得不用,包含库文件用双尖括号,包含自定义头文件用双引号. 2.#define指令   预定义,通常用它来定义常量(包括无参量与 ...

  7. [Sass]混合宏的参数

    [Sass]混合宏的参数--传一个不带值的参数 Sass 的混合宏有一个强大的功能,可以传参,那么在 Sass 中传参主要有以下几种情形: A) 传一个不带值的参数 在混合宏中,可以传一个不带任何值的 ...

  8. [Sass]混合宏

    [Sass]混合宏-声明混合宏 如果整个网站中有几处小样式类似,比如颜色,字体等,在 Sass 可以使用变量来统一处理,那么这种选择还是不错的.但当你的样式变得越来越复杂,需要重复使用大段的样式时,使 ...

  9. BOOST_AUTO宏

    在boost中,有个非常不错的宏BOOST_AUTO(),它的作用是自动给var定义类型,适合function()函数返回的值的类型. int function() { ; } main() { BO ...

随机推荐

  1. Android ADB 端口占用问题解决方案

    问题描述: The connection to adb is down, and a severe error has occured. You must restart adb and Eclips ...

  2. 阿里云之OSS 开放存储服务开发笔记

    在使用云服务以后,你不用考虑他是否能承受压力,而是费用.不要考虑是否被攻击,而是他的API实现.本人开发阿里云服务也走了些崎岖之路,写下以备忘之. 阿里云的开放存储服务可以提供文件的存储服务,开放了上 ...

  3. Problem 1016 咒文卷轴 优先队列+前缀和+rmq

    题目链接: 题目 Problem 1016 咒文卷轴 Time Limit: 3000 mSec Memory Limit : 131072 KB 问题描述 小Y 是一个魔法师,有一天他获得了一卷神秘 ...

  4. The 10th Zhejiang Provincial Collegiate Programming Contest

    Applications http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5008 string set 专场 #include& ...

  5. nenu contest2

    http://vjudge.net/vjudge/contest/view.action?cid=54562#overview H  B. Polygons http://codeforces.com ...

  6. 设置Eclipse智能提示

    原地址:http://blog.csdn.net/sz_bdqn/article/details/4956162 今天有点时间,研究了一下MyEclispse的智能感知的功能.刚开始使用它时总是感觉如 ...

  7. gcd 最大公约数 模版!

    1: #define ll long long ll gcd(ll a,ll b) { ) { return b; }else { return gcd(b % a,a); } } 2: int64 ...

  8. abs(INT_MAX-(-1))

    写一个程序,结果总是不对,check逻辑好几遍也没发现错误,无奈之下debug.发现一个有趣的现象abs(INT_MAX-(-1))返回值是-2147483648.于是看了下abs函数的代码实现. i ...

  9. DP:LCS(最长公共子串、最长公共子序列)

    1. 两者区别 约定:在本文中用 LCStr 表示最长公共子串(Longest Common Substring),LCSeq 表示最长公共子序列(Longest Common Subsequence ...

  10. 李洪强漫谈iOS开发[C语言-040]-switch case

    李洪强漫谈iOS开发[C语言-039]-switch case 补充: