PERFORCE change 121573 for review

Sepherosa Ziehau sephe at FreeBSD.org
Wed Jun 13 13:17:09 UTC 2007


http://perforce.freebsd.org/chv.cgi?CH=121573

Change 121573 by sephe at sephe_enigma:sam_wifi on 2007/06/13 13:16:39

	IFC @121571 (unbreak buildworld)

Affected files ...

.. //depot/projects/wifi/lib/libarchive/archive_read_support_format_tar.c#19 integrate
.. //depot/projects/wifi/lib/libarchive/test/Makefile#6 integrate
.. //depot/projects/wifi/lib/libarchive/test/main.c#4 integrate
.. //depot/projects/wifi/lib/libarchive/test/test_read_format_gtar_sparse.c#1 branch
.. //depot/projects/wifi/lib/libarchive/test/test_tar_filenames.c#4 integrate
.. //depot/projects/wifi/lib/libarchive/test/test_write_format_ar.c#4 integrate
.. //depot/projects/wifi/lib/libc/net/Makefile.inc#10 integrate
.. //depot/projects/wifi/lib/libc/net/sourcefilter.3#1 branch
.. //depot/projects/wifi/lib/libc/net/sourcefilter.c#1 branch
.. //depot/projects/wifi/sbin/Makefile#13 integrate
.. //depot/projects/wifi/sbin/mknod/mknod.c#2 integrate
.. //depot/projects/wifi/share/man/man4/nfe.4#5 integrate
.. //depot/projects/wifi/share/man/man5/src.conf.5#6 integrate
.. //depot/projects/wifi/share/mk/bsd.own.mk#10 integrate
.. //depot/projects/wifi/sys/conf/NOTES#42 integrate
.. //depot/projects/wifi/sys/conf/files#55 integrate
.. //depot/projects/wifi/sys/conf/options#35 integrate
.. //depot/projects/wifi/sys/dev/cxgb/common/cxgb_ael1002.c#3 integrate
.. //depot/projects/wifi/sys/dev/cxgb/common/cxgb_common.h#3 integrate
.. //depot/projects/wifi/sys/dev/cxgb/common/cxgb_mc5.c#3 integrate
.. //depot/projects/wifi/sys/dev/cxgb/common/cxgb_t3_hw.c#3 integrate
.. //depot/projects/wifi/sys/dev/cxgb/common/cxgb_vsc7323.c#1 branch
.. //depot/projects/wifi/sys/dev/cxgb/common/cxgb_xgmac.c#3 integrate
.. //depot/projects/wifi/sys/dev/cxgb/cxgb_adapter.h#4 integrate
.. //depot/projects/wifi/sys/dev/cxgb/cxgb_config.h#3 integrate
.. //depot/projects/wifi/sys/dev/cxgb/cxgb_lro.c#4 integrate
.. //depot/projects/wifi/sys/dev/cxgb/cxgb_main.c#6 integrate
.. //depot/projects/wifi/sys/dev/cxgb/cxgb_offload.c#2 integrate
.. //depot/projects/wifi/sys/dev/cxgb/cxgb_offload.h#2 integrate
.. //depot/projects/wifi/sys/dev/cxgb/cxgb_sge.c#6 integrate
.. //depot/projects/wifi/sys/dev/cxgb/t3fw-4.0.0.bin.gz.uu#2 delete
.. //depot/projects/wifi/sys/dev/cxgb/t3fw-4.1.0.bin.gz.uu#1 branch
.. //depot/projects/wifi/sys/dev/mxge/if_mxge.c#13 integrate
.. //depot/projects/wifi/sys/dev/usb/dsbr100io.h#3 integrate
.. //depot/projects/wifi/sys/dev/usb/ehci.c#14 integrate
.. //depot/projects/wifi/sys/dev/usb/hid.c#6 integrate
.. //depot/projects/wifi/sys/dev/usb/if_aue.c#15 integrate
.. //depot/projects/wifi/sys/dev/usb/if_axe.c#21 integrate
.. //depot/projects/wifi/sys/dev/usb/if_cdce.c#10 integrate
.. //depot/projects/wifi/sys/dev/usb/if_cue.c#14 integrate
.. //depot/projects/wifi/sys/dev/usb/if_kue.c#14 integrate
.. //depot/projects/wifi/sys/dev/usb/if_rue.c#14 integrate
.. //depot/projects/wifi/sys/dev/usb/if_rum.c#5 integrate
.. //depot/projects/wifi/sys/dev/usb/if_udav.c#16 integrate
.. //depot/projects/wifi/sys/dev/usb/if_ural.c#30 integrate
.. //depot/projects/wifi/sys/dev/usb/ohci.c#10 integrate
.. //depot/projects/wifi/sys/dev/usb/ohcivar.h#7 integrate
.. //depot/projects/wifi/sys/dev/usb/rio500_usb.h#3 integrate
.. //depot/projects/wifi/sys/dev/usb/uark.c#5 integrate
.. //depot/projects/wifi/sys/dev/usb/ubsa.c#9 integrate
.. //depot/projects/wifi/sys/dev/usb/ubser.c#9 integrate
.. //depot/projects/wifi/sys/dev/usb/udbp.c#6 integrate
.. //depot/projects/wifi/sys/dev/usb/ufm.c#7 integrate
.. //depot/projects/wifi/sys/dev/usb/ufoma.c#6 integrate
.. //depot/projects/wifi/sys/dev/usb/uftdi.c#9 integrate
.. //depot/projects/wifi/sys/dev/usb/uhci.c#11 integrate
.. //depot/projects/wifi/sys/dev/usb/uhcivar.h#6 integrate
.. //depot/projects/wifi/sys/dev/usb/uhid.c#11 integrate
.. //depot/projects/wifi/sys/dev/usb/uhub.c#11 integrate
.. //depot/projects/wifi/sys/dev/usb/uipaq.c#3 integrate
.. //depot/projects/wifi/sys/dev/usb/ukbd.c#10 integrate
.. //depot/projects/wifi/sys/dev/usb/ulpt.c#8 integrate
.. //depot/projects/wifi/sys/dev/usb/umass.c#15 integrate
.. //depot/projects/wifi/sys/dev/usb/umct.c#7 integrate
.. //depot/projects/wifi/sys/dev/usb/umodem.c#9 integrate
.. //depot/projects/wifi/sys/dev/usb/ums.c#13 integrate
.. //depot/projects/wifi/sys/dev/usb/uplcom.c#14 integrate
.. //depot/projects/wifi/sys/dev/usb/urio.c#7 integrate
.. //depot/projects/wifi/sys/dev/usb/usb.c#13 integrate
.. //depot/projects/wifi/sys/dev/usb/usb.h#6 integrate
.. //depot/projects/wifi/sys/dev/usb/usb_mem.c#7 integrate
.. //depot/projects/wifi/sys/dev/usb/usb_mem.h#3 integrate
.. //depot/projects/wifi/sys/dev/usb/usb_port.h#10 integrate
.. //depot/projects/wifi/sys/dev/usb/usbdi.c#8 integrate
.. //depot/projects/wifi/sys/dev/usb/usbdi.h#9 integrate
.. //depot/projects/wifi/sys/dev/usb/usbdi_util.c#5 integrate
.. //depot/projects/wifi/sys/dev/usb/usbdivar.h#7 integrate
.. //depot/projects/wifi/sys/dev/usb/uscanner.c#11 integrate
.. //depot/projects/wifi/sys/dev/usb/uvisor.c#10 integrate
.. //depot/projects/wifi/sys/dev/usb/uvscom.c#9 integrate
.. //depot/projects/wifi/sys/geom/part/g_part_mbr.c#1 branch
.. //depot/projects/wifi/sys/ia64/conf/DEFAULTS#6 integrate
.. //depot/projects/wifi/sys/kern/kern_kse.c#17 integrate
.. //depot/projects/wifi/sys/kern/kern_switch.c#19 integrate
.. //depot/projects/wifi/sys/kern/kern_thread.c#22 integrate
.. //depot/projects/wifi/sys/kern/subr_sleepqueue.c#14 integrate
.. //depot/projects/wifi/sys/kern/subr_trap.c#13 integrate
.. //depot/projects/wifi/sys/kern/subr_turnstile.c#12 integrate
.. //depot/projects/wifi/sys/libkern/mcount.c#2 integrate
.. //depot/projects/wifi/sys/modules/cxgb/Makefile#4 integrate
.. //depot/projects/wifi/sys/modules/ip_mroute_mod/Makefile#4 integrate
.. //depot/projects/wifi/sys/net/if_ethersubr.c#23 integrate
.. //depot/projects/wifi/sys/netgraph/bluetooth/drivers/ubtbcmfw/ubtbcmfw.c#6 integrate
.. //depot/projects/wifi/sys/netgraph/ng_car.c#3 integrate
.. //depot/projects/wifi/sys/netinet/sctp.h#8 integrate
.. //depot/projects/wifi/sys/netinet/sctp_constants.h#13 integrate
.. //depot/projects/wifi/sys/netinet/sctp_input.c#14 integrate
.. //depot/projects/wifi/sys/netinet/sctp_pcb.c#15 integrate
.. //depot/projects/wifi/sys/netinet/sctp_structs.h#10 integrate
.. //depot/projects/wifi/sys/netinet/sctp_sysctl.c#6 integrate
.. //depot/projects/wifi/sys/netinet/sctp_sysctl.h#3 integrate
.. //depot/projects/wifi/sys/netinet/sctp_timer.c#10 integrate
.. //depot/projects/wifi/sys/netinet/sctputil.c#14 integrate
.. //depot/projects/wifi/sys/powerpc/conf/DEFAULTS#6 integrate
.. //depot/projects/wifi/sys/sun4v/include/pcpu.h#4 integrate
.. //depot/projects/wifi/sys/sys/proc.h#33 integrate
.. //depot/projects/wifi/sys/sys/sched.h#8 integrate
.. //depot/projects/wifi/sys/vm/vm_pageout.c#16 integrate
.. //depot/projects/wifi/tools/build/options/WITHOUT_KVM#1 branch
.. //depot/projects/wifi/tools/build/options/WITHOUT_KVM_SUPPORT#1 branch
.. //depot/projects/wifi/tools/tools/recoverdisk/Makefile#5 delete
.. //depot/projects/wifi/tools/tools/recoverdisk/recoverdisk.1#3 delete
.. //depot/projects/wifi/tools/tools/recoverdisk/recoverdisk.c#5 delete
.. //depot/projects/wifi/usr.bin/Makefile#14 integrate
.. //depot/projects/wifi/usr.bin/netstat/sctp.c#2 integrate
.. //depot/projects/wifi/usr.sbin/ifmcstat/Makefile#4 integrate

