-1

How to make du command throw 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.

E.g.

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

1 Answers1

2

The error message appears to be EIO. The man page says

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

In-turn, POSIX says:

Input/output error. Some physical input or output error has occurred. 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.

So, where does that leave you? Well, you need to somehow simulate du receiving EIO from a syscall. You should be able to use strace to make an arbitrary syscall return EIO, but which one?

Start by running du under strace to see which syscalls might return EIO. fstat(2) does not return EIO on Linux, so it must be another syscall.

Sagar
  • 1,617
  • 9
  • 17
  • Just because it's not in the man page, doesn't mean `du` won't propagate it. This worked for me: `strace -o /dev/null -e inject=fstat:when=4:error=EIO du /home`. Also, I didn't know strace can inject errors, thanks for that. – root Jul 05 '22 at 01:45
  • Thanks Sagar and root. Will try this command. – Subhash Karemore Jul 05 '22 at 13:13