Re: reading a raw device starting from end

From: Amit S. Kale (akale@veritas.com)
Date: Mon Apr 24 2000 - 07:18:12 EST


I suggest following patch to raw.c

--- drivers/char/raw.c Tue Mar 28 11:56:08 2000
+++ raw.c Mon Apr 24 17:44:38 2000
@@ -274,8 +274,12 @@

        if ((*offp & sector_mask) || (size & sector_mask))
                return -EINVAL;
- if ((*offp >> sector_bits) > limit)
+ if ((*offp >> sector_bits) >limit) {
+ if (size) {
+ return -ENXIO;
+ }
                return 0;
+ }

        /*
         * We'll just use one kiobuf

Thanks.
On Fri, 21 Apr 2000, Amit S. Kale wrote:
> On Fri, 21 Apr 2000, Stephen C. Tweedie wrote:
> > Hi,
> >
> > On Fri, Apr 21, 2000 at 04:30:28PM +0530, Amit S. Kale wrote:
> > >
> > > Reading a raw device starting from end returns 0.
> > > If you do a 'dd' to a raw device without specifying count of blocks, it writes
> > > to the end. After this write returns 0 which causes dd to retry the write ( Not
> > > sure why dd retries write ) Thus dd falls into an infinite loop.
> > >
> > > This does not happen on a block device as writing starting from end returns
> > > ENOSPC
> > >
> > > Should this be considered as a bug in dd or incorrect behavior of raw device
> > > driver?
> >
> > I don't know. POSIX certainly doesn't specify exactly what to do in
> > this case. I never use "dd" on raw devices, as (at least on Linux) it
> > does not align its buffers correctly,
>
> Other unixes use bounce buffers so alignment is not required.
> dd in RH6.2 apparently uses page aligned buffers.
>
> > but "lmdd" does not have the
> > problem you describe: it terminates correctly after a short write.
> >
> > Do you know what other Unixen return in this case?
>
> I checked behaviors on solaris. Both dd and raw devices behave differently
> there.
>
> 1. dd on solaris terminates if number of bytes written are less then
> request. The shown by dd is is error 'unexpected short write'
> This happens when a write starts before end of a device and extends beyond it.
> dd on linux is certainly buggy.
>
> 2. raw device returns ENXIO when writing to a raw device starting from end of
> the device.
>
> --
> Amit Kale
> Veritas Software ( http://www.veritas.com )

-- 
Amit Kale
Veritas Software ( http://www.veritas.com )

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Apr 30 2000 - 21:00:07 EST