1#!/bin/sh
2# Ensure that tail seeks to the end of a device
3
4# Copyright (C) 2017-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_ tail
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# Get path to device the current dir is on.
34# Note df can only get fs size, not device size.
35device=$(df --output=source . | tail -n1) || framework_failure_
36
37dev_size=$(get_device_size "$device") ||
38  skip_ "failed to determine size of $device"
39
40tail_offset=$(expr $dev_size - 1023) ||
41  skip_ "failed to determine tail offset"
42
43timeout 10 tail -c 1024 "$device" > end1 || fail=1
44timeout 10 tail -c +"$tail_offset" "$device" > end2 || fail=1
45test $(wc -c < end1) = 1024 || fail=1
46cmp end1 end2 || fail=1
47
48Exit $fail
49