Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question

migrated from stackoverflow.com Feb 28 '11 at 20:33

This question came from our site for professional and enthusiast programmers.

add comment

4 Answers 4

up vote 4 down vote accepted

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
share|improve this answer
    
Thank you, @Gilles. I think, in python solution, os.strerror is required.. –  TheCottonSilk Mar 1 '11 at 5:28
    
@TheCottonSilk: Thanks, fixed. Note that you can now suggest edits on any post. –  Gilles Mar 1 '11 at 8:01
add comment

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?

share|improve this answer
    
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 7: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 7: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 7: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 7: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 Feb 28 '11 at 21:22
show 1 more comment

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.

share|improve this answer
    
perror(1)? I never knew that. Oh, it's from MySQL, not everybody has this. –  Gilles Feb 28 '11 at 21:31
    
@Gilles D'oh, you beat me to the perl version! ;-) –  Mikel Feb 28 '11 at 21:37
    
Thank you, @Mikel! I never knew these many options are available..or am I lucky to be here!!! :) –  TheCottonSilk Mar 1 '11 at 5:32
add comment

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 */
share|improve this answer
1  
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 Feb 28 '11 at 22:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.