mirror of
git://sourceware.org/git/lvm2.git
synced 2025-09-08 13:44:19 +03:00
aux: add corrupt_dev
Add function to corrupt some bytes in give file path presenting a device. 1st. patern in just once replaced with 2nd. pattern. Usable to simulate some bit corruption for integrity devices.
This commit is contained in:
@@ -952,6 +952,25 @@ clear_devs() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# corrupt device content
|
||||||
|
# $1 file_path
|
||||||
|
# $2 string/pattern search for curruption
|
||||||
|
# $3 string/pattern replacing/corruptiong
|
||||||
|
corrupt_dev() {
|
||||||
|
local a
|
||||||
|
|
||||||
|
# search for string on a file
|
||||||
|
# Note: returned string may possibly start with other ASCII chars
|
||||||
|
# a[0] is position in file, a[1] is the actual string
|
||||||
|
a=( $(strings -t d -n 64 "$1" | grep -m 1 "$2") ) || true
|
||||||
|
|
||||||
|
test -n "${a[0]-}" || return 0
|
||||||
|
|
||||||
|
# Seek for the sequence and replace it with corruption pattern
|
||||||
|
echo -n "${a[1]/$2/$3}" | dd of="$1" bs=1 oseek="${a[0]}" conv=fdatasync
|
||||||
|
}
|
||||||
|
|
||||||
prepare_backing_dev() {
|
prepare_backing_dev() {
|
||||||
local size=${1=32}
|
local size=${1=32}
|
||||||
shift
|
shift
|
||||||
|
Reference in New Issue
Block a user