Differences ...

==== //depot/projects/wifi/lib/libarchive/archive_read_support_format_tar.c#19 (text+ko) ====

@@ -24,7 +24,7 @@
  */
 
 #include "archive_platform.h"
-__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_tar.c,v 1.56 2007/05/29 01:00:19 kientzle Exp $");
+__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_tar.c,v 1.57 2007/06/13 03:35:37 kientzle Exp $");
 
 #ifdef HAVE_ERRNO_H
 #include <errno.h>
@@ -150,22 +150,34 @@
 	struct archive_string	 longname;
 	struct archive_string	 pax_header;
 	struct archive_string	 pax_global;
+	struct archive_string	 line;
 	wchar_t 		*pax_entry;
 	size_t			 pax_entry_length;
 	int			 header_recursion_depth;
 	off_t			 entry_bytes_remaining;
 	off_t			 entry_offset;
 	off_t			 entry_padding;
+	off_t			 realsize;
 	struct sparse_block	*sparse_list;
+	struct sparse_block	*sparse_last;
+	int64_t			 sparse_offset;
+	int64_t			 sparse_numbytes;
+	int			 sparse_gnu_major;
+	int			 sparse_gnu_minor;
+	char			 sparse_gnu_pending;
 };
 
 static size_t	UTF8_mbrtowc(wchar_t *pwc, const char *s, size_t n);
 static int	archive_block_is_null(const unsigned char *p);
 static char	*base64_decode(const wchar_t *, size_t, size_t *);
