From unknown Mon Jun 23 18:33:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#13391: dd silently ignores lseek error Resent-From: Neil Klopfenstein Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Tue, 08 Jan 2013 18:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 13391 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 13391@debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.135766942010606 (code B ref -1); Tue, 08 Jan 2013 18:24:02 +0000 Received: (at submit) by debbugs.gnu.org; 8 Jan 2013 18:23:40 +0000 Received: from localhost ([127.0.0.1]:57159 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tsdps-0002l0-3g for submit@debbugs.gnu.org; Tue, 08 Jan 2013 13:23:40 -0500 Received: from eggs.gnu.org ([208.118.235.92]:40991) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TsdeS-0002T2-4a for submit@debbugs.gnu.org; Tue, 08 Jan 2013 13:11:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TsdeA-0007gz-4B for submit@debbugs.gnu.org; Tue, 08 Jan 2013 13:11:41 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_LOW,T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:58653) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsdeA-0007gp-0O for submit@debbugs.gnu.org; Tue, 08 Jan 2013 13:11:34 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tsde5-0002GE-Ib for bug-coreutils@gnu.org; Tue, 08 Jan 2013 13:11:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tsde0-0007ff-W1 for bug-coreutils@gnu.org; Tue, 08 Jan 2013 13:11:29 -0500 Received: from mail-ee0-f49.google.com ([74.125.83.49]:59849) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tsde0-0007fN-Mr for bug-coreutils@gnu.org; Tue, 08 Jan 2013 13:11:24 -0500 Received: by mail-ee0-f49.google.com with SMTP id c4so366548eek.36 for ; Tue, 08 Jan 2013 10:11:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; bh=cYIhb1KTHpoIW6RDjGtnToqjqhOlVvitICNu2rUt9/U=; b=abydOWfCIN/E0vwZLLOk+vgnBpkvg7l95HUTjHu9/aC7dIjUqgfbs4H3+25RKCwf+M AdwbYgbemagDyXvLbhZ8q/4DmxioBOOAnPtAxPPgLE6gJm/8YRNkm0NmjNHHEZNWqNG2 ISNo9pXbLxz3ZUsRw4j2qSkpo+H7K2VXnJggQCMZVx8FEdHwpa0mVk5BFA+NlbuooiSZ 8PsFZJexrvOGJA5DcbuAutzfvb9q7oUY0in0mOpww5TEB/JDb/iwa9hywvvcA/ZDL1Fs 01yStVkvHywZWQBlNMKLEZbBnx1GdC35MV2qIFJctAeS//itRduaqYM4SLnoIIiA9IvD TVYQ== MIME-Version: 1.0 Received: by 10.14.218.69 with SMTP id j45mr175805724eep.35.1357668683011; Tue, 08 Jan 2013 10:11:23 -0800 (PST) Received: by 10.14.127.136 with HTTP; Tue, 8 Jan 2013 10:11:22 -0800 (PST) Date: Tue, 8 Jan 2013 15:11:22 -0300 X-Google-Sender-Auth: FppSJACXBI-VzxCQ6hIeYMbi9us Message-ID: From: Neil Klopfenstein Content-Type: multipart/alternative; boundary=047d7b6042fa92d5c504d2cadfd9 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 208.118.235.17 X-Spam-Score: -3.4 (---) X-Mailman-Approved-At: Tue, 08 Jan 2013 13:23:39 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.7 (----) --047d7b6042fa92d5c504d2cadfd9 Content-Type: text/plain; charset=ISO-8859-1 Hi all, While trying to diagnose a weird filesystem bug, I found an error in GNU dd v8.12. The weird bug is causing lseek() to fail improperly. That's not the problem I'm reporting, though. I was trying to use dd to demonstrate the lseek error to my sysadmin. Instead, I found that dd is ignoring the lseek failure. Here is the relevant strace output: $ strace dd if=libdvapp-O.a of=/dev/null bs=33k skip=1 ... open("libdvapp-O.a", O_RDONLY) = 3 dup2(3, 0) = 0 close(3) = 0 lseek(0, 0, SEEK_CUR) = 0 open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3 dup2(3, 1) = 1 close(3) = 0 clock_gettime(CLOCK_MONOTONIC, {12951065, 389531862}) = 0 ioctl(0, MGSL_IOCSTXIDLE or MTIOCGET or SNDCTL_MIDI_MPUCMD, 0x7fbfffe3f0) = -1 ENOTTY (Inappropriate ioctl for device) lseek(0, 33792, SEEK_CUR) = -1 EINVAL (Invalid argument) ^ this is the syscall which should not be failing ioctl(0, MGSL_IOCSTXIDLE or MTIOCGET or SNDCTL_MIDI_MPUCMD, 0x7fbfffe3f0) = -1 ENOTTY (Inappropriate ioctl for device) lseek(0, 0, SEEK_END) = -1 EINVAL (Invalid argument) read(0, "!\n/ 13576110"..., 33792) = 33792 ... Note that it begins reading at the _beginning of the ar file_ -- the 'skip' argument has failed silently. The output of dd does not indicate any error: 3+1 records in 3+1 records out 103310 bytes (103 kB) copied, 0.000375 s, 275 MB/s Expected behavior: dd should pass on any unexpected errors reported by system calls. I realize this is an old version of coreutils but I don't have a newer version available to test against the anomaly. Sorry if it's already been fixed. Regards, --Neil --047d7b6042fa92d5c504d2cadfd9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi all,

While trying to diagnose a weird filesystem= bug, I found an error in GNU dd v8.12.

The weird bug is causing lse= ek() to fail improperly. That's not the problem I'm reporting, thou= gh. I was trying to use dd to demonstrate the lseek error to my sysadmin. I= nstead, I found that dd is ignoring the lseek failure.

