From owner-p4-projects@FreeBSD.ORG Thu Jun 3 12:41:55 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 3DA9D16A4D0; Thu, 3 Jun 2004 12:41:55 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1185A16A4CE for ; Thu, 3 Jun 2004 12:41:55 -0700 (PDT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0414F43D1D for ; Thu, 3 Jun 2004 12:41:55 -0700 (PDT) (envelope-from peter@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.11/8.12.11) with ESMTP id i53Jfsr0001153 for ; Thu, 3 Jun 2004 12:41:54 -0700 (PDT) (envelope-from peter@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.11/8.12.11/Submit) id i53JfjPS001010 for perforce@freebsd.org; Thu, 3 Jun 2004 12:41:45 -0700 (PDT) (envelope-from peter@freebsd.org) Date: Thu, 3 Jun 2004 12:41:45 -0700 (PDT) Message-Id: <200406031941.i53JfjPS001010@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to peter@freebsd.org using -f From: Peter Wemm To: Perforce Change Reviews Subject: PERFORCE change 54095 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jun 2004 19:41:56 -0000 http://perforce.freebsd.org/chv.cgi?CH=54095 Change 54095 by peter@peter_daintree on 2004/06/03 12:41:36 IFC @54094 Affected files ... .. //depot/projects/hammer/bin/ls/ls.c#11 integrate .. //depot/projects/hammer/bin/ps/ps.c#13 integrate .. //depot/projects/hammer/etc/defaults/rc.conf#28 integrate .. //depot/projects/hammer/etc/rc.d/ip6addrctl#3 integrate .. //depot/projects/hammer/lib/libarchive/Makefile#9 integrate .. //depot/projects/hammer/lib/libarchive/archive.h#9 integrate .. //depot/projects/hammer/lib/libarchive/archive_private.h#10 integrate .. //depot/projects/hammer/lib/libarchive/archive_read.3#6 integrate .. //depot/projects/hammer/lib/libarchive/archive_read.c#7 integrate .. //depot/projects/hammer/lib/libarchive/archive_read_data_into_fd.c#6 integrate .. //depot/projects/hammer/lib/libarchive/archive_read_support_format_cpio.c#8 integrate .. //depot/projects/hammer/lib/libarchive/archive_read_support_format_tar.c#12 integrate .. //depot/projects/hammer/lib/libc/gen/dlopen.3#4 integrate .. //depot/projects/hammer/lib/libc/net/name6.c#11 integrate .. //depot/projects/hammer/lib/libncp/ncpl_subr.c#6 integrate .. //depot/projects/hammer/lib/libusbhid/usbhid.h#4 integrate .. //depot/projects/hammer/lib/msun/src/e_atan2f.c#2 integrate .. //depot/projects/hammer/lib/msun/src/k_tan.c#3 integrate .. //depot/projects/hammer/lib/msun/src/k_tanf.c#2 integrate .. //depot/projects/hammer/release/alpha/mkisoimages.sh#2 integrate .. //depot/projects/hammer/release/amd64/mkisoimages.sh#3 integrate .. //depot/projects/hammer/release/i386/mkisoimages.sh#3 integrate .. //depot/projects/hammer/release/ia64/mkisoimages.sh#3 integrate .. //depot/projects/hammer/release/sparc64/mkisoimages.sh#4 integrate .. //depot/projects/hammer/sbin/devfs/extern.h#2 integrate .. //depot/projects/hammer/sbin/ggate/ggated/ggated.c#2 integrate .. //depot/projects/hammer/sbin/ipfw/ipfw2.c#24 integrate .. //depot/projects/hammer/sbin/sunlabel/sunlabel.8#4 integrate .. //depot/projects/hammer/share/man/man7/ports.7#8 integrate .. //depot/projects/hammer/sys/alpha/alpha/mem.c#9 integrate .. //depot/projects/hammer/sys/alpha/alpha/uio_machdep.c#3 integrate .. //depot/projects/hammer/sys/amd64/amd64/legacy.c#12 integrate .. //depot/projects/hammer/sys/amd64/amd64/mem.c#20 integrate .. //depot/projects/hammer/sys/amd64/amd64/trap.c#46 integrate .. //depot/projects/hammer/sys/amd64/amd64/uio_machdep.c#3 integrate .. //depot/projects/hammer/sys/amd64/isa/atpic.c#42 integrate .. //depot/projects/hammer/sys/amd64/isa/clock.c#25 integrate .. //depot/projects/hammer/sys/amd64/pci/pci_bus.c#21 integrate .. //depot/projects/hammer/sys/arm/arm/uio_machdep.c#2 integrate .. //depot/projects/hammer/sys/boot/i386/boot2/boot1.S#4 integrate .. //depot/projects/hammer/sys/compat/ndis/kern_ndis.c#16 integrate .. //depot/projects/hammer/sys/dev/aac/aac.c#22 integrate .. //depot/projects/hammer/sys/dev/aac/aac_cam.c#8 integrate .. //depot/projects/hammer/sys/dev/aac/aac_disk.c#9 integrate .. //depot/projects/hammer/sys/dev/aac/aacvar.h#10 integrate .. //depot/projects/hammer/sys/dev/adlink/adlink.c#8 integrate .. //depot/projects/hammer/sys/dev/arl/if_arl.c#6 integrate .. //depot/projects/hammer/sys/dev/ata/ata-cbus.c#7 integrate .. //depot/projects/hammer/sys/dev/fb/tga.c#3 integrate .. //depot/projects/hammer/sys/dev/fxp/if_fxp.c#32 integrate .. //depot/projects/hammer/sys/dev/fxp/if_fxpvar.h#10 integrate .. //depot/projects/hammer/sys/dev/gem/if_gem.c#12 integrate .. //depot/projects/hammer/sys/dev/gem/if_gem_pci.c#9 integrate .. //depot/projects/hammer/sys/dev/hme/if_hme.c#10 integrate .. //depot/projects/hammer/sys/dev/hme/if_hme_pci.c#7 integrate .. //depot/projects/hammer/sys/dev/hme/if_hme_sbus.c#7 integrate .. //depot/projects/hammer/sys/dev/if_ndis/if_ndis_pccard.c#5 integrate .. //depot/projects/hammer/sys/dev/if_ndis/if_ndis_pci.c#5 integrate .. //depot/projects/hammer/sys/dev/isp/isp_sbus.c#8 integrate .. //depot/projects/hammer/sys/dev/ixgb/if_ixgb.h#2 integrate .. //depot/projects/hammer/sys/dev/lnc/if_lnc_cbus.c#7 integrate .. //depot/projects/hammer/sys/dev/nmdm/nmdm.c#10 integrate .. //depot/projects/hammer/sys/dev/puc/puc_ebus.c#2 integrate .. //depot/projects/hammer/sys/dev/puc/puc_sbus.c#3 integrate .. //depot/projects/hammer/sys/dev/sab/sab.c#11 integrate .. //depot/projects/hammer/sys/dev/tga/tga_pci.c#6 integrate .. //depot/projects/hammer/sys/dev/uart/uart_bus_ebus.c#4 integrate .. //depot/projects/hammer/sys/dev/zs/zs_sbus.c#4 integrate .. //depot/projects/hammer/sys/i386/i386/trap.c#25 integrate .. //depot/projects/hammer/sys/i386/i386/uio_machdep.c#4 integrate .. //depot/projects/hammer/sys/ia64/ia64/mem.c#9 integrate .. //depot/projects/hammer/sys/ia64/ia64/uio_machdep.c#3 integrate .. //depot/projects/hammer/sys/kern/kern_clock.c#17 integrate .. //depot/projects/hammer/sys/kern/kern_exec.c#28 integrate .. //depot/projects/hammer/sys/kern/kern_exit.c#27 integrate .. //depot/projects/hammer/sys/kern/kern_lock.c#8 integrate .. //depot/projects/hammer/sys/kern/kern_sig.c#40 integrate .. //depot/projects/hammer/sys/kern/kern_subr.c#12 integrate .. //depot/projects/hammer/sys/kern/kern_thread.c#49 integrate .. //depot/projects/hammer/sys/kern/sched_ule.c#31 integrate .. //depot/projects/hammer/sys/kern/subr_bus.c#18 integrate .. //depot/projects/hammer/sys/kern/subr_witness.c#27 integrate .. //depot/projects/hammer/sys/kern/uipc_socket.c#23 integrate .. //depot/projects/hammer/sys/kern/uipc_socket2.c#17 integrate .. //depot/projects/hammer/sys/kern/uipc_syscalls.c#25 integrate .. //depot/projects/hammer/sys/kern/vfs_vnops.c#16 integrate .. //depot/projects/hammer/sys/net/ethernet.h#4 integrate .. //depot/projects/hammer/sys/net/if_ethersubr.c#27 integrate .. //depot/projects/hammer/sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c#7 integrate .. //depot/projects/hammer/sys/netgraph/ng_ksocket.c#9 integrate .. //depot/projects/hammer/sys/netinet/raw_ip.c#20 integrate .. //depot/projects/hammer/sys/netinet6/ip6_input.c#13 integrate .. //depot/projects/hammer/sys/pc98/pc98/pmc.c#2 integrate .. //depot/projects/hammer/sys/powerpc/powerpc/uio_machdep.c#3 integrate .. //depot/projects/hammer/sys/sparc64/central/central.c#2 integrate .. //depot/projects/hammer/sys/sparc64/ebus/ebus.c#10 integrate .. //depot/projects/hammer/sys/sparc64/fhc/fhc_central.c#2 integrate .. //depot/projects/hammer/sys/sparc64/fhc/fhc_nexus.c#2 integrate .. //depot/projects/hammer/sys/sparc64/pci/apb.c#6 integrate .. //depot/projects/hammer/sys/sparc64/sparc64/mem.c#8 integrate .. //depot/projects/hammer/sys/sparc64/sparc64/uio_machdep.c#4 integrate .. //depot/projects/hammer/sys/sys/proc.h#51 integrate .. //depot/projects/hammer/sys/sys/socketvar.h#14 integrate .. //depot/projects/hammer/sys/ufs/ffs/ffs_rawread.c#9 integrate .. //depot/projects/hammer/usr.bin/calendar/calendars/calendar.freebsd#19 integrate .. //depot/projects/hammer/usr.bin/du/du.1#3 integrate .. //depot/projects/hammer/usr.bin/du/du.c#7 integrate .. //depot/projects/hammer/usr.bin/netstat/inet.c#10 integrate .. //depot/projects/hammer/usr.bin/tar/bsdtar.c#8 integrate .. //depot/projects/hammer/usr.bin/tar/matching.c#4 integrate .. //depot/projects/hammer/usr.sbin/daemon/daemon.8#3 integrate .. //depot/projects/hammer/usr.sbin/daemon/daemon.c#3 integrate .. //depot/projects/hammer/usr.sbin/newsyslog/newsyslog.c#12 integrate Differences ... ==== //depot/projects/hammer/bin/ls/ls.c#11 (text+ko) ==== @@ -42,7 +42,7 @@ #endif /* not lint */ #endif #include -__FBSDID("$FreeBSD: src/bin/ls/ls.c,v 1.76 2004/04/06 20:06:47 markm Exp $"); +__FBSDID("$FreeBSD: src/bin/ls/ls.c,v 1.77 2004/06/03 15:04:00 le Exp $"); #include #include @@ -621,6 +621,7 @@ MAKENINES(maxblock); MAKENINES(maxnlink); MAKENINES(maxsize); + free(jinitmax); } bcfile = 0; flags = NULL; ==== //depot/projects/hammer/bin/ps/ps.c#13 (text+ko) ==== @@ -47,7 +47,7 @@ #endif #include -__FBSDID("$FreeBSD: src/bin/ps/ps.c,v 1.96 2004/06/01 19:00:42 gad Exp $"); +__FBSDID("$FreeBSD: src/bin/ps/ps.c,v 1.98 2004/06/01 23:27:11 gad Exp $"); #include #include @@ -85,10 +85,10 @@ #endif /* - * isdigit is defined to work on an 'int', in the range 0 to 255, plus EOF. - * Define a wrapper which can take 'char', either signed or unsigned. + * isdigit takes an `int', but expects values in the range of unsigned char. + * This wrapper ensures that values from a 'char' end up in the correct range. */ -#define isdigitch(Anychar) isdigit(((int) Anychar) & 255) +#define isdigitch(Anychar) isdigit((u_char)(Anychar)) int cflag; /* -c */ int eval; /* Exit value */ @@ -207,7 +207,7 @@ init_list(&uidlist, addelem_uid, sizeof(uid_t), "user"); memf = nlistf = _PATH_DEVNULL; while ((ch = getopt(argc, argv, PS_ARGS)) != -1) - switch((char)ch) { + switch ((char)ch) { case 'A': /* * Exactly the same as `-ax'. This has been @@ -427,10 +427,8 @@ * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. */ - if (dropgid) { + if (dropgid) setgid(getgid()); - setuid(getuid()); - } kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf); if (kd == 0) @@ -658,9 +656,8 @@ if (grp == NULL) { warnx("No %s %s '%s'", inf->lname, nameorID, elem); optfatal = 1; - return (0); /* Do not add this value. */ + return (0); } - if (inf->count >= inf->maxcount) expand_list(inf); inf->l.gids[(inf->count)++] = grp->gr_gid; @@ -691,9 +688,8 @@ } if (errno == ERANGE) { optfatal = 1; - return (0); /* Do not add this value. */ + return (0); } - if (inf->count >= inf->maxcount) expand_list(inf); inf->l.pids[(inf->count)++] = tempid; @@ -721,14 +717,13 @@ if (stat(ttypath, &sb) == -1) { warn("%s", ttypath); optfatal = 1; - return (0); /* Do not add this value. */ + return (0); } if (!S_ISCHR(sb.st_mode)) { warn("%s: Not a terminal", ttypath); optfatal = 1; - return (0); /* Do not add this value. */ + return (0); } - if (inf->count >= inf->maxcount) expand_list(inf); inf->l.ttys[(inf->count)++] = sb.st_rdev; @@ -772,9 +767,8 @@ * errors (and the command will be aborted). */ optfatal = 1; - return (0); /* Do not add this value. */ + return (0); } - if (inf->count >= inf->maxcount) expand_list(inf); inf->l.uids[(inf->count)++] = pwd->pw_uid; @@ -790,7 +784,7 @@ char elemcopy[PATH_MAX]; if (*argp == 0) - inf->addelem(inf, elemcopy); + inf->addelem(inf, elemcopy); while (*argp != '\0') { while (*argp != '\0' && strchr(W_SEP, *argp) != NULL) argp++; @@ -849,8 +843,7 @@ newlist = realloc(inf->l.ptr, newmax * inf->elemsize); if (newlist == NULL) { free(inf->l.ptr); - errx(1, "realloc to %d %ss failed", newmax, - inf->lname); + errx(1, "realloc to %d %ss failed", newmax, inf->lname); } inf->maxcount = newmax; inf->l.ptr = newlist; ==== //depot/projects/hammer/etc/defaults/rc.conf#28 (text+ko) ==== @@ -13,7 +13,7 @@ # # All arguments must be in double or single quotes. # -# $FreeBSD: src/etc/defaults/rc.conf,v 1.206 2004/05/29 04:52:37 njl Exp $ +# $FreeBSD: src/etc/defaults/rc.conf,v 1.208 2004/06/02 09:58:18 ume Exp $ ############################################################## ### Important initial Boot-time options #################### @@ -340,6 +340,8 @@ ipv6_ipfilter_rules="/etc/ipf6.rules" # rules definition file for ipfilter, # see /usr/src/contrib/ipfilter/rules # for examples +ip6addrctl_enable="NO" # Set to YES to enable default address selection +ip6addrctl_verbose="NO" # Set to YES to enable verbose configuration messages ############################################################## ### System console options ################################# ==== //depot/projects/hammer/etc/rc.d/ip6addrctl#3 (text+ko) ==== @@ -1,6 +1,6 @@ #!/bin/sh # -# $FreeBSD: src/etc/rc.d/ip6addrctl,v 1.2 2004/03/08 12:25:05 pjd Exp $ +# $FreeBSD: src/etc/rc.d/ip6addrctl,v 1.3 2004/06/02 09:39:49 ume Exp $ # # PROVIDE: ip6addrctl @@ -9,11 +9,37 @@ # KEYWORD: FreeBSD nojail . /etc/rc.subr -. /etc/network.subr name="ip6addrctl" +rcvar=`set_rcvar` start_cmd="ip6addrctl_start" -stop_cmd=':' +stop_cmd="ip6addrctl_stop" +extra_commands="status prefer_ipv6 prefer_ipv4" +status_cmd="ip6addrctl" +prefer_ipv6_cmd="ip6addrctl_prefer_ipv6" +prefer_ipv4_cmd="ip6addrctl_prefer_ipv4" + +ip6addrctl_prefer_ipv6() +{ + ip6addrctl flush >/dev/null 2>&1 + ip6addrctl add ::1/128 50 0 + ip6addrctl add ::/0 40 1 + ip6addrctl add 2002::/16 30 2 + ip6addrctl add ::/96 20 3 + ip6addrctl add ::ffff:0:0/96 10 4 + checkyesno ip6addrctl_verbose && ip6addrctl +} + +ip6addrctl_prefer_ipv4() +{ + ip6addrctl flush >/dev/null 2>&1 + ip6addrctl add ::ffff:0:0/96 50 0 + ip6addrctl add ::1/128 40 1 + ip6addrctl add ::/0 30 2 + ip6addrctl add 2002::/16 20 3 + ip6addrctl add ::/96 10 4 + checkyesno ip6addrctl_verbose && ip6addrctl +} ip6addrctl_start() { @@ -24,10 +50,24 @@ if [ -f /etc/ip6addrctl.conf ]; then ip6addrctl flush >/dev/null 2>&1 ip6addrctl install /etc/ip6addrctl.conf - ip6addrctl + checkyesno ip6addrctl_verbose && ip6addrctl + else + if checkyesno ipv6_enable; then + ip6addrctl_prefer_ipv6 + else + ip6addrctl_prefer_ipv4 + fi fi fi } +ip6addrctl_stop() +{ + if ifconfig lo0 inet6 >/dev/null 2>&1; then + # We have IPv6 support in kernel. + ip6addrctl flush >/dev/null 2>&1 + fi +} + load_rc_config $name run_rc_command "$1" ==== //depot/projects/hammer/lib/libarchive/Makefile#9 (text+ko) ==== @@ -1,10 +1,10 @@ -# $FreeBSD: src/lib/libarchive/Makefile,v 1.11 2004/05/27 23:57:45 kientzle Exp $ +# $FreeBSD: src/lib/libarchive/Makefile,v 1.12 2004/06/02 08:16:21 kientzle Exp $ LIB= archive SHLIB_MAJOR= 1 .if ${MACHINE_ARCH} == "arm" -WARNS?= 3 +WARNS?= 3 .else WARNS?= 6 .endif @@ -92,8 +92,9 @@ MLINKS+= archive_entry.3 archive_entry_uname.3 MLINKS+= archive_entry.3 archive_entry_uname_w.3 MLINKS+= archive_read.3 archive_read_data.3 +MLINKS+= archive_read.3 archive_read_data_block.3 MLINKS+= archive_read.3 archive_read_data_into_buffer.3 -MLINKS+= archive_read.3 archive_read_data_into_file.3 +MLINKS+= archive_read.3 archive_read_data_into_fd.3 MLINKS+= archive_read.3 archive_read_data_skip.3 MLINKS+= archive_read.3 archive_read_extract.3 MLINKS+= archive_read.3 archive_read_extract_set_progress_callback.3 ==== //depot/projects/hammer/lib/libarchive/archive.h#9 (text+ko) ==== @@ -23,7 +23,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/lib/libarchive/archive.h,v 1.10 2004/05/27 04:00:25 kientzle Exp $ + * $FreeBSD: src/lib/libarchive/archive.h,v 1.11 2004/06/02 08:14:43 kientzle Exp $ */ #ifndef ARCHIVE_H_INCLUDED @@ -166,6 +166,14 @@ /* Read data from the body of an entry. Similar to read(2). */ ssize_t archive_read_data(struct archive *, void *, size_t); +/* + * A zero-copy version of archive_read_data that also exposes the file offset + * of each returned block. Note that the client has no way to specify + * the desired size of the block. The API does gaurantee that offsets will + * be strictly increasing and that returned blocks will not overlap. + */ +int archive_read_data_block(struct archive *a, + const void **buff, size_t *size, off_t *offset); /*- * Some convenience functions that are built on archive_read_data: ==== //depot/projects/hammer/lib/libarchive/archive_private.h#10 (text+ko) ==== @@ -23,7 +23,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/lib/libarchive/archive_private.h,v 1.10 2004/05/27 05:02:35 kientzle Exp $ + * $FreeBSD: src/lib/libarchive/archive_private.h,v 1.11 2004/06/02 08:14:43 kientzle Exp $ */ #ifndef ARCHIVE_PRIVATE_H_INCLUDED @@ -54,12 +54,13 @@ size_t null_length; /* - * Used to limit reads of entry data. Eventually, each reader - * will be able to register it's own read_data routine and these - * will move into the per-format data for the formats that use them. + * Used by archive_read_data() to track blocks and copy + * data to client buffers, filling gaps with zero bytes. */ - off_t entry_bytes_remaining; - off_t entry_padding; /* Skip this much after entry data. */ + const char *read_data_block; + off_t read_data_offset; + off_t read_data_output_offset; + size_t read_data_remaining; uid_t user_uid; /* UID of current user. */ @@ -151,6 +152,7 @@ struct archive_format_descriptor { int (*bid)(struct archive *); int (*read_header)(struct archive *, struct archive_entry *); + int (*read_data)(struct archive *, const void **, size_t *, off_t *); int (*cleanup)(struct archive *); void *format_data; /* Format-specific data for readers. */ } formats[4]; @@ -168,9 +170,8 @@ void *format_data; /* Used by writers. */ /* - * Pointers to format-specific functions. On read, these are - * initialized in the bid process. On write, they're initialized by - * archive_write_set_format_XXX() calls. + * Pointers to format-specific functions for writing. They're + * initialized by archive_write_set_format_XXX() calls. */ int (*format_init)(struct archive *); /* Only used on write. */ int (*format_finish)(struct archive *); @@ -220,6 +221,7 @@ void *format_data, int (*bid)(struct archive *), int (*read_header)(struct archive *, struct archive_entry *), + int (*read_data)(struct archive *, const void **, size_t *, off_t *), int (*cleanup)(struct archive *)); int __archive_read_register_compression(struct archive *a, ==== //depot/projects/hammer/lib/libarchive/archive_read.3#6 (text+ko) ==== @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libarchive/archive_read.3,v 1.5 2004/05/27 04:21:52 kientzle Exp $ +.\" $FreeBSD: src/lib/libarchive/archive_read.3,v 1.6 2004/06/02 08:14:43 kientzle Exp $ .\" .Dd October 1, 2003 .Dt archive_read 3 @@ -43,9 +43,10 @@ .Nm archive_read_open_file , .Nm archive_read_next_header , .Nm archive_read_data , +.Nm archive_read_data_block , .Nm archive_read_data_skip , .Nm archive_read_data_into_buffer , -.Nm archive_read_data_into_file , +.Nm archive_read_data_into_fd , .Nm archive_read_extract , .Nm archive_read_extract_set_progress_callback , .Nm archive_read_finish @@ -83,11 +84,13 @@ .Ft ssize_t .Fn archive_read_data "struct archive *" "void *buff" "size_t len" .Ft int +.Fn archive_read_data_block "struct archive *" "const void **buff" "size_t *len" "off_t *offset" +.Ft int .Fn archive_read_data_skip "struct archive *" .Ft int .Fn archive_read_data_into_buffer "struct archive *" "void *" .Ft int -.Fn archive_read_data_into_file "struct archive *" "int fd" +.Fn archive_read_data_into_fd "struct archive *" "int fd" .Ft int .Fn archive_read_extract "struct archive *" "int flags" .Ft void @@ -165,18 +168,30 @@ .Tn struct archive_entry . .It Fn archive_read_data Read data associated with the header just read. +Internally, this is a convenience function that uses +.Fn archive_read_data_block . +.It Fn archive_read_data_block +Return the next available block of data for this entry. +Unlike +.Fn archive_read_data , +the +.Fn archive_read_data_block +function avoids copying data and allows you to correctly handle +sparse files, as supported by some archive formats. +The library gaurantees that offsets will increase and that blocks +will not overlap. .It Fn archive_read_data_skip A convenience function that repeatedly calls -.Fn archive_read_data +.Fn archive_read_data_block to skip all of the data for this archive entry. .It Fn archive_read_data_into_buffer A convenience function that repeatedly calls -.Fn archive_read_data +.Fn archive_read_data_block to copy the entire entry into the client-supplied buffer. Note that the client is responsible for sizing the buffer appropriately. -.It Fn archive_read_data_into_file +.It Fn archive_read_data_into_fd A convenience function that repeatedly calls -.Fn archive_read_data +.Fn archive_read_data_block to copy the entire entry to the provided file descriptor. .It Fn archive_read_extract A convenience function that recreates the specified object on ==== //depot/projects/hammer/lib/libarchive/archive_read.c#7 (text+ko) ==== @@ -33,7 +33,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read.c,v 1.6 2004/04/13 23:45:37 kientzle Exp $"); +__FBSDID("$FreeBSD: src/lib/libarchive/archive_read.c,v 1.7 2004/06/02 08:14:43 kientzle Exp $"); #include #include @@ -319,42 +319,61 @@ } /* - * Read data from an archive entry. + * Read data from an archive entry, using a read(2)-style interface. + * This is a convenience routine that just calls + * archive_read_data_block and copies the results into the client + * buffer, filling any gaps with zero bytes. Clients using this + * API can be completely ignorant of sparse-file issues; sparse files + * will simply be padded with nulls. */ ssize_t archive_read_data(struct archive *a, void *buff, size_t s) { - const void *data; - ssize_t bytes_read; + off_t remaining; + char *dest; + size_t bytes_read; + size_t len; + int r; + + bytes_read = 0; + dest = buff; - archive_check_magic(a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA); - /* - * off_t is generally at least as wide as size_t, so widen for - * comparison and narrow for the assignment. Otherwise, on - * platforms with 32-bit size_t and 64-bit off_t, we won't be - * able to correctly read archives with entries larger than - * 4gig. - */ - if ((off_t)s > a->entry_bytes_remaining) - s = (size_t)a->entry_bytes_remaining; - if (s > 0) { - bytes_read = (a->compression_read_ahead)(a, &data, 1); - if (bytes_read < 0) { - a->state = ARCHIVE_STATE_FATAL; - return (bytes_read); + while (s > 0) { + if (a->read_data_remaining <= 0) { + r = archive_read_data_block(a, + (const void **)&a->read_data_block, + &a->read_data_remaining, + &a->read_data_offset); + if (r == ARCHIVE_EOF) + return (bytes_read); + if (r != ARCHIVE_OK) + return (r); } - if ((size_t)bytes_read > s) - bytes_read = s; - } else - bytes_read = 0; - if (bytes_read > 0) { - memcpy(buff, data, bytes_read); - (a->compression_read_consume)(a, bytes_read); + if (a->read_data_offset < a->read_data_output_offset) { + remaining = + a->read_data_output_offset - a->read_data_offset; + if (remaining > (off_t)s) + remaining = (off_t)s; + len = (size_t)remaining; + memset(dest, 0, len); + a->read_data_output_offset += len; + s -= len; + bytes_read += len; + } else { + len = a->read_data_remaining; + if (len > s) + len = s; + memcpy(dest, a->read_data_block, len); + s -= len; + a->read_data_remaining -= len; + a->read_data_output_offset += len; + a->read_data_offset += len; + dest += len; + bytes_read += len; + } } - - a->entry_bytes_remaining -= bytes_read; - return (bytes_read); + return (ARCHIVE_OK); } /* @@ -363,33 +382,46 @@ int archive_read_data_skip(struct archive *a) { + int r; const void *buff; - ssize_t bytes_read, to_skip; + ssize_t size; + off_t offset; archive_check_magic(a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA); - to_skip = a->entry_bytes_remaining + a->entry_padding; - a->entry_bytes_remaining = 0; + while ((r = archive_read_data_block(a, &buff, &size, &offset)) == + ARCHIVE_OK) + ; + + if (r == ARCHIVE_EOF) + r = ARCHIVE_OK; + + a->state = ARCHIVE_STATE_HEADER; + return (r); +} + +/* + * Read the next block of entry data from the archive. + * This is a zero-copy interface; the client receives a pointer, + * size, and file offset of the next available block of data. + * + * Returns ARCHIVE_OK if the operation is successful, ARCHIVE_EOF if + * the end of entry is encountered. + */ +int +archive_read_data_block(struct archive *a, + const void **buff, size_t *size, off_t *offset) +{ + archive_check_magic(a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA); - for (; to_skip > 0; to_skip -= bytes_read) { - /* TODO: Optimize skip in compression layer. */ - bytes_read = (a->compression_read_ahead)(a, &buff, to_skip); - if (bytes_read < 0) { - a->entry_padding = to_skip; - return (ARCHIVE_FATAL); - } - if (bytes_read == 0) { - archive_set_error(a, EIO, - "Premature end of archive entry"); - return (ARCHIVE_FATAL); - } - if (bytes_read > to_skip) - bytes_read = to_skip; - (a->compression_read_consume)(a, bytes_read); + if (a->format->read_data == NULL) { + archive_set_error(a, ARCHIVE_ERRNO_PROGRAMMER, + "Internal error: " + "No format_read_data_block function registered"); + return (ARCHIVE_FATAL); } - a->entry_padding = 0; - a->state = ARCHIVE_STATE_HEADER; - return (ARCHIVE_OK); + + return (a->format->read_data)(a, buff, size, offset); } /* @@ -445,6 +477,7 @@ void *format_data, int (*bid)(struct archive *), int (*read_header)(struct archive *, struct archive_entry *), + int (*read_data)(struct archive *, const void **, size_t *, off_t *), int (*cleanup)(struct archive *)) { int i, number_slots; @@ -459,6 +492,7 @@ if (a->formats[i].bid == NULL) { a->formats[i].bid = bid; a->formats[i].read_header = read_header; + a->formats[i].read_data = read_data; a->formats[i].cleanup = cleanup; a->formats[i].format_data = format_data; return (ARCHIVE_OK); ==== //depot/projects/hammer/lib/libarchive/archive_read_data_into_fd.c#6 (text+ko) ==== @@ -25,7 +25,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_data_into_fd.c,v 1.5 2004/05/13 06:01:14 kientzle Exp $"); +__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_data_into_fd.c,v 1.6 2004/06/02 08:14:43 kientzle Exp $"); #include #include @@ -33,36 +33,49 @@ #include "archive.h" #include "archive_private.h" +/* Maximum amount of data to write at one time. */ +#define MAX_WRITE (1024 * 1024) + /* - * This implementation minimizes copying of data. + * This implementation minimizes copying of data and is sparse-file aware. */ ssize_t archive_read_data_into_fd(struct archive *a, int fd) { - ssize_t bytes_read, bytes_written, total_written; + int r; const void *buff; + ssize_t size, bytes_to_write; + ssize_t bytes_written, total_written; + off_t offset; + off_t output_offset; + + archive_check_magic(a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA); total_written = 0; - while (a->entry_bytes_remaining > 0) { - /* Remember: '1' here is minimum, not maximum. */ - /* Read-ahead function will return as much as is convenient. */ - bytes_read = (a->compression_read_ahead)(a, &buff, 1); - if (bytes_read < 0) - return (-1); - if (bytes_read > a->entry_bytes_remaining) - bytes_read = (ssize_t)a->entry_bytes_remaining; - /* Don't copy more than 1 megabyte at a time. */ - if (bytes_read > (1024*1024)) - bytes_read = 1024*1024; + output_offset = 0; - bytes_written = write(fd, buff, bytes_read); - if (bytes_written < 0) - return (-1); - (a->compression_read_consume)(a, bytes_written); - total_written += bytes_written; - a->entry_bytes_remaining -= bytes_written; - if (a->extract_progress != NULL) - (*a->extract_progress)(a->extract_progress_user_data); + while ((r = archive_read_data_block(a, &buff, &size, &offset)) == + ARCHIVE_OK) { + if (offset > output_offset) { + lseek(fd, offset - output_offset, SEEK_CUR); + output_offset = offset; + } + while (size > 0) { + bytes_to_write = size; + if (bytes_to_write > MAX_WRITE) + bytes_to_write = MAX_WRITE; + bytes_written = write(fd, buff, bytes_to_write); + if (bytes_written < 0) + return (-1); + output_offset += bytes_written; + total_written += bytes_written; + size -= bytes_written; + if (a->extract_progress != NULL) + (*a->extract_progress)(a->extract_progress_user_data); + } } + + if (r != ARCHIVE_EOF) + return (-1); return (total_written); } ==== //depot/projects/hammer/lib/libarchive/archive_read_support_format_cpio.c#8 (text+ko) ==== @@ -25,7 +25,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_cpio.c,v 1.9 2004/05/03 01:40:34 kientzle Exp $"); +__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_cpio.c,v 1.10 2004/06/02 08:14:43 kientzle Exp $"); #include @@ -97,27 +97,32 @@ #define CPIO_MAGIC 0x13141516 struct cpio { int magic; - int (*read_header)(struct archive *, struct stat *, - size_t *, size_t *); + int (*read_header)(struct archive *, struct cpio *, + struct stat *, size_t *, size_t *); struct links_entry *links_head; struct archive_string entry_name; struct archive_string entry_linkname; + off_t entry_bytes_remaining; + off_t entry_offset; + off_t entry_padding; }; static int64_t atol16(const char *, unsigned); static int64_t atol8(const char *, unsigned); static int archive_read_format_cpio_bid(struct archive *); static int archive_read_format_cpio_cleanup(struct archive *); +static int archive_read_format_cpio_read_data(struct archive *, + const void **, size_t *, off_t *); static int archive_read_format_cpio_read_header(struct archive *, struct archive_entry *); static int be4(const unsigned char *); -static int header_bin_be(struct archive *, struct stat *, +static int header_bin_be(struct archive *, struct cpio *, struct stat *, size_t *, size_t *); -static int header_bin_le(struct archive *, struct stat *, +static int header_bin_le(struct archive *, struct cpio *, struct stat *, size_t *, size_t *); -static int header_newc(struct archive *, struct stat *, +static int header_newc(struct archive *, struct cpio *, struct stat *, size_t *, size_t *); -static int header_odc(struct archive *, struct stat *, +static int header_odc(struct archive *, struct cpio *, struct stat *, size_t *, size_t *); static int le4(const unsigned char *); static void record_hardlink(struct cpio *cpio, struct archive_entry *entry, @@ -137,6 +142,7 @@ cpio, archive_read_format_cpio_bid, archive_read_format_cpio_read_header, + archive_read_format_cpio_read_data, archive_read_format_cpio_cleanup); if (r != ARCHIVE_OK) @@ -216,7 +222,7 @@ memset(&st, 0, sizeof(st)); cpio = *(a->pformat_data); - r = (cpio->read_header(a, &st, &namelength, &name_pad)); + r = (cpio->read_header(a, cpio, &st, &namelength, &name_pad)); if (r != ARCHIVE_OK) return (r); @@ -231,18 +237,19 @@ (a->compression_read_consume)(a, namelength + name_pad); archive_strncpy(&cpio->entry_name, h, namelength); archive_entry_set_pathname(entry, cpio->entry_name.s); + cpio->entry_offset = 0; /* If this is a symlink, read the link contents. */ if (S_ISLNK(st.st_mode)) { bytes = (a->compression_read_ahead)(a, &h, - a->entry_bytes_remaining); - if ((off_t)bytes < a->entry_bytes_remaining) + cpio->entry_bytes_remaining); + if ((off_t)bytes < cpio->entry_bytes_remaining) return (ARCHIVE_FATAL); - (a->compression_read_consume)(a, a->entry_bytes_remaining); + (a->compression_read_consume)(a, cpio->entry_bytes_remaining); archive_strncpy(&cpio->entry_linkname, h, - a->entry_bytes_remaining); + cpio->entry_bytes_remaining); archive_entry_set_symlink(entry, cpio->entry_linkname.s); - a->entry_bytes_remaining = 0; + cpio->entry_bytes_remaining = 0; } /* Compare name to "TRAILER!!!" to test for end-of-archive. */ @@ -259,7 +266,44 @@ } static int -header_newc(struct archive *a, struct stat *st, +archive_read_format_cpio_read_data(struct archive *a, + const void **buff, size_t *size, off_t *offset) +{ + ssize_t bytes_read; + struct cpio *cpio; + + cpio = *(a->pformat_data); + if (cpio->entry_bytes_remaining > 0) { + bytes_read = (a->compression_read_ahead)(a, buff, 1); + if (bytes_read <= 0) + return (ARCHIVE_FATAL); + if (bytes_read > cpio->entry_bytes_remaining) + bytes_read = cpio->entry_bytes_remaining; + *size = bytes_read; + *offset = cpio->entry_offset; + cpio->entry_offset += bytes_read; + cpio->entry_bytes_remaining -= bytes_read; + (a->compression_read_consume)(a, bytes_read); + return (ARCHIVE_OK); + } else { + while (cpio->entry_padding > 0) { + bytes_read = (a->compression_read_ahead)(a, buff, 1); + if (bytes_read <= 0) + return (ARCHIVE_FATAL); + if (bytes_read > cpio->entry_padding) + bytes_read = cpio->entry_padding; + (a->compression_read_consume)(a, bytes_read); + cpio->entry_padding -= bytes_read; + } + *buff = NULL; + *size = 0; + *offset = cpio->entry_offset; + return (ARCHIVE_EOF); + } +} + +static int +header_newc(struct archive *a, struct cpio *cpio, struct stat *st, size_t *namelength, size_t *name_pad) { const void *h; @@ -293,16 +337,16 @@ * size. struct stat.st_size may only be 32 bits, so * assigning there first could lose information. */ - a->entry_bytes_remaining = + cpio->entry_bytes_remaining = atol16(header->c_filesize, sizeof(header->c_filesize)); - st->st_size = a->entry_bytes_remaining; + st->st_size = cpio->entry_bytes_remaining; /* Pad file contents to a multiple of 4. */ - a->entry_padding = 3 & -a->entry_bytes_remaining; + cpio->entry_padding = 3 & -cpio->entry_bytes_remaining; return (ARCHIVE_OK); } static int -header_odc(struct archive *a, struct stat *st, +header_odc(struct archive *a, struct cpio *cpio, struct stat *st, size_t *namelength, size_t *name_pad) { const void *h; @@ -338,15 +382,15 @@ * size. struct stat.st_size may only be 32 bits, so * assigning there first could lose information. */ - a->entry_bytes_remaining = + cpio->entry_bytes_remaining = atol8(header->c_filesize, sizeof(header->c_filesize)); - st->st_size = a->entry_bytes_remaining; - a->entry_padding = 0; + st->st_size = cpio->entry_bytes_remaining; + cpio->entry_padding = 0; return (ARCHIVE_OK); } static int -header_bin_le(struct archive *a, struct stat *st, +header_bin_le(struct archive *a, struct cpio *cpio, struct stat *st, size_t *namelength, size_t *name_pad) { const void *h; @@ -376,14 +420,14 @@ *namelength = header->c_namesize[0] + header->c_namesize[1] * 256; *name_pad = *namelength & 1; /* Pad to even. */ - a->entry_bytes_remaining = le4(header->c_filesize); - st->st_size = a->entry_bytes_remaining; - a->entry_padding = a->entry_bytes_remaining & 1; /* Pad to even. */ + cpio->entry_bytes_remaining = le4(header->c_filesize); + st->st_size = cpio->entry_bytes_remaining; >>> TRUNCATED FOR MAIL (1000 lines) <<<