-static int	gnu_read_sparse_data(struct archive_read *, struct tar *,
+static void	 gnu_add_sparse_entry(struct tar *,
+		    off_t offset, off_t remaining);
+static int	gnu_sparse_old_read(struct archive_read *, struct tar *,
 		    const struct archive_entry_header_gnutar *header);
-static void	gnu_parse_sparse_data(struct archive_read *, struct tar *,
+static void	gnu_sparse_old_parse(struct tar *,
 		    const struct gnu_sparse *sparse, int length);
+static int	gnu_sparse_01_parse(struct tar *, const wchar_t *);
+static ssize_t	gnu_sparse_10_read(struct archive_read *, struct tar *);
 static int	header_Solaris_ACL(struct archive_read *,  struct tar *,
 		    struct archive_entry *, const void *);
 static int	header_common(struct archive_read *,  struct tar *,
@@ -194,11 +206,12 @@
 static int	archive_read_format_tar_read_header(struct archive_read *,
 		    struct archive_entry *);
 static int	checksum(struct archive_read *, const void *);
-static int 	pax_attribute(struct archive_entry *,
+static int 	pax_attribute(struct tar *, struct archive_entry *,
 		    wchar_t *key, wchar_t *value);
 static int 	pax_header(struct archive_read *, struct tar *,
 		    struct archive_entry *, char *attr);
 static void	pax_time(const wchar_t *, int64_t *sec, long *nanos);
+static ssize_t	readline(struct archive_read *, struct tar *, const char **);
 static int	read_body_to_string(struct archive_read *, struct tar *,
 		    struct archive_string *, const void *h);
 static int64_t	tar_atol(const char *, unsigned);
@@ -250,17 +263,23 @@
 archive_read_format_tar_cleanup(struct archive_read *a)
 {
 	struct tar *tar;
+	struct sparse_block *p;
 
 	tar = (struct tar *)(a->format->data);
+	while (tar->sparse_list != NULL) {
+		p = tar->sparse_list;
+		tar->sparse_list = p->next;
+		free(p);
+	}
 	archive_string_free(&tar->acl_text);
 	archive_string_free(&tar->entry_name);
 	archive_string_free(&tar->entry_linkname);
 	archive_string_free(&tar->entry_uname);
 	archive_string_free(&tar->entry_gname);
+	archive_string_free(&tar->line);
 	archive_string_free(&tar->pax_global);
 	archive_string_free(&tar->pax_header);
-	if (tar->pax_entry != NULL)
-		free(tar->pax_entry);
+	free(tar->pax_entry);
 	free(tar);
 	(a->format->data) = NULL;
 	return (ARCHIVE_OK);
@@ -400,9 +419,11 @@
 	static int default_inode;
 	static int default_dev;
 	struct tar *tar;
+	struct sparse_block *sp;
 	const char *p;
 	int r;
 	size_t l;
+	ssize_t size;
 
 	/* Assign default device/inode values. */
 	archive_entry_set_dev(entry, 1 + default_dev); /* Don't use zero. */
@@ -415,9 +436,40 @@
 
 	tar = (struct tar *)(a->format->data);
 	tar->entry_offset = 0;
+	while (tar->sparse_list != NULL) {
+		sp = tar->sparse_list;
+		tar->sparse_list = sp->next;
+		free(sp);
+	}
+	tar->sparse_last = NULL;
 
 	r = tar_read_header(a, tar, entry);
 
+	/*
+	 * Yuck.  See comments for gnu_sparse_10_read for why this
+	 * is here and not in _read_data where it "should" go.
+	 */
+	if (tar->sparse_gnu_pending
+	    && tar->sparse_gnu_major == 1
+	    && tar->sparse_gnu_minor == 0) {
+		tar->sparse_gnu_pending = 0;
+		/* Read initial sparse map. */
+		size = gnu_sparse_10_read(a, tar);
+		if (size < 0)
+			return (size);
+		tar->entry_bytes_remaining -= size;
+		tar->entry_padding += size;
+	}
+
+	/*
+	 * "non-sparse" files are really just sparse files with
+	 * a single block.
+	 */
+	if (tar->sparse_list == NULL)
+		gnu_add_sparse_entry(tar, 0, tar->entry_bytes_remaining);
+
+	tar->realsize = archive_entry_size(entry);
+
 	if (r == ARCHIVE_OK) {
 		/*
 		 * "Regular" entry with trailing '/' is really
@@ -442,55 +494,64 @@
 	struct sparse_block *p;
 
 	tar = (struct tar *)(a->format->data);
-	if (tar->sparse_list != NULL) {
-		/* Remove exhausted entries from sparse list. */
-		while (tar->sparse_list != NULL &&
-		    tar->sparse_list->remaining == 0) {
-			p = tar->sparse_list;
-			tar->sparse_list = p->next;
-			free(p);
+
+	if (tar->sparse_gnu_pending) {
+		if (tar->sparse_gnu_major == 1 && tar->sparse_gnu_minor == 0) {
+			/*
+			 * <sigh> We should parse the sparse data
+			 * here, but have to parse it as part of the
+			 * header because of a bug in GNU tar 1.16.1.
+			 */
+		} else {
+			*size = 0;
+			*offset = 0;
+			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+			    "Unrecognized GNU sparse file format");
+			return (ARCHIVE_WARN);
 		}
-		if (tar->sparse_list == NULL) {
-			/* We exhausted the entire sparse list. */
-			tar->entry_bytes_remaining = 0;
-		}
+		tar->sparse_gnu_pending = 0;
+	}
+
+	/* Remove exhausted entries from sparse list. */
+	while (tar->sparse_list != NULL &&
+	    tar->sparse_list->remaining == 0) {
+		p = tar->sparse_list;
+		tar->sparse_list = p->next;
+		free(p);
 	}
 
-	if (tar->entry_bytes_remaining > 0) {
-		bytes_read = (a->decompressor->read_ahead)(a, buff, 1);
-		if (bytes_read == 0) {
-			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
-			    "Truncated tar archive");
-			return (ARCHIVE_FATAL);
-		}
-		if (bytes_read < 0)
-			return (ARCHIVE_FATAL);
-		if (bytes_read > tar->entry_bytes_remaining)
-			bytes_read = tar->entry_bytes_remaining;
-		if (tar->sparse_list != NULL) {
-			/* Don't read more than is available in the
-			 * current sparse block. */
-			if (tar->sparse_list->remaining < bytes_read)
-				bytes_read = tar->sparse_list->remaining;
-			tar->entry_offset = tar->sparse_list->offset;
-			tar->sparse_list->remaining -= bytes_read;
-			tar->sparse_list->offset += bytes_read;
-		}
-		*size = bytes_read;
-		*offset = tar->entry_offset;
-		tar->entry_offset += bytes_read;
-		tar->entry_bytes_remaining -= bytes_read;
-		(a->decompressor->consume)(a, bytes_read);
-		return (ARCHIVE_OK);
-	} else {
+	/* If we're at end of file, return EOF. */
+	if (tar->sparse_list == NULL || tar->entry_bytes_remaining == 0) {
 		if ((a->decompressor->skip)(a, tar->entry_padding) < 0)
 			return (ARCHIVE_FATAL);
 		tar->entry_padding = 0;
 		*buff = NULL;
 		*size = 0;
-		*offset = tar->entry_offset;
+		*offset = tar->realsize;
 		return (ARCHIVE_EOF);
 	}
+
+	bytes_read = (a->decompressor->read_ahead)(a, buff, 1);
+	if (bytes_read == 0) {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Truncated tar archive");
+		return (ARCHIVE_FATAL);
+	}
+	if (bytes_read < 0)
+		return (ARCHIVE_FATAL);
+	if (bytes_read > tar->entry_bytes_remaining)
+		bytes_read = tar->entry_bytes_remaining;
+	/* Don't read more than is available in the
+	 * current sparse block. */
+	if (tar->sparse_list->remaining < bytes_read)
+		bytes_read = tar->sparse_list->remaining;
+	*size = bytes_read;
+	*offset = tar->sparse_list->offset;
+	tar->sparse_list->remaining -= bytes_read;
+	tar->sparse_list->offset += bytes_read;
+	tar->entry_bytes_remaining -= bytes_read;
+	(a->decompressor->consume)(a, bytes_read);
+	return (ARCHIVE_OK);
 }
 
 static int
@@ -521,6 +582,7 @@
 		tar->sparse_list = p->next;
 		free(p);
 	}
+	tar->sparse_last = NULL;
 
 	return (ARCHIVE_OK);
 }
@@ -847,7 +909,8 @@
 	archive_entry_set_mode(entry, tar_atol(header->mode, sizeof(header->mode)));
 	archive_entry_set_uid(entry, tar_atol(header->uid, sizeof(header->uid)));
 	archive_entry_set_gid(entry, tar_atol(header->gid, sizeof(header->gid)));
-	archive_entry_set_size(entry, tar_atol(header->size, sizeof(header->size)));
+	tar->entry_bytes_remaining = tar_atol(header->size, sizeof(header->size));
+	archive_entry_set_size(entry, tar->entry_bytes_remaining);
 	archive_entry_set_mtime(entry, tar_atol(header->mtime, sizeof(header->mtime)), 0);
 
 	/* Handle the tar type flag appropriately. */
@@ -892,29 +955,35 @@
 		 */
 		if (archive_entry_size(entry) > 0  &&
 		    a->archive.archive_format != ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE  &&
-		    archive_read_format_tar_bid(a) > 50)
+		    archive_read_format_tar_bid(a) > 50) {
 			archive_entry_set_size(entry, 0);
-		break;
+			tar->entry_bytes_remaining = 0;
+		}
 	case '2': /* Symlink */
 		archive_entry_set_filetype(entry, AE_IFLNK);
 		archive_entry_set_size(entry, 0);
+		tar->entry_bytes_remaining = 0;
 		archive_entry_set_symlink(entry, tar->entry_linkname.s);
 		break;
 	case '3': /* Character device */
 		archive_entry_set_filetype(entry, AE_IFCHR);
 		archive_entry_set_size(entry, 0);
+		tar->entry_bytes_remaining = 0;
 		break;
 	case '4': /* Block device */
 		archive_entry_set_filetype(entry, AE_IFBLK);
 		archive_entry_set_size(entry, 0);
+		tar->entry_bytes_remaining = 0;
 		break;
 	case '5': /* Dir */
 		archive_entry_set_filetype(entry, AE_IFDIR);
 		archive_entry_set_size(entry, 0);
+		tar->entry_bytes_remaining = 0;
 		break;
 	case '6': /* FIFO device */
 		archive_entry_set_filetype(entry, AE_IFIFO);
 		archive_entry_set_size(entry, 0);
+		tar->entry_bytes_remaining = 0;
 		break;
 	case 'D': /* GNU incremental directory type */
 		/*
@@ -972,7 +1041,6 @@
 	/* Grab rest of common fields */
 	header_common(a, tar, entry, h);
 
-	tar->entry_bytes_remaining = archive_entry_size(entry);
 	tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining);
 	return (0);
 }
