[comp.unix.wizards] How do I tell physio that my device has reached EOF?

name@portia.Stanford.EDU (tony cooper) (11/16/89)

In the context of a raw device driver for a tape drive, physio() tells
my strategy routine to schedule that 16 blocks of data be put into a
buf buffer. My device transfers 14 blocks then reaches EOF. My question
is this: How do I report back to physio() that 14 blocks have been put
into the buf structure and that EOF has been reached.

When I try:
                            bp->b_resid = 2*512;   /* 2 blocks unread */
                            bp->b_flags &= ~B_ERROR;
                            bp->b_error = 0;
			    iodone(bp);

physio() realises that only 14 blocks were read and does the right thing
with them. But then it comes back and asks for another 16 blocks, not
realizing that EOF has been reached. The device obliges by reading 16
blocks from the next file on the tape drive since the tape was positioned
ready for the next file.

In the case that 16 blocks were unread instead of 2 before the EOF was
reached then bp->b_resid equals 16 blocks and physio() accepts that EOF
has been reached and doesn't ask for any more. But for less than 16 blocks
unread, this does not work. I have tried things such as setting b_count
to zero or to b_resid, but with no luck.

A solution to this problem would be greatly appreciated. Thanks.

Tony Cooper
tony@popserver.stanford.edu
name@portia.stanford.edu

allbery@NCoast.ORG (Brandon S. Allbery) (11/17/89)

As quoted from <6705@portia.Stanford.EDU> by name@portia.Stanford.EDU (tony cooper):
+---------------
| In the context of a raw device driver for a tape drive, physio() tells
| my strategy routine to schedule that 16 blocks of data be put into a
| buf buffer. My device transfers 14 blocks then reaches EOF. My question
| is this: How do I report back to physio() that 14 blocks have been put
| into the buf structure and that EOF has been reached.
+---------------

Combining your posting with my experience with this on the user-process end, I
conclude that your driver must remember that it hit EOF and report transfer-
ring 0 blocks on subsequent calls or until the driver is sent a command to
advance to the next file on the tape.

Related or not I don't know, not being a kernel hack, but:  from the user
process end, read() works this same way.  The last block in a file returns a
short count, then 0 is returned by subsequent reads.

++Brandon
-- 
Brandon S. Allbery    allbery@NCoast.ORG, BALLBERY (MCI Mail), ALLBERY (Delphi)
uunet!hal.cwru.edu!ncoast!allbery ncoast!allbery@hal.cwru.edu bsa@telotech.uucp
*(comp.sources.misc mail to comp-sources-misc[-request]@backbone.site, please)*
*Third party vote-collection service: send mail to allbery@uunet.uu.net (ONLY)*
expnet.all: Experiments in *net management and organization.  Mail me for info.