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
The error message appears to be EIO. The man page says
In-turn, POSIX says:
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
duunder strace to see which syscalls might return EIO. fstat(2) does not return EIO on Linux, so it must be another syscall.