Here is the relevant strace output:
$ strace dd if=3Dlibdvapp-O.a of= =3D/dev/null bs=3D33k skip=3D1
...
open("libdvapp-O.a", O_R= DONLY) =3D 3
dup2(3, 0)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D 0
close(3)=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =3D 0
lseek(0, 0, SEEK_CUR)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =3D 0
open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC, 0666) =3D 3=
dup2(3, 1)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D 1
close(3)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D 0
cl= ock_gettime(CLOCK_MONOTONIC, {12951065, 389531862}) =3D 0
ioctl(0, MGSL_IOCSTXIDLE or MTIOCGET or SNDCTL_MIDI_MPUCMD, 0x7fbfffe3f0) = =3D -1 ENOTTY (Inappropriate ioctl for device)
lseek(0, 33792, SEEK_CUR)= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D -1 EINVAL (Invalid argument)=
=A0^ this is the syscall which should not be failing
ioctl(0, MGSL_IOCSTXIDLE or MTIOCGET or SNDCTL_MIDI_MPUCMD, 0x7fbfffe3f0) = =3D -1 ENOTTY (Inappropriate ioctl for device)
lseek(0, 0, SEEK_END)=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D -1 EINVAL (Invalid = argument)
read(0, "!<arch>\n/=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 13576110"..., 33792) =3D 33792
...

Note that it begins reading at the _beginning of the ar file_ --= the 'skip' argument has failed silently. The output of dd does not= indicate any error:

3+1 records in
3+1 records out
103310 byt= es (103 kB) copied, 0.000375 s, 275 MB/s

Expected behavior: dd should pass on any unexpected errors reported by = system calls.

I realize this is an old version of coreutils but I do= n't have a newer version available to test against the anomaly. Sorry i= f it's already been fixed.

