From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 17 22:20:15 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 87DB41065697; Wed, 17 Feb 2010 22:20:15 +0000 (UTC) (envelope-from nox@jelal.kn-bremen.de) Received: from smtp.kn-bremen.de (gelbbaer.kn-bremen.de [78.46.108.116]) by mx1.freebsd.org (Postfix) with ESMTP id 49C3C8FC13; Wed, 17 Feb 2010 22:20:15 +0000 (UTC) Received: by smtp.kn-bremen.de (Postfix, from userid 10) id A2EB11E00771; Wed, 17 Feb 2010 23:01:38 +0100 (CET) Received: from triton8.kn-bremen.de (noident@localhost [127.0.0.1]) by triton8.kn-bremen.de (8.14.3/8.14.3) with ESMTP id o1HLxfZQ019932; Wed, 17 Feb 2010 22:59:41 +0100 (CET) (envelope-from nox@triton8.kn-bremen.de) Received: (from nox@localhost) by triton8.kn-bremen.de (8.14.3/8.14.3/Submit) id o1HLxfZx019931; Wed, 17 Feb 2010 22:59:41 +0100 (CET) (envelope-from nox) From: Juergen Lock Date: Wed, 17 Feb 2010 22:59:40 +0100 To: freebsd-hackers@FreeBSD.org Message-ID: <20100217215940.GA19713@triton8.kn-bremen.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-Mailman-Approved-At: Wed, 17 Feb 2010 22:47:25 +0000 Cc: kientzle@FreeBSD.org Subject: "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: Wed, 17 Feb 2010 22:20:15 -0000 Hi! I recently wanted to quickly look at an optical disc without mounting it and since bsdtar/libarchive know iso9660 I just did the command in the Subject. It worked, but it was sloow... :( Apparently it read all of the disc without seeking. The following patch fixes this, is something like this desired? If yes I could look how to do the same for Linux, I _think_ there you could just check for S_ISBLK and try to lseek to the end and back, at least that seems to be how you find out the size of a block device there... Cheers, Juergen Index: lib/libarchive/archive_read_open_filename.c @@ -44,6 +44,10 @@ #ifdef HAVE_UNISTD_H #include #endif +#ifdef __FreeBSD__ +#include +#include +#endif #include "archive.h" @@ -83,6 +87,9 @@ struct read_file_data *mine; void *b; int fd; +#ifdef __FreeBSD__ + off_t mediasize = 0; +#endif archive_clear_error(a); if (filename == NULL || filename[0] == '\0') { @@ -143,6 +150,17 @@ */ mine->can_skip = 1; } +#ifdef __FreeBSD__ + /* + * on FreeBSD if a device supports the DIOCGMEDIASIZE ioctl + * it is a disk-like device and should be seekable. + */ + else if (S_ISCHR(st.st_mode) && + !ioctl(fd, DIOCGMEDIASIZE, &mediasize) && mediasize) { + archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino); + mine->can_skip = 1; + } +#endif return (archive_read_open2(a, mine, NULL, file_read, file_skip, file_close)); }