"tar tfv /dev/cd0" speedup patch

Juergen Lock nox at jelal.kn-bremen.de
Wed Feb 17 22:20:15 UTC 2010


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 <unistd.h>
 #endif
+#ifdef __FreeBSD__
+#include <sys/ioctl.h>
+#include <sys/disk.h>
+#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));
 }


More information about the freebsd-hackers mailing list