免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2361 | 回复: 1
打印 上一主题 下一主题

[函数] 请教:如果mmap的文件出现IO错误会怎样??? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-03-03 14:25 |只看该作者 |倒序浏览
有这么一个文件,通过read/write读写它会出现IO错误(errno为EIO,存储该文件的某些扇区确实已经损坏)。
如果以mmap的方式来操作这个文件,怎么样才能知道访问这个文件的过程中是否出现了IO错误?

我在网上搜索到了一个对该问题的回答:
Sakagami Hiroki wrote:
> Hi,
>
> When I open() a file on the disk and perform read() / write()
> operations on the descriptor, I can detect a physical disk
> I/O error by checking the return code and errno.

If O_SYNC has not been specified while opening the file, the return
code does not tell you if a physical error has occured.

> But when I mmap() a file on the disk and perform memcpy() on
> the mapped area, how do I know whether a disk error occurs?

You'll get a signal. Not sure which, probably SIGSEGV or SIGBUS.

难道现实真的像这位仁兄回复的这么悲惨吗?

论坛徽章:
0
2 [报告]
发表于 2011-03-03 18:44 |只看该作者
#include <sys/mman.h>

       void *mmap(void *addr, size_t length, int prot, int flags,
                  int fd, off_t offset);
       int munmap(void *addr, size_t length);

   有返回值 自己判断
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP