4

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) ?

4 Answers4

7

From the shell, you can run perror:

$ perror 123
OS error code 123:  No medium found

That comes with MySQL.

If you don't have MySQL, you can use Perl or Python, e.g.:

$ perl -MPOSIX -e 'print strerror(123)'
No medium found

$ python -c 'import os; print os.strerror(123)'
No medium found

In a C program you can use the function with the same name:

void perror(const char *s);

It prints your message s with the reason for the error appended.

Or you can use:

char *strerror(int errnum);

to return the description of the error as a string so you can inspect it or print it how you like.

See man 3 perror and man 3 strerror for details.

Mikel
  • 57,299
  • 15
  • 134
  • 153
6

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
3

It ultimately ends up in errno.h, after multiple #includes That error is ENOMEDIUM, found in /usr/include/asm-generic/errno.h. Did you unmount it before removing it?

Keith
  • 7,914
  • 1
  • 28
  • 29
  • I did not unmount the card before removing it. Do we need to unmount the SD/MMC cards? In the driver implementation (drivers/mmc/core/core.c), it is assumed that card could be removed during the life cycle. I agree that there may be an on-going query (status inquiry, etc.) from kernel (bus) side, and it did not find the medium and raised this error. – TheCottonSilk Feb 28 '11 at 07:27
  • Now, that -123 issue is resolved. Thank you @Keith! The bigger query: (in general) how to track the error codes/numbers in Linux..what path is ideal for it? – TheCottonSilk Feb 28 '11 at 07:31
  • 2
    You must unmount any mounted media before removing it. The kernel may have cached some data and not written it to the media yet. Your system may have automounted it (usually they are set up that way), but must be manually (in GUI or CLI tool) unmounted or ejected before you can safely remove it. All OSes require that. – Keith Feb 28 '11 at 07:32
  • I am not sure about the general question. I always just use grep and track it down in the header files. Perhaps I'll write a Python script. ;-) – Keith Feb 28 '11 at 07:34
  • @Keith: Some OSes make you think you don't need to unmount cleanly, and turn off write buffering for removable media. But it's not a good idea. – Gilles 'SO- stop being evil' Feb 28 '11 at 21:22
  • @Keith perror(1) already does this if you have mysql-server installed. – Mikel Feb 28 '11 at 21:29
1

You may look into a little utility called errno. It is essentially some shell hackery that uses sed to pull out information from the header files mentioned in other answers. The output looks like the following:

$ errno 123
ENOMEDIUM      123     /* No medium found */
$ errno 111
ECONNREFUSED    111     /* Connection refused */
$ errno 122
EDQUOT        122     /* Quota exceeded */
Steven D
  • 46,160
  • 2
    You get the C preprocessor constant, but at the expense of having to install yet another utility, and a not very robust one at that. I'll stick to Perl or Python. Or even zsh, where you also get the constant name with zmodload zsh/system; echo $errnos[123]. – Gilles 'SO- stop being evil' Feb 28 '11 at 22:45