image_to_usb.sh: allow writing to character devices

This is useful for debugging, e.g. --to /dev/null. The user will have to
use --force_non_usb to allow this, in which case all bets are off and we
should let her do this.  Also note that, before this fix, using --to
/dev/null would have given a strange error message (target device does
not exist); with it, we're handling all devices in a more comprehensive
way, spitting the right error message when appropriate.

BUG=None
TEST=--to /dev/null dies as expected; works with --force_non_usb

Change-Id: I514e14e1f7cc49b3d6172a2a53aa6da33ef5ecfd
Reviewed-on: https://gerrit.chromium.org/gerrit/41133
Commit-Queue: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
This commit is contained in:
Gilad Arnold 2013-01-11 10:43:04 -08:00 committed by ChromeBot
parent 8f861c05b6
commit 11e0f66cc9

View File

@ -226,7 +226,7 @@ FLAGS_to=`eval readlink -f ${FLAGS_to}`
# Check whether target device is USB/MMC, and obtain a string descriptor for it.
unset disk_string
if [ -b "${FLAGS_to}" ]; then
if [ -b "${FLAGS_to}" -o -c "${FLAGS_to}" ]; then
if list_usb_disks | grep -q '^'${FLAGS_to##*/}'$' ||
list_mmc_disks | grep -q '^'${FLAGS_to##*/}'$'; then
disk_string=$(get_disk_string ${FLAGS_to})
@ -310,7 +310,7 @@ if [ ! -f "${SRC_IMAGE}" ]; then
fi
# Let's do it.
if [ -b "${FLAGS_to}" ]; then
if [ -b "${FLAGS_to}" -o -c "${FLAGS_to}" ]; then
# Output to a block device (i.e., a real USB key / SD card), so need sudo dd
if [ ${FLAGS_install} -ne ${FLAGS_TRUE} ]; then
echo "Copying image ${SRC_IMAGE} to device ${FLAGS_to}..."