GNU bug report logs - #29259
tail does not seek to the end of block device

Previous Next

Package: coreutils;

Reported by: David Durham <daviddurham01 <at> gmail.com>

Date: Sat, 11 Nov 2017 20:30:02 UTC

Severity: normal

Tags: fixed

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 29259 in the body.
You can then email your comments to 29259 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#29259; Package coreutils. (Sat, 11 Nov 2017 20:30:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to David Durham <daviddurham01 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Sat, 11 Nov 2017 20:30:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: David Durham <daviddurham01 <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: tail does not seek to the end of block device
Date: Sat, 11 Nov 2017 15:08:22 -0500
[Message part 1 (text/plain, inline)]
sudo tail -c 1024 /dev/sda2 | hd  the entire /dev/sda2 device rather than
seeking to the end. This takes a very long time with large disks. Deltik
gives a nice explanation here -
https://superuser.com/questions/1267402/how-do-i-tail-a-block-device-in-linux
- of how ioctl can be used to obtain the size of a block device instead of
fstat.

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#29259; Package coreutils. (Mon, 13 Nov 2017 05:51:01 GMT) Full text and rfc822 format available.

Message #8 received at 29259 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: David Durham <daviddurham01 <at> gmail.com>, 29259 <at> debbugs.gnu.org
Subject: Re: bug#29259: tail does not seek to the end of block device
Date: Sun, 12 Nov 2017 21:50:29 -0800
On 11/11/17 12:08, David Durham wrote:
> sudo tail -c 1024 /dev/sda2 | hd  the entire /dev/sda2 device rather than
> seeking to the end. This takes a very long time with large disks. Deltik
> gives a nice explanation here -
> https://superuser.com/questions/1267402/how-do-i-tail-a-block-device-in-linux
> - of how ioctl can be used to obtain the size of a block device instead of
> fstat.
> 
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
> Virus-free.
> www.avast.com
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
> 

Yes maybe. The answer at the link shows how to do it efficiently with
the existing `dd` and `blockdev --getsize64` tools.
I also mentioned there the iflag=skip_bytes option which allows
one to efficiently skip portions of a disk independently from the I/O size.

Given dd is a more natural tool for dealing with device I/O,
and that processing the end of a device is an unusual use case,
I'm on the fence as to whether `tail` should handle this case specially.

cheers,
Pádraig




Information forwarded to bug-coreutils <at> gnu.org:
bug#29259; Package coreutils. (Mon, 13 Nov 2017 05:53:02 GMT) Full text and rfc822 format available.

Message #11 received at 29259 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Pádraig Brady <P <at> draigBrady.com>,
 David Durham <daviddurham01 <at> gmail.com>, 29259 <at> debbugs.gnu.org
Subject: Re: bug#29259: tail does not seek to the end of block device
Date: Sun, 12 Nov 2017 21:52:43 -0800
Why doesn't lseek work for this?




Information forwarded to bug-coreutils <at> gnu.org:
bug#29259; Package coreutils. (Mon, 13 Nov 2017 06:22:01 GMT) Full text and rfc822 format available.

Message #14 received at 29259 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>, David Durham <daviddurham01 <at> gmail.com>, 
 29259 <at> debbugs.gnu.org
Subject: Re: bug#29259: tail does not seek to the end of block device
Date: Sun, 12 Nov 2017 22:21:14 -0800
On 12/11/17 21:52, Paul Eggert wrote:
> Why doesn't lseek work for this?

Good call, it probably would.
Something like the following is more acceptable
since it adds very little complexity:

diff --git a/src/tail.c b/src/tail.c
index 1c7418d..a10470b 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1846,9 +1846,13 @@ tail_bytes (const char *pretty_filename, int fd, uintmax_
     }
   else
     {
-      off_t end_pos = ((! presume_input_pipe && usable_st_size (&stats)
-                        && n_bytes <= OFF_T_MAX)
-                       ? stats.st_size : -1);
+      off_t end_pos = -1;
+      if (! presume_input_pipe && n_bytes <= OFF_T_MAX)
+        {
+          end_pos = usable_st_size (&stats)
+                    ? stats.st_size
+                    : lseek (fd, n_bytes, SEEK_END);
+        }
       if (end_pos <= ST_BLKSIZE (stats))
         return pipe_bytes (pretty_filename, fd, n_bytes, read_pos);
       off_t current_pos = xlseek (fd, 0, SEEK_CUR, pretty_filename);





Information forwarded to bug-coreutils <at> gnu.org:
bug#29259; Package coreutils. (Mon, 13 Nov 2017 08:04:02 GMT) Full text and rfc822 format available.

Message #17 received at 29259 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>, David Durham <daviddurham01 <at> gmail.com>, 
 29259 <at> debbugs.gnu.org
Subject: Re: bug#29259: tail does not seek to the end of block device
Date: Mon, 13 Nov 2017 00:03:06 -0800
[Message part 1 (text/plain, inline)]
On 12/11/17 22:21, Pádraig Brady wrote:
> On 12/11/17 21:52, Paul Eggert wrote:
>> Why doesn't lseek work for this?
> 
> Good call, it probably would.
> Something like the following is more acceptable
> since it adds very little complexity:

Full patch attached with tests.

cheers,
Pádraig

[tail-end-of-device.patch (text/x-patch, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#29259; Package coreutils. (Mon, 13 Nov 2017 15:11:02 GMT) Full text and rfc822 format available.

Message #20 received at 29259 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Pádraig Brady <P <at> draigbrady.com>
Cc: Paul Eggert <eggert <at> cs.ucla.edu>, 29259 <at> debbugs.gnu.org,
 David Durham <daviddurham01 <at> gmail.com>
Subject: Re: bug#29259: tail does not seek to the end of block device
Date: Mon, 13 Nov 2017 07:09:36 -0800
On Mon, Nov 13, 2017 at 12:03 AM, Pádraig Brady <P <at> draigbrady.com> wrote:
> On 12/11/17 22:21, Pádraig Brady wrote:
>> On 12/11/17 21:52, Paul Eggert wrote:
>>> Why doesn't lseek work for this?
>>
>> Good call, it probably would.
>> Something like the following is more acceptable
>> since it adds very little complexity:
>
> Full patch attached with tests.

Nice work. I found nothing to improve.




Information forwarded to bug-coreutils <at> gnu.org:
bug#29259; Package coreutils. (Tue, 30 Oct 2018 02:06:02 GMT) Full text and rfc822 format available.

Message #23 received at 29259 <at> debbugs.gnu.org (full text, mbox):

From: Assaf Gordon <assafgordon <at> gmail.com>
To: 29259 <at> debbugs.gnu.org
Subject: Re: bug#29259: tail does not seek to the end of block device
Date: Mon, 29 Oct 2018 20:05:36 -0600
tags 29259 fixed
close 29259
stop

(triaging old bugs)

Pushed here:

tail: seek to the end of block devices
https://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=31dd7a0de272affa1120ba1fbc7db3445c548aa5

so closing as "fixed".

-assaf




Added tag(s) fixed. Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 30 Oct 2018 02:06:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 29259 <at> debbugs.gnu.org and David Durham <daviddurham01 <at> gmail.com> Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 30 Oct 2018 02:06:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 27 Nov 2018 12:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 149 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.