#!/bin/sh

# Check how ftruncate, lseek and stat family syscalls are traced.

. "${srcdir=.}/init.sh"

check_prog dd
check_prog find

EXPECTED="$LOG.expected"
size=46118400000
sample=stat_sample

rm -f $sample
umask 022

run_prog_skip_if_failed \
	dd seek=$size bs=1 count=0 if=/dev/null of=$sample
run_strace -edesc $args

r_ftruncate="ftruncate(64)?\\(1, $size\\) += 0"
r_lseek="lseek\\(1, $size, SEEK_CUR\\) += $size"
r_llseek="_llseek\\(1, $size, \\[$size\\], SEEK_CUR\\) += 0"

cat > "$EXPECTED" << __EOF__
$r_ftruncate
$r_lseek|$r_llseek
__EOF__

match_grep "$LOG" "$EXPECTED"

run_prog_skip_if_failed \
	find -L $sample -quit
run_strace -efile $args

stat="\\{st_mode=S_IFREG\\|0644, st_size=$size, \\.\\.\\.\\}"
r_stat="stat(64)?\\(\"$sample\", $stat\\) += 0"
r_fstatat="(new)?fstatat(64)?\\(AT_FDCWD, \"$sample\", $stat, 0\\) += 0"

cat > "$EXPECTED" << __EOF__
$r_stat|$r_fstatat
__EOF__

match_grep "$LOG" "$EXPECTED"

run_prog_skip_if_failed \
	find $sample -quit
run_strace -efile $args

r_lstat="lstat(64)?\\(\"$sample\", $stat\\) += 0"
r_lfstatat="(new)?fstatat(64)?\\(AT_FDCWD, \"$sample\", $stat, AT_SYMLINK_NOFOLLOW\\) += 0"

cat > "$EXPECTED" << __EOF__
$r_lstat|$r_lfstatat
__EOF__

match_grep "$LOG" "$EXPECTED"

rm -f "$EXPECTED" $sample

exit 0