How do I flush buffers from a script?

How do I flush buffers from a script?

Post by Chris Tophe » Wed, 25 Jul 2001 04:38:07



I have a floppy formatting/testing script.  In order to verify that
written data is correct, I have to manually eject the floppy and
reinsert it to "dirty" the Unix buffers.

Is there a way to "dirty" the IO buffers from my script?

 
 
 

How do I flush buffers from a script?

Post by Gardner Buchan » Wed, 25 Jul 2001 07:53:20




Quote:> I have a floppy formatting/testing script.  In order to verify that
> written data is correct, I have to manually eject the floppy and
> reinsert it to "dirty" the Unix buffers.

> Is there a way to "dirty" the IO buffers from my script?

If you unmount the filesystem, everything is flushed to the media
at that point.  You can do the same thing with sync, except that
it might complete asyncronously so your script can't assume the
operation is complete just because the sync command finished.

When I need to "verify" a removable medium like a floppy or a tape,
I usually just dd it from the raw device into /dev/null.  The dd
will moan if there are media errors and your script can check for
status reliably.  You can also look at the dd output to see how
many blocks of what sizes were read and how fast, if you need a
more sophisticated view of how well the medium can be read.

Reads to the raw device (/dev/rfd0) ALWAYS translate into physical
reads.  There is no buffering.  Only filesystem I/O going on via
the kernel's filesystem implementation is buffered.  I recall that
FreeBSD has dropped the old block-device semantics and even block
(cooked) devices work like raw devices when userland processes try
to use them.

============================================================

Ottawa, ON             FreeBSD: Where you want to go. Today.

 
 
 

How do I flush buffers from a script?

Post by Chris Tophe » Thu, 26 Jul 2001 15:26:06





> > Is there a way to "dirty" the IO buffers from my script?

> If you unmount the filesystem, everything is flushed to the media
> at that point.  You can do the same thing with sync, except that
> it might complete asyncronously so your script can't assume the
> operation is complete just because the sync command finished.

But I never have the thing mounted. I"m writing 1's and 0's, reading
them back, writing 0's and 1', reading them back.  Writing with
">" which I think waits for completion.  In any case, that's not my
problem.  The problem is that if I read the data back off the floppy
then the OS reads from a buffer, not from the floppy.  At least that's
how I understood it to work (and think I remeber observing) on Linux
where I wrote the first version of the script.  More below.

Quote:> When I need to "verify" a removable medium like a floppy or a tape,
> I usually just dd it from the raw device into /dev/null.  The dd
> will moan if there are media errors and your script can check for
> status reliably.  You can also look at the dd output to see how
> many blocks of what sizes were read and how fast, if you need a
> more sophisticated view of how well the medium can be read.

I think that only detects errors in the floppy formatting.  I'm
letting the "fdformat" command (with verification) handle that part.
I don't know if that even touches the data bytes.  I'd be nice to
know what it does.

Quote:> Reads to the raw device (/dev/rfd0) ALWAYS translate into physical
> reads.  There is no buffering.  Only filesystem I/O going on via
> the kernel's filesystem implementation is buffered.  I recall that
> FreeBSD has dropped the old block-device semantics and even block
> (cooked) devices work like raw devices when userland processes try
> to use them.

Now THAT's interesting.  Sounds like the buffers don't exist and so
don't need to be dirtied on FreeBSD.  Guess I should try some
experiments and try to verify that for my own satisfaction.  I must
admit to not experimenting with my FreeBSD version.

Thanks much.

 
 
 

How do I flush buffers from a script?

Post by Gardner Buchan » Fri, 27 Jul 2001 05:09:56




Quote:

> But I never have the thing mounted. I"m writing 1's and 0's, reading
> them back, writing 0's and 1', reading them back.  Writing with
> ">" which I think waits for completion.  In any case, that's not my
> problem.  The problem is that if I read the data back off the floppy
> then the OS reads from a buffer, not from the floppy.  At least that's
> how I understood it to work (and think I remeber observing) on Linux
> where I wrote the first version of the script.  More below.

Are you saying you do something like this?:

  cat > /dev/rfd0

If yes, then indeed, when the command is done, the stuff is written.

">" is a bad idea with raw devices though, because they will insist on
being read/written in block-sized pieces.  Stdio doesn't always do this
but things like tar and dd will - or can be persuaded to.

Quote:

>> When I need to "verify" a removable medium like a floppy or a tape,
>> I usually just dd it from the raw device into /dev/null.

> I think that only detects errors in the floppy formatting.  I'm

Yes, in a way.  I've always found that that is the source of problems
with removable media though.  I trust the OS to write what I tell
it to.  I boldy assume that if (1) the write succeeded and (2)
something can be read back that this implies what I wrote can be
read.

Quote:> letting the "fdformat" command (with verification) handle that part.
> I don't know if that even touches the data bytes.  I'd be nice to
> know what it does.

It formats and then reads to be sure that the tracks actually work.
For bulk diskette handling, your best bet is to format without verify,
then write, then verify what you've written.  The extra verification
after formatting is mostly wasted since, on average, the media is okay
and you're going to go and verify it afterwards anyway.

Quote:

>> Reads to the raw device (/dev/rfd0) ALWAYS translate into physical
>> reads.  There is no buffering.

> Now THAT's interesting.  Sounds like the buffers don't exist and so
> don't need to be dirtied on FreeBSD.  Guess I should try some
> experiments and try to verify that for my own satisfaction.  I must
> admit to not experimenting with my FreeBSD version.

Not just FreeBSD; all Unixen do this.  I think it is a Posix spec.
I said reads, but the same goes for writes too.

Quote:> Thanks much.

Pro noblem,

============================================================

Ottawa, ON             FreeBSD: Where you want to go. Today.

 
 
 

How do I flush buffers from a script?

Post by Steve O'Hara-Smit » Fri, 27 Jul 2001 15:06:15


On Wed, 25 Jul 2001 20:09:56 GMT

GB> ">" is a bad idea with raw devices though, because they will insist on
GB> being read/written in block-sized pieces.  Stdio doesn't always do this
GB> but things like tar and dd will - or can be persuaded to.

        There is no block/character device distinction in FreeBSD so this no
longer applies. All devices are character devices.

--
    Directable Mirrors - A Better Way To Focus The Sun

                        http://www.best.com/~sohara

 
 
 

How do I flush buffers from a script?

Post by Gardner Buchan » Thu, 02 Aug 2001 07:58:52




> On Wed, 25 Jul 2001 20:09:56 GMT

> GB> ">" is a bad idea with raw devices though, because they will insist on
> GB> being read/written in block-sized pieces.  Stdio doesn't always do this
> GB> but things like tar and dd will - or can be persuaded to.

>    There is no block/character device distinction in FreeBSD so this no
> longer applies. All devices are character devices.

This is not a block/character issue.  Watch:




dd: /dev/rfd0: Invalid argument


1+0 records in
1+0 records out
512 bytes transferred in 1.350958 secs (379 bytes/sec)

If bs=511 it fails, but if bs=512 it works.  Multiples of 512
are required for this device.

============================================================

Ottawa, ON             FreeBSD: Where you want to go. Today.

 
 
 

How do I flush buffers from a script?

Post by Steve O'Hara-Smit » Fri, 03 Aug 2001 02:17:56


On Tue, 31 Jul 2001 22:58:52 GMT

GB> >     There is no block/character device distinction in FreeBSD so this no
GB> > longer applies. All devices are character devices.
GB> >
GB>
GB> This is not a block/character issue.  Watch:
<snip example>

        So I see, my main point was that /dev/rfd0 and /dev/fd0 are the
*same* (9,0), I had thought (without testing) that this would imply that
blocking is irrelevant, actually it seems that it is inescapable.

--
    Directable Mirrors - A Better Way To Focus The Sun

                        http://www.best.com/~sohara

 
 
 

1. doing buffered RPC via clnt_call: how to do a buffer flush?

Hi,

   at the university I am trying to write a fast client/server application
using RPC (tcp mode).
For this I am trying to force RPC to buffer RPC calls which do not need a return
value locally at the client. This should greatly increase the speed of
my application as I do not have to wait for the servers response at every call.

I have figured out to use the buffered clnt_call
   (see RPCs clnt_tcp.c:
      * TCP based RPC supports 'batched calls'.
      * A sequence of calls may be batched-up in a send buffer.  The rpc call
      * return immediately to the client even though the call was not necessaril
      * sent.  The batching occurs if the results' xdr routine is NULL (0) AND
      * the rpc timeout value is zero (see clnt.h, rpc).
    )
This buffers the RPC locally at the client, but seem not send the RPC call
to the server regulary.

My question:

  How do I force RPC to send the buffer contents from the client to the server?
  (how do I flush the buffer).

Any hint is appreciated.


Many thanks.

-- Birgit

2. kppp timeout in corel and kde

3. Netscape3.0b and JavaScript/Java errors

4. Make fails in script in Linux Test Project

5. HP JetDirect: Flushing buffer on printer

6. DCE. secd won't restart... Replica cannot get local host identity

7. Well, flush my buffers!

8. Automatically flushing STDOUT buffer?

9. Forcing a flush of stdout buffer

10. No way to flush rx buffer in serial driver?

11. How to flush UDP socket buffer?