Linux – How to Understand Error Codes

error handlinglinuxsystem-calls

I am working on Linux (Kernel Version 2.6.32.28) laptop.
After I inserted/did file io/removed a SD combo card, I got following errors:

mmcblk0: error -123 sending status command  
mmcblk0: error -123 sending read/write command, response 0x0, card status 0x0  
mmcblk0: error -123 sending requesting status 

Now, I would like to understand what these errors mean.

As I saw few standard error codes are located in arch/powerpc/boot/stdio.h and other scattered at various other places..

Is there any systematic way in Linux to track (& understand) the error codes (in the source) ?

Best Answer

There are standard error values, defined in errno.h. You can look at this file on your system to see the numerical values. On most systems, they're in /usr/include/errno.h or a file that it includes. On Linux, most are in /usr/include/asm-generic/errno-base.h or /usr/include/asm-generic/errno.h, with a few more in /usr/include/bits/errno.h.

If you have a numerical value, call the standard library function strerror or perror to obtain the corresponding error message (in your current locale). From the command line, a quick way to see an error string is one of

perl -MPOSIX -le 'print strerror 123'
python -c 'import os; print os.strerror(123)'
zmodload zsh/system; syserror 123  # in zsh
Related Question