Regards,
--Neil
--047d7b6042fa92d5c504d2cadfd9-- From unknown Mon Jun 23 18:33:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#13391: dd silently ignores lseek error Resent-From: Paul Eggert Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Tue, 08 Jan 2013 20:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13391 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Neil Klopfenstein Cc: 13391@debbugs.gnu.org Received: via spool by 13391-submit@debbugs.gnu.org id=B13391.135767853327795 (code B ref 13391); Tue, 08 Jan 2013 20:56:02 +0000 Received: (at 13391) by debbugs.gnu.org; 8 Jan 2013 20:55:33 +0000 Received: from localhost ([127.0.0.1]:57323 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TsgCp-0007EE-5K for submit@debbugs.gnu.org; Tue, 08 Jan 2013 15:55:33 -0500 Received: from smtp.cs.ucla.edu ([131.179.128.62]:39985) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TsgCl-0007Dy-Rg for 13391@debbugs.gnu.org; Tue, 08 Jan 2013 15:55:29 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 2009939E8106; Tue, 8 Jan 2013 12:55:16 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JJE53mchugUT; Tue, 8 Jan 2013 12:55:15 -0800 (PST) Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id C1A4139E8008; Tue, 8 Jan 2013 12:55:15 -0800 (PST) Message-ID: <50EC87B3.3060508@cs.ucla.edu> Date: Tue, 08 Jan 2013 12:55:15 -0800 From: Paul Eggert User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Score: -1.5 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.5 (-) On 01/08/13 10:11, Neil Klopfenstein wrote: > Note that it begins reading at the _beginning of the ar file_ -- the 'skip' > argument has failed silently. But the 'skip' hasn't failed. It's merely being implemented via 'read' rather than via 'lseek'. The records are being skipped correctly. It might be useful to give dd a new option, which causes it to insist on lseeking rather than reading in cases like these, and to report an error if the lseek fails. From unknown Mon Jun 23 18:33:06 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.428 (Entity 5.428) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Neil Klopfenstein Subject: bug#13391: closed (Re: bug#13391: dd silently ignores lseek error) Message-ID: References: <50ECC46E.8030203@draigBrady.com> X-Gnu-PR-Message: they-closed 13391 X-Gnu-PR-Package: coreutils Reply-To: 13391@debbugs.gnu.org Date: Wed, 09 Jan 2013 01:15:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1357694102-22643-1" This is a multi-part message in MIME format... ------------=_1357694102-22643-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #13391: dd silently ignores lseek error which was filed against the coreutils package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 13391@debbugs.gnu.org. --=20 13391: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D13391 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1357694102-22643-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 13391-done) by debbugs.gnu.org; 9 Jan 2013 01:14:45 +0000 Received: from localhost ([127.0.0.1]:57502 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TskFg-0005si-D5 for submit@debbugs.gnu.org; Tue, 08 Jan 2013 20:14:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:61447) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TskFd-0005sZ-Av for 13391-done@debbugs.gnu.org; Tue, 08 Jan 2013 20:14:43 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r091EPVo009940 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 8 Jan 2013 20:14:26 -0500 Received: from [10.36.116.35] (ovpn-116-35.ams2.redhat.com [10.36.116.35]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r091EMSf032403 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Tue, 8 Jan 2013 20:14:24 -0500 Message-ID: <50ECC46E.8030203@draigBrady.com> Date: Wed, 09 Jan 2013 01:14:22 +0000 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: Paul Eggert Subject: Re: bug#13391: dd silently ignores lseek error References: <50EC87B3.3060508@cs.ucla.edu> In-Reply-To: <50EC87B3.3060508@cs.ucla.edu> Content-Type: multipart/mixed; boundary="------------020904020303080705080106" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Spam-Score: -6.9 (------) X-Debbugs-Envelope-To: 13391-done Cc: Neil Klopfenstein , 13391-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.9 (------) This is a multi-part message in MIME format. --------------020904020303080705080106 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id r091EPVo009940 On 01/08/2013 08:55 PM, Paul Eggert wrote: > On 01/08/13 10:11, Neil Klopfenstein wrote: >> Note that it begins reading at the _beginning of the ar file_ -- the '= skip' >> argument has failed silently. > > But the 'skip' hasn't failed. It's merely being implemented via 'read' > rather than via 'lseek'. The records are being skipped correctly. > > It might be useful to give dd a new option, which causes it > to insist on lseeking rather than reading in cases like these, > and to report an error if the lseek fails. I had a look around for a tool to verify that a file/device supports the seek operation and couldn't find one. So this seems like useful functionality. Worth applying the attached? thanks, P=C3=A1draig. --------------020904020303080705080106 Content-Type: text/x-patch; name="dd-flag-seekable.diff" Content-Disposition: attachment; filename="dd-flag-seekable.diff" Content-Transfer-Encoding: 7bit >From ea524ab7388bb35e591dcdb0fc7f7989d61143ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Wed, 9 Jan 2013 00:42:38 +0000 Subject: [PATCH] dd: add [io]flag=seekable to verify file support for lseek * src/dd.c: Add the new O_SEEKABLE flag. (main): Verify leek() works if O_SEEKABLE is set. (usage): Describe the new flag. * tests/dd/misc.sh: Augment the test for the new options. * doc/coreutils.texi (dd invocation): Describe the new option. * cfg.mk (sc_dd_O_FLAGS): Add O_SEEKABLE to the list of private flags with a a single underscore. * NEWS: Mention the new feature. Suggested by Paul Eggert in http://bugs.gnu.org/13391 --- NEWS | 3 +++ cfg.mk | 2 +- doc/coreutils.texi | 6 ++++++ src/dd.c | 28 +++++++++++++++++++++++++++- tests/dd/misc.sh | 8 ++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 754b2cf..9c415ec 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,9 @@ GNU coreutils NEWS -*- outline -*- ** New features + dd now accepts 'iflag=seekable' and 'oflag=seekable' to verify that the + corresponding files support the seek operation. + df now accepts the --output[=FIELD_LIST] option to define the list of columns to include in the output, or all available columns if the FIELD_LIST is omitted. Note this enables df to output both block and inode fields together. diff --git a/cfg.mk b/cfg.mk index fbc64b4..bf43861 100644 --- a/cfg.mk +++ b/cfg.mk @@ -57,7 +57,7 @@ _hv_file ?= $(srcdir)/tests/misc/help-version dd = $(srcdir)/src/dd.c sc_dd_O_FLAGS: @rm -f $@.1 $@.2 - @{ echo O_FULLBLOCK; echo O_NOCACHE; \ + @{ echo O_FULLBLOCK; echo O_NOCACHE; echo O_SEEKABLE; \ perl -nle '/^ +\| (O_\w*)$$/ and print $$1' $(dd); } | sort > $@.1 @{ echo O_NOFOLLOW; perl -nle '/{"[a-z]+",\s*(O_\w+)},/ and print $$1' \ $(dd); } | sort > $@.2 diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 45a4b3d..9ee9d86 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -8399,6 +8399,12 @@ rather than a block count, which allows specifying an offset that is not a multiple of the I/O block size. This flag can be used only with @code{oflag}. +@item seekable +@opindex seekable +Fail unless the file is seekable. +Note @samp{skip=} or @samp{seek=} don't suffice for this check, +as they will resort to reading, to skip over data. + @end table These flags are not supported on all systems, and @samp{dd} rejects diff --git a/src/dd.c b/src/dd.c index ef5664b..21b4b21 100644 --- a/src/dd.c +++ b/src/dd.c @@ -216,6 +216,9 @@ static xtime_t start_time; /* True if input is seekable. */ static bool input_seekable; +/* True if output is seekable. */ +static bool output_seekable; + /* Error number corresponding to initial attempt to lseek input. If ESPIPE, do not issue any more diagnostics about it. */ static int input_seek_errno; @@ -326,7 +329,10 @@ enum O_SKIP_BYTES = FFS_MASK (v4), v5 = v4 ^ O_SKIP_BYTES, - O_SEEK_BYTES = FFS_MASK (v5) + O_SEEK_BYTES = FFS_MASK (v5), + v6 = v5 ^ O_SEEK_BYTES, + + O_SEEKABLE = FFS_MASK (v6) }; /* Ensure that we got something. */ @@ -335,6 +341,7 @@ verify (O_NOCACHE != 0); verify (O_COUNT_BYTES != 0); verify (O_SKIP_BYTES != 0); verify (O_SEEK_BYTES != 0); +verify (O_SEEKABLE != 0); #define MULTIPLE_BITS_SET(i) (((i) & ((i) - 1)) != 0) @@ -344,6 +351,7 @@ verify ( ! MULTIPLE_BITS_SET (O_NOCACHE)); verify ( ! MULTIPLE_BITS_SET (O_COUNT_BYTES)); verify ( ! MULTIPLE_BITS_SET (O_SKIP_BYTES)); verify ( ! MULTIPLE_BITS_SET (O_SEEK_BYTES)); +verify ( ! MULTIPLE_BITS_SET (O_SEEKABLE)); /* Flags, for iflag="..." and oflag="...". */ static struct symbol_value const flags[] = @@ -366,6 +374,7 @@ static struct symbol_value const flags[] = {"count_bytes", O_COUNT_BYTES}, {"skip_bytes", O_SKIP_BYTES}, {"seek_bytes", O_SEEK_BYTES}, + {"seekable", O_SEEKABLE}, {"", 0} }; @@ -619,6 +628,9 @@ Each FLAG symbol may be:\n\ if (O_SEEK_BYTES) fputs (_(" seek_bytes treat 'seek=N' as a byte count (oflag only)\n\ "), stdout); + if (O_SEEKABLE) + fputs (_(" seekable fail unless seekable\n\ +"), stdout); { char const *siginfo_name = (SIGINFO == SIGUSR1 ? "USR1" : "INFO"); @@ -1607,6 +1619,7 @@ skip (int fdesc, char const *file, uintmax_t records, size_t blocksize, } /* else file_size && offset > OFF_T_MAX or file ! seekable */ + do { ssize_t nread = iread_fnc (fdesc, buf, records ? blocksize : *bytes); @@ -2270,6 +2283,19 @@ main (int argc, char **argv) } } + offset = lseek (STDOUT_FILENO, 0, SEEK_CUR); + output_seekable = (0 <= offset); + if (! input_seekable && (input_flags & O_SEEKABLE)) + { + error (EXIT_FAILURE, input_seek_errno, _("input is not seekable %s"), + quote (input_file)); + } + if (! output_seekable && (output_flags & O_SEEKABLE)) + { + error (EXIT_FAILURE, errno, _("output is not seekable %s"), + quote (output_file)); + } + start_time = gethrxtime (); exit_status = dd_copy (); diff --git a/tests/dd/misc.sh b/tests/dd/misc.sh index b9ad31a..cc84457 100755 --- a/tests/dd/misc.sh +++ b/tests/dd/misc.sh @@ -102,4 +102,12 @@ compare err_ok err || fail=1 test $fail -eq 0 && fail=$warn +# check iflag=seekable and oflag=seekable +dd if=/dev/null of=/dev/null iflag=seekable oflag=seekable count=0 || fail=1 +echo 'pipe' | dd of=/dev/null iflag=seekable count=0 && fail=1 +dd if=/dev/null oflag=seekable count=0 status=none 2>err | cat +echo "dd: output is not seekable 'standard output': Illegal seek" > err_ok || + framework_failure_ +compare err_ok err || fail=1 + Exit $fail -- 1.7.6.4 --------------020904020303080705080106-- ------------=_1357694102-22643-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 8 Jan 2013 18:23:40 +0000 Received: from localhost ([127.0.0.1]:57159 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tsdps-0002l0-3g for submit@debbugs.gnu.org; Tue, 08 Jan 2013 13:23:40 -0500 Received: from eggs.gnu.org ([208.118.235.92]:40991) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TsdeS-0002T2-4a for submit@debbugs.gnu.org; Tue, 08 Jan 2013 13:11:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TsdeA-0007gz-4B for submit@debbugs.gnu.org; Tue, 08 Jan 2013 13:11:41 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_LOW,T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:58653) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsdeA-0007gp-0O for submit@debbugs.gnu.org; Tue, 08 Jan 2013 13:11:34 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tsde5-0002GE-Ib for bug-coreutils@gnu.org; Tue, 08 Jan 2013 13:11:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tsde0-0007ff-W1 for bug-coreutils@gnu.org; Tue, 08 Jan 2013 13:11:29 -0500 Received: from mail-ee0-f49.google.com ([74.125.83.49]:59849) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tsde0-0007fN-Mr for bug-coreutils@gnu.org; Tue, 08 Jan 2013 13:11:24 -0500 Received: by mail-ee0-f49.google.com with SMTP id c4so366548eek.36 for ; Tue, 08 Jan 2013 10:11:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; bh=cYIhb1KTHpoIW6RDjGtnToqjqhOlVvitICNu2rUt9/U=; b=abydOWfCIN/E0vwZLLOk+vgnBpkvg7l95HUTjHu9/aC7dIjUqgfbs4H3+25RKCwf+M AdwbYgbemagDyXvLbhZ8q/4DmxioBOOAnPtAxPPgLE6gJm/8YRNkm0NmjNHHEZNWqNG2 ISNo9pXbLxz3ZUsRw4j2qSkpo+H7K2VXnJggQCMZVx8FEdHwpa0mVk5BFA+NlbuooiSZ 8PsFZJexrvOGJA5DcbuAutzfvb9q7oUY0in0mOpww5TEB/JDb/iwa9hywvvcA/ZDL1Fs 01yStVkvHywZWQBlNMKLEZbBnx1GdC35MV2qIFJctAeS//itRduaqYM4SLnoIIiA9IvD TVYQ== MIME-Version: 1.0 Received: by 10.14.218.69 with SMTP id j45mr175805724eep.35.1357668683011; Tue, 08 Jan 2013 10:11:23 -0800 (PST) Received: by 10.14.127.136 with HTTP; Tue, 8 Jan 2013 10:11:22 -0800 (PST) Date: Tue, 8 Jan 2013 15:11:22 -0300 X-Google-Sender-Auth: FppSJACXBI-VzxCQ6hIeYMbi9us Message-ID: Subject: dd silently ignores lseek error From: Neil Klopfenstein To: bug-coreutils@gnu.org Content-Type: multipart/alternative; boundary=047d7b6042fa92d5c504d2cadfd9 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 208.118.235.17 X-Spam-Score: -3.4 (---) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Tue, 08 Jan 2013 13:23:39 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.7 (----) --047d7b6042fa92d5c504d2cadfd9 Content-Type: text/plain; charset=ISO-8859-1 Hi all, While trying to diagnose a weird filesystem bug, I found an error in GNU dd v8.12. The weird bug is causing lseek() to fail improperly. That's not the problem I'm reporting, though. I was trying to use dd to demonstrate the lseek error to my sysadmin. Instead, I found that dd is ignoring the lseek failure. Here is the relevant strace output: $ strace dd if=libdvapp-O.a of=/dev/null bs=33k skip=1 ... open("libdvapp-O.a", O_RDONLY) = 3 dup2(3, 0) = 0 close(3) = 0 lseek(0, 0, SEEK_CUR) = 0 open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3 dup2(3, 1) = 1 close(3) = 0 clock_gettime(CLOCK_MONOTONIC, {12951065, 389531862}) = 0 ioctl(0, MGSL_IOCSTXIDLE or MTIOCGET or SNDCTL_MIDI_MPUCMD, 0x7fbfffe3f0) = -1 ENOTTY (Inappropriate ioctl for device) lseek(0, 33792, SEEK_CUR) = -1 EINVAL (Invalid argument) ^ this is the syscall which should not be failing ioctl(0, MGSL_IOCSTXIDLE or MTIOCGET or SNDCTL_MIDI_MPUCMD, 0x7fbfffe3f0) = -1 ENOTTY (Inappropriate ioctl for device) lseek(0, 0, SEEK_END) = -1 EINVAL (Invalid argument) read(0, "!\n/ 13576110"..., 33792) = 33792 ... Note that it begins reading at the _beginning of the ar file_ -- the 'skip' argument has failed silently. The output of dd does not indicate any error: 3+1 records in 3+1 records out 103310 bytes (103 kB) copied, 0.000375 s, 275 MB/s Expected behavior: dd should pass on any unexpected errors reported by system calls. I realize this is an old version of coreutils but I don't have a newer version available to test against the anomaly. Sorry if it's already been fixed. Regards, --Neil --047d7b6042fa92d5c504d2cadfd9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi all,

