1#!/bin/sh 2# test diagnostics are printed immediately when seeking beyond device. 3 4# Copyright (C) 2008-2023 Free Software Foundation, Inc. 5 6# This program is free software: you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation, either version 3 of the License, or 9# (at your option) any later version. 10 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <https://www.gnu.org/licenses/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ dd 21 22# need write access to local device 23# (even though we don't actually write anything) 24require_root_ 25require_local_dir_ 26 27get_device_size() { 28 BLOCKDEV=blockdev 29 $BLOCKDEV -V >/dev/null 2>&1 || BLOCKDEV=/sbin/blockdev 30 $BLOCKDEV --getsize64 "$1" 31} 32 33 34# Get path to device the current dir is on. 35# Note df can only get fs size, not device size. 36device=$(df --output=source . | tail -n1) || framework_failure_ 37 38dev_size=$(get_device_size "$device") || 39 skip_ "failed to determine size of $device" 40 41# Don't use shell arithmetic as older versions of dash use longs 42DEV_OFLOW=$(expr $dev_size + 1) || framework_failure_ 43 44timeout 10 dd bs=1 skip=$DEV_OFLOW count=0 status=noxfer < "$device" 2> err 45test "$?" = "1" || fail=1 46echo "dd: 'standard input': cannot skip: Invalid argument 470+0 records in 480+0 records out" > err_ok || framework_failure_ 49compare err_ok err || fail=1 50 51timeout 10 dd bs=1 seek=$DEV_OFLOW count=0 status=noxfer > "$device" 2> err 52test "$?" = "1" || fail=1 53echo "dd: 'standard output': cannot seek: Invalid argument 540+0 records in 550+0 records out" > err_ok || framework_failure_ 56compare err_ok err || fail=1 57 58Exit $fail 59