Subject: coreutils: tail: on blockdevs reads the whole thing, doesn't on files of the same size

From: наб <[email-masked]>
Date: Sun, 25 Jun 2023 01:17:10 +0200

Package: coreutils
Version: 9.1-1
Severity: normal

Dear Maintainer,

$ cp --sparse=always /dev/zvol/filling/store/nabijaczleweli/vm-zoot /tmp/
$ time tail /dev/zvol/filling/store/nabijaczleweli/vm-zoot | b2sum
11d28bd10ad4d4ae652e02aaaa6f59f1ef5ff5f44111e3e3c80d5ae01f666e00f38d626784539b9f095255a246d9b6b56624fd08c8916a10b16e7b5b6560d7f1  -

real    0m17.235s
user    0m1.344s
sys     0m9.693s
$ time tail /tmp/vm-zoot | b2sum
11d28bd10ad4d4ae652e02aaaa6f59f1ef5ff5f44111e3e3c80d5ae01f666e00f38d626784539b9f095255a246d9b6b56624fd08c8916a10b16e7b5b6560d7f1  -

real    0m0.005s
user    0m0.005s
sys     0m0.004s
$ time cat /dev/zvol/filling/store/nabijaczleweli/vm-zoot | tail | b2sum
11d28bd10ad4d4ae652e02aaaa6f59f1ef5ff5f44111e3e3c80d5ae01f666e00f38d626784539b9f095255a246d9b6b56624fd08c8916a10b16e7b5b6560d7f1  -

real    0m17.271s
user    0m1.620s
sys     0m17.504s

Somehow I feel there's no reason that tail couldn't lseek(SEEK_END) on a
blockdev just as well as it can do on a regular file.

Best,
наб

-- System Information:
Debian Release: 12.0
  APT prefers stable-security
  APT policy: (500, 'stable-security'), (500, 'stable-debug'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.1.0-9-amd64 (SMP w/24 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_FIRMWARE_WORKAROUND, TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), LANGUAGE=en_GB:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages coreutils depends on:
ii  libacl1      2.3.1-3
ii  libattr1     1:2.5.1-4
ii  libc6        2.36-9
ii  libgmp10     2:6.2.1+dfsg1-1.1
ii  libselinux1  3.4-1+b6

coreutils recommends no packages.

coreutils suggests no packages.

-- no debconf information