- 论坛徽章:
- 0
|
有这么一个文件,通过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.
难道现实真的像这位仁兄回复的这么悲惨吗? |
|