Sortix rw is a program that reads blocks from the standard input and copies them to the standard output until the end of the standard input. rw(1) is designed to be a replacement for dd(1), providing only the the core blockwise I/O. reddit / BSD ---------------------------------------------------------------------- choombak · 2018-05-30 15:42 Ummm... okay... I'll stick with and prefer dd. Difference between dd and rw? A shell script. ---------------------------------------------------------------------- MaxPayneNoir · 2018-05-30 15:53 > rw is not yet able to determine the size of block devices on Illumos, Minix, NetBSD, and OpenBSD ---------------------------------------------------------------------- ILikeLeptons · 2018-05-31 02:43 in what context would using rw be a better fit than using dd? ---------------------------------------------------------------------- DHermit · 2018-05-31 14:19 Your Archlinux command shows pacaur, which is unmaintained Maybe just link to the aur page? ---------------------------------------------------------------------- Kernigh · 2018-06-03 20:16 So how do I get the size of a block device in OpenBSD? The only way that works for me is to look at the disklabel. [The code at rw.c line 442](https://gitlab.com/sortix/rw- portable/blob/master/rw.c#L442) calls fstat(2) and looks at st_size. If that is zero, it tries to lseek(2) to the end of the file. I try both with OpenBSD 6.3 and /dev/sd2i (a DOS filesystem on a USB stick), using interactive Ruby: # su kernigh -c irb25 3 i = IO.for_fd(3) => # irb(main):002:0> i.stat.size => 0 irb(main):003:0> i.seek(0, IO::SEEK_END) => 0 Both answer with a size of zero. If I use the disklabel, I get a larger size: # disklabel sd2 ... 16 partitions: # size offset fstype [fsize bsize cpg] c: 15790215 0 unused i: 15775767 63 MSDOS # /mnt/sd2 ---------------------------------------------------------------------- Sortie · 2018-06-07 21:38 It's overall more usable in my opinion and has better defaults. It doesn't emit progress information by default, so it's more useful in scripting. It lets you express block sizes, counts, and offsets in more useful formats rather than requiring you to compute it manually. For instance, you can do “rw -i /dev/foo -I -512 -c 512 " to read the last 512 bytes of a harddisk. ---------------------------------------------------------------------- Sortie · 2018-06-07 21:42 That's about as far as I got. The disklabel API is very OpenBSD centric. NetBSD also has it, but it's different. The disk label tells me the size of the backing block device, not of the partition block size, so it does the wrong thing for partitions. It also may do the wrong thing for unpartitioned block devices, but I think that case might have a fallback disklabel. IMO, OpenBSD should improve and set st_size and let SEEK_END work, but this behavior makes sense based on how block devices are traditionally implemented (but then there should be a simple API to get the actual block device size, not through the disklabel system that's a much lower level). ---------------------------------------------------------------------- Kernigh · 2018-06-08 17:58 I wrote [some code to get the partition size in OpenBSD](https://gist. github.com/kernigh/09ced7c9018272812d2ebf7c5b0b68da). (*Edit to add:* I assume d_version == 1. My code looks would be wrong d_version == 0. I guess that DIOCGDINFO always sets d_version = 1, but I'm not sure.) # ./disksize /dev/rsd2i /dev/sd2i: 8077192704 bytes # ./disksize /dev/rsd2c /dev/sd2c: 8084590080 bytes The size is in bytes, like `disklabel -pb`. I needed to include 6 different headers just to get the size.Users need read permission on the device. (If OpenBSD would set st_size, it would leak the size to users who can't read the device, but can read /dev and stat(2) the device.) My code is wrong for Minix and NetBSD because it uses OpenBSD's DL_GETPSIZE macro. The disklabel in Minix and NetBSD seems obsolete, because it doesn't work with larger disks. The correct way might use DIOCGWEDGEINFO (sys/dkio.h) with struct dkwedge_info (sys/disk.h).