简体   繁体   English

如何使 du 命令抛出输入/输出错误

[英]How to make du command throw input/output error

How to make du command throw input/output error .如何使du命令抛出input/output error For some reason, I want to reproduce this use case and want to verify my fix before changes pushed to production.出于某种原因,我想重现此用例并希望在将更改推送到生产之前验证我的修复。 I am not able to understand how to reproduce this use case.我无法理解如何重现此用例。 I tried so many thing, but no luck.我尝试了很多东西,但没有运气。 Any other command also fine which throws input/output error for file system.任何其他命令也可以为文件系统引发输入/输出错误。

Eg例如

du -sh /data/
du: cannot access '/data/': Input/output error

The error message appears to be EIO .错误消息似乎是 EIO The man page says手册页

EIO Input/output error (POSIX.1-2001).

In-turn, POSIX says :反过来, POSIX 说

Input/output error.输入/输出错误。 Some physical input or output error has occurred.发生了一些物理输入或 output 错误。 This error may be reported on a subsequent operation on the same file descriptor.对同一文件描述符的后续操作可能会报告此错误。 Any other error-causing operation on the same file descriptor may cause the [EIO] error indication to be lost.对同一文件描述符的任何其他导致错误的操作都可能导致 [EIO] 错误指示丢失。

So, where does that leave you?那么,这让你何去何从? Well, you need to somehow simulate du receiving EIO from a syscall.好吧,您需要以某种方式模拟 du 从系统调用接收 EIO。 You should be able to use strace to make an arbitrary syscall return EIO , but which one?您应该能够使用 strace 使任意系统调用返回 EIO ,但是哪一个呢?

Start by running du under strace to see which syscalls might return EIO.首先在 strace 下运行du以查看哪些系统调用可能返回 EIO。 fstat(2) does not return EIO on Linux, so it must be another syscall. fstat(2) 不会在 Linux 上返回 EIO,因此它必须是另一个系统调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM