Computer Old Farts Forum
 help / color / mirror / Atom feed
From: Steve Jenkin <sjenkin@canb.auug.org.au>
To: COFF <coff@tuhs.org>
Subject: [COFF] Re: Shell script advice: using 'dd' to write multiple media
Date: Tue, 27 Jun 2023 14:43:35 +1000	[thread overview]
Message-ID: <30A876C5-8200-401F-A207-8DA31BEAE233@canb.auug.org.au> (raw)
In-Reply-To: <CAC20D2NEMStT9Fd2a4dDDxPHVwtWpz8K4Bc7Qe6U1NT_9HVt2Q@mail.gmail.com>



> On 27 Jun 2023, at 09:32, Clem Cole <clemc@ccc.com> wrote:
> 
> The trick here is understanding how ibs & obs, EOF is handled and probably osync, then how to use iseek (iskip in modern versions).
> It's not that hard. Its been done many times. 
> 
> One of the more interesting issues with dd is most versions still are single threaded which sucks for most media - particularly f you want to stream things.
> There was a wonderful hack to dd done in the. early 1980s by Tapani Lindgren ddd - double dd - which used two processes and a pipe to control them, so one process was always reading while the other was writing.   You can one it Volume 14, issue 85 in the comp.sources.unix archives.
> 
> Years ago, I hacked up a version using threads to do the same thing with a mutex to protect everything (It ever ran on Windows at some point). 
> ᐧ


Clem,

Thanks very much for the note & comments.

Of course, amongst the many fine things you’ve done,
you’d written a proper, high-quality solution to this problem.
I’d expect no less :)

I take your point:

	‘dd’ is a beast, very subtle with lots of options.
	Very good idea to use ‘osync’ to pad the last block written out to same size.
	[ I’ve never though to do that ]

What I remember about the script is that ‘dd’ didn’t have to be told the number of media to be written.
It detected ‘End of File’ on the input (pipe) and terminated the loop.
It’s this action I’ve never solved.

There were a few other things done in the body of the loop:

	writing to the operator the number of the media, to label it
	reading a response from /dev/tty, to allow the operator to change media

		eg:  read -p "OK? " resp </dev/tty 

I’ve constructed two examples below of splitting input into fixed blocks.
using the easiest repeatable & limited stream I thought of:
	ls -1

When I know the number of blocks, a for loop does exactly what I hope & expect.
Including the trailing short block.

But writing a ‘while’ loop with ‘dd’ as the condition - it’s an infinite loop.

Even though STDIN is exhausted and ‘dd’ knows it, read returns zero bytes,
and ‘dd' doesn’t return an error (because there’s no ‘read error’, just ’No Data').

This Mac example uses ‘bash’.

I think in 1985 it was Bourne shell, maybe Korn shell, definitely not ‘csh’.

cheers
steve

==========

iMac1:~/ steve$ ls -1 | wc -c
 1071404

iMac1:~/ steve$ ls -1 | for i in {1..108}; do dd of=/dev/null bs=10000 count=1;  done
1+0 records in
1+0 records out
10000 bytes transferred in 0.249052 secs (40152 bytes/sec)

… another 105 times

10000 bytes transferred in 0.000011 secs (911805217 bytes/sec)

0+1 records in
0+1 records out
1404 bytes transferred in 0.000007 secs (203062166 bytes/sec)

==========

iMac1:~/ steve$ ls -1 | while dd of=/dev/null bs=10000 count=1; do : ;  done	# ‘:’ is a null command within loop

1+0 records in
1+0 records out
10000 bytes transferred in 0.251171 secs (39813 bytes/sec)

… another 105 times

0+1 records in
0+1 records out
1404 bytes transferred in 0.000009 secs (154968495 bytes/sec)

0+0 records in
0+0 records out
0 bytes transferred in 0.000006 secs (0 bytes/sec)

0+0 records in
0+0 records out
0 bytes transferred in 0.000007 secs (0 bytes/sec)

… and it's an infinite loop, repeating the last group of lines :(

==========
--
Steve Jenkin, IT Systems and Design 
0412 786 915 (+61 412 786 915)
PO Box 38, Kippax ACT 2615, AUSTRALIA

mailto:sjenkin@canb.auug.org.au http://members.tip.net.au/~sjenkin


  reply	other threads:[~2023-06-27  4:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-26 23:09 [COFF] " steve jenkin
2023-06-26 23:21 ` [COFF] " Dave Horsfall
2023-06-26 23:44   ` steve jenkin
2023-06-27 21:01     ` Dave Horsfall
2023-06-26 23:32 ` Clem Cole
2023-06-27  4:43   ` Steve Jenkin [this message]
2023-06-26 23:44 ` Bakul Shah
2023-06-27  3:47   ` Steve Jenkin
2023-06-27 15:50     ` Steffen Nurpmeso
2023-06-27 16:07       ` Steffen Nurpmeso
2023-06-27  0:25 ` segaloco via COFF
2023-06-27  6:23 ` Ralph Corderoy
2023-06-27  6:28   ` Adam Thornton
2023-06-27  6:33     ` Ralph Corderoy
2023-06-27  7:53   ` steve jenkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=30A876C5-8200-401F-A207-8DA31BEAE233@canb.auug.org.au \
    --to=sjenkin@canb.auug.org.au \
    --cc=coff@tuhs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).