On Wed, Apr 14, 2010 at 12:14:13PM +0000, Paul Stoeber wrote: > The command > cat /dev/zero | dd bs=1000 count=20000 > doesn't always produce the desired number of bytes. > Is this supposed to happen?
Yes, I think so. Reading from a pipe may turn up a block of data smaller than requested. To avoid short reads, use a buffer equal to PIPE_BUF (512), or read directly from /dev/zero, using if=/dev/zero. -Otto > > # cat bug > t=`mktemp` > for i in `jot 100`; do > cat /dev/zero | dd bs=1000 count=20000 > /dev/null 2> $t > grep -q '^20000+0 records in' $t || cat $t > done > rm $t > # sh bug > 18840+1160 records in > 18840+1160 records out > 19285968 bytes transferred in 0.052 secs (364753338 bytes/sec) > 19779+221 records in > 19779+221 records out > 19864200 bytes transferred in 0.059 secs (333040490 bytes/sec) > 19763+237 records in > 19763+237 records out > 19854024 bytes transferred in 0.059 secs (333238624 bytes/sec) > 19556+444 records in > 19556+444 records out > 19726120 bytes transferred in 0.058 secs (338558654 bytes/sec) > 18824+1176 records in > 18824+1176 records out > 19275584 bytes transferred in 0.053 secs (360001942 bytes/sec) > 19902+98 records in > 19902+98 records out > 19939328 bytes transferred in 0.060 secs (330077606 bytes/sec) > 19780+220 records in > 19780+220 records out > 19864920 bytes transferred in 0.059 secs (332617585 bytes/sec) > # > > dmesg: > > OpenBSD 4.7-current (GENERIC) #603: Mon Apr 12 16:28:26 MDT 2010 > dera...@i386.openbsd.org:/usr/src/sys/arch/i386/compile/GENERIC > cpu0: Intel(R) Pentium(R) M processor 1600MHz ("GenuineIntel" 686-class) 1.61 > GHz > cpu0: > FPU,V86,DE,PSE,TSC,MSR,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,TM,SBF,EST,TM2 > real mem = 527265792 (502MB) > avail mem = 501395456 (478MB) > mainbus0 at root > bios0 at mainbus0: AT/286+ BIOS, date 06/10/03, SMBIOS rev. 2.3 @ 0xf5620 (37 > entries) > bios0: vendor American Megatrends Inc. version "0206" date 06/10/2003 > bios0: ASUSTeK Computer Inc. M2N > apm0 at bios0: Power Management spec V1.2 > apm0: AC on, no battery > acpi at bios0 function 0x0 not configured > pcibios at bios0 function 0x1a not configured > bios0: ROM list: 0xc0000/0xd000 > cpu0 at mainbus0: (uniprocessor) > cpu0: Enhanced SpeedStep 1601 MHz: speeds: 1600, 1400, 1200, 1000, 800, 600 > MHz > pci0 at mainbus0 bus 0: configuration mode 1 (bios) > pchb0 at pci0 dev 0 function 0 "Intel 82855GM Host" rev 0x02 > "Intel 82855GM Memory" rev 0x02 at pci0 dev 0 function 1 not configured > "Intel 82855GM Config" rev 0x02 at pci0 dev 0 function 3 not configured > vga1 at pci0 dev 2 function 0 "Intel 82855GM Video" rev 0x02 > wsdisplay0 at vga1 mux 1: console (80x25, vt100 emulation) > wsdisplay0: screen 1-5 added (80x25, vt100 emulation) > intagp0 at vga1 > agp0 at intagp0: aperture at 0xf0000000, size 0x8000000 > inteldrm0 at vga1: irq 5 > drm0 at inteldrm0 > "Intel 82855GM Video" rev 0x02 at pci0 dev 2 function 1 not configured > uhci0 at pci0 dev 29 function 0 "Intel 82801DB USB" rev 0x03: irq 5 > uhci1 at pci0 dev 29 function 1 "Intel 82801DB USB" rev 0x03: irq 5 > uhci2 at pci0 dev 29 function 2 "Intel 82801DB USB" rev 0x03: irq 5 > ehci0 at pci0 dev 29 function 7 "Intel 82801DB USB" rev 0x03: irq 4 > ehci0: timed out waiting for BIOS > usb0 at ehci0: USB revision 2.0 > uhub0 at usb0 "Intel EHCI root hub" rev 2.00/1.00 addr 1 > ppb0 at pci0 dev 30 function 0 "Intel 82801BAM Hub-to-PCI" rev 0x83 > pci1 at ppb0 bus 1 > cbb0 at pci1 dev 3 function 0 "Ricoh 5C476 CardBus" rev 0xa9: couldn't map > interrupt > cbb1 at pci1 dev 3 function 1 "Ricoh 5C476 CardBus" rev 0xa9: couldn't map > interrupt > "Ricoh 5C552 Firewire" rev 0x01 at pci1 dev 3 function 2 not configured > rl0 at pci1 dev 4 function 0 "Realtek 8139" rev 0x10: irq 5, address > 00:e0:18:06:ac:25 > rlphy0 at rl0 phy 0: RTL internal PHY > ipw0 at pci1 dev 5 function 0 "Intel PRO/Wireless 2100" rev 0x04: irq 5, > address 00:04:23:77:1d:5e > ichpcib0 at pci0 dev 31 function 0 "Intel 82801DBM LPC" rev 0x03: 24-bit > timer at 3579545Hz > pciide0 at pci0 dev 31 function 1 "Intel 82801DBM IDE" rev 0x03: DMA, channel > 0 configured to compatibility, channel 1 configured to compatibility > wd0 at pciide0 channel 0 drive 0: <IC25N060ATMR04-0> > wd0: 16-sector PIO, LBA48, 57231MB, 117210240 sectors > wd0(pciide0:0:0): using PIO mode 4, Ultra-DMA mode 5 > atapiscsi0 at pciide0 channel 1 drive 0 > scsibus0 at atapiscsi0: 2 targets > cd0 at scsibus0 targ 0 lun 0: <TOSHIBA, DVD-ROM SD-R2312, 1708> ATAPI 5/cdrom > removable > cd0(pciide0:1:0): using PIO mode 4, Ultra-DMA mode 2 > auich0 at pci0 dev 31 function 5 "Intel 82801DB AC97" rev 0x03usb1 at uhci0: > USB revision 1.0 > uhub1 at usb1 "Intel UHCI root hub" rev 1.00/1.00 addr 1 > usb2 at uhci1: USB revision 1.0 > uhub2 at usb2 "Intel UHCI root hub" rev 1.00/1.00 addr 1 > usb3 at uhci2: USB revision 1.0 > uhub3 at usb3 "Intel UHCI root hub" rev 1.00/1.00 addr 1 > isa0 at ichpcib0 > isadma0 at isa0 > com1 at isa0 port 0x2f8/8 irq 3: ns16550a, 16 byte fifo > pckbc0 at isa0 port 0x60/5 > pckbd0 at pckbc0 (kbd slot) > pckbc0: using irq 1 for kbd slot > wskbd0 at pckbd0: console keyboard, using wsdisplay0 > pms0 at pckbc0 (aux slot) > pckbc0: using irq 12 for aux slot > wsmouse0 at pms0 mux 0 > pcppi0 at isa0 port 0x61 > midi0 at pcppi0: <PC speaker> > spkr0 at pcppi0 > lpt0 at isa0 port 0x378/4 irq 7 > npx0 at isa0 port 0xf0/16: reported by CPUID; using exception 16 > fdc0 at isa0 port 0x3f0/6 irq 6 drq 2 > pcic0 at isa0 port 0x3e0/2 iomem 0xd0000/65536 > pcic0 controller 0: <Intel 82365SL rev 1> has sockets A and B > pcmcia0 at pcic0 controller 0 socket 0 > pcmcia1 at pcic0 controller 0 socket 1 > pcic0: irq 9, polling enabled > biomask ed75 netmask ed75 ttymask ffff > mtrr: Pentium Pro MTRR support > umass0 at uhub0 port 2 configuration 1 interface 0 "SMI Corporation USB DISK" > rev 2.00/11.00 addr 2 > umass0: using SCSI over Bulk-Only > scsibus1 at umass0: 2 targets, initiator 0 > sd0 at scsibus1 targ 1 lun 0: <USB, Stick 2.0 ME, 1100> SCSI0 0/direct > removable > sd0: 967MB, 512 bytes/sec, 1981440 sec total > vscsi0 at root > scsibus2 at vscsi0: 256 targets > softraid0 at root > root on sd0a swap on sd0b dump on sd0b