When using Linux (Debian), I often use dd to copy a disk image to an SD card. I have written a script that throws an error if the device file specified in the "of" option is too large. This keeps me from accidentally blowing away one of my hard disks.
SD_SIZE=$(sudo sfdisk -s ${SD_DEV})
if [ $SD_SIZE -gt 33554432 ]; then
echo "might not be and SD card, exiting"
exit 1
fi
However, if I insert the SD card and forget to unmount it, results are sketchy. Sometimes the copy succeeds and sometimes it fails.
I can amend my script with the answer here: How to check if a filesystem is mounted with a script
However, is there an option in dd with this functionality? (on OS X dd will not write to a mounted disk by default)
Also of interest, why will dd (on OS X) error when trying to copy to a mounted disk? Perhaps some differences in the kernel or dd? Here is the error you get if you try to dd to a drive that is mounted in OS X (10.9):
dd: /dev/diskN: Resource busy, make sure the disk is not in use
I can write to the disk using cp, so perhaps the system calls that dd is making are not as simple as OPEN then WRITE.