While trying to diagnose a weird filesystem= bug, I found an error in GNU dd v8.12.

The weird bug is causing lse= ek() to fail improperly. That's not the problem I'm reporting, thou= gh. I was trying to use dd to demonstrate the lseek error to my sysadmin. I= nstead, I found that dd is ignoring the lseek failure.

Here is the relevant strace output:
$ strace dd if=3Dlibdvapp-O.a of= =3D/dev/null bs=3D33k skip=3D1
...
open("libdvapp-O.a", O_R= DONLY) =3D 3
dup2(3, 0)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D 0
close(3)=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =3D 0
lseek(0, 0, SEEK_CUR)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =3D 0
open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC, 0666) =3D 3=
dup2(3, 1)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D 1
close(3)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D 0
cl= ock_gettime(CLOCK_MONOTONIC, {12951065, 389531862}) =3D 0
ioctl(0, MGSL_IOCSTXIDLE or MTIOCGET or SNDCTL_MIDI_MPUCMD, 0x7fbfffe3f0) = =3D -1 ENOTTY (Inappropriate ioctl for device)
lseek(0, 33792, SEEK_CUR)= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D -1 EINVAL (Invalid argument)=
=A0^ this is the syscall which should not be failing
ioctl(0, MGSL_IOCSTXIDLE or MTIOCGET or SNDCTL_MIDI_MPUCMD, 0x7fbfffe3f0) = =3D -1 ENOTTY (Inappropriate ioctl for device)
lseek(0, 0, SEEK_END)=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D -1 EINVAL (Invalid = argument)
read(0, "!<arch>\n/=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 13576110"..., 33792) =3D 33792
...

