Failed writes to block devices don't report an error

Sebastian Huber sebastian.huber at
Wed Jun 23 07:32:40 UTC 2010


On 06/23/2010 03:18 AM, Chris Johns wrote:
> On 22/06/10 11:03 PM, Arnout Vandecappelle wrote:
>> 1. Make sure rtems_bdbuf_sync() returns an error if the write fails.
>> rtems_bdbuf_sync() is called when disks or files are sync'ed.  It writes
>> back a block and waits for the writeback to finish.  Currently, it always
>> returns successfully but we could put error detection code in here.
> This would be good to have. I see it being needed which ever way we go.
> I also see the following:
>  if (write(fd, buf, size) != size)
>    goto handle_error
>  if (sync_call(..) < 0)
>    goto handle_error
> in an application could be a work around until a more standard approach
> is made. I prefer this over the other suggestions.

Yes, this should be the first step.

>> 4. In the block device driver itself (spi-sd-card.c in my case),
>> detect that
>> the media is removed and take appropriate action.  I'm not entirely sure,
>> though, what 'appropriate action' would be.
> I know Sebastian has something like this for USB devices. Maybe he can
> help here.

The USB mass storage driver returns an error in case the USB device vanished.
Since the application will notice this only in case of reads you have to read
from time to time currently to detect a device removal.  You have to be very
careful to clean up used file systems and unmount the file system (unused!).
To unmount a file system in use will likely lead to heap corruption.  For have
written a media manager for this purpose.  It executes standard actions in case
of media attach and detach events.

> I also think we should think about adding error stat reporting at the
> device layer in a standard manner. A little like network drivers have so
> application can monitor the devices and manage any issues it sees as
> important. I see this as a device issue not a a bdbuf thing. You open
> the device node and perform the error stat ioctl call to get the stats.

We should also consider to add statistics to bdbuf to measure errors and

Have a nice day!

Sebastian Huber, embedded brains GmbH

Address : Obere Lagerstr. 30, D-82178 Puchheim, Germany
Phone   : +49 89 18 90 80 79-6
Fax     : +49 89 18 90 80 79-9
E-Mail  : sebastian.huber at
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

More information about the users mailing list