@@ -1014,7 +1082,6 @@
 	 */
 	err2 = pax_header(a, tar, entry, tar->pax_header.s);
 	err =  err_combine(err, err2);
-	tar->entry_bytes_remaining = archive_entry_size(entry);
 	tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining);
 	return (err);
 }
@@ -1065,7 +1132,6 @@
 		    tar_atol(header->rdevminor, sizeof(header->rdevminor)));
 	}
 
-	tar->entry_bytes_remaining = archive_entry_size(entry);
 	tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining);
 
 	return (0);
@@ -1160,7 +1226,7 @@
 		value = wp + 1;
 
 		/* Identify this attribute and set it in the entry. */
-		err2 = pax_attribute(entry, key, value);
+		err2 = pax_attribute(tar, entry, key, value);
 		err = err_combine(err, err2);
 
 		/* Skip to next line */
@@ -1215,19 +1281,72 @@
  * extensions should always have keywords of the form "VENDOR.attribute"
  * In particular, it's quite feasible to support many different
  * vendor extensions here.  I'm using "LIBARCHIVE" for extensions
- * unique to this library (currently, there are none).
+ * unique to this library.
  *
- * Investigate other vendor-specific extensions, as well and see if
+ * Investigate other vendor-specific extensions and see if
  * any of them look useful.
  */
 static int
