sparsify: Prevent overwriting block or char output devices (RHBZ#1056290).

virt-sparsify doesn't work if the output is a block device, and cannot
possibly work if the output is a char device.  Currently if you try
this it actually overwrites (deletes) the output device which is not
exactly desirable.  Therefore throw an error and exit.

Cherry picked from commit 13bca32e4e.
Added additional supporting functions is_block_device and
is_char_device from upstream.
This commit is contained in:
Richard W.M. Jones
2014-01-22 13:10:08 +00:00
parent 7be678d7f7
commit 05d53de9cd

View File

@@ -151,6 +151,23 @@ read the man page virt-sparsify(1).
if contains_colon outdisk then
error (f_"output filename '%s' contains a colon (':'); qemu-img command line syntax prevents us from using such an image") outdisk;
(* Check the output is not a block or char special (RHBZ#1056290). *)
let is_block_device file =
try (Unix.stat file).Unix.st_kind = Unix.S_BLK
with Unix.Unix_error _ -> false
and is_char_device file =
try (Unix.stat file).Unix.st_kind = Unix.S_CHR
with Unix.Unix_error _ -> false
in
if is_block_device outdisk then
error (f_"output '%s' cannot be a block device, it must be a regular file")
outdisk;
if is_char_device outdisk then
error (f_"output '%s' cannot be a character device, it must be a regular file")
outdisk;
indisk, outdisk, compress, convert,
debug_gc, format, ignores, machine_readable,
option, quiet, verbose, trace, zeroes