EIO Input/output error (POSIX.1)
另外,根据read(2)的说法:
EIO I/O error. This will happen for example when the process is
in a background process group, tries to read from its
controlling terminal, and either it is ignoring or blocking
SIGTTIN or its process group is orphaned. It may also occur
when there is a low-level I/O error while reading from a
disk or tape.
EIO A low-level I/O error occurred while modifying the inode.
因此,模拟特定的错误代码可能很困难;注意到I / O还有其他系统调用,特别是writev(2)和(间接)mmap(2),但read(2)和write(2)是最常见的。
但是,一般来说,大多数软件都没有专门处理EIO w.r.t.其他错误代码;您可能通过获取其他错误代码进行了足够的测试,例如
EDQUOT The user's quota of disk blocks on the filesystem containing
the file referred to by fd has been exhausted.
如果你真的想特别伪造EIO你可能会对设备造成物理损坏(或者可能只是在错误的时刻拔掉USB磁盘)或编写自己的Filesystem in User Space(FUSE)来模拟它。我不认为这是值得的努力(因为当某些东西得到EIO整个计算机变得非常快速无法使用,并且用户将注意到无论如何....并且因为大多数软件同样处理所有错误代码 - 除了EINTR)
在代码的C部分,您可能想要使用strerror(3)(可能使用syslog(3))和/或perror(3)。我不确定是否值得努力处理EIO与大多数其他错误的区别。
注意:许多关键域都有标准,用于定义如何处理错误以及应该开发和测试代码,例如:汽车中的ISO26262或航空电子设备中的DO-178B。遵循您的域名标准。