-pax_attribute(struct archive_entry *entry,
+pax_attribute(struct tar *tar, struct archive_entry *entry,
     wchar_t *key, wchar_t *value)
 {
 	int64_t s;
 	long n;
 
 	switch (key[0]) {
+	case 'G':
+		/* GNU "0.0" sparse pax format. */
+		if (wcscmp(key, L"GNU.sparse.numblocks") == 0) {
+			tar->sparse_offset = -1;
+			tar->sparse_numbytes = -1;
+			tar->sparse_gnu_major = 0;
+			tar->sparse_gnu_minor = 0;
+		}
+		if (wcscmp(key, L"GNU.sparse.offset") == 0) {
+			tar->sparse_offset = tar_atol10(value, wcslen(value));
+			if (tar->sparse_numbytes != -1) {
+				gnu_add_sparse_entry(tar,
+				    tar->sparse_offset, tar->sparse_numbytes);
+				tar->sparse_offset = -1;
+				tar->sparse_numbytes = -1;
+			}
+		}
+		if (wcscmp(key, L"GNU.sparse.numbytes") == 0) {
+			tar->sparse_numbytes = tar_atol10(value, wcslen(value));
+			if (tar->sparse_numbytes != -1) {
+				gnu_add_sparse_entry(tar,
+				    tar->sparse_offset, tar->sparse_numbytes);
+				tar->sparse_offset = -1;
+				tar->sparse_numbytes = -1;
+			}
+		}
+		if (wcscmp(key, L"GNU.sparse.size") == 0)
+			archive_entry_set_size(entry,
+			    tar_atol10(value, wcslen(value)));
+
+		/* GNU "0.1" sparse pax format. */
+		if (wcscmp(key, L"GNU.sparse.map") == 0) {
+			tar->sparse_gnu_major = 0;
+			tar->sparse_gnu_minor = 1;
+			if (gnu_sparse_01_parse(tar, value) != ARCHIVE_OK)
+				return (ARCHIVE_WARN);
+		}
+
+		/* GNU "1.0" sparse pax format */
+		if (wcscmp(key, L"GNU.sparse.major") == 0) {
+			tar->sparse_gnu_major = tar_atol10(value, wcslen(value));
+			tar->sparse_gnu_pending = 1;
+		}
+		if (wcscmp(key, L"GNU.sparse.minor") == 0) {
+			tar->sparse_gnu_minor = tar_atol10(value, wcslen(value));
+			tar->sparse_gnu_pending = 1;
+		}
+		if (wcscmp(key, L"GNU.sparse.name") == 0)
+			archive_entry_copy_pathname_w(entry, value);
+		if (wcscmp(key, L"GNU.sparse.realsize") == 0)
+			archive_entry_set_size(entry,
+			    tar_atol10(value, wcslen(value)));
+		break;
 	case 'L':
 		/* Our extensions */
 /* TODO: Handle arbitrary extended attributes... */
@@ -1306,8 +1425,12 @@
 	case 's':
 		/* POSIX has reserved 'security.*' */
 		/* Someday: if (wcscmp(key, L"security.acl")==0) { ... } */
-		if (wcscmp(key, L"size")==0)
-			archive_entry_set_size(entry, tar_atol10(value, wcslen(value)));
+		if (wcscmp(key, L"size")==0) {
+			tar->entry_bytes_remaining = tar_atol10(value, wcslen(value));
+			archive_entry_set_size(entry, tar->entry_bytes_remaining);
+		}
+		tar->entry_bytes_remaining = 0;
+
 		break;
 	case 'u':
 		if (wcscmp(key, L"uid")==0)
@@ -1418,7 +1541,6 @@
 	} else
 		archive_entry_set_rdev(entry, 0);
 
-	tar->entry_bytes_remaining = archive_entry_size(entry);
 	tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining);
 
 	/* Grab GNU-specific fields. */
@@ -1432,7 +1554,7 @@
 	}
 
 	if (header->sparse[0].offset[0] != 0) {
-		gnu_read_sparse_data(a, tar, header);
+		gnu_sparse_old_read(a, tar, header);
 	} else {
 		if (header->isextended[0] != 0) {
 			/* XXX WTF? XXX */
@@ -1442,8 +1564,38 @@
 	return (0);
 }
 
+static void
+gnu_add_sparse_entry(struct tar *tar, off_t offset, off_t remaining)
+{
+	struct sparse_block *p;
+
+	p = (struct sparse_block *)malloc(sizeof(*p));
+	if (p == NULL)
+		__archive_errx(1, "Out of memory");
+	memset(p, 0, sizeof(*p));
+	if (tar->sparse_last != NULL)
+		tar->sparse_last->next = p;
+	else
+		tar->sparse_list = p;
+	tar->sparse_last = p;
+	p->offset = offset;
+	p->remaining = remaining;
+}
+
+/*
+ * GNU tar old-format sparse data.
+ *
+ * GNU old-format sparse data is stored in a fixed-field
+ * format.  Offset/size values are 11-byte octal fields (same
+ * format as 'size' field in ustart header).  These are
+ * stored in the header, allocating subsequent header blocks
+ * as needed.  Extending the header in this way is a pretty
+ * severe POSIX violation; this design has earned GNU tar a
+ * lot of criticism.
+ */
+
 static int
-gnu_read_sparse_data(struct archive_read *a, struct tar *tar,
+gnu_sparse_old_read(struct archive_read *a, struct tar *tar,
     const struct archive_entry_header_gnutar *header)
 {
 	ssize_t bytes_read;
@@ -1455,7 +1607,7 @@
 	};
 	const struct extended *ext;
 
-	gnu_parse_sparse_data(a, tar, header->sparse, 4);
+	gnu_sparse_old_parse(tar, header->sparse, 4);
 	if (header->isextended[0] == 0)
 		return (ARCHIVE_OK);
 
@@ -1471,7 +1623,7 @@
 		}
 		(a->decompressor->consume)(a, 512);
 		ext = (const struct extended *)data;
-		gnu_parse_sparse_data(a, tar, ext->sparse, 21);
+		gnu_sparse_old_parse(tar, ext->sparse, 21);
 	} while (ext->isextended[0] != 0);
 	if (tar->sparse_list != NULL)
 		tar->entry_offset = tar->sparse_list->offset;
