Skip to content

Of character and block devices

While playing around with an OpenBSD system, I came across the different represenation of disk devices in BSD systems again:

$ ls -l /dev/{r,}wd0c
crw-r-----  1 root  operator   11,   2 Jun 28 02:22 /dev/rwd0c
brw-r-----  1 root  operator    0,   2 Jun 28 02:22 /dev/wd0c

$ pv -Ss 200m < /dev/wd0c > /dev/null  
 200MiB 0:00:11 [17.5MiB/s] [==================>] 100%

$ pv -Ss 200m < /dev/rwd0c > /dev/null 
 200MiB 0:00:03 [56.4MiB/s] [==================>] 100%
The FreeBSD Architecture Handbook documents this quite nicely:

  > Block devices are disk devices for which the kernel provides
  > caching. This caching makes block-devices almost unusable,
  > or at least dangerously unreliable. The caching will reorder
  > the sequence of write operations, depriving the application of
  > the ability to know the exact disk contents at any one instant
  > in time.
In short: don't use block devices on BSD systems but use their raw (character) devices instead, at least when accessing them directly.