diff options
Diffstat (limited to 'ctdb/tests/UNIT/eventscripts/stubs/stat')
-rwxr-xr-x | ctdb/tests/UNIT/eventscripts/stubs/stat | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/ctdb/tests/UNIT/eventscripts/stubs/stat b/ctdb/tests/UNIT/eventscripts/stubs/stat new file mode 100755 index 0000000..71508f6 --- /dev/null +++ b/ctdb/tests/UNIT/eventscripts/stubs/stat @@ -0,0 +1,71 @@ +#!/bin/sh + +usage () +{ + echo "stat -c FMT FILE ..." + exit 1 +} + +format="" + +while getopts "c:h:?" opt ; do + case "$opt" in + c) format="$OPTARG" ;; + \?|h) usage ;; + esac +done +shift $((OPTIND - 1)) + +fake_device_id () +{ + _path="$1" + + _t=$(echo "$FAKE_FILE_ID_MAP" | + awk -v path="${_path}" '$1 == path { print $2 }') + _major_minor="${_t%:*}" + _major="0x${_major_minor%:*}" + _minor="0x${_major_minor#*:}" + _device_id=$((_major * 256 + _minor)) + echo "$_device_id" +} + +fake_inode () +{ + _path="$1" + + _t=$(echo "$FAKE_FILE_ID_MAP" | + awk -v path="${_path}" '$1 == path { print $2 }') + echo "${_t##*:}" +} + +if [ -n "$format" ] ; then + for f ; do + if [ ! -e "$f" ] ; then + continue + fi + case "$f" in + /*) path="$f" ;; + *) path="${PWD}/${f}" ;; + esac + + case "$format" in + "s#[0-9a-f]*:[0-9a-f]*:%i #%n #") + inode=$(fake_inode "$path") + echo "s#[0-9a-f]*:[0-9a-f]*:${inode} #${f} #" + ;; + "%d:%i") + device_id=$(fake_device_id "$path") + inode=$(fake_inode "$path") + echo "${device_id}:${inode}" + ;; + *) + echo "Unsupported format \"${format}\"" + usage + ;; + esac + done + + exit +fi + +usage |