From owner-freebsd-hackers@FreeBSD.ORG Sun Nov 20 17:51:00 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 1233) id C937C1065676; Sun, 20 Nov 2011 17:51:00 +0000 (UTC) Date: Sun, 20 Nov 2011 17:51:00 +0000 From: Alexander Best To: Dieter BSD Message-ID: <20111120175100.GA10240@freebsd.org> References: <20111120174025.233420@gmx.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20111120174025.233420@gmx.com> Cc: freebsd-hackers@freebsd.org Subject: Re: easy way to determine if a stream or fd is seekable 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: Sun, 20 Nov 2011 17:51:00 -0000 On Sun Nov 20 11, Dieter BSD wrote: > > something like the following inside lseek() would take care of tape drives: > > > >        if (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)) { > >                if (ioctl(io->fd, FIODTYPE, &type) == -1) > >                        err(1, "%s", io->name); > > > >                if (type & D_TAPE) > >                        return(EBADF) > >        } > > I'd suggest ENODEV ("Operation not supported by device") rather than > EBADF ("Bad file descriptor"). > > To do this correctly, we'd need some standard way to ask the > device driver if the device can perform the seek or not. this might be a bit of a problem, since those devices and drivers that don't support seeking are mostly legacy tape drives. i don't think these drivers are actively being maintained atm. another issue are removable media. running the patched version of hexdump (i posted a patch earlier today) shows that running fseeko() against /dev/cd0, where no media is present, succeeds. with a media inserted however, /dev/cd0 is very well capable of seeking. cheers. alex >