@@ -1479,34 +1631,165 @@
 }
 
 static void
-gnu_parse_sparse_data(struct archive_read *a, struct tar *tar,
+gnu_sparse_old_parse(struct tar *tar,
     const struct gnu_sparse *sparse, int length)
 {
-	struct sparse_block *last;
-	struct sparse_block *p;
+	while (length > 0 && sparse->offset[0] != 0) {
+		gnu_add_sparse_entry(tar,
+		    tar_atol(sparse->offset, sizeof(sparse->offset)),
+		    tar_atol(sparse->numbytes, sizeof(sparse->numbytes)));
+		sparse++;
+		length--;
+	}
+}
+
+/*
+ * GNU tar sparse format 0.0
+ *
+ * Beginning with GNU tar 1.15, sparse files are stored using
+ * information in the pax extended header.  The GNU tar maintainers
+ * have gone through a number of variations in the process of working
+ * out this scheme; furtunately, they're all numbered.
+ *
+ * Sparse format 0.0 uses attribute GNU.sparse.numblocks to store the
+ * number of blocks, and GNU.sparse.offset/GNU.sparse.numbytes to
+ * store offset/size for each block.  The repeated instances of these
+ * latter fields violate the pax specification (which frowns on
+ * duplicate keys), so this format was quickly replaced.
+ */
+
+/*
+ * GNU tar sparse format 0.1
+ *
+ * This version replaced the offset/numbytes attributes with
+ * a single "map" attribute that stored a list of integers.  This
+ * format had two problems: First, the "map" attribute could be very
+ * long, which caused problems for some implementations.  More
+ * importantly, the sparse data was lost when extracted by archivers
+ * that didn't recognize this extension.
+ */
+
+static int
+gnu_sparse_01_parse(struct tar *tar, const wchar_t *p)
+{
+	const wchar_t *e;
+	off_t offset = -1, size = -1;
+
+	for (;;) {
+		e = p;
+		while (*e != '\0' && *e != ',') {
+			if (*e < '0' || *e > '9')
+				return (ARCHIVE_WARN);
+			e++;
+		}
+		if (offset < 0) {
+			offset = tar_atol10(p, e - p);
+			if (offset < 0)
+				return (ARCHIVE_WARN);
+		} else {
+			size = tar_atol10(p, e - p);
+			if (size < 0)
+				return (ARCHIVE_WARN);
+			gnu_add_sparse_entry(tar, offset, size);
+			offset = -1;
+		}
+		if (*e == '\0')
+			return (ARCHIVE_OK);
+		p = e + 1;
+	}
+}
+
+/*
+ * GNU tar sparse format 1.0
+ *
+ * The idea: The offset/size data is stored as a series of base-10
+ * ASCII numbers prepended to the file data, so that dearchivers that
+ * don't support this format will extract the block map along with the
+ * data and a separate post-process can restore the sparseness.
+ *
+ * Unfortunately, GNU tar 1.16 adds bogus padding to the end of the
+ * entry that depends on the size of the map; this means we have to
+ * parse the sparse map when we read the header (otherwise, entry_skip
+ * will fail).  This is why sparse_10_read is called from read_header
+ * above, instead of at the beginning of read_data, where it "should"
+ * go.
+ *
+ * This variant also replaced GNU.sparse.size with GNU.sparse.realsize
+ * and introduced the GNU.sparse.major/GNU.sparse.minor attributes.
+ */
+
+/*
+ * Read the next line from the input, and parse it as a decimal
+ * integer followed by '\n'.  Returns positive integer value or
+ * negative on error.
+ */
+static int64_t
+gnu_sparse_10_atol(struct archive_read *a, struct tar *tar,
+    ssize_t *total_read)
+{
+	int64_t l, limit, last_digit_limit;
+	const char *p;
+	ssize_t bytes_read;
+	int base, digit;
 
-	(void)a; /* UNUSED */
+	base = 10;
+	limit = INT64_MAX / base;
+	last_digit_limit = INT64_MAX % base;
 
-	last = tar->sparse_list;
-	while (last != NULL && last->next != NULL)
-		last = last->next;
+	bytes_read = readline(a, tar, &p);
+	if (bytes_read <= 0)
+		return (ARCHIVE_FATAL);
+	*total_read += bytes_read;
 
-	while (length > 0 && sparse->offset[0] != 0) {
-		p = (struct sparse_block *)malloc(sizeof(*p));
-		if (p == NULL)
-			__archive_errx(1, "Out of memory");
-		memset(p, 0, sizeof(*p));
-		if (last != NULL)
-			last->next = p;
+	l = 0;
+	while (bytes_read > 0) {
+		if (*p == '\n')
+			return (l);
+		if (*p < '0' || *p >= '0' + base)
+			return (ARCHIVE_WARN);
+		digit = *p - '0';
+		if (l > limit || (l == limit && digit > last_digit_limit))
+			l = UINT64_MAX; /* Truncate on overflow. */
 		else
-			tar->sparse_list = p;
-		last = p;
-		p->offset = tar_atol(sparse->offset, sizeof(sparse->offset));
-		p->remaining =
-		    tar_atol(sparse->numbytes, sizeof(sparse->numbytes));
-		sparse++;
-		length--;
+			l = (l * base) + digit;
+		p++;
+		bytes_read--;
+	}
+	/* TODO: Error message. */
+	return (ARCHIVE_WARN);
+}
+
+/*
+ * Returns number of bytes consumed to read the sparse block data.
+ */
+static ssize_t
+gnu_sparse_10_read(struct archive_read *a, struct tar *tar)
+{
+	ssize_t bytes_read = 0;
+	int entries;
+	off_t offset, size, to_skip;
+
+	/* Parse entries. */
+	entries = gnu_sparse_10_atol(a, tar, &bytes_read);
+	if (entries < 0)
+		return (ARCHIVE_FATAL);
+	/* Parse the individual entries. */
+	while (entries-- > 0) {
+		/* Parse offset/size */
+		offset = gnu_sparse_10_atol(a, tar, &bytes_read);
+		if (offset < 0)
+			return (ARCHIVE_FATAL);
+		size = gnu_sparse_10_atol(a, tar, &bytes_read);
+		if (size < 0)
+			return (ARCHIVE_FATAL);
+		/* Add a new sparse entry. */
+		gnu_add_sparse_entry(tar, offset, size);
 	}
+	/* Skip rest of block... */
+	to_skip = 0x1ff & -bytes_read;
+	if (to_skip != (a->decompressor->skip)(a, to_skip))
+		return (ARCHIVE_FATAL);
+	return (bytes_read + to_skip);
 }
 
 /*-
@@ -1574,7 +1857,6 @@
 	return (sign < 0) ? -l : l;
 }
 
-
 /*
  * Note that this implementation does not (and should not!) obey
  * locale settings; you cannot simply substitute strtol here, since
@@ -1647,6 +1929,55 @@
 	return (l);
 }
 
+/*
+ * Returns length of line (including trailing newline)
+ * or negative on error.  'start' argument is updated to
+ * point to first character of line.  This avoids copying
+ * when possible.
+ */
+static ssize_t
+readline(struct archive_read *a, struct tar *tar, const char **start)
+{
+	ssize_t bytes_read;
+	ssize_t total_size = 0;
+	const void *t;
+	const char *s;
+	void *p;
+
+	bytes_read = (a->decompressor->read_ahead)(a, &t, 1);
+	if (bytes_read <= 0)
+		return (ARCHIVE_FATAL);
+	s = t;  /* Start of line? */
+	p = memchr(t, '\n', bytes_read);
+	/* If we found '\n' in the read buffer, return pointer to that. */
+	if (p != NULL) {
+		bytes_read = 1 + ((const char *)p) - s;
+		(a->decompressor->consume)(a, bytes_read);
+		*start = s;
+		return (bytes_read);
+	}
+	/* Otherwise, we need to accumulate in a line buffer. */
+	for (;;) {
+		archive_string_ensure(&tar->line, total_size + bytes_read);
+		memcpy(tar->line.s + total_size, t, bytes_read);
+		(a->decompressor->consume)(a, bytes_read);
+		total_size += bytes_read;
+		/* Read some more. */
+		bytes_read = (a->decompressor->read_ahead)(a, &t, 1);
+		if (bytes_read <= 0)
+			return (ARCHIVE_FATAL);
+		s = t;  /* Start of line? */
+		p = memchr(t, '\n', bytes_read);
+		/* If we found '\n', finish the line. */
+		if (p != NULL) {
+			bytes_read = 1 + ((const char *)p) - s;
+			(a->decompressor->consume)(a, bytes_read);
+			*start = tar->line.s;
+			return (total_size + bytes_read);
+		}
+	}
+}
+
 static int
 utf8_decode(wchar_t *dest, const char *src, size_t length)
 {

==== //depot/projects/wifi/lib/libarchive/test/Makefile#6 (text+ko) ====

@@ -1,4 +1,4 @@
-# $FreeBSD: src/lib/libarchive/test/Makefile,v 1.5 2007/05/29 01:00:20 kientzle Exp $
+# $FreeBSD: src/lib/libarchive/test/Makefile,v 1.7 2007/06/13 03:35:37 kientzle Exp $
 
 TESTS= \
 	test_acl_basic.c			\
@@ -19,6 +19,7 @@
 	test_read_format_cpio_svr4c_Z.c		\
 	test_read_format_empty.c		\
 	test_read_format_gtar_gz.c		\
+	test_read_format_gtar_sparse.c		\
 	test_read_format_iso_gz.c		\
 	test_read_format_isorr_bz2.c		\
 	test_read_format_pax_bz2.c		\
@@ -48,7 +49,6 @@
 
 CLEANFILES+= list.h
 
-MK_MAN=no
 NO_MAN=yes
 
 PROG=libarchive_test
@@ -63,7 +63,7 @@
 #WARNS=6
 
 test:	libarchive_test
-	./libarchive_test
+	./libarchive_test -k
 
 list.h: ${TESTS} Makefile
 	(cd ${.CURDIR}; cat ${TESTS}) | grep DEFINE_TEST > list.h

==== //depot/projects/wifi/lib/libarchive/test/main.c#4 (text+ko) ====

@@ -32,7 +32,14 @@
 #include <time.h>
 
 #include "test.h"
-__FBSDID("$FreeBSD: src/lib/libarchive/test/main.c,v 1.3 2007/05/29 01:00:20 kientzle Exp $");
+__FBSDID("$FreeBSD: src/lib/libarchive/test/main.c,v 1.4 2007/06/13 03:30:46 kientzle Exp $");
+
+/* Default is to crash and try to force a core dump on failure. */
+static int dump_on_failure = 1;
+/* Default is to print some basic information about each test. */
+static int quiet_flag = 0;
+/* Cumulative count of failures. */
+static int failures = 0;
 
 /*
  * My own implementation of the standard assert() macro emits the
@@ -51,10 +58,13 @@
  */
 static char msg[4096];
 
+
 /* Common handling of failed tests. */
 static void
 test_failed(struct archive *a)
 {
+	failures ++;
+
 	if (msg[0] != '\0') {
 		fprintf(stderr, "   Description: %s\n", msg);
 		msg[0] = '\0';
@@ -63,9 +73,11 @@
 		fprintf(stderr, "   archive error: %s\n", archive_error_string(a));
 	}
 
-	fprintf(stderr, " *** forcing core dump so failure can be debugged ***\n");
-	*(char *)(NULL) = 0;
-	exit(1);
+	if (dump_on_failure) {
+		fprintf(stderr, " *** forcing core dump so failure can be debugged ***\n");
+		*(char *)(NULL) = 0;
+		exit(1);
+	}
 }
 
 /* Set up a message to display only after a test fails. */
@@ -160,9 +172,12 @@
 	#include "list.h"
 };
 
-static void test_run(int i, const char *tmpdir)
+static int test_run(int i, const char *tmpdir)
 {
-	printf("%d: %s\n", i, tests[i].name);
+	int failures_before = failures;
+
+	if (!quiet_flag)
+		printf("%d: %s\n", i, tests[i].name);
 	/*
 	 * Always explicitly chdir() in case the last test moved us to
 	 * a strange place.
@@ -187,6 +202,7 @@
 		exit(1);
 	}
 	(*tests[i].func)();
+	return (failures - failures_before);
 }
 
 static void usage(void)
@@ -194,9 +210,13 @@
 	static const int limit = sizeof(tests) / sizeof(tests[0]);
 	int i;
 
-	printf("Usage: libarchive_test <test> <test> ...\n");
+	printf("Usage: libarchive_test [options] <test> <test> ...\n");
 	printf("Default is to run all tests.\n");
 	printf("Otherwise, specify the numbers of the tests you wish to run.\n");
+	printf("Options:\n");
+	printf("  -k  Keep running after failures.\n");
+	printf("      Default: Core dump after any failure.\n");
+	printf("  -q  Quiet.\n");
 	printf("Available tests:\n");
 	for (i = 0; i < limit; i++)
 		printf("  %d: %s\n", i, tests[i].name);
@@ -206,10 +226,26 @@
 int main(int argc, char **argv)
 {
 	static const int limit = sizeof(tests) / sizeof(tests[0]);

>>> TRUNCATED FOR MAIL (1000 lines) <<<


More information about the p4-projects mailing list