GNU bug report logs - #17149
shred - tape data

Previous Next

Package: coreutils;

Reported by: Rupert Russell <Rupert.Russell <at> ilmor.co.uk>

Date: Mon, 31 Mar 2014 15:45:04 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


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

From: Pádraig Brady <P <at> draigBrady.com>
To: Rupert Russell <Rupert.Russell <at> ilmor.co.uk>
Cc: 'Paul Eggert' <eggert <at> cs.ucla.edu>,
 "17149 <at> debbugs.gnu.org" <17149 <at> debbugs.gnu.org>
Subject: Re: bug#17149: shred - tape data
Date: Wed, 02 Apr 2014 15:55:16 +0100
On 04/02/2014 09:03 AM, Rupert Russell wrote:
> Paul,
> 
> Interesting challenge you set extracting the last few lines from a 4 gig file, but I've passed that test I think. (Used Less..)
> 
> 
> read(3, "..., 12288) = 12288
> write(4, "..., 12288) = -1 ENOSPC (No space left on device)

So we got ENOSPC and didn't warn about that,
but rather just used that info to determine the end of the device.
That also implies that the initial lseek (fd, 0, SEEK_END)
on the device did return a failure (which we ignored by design).

> write(2, "/dev/st0: pass 1/3 (random)...19"..., 48) = 48

> sync()                                  = 0

> lseek(4, 0, SEEK_SET)                   = 0

We ask here to "rewind", which returns "successfully"

> write(2, "/dev/st0: pass 2/3 (random)...", 30) = 30

> read(3, "..., 12288) = 12288
> write(4, "..., 12288) = 12288

I'm a bit surprised this first write passes

> read(3, "..., 12288) = 12288
> write(4, "..., 12288) = -1 ENOSPC (No space left on device)
> write(2, "/dev/st0: error writing at offse"..., 39) = 39
> write(2, ": No space left on device", 25) = 25
> close(4)                                = 0

So now we know the size of the device, we correctly warn about this error.

The key point is the lseek(4, 0, SEEK_SET) returns success here for the tape device.
I guessed that this was by design, but let's just delve into the code a little...

  http://lxr.linux.no/linux+v3.13.5/drivers/scsi/st.c#L1176
    static int st_open(struct inode *inode, struct file *filp) {
      /*
       * We really want to do nonseekable_open(inode, filp); here, but some
       * versions of tar incorrectly call lseek on tapes and bail out if that
       * fails.  So we disallow pread() and pwrite(), but permit lseeks.
       */
    }
  And the lseek() maps to a noop that just returns the current file pointer.

thanks,
Pádraig.




This bug report was last modified 11 years and 44 days ago.

Previous Next


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