Note that it begins reading at the _beginning of the ar file_ --= the 'skip' argument has failed silently. The output of dd does not= indicate any error:

3+1 records in
3+1 records out
103310 byt= es (103 kB) copied, 0.000375 s, 275 MB/s

Expected behavior: dd should pass on any unexpected errors reported by = system calls.

I realize this is an old version of coreutils but I do= n't have a newer version available to test against the anomaly. Sorry i= f it's already been fixed.

Regards,
--Neil
--047d7b6042fa92d5c504d2cadfd9-- ------------=_1357694102-22643-1-- From unknown Mon Jun 23 18:33:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#13391: dd silently ignores lseek error Resent-From: Paul Eggert Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Wed, 09 Jan 2013 04:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13391 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: =?UTF-8?Q?P=C3=A1draig?= Brady Cc: Neil Klopfenstein , 13391-done@debbugs.gnu.org Received: via spool by 13391-done@debbugs.gnu.org id=D13391.135770750814610 (code D ref 13391); Wed, 09 Jan 2013 04:59:02 +0000 Received: (at 13391-done) by debbugs.gnu.org; 9 Jan 2013 04:58:28 +0000 Received: from localhost ([127.0.0.1]:57624 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TsnkB-0003na-JZ for submit@debbugs.gnu.org; Tue, 08 Jan 2013 23:58:27 -0500 Received: from smtp.cs.ucla.edu ([131.179.128.62]:33600) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tsnk8-0003nN-84 for 13391-done@debbugs.gnu.org; Tue, 08 Jan 2013 23:58:25 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id BD7C4A60001; Tue, 8 Jan 2013 20:58:10 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oLvyhTSRcUrx; Tue, 8 Jan 2013 20:58:10 -0800 (PST) Received: from [192.168.1.9] (pool-71-189-154-249.lsanca.fios.verizon.net [71.189.154.249]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 6A25439E8105; Tue, 8 Jan 2013 20:58:10 -0800 (PST) Message-ID: <50ECF8DA.8080506@cs.ucla.edu> Date: Tue, 08 Jan 2013 20:58:02 -0800 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 References: <50EC87B3.3060508@cs.ucla.edu> <50ECC46E.8030203@draigBrady.com> In-Reply-To: <50ECC46E.8030203@draigBrady.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -1.5 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.5 (-) On 01/08/2013 05:14 PM, P=C3=A1draig Brady wrote: > Worth applying the attached? Looks good, except I would avoid calling lseek on STDOUT_FILENO unless oflag=3Dseekable is set. Just being conservative: the effect of lseek on unseekable files is implementation-defined. From unknown Mon Jun 23 18:33:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#13391: dd silently ignores lseek error Resent-From: Erik Auerswald Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Wed, 09 Jan 2013 07:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13391 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 13391@debbugs.gnu.org, P@draigBrady.com, neil.klopfenstein@gmail.com Received: via spool by 13391-submit@debbugs.gnu.org id=B13391.135771624627870 (code B ref 13391); Wed, 09 Jan 2013 07:25:02 +0000 Received: (at 13391) by debbugs.gnu.org; 9 Jan 2013 07:24:06 +0000 Received: from localhost ([127.0.0.1]:57760 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tsq17-0007FS-Fp for submit@debbugs.gnu.org; Wed, 09 Jan 2013 02:24:06 -0500 Received: from mailgw1.uni-kl.de ([131.246.120.220]:39271) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tsq14-0007F2-4N for 13391@debbugs.gnu.org; Wed, 09 Jan 2013 02:24:03 -0500 Received: from sushi.unix-ag.uni-kl.de (sushi.unix-ag.uni-kl.de [IPv6:2001:638:208:ef34:0:ff:fe00:65]) by mailgw1.uni-kl.de (8.14.3/8.14.3/Debian-9.4) with ESMTP id r097NqCV027989 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 9 Jan 2013 08:23:52 +0100 Received: from sushi.unix-ag.uni-kl.de (ip6-localhost [IPv6:::1]) by sushi.unix-ag.uni-kl.de (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id r097Nqq3030329 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 9 Jan 2013 08:23:52 +0100 Received: (from auerswal@localhost) by sushi.unix-ag.uni-kl.de (8.14.3/8.14.3/Submit) id r097NqoO030328; Wed, 9 Jan 2013 08:23:52 +0100 Date: Wed, 9 Jan 2013 08:23:51 +0100 From: Erik Auerswald Message-ID: <20130109072351.GA29511@sushi.unix-ag.uni-kl.de> Mail-Followup-To: Erik Auerswald , 13391@debbugs.gnu.org, P@draigBrady.com, neil.klopfenstein@gmail.com References: <50EC87B3.3060508@cs.ucla.edu> <50ECC46E.8030203@draigBrady.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <50ECC46E.8030203@draigBrady.com> User-Agent: Mutt/1.5.18 (2008-05-17) Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mailgw1.uni-kl.de id r097NqCV027989 X-Spam-Score: -1.5 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.3 (--) Hi, On Wed, Jan 09, 2013 at 01:14:22AM +0000, P=E1draig Brady wrote: > On 01/08/2013 08:55 PM, Paul Eggert wrote: >> On 01/08/13 10:11, Neil Klopfenstein wrote: >>> Note that it begins reading at the _beginning of the ar file_ -- the = 'skip' >>> argument has failed silently. >> >> But the 'skip' hasn't failed. It's merely being implemented via 'read= ' >> rather than via 'lseek'. The records are being skipped correctly. >> >> It might be useful to give dd a new option, which causes it >> to insist on lseeking rather than reading in cases like these, >> and to report an error if the lseek fails. > > I had a look around for a tool to verify > that a file/device supports the seek operation > and couldn't find one. > So this seems like useful functionality. > Worth applying the attached? > [...] >=20 > * src/dd.c: Add the new O_SEEKABLE flag. > (main): Verify leek() works if O_SEEKABLE is set. ^^^^^^lseek() > [...] > /* else file_size && offset > OFF_T_MAX or file ! seekable */ > =20 > + Stray new newline? > do > [...] Besides these nitpicks the patch looks good to me. HTH, Erik From unknown Mon Jun 23 18:33:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#13391: dd silently ignores lseek error Resent-From: Bernhard Voelker Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Wed, 09 Jan 2013 07:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13391 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 13391@debbugs.gnu.org, P@draigBrady.com, neil.klopfenstein@gmail.com Received: via spool by 13391-submit@debbugs.gnu.org id=B13391.135771700529005 (code B ref 13391); Wed, 09 Jan 2013 07:37:02 +0000 Received: (at 13391) by debbugs.gnu.org; 9 Jan 2013 07:36:45 +0000 Received: from localhost ([127.0.0.1]:57781 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TsqDM-0007Xl-GH for submit@debbugs.gnu.org; Wed, 09 Jan 2013 02:36:44 -0500 Received: from moutng.kundenserver.de ([212.227.17.9]:55002) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TsqDJ-0007XZ-UB for 13391@debbugs.gnu.org; Wed, 09 Jan 2013 02:36:43 -0500 Received: from [192.168.1.11] (p4FC3E6F0.dip.t-dialin.net [79.195.230.240]) by mrelayeu.kundenserver.de (node=mreu1) with ESMTP (Nemesis) id 0LlrKG-1TJmRO33hY-00ZsVo; Wed, 09 Jan 2013 08:36:26 +0100 Message-ID: <50ED1DF9.9040303@bernhard-voelker.de> Date: Wed, 09 Jan 2013 08:36:25 +0100 From: Bernhard Voelker User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 References: <50EC87B3.3060508@cs.ucla.edu> <50ECC46E.8030203@draigBrady.com> In-Reply-To: <50ECC46E.8030203@draigBrady.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Provags-ID: V02:K0:9ys9gsIGFfrzjZ87Q8sZ2X/vT5wxYtYKktAB9/TVClT Bs7JUhEp0dZhMoyA1C5cPT6f2zetdZnmVuFcgmFECGuGMZcA6S M3Pv6psdbS76EsNdufoD40KTf3CpKL0+6/NvYPuPsYgqxU1LnY yLFK+6SUsxPsVzU6UEPWQq+ZWdMVm04ll4v7pxijbfWFcRGwwE lhoe8kFtr88LQRFj7hjnk6x0MiAv/clyVbVR9k/NT+dpwB9LiB CjD9skV3XiW8c0o2caJUvnR4Q6FEzFPFVjiE9IAW3KMWdpq0mW xt0DWU/jVzkR605Y8G/6vDQNejnaRc3tDzSFrml30Qjg3uk065 looQNOrtVrgipIvu1sulQcl7Kak3a1JAegj3j+Dpt X-Spam-Score: 0.8 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -0.0 (/) On 01/09/2013 02:14 AM, Pádraig Brady wrote: > I had a look around for a tool to verify > that a file/device supports the seek operation > and couldn't find one. > So this seems like useful functionality. > Worth applying the attached? > * cfg.mk (sc_dd_O_FLAGS): Add O_SEEKABLE to the list of private > flags with a a single underscore. s/a a/a/ > @@ -619,6 +628,9 @@ Each FLAG symbol may be:\n\ > if (O_SEEK_BYTES) > fputs (_(" seek_bytes treat 'seek=N' as a byte count (oflag only)\n\ > "), stdout); > + if (O_SEEKABLE) > + fputs (_(" seekable fail unless seekable\n\ > +"), stdout); no line break needed here. > + offset = lseek (STDOUT_FILENO, 0, SEEK_CUR); > + output_seekable = (0 <= offset); > + if (! input_seekable && (input_flags & O_SEEKABLE)) > + { > + error (EXIT_FAILURE, input_seek_errno, _("input is not seekable %s"), > + quote (input_file)); > + } why not check input_seekable where it is set - ~60 lines above? Have a nice day, Berny From unknown Mon Jun 23 18:33:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#13391: dd silently ignores lseek error Resent-From: Philip Rowlands Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Wed, 09 Jan 2013 08:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13391 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 13391@debbugs.gnu.org, P@draigBrady.com, neil.klopfenstein@gmail.com Received: via spool by 13391-submit@debbugs.gnu.org id=B13391.13577200791256 (code B ref 13391); Wed, 09 Jan 2013 08:28:02 +0000 Received: (at 13391) by debbugs.gnu.org; 9 Jan 2013 08:27:59 +0000 Received: from localhost ([127.0.0.1]:57835 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tsr0v-0000KC-Vc for submit@debbugs.gnu.org; Wed, 09 Jan 2013 03:27:58 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:56741) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tsr0t-0000K4-D2 for 13391@debbugs.gnu.org; Wed, 09 Jan 2013 03:27:56 -0500 Received: from compute4.internal (compute4.nyi.mail.srv.osa [10.202.2.44]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 4066E20230; Wed, 9 Jan 2013 03:27:46 -0500 (EST) Received: from frontend2.nyi.mail.srv.osa ([10.202.2.161]) by compute4.internal (MEProxy); Wed, 09 Jan 2013 03:27:46 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=dimebar.com; h= message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; s=mesmtp; bh=egAgIPKrDrdFCK4qFWUvo3i4oh0=; b=KLz4h+pmSkIl3EV3NSgMGvV/OJwZ cy4Wg2jGZiYGbY7eXo8IkmdDA5i8ZsxKlWqpdEmjr6we3AWe8P4jDHUxDxhCtyy9 Mea79DWBfh05LFrIhrKyI3M5IGk80Yh80Sd2CmoPuxYnRM2wSubbhY+xwUvazkqQ mwHG5hjKBM7pzlE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:date:from:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=egAgIPKrDrdFCK4qFWUvo3 i4oh0=; b=l4wP1GWOWoLsKrApsGpbq+ExTMVwPhjETWb5fstpdp9Zl6/IRj4WR9 VQdnf7mXO0j019fINdwJk8Hs4YNTsa3oUmlRbP129gEVkB5Nux3EnIMZY+s3V0QQ gUHivaQx63oeG7ePqgpztob9dU3QMpjfHgBBE5vpF81IdS+keviGM= X-Sasl-enc: d9G+fBjUs4DziRBnROhj0tYCghtE+g3hnmjeoT0Uw9ix 1357720065 Received: from [192.168.1.219] (unknown [86.130.162.153]) by mail.messagingengine.com (Postfix) with ESMTPA id 9C8404825BB; Wed, 9 Jan 2013 03:27:45 -0500 (EST) Message-ID: <50ED29F9.2060607@dimebar.com> Date: Wed, 09 Jan 2013 08:27:37 +0000 From: Philip Rowlands User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 References: <50EC87B3.3060508@cs.ucla.edu> <50ECC46E.8030203@draigBrady.com> In-Reply-To: <50ECC46E.8030203@draigBrady.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: 0.1 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.2 (-) > From ea524ab7388bb35e591dcdb0fc7f7989d61143ae Mon Sep 17 00:00:00 2001 > From: =?UTF-8?q?P=C3=A1draig=20Brady?= > Date: Wed, 9 Jan 2013 00:42:38 +0000 > Subject: [PATCH] dd: add [io]flag=seekable to verify file support for lseek > > * src/dd.c: Add the new O_SEEKABLE flag. > (main): Verify leek() works if O_SEEKABLE is set. leek? > (usage): Describe the new flag. > * tests/dd/misc.sh: Augment the test for the new options. > * doc/coreutils.texi (dd invocation): Describe the new option. > * cfg.mk (sc_dd_O_FLAGS): Add O_SEEKABLE to the list of private > flags with a a single underscore. > * NEWS: Mention the new feature. From unknown Mon Jun 23 18:33:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#13391: dd silently ignores lseek error Resent-From: =?UTF-8?Q?P=C3=A1draig?= Brady Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Wed, 09 Jan 2013 10:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13391 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Bernhard Voelker Cc: neil.klopfenstein@gmail.com, 13391@debbugs.gnu.org Received: via spool by 13391-submit@debbugs.gnu.org id=B13391.135772615310477 (code B ref 13391); Wed, 09 Jan 2013 10:10:02 +0000 Received: (at 13391) by debbugs.gnu.org; 9 Jan 2013 10:09:13 +0000 Received: from localhost ([127.0.0.1]:57920 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tssau-0002iv-QJ for submit@debbugs.gnu.org; Wed, 09 Jan 2013 05:09:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46398) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tssar-0002ik-5g for 13391@debbugs.gnu.org; Wed, 09 Jan 2013 05:09:11 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r09A8omc018449 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 9 Jan 2013 05:08:50 -0500 Received: from [10.36.116.72] (ovpn-116-72.ams2.redhat.com [10.36.116.72]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r09A8lQA019949 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Wed, 9 Jan 2013 05:08:48 -0500 Message-ID: <50ED41AE.5000801@draigBrady.com> Date: Wed, 09 Jan 2013 10:08:46 +0000 From: =?UTF-8?Q?P=C3=A1draig?= Brady User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 References: <50EC87B3.3060508@cs.ucla.edu> <50ECC46E.8030203@draigBrady.com> <50ED1DF9.9040303@bernhard-voelker.de> In-Reply-To: <50ED1DF9.9040303@bernhard-voelker.de> Content-Type: text/plain; charset=UTF-8; format=flowed X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id r09A8omc018449 X-Spam-Score: -4.2 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.0 (-----) On 01/09/2013 07:36 AM, Bernhard Voelker wrote: > why not check input_seekable where it is set - ~60 lines above? I was trying to keep related code together. Thanks for all the reviews, which I've fixed locally. To provide an argument for why this shouldn't go in, the following is equivalent: python -c 'import os; os.lseek(0,0,os.SEEK_CUR)' 2>/dev/null < /the/fi= le && dd if=3D/the/file ... So if the need is esoteric enough the above might suffice? I'll leave it stew for a while longer. thanks, P=C3=A1draig. From unknown Mon Jun 23 18:33:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#13391: dd silently ignores lseek error Resent-From: =?UTF-8?Q?P=C3=A1draig?= Brady Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 17 Jan 2013 11:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13391 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Bernhard Voelker Cc: neil.klopfenstein@gmail.com, 13391@debbugs.gnu.org Received: via spool by 13391-submit@debbugs.gnu.org id=B13391.135842385425115 (code B ref 13391); Thu, 17 Jan 2013 11:58:01 +0000 Received: (at 13391) by debbugs.gnu.org; 17 Jan 2013 11:57:34 +0000 Received: from localhost ([127.0.0.1]:36302 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tvo69-0006X1-B8 for submit@debbugs.gnu.org; Thu, 17 Jan 2013 06:57:34 -0500 Received: from mail3.vodafone.ie ([213.233.128.45]:64613) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tvo63-0006Wn-DY for 13391@debbugs.gnu.org; Thu, 17 Jan 2013 06:57:31 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ap0BAILl91BtTSm9/2dsb2JhbAANN4N1glCFXLIYgxEBAQEEI1YQCw0BAwMBAgEJFgsCAgkDAgECAT0IBg0BBQIBARaIBqdLcJElkCWBEwOPCIgghHGFLYgE Received: from unknown (HELO [192.168.1.79]) ([109.77.41.189]) by mail3.vodafone.ie with ESMTP; 17 Jan 2013 11:56:45 +0000 Message-ID: <50F7E6FC.3020101@draigBrady.com> Date: Thu, 17 Jan 2013 11:56:44 +0000 From: =?UTF-8?Q?P=C3=A1draig?= Brady User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 References: <50EC87B3.3060508@cs.ucla.edu> <50ECC46E.8030203@draigBrady.com> <50ED1DF9.9040303@bernhard-voelker.de> <50ED41AE.5000801@draigBrady.com> In-Reply-To: <50ED41AE.5000801@draigBrady.com> Content-Type: multipart/mixed; boundary="------------080808060109030905000104" X-Spam-Score: -1.9 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) This is a multi-part message in MIME format. --------------080808060109030905000104 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 01/09/2013 10:08 AM, Pádraig Brady wrote: > On 01/09/2013 07:36 AM, Bernhard Voelker wrote: >> why not check input_seekable where it is set - ~60 lines above? > > I was trying to keep related code together. > > > Thanks for all the reviews, which I've fixed locally. > > To provide an argument for why this shouldn't go in, > the following is equivalent: > > python -c 'import os; os.lseek(0,0,os.SEEK_CUR)' 2>/dev/null < /the/file && > dd if=/the/file ... > > So if the need is esoteric enough the above might suffice? > > I'll leave it stew for a while longer. I'm still 50:50 give the above, so I'll not push until I get more positive feedback. The latest is attached for reference. thanks, Pádraig. --------------080808060109030905000104 Content-Type: text/x-patch; name="dd-seekable.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="dd-seekable.diff" >From fbbd753db704357002f5e99b05e47638a0f62a7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Wed, 9 Jan 2013 00:42:38 +0000 Subject: [PATCH] dd: add [io]flag=seekable to verify file support for lseek * src/dd.c: Add the new O_SEEKABLE flag. (main): Verify lseek() works if O_SEEKABLE is set. (usage): Describe the new flag. * tests/dd/misc.sh: Augment the test for the new options. * doc/coreutils.texi (dd invocation): Describe the new option. * cfg.mk (sc_dd_O_FLAGS): Add O_SEEKABLE to the list of private flags with a single underscore. * NEWS: Mention the new feature. Suggested by Paul Eggert in http://bugs.gnu.org/13391 --- NEWS | 3 +++ cfg.mk | 2 +- doc/coreutils.texi | 6 ++++++ src/dd.c | 21 ++++++++++++++++++++- tests/dd/misc.sh | 8 ++++++++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 754b2cf..9c415ec 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,9 @@ GNU coreutils NEWS -*- outline -*- ** New features + dd now accepts 'iflag=seekable' and 'oflag=seekable' to verify that the + corresponding files support the seek operation. + df now accepts the --output[=FIELD_LIST] option to define the list of columns to include in the output, or all available columns if the FIELD_LIST is omitted. Note this enables df to output both block and inode fields together. diff --git a/cfg.mk b/cfg.mk index fbc64b4..bf43861 100644 --- a/cfg.mk +++ b/cfg.mk @@ -57,7 +57,7 @@ _hv_file ?= $(srcdir)/tests/misc/help-version dd = $(srcdir)/src/dd.c sc_dd_O_FLAGS: @rm -f $@.1 $@.2 - @{ echo O_FULLBLOCK; echo O_NOCACHE; \ + @{ echo O_FULLBLOCK; echo O_NOCACHE; echo O_SEEKABLE; \ perl -nle '/^ +\| (O_\w*)$$/ and print $$1' $(dd); } | sort > $@.1 @{ echo O_NOFOLLOW; perl -nle '/{"[a-z]+",\s*(O_\w+)},/ and print $$1' \ $(dd); } | sort > $@.2 diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 45a4b3d..9ee9d86 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -8399,6 +8399,12 @@ rather than a block count, which allows specifying an offset that is not a multiple of the I/O block size. This flag can be used only with @code{oflag}. +@item seekable +@opindex seekable +Fail unless the file is seekable. +Note @samp{skip=} or @samp{seek=} don't suffice for this check, +as they will resort to reading, to skip over data. + @end table These flags are not supported on all systems, and @samp{dd} rejects diff --git a/src/dd.c b/src/dd.c index ef5664b..64015b0 100644 --- a/src/dd.c +++ b/src/dd.c @@ -326,7 +326,10 @@ enum O_SKIP_BYTES = FFS_MASK (v4), v5 = v4 ^ O_SKIP_BYTES, - O_SEEK_BYTES = FFS_MASK (v5) + O_SEEK_BYTES = FFS_MASK (v5), + v6 = v5 ^ O_SEEK_BYTES, + + O_SEEKABLE = FFS_MASK (v6) }; /* Ensure that we got something. */ @@ -335,6 +338,7 @@ verify (O_NOCACHE != 0); verify (O_COUNT_BYTES != 0); verify (O_SKIP_BYTES != 0); verify (O_SEEK_BYTES != 0); +verify (O_SEEKABLE != 0); #define MULTIPLE_BITS_SET(i) (((i) & ((i) - 1)) != 0) @@ -344,6 +348,7 @@ verify ( ! MULTIPLE_BITS_SET (O_NOCACHE)); verify ( ! MULTIPLE_BITS_SET (O_COUNT_BYTES)); verify ( ! MULTIPLE_BITS_SET (O_SKIP_BYTES)); verify ( ! MULTIPLE_BITS_SET (O_SEEK_BYTES)); +verify ( ! MULTIPLE_BITS_SET (O_SEEKABLE)); /* Flags, for iflag="..." and oflag="...". */ static struct symbol_value const flags[] = @@ -366,6 +371,7 @@ static struct symbol_value const flags[] = {"count_bytes", O_COUNT_BYTES}, {"skip_bytes", O_SKIP_BYTES}, {"seek_bytes", O_SEEK_BYTES}, + {"seekable", O_SEEKABLE}, {"", 0} }; @@ -619,6 +625,8 @@ Each FLAG symbol may be:\n\ if (O_SEEK_BYTES) fputs (_(" seek_bytes treat 'seek=N' as a byte count (oflag only)\n\ "), stdout); + if (O_SEEKABLE) + fputs (_(" seekable fail unless seekable\n"), stdout); { char const *siginfo_name = (SIGINFO == SIGUSR1 ? "USR1" : "INFO"); @@ -2270,6 +2278,17 @@ main (int argc, char **argv) } } + if (! input_seekable && (input_flags & O_SEEKABLE)) + { + error (EXIT_FAILURE, input_seek_errno, _("input is not seekable %s"), + quote (input_file)); + } + if ((output_flags & O_SEEKABLE) && lseek (STDOUT_FILENO, 0, SEEK_CUR) < 0) + { + error (EXIT_FAILURE, errno, _("output is not seekable %s"), + quote (output_file)); + } + start_time = gethrxtime (); exit_status = dd_copy (); diff --git a/tests/dd/misc.sh b/tests/dd/misc.sh index b9ad31a..cc84457 100755 --- a/tests/dd/misc.sh +++ b/tests/dd/misc.sh @@ -102,4 +102,12 @@ compare err_ok err || fail=1 test $fail -eq 0 && fail=$warn +# check iflag=seekable and oflag=seekable +dd if=/dev/null of=/dev/null iflag=seekable oflag=seekable count=0 || fail=1 +echo 'pipe' | dd of=/dev/null iflag=seekable count=0 && fail=1 +dd if=/dev/null oflag=seekable count=0 status=none 2>err | cat +echo "dd: output is not seekable 'standard output': Illegal seek" > err_ok || + framework_failure_ +compare err_ok err || fail=1 + Exit $fail -- 1.7.6.4 --------------080808060109030905000104--