From owner-freebsd-hackers@FreeBSD.ORG Fri Feb 19 08:34:31 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AFD361065692 for ; Fri, 19 Feb 2010 08:34:31 +0000 (UTC) (envelope-from matthias.andree@gmx.de) Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by mx1.freebsd.org (Postfix) with SMTP id 1578A8FC0C for ; Fri, 19 Feb 2010 08:34:30 +0000 (UTC) Received: (qmail invoked by alias); 19 Feb 2010 08:34:29 -0000 Received: from g227156056.adsl.alicedsl.de (EHLO mandree.no-ip.org) [92.227.156.56] by mail.gmx.net (mp055) with SMTP; 19 Feb 2010 09:34:29 +0100 X-Authenticated: #428038 X-Provags-ID: V01U2FsdGVkX18tSxk4uBMt66y633KTodxhOyG8qAT6gvKyEcJVS4 5v1Gue6pHwcc6Z Received: from merlin.emma.line.org (localhost [127.0.0.1]) by merlin.emma.line.org (Postfix) with ESMTP id 14BFB94657; Fri, 19 Feb 2010 09:34:28 +0100 (CET) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "Tim Kientzle" , freebsd-hackers@freebsd.org References: <20100217215940.GA19713@triton8.kn-bremen.de> <4B7CE066.4030403@freebsd.org> <20100218183459.GA65508@triton8.kn-bremen.de> <20100218191347.GA4040@britannica.bec.de> <4B7E1BA5.7050209@freebsd.org> Date: Fri, 19 Feb 2010 09:34:27 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Matthias Andree" Organization: Message-ID: In-Reply-To: <4B7E1BA5.7050209@freebsd.org> User-Agent: Opera Mail/10.10 (Linux) X-Y-GMX-Trusted: 0 X-FuHaFi: 0.52000000000000002 Cc: Subject: seeking and seekability (was: "tar tfv /dev/cd0" speedup patch) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Feb 2010 08:34:31 -0000 Am 19.02.2010, 06:03 Uhr, schrieb Tim Kientzle : > Joerg Sonnenberger wrote: >> On Thu, Feb 18, 2010 at 07:34:59PM +0100, Juergen Lock wrote: >>> Ok here is a new version of the patch with these things fixed and the >>> Linux case added: (Linux case not tested yet, and yes I did this on >>> stable/8.) >> Why the check at all? Shouldn't devices that don't allow seek fail >> that? >> E.g. for devices, just try to seek ahead and fallback to normal reading? > > That was the initial implementation in libarchive, but > I had a number of reports of that not working for > tape drives. I recently dug out and connected an > old DDS drive I had in the closet, so I should > probably try again and see if I misunderstood > something along the way. I'd already written this in a private email to Tim before I came across this continued discussion on -hackers@, I'll paste a modified version of my own part: I strongly believe that someone should really fix lseek() in FreeBSD outside GEOM. There is precedence, namely and it was never properly fixed. The PR was closed because the actual reported problem on da(4) no longer occurred since FreeBSD 5 after the GEOM migration, and my issue was with da(4) on FreeBSD 4. Now I'm learning that the very same bug persists through -CURRENT nearly a decade later: after lseek devices such as sa(4) will return "garbage" (i. e. from the unchanged offset) rather than failing. It should be sorted out before 8.1. Am I naive if I expect lseek to return (off_t)-1 with errno == ESPIPE on non-seekable devices? I'll concede that sa(4) is neither socket nor pipe nor fifo in the strict sense, but all share the non-seekability. If lseek() can't know the device isn't seekable, subsequent I/O operations should return EIO along with a proper kernel log message for the first occasion per process, but that would not help applications or libarchive for that matter - they will need a canonical way to find out if a device is seekable. Unfortunately FreeBSD maps many physical block devices that are unbuffered to character special device nodes, so the obvious way of calling [f]stat() and then checking S_ISBLK(st.st_mode) will return FALSE even for devices that can seek. -- Matthias Andree