From c9cefec1595e72d698a0c906b9ec6756b4b0320c Mon Sep 17 00:00:00 2001 From: Jung-uk Kim Date: Mon, 22 Mar 2010 18:43:36 +0000 Subject: [PATCH 001/119] Support memory wraparound instead of high memory as VM86 mode does. Suggested by: delphij --- sys/compat/x86bios/x86bios.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/sys/compat/x86bios/x86bios.c b/sys/compat/x86bios/x86bios.c index 088f073e659..af352af3a2f 100644 --- a/sys/compat/x86bios/x86bios.c +++ b/sys/compat/x86bios/x86bios.c @@ -56,8 +56,7 @@ __FBSDID("$FreeBSD$"); #define X86BIOS_IVT_SIZE 0x00000500 /* 1K + 256 (BDA) */ #define X86BIOS_SEG_SIZE 0x00010000 /* 64K */ -#define X86BIOS_MEM_SIZE (0x00100000 + X86BIOS_SEG_SIZE) - /* 1M + 64K (high memory) */ +#define X86BIOS_MEM_SIZE 0x00100000 /* 1M */ #define X86BIOS_IVT_BASE 0x00000000 #define X86BIOS_RAM_BASE 0x00001000 @@ -115,9 +114,11 @@ x86bios_get_pages(uint32_t offset, size_t size) { int i; - if (offset + size > X86BIOS_MEM_SIZE) + if (offset + size > X86BIOS_MEM_SIZE + X86BIOS_IVT_SIZE) return (NULL); + if (offset >= X86BIOS_MEM_SIZE) + offset -= X86BIOS_MEM_SIZE; i = offset / X86BIOS_PAGE_SIZE; if (x86bios_map[i] != 0) return ((void *)(x86bios_map[i] + offset - @@ -526,13 +527,6 @@ x86bios_map_mem(void) return (1); } #endif - /* Change attribute for high memory. */ - if (pmap_change_attr((vm_offset_t)x86bios_rom + X86BIOS_ROM_SIZE - - X86BIOS_SEG_SIZE, X86BIOS_SEG_SIZE, PAT_WRITE_BACK) != 0) { - pmap_unmapdev((vm_offset_t)x86bios_ivt, X86BIOS_IVT_SIZE); - pmap_unmapdev((vm_offset_t)x86bios_rom, X86BIOS_ROM_SIZE); - return (1); - } x86bios_seg = contigmalloc(X86BIOS_SEG_SIZE, M_DEVBUF, M_WAITOK, X86BIOS_RAM_BASE, x86bios_rom_phys, X86BIOS_PAGE_SIZE, 0); @@ -556,10 +550,6 @@ x86bios_map_mem(void) X86BIOS_ROM_BASE, X86BIOS_MEM_SIZE - X86BIOS_SEG_SIZE - 1, (void *)((vm_offset_t)x86bios_rom + X86BIOS_ROM_BASE - (vm_offset_t)x86bios_rom_phys)); - printf("x86bios: HIMEM 0x%06x-0x%06x at %p\n", - X86BIOS_MEM_SIZE - X86BIOS_SEG_SIZE, X86BIOS_MEM_SIZE - 1, - (void *)((vm_offset_t)x86bios_rom + X86BIOS_ROM_SIZE - - X86BIOS_SEG_SIZE)); } return (0); From 798aea00f8cda53d72ae7aaa0c514d985678322f Mon Sep 17 00:00:00 2001 From: Xin LI Date: Mon, 22 Mar 2010 21:11:55 +0000 Subject: [PATCH 002/119] Update to zlib 1.2.4 and add versioned symbols to the library. Sponsored by: iXsystems, Inc. --- ObsoleteFiles.inc | 5 + lib/libz/ChangeLog | 277 +++++- lib/libz/FAQ | 261 +++--- lib/libz/Makefile | 46 +- lib/libz/README | 85 +- lib/libz/Symbol.map | 96 ++ lib/libz/Versions.def | 11 + lib/libz/adler32.c | 38 +- lib/libz/compress.c | 5 +- lib/libz/contrib/README.contrib | 77 ++ lib/libz/contrib/asm686/README.686 | 51 ++ lib/libz/contrib/asm686/match.S | 343 +++++++ lib/libz/contrib/gcc_gvmat64/gvmat64.S | 574 ++++++++++++ lib/libz/crc32.c | 33 +- lib/libz/deflate.c | 268 ++++-- lib/libz/deflate.h | 17 +- lib/libz/{ => doc}/algorithm.txt | 2 +- lib/libz/doc/rfc1950.txt | 619 +++++++++++++ lib/libz/doc/rfc1951.txt | 955 ++++++++++++++++++++ lib/libz/doc/rfc1952.txt | 675 ++++++++++++++ lib/libz/doc/txtvsbin.txt | 107 +++ lib/libz/example.c | 4 +- lib/libz/gzclose.c | 25 + lib/libz/gzguts.h | 132 +++ lib/libz/gzio.c | 1027 --------------------- lib/libz/gzlib.c | 535 +++++++++++ lib/libz/gzread.c | 653 ++++++++++++++ lib/libz/gzwrite.c | 532 +++++++++++ lib/libz/infback.c | 93 +- lib/libz/inffast.c | 78 +- lib/libz/inflate.c | 282 ++++-- lib/libz/inflate.h | 31 +- lib/libz/inftrees.c | 61 +- lib/libz/inftrees.h | 23 +- lib/libz/minigzip.c | 131 ++- lib/libz/trees.c | 82 +- lib/libz/uncompr.c | 4 +- lib/libz/zconf.h | 205 +++-- lib/libz/zlib.3 | 66 +- lib/libz/zlib.h | 1137 ++++++++++++++---------- lib/libz/zutil.c | 8 +- lib/libz/zutil.h | 52 +- sys/sys/param.h | 2 +- 43 files changed, 7564 insertions(+), 2144 deletions(-) create mode 100644 lib/libz/Symbol.map create mode 100644 lib/libz/Versions.def create mode 100644 lib/libz/contrib/README.contrib create mode 100644 lib/libz/contrib/asm686/README.686 create mode 100644 lib/libz/contrib/asm686/match.S create mode 100644 lib/libz/contrib/gcc_gvmat64/gvmat64.S rename lib/libz/{ => doc}/algorithm.txt (99%) create mode 100644 lib/libz/doc/rfc1950.txt create mode 100644 lib/libz/doc/rfc1951.txt create mode 100644 lib/libz/doc/rfc1952.txt create mode 100644 lib/libz/doc/txtvsbin.txt create mode 100644 lib/libz/gzclose.c create mode 100644 lib/libz/gzguts.h delete mode 100644 lib/libz/gzio.c create mode 100644 lib/libz/gzlib.c create mode 100644 lib/libz/gzread.c create mode 100644 lib/libz/gzwrite.c diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc index fe0f4f21a23..ee300e0d708 100644 --- a/ObsoleteFiles.inc +++ b/ObsoleteFiles.inc @@ -14,6 +14,11 @@ # The file is partitioned: OLD_FILES first, then OLD_LIBS and OLD_DIRS last. # +# 20100322: libz update +OLD_LIBS+=lib/libz.so.5 +.if ${TARGET_ARCH} == "amd64" +OLD_LIBS+=usr/lib32/libz.so.5 +.endif # 20100314: removal of regexp.h OLD_FILES+=usr/include/regexp.h OLD_FILES+=usr/share/man/man3/regexp.3.gz diff --git a/lib/libz/ChangeLog b/lib/libz/ChangeLog index 7f6869d3235..6d046ee44b8 100644 --- a/lib/libz/ChangeLog +++ b/lib/libz/ChangeLog @@ -1,6 +1,281 @@ ChangeLog file for zlib +Changes in 1.2.4 (14 Mar 2010) +- Fix VER3 extraction in configure for no fourth subversion +- Update zlib.3, add docs to Makefile.in to make .pdf out of it +- Add zlib.3.pdf to distribution +- Don't set error code in gzerror() if passed pointer is NULL +- Apply destination directory fixes to CMakeLists.txt [Lowman] +- Move #cmakedefine's to a new zconf.in.cmakein +- Restore zconf.h for builds that don't use configure or cmake +- Add distclean to dummy Makefile for convenience +- Update and improve INDEX, README, and FAQ +- Update CMakeLists.txt for the return of zconf.h [Lowman] +- Update contrib/vstudio/vc9 and vc10 [Vollant] +- Change libz.dll.a back to libzdll.a in win32/Makefile.gcc +- Apply license and readme changes to contrib/asm686 [Raiter] +- Check file name lengths and add -c option in minigzip.c [Li] +- Update contrib/amd64 and contrib/masmx86/ [Vollant] +- Avoid use of "eof" parameter in trees.c to not shadow library variable +- Update make_vms.com for removal of zlibdefs.h [Zinser] +- Update assembler code and vstudio projects in contrib [Vollant] +- Remove outdated assembler code contrib/masm686 and contrib/asm586 +- Remove old vc7 and vc8 from contrib/vstudio +- Update win32/Makefile.msc, add ZLIB_VER_SUBREVISION [Rowe] +- Fix memory leaks in gzclose_r() and gzclose_w(), file leak in gz_open() +- Add contrib/gcc_gvmat64 for longest_match and inflate_fast [Vollant] +- Remove *64 functions from win32/zlib.def (they're not 64-bit yet) +- Fix bug in void-returning vsprintf() case in gzwrite.c +- Fix name change from inflate.h in contrib/inflate86/inffas86.c +- Check if temporary file exists before removing in make_vms.com [Zinser] +- Fix make install and uninstall for --static option +- Fix usage of _MSC_VER in gzguts.h and zutil.h [Truta] +- Update readme.txt in contrib/masmx64 and masmx86 to assemble + +Changes in 1.2.3.9 (21 Feb 2010) +- Expunge gzio.c +- Move as400 build information to old +- Fix updates in contrib/minizip and contrib/vstudio +- Add const to vsnprintf test in configure to avoid warnings [Weigelt] +- Delete zconf.h (made by configure) [Weigelt] +- Change zconf.in.h to zconf.h.in per convention [Weigelt] +- Check for NULL buf in gzgets() +- Return empty string for gzgets() with len == 1 (like fgets()) +- Fix description of gzgets() in zlib.h for end-of-file, NULL return +- Update minizip to 1.1 [Vollant] +- Avoid MSVC loss of data warnings in gzread.c, gzwrite.c +- Note in zlib.h that gzerror() should be used to distinguish from EOF +- Remove use of snprintf() from gzlib.c +- Fix bug in gzseek() +- Update contrib/vstudio, adding vc9 and vc10 [Kuno, Vollant] +- Fix zconf.h generation in CMakeLists.txt [Lowman] +- Improve comments in zconf.h where modified by configure + +Changes in 1.2.3.8 (13 Feb 2010) +- Clean up text files (tabs, trailing whitespace, etc.) [Oberhumer] +- Use z_off64_t in gz_zero() and gz_skip() to match state->skip +- Avoid comparison problem when sizeof(int) == sizeof(z_off64_t) +- Revert to Makefile.in from 1.2.3.6 (live with the clutter) +- Fix missing error return in gzflush(), add zlib.h note +- Add *64 functions to zlib.map [Levin] +- Fix signed/unsigned comparison in gz_comp() +- Use SFLAGS when testing shared linking in configure +- Add --64 option to ./configure to use -m64 with gcc +- Fix ./configure --help to correctly name options +- Have make fail if a test fails [Levin] +- Avoid buffer overrun in contrib/masmx64/gvmat64.asm [Simpson] +- Remove assembler object files from contrib + +Changes in 1.2.3.7 (24 Jan 2010) +- Always gzopen() with O_LARGEFILE if available +- Fix gzdirect() to work immediately after gzopen() or gzdopen() +- Make gzdirect() more precise when the state changes while reading +- Improve zlib.h documentation in many places +- Catch memory allocation failure in gz_open() +- Complete close operation if seek forward in gzclose_w() fails +- Return Z_ERRNO from gzclose_r() if close() fails +- Return Z_STREAM_ERROR instead of EOF for gzclose() being passed NULL +- Return zero for gzwrite() errors to match zlib.h description +- Return -1 on gzputs() error to match zlib.h description +- Add zconf.in.h to allow recovery from configure modification [Weigelt] +- Fix static library permissions in Makefile.in [Weigelt] +- Avoid warnings in configure tests that hide functionality [Weigelt] +- Add *BSD and DragonFly to Linux case in configure [gentoo 123571] +- Change libzdll.a to libz.dll.a in win32/Makefile.gcc [gentoo 288212] +- Avoid access of uninitialized data for first inflateReset2 call [Gomes] +- Keep object files in subdirectories to reduce the clutter somewhat +- Remove default Makefile and zlibdefs.h, add dummy Makefile +- Add new external functions to Z_PREFIX, remove duplicates, z_z_ -> z_ +- Remove zlibdefs.h completely -- modify zconf.h instead + +Changes in 1.2.3.6 (17 Jan 2010) +- Avoid void * arithmetic in gzread.c and gzwrite.c +- Make compilers happier with const char * for gz_error message +- Avoid unused parameter warning in inflate.c +- Avoid signed-unsigned comparison warning in inflate.c +- Indent #pragma's for traditional C +- Fix usage of strwinerror() in glib.c, change to gz_strwinerror() +- Correct email address in configure for system options +- Update make_vms.com and add make_vms.com to contrib/minizip [Zinser] +- Update zlib.map [Brown] +- Fix Makefile.in for Solaris 10 make of example64 and minizip64 [Tšršk] +- Apply various fixes to CMakeLists.txt [Lowman] +- Add checks on len in gzread() and gzwrite() +- Add error message for no more room for gzungetc() +- Remove zlib version check in gzwrite() +- Defer compression of gzprintf() result until need to +- Use snprintf() in gzdopen() if available +- Remove USE_MMAP configuration determination (only used by minigzip) +- Remove examples/pigz.c (available separately) +- Update examples/gun.c to 1.6 + +Changes in 1.2.3.5 (8 Jan 2010) +- Add space after #if in zutil.h for some compilers +- Fix relatively harmless bug in deflate_fast() [Exarevsky] +- Fix same problem in deflate_slow() +- Add $(SHAREDLIBV) to LIBS in Makefile.in [Brown] +- Add deflate_rle() for faster Z_RLE strategy run-length encoding +- Add deflate_huff() for faster Z_HUFFMAN_ONLY encoding +- Change name of "write" variable in inffast.c to avoid library collisions +- Fix premature EOF from gzread() in gzio.c [Brown] +- Use zlib header window size if windowBits is 0 in inflateInit2() +- Remove compressBound() call in deflate.c to avoid linking compress.o +- Replace use of errno in gz* with functions, support WinCE [Alves] +- Provide alternative to perror() in minigzip.c for WinCE [Alves] +- Don't use _vsnprintf on later versions of MSVC [Lowman] +- Add CMake build script and input file [Lowman] +- Update contrib/minizip to 1.1 [Svensson, Vollant] +- Moved nintendods directory from contrib to . +- Replace gzio.c with a new set of routines with the same functionality +- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above +- Update contrib/minizip to 1.1b +- Change gzeof() to return 0 on error instead of -1 to agree with zlib.h + +Changes in 1.2.3.4 (21 Dec 2009) +- Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility +- Update comments in configure and Makefile.in for default --shared +- Fix test -z's in configure [Marquess] +- Build examplesh and minigzipsh when not testing +- Change NULL's to Z_NULL's in deflate.c and in comments in zlib.h +- Import LDFLAGS from the environment in configure +- Fix configure to populate SFLAGS with discovered CFLAGS options +- Adapt make_vms.com to the new Makefile.in [Zinser] +- Add zlib2ansi script for C++ compilation [Marquess] +- Add _FILE_OFFSET_BITS=64 test to make test (when applicable) +- Add AMD64 assembler code for longest match to contrib [Teterin] +- Include options from $SFLAGS when doing $LDSHARED +- Simplify 64-bit file support by introducing z_off64_t type +- Make shared object files in objs directory to work around old Sun cc +- Use only three-part version number for Darwin shared compiles +- Add rc option to ar in Makefile.in for when ./configure not run +- Add -WI,-rpath,. to LDFLAGS for OSF 1 V4* +- Set LD_LIBRARYN32_PATH for SGI IRIX shared compile +- Protect against _FILE_OFFSET_BITS being defined when compiling zlib +- Rename Makefile.in targets allstatic to static and allshared to shared +- Fix static and shared Makefile.in targets to be independent +- Correct error return bug in gz_open() by setting state [Brown] +- Put spaces before ;;'s in configure for better sh compatibility +- Add pigz.c (parallel implementation of gzip) to examples/ +- Correct constant in crc32.c to UL [Leventhal] +- Reject negative lengths in crc32_combine() +- Add inflateReset2() function to work like inflateEnd()/inflateInit2() +- Include sys/types.h for _LARGEFILE64_SOURCE [Brown] +- Correct typo in doc/algorithm.txt [Janik] +- Fix bug in adler32_combine() [Zhu] +- Catch missing-end-of-block-code error in all inflates and in puff + Assures that random input to inflate eventually results in an error +- Added enough.c (calculation of ENOUGH for inftrees.h) to examples/ +- Update ENOUGH and its usage to reflect discovered bounds +- Fix gzerror() error report on empty input file [Brown] +- Add ush casts in trees.c to avoid pedantic runtime errors +- Fix typo in zlib.h uncompress() description [Reiss] +- Correct inflate() comments with regard to automatic header detection +- Remove deprecation comment on Z_PARTIAL_FLUSH (it stays) +- Put new version of gzlog (2.0) in examples with interruption recovery +- Add puff compile option to permit invalid distance-too-far streams +- Add puff TEST command options, ability to read piped input +- Prototype the *64 functions in zlib.h when _FILE_OFFSET_BITS == 64, but + _LARGEFILE64_SOURCE not defined +- Fix Z_FULL_FLUSH to truly erase the past by resetting s->strstart +- Fix deflateSetDictionary() to use all 32K for output consistency +- Remove extraneous #define MIN_LOOKAHEAD in deflate.c (in deflate.h) +- Clear bytes after deflate lookahead to avoid use of uninitialized data +- Change a limit in inftrees.c to be more transparent to Coverity Prevent +- Update win32/zlib.def with exported symbols from zlib.h +- Correct spelling error in zlib.h [Willem] +- Allow Z_BLOCK for deflate() to force a new block +- Allow negative bits in inflatePrime() to delete existing bit buffer +- Add Z_TREES flush option to inflate() to return at end of trees +- Add inflateMark() to return current state information for random access +- Add Makefile for NintendoDS to contrib [Costa] +- Add -w in configure compile tests to avoid spurious warnings [Beucler] +- Fix typos in zlib.h comments for deflateSetDictionary() +- Fix EOF detection in transparent gzread() [Maier] + +Changes in 1.2.3.3 (2 October 2006) +- Make --shared the default for configure, add a --static option +- Add compile option to permit invalid distance-too-far streams +- Add inflateUndermine() function which is required to enable above +- Remove use of "this" variable name for C++ compatibility [Marquess] +- Add testing of shared library in make test, if shared library built +- Use ftello() and fseeko() if available instead of ftell() and fseek() +- Provide two versions of all functions that use the z_off_t type for + binary compatibility -- a normal version and a 64-bit offset version, + per the Large File Support Extension when _LARGEFILE64_SOURCE is + defined; use the 64-bit versions by default when _FILE_OFFSET_BITS + is defined to be 64 +- Add a --uname= option to configure to perhaps help with cross-compiling + +Changes in 1.2.3.2 (3 September 2006) +- Turn off silly Borland warnings [Hay] +- Use off64_t and define _LARGEFILE64_SOURCE when present +- Fix missing dependency on inffixed.h in Makefile.in +- Rig configure --shared to build both shared and static [Teredesai, Truta] +- Remove zconf.in.h and instead create a new zlibdefs.h file +- Fix contrib/minizip/unzip.c non-encrypted after encrypted [Vollant] +- Add treebuild.xml (see http://treebuild.metux.de/) [Weigelt] + +Changes in 1.2.3.1 (16 August 2006) +- Add watcom directory with OpenWatcom make files [Daniel] +- Remove #undef of FAR in zconf.in.h for MVS [Fedtke] +- Update make_vms.com [Zinser] +- Use -fPIC for shared build in configure [Teredesai, Nicholson] +- Use only major version number for libz.so on IRIX and OSF1 [Reinholdtsen] +- Use fdopen() (not _fdopen()) for Interix in zutil.h [BŠck] +- Add some FAQ entries about the contrib directory +- Update the MVS question in the FAQ +- Avoid extraneous reads after EOF in gzio.c [Brown] +- Correct spelling of "successfully" in gzio.c [Randers-Pehrson] +- Add comments to zlib.h about gzerror() usage [Brown] +- Set extra flags in gzip header in gzopen() like deflate() does +- Make configure options more compatible with double-dash conventions + [Weigelt] +- Clean up compilation under Solaris SunStudio cc [Rowe, Reinholdtsen] +- Fix uninstall target in Makefile.in [Truta] +- Add pkgconfig support [Weigelt] +- Use $(DESTDIR) macro in Makefile.in [Reinholdtsen, Weigelt] +- Replace set_data_type() with a more accurate detect_data_type() in + trees.c, according to the txtvsbin.txt document [Truta] +- Swap the order of #include and #include "zlib.h" in + gzio.c, example.c and minigzip.c [Truta] +- Shut up annoying VS2005 warnings about standard C deprecation [Rowe, + Truta] (where?) +- Fix target "clean" from win32/Makefile.bor [Truta] +- Create .pdb and .manifest files in win32/makefile.msc [Ziegler, Rowe] +- Update zlib www home address in win32/DLL_FAQ.txt [Truta] +- Update contrib/masmx86/inffas32.asm for VS2005 [Vollant, Van Wassenhove] +- Enable browse info in the "Debug" and "ASM Debug" configurations in + the Visual C++ 6 project, and set (non-ASM) "Debug" as default [Truta] +- Add pkgconfig support [Weigelt] +- Add ZLIB_VER_MAJOR, ZLIB_VER_MINOR and ZLIB_VER_REVISION in zlib.h, + for use in win32/zlib1.rc [Polushin, Rowe, Truta] +- Add a document that explains the new text detection scheme to + doc/txtvsbin.txt [Truta] +- Add rfc1950.txt, rfc1951.txt and rfc1952.txt to doc/ [Truta] +- Move algorithm.txt into doc/ [Truta] +- Synchronize FAQ with website +- Fix compressBound(), was low for some pathological cases [Fearnley] +- Take into account wrapper variations in deflateBound() +- Set examples/zpipe.c input and output to binary mode for Windows +- Update examples/zlib_how.html with new zpipe.c (also web site) +- Fix some warnings in examples/gzlog.c and examples/zran.c (it seems + that gcc became pickier in 4.0) +- Add zlib.map for Linux: "All symbols from zlib-1.1.4 remain + un-versioned, the patch adds versioning only for symbols introduced in + zlib-1.2.0 or later. It also declares as local those symbols which are + not designed to be exported." [Levin] +- Update Z_PREFIX list in zconf.in.h, add --zprefix option to configure +- Do not initialize global static by default in trees.c, add a response + NO_INIT_GLOBAL_POINTERS to initialize them if needed [Marquess] +- Don't use strerror() in gzio.c under WinCE [Yakimov] +- Don't use errno.h in zutil.h under WinCE [Yakimov] +- Move arguments for AR to its usage to allow replacing ar [Marot] +- Add HAVE_VISIBILITY_PRAGMA in zconf.in.h for Mozilla [Randers-Pehrson] +- Improve inflateInit() and inflateInit2() documentation +- Fix structure size comment in inflate.h +- Change configure help option from --h* to --help [Santos] + Changes in 1.2.3 (18 July 2005) - Apply security vulnerability fixes to contrib/infback9 as well - Clean up some text files (carriage returns, trailing space) @@ -13,7 +288,7 @@ Changes in 1.2.2.4 (11 July 2005) compile - Fix some spelling errors in comments [Betts] - Correct inflateInit2() error return documentation in zlib.h -- Added zran.c example of compressed data random access to examples +- Add zran.c example of compressed data random access to examples directory, shows use of inflatePrime() - Fix cast for assignments to strm->state in inflate.c and infback.c - Fix zlibCompileFlags() in zutil.c to use 1L for long shifts [Oberhumer] diff --git a/lib/libz/FAQ b/lib/libz/FAQ index 441d910daa1..1a22750a58e 100644 --- a/lib/libz/FAQ +++ b/lib/libz/FAQ @@ -3,8 +3,8 @@ If your question is not there, please check the zlib home page -http://www.zlib.org which may have more recent information. -The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html +http://zlib.net/ which may have more recent information. +The lastest zlib FAQ is at http://zlib.net/zlib_faq.html 1. Is zlib Y2K-compliant? @@ -13,54 +13,51 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html 2. Where can I get a Windows DLL version? - The zlib sources can be compiled without change to produce a DLL. - See the file win32/DLL_FAQ.txt in the zlib distribution. - Pointers to the precompiled DLL are found in the zlib web site at - http://www.zlib.org. + The zlib sources can be compiled without change to produce a DLL. See the + file win32/DLL_FAQ.txt in the zlib distribution. Pointers to the + precompiled DLL are found in the zlib web site at http://zlib.net/ . 3. Where can I get a Visual Basic interface to zlib? See - * http://www.dogma.net/markn/articles/zlibtool/zlibtool.htm - * contrib/visual-basic.txt in the zlib distribution + * http://marknelson.us/1997/01/01/zlib-engine/ * win32/DLL_FAQ.txt in the zlib distribution 4. compress() returns Z_BUF_ERROR. - Make sure that before the call of compress, the length of the compressed - buffer is equal to the total size of the compressed buffer and not - zero. For Visual Basic, check that this parameter is passed by reference + Make sure that before the call of compress(), the length of the compressed + buffer is equal to the available size of the compressed buffer and not + zero. For Visual Basic, check that this parameter is passed by reference ("as any"), not by value ("as long"). 5. deflate() or inflate() returns Z_BUF_ERROR. - Before making the call, make sure that avail_in and avail_out are not - zero. When setting the parameter flush equal to Z_FINISH, also make sure - that avail_out is big enough to allow processing all pending input. - Note that a Z_BUF_ERROR is not fatal--another call to deflate() or - inflate() can be made with more input or output space. A Z_BUF_ERROR - may in fact be unavoidable depending on how the functions are used, since - it is not possible to tell whether or not there is more output pending - when strm.avail_out returns with zero. + Before making the call, make sure that avail_in and avail_out are not zero. + When setting the parameter flush equal to Z_FINISH, also make sure that + avail_out is big enough to allow processing all pending input. Note that a + Z_BUF_ERROR is not fatal--another call to deflate() or inflate() can be + made with more input or output space. A Z_BUF_ERROR may in fact be + unavoidable depending on how the functions are used, since it is not + possible to tell whether or not there is more output pending when + strm.avail_out returns with zero. See http://zlib.net/zlib_how.html for a + heavily annotated example. 6. Where's the zlib documentation (man pages, etc.)? - It's in zlib.h for the moment, and Francis S. Lin has converted it to a - web page zlib.html. Volunteers to transform this to Unix-style man pages, - please contact us (zlib@gzip.org). Examples of zlib usage are in the files - example.c and minigzip.c. + It's in zlib.h . Examples of zlib usage are in the files example.c and + minigzip.c, with more in examples/ . 7. Why don't you use GNU autoconf or libtool or ...? - Because we would like to keep zlib as a very small and simple - package. zlib is rather portable and doesn't need much configuration. + Because we would like to keep zlib as a very small and simple package. + zlib is rather portable and doesn't need much configuration. 8. I found a bug in zlib. - Most of the time, such problems are due to an incorrect usage of - zlib. Please try to reproduce the problem with a small program and send - the corresponding source to us at zlib@gzip.org . Do not send - multi-megabyte data files without prior agreement. + Most of the time, such problems are due to an incorrect usage of zlib. + Please try to reproduce the problem with a small program and send the + corresponding source to us at zlib@gzip.org . Do not send multi-megabyte + data files without prior agreement. 9. Why do I get "undefined reference to gzputc"? @@ -82,7 +79,7 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html 12. Can zlib handle .Z files? - No, sorry. You have to spawn an uncompress or gunzip subprocess, or adapt + No, sorry. You have to spawn an uncompress or gunzip subprocess, or adapt the code of uncompress on your own. 13. How can I make a Unix shared library? @@ -99,8 +96,10 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html However, many flavors of Unix come with a shared zlib already installed. Before going to the trouble of compiling a shared version of zlib and - trying to install it, you may want to check if it's already there! If you - can #include , it's there. The -lz option will probably link to it. + trying to install it, you may want to check if it's already there! If you + can #include , it's there. The -lz option will probably link to + it. You can check the version at the top of zlib.h or with the + ZLIB_VERSION symbol defined in zlib.h . 15. I have a question about OttoPDF. @@ -109,8 +108,8 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html 16. Can zlib decode Flate data in an Adobe PDF file? - Yes. See http://www.fastio.com/ (ClibPDF), or http://www.pdflib.com/ . - To modify PDF forms, see http://sourceforge.net/projects/acroformtool/ . + Yes. See http://www.pdflib.com/ . To modify PDF forms, see + http://sourceforge.net/projects/acroformtool/ . 17. Why am I getting this "register_frame_info not found" error on Solaris? @@ -121,67 +120,67 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html symbol __register_frame_info: referenced symbol not found The symbol __register_frame_info is not part of zlib, it is generated by - the C compiler (cc or gcc). You must recompile applications using zlib - which have this problem. This problem is specific to Solaris. See + the C compiler (cc or gcc). You must recompile applications using zlib + which have this problem. This problem is specific to Solaris. See http://www.sunfreeware.com for Solaris versions of zlib and applications using zlib. 18. Why does gzip give an error on a file I make with compress/deflate? The compress and deflate functions produce data in the zlib format, which - is different and incompatible with the gzip format. The gz* functions in - zlib on the other hand use the gzip format. Both the zlib and gzip - formats use the same compressed data format internally, but have different - headers and trailers around the compressed data. + is different and incompatible with the gzip format. The gz* functions in + zlib on the other hand use the gzip format. Both the zlib and gzip formats + use the same compressed data format internally, but have different headers + and trailers around the compressed data. 19. Ok, so why are there two different formats? - The gzip format was designed to retain the directory information about - a single file, such as the name and last modification date. The zlib - format on the other hand was designed for in-memory and communication - channel applications, and has a much more compact header and trailer and - uses a faster integrity check than gzip. + The gzip format was designed to retain the directory information about a + single file, such as the name and last modification date. The zlib format + on the other hand was designed for in-memory and communication channel + applications, and has a much more compact header and trailer and uses a + faster integrity check than gzip. 20. Well that's nice, but how do I make a gzip file in memory? You can request that deflate write the gzip format instead of the zlib - format using deflateInit2(). You can also request that inflate decode - the gzip format using inflateInit2(). Read zlib.h for more details. + format using deflateInit2(). You can also request that inflate decode the + gzip format using inflateInit2(). Read zlib.h for more details. 21. Is zlib thread-safe? - Yes. However any library routines that zlib uses and any application- - provided memory allocation routines must also be thread-safe. zlib's gz* + Yes. However any library routines that zlib uses and any application- + provided memory allocation routines must also be thread-safe. zlib's gz* functions use stdio library routines, and most of zlib's functions use the - library memory allocation routines by default. zlib's Init functions allow - for the application to provide custom memory allocation routines. + library memory allocation routines by default. zlib's *Init* functions + allow for the application to provide custom memory allocation routines. Of course, you should only operate on any given zlib or gzip stream from a single thread at a time. 22. Can I use zlib in my commercial application? - Yes. Please read the license in zlib.h. + Yes. Please read the license in zlib.h. 23. Is zlib under the GNU license? - No. Please read the license in zlib.h. + No. Please read the license in zlib.h. 24. The license says that altered source versions must be "plainly marked". So what exactly do I need to do to meet that requirement? - You need to change the ZLIB_VERSION and ZLIB_VERNUM #defines in zlib.h. In + You need to change the ZLIB_VERSION and ZLIB_VERNUM #defines in zlib.h. In particular, the final version number needs to be changed to "f", and an - identification string should be appended to ZLIB_VERSION. Version numbers + identification string should be appended to ZLIB_VERSION. Version numbers x.x.x.f are reserved for modifications to zlib by others than the zlib - maintainers. For example, if the version of the base zlib you are altering + maintainers. For example, if the version of the base zlib you are altering is "1.2.3.4", then in zlib.h you should change ZLIB_VERNUM to 0x123f, and - ZLIB_VERSION to something like "1.2.3.f-zachary-mods-v3". You can also + ZLIB_VERSION to something like "1.2.3.f-zachary-mods-v3". You can also update the version strings in deflate.c and inftrees.c. For altered source distributions, you should also note the origin and nature of the changes in zlib.h, as well as in ChangeLog and README, along - with the dates of the alterations. The origin should include at least your + with the dates of the alterations. The origin should include at least your name (or your company's name), and an email address to contact for help or issues with the library. @@ -197,105 +196,112 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html 26. Will zlib work on a 64-bit machine? - It should. It has been tested on 64-bit machines, and has no dependence - on any data types being limited to 32-bits in length. If you have any + Yes. It has been tested on 64-bit machines, and has no dependence on any + data types being limited to 32-bits in length. If you have any difficulties, please provide a complete problem report to zlib@gzip.org 27. Will zlib decompress data from the PKWare Data Compression Library? - No. The PKWare DCL uses a completely different compressed data format - than does PKZIP and zlib. However, you can look in zlib's contrib/blast + No. The PKWare DCL uses a completely different compressed data format than + does PKZIP and zlib. However, you can look in zlib's contrib/blast directory for a possible solution to your problem. 28. Can I access data randomly in a compressed stream? - No, not without some preparation. If when compressing you periodically - use Z_FULL_FLUSH, carefully write all the pending data at those points, - and keep an index of those locations, then you can start decompression - at those points. You have to be careful to not use Z_FULL_FLUSH too - often, since it can significantly degrade compression. + No, not without some preparation. If when compressing you periodically use + Z_FULL_FLUSH, carefully write all the pending data at those points, and + keep an index of those locations, then you can start decompression at those + points. You have to be careful to not use Z_FULL_FLUSH too often, since it + can significantly degrade compression. Alternatively, you can scan a + deflate stream once to generate an index, and then use that index for + random access. See examples/zran.c . 29. Does zlib work on MVS, OS/390, CICS, etc.? - We don't know for sure. We have heard occasional reports of success on - these systems. If you do use it on one of these, please provide us with - a report, instructions, and patches that we can reference when we get - these questions. Thanks. + It has in the past, but we have not heard of any recent evidence. There + were working ports of zlib 1.1.4 to MVS, but those links no longer work. + If you know of recent, successful applications of zlib on these operating + systems, please let us know. Thanks. -30. Is there some simpler, easier to read version of inflate I can look at - to understand the deflate format? +30. Is there some simpler, easier to read version of inflate I can look at to + understand the deflate format? - First off, you should read RFC 1951. Second, yes. Look in zlib's + First off, you should read RFC 1951. Second, yes. Look in zlib's contrib/puff directory. 31. Does zlib infringe on any patents? - As far as we know, no. In fact, that was originally the whole point behind - zlib. Look here for some more information: + As far as we know, no. In fact, that was originally the whole point behind + zlib. Look here for some more information: http://www.gzip.org/#faq11 32. Can zlib work with greater than 4 GB of data? - Yes. inflate() and deflate() will process any amount of data correctly. + Yes. inflate() and deflate() will process any amount of data correctly. Each call of inflate() or deflate() is limited to input and output chunks of the maximum value that can be stored in the compiler's "unsigned int" - type, but there is no limit to the number of chunks. Note however that the - strm.total_in and strm_total_out counters may be limited to 4 GB. These + type, but there is no limit to the number of chunks. Note however that the + strm.total_in and strm_total_out counters may be limited to 4 GB. These counters are provided as a convenience and are not used internally by - inflate() or deflate(). The application can easily set up its own counters + inflate() or deflate(). The application can easily set up its own counters updated after each call of inflate() or deflate() to count beyond 4 GB. compress() and uncompress() may be limited to 4 GB, since they operate in a - single call. gzseek() and gztell() may be limited to 4 GB depending on how - zlib is compiled. See the zlibCompileFlags() function in zlib.h. + single call. gzseek() and gztell() may be limited to 4 GB depending on how + zlib is compiled. See the zlibCompileFlags() function in zlib.h. - The word "may" appears several times above since there is a 4 GB limit - only if the compiler's "long" type is 32 bits. If the compiler's "long" - type is 64 bits, then the limit is 16 exabytes. + The word "may" appears several times above since there is a 4 GB limit only + if the compiler's "long" type is 32 bits. If the compiler's "long" type is + 64 bits, then the limit is 16 exabytes. 33. Does zlib have any security vulnerabilities? - The only one that we are aware of is potentially in gzprintf(). If zlib - is compiled to use sprintf() or vsprintf(), then there is no protection - against a buffer overflow of a 4K string space, other than the caller of - gzprintf() assuring that the output will not exceed 4K. On the other - hand, if zlib is compiled to use snprintf() or vsnprintf(), which should - normally be the case, then there is no vulnerability. The ./configure - script will display warnings if an insecure variation of sprintf() will - be used by gzprintf(). Also the zlibCompileFlags() function will return - information on what variant of sprintf() is used by gzprintf(). + The only one that we are aware of is potentially in gzprintf(). If zlib is + compiled to use sprintf() or vsprintf(), then there is no protection + against a buffer overflow of an 8K string space (or other value as set by + gzbuffer()), other than the caller of gzprintf() assuring that the output + will not exceed 8K. On the other hand, if zlib is compiled to use + snprintf() or vsnprintf(), which should normally be the case, then there is + no vulnerability. The ./configure script will display warnings if an + insecure variation of sprintf() will be used by gzprintf(). Also the + zlibCompileFlags() function will return information on what variant of + sprintf() is used by gzprintf(). If you don't have snprintf() or vsnprintf() and would like one, you can find a portable implementation here: http://www.ijs.si/software/snprintf/ - Note that you should be using the most recent version of zlib. Versions - 1.1.3 and before were subject to a double-free vulnerability. + Note that you should be using the most recent version of zlib. Versions + 1.1.3 and before were subject to a double-free vulnerability, and versions + 1.2.1 and 1.2.2 were subject to an access exception when decompressing + invalid compressed data. 34. Is there a Java version of zlib? Probably what you want is to use zlib in Java. zlib is already included as part of the Java SDK in the java.util.zip package. If you really want a version of zlib written in the Java language, look on the zlib home - page for links: http://www.zlib.org/ + page for links: http://zlib.net/ . 35. I get this or that compiler or source-code scanner warning when I crank it up to maximally-pedantic. Can't you guys write proper code? Many years ago, we gave up attempting to avoid warnings on every compiler - in the universe. It just got to be a waste of time, and some compilers - were downright silly. So now, we simply make sure that the code always - works. + in the universe. It just got to be a waste of time, and some compilers + were downright silly as well as contradicted each other. So now, we simply + make sure that the code always works. 36. Valgrind (or some similar memory access checker) says that deflate is performing a conditional jump that depends on an uninitialized value. Isn't that a bug? - No. That is intentional for performance reasons, and the output of - deflate is not affected. This only started showing up recently since - zlib 1.2.x uses malloc() by default for allocations, whereas earlier - versions used calloc(), which zeros out the allocated memory. + No. That is intentional for performance reasons, and the output of deflate + is not affected. This only started showing up recently since zlib 1.2.x + uses malloc() by default for allocations, whereas earlier versions used + calloc(), which zeros out the allocated memory. Even though the code was + correct, versions 1.2.4 and later was changed to not stimulate these + checkers. 37. Will zlib read the (insert any ancient or arcane format here) compressed data format? @@ -305,20 +311,21 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html 38. How can I encrypt/decrypt zip files with zlib? - zlib doesn't support encryption. The original PKZIP encryption is very weak - and can be broken with freely available programs. To get strong encryption, - use GnuPG, http://www.gnupg.org/ , which already includes zlib compression. - For PKZIP compatible "encryption", look at http://www.info-zip.org/ + zlib doesn't support encryption. The original PKZIP encryption is very + weak and can be broken with freely available programs. To get strong + encryption, use GnuPG, http://www.gnupg.org/ , which already includes zlib + compression. For PKZIP compatible "encryption", look at + http://www.info-zip.org/ 39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings? - "gzip" is the gzip format, and "deflate" is the zlib format. They should - probably have called the second one "zlib" instead to avoid confusion - with the raw deflate compressed data format. While the HTTP 1.1 RFC 2616 + "gzip" is the gzip format, and "deflate" is the zlib format. They should + probably have called the second one "zlib" instead to avoid confusion with + the raw deflate compressed data format. While the HTTP 1.1 RFC 2616 correctly points to the zlib specification in RFC 1950 for the "deflate" transfer encoding, there have been reports of servers and browsers that incorrectly produce or expect raw deflate data per the deflate - specficiation in RFC 1951, most notably Microsoft. So even though the + specficiation in RFC 1951, most notably Microsoft. So even though the "deflate" transfer encoding using the zlib format would be the more efficient approach (and in fact exactly what the zlib format was designed for), using the "gzip" transfer encoding is probably more reliable due to @@ -328,12 +335,32 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html 40. Does zlib support the new "Deflate64" format introduced by PKWare? - No. PKWare has apparently decided to keep that format proprietary, since - they have not documented it as they have previous compression formats. - In any case, the compression improvements are so modest compared to other - more modern approaches, that it's not worth the effort to implement. + No. PKWare has apparently decided to keep that format proprietary, since + they have not documented it as they have previous compression formats. In + any case, the compression improvements are so modest compared to other more + modern approaches, that it's not worth the effort to implement. -41. Can you please sign these lengthy legal documents and fax them back to us +41. I'm having a problem with the zip functions in zlib, can you help? + + There are no zip functions in zlib. You are probably using minizip by + Giles Vollant, which is found in the contrib directory of zlib. It is not + part of zlib. In fact none of the stuff in contrib is part of zlib. The + files in there are not supported by the zlib authors. You need to contact + the authors of the respective contribution for help. + +42. The match.asm code in contrib is under the GNU General Public License. + Since it's part of zlib, doesn't that mean that all of zlib falls under the + GNU GPL? + + No. The files in contrib are not part of zlib. They were contributed by + other authors and are provided as a convenience to the user within the zlib + distribution. Each item in contrib has its own license. + +43. Is zlib subject to export controls? What is its ECCN? + + zlib is not subject to export controls, and so is classified as EAR99. + +44. Can you please sign these lengthy legal documents and fax them back to us so that we can use your software in our product? No. Go away. Shoo. diff --git a/lib/libz/Makefile b/lib/libz/Makefile index 595b4f3d546..8835e0da8e1 100644 --- a/lib/libz/Makefile +++ b/lib/libz/Makefile @@ -4,21 +4,53 @@ LIB= z SHLIBDIR?= /lib +SHLIB_MAJOR= 6 MAN= zlib.3 -#CFLAGS+= -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 -#CFLAGS+= -g -DDEBUG -#CFLAGS+= -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ -# -Wstrict-prototypes -Wmissing-prototypes +#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 +#CFLAGS=-g -DDEBUG +#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ +# -Wstrict-prototypes -Wmissing-prototypes -CFLAGS+= -DHAS_snprintf -DHAS_vsnprintf +CFLAGS+= -DHAS_snprintf -DHAS_vsnprintf -I${.CURDIR} WARNS?= 3 CLEANFILES+= example.o example foo.gz minigzip.o minigzip -SRCS = adler32.c compress.c crc32.c gzio.c uncompr.c deflate.c trees.c \ - zutil.c inflate.c inftrees.c inffast.c zopen.c infback.c +SRCS+= adler32.c +SRCS+= compress.c +SRCS+= crc32.c +SRCS+= deflate.c +SRCS+= gzclose.c +SRCS+= gzlib.c +SRCS+= gzread.c +SRCS+= gzwrite.c +SRCS+= infback.c +SRCS+= inffast.c +SRCS+= inflate.c +SRCS+= inftrees.c +SRCS+= trees.c +SRCS+= uncompr.c +SRCS+= zopen.c +SRCS+= zutil.c + +.if ${MACHINE_ARCH} == "i386" && ${MACHINE_CPU:M*i686*} +.PATH: ${.CURDIR}/contrib/asm686 +SRCS+= match.S +CFLAGS+= -DASMV -DNO_UNDERLINE +.endif + +.if ${MACHINE_ARCH} == "amd64" +.PATH: ${.CURDIR}/contrib/gcc_gvmat64 +SRCS+= gvmat64.S +CFLAGS+= -DASMV -DNO_UNDERLINE +.endif + +VERSION_DEF= ${.CURDIR}/Versions.def +SYMBOL_MAPS= ${.CURDIR}/Symbol.map +CFLAGS+= -DSYMBOL_VERSIONING + INCS= zconf.h zlib.h minigzip: all minigzip.o diff --git a/lib/libz/README b/lib/libz/README index 758cc50020d..f24aeee110f 100644 --- a/lib/libz/README +++ b/lib/libz/README @@ -1,56 +1,51 @@ ZLIB DATA COMPRESSION LIBRARY -zlib 1.2.3 is a general purpose data compression library. All the code is +zlib 1.2.4 is a general purpose data compression library. All the code is thread safe. The data format used by the zlib library is described by RFCs (Request for Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) -and rfc1952.txt (gzip format). These documents are also available in other -formats from ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html +and rfc1952.txt (gzip format). All functions of the compression library are documented in the file zlib.h -(volunteer to write man pages welcome, contact zlib@gzip.org). A usage example +(volunteer to write man pages welcome, contact zlib@gzip.org). A usage example of the library is given in the file example.c which also tests that the library -is working correctly. Another example is given in the file minigzip.c. The +is working correctly. Another example is given in the file minigzip.c. The compression library itself is composed of all source files except example.c and minigzip.c. To compile all files and run the test program, follow the instructions given at -the top of Makefile. In short "make test; make install" should work for most -machines. For Unix: "./configure; make test; make install". For MSDOS, use one -of the special makefiles such as Makefile.msc. For VMS, use make_vms.com. +the top of Makefile.in. In short "./configure; make test", and if that goes +well, "make install" should work for most flavors of Unix. For Windows, use one +of the special makefiles in win32/ or projects/ . For VMS, use make_vms.com. Questions about zlib should be sent to , or to Gilles Vollant - for the Windows DLL version. The zlib home page is -http://www.zlib.org or http://www.gzip.org/zlib/ Before reporting a problem, -please check this site to verify that you have the latest version of zlib; -otherwise get the latest version and check whether the problem still exists or -not. + for the Windows DLL version. The zlib home page is +http://zlib.net/ . Before reporting a problem, please check this site to +verify that you have the latest version of zlib; otherwise get the latest +version and check whether the problem still exists or not. -PLEASE read the zlib FAQ http://www.gzip.org/zlib/zlib_faq.html before asking -for help. +PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help. -Mark Nelson wrote an article about zlib for the Jan. 1997 -issue of Dr. Dobb's Journal; a copy of the article is available in -http://dogma.net/markn/articles/zlibtool/zlibtool.htm +Mark Nelson wrote an article about zlib for the Jan. 1997 +issue of Dr. Dobb's Journal; a copy of the article is available at +http://marknelson.us/1997/01/01/zlib-engine/ . -The changes made in version 1.2.3 are documented in the file ChangeLog. +The changes made in version 1.2.4 are documented in the file ChangeLog. -Unsupported third party contributions are provided in directory "contrib". +Unsupported third party contributions are provided in directory contrib/ . -A Java implementation of zlib is available in the Java Development Kit -http://java.sun.com/j2se/1.4.2/docs/api/java/util/zip/package-summary.html -See the zlib home page http://www.zlib.org for details. +zlib is available in Java using the java.util.zip package, documented at +http://java.sun.com/developer/technicalArticles/Programming/compression/ . -A Perl interface to zlib written by Paul Marquess is in the -CPAN (Comprehensive Perl Archive Network) sites -http://www.cpan.org/modules/by-module/Compress/ +A Perl interface to zlib written by Paul Marquess is available +at CPAN (Comprehensive Perl Archive Network) sites, including +http://search.cpan.org/~pmqs/IO-Compress-Zlib/ . A Python interface to zlib written by A.M. Kuchling is available in Python 1.5 and later versions, see -http://www.python.org/doc/lib/module-zlib.html +http://www.python.org/doc/lib/module-zlib.html . -A zlib binding for TCL written by Andreas Kupries is -availlable at http://www.oche.de/~akupries/soft/trf/trf_zip.html +zlib is built into tcl: http://wiki.tcl.tk/4610 . An experimental package to read and write files in .zip format, written on top of zlib by Gilles Vollant , is available in the @@ -74,25 +69,21 @@ Notes for some targets: - zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with other compilers. Use "make test" to check your compiler. -- gzdopen is not supported on RISCOS, BEOS and by some Mac compilers. +- gzdopen is not supported on RISCOS or BEOS. - For PalmOs, see http://palmzlib.sourceforge.net/ -- When building a shared, i.e. dynamic library on Mac OS X, the library must be - installed before testing (do "make install" before "make test"), since the - library location is specified in the library. - Acknowledgments: - The deflate format used by zlib was defined by Phil Katz. The deflate - and zlib specifications were written by L. Peter Deutsch. Thanks to all the - people who reported problems and suggested various improvements in zlib; - they are too numerous to cite here. + The deflate format used by zlib was defined by Phil Katz. The deflate and + zlib specifications were written by L. Peter Deutsch. Thanks to all the + people who reported problems and suggested various improvements in zlib; they + are too numerous to cite here. Copyright notice: - (C) 1995-2004 Jean-loup Gailly and Mark Adler + (C) 1995-2010 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -113,13 +104,11 @@ Copyright notice: Jean-loup Gailly Mark Adler jloup@gzip.org madler@alumni.caltech.edu -If you use the zlib library in a product, we would appreciate *not* -receiving lengthy legal documents to sign. The sources are provided -for free but without warranty of any kind. The library has been -entirely written by Jean-loup Gailly and Mark Adler; it does not -include third-party code. +If you use the zlib library in a product, we would appreciate *not* receiving +lengthy legal documents to sign. The sources are provided for free but without +warranty of any kind. The library has been entirely written by Jean-loup +Gailly and Mark Adler; it does not include third-party code. -If you redistribute modified sources, we would appreciate that you include -in the file ChangeLog history information documenting your changes. Please -read the FAQ for more information on the distribution of modified source -versions. +If you redistribute modified sources, we would appreciate that you include in +the file ChangeLog history information documenting your changes. Please read +the FAQ for more information on the distribution of modified source versions. diff --git a/lib/libz/Symbol.map b/lib/libz/Symbol.map new file mode 100644 index 00000000000..714606b5949 --- /dev/null +++ b/lib/libz/Symbol.map @@ -0,0 +1,96 @@ +/* + * $FreeBSD$ + */ + +ZLIB_1.2.4.0 { + adler32; + adler32_combine64; + compress; + compress2; + compressBound; + crc32; + crc32_combine64; + deflate; + deflateBound; + deflateCopy; + deflateEnd; + deflateInit2_; + deflateInit_; + deflateParams; + deflatePrime; + deflateReset; + deflateSetDictionary; + deflateSetHeader; + deflateTune; + get_crc_table; + gzbuffer; + gzclearerr; + gzclose; + gzclose_r; + gzclose_w; + gzdirect; + gzdopen; + gzeof; + gzerror; + gzflush; + gzgetc; + gzgets; + gzoffset64; + gzopen64; + gzprintf; + gzputc; + gzputs; + gzread; + gzrewind; + gzseek64; + gzsetparams; + gztell64; + gzungetc; + gzwrite; + inflate; + inflateBack; + inflateBackEnd; + inflateBackInit_; + inflateCopy; + inflateEnd; + inflateGetHeader; + inflateInit2_; + inflateInit_; + inflateMark; + inflatePrime; + inflateReset; + inflateReset2; + inflateSetDictionary; + inflateSync; + inflateSyncPoint; + inflateUndermine; + uncompress; + zError; + zlibCompileFlags; + zlibVersion; +}; + +FBSD_1.2 { + zopen; +}; + +ZLIBprivate_1.0 { + _tr_align; + _tr_flush_block; + _tr_init; + _tr_stored_block; + _tr_tally; + adler32_combine; + crc32_combine; + gz_error; + gzoffset; + gzopen; + gzseek; + gztell; + inflate_fast; + inflate_table; + longest_match; + match_init; + zcalloc; + zcfree; +}; diff --git a/lib/libz/Versions.def b/lib/libz/Versions.def new file mode 100644 index 00000000000..fe413a4711f --- /dev/null +++ b/lib/libz/Versions.def @@ -0,0 +1,11 @@ +# $FreeBSD$ + +ZLIB_1.2.4.0 { +}; + +FBSD_1.2 { +} ZLIB_1.2.4.0; + +ZLIBprivate_1.0 { +} ZLIB_1.2.4.0; + diff --git a/lib/libz/adler32.c b/lib/libz/adler32.c index 007ba26277c..65ad6a5adc4 100644 --- a/lib/libz/adler32.c +++ b/lib/libz/adler32.c @@ -1,12 +1,15 @@ /* adler32.c -- compute the Adler-32 checksum of a data stream - * Copyright (C) 1995-2004 Mark Adler + * Copyright (C) 1995-2007 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ /* @(#) $Id$ */ -#define ZLIB_INTERNAL -#include "zlib.h" +#include "zutil.h" + +#define local static + +local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2); #define BASE 65521UL /* largest prime smaller than 65536 */ #define NMAX 5552 @@ -125,10 +128,10 @@ uLong ZEXPORT adler32(adler, buf, len) } /* ========================================================================= */ -uLong ZEXPORT adler32_combine(adler1, adler2, len2) +local uLong adler32_combine_(adler1, adler2, len2) uLong adler1; uLong adler2; - z_off_t len2; + z_off64_t len2; { unsigned long sum1; unsigned long sum2; @@ -141,9 +144,26 @@ uLong ZEXPORT adler32_combine(adler1, adler2, len2) MOD(sum2); sum1 += (adler2 & 0xffff) + BASE - 1; sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; - if (sum1 > BASE) sum1 -= BASE; - if (sum1 > BASE) sum1 -= BASE; - if (sum2 > (BASE << 1)) sum2 -= (BASE << 1); - if (sum2 > BASE) sum2 -= BASE; + if (sum1 >= BASE) sum1 -= BASE; + if (sum1 >= BASE) sum1 -= BASE; + if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); + if (sum2 >= BASE) sum2 -= BASE; return sum1 | (sum2 << 16); } + +/* ========================================================================= */ +uLong ZEXPORT adler32_combine(adler1, adler2, len2) + uLong adler1; + uLong adler2; + z_off_t len2; +{ + return adler32_combine_(adler1, adler2, len2); +} + +uLong ZEXPORT adler32_combine64(adler1, adler2, len2) + uLong adler1; + uLong adler2; + z_off64_t len2; +{ + return adler32_combine_(adler1, adler2, len2); +} diff --git a/lib/libz/compress.c b/lib/libz/compress.c index df04f0148e6..ea4dfbe9d7b 100644 --- a/lib/libz/compress.c +++ b/lib/libz/compress.c @@ -1,5 +1,5 @@ /* compress.c -- compress a memory buffer - * Copyright (C) 1995-2003 Jean-loup Gailly. + * Copyright (C) 1995-2005 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -75,5 +75,6 @@ int ZEXPORT compress (dest, destLen, source, sourceLen) uLong ZEXPORT compressBound (sourceLen) uLong sourceLen; { - return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11; + return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + + (sourceLen >> 25) + 13; } diff --git a/lib/libz/contrib/README.contrib b/lib/libz/contrib/README.contrib new file mode 100644 index 00000000000..dd2285d960a --- /dev/null +++ b/lib/libz/contrib/README.contrib @@ -0,0 +1,77 @@ +All files under this contrib directory are UNSUPPORTED. There were +provided by users of zlib and were not tested by the authors of zlib. +Use at your own risk. Please contact the authors of the contributions +for help about these, not the zlib authors. Thanks. + + +ada/ by Dmitriy Anisimkov + Support for Ada + See http://zlib-ada.sourceforge.net/ + +amd64/ by Mikhail Teterin + asm code for AMD64 + See patch at http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/96393 + +asm686/ by Brian Raiter + asm code for Pentium and PPro/PII, using the AT&T (GNU as) syntax + See http://www.muppetlabs.com/~breadbox/software/assembly.html + +blast/ by Mark Adler + Decompressor for output of PKWare Data Compression Library (DCL) + +delphi/ by Cosmin Truta + Support for Delphi and C++ Builder + +dotzlib/ by Henrik Ravn + Support for Microsoft .Net and Visual C++ .Net + +gcc_gvmat64/by Gilles Vollant + GCC Version of x86 64-bit (AMD64 and Intel EM64t) code for x64 + assembler to replace longest_match() and inflate_fast() + +infback9/ by Mark Adler + Unsupported diffs to infback to decode the deflate64 format + +inflate86/ by Chris Anderson + Tuned x86 gcc asm code to replace inflate_fast() + +iostream/ by Kevin Ruland + A C++ I/O streams interface to the zlib gz* functions + +iostream2/ by Tyge Løvset + Another C++ I/O streams interface + +iostream3/ by Ludwig Schwardt + and Kevin Ruland + Yet another C++ I/O streams interface + +masmx64/ by Gilles Vollant + x86 64-bit (AMD64 and Intel EM64t) code for x64 assembler to + replace longest_match() and inflate_fast(), also masm x86 + 64-bits translation of Chris Anderson inflate_fast() + +masmx86/ by Gilles Vollant + x86 asm code to replace longest_match() and inflate_fast(), + for Visual C++ and MASM (32 bits). + Based on Brian Raiter (asm686) and Chris Anderson (inflate86) + +minizip/ by Gilles Vollant + Mini zip and unzip based on zlib + Includes Zip64 support by Mathias Svensson + See http://www.winimage.com/zLibDll/unzip.html + +pascal/ by Bob Dellaca et al. + Support for Pascal + +puff/ by Mark Adler + Small, low memory usage inflate. Also serves to provide an + unambiguous description of the deflate format. + +testzlib/ by Gilles Vollant + Example of the use of zlib + +untgz/ by Pedro A. Aranda Gutierrez + A very simple tar.gz file extractor using zlib + +vstudio/ by Gilles Vollant + Building a minizip-enhanced zlib with Microsoft Visual Studio diff --git a/lib/libz/contrib/asm686/README.686 b/lib/libz/contrib/asm686/README.686 new file mode 100644 index 00000000000..a0bf3bea4af --- /dev/null +++ b/lib/libz/contrib/asm686/README.686 @@ -0,0 +1,51 @@ +This is a patched version of zlib, modified to use +Pentium-Pro-optimized assembly code in the deflation algorithm. The +files changed/added by this patch are: + +README.686 +match.S + +The speedup that this patch provides varies, depending on whether the +compiler used to build the original version of zlib falls afoul of the +PPro's speed traps. My own tests show a speedup of around 10-20% at +the default compression level, and 20-30% using -9, against a version +compiled using gcc 2.7.2.3. Your mileage may vary. + +Note that this code has been tailored for the PPro/PII in particular, +and will not perform particuarly well on a Pentium. + +If you are using an assembler other than GNU as, you will have to +translate match.S to use your assembler's syntax. (Have fun.) + +Brian Raiter +breadbox@muppetlabs.com +April, 1998 + + +Added for zlib 1.1.3: + +The patches come from +http://www.muppetlabs.com/~breadbox/software/assembly.html + +To compile zlib with this asm file, copy match.S to the zlib directory +then do: + +CFLAGS="-O3 -DASMV" ./configure +make OBJA=match.o + + +Update: + +I've been ignoring these assembly routines for years, believing that +gcc's generated code had caught up with it sometime around gcc 2.95 +and the major rearchitecting of the Pentium 4. However, I recently +learned that, despite what I believed, this code still has some life +in it. On the Pentium 4 and AMD64 chips, it continues to run about 8% +faster than the code produced by gcc 4.1. + +In acknowledgement of its continuing usefulness, I've altered the +license to match that of the rest of zlib. Share and Enjoy! + +Brian Raiter +breadbox@muppetlabs.com +April, 2007 diff --git a/lib/libz/contrib/asm686/match.S b/lib/libz/contrib/asm686/match.S new file mode 100644 index 00000000000..06817e1dd08 --- /dev/null +++ b/lib/libz/contrib/asm686/match.S @@ -0,0 +1,343 @@ +/* match.S -- x86 assembly version of the zlib longest_match() function. + * Optimized for the Intel 686 chips (PPro and later). + * + * Copyright (C) 1998, 2007 Brian Raiter + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the author be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#ifndef NO_UNDERLINE +#define match_init _match_init +#define longest_match _longest_match +#endif + +#define MAX_MATCH (258) +#define MIN_MATCH (3) +#define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1) +#define MAX_MATCH_8 ((MAX_MATCH + 7) & ~7) + +/* stack frame offsets */ + +#define chainlenwmask 0 /* high word: current chain len */ + /* low word: s->wmask */ +#define window 4 /* local copy of s->window */ +#define windowbestlen 8 /* s->window + bestlen */ +#define scanstart 16 /* first two bytes of string */ +#define scanend 12 /* last two bytes of string */ +#define scanalign 20 /* dword-misalignment of string */ +#define nicematch 24 /* a good enough match size */ +#define bestlen 28 /* size of best match so far */ +#define scan 32 /* ptr to string wanting match */ + +#define LocalVarsSize (36) +/* saved ebx 36 */ +/* saved edi 40 */ +/* saved esi 44 */ +/* saved ebp 48 */ +/* return address 52 */ +#define deflatestate 56 /* the function arguments */ +#define curmatch 60 + +/* All the +zlib1222add offsets are due to the addition of fields + * in zlib in the deflate_state structure since the asm code was first written + * (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)"). + * (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0"). + * if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8"). + */ + +#define zlib1222add (8) + +#define dsWSize (36+zlib1222add) +#define dsWMask (44+zlib1222add) +#define dsWindow (48+zlib1222add) +#define dsPrev (56+zlib1222add) +#define dsMatchLen (88+zlib1222add) +#define dsPrevMatch (92+zlib1222add) +#define dsStrStart (100+zlib1222add) +#define dsMatchStart (104+zlib1222add) +#define dsLookahead (108+zlib1222add) +#define dsPrevLen (112+zlib1222add) +#define dsMaxChainLen (116+zlib1222add) +#define dsGoodMatch (132+zlib1222add) +#define dsNiceMatch (136+zlib1222add) + + +.file "match.S" + +.globl match_init, longest_match + +.text + +/* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */ + +longest_match: + +/* Save registers that the compiler may be using, and adjust %esp to */ +/* make room for our stack frame. */ + + pushl %ebp + pushl %edi + pushl %esi + pushl %ebx + subl $LocalVarsSize, %esp + +/* Retrieve the function arguments. %ecx will hold cur_match */ +/* throughout the entire function. %edx will hold the pointer to the */ +/* deflate_state structure during the function's setup (before */ +/* entering the main loop). */ + + movl deflatestate(%esp), %edx + movl curmatch(%esp), %ecx + +/* uInt wmask = s->w_mask; */ +/* unsigned chain_length = s->max_chain_length; */ +/* if (s->prev_length >= s->good_match) { */ +/* chain_length >>= 2; */ +/* } */ + + movl dsPrevLen(%edx), %eax + movl dsGoodMatch(%edx), %ebx + cmpl %ebx, %eax + movl dsWMask(%edx), %eax + movl dsMaxChainLen(%edx), %ebx + jl LastMatchGood + shrl $2, %ebx +LastMatchGood: + +/* chainlen is decremented once beforehand so that the function can */ +/* use the sign flag instead of the zero flag for the exit test. */ +/* It is then shifted into the high word, to make room for the wmask */ +/* value, which it will always accompany. */ + + decl %ebx + shll $16, %ebx + orl %eax, %ebx + movl %ebx, chainlenwmask(%esp) + +/* if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; */ + + movl dsNiceMatch(%edx), %eax + movl dsLookahead(%edx), %ebx + cmpl %eax, %ebx + jl LookaheadLess + movl %eax, %ebx +LookaheadLess: movl %ebx, nicematch(%esp) + +/* register Bytef *scan = s->window + s->strstart; */ + + movl dsWindow(%edx), %esi + movl %esi, window(%esp) + movl dsStrStart(%edx), %ebp + lea (%esi,%ebp), %edi + movl %edi, scan(%esp) + +/* Determine how many bytes the scan ptr is off from being */ +/* dword-aligned. */ + + movl %edi, %eax + negl %eax + andl $3, %eax + movl %eax, scanalign(%esp) + +/* IPos limit = s->strstart > (IPos)MAX_DIST(s) ? */ +/* s->strstart - (IPos)MAX_DIST(s) : NIL; */ + + movl dsWSize(%edx), %eax + subl $MIN_LOOKAHEAD, %eax + subl %eax, %ebp + jg LimitPositive + xorl %ebp, %ebp +LimitPositive: + +/* int best_len = s->prev_length; */ + + movl dsPrevLen(%edx), %eax + movl %eax, bestlen(%esp) + +/* Store the sum of s->window + best_len in %esi locally, and in %esi. */ + + addl %eax, %esi + movl %esi, windowbestlen(%esp) + +/* register ush scan_start = *(ushf*)scan; */ +/* register ush scan_end = *(ushf*)(scan+best_len-1); */ +/* Posf *prev = s->prev; */ + + movzwl (%edi), %ebx + movl %ebx, scanstart(%esp) + movzwl -1(%edi,%eax), %ebx + movl %ebx, scanend(%esp) + movl dsPrev(%edx), %edi + +/* Jump into the main loop. */ + + movl chainlenwmask(%esp), %edx + jmp LoopEntry + +.balign 16 + +/* do { + * match = s->window + cur_match; + * if (*(ushf*)(match+best_len-1) != scan_end || + * *(ushf*)match != scan_start) continue; + * [...] + * } while ((cur_match = prev[cur_match & wmask]) > limit + * && --chain_length != 0); + * + * Here is the inner loop of the function. The function will spend the + * majority of its time in this loop, and majority of that time will + * be spent in the first ten instructions. + * + * Within this loop: + * %ebx = scanend + * %ecx = curmatch + * %edx = chainlenwmask - i.e., ((chainlen << 16) | wmask) + * %esi = windowbestlen - i.e., (window + bestlen) + * %edi = prev + * %ebp = limit + */ +LookupLoop: + andl %edx, %ecx + movzwl (%edi,%ecx,2), %ecx + cmpl %ebp, %ecx + jbe LeaveNow + subl $0x00010000, %edx + js LeaveNow +LoopEntry: movzwl -1(%esi,%ecx), %eax + cmpl %ebx, %eax + jnz LookupLoop + movl window(%esp), %eax + movzwl (%eax,%ecx), %eax + cmpl scanstart(%esp), %eax + jnz LookupLoop + +/* Store the current value of chainlen. */ + + movl %edx, chainlenwmask(%esp) + +/* Point %edi to the string under scrutiny, and %esi to the string we */ +/* are hoping to match it up with. In actuality, %esi and %edi are */ +/* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is */ +/* initialized to -(MAX_MATCH_8 - scanalign). */ + + movl window(%esp), %esi + movl scan(%esp), %edi + addl %ecx, %esi + movl scanalign(%esp), %eax + movl $(-MAX_MATCH_8), %edx + lea MAX_MATCH_8(%edi,%eax), %edi + lea MAX_MATCH_8(%esi,%eax), %esi + +/* Test the strings for equality, 8 bytes at a time. At the end, + * adjust %edx so that it is offset to the exact byte that mismatched. + * + * We already know at this point that the first three bytes of the + * strings match each other, and they can be safely passed over before + * starting the compare loop. So what this code does is skip over 0-3 + * bytes, as much as necessary in order to dword-align the %edi + * pointer. (%esi will still be misaligned three times out of four.) + * + * It should be confessed that this loop usually does not represent + * much of the total running time. Replacing it with a more + * straightforward "rep cmpsb" would not drastically degrade + * performance. + */ +LoopCmps: + movl (%esi,%edx), %eax + xorl (%edi,%edx), %eax + jnz LeaveLoopCmps + movl 4(%esi,%edx), %eax + xorl 4(%edi,%edx), %eax + jnz LeaveLoopCmps4 + addl $8, %edx + jnz LoopCmps + jmp LenMaximum +LeaveLoopCmps4: addl $4, %edx +LeaveLoopCmps: testl $0x0000FFFF, %eax + jnz LenLower + addl $2, %edx + shrl $16, %eax +LenLower: subb $1, %al + adcl $0, %edx + +/* Calculate the length of the match. If it is longer than MAX_MATCH, */ +/* then automatically accept it as the best possible match and leave. */ + + lea (%edi,%edx), %eax + movl scan(%esp), %edi + subl %edi, %eax + cmpl $MAX_MATCH, %eax + jge LenMaximum + +/* If the length of the match is not longer than the best match we */ +/* have so far, then forget it and return to the lookup loop. */ + + movl deflatestate(%esp), %edx + movl bestlen(%esp), %ebx + cmpl %ebx, %eax + jg LongerMatch + movl windowbestlen(%esp), %esi + movl dsPrev(%edx), %edi + movl scanend(%esp), %ebx + movl chainlenwmask(%esp), %edx + jmp LookupLoop + +/* s->match_start = cur_match; */ +/* best_len = len; */ +/* if (len >= nice_match) break; */ +/* scan_end = *(ushf*)(scan+best_len-1); */ + +LongerMatch: movl nicematch(%esp), %ebx + movl %eax, bestlen(%esp) + movl %ecx, dsMatchStart(%edx) + cmpl %ebx, %eax + jge LeaveNow + movl window(%esp), %esi + addl %eax, %esi + movl %esi, windowbestlen(%esp) + movzwl -1(%edi,%eax), %ebx + movl dsPrev(%edx), %edi + movl %ebx, scanend(%esp) + movl chainlenwmask(%esp), %edx + jmp LookupLoop + +/* Accept the current string, with the maximum possible length. */ + +LenMaximum: movl deflatestate(%esp), %edx + movl $MAX_MATCH, bestlen(%esp) + movl %ecx, dsMatchStart(%edx) + +/* if ((uInt)best_len <= s->lookahead) return (uInt)best_len; */ +/* return s->lookahead; */ + +LeaveNow: + movl deflatestate(%esp), %edx + movl bestlen(%esp), %ebx + movl dsLookahead(%edx), %eax + cmpl %eax, %ebx + jg LookaheadRet + movl %ebx, %eax +LookaheadRet: + +/* Restore the stack and return from whence we came. */ + + addl $LocalVarsSize, %esp + popl %ebx + popl %esi + popl %edi + popl %ebp +match_init: ret diff --git a/lib/libz/contrib/gcc_gvmat64/gvmat64.S b/lib/libz/contrib/gcc_gvmat64/gvmat64.S new file mode 100644 index 00000000000..23309fa286e --- /dev/null +++ b/lib/libz/contrib/gcc_gvmat64/gvmat64.S @@ -0,0 +1,574 @@ +/* +;uInt longest_match_x64( +; deflate_state *s, +; IPos cur_match); // current match + +; gvmat64.S -- Asm portion of the optimized longest_match for 32 bits x86_64 +; (AMD64 on Athlon 64, Opteron, Phenom +; and Intel EM64T on Pentium 4 with EM64T, Pentium D, Core 2 Duo, Core I5/I7) +; this file is translation from gvmat64.asm to GCC 4.x (for Linux, Mac XCode) +; Copyright (C) 1995-2010 Jean-loup Gailly, Brian Raiter and Gilles Vollant. +; +; File written by Gilles Vollant, by converting to assembly the longest_match +; from Jean-loup Gailly in deflate.c of zLib and infoZip zip. +; and by taking inspiration on asm686 with masm, optimised assembly code +; from Brian Raiter, written 1998 +; +; This software is provided 'as-is', without any express or implied +; warranty. In no event will the authors be held liable for any damages +; arising from the use of this software. +; +; Permission is granted to anyone to use this software for any purpose, +; including commercial applications, and to alter it and redistribute it +; freely, subject to the following restrictions: +; +; 1. The origin of this software must not be misrepresented; you must not +; claim that you wrote the original software. If you use this software +; in a product, an acknowledgment in the product documentation would be +; appreciated but is not required. +; 2. Altered source versions must be plainly marked as such, and must not be +; misrepresented as being the original software +; 3. This notice may not be removed or altered from any source distribution. +; +; http://www.zlib.net +; http://www.winimage.com/zLibDll +; http://www.muppetlabs.com/~breadbox/software/assembly.html +; +; to compile this file for zLib, I use option: +; gcc -c -arch x86_64 gvmat64.S + + +;uInt longest_match(s, cur_match) +; deflate_state *s; +; IPos cur_match; // current match / +; +; with XCode for Mac, I had strange error with some jump on intel syntax +; this is why BEFORE_JMP and AFTER_JMP are used + */ + + +#define BEFORE_JMP .att_syntax +#define AFTER_JMP .intel_syntax noprefix + +#ifndef NO_UNDERLINE +# define match_init _match_init +# define longest_match _longest_match +#endif + +.intel_syntax noprefix + +.globl match_init, longest_match +.text +longest_match: + + + +#define LocalVarsSize 96 +/* +; register used : rax,rbx,rcx,rdx,rsi,rdi,r8,r9,r10,r11,r12 +; free register : r14,r15 +; register can be saved : rsp +*/ + +#define chainlenwmask (rsp + 8 - LocalVarsSize) +#define nicematch (rsp + 16 - LocalVarsSize) + +#define save_rdi (rsp + 24 - LocalVarsSize) +#define save_rsi (rsp + 32 - LocalVarsSize) +#define save_rbx (rsp + 40 - LocalVarsSize) +#define save_rbp (rsp + 48 - LocalVarsSize) +#define save_r12 (rsp + 56 - LocalVarsSize) +#define save_r13 (rsp + 64 - LocalVarsSize) +#define save_r14 (rsp + 72 - LocalVarsSize) +#define save_r15 (rsp + 80 - LocalVarsSize) + + +/* +; all the +4 offsets are due to the addition of pending_buf_size (in zlib +; in the deflate_state structure since the asm code was first written +; (if you compile with zlib 1.0.4 or older, remove the +4). +; Note : these value are good with a 8 bytes boundary pack structure +*/ + +#define MAX_MATCH 258 +#define MIN_MATCH 3 +#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) + +/* +;;; Offsets for fields in the deflate_state structure. These numbers +;;; are calculated from the definition of deflate_state, with the +;;; assumption that the compiler will dword-align the fields. (Thus, +;;; changing the definition of deflate_state could easily cause this +;;; program to crash horribly, without so much as a warning at +;;; compile time. Sigh.) + +; all the +zlib1222add offsets are due to the addition of fields +; in zlib in the deflate_state structure since the asm code was first written +; (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)"). +; (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0"). +; if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8"). +*/ + + + +/* you can check the structure offset by running + +#include +#include +#include "deflate.h" + +void print_depl() +{ +deflate_state ds; +deflate_state *s=&ds; +printf("size pointer=%u\n",(int)sizeof(void*)); + +printf("#define dsWSize %u\n",(int)(((char*)&(s->w_size))-((char*)s))); +printf("#define dsWMask %u\n",(int)(((char*)&(s->w_mask))-((char*)s))); +printf("#define dsWindow %u\n",(int)(((char*)&(s->window))-((char*)s))); +printf("#define dsPrev %u\n",(int)(((char*)&(s->prev))-((char*)s))); +printf("#define dsMatchLen %u\n",(int)(((char*)&(s->match_length))-((char*)s))); +printf("#define dsPrevMatch %u\n",(int)(((char*)&(s->prev_match))-((char*)s))); +printf("#define dsStrStart %u\n",(int)(((char*)&(s->strstart))-((char*)s))); +printf("#define dsMatchStart %u\n",(int)(((char*)&(s->match_start))-((char*)s))); +printf("#define dsLookahead %u\n",(int)(((char*)&(s->lookahead))-((char*)s))); +printf("#define dsPrevLen %u\n",(int)(((char*)&(s->prev_length))-((char*)s))); +printf("#define dsMaxChainLen %u\n",(int)(((char*)&(s->max_chain_length))-((char*)s))); +printf("#define dsGoodMatch %u\n",(int)(((char*)&(s->good_match))-((char*)s))); +printf("#define dsNiceMatch %u\n",(int)(((char*)&(s->nice_match))-((char*)s))); +} +*/ + +#define dsWSize 68 +#define dsWMask 76 +#define dsWindow 80 +#define dsPrev 96 +#define dsMatchLen 144 +#define dsPrevMatch 148 +#define dsStrStart 156 +#define dsMatchStart 160 +#define dsLookahead 164 +#define dsPrevLen 168 +#define dsMaxChainLen 172 +#define dsGoodMatch 188 +#define dsNiceMatch 192 + +#define window_size [ rcx + dsWSize] +#define WMask [ rcx + dsWMask] +#define window_ad [ rcx + dsWindow] +#define prev_ad [ rcx + dsPrev] +#define strstart [ rcx + dsStrStart] +#define match_start [ rcx + dsMatchStart] +#define Lookahead [ rcx + dsLookahead] //; 0ffffffffh on infozip +#define prev_length [ rcx + dsPrevLen] +#define max_chain_length [ rcx + dsMaxChainLen] +#define good_match [ rcx + dsGoodMatch] +#define nice_match [ rcx + dsNiceMatch] + +/* +; windows: +; parameter 1 in rcx(deflate state s), param 2 in rdx (cur match) + +; see http://weblogs.asp.net/oldnewthing/archive/2004/01/14/58579.aspx and +; http://msdn.microsoft.com/library/en-us/kmarch/hh/kmarch/64bitAMD_8e951dd2-ee77-4728-8702-55ce4b5dd24a.xml.asp +; +; All registers must be preserved across the call, except for +; rax, rcx, rdx, r8, r9, r10, and r11, which are scratch. + +; +; gcc on macosx-linux: +; see http://www.x86-64.org/documentation/abi-0.99.pdf +; param 1 in rdi, param 2 in rsi +; rbx, rsp, rbp, r12 to r15 must be preserved + +;;; Save registers that the compiler may be using, and adjust esp to +;;; make room for our stack frame. + + +;;; Retrieve the function arguments. r8d will hold cur_match +;;; throughout the entire function. edx will hold the pointer to the +;;; deflate_state structure during the function's setup (before +;;; entering the main loop. + +; ms: parameter 1 in rcx (deflate_state* s), param 2 in edx -> r8 (cur match) +; mac: param 1 in rdi, param 2 rsi +; this clear high 32 bits of r8, which can be garbage in both r8 and rdx +*/ + mov [save_rbx],rbx + mov [save_rbp],rbp + + + mov rcx,rdi + + mov r8d,esi + + + mov [save_r12],r12 + mov [save_r13],r13 + mov [save_r14],r14 + mov [save_r15],r15 + + +//;;; uInt wmask = s->w_mask; +//;;; unsigned chain_length = s->max_chain_length; +//;;; if (s->prev_length >= s->good_match) { +//;;; chain_length >>= 2; +//;;; } + + + mov edi, prev_length + mov esi, good_match + mov eax, WMask + mov ebx, max_chain_length + cmp edi, esi + jl LastMatchGood + shr ebx, 2 +LastMatchGood: + +//;;; chainlen is decremented once beforehand so that the function can +//;;; use the sign flag instead of the zero flag for the exit test. +//;;; It is then shifted into the high word, to make room for the wmask +//;;; value, which it will always accompany. + + dec ebx + shl ebx, 16 + or ebx, eax + +//;;; on zlib only +//;;; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; + + + + mov eax, nice_match + mov [chainlenwmask], ebx + mov r10d, Lookahead + cmp r10d, eax + cmovnl r10d, eax + mov [nicematch],r10d + + + +//;;; register Bytef *scan = s->window + s->strstart; + mov r10, window_ad + mov ebp, strstart + lea r13, [r10 + rbp] + +//;;; Determine how many bytes the scan ptr is off from being +//;;; dword-aligned. + + mov r9,r13 + neg r13 + and r13,3 + +//;;; IPos limit = s->strstart > (IPos)MAX_DIST(s) ? +//;;; s->strstart - (IPos)MAX_DIST(s) : NIL; + + + mov eax, window_size + sub eax, MIN_LOOKAHEAD + + + xor edi,edi + sub ebp, eax + + mov r11d, prev_length + + cmovng ebp,edi + +//;;; int best_len = s->prev_length; + + +//;;; Store the sum of s->window + best_len in esi locally, and in esi. + + lea rsi,[r10+r11] + +//;;; register ush scan_start = *(ushf*)scan; +//;;; register ush scan_end = *(ushf*)(scan+best_len-1); +//;;; Posf *prev = s->prev; + + movzx r12d,word ptr [r9] + movzx ebx, word ptr [r9 + r11 - 1] + + mov rdi, prev_ad + +//;;; Jump into the main loop. + + mov edx, [chainlenwmask] + + cmp bx,word ptr [rsi + r8 - 1] + jz LookupLoopIsZero + + + +LookupLoop1: + and r8d, edx + + movzx r8d, word ptr [rdi + r8*2] + cmp r8d, ebp + jbe LeaveNow + + + + sub edx, 0x00010000 + BEFORE_JMP + js LeaveNow + AFTER_JMP + +LoopEntry1: + cmp bx,word ptr [rsi + r8 - 1] + BEFORE_JMP + jz LookupLoopIsZero + AFTER_JMP + +LookupLoop2: + and r8d, edx + + movzx r8d, word ptr [rdi + r8*2] + cmp r8d, ebp + BEFORE_JMP + jbe LeaveNow + AFTER_JMP + sub edx, 0x00010000 + BEFORE_JMP + js LeaveNow + AFTER_JMP + +LoopEntry2: + cmp bx,word ptr [rsi + r8 - 1] + BEFORE_JMP + jz LookupLoopIsZero + AFTER_JMP + +LookupLoop4: + and r8d, edx + + movzx r8d, word ptr [rdi + r8*2] + cmp r8d, ebp + BEFORE_JMP + jbe LeaveNow + AFTER_JMP + sub edx, 0x00010000 + BEFORE_JMP + js LeaveNow + AFTER_JMP + +LoopEntry4: + + cmp bx,word ptr [rsi + r8 - 1] + BEFORE_JMP + jnz LookupLoop1 + jmp LookupLoopIsZero + AFTER_JMP +/* +;;; do { +;;; match = s->window + cur_match; +;;; if (*(ushf*)(match+best_len-1) != scan_end || +;;; *(ushf*)match != scan_start) continue; +;;; [...] +;;; } while ((cur_match = prev[cur_match & wmask]) > limit +;;; && --chain_length != 0); +;;; +;;; Here is the inner loop of the function. The function will spend the +;;; majority of its time in this loop, and majority of that time will +;;; be spent in the first ten instructions. +;;; +;;; Within this loop: +;;; ebx = scanend +;;; r8d = curmatch +;;; edx = chainlenwmask - i.e., ((chainlen << 16) | wmask) +;;; esi = windowbestlen - i.e., (window + bestlen) +;;; edi = prev +;;; ebp = limit +*/ +.balign 16 +LookupLoop: + and r8d, edx + + movzx r8d, word ptr [rdi + r8*2] + cmp r8d, ebp + BEFORE_JMP + jbe LeaveNow + AFTER_JMP + sub edx, 0x00010000 + BEFORE_JMP + js LeaveNow + AFTER_JMP + +LoopEntry: + + cmp bx,word ptr [rsi + r8 - 1] + BEFORE_JMP + jnz LookupLoop1 + AFTER_JMP +LookupLoopIsZero: + cmp r12w, word ptr [r10 + r8] + BEFORE_JMP + jnz LookupLoop1 + AFTER_JMP + + +//;;; Store the current value of chainlen. + mov [chainlenwmask], edx +/* +;;; Point edi to the string under scrutiny, and esi to the string we +;;; are hoping to match it up with. In actuality, esi and edi are +;;; both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and edx is +;;; initialized to -(MAX_MATCH_8 - scanalign). +*/ + lea rsi,[r8+r10] + mov rdx, 0xfffffffffffffef8 //; -(MAX_MATCH_8) + lea rsi, [rsi + r13 + 0x0108] //;MAX_MATCH_8] + lea rdi, [r9 + r13 + 0x0108] //;MAX_MATCH_8] + + prefetcht1 [rsi+rdx] + prefetcht1 [rdi+rdx] + +/* +;;; Test the strings for equality, 8 bytes at a time. At the end, +;;; adjust rdx so that it is offset to the exact byte that mismatched. +;;; +;;; We already know at this point that the first three bytes of the +;;; strings match each other, and they can be safely passed over before +;;; starting the compare loop. So what this code does is skip over 0-3 +;;; bytes, as much as necessary in order to dword-align the edi +;;; pointer. (rsi will still be misaligned three times out of four.) +;;; +;;; It should be confessed that this loop usually does not represent +;;; much of the total running time. Replacing it with a more +;;; straightforward "rep cmpsb" would not drastically degrade +;;; performance. +*/ + +LoopCmps: + mov rax, [rsi + rdx] + xor rax, [rdi + rdx] + jnz LeaveLoopCmps + + mov rax, [rsi + rdx + 8] + xor rax, [rdi + rdx + 8] + jnz LeaveLoopCmps8 + + + mov rax, [rsi + rdx + 8+8] + xor rax, [rdi + rdx + 8+8] + jnz LeaveLoopCmps16 + + add rdx,8+8+8 + + BEFORE_JMP + jnz LoopCmps + jmp LenMaximum + AFTER_JMP + +LeaveLoopCmps16: add rdx,8 +LeaveLoopCmps8: add rdx,8 +LeaveLoopCmps: + + test eax, 0x0000FFFF + jnz LenLower + + test eax,0xffffffff + + jnz LenLower32 + + add rdx,4 + shr rax,32 + or ax,ax + BEFORE_JMP + jnz LenLower + AFTER_JMP + +LenLower32: + shr eax,16 + add rdx,2 + +LenLower: + sub al, 1 + adc rdx, 0 +//;;; Calculate the length of the match. If it is longer than MAX_MATCH, +//;;; then automatically accept it as the best possible match and leave. + + lea rax, [rdi + rdx] + sub rax, r9 + cmp eax, MAX_MATCH + BEFORE_JMP + jge LenMaximum + AFTER_JMP +/* +;;; If the length of the match is not longer than the best match we +;;; have so far, then forget it and return to the lookup loop. +;/////////////////////////////////// +*/ + cmp eax, r11d + jg LongerMatch + + lea rsi,[r10+r11] + + mov rdi, prev_ad + mov edx, [chainlenwmask] + BEFORE_JMP + jmp LookupLoop + AFTER_JMP +/* +;;; s->match_start = cur_match; +;;; best_len = len; +;;; if (len >= nice_match) break; +;;; scan_end = *(ushf*)(scan+best_len-1); +*/ +LongerMatch: + mov r11d, eax + mov match_start, r8d + cmp eax, [nicematch] + BEFORE_JMP + jge LeaveNow + AFTER_JMP + + lea rsi,[r10+rax] + + movzx ebx, word ptr [r9 + rax - 1] + mov rdi, prev_ad + mov edx, [chainlenwmask] + BEFORE_JMP + jmp LookupLoop + AFTER_JMP + +//;;; Accept the current string, with the maximum possible length. + +LenMaximum: + mov r11d,MAX_MATCH + mov match_start, r8d + +//;;; if ((uInt)best_len <= s->lookahead) return (uInt)best_len; +//;;; return s->lookahead; + +LeaveNow: + mov eax, Lookahead + cmp r11d, eax + cmovng eax, r11d + + + +//;;; Restore the stack and return from whence we came. + + +// mov rsi,[save_rsi] +// mov rdi,[save_rdi] + mov rbx,[save_rbx] + mov rbp,[save_rbp] + mov r12,[save_r12] + mov r13,[save_r13] + mov r14,[save_r14] + mov r15,[save_r15] + + + ret 0 +//; please don't remove this string ! +//; Your can freely use gvmat64 in any free or commercial app +//; but it is far better don't remove the string in the binary! + // db 0dh,0ah,"asm686 with masm, optimised assembly code from Brian Raiter, written 1998, converted to amd 64 by Gilles Vollant 2005",0dh,0ah,0 + + +match_init: + ret 0 + + diff --git a/lib/libz/crc32.c b/lib/libz/crc32.c index f658a9ef55e..1acc7ed8e49 100644 --- a/lib/libz/crc32.c +++ b/lib/libz/crc32.c @@ -1,5 +1,5 @@ /* crc32.c -- compute the CRC-32 of a data stream - * Copyright (C) 1995-2005 Mark Adler + * Copyright (C) 1995-2006 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h * * Thanks to Rodney Brown for his contribution of faster @@ -53,7 +53,7 @@ /* Definitions for doing the crc four data bytes at a time. */ #ifdef BYFOUR -# define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \ +# define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \ (((w)&0xff00)<<8)+(((w)&0xff)<<24)) local unsigned long crc32_little OF((unsigned long, const unsigned char FAR *, unsigned)); @@ -68,6 +68,8 @@ local unsigned long gf2_matrix_times OF((unsigned long *mat, unsigned long vec)); local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); +local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2); + #ifdef DYNAMIC_CRC_TABLE @@ -367,22 +369,22 @@ local void gf2_matrix_square(square, mat) } /* ========================================================================= */ -uLong ZEXPORT crc32_combine(crc1, crc2, len2) +local uLong crc32_combine_(crc1, crc2, len2) uLong crc1; uLong crc2; - z_off_t len2; + z_off64_t len2; { int n; unsigned long row; unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ - /* degenerate case */ - if (len2 == 0) + /* degenerate case (also disallow negative lengths) */ + if (len2 <= 0) return crc1; /* put operator for one zero bit in odd */ - odd[0] = 0xedb88320L; /* CRC-32 polynomial */ + odd[0] = 0xedb88320UL; /* CRC-32 polynomial */ row = 1; for (n = 1; n < GF2_DIM; n++) { odd[n] = row; @@ -421,3 +423,20 @@ uLong ZEXPORT crc32_combine(crc1, crc2, len2) crc1 ^= crc2; return crc1; } + +/* ========================================================================= */ +uLong ZEXPORT crc32_combine(crc1, crc2, len2) + uLong crc1; + uLong crc2; + z_off_t len2; +{ + return crc32_combine_(crc1, crc2, len2); +} + +uLong ZEXPORT crc32_combine64(crc1, crc2, len2) + uLong crc1; + uLong crc2; + z_off64_t len2; +{ + return crc32_combine_(crc1, crc2, len2); +} diff --git a/lib/libz/deflate.c b/lib/libz/deflate.c index 29ce1f64a57..fcd698cc62f 100644 --- a/lib/libz/deflate.c +++ b/lib/libz/deflate.c @@ -1,5 +1,5 @@ /* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2005 Jean-loup Gailly. + * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -52,7 +52,7 @@ #include "deflate.h" const char deflate_copyright[] = - " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly "; + " deflate 1.2.4 Copyright 1995-2010 Jean-loup Gailly and Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -79,19 +79,18 @@ local block_state deflate_fast OF((deflate_state *s, int flush)); #ifndef FASTEST local block_state deflate_slow OF((deflate_state *s, int flush)); #endif +local block_state deflate_rle OF((deflate_state *s, int flush)); +local block_state deflate_huff OF((deflate_state *s, int flush)); local void lm_init OF((deflate_state *s)); local void putShortMSB OF((deflate_state *s, uInt b)); local void flush_pending OF((z_streamp strm)); local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); -#ifndef FASTEST #ifdef ASMV void match_init OF((void)); /* asm code initialization */ uInt longest_match OF((deflate_state *s, IPos cur_match)); #else local uInt longest_match OF((deflate_state *s, IPos cur_match)); #endif -#endif -local uInt longest_match_fast OF((deflate_state *s, IPos cur_match)); #ifdef DEBUG local void check_match OF((deflate_state *s, IPos start, IPos match, @@ -110,11 +109,6 @@ local void check_match OF((deflate_state *s, IPos start, IPos match, #endif /* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ -#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) -/* Minimum amount of lookahead, except at the end of the input file. - * See deflate.c for comments about the MIN_MATCH+1. - */ - /* Values for max_lazy_match, good_match and max_chain_length, depending on * the desired pack level (0..9). The values given below have been tuned to * exclude worst case performance for pathological files. Better values may be @@ -288,6 +282,8 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); + s->high_water = 0; /* nothing written to s->window yet */ + s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); @@ -332,8 +328,8 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) strm->adler = adler32(strm->adler, dictionary, dictLength); if (length < MIN_MATCH) return Z_OK; - if (length > MAX_DIST(s)) { - length = MAX_DIST(s); + if (length > s->w_size) { + length = s->w_size; dictionary += dictLength - length; /* use the tail of the dictionary */ } zmemcpy(s->window, dictionary, length); @@ -435,9 +431,10 @@ int ZEXPORT deflateParams(strm, level, strategy) } func = configuration_table[s->level].func; - if (func != configuration_table[level].func && strm->total_in != 0) { + if ((strategy != s->strategy || func != configuration_table[level].func) && + strm->total_in != 0) { /* Flush the last buffer: */ - err = deflate(strm, Z_PARTIAL_FLUSH); + err = deflate(strm, Z_BLOCK); } if (s->level != level) { s->level = level; @@ -481,33 +478,66 @@ int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) * resulting from using fixed blocks instead of stored blocks, which deflate * can emit on compressed data for some combinations of the parameters. * - * This function could be more sophisticated to provide closer upper bounds - * for every combination of windowBits and memLevel, as well as wrap. - * But even the conservative upper bound of about 14% expansion does not - * seem onerous for output buffer allocation. + * This function could be more sophisticated to provide closer upper bounds for + * every combination of windowBits and memLevel. But even the conservative + * upper bound of about 14% expansion does not seem onerous for output buffer + * allocation. */ uLong ZEXPORT deflateBound(strm, sourceLen) z_streamp strm; uLong sourceLen; { deflate_state *s; - uLong destLen; + uLong complen, wraplen; + Bytef *str; - /* conservative upper bound */ - destLen = sourceLen + - ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11; + /* conservative upper bound for compressed data */ + complen = sourceLen + + ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; - /* if can't get parameters, return conservative bound */ + /* if can't get parameters, return conservative bound plus zlib wrapper */ if (strm == Z_NULL || strm->state == Z_NULL) - return destLen; + return complen + 6; + + /* compute wrapper length */ + s = strm->state; + switch (s->wrap) { + case 0: /* raw deflate */ + wraplen = 0; + break; + case 1: /* zlib wrapper */ + wraplen = 6 + (s->strstart ? 4 : 0); + break; + case 2: /* gzip wrapper */ + wraplen = 18; + if (s->gzhead != Z_NULL) { /* user-supplied gzip header */ + if (s->gzhead->extra != Z_NULL) + wraplen += 2 + s->gzhead->extra_len; + str = s->gzhead->name; + if (str != Z_NULL) + do { + wraplen++; + } while (*str++); + str = s->gzhead->comment; + if (str != Z_NULL) + do { + wraplen++; + } while (*str++); + if (s->gzhead->hcrc) + wraplen += 2; + } + break; + default: /* for compiler happiness */ + wraplen = 6; + } /* if not default parameters, return conservative bound */ - s = strm->state; if (s->w_bits != 15 || s->hash_bits != 8 + 7) - return destLen; + return complen + wraplen; /* default settings: return tight bound for that case */ - return compressBound(sourceLen); + return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + + (sourceLen >> 25) + 13 - 6 + wraplen; } /* ========================================================================= @@ -557,7 +587,7 @@ int ZEXPORT deflate (strm, flush) deflate_state *s; if (strm == Z_NULL || strm->state == Z_NULL || - flush > Z_FINISH || flush < 0) { + flush > Z_BLOCK || flush < 0) { return Z_STREAM_ERROR; } s = strm->state; @@ -581,7 +611,7 @@ int ZEXPORT deflate (strm, flush) put_byte(s, 31); put_byte(s, 139); put_byte(s, 8); - if (s->gzhead == NULL) { + if (s->gzhead == Z_NULL) { put_byte(s, 0); put_byte(s, 0); put_byte(s, 0); @@ -608,7 +638,7 @@ int ZEXPORT deflate (strm, flush) (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? 4 : 0)); put_byte(s, s->gzhead->os & 0xff); - if (s->gzhead->extra != NULL) { + if (s->gzhead->extra != Z_NULL) { put_byte(s, s->gzhead->extra_len & 0xff); put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); } @@ -650,7 +680,7 @@ int ZEXPORT deflate (strm, flush) } #ifdef GZIP if (s->status == EXTRA_STATE) { - if (s->gzhead->extra != NULL) { + if (s->gzhead->extra != Z_NULL) { uInt beg = s->pending; /* start of bytes to update crc */ while (s->gzindex < (s->gzhead->extra_len & 0xffff)) { @@ -678,7 +708,7 @@ int ZEXPORT deflate (strm, flush) s->status = NAME_STATE; } if (s->status == NAME_STATE) { - if (s->gzhead->name != NULL) { + if (s->gzhead->name != Z_NULL) { uInt beg = s->pending; /* start of bytes to update crc */ int val; @@ -709,7 +739,7 @@ int ZEXPORT deflate (strm, flush) s->status = COMMENT_STATE; } if (s->status == COMMENT_STATE) { - if (s->gzhead->comment != NULL) { + if (s->gzhead->comment != Z_NULL) { uInt beg = s->pending; /* start of bytes to update crc */ int val; @@ -787,7 +817,9 @@ int ZEXPORT deflate (strm, flush) (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { block_state bstate; - bstate = (*(configuration_table[s->level].func))(s, flush); + bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : + (s->strategy == Z_RLE ? deflate_rle(s, flush) : + (*(configuration_table[s->level].func))(s, flush)); if (bstate == finish_started || bstate == finish_done) { s->status = FINISH_STATE; @@ -808,13 +840,17 @@ int ZEXPORT deflate (strm, flush) if (bstate == block_done) { if (flush == Z_PARTIAL_FLUSH) { _tr_align(s); - } else { /* FULL_FLUSH or SYNC_FLUSH */ + } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */ _tr_stored_block(s, (char*)0, 0L, 0); /* For a full flush, this empty block will be recognized * as a special marker by inflate_sync(). */ if (flush == Z_FULL_FLUSH) { CLEAR_HASH(s); /* forget history */ + if (s->lookahead == 0) { + s->strstart = 0; + s->block_start = 0L; + } } } flush_pending(strm); @@ -1167,12 +1203,13 @@ local uInt longest_match(s, cur_match) return s->lookahead; } #endif /* ASMV */ -#endif /* FASTEST */ + +#else /* FASTEST */ /* --------------------------------------------------------------------------- - * Optimized version for level == 1 or strategy == Z_RLE only + * Optimized version for FASTEST only */ -local uInt longest_match_fast(s, cur_match) +local uInt longest_match(s, cur_match) deflate_state *s; IPos cur_match; /* current match */ { @@ -1225,6 +1262,8 @@ local uInt longest_match_fast(s, cur_match) return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; } +#endif /* FASTEST */ + #ifdef DEBUG /* =========================================================================== * Check that the match at match_start is indeed a match. @@ -1303,7 +1342,6 @@ local void fill_window(s) later. (Using level 0 permanently is not an optimal usage of zlib, so we don't care about this pathological case.) */ - /* %%% avoid this when Z_RLE */ n = s->hash_size; p = &s->head[n]; do { @@ -1355,27 +1393,61 @@ local void fill_window(s) */ } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); + + /* If the WIN_INIT bytes after the end of the current data have never been + * written, then zero those bytes in order to avoid memory check reports of + * the use of uninitialized (or uninitialised as Julian writes) bytes by + * the longest match routines. Update the high water mark for the next + * time through here. WIN_INIT is set to MAX_MATCH since the longest match + * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. + */ + if (s->high_water < s->window_size) { + ulg curr = s->strstart + (ulg)(s->lookahead); + ulg init; + + if (s->high_water < curr) { + /* Previous high water mark below current data -- zero WIN_INIT + * bytes or up to end of window, whichever is less. + */ + init = s->window_size - curr; + if (init > WIN_INIT) + init = WIN_INIT; + zmemzero(s->window + curr, (unsigned)init); + s->high_water = curr + init; + } + else if (s->high_water < (ulg)curr + WIN_INIT) { + /* High water mark at or above current data, but below current data + * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up + * to end of window, whichever is less. + */ + init = (ulg)curr + WIN_INIT - s->high_water; + if (init > s->window_size - s->high_water) + init = s->window_size - s->high_water; + zmemzero(s->window + s->high_water, (unsigned)init); + s->high_water += init; + } + } } /* =========================================================================== * Flush the current block, with given end-of-file flag. * IN assertion: strstart is set to the end of the current match. */ -#define FLUSH_BLOCK_ONLY(s, eof) { \ +#define FLUSH_BLOCK_ONLY(s, last) { \ _tr_flush_block(s, (s->block_start >= 0L ? \ (charf *)&s->window[(unsigned)s->block_start] : \ (charf *)Z_NULL), \ (ulg)((long)s->strstart - s->block_start), \ - (eof)); \ + (last)); \ s->block_start = s->strstart; \ flush_pending(s->strm); \ Tracev((stderr,"[FLUSH]")); \ } /* Same but force premature exit if necessary. */ -#define FLUSH_BLOCK(s, eof) { \ - FLUSH_BLOCK_ONLY(s, eof); \ - if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \ +#define FLUSH_BLOCK(s, last) { \ + FLUSH_BLOCK_ONLY(s, last); \ + if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ } /* =========================================================================== @@ -1449,7 +1521,7 @@ local block_state deflate_fast(s, flush) deflate_state *s; int flush; { - IPos hash_head = NIL; /* head of the hash chain */ + IPos hash_head; /* head of the hash chain */ int bflush; /* set if current block must be flushed */ for (;;) { @@ -1469,6 +1541,7 @@ local block_state deflate_fast(s, flush) /* Insert the string window[strstart .. strstart+2] in the * dictionary, and set hash_head to the head of the hash chain: */ + hash_head = NIL; if (s->lookahead >= MIN_MATCH) { INSERT_STRING(s, s->strstart, hash_head); } @@ -1481,19 +1554,8 @@ local block_state deflate_fast(s, flush) * of window index 0 (in particular we have to avoid a match * of the string with itself at the start of the input file). */ -#ifdef FASTEST - if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) || - (s->strategy == Z_RLE && s->strstart - hash_head == 1)) { - s->match_length = longest_match_fast (s, hash_head); - } -#else - if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) { - s->match_length = longest_match (s, hash_head); - } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) { - s->match_length = longest_match_fast (s, hash_head); - } -#endif - /* longest_match() or longest_match_fast() sets match_start */ + s->match_length = longest_match (s, hash_head); + /* longest_match() sets match_start */ } if (s->match_length >= MIN_MATCH) { check_match(s, s->strstart, s->match_start, s->match_length); @@ -1555,7 +1617,7 @@ local block_state deflate_slow(s, flush) deflate_state *s; int flush; { - IPos hash_head = NIL; /* head of hash chain */ + IPos hash_head; /* head of hash chain */ int bflush; /* set if current block must be flushed */ /* Process the input block. */ @@ -1576,6 +1638,7 @@ local block_state deflate_slow(s, flush) /* Insert the string window[strstart .. strstart+2] in the * dictionary, and set hash_head to the head of the hash chain: */ + hash_head = NIL; if (s->lookahead >= MIN_MATCH) { INSERT_STRING(s, s->strstart, hash_head); } @@ -1591,12 +1654,8 @@ local block_state deflate_slow(s, flush) * of window index 0 (in particular we have to avoid a match * of the string with itself at the start of the input file). */ - if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) { - s->match_length = longest_match (s, hash_head); - } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) { - s->match_length = longest_match_fast (s, hash_head); - } - /* longest_match() or longest_match_fast() sets match_start */ + s->match_length = longest_match (s, hash_head); + /* longest_match() sets match_start */ if (s->match_length <= 5 && (s->strategy == Z_FILTERED #if TOO_FAR <= 32767 @@ -1674,7 +1733,6 @@ local block_state deflate_slow(s, flush) } #endif /* FASTEST */ -#if 0 /* =========================================================================== * For Z_RLE, simply look for runs of bytes, generate matches only of distance * one. Do not maintain a hash table. (It will be regenerated if this run of @@ -1684,11 +1742,9 @@ local block_state deflate_rle(s, flush) deflate_state *s; int flush; { - int bflush; /* set if current block must be flushed */ - uInt run; /* length of run */ - uInt max; /* maximum length of run */ - uInt prev; /* byte at distance one to match */ - Bytef *scan; /* scan for end of run */ + int bflush; /* set if current block must be flushed */ + uInt prev; /* byte at distance one to match */ + Bytef *scan, *strend; /* scan goes up to strend for length of run */ for (;;) { /* Make sure that we always have enough lookahead, except @@ -1704,23 +1760,33 @@ local block_state deflate_rle(s, flush) } /* See how many times the previous byte repeats */ - run = 0; - if (s->strstart > 0) { /* if there is a previous byte, that is */ - max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH; + s->match_length = 0; + if (s->lookahead >= MIN_MATCH && s->strstart > 0) { scan = s->window + s->strstart - 1; - prev = *scan++; - do { - if (*scan++ != prev) - break; - } while (++run < max); + prev = *scan; + if (prev == *++scan && prev == *++scan && prev == *++scan) { + strend = s->window + s->strstart + MAX_MATCH; + do { + } while (prev == *++scan && prev == *++scan && + prev == *++scan && prev == *++scan && + prev == *++scan && prev == *++scan && + prev == *++scan && prev == *++scan && + scan < strend); + s->match_length = MAX_MATCH - (int)(strend - scan); + if (s->match_length > s->lookahead) + s->match_length = s->lookahead; + } } /* Emit match if have run of MIN_MATCH or longer, else emit literal */ - if (run >= MIN_MATCH) { - check_match(s, s->strstart, s->strstart - 1, run); - _tr_tally_dist(s, 1, run - MIN_MATCH, bflush); - s->lookahead -= run; - s->strstart += run; + if (s->match_length >= MIN_MATCH) { + check_match(s, s->strstart, s->strstart - 1, s->match_length); + + _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush); + + s->lookahead -= s->match_length; + s->strstart += s->match_length; + s->match_length = 0; } else { /* No match, output a literal byte */ Tracevv((stderr,"%c", s->window[s->strstart])); @@ -1733,4 +1799,36 @@ local block_state deflate_rle(s, flush) FLUSH_BLOCK(s, flush == Z_FINISH); return flush == Z_FINISH ? finish_done : block_done; } -#endif + +/* =========================================================================== + * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. + * (It will be regenerated if this run of deflate switches away from Huffman.) + */ +local block_state deflate_huff(s, flush) + deflate_state *s; + int flush; +{ + int bflush; /* set if current block must be flushed */ + + for (;;) { + /* Make sure that we have a literal to write. */ + if (s->lookahead == 0) { + fill_window(s); + if (s->lookahead == 0) { + if (flush == Z_NO_FLUSH) + return need_more; + break; /* flush the current block */ + } + } + + /* Output a literal byte */ + s->match_length = 0; + Tracevv((stderr,"%c", s->window[s->strstart])); + _tr_tally_lit (s, s->window[s->strstart], bflush); + s->lookahead--; + s->strstart++; + if (bflush) FLUSH_BLOCK(s, 0); + } + FLUSH_BLOCK(s, flush == Z_FINISH); + return flush == Z_FINISH ? finish_done : block_done; +} diff --git a/lib/libz/deflate.h b/lib/libz/deflate.h index 05a5ab3a2c1..f53deba852b 100644 --- a/lib/libz/deflate.h +++ b/lib/libz/deflate.h @@ -1,5 +1,5 @@ /* deflate.h -- internal compression state - * Copyright (C) 1995-2004 Jean-loup Gailly + * Copyright (C) 1995-2009 Jean-loup Gailly * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -260,6 +260,13 @@ typedef struct internal_state { * are always zero. */ + ulg high_water; + /* High water mark offset in window for initialized bytes -- bytes above + * this are set to zero in order to avoid memory check warnings when + * longest match routines access bytes past the input. This is then + * updated to the new high water mark. + */ + } FAR deflate_state; /* Output a byte on the stream. @@ -278,14 +285,18 @@ typedef struct internal_state { * distances are limited to MAX_DIST instead of WSIZE. */ +#define WIN_INIT MAX_MATCH +/* Number of bytes after end of data in window to initialize in order to avoid + memory checker errors from longest match routines */ + /* in trees.c */ void _tr_init OF((deflate_state *s)); int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len, - int eof)); + int last)); void _tr_align OF((deflate_state *s)); void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len, - int eof)); + int last)); #define d_code(dist) \ ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) diff --git a/lib/libz/algorithm.txt b/lib/libz/doc/algorithm.txt similarity index 99% rename from lib/libz/algorithm.txt rename to lib/libz/doc/algorithm.txt index b022dde312a..34960bddacc 100644 --- a/lib/libz/algorithm.txt +++ b/lib/libz/doc/algorithm.txt @@ -121,7 +121,7 @@ At least for deflate's output that generates new trees every several 10's of kbytes. You can imagine that filling in a 2^15 entry table for a 15-bit code would take too long if you're only decoding several thousand symbols. At the other extreme, you could make a new table for every bit in the code. In fact, -that's essentially a Huffman tree. But then you spend two much time +that's essentially a Huffman tree. But then you spend too much time traversing the tree while decoding, even for short symbols. So the number of bits for the first lookup table is a trade of the time to diff --git a/lib/libz/doc/rfc1950.txt b/lib/libz/doc/rfc1950.txt new file mode 100644 index 00000000000..ce6428a0f2e --- /dev/null +++ b/lib/libz/doc/rfc1950.txt @@ -0,0 +1,619 @@ + + + + + + +Network Working Group P. Deutsch +Request for Comments: 1950 Aladdin Enterprises +Category: Informational J-L. Gailly + Info-ZIP + May 1996 + + + ZLIB Compressed Data Format Specification version 3.3 + +Status of This Memo + + This memo provides information for the Internet community. This memo + does not specify an Internet standard of any kind. Distribution of + this memo is unlimited. + +IESG Note: + + The IESG takes no position on the validity of any Intellectual + Property Rights statements contained in this document. + +Notices + + Copyright (c) 1996 L. Peter Deutsch and Jean-Loup Gailly + + Permission is granted to copy and distribute this document for any + purpose and without charge, including translations into other + languages and incorporation into compilations, provided that the + copyright notice and this notice are preserved, and that any + substantive changes or deletions from the original are clearly + marked. + + A pointer to the latest version of this and related documentation in + HTML format can be found at the URL + . + +Abstract + + This specification defines a lossless compressed data format. The + data can be produced or consumed, even for an arbitrarily long + sequentially presented input data stream, using only an a priori + bounded amount of intermediate storage. The format presently uses + the DEFLATE compression method but can be easily extended to use + other compression methods. It can be implemented readily in a manner + not covered by patents. This specification also defines the ADLER-32 + checksum (an extension and improvement of the Fletcher checksum), + used for detection of data corruption, and provides an algorithm for + computing it. + + + + +Deutsch & Gailly Informational [Page 1] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + +Table of Contents + + 1. Introduction ................................................... 2 + 1.1. Purpose ................................................... 2 + 1.2. Intended audience ......................................... 3 + 1.3. Scope ..................................................... 3 + 1.4. Compliance ................................................ 3 + 1.5. Definitions of terms and conventions used ................ 3 + 1.6. Changes from previous versions ............................ 3 + 2. Detailed specification ......................................... 3 + 2.1. Overall conventions ....................................... 3 + 2.2. Data format ............................................... 4 + 2.3. Compliance ................................................ 7 + 3. References ..................................................... 7 + 4. Source code .................................................... 8 + 5. Security Considerations ........................................ 8 + 6. Acknowledgements ............................................... 8 + 7. Authors' Addresses ............................................. 8 + 8. Appendix: Rationale ............................................ 9 + 9. Appendix: Sample code ..........................................10 + +1. Introduction + + 1.1. Purpose + + The purpose of this specification is to define a lossless + compressed data format that: + + * Is independent of CPU type, operating system, file system, + and character set, and hence can be used for interchange; + + * Can be produced or consumed, even for an arbitrarily long + sequentially presented input data stream, using only an a + priori bounded amount of intermediate storage, and hence can + be used in data communications or similar structures such as + Unix filters; + + * Can use a number of different compression methods; + + * Can be implemented readily in a manner not covered by + patents, and hence can be practiced freely. + + The data format defined by this specification does not attempt to + allow random access to compressed data. + + + + + + + +Deutsch & Gailly Informational [Page 2] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + + 1.2. Intended audience + + This specification is intended for use by implementors of software + to compress data into zlib format and/or decompress data from zlib + format. + + The text of the specification assumes a basic background in + programming at the level of bits and other primitive data + representations. + + 1.3. Scope + + The specification specifies a compressed data format that can be + used for in-memory compression of a sequence of arbitrary bytes. + + 1.4. Compliance + + Unless otherwise indicated below, a compliant decompressor must be + able to accept and decompress any data set that conforms to all + the specifications presented here; a compliant compressor must + produce data sets that conform to all the specifications presented + here. + + 1.5. Definitions of terms and conventions used + + byte: 8 bits stored or transmitted as a unit (same as an octet). + (For this specification, a byte is exactly 8 bits, even on + machines which store a character on a number of bits different + from 8.) See below, for the numbering of bits within a byte. + + 1.6. Changes from previous versions + + Version 3.1 was the first public release of this specification. + In version 3.2, some terminology was changed and the Adler-32 + sample code was rewritten for clarity. In version 3.3, the + support for a preset dictionary was introduced, and the + specification was converted to RFC style. + +2. Detailed specification + + 2.1. Overall conventions + + In the diagrams below, a box like this: + + +---+ + | | <-- the vertical bars might be missing + +---+ + + + + +Deutsch & Gailly Informational [Page 3] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + + represents one byte; a box like this: + + +==============+ + | | + +==============+ + + represents a variable number of bytes. + + Bytes stored within a computer do not have a "bit order", since + they are always treated as a unit. However, a byte considered as + an integer between 0 and 255 does have a most- and least- + significant bit, and since we write numbers with the most- + significant digit on the left, we also write bytes with the most- + significant bit on the left. In the diagrams below, we number the + bits of a byte so that bit 0 is the least-significant bit, i.e., + the bits are numbered: + + +--------+ + |76543210| + +--------+ + + Within a computer, a number may occupy multiple bytes. All + multi-byte numbers in the format described here are stored with + the MOST-significant byte first (at the lower memory address). + For example, the decimal number 520 is stored as: + + 0 1 + +--------+--------+ + |00000010|00001000| + +--------+--------+ + ^ ^ + | | + | + less significant byte = 8 + + more significant byte = 2 x 256 + + 2.2. Data format + + A zlib stream has the following structure: + + 0 1 + +---+---+ + |CMF|FLG| (more-->) + +---+---+ + + + + + + + + +Deutsch & Gailly Informational [Page 4] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + + (if FLG.FDICT set) + + 0 1 2 3 + +---+---+---+---+ + | DICTID | (more-->) + +---+---+---+---+ + + +=====================+---+---+---+---+ + |...compressed data...| ADLER32 | + +=====================+---+---+---+---+ + + Any data which may appear after ADLER32 are not part of the zlib + stream. + + CMF (Compression Method and flags) + This byte is divided into a 4-bit compression method and a 4- + bit information field depending on the compression method. + + bits 0 to 3 CM Compression method + bits 4 to 7 CINFO Compression info + + CM (Compression method) + This identifies the compression method used in the file. CM = 8 + denotes the "deflate" compression method with a window size up + to 32K. This is the method used by gzip and PNG (see + references [1] and [2] in Chapter 3, below, for the reference + documents). CM = 15 is reserved. It might be used in a future + version of this specification to indicate the presence of an + extra field before the compressed data. + + CINFO (Compression info) + For CM = 8, CINFO is the base-2 logarithm of the LZ77 window + size, minus eight (CINFO=7 indicates a 32K window size). Values + of CINFO above 7 are not allowed in this version of the + specification. CINFO is not defined in this specification for + CM not equal to 8. + + FLG (FLaGs) + This flag byte is divided as follows: + + bits 0 to 4 FCHECK (check bits for CMF and FLG) + bit 5 FDICT (preset dictionary) + bits 6 to 7 FLEVEL (compression level) + + The FCHECK value must be such that CMF and FLG, when viewed as + a 16-bit unsigned integer stored in MSB order (CMF*256 + FLG), + is a multiple of 31. + + + + +Deutsch & Gailly Informational [Page 5] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + + FDICT (Preset dictionary) + If FDICT is set, a DICT dictionary identifier is present + immediately after the FLG byte. The dictionary is a sequence of + bytes which are initially fed to the compressor without + producing any compressed output. DICT is the Adler-32 checksum + of this sequence of bytes (see the definition of ADLER32 + below). The decompressor can use this identifier to determine + which dictionary has been used by the compressor. + + FLEVEL (Compression level) + These flags are available for use by specific compression + methods. The "deflate" method (CM = 8) sets these flags as + follows: + + 0 - compressor used fastest algorithm + 1 - compressor used fast algorithm + 2 - compressor used default algorithm + 3 - compressor used maximum compression, slowest algorithm + + The information in FLEVEL is not needed for decompression; it + is there to indicate if recompression might be worthwhile. + + compressed data + For compression method 8, the compressed data is stored in the + deflate compressed data format as described in the document + "DEFLATE Compressed Data Format Specification" by L. Peter + Deutsch. (See reference [3] in Chapter 3, below) + + Other compressed data formats are not specified in this version + of the zlib specification. + + ADLER32 (Adler-32 checksum) + This contains a checksum value of the uncompressed data + (excluding any dictionary data) computed according to Adler-32 + algorithm. This algorithm is a 32-bit extension and improvement + of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073 + standard. See references [4] and [5] in Chapter 3, below) + + Adler-32 is composed of two sums accumulated per byte: s1 is + the sum of all bytes, s2 is the sum of all s1 values. Both sums + are done modulo 65521. s1 is initialized to 1, s2 to zero. The + Adler-32 checksum is stored as s2*65536 + s1 in most- + significant-byte first (network) order. + + + + + + + + +Deutsch & Gailly Informational [Page 6] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + + 2.3. Compliance + + A compliant compressor must produce streams with correct CMF, FLG + and ADLER32, but need not support preset dictionaries. When the + zlib data format is used as part of another standard data format, + the compressor may use only preset dictionaries that are specified + by this other data format. If this other format does not use the + preset dictionary feature, the compressor must not set the FDICT + flag. + + A compliant decompressor must check CMF, FLG, and ADLER32, and + provide an error indication if any of these have incorrect values. + A compliant decompressor must give an error indication if CM is + not one of the values defined in this specification (only the + value 8 is permitted in this version), since another value could + indicate the presence of new features that would cause subsequent + data to be interpreted incorrectly. A compliant decompressor must + give an error indication if FDICT is set and DICTID is not the + identifier of a known preset dictionary. A decompressor may + ignore FLEVEL and still be compliant. When the zlib data format + is being used as a part of another standard format, a compliant + decompressor must support all the preset dictionaries specified by + the other format. When the other format does not use the preset + dictionary feature, a compliant decompressor must reject any + stream in which the FDICT flag is set. + +3. References + + [1] Deutsch, L.P.,"GZIP Compressed Data Format Specification", + available in ftp://ftp.uu.net/pub/archiving/zip/doc/ + + [2] Thomas Boutell, "PNG (Portable Network Graphics) specification", + available in ftp://ftp.uu.net/graphics/png/documents/ + + [3] Deutsch, L.P.,"DEFLATE Compressed Data Format Specification", + available in ftp://ftp.uu.net/pub/archiving/zip/doc/ + + [4] Fletcher, J. G., "An Arithmetic Checksum for Serial + Transmissions," IEEE Transactions on Communications, Vol. COM-30, + No. 1, January 1982, pp. 247-252. + + [5] ITU-T Recommendation X.224, Annex D, "Checksum Algorithms," + November, 1993, pp. 144, 145. (Available from + gopher://info.itu.ch). ITU-T X.244 is also the same as ISO 8073. + + + + + + + +Deutsch & Gailly Informational [Page 7] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + +4. Source code + + Source code for a C language implementation of a "zlib" compliant + library is available at ftp://ftp.uu.net/pub/archiving/zip/zlib/. + +5. Security Considerations + + A decoder that fails to check the ADLER32 checksum value may be + subject to undetected data corruption. + +6. Acknowledgements + + Trademarks cited in this document are the property of their + respective owners. + + Jean-Loup Gailly and Mark Adler designed the zlib format and wrote + the related software described in this specification. Glenn + Randers-Pehrson converted this document to RFC and HTML format. + +7. Authors' Addresses + + L. Peter Deutsch + Aladdin Enterprises + 203 Santa Margarita Ave. + Menlo Park, CA 94025 + + Phone: (415) 322-0103 (AM only) + FAX: (415) 322-1734 + EMail: + + + Jean-Loup Gailly + + EMail: + + Questions about the technical content of this specification can be + sent by email to + + Jean-Loup Gailly and + Mark Adler + + Editorial comments on this specification can be sent by email to + + L. Peter Deutsch and + Glenn Randers-Pehrson + + + + + + +Deutsch & Gailly Informational [Page 8] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + +8. Appendix: Rationale + + 8.1. Preset dictionaries + + A preset dictionary is specially useful to compress short input + sequences. The compressor can take advantage of the dictionary + context to encode the input in a more compact manner. The + decompressor can be initialized with the appropriate context by + virtually decompressing a compressed version of the dictionary + without producing any output. However for certain compression + algorithms such as the deflate algorithm this operation can be + achieved without actually performing any decompression. + + The compressor and the decompressor must use exactly the same + dictionary. The dictionary may be fixed or may be chosen among a + certain number of predefined dictionaries, according to the kind + of input data. The decompressor can determine which dictionary has + been chosen by the compressor by checking the dictionary + identifier. This document does not specify the contents of + predefined dictionaries, since the optimal dictionaries are + application specific. Standard data formats using this feature of + the zlib specification must precisely define the allowed + dictionaries. + + 8.2. The Adler-32 algorithm + + The Adler-32 algorithm is much faster than the CRC32 algorithm yet + still provides an extremely low probability of undetected errors. + + The modulo on unsigned long accumulators can be delayed for 5552 + bytes, so the modulo operation time is negligible. If the bytes + are a, b, c, the second sum is 3a + 2b + c + 3, and so is position + and order sensitive, unlike the first sum, which is just a + checksum. That 65521 is prime is important to avoid a possible + large class of two-byte errors that leave the check unchanged. + (The Fletcher checksum uses 255, which is not prime and which also + makes the Fletcher check insensitive to single byte changes 0 <-> + 255.) + + The sum s1 is initialized to 1 instead of zero to make the length + of the sequence part of s2, so that the length does not have to be + checked separately. (Any sequence of zeroes has a Fletcher + checksum of zero.) + + + + + + + + +Deutsch & Gailly Informational [Page 9] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + +9. Appendix: Sample code + + The following C code computes the Adler-32 checksum of a data buffer. + It is written for clarity, not for speed. The sample code is in the + ANSI C programming language. Non C users may find it easier to read + with these hints: + + & Bitwise AND operator. + >> Bitwise right shift operator. When applied to an + unsigned quantity, as here, right shift inserts zero bit(s) + at the left. + << Bitwise left shift operator. Left shift inserts zero + bit(s) at the right. + ++ "n++" increments the variable n. + % modulo operator: a % b is the remainder of a divided by b. + + #define BASE 65521 /* largest prime smaller than 65536 */ + + /* + Update a running Adler-32 checksum with the bytes buf[0..len-1] + and return the updated checksum. The Adler-32 checksum should be + initialized to 1. + + Usage example: + + unsigned long adler = 1L; + + while (read_buffer(buffer, length) != EOF) { + adler = update_adler32(adler, buffer, length); + } + if (adler != original_adler) error(); + */ + unsigned long update_adler32(unsigned long adler, + unsigned char *buf, int len) + { + unsigned long s1 = adler & 0xffff; + unsigned long s2 = (adler >> 16) & 0xffff; + int n; + + for (n = 0; n < len; n++) { + s1 = (s1 + buf[n]) % BASE; + s2 = (s2 + s1) % BASE; + } + return (s2 << 16) + s1; + } + + /* Return the adler32 of the bytes buf[0..len-1] */ + + + + +Deutsch & Gailly Informational [Page 10] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + + unsigned long adler32(unsigned char *buf, int len) + { + return update_adler32(1L, buf, len); + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Deutsch & Gailly Informational [Page 11] + diff --git a/lib/libz/doc/rfc1951.txt b/lib/libz/doc/rfc1951.txt new file mode 100644 index 00000000000..403c8c722ff --- /dev/null +++ b/lib/libz/doc/rfc1951.txt @@ -0,0 +1,955 @@ + + + + + + +Network Working Group P. Deutsch +Request for Comments: 1951 Aladdin Enterprises +Category: Informational May 1996 + + + DEFLATE Compressed Data Format Specification version 1.3 + +Status of This Memo + + This memo provides information for the Internet community. This memo + does not specify an Internet standard of any kind. Distribution of + this memo is unlimited. + +IESG Note: + + The IESG takes no position on the validity of any Intellectual + Property Rights statements contained in this document. + +Notices + + Copyright (c) 1996 L. Peter Deutsch + + Permission is granted to copy and distribute this document for any + purpose and without charge, including translations into other + languages and incorporation into compilations, provided that the + copyright notice and this notice are preserved, and that any + substantive changes or deletions from the original are clearly + marked. + + A pointer to the latest version of this and related documentation in + HTML format can be found at the URL + . + +Abstract + + This specification defines a lossless compressed data format that + compresses data using a combination of the LZ77 algorithm and Huffman + coding, with efficiency comparable to the best currently available + general-purpose compression methods. The data can be produced or + consumed, even for an arbitrarily long sequentially presented input + data stream, using only an a priori bounded amount of intermediate + storage. The format can be implemented readily in a manner not + covered by patents. + + + + + + + + +Deutsch Informational [Page 1] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + +Table of Contents + + 1. Introduction ................................................... 2 + 1.1. Purpose ................................................... 2 + 1.2. Intended audience ......................................... 3 + 1.3. Scope ..................................................... 3 + 1.4. Compliance ................................................ 3 + 1.5. Definitions of terms and conventions used ................ 3 + 1.6. Changes from previous versions ............................ 4 + 2. Compressed representation overview ............................. 4 + 3. Detailed specification ......................................... 5 + 3.1. Overall conventions ....................................... 5 + 3.1.1. Packing into bytes .................................. 5 + 3.2. Compressed block format ................................... 6 + 3.2.1. Synopsis of prefix and Huffman coding ............... 6 + 3.2.2. Use of Huffman coding in the "deflate" format ....... 7 + 3.2.3. Details of block format ............................. 9 + 3.2.4. Non-compressed blocks (BTYPE=00) ................... 11 + 3.2.5. Compressed blocks (length and distance codes) ...... 11 + 3.2.6. Compression with fixed Huffman codes (BTYPE=01) .... 12 + 3.2.7. Compression with dynamic Huffman codes (BTYPE=10) .. 13 + 3.3. Compliance ............................................... 14 + 4. Compression algorithm details ................................. 14 + 5. References .................................................... 16 + 6. Security Considerations ....................................... 16 + 7. Source code ................................................... 16 + 8. Acknowledgements .............................................. 16 + 9. Author's Address .............................................. 17 + +1. Introduction + + 1.1. Purpose + + The purpose of this specification is to define a lossless + compressed data format that: + * Is independent of CPU type, operating system, file system, + and character set, and hence can be used for interchange; + * Can be produced or consumed, even for an arbitrarily long + sequentially presented input data stream, using only an a + priori bounded amount of intermediate storage, and hence + can be used in data communications or similar structures + such as Unix filters; + * Compresses data with efficiency comparable to the best + currently available general-purpose compression methods, + and in particular considerably better than the "compress" + program; + * Can be implemented readily in a manner not covered by + patents, and hence can be practiced freely; + + + +Deutsch Informational [Page 2] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + * Is compatible with the file format produced by the current + widely used gzip utility, in that conforming decompressors + will be able to read data produced by the existing gzip + compressor. + + The data format defined by this specification does not attempt to: + + * Allow random access to compressed data; + * Compress specialized data (e.g., raster graphics) as well + as the best currently available specialized algorithms. + + A simple counting argument shows that no lossless compression + algorithm can compress every possible input data set. For the + format defined here, the worst case expansion is 5 bytes per 32K- + byte block, i.e., a size increase of 0.015% for large data sets. + English text usually compresses by a factor of 2.5 to 3; + executable files usually compress somewhat less; graphical data + such as raster images may compress much more. + + 1.2. Intended audience + + This specification is intended for use by implementors of software + to compress data into "deflate" format and/or decompress data from + "deflate" format. + + The text of the specification assumes a basic background in + programming at the level of bits and other primitive data + representations. Familiarity with the technique of Huffman coding + is helpful but not required. + + 1.3. Scope + + The specification specifies a method for representing a sequence + of bytes as a (usually shorter) sequence of bits, and a method for + packing the latter bit sequence into bytes. + + 1.4. Compliance + + Unless otherwise indicated below, a compliant decompressor must be + able to accept and decompress any data set that conforms to all + the specifications presented here; a compliant compressor must + produce data sets that conform to all the specifications presented + here. + + 1.5. Definitions of terms and conventions used + + Byte: 8 bits stored or transmitted as a unit (same as an octet). + For this specification, a byte is exactly 8 bits, even on machines + + + +Deutsch Informational [Page 3] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + which store a character on a number of bits different from eight. + See below, for the numbering of bits within a byte. + + String: a sequence of arbitrary bytes. + + 1.6. Changes from previous versions + + There have been no technical changes to the deflate format since + version 1.1 of this specification. In version 1.2, some + terminology was changed. Version 1.3 is a conversion of the + specification to RFC style. + +2. Compressed representation overview + + A compressed data set consists of a series of blocks, corresponding + to successive blocks of input data. The block sizes are arbitrary, + except that non-compressible blocks are limited to 65,535 bytes. + + Each block is compressed using a combination of the LZ77 algorithm + and Huffman coding. The Huffman trees for each block are independent + of those for previous or subsequent blocks; the LZ77 algorithm may + use a reference to a duplicated string occurring in a previous block, + up to 32K input bytes before. + + Each block consists of two parts: a pair of Huffman code trees that + describe the representation of the compressed data part, and a + compressed data part. (The Huffman trees themselves are compressed + using Huffman encoding.) The compressed data consists of a series of + elements of two types: literal bytes (of strings that have not been + detected as duplicated within the previous 32K input bytes), and + pointers to duplicated strings, where a pointer is represented as a + pair . The representation used in the + "deflate" format limits distances to 32K bytes and lengths to 258 + bytes, but does not limit the size of a block, except for + uncompressible blocks, which are limited as noted above. + + Each type of value (literals, distances, and lengths) in the + compressed data is represented using a Huffman code, using one code + tree for literals and lengths and a separate code tree for distances. + The code trees for each block appear in a compact form just before + the compressed data for that block. + + + + + + + + + + +Deutsch Informational [Page 4] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + +3. Detailed specification + + 3.1. Overall conventions In the diagrams below, a box like this: + + +---+ + | | <-- the vertical bars might be missing + +---+ + + represents one byte; a box like this: + + +==============+ + | | + +==============+ + + represents a variable number of bytes. + + Bytes stored within a computer do not have a "bit order", since + they are always treated as a unit. However, a byte considered as + an integer between 0 and 255 does have a most- and least- + significant bit, and since we write numbers with the most- + significant digit on the left, we also write bytes with the most- + significant bit on the left. In the diagrams below, we number the + bits of a byte so that bit 0 is the least-significant bit, i.e., + the bits are numbered: + + +--------+ + |76543210| + +--------+ + + Within a computer, a number may occupy multiple bytes. All + multi-byte numbers in the format described here are stored with + the least-significant byte first (at the lower memory address). + For example, the decimal number 520 is stored as: + + 0 1 + +--------+--------+ + |00001000|00000010| + +--------+--------+ + ^ ^ + | | + | + more significant byte = 2 x 256 + + less significant byte = 8 + + 3.1.1. Packing into bytes + + This document does not address the issue of the order in which + bits of a byte are transmitted on a bit-sequential medium, + since the final data format described here is byte- rather than + + + +Deutsch Informational [Page 5] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + bit-oriented. However, we describe the compressed block format + in below, as a sequence of data elements of various bit + lengths, not a sequence of bytes. We must therefore specify + how to pack these data elements into bytes to form the final + compressed byte sequence: + + * Data elements are packed into bytes in order of + increasing bit number within the byte, i.e., starting + with the least-significant bit of the byte. + * Data elements other than Huffman codes are packed + starting with the least-significant bit of the data + element. + * Huffman codes are packed starting with the most- + significant bit of the code. + + In other words, if one were to print out the compressed data as + a sequence of bytes, starting with the first byte at the + *right* margin and proceeding to the *left*, with the most- + significant bit of each byte on the left as usual, one would be + able to parse the result from right to left, with fixed-width + elements in the correct MSB-to-LSB order and Huffman codes in + bit-reversed order (i.e., with the first bit of the code in the + relative LSB position). + + 3.2. Compressed block format + + 3.2.1. Synopsis of prefix and Huffman coding + + Prefix coding represents symbols from an a priori known + alphabet by bit sequences (codes), one code for each symbol, in + a manner such that different symbols may be represented by bit + sequences of different lengths, but a parser can always parse + an encoded string unambiguously symbol-by-symbol. + + We define a prefix code in terms of a binary tree in which the + two edges descending from each non-leaf node are labeled 0 and + 1 and in which the leaf nodes correspond one-for-one with (are + labeled with) the symbols of the alphabet; then the code for a + symbol is the sequence of 0's and 1's on the edges leading from + the root to the leaf labeled with that symbol. For example: + + + + + + + + + + + +Deutsch Informational [Page 6] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + /\ Symbol Code + 0 1 ------ ---- + / \ A 00 + /\ B B 1 + 0 1 C 011 + / \ D 010 + A /\ + 0 1 + / \ + D C + + A parser can decode the next symbol from an encoded input + stream by walking down the tree from the root, at each step + choosing the edge corresponding to the next input bit. + + Given an alphabet with known symbol frequencies, the Huffman + algorithm allows the construction of an optimal prefix code + (one which represents strings with those symbol frequencies + using the fewest bits of any possible prefix codes for that + alphabet). Such a code is called a Huffman code. (See + reference [1] in Chapter 5, references for additional + information on Huffman codes.) + + Note that in the "deflate" format, the Huffman codes for the + various alphabets must not exceed certain maximum code lengths. + This constraint complicates the algorithm for computing code + lengths from symbol frequencies. Again, see Chapter 5, + references for details. + + 3.2.2. Use of Huffman coding in the "deflate" format + + The Huffman codes used for each alphabet in the "deflate" + format have two additional rules: + + * All codes of a given bit length have lexicographically + consecutive values, in the same order as the symbols + they represent; + + * Shorter codes lexicographically precede longer codes. + + + + + + + + + + + + +Deutsch Informational [Page 7] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + We could recode the example above to follow this rule as + follows, assuming that the order of the alphabet is ABCD: + + Symbol Code + ------ ---- + A 10 + B 0 + C 110 + D 111 + + I.e., 0 precedes 10 which precedes 11x, and 110 and 111 are + lexicographically consecutive. + + Given this rule, we can define the Huffman code for an alphabet + just by giving the bit lengths of the codes for each symbol of + the alphabet in order; this is sufficient to determine the + actual codes. In our example, the code is completely defined + by the sequence of bit lengths (2, 1, 3, 3). The following + algorithm generates the codes as integers, intended to be read + from most- to least-significant bit. The code lengths are + initially in tree[I].Len; the codes are produced in + tree[I].Code. + + 1) Count the number of codes for each code length. Let + bl_count[N] be the number of codes of length N, N >= 1. + + 2) Find the numerical value of the smallest code for each + code length: + + code = 0; + bl_count[0] = 0; + for (bits = 1; bits <= MAX_BITS; bits++) { + code = (code + bl_count[bits-1]) << 1; + next_code[bits] = code; + } + + 3) Assign numerical values to all codes, using consecutive + values for all codes of the same length with the base + values determined at step 2. Codes that are never used + (which have a bit length of zero) must not be assigned a + value. + + for (n = 0; n <= max_code; n++) { + len = tree[n].Len; + if (len != 0) { + tree[n].Code = next_code[len]; + next_code[len]++; + } + + + +Deutsch Informational [Page 8] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + } + + Example: + + Consider the alphabet ABCDEFGH, with bit lengths (3, 3, 3, 3, + 3, 2, 4, 4). After step 1, we have: + + N bl_count[N] + - ----------- + 2 1 + 3 5 + 4 2 + + Step 2 computes the following next_code values: + + N next_code[N] + - ------------ + 1 0 + 2 0 + 3 2 + 4 14 + + Step 3 produces the following code values: + + Symbol Length Code + ------ ------ ---- + A 3 010 + B 3 011 + C 3 100 + D 3 101 + E 3 110 + F 2 00 + G 4 1110 + H 4 1111 + + 3.2.3. Details of block format + + Each block of compressed data begins with 3 header bits + containing the following data: + + first bit BFINAL + next 2 bits BTYPE + + Note that the header bits do not necessarily begin on a byte + boundary, since a block does not necessarily occupy an integral + number of bytes. + + + + + +Deutsch Informational [Page 9] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + BFINAL is set if and only if this is the last block of the data + set. + + BTYPE specifies how the data are compressed, as follows: + + 00 - no compression + 01 - compressed with fixed Huffman codes + 10 - compressed with dynamic Huffman codes + 11 - reserved (error) + + The only difference between the two compressed cases is how the + Huffman codes for the literal/length and distance alphabets are + defined. + + In all cases, the decoding algorithm for the actual data is as + follows: + + do + read block header from input stream. + if stored with no compression + skip any remaining bits in current partially + processed byte + read LEN and NLEN (see next section) + copy LEN bytes of data to output + otherwise + if compressed with dynamic Huffman codes + read representation of code trees (see + subsection below) + loop (until end of block code recognized) + decode literal/length value from input stream + if value < 256 + copy value (literal byte) to output stream + otherwise + if value = end of block (256) + break from loop + otherwise (value = 257..285) + decode distance from input stream + + move backwards distance bytes in the output + stream, and copy length bytes from this + position to the output stream. + end loop + while not last block + + Note that a duplicated string reference may refer to a string + in a previous block; i.e., the backward distance may cross one + or more block boundaries. However a distance cannot refer past + the beginning of the output stream. (An application using a + + + +Deutsch Informational [Page 10] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + preset dictionary might discard part of the output stream; a + distance can refer to that part of the output stream anyway) + Note also that the referenced string may overlap the current + position; for example, if the last 2 bytes decoded have values + X and Y, a string reference with + adds X,Y,X,Y,X to the output stream. + + We now specify each compression method in turn. + + 3.2.4. Non-compressed blocks (BTYPE=00) + + Any bits of input up to the next byte boundary are ignored. + The rest of the block consists of the following information: + + 0 1 2 3 4... + +---+---+---+---+================================+ + | LEN | NLEN |... LEN bytes of literal data...| + +---+---+---+---+================================+ + + LEN is the number of data bytes in the block. NLEN is the + one's complement of LEN. + + 3.2.5. Compressed blocks (length and distance codes) + + As noted above, encoded data blocks in the "deflate" format + consist of sequences of symbols drawn from three conceptually + distinct alphabets: either literal bytes, from the alphabet of + byte values (0..255), or pairs, + where the length is drawn from (3..258) and the distance is + drawn from (1..32,768). In fact, the literal and length + alphabets are merged into a single alphabet (0..285), where + values 0..255 represent literal bytes, the value 256 indicates + end-of-block, and values 257..285 represent length codes + (possibly in conjunction with extra bits following the symbol + code) as follows: + + + + + + + + + + + + + + + + +Deutsch Informational [Page 11] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + Extra Extra Extra + Code Bits Length(s) Code Bits Lengths Code Bits Length(s) + ---- ---- ------ ---- ---- ------- ---- ---- ------- + 257 0 3 267 1 15,16 277 4 67-82 + 258 0 4 268 1 17,18 278 4 83-98 + 259 0 5 269 2 19-22 279 4 99-114 + 260 0 6 270 2 23-26 280 4 115-130 + 261 0 7 271 2 27-30 281 5 131-162 + 262 0 8 272 2 31-34 282 5 163-194 + 263 0 9 273 3 35-42 283 5 195-226 + 264 0 10 274 3 43-50 284 5 227-257 + 265 1 11,12 275 3 51-58 285 0 258 + 266 1 13,14 276 3 59-66 + + The extra bits should be interpreted as a machine integer + stored with the most-significant bit first, e.g., bits 1110 + represent the value 14. + + Extra Extra Extra + Code Bits Dist Code Bits Dist Code Bits Distance + ---- ---- ---- ---- ---- ------ ---- ---- -------- + 0 0 1 10 4 33-48 20 9 1025-1536 + 1 0 2 11 4 49-64 21 9 1537-2048 + 2 0 3 12 5 65-96 22 10 2049-3072 + 3 0 4 13 5 97-128 23 10 3073-4096 + 4 1 5,6 14 6 129-192 24 11 4097-6144 + 5 1 7,8 15 6 193-256 25 11 6145-8192 + 6 2 9-12 16 7 257-384 26 12 8193-12288 + 7 2 13-16 17 7 385-512 27 12 12289-16384 + 8 3 17-24 18 8 513-768 28 13 16385-24576 + 9 3 25-32 19 8 769-1024 29 13 24577-32768 + + 3.2.6. Compression with fixed Huffman codes (BTYPE=01) + + The Huffman codes for the two alphabets are fixed, and are not + represented explicitly in the data. The Huffman code lengths + for the literal/length alphabet are: + + Lit Value Bits Codes + --------- ---- ----- + 0 - 143 8 00110000 through + 10111111 + 144 - 255 9 110010000 through + 111111111 + 256 - 279 7 0000000 through + 0010111 + 280 - 287 8 11000000 through + 11000111 + + + +Deutsch Informational [Page 12] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + The code lengths are sufficient to generate the actual codes, + as described above; we show the codes in the table for added + clarity. Literal/length values 286-287 will never actually + occur in the compressed data, but participate in the code + construction. + + Distance codes 0-31 are represented by (fixed-length) 5-bit + codes, with possible additional bits as shown in the table + shown in Paragraph 3.2.5, above. Note that distance codes 30- + 31 will never actually occur in the compressed data. + + 3.2.7. Compression with dynamic Huffman codes (BTYPE=10) + + The Huffman codes for the two alphabets appear in the block + immediately after the header bits and before the actual + compressed data, first the literal/length code and then the + distance code. Each code is defined by a sequence of code + lengths, as discussed in Paragraph 3.2.2, above. For even + greater compactness, the code length sequences themselves are + compressed using a Huffman code. The alphabet for code lengths + is as follows: + + 0 - 15: Represent code lengths of 0 - 15 + 16: Copy the previous code length 3 - 6 times. + The next 2 bits indicate repeat length + (0 = 3, ... , 3 = 6) + Example: Codes 8, 16 (+2 bits 11), + 16 (+2 bits 10) will expand to + 12 code lengths of 8 (1 + 6 + 5) + 17: Repeat a code length of 0 for 3 - 10 times. + (3 bits of length) + 18: Repeat a code length of 0 for 11 - 138 times + (7 bits of length) + + A code length of 0 indicates that the corresponding symbol in + the literal/length or distance alphabet will not occur in the + block, and should not participate in the Huffman code + construction algorithm given earlier. If only one distance + code is used, it is encoded using one bit, not zero bits; in + this case there is a single code length of one, with one unused + code. One distance code of zero bits means that there are no + distance codes used at all (the data is all literals). + + We can now define the format of the block: + + 5 Bits: HLIT, # of Literal/Length codes - 257 (257 - 286) + 5 Bits: HDIST, # of Distance codes - 1 (1 - 32) + 4 Bits: HCLEN, # of Code Length codes - 4 (4 - 19) + + + +Deutsch Informational [Page 13] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + (HCLEN + 4) x 3 bits: code lengths for the code length + alphabet given just above, in the order: 16, 17, 18, + 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 + + These code lengths are interpreted as 3-bit integers + (0-7); as above, a code length of 0 means the + corresponding symbol (literal/length or distance code + length) is not used. + + HLIT + 257 code lengths for the literal/length alphabet, + encoded using the code length Huffman code + + HDIST + 1 code lengths for the distance alphabet, + encoded using the code length Huffman code + + The actual compressed data of the block, + encoded using the literal/length and distance Huffman + codes + + The literal/length symbol 256 (end of data), + encoded using the literal/length Huffman code + + The code length repeat codes can cross from HLIT + 257 to the + HDIST + 1 code lengths. In other words, all code lengths form + a single sequence of HLIT + HDIST + 258 values. + + 3.3. Compliance + + A compressor may limit further the ranges of values specified in + the previous section and still be compliant; for example, it may + limit the range of backward pointers to some value smaller than + 32K. Similarly, a compressor may limit the size of blocks so that + a compressible block fits in memory. + + A compliant decompressor must accept the full range of possible + values defined in the previous section, and must accept blocks of + arbitrary size. + +4. Compression algorithm details + + While it is the intent of this document to define the "deflate" + compressed data format without reference to any particular + compression algorithm, the format is related to the compressed + formats produced by LZ77 (Lempel-Ziv 1977, see reference [2] below); + since many variations of LZ77 are patented, it is strongly + recommended that the implementor of a compressor follow the general + algorithm presented here, which is known not to be patented per se. + The material in this section is not part of the definition of the + + + +Deutsch Informational [Page 14] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + specification per se, and a compressor need not follow it in order to + be compliant. + + The compressor terminates a block when it determines that starting a + new block with fresh trees would be useful, or when the block size + fills up the compressor's block buffer. + + The compressor uses a chained hash table to find duplicated strings, + using a hash function that operates on 3-byte sequences. At any + given point during compression, let XYZ be the next 3 input bytes to + be examined (not necessarily all different, of course). First, the + compressor examines the hash chain for XYZ. If the chain is empty, + the compressor simply writes out X as a literal byte and advances one + byte in the input. If the hash chain is not empty, indicating that + the sequence XYZ (or, if we are unlucky, some other 3 bytes with the + same hash function value) has occurred recently, the compressor + compares all strings on the XYZ hash chain with the actual input data + sequence starting at the current point, and selects the longest + match. + + The compressor searches the hash chains starting with the most recent + strings, to favor small distances and thus take advantage of the + Huffman encoding. The hash chains are singly linked. There are no + deletions from the hash chains; the algorithm simply discards matches + that are too old. To avoid a worst-case situation, very long hash + chains are arbitrarily truncated at a certain length, determined by a + run-time parameter. + + To improve overall compression, the compressor optionally defers the + selection of matches ("lazy matching"): after a match of length N has + been found, the compressor searches for a longer match starting at + the next input byte. If it finds a longer match, it truncates the + previous match to a length of one (thus producing a single literal + byte) and then emits the longer match. Otherwise, it emits the + original match, and, as described above, advances N bytes before + continuing. + + Run-time parameters also control this "lazy match" procedure. If + compression ratio is most important, the compressor attempts a + complete second search regardless of the length of the first match. + In the normal case, if the current match is "long enough", the + compressor reduces the search for a longer match, thus speeding up + the process. If speed is most important, the compressor inserts new + strings in the hash table only when no match was found, or when the + match is not "too long". This degrades the compression ratio but + saves time since there are both fewer insertions and fewer searches. + + + + + +Deutsch Informational [Page 15] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + +5. References + + [1] Huffman, D. A., "A Method for the Construction of Minimum + Redundancy Codes", Proceedings of the Institute of Radio + Engineers, September 1952, Volume 40, Number 9, pp. 1098-1101. + + [2] Ziv J., Lempel A., "A Universal Algorithm for Sequential Data + Compression", IEEE Transactions on Information Theory, Vol. 23, + No. 3, pp. 337-343. + + [3] Gailly, J.-L., and Adler, M., ZLIB documentation and sources, + available in ftp://ftp.uu.net/pub/archiving/zip/doc/ + + [4] Gailly, J.-L., and Adler, M., GZIP documentation and sources, + available as gzip-*.tar in ftp://prep.ai.mit.edu/pub/gnu/ + + [5] Schwartz, E. S., and Kallick, B. "Generating a canonical prefix + encoding." Comm. ACM, 7,3 (Mar. 1964), pp. 166-169. + + [6] Hirschberg and Lelewer, "Efficient decoding of prefix codes," + Comm. ACM, 33,4, April 1990, pp. 449-459. + +6. Security Considerations + + Any data compression method involves the reduction of redundancy in + the data. Consequently, any corruption of the data is likely to have + severe effects and be difficult to correct. Uncompressed text, on + the other hand, will probably still be readable despite the presence + of some corrupted bytes. + + It is recommended that systems using this data format provide some + means of validating the integrity of the compressed data. See + reference [3], for example. + +7. Source code + + Source code for a C language implementation of a "deflate" compliant + compressor and decompressor is available within the zlib package at + ftp://ftp.uu.net/pub/archiving/zip/zlib/. + +8. Acknowledgements + + Trademarks cited in this document are the property of their + respective owners. + + Phil Katz designed the deflate format. Jean-Loup Gailly and Mark + Adler wrote the related software described in this specification. + Glenn Randers-Pehrson converted this document to RFC and HTML format. + + + +Deutsch Informational [Page 16] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + +9. Author's Address + + L. Peter Deutsch + Aladdin Enterprises + 203 Santa Margarita Ave. + Menlo Park, CA 94025 + + Phone: (415) 322-0103 (AM only) + FAX: (415) 322-1734 + EMail: + + Questions about the technical content of this specification can be + sent by email to: + + Jean-Loup Gailly and + Mark Adler + + Editorial comments on this specification can be sent by email to: + + L. Peter Deutsch and + Glenn Randers-Pehrson + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Deutsch Informational [Page 17] + diff --git a/lib/libz/doc/rfc1952.txt b/lib/libz/doc/rfc1952.txt new file mode 100644 index 00000000000..a8e51b4567f --- /dev/null +++ b/lib/libz/doc/rfc1952.txt @@ -0,0 +1,675 @@ + + + + + + +Network Working Group P. Deutsch +Request for Comments: 1952 Aladdin Enterprises +Category: Informational May 1996 + + + GZIP file format specification version 4.3 + +Status of This Memo + + This memo provides information for the Internet community. This memo + does not specify an Internet standard of any kind. Distribution of + this memo is unlimited. + +IESG Note: + + The IESG takes no position on the validity of any Intellectual + Property Rights statements contained in this document. + +Notices + + Copyright (c) 1996 L. Peter Deutsch + + Permission is granted to copy and distribute this document for any + purpose and without charge, including translations into other + languages and incorporation into compilations, provided that the + copyright notice and this notice are preserved, and that any + substantive changes or deletions from the original are clearly + marked. + + A pointer to the latest version of this and related documentation in + HTML format can be found at the URL + . + +Abstract + + This specification defines a lossless compressed data format that is + compatible with the widely used GZIP utility. The format includes a + cyclic redundancy check value for detecting data corruption. The + format presently uses the DEFLATE method of compression but can be + easily extended to use other compression methods. The format can be + implemented readily in a manner not covered by patents. + + + + + + + + + + +Deutsch Informational [Page 1] + +RFC 1952 GZIP File Format Specification May 1996 + + +Table of Contents + + 1. Introduction ................................................... 2 + 1.1. Purpose ................................................... 2 + 1.2. Intended audience ......................................... 3 + 1.3. Scope ..................................................... 3 + 1.4. Compliance ................................................ 3 + 1.5. Definitions of terms and conventions used ................. 3 + 1.6. Changes from previous versions ............................ 3 + 2. Detailed specification ......................................... 4 + 2.1. Overall conventions ....................................... 4 + 2.2. File format ............................................... 5 + 2.3. Member format ............................................. 5 + 2.3.1. Member header and trailer ........................... 6 + 2.3.1.1. Extra field ................................... 8 + 2.3.1.2. Compliance .................................... 9 + 3. References .................................................. 9 + 4. Security Considerations .................................... 10 + 5. Acknowledgements ........................................... 10 + 6. Author's Address ........................................... 10 + 7. Appendix: Jean-Loup Gailly's gzip utility .................. 11 + 8. Appendix: Sample CRC Code .................................. 11 + +1. Introduction + + 1.1. Purpose + + The purpose of this specification is to define a lossless + compressed data format that: + + * Is independent of CPU type, operating system, file system, + and character set, and hence can be used for interchange; + * Can compress or decompress a data stream (as opposed to a + randomly accessible file) to produce another data stream, + using only an a priori bounded amount of intermediate + storage, and hence can be used in data communications or + similar structures such as Unix filters; + * Compresses data with efficiency comparable to the best + currently available general-purpose compression methods, + and in particular considerably better than the "compress" + program; + * Can be implemented readily in a manner not covered by + patents, and hence can be practiced freely; + * Is compatible with the file format produced by the current + widely used gzip utility, in that conforming decompressors + will be able to read data produced by the existing gzip + compressor. + + + + +Deutsch Informational [Page 2] + +RFC 1952 GZIP File Format Specification May 1996 + + + The data format defined by this specification does not attempt to: + + * Provide random access to compressed data; + * Compress specialized data (e.g., raster graphics) as well as + the best currently available specialized algorithms. + + 1.2. Intended audience + + This specification is intended for use by implementors of software + to compress data into gzip format and/or decompress data from gzip + format. + + The text of the specification assumes a basic background in + programming at the level of bits and other primitive data + representations. + + 1.3. Scope + + The specification specifies a compression method and a file format + (the latter assuming only that a file can store a sequence of + arbitrary bytes). It does not specify any particular interface to + a file system or anything about character sets or encodings + (except for file names and comments, which are optional). + + 1.4. Compliance + + Unless otherwise indicated below, a compliant decompressor must be + able to accept and decompress any file that conforms to all the + specifications presented here; a compliant compressor must produce + files that conform to all the specifications presented here. The + material in the appendices is not part of the specification per se + and is not relevant to compliance. + + 1.5. Definitions of terms and conventions used + + byte: 8 bits stored or transmitted as a unit (same as an octet). + (For this specification, a byte is exactly 8 bits, even on + machines which store a character on a number of bits different + from 8.) See below for the numbering of bits within a byte. + + 1.6. Changes from previous versions + + There have been no technical changes to the gzip format since + version 4.1 of this specification. In version 4.2, some + terminology was changed, and the sample CRC code was rewritten for + clarity and to eliminate the requirement for the caller to do pre- + and post-conditioning. Version 4.3 is a conversion of the + specification to RFC style. + + + +Deutsch Informational [Page 3] + +RFC 1952 GZIP File Format Specification May 1996 + + +2. Detailed specification + + 2.1. Overall conventions + + In the diagrams below, a box like this: + + +---+ + | | <-- the vertical bars might be missing + +---+ + + represents one byte; a box like this: + + +==============+ + | | + +==============+ + + represents a variable number of bytes. + + Bytes stored within a computer do not have a "bit order", since + they are always treated as a unit. However, a byte considered as + an integer between 0 and 255 does have a most- and least- + significant bit, and since we write numbers with the most- + significant digit on the left, we also write bytes with the most- + significant bit on the left. In the diagrams below, we number the + bits of a byte so that bit 0 is the least-significant bit, i.e., + the bits are numbered: + + +--------+ + |76543210| + +--------+ + + This document does not address the issue of the order in which + bits of a byte are transmitted on a bit-sequential medium, since + the data format described here is byte- rather than bit-oriented. + + Within a computer, a number may occupy multiple bytes. All + multi-byte numbers in the format described here are stored with + the least-significant byte first (at the lower memory address). + For example, the decimal number 520 is stored as: + + 0 1 + +--------+--------+ + |00001000|00000010| + +--------+--------+ + ^ ^ + | | + | + more significant byte = 2 x 256 + + less significant byte = 8 + + + +Deutsch Informational [Page 4] + +RFC 1952 GZIP File Format Specification May 1996 + + + 2.2. File format + + A gzip file consists of a series of "members" (compressed data + sets). The format of each member is specified in the following + section. The members simply appear one after another in the file, + with no additional information before, between, or after them. + + 2.3. Member format + + Each member has the following structure: + + +---+---+---+---+---+---+---+---+---+---+ + |ID1|ID2|CM |FLG| MTIME |XFL|OS | (more-->) + +---+---+---+---+---+---+---+---+---+---+ + + (if FLG.FEXTRA set) + + +---+---+=================================+ + | XLEN |...XLEN bytes of "extra field"...| (more-->) + +---+---+=================================+ + + (if FLG.FNAME set) + + +=========================================+ + |...original file name, zero-terminated...| (more-->) + +=========================================+ + + (if FLG.FCOMMENT set) + + +===================================+ + |...file comment, zero-terminated...| (more-->) + +===================================+ + + (if FLG.FHCRC set) + + +---+---+ + | CRC16 | + +---+---+ + + +=======================+ + |...compressed blocks...| (more-->) + +=======================+ + + 0 1 2 3 4 5 6 7 + +---+---+---+---+---+---+---+---+ + | CRC32 | ISIZE | + +---+---+---+---+---+---+---+---+ + + + + +Deutsch Informational [Page 5] + +RFC 1952 GZIP File Format Specification May 1996 + + + 2.3.1. Member header and trailer + + ID1 (IDentification 1) + ID2 (IDentification 2) + These have the fixed values ID1 = 31 (0x1f, \037), ID2 = 139 + (0x8b, \213), to identify the file as being in gzip format. + + CM (Compression Method) + This identifies the compression method used in the file. CM + = 0-7 are reserved. CM = 8 denotes the "deflate" + compression method, which is the one customarily used by + gzip and which is documented elsewhere. + + FLG (FLaGs) + This flag byte is divided into individual bits as follows: + + bit 0 FTEXT + bit 1 FHCRC + bit 2 FEXTRA + bit 3 FNAME + bit 4 FCOMMENT + bit 5 reserved + bit 6 reserved + bit 7 reserved + + If FTEXT is set, the file is probably ASCII text. This is + an optional indication, which the compressor may set by + checking a small amount of the input data to see whether any + non-ASCII characters are present. In case of doubt, FTEXT + is cleared, indicating binary data. For systems which have + different file formats for ascii text and binary data, the + decompressor can use FTEXT to choose the appropriate format. + We deliberately do not specify the algorithm used to set + this bit, since a compressor always has the option of + leaving it cleared and a decompressor always has the option + of ignoring it and letting some other program handle issues + of data conversion. + + If FHCRC is set, a CRC16 for the gzip header is present, + immediately before the compressed data. The CRC16 consists + of the two least significant bytes of the CRC32 for all + bytes of the gzip header up to and not including the CRC16. + [The FHCRC bit was never set by versions of gzip up to + 1.2.4, even though it was documented with a different + meaning in gzip 1.2.4.] + + If FEXTRA is set, optional extra fields are present, as + described in a following section. + + + +Deutsch Informational [Page 6] + +RFC 1952 GZIP File Format Specification May 1996 + + + If FNAME is set, an original file name is present, + terminated by a zero byte. The name must consist of ISO + 8859-1 (LATIN-1) characters; on operating systems using + EBCDIC or any other character set for file names, the name + must be translated to the ISO LATIN-1 character set. This + is the original name of the file being compressed, with any + directory components removed, and, if the file being + compressed is on a file system with case insensitive names, + forced to lower case. There is no original file name if the + data was compressed from a source other than a named file; + for example, if the source was stdin on a Unix system, there + is no file name. + + If FCOMMENT is set, a zero-terminated file comment is + present. This comment is not interpreted; it is only + intended for human consumption. The comment must consist of + ISO 8859-1 (LATIN-1) characters. Line breaks should be + denoted by a single line feed character (10 decimal). + + Reserved FLG bits must be zero. + + MTIME (Modification TIME) + This gives the most recent modification time of the original + file being compressed. The time is in Unix format, i.e., + seconds since 00:00:00 GMT, Jan. 1, 1970. (Note that this + may cause problems for MS-DOS and other systems that use + local rather than Universal time.) If the compressed data + did not come from a file, MTIME is set to the time at which + compression started. MTIME = 0 means no time stamp is + available. + + XFL (eXtra FLags) + These flags are available for use by specific compression + methods. The "deflate" method (CM = 8) sets these flags as + follows: + + XFL = 2 - compressor used maximum compression, + slowest algorithm + XFL = 4 - compressor used fastest algorithm + + OS (Operating System) + This identifies the type of file system on which compression + took place. This may be useful in determining end-of-line + convention for text files. The currently defined values are + as follows: + + + + + + +Deutsch Informational [Page 7] + +RFC 1952 GZIP File Format Specification May 1996 + + + 0 - FAT filesystem (MS-DOS, OS/2, NT/Win32) + 1 - Amiga + 2 - VMS (or OpenVMS) + 3 - Unix + 4 - VM/CMS + 5 - Atari TOS + 6 - HPFS filesystem (OS/2, NT) + 7 - Macintosh + 8 - Z-System + 9 - CP/M + 10 - TOPS-20 + 11 - NTFS filesystem (NT) + 12 - QDOS + 13 - Acorn RISCOS + 255 - unknown + + XLEN (eXtra LENgth) + If FLG.FEXTRA is set, this gives the length of the optional + extra field. See below for details. + + CRC32 (CRC-32) + This contains a Cyclic Redundancy Check value of the + uncompressed data computed according to CRC-32 algorithm + used in the ISO 3309 standard and in section 8.1.1.6.2 of + ITU-T recommendation V.42. (See http://www.iso.ch for + ordering ISO documents. See gopher://info.itu.ch for an + online version of ITU-T V.42.) + + ISIZE (Input SIZE) + This contains the size of the original (uncompressed) input + data modulo 2^32. + + 2.3.1.1. Extra field + + If the FLG.FEXTRA bit is set, an "extra field" is present in + the header, with total length XLEN bytes. It consists of a + series of subfields, each of the form: + + +---+---+---+---+==================================+ + |SI1|SI2| LEN |... LEN bytes of subfield data ...| + +---+---+---+---+==================================+ + + SI1 and SI2 provide a subfield ID, typically two ASCII letters + with some mnemonic value. Jean-Loup Gailly + is maintaining a registry of subfield + IDs; please send him any subfield ID you wish to use. Subfield + IDs with SI2 = 0 are reserved for future use. The following + IDs are currently defined: + + + +Deutsch Informational [Page 8] + +RFC 1952 GZIP File Format Specification May 1996 + + + SI1 SI2 Data + ---------- ---------- ---- + 0x41 ('A') 0x70 ('P') Apollo file type information + + LEN gives the length of the subfield data, excluding the 4 + initial bytes. + + 2.3.1.2. Compliance + + A compliant compressor must produce files with correct ID1, + ID2, CM, CRC32, and ISIZE, but may set all the other fields in + the fixed-length part of the header to default values (255 for + OS, 0 for all others). The compressor must set all reserved + bits to zero. + + A compliant decompressor must check ID1, ID2, and CM, and + provide an error indication if any of these have incorrect + values. It must examine FEXTRA/XLEN, FNAME, FCOMMENT and FHCRC + at least so it can skip over the optional fields if they are + present. It need not examine any other part of the header or + trailer; in particular, a decompressor may ignore FTEXT and OS + and always produce binary output, and still be compliant. A + compliant decompressor must give an error indication if any + reserved bit is non-zero, since such a bit could indicate the + presence of a new field that would cause subsequent data to be + interpreted incorrectly. + +3. References + + [1] "Information Processing - 8-bit single-byte coded graphic + character sets - Part 1: Latin alphabet No.1" (ISO 8859-1:1987). + The ISO 8859-1 (Latin-1) character set is a superset of 7-bit + ASCII. Files defining this character set are available as + iso_8859-1.* in ftp://ftp.uu.net/graphics/png/documents/ + + [2] ISO 3309 + + [3] ITU-T recommendation V.42 + + [4] Deutsch, L.P.,"DEFLATE Compressed Data Format Specification", + available in ftp://ftp.uu.net/pub/archiving/zip/doc/ + + [5] Gailly, J.-L., GZIP documentation, available as gzip-*.tar in + ftp://prep.ai.mit.edu/pub/gnu/ + + [6] Sarwate, D.V., "Computation of Cyclic Redundancy Checks via Table + Look-Up", Communications of the ACM, 31(8), pp.1008-1013. + + + + +Deutsch Informational [Page 9] + +RFC 1952 GZIP File Format Specification May 1996 + + + [7] Schwaderer, W.D., "CRC Calculation", April 85 PC Tech Journal, + pp.118-133. + + [8] ftp://ftp.adelaide.edu.au/pub/rocksoft/papers/crc_v3.txt, + describing the CRC concept. + +4. Security Considerations + + Any data compression method involves the reduction of redundancy in + the data. Consequently, any corruption of the data is likely to have + severe effects and be difficult to correct. Uncompressed text, on + the other hand, will probably still be readable despite the presence + of some corrupted bytes. + + It is recommended that systems using this data format provide some + means of validating the integrity of the compressed data, such as by + setting and checking the CRC-32 check value. + +5. Acknowledgements + + Trademarks cited in this document are the property of their + respective owners. + + Jean-Loup Gailly designed the gzip format and wrote, with Mark Adler, + the related software described in this specification. Glenn + Randers-Pehrson converted this document to RFC and HTML format. + +6. Author's Address + + L. Peter Deutsch + Aladdin Enterprises + 203 Santa Margarita Ave. + Menlo Park, CA 94025 + + Phone: (415) 322-0103 (AM only) + FAX: (415) 322-1734 + EMail: + + Questions about the technical content of this specification can be + sent by email to: + + Jean-Loup Gailly and + Mark Adler + + Editorial comments on this specification can be sent by email to: + + L. Peter Deutsch and + Glenn Randers-Pehrson + + + +Deutsch Informational [Page 10] + +RFC 1952 GZIP File Format Specification May 1996 + + +7. Appendix: Jean-Loup Gailly's gzip utility + + The most widely used implementation of gzip compression, and the + original documentation on which this specification is based, were + created by Jean-Loup Gailly . Since this + implementation is a de facto standard, we mention some more of its + features here. Again, the material in this section is not part of + the specification per se, and implementations need not follow it to + be compliant. + + When compressing or decompressing a file, gzip preserves the + protection, ownership, and modification time attributes on the local + file system, since there is no provision for representing protection + attributes in the gzip file format itself. Since the file format + includes a modification time, the gzip decompressor provides a + command line switch that assigns the modification time from the file, + rather than the local modification time of the compressed input, to + the decompressed output. + +8. Appendix: Sample CRC Code + + The following sample code represents a practical implementation of + the CRC (Cyclic Redundancy Check). (See also ISO 3309 and ITU-T V.42 + for a formal specification.) + + The sample code is in the ANSI C programming language. Non C users + may find it easier to read with these hints: + + & Bitwise AND operator. + ^ Bitwise exclusive-OR operator. + >> Bitwise right shift operator. When applied to an + unsigned quantity, as here, right shift inserts zero + bit(s) at the left. + ! Logical NOT operator. + ++ "n++" increments the variable n. + 0xNNN 0x introduces a hexadecimal (base 16) constant. + Suffix L indicates a long value (at least 32 bits). + + /* Table of CRCs of all 8-bit messages. */ + unsigned long crc_table[256]; + + /* Flag: has the table been computed? Initially false. */ + int crc_table_computed = 0; + + /* Make the table for a fast CRC. */ + void make_crc_table(void) + { + unsigned long c; + + + +Deutsch Informational [Page 11] + +RFC 1952 GZIP File Format Specification May 1996 + + + int n, k; + for (n = 0; n < 256; n++) { + c = (unsigned long) n; + for (k = 0; k < 8; k++) { + if (c & 1) { + c = 0xedb88320L ^ (c >> 1); + } else { + c = c >> 1; + } + } + crc_table[n] = c; + } + crc_table_computed = 1; + } + + /* + Update a running crc with the bytes buf[0..len-1] and return + the updated crc. The crc should be initialized to zero. Pre- and + post-conditioning (one's complement) is performed within this + function so it shouldn't be done by the caller. Usage example: + + unsigned long crc = 0L; + + while (read_buffer(buffer, length) != EOF) { + crc = update_crc(crc, buffer, length); + } + if (crc != original_crc) error(); + */ + unsigned long update_crc(unsigned long crc, + unsigned char *buf, int len) + { + unsigned long c = crc ^ 0xffffffffL; + int n; + + if (!crc_table_computed) + make_crc_table(); + for (n = 0; n < len; n++) { + c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8); + } + return c ^ 0xffffffffL; + } + + /* Return the CRC of the bytes buf[0..len-1]. */ + unsigned long crc(unsigned char *buf, int len) + { + return update_crc(0L, buf, len); + } + + + + +Deutsch Informational [Page 12] + diff --git a/lib/libz/doc/txtvsbin.txt b/lib/libz/doc/txtvsbin.txt new file mode 100644 index 00000000000..3d0f0634f72 --- /dev/null +++ b/lib/libz/doc/txtvsbin.txt @@ -0,0 +1,107 @@ +A Fast Method for Identifying Plain Text Files +============================================== + + +Introduction +------------ + +Given a file coming from an unknown source, it is sometimes desirable +to find out whether the format of that file is plain text. Although +this may appear like a simple task, a fully accurate detection of the +file type requires heavy-duty semantic analysis on the file contents. +It is, however, possible to obtain satisfactory results by employing +various heuristics. + +Previous versions of PKZip and other zip-compatible compression tools +were using a crude detection scheme: if more than 80% (4/5) of the bytes +found in a certain buffer are within the range [7..127], the file is +labeled as plain text, otherwise it is labeled as binary. A prominent +limitation of this scheme is the restriction to Latin-based alphabets. +Other alphabets, like Greek, Cyrillic or Asian, make extensive use of +the bytes within the range [128..255], and texts using these alphabets +are most often misidentified by this scheme; in other words, the rate +of false negatives is sometimes too high, which means that the recall +is low. Another weakness of this scheme is a reduced precision, due to +the false positives that may occur when binary files containing large +amounts of textual characters are misidentified as plain text. + +In this article we propose a new, simple detection scheme that features +a much increased precision and a near-100% recall. This scheme is +designed to work on ASCII, Unicode and other ASCII-derived alphabets, +and it handles single-byte encodings (ISO-8859, MacRoman, KOI8, etc.) +and variable-sized encodings (ISO-2022, UTF-8, etc.). Wider encodings +(UCS-2/UTF-16 and UCS-4/UTF-32) are not handled, however. + + +The Algorithm +------------- + +The algorithm works by dividing the set of bytecodes [0..255] into three +categories: +- The white list of textual bytecodes: + 9 (TAB), 10 (LF), 13 (CR), 32 (SPACE) to 255. +- The gray list of tolerated bytecodes: + 7 (BEL), 8 (BS), 11 (VT), 12 (FF), 26 (SUB), 27 (ESC). +- The black list of undesired, non-textual bytecodes: + 0 (NUL) to 6, 14 to 31. + +If a file contains at least one byte that belongs to the white list and +no byte that belongs to the black list, then the file is categorized as +plain text; otherwise, it is categorized as binary. (The boundary case, +when the file is empty, automatically falls into the latter category.) + + +Rationale +--------- + +The idea behind this algorithm relies on two observations. + +The first observation is that, although the full range of 7-bit codes +[0..127] is properly specified by the ASCII standard, most control +characters in the range [0..31] are not used in practice. The only +widely-used, almost universally-portable control codes are 9 (TAB), +10 (LF) and 13 (CR). There are a few more control codes that are +recognized on a reduced range of platforms and text viewers/editors: +7 (BEL), 8 (BS), 11 (VT), 12 (FF), 26 (SUB) and 27 (ESC); but these +codes are rarely (if ever) used alone, without being accompanied by +some printable text. Even the newer, portable text formats such as +XML avoid using control characters outside the list mentioned here. + +The second observation is that most of the binary files tend to contain +control characters, especially 0 (NUL). Even though the older text +detection schemes observe the presence of non-ASCII codes from the range +[128..255], the precision rarely has to suffer if this upper range is +labeled as textual, because the files that are genuinely binary tend to +contain both control characters and codes from the upper range. On the +other hand, the upper range needs to be labeled as textual, because it +is used by virtually all ASCII extensions. In particular, this range is +used for encoding non-Latin scripts. + +Since there is no counting involved, other than simply observing the +presence or the absence of some byte values, the algorithm produces +consistent results, regardless what alphabet encoding is being used. +(If counting were involved, it could be possible to obtain different +results on a text encoded, say, using ISO-8859-16 versus UTF-8.) + +There is an extra category of plain text files that are "polluted" with +one or more black-listed codes, either by mistake or by peculiar design +considerations. In such cases, a scheme that tolerates a small fraction +of black-listed codes would provide an increased recall (i.e. more true +positives). This, however, incurs a reduced precision overall, since +false positives are more likely to appear in binary files that contain +large chunks of textual data. Furthermore, "polluted" plain text should +be regarded as binary by general-purpose text detection schemes, because +general-purpose text processing algorithms might not be applicable. +Under this premise, it is safe to say that our detection method provides +a near-100% recall. + +Experiments have been run on many files coming from various platforms +and applications. We tried plain text files, system logs, source code, +formatted office documents, compiled object code, etc. The results +confirm the optimistic assumptions about the capabilities of this +algorithm. + + +-- +Cosmin Truta +Last updated: 2006-May-28 diff --git a/lib/libz/example.c b/lib/libz/example.c index 6c8a0ee7633..604736f15f6 100644 --- a/lib/libz/example.c +++ b/lib/libz/example.c @@ -1,12 +1,12 @@ /* example.c -- usage example of the zlib compression library - * Copyright (C) 1995-2004 Jean-loup Gailly. + * Copyright (C) 1995-2006 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ /* @(#) $Id$ */ -#include #include "zlib.h" +#include #ifdef STDC # include diff --git a/lib/libz/gzclose.c b/lib/libz/gzclose.c new file mode 100644 index 00000000000..caeb99a3177 --- /dev/null +++ b/lib/libz/gzclose.c @@ -0,0 +1,25 @@ +/* gzclose.c -- zlib gzclose() function + * Copyright (C) 2004, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "gzguts.h" + +/* gzclose() is in a separate file so that it is linked in only if it is used. + That way the other gzclose functions can be used instead to avoid linking in + unneeded compression or decompression routines. */ +int ZEXPORT gzclose(file) + gzFile file; +{ +#ifndef NO_GZCOMPRESS + gz_statep state; + + if (file == NULL) + return Z_STREAM_ERROR; + state = (gz_statep)file; + + return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); +#else + return gzclose_r(file); +#endif +} diff --git a/lib/libz/gzguts.h b/lib/libz/gzguts.h new file mode 100644 index 00000000000..0e7ed4330a5 --- /dev/null +++ b/lib/libz/gzguts.h @@ -0,0 +1,132 @@ +/* gzguts.h -- zlib internal header definitions for gz* operations + * Copyright (C) 2004, 2005, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#ifdef _LARGEFILE64_SOURCE +# ifndef _LARGEFILE_SOURCE +# define _LARGEFILE_SOURCE +# endif +# ifdef _FILE_OFFSET_BITS +# undef _FILE_OFFSET_BITS +# endif +#endif + +#define ZLIB_INTERNAL + +#include +#include "zlib.h" +#ifdef STDC +# include +# include +# include +#endif +#include + +#ifdef NO_DEFLATE /* for compatibility with old definition */ +# define NO_GZCOMPRESS +#endif + +#ifdef _MSC_VER +# include +# define vsnprintf _vsnprintf +#endif + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + +/* gz* functions always use library allocation functions */ +#ifndef STDC + extern voidp malloc OF((uInt size)); + extern void free OF((voidpf ptr)); +#endif + +/* get errno and strerror definition */ +#if defined UNDER_CE && defined NO_ERRNO_H +# include +# define zstrerror() gz_strwinerror((DWORD)GetLastError()) +#else +# ifdef STDC +# include +# define zstrerror() strerror(errno) +# else +# define zstrerror() "stdio error (consult errno)" +# endif +#endif + +/* MVS fdopen() */ +#ifdef __MVS__ + #pragma map (fdopen , "\174\174FDOPEN") + FILE *fdopen(int, const char *); +#endif + +#ifdef _LARGEFILE64_SOURCE +# define z_off64_t off64_t +#else +# define z_off64_t z_off_t +#endif + +/* default i/o buffer size -- double this for output when reading */ +#define GZBUFSIZE 8192 + +/* gzip modes, also provide a little integrity check on the passed structure */ +#define GZ_NONE 0 +#define GZ_READ 7247 +#define GZ_WRITE 31153 +#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ + +/* values for gz_state how */ +#define LOOK 0 /* look for a gzip header */ +#define COPY 1 /* copy input directly */ +#define GZIP 2 /* decompress a gzip stream */ + +/* internal gzip file state data structure */ +typedef struct { + /* used for both reading and writing */ + int mode; /* see gzip modes above */ + int fd; /* file descriptor */ + char *path; /* path or fd for error messages */ + z_off64_t pos; /* current position in uncompressed data */ + unsigned size; /* buffer size, zero if not allocated yet */ + unsigned want; /* requested buffer size, default is GZBUFSIZE */ + unsigned char *in; /* input buffer */ + unsigned char *out; /* output buffer (double-sized when reading) */ + unsigned char *next; /* next output data to deliver or write */ + /* just for reading */ + unsigned have; /* amount of output data unused at next */ + int eof; /* true if end of input file reached */ + z_off64_t start; /* where the gzip data started, for rewinding */ + z_off64_t raw; /* where the raw data started, for seeking */ + int how; /* 0: get header, 1: copy, 2: decompress */ + int direct; /* true if last read direct, false if gzip */ + /* just for writing */ + int level; /* compression level */ + int strategy; /* compression strategy */ + /* seek request */ + z_off64_t skip; /* amount to skip (already rewound if backwards) */ + int seek; /* true if seek request pending */ + /* error information */ + int err; /* error code */ + char *msg; /* error message */ + /* zlib inflate or deflate stream */ + z_stream strm; /* stream structure in-place (not a pointer) */ +} gz_state; +typedef gz_state FAR *gz_statep; + +/* shared functions */ +ZEXTERN void ZEXPORT gz_error OF((gz_statep, int, const char *)); +#if defined UNDER_CE && defined NO_ERRNO_H +ZEXTERN char ZEXPORT *gz_strwinerror OF((DWORD error)); +#endif + +/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t + value -- needed when comparing unsigned to z_off64_t, which is signed + (possible z_off64_t types off_t, off64_t, and long are all signed) */ +#ifdef INT_MAX +# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) +#else +ZEXTERN unsigned ZEXPORT gz_intmax OF((void)); +# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) +#endif diff --git a/lib/libz/gzio.c b/lib/libz/gzio.c deleted file mode 100644 index 0aa03e9f997..00000000000 --- a/lib/libz/gzio.c +++ /dev/null @@ -1,1027 +0,0 @@ -/* gzio.c -- IO on .gz files - * Copyright (C) 1995-2005 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - * - * Compile this file with -DNO_GZCOMPRESS to avoid the compression code. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include - -#include "zutil.h" - -#ifdef NO_DEFLATE /* for compatibility with old definition */ -# define NO_GZCOMPRESS -#endif - -#ifndef NO_DUMMY_DECL -struct internal_state {int dummy;}; /* for buggy compilers */ -#endif - -#ifndef Z_BUFSIZE -# ifdef MAXSEG_64K -# define Z_BUFSIZE 4096 /* minimize memory usage for 16-bit DOS */ -# else -# define Z_BUFSIZE 16384 -# endif -#endif -#ifndef Z_PRINTF_BUFSIZE -# define Z_PRINTF_BUFSIZE 4096 -#endif - -#ifdef __MVS__ -# pragma map (fdopen , "\174\174FDOPEN") - FILE *fdopen(int, const char *); -#endif - -#ifndef STDC -extern voidp malloc OF((uInt size)); -extern void free OF((voidpf ptr)); -#endif - -#define ALLOC(size) malloc(size) -#define TRYFREE(p) {if (p) free(p);} - -static int const gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */ - -/* gzip flag byte */ -#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ -#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */ -#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ -#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ -#define COMMENT 0x10 /* bit 4 set: file comment present */ -#define RESERVED 0xE0 /* bits 5..7: reserved */ - -typedef struct gz_stream { - z_stream stream; - int z_err; /* error code for last stream operation */ - int z_eof; /* set if end of input file */ - FILE *file; /* .gz file */ - Byte *inbuf; /* input buffer */ - Byte *outbuf; /* output buffer */ - uLong crc; /* crc32 of uncompressed data */ - char *msg; /* error message */ - char *path; /* path name for debugging only */ - int transparent; /* 1 if input file is not a .gz file */ - char mode; /* 'w' or 'r' */ - z_off_t start; /* start of compressed data in file (header skipped) */ - z_off_t in; /* bytes into deflate or inflate */ - z_off_t out; /* bytes out of deflate or inflate */ - int back; /* one character push-back */ - int last; /* true if push-back is last character */ -} gz_stream; - - -local gzFile gz_open OF((const char *path, const char *mode, int fd)); -local int do_flush OF((gzFile file, int flush)); -local int get_byte OF((gz_stream *s)); -local void check_header OF((gz_stream *s)); -local int destroy OF((gz_stream *s)); -local void putLong OF((FILE *file, uLong x)); -local uLong getLong OF((gz_stream *s)); - -/* =========================================================================== - Opens a gzip (.gz) file for reading or writing. The mode parameter - is as in fopen ("rb" or "wb"). The file is given either by file descriptor - or path name (if fd == -1). - gz_open returns NULL if the file could not be opened or if there was - insufficient memory to allocate the (de)compression state; errno - can be checked to distinguish the two cases (if errno is zero, the - zlib error is Z_MEM_ERROR). -*/ -local gzFile gz_open (path, mode, fd) - const char *path; - const char *mode; - int fd; -{ - int err; - int level = Z_DEFAULT_COMPRESSION; /* compression level */ - int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */ - char *p = (char*)mode; - gz_stream *s; - char fmode[80]; /* copy of mode, without the compression level */ - char *m = fmode; - - if (!path || !mode) return Z_NULL; - - s = (gz_stream *)ALLOC(sizeof(gz_stream)); - if (!s) return Z_NULL; - - s->stream.zalloc = (alloc_func)0; - s->stream.zfree = (free_func)0; - s->stream.opaque = (voidpf)0; - s->stream.next_in = s->inbuf = Z_NULL; - s->stream.next_out = s->outbuf = Z_NULL; - s->stream.avail_in = s->stream.avail_out = 0; - s->file = NULL; - s->z_err = Z_OK; - s->z_eof = 0; - s->in = 0; - s->out = 0; - s->back = EOF; - s->crc = crc32(0L, Z_NULL, 0); - s->msg = NULL; - s->transparent = 0; - - s->path = (char*)ALLOC(strlen(path)+1); - if (s->path == NULL) { - return destroy(s), (gzFile)Z_NULL; - } - strcpy(s->path, path); /* do this early for debugging */ - - s->mode = '\0'; - do { - if (*p == 'r') s->mode = 'r'; - if (*p == 'w' || *p == 'a') s->mode = 'w'; - if (*p >= '0' && *p <= '9') { - level = *p - '0'; - } else if (*p == 'f') { - strategy = Z_FILTERED; - } else if (*p == 'h') { - strategy = Z_HUFFMAN_ONLY; - } else if (*p == 'R') { - strategy = Z_RLE; - } else { - *m++ = *p; /* copy the mode */ - } - } while (*p++ && m != fmode + sizeof(fmode)); - if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL; - - if (s->mode == 'w') { -#ifdef NO_GZCOMPRESS - err = Z_STREAM_ERROR; -#else - err = deflateInit2(&(s->stream), level, - Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy); - /* windowBits is passed < 0 to suppress zlib header */ - - s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE); -#endif - if (err != Z_OK || s->outbuf == Z_NULL) { - return destroy(s), (gzFile)Z_NULL; - } - } else { - s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); - - err = inflateInit2(&(s->stream), -MAX_WBITS); - /* windowBits is passed < 0 to tell that there is no zlib header. - * Note that in this case inflate *requires* an extra "dummy" byte - * after the compressed stream in order to complete decompression and - * return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are - * present after the compressed stream. - */ - if (err != Z_OK || s->inbuf == Z_NULL) { - return destroy(s), (gzFile)Z_NULL; - } - } - s->stream.avail_out = Z_BUFSIZE; - - errno = 0; - s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode); - - if (s->file == NULL) { - return destroy(s), (gzFile)Z_NULL; - } - if (s->mode == 'w') { - /* Write a very simple .gz header: - */ - fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1], - Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE); - s->start = 10L; - /* We use 10L instead of ftell(s->file) to because ftell causes an - * fflush on some systems. This version of the library doesn't use - * start anyway in write mode, so this initialization is not - * necessary. - */ - } else { - check_header(s); /* skip the .gz header */ - s->start = ftell(s->file) - s->stream.avail_in; - } - - return (gzFile)s; -} - -/* =========================================================================== - Opens a gzip (.gz) file for reading or writing. -*/ -gzFile ZEXPORT gzopen (path, mode) - const char *path; - const char *mode; -{ - return gz_open (path, mode, -1); -} - -/* =========================================================================== - Associate a gzFile with the file descriptor fd. fd is not dup'ed here - to mimic the behavio(u)r of fdopen. -*/ -gzFile ZEXPORT gzdopen (fd, mode) - int fd; - const char *mode; -{ - char name[46]; /* allow for up to 128-bit integers */ - - if (fd < 0) return (gzFile)Z_NULL; - snprintf(name, sizeof(name), "", fd); /* for debugging */ - - return gz_open (name, mode, fd); -} - -/* =========================================================================== - * Update the compression level and strategy - */ -int ZEXPORT gzsetparams (file, level, strategy) - gzFile file; - int level; - int strategy; -{ - gz_stream *s = (gz_stream*)file; - - if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; - - /* Make room to allow flushing */ - if (s->stream.avail_out == 0) { - - s->stream.next_out = s->outbuf; - if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) { - s->z_err = Z_ERRNO; - } - s->stream.avail_out = Z_BUFSIZE; - } - - return deflateParams (&(s->stream), level, strategy); -} - -/* =========================================================================== - Read a byte from a gz_stream; update next_in and avail_in. Return EOF - for end of file. - IN assertion: the stream s has been sucessfully opened for reading. -*/ -local int get_byte(s) - gz_stream *s; -{ - if (s->z_eof) return EOF; - if (s->stream.avail_in == 0) { - errno = 0; - s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file); - if (s->stream.avail_in == 0) { - s->z_eof = 1; - if (ferror(s->file)) s->z_err = Z_ERRNO; - return EOF; - } - s->stream.next_in = s->inbuf; - } - s->stream.avail_in--; - return *(s->stream.next_in)++; -} - -/* =========================================================================== - Check the gzip header of a gz_stream opened for reading. Set the stream - mode to transparent if the gzip magic header is not present; set s->err - to Z_DATA_ERROR if the magic header is present but the rest of the header - is incorrect. - IN assertion: the stream s has already been created sucessfully; - s->stream.avail_in is zero for the first time, but may be non-zero - for concatenated .gz files. -*/ -local void check_header(s) - gz_stream *s; -{ - int method; /* method byte */ - int flags; /* flags byte */ - uInt len; - int c; - - /* Assure two bytes in the buffer so we can peek ahead -- handle case - where first byte of header is at the end of the buffer after the last - gzip segment */ - len = s->stream.avail_in; - if (len < 2) { - if (len) s->inbuf[0] = s->stream.next_in[0]; - errno = 0; - len = (uInt)fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file); - if (len == 0 && ferror(s->file)) s->z_err = Z_ERRNO; - s->stream.avail_in += len; - s->stream.next_in = s->inbuf; - if (s->stream.avail_in < 2) { - s->transparent = s->stream.avail_in; - return; - } - } - - /* Peek ahead to check the gzip magic header */ - if (s->stream.next_in[0] != gz_magic[0] || - s->stream.next_in[1] != gz_magic[1]) { - s->transparent = 1; - return; - } - s->stream.avail_in -= 2; - s->stream.next_in += 2; - - /* Check the rest of the gzip header */ - method = get_byte(s); - flags = get_byte(s); - if (method != Z_DEFLATED || (flags & RESERVED) != 0) { - s->z_err = Z_DATA_ERROR; - return; - } - - /* Discard time, xflags and OS code: */ - for (len = 0; len < 6; len++) (void)get_byte(s); - - if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */ - len = (uInt)get_byte(s); - len += ((uInt)get_byte(s))<<8; - /* len is garbage if EOF but the loop below will quit anyway */ - while (len-- != 0 && get_byte(s) != EOF) ; - } - if ((flags & ORIG_NAME) != 0) { /* skip the original file name */ - while ((c = get_byte(s)) != 0 && c != EOF) ; - } - if ((flags & COMMENT) != 0) { /* skip the .gz file comment */ - while ((c = get_byte(s)) != 0 && c != EOF) ; - } - if ((flags & HEAD_CRC) != 0) { /* skip the header crc */ - for (len = 0; len < 2; len++) (void)get_byte(s); - } - s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK; -} - - /* =========================================================================== - * Cleanup then free the given gz_stream. Return a zlib error code. - Try freeing in the reverse order of allocations. - */ -local int destroy (s) - gz_stream *s; -{ - int err = Z_OK; - - if (!s) return Z_STREAM_ERROR; - - TRYFREE(s->msg); - - if (s->stream.state != NULL) { - if (s->mode == 'w') { -#ifdef NO_GZCOMPRESS - err = Z_STREAM_ERROR; -#else - err = deflateEnd(&(s->stream)); -#endif - } else if (s->mode == 'r') { - err = inflateEnd(&(s->stream)); - } - } - if (s->file != NULL && fclose(s->file)) { -#ifdef ESPIPE - if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */ -#endif - err = Z_ERRNO; - } - if (s->z_err < 0) err = s->z_err; - - TRYFREE(s->inbuf); - TRYFREE(s->outbuf); - TRYFREE(s->path); - TRYFREE(s); - return err; -} - -/* =========================================================================== - Reads the given number of uncompressed bytes from the compressed file. - gzread returns the number of bytes actually read (0 for end of file). -*/ -int ZEXPORT gzread (file, buf, len) - gzFile file; - voidp buf; - unsigned len; -{ - gz_stream *s = (gz_stream*)file; - Bytef *start = (Bytef*)buf; /* starting point for crc computation */ - Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */ - - if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR; - - if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1; - if (s->z_err == Z_STREAM_END) return 0; /* EOF */ - - next_out = (Byte*)buf; - s->stream.next_out = (Bytef*)buf; - s->stream.avail_out = len; - - if (s->stream.avail_out && s->back != EOF) { - *next_out++ = s->back; - s->stream.next_out++; - s->stream.avail_out--; - s->back = EOF; - s->out++; - start++; - if (s->last) { - s->z_err = Z_STREAM_END; - return 1; - } - } - - while (s->stream.avail_out != 0) { - - if (s->transparent) { - /* Copy first the lookahead bytes: */ - uInt n = s->stream.avail_in; - if (n > s->stream.avail_out) n = s->stream.avail_out; - if (n > 0) { - zmemcpy(s->stream.next_out, s->stream.next_in, n); - next_out += n; - s->stream.next_out = next_out; - s->stream.next_in += n; - s->stream.avail_out -= n; - s->stream.avail_in -= n; - } - if (s->stream.avail_out > 0) { - s->stream.avail_out -= - (uInt)fread(next_out, 1, s->stream.avail_out, s->file); - } - len -= s->stream.avail_out; - s->in += len; - s->out += len; - if (len == 0) s->z_eof = 1; - return (int)len; - } - if (s->stream.avail_in == 0 && !s->z_eof) { - - errno = 0; - s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file); - if (s->stream.avail_in == 0) { - s->z_eof = 1; - if (ferror(s->file)) { - s->z_err = Z_ERRNO; - break; - } - } - s->stream.next_in = s->inbuf; - } - s->in += s->stream.avail_in; - s->out += s->stream.avail_out; - s->z_err = inflate(&(s->stream), Z_NO_FLUSH); - s->in -= s->stream.avail_in; - s->out -= s->stream.avail_out; - - if (s->z_err == Z_STREAM_END) { - /* Check CRC and original size */ - s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start)); - start = s->stream.next_out; - - if (getLong(s) != s->crc) { - s->z_err = Z_DATA_ERROR; - } else { - (void)getLong(s); - /* The uncompressed length returned by above getlong() may be - * different from s->out in case of concatenated .gz files. - * Check for such files: - */ - check_header(s); - if (s->z_err == Z_OK) { - inflateReset(&(s->stream)); - s->crc = crc32(0L, Z_NULL, 0); - } - } - } - if (s->z_err != Z_OK || s->z_eof) break; - } - s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start)); - - if (len == s->stream.avail_out && - (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO)) - return -1; - return (int)(len - s->stream.avail_out); -} - - -/* =========================================================================== - Reads one byte from the compressed file. gzgetc returns this byte - or -1 in case of end of file or error. -*/ -int ZEXPORT gzgetc(file) - gzFile file; -{ - unsigned char c; - - return gzread(file, &c, 1) == 1 ? c : -1; -} - - -/* =========================================================================== - Push one byte back onto the stream. -*/ -int ZEXPORT gzungetc(c, file) - int c; - gzFile file; -{ - gz_stream *s = (gz_stream*)file; - - if (s == NULL || s->mode != 'r' || c == EOF || s->back != EOF) return EOF; - s->back = c; - s->out--; - s->last = (s->z_err == Z_STREAM_END); - if (s->last) s->z_err = Z_OK; - s->z_eof = 0; - return c; -} - - -/* =========================================================================== - Reads bytes from the compressed file until len-1 characters are - read, or a newline character is read and transferred to buf, or an - end-of-file condition is encountered. The string is then terminated - with a null character. - gzgets returns buf, or Z_NULL in case of error. - - The current implementation is not optimized at all. -*/ -char * ZEXPORT gzgets(file, buf, len) - gzFile file; - char *buf; - int len; -{ - char *b = buf; - if (buf == Z_NULL || len <= 0) return Z_NULL; - - while (--len > 0 && gzread(file, buf, 1) == 1 && *buf++ != '\n') ; - *buf = '\0'; - return b == buf && len > 0 ? Z_NULL : b; -} - - -#ifndef NO_GZCOMPRESS -/* =========================================================================== - Writes the given number of uncompressed bytes into the compressed file. - gzwrite returns the number of bytes actually written (0 in case of error). -*/ -int ZEXPORT gzwrite (file, buf, len) - gzFile file; - voidpc buf; - unsigned len; -{ - gz_stream *s = (gz_stream*)file; - - if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; - - s->stream.next_in = (Bytef*)buf; - s->stream.avail_in = len; - - while (s->stream.avail_in != 0) { - - if (s->stream.avail_out == 0) { - - s->stream.next_out = s->outbuf; - if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) { - s->z_err = Z_ERRNO; - break; - } - s->stream.avail_out = Z_BUFSIZE; - } - s->in += s->stream.avail_in; - s->out += s->stream.avail_out; - s->z_err = deflate(&(s->stream), Z_NO_FLUSH); - s->in -= s->stream.avail_in; - s->out -= s->stream.avail_out; - if (s->z_err != Z_OK) break; - } - s->crc = crc32(s->crc, (const Bytef *)buf, len); - - return (int)(len - s->stream.avail_in); -} - - -/* =========================================================================== - Converts, formats, and writes the args to the compressed file under - control of the format string, as in fprintf. gzprintf returns the number of - uncompressed bytes actually written (0 in case of error). -*/ -#ifdef STDC -#include - -int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...) -{ - char buf[Z_PRINTF_BUFSIZE]; - va_list va; - int len; - - buf[sizeof(buf) - 1] = 0; - va_start(va, format); -#ifdef NO_vsnprintf -# ifdef HAS_vsprintf_void - (void)vsprintf(buf, format, va); - va_end(va); - for (len = 0; len < sizeof(buf); len++) - if (buf[len] == 0) break; -# else - len = vsprintf(buf, format, va); - va_end(va); -# endif -#else -# ifdef HAS_vsnprintf_void - (void)vsnprintf(buf, sizeof(buf), format, va); - va_end(va); - len = strlen(buf); -# else - len = vsnprintf(buf, sizeof(buf), format, va); - va_end(va); -# endif -#endif - if (len <= 0 || len >= (int)sizeof(buf) || buf[sizeof(buf) - 1] != 0) - return 0; - return gzwrite(file, buf, (unsigned)len); -} -#else /* not ANSI C */ - -int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, - a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) - gzFile file; - const char *format; - int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, - a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; -{ - char buf[Z_PRINTF_BUFSIZE]; - int len; - - buf[sizeof(buf) - 1] = 0; -#ifdef NO_snprintf -# ifdef HAS_sprintf_void - sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8, - a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); - for (len = 0; len < sizeof(buf); len++) - if (buf[len] == 0) break; -# else - len = sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8, - a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); -# endif -#else -# ifdef HAS_snprintf_void - snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8, - a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); - len = strlen(buf); -# else - len = snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8, - a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); -# endif -#endif - if (len <= 0 || len >= sizeof(buf) || buf[sizeof(buf) - 1] != 0) - return 0; - return gzwrite(file, buf, len); -} -#endif - -/* =========================================================================== - Writes c, converted to an unsigned char, into the compressed file. - gzputc returns the value that was written, or -1 in case of error. -*/ -int ZEXPORT gzputc(file, c) - gzFile file; - int c; -{ - unsigned char cc = (unsigned char) c; /* required for big endian systems */ - - return gzwrite(file, &cc, 1) == 1 ? (int)cc : -1; -} - - -/* =========================================================================== - Writes the given null-terminated string to the compressed file, excluding - the terminating null character. - gzputs returns the number of characters written, or -1 in case of error. -*/ -int ZEXPORT gzputs(file, s) - gzFile file; - const char *s; -{ - return gzwrite(file, (char*)s, (unsigned)strlen(s)); -} - - -/* =========================================================================== - Flushes all pending output into the compressed file. The parameter - flush is as in the deflate() function. -*/ -local int do_flush (file, flush) - gzFile file; - int flush; -{ - uInt len; - int done = 0; - gz_stream *s = (gz_stream*)file; - - if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; - - s->stream.avail_in = 0; /* should be zero already anyway */ - - for (;;) { - len = Z_BUFSIZE - s->stream.avail_out; - - if (len != 0) { - if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) { - s->z_err = Z_ERRNO; - return Z_ERRNO; - } - s->stream.next_out = s->outbuf; - s->stream.avail_out = Z_BUFSIZE; - } - if (done) break; - s->out += s->stream.avail_out; - s->z_err = deflate(&(s->stream), flush); - s->out -= s->stream.avail_out; - - /* Ignore the second of two consecutive flushes: */ - if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK; - - /* deflate has finished flushing only when it hasn't used up - * all the available space in the output buffer: - */ - done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END); - - if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break; - } - return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; -} - -int ZEXPORT gzflush (file, flush) - gzFile file; - int flush; -{ - gz_stream *s = (gz_stream*)file; - int err = do_flush (file, flush); - - if (err) return err; - fflush(s->file); - return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; -} -#endif /* NO_GZCOMPRESS */ - -/* =========================================================================== - Sets the starting position for the next gzread or gzwrite on the given - compressed file. The offset represents a number of bytes in the - gzseek returns the resulting offset location as measured in bytes from - the beginning of the uncompressed stream, or -1 in case of error. - SEEK_END is not implemented, returns error. - In this version of the library, gzseek can be extremely slow. -*/ -z_off_t ZEXPORT gzseek (file, offset, whence) - gzFile file; - z_off_t offset; - int whence; -{ - gz_stream *s = (gz_stream*)file; - - if (s == NULL || whence == SEEK_END || - s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) { - return -1L; - } - - if (s->mode == 'w') { -#ifdef NO_GZCOMPRESS - return -1L; -#else - if (whence == SEEK_SET) { - offset -= s->in; - } - if (offset < 0) return -1L; - - /* At this point, offset is the number of zero bytes to write. */ - if (s->inbuf == Z_NULL) { - s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */ - if (s->inbuf == Z_NULL) return -1L; - zmemzero(s->inbuf, Z_BUFSIZE); - } - while (offset > 0) { - uInt size = Z_BUFSIZE; - if (offset < Z_BUFSIZE) size = (uInt)offset; - - size = gzwrite(file, s->inbuf, size); - if (size == 0) return -1L; - - offset -= size; - } - return s->in; -#endif - } - /* Rest of function is for reading only */ - - /* compute absolute position */ - if (whence == SEEK_CUR) { - offset += s->out; - } - if (offset < 0) return -1L; - - if (s->transparent) { - /* map to fseek */ - s->back = EOF; - s->stream.avail_in = 0; - s->stream.next_in = s->inbuf; - if (fseek(s->file, offset, SEEK_SET) < 0) return -1L; - - s->in = s->out = offset; - return offset; - } - - /* For a negative seek, rewind and use positive seek */ - if (offset >= s->out) { - offset -= s->out; - } else if (gzrewind(file) < 0) { - return -1L; - } - /* offset is now the number of bytes to skip. */ - - if (offset != 0 && s->outbuf == Z_NULL) { - s->outbuf = (Byte*)ALLOC(Z_BUFSIZE); - if (s->outbuf == Z_NULL) return -1L; - } - if (offset && s->back != EOF) { - s->back = EOF; - s->out++; - offset--; - if (s->last) s->z_err = Z_STREAM_END; - } - while (offset > 0) { - int size = Z_BUFSIZE; - if (offset < Z_BUFSIZE) size = (int)offset; - - size = gzread(file, s->outbuf, (uInt)size); - if (size <= 0) return -1L; - offset -= size; - } - return s->out; -} - -/* =========================================================================== - Rewinds input file. -*/ -int ZEXPORT gzrewind (file) - gzFile file; -{ - gz_stream *s = (gz_stream*)file; - - if (s == NULL || s->mode != 'r') return -1; - - s->z_err = Z_OK; - s->z_eof = 0; - s->back = EOF; - s->stream.avail_in = 0; - s->stream.next_in = s->inbuf; - s->crc = crc32(0L, Z_NULL, 0); - if (!s->transparent) (void)inflateReset(&s->stream); - s->in = 0; - s->out = 0; - return fseek(s->file, s->start, SEEK_SET); -} - -/* =========================================================================== - Returns the starting position for the next gzread or gzwrite on the - given compressed file. This position represents a number of bytes in the - uncompressed data stream. -*/ -z_off_t ZEXPORT gztell (file) - gzFile file; -{ - return gzseek(file, 0L, SEEK_CUR); -} - -/* =========================================================================== - Returns 1 when EOF has previously been detected reading the given - input stream, otherwise zero. -*/ -int ZEXPORT gzeof (file) - gzFile file; -{ - gz_stream *s = (gz_stream*)file; - - /* With concatenated compressed files that can have embedded - * crc trailers, z_eof is no longer the only/best indicator of EOF - * on a gz_stream. Handle end-of-stream error explicitly here. - */ - if (s == NULL || s->mode != 'r') return 0; - if (s->z_eof) return 1; - return s->z_err == Z_STREAM_END; -} - -/* =========================================================================== - Returns 1 if reading and doing so transparently, otherwise zero. -*/ -int ZEXPORT gzdirect (file) - gzFile file; -{ - gz_stream *s = (gz_stream*)file; - - if (s == NULL || s->mode != 'r') return 0; - return s->transparent; -} - -/* =========================================================================== - Outputs a long in LSB order to the given file -*/ -local void putLong (file, x) - FILE *file; - uLong x; -{ - int n; - for (n = 0; n < 4; n++) { - fputc((int)(x & 0xff), file); - x >>= 8; - } -} - -/* =========================================================================== - Reads a long in LSB order from the given gz_stream. Sets z_err in case - of error. -*/ -local uLong getLong (s) - gz_stream *s; -{ - uLong x = (uLong)get_byte(s); - int c; - - x += ((uLong)get_byte(s))<<8; - x += ((uLong)get_byte(s))<<16; - c = get_byte(s); - if (c == EOF) s->z_err = Z_DATA_ERROR; - x += ((uLong)c)<<24; - return x; -} - -/* =========================================================================== - Flushes all pending output if necessary, closes the compressed file - and deallocates all the (de)compression state. -*/ -int ZEXPORT gzclose (file) - gzFile file; -{ - gz_stream *s = (gz_stream*)file; - - if (s == NULL) return Z_STREAM_ERROR; - - if (s->mode == 'w') { -#ifdef NO_GZCOMPRESS - return Z_STREAM_ERROR; -#else - if (do_flush (file, Z_FINISH) != Z_OK) - return destroy((gz_stream*)file); - - putLong (s->file, s->crc); - putLong (s->file, (uLong)(s->in & 0xffffffff)); -#endif - } - return destroy((gz_stream*)file); -} - -#ifdef STDC -# define zstrerror(errnum) strerror(errnum) -#else -# define zstrerror(errnum) "" -#endif - -/* =========================================================================== - Returns the error message for the last error which occurred on the - given compressed file. errnum is set to zlib error number. If an - error occurred in the file system and not in the compression library, - errnum is set to Z_ERRNO and the application may consult errno - to get the exact error code. -*/ -const char * ZEXPORT gzerror (file, errnum) - gzFile file; - int *errnum; -{ - char *m; - gz_stream *s = (gz_stream*)file; - - if (s == NULL) { - *errnum = Z_STREAM_ERROR; - return (const char*)ERR_MSG(Z_STREAM_ERROR); - } - *errnum = s->z_err; - if (*errnum == Z_OK) return (const char*)""; - - m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg); - - if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err); - - TRYFREE(s->msg); - s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3); - if (s->msg == Z_NULL) return (const char*)ERR_MSG(Z_MEM_ERROR); - strcpy(s->msg, s->path); - strcat(s->msg, ": "); - strcat(s->msg, m); - return (const char*)s->msg; -} - -/* =========================================================================== - Clear the error and end-of-file flags, and do the same for the real file. -*/ -void ZEXPORT gzclearerr (file) - gzFile file; -{ - gz_stream *s = (gz_stream*)file; - - if (s == NULL) return; - if (s->z_err != Z_STREAM_END) s->z_err = Z_OK; - s->z_eof = 0; - clearerr(s->file); -} diff --git a/lib/libz/gzlib.c b/lib/libz/gzlib.c new file mode 100644 index 00000000000..6fdb08a8145 --- /dev/null +++ b/lib/libz/gzlib.c @@ -0,0 +1,535 @@ +/* gzlib.c -- zlib functions common to reading and writing gzip files + * Copyright (C) 2004, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "gzguts.h" + +#ifdef _LARGEFILE64_SOURCE +# define LSEEK lseek64 +#else +# define LSEEK lseek +#endif + +/* Local functions */ +local void gz_reset OF((gz_statep)); +local gzFile gz_open OF((const char *, int, const char *)); + +#if defined UNDER_CE && defined NO_ERRNO_H + +/* Map the Windows error number in ERROR to a locale-dependent error message + string and return a pointer to it. Typically, the values for ERROR come + from GetLastError. + + The string pointed to shall not be modified by the application, but may be + overwritten by a subsequent call to gz_strwinerror + + The gz_strwinerror function does not change the current setting of + GetLastError. */ +char ZEXPORT *gz_strwinerror (error) + DWORD error; +{ + static char buf[1024]; + + wchar_t *msgbuf; + DWORD lasterr = GetLastError(); + DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_ALLOCATE_BUFFER, + NULL, + error, + 0, /* Default language */ + (LPVOID)&msgbuf, + 0, + NULL); + if (chars != 0) { + /* If there is an \r\n appended, zap it. */ + if (chars >= 2 + && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { + chars -= 2; + msgbuf[chars] = 0; + } + + if (chars > sizeof (buf) - 1) { + chars = sizeof (buf) - 1; + msgbuf[chars] = 0; + } + + wcstombs(buf, msgbuf, chars + 1); + LocalFree(msgbuf); + } + else { + sprintf(buf, "unknown win32 error (%ld)", error); + } + + SetLastError(lasterr); + return buf; +} + +#endif /* UNDER_CE && NO_ERRNO_H */ + +/* Reset gzip file state */ +local void gz_reset(state) + gz_statep state; +{ + if (state->mode == GZ_READ) { /* for reading ... */ + state->have = 0; /* no output data available */ + state->eof = 0; /* not at end of file */ + state->how = LOOK; /* look for gzip header */ + state->direct = 1; /* default for empty file */ + } + state->seek = 0; /* no seek request pending */ + gz_error(state, Z_OK, NULL); /* clear error */ + state->pos = 0; /* no uncompressed data yet */ + state->strm.avail_in = 0; /* no input data yet */ +} + +/* Open a gzip file either by name or file descriptor. */ +local gzFile gz_open(path, fd, mode) + const char *path; + int fd; + const char *mode; +{ + gz_statep state; + + /* allocate gzFile structure to return */ + state = malloc(sizeof(gz_state)); + if (state == NULL) + return NULL; + state->size = 0; /* no buffers allocated yet */ + state->want = GZBUFSIZE; /* requested buffer size */ + state->msg = NULL; /* no error message yet */ + + /* interpret mode */ + state->mode = GZ_NONE; + state->level = Z_DEFAULT_COMPRESSION; + state->strategy = Z_DEFAULT_STRATEGY; + while (*mode) { + if (*mode >= '0' && *mode <= '9') + state->level = *mode - '0'; + else + switch (*mode) { + case 'r': + state->mode = GZ_READ; + break; +#ifndef NO_GZCOMPRESS + case 'w': + state->mode = GZ_WRITE; + break; + case 'a': + state->mode = GZ_APPEND; + break; +#endif + case '+': /* can't read and write at the same time */ + free(state); + return NULL; + case 'b': /* ignore -- will request binary anyway */ + break; + case 'f': + state->strategy = Z_FILTERED; + break; + case 'h': + state->strategy = Z_HUFFMAN_ONLY; + break; + case 'R': + state->strategy = Z_RLE; + break; + case 'F': + state->strategy = Z_FIXED; + default: /* could consider as an error, but just ignore */ + ; + } + mode++; + } + + /* must provide an "r", "w", or "a" */ + if (state->mode == GZ_NONE) { + free(state); + return NULL; + } + + /* save the path name for error messages */ + state->path = malloc(strlen(path) + 1); + if (state->path == NULL) { + free(state); + return NULL; + } + strcpy(state->path, path); + + /* open the file with the appropriate mode (or just use fd) */ + state->fd = fd != -1 ? fd : + open(path, +#ifdef O_LARGEFILE + O_LARGEFILE | +#endif +#ifdef O_BINARY + O_BINARY | +#endif + (state->mode == GZ_READ ? + O_RDONLY : + (O_WRONLY | O_CREAT | ( + state->mode == GZ_WRITE ? + O_TRUNC : + O_APPEND))), + 0666); + if (state->fd == -1) { + free(state); + return NULL; + } + if (state->mode == GZ_APPEND) + state->mode = GZ_WRITE; /* simplify later checks */ + + /* save the current position for rewinding (only if reading) */ + if (state->mode == GZ_READ) { + state->start = LSEEK(state->fd, 0, SEEK_CUR); + if (state->start == -1) state->start = 0; + } + + /* initialize stream */ + gz_reset(state); + + /* return stream */ + return (gzFile)state; +} + +/* -- see zlib.h -- */ +gzFile ZEXPORT gzopen(path, mode) + const char *path; + const char *mode; +{ + return gz_open(path, -1, mode); +} + +/* -- see zlib.h -- */ +gzFile ZEXPORT gzopen64(path, mode) + const char *path; + const char *mode; +{ + return gz_open(path, -1, mode); +} + +/* -- see zlib.h -- */ +gzFile ZEXPORT gzdopen(fd, mode) + int fd; + const char *mode; +{ + char *path; /* identifier for error messages */ + gzFile gz; + + if (fd == -1 || (path = malloc(7 + 3 * sizeof(int))) == NULL) + return NULL; + sprintf(path, "", fd); + gz = gz_open(path, fd, mode); + free(path); + return gz; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzbuffer(file, size) + gzFile file; + unsigned size; +{ + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return -1; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return -1; + + /* make sure we haven't already allocated memory */ + if (state->size != 0) + return -1; + + /* check and set requested size */ + if (size == 0) + return -1; + state->want = size; + return 0; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzrewind(file) + gzFile file; +{ + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + + /* check that we're reading and that there's no error */ + if (state->mode != GZ_READ || state->err != Z_OK) + return -1; + + /* back up and start over */ + if (LSEEK(state->fd, state->start, SEEK_SET) == -1) + return -1; + gz_reset(state); + return 0; +} + +/* -- see zlib.h -- */ +z_off64_t ZEXPORT gzseek64(file, offset, whence) + gzFile file; + z_off64_t offset; + int whence; +{ + unsigned n; + z_off64_t ret; + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return -1; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return -1; + + /* check that there's no error */ + if (state->err != Z_OK) + return -1; + + /* can only seek from start or relative to current position */ + if (whence != SEEK_SET && whence != SEEK_CUR) + return -1; + + /* normalize offset to a SEEK_CUR specification */ + if (whence == SEEK_SET) + offset -= state->pos; + else if (state->seek) + offset += state->skip; + state->seek = 0; + + /* if within raw area while reading, just go there */ + if (state->mode == GZ_READ && state->how == COPY && + state->pos + offset >= state->raw) { + ret = LSEEK(state->fd, offset, SEEK_CUR); + if (ret == -1) + return -1; + state->have = 0; + state->eof = 0; + state->seek = 0; + gz_error(state, Z_OK, NULL); + state->strm.avail_in = 0; + state->pos += offset; + return state->pos; + } + + /* calculate skip amount, rewinding if needed for back seek when reading */ + if (offset < 0) { + if (state->mode != GZ_READ) /* writing -- can't go backwards */ + return -1; + offset += state->pos; + if (offset < 0) /* before start of file! */ + return -1; + if (gzrewind(file) == -1) /* rewind, then skip to offset */ + return -1; + } + + /* if reading, skip what's in output buffer (one less gzgetc() check) */ + if (state->mode == GZ_READ) { + n = GT_OFF(state->have) || (z_off64_t)state->have > offset ? + (unsigned)offset : state->have; + state->have -= n; + state->next += n; + state->pos += n; + offset -= n; + } + + /* request skip (if not zero) */ + if (offset) { + state->seek = 1; + state->skip = offset; + } + return state->pos + offset; +} + +/* -- see zlib.h -- */ +z_off_t ZEXPORT gzseek(file, offset, whence) + gzFile file; + z_off_t offset; + int whence; +{ + z_off64_t ret; + + ret = gzseek64(file, (z_off64_t)offset, whence); + return ret == (z_off_t)ret ? (z_off_t)ret : -1; +} + +/* -- see zlib.h -- */ +z_off64_t ZEXPORT gztell64(file) + gzFile file; +{ + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return -1; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return -1; + + /* return position */ + return state->pos + (state->seek ? state->skip : 0); +} + +/* -- see zlib.h -- */ +z_off_t ZEXPORT gztell(file) + gzFile file; +{ + z_off64_t ret; + + ret = gztell64(file); + return ret == (z_off_t)ret ? (z_off_t)ret : -1; +} + +/* -- see zlib.h -- */ +z_off64_t ZEXPORT gzoffset64(file) + gzFile file; +{ + z_off64_t offset; + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return -1; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return -1; + + /* compute and return effective offset in file */ + offset = LSEEK(state->fd, 0, SEEK_CUR); + if (offset == -1) + return -1; + if (state->mode == GZ_READ) /* reading */ + offset -= state->strm.avail_in; /* don't count buffered input */ + return offset; +} + +/* -- see zlib.h -- */ +z_off_t ZEXPORT gzoffset(file) + gzFile file; +{ + z_off64_t ret; + + ret = gzoffset64(file); + return ret == (z_off_t)ret ? (z_off_t)ret : -1; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzeof(file) + gzFile file; +{ + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return 0; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return 0; + + /* return end-of-file state */ + return state->mode == GZ_READ ? (state->eof && state->have == 0) : 0; +} + +/* -- see zlib.h -- */ +const char * ZEXPORT gzerror(file, errnum) + gzFile file; + int *errnum; +{ + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return NULL; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return NULL; + + /* return error information */ + if (errnum != NULL) + *errnum = state->err; + return state->msg == NULL ? "" : state->msg; +} + +/* -- see zlib.h -- */ +void ZEXPORT gzclearerr(file) + gzFile file; +{ + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return; + + /* clear error and end-of-file */ + if (state->mode == GZ_READ) + state->eof = 0; + gz_error(state, Z_OK, NULL); +} + +/* Create an error message in allocated memory and set state->err and + state->msg accordingly. Free any previous error message already there. Do + not try to free or allocate space if the error is Z_MEM_ERROR (out of + memory). Simply save the error message as a static string. If there is an + allocation failure constructing the error message, then convert the error to + out of memory. */ +void ZEXPORT gz_error(state, err, msg) + gz_statep state; + int err; + const char *msg; +{ + /* free previously allocated message and clear */ + if (state->msg != NULL) { + if (state->err != Z_MEM_ERROR) + free(state->msg); + state->msg = NULL; + } + + /* set error code, and if no message, then done */ + state->err = err; + if (msg == NULL) + return; + + /* for an out of memory error, save as static string */ + if (err == Z_MEM_ERROR) { + state->msg = (char *)msg; + return; + } + + /* construct error message with path */ + if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { + state->err = Z_MEM_ERROR; + state->msg = (char *)"out of memory"; + return; + } + strcpy(state->msg, state->path); + strcat(state->msg, ": "); + strcat(state->msg, msg); + return; +} + +#ifndef INT_MAX +/* portably return maximum value for an int (when limits.h presumed not + available) -- we need to do this to cover cases where 2's complement not + used, since C standard permits 1's complement and sign-bit representations, + otherwise we could just use ((unsigned)-1) >> 1 */ +unsigned ZEXPORT gz_intmax() +{ + unsigned p, q; + + p = 1; + do { + q = p; + p <<= 1; + p++; + } while (p > q); + return q >> 1; +} +#endif diff --git a/lib/libz/gzread.c b/lib/libz/gzread.c new file mode 100644 index 00000000000..fecc36b6988 --- /dev/null +++ b/lib/libz/gzread.c @@ -0,0 +1,653 @@ +/* gzread.c -- zlib functions for reading gzip files + * Copyright (C) 2004, 2005, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "gzguts.h" +#include + +/* Local functions */ +local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *)); +local int gz_avail OF((gz_statep)); +local int gz_next4 OF((gz_statep, unsigned long *)); +local int gz_head OF((gz_statep)); +local int gz_decomp OF((gz_statep)); +local int gz_make OF((gz_statep)); +local int gz_skip OF((gz_statep, z_off64_t)); + +/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from + state->fd, and update state->eof, state->err, and state->msg as appropriate. + This function needs to loop on read(), since read() is not guaranteed to + read the number of bytes requested, depending on the type of descriptor. */ +local int gz_load(state, buf, len, have) + gz_statep state; + unsigned char *buf; + unsigned len; + unsigned *have; +{ + int ret; + + *have = 0; + do { + ret = read(state->fd, buf + *have, len - *have); + if (ret <= 0) + break; + *have += ret; + } while (*have < len); + if (ret < 0) { + gz_error(state, Z_ERRNO, zstrerror()); + return -1; + } + if (ret == 0) + state->eof = 1; + return 0; +} + +/* Load up input buffer and set eof flag if last data loaded -- return -1 on + error, 0 otherwise. Note that the eof flag is set when the end of the input + file is reached, even though there may be unused data in the buffer. Once + that data has been used, no more attempts will be made to read the file. + gz_avail() assumes that strm->avail_in == 0. */ +local int gz_avail(state) + gz_statep state; +{ + z_streamp strm = &(state->strm); + + if (state->err != Z_OK) + return -1; + if (state->eof == 0) { + if (gz_load(state, state->in, state->size, &(strm->avail_in)) == -1) + return -1; + strm->next_in = state->in; + } + return 0; +} + +/* Get next byte from input, or -1 if end or error. */ +#define NEXT() ((strm->avail_in == 0 && gz_avail(state) == -1) ? -1 : \ + (strm->avail_in == 0 ? -1 : \ + (strm->avail_in--, *(strm->next_in)++))) + +/* Get a four-byte little-endian integer and return 0 on success and the value + in *ret. Otherwise -1 is returned and *ret is not modified. */ +local int gz_next4(state, ret) + gz_statep state; + unsigned long *ret; +{ + int ch; + unsigned long val; + z_streamp strm = &(state->strm); + + val = NEXT(); + val += (unsigned)NEXT() << 8; + val += (unsigned long)NEXT() << 16; + ch = NEXT(); + if (ch == -1) + return -1; + val += (unsigned long)ch << 24; + *ret = val; + return 0; +} + +/* Look for gzip header, set up for inflate or copy. state->have must be zero. + If this is the first time in, allocate required memory. state->how will be + left unchanged if there is no more input data available, will be set to COPY + if there is no gzip header and direct copying will be performed, or it will + be set to GZIP for decompression, and the gzip header will be skipped so + that the next available input data is the raw deflate stream. If direct + copying, then leftover input data from the input buffer will be copied to + the output buffer. In that case, all further file reads will be directly to + either the output buffer or a user buffer. If decompressing, the inflate + state and the check value will be initialized. gz_head() will return 0 on + success or -1 on failure. Failures may include read errors or gzip header + errors. */ +local int gz_head(state) + gz_statep state; +{ + z_streamp strm = &(state->strm); + int flags; + unsigned len; + + /* allocate read buffers and inflate memory */ + if (state->size == 0) { + /* allocate buffers */ + state->in = malloc(state->want); + state->out = malloc(state->want << 1); + if (state->in == NULL || state->out == NULL) { + if (state->out != NULL) + free(state->out); + if (state->in != NULL) + free(state->in); + gz_error(state, Z_MEM_ERROR, "out of memory"); + return -1; + } + state->size = state->want; + + /* allocate inflate memory */ + state->strm.zalloc = Z_NULL; + state->strm.zfree = Z_NULL; + state->strm.opaque = Z_NULL; + state->strm.avail_in = 0; + state->strm.next_in = Z_NULL; + if (inflateInit2(&(state->strm), -15) != Z_OK) { /* raw inflate */ + free(state->out); + free(state->in); + state->size = 0; + gz_error(state, Z_MEM_ERROR, "out of memory"); + return -1; + } + } + + /* get some data in the input buffer */ + if (strm->avail_in == 0) { + if (gz_avail(state) == -1) + return -1; + if (strm->avail_in == 0) + return 0; + } + + /* look for the gzip magic header bytes 31 and 139 */ + if (strm->next_in[0] == 31) { + strm->avail_in--; + strm->next_in++; + if (strm->avail_in == 0 && gz_avail(state) == -1) + return -1; + if (strm->avail_in && strm->next_in[0] == 139) { + /* we have a gzip header, woo hoo! */ + strm->avail_in--; + strm->next_in++; + + /* skip rest of header */ + if (NEXT() != 8) { /* compression method */ + gz_error(state, Z_DATA_ERROR, "unknown compression method"); + return -1; + } + flags = NEXT(); + if (flags & 0xe0) { /* reserved flag bits */ + gz_error(state, Z_DATA_ERROR, "unknown header flags set"); + return -1; + } + NEXT(); /* modification time */ + NEXT(); + NEXT(); + NEXT(); + NEXT(); /* extra flags */ + NEXT(); /* operating system */ + if (flags & 4) { /* extra field */ + len = (unsigned)NEXT(); + len += (unsigned)NEXT() << 8; + while (len--) + if (NEXT() < 0) + break; + } + if (flags & 8) /* file name */ + while (NEXT() > 0) + ; + if (flags & 16) /* comment */ + while (NEXT() > 0) + ; + if (flags & 2) { /* header crc */ + NEXT(); + NEXT(); + } + /* an unexpected end of file is not checked for here -- it will be + noticed on the first request for uncompressed data */ + + /* set up for decompression */ + inflateReset(strm); + strm->adler = crc32(0L, Z_NULL, 0); + state->how = GZIP; + state->direct = 0; + return 0; + } + else { + /* not a gzip file -- save first byte (31) and fall to raw i/o */ + state->out[0] = 31; + state->have = 1; + } + } + + /* doing raw i/o, save start of raw data for seeking, copy any leftover + input to output -- this assumes that the output buffer is larger than + the input buffer, which also assures space for gzungetc() */ + state->raw = state->pos; + state->next = state->out; + if (strm->avail_in) { + memcpy(state->next + state->have, strm->next_in, strm->avail_in); + state->have += strm->avail_in; + strm->avail_in = 0; + } + state->how = COPY; + state->direct = 1; + return 0; +} + +/* Decompress from input to the provided next_out and avail_out in the state. + If the end of the compressed data is reached, then verify the gzip trailer + check value and length (modulo 2^32). state->have and state->next are set + to point to the just decompressed data, and the crc is updated. If the + trailer is verified, state->how is reset to LOOK to look for the next gzip + stream or raw data, once state->have is depleted. Returns 0 on success, -1 + on failure. Failures may include invalid compressed data or a failed gzip + trailer verification. */ +local int gz_decomp(state) + gz_statep state; +{ + int ret; + unsigned had; + unsigned long crc, len; + z_streamp strm = &(state->strm); + + /* fill output buffer up to end of deflate stream */ + had = strm->avail_out; + do { + /* get more input for inflate() */ + if (strm->avail_in == 0 && gz_avail(state) == -1) + return -1; + if (strm->avail_in == 0) { + gz_error(state, Z_DATA_ERROR, "unexpected end of file"); + return -1; + } + + /* decompress and handle errors */ + ret = inflate(strm, Z_NO_FLUSH); + if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) { + gz_error(state, Z_STREAM_ERROR, + "internal error: inflate stream corrupt"); + return -1; + } + if (ret == Z_MEM_ERROR) { + gz_error(state, Z_MEM_ERROR, "out of memory"); + return -1; + } + if (ret == Z_DATA_ERROR) { /* deflate stream invalid */ + gz_error(state, Z_DATA_ERROR, + strm->msg == NULL ? "compressed data error" : strm->msg); + return -1; + } + } while (strm->avail_out && ret != Z_STREAM_END); + + /* update available output and crc check value */ + state->have = had - strm->avail_out; + state->next = strm->next_out - state->have; + strm->adler = crc32(strm->adler, state->next, state->have); + + /* check gzip trailer if at end of deflate stream */ + if (ret == Z_STREAM_END) { + if (gz_next4(state, &crc) == -1 || gz_next4(state, &len) == -1) { + gz_error(state, Z_DATA_ERROR, "unexpected end of file"); + return -1; + } + if (crc != strm->adler) { + gz_error(state, Z_DATA_ERROR, "incorrect data check"); + return -1; + } + if (len != (strm->total_out & 0xffffffffL)) { + gz_error(state, Z_DATA_ERROR, "incorrect length check"); + return -1; + } + state->how = LOOK; /* ready for next stream, once have is 0 (leave + state->direct unchanged to remember how) */ + } + + /* good decompression */ + return 0; +} + +/* Make data and put in the output buffer. Assumes that state->have == 0. + Data is either copied from the input file or decompressed from the input + file depending on state->how. If state->how is LOOK, then a gzip header is + looked for (and skipped if found) to determine wither to copy or decompress. + Returns -1 on error, otherwise 0. gz_make() will leave state->have as COPY + or GZIP unless the end of the input file has been reached and all data has + been processed. */ +local int gz_make(state) + gz_statep state; +{ + z_streamp strm = &(state->strm); + + if (state->how == LOOK) { /* look for gzip header */ + if (gz_head(state) == -1) + return -1; + if (state->have) /* got some data from gz_head() */ + return 0; + } + if (state->how == COPY) { /* straight copy */ + if (gz_load(state, state->out, state->size << 1, &(state->have)) == -1) + return -1; + state->next = state->out; + } + else if (state->how == GZIP) { /* decompress */ + strm->avail_out = state->size << 1; + strm->next_out = state->out; + if (gz_decomp(state) == -1) + return -1; + } + return 0; +} + +/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */ +local int gz_skip(state, len) + gz_statep state; + z_off64_t len; +{ + unsigned n; + + /* skip over len bytes or reach end-of-file, whichever comes first */ + while (len) + /* skip over whatever is in output buffer */ + if (state->have) { + n = GT_OFF(state->have) || (z_off64_t)state->have > len ? + (unsigned)len : state->have; + state->have -= n; + state->next += n; + state->pos += n; + len -= n; + } + + /* output buffer empty -- return if we're at the end of the input */ + else if (state->eof && state->strm.avail_in == 0) + break; + + /* need more data to skip -- load up output buffer */ + else { + /* get more output, looking for header if required */ + if (gz_make(state) == -1) + return -1; + } + return 0; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzread(file, buf, len) + gzFile file; + voidp buf; + unsigned len; +{ + unsigned got, n; + gz_statep state; + z_streamp strm; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're reading and that there's no error */ + if (state->mode != GZ_READ || state->err != Z_OK) + return -1; + + /* since an int is returned, make sure len fits in one, otherwise return + with an error (this avoids the flaw in the interface) */ + if ((int)len < 0) { + gz_error(state, Z_BUF_ERROR, "requested length does not fit in int"); + return -1; + } + + /* if len is zero, avoid unnecessary operations */ + if (len == 0) + return 0; + + /* process a skip request */ + if (state->seek) { + state->seek = 0; + if (gz_skip(state, state->skip) == -1) + return -1; + } + + /* get len bytes to buf, or less than len if at the end */ + got = 0; + do { + /* first just try copying data from the output buffer */ + if (state->have) { + n = state->have > len ? len : state->have; + memcpy(buf, state->next, n); + state->next += n; + state->have -= n; + } + + /* output buffer empty -- return if we're at the end of the input */ + else if (state->eof && strm->avail_in == 0) + break; + + /* need output data -- for small len or new stream load up our output + buffer */ + else if (state->how == LOOK || len < (state->size << 1)) { + /* get more output, looking for header if required */ + if (gz_make(state) == -1) + return -1; + continue; /* no progress yet -- go back to memcpy() above */ + /* the copy above assures that we will leave with space in the + output buffer, allowing at least one gzungetc() to succeed */ + } + + /* large len -- read directly into user buffer */ + else if (state->how == COPY) { /* read directly */ + if (gz_load(state, buf, len, &n) == -1) + return -1; + } + + /* large len -- decompress directly into user buffer */ + else { /* state->how == GZIP */ + strm->avail_out = len; + strm->next_out = buf; + if (gz_decomp(state) == -1) + return -1; + n = state->have; + state->have = 0; + } + + /* update progress */ + len -= n; + buf = (char *)buf + n; + got += n; + state->pos += n; + } while (len); + + /* return number of bytes read into user buffer (will fit in int) */ + return (int)got; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzgetc(file) + gzFile file; +{ + int ret; + unsigned char buf[1]; + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + + /* check that we're reading and that there's no error */ + if (state->mode != GZ_READ || state->err != Z_OK) + return -1; + + /* try output buffer (no need to check for skip request) */ + if (state->have) { + state->have--; + state->pos++; + return *(state->next)++; + } + + /* nothing there -- try gzread() */ + ret = gzread(file, buf, 1); + return ret < 1 ? -1 : buf[0]; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzungetc(c, file) + int c; + gzFile file; +{ + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + + /* check that we're reading and that there's no error */ + if (state->mode != GZ_READ || state->err != Z_OK) + return -1; + + /* process a skip request */ + if (state->seek) { + state->seek = 0; + if (gz_skip(state, state->skip) == -1) + return -1; + } + + /* can't push EOF */ + if (c < 0) + return -1; + + /* if output buffer empty, put byte at end (allows more pushing) */ + if (state->have == 0) { + state->have = 1; + state->next = state->out + (state->size << 1) - 1; + state->next[0] = c; + state->pos--; + return c; + } + + /* if no room, give up (must have already done a gzungetc()) */ + if (state->have == (state->size << 1)) { + gz_error(state, Z_BUF_ERROR, "out of room to push characters"); + return -1; + } + + /* slide output data if needed and insert byte before existing data */ + if (state->next == state->out) { + unsigned char *src = state->out + state->have; + unsigned char *dest = state->out + (state->size << 1); + while (src > state->out) + *--dest = *--src; + state->next = dest; + } + state->have++; + state->next--; + state->next[0] = c; + state->pos--; + return c; +} + +/* -- see zlib.h -- */ +char * ZEXPORT gzgets(file, buf, len) + gzFile file; + char *buf; + int len; +{ + unsigned left, n; + char *str; + unsigned char *eol; + gz_statep state; + + /* check parameters and get internal structure */ + if (file == NULL || buf == NULL || len < 1) + return NULL; + state = (gz_statep)file; + + /* check that we're reading and that there's no error */ + if (state->mode != GZ_READ || state->err != Z_OK) + return NULL; + + /* process a skip request */ + if (state->seek) { + state->seek = 0; + if (gz_skip(state, state->skip) == -1) + return NULL; + } + + /* copy output bytes up to new line or len - 1, whichever comes first -- + append a terminating zero to the string (we don't check for a zero in + the contents, let the user worry about that) */ + str = buf; + left = (unsigned)len - 1; + if (left) do { + /* assure that something is in the output buffer */ + if (state->have == 0) { + if (gz_make(state) == -1) + return NULL; /* error */ + if (state->have == 0) { /* end of file */ + if (buf == str) /* got bupkus */ + return NULL; + break; /* got something -- return it */ + } + } + + /* look for end-of-line in current output buffer */ + n = state->have > left ? left : state->have; + eol = memchr(state->next, '\n', n); + if (eol != NULL) + n = (unsigned)(eol - state->next) + 1; + + /* copy through end-of-line, or remainder if not found */ + memcpy(buf, state->next, n); + state->have -= n; + state->next += n; + state->pos += n; + left -= n; + buf += n; + } while (left && eol == NULL); + + /* found end-of-line or out of space -- terminate string and return it */ + buf[0] = 0; + return str; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzdirect(file) + gzFile file; +{ + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return 0; + state = (gz_statep)file; + + /* check that we're reading */ + if (state->mode != GZ_READ) + return 0; + + /* if the state is not known, but we can find out, then do so (this is + mainly for right after a gzopen() or gzdopen()) */ + if (state->how == LOOK && state->have == 0) + (void)gz_head(state); + + /* return 1 if reading direct, 0 if decompressing a gzip stream */ + return state->direct; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzclose_r(file) + gzFile file; +{ + int ret; + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return Z_STREAM_ERROR; + state = (gz_statep)file; + + /* check that we're reading */ + if (state->mode != GZ_READ) + return Z_STREAM_ERROR; + + /* free memory and close file */ + if (state->size) { + inflateEnd(&(state->strm)); + free(state->out); + free(state->in); + } + gz_error(state, Z_OK, NULL); + free(state->path); + ret = close(state->fd); + free(state); + return ret ? Z_ERRNO : Z_OK; +} diff --git a/lib/libz/gzwrite.c b/lib/libz/gzwrite.c new file mode 100644 index 00000000000..0f147315c79 --- /dev/null +++ b/lib/libz/gzwrite.c @@ -0,0 +1,532 @@ +/* gzwrite.c -- zlib functions for writing gzip files + * Copyright (C) 2004, 2005, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "gzguts.h" +#include + +/* Local functions */ +local int gz_init OF((gz_statep)); +local int gz_comp OF((gz_statep, int)); +local int gz_zero OF((gz_statep, z_off64_t)); + +/* Initialize state for writing a gzip file. Mark initialization by setting + state->size to non-zero. Return -1 on failure or 0 on success. */ +local int gz_init(state) + gz_statep state; +{ + int ret; + z_streamp strm = &(state->strm); + + /* allocate input and output buffers */ + state->in = malloc(state->want); + state->out = malloc(state->want); + if (state->in == NULL || state->out == NULL) { + if (state->out != NULL) + free(state->out); + if (state->in != NULL) + free(state->in); + gz_error(state, Z_MEM_ERROR, "out of memory"); + return -1; + } + + /* allocate deflate memory, set up for gzip compression */ + strm->zalloc = Z_NULL; + strm->zfree = Z_NULL; + strm->opaque = Z_NULL; + ret = deflateInit2(strm, state->level, Z_DEFLATED, + 15 + 16, 8, state->strategy); + if (ret != Z_OK) { + free(state->in); + gz_error(state, Z_MEM_ERROR, "out of memory"); + return -1; + } + + /* mark state as initialized */ + state->size = state->want; + + /* initialize write buffer */ + strm->avail_out = state->size; + strm->next_out = state->out; + state->next = strm->next_out; + return 0; +} + +/* Compress whatever is at avail_in and next_in and write to the output file. + Return -1 if there is an error writing to the output file, otherwise 0. + flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH, + then the deflate() state is reset to start a new gzip stream. */ +local int gz_comp(state, flush) + gz_statep state; + int flush; +{ + int ret, got; + unsigned have; + z_streamp strm = &(state->strm); + + /* allocate memory if this is the first time through */ + if (state->size == 0 && gz_init(state) == -1) + return -1; + + /* run deflate() on provided input until it produces no more output */ + ret = Z_OK; + do { + /* write out current buffer contents if full, or if flushing, but if + doing Z_FINISH then don't write until we get to Z_STREAM_END */ + if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && + (flush != Z_FINISH || ret == Z_STREAM_END))) { + have = (unsigned)(strm->next_out - state->next); + if (have && ((got = write(state->fd, state->next, have)) < 0 || + (unsigned)got != have)) { + gz_error(state, Z_ERRNO, zstrerror()); + return -1; + } + if (strm->avail_out == 0) { + strm->avail_out = state->size; + strm->next_out = state->out; + } + state->next = strm->next_out; + } + + /* compress */ + have = strm->avail_out; + ret = deflate(strm, flush); + if (ret == Z_STREAM_ERROR) { + gz_error(state, Z_STREAM_ERROR, + "internal error: deflate stream corrupt"); + return -1; + } + have -= strm->avail_out; + } while (have); + + /* if that completed a deflate stream, allow another to start */ + if (flush == Z_FINISH) + deflateReset(strm); + + /* all done, no errors */ + return 0; +} + +/* Compress len zeros to output. Return -1 on error, 0 on success. */ +local int gz_zero(state, len) + gz_statep state; + z_off64_t len; +{ + int first; + unsigned n; + z_streamp strm = &(state->strm); + + /* consume whatever's left in the input buffer */ + if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) + return -1; + + /* compress len zeros (len guaranteed > 0) */ + first = 1; + while (len) { + n = GT_OFF(state->size) || (z_off64_t)state->size > len ? + (unsigned)len : state->size; + if (first) { + memset(state->in, 0, n); + first = 0; + } + strm->avail_in = n; + strm->next_in = state->in; + state->pos += n; + if (gz_comp(state, Z_NO_FLUSH) == -1) + return -1; + len -= n; + } + return 0; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzwrite(file, buf, len) + gzFile file; + voidpc buf; + unsigned len; +{ + unsigned put = len; + unsigned n; + gz_statep state; + z_streamp strm; + + /* get internal structure */ + if (file == NULL) + return 0; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return 0; + + /* since an int is returned, make sure len fits in one, otherwise return + with an error (this avoids the flaw in the interface) */ + if ((int)len < 0) { + gz_error(state, Z_BUF_ERROR, "requested length does not fit in int"); + return 0; + } + + /* if len is zero, avoid unnecessary operations */ + if (len == 0) + return 0; + + /* allocate memory if this is the first time through */ + if (state->size == 0 && gz_init(state) == -1) + return 0; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return 0; + } + + /* for small len, copy to input buffer, otherwise compress directly */ + if (len < state->size) { + /* copy to input buffer, compress when full */ + do { + if (strm->avail_in == 0) + strm->next_in = state->in; + n = state->size - strm->avail_in; + if (n > len) + n = len; + memcpy(strm->next_in + strm->avail_in, buf, n); + strm->avail_in += n; + state->pos += n; + buf = (char *)buf + n; + len -= n; + if (len && gz_comp(state, Z_NO_FLUSH) == -1) + return 0; + } while (len); + } + else { + /* consume whatever's left in the input buffer */ + if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) + return 0; + + /* directly compress user buffer to file */ + strm->avail_in = len; + strm->next_in = (voidp)buf; + state->pos += len; + if (gz_comp(state, Z_NO_FLUSH) == -1) + return 0; + } + + /* input was all buffered or compressed (put will fit in int) */ + return (int)put; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzputc(file, c) + gzFile file; + int c; +{ + unsigned char buf[1]; + gz_statep state; + z_streamp strm; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return -1; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return -1; + } + + /* try writing to input buffer for speed (state->size == 0 if buffer not + initialized) */ + if (strm->avail_in < state->size) { + if (strm->avail_in == 0) + strm->next_in = state->in; + strm->next_in[strm->avail_in++] = c; + state->pos++; + return c; + } + + /* no room in buffer or not initialized, use gz_write() */ + buf[0] = c; + if (gzwrite(file, buf, 1) != 1) + return -1; + return c; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzputs(file, str) + gzFile file; + const char *str; +{ + int ret; + unsigned len; + + /* write string */ + len = (unsigned)strlen(str); + ret = gzwrite(file, str, len); + return ret == 0 && len != 0 ? -1 : ret; +} + +#ifdef STDC +#include + +/* -- see zlib.h -- */ +int ZEXPORTVA gzprintf (gzFile file, const char *format, ...) +{ + int size, len; + gz_statep state; + z_streamp strm; + va_list va; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return 0; + + /* make sure we have some buffer space */ + if (state->size == 0 && gz_init(state) == -1) + return 0; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return 0; + } + + /* consume whatever's left in the input buffer */ + if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) + return 0; + + /* do the printf() into the input buffer, put length in len */ + size = (int)(state->size); + state->in[size - 1] = 0; + va_start(va, format); +#ifdef NO_vsnprintf +# ifdef HAS_vsprintf_void + (void)vsprintf(state->in, format, va); + va_end(va); + for (len = 0; len < size; len++) + if (state->in[len] == 0) break; +# else + len = vsprintf(state->in, format, va); + va_end(va); +# endif +#else +# ifdef HAS_vsnprintf_void + (void)vsnprintf(state->in, size, format, va); + va_end(va); + len = strlen(state->in); +# else + len = vsnprintf((char *)(state->in), size, format, va); + va_end(va); +# endif +#endif + + /* check that printf() results fit in buffer */ + if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) + return 0; + + /* update buffer and position, defer compression until needed */ + strm->avail_in = (unsigned)len; + strm->next_in = state->in; + state->pos += len; + return len; +} + +#else /* !STDC */ + +/* -- see zlib.h -- */ +int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) + gzFile file; + const char *format; + int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; +{ + int size, len; + gz_statep state; + z_streamp strm; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return 0; + + /* make sure we have some buffer space */ + if (state->size == 0 && gz_init(state) == -1) + return 0; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return 0; + } + + /* consume whatever's left in the input buffer */ + if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) + return 0; + + /* do the printf() into the input buffer, put length in len */ + size = (int)(state->size); + state->in[size - 1] = 0; +#ifdef NO_snprintf +# ifdef HAS_sprintf_void + sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); + for (len = 0; len < size; len++) + if (state->in[len] == 0) break; +# else + len = sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); +# endif +#else +# ifdef HAS_snprintf_void + snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); + len = strlen(state->in); +# else + len = snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); +# endif +#endif + + /* check that printf() results fit in buffer */ + if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) + return 0; + + /* update buffer and position, defer compression until needed */ + strm->avail_in = (unsigned)len; + strm->next_in = state->in; + state->pos += len; + return len; +} + +#endif + +/* -- see zlib.h -- */ +int ZEXPORT gzflush(file, flush) + gzFile file; + int flush; +{ + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return Z_STREAM_ERROR; + + /* check flush parameter */ + if (flush < 0 || flush > Z_FINISH) + return Z_STREAM_ERROR; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return -1; + } + + /* compress remaining data with requested flush */ + gz_comp(state, flush); + return state->err; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzsetparams(file, level, strategy) + gzFile file; + int level; + int strategy; +{ + gz_statep state; + z_streamp strm; + + /* get internal structure */ + if (file == NULL) + return Z_STREAM_ERROR; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return Z_STREAM_ERROR; + + /* if no change is requested, then do nothing */ + if (level == state->level && strategy == state->strategy) + return Z_OK; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return -1; + } + + /* change compression parameters for subsequent input */ + if (state->size) { + /* flush previous input with previous parameters before changing */ + if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1) + return state->err; + deflateParams(strm, level, strategy); + } + state->level = level; + state->strategy = strategy; + return Z_OK; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzclose_w(file) + gzFile file; +{ + int ret = 0; + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return Z_STREAM_ERROR; + state = (gz_statep)file; + + /* check that we're writing */ + if (state->mode != GZ_WRITE) + return Z_STREAM_ERROR; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + ret += gz_zero(state, state->skip); + } + + /* flush, free memory, and close file */ + ret += gz_comp(state, Z_FINISH); + (void)deflateEnd(&(state->strm)); + free(state->out); + free(state->in); + gz_error(state, Z_OK, NULL); + free(state->path); + ret += close(state->fd); + free(state); + return ret ? Z_ERRNO : Z_OK; +} diff --git a/lib/libz/infback.c b/lib/libz/infback.c index 455dbc9ee84..af3a8c965d5 100644 --- a/lib/libz/infback.c +++ b/lib/libz/infback.c @@ -1,5 +1,5 @@ /* infback.c -- inflate using a call-back interface - * Copyright (C) 1995-2005 Mark Adler + * Copyright (C) 1995-2009 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -55,7 +55,7 @@ int stream_size; state->wbits = windowBits; state->wsize = 1U << windowBits; state->window = window; - state->write = 0; + state->wnext = 0; state->whave = 0; return Z_OK; } @@ -253,7 +253,7 @@ void FAR *out_desc; unsigned bits; /* bits in bit buffer */ unsigned copy; /* number of stored or match bytes to copy */ unsigned char FAR *from; /* where to copy match bytes from */ - code this; /* current decoding table entry */ + code here; /* current decoding table entry */ code last; /* parent table entry */ unsigned len; /* length to copy for repeats, bits to drop */ int ret; /* return code */ @@ -389,19 +389,19 @@ void FAR *out_desc; state->have = 0; while (state->have < state->nlen + state->ndist) { for (;;) { - this = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(this.bits) <= bits) break; + here = state->lencode[BITS(state->lenbits)]; + if ((unsigned)(here.bits) <= bits) break; PULLBYTE(); } - if (this.val < 16) { - NEEDBITS(this.bits); - DROPBITS(this.bits); - state->lens[state->have++] = this.val; + if (here.val < 16) { + NEEDBITS(here.bits); + DROPBITS(here.bits); + state->lens[state->have++] = here.val; } else { - if (this.val == 16) { - NEEDBITS(this.bits + 2); - DROPBITS(this.bits); + if (here.val == 16) { + NEEDBITS(here.bits + 2); + DROPBITS(here.bits); if (state->have == 0) { strm->msg = (char *)"invalid bit length repeat"; state->mode = BAD; @@ -411,16 +411,16 @@ void FAR *out_desc; copy = 3 + BITS(2); DROPBITS(2); } - else if (this.val == 17) { - NEEDBITS(this.bits + 3); - DROPBITS(this.bits); + else if (here.val == 17) { + NEEDBITS(here.bits + 3); + DROPBITS(here.bits); len = 0; copy = 3 + BITS(3); DROPBITS(3); } else { - NEEDBITS(this.bits + 7); - DROPBITS(this.bits); + NEEDBITS(here.bits + 7); + DROPBITS(here.bits); len = 0; copy = 11 + BITS(7); DROPBITS(7); @@ -438,7 +438,16 @@ void FAR *out_desc; /* handle error breaks in while */ if (state->mode == BAD) break; - /* build code tables */ + /* check for end-of-block code (better have one) */ + if (state->lens[256] == 0) { + strm->msg = (char *)"invalid code -- missing end-of-block"; + state->mode = BAD; + break; + } + + /* build code tables -- note: do not change the lenbits or distbits + values here (9 and 6) without reading the comments in inftrees.h + concerning the ENOUGH constants, which depend on those values */ state->next = state->codes; state->lencode = (code const FAR *)(state->next); state->lenbits = 9; @@ -474,28 +483,28 @@ void FAR *out_desc; /* get a literal, length, or end-of-block code */ for (;;) { - this = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(this.bits) <= bits) break; + here = state->lencode[BITS(state->lenbits)]; + if ((unsigned)(here.bits) <= bits) break; PULLBYTE(); } - if (this.op && (this.op & 0xf0) == 0) { - last = this; + if (here.op && (here.op & 0xf0) == 0) { + last = here; for (;;) { - this = state->lencode[last.val + + here = state->lencode[last.val + (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + this.bits) <= bits) break; + if ((unsigned)(last.bits + here.bits) <= bits) break; PULLBYTE(); } DROPBITS(last.bits); } - DROPBITS(this.bits); - state->length = (unsigned)this.val; + DROPBITS(here.bits); + state->length = (unsigned)here.val; /* process literal */ - if (this.op == 0) { - Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ? + if (here.op == 0) { + Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", this.val)); + "inflate: literal 0x%02x\n", here.val)); ROOM(); *put++ = (unsigned char)(state->length); left--; @@ -504,21 +513,21 @@ void FAR *out_desc; } /* process end of block */ - if (this.op & 32) { + if (here.op & 32) { Tracevv((stderr, "inflate: end of block\n")); state->mode = TYPE; break; } /* invalid code */ - if (this.op & 64) { + if (here.op & 64) { strm->msg = (char *)"invalid literal/length code"; state->mode = BAD; break; } /* length code -- get extra bits, if any */ - state->extra = (unsigned)(this.op) & 15; + state->extra = (unsigned)(here.op) & 15; if (state->extra != 0) { NEEDBITS(state->extra); state->length += BITS(state->extra); @@ -528,30 +537,30 @@ void FAR *out_desc; /* get distance code */ for (;;) { - this = state->distcode[BITS(state->distbits)]; - if ((unsigned)(this.bits) <= bits) break; + here = state->distcode[BITS(state->distbits)]; + if ((unsigned)(here.bits) <= bits) break; PULLBYTE(); } - if ((this.op & 0xf0) == 0) { - last = this; + if ((here.op & 0xf0) == 0) { + last = here; for (;;) { - this = state->distcode[last.val + + here = state->distcode[last.val + (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + this.bits) <= bits) break; + if ((unsigned)(last.bits + here.bits) <= bits) break; PULLBYTE(); } DROPBITS(last.bits); } - DROPBITS(this.bits); - if (this.op & 64) { + DROPBITS(here.bits); + if (here.op & 64) { strm->msg = (char *)"invalid distance code"; state->mode = BAD; break; } - state->offset = (unsigned)this.val; + state->offset = (unsigned)here.val; /* get distance extra bits, if any */ - state->extra = (unsigned)(this.op) & 15; + state->extra = (unsigned)(here.op) & 15; if (state->extra != 0) { NEEDBITS(state->extra); state->offset += BITS(state->extra); diff --git a/lib/libz/inffast.c b/lib/libz/inffast.c index bbee92ed1e6..0a0761f3de0 100644 --- a/lib/libz/inffast.c +++ b/lib/libz/inffast.c @@ -1,5 +1,5 @@ /* inffast.c -- fast decoding - * Copyright (C) 1995-2004 Mark Adler + * Copyright (C) 1995-2008 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -79,7 +79,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ #endif unsigned wsize; /* window size or zero if not using window */ unsigned whave; /* valid bytes in the window */ - unsigned write; /* window write index */ + unsigned wnext; /* window write index */ unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ unsigned long hold; /* local strm->hold */ unsigned bits; /* local strm->bits */ @@ -87,7 +87,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ code const FAR *dcode; /* local strm->distcode */ unsigned lmask; /* mask for first level of length codes */ unsigned dmask; /* mask for first level of distance codes */ - code this; /* retrieved table entry */ + code here; /* retrieved table entry */ unsigned op; /* code bits, operation, extra bits, or */ /* window position, window bytes to copy */ unsigned len; /* match length, unused bytes */ @@ -106,7 +106,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ #endif wsize = state->wsize; whave = state->whave; - write = state->write; + wnext = state->wnext; window = state->window; hold = state->hold; bits = state->bits; @@ -124,20 +124,20 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ hold += (unsigned long)(PUP(in)) << bits; bits += 8; } - this = lcode[hold & lmask]; + here = lcode[hold & lmask]; dolen: - op = (unsigned)(this.bits); + op = (unsigned)(here.bits); hold >>= op; bits -= op; - op = (unsigned)(this.op); + op = (unsigned)(here.op); if (op == 0) { /* literal */ - Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ? + Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", this.val)); - PUP(out) = (unsigned char)(this.val); + "inflate: literal 0x%02x\n", here.val)); + PUP(out) = (unsigned char)(here.val); } else if (op & 16) { /* length base */ - len = (unsigned)(this.val); + len = (unsigned)(here.val); op &= 15; /* number of extra bits */ if (op) { if (bits < op) { @@ -155,14 +155,14 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ hold += (unsigned long)(PUP(in)) << bits; bits += 8; } - this = dcode[hold & dmask]; + here = dcode[hold & dmask]; dodist: - op = (unsigned)(this.bits); + op = (unsigned)(here.bits); hold >>= op; bits -= op; - op = (unsigned)(this.op); + op = (unsigned)(here.op); if (op & 16) { /* distance base */ - dist = (unsigned)(this.val); + dist = (unsigned)(here.val); op &= 15; /* number of extra bits */ if (bits < op) { hold += (unsigned long)(PUP(in)) << bits; @@ -187,12 +187,34 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ if (dist > op) { /* see if copy from window */ op = dist - op; /* distance back in window */ if (op > whave) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; + if (state->sane) { + strm->msg = + (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } +#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR + if (len <= op - whave) { + do { + PUP(out) = 0; + } while (--len); + continue; + } + len -= op - whave; + do { + PUP(out) = 0; + } while (--op > whave); + if (op == 0) { + from = out - dist; + do { + PUP(out) = PUP(from); + } while (--len); + continue; + } +#endif } from = window - OFF; - if (write == 0) { /* very common case */ + if (wnext == 0) { /* very common case */ from += wsize - op; if (op < len) { /* some from window */ len -= op; @@ -202,17 +224,17 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ from = out - dist; /* rest from output */ } } - else if (write < op) { /* wrap around window */ - from += wsize + write - op; - op -= write; + else if (wnext < op) { /* wrap around window */ + from += wsize + wnext - op; + op -= wnext; if (op < len) { /* some from end of window */ len -= op; do { PUP(out) = PUP(from); } while (--op); from = window - OFF; - if (write < len) { /* some from start of window */ - op = write; + if (wnext < len) { /* some from start of window */ + op = wnext; len -= op; do { PUP(out) = PUP(from); @@ -222,7 +244,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ } } else { /* contiguous in window */ - from += write - op; + from += wnext - op; if (op < len) { /* some from window */ len -= op; do { @@ -259,7 +281,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ } } else if ((op & 64) == 0) { /* 2nd level distance code */ - this = dcode[this.val + (hold & ((1U << op) - 1))]; + here = dcode[here.val + (hold & ((1U << op) - 1))]; goto dodist; } else { @@ -269,7 +291,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ } } else if ((op & 64) == 0) { /* 2nd level length code */ - this = lcode[this.val + (hold & ((1U << op) - 1))]; + here = lcode[here.val + (hold & ((1U << op) - 1))]; goto dolen; } else if (op & 32) { /* end-of-block */ @@ -305,7 +327,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): - Using bit fields for code structure - Different op definition to avoid & for extra bits (do & for table bits) - - Three separate decoding do-loops for direct, window, and write == 0 + - Three separate decoding do-loops for direct, window, and wnext == 0 - Special case for distance > 1 copies to do overlapped load and store copy - Explicit branch predictions (based on measured branch probabilities) - Deferring match copy and interspersed it with decoding subsequent codes diff --git a/lib/libz/inflate.c b/lib/libz/inflate.c index 792fdee8e9c..a8431abeacf 100644 --- a/lib/libz/inflate.c +++ b/lib/libz/inflate.c @@ -1,5 +1,5 @@ /* inflate.c -- zlib decompression - * Copyright (C) 1995-2005 Mark Adler + * Copyright (C) 1995-2010 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -45,7 +45,7 @@ * - Rearrange window copies in inflate_fast() for speed and simplification * - Unroll last copy for window match in inflate_fast() * - Use local copies of window variables in inflate_fast() for speed - * - Pull out common write == 0 case for speed in inflate_fast() + * - Pull out common wnext == 0 case for speed in inflate_fast() * - Make op and len in inflate_fast() unsigned for consistency * - Add FAR to lcode and dcode declarations in inflate_fast() * - Simplified bad distance check in inflate_fast() @@ -117,28 +117,52 @@ z_streamp strm; state->head = Z_NULL; state->wsize = 0; state->whave = 0; - state->write = 0; + state->wnext = 0; state->hold = 0; state->bits = 0; state->lencode = state->distcode = state->next = state->codes; + state->sane = 1; + state->back = -1; Tracev((stderr, "inflate: reset\n")); return Z_OK; } -int ZEXPORT inflatePrime(strm, bits, value) +int ZEXPORT inflateReset2(strm, windowBits) z_streamp strm; -int bits; -int value; +int windowBits; { + int wrap; struct inflate_state FAR *state; + /* get the state */ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; state = (struct inflate_state FAR *)strm->state; - if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR; - value &= (1L << bits) - 1; - state->hold += value << state->bits; - state->bits += bits; - return Z_OK; + + /* extract wrap request from windowBits parameter */ + if (windowBits < 0) { + wrap = 0; + windowBits = -windowBits; + } + else { + wrap = (windowBits >> 4) + 1; +#ifdef GUNZIP + if (windowBits < 48) + windowBits &= 15; +#endif + } + + /* set number of window bits, free window if different */ + if (windowBits && (windowBits < 8 || windowBits > 15)) + return Z_STREAM_ERROR; + if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) { + ZFREE(strm, state->window); + state->window = Z_NULL; + } + + /* update state and reset the rest of it */ + state->wrap = wrap; + state->wbits = (unsigned)windowBits; + return inflateReset(strm); } int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) @@ -147,6 +171,7 @@ int windowBits; const char *version; int stream_size; { + int ret; struct inflate_state FAR *state; if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || @@ -164,24 +189,13 @@ int stream_size; if (state == Z_NULL) return Z_MEM_ERROR; Tracev((stderr, "inflate: allocated\n")); strm->state = (struct internal_state FAR *)state; - if (windowBits < 0) { - state->wrap = 0; - windowBits = -windowBits; - } - else { - state->wrap = (windowBits >> 4) + 1; -#ifdef GUNZIP - if (windowBits < 48) windowBits &= 15; -#endif - } - if (windowBits < 8 || windowBits > 15) { + state->window = Z_NULL; + ret = inflateReset2(strm, windowBits); + if (ret != Z_OK) { ZFREE(strm, state); strm->state = Z_NULL; - return Z_STREAM_ERROR; } - state->wbits = (unsigned)windowBits; - state->window = Z_NULL; - return inflateReset(strm); + return ret; } int ZEXPORT inflateInit_(strm, version, stream_size) @@ -192,6 +206,27 @@ int stream_size; return inflateInit2_(strm, DEF_WBITS, version, stream_size); } +int ZEXPORT inflatePrime(strm, bits, value) +z_streamp strm; +int bits; +int value; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if (bits < 0) { + state->hold = 0; + state->bits = 0; + return Z_OK; + } + if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR; + value &= (1L << bits) - 1; + state->hold += value << state->bits; + state->bits += bits; + return Z_OK; +} + /* Return state with length and distance decoding tables and index sizes set to fixed code decoding. Normally this returns fixed tables from inffixed.h. @@ -340,7 +375,7 @@ unsigned out; /* if window not in use yet, initialize */ if (state->wsize == 0) { state->wsize = 1U << state->wbits; - state->write = 0; + state->wnext = 0; state->whave = 0; } @@ -348,22 +383,22 @@ unsigned out; copy = out - strm->avail_out; if (copy >= state->wsize) { zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); - state->write = 0; + state->wnext = 0; state->whave = state->wsize; } else { - dist = state->wsize - state->write; + dist = state->wsize - state->wnext; if (dist > copy) dist = copy; - zmemcpy(state->window + state->write, strm->next_out - copy, dist); + zmemcpy(state->window + state->wnext, strm->next_out - copy, dist); copy -= dist; if (copy) { zmemcpy(state->window, strm->next_out - copy, copy); - state->write = copy; + state->wnext = copy; state->whave = state->wsize; } else { - state->write += dist; - if (state->write == state->wsize) state->write = 0; + state->wnext += dist; + if (state->wnext == state->wsize) state->wnext = 0; if (state->whave < state->wsize) state->whave += dist; } } @@ -564,7 +599,7 @@ int flush; unsigned in, out; /* save starting available input and output */ unsigned copy; /* number of stored or match bytes to copy */ unsigned char FAR *from; /* where to copy match bytes from */ - code this; /* current decoding table entry */ + code here; /* current decoding table entry */ code last; /* parent table entry */ unsigned len; /* length to copy for repeats, bits to drop */ int ret; /* return code */ @@ -619,7 +654,9 @@ int flush; } DROPBITS(4); len = BITS(4) + 8; - if (len > state->wbits) { + if (state->wbits == 0) + state->wbits = len; + else if (len > state->wbits) { strm->msg = (char *)"invalid window size"; state->mode = BAD; break; @@ -771,7 +808,7 @@ int flush; strm->adler = state->check = adler32(0L, Z_NULL, 0); state->mode = TYPE; case TYPE: - if (flush == Z_BLOCK) goto inf_leave; + if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave; case TYPEDO: if (state->last) { BYTEBITS(); @@ -791,7 +828,11 @@ int flush; fixedtables(state); Tracev((stderr, "inflate: fixed codes block%s\n", state->last ? " (last)" : "")); - state->mode = LEN; /* decode codes */ + state->mode = LEN_; /* decode codes */ + if (flush == Z_TREES) { + DROPBITS(2); + goto inf_leave; + } break; case 2: /* dynamic block */ Tracev((stderr, "inflate: dynamic codes block%s\n", @@ -816,6 +857,9 @@ int flush; Tracev((stderr, "inflate: stored length %u\n", state->length)); INITBITS(); + state->mode = COPY_; + if (flush == Z_TREES) goto inf_leave; + case COPY_: state->mode = COPY; case COPY: copy = state->length; @@ -876,19 +920,19 @@ int flush; case CODELENS: while (state->have < state->nlen + state->ndist) { for (;;) { - this = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(this.bits) <= bits) break; + here = state->lencode[BITS(state->lenbits)]; + if ((unsigned)(here.bits) <= bits) break; PULLBYTE(); } - if (this.val < 16) { - NEEDBITS(this.bits); - DROPBITS(this.bits); - state->lens[state->have++] = this.val; + if (here.val < 16) { + NEEDBITS(here.bits); + DROPBITS(here.bits); + state->lens[state->have++] = here.val; } else { - if (this.val == 16) { - NEEDBITS(this.bits + 2); - DROPBITS(this.bits); + if (here.val == 16) { + NEEDBITS(here.bits + 2); + DROPBITS(here.bits); if (state->have == 0) { strm->msg = (char *)"invalid bit length repeat"; state->mode = BAD; @@ -898,16 +942,16 @@ int flush; copy = 3 + BITS(2); DROPBITS(2); } - else if (this.val == 17) { - NEEDBITS(this.bits + 3); - DROPBITS(this.bits); + else if (here.val == 17) { + NEEDBITS(here.bits + 3); + DROPBITS(here.bits); len = 0; copy = 3 + BITS(3); DROPBITS(3); } else { - NEEDBITS(this.bits + 7); - DROPBITS(this.bits); + NEEDBITS(here.bits + 7); + DROPBITS(here.bits); len = 0; copy = 11 + BITS(7); DROPBITS(7); @@ -925,7 +969,16 @@ int flush; /* handle error breaks in while */ if (state->mode == BAD) break; - /* build code tables */ + /* check for end-of-block code (better have one) */ + if (state->lens[256] == 0) { + strm->msg = (char *)"invalid code -- missing end-of-block"; + state->mode = BAD; + break; + } + + /* build code tables -- note: do not change the lenbits or distbits + values here (9 and 6) without reading the comments in inftrees.h + concerning the ENOUGH constants, which depend on those values */ state->next = state->codes; state->lencode = (code const FAR *)(state->next); state->lenbits = 9; @@ -946,88 +999,102 @@ int flush; break; } Tracev((stderr, "inflate: codes ok\n")); + state->mode = LEN_; + if (flush == Z_TREES) goto inf_leave; + case LEN_: state->mode = LEN; case LEN: if (have >= 6 && left >= 258) { RESTORE(); inflate_fast(strm, out); LOAD(); + if (state->mode == TYPE) + state->back = -1; break; } + state->back = 0; for (;;) { - this = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(this.bits) <= bits) break; + here = state->lencode[BITS(state->lenbits)]; + if ((unsigned)(here.bits) <= bits) break; PULLBYTE(); } - if (this.op && (this.op & 0xf0) == 0) { - last = this; + if (here.op && (here.op & 0xf0) == 0) { + last = here; for (;;) { - this = state->lencode[last.val + + here = state->lencode[last.val + (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + this.bits) <= bits) break; + if ((unsigned)(last.bits + here.bits) <= bits) break; PULLBYTE(); } DROPBITS(last.bits); + state->back += last.bits; } - DROPBITS(this.bits); - state->length = (unsigned)this.val; - if ((int)(this.op) == 0) { - Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ? + DROPBITS(here.bits); + state->back += here.bits; + state->length = (unsigned)here.val; + if ((int)(here.op) == 0) { + Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", this.val)); + "inflate: literal 0x%02x\n", here.val)); state->mode = LIT; break; } - if (this.op & 32) { + if (here.op & 32) { Tracevv((stderr, "inflate: end of block\n")); + state->back = -1; state->mode = TYPE; break; } - if (this.op & 64) { + if (here.op & 64) { strm->msg = (char *)"invalid literal/length code"; state->mode = BAD; break; } - state->extra = (unsigned)(this.op) & 15; + state->extra = (unsigned)(here.op) & 15; state->mode = LENEXT; case LENEXT: if (state->extra) { NEEDBITS(state->extra); state->length += BITS(state->extra); DROPBITS(state->extra); + state->back += state->extra; } Tracevv((stderr, "inflate: length %u\n", state->length)); + state->was = state->length; state->mode = DIST; case DIST: for (;;) { - this = state->distcode[BITS(state->distbits)]; - if ((unsigned)(this.bits) <= bits) break; + here = state->distcode[BITS(state->distbits)]; + if ((unsigned)(here.bits) <= bits) break; PULLBYTE(); } - if ((this.op & 0xf0) == 0) { - last = this; + if ((here.op & 0xf0) == 0) { + last = here; for (;;) { - this = state->distcode[last.val + + here = state->distcode[last.val + (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + this.bits) <= bits) break; + if ((unsigned)(last.bits + here.bits) <= bits) break; PULLBYTE(); } DROPBITS(last.bits); + state->back += last.bits; } - DROPBITS(this.bits); - if (this.op & 64) { + DROPBITS(here.bits); + state->back += here.bits; + if (here.op & 64) { strm->msg = (char *)"invalid distance code"; state->mode = BAD; break; } - state->offset = (unsigned)this.val; - state->extra = (unsigned)(this.op) & 15; + state->offset = (unsigned)here.val; + state->extra = (unsigned)(here.op) & 15; state->mode = DISTEXT; case DISTEXT: if (state->extra) { NEEDBITS(state->extra); state->offset += BITS(state->extra); DROPBITS(state->extra); + state->back += state->extra; } #ifdef INFLATE_STRICT if (state->offset > state->dmax) { @@ -1036,11 +1103,6 @@ int flush; break; } #endif - if (state->offset > state->whave + out - left) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } Tracevv((stderr, "inflate: distance %u\n", state->offset)); state->mode = MATCH; case MATCH: @@ -1048,12 +1110,32 @@ int flush; copy = out - left; if (state->offset > copy) { /* copy from window */ copy = state->offset - copy; - if (copy > state->write) { - copy -= state->write; + if (copy > state->whave) { + if (state->sane) { + strm->msg = (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } +#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR + Trace((stderr, "inflate.c too far\n")); + copy -= state->whave; + if (copy > state->length) copy = state->length; + if (copy > left) copy = left; + left -= copy; + state->length -= copy; + do { + *put++ = 0; + } while (--copy); + if (state->length == 0) state->mode = LEN; + break; +#endif + } + if (copy > state->wnext) { + copy -= state->wnext; from = state->window + (state->wsize - copy); } else - from = state->window + (state->write - copy); + from = state->window + (state->wnext - copy); if (copy > state->length) copy = state->length; } else { /* copy from output */ @@ -1146,7 +1228,8 @@ int flush; strm->adler = state->check = UPDATE(state->check, strm->next_out - out, out); strm->data_type = state->bits + (state->last ? 64 : 0) + - (state->mode == TYPE ? 128 : 0); + (state->mode == TYPE ? 128 : 0) + + (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0); if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK) ret = Z_BUF_ERROR; return ret; @@ -1366,3 +1449,32 @@ z_streamp source; dest->state = (struct internal_state FAR *)copy; return Z_OK; } + +int ZEXPORT inflateUndermine(strm, subvert) +z_streamp strm; +int subvert; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + state->sane = !subvert; +#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR + return Z_OK; +#else + state->sane = 1; + return Z_DATA_ERROR; +#endif +} + +long ZEXPORT inflateMark(strm) +z_streamp strm; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16; + state = (struct inflate_state FAR *)strm->state; + return ((long)(state->back) << 16) + + (state->mode == COPY ? state->length : + (state->mode == MATCH ? state->was - state->length : 0)); +} diff --git a/lib/libz/inflate.h b/lib/libz/inflate.h index 07bd3e78a7c..95f4986d400 100644 --- a/lib/libz/inflate.h +++ b/lib/libz/inflate.h @@ -1,5 +1,5 @@ /* inflate.h -- internal inflate state definition - * Copyright (C) 1995-2004 Mark Adler + * Copyright (C) 1995-2009 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -32,11 +32,13 @@ typedef enum { TYPE, /* i: waiting for type bits, including last-flag bit */ TYPEDO, /* i: same, but skip check to exit inflate on new block */ STORED, /* i: waiting for stored size (length and complement) */ + COPY_, /* i/o: same as COPY below, but only first time in */ COPY, /* i/o: waiting for input or output to copy stored block */ TABLE, /* i: waiting for dynamic block table lengths */ LENLENS, /* i: waiting for code length code lengths */ CODELENS, /* i: waiting for length/lit and distance code lengths */ - LEN, /* i: waiting for length/lit code */ + LEN_, /* i: same as LEN below, but only first time in */ + LEN, /* i: waiting for length/lit/eob code */ LENEXT, /* i: waiting for length extra bits */ DIST, /* i: waiting for distance code */ DISTEXT, /* i: waiting for distance extra bits */ @@ -53,19 +55,21 @@ typedef enum { /* State transitions between above modes - - (most modes can go to the BAD or MEM mode -- not shown for clarity) + (most modes can go to BAD or MEM on error -- not shown for clarity) Process header: - HEAD -> (gzip) or (zlib) - (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME - NAME -> COMMENT -> HCRC -> TYPE + HEAD -> (gzip) or (zlib) or (raw) + (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> + HCRC -> TYPE (zlib) -> DICTID or TYPE DICTID -> DICT -> TYPE + (raw) -> TYPEDO Read deflate blocks: - TYPE -> STORED or TABLE or LEN or CHECK - STORED -> COPY -> TYPE - TABLE -> LENLENS -> CODELENS -> LEN - Read deflate codes: + TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK + STORED -> COPY_ -> COPY -> TYPE + TABLE -> LENLENS -> CODELENS -> LEN_ + LEN_ -> LEN + Read deflate codes in fixed or dynamic block: LEN -> LENEXT or LIT or TYPE LENEXT -> DIST -> DISTEXT -> MATCH -> LEN LIT -> LEN @@ -73,7 +77,7 @@ typedef enum { CHECK -> LENGTH -> DONE */ -/* state maintained between inflate() calls. Approximately 7K bytes. */ +/* state maintained between inflate() calls. Approximately 10K bytes. */ struct inflate_state { inflate_mode mode; /* current inflate mode */ int last; /* true if processing last block */ @@ -88,7 +92,7 @@ struct inflate_state { unsigned wbits; /* log base 2 of requested window size */ unsigned wsize; /* window size or zero if not using window */ unsigned whave; /* valid bytes in the window */ - unsigned write; /* window write index */ + unsigned wnext; /* window write index */ unsigned char FAR *window; /* allocated sliding window, if needed */ /* bit accumulator */ unsigned long hold; /* input bit accumulator */ @@ -112,4 +116,7 @@ struct inflate_state { unsigned short lens[320]; /* temporary storage for code lengths */ unsigned short work[288]; /* work area for code table building */ code codes[ENOUGH]; /* space for code tables */ + int sane; /* if false, allow invalid distance too far */ + int back; /* bits back of last unprocessed length/lit */ + unsigned was; /* initial length of match */ }; diff --git a/lib/libz/inftrees.c b/lib/libz/inftrees.c index 8a9c13ff03d..ccf7fa965f6 100644 --- a/lib/libz/inftrees.c +++ b/lib/libz/inftrees.c @@ -1,5 +1,5 @@ /* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2005 Mark Adler + * Copyright (C) 1995-2010 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -9,7 +9,7 @@ #define MAXBITS 15 const char inflate_copyright[] = - " inflate 1.2.3 Copyright 1995-2005 Mark Adler "; + " inflate 1.2.4 Copyright 1995-2010 Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -50,7 +50,7 @@ unsigned short FAR *work; unsigned fill; /* index for replicating entries */ unsigned low; /* low bits for current root entry */ unsigned mask; /* mask for low root bits */ - code this; /* table entry for duplication */ + code here; /* table entry for duplication */ code FAR *next; /* next available space in table */ const unsigned short FAR *base; /* base value table to use */ const unsigned short FAR *extra; /* extra bits table to use */ @@ -62,7 +62,7 @@ unsigned short FAR *work; 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196}; + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 64, 195}; static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, @@ -115,15 +115,15 @@ unsigned short FAR *work; if (count[max] != 0) break; if (root > max) root = max; if (max == 0) { /* no symbols to code at all */ - this.op = (unsigned char)64; /* invalid code marker */ - this.bits = (unsigned char)1; - this.val = (unsigned short)0; - *(*table)++ = this; /* make a table to force an error */ - *(*table)++ = this; + here.op = (unsigned char)64; /* invalid code marker */ + here.bits = (unsigned char)1; + here.val = (unsigned short)0; + *(*table)++ = here; /* make a table to force an error */ + *(*table)++ = here; *bits = 1; return 0; /* no symbols, but wait for decoding to report error */ } - for (min = 1; min <= MAXBITS; min++) + for (min = 1; min < max; min++) if (count[min] != 0) break; if (root < min) root = min; @@ -166,11 +166,10 @@ unsigned short FAR *work; entered in the tables. used keeps track of how many table entries have been allocated from the - provided *table space. It is checked when a LENS table is being made - against the space in *table, ENOUGH, minus the maximum space needed by - the worst case distance code, MAXD. This should never happen, but the - sufficiency of ENOUGH has not been proven exhaustively, hence the check. - This assumes that when type == LENS, bits == 9. + provided *table space. It is checked for LENS and DIST tables against + the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in + the initial root table size constants. See the comments in inftrees.h + for more information. sym increments through all symbols, and the loop terminates when all codes of length max, i.e. all codes, have been processed. This @@ -209,24 +208,25 @@ unsigned short FAR *work; mask = used - 1; /* mask for comparing low */ /* check available table space */ - if (type == LENS && used >= ENOUGH - MAXD) + if ((type == LENS && used >= ENOUGH_LENS) || + (type == DISTS && used >= ENOUGH_DISTS)) return 1; /* process all codes and make table entries */ for (;;) { /* create table entry */ - this.bits = (unsigned char)(len - drop); + here.bits = (unsigned char)(len - drop); if ((int)(work[sym]) < end) { - this.op = (unsigned char)0; - this.val = work[sym]; + here.op = (unsigned char)0; + here.val = work[sym]; } else if ((int)(work[sym]) > end) { - this.op = (unsigned char)(extra[work[sym]]); - this.val = base[work[sym]]; + here.op = (unsigned char)(extra[work[sym]]); + here.val = base[work[sym]]; } else { - this.op = (unsigned char)(32 + 64); /* end of block */ - this.val = 0; + here.op = (unsigned char)(32 + 64); /* end of block */ + here.val = 0; } /* replicate for those indices with low len bits equal to huff */ @@ -235,7 +235,7 @@ unsigned short FAR *work; min = fill; /* save offset to next table */ do { fill -= incr; - next[(huff >> drop) + fill] = this; + next[(huff >> drop) + fill] = here; } while (fill != 0); /* backwards increment the len-bit code huff */ @@ -277,7 +277,8 @@ unsigned short FAR *work; /* check for enough space */ used += 1U << curr; - if (type == LENS && used >= ENOUGH - MAXD) + if ((type == LENS && used >= ENOUGH_LENS) || + (type == DISTS && used >= ENOUGH_DISTS)) return 1; /* point entry in root table to sub-table */ @@ -295,20 +296,20 @@ unsigned short FAR *work; through high index bits. When the current sub-table is filled, the loop drops back to the root table to fill in any remaining entries there. */ - this.op = (unsigned char)64; /* invalid code marker */ - this.bits = (unsigned char)(len - drop); - this.val = (unsigned short)0; + here.op = (unsigned char)64; /* invalid code marker */ + here.bits = (unsigned char)(len - drop); + here.val = (unsigned short)0; while (huff != 0) { /* when done with sub-table, drop back to root table */ if (drop != 0 && (huff & mask) != low) { drop = 0; len = root; next = *table; - this.bits = (unsigned char)len; + here.bits = (unsigned char)len; } /* put invalid code marker in table */ - next[huff >> drop] = this; + next[huff >> drop] = here; /* backwards increment the len-bit code huff */ incr = 1U << (len - 1); diff --git a/lib/libz/inftrees.h b/lib/libz/inftrees.h index b1104c87e76..67461da0348 100644 --- a/lib/libz/inftrees.h +++ b/lib/libz/inftrees.h @@ -35,15 +35,22 @@ typedef struct { 01000000 - invalid code */ -/* Maximum size of dynamic tree. The maximum found in a long but non- - exhaustive search was 1444 code structures (852 for length/literals - and 592 for distances, the latter actually the result of an - exhaustive search). The true maximum is not known, but the value - below is more than safe. */ -#define ENOUGH 2048 -#define MAXD 592 +/* Maximum size of the dynamic table. The maximum number of code structures is + 1444, which is the sum of 852 for literal/length codes and 592 for distance + codes. These values were found by exhaustive searches using the program + examples/enough.c found in the zlib distribtution. The arguments to that + program are the number of symbols, the initial root table size, and the + maximum bit length of a code. "enough 286 9 15" for literal/length codes + returns returns 852, and "enough 30 6 15" for distance codes returns 592. + The initial root table size (9 or 6) is found in the fifth argument of the + inflate_table() calls in inflate.c and infback.c. If the root table size is + changed, then these maximum sizes would be need to be recalculated and + updated. */ +#define ENOUGH_LENS 852 +#define ENOUGH_DISTS 592 +#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) -/* Type of code to build for inftable() */ +/* Type of code to build for inflate_table() */ typedef enum { CODES, LENS, diff --git a/lib/libz/minigzip.c b/lib/libz/minigzip.c index b29d14aea48..84d823b72f9 100644 --- a/lib/libz/minigzip.c +++ b/lib/libz/minigzip.c @@ -1,5 +1,5 @@ /* minigzip.c -- simulate gzip using the zlib compression library - * Copyright (C) 1995-2005 Jean-loup Gailly. + * Copyright (C) 1995-2006, 2010 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -13,11 +13,10 @@ * or in pipe mode. */ -#include -__FBSDID("$FreeBSD$"); +/* @(#) $Id$ */ -#include #include "zlib.h" +#include #ifdef STDC # include @@ -55,6 +54,70 @@ __FBSDID("$FreeBSD$"); extern int unlink OF((const char *)); #endif +#if defined(UNDER_CE) && defined(NO_ERRNO_H) +# include +# define perror(s) pwinerror(s) + +/* Map the Windows error number in ERROR to a locale-dependent error + message string and return a pointer to it. Typically, the values + for ERROR come from GetLastError. + + The string pointed to shall not be modified by the application, + but may be overwritten by a subsequent call to strwinerror + + The strwinerror function does not change the current setting + of GetLastError. */ + +static char *strwinerror (error) + DWORD error; +{ + static char buf[1024]; + + wchar_t *msgbuf; + DWORD lasterr = GetLastError(); + DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_ALLOCATE_BUFFER, + NULL, + error, + 0, /* Default language */ + (LPVOID)&msgbuf, + 0, + NULL); + if (chars != 0) { + /* If there is an \r\n appended, zap it. */ + if (chars >= 2 + && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { + chars -= 2; + msgbuf[chars] = 0; + } + + if (chars > sizeof (buf) - 1) { + chars = sizeof (buf) - 1; + msgbuf[chars] = 0; + } + + wcstombs(buf, msgbuf, chars + 1); + LocalFree(msgbuf); + } + else { + sprintf(buf, "unknown win32 error (%ld)", error); + } + + SetLastError(lasterr); + return buf; +} + +static void pwinerror (s) + const char *s; +{ + if (s && *s) + fprintf(stderr, "%s: %s\n", s, strwinerror(GetLastError ())); + else + fprintf(stderr, "%s\n", strwinerror(GetLastError ())); +} + +#endif /* UNDER_CE && NO_ERRNO_H */ + #ifndef GZ_SUFFIX # define GZ_SUFFIX ".gz" #endif @@ -201,9 +264,9 @@ void file_compress(file, mode) if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) { fprintf(stderr, "%s: filename too long\n", prog); - exit(1); + exit(1); } - + strcpy(outfile, file); strcat(outfile, GZ_SUFFIX); @@ -237,7 +300,7 @@ void file_uncompress(file) if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) { fprintf(stderr, "%s: filename too long\n", prog); - exit(1); + exit(1); } strcpy(buf, file); @@ -304,9 +367,9 @@ int main(argc, argv) while (argc > 0) { if (strcmp(*argv, "-c") == 0) - copyout = 1; + copyout = 1; else if (strcmp(*argv, "-d") == 0) - uncompr = 1; + uncompr = 1; else if (strcmp(*argv, "-f") == 0) outmode[3] = 'f'; else if (strcmp(*argv, "-h") == 0) @@ -335,36 +398,36 @@ int main(argc, argv) gz_compress(stdin, file); } } else { - if (copyout) { - SET_BINARY_MODE(stdout); - } + if (copyout) { + SET_BINARY_MODE(stdout); + } do { if (uncompr) { - if (copyout) { - file = gzopen(*argv, "rb"); - if (file == NULL) - fprintf(stderr, "%s: can't gzopen %s\n", prog, *argv); - else - gz_uncompress(file, stdout); - } else { - file_uncompress(*argv); - } + if (copyout) { + file = gzopen(*argv, "rb"); + if (file == NULL) + fprintf(stderr, "%s: can't gzopen %s\n", prog, *argv); + else + gz_uncompress(file, stdout); + } else { + file_uncompress(*argv); + } } else { - if (copyout) { - FILE * in = fopen(*argv, "rb"); + if (copyout) { + FILE * in = fopen(*argv, "rb"); - if (in == NULL) { - perror(*argv); - } else { - file = gzdopen(fileno(stdout), outmode); - if (file == NULL) error("can't gzdopen stdout"); + if (in == NULL) { + perror(*argv); + } else { + file = gzdopen(fileno(stdout), outmode); + if (file == NULL) error("can't gzdopen stdout"); - gz_compress(in, file); - } - - } else { - file_compress(*argv, outmode); - } + gz_compress(in, file); + } + + } else { + file_compress(*argv, outmode); + } } } while (argv++, --argc); } diff --git a/lib/libz/trees.c b/lib/libz/trees.c index 395e4e16814..1a6e997ac0a 100644 --- a/lib/libz/trees.c +++ b/lib/libz/trees.c @@ -1,5 +1,6 @@ /* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-2005 Jean-loup Gailly + * Copyright (C) 1995-2009 Jean-loup Gailly + * detect_data_type() function provided freely by Cosmin Truta, 2006 * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -152,7 +153,7 @@ local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, int blcodes)); local void compress_block OF((deflate_state *s, ct_data *ltree, ct_data *dtree)); -local void set_data_type OF((deflate_state *s)); +local int detect_data_type OF((deflate_state *s)); local unsigned bi_reverse OF((unsigned value, int length)); local void bi_windup OF((deflate_state *s)); local void bi_flush OF((deflate_state *s)); @@ -203,12 +204,12 @@ local void send_bits(s, value, length) * unused bits in value. */ if (s->bi_valid > (int)Buf_size - length) { - s->bi_buf |= (value << s->bi_valid); + s->bi_buf |= (ush)value << s->bi_valid; put_short(s, s->bi_buf); s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); s->bi_valid += length - Buf_size; } else { - s->bi_buf |= value << s->bi_valid; + s->bi_buf |= (ush)value << s->bi_valid; s->bi_valid += length; } } @@ -218,12 +219,12 @@ local void send_bits(s, value, length) { int len = length;\ if (s->bi_valid > (int)Buf_size - len) {\ int val = value;\ - s->bi_buf |= (val << s->bi_valid);\ + s->bi_buf |= (ush)val << s->bi_valid;\ put_short(s, s->bi_buf);\ s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ s->bi_valid += len - Buf_size;\ } else {\ - s->bi_buf |= (value) << s->bi_valid;\ + s->bi_buf |= (ush)(value) << s->bi_valid;\ s->bi_valid += len;\ }\ } @@ -250,11 +251,13 @@ local void tr_static_init() if (static_init_done) return; /* For some embedded targets, global variables are not initialized: */ +#ifdef NO_INIT_GLOBAL_POINTERS static_l_desc.static_tree = static_ltree; static_l_desc.extra_bits = extra_lbits; static_d_desc.static_tree = static_dtree; static_d_desc.extra_bits = extra_dbits; static_bl_desc.extra_bits = extra_blbits; +#endif /* Initialize the mapping length (0..255) -> length code (0..28) */ length = 0; @@ -864,13 +867,13 @@ local void send_all_trees(s, lcodes, dcodes, blcodes) /* =========================================================================== * Send a stored block */ -void _tr_stored_block(s, buf, stored_len, eof) +void _tr_stored_block(s, buf, stored_len, last) deflate_state *s; charf *buf; /* input block */ ulg stored_len; /* length of input block */ - int eof; /* true if this is the last block for a file */ + int last; /* one if this is the last block for a file */ { - send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */ + send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */ #ifdef DEBUG s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; s->compressed_len += (stored_len + 4) << 3; @@ -918,11 +921,11 @@ void _tr_align(s) * Determine the best encoding for the current block: dynamic trees, static * trees or store, and output the encoded block to the zip file. */ -void _tr_flush_block(s, buf, stored_len, eof) +void _tr_flush_block(s, buf, stored_len, last) deflate_state *s; charf *buf; /* input block, or NULL if too old */ ulg stored_len; /* length of input block */ - int eof; /* true if this is the last block for a file */ + int last; /* one if this is the last block for a file */ { ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ int max_blindex = 0; /* index of last bit length code of non zero freq */ @@ -931,8 +934,8 @@ void _tr_flush_block(s, buf, stored_len, eof) if (s->level > 0) { /* Check if the file is binary or text */ - if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN) - set_data_type(s); + if (s->strm->data_type == Z_UNKNOWN) + s->strm->data_type = detect_data_type(s); /* Construct the literal and distance trees */ build_tree(s, (tree_desc *)(&(s->l_desc))); @@ -978,20 +981,20 @@ void _tr_flush_block(s, buf, stored_len, eof) * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to * transform a block into a stored block. */ - _tr_stored_block(s, buf, stored_len, eof); + _tr_stored_block(s, buf, stored_len, last); #ifdef FORCE_STATIC } else if (static_lenb >= 0) { /* force static trees */ #else } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { #endif - send_bits(s, (STATIC_TREES<<1)+eof, 3); + send_bits(s, (STATIC_TREES<<1)+last, 3); compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); #ifdef DEBUG s->compressed_len += 3 + s->static_len; #endif } else { - send_bits(s, (DYN_TREES<<1)+eof, 3); + send_bits(s, (DYN_TREES<<1)+last, 3); send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, max_blindex+1); compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree); @@ -1005,14 +1008,14 @@ void _tr_flush_block(s, buf, stored_len, eof) */ init_block(s); - if (eof) { + if (last) { bi_windup(s); #ifdef DEBUG s->compressed_len += 7; /* align on byte boundary */ #endif } Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, - s->compressed_len-7*eof)); + s->compressed_len-7*last)); } /* =========================================================================== @@ -1118,24 +1121,45 @@ local void compress_block(s, ltree, dtree) } /* =========================================================================== - * Set the data type to BINARY or TEXT, using a crude approximation: - * set it to Z_TEXT if all symbols are either printable characters (33 to 255) - * or white spaces (9 to 13, or 32); or set it to Z_BINARY otherwise. + * Check if the data type is TEXT or BINARY, using the following algorithm: + * - TEXT if the two conditions below are satisfied: + * a) There are no non-portable control characters belonging to the + * "black list" (0..6, 14..25, 28..31). + * b) There is at least one printable character belonging to the + * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). + * - BINARY otherwise. + * - The following partially-portable control characters form a + * "gray list" that is ignored in this detection algorithm: + * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). * IN assertion: the fields Freq of dyn_ltree are set. */ -local void set_data_type(s) +local int detect_data_type(s) deflate_state *s; { + /* black_mask is the bit mask of black-listed bytes + * set bits 0..6, 14..25, and 28..31 + * 0xf3ffc07f = binary 11110011111111111100000001111111 + */ + unsigned long black_mask = 0xf3ffc07fUL; int n; - for (n = 0; n < 9; n++) + /* Check for non-textual ("black-listed") bytes. */ + for (n = 0; n <= 31; n++, black_mask >>= 1) + if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0)) + return Z_BINARY; + + /* Check for textual ("white-listed") bytes. */ + if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 + || s->dyn_ltree[13].Freq != 0) + return Z_TEXT; + for (n = 32; n < LITERALS; n++) if (s->dyn_ltree[n].Freq != 0) - break; - if (n == 9) - for (n = 14; n < 32; n++) - if (s->dyn_ltree[n].Freq != 0) - break; - s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY; + return Z_TEXT; + + /* There are no "black-listed" or "white-listed" bytes: + * this stream either is empty or has tolerated ("gray-listed") bytes only. + */ + return Z_BINARY; } /* =========================================================================== diff --git a/lib/libz/uncompr.c b/lib/libz/uncompr.c index b59e3d0defb..ad98be3a5d8 100644 --- a/lib/libz/uncompr.c +++ b/lib/libz/uncompr.c @@ -1,5 +1,5 @@ /* uncompr.c -- decompress a memory buffer - * Copyright (C) 1995-2003 Jean-loup Gailly. + * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -16,8 +16,6 @@ been saved previously by the compressor and transmitted to the decompressor by some mechanism outside the scope of this compression library.) Upon exit, destLen is the actual size of the compressed buffer. - This function can be used to decompress a whole file at once if the - input file is mmap'ed. uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if there was not enough room in the output diff --git a/lib/libz/zconf.h b/lib/libz/zconf.h index 205db95c0f1..82d3af8743b 100644 --- a/lib/libz/zconf.h +++ b/lib/libz/zconf.h @@ -1,5 +1,5 @@ /* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2005 Jean-loup Gailly. + * Copyright (C) 1995-2010 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -11,52 +11,124 @@ /* * If you *really* need a unique prefix for all types and library functions, * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + * Even better than compiling with -DZ_PREFIX would be to use configure to set + * this permanently in zconf.h using "./configure --zprefix". */ -#ifdef Z_PREFIX -# define deflateInit_ z_deflateInit_ -# define deflate z_deflate -# define deflateEnd z_deflateEnd -# define inflateInit_ z_inflateInit_ -# define inflate z_inflate -# define inflateEnd z_inflateEnd -# define deflateInit2_ z_deflateInit2_ -# define deflateSetDictionary z_deflateSetDictionary -# define deflateCopy z_deflateCopy -# define deflateReset z_deflateReset -# define deflateParams z_deflateParams -# define deflateBound z_deflateBound -# define deflatePrime z_deflatePrime -# define inflateInit2_ z_inflateInit2_ -# define inflateSetDictionary z_inflateSetDictionary -# define inflateSync z_inflateSync -# define inflateSyncPoint z_inflateSyncPoint -# define inflateCopy z_inflateCopy -# define inflateReset z_inflateReset -# define inflateBack z_inflateBack -# define inflateBackEnd z_inflateBackEnd +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ + +/* all linked symbols */ +# define _dist_code z__dist_code +# define _length_code z__length_code +# define _tr_align z__tr_align +# define _tr_flush_block z__tr_flush_block +# define _tr_init z__tr_init +# define _tr_stored_block z__tr_stored_block +# define _tr_tally z__tr_tally +# define adler32 z_adler32 +# define adler32_combine z_adler32_combine +# define adler32_combine64 z_adler32_combine64 # define compress z_compress # define compress2 z_compress2 # define compressBound z_compressBound -# define uncompress z_uncompress -# define adler32 z_adler32 # define crc32 z_crc32 +# define crc32_combine z_crc32_combine +# define crc32_combine64 z_crc32_combine64 +# define deflate z_deflate +# define deflateBound z_deflateBound +# define deflateCopy z_deflateCopy +# define deflateEnd z_deflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateInit_ z_deflateInit_ +# define deflateParams z_deflateParams +# define deflatePrime z_deflatePrime +# define deflateReset z_deflateReset +# define deflateSetDictionary z_deflateSetDictionary +# define deflateSetHeader z_deflateSetHeader +# define deflateTune z_deflateTune +# define deflate_copyright z_deflate_copyright # define get_crc_table z_get_crc_table +# define gz_error z_gz_error +# define gz_intmax z_gz_intmax +# define gz_strwinerror z_gz_strwinerror +# define gzbuffer z_gzbuffer +# define gzclearerr z_gzclearerr +# define gzclose z_gzclose +# define gzclose_r z_gzclose_r +# define gzclose_w z_gzclose_w +# define gzdirect z_gzdirect +# define gzdopen z_gzdopen +# define gzeof z_gzeof +# define gzerror z_gzerror +# define gzflush z_gzflush +# define gzgetc z_gzgetc +# define gzgets z_gzgets +# define gzoffset z_gzoffset +# define gzoffset64 z_gzoffset64 +# define gzopen z_gzopen +# define gzopen64 z_gzopen64 +# define gzprintf z_gzprintf +# define gzputc z_gzputc +# define gzputs z_gzputs +# define gzread z_gzread +# define gzrewind z_gzrewind +# define gzseek z_gzseek +# define gzseek64 z_gzseek64 +# define gzsetparams z_gzsetparams +# define gztell z_gztell +# define gztell64 z_gztell64 +# define gzungetc z_gzungetc +# define gzwrite z_gzwrite +# define inflate z_inflate +# define inflateBack z_inflateBack +# define inflateBackEnd z_inflateBackEnd +# define inflateBackInit_ z_inflateBackInit_ +# define inflateCopy z_inflateCopy +# define inflateEnd z_inflateEnd +# define inflateGetHeader z_inflateGetHeader +# define inflateInit2_ z_inflateInit2_ +# define inflateInit_ z_inflateInit_ +# define inflateMark z_inflateMark +# define inflatePrime z_inflatePrime +# define inflateReset z_inflateReset +# define inflateReset2 z_inflateReset2 +# define inflateSetDictionary z_inflateSetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateUndermine z_inflateUndermine +# define inflate_copyright z_inflate_copyright +# define inflate_fast z_inflate_fast +# define inflate_table z_inflate_table +# define uncompress z_uncompress # define zError z_zError +# define zcalloc z_zcalloc +# define zcfree z_zcfree +# define zlibCompileFlags z_zlibCompileFlags +# define zlibVersion z_zlibVersion -# define alloc_func z_alloc_func -# define free_func z_free_func -# define in_func z_in_func -# define out_func z_out_func +/* all zlib typedefs in zlib.h and zconf.h */ # define Byte z_Byte -# define uInt z_uInt -# define uLong z_uLong # define Bytef z_Bytef +# define alloc_func z_alloc_func # define charf z_charf +# define free_func z_free_func +# define gzFile z_gzFile +# define gz_header z_gz_header +# define gz_headerp z_gz_headerp +# define in_func z_in_func # define intf z_intf +# define out_func z_out_func +# define uInt z_uInt # define uIntf z_uIntf +# define uLong z_uLong # define uLongf z_uLongf -# define voidpf z_voidpf # define voidp z_voidp +# define voidpc z_voidpc +# define voidpf z_voidpf + +/* all zlib structs in zlib.h and zconf.h */ +# define gz_header_s z_gz_header_s +# define internal_state z_internal_state + #endif #if defined(__MSDOS__) && !defined(MSDOS) @@ -243,6 +315,10 @@ # endif #endif +#ifdef HAVE_VISIBILITY_PRAGMA +# define ZEXTERN __attribute__((visibility ("default"))) extern +#endif + #ifndef ZEXTERN # define ZEXTERN extern #endif @@ -284,14 +360,25 @@ typedef uLong FAR uLongf; typedef Byte *voidp; #endif -#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */ -# include /* for off_t */ -# include /* for SEEK_* and off_t */ -# ifdef VMS -# include /* for off_t */ -# endif -# define z_off_t off_t +#if 0 /* was set to #if 0 by ./configure */ +# define Z_HAVE_UNISTD_H #endif + +#ifdef Z_HAVE_UNISTD_H +# include /* for off_t */ +# include /* for SEEK_* and off_t */ +# ifdef VMS +# include /* for off_t */ +# endif +# ifndef z_off_t +# define z_off_t off_t +# endif +#endif + +#ifdef _LARGEFILE64_SOURCE +# include +#endif + #ifndef SEEK_SET # define SEEK_SET 0 /* Seek from beginning of file. */ # define SEEK_CUR 1 /* Seek from current position. */ @@ -299,12 +386,13 @@ typedef uLong FAR uLongf; #endif /* - * This is hard-configured for FreeBSD, since zlib doesn't actually support - * using the system off_t for offsets unless off_t is no longer than long. - * To minimize the diff, we just "undef z_off_t" rather than modifying - * the following lines. + * This is hard-configured for FreeBSD. */ -#undef z_off_t +#include +#define z_off_t off_t +#ifndef _FILE_OFFSET_BITS +#define _FILE_OFFSET_BITS 64 +#endif #ifndef z_off_t # define z_off_t long @@ -316,26 +404,23 @@ typedef uLong FAR uLongf; #if defined(__MVS__) # define NO_vsnprintf -# ifdef FAR -# undef FAR -# endif #endif /* MVS linker does not support external names larger than 8 bytes */ #if defined(__MVS__) -# pragma map(deflateInit_,"DEIN") -# pragma map(deflateInit2_,"DEIN2") -# pragma map(deflateEnd,"DEEND") -# pragma map(deflateBound,"DEBND") -# pragma map(inflateInit_,"ININ") -# pragma map(inflateInit2_,"ININ2") -# pragma map(inflateEnd,"INEND") -# pragma map(inflateSync,"INSY") -# pragma map(inflateSetDictionary,"INSEDI") -# pragma map(compressBound,"CMBND") -# pragma map(inflate_table,"INTABL") -# pragma map(inflate_fast,"INFA") -# pragma map(inflate_copyright,"INCOPY") + #pragma map(deflateInit_,"DEIN") + #pragma map(deflateInit2_,"DEIN2") + #pragma map(deflateEnd,"DEEND") + #pragma map(deflateBound,"DEBND") + #pragma map(inflateInit_,"ININ") + #pragma map(inflateInit2_,"ININ2") + #pragma map(inflateEnd,"INEND") + #pragma map(inflateSync,"INSY") + #pragma map(inflateSetDictionary,"INSEDI") + #pragma map(compressBound,"CMBND") + #pragma map(inflate_table,"INTABL") + #pragma map(inflate_fast,"INFA") + #pragma map(inflate_copyright,"INCOPY") #endif #endif /* ZCONF_H */ diff --git a/lib/libz/zlib.3 b/lib/libz/zlib.3 index 90b8162870f..52999c70493 100644 --- a/lib/libz/zlib.3 +++ b/lib/libz/zlib.3 @@ -1,4 +1,4 @@ -.TH ZLIB 3 "18 July 2005" +.TH ZLIB 3 "14 March 2010" .SH NAME zlib \- compression/decompression library .SH SYNOPSIS @@ -9,15 +9,15 @@ for full description] The .I zlib library is a general purpose data compression library. -The code is thread safe. +The code is thread safe, assuming that the standard library functions +used are thread safe, such as memory allocation routines. It provides in-memory compression and decompression functions, including integrity checks of the uncompressed data. This version of the library supports only one compression method (deflation) -but other algorithms will be added later -and will have the same stream interface. +but other algorithms may be added later +with the same stream interface. .LP Compression can be done in a single step if the buffers are large enough -(for example if an input file is mmap'ed), or can be done by repeated calls of the compression function. In the latter case, the application must provide more input and/or consume the output @@ -30,7 +30,7 @@ with an interface similar to that of stdio. .LP The library does not install any signal handler. The decoder checks the consistency of the compressed data, -so the library should never crash even in case of corrupted input. +so the library should never crash even in the case of corrupted input. .LP All functions of the compression library are documented in the file .IR zlib.h . @@ -38,18 +38,19 @@ The distribution source includes examples of use of the library in the files .I example.c and -.IR minigzip.c . +.IR minigzip.c, +as well as other examples in the +.IR examples/ +directory. .LP Changes to this version are documented in the file .I ChangeLog -that accompanies the source, -and are concerned primarily with bug fixes and portability enhancements. +that accompanies the source. .LP -A Java implementation of .I zlib -is available in the Java Development Kit 1.1: +is available in Java using the java.util.zip package: .IP -http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html +http://java.sun.com/developer/technicalArticles/Programming/compression/ .LP A Perl interface to .IR zlib , @@ -57,7 +58,7 @@ written by Paul Marquess (pmqs@cpan.org), is available at CPAN (Comprehensive Perl Archive Network) sites, including: .IP -http://www.cpan.org/modules/by-module/Compress/ +http://search.cpan.org/~pmqs/IO-Compress-Zlib/ .LP A Python interface to .IR zlib , @@ -66,14 +67,11 @@ is available in Python 1.5 and later versions: .IP http://www.python.org/doc/lib/module-zlib.html .LP -A .I zlib -binding for -.IR tcl (1), -written by Andreas Kupries (a.kupries@westend.com), -is availlable at: +is built into +.IR tcl: .IP -http://www.westend.com/~kupries/doc/trf/man/man.html +http://wiki.tcl.tk/4610 .LP An experimental package to read and write files in .zip format, written on top of @@ -81,40 +79,34 @@ written on top of by Gilles Vollant (info@winimage.com), is available at: .IP -http://www.winimage.com/zLibDll/unzip.html +http://www.winimage.com/zLibDll/minizip.html and also in the .I contrib/minizip directory of the main .I zlib -web site. +source distribution. .SH "SEE ALSO" The .I zlib -web site can be found at either of these locations: +web site can be found at: .IP -http://www.zlib.org -.br -http://www.gzip.org/zlib/ +http://zlib.net/ .LP The data format used by the zlib library is described by RFC (Request for Comments) 1950 to 1952 in the files: .IP -http://www.ietf.org/rfc/rfc1950.txt (concerning zlib format) +http://www.ietf.org/rfc/rfc1950.txt (for the zlib header and trailer format) .br -http://www.ietf.org/rfc/rfc1951.txt (concerning deflate format) +http://www.ietf.org/rfc/rfc1951.txt (for the deflate compressed data format) .br -http://www.ietf.org/rfc/rfc1952.txt (concerning gzip format) +http://www.ietf.org/rfc/rfc1952.txt (for the gzip header and trailer format) .LP -These documents are also available in other formats from: -.IP -ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html -.LP -Mark Nelson (markn@ieee.org) wrote an article about +Mark Nelson wrote an article about .I zlib for the Jan. 1997 issue of Dr. Dobb's Journal; a copy of the article is available at: .IP -http://dogma.net/markn/articles/zlibtool/zlibtool.htm +http://marknelson.us/1997/01/01/zlib-engine/ .SH "REPORTING PROBLEMS" Before reporting a problem, please check the @@ -127,14 +119,14 @@ Please read the .I zlib FAQ at: .IP -http://www.gzip.org/zlib/zlib_faq.html +http://zlib.net/zlib_faq.html .LP before asking for help. Send questions and/or comments to zlib@gzip.org, or (for the Windows DLL version) to Gilles Vollant (info@winimage.com). .SH AUTHORS -Version 1.2.3 -Copyright (C) 1995-2005 Jean-loup Gailly (jloup@gzip.org) +Version 1.2.4 +Copyright (C) 1995-2010 Jean-loup Gailly (jloup@gzip.org) and Mark Adler (madler@alumni.caltech.edu). .LP This software is provided "as-is," diff --git a/lib/libz/zlib.h b/lib/libz/zlib.h index 022817927ce..9012168f69a 100644 --- a/lib/libz/zlib.h +++ b/lib/libz/zlib.h @@ -1,7 +1,7 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.3, July 18th, 2005 + version 1.2.4, Mar 14th, 2010 - Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler + Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -37,41 +37,44 @@ extern "C" { #endif -#define ZLIB_VERSION "1.2.3" -#define ZLIB_VERNUM 0x1230 +#define ZLIB_VERSION "1.2.4" +#define ZLIB_VERNUM 0x1240 +#define ZLIB_VER_MAJOR 1 +#define ZLIB_VER_MINOR 2 +#define ZLIB_VER_REVISION 4 +#define ZLIB_VER_SUBREVISION 0 /* - The 'zlib' compression library provides in-memory compression and - decompression functions, including integrity checks of the uncompressed - data. This version of the library supports only one compression method - (deflation) but other algorithms will be added later and will have the same - stream interface. + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed data. + This version of the library supports only one compression method (deflation) + but other algorithms will be added later and will have the same stream + interface. - Compression can be done in a single step if the buffers are large - enough (for example if an input file is mmap'ed), or can be done by - repeated calls of the compression function. In the latter case, the - application must provide more input and/or consume the output + Compression can be done in a single step if the buffers are large enough, + or can be done by repeated calls of the compression function. In the latter + case, the application must provide more input and/or consume the output (providing more output space) before each call. - The compressed data format used by default by the in-memory functions is + The compressed data format used by default by the in-memory functions is the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped around a deflate stream, which is itself documented in RFC 1951. - The library also supports reading and writing files in gzip (.gz) format + The library also supports reading and writing files in gzip (.gz) format with an interface similar to that of stdio using the functions that start with "gz". The gzip format is different from the zlib format. gzip is a gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. - This library can optionally read and write gzip streams in memory as well. + This library can optionally read and write gzip streams in memory as well. - The zlib format was designed to be compact and fast for use in memory + The zlib format was designed to be compact and fast for use in memory and on communications channels. The gzip format was designed for single- file compression on file systems, has a larger header than zlib to maintain directory information, and uses a different, slower check method than zlib. - The library does not install any signal handler. The decoder checks - the consistency of the compressed data, so the library should never - crash even in case of corrupted input. + The library does not install any signal handler. The decoder checks + the consistency of the compressed data, so the library should never crash + even in case of corrupted input. */ typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); @@ -126,45 +129,45 @@ typedef struct gz_header_s { typedef gz_header FAR *gz_headerp; /* - The application must update next_in and avail_in when avail_in has - dropped to zero. It must update next_out and avail_out when avail_out - has dropped to zero. The application must initialize zalloc, zfree and - opaque before calling the init function. All other fields are set by the - compression library and must not be updated by the application. + The application must update next_in and avail_in when avail_in has dropped + to zero. It must update next_out and avail_out when avail_out has dropped + to zero. The application must initialize zalloc, zfree and opaque before + calling the init function. All other fields are set by the compression + library and must not be updated by the application. - The opaque value provided by the application will be passed as the first - parameter for calls of zalloc and zfree. This can be useful for custom - memory management. The compression library attaches no meaning to the + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the opaque value. - zalloc must return Z_NULL if there is not enough memory for the object. + zalloc must return Z_NULL if there is not enough memory for the object. If zlib is used in a multi-threaded application, zalloc and zfree must be thread safe. - On 16-bit systems, the functions zalloc and zfree must be able to allocate - exactly 65536 bytes, but will not be required to allocate more than this - if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, - pointers returned by zalloc for objects of exactly 65536 bytes *must* - have their offset normalized to zero. The default allocation function - provided by this library ensures this (see zutil.c). To reduce memory - requirements and avoid any allocation of 64K objects, at the expense of - compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this if + the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers + returned by zalloc for objects of exactly 65536 bytes *must* have their + offset normalized to zero. The default allocation function provided by this + library ensures this (see zutil.c). To reduce memory requirements and avoid + any allocation of 64K objects, at the expense of compression ratio, compile + the library with -DMAX_WBITS=14 (see zconf.h). - The fields total_in and total_out can be used for statistics or - progress reports. After compression, total_in holds the total size of - the uncompressed data and may be saved for use in the decompressor - (particularly if the decompressor wants to decompress everything in - a single step). + The fields total_in and total_out can be used for statistics or progress + reports. After compression, total_in holds the total size of the + uncompressed data and may be saved for use in the decompressor (particularly + if the decompressor wants to decompress everything in a single step). */ /* constants */ #define Z_NO_FLUSH 0 -#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ +#define Z_PARTIAL_FLUSH 1 #define Z_SYNC_FLUSH 2 #define Z_FULL_FLUSH 3 #define Z_FINISH 4 #define Z_BLOCK 5 +#define Z_TREES 6 /* Allowed flush values; see deflate() and inflate() below for details */ #define Z_OK 0 @@ -176,8 +179,8 @@ typedef gz_header FAR *gz_headerp; #define Z_MEM_ERROR (-4) #define Z_BUF_ERROR (-5) #define Z_VERSION_ERROR (-6) -/* Return codes for the compression/decompression functions. Negative - * values are errors, positive values are used for special but normal events. +/* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. */ #define Z_NO_COMPRESSION 0 @@ -207,119 +210,140 @@ typedef gz_header FAR *gz_headerp; #define zlib_version zlibVersion() /* for compatibility with versions < 1.0.2 */ + /* basic functions */ ZEXTERN const char * ZEXPORT zlibVersion OF((void)); /* The application can compare zlibVersion and ZLIB_VERSION for consistency. - If the first character differs, the library code actually used is - not compatible with the zlib.h header file used by the application. - This check is automatically made by deflateInit and inflateInit. + If the first character differs, the library code actually used is not + compatible with the zlib.h header file used by the application. This check + is automatically made by deflateInit and inflateInit. */ /* ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); - Initializes the internal stream state for compression. The fields - zalloc, zfree and opaque must be initialized before by the caller. - If zalloc and zfree are set to Z_NULL, deflateInit updates them to - use default allocation functions. + Initializes the internal stream state for compression. The fields + zalloc, zfree and opaque must be initialized before by the caller. If + zalloc and zfree are set to Z_NULL, deflateInit updates them to use default + allocation functions. The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: - 1 gives best speed, 9 gives best compression, 0 gives no compression at - all (the input data is simply copied a block at a time). - Z_DEFAULT_COMPRESSION requests a default compromise between speed and - compression (currently equivalent to level 6). + 1 gives best speed, 9 gives best compression, 0 gives no compression at all + (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION + requests a default compromise between speed and compression (currently + equivalent to level 6). - deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if level is not a valid compression level, + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if level is not a valid compression level, or Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible - with the version assumed by the caller (ZLIB_VERSION). - msg is set to null if there is no error message. deflateInit does not - perform any compression: this will be done by deflate(). + with the version assumed by the caller (ZLIB_VERSION). msg is set to null + if there is no error message. deflateInit does not perform any compression: + this will be done by deflate(). */ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); /* deflate compresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce some - output latency (reading input without producing any output) except when + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when forced to flush. - The detailed semantics are as follows. deflate performs one or both of the + The detailed semantics are as follows. deflate performs one or both of the following actions: - Compress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not + accordingly. If not all input can be processed (because there is not enough room in the output buffer), next_in and avail_in are updated and processing will resume at this point for the next call of deflate(). - Provide more output starting at next_out and update next_out and avail_out - accordingly. This action is forced if the parameter flush is non zero. + accordingly. This action is forced if the parameter flush is non zero. Forcing flush frequently degrades the compression ratio, so this parameter - should be set only when necessary (in interactive applications). - Some output may be provided even if flush is not set. + should be set only when necessary (in interactive applications). Some + output may be provided even if flush is not set. - Before the call of deflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming - more output, and updating avail_in or avail_out accordingly; avail_out - should never be zero before the call. The application can consume the - compressed output when it wants, for example when the output buffer is full - (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK - and with zero avail_out, it must be called again after making room in the - output buffer because there might be more output pending. + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating avail_in or avail_out accordingly; avail_out should + never be zero before the call. The application can consume the compressed + output when it wants, for example when the output buffer is full (avail_out + == 0), or after each call of deflate(). If deflate returns Z_OK and with + zero avail_out, it must be called again after making room in the output + buffer because there might be more output pending. Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to - decide how much data to accumualte before producing output, in order to + decide how much data to accumulate before producing output, in order to maximize compression. If the parameter flush is set to Z_SYNC_FLUSH, all pending output is flushed to the output buffer and the output is aligned on a byte boundary, so - that the decompressor can get all input data available so far. (In particular - avail_in is zero after the call if enough output space has been provided - before the call.) Flushing may degrade compression for some compression - algorithms and so it should be used only when necessary. + that the decompressor can get all input data available so far. (In + particular avail_in is zero after the call if enough output space has been + provided before the call.) Flushing may degrade compression for some + compression algorithms and so it should be used only when necessary. This + completes the current deflate block and follows it with an empty stored block + that is three bits plus filler bits to the next byte, followed by four bytes + (00 00 ff ff). + + If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the + output buffer, but the output is not aligned to a byte boundary. All of the + input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. + This completes the current deflate block and follows it with an empty fixed + codes block that is 10 bits long. This assures that enough bytes are output + in order for the decompressor to finish the block before the empty fixed code + block. + + If flush is set to Z_BLOCK, a deflate block is completed and emitted, as + for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to + seven bits of the current block are held to be written as the next byte after + the next deflate block is completed. In this case, the decompressor may not + be provided enough bits at this point in order to complete decompression of + the data provided so far to the compressor. It may need to wait for the next + block to be emitted. This is for advanced applications that need to control + the emission of deflate blocks. If flush is set to Z_FULL_FLUSH, all output is flushed as with Z_SYNC_FLUSH, and the compression state is reset so that decompression can restart from this point if previous compressed data has been damaged or if - random access is desired. Using Z_FULL_FLUSH too often can seriously degrade + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade compression. If deflate returns with avail_out == 0, this function must be called again with the same value of the flush parameter and more output space (updated avail_out), until the flush is complete (deflate returns with non-zero - avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that + avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that avail_out is greater than six to avoid repeated flush markers due to avail_out == 0 on return. If the parameter flush is set to Z_FINISH, pending input is processed, - pending output is flushed and deflate returns with Z_STREAM_END if there - was enough output space; if deflate returns with Z_OK, this function must be + pending output is flushed and deflate returns with Z_STREAM_END if there was + enough output space; if deflate returns with Z_OK, this function must be called again with Z_FINISH and more output space (updated avail_out) but no - more input data, until it returns with Z_STREAM_END or an error. After - deflate has returned Z_STREAM_END, the only possible operations on the - stream are deflateReset or deflateEnd. + more input data, until it returns with Z_STREAM_END or an error. After + deflate has returned Z_STREAM_END, the only possible operations on the stream + are deflateReset or deflateEnd. Z_FINISH can be used immediately after deflateInit if all the compression - is to be done in a single step. In this case, avail_out must be at least - the value returned by deflateBound (see below). If deflate does not return + is to be done in a single step. In this case, avail_out must be at least the + value returned by deflateBound (see below). If deflate does not return Z_STREAM_END, then it must be called again as described above. deflate() sets strm->adler to the adler32 checksum of all input read so far (that is, total_in bytes). deflate() may update strm->data_type if it can make a good guess about - the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered - binary. This field is only for information purposes and does not affect - the compression algorithm in any manner. + the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered + binary. This field is only for information purposes and does not affect the + compression algorithm in any manner. deflate() returns Z_OK if some progress has been made (more input processed or more output produced), Z_STREAM_END if all input has been consumed and all output has been produced (only when flush is set to Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example - if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible - (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not + if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible + (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not fatal, and deflate() can be called again with more input and more output space to continue compressing. */ @@ -328,13 +352,13 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); /* All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any - pending output. + This function discards any unprocessed input and does not flush any pending + output. deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state was inconsistent, Z_DATA_ERROR if the stream was freed - prematurely (some input or output was discarded). In the error case, - msg may be set but then points to a static string (which must not be + prematurely (some input or output was discarded). In the error case, msg + may be set but then points to a static string (which must not be deallocated). */ @@ -342,10 +366,10 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); /* ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); - Initializes the internal stream state for decompression. The fields + Initializes the internal stream state for decompression. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized before by - the caller. If next_in is not Z_NULL and avail_in is large enough (the exact - value depends on the compression method), inflateInit determines the + the caller. If next_in is not Z_NULL and avail_in is large enough (the + exact value depends on the compression method), inflateInit determines the compression method from the zlib header and allocates all data structures accordingly; otherwise the allocation will be deferred to the first call of inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to @@ -353,95 +377,108 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_VERSION_ERROR if the zlib library version is incompatible with the - version assumed by the caller. msg is set to null if there is no error - message. inflateInit does not perform any decompression apart from reading - the zlib header if present: this will be done by inflate(). (So next_in and - avail_in may be modified, but next_out and avail_out are unchanged.) + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit() does not process any header information -- that is deferred + until inflate() is called. */ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); /* inflate decompresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce + buffer becomes empty or the output buffer becomes full. It may introduce some output latency (reading input without producing any output) except when forced to flush. - The detailed semantics are as follows. inflate performs one or both of the + The detailed semantics are as follows. inflate performs one or both of the following actions: - Decompress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in is updated and processing - will resume at this point for the next call of inflate(). + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in is updated and processing will + resume at this point for the next call of inflate(). - Provide more output starting at next_out and update next_out and avail_out - accordingly. inflate() provides as much output as possible, until there - is no more input data or no more space in the output buffer (see below - about the flush parameter). + accordingly. inflate() provides as much output as possible, until there is + no more input data or no more space in the output buffer (see below about + the flush parameter). - Before the call of inflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming - more output, and updating the next_* and avail_* values accordingly. - The application can consume the uncompressed output when it wants, for - example when the output buffer is full (avail_out == 0), or after each - call of inflate(). If inflate returns Z_OK and with zero avail_out, it - must be called again after making room in the output buffer because there - might be more output pending. + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating the next_* and avail_* values accordingly. The + application can consume the uncompressed output when it wants, for example + when the output buffer is full (avail_out == 0), or after each call of + inflate(). If inflate returns Z_OK and with zero avail_out, it must be + called again after making room in the output buffer because there might be + more output pending. - The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, - Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much - output as possible to the output buffer. Z_BLOCK requests that inflate() stop - if and when it gets to the next deflate block boundary. When decoding the - zlib or gzip format, this will cause inflate() to return immediately after - the header and before the first block. When doing a raw inflate, inflate() - will go ahead and process the first block, and will return when it gets to - the end of that block, or when it runs out of data. + The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, + Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much + output as possible to the output buffer. Z_BLOCK requests that inflate() + stop if and when it gets to the next deflate block boundary. When decoding + the zlib or gzip format, this will cause inflate() to return immediately + after the header and before the first block. When doing a raw inflate, + inflate() will go ahead and process the first block, and will return when it + gets to the end of that block, or when it runs out of data. The Z_BLOCK option assists in appending to or combining deflate streams. Also to assist in this, on return inflate() will set strm->data_type to the - number of unused bits in the last byte taken from strm->next_in, plus 64 - if inflate() is currently decoding the last block in the deflate stream, - plus 128 if inflate() returned immediately after decoding an end-of-block - code or decoding the complete header up to just before the first byte of the - deflate stream. The end-of-block will not be indicated until all of the - uncompressed data from that block has been written to strm->next_out. The - number of unused bits may in general be greater than seven, except when - bit 7 of data_type is set, in which case the number of unused bits will be - less than eight. + number of unused bits in the last byte taken from strm->next_in, plus 64 if + inflate() is currently decoding the last block in the deflate stream, plus + 128 if inflate() returned immediately after decoding an end-of-block code or + decoding the complete header up to just before the first byte of the deflate + stream. The end-of-block will not be indicated until all of the uncompressed + data from that block has been written to strm->next_out. The number of + unused bits may in general be greater than seven, except when bit 7 of + data_type is set, in which case the number of unused bits will be less than + eight. data_type is set as noted here every time inflate() returns for all + flush options, and so can be used to determine the amount of currently + consumed input in bits. + + The Z_TREES option behaves as Z_BLOCK does, but it also returns when the + end of each deflate block header is reached, before any actual data in that + block is decoded. This allows the caller to determine the length of the + deflate block header for later use in random access within a deflate block. + 256 is added to the value of strm->data_type when inflate() returns + immediately after reaching the end of the deflate block header. inflate() should normally be called until it returns Z_STREAM_END or an - error. However if all decompression is to be performed in a single step - (a single call of inflate), the parameter flush should be set to - Z_FINISH. In this case all pending input is processed and all pending - output is flushed; avail_out must be large enough to hold all the - uncompressed data. (The size of the uncompressed data may have been saved - by the compressor for this purpose.) The next operation on this stream must - be inflateEnd to deallocate the decompression state. The use of Z_FINISH - is never required, but can be used to inform inflate that a faster approach - may be used for the single inflate() call. + error. However if all decompression is to be performed in a single step (a + single call of inflate), the parameter flush should be set to Z_FINISH. In + this case all pending input is processed and all pending output is flushed; + avail_out must be large enough to hold all the uncompressed data. (The size + of the uncompressed data may have been saved by the compressor for this + purpose.) The next operation on this stream must be inflateEnd to deallocate + the decompression state. The use of Z_FINISH is never required, but can be + used to inform inflate that a faster approach may be used for the single + inflate() call. In this implementation, inflate() always flushes as much output as possible to the output buffer, and always uses the faster approach on the - first call. So the only effect of the flush parameter in this implementation + first call. So the only effect of the flush parameter in this implementation is on the return value of inflate(), as noted below, or when it returns early - because Z_BLOCK is used. + because Z_BLOCK or Z_TREES is used. If a preset dictionary is needed after this call (see inflateSetDictionary below), inflate sets strm->adler to the adler32 checksum of the dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise it sets strm->adler to the adler32 checksum of all output produced so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described - below. At the end of the stream, inflate() checks that its computed adler32 + below. At the end of the stream, inflate() checks that its computed adler32 checksum is equal to that saved by the compressor and returns Z_STREAM_END only if the checksum is correct. - inflate() will decompress and check either zlib-wrapped or gzip-wrapped - deflate data. The header type is detected automatically. Any information - contained in the gzip header is not retained, so applications that need that - information should instead use raw inflate, see inflateInit2() below, or - inflateBack() and perform their own processing of the gzip header and - trailer. + inflate() can decompress and check either zlib-wrapped or gzip-wrapped + deflate data. The header type is detected automatically, if requested when + initializing with inflateInit2(). Any information contained in the gzip + header is not retained, so applications that need that information should + instead use raw inflate, see inflateInit2() below, or inflateBack() and + perform their own processing of the gzip header and trailer. inflate() returns Z_OK if some progress has been made (more input processed or more output produced), Z_STREAM_END if the end of the compressed data has @@ -449,27 +486,28 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); preset dictionary is needed at this point, Z_DATA_ERROR if the input data was corrupted (input stream not conforming to the zlib format or incorrect check value), Z_STREAM_ERROR if the stream structure was inconsistent (for example - if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, + next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if no progress is possible or if there was not enough room in the - output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and + output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and inflate() can be called again with more input and more output space to - continue decompressing. If Z_DATA_ERROR is returned, the application may then - call inflateSync() to look for a good compression block if a partial recovery - of the data is desired. + continue decompressing. If Z_DATA_ERROR is returned, the application may + then call inflateSync() to look for a good compression block if a partial + recovery of the data is desired. */ ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); /* All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any - pending output. + This function discards any unprocessed input and does not flush any pending + output. inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state - was inconsistent. In the error case, msg may be set but then points to a + was inconsistent. In the error case, msg may be set but then points to a static string (which must not be deallocated). */ + /* Advanced functions */ /* @@ -484,55 +522,57 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, int memLevel, int strategy)); - This is another version of deflateInit with more compression options. The - fields next_in, zalloc, zfree and opaque must be initialized before by - the caller. + This is another version of deflateInit with more compression options. The + fields next_in, zalloc, zfree and opaque must be initialized before by the + caller. - The method parameter is the compression method. It must be Z_DEFLATED in + The method parameter is the compression method. It must be Z_DEFLATED in this version of the library. The windowBits parameter is the base two logarithm of the window size - (the size of the history buffer). It should be in the range 8..15 for this - version of the library. Larger values of this parameter result in better - compression at the expense of memory usage. The default value is 15 if + (the size of the history buffer). It should be in the range 8..15 for this + version of the library. Larger values of this parameter result in better + compression at the expense of memory usage. The default value is 15 if deflateInit is used instead. - windowBits can also be -8..-15 for raw deflate. In this case, -windowBits - determines the window size. deflate() will then generate raw deflate data + windowBits can also be -8..-15 for raw deflate. In this case, -windowBits + determines the window size. deflate() will then generate raw deflate data with no zlib header or trailer, and will not compute an adler32 check value. - windowBits can also be greater than 15 for optional gzip encoding. Add + windowBits can also be greater than 15 for optional gzip encoding. Add 16 to windowBits to write a simple gzip header and trailer around the - compressed data instead of a zlib wrapper. The gzip header will have no - file name, no extra data, no comment, no modification time (set to zero), - no header crc, and the operating system will be set to 255 (unknown). If a + compressed data instead of a zlib wrapper. The gzip header will have no + file name, no extra data, no comment, no modification time (set to zero), no + header crc, and the operating system will be set to 255 (unknown). If a gzip stream is being written, strm->adler is a crc32 instead of an adler32. The memLevel parameter specifies how much memory should be allocated - for the internal compression state. memLevel=1 uses minimum memory but - is slow and reduces compression ratio; memLevel=9 uses maximum memory - for optimal speed. The default value is 8. See zconf.h for total memory - usage as a function of windowBits and memLevel. + for the internal compression state. memLevel=1 uses minimum memory but is + slow and reduces compression ratio; memLevel=9 uses maximum memory for + optimal speed. The default value is 8. See zconf.h for total memory usage + as a function of windowBits and memLevel. - The strategy parameter is used to tune the compression algorithm. Use the + The strategy parameter is used to tune the compression algorithm. Use the value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no string match), or Z_RLE to limit match distances to one (run-length - encoding). Filtered data consists mostly of small values with a somewhat - random distribution. In this case, the compression algorithm is tuned to - compress them better. The effect of Z_FILTERED is to force more Huffman + encoding). Filtered data consists mostly of small values with a somewhat + random distribution. In this case, the compression algorithm is tuned to + compress them better. The effect of Z_FILTERED is to force more Huffman coding and less string matching; it is somewhat intermediate between - Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as - Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy - parameter only affects the compression ratio but not the correctness of the - compressed output even if it is not set appropriately. Z_FIXED prevents the - use of dynamic Huffman codes, allowing for a simpler decoder for special - applications. + Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as + fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The + strategy parameter only affects the compression ratio but not the + correctness of the compressed output even if it is not set appropriately. + Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler + decoder for special applications. - deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid - method). msg is set to null if there is no error message. deflateInit2 does - not perform any compression: this will be done by deflate(). + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid + method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is + incompatible with the version assumed by the caller (ZLIB_VERSION). msg is + set to null if there is no error message. deflateInit2 does not perform any + compression: this will be done by deflate(). */ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, @@ -540,37 +580,37 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, uInt dictLength)); /* Initializes the compression dictionary from the given byte sequence - without producing any compressed output. This function must be called - immediately after deflateInit, deflateInit2 or deflateReset, before any - call of deflate. The compressor and decompressor must use exactly the same + without producing any compressed output. This function must be called + immediately after deflateInit, deflateInit2 or deflateReset, before any call + of deflate. The compressor and decompressor must use exactly the same dictionary (see inflateSetDictionary). The dictionary should consist of strings (byte sequences) that are likely to be encountered later in the data to be compressed, with the most commonly - used strings preferably put towards the end of the dictionary. Using a + used strings preferably put towards the end of the dictionary. Using a dictionary is most useful when the data to be compressed is short and can be predicted with good accuracy; the data can then be compressed better than with the default empty dictionary. Depending on the size of the compression data structures selected by deflateInit or deflateInit2, a part of the dictionary may in effect be - discarded, for example if the dictionary is larger than the window size in - deflate or deflate2. Thus the strings most likely to be useful should be - put at the end of the dictionary, not at the front. In addition, the - current implementation of deflate will use at most the window size minus - 262 bytes of the provided dictionary. + discarded, for example if the dictionary is larger than the window size + provided in deflateInit or deflateInit2. Thus the strings most likely to be + useful should be put at the end of the dictionary, not at the front. In + addition, the current implementation of deflate will use at most the window + size minus 262 bytes of the provided dictionary. Upon return of this function, strm->adler is set to the adler32 value of the dictionary; the decompressor may later use this value to determine - which dictionary has been used by the compressor. (The adler32 value + which dictionary has been used by the compressor. (The adler32 value applies to the whole dictionary even if only a subset of the dictionary is actually used by the compressor.) If a raw deflate was requested, then the adler32 value is not computed and strm->adler is not set. deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a - parameter is invalid (such as NULL dictionary) or the stream state is + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is inconsistent (for example if deflate has already been called for this stream - or if the compression method is bsort). deflateSetDictionary does not + or if the compression method is bsort). deflateSetDictionary does not perform any compression: this will be done by deflate(). */ @@ -581,26 +621,26 @@ ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, This function can be useful when several compression strategies will be tried, for example when there are several ways of pre-processing the input - data with a filter. The streams that will be discarded should then be freed + data with a filter. The streams that will be discarded should then be freed by calling deflateEnd. Note that deflateCopy duplicates the internal - compression state which can be quite large, so this strategy is slow and - can consume lots of memory. + compression state which can be quite large, so this strategy is slow and can + consume lots of memory. deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being NULL). msg is left unchanged in both source and + (such as zalloc being Z_NULL). msg is left unchanged in both source and destination. */ ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); /* This function is equivalent to deflateEnd followed by deflateInit, - but does not free and reallocate all the internal compression state. - The stream will keep the same compression level and any other attributes - that may have been set by deflateInit2. + but does not free and reallocate all the internal compression state. The + stream will keep the same compression level and any other attributes that + may have been set by deflateInit2. - deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being NULL). + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). */ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, @@ -610,18 +650,18 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, Dynamically update the compression level and compression strategy. The interpretation of level and strategy is as in deflateInit2. This can be used to switch between compression and straight copy of the input data, or - to switch to a different kind of input data requiring a different - strategy. If the compression level is changed, the input available so far - is compressed with the old level (and may be flushed); the new level will - take effect only at the next call of deflate(). + to switch to a different kind of input data requiring a different strategy. + If the compression level is changed, the input available so far is + compressed with the old level (and may be flushed); the new level will take + effect only at the next call of deflate(). Before the call of deflateParams, the stream state must be set as for - a call of deflate(), since the currently available input may have to - be compressed and flushed. In particular, strm->avail_out must be non-zero. + a call of deflate(), since the currently available input may have to be + compressed and flushed. In particular, strm->avail_out must be non-zero. deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source - stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR - if strm->avail_out was zero. + stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if + strm->avail_out was zero. */ ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, @@ -645,9 +685,10 @@ ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, uLong sourceLen)); /* deflateBound() returns an upper bound on the compressed size after - deflation of sourceLen bytes. It must be called after deflateInit() - or deflateInit2(). This would be used to allocate an output buffer - for deflation in a single pass, and so would be called before deflate(). + deflation of sourceLen bytes. It must be called after deflateInit() or + deflateInit2(), and after deflateSetHeader(), if used. This would be used + to allocate an output buffer for deflation in a single pass, and so would be + called before deflate(). */ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, @@ -655,21 +696,21 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, int value)); /* deflatePrime() inserts bits in the deflate output stream. The intent - is that this function is used to start off the deflate output with the - bits leftover from a previous deflate stream when appending to it. As such, - this function can only be used for raw deflate, and must be used before the - first deflate() call after a deflateInit2() or deflateReset(). bits must be - less than or equal to 16, and that many of the least significant bits of - value will be inserted in the output. + is that this function is used to start off the deflate output with the bits + leftover from a previous deflate stream when appending to it. As such, this + function can only be used for raw deflate, and must be used before the first + deflate() call after a deflateInit2() or deflateReset(). bits must be less + than or equal to 16, and that many of the least significant bits of value + will be inserted in the output. - deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent. */ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, gz_headerp head)); /* - deflateSetHeader() provides gzip header information for when a gzip + deflateSetHeader() provides gzip header information for when a gzip stream is requested by deflateInit2(). deflateSetHeader() may be called after deflateInit2() or deflateReset() and before the first call of deflate(). The text, time, os, extra field, name, and comment information @@ -682,11 +723,11 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, 1.3.x) do not support header crc's, and will report that it is a "multi-part gzip file" and give up. - If deflateSetHeader is not used, the default gzip header has text false, + If deflateSetHeader is not used, the default gzip header has text false, the time set to zero, and os set to 255, with no extra, name, or comment fields. The gzip header is returned to the default state by deflateReset(). - deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent. */ @@ -694,43 +735,50 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, int windowBits)); - This is another version of inflateInit with an extra parameter. The + This is another version of inflateInit with an extra parameter. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized before by the caller. The windowBits parameter is the base two logarithm of the maximum window size (the size of the history buffer). It should be in the range 8..15 for - this version of the library. The default value is 15 if inflateInit is used - instead. windowBits must be greater than or equal to the windowBits value + this version of the library. The default value is 15 if inflateInit is used + instead. windowBits must be greater than or equal to the windowBits value provided to deflateInit2() while compressing, or it must be equal to 15 if - deflateInit2() was not used. If a compressed stream with a larger window + deflateInit2() was not used. If a compressed stream with a larger window size is given as input, inflate() will return with the error code Z_DATA_ERROR instead of trying to allocate a larger window. - windowBits can also be -8..-15 for raw inflate. In this case, -windowBits - determines the window size. inflate() will then process raw deflate data, + windowBits can also be zero to request that inflate use the window size in + the zlib header of the compressed stream. + + windowBits can also be -8..-15 for raw inflate. In this case, -windowBits + determines the window size. inflate() will then process raw deflate data, not looking for a zlib or gzip header, not generating a check value, and not - looking for any check values for comparison at the end of the stream. This + looking for any check values for comparison at the end of the stream. This is for use with other formats that use the deflate compressed data format - such as zip. Those formats provide their own check values. If a custom + such as zip. Those formats provide their own check values. If a custom format is developed using the raw deflate format for compressed data, it is recommended that a check value such as an adler32 or a crc32 be applied to the uncompressed data as is done in the zlib, gzip, and zip formats. For - most applications, the zlib format should be used as is. Note that comments + most applications, the zlib format should be used as is. Note that comments above on the use in deflateInit2() applies to the magnitude of windowBits. - windowBits can also be greater than 15 for optional gzip decoding. Add + windowBits can also be greater than 15 for optional gzip decoding. Add 32 to windowBits to enable zlib and gzip decoding with automatic header detection, or add 16 to decode only the gzip format (the zlib format will - return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is - a crc32 instead of an adler32. + return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a + crc32 instead of an adler32. inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg - is set to null if there is no error message. inflateInit2 does not perform - any decompression apart from reading the zlib header if present: this will - be done by inflate(). (So next_in and avail_in may be modified, but next_out - and avail_out are unchanged.) + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit2 does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit2() does not process any header information -- that is + deferred until inflate() is called. */ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, @@ -738,8 +786,8 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, uInt dictLength)); /* Initializes the decompression dictionary from the given uncompressed byte - sequence. This function must be called immediately after a call of inflate, - if that call returned Z_NEED_DICT. The dictionary chosen by the compressor + sequence. This function must be called immediately after a call of inflate, + if that call returned Z_NEED_DICT. The dictionary chosen by the compressor can be determined from the adler32 value returned by that call of inflate. The compressor and decompressor must use exactly the same dictionary (see deflateSetDictionary). For raw inflate, this function can be called @@ -748,26 +796,26 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, dictionary that was used for compression is provided. inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a - parameter is invalid (such as NULL dictionary) or the stream state is + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the - expected one (incorrect adler32 value). inflateSetDictionary does not + expected one (incorrect adler32 value). inflateSetDictionary does not perform any decompression: this will be done by subsequent calls of inflate(). */ ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); /* - Skips invalid compressed data until a full flush point (see above the - description of deflate with Z_FULL_FLUSH) can be found, or until all - available input is skipped. No output is provided. + Skips invalid compressed data until a full flush point (see above the + description of deflate with Z_FULL_FLUSH) can be found, or until all + available input is skipped. No output is provided. - inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR - if no more input was provided, Z_DATA_ERROR if no flush point has been found, - or Z_STREAM_ERROR if the stream structure was inconsistent. In the success - case, the application may save the current current value of total_in which - indicates where valid compressed data was found. In the error case, the - application may repeatedly call inflateSync, providing more input each time, - until success or end of the input data. + inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR + if no more input was provided, Z_DATA_ERROR if no flush point has been + found, or Z_STREAM_ERROR if the stream structure was inconsistent. In the + success case, the application may save the current current value of total_in + which indicates where valid compressed data was found. In the error case, + the application may repeatedly call inflateSync, providing more input each + time, until success or end of the input data. */ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, @@ -782,18 +830,30 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being NULL). msg is left unchanged in both source and + (such as zalloc being Z_NULL). msg is left unchanged in both source and destination. */ ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); /* This function is equivalent to inflateEnd followed by inflateInit, - but does not free and reallocate all the internal decompression state. - The stream will keep attributes that may have been set by inflateInit2. + but does not free and reallocate all the internal decompression state. The + stream will keep attributes that may have been set by inflateInit2. - inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being NULL). + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, + int windowBits)); +/* + This function is the same as inflateReset, but it also permits changing + the wrap and window size requests. The windowBits parameter is interpreted + the same as it is for inflateInit2. + + inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL), or if + the windowBits parameter is invalid. */ ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, @@ -801,54 +861,87 @@ ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, int value)); /* This function inserts bits in the inflate input stream. The intent is - that this function is used to start inflating at a bit position in the - middle of a byte. The provided bits will be used before any bytes are used - from next_in. This function should only be used with raw inflate, and - should be used before the first inflate() call after inflateInit2() or - inflateReset(). bits must be less than or equal to 16, and that many of the - least significant bits of value will be inserted in the input. + that this function is used to start inflating at a bit position in the + middle of a byte. The provided bits will be used before any bytes are used + from next_in. This function should only be used with raw inflate, and + should be used before the first inflate() call after inflateInit2() or + inflateReset(). bits must be less than or equal to 16, and that many of the + least significant bits of value will be inserted in the input. - inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + If bits is negative, then the input stream bit buffer is emptied. Then + inflatePrime() can be called again to put bits in the buffer. This is used + to clear out bits leftover after feeding inflate a block description prior + to feeding inflate codes. + + inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent. */ +ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); +/* + This function returns two values, one in the lower 16 bits of the return + value, and the other in the remaining upper bits, obtained by shifting the + return value down 16 bits. If the upper value is -1 and the lower value is + zero, then inflate() is currently decoding information outside of a block. + If the upper value is -1 and the lower value is non-zero, then inflate is in + the middle of a stored block, with the lower value equaling the number of + bytes from the input remaining to copy. If the upper value is not -1, then + it is the number of bits back from the current bit position in the input of + the code (literal or length/distance pair) currently being processed. In + that case the lower value is the number of bytes already emitted for that + code. + + A code is being processed if inflate is waiting for more input to complete + decoding of the code, or if it has completed decoding but is waiting for + more output space to write the literal or match data. + + inflateMark() is used to mark locations in the input data for random + access, which may be at bit positions, and to note those cases where the + output of a code may span boundaries of random access blocks. The current + location in the input stream can be determined from avail_in and data_type + as noted in the description for the Z_BLOCK flush parameter for inflate. + + inflateMark returns the value noted above or -1 << 16 if the provided + source stream state was inconsistent. +*/ + ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, gz_headerp head)); /* - inflateGetHeader() requests that gzip header information be stored in the + inflateGetHeader() requests that gzip header information be stored in the provided gz_header structure. inflateGetHeader() may be called after inflateInit2() or inflateReset(), and before the first call of inflate(). As inflate() processes the gzip stream, head->done is zero until the header is completed, at which time head->done is set to one. If a zlib stream is being decoded, then head->done is set to -1 to indicate that there will be - no gzip header information forthcoming. Note that Z_BLOCK can be used to - force inflate() to return immediately after header processing is complete - and before any actual data is decompressed. + no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be + used to force inflate() to return immediately after header processing is + complete and before any actual data is decompressed. - The text, time, xflags, and os fields are filled in with the gzip header + The text, time, xflags, and os fields are filled in with the gzip header contents. hcrc is set to true if there is a header CRC. (The header CRC - was valid if done is set to one.) If extra is not Z_NULL, then extra_max + was valid if done is set to one.) If extra is not Z_NULL, then extra_max contains the maximum number of bytes to write to extra. Once done is true, extra_len contains the actual extra field length, and extra contains the extra field, or that field truncated if extra_max is less than extra_len. If name is not Z_NULL, then up to name_max characters are written there, terminated with a zero unless the length is greater than name_max. If comment is not Z_NULL, then up to comm_max characters are written there, - terminated with a zero unless the length is greater than comm_max. When - any of extra, name, or comment are not Z_NULL and the respective field is - not present in the header, then that field is set to Z_NULL to signal its + terminated with a zero unless the length is greater than comm_max. When any + of extra, name, or comment are not Z_NULL and the respective field is not + present in the header, then that field is set to Z_NULL to signal its absence. This allows the use of deflateSetHeader() with the returned structure to duplicate the header. However if those fields are set to allocated memory, then the application will need to save those pointers elsewhere so that they can be eventually freed. - If inflateGetHeader is not used, then the header information is simply + If inflateGetHeader is not used, then the header information is simply discarded. The header is always checked for validity, including the header CRC if present. inflateReset() will reset the process to discard the header information. The application would need to call inflateGetHeader() again to retrieve the header from the next gzip stream. - inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent. */ @@ -869,9 +962,9 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, See inflateBack() for the usage of these routines. inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of - the paramaters are invalid, Z_MEM_ERROR if the internal state could not - be allocated, or Z_VERSION_ERROR if the version of the library does not - match the version of the header file. + the paramaters are invalid, Z_MEM_ERROR if the internal state could not be + allocated, or Z_VERSION_ERROR if the version of the library does not match + the version of the header file. */ typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); @@ -891,15 +984,15 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, inflateBackInit() must be called first to allocate the internal state and to initialize the state with the user-provided window buffer. inflateBack() may then be used multiple times to inflate a complete, raw - deflate stream with each call. inflateBackEnd() is then called to free - the allocated state. + deflate stream with each call. inflateBackEnd() is then called to free the + allocated state. A raw deflate stream is one with no zlib or gzip header or trailer. This routine would normally be used in a utility that reads zip or gzip files and writes out uncompressed files. The utility would decode the - header and process the trailer on its own, hence this routine expects - only the raw deflate stream to decompress. This is different from the - normal behavior of inflate(), which expects either a zlib or gzip header and + header and process the trailer on its own, hence this routine expects only + the raw deflate stream to decompress. This is different from the normal + behavior of inflate(), which expects either a zlib or gzip header and trailer around the deflate stream. inflateBack() uses two subroutines supplied by the caller that are then @@ -925,7 +1018,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in must also be initialized, and then if strm->avail_in is not zero, input will - initially be taken from strm->next_in[0 .. strm->avail_in - 1]. + initially be taken from strm->next_in[0 .. strm->avail_in - 1]. The in_desc and out_desc parameters of inflateBack() is passed as the first parameter of in() and out() respectively when they are called. These @@ -935,15 +1028,15 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, On return, inflateBack() will set strm->next_in and strm->avail_in to pass back any unused input that was provided by the last in() call. The return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR - if in() or out() returned an error, Z_DATA_ERROR if there was a format - error in the deflate stream (in which case strm->msg is set to indicate the - nature of the error), or Z_STREAM_ERROR if the stream was not properly - initialized. In the case of Z_BUF_ERROR, an input or output error can be - distinguished using strm->next_in which will be Z_NULL only if in() returned - an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to - out() returning non-zero. (in() will always be called before out(), so - strm->next_in is assured to be defined if out() returns non-zero.) Note - that inflateBack() cannot return Z_OK. + if in() or out() returned an error, Z_DATA_ERROR if there was a format error + in the deflate stream (in which case strm->msg is set to indicate the nature + of the error), or Z_STREAM_ERROR if the stream was not properly initialized. + In the case of Z_BUF_ERROR, an input or output error can be distinguished + using strm->next_in which will be Z_NULL only if in() returned an error. If + strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning + non-zero. (in() will always be called before out(), so strm->next_in is + assured to be defined if out() returns non-zero.) Note that inflateBack() + cannot return Z_OK. */ ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); @@ -999,23 +1092,22 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); /* utility functions */ /* - The following utility functions are implemented on top of the - basic stream-oriented functions. To simplify the interface, some - default options are assumed (compression level and memory usage, - standard memory allocation functions). The source code of these - utility functions can easily be modified if you need special options. + The following utility functions are implemented on top of the basic + stream-oriented functions. To simplify the interface, some default options + are assumed (compression level and memory usage, standard memory allocation + functions). The source code of these utility functions can be modified if + you need special options. */ ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)); /* Compresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be at least the value returned - by compressBound(sourceLen). Upon exit, destLen is the actual size of the + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the compressed buffer. - This function can be used to compress a whole file at once if the - input file is mmap'ed. + compress returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if there was not enough room in the output buffer. @@ -1025,11 +1117,11 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)); /* - Compresses the source buffer into the destination buffer. The level + Compresses the source buffer into the destination buffer. The level parameter has the same meaning as in deflateInit. sourceLen is the byte - length of the source buffer. Upon entry, destLen is the total size of the + length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be at least the value returned by - compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressBound(sourceLen). Upon exit, destLen is the actual size of the compressed buffer. compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough @@ -1040,22 +1132,20 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); /* compressBound() returns an upper bound on the compressed size after - compress() or compress2() on sourceLen bytes. It would be used before - a compress() or compress2() call to allocate the destination buffer. + compress() or compress2() on sourceLen bytes. It would be used before a + compress() or compress2() call to allocate the destination buffer. */ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)); /* Decompresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be large enough to hold the - entire uncompressed data. (The size of the uncompressed data must have - been saved previously by the compressor and transmitted to the decompressor - by some mechanism outside the scope of this compression library.) - Upon exit, destLen is the actual size of the compressed buffer. - This function can be used to decompress a whole file at once if the - input file is mmap'ed. + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be large enough to hold the entire + uncompressed data. (The size of the uncompressed data must have been saved + previously by the compressor and transmitted to the decompressor by some + mechanism outside the scope of this compression library.) Upon exit, destLen + is the actual size of the uncompressed buffer. uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if there was not enough room in the output @@ -1063,136 +1153,199 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, */ -typedef voidp gzFile; + /* gzip file access functions */ -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); /* - Opens a gzip (.gz) file for reading or writing. The mode parameter - is as in fopen ("rb" or "wb") but can also include a compression level - ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for - Huffman only compression as in "wb1h", or 'R' for run-length encoding - as in "wb1R". (See the description of deflateInit2 for more information - about the strategy parameter.) + This library supports reading and writing files in gzip (.gz) format with + an interface similar to that of stdio, using the functions that start with + "gz". The gzip format is different from the zlib format. gzip is a gzip + wrapper, documented in RFC 1952, wrapped around a deflate stream. +*/ + +typedef voidp gzFile; /* opaque gzip file descriptor */ + +/* +ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); + + Opens a gzip (.gz) file for reading or writing. The mode parameter is as + in fopen ("rb" or "wb") but can also include a compression level ("wb9") or + a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only + compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' + for fixed code compression as in "wb9F". (See the description of + deflateInit2 for more information about the strategy parameter.) Also "a" + can be used instead of "w" to request that the gzip stream that will be + written be appended to the file. "+" will result in an error, since reading + and writing to the same gzip file is not supported. gzopen can be used to read a file which is not in gzip format; in this case gzread will directly read from the file without decompression. - gzopen returns NULL if the file could not be opened or if there was - insufficient memory to allocate the (de)compression state; errno - can be checked to distinguish the two cases (if errno is zero, the - zlib error is Z_MEM_ERROR). */ + gzopen returns NULL if the file could not be opened, if there was + insufficient memory to allocate the gzFile state, or if an invalid mode was + specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). + errno can be checked to determine if the reason gzopen failed was that the + file could not be opened. +*/ -ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); /* - gzdopen() associates a gzFile with the file descriptor fd. File - descriptors are obtained from calls like open, dup, creat, pipe or - fileno (in the file has been previously opened with fopen). - The mode parameter is as in gzopen. - The next call of gzclose on the returned gzFile will also close the - file descriptor fd, just like fclose(fdopen(fd), mode) closes the file - descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). - gzdopen returns NULL if there was insufficient memory to allocate - the (de)compression state. + gzdopen associates a gzFile with the file descriptor fd. File descriptors + are obtained from calls like open, dup, creat, pipe or fileno (if the file + has been previously opened with fopen). The mode parameter is as in gzopen. + + The next call of gzclose on the returned gzFile will also close the file + descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor + fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, + mode);. The duplicated descriptor should be saved to avoid a leak, since + gzdopen does not close fd if it fails. + + gzdopen returns NULL if there was insufficient memory to allocate the + gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not + provided, or '+' was provided), or if fd is -1. The file descriptor is not + used until the next gz* read, write, seek, or close operation, so gzdopen + will not detect if fd is invalid (unless fd is -1). +*/ + +ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); +/* + Set the internal buffer size used by this library's functions. The + default buffer size is 8192 bytes. This function must be called after + gzopen() or gzdopen(), and before any other calls that read or write the + file. The buffer memory allocation is always deferred to the first read or + write. Two buffers are allocated, either both of the specified size when + writing, or one of the specified size and the other twice that size when + reading. A larger buffer size of, for example, 64K or 128K bytes will + noticeably increase the speed of decompression (reading). + + The new buffer size also affects the maximum length for gzprintf(). + + gzbuffer() returns 0 on success, or -1 on failure, such as being called + too late. */ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); /* - Dynamically update the compression level or strategy. See the description + Dynamically update the compression level or strategy. See the description of deflateInit2 for the meaning of these parameters. + gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not opened for writing. */ -ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); /* - Reads the given number of uncompressed bytes from the compressed file. - If the input file was not in gzip format, gzread copies the given number - of bytes into the buffer. - gzread returns the number of uncompressed bytes actually read (0 for - end of file, -1 for error). */ + Reads the given number of uncompressed bytes from the compressed file. If + the input file was not in gzip format, gzread copies the given number of + bytes into the buffer. -ZEXTERN int ZEXPORT gzwrite OF((gzFile file, - voidpc buf, unsigned len)); -/* - Writes the given number of uncompressed bytes into the compressed file. - gzwrite returns the number of uncompressed bytes actually written - (0 in case of error). + After reaching the end of a gzip stream in the input, gzread will continue + to read, looking for another gzip stream, or failing that, reading the rest + of the input file directly without decompression. The entire input file + will be read if gzread is called until it returns less than the requested + len. + + gzread returns the number of uncompressed bytes actually read, less than + len for end of file, or -1 for error. */ -ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); +ZEXTERN int ZEXPORT gzwrite OF((gzFile file, + voidpc buf, unsigned len)); /* - Converts, formats, and writes the args to the compressed file under - control of the format string, as in fprintf. gzprintf returns the number of - uncompressed bytes actually written (0 in case of error). The number of - uncompressed bytes written is limited to 4095. The caller should assure that - this limit is not exceeded. If it is exceeded, then gzprintf() will return - return an error (0) with nothing written. In this case, there may also be a - buffer overflow with unpredictable consequences, which is possible only if - zlib was compiled with the insecure functions sprintf() or vsprintf() - because the secure snprintf() or vsnprintf() functions were not available. + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of uncompressed bytes written or 0 in case of + error. +*/ + +ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); +/* + Converts, formats, and writes the arguments to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written, or 0 in case of error. The number of + uncompressed bytes written is limited to 8191, or one less than the buffer + size given to gzbuffer(). The caller should assure that this limit is not + exceeded. If it is exceeded, then gzprintf() will return an error (0) with + nothing written. In this case, there may also be a buffer overflow with + unpredictable consequences, which is possible only if zlib was compiled with + the insecure functions sprintf() or vsprintf() because the secure snprintf() + or vsnprintf() functions were not available. This can be determined using + zlibCompileFlags(). */ ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); /* - Writes the given null-terminated string to the compressed file, excluding + Writes the given null-terminated string to the compressed file, excluding the terminating null character. - gzputs returns the number of characters written, or -1 in case of error. + + gzputs returns the number of characters written, or -1 in case of error. */ ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); /* - Reads bytes from the compressed file until len-1 characters are read, or - a newline character is read and transferred to buf, or an end-of-file - condition is encountered. The string is then terminated with a null - character. - gzgets returns buf, or Z_NULL in case of error. + Reads bytes from the compressed file until len-1 characters are read, or a + newline character is read and transferred to buf, or an end-of-file + condition is encountered. If any characters are read or if len == 1, the + string is terminated with a null character. If no characters are read due + to an end-of-file or len < 1, then the buffer is left untouched. + + gzgets returns buf which is a null-terminated string, or it returns NULL + for end-of-file or in case of error. If there was an error, the contents at + buf are indeterminate. */ -ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); /* - Writes c, converted to an unsigned char, into the compressed file. - gzputc returns the value that was written, or -1 in case of error. + Writes c, converted to an unsigned char, into the compressed file. gzputc + returns the value that was written, or -1 in case of error. */ -ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); /* - Reads one byte from the compressed file. gzgetc returns this byte - or -1 in case of end of file or error. + Reads one byte from the compressed file. gzgetc returns this byte or -1 + in case of end of file or error. */ -ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); /* - Push one character back onto the stream to be read again later. - Only one character of push-back is allowed. gzungetc() returns the - character pushed, or -1 on failure. gzungetc() will fail if a - character has been pushed but not read yet, or if c is -1. The pushed - character will be discarded if the stream is repositioned with gzseek() - or gzrewind(). + Push one character back onto the stream to be read as the first character + on the next read. At least one character of push-back is allowed. + gzungetc() returns the character pushed, or -1 on failure. gzungetc() will + fail if c is -1, and may fail if a character has been pushed but not read + yet. If gzungetc is used immediately after gzopen or gzdopen, at least the + output buffer size of pushed characters is allowed. (See gzbuffer above.) + The pushed character will be discarded if the stream is repositioned with + gzseek() or gzrewind(). */ -ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); /* - Flushes all pending output into the compressed file. The parameter - flush is as in the deflate() function. The return value is the zlib - error number (see function gzerror below). gzflush returns Z_OK if - the flush parameter is Z_FINISH and all output could be flushed. - gzflush should be called only when strictly necessary because it can - degrade compression. + Flushes all pending output into the compressed file. The parameter flush + is as in the deflate() function. The return value is the zlib error number + (see function gzerror below). gzflush is only permitted when writing. + + If the flush parameter is Z_FINISH, the remaining data is written and the + gzip stream is completed in the output. If gzwrite() is called again, a new + gzip stream will be started in the output. gzread() is able to read such + concatented gzip streams. + + gzflush should be called only when strictly necessary because it will + degrade compression if called too often. */ -ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, - z_off_t offset, int whence)); /* - Sets the starting position for the next gzread or gzwrite on the - given compressed file. The offset represents a number of bytes in the - uncompressed data stream. The whence parameter is defined as in lseek(2); +ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, + z_off_t offset, int whence)); + + Sets the starting position for the next gzread or gzwrite on the given + compressed file. The offset represents a number of bytes in the + uncompressed data stream. The whence parameter is defined as in lseek(2); the value SEEK_END is not supported. + If the file is opened for reading, this function is emulated but can be - extremely slow. If the file is opened for writing, only forward seeks are + extremely slow. If the file is opened for writing, only forward seeks are supported; gzseek then compresses a sequence of zeroes up to the new starting position. - gzseek returns the resulting offset location as measured in bytes from + gzseek returns the resulting offset location as measured in bytes from the beginning of the uncompressed stream, or -1 in case of error, in particular if the file is opened for writing and the new starting position would be before the current position. @@ -1202,68 +1355,127 @@ ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); /* Rewinds the given file. This function is supported only for reading. - gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) */ -ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); /* - Returns the starting position for the next gzread or gzwrite on the - given compressed file. This position represents a number of bytes in the - uncompressed data stream. +ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); - gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) + Returns the starting position for the next gzread or gzwrite on the given + compressed file. This position represents a number of bytes in the + uncompressed data stream, and is zero when starting, even if appending or + reading a gzip stream from the middle of a file using gzdopen(). + + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); + + Returns the current offset in the file being read or written. This offset + includes the count of bytes that precede the gzip stream, for example when + appending or when using gzdopen() for reading. When reading, the offset + does not include as yet unused buffered input. This information can be used + for a progress indicator. On error, gzoffset() returns -1. */ ZEXTERN int ZEXPORT gzeof OF((gzFile file)); /* - Returns 1 when EOF has previously been detected reading the given - input stream, otherwise zero. + Returns true (1) if the end-of-file indicator has been set while reading, + false (0) otherwise. Note that the end-of-file indicator is set only if the + read tried to go past the end of the input, but came up short. Therefore, + just like feof(), gzeof() may return false even if there is no more data to + read, in the event that the last read request was for the exact number of + bytes remaining in the input file. This will happen if the input file size + is an exact multiple of the buffer size. + + If gzeof() returns true, then the read functions will return no more data, + unless the end-of-file indicator is reset by gzclearerr() and the input file + has grown since the previous end of file was detected. */ ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); /* - Returns 1 if file is being read directly without decompression, otherwise - zero. + Returns true (1) if file is being copied directly while reading, or false + (0) if file is a gzip stream being decompressed. This state can change from + false to true while reading the input file if the end of a gzip stream is + reached, but is followed by data that is not another gzip stream. + + If the input file is empty, gzdirect() will return true, since the input + does not contain a gzip stream. + + If gzdirect() is used immediately after gzopen() or gzdopen() it will + cause buffers to be allocated to allow reading the file to determine if it + is a gzip file. Therefore if gzbuffer() is used, it should be called before + gzdirect(). */ ZEXTERN int ZEXPORT gzclose OF((gzFile file)); /* - Flushes all pending output if necessary, closes the compressed file - and deallocates all the (de)compression state. The return value is the zlib - error number (see function gzerror below). + Flushes all pending output if necessary, closes the compressed file and + deallocates the (de)compression state. Note that once file is closed, you + cannot call gzerror with file, since its structures have been deallocated. + gzclose must not be called more than once on the same file, just as free + must not be called more than once on the same allocation. + + gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a + file operation error, or Z_OK on success. +*/ + +ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); +/* + Same as gzclose(), but gzclose_r() is only for use when reading, and + gzclose_w() is only for use when writing or appending. The advantage to + using these instead of gzclose() is that they avoid linking in zlib + compression or decompression code that is not used when only reading or only + writing respectively. If gzclose() is used, then both compression and + decompression code will be included the application when linking to a static + zlib library. */ ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); /* - Returns the error message for the last error which occurred on the - given compressed file. errnum is set to zlib error number. If an - error occurred in the file system and not in the compression library, - errnum is set to Z_ERRNO and the application may consult errno - to get the exact error code. + Returns the error message for the last error which occurred on the given + compressed file. errnum is set to zlib error number. If an error occurred + in the file system and not in the compression library, errnum is set to + Z_ERRNO and the application may consult errno to get the exact error code. + + The application must not modify the returned string. Future calls to + this function may invalidate the previously returned string. If file is + closed, then the string previously returned by gzerror will no longer be + available. + + gzerror() should be used to distinguish errors from end-of-file for those + functions above that do not distinguish those cases in their return values. */ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); /* - Clears the error and end-of-file flags for file. This is analogous to the - clearerr() function in stdio. This is useful for continuing to read a gzip + Clears the error and end-of-file flags for file. This is analogous to the + clearerr() function in stdio. This is useful for continuing to read a gzip file that is being written concurrently. */ + /* checksum functions */ /* These functions are not related to compression but are exported - anyway because they might be useful in applications using the - compression library. + anyway because they might be useful in applications using the compression + library. */ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); /* Update a running Adler-32 checksum with the bytes buf[0..len-1] and - return the updated checksum. If buf is NULL, this function returns - the required initial value for the checksum. - An Adler-32 checksum is almost as reliable as a CRC32 but can be computed - much faster. Usage example: + return the updated checksum. If buf is Z_NULL, this function returns the + required initial value for the checksum. + + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed + much faster. + + Usage example: uLong adler = adler32(0L, Z_NULL, 0); @@ -1273,9 +1485,10 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); if (adler != original_adler) error(); */ +/* ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, z_off_t len2)); -/* + Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of @@ -1285,9 +1498,11 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); /* Update a running CRC-32 with the bytes buf[0..len-1] and return the - updated CRC-32. If buf is NULL, this function returns the required initial - value for the for the crc. Pre- and post-conditioning (one's complement) is - performed within this function so it shouldn't be done by the application. + updated CRC-32. If buf is Z_NULL, this function returns the required + initial value for the for the crc. Pre- and post-conditioning (one's + complement) is performed within this function so it shouldn't be done by the + application. + Usage example: uLong crc = crc32(0L, Z_NULL, 0); @@ -1298,9 +1513,9 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); if (crc != original_crc) error(); */ +/* ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); -/* Combine two CRC-32 check values into one. For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, CRC-32 check values were calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 @@ -1339,16 +1554,48 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) #define inflateBackInit(strm, windowBits, window) \ inflateBackInit_((strm), (windowBits), (window), \ - ZLIB_VERSION, sizeof(z_stream)) + ZLIB_VERSION, sizeof(z_stream)) +#ifdef _LARGEFILE64_SOURCE + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN off64_t ZEXPORT gzseek64 OF((gzFile, off64_t, int)); + ZEXTERN off64_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN off64_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, off64_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, off64_t)); +#elif _FILE_OFFSET_BITS == 64 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN off_t ZEXPORT gzseek64 OF((gzFile, off_t, int)); + ZEXTERN off_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN off_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, off_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, off_t)); +#endif + +#if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS == 64 +# define gzopen gzopen64 +# define gzseek gzseek64 +# define gztell gztell64 +# define gzoffset gzoffset64 +# define adler32_combine adler32_combine64 +# define crc32_combine crc32_combine64 +#else + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); +#endif #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) struct internal_state {int dummy;}; /* hack for buggy compilers */ #endif ZEXTERN const char * ZEXPORT zError OF((int)); -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); +ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); +ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); #ifdef __cplusplus } diff --git a/lib/libz/zutil.c b/lib/libz/zutil.c index d55f5948a37..98a55a88384 100644 --- a/lib/libz/zutil.c +++ b/lib/libz/zutil.c @@ -34,25 +34,25 @@ uLong ZEXPORT zlibCompileFlags() uLong flags; flags = 0; - switch (sizeof(uInt)) { + switch ((int)(sizeof(uInt))) { case 2: break; case 4: flags += 1; break; case 8: flags += 2; break; default: flags += 3; } - switch (sizeof(uLong)) { + switch ((int)(sizeof(uLong))) { case 2: break; case 4: flags += 1 << 2; break; case 8: flags += 2 << 2; break; default: flags += 3 << 2; } - switch (sizeof(voidpf)) { + switch ((int)(sizeof(voidpf))) { case 2: break; case 4: flags += 1 << 4; break; case 8: flags += 2 << 4; break; default: flags += 3 << 4; } - switch (sizeof(z_off_t)) { + switch ((int)(sizeof(z_off_t))) { case 2: break; case 4: flags += 1 << 6; break; case 8: flags += 2 << 6; break; diff --git a/lib/libz/zutil.h b/lib/libz/zutil.h index b7d5eff81b6..025035dbe9c 100644 --- a/lib/libz/zutil.h +++ b/lib/libz/zutil.h @@ -1,5 +1,5 @@ /* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-2005 Jean-loup Gailly. + * Copyright (C) 1995-2010 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -17,26 +17,24 @@ #include "zlib.h" #ifdef STDC -# ifndef _WIN32_WCE +# if !(defined(_WIN32_WCE) && defined(_MSC_VER)) # include # endif # include # include #endif -#ifdef NO_ERRNO_H -# ifdef _WIN32_WCE - /* The Microsoft C Run-Time Library for Windows CE doesn't have - * errno. We define it as a global variable to simplify porting. - * Its value is always 0 and should not be used. We rename it to - * avoid conflict with other libraries that use the same workaround. - */ -# define errno z_errno -# endif - extern int errno; + +#if defined(UNDER_CE) && defined(NO_ERRNO_H) +# define zseterrno(ERR) SetLastError((DWORD)(ERR)) +# define zerrno() ((int)GetLastError()) #else -# ifndef _WIN32_WCE +# ifdef NO_ERRNO_H + extern int errno; +# else # include # endif +# define zseterrno(ERR) do { errno = (ERR); } while (0) +# define zerrno() errno #endif #ifndef local @@ -89,7 +87,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) # define OS_CODE 0x00 # if defined(__TURBOC__) || defined(__BORLANDC__) -# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) +# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) /* Allow compilation with ANSI keywords only enabled */ void _Cdecl farfree( void *block ); void *_Cdecl farmalloc( unsigned long nbytes ); @@ -118,7 +116,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ #ifdef OS2 # define OS_CODE 0x06 # ifdef M_I86 - #include +# include # endif #endif @@ -151,7 +149,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # define fdopen(fd,mode) NULL /* No fdopen() */ #endif -#if (defined(_MSC_VER) && (_MSC_VER > 600)) +#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX # if defined(_WIN32_WCE) # define fdopen(fd,mode) NULL /* No fdopen() */ # ifndef _PTRDIFF_T_DEFINED @@ -161,6 +159,18 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # else # define fdopen(fd,type) _fdopen(fd,type) # endif +#endif + +#if defined(__BORLANDC__) + #pragma warn -8004 + #pragma warn -8008 + #pragma warn -8066 +#endif + +#ifdef _LARGEFILE64_SOURCE +# define z_off64_t off64_t +#else +# define z_off64_t z_off_t #endif /* common defaults */ @@ -171,6 +181,12 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ #ifndef F_OPEN # define F_OPEN(name, mode) fopen((name), (mode)) +#endif + +#ifdef _LARGEFILE64_SOURCE +# define F_OPEN64(name, mode) fopen64((name), (mode)) +#else +# define F_OPEN64(name, mode) fopen((name), (mode)) #endif /* functions */ @@ -197,7 +213,9 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # ifdef WIN32 /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ # if !defined(vsnprintf) && !defined(NO_vsnprintf) -# define vsnprintf _vsnprintf +# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) +# define vsnprintf _vsnprintf +# endif # endif # endif # ifdef __SASC diff --git a/sys/sys/param.h b/sys/sys/param.h index 11e3fa673b6..9f87ee2c21c 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -58,7 +58,7 @@ * in the range 5 to 9. */ #undef __FreeBSD_version -#define __FreeBSD_version 900009 /* Master, propagated to newvers */ +#define __FreeBSD_version 900010 /* Master, propagated to newvers */ #ifndef LOCORE #include From ae91fee256bcf6c8bcb27d01d12f25244c5a887c Mon Sep 17 00:00:00 2001 From: Xin LI Date: Mon, 22 Mar 2010 21:19:17 +0000 Subject: [PATCH 003/119] Enable mmap for minigzip(1). --- usr.bin/minigzip/Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/usr.bin/minigzip/Makefile b/usr.bin/minigzip/Makefile index 9a0ab9560fe..21b09240844 100644 --- a/usr.bin/minigzip/Makefile +++ b/usr.bin/minigzip/Makefile @@ -1,10 +1,13 @@ # $FreeBSD$ +SRCDIR= ${.CURDIR}/../../lib/libz +.PATH: ${SRCDIR} + PROG= minigzip -LDADD= -lz -DPADD= ${LIBZ} -.PATH: ${.CURDIR}/../../lib/libz WARNS?= 5 +CFLAGS+=-DUSE_MMAP +DPADD= ${LIBZ} +LDADD= -lz .include From e95a70ff0d71b97b941218383304ff2899a8a023 Mon Sep 17 00:00:00 2001 From: Edwin Groothuis Date: Mon, 22 Mar 2010 21:25:08 +0000 Subject: [PATCH 004/119] Vendor import of tzdata2010f: The Australian Antartic Division: - Macquarie Island will stay on UTC+11 for winter and not switch back from DST. - Casey station reverted to its normal time of UTC+8 on 5 March 2010. - Davis station will revert to its normal time of UTC+7 at 10 March 2010 - Mawson station stays on UTC+5. Syria will start DST on Thursday 1 April 2010 at midnight. Correct Samao DST start date (26 Sep vs 24 Oct) Obtained from: ftp://elsie.nci.nih.gov/pub/ --- antarctica | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++--- asia | 13 +++++++++-- australasia | 4 ++-- zone.tab | 3 ++- 4 files changed, 77 insertions(+), 8 deletions(-) diff --git a/antarctica b/antarctica index f18ae959e3e..629b2d7b815 100644 --- a/antarctica +++ b/antarctica @@ -1,5 +1,5 @@ #
-# @(#)antarctica	8.7
+# @(#)antarctica	8.8
 # This file is in the public domain, so clarified as of
 # 2009-05-17 by Arthur David Olson.
 
@@ -57,6 +57,33 @@ Rule	ChileAQ	1999	only	-	Apr	 4	3:00u	0	-
 Rule	ChileAQ	1999	max	-	Oct	Sun>=9	4:00u	1:00	S
 Rule	ChileAQ	2000	max	-	Mar	Sun>=9	3:00u	0	-
 
+# These rules are stolen from the `australasia' file.
+Rule	AusAQ	1917	only	-	Jan	 1	0:01	1:00	-
+Rule	AusAQ	1917	only	-	Mar	25	2:00	0	-
+Rule	AusAQ	1942	only	-	Jan	 1	2:00	1:00	-
+Rule	AusAQ	1942	only	-	Mar	29	2:00	0	-
+Rule	AusAQ	1942	only	-	Sep	27	2:00	1:00	-
+Rule	AusAQ	1943	1944	-	Mar	lastSun	2:00	0	-
+Rule	AusAQ	1943	only	-	Oct	 3	2:00	1:00	-
+Rule	ATAQ	1967	only	-	Oct	Sun>=1	2:00s	1:00	-
+Rule	ATAQ	1968	only	-	Mar	lastSun	2:00s	0	-
+Rule	ATAQ	1968	1985	-	Oct	lastSun	2:00s	1:00	-
+Rule	ATAQ	1969	1971	-	Mar	Sun>=8	2:00s	0	-
+Rule	ATAQ	1972	only	-	Feb	lastSun	2:00s	0	-
+Rule	ATAQ	1973	1981	-	Mar	Sun>=1	2:00s	0	-
+Rule	ATAQ	1982	1983	-	Mar	lastSun	2:00s	0	-
+Rule	ATAQ	1984	1986	-	Mar	Sun>=1	2:00s	0	-
+Rule	ATAQ	1986	only	-	Oct	Sun>=15	2:00s	1:00	-
+Rule	ATAQ	1987	1990	-	Mar	Sun>=15	2:00s	0	-
+Rule	ATAQ	1987	only	-	Oct	Sun>=22	2:00s	1:00	-
+Rule	ATAQ	1988	1990	-	Oct	lastSun	2:00s	1:00	-
+Rule	ATAQ	1991	1999	-	Oct	Sun>=1	2:00s	1:00	-
+Rule	ATAQ	1991	2005	-	Mar	lastSun	2:00s	0	-
+Rule	ATAQ	2000	only	-	Aug	lastSun	2:00s	1:00	-
+Rule	ATAQ	2001	max	-	Oct	Sun>=1	2:00s	1:00	-
+Rule	ATAQ	2006	only	-	Apr	Sun>=1	2:00s	0	-
+Rule	ATAQ	2007	only	-	Mar	lastSun	2:00s	0	-
+Rule	ATAQ	2008	max	-	Apr	Sun>=1	2:00s	0	-
 
 # Argentina - year-round bases
 # Belgrano II, Confin Coast, -770227-0343737, since 1972-02-05
@@ -98,20 +125,52 @@ Rule	ChileAQ	2000	max	-	Mar	Sun>=9	3:00u	0	-
 # http://www.timeanddate.com/news/time/antarctica-new-times.html
 # 
 
+# From Steffen Thorsen (2010-03-10):
+# We got these changes from the Australian Antarctic Division:
+# - Macquarie Island will stay on UTC+11 for winter and therefore not
+# switch back from daylight savings time when other parts of Australia do
+# on 4 April.
+#
+# - Casey station reverted to its normal time of UTC+8 on 5 March 2010.
+# The change to UTC+11 is being considered as a regular summer thing but
+# has not been decided yet.
+#
+# - Davis station will revert to its normal time of UTC+7 at 10 March 2010
+# 20:00 UTC.
+#
+# - Mawson station stays on UTC+5.
+#
+# In addition to the Rule changes for Casey/Davis, it means that Macquarie
+# will no longer be like Hobart and will have to have its own Zone created.
+#
+# Background:
+# 
+# http://www.timeanddate.com/news/time/antartica-time-changes-2010.html
+# 
+
 # Zone	NAME		GMTOFF	RULES	FORMAT	[UNTIL]
 Zone Antarctica/Casey	0	-	zzz	1969
 			8:00	-	WST	2009 Oct 18 2:00
 						# Western (Aus) Standard Time
-			11:00	-	CAST	# Casey Time
+			11:00	-	CAST	2010 Mar 5 2:00
+						# Casey Time
+			8:00	-	WST
 Zone Antarctica/Davis	0	-	zzz	1957 Jan 13
 			7:00	-	DAVT	1964 Nov # Davis Time
 			0	-	zzz	1969 Feb
 			7:00	-	DAVT	2009 Oct 18 2:00
-			5:00	-	DAVT
+			5:00	-	DAVT	2010 Mar 10 20:00u
+			7:00	-	DAVT
 Zone Antarctica/Mawson	0	-	zzz	1954 Feb 13
 			6:00	-	MAWT	2009 Oct 18 2:00
 						# Mawson Time
 			5:00	-	MAWT
+Zone Antarctica/Macquarie 0	-	zzz	1911
+			10:00	-	EST	1916 Oct 1 2:00
+			10:00	1:00	EST	1917 Feb
+			10:00	AusAQ	EST	1967
+			10:00	ATAQ	EST	2010 Apr 4 3:00
+			11:00	-	MIST	# Macquarie Island Time
 # References:
 # 
 # Casey Weather (1998-02-26)
diff --git a/asia b/asia
index 41aeb4bb0ab..859d9c54d43 100644
--- a/asia
+++ b/asia
@@ -1,4 +1,4 @@
-# @(#)asia	8.55
+# @(#)asia	8.56
 # This file is in the public domain, so clarified as of
 # 2009-05-17 by Arthur David Olson.
 
@@ -2438,9 +2438,18 @@ Rule	Syria	2007	only	-	Nov	 Fri>=1	0:00	0	-
 # Thursday of the month or the start of the last Friday of the month or
 # something else. For now, use the start of the last Friday.
 
+# From Steffen Thorsen (2010-03-17):
+# The "Syrian News Station" reported on 2010-03-16 that the Council of
+# Ministers has decided that Syria will start DST on midnight Thursday
+# 2010-04-01: (midnight between Thursday and Friday):
+# 
+# http://sns.sy/sns/?path=news/read/11421 (Arabic)
+# 
+
 Rule	Syria	2008	only	-	Apr	Fri>=1	0:00	1:00	S
 Rule	Syria	2008	only	-	Nov	1	0:00	0	-
-Rule	Syria	2009	max	-	Mar	lastFri	0:00	1:00	S
+Rule	Syria	2009	only	-	Mar	lastFri	0:00	1:00	S
+Rule	Syria	2010	max	-	Apr	Fri>=1	0:00	1:00	S
 Rule	Syria	2009	max	-	Oct	lastFri	0:00	0	-
 
 # Zone	NAME		GMTOFF	RULES	FORMAT	[UNTIL]
diff --git a/australasia b/australasia
index 614a446c13a..9884b6750a7 100644
--- a/australasia
+++ b/australasia
@@ -1,5 +1,5 @@
 # 
-# @(#)australasia	8.16
+# @(#)australasia	8.17
 # This file is in the public domain, so clarified as of
 # 2009-05-17 by Arthur David Olson.
 
@@ -490,7 +490,7 @@ Zone Pacific/Pago_Pago	 12:37:12 -	LMT	1879 Jul  5
 Zone Pacific/Apia	 12:33:04 -	LMT	1879 Jul  5
 			-11:26:56 -	LMT	1911
 			-11:30	-	SAMT	1950		# Samoa Time
-			-11:00	-	WST	2010 Oct 24
+			-11:00	-	WST	2010 Sep 26
 			-11:00	1:00	WSDT	2011 Apr 3
 			-11:00	-	WST
 
diff --git a/zone.tab b/zone.tab
index 2792d57eca9..c04d3e8ecc1 100644
--- a/zone.tab
+++ b/zone.tab
@@ -1,5 +1,5 @@
 # 
-# @(#)zone.tab	8.33
+# @(#)zone.tab	8.34
 # This file is in the public domain, so clarified as of
 # 2009-05-17 by Arthur David Olson.
 #
@@ -44,6 +44,7 @@ AQ	-6617+11031	Antarctica/Casey	Casey Station, Bailey Peninsula
 AQ	-7824+10654	Antarctica/Vostok	Vostok Station, S Magnetic Pole
 AQ	-6640+14001	Antarctica/DumontDUrville	Dumont-d'Urville Station, Terre Adelie
 AQ	-690022+0393524	Antarctica/Syowa	Syowa Station, E Ongul I
+AQ	-5430+15857	Antarctica/Macquarie	Macquarie Island Station, Macquarie Island
 AR	-3436-05827	America/Argentina/Buenos_Aires	Buenos Aires (BA, CF)
 AR	-3124-06411	America/Argentina/Cordoba	most locations (CB, CC, CN, ER, FM, MN, SE, SF)
 AR	-2447-06525	America/Argentina/Salta	(SA, LP, NQ, RN)

From 1a23373cebe1ddd05e1bbfc89944bb1eabb470da Mon Sep 17 00:00:00 2001
From: Kip Macy 
Date: Mon, 22 Mar 2010 22:39:32 +0000
Subject: [PATCH 006/119] - enable alignment on amd64 only - only align pcpu
 caches and the volatile portion of uma_zone

---
 sys/vm/uma_int.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/sys/vm/uma_int.h b/sys/vm/uma_int.h
index e04dd39afa3..27396ea077d 100644
--- a/sys/vm/uma_int.h
+++ b/sys/vm/uma_int.h
@@ -162,7 +162,11 @@ struct uma_hash {
 /*
  * align field or structure to cache line
  */
+#if defined(__amd64__)
+#define UMA_ALIGN	__aligned(CACHE_LINE_SIZE)
+#else
 #define UMA_ALIGN
+#endif
 
 /*
  * Structures for per cpu queues.
@@ -173,7 +177,7 @@ struct uma_bucket {
 	int16_t	ub_cnt;				/* Count of free items. */
 	int16_t	ub_entries;			/* Max items. */
 	void	*ub_bucket[];			/* actual allocation storage */
-} UMA_ALIGN;
+};
 
 typedef struct uma_bucket * uma_bucket_t;
 
@@ -330,7 +334,7 @@ struct uma_zone {
 	 * This HAS to be the last item because we adjust the zone size
 	 * based on NCPU and then allocate the space for the zones.
 	 */
-	struct uma_cache	uz_cpu[1] UMA_ALIGN; /* Per cpu caches */
+	struct uma_cache	uz_cpu[1]; /* Per cpu caches */
 };
 
 /*

From 3059584e2a3db1a980012c5c549d15c4796c17a0 Mon Sep 17 00:00:00 2001
From: Kip Macy 
Date: Mon, 22 Mar 2010 23:04:12 +0000
Subject: [PATCH 007/119] - boot-time size the ipv4 flowtable and the maximum
 number of flows - increase flow cleaning frequency and decrease flow caching
 time   when near the flow limit - stop allocating new flows when within 3% of
 maxflows don't start   allocating again until below 12.5%

MFC after:	7 days
---
 sys/net/flowtable.c    | 106 +++++++++++++++++++++++++++++++----------
 sys/netinet/ip_input.c |  16 ++++++-
 2 files changed, 96 insertions(+), 26 deletions(-)

diff --git a/sys/net/flowtable.c b/sys/net/flowtable.c
index fe79c807fb1..39b6b40a996 100644
--- a/sys/net/flowtable.c
+++ b/sys/net/flowtable.c
@@ -155,30 +155,33 @@ struct flowtable_stats {
 	uint64_t	ft_frees;
 	uint64_t	ft_hits;
 	uint64_t	ft_lookups;
-} __aligned(128);
+} __aligned(CACHE_LINE_SIZE);
 
 struct flowtable {
 	struct	flowtable_stats ft_stats[MAXCPU];
 	int 		ft_size;
 	int 		ft_lock_count;
 	uint32_t	ft_flags;
-
-	uint32_t	ft_udp_idle;
-	uint32_t	ft_fin_wait_idle;
-	uint32_t	ft_syn_idle;
-	uint32_t	ft_tcp_idle;
-
 	char		*ft_name;
 	fl_lock_t	*ft_lock;
 	fl_lock_t 	*ft_unlock;
 	fl_rtalloc_t	*ft_rtalloc;
+	/*
+	 * XXX need to pad out 
+	 */ 
 	struct mtx	*ft_locks;
-
 	union flentryp	ft_table;
 	bitstr_t 	*ft_masks[MAXCPU];
 	bitstr_t	*ft_tmpmask;
 	struct flowtable *ft_next;
-} __aligned(128);
+
+	uint32_t	ft_count __aligned(CACHE_LINE_SIZE);
+	uint32_t	ft_udp_idle __aligned(CACHE_LINE_SIZE);
+	uint32_t	ft_fin_wait_idle;
+	uint32_t	ft_syn_idle;
+	uint32_t	ft_tcp_idle;
+	boolean_t	ft_full;
+} __aligned(CACHE_LINE_SIZE);
 
 static struct proc *flowcleanerproc;
 static VNET_DEFINE(struct flowtable *, flow_list_head);
@@ -191,9 +194,11 @@ static VNET_DEFINE(uma_zone_t, flow_ipv6_zone);
 #define	V_flow_ipv4_zone	VNET(flow_ipv4_zone)
 #define	V_flow_ipv6_zone	VNET(flow_ipv6_zone)
 
+
 static struct cv 	flowclean_cv;
 static struct mtx	flowclean_lock;
 static uint32_t		flowclean_cycles;
+static uint32_t		flowclean_freq;
 
 #ifdef FLOWTABLE_DEBUG
 #define FLDPRINTF(ft, flags, fmt, ...) 		\
@@ -230,7 +235,7 @@ static VNET_DEFINE(int, flowtable_syn_expire) = SYN_IDLE;
 static VNET_DEFINE(int, flowtable_udp_expire) = UDP_IDLE;
 static VNET_DEFINE(int, flowtable_fin_wait_expire) = FIN_WAIT_IDLE;
 static VNET_DEFINE(int, flowtable_tcp_expire) = TCP_IDLE;
-static VNET_DEFINE(int, flowtable_nmbflows) = 4096;
+static VNET_DEFINE(int, flowtable_nmbflows);
 static VNET_DEFINE(int, flowtable_ready) = 0;
 
 #define	V_flowtable_enable		VNET(flowtable_enable)
@@ -905,6 +910,61 @@ flowtable_set_hashkey(struct flentry *fle, uint32_t *key)
 		hashkey[i] = key[i];
 }
 
+static struct flentry *
+flow_alloc(struct flowtable *ft)
+{
+	struct flentry *newfle;
+	uma_zone_t zone;
+
+	newfle = NULL;
+	zone = (ft->ft_flags & FL_IPV6) ? V_flow_ipv6_zone : V_flow_ipv4_zone;
+
+	newfle = uma_zalloc(zone, M_NOWAIT | M_ZERO);
+	if (newfle != NULL)
+		atomic_add_int(&ft->ft_count, 1);
+	return (newfle);
+}
+
+static void
+flow_free(struct flentry *fle, struct flowtable *ft)
+{
+	uma_zone_t zone;
+
+	zone = (ft->ft_flags & FL_IPV6) ? V_flow_ipv6_zone : V_flow_ipv4_zone;
+	atomic_add_int(&ft->ft_count, -1);
+	uma_zfree(zone, fle);
+}
+
+static int
+flow_full(struct flowtable *ft)
+{
+	boolean_t full;
+	uint32_t count;
+	
+	full = ft->ft_full;
+	count = ft->ft_count;
+
+	if (full && (count < (V_flowtable_nmbflows - (V_flowtable_nmbflows >> 3))))
+		ft->ft_full = FALSE;
+	else if (!full && (count > (V_flowtable_nmbflows - (V_flowtable_nmbflows >> 5))))
+		ft->ft_full = TRUE;
+	
+	if (full && !ft->ft_full) {
+		flowclean_freq = 4*hz;
+		if ((ft->ft_flags & FL_HASH_ALL) == 0)
+			ft->ft_udp_idle = ft->ft_fin_wait_idle =
+			    ft->ft_syn_idle = ft->ft_tcp_idle = 5;
+		cv_broadcast(&flowclean_cv);
+	} else if (!full && ft->ft_full) {
+		flowclean_freq = 20*hz;
+		if ((ft->ft_flags & FL_HASH_ALL) == 0)
+			ft->ft_udp_idle = ft->ft_fin_wait_idle =
+			    ft->ft_syn_idle = ft->ft_tcp_idle = 30;
+	}
+
+	return (ft->ft_full);
+}
+
 static int
 flowtable_insert(struct flowtable *ft, uint32_t hash, uint32_t *key,
     uint32_t fibnum, struct route *ro, uint16_t flags)
@@ -912,12 +972,10 @@ flowtable_insert(struct flowtable *ft, uint32_t hash, uint32_t *key,
 	struct flentry *fle, *fletail, *newfle, **flep;
 	struct flowtable_stats *fs = &ft->ft_stats[curcpu];
 	int depth;
-	uma_zone_t flezone;
 	bitstr_t *mask;
 	uint8_t proto;
 
-	flezone = (flags & FL_IPV6) ? V_flow_ipv6_zone : V_flow_ipv4_zone;
-	newfle = uma_zalloc(flezone, M_NOWAIT | M_ZERO);
+	newfle = flow_alloc(ft);
 	if (newfle == NULL)
 		return (ENOMEM);
 
@@ -948,9 +1006,8 @@ flowtable_insert(struct flowtable *ft, uint32_t hash, uint32_t *key,
 			 * or we lost a race to insert
 			 */
 			FL_ENTRY_UNLOCK(ft, hash);
-			uma_zfree((newfle->f_flags & FL_IPV6) ?
-			    V_flow_ipv6_zone : V_flow_ipv4_zone, newfle);
-
+			flow_free(newfle, ft);
+			
 			if (flags & FL_OVERWRITE) 
 				goto skip;
 			return (EEXIST);
@@ -1147,7 +1204,7 @@ keycheck:
 	}
 	FL_ENTRY_UNLOCK(ft, hash);
 uncached:
-	if (flags & FL_NOAUTO)
+	if (flags & FL_NOAUTO || flow_full(ft))
 		return (NULL);
 
 	fs->ft_misses++;
@@ -1325,7 +1382,7 @@ flowtable_alloc(char *name, int nentry, int flags)
  * 
  */
 static void
-fle_free(struct flentry *fle)
+fle_free(struct flentry *fle, struct flowtable *ft)
 {
 	struct rtentry *rt;
 	struct llentry *lle;
@@ -1334,8 +1391,7 @@ fle_free(struct flentry *fle)
 	lle = __DEVOLATILE(struct llentry *, fle->f_lle);
 	RTFREE(rt);
 	LLE_FREE(lle);
-	uma_zfree((fle->f_flags & FL_IPV6) ?
-	    V_flow_ipv6_zone : V_flow_ipv4_zone, fle);
+	flow_free(fle, ft);
 }
 
 static void
@@ -1426,7 +1482,7 @@ flowtable_free_stale(struct flowtable *ft, struct rtentry *rt)
 		flefreehead = fle->f_next;
 		count++;
 		fs->ft_frees++;
-		fle_free(fle);
+		fle_free(fle, ft);
 	}
 	if (V_flowtable_debug && count)
 		log(LOG_DEBUG, "freed %d flow entries\n", count);
@@ -1518,7 +1574,7 @@ flowtable_cleaner(void)
 		 */
 		mtx_lock(&flowclean_lock);
 		cv_broadcast(&flowclean_cv);
-		cv_timedwait(&flowclean_cv, &flowclean_lock, 10*hz);
+		cv_timedwait(&flowclean_cv, &flowclean_lock, flowclean_freq);
 		mtx_unlock(&flowclean_lock);
 	}
 }
@@ -1548,6 +1604,7 @@ static void
 flowtable_init_vnet(const void *unused __unused)
 {
 
+	V_flowtable_nmbflows = 1024 + maxusers * 64 * mp_ncpus;
 	V_flow_ipv4_zone = uma_zcreate("ip4flow", sizeof(struct flentry_v4),
 	    NULL, NULL, NULL, NULL, 64, UMA_ZONE_MAXBUCKET);
 	V_flow_ipv6_zone = uma_zcreate("ip6flow", sizeof(struct flentry_v6),
@@ -1556,7 +1613,7 @@ flowtable_init_vnet(const void *unused __unused)
 	uma_zone_set_max(V_flow_ipv6_zone, V_flowtable_nmbflows);
 	V_flowtable_ready = 1;
 }
-VNET_SYSINIT(flowtable_init_vnet, SI_SUB_KTHREAD_INIT, SI_ORDER_MIDDLE,
+VNET_SYSINIT(flowtable_init_vnet, SI_SUB_SMP, SI_ORDER_ANY,
     flowtable_init_vnet, NULL);
 
 static void
@@ -1567,8 +1624,9 @@ flowtable_init(const void *unused __unused)
 	mtx_init(&flowclean_lock, "flowclean lock", NULL, MTX_DEF);
 	EVENTHANDLER_REGISTER(ifnet_departure_event, flowtable_flush, NULL,
 	    EVENTHANDLER_PRI_ANY);
+	flowclean_freq = 20*hz;
 }
-SYSINIT(flowtable_init, SI_SUB_KTHREAD_INIT, SI_ORDER_ANY,
+SYSINIT(flowtable_init, SI_SUB_SMP, SI_ORDER_MIDDLE,
     flowtable_init, NULL);
 
 
diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c
index d91bcb0e4be..8be51fb992d 100644
--- a/sys/netinet/ip_input.c
+++ b/sys/netinet/ip_input.c
@@ -327,8 +327,20 @@ ip_init(void)
 			"error %d\n", __func__, i);
 
 #ifdef FLOWTABLE
-	TUNABLE_INT_FETCH("net.inet.ip.output_flowtable_size",
-	    &V_ip_output_flowtable_size);
+	if (TUNABLE_INT_FETCH("net.inet.ip.output_flowtable_size",
+		&V_ip_output_flowtable_size)) {
+		if (V_ip_output_flowtable_size < 256)
+			V_ip_output_flowtable_size = 256;
+		if (!powerof2(V_ip_output_flowtable_size)) {
+			printf("flowtable must be power of 2 size\n");
+			V_ip_output_flowtable_size = 2048;
+		}
+	} else {
+		/*
+		 * round up to the next power of 2
+		 */
+		V_ip_output_flowtable_size = 1 << fls((1024 + maxusers * 64)-1);
+	}
 	V_ip_ft = flowtable_alloc("ipv4", V_ip_output_flowtable_size, FL_PCPU);
 #endif
 

From 6d58efc75d672a1f402506b828a6d5f8d8240c7c Mon Sep 17 00:00:00 2001
From: Marcel Moolenaar 
Date: Tue, 23 Mar 2010 01:07:30 +0000
Subject: [PATCH 008/119] Actually pass a pointer to the trapframe to
 powerpc_extr_interrupt().

---
 sys/powerpc/booke/trap_subr.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sys/powerpc/booke/trap_subr.S b/sys/powerpc/booke/trap_subr.S
index 2e67725dc4f..b71f4bdb790 100644
--- a/sys/powerpc/booke/trap_subr.S
+++ b/sys/powerpc/booke/trap_subr.S
@@ -441,6 +441,7 @@ INTERRUPT(int_instr_storage)
 INTERRUPT(int_external_input)
 	STANDARD_PROLOG(SPR_SPRG1, PC_TEMPSAVE, SPR_SRR0, SPR_SRR1)
 	FRAME_SETUP(SPR_SPRG1, PC_TEMPSAVE, EXC_EXI)
+	addi	%r3, %r1, 8
 	bl	CNAME(powerpc_extr_interrupt)
 	b	trapexit
 

From d4bccd63a20b5f2218f39be80bd0c1acbb671f04 Mon Sep 17 00:00:00 2001
From: Nathan Whitehorn 
Date: Tue, 23 Mar 2010 01:09:45 +0000
Subject: [PATCH 009/119] Do not declare the various OFW command buffers
 static. It does not appear to be necessary on either sparc64 or powerpc, and
 is a concurrency nightmare.

Reviewed by:	marius
---
 sys/dev/ofw/ofw_standard.c | 48 +++++++++++++++++++-------------------
 sys/powerpc/ofw/ofw_real.c | 46 ++++++++++++++++++------------------
 2 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/sys/dev/ofw/ofw_standard.c b/sys/dev/ofw/ofw_standard.c
index de18a9e73df..0fda7db8467 100644
--- a/sys/dev/ofw/ofw_standard.c
+++ b/sys/dev/ofw/ofw_standard.c
@@ -165,7 +165,7 @@ ofw_std_init(ofw_t ofw, void *openfirm)
 static int
 ofw_std_test(ofw_t ofw, const char *name)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -187,7 +187,7 @@ static int
 ofw_std_interpret(ofw_t ofw, const char *cmd, int nreturns,
     unsigned long *returns)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -217,7 +217,7 @@ ofw_std_interpret(ofw_t ofw, const char *cmd, int nreturns,
 static phandle_t
 ofw_std_peer(ofw_t ofw, phandle_t node)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -239,7 +239,7 @@ ofw_std_peer(ofw_t ofw, phandle_t node)
 static phandle_t
 ofw_std_child(ofw_t ofw, phandle_t node)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -261,7 +261,7 @@ ofw_std_child(ofw_t ofw, phandle_t node)
 static phandle_t
 ofw_std_parent(ofw_t ofw, phandle_t node)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -283,7 +283,7 @@ ofw_std_parent(ofw_t ofw, phandle_t node)
 static phandle_t
 ofw_std_instance_to_package(ofw_t ofw, ihandle_t instance)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -305,7 +305,7 @@ ofw_std_instance_to_package(ofw_t ofw, ihandle_t instance)
 static ssize_t
 ofw_std_getproplen(ofw_t ofw, phandle_t package, const char *propname)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -330,7 +330,7 @@ static ssize_t
 ofw_std_getprop(ofw_t ofw, phandle_t package, const char *propname, void *buf,
     size_t buflen)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -359,7 +359,7 @@ static int
 ofw_std_nextprop(ofw_t ofw, phandle_t package, const char *previous, char *buf,
     size_t size)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -387,7 +387,7 @@ static int
 ofw_std_setprop(ofw_t ofw, phandle_t package, const char *propname,
     const void *buf, size_t len)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -415,7 +415,7 @@ ofw_std_setprop(ofw_t ofw, phandle_t package, const char *propname,
 static ssize_t
 ofw_std_canon(ofw_t ofw, const char *device, char *buf, size_t len)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -441,7 +441,7 @@ ofw_std_canon(ofw_t ofw, const char *device, char *buf, size_t len)
 static phandle_t
 ofw_std_finddevice(ofw_t ofw, const char *device)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -463,7 +463,7 @@ ofw_std_finddevice(ofw_t ofw, const char *device)
 static ssize_t
 ofw_std_instance_to_path(ofw_t ofw, ihandle_t instance, char *buf, size_t len)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -489,7 +489,7 @@ ofw_std_instance_to_path(ofw_t ofw, ihandle_t instance, char *buf, size_t len)
 static ssize_t
 ofw_std_package_to_path(ofw_t ofw, phandle_t package, char *buf, size_t len)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -516,7 +516,7 @@ static int
 ofw_std_call_method(ofw_t ofw, ihandle_t instance, const char *method,
     int nargs, int nreturns, unsigned long *args_and_returns)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -559,7 +559,7 @@ ofw_std_call_method(ofw_t ofw, ihandle_t instance, const char *method,
 static ihandle_t
 ofw_std_open(ofw_t ofw, const char *device)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -581,7 +581,7 @@ ofw_std_open(ofw_t ofw, const char *device)
 static void
 ofw_std_close(ofw_t ofw, ihandle_t instance)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -599,7 +599,7 @@ ofw_std_close(ofw_t ofw, ihandle_t instance)
 static ssize_t
 ofw_std_read(ofw_t ofw, ihandle_t instance, void *addr, size_t len)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -626,7 +626,7 @@ ofw_std_read(ofw_t ofw, ihandle_t instance, void *addr, size_t len)
 static ssize_t
 ofw_std_write(ofw_t ofw, ihandle_t instance, const void *addr, size_t len)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -652,7 +652,7 @@ ofw_std_write(ofw_t ofw, ihandle_t instance, const void *addr, size_t len)
 static int
 ofw_std_seek(ofw_t ofw, ihandle_t instance, uint64_t pos)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -682,7 +682,7 @@ ofw_std_seek(ofw_t ofw, ihandle_t instance, uint64_t pos)
 static caddr_t
 ofw_std_claim(ofw_t ofw, void *virt, size_t size, u_int align)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -708,7 +708,7 @@ ofw_std_claim(ofw_t ofw, void *virt, size_t size, u_int align)
 static void
 ofw_std_release(ofw_t ofw, void *virt, size_t size)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -732,7 +732,7 @@ ofw_std_release(ofw_t ofw, void *virt, size_t size)
 static void
 ofw_std_enter(ofw_t ofw)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -748,7 +748,7 @@ ofw_std_enter(ofw_t ofw)
 static void
 ofw_std_exit(ofw_t ofw)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
diff --git a/sys/powerpc/ofw/ofw_real.c b/sys/powerpc/ofw/ofw_real.c
index a65ee91cf1b..094025c4194 100644
--- a/sys/powerpc/ofw/ofw_real.c
+++ b/sys/powerpc/ofw/ofw_real.c
@@ -273,7 +273,7 @@ ofw_real_init(ofw_t ofw, void *openfirm)
 static int
 ofw_real_test(ofw_t ofw, const char *name)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -304,7 +304,7 @@ ofw_real_test(ofw_t ofw, const char *name)
 static phandle_t
 ofw_real_peer(ofw_t ofw, phandle_t node)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -326,7 +326,7 @@ ofw_real_peer(ofw_t ofw, phandle_t node)
 static phandle_t
 ofw_real_child(ofw_t ofw, phandle_t node)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -348,7 +348,7 @@ ofw_real_child(ofw_t ofw, phandle_t node)
 static phandle_t
 ofw_real_parent(ofw_t ofw, phandle_t node)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -370,7 +370,7 @@ ofw_real_parent(ofw_t ofw, phandle_t node)
 static phandle_t
 ofw_real_instance_to_package(ofw_t ofw, ihandle_t instance)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -392,7 +392,7 @@ ofw_real_instance_to_package(ofw_t ofw, ihandle_t instance)
 static ssize_t
 ofw_real_getproplen(ofw_t ofw, phandle_t package, const char *propname)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -422,7 +422,7 @@ static ssize_t
 ofw_real_getprop(ofw_t ofw, phandle_t package, const char *propname, void *buf, 
     size_t buflen)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -458,7 +458,7 @@ static int
 ofw_real_nextprop(ofw_t ofw, phandle_t package, const char *previous, 
     char *buf, size_t size)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -493,7 +493,7 @@ static int
 ofw_real_setprop(ofw_t ofw, phandle_t package, const char *propname,
     const void *buf, size_t len)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -526,7 +526,7 @@ ofw_real_setprop(ofw_t ofw, phandle_t package, const char *propname,
 static ssize_t
 ofw_real_canon(ofw_t ofw, const char *device, char *buf, size_t len)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -559,7 +559,7 @@ ofw_real_canon(ofw_t ofw, const char *device, char *buf, size_t len)
 static phandle_t
 ofw_real_finddevice(ofw_t ofw, const char *device)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -586,7 +586,7 @@ ofw_real_finddevice(ofw_t ofw, const char *device)
 static ssize_t
 ofw_real_instance_to_path(ofw_t ofw, ihandle_t instance, char *buf, size_t len)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -619,7 +619,7 @@ ofw_real_instance_to_path(ofw_t ofw, ihandle_t instance, char *buf, size_t len)
 static ssize_t
 ofw_real_package_to_path(ofw_t ofw, phandle_t package, char *buf, size_t len)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -653,7 +653,7 @@ static int
 ofw_real_call_method(ofw_t ofw, ihandle_t instance, const char *method, 
     int nargs, int nreturns, unsigned long *args_and_returns)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -701,7 +701,7 @@ ofw_real_call_method(ofw_t ofw, ihandle_t instance, const char *method,
 static ihandle_t
 ofw_real_open(ofw_t ofw, const char *device)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -729,7 +729,7 @@ ofw_real_open(ofw_t ofw, const char *device)
 static void
 ofw_real_close(ofw_t ofw, ihandle_t instance)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -747,7 +747,7 @@ ofw_real_close(ofw_t ofw, ihandle_t instance)
 static ssize_t
 ofw_real_read(ofw_t ofw, ihandle_t instance, void *addr, size_t len)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -780,7 +780,7 @@ ofw_real_read(ofw_t ofw, ihandle_t instance, void *addr, size_t len)
 static ssize_t
 ofw_real_write(ofw_t ofw, ihandle_t instance, const void *addr, size_t len)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -811,7 +811,7 @@ ofw_real_write(ofw_t ofw, ihandle_t instance, const void *addr, size_t len)
 static int
 ofw_real_seek(ofw_t ofw, ihandle_t instance, u_int64_t pos)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -841,7 +841,7 @@ ofw_real_seek(ofw_t ofw, ihandle_t instance, u_int64_t pos)
 static caddr_t
 ofw_real_claim(ofw_t ofw, void *virt, size_t size, u_int align)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -867,7 +867,7 @@ ofw_real_claim(ofw_t ofw, void *virt, size_t size, u_int align)
 static void
 ofw_real_release(ofw_t ofw, void *virt, size_t size)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -891,7 +891,7 @@ ofw_real_release(ofw_t ofw, void *virt, size_t size)
 static void
 ofw_real_enter(ofw_t ofw)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;
@@ -907,7 +907,7 @@ ofw_real_enter(ofw_t ofw)
 static void
 ofw_real_exit(ofw_t ofw)
 {
-	static struct {
+	struct {
 		cell_t name;
 		cell_t nargs;
 		cell_t nreturns;

From 46c3bbc0ea309d70ceb2ba7689583c3930931e13 Mon Sep 17 00:00:00 2001
From: Nathan Whitehorn 
Date: Tue, 23 Mar 2010 01:11:10 +0000
Subject: [PATCH 010/119] Open Firmware on powerpc is generally non-reetrant,
 so serialize all OF calls with a mutex.

---
 sys/powerpc/aim/ofw_machdep.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/sys/powerpc/aim/ofw_machdep.c b/sys/powerpc/aim/ofw_machdep.c
index 6e276970edd..6e98f3e4fba 100644
--- a/sys/powerpc/aim/ofw_machdep.c
+++ b/sys/powerpc/aim/ofw_machdep.c
@@ -63,6 +63,8 @@ __FBSDID("$FreeBSD$");
 static struct mem_region OFmem[OFMEM_REGIONS + 1], OFavail[OFMEM_REGIONS + 3];
 static struct mem_region OFfree[OFMEM_REGIONS + 3];
 
+static struct mtx ofw_mutex;
+
 struct mem_region64 {
         vm_offset_t     mr_start_hi;
         vm_offset_t     mr_start_lo;
@@ -281,6 +283,8 @@ OF_bootstrap()
 {
 	boolean_t status = FALSE;
 
+	mtx_init(&ofw_mutex, "open firmware", NULL, MTX_DEF);
+
 	if (ofwcall != NULL) {
 		if (ofw_real_mode)
 			status = OF_install(OFW_STD_REAL, 0);
@@ -314,6 +318,8 @@ openfirmware(void *args)
 	if (pmap_bootstrapped && ofw_real_mode)
 		args = (void *)pmap_kextract((vm_offset_t)args);
 
+	mtx_lock(&ofw_mutex);
+
 	__asm __volatile(	"\t"
 		"sync\n\t"
 		"mfmsr  %0\n\t"
@@ -366,6 +372,8 @@ openfirmware(void *args)
 		: : "r" (oldmsr)
 	);
 
+	mtx_unlock(&ofw_mutex);
+
 	return (result);
 }
 

From 0e13104de6223fb6ee0c5699d0eea37384b98c11 Mon Sep 17 00:00:00 2001
From: Randall Stewart 
Date: Tue, 23 Mar 2010 01:36:50 +0000
Subject: [PATCH 011/119] Fixes a bug where SACKs in the face of mapping_array
 expansion would break. Basically once we expanded the array we no longer had
 both mapping arrays in sync which the sack processing code depends on. This
 would mean we were randomly referring to memory that was probably not there.
 This mostly just gave us bad sack results going back to the peer. If
 INVARIENTS was on of course we would hit the panic routine in the sack_check
 call.

We also add a print routine for the place where one would panic in
invarients so one can see what the main mapping array holds.

Reviewed by: tuexen@freebsd.org
MFC after:	2 weeks
---
 sys/netinet/sctp_indata.c | 36 +-----------------------------
 sys/netinet/sctputil.c    | 47 +++++++++++++++++++++++++++------------
 sys/netinet/sctputil.h    |  2 +-
 3 files changed, 35 insertions(+), 50 deletions(-)

diff --git a/sys/netinet/sctp_indata.c b/sys/netinet/sctp_indata.c
index cdb78aff0e0..65eb08642f5 100644
--- a/sys/netinet/sctp_indata.c
+++ b/sys/netinet/sctp_indata.c
@@ -2540,15 +2540,7 @@ sctp_sack_check(struct sctp_tcb *stcb, int ok_to_sack, int was_a_gap, int *abort
 	/* int nr_at; */
 	/* int nr_last_all_ones = 0; */
 	/* int nr_slide_from, nr_slide_end, nr_lgap, nr_distance; */
-
 	uint32_t old_cumack, old_base, old_highest;
-	unsigned char aux_array[64];
-
-	/*
-	 * EY! Don't think this is required but I am immitating the code for
-	 * map just to make sure
-	 */
-	unsigned char nr_aux_array[64];
 
 	asoc = &stcb->asoc;
 	at = 0;
@@ -2556,33 +2548,6 @@ sctp_sack_check(struct sctp_tcb *stcb, int ok_to_sack, int was_a_gap, int *abort
 	old_cumack = asoc->cumulative_tsn;
 	old_base = asoc->mapping_array_base_tsn;
 	old_highest = asoc->highest_tsn_inside_map;
-	if (asoc->mapping_array_size < 64)
-		memcpy(aux_array, asoc->mapping_array,
-		    asoc->mapping_array_size);
-	else
-		memcpy(aux_array, asoc->mapping_array, 64);
-	/* EY do the same for nr_mapping_array */
-	if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) {
-		if (asoc->nr_mapping_array_size != asoc->mapping_array_size) {
-			/*
-			 * printf("\nEY-IN sack_check method: \nEY-" "The
-			 * size of map and nr_map are inconsitent")
-			 */ ;
-		}
-		if (asoc->nr_mapping_array_base_tsn != asoc->mapping_array_base_tsn) {
-			/*
-			 * printf("\nEY-IN sack_check method VERY CRUCIAL
-			 * error: \nEY-" "The base tsns of map and nr_map
-			 * are inconsitent")
-			 */ ;
-		}
-		/* EY! just immitating the above code */
-		if (asoc->nr_mapping_array_size < 64)
-			memcpy(nr_aux_array, asoc->nr_mapping_array,
-			    asoc->nr_mapping_array_size);
-		else
-			memcpy(aux_array, asoc->nr_mapping_array, 64);
-	}
 	/*
 	 * We could probably improve this a small bit by calculating the
 	 * offset of the current cum-ack as the starting point.
@@ -2618,6 +2583,7 @@ sctp_sack_check(struct sctp_tcb *stcb, int ok_to_sack, int was_a_gap, int *abort
 #else
 		SCTP_PRINTF("huh, cumack 0x%x greater than high-tsn 0x%x in map - should panic?\n",
 		    asoc->cumulative_tsn, asoc->highest_tsn_inside_map);
+		sctp_print_mapping_array(asoc);
 		if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) {
 			sctp_log_map(0, 6, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT);
 		}
diff --git a/sys/netinet/sctputil.c b/sys/netinet/sctputil.c
index 658dc555710..c03b9d0e245 100644
--- a/sys/netinet/sctputil.c
+++ b/sys/netinet/sctputil.c
@@ -1180,6 +1180,25 @@ sctp_init_asoc(struct sctp_inpcb *m, struct sctp_tcb *stcb,
 	return (0);
 }
 
+void
+sctp_print_mapping_array(struct sctp_association *asoc)
+{
+	int i;
+
+	printf("Mapping size:%d baseTSN:%8.8x cumAck:%8.8x highestTSN:%8.8x\n",
+	    asoc->mapping_array_size,
+	    asoc->mapping_array_base_tsn,
+	    asoc->cumulative_tsn,
+	    asoc->highest_tsn_inside_map
+	    );
+	for (i = 0; i < asoc->mapping_array_size; i++) {
+		printf("%8.8x ", asoc->mapping_array[i]);
+		if (((i + 1) % 8) == 0)
+			printf("\n");
+	}
+	printf("\n");
+}
+
 int
 sctp_expand_mapping_array(struct sctp_association *asoc, uint32_t needed)
 {
@@ -1187,7 +1206,9 @@ sctp_expand_mapping_array(struct sctp_association *asoc, uint32_t needed)
 	uint8_t *new_array;
 	uint32_t new_size;
 
+
 	new_size = asoc->mapping_array_size + ((needed + 7) / 8 + SCTP_MAPPING_ARRAY_INCR);
+
 	SCTP_MALLOC(new_array, uint8_t *, new_size, SCTP_M_MAP);
 	if (new_array == NULL) {
 		/* can't get more, forget it */
@@ -1200,21 +1221,19 @@ sctp_expand_mapping_array(struct sctp_association *asoc, uint32_t needed)
 	SCTP_FREE(asoc->mapping_array, SCTP_M_MAP);
 	asoc->mapping_array = new_array;
 	asoc->mapping_array_size = new_size;
-	if (asoc->peer_supports_nr_sack) {
-		new_size = asoc->nr_mapping_array_size + ((needed + 7) / 8 + SCTP_NR_MAPPING_ARRAY_INCR);
-		SCTP_MALLOC(new_array, uint8_t *, new_size, SCTP_M_MAP);
-		if (new_array == NULL) {
-			/* can't get more, forget it */
-			SCTP_PRINTF("No memory for expansion of SCTP mapping array %d\n",
-			    new_size);
-			return (-1);
-		}
-		memset(new_array, 0, new_size);
-		memcpy(new_array, asoc->nr_mapping_array, asoc->nr_mapping_array_size);
-		SCTP_FREE(asoc->nr_mapping_array, SCTP_M_MAP);
-		asoc->nr_mapping_array = new_array;
-		asoc->nr_mapping_array_size = new_size;
+	new_size = asoc->nr_mapping_array_size + ((needed + 7) / 8 + SCTP_NR_MAPPING_ARRAY_INCR);
+	SCTP_MALLOC(new_array, uint8_t *, new_size, SCTP_M_MAP);
+	if (new_array == NULL) {
+		/* can't get more, forget it */
+		SCTP_PRINTF("No memory for expansion of SCTP mapping array %d\n",
+		    new_size);
+		return (-1);
 	}
+	memset(new_array, 0, new_size);
+	memcpy(new_array, asoc->nr_mapping_array, asoc->nr_mapping_array_size);
+	SCTP_FREE(asoc->nr_mapping_array, SCTP_M_MAP);
+	asoc->nr_mapping_array = new_array;
+	asoc->nr_mapping_array_size = new_size;
 	return (0);
 }
 
diff --git a/sys/netinet/sctputil.h b/sys/netinet/sctputil.h
index f3a731ea1a0..8d663abe2ca 100644
--- a/sys/netinet/sctputil.h
+++ b/sys/netinet/sctputil.h
@@ -376,7 +376,7 @@ int sctp_fill_stat_log(void *, size_t *);
 void sctp_log_fr(uint32_t, uint32_t, uint32_t, int);
 void sctp_log_sack(uint32_t, uint32_t, uint32_t, uint16_t, uint16_t, int);
 void sctp_log_map(uint32_t, uint32_t, uint32_t, int);
-
+void sctp_print_mapping_array(struct sctp_association *asoc);
 void sctp_clr_stat_log(void);
 
 

From 3df9e0375a80324fc2c38fd9a582c31ad286e035 Mon Sep 17 00:00:00 2001
From: Nathan Whitehorn 
Date: Tue, 23 Mar 2010 03:14:44 +0000
Subject: [PATCH 012/119] Get nexus(4) out of the RTC business. The interface
 used by nexus(4) in Open Firmware was Apple-specific, and we have complete
 coverage of Apple system controllers, so move RTC responsibilities into the
 system controller drivers. This avoids interesting problems from manipulating
 these devices through Open Firmware behind the backs of their drivers.

Obtained from:	NetBSD
MFC after:	2 weeks
---
 sys/powerpc/aim/nexus.c        | 60 ------------------------------
 sys/powerpc/powermac/cuda.c    | 65 ++++++++++++++++++++++++++++++++-
 sys/powerpc/powermac/cudavar.h |  1 +
 sys/powerpc/powermac/pmu.c     | 59 +++++++++++++++++++++++++++++-
 sys/powerpc/powermac/smu.c     | 67 ++++++++++++++++++++++++++++++++++
 5 files changed, 190 insertions(+), 62 deletions(-)

diff --git a/sys/powerpc/aim/nexus.c b/sys/powerpc/aim/nexus.c
index d92090b9cf4..54567b135c6 100644
--- a/sys/powerpc/aim/nexus.c
+++ b/sys/powerpc/aim/nexus.c
@@ -60,7 +60,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -74,7 +73,6 @@
 
 #include 
 
-#include "clock_if.h"
 #include "ofw_bus_if.h"
 #include "pic_if.h"
 
@@ -142,12 +140,6 @@ static const char	*nexus_ofw_get_name(device_t, device_t);
 static const char	*nexus_ofw_get_type(device_t, device_t);
 static const char	*nexus_ofw_get_compat(device_t, device_t);
 
-/*
- * Clock interface.
- */
-static int nexus_gettime(device_t, struct timespec *);
-static int nexus_settime(device_t, struct timespec *);
-
 /*
  * Local routines
  */
@@ -181,10 +173,6 @@ static device_method_t nexus_methods[] = {
 	DEVMETHOD(ofw_bus_get_type, nexus_ofw_get_type),
 	DEVMETHOD(ofw_bus_get_compat, nexus_ofw_get_compat),
 
-	/* Clock interface */
-	DEVMETHOD(clock_gettime,	nexus_gettime),
-	DEVMETHOD(clock_settime,	nexus_settime),
-
 	{ 0, 0 }
 };
 
@@ -240,7 +228,6 @@ nexus_attach(device_t dev)
 
 	}
 
-	clock_register(dev, 1000);
 	return (bus_generic_attach(dev));
 }
 
@@ -512,50 +499,3 @@ nexus_ofw_get_compat(device_t bus, device_t dev)
 	return (dinfo->ndi_compatible);
 }
 
-#define	DIFF19041970	2082844800
-
-static int
-nexus_gettime(device_t dev, struct timespec *ts)
-{
-	char path[128];
-	ihandle_t ih;
-	phandle_t ph;
-	u_int rtc;
-
-	ph = OF_finddevice("rtc");
-	if (ph == -1)
-		return (ENOENT);
-
-	OF_package_to_path(ph, path, sizeof(path));
-	ih = OF_open(path);
-	if (ih == -1)
-		return (ENXIO);
-
-	if (OF_call_method("read-rtc", ih, 0, 1, &rtc))
-		return (EIO);
-
-	ts->tv_sec = rtc - DIFF19041970;
-	ts->tv_nsec = 0;
-	return (0);
-}
-
-static int
-nexus_settime(device_t dev, struct timespec *ts)
-{
-	char path[128];
-	ihandle_t ih;
-	phandle_t ph;     
-	u_int rtc;
-
-	ph = OF_finddevice("rtc");     
-	if (ph == -1)     
-		return (ENOENT);
-
-	OF_package_to_path(ph, path, sizeof(path));                   
-	ih = OF_open(path);
-	if (ih == -1)
-		return (ENXIO);
-
-	rtc = ts->tv_sec + DIFF19041970;
-	return ((OF_call_method("write-rtc", ih, 1, 0, rtc) != 0) ? EIO : 0);
-}
diff --git a/sys/powerpc/powermac/cuda.c b/sys/powerpc/powermac/cuda.c
index 203889c5675..230298e35c4 100644
--- a/sys/powerpc/powermac/cuda.c
+++ b/sys/powerpc/powermac/cuda.c
@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -55,6 +56,7 @@ __FBSDID("$FreeBSD$");
 
 #include 
 
+#include "clock_if.h"
 #include "cudavar.h"
 #include "viareg.h"
 
@@ -72,6 +74,12 @@ static u_int	cuda_poll(device_t dev);
 static void	cuda_send_inbound(struct cuda_softc *sc);
 static void	cuda_send_outbound(struct cuda_softc *sc);
 
+/*
+ * Clock interface
+ */
+static int cuda_gettime(device_t dev, struct timespec *ts);
+static int cuda_settime(device_t dev, struct timespec *ts);
+
 static device_method_t  cuda_methods[] = {
 	/* Device interface */
 	DEVMETHOD(device_probe,		cuda_probe),
@@ -90,6 +98,10 @@ static device_method_t  cuda_methods[] = {
 	DEVMETHOD(adb_hb_controller_poll,	cuda_poll),
 	DEVMETHOD(adb_hb_set_autopoll_mask,	cuda_adb_autopoll),
 
+	/* Clock interface */
+	DEVMETHOD(clock_gettime,	cuda_gettime),
+	DEVMETHOD(clock_settime,	cuda_settime),
+
 	{ 0, 0 },
 };
 
@@ -173,6 +185,7 @@ cuda_attach(device_t dev)
 	sc->sc_polling = 0;
 	sc->sc_state = CUDA_NOTREADY;
 	sc->sc_autopoll = 0;
+	sc->sc_rtc = -1;
 
 	STAILQ_INIT(&sc->sc_inq);
 	STAILQ_INIT(&sc->sc_outq);
@@ -236,6 +249,8 @@ cuda_attach(device_t dev)
 		}
 	}
 
+	clock_register(dev, 1000);
+
 	return (bus_generic_attach(dev));
 }
 
@@ -444,8 +459,18 @@ cuda_send_inbound(struct cuda_softc *sc)
 			break;
 		   case CUDA_PSEUDO:
 			mtx_lock(&sc->sc_mutex);
-			if (pkt->data[0] == CMD_AUTOPOLL)
+			switch (pkt->data[1]) {
+			case CMD_AUTOPOLL:
 				sc->sc_autopoll = 1;
+				break;
+			case CMD_READ_RTC:
+				memcpy(&sc->sc_rtc, &pkt->data[2],
+				    sizeof(sc->sc_rtc));
+				wakeup(&sc->sc_rtc);
+				break;
+			case CMD_WRITE_RTC:
+				break;
+			}
 			mtx_unlock(&sc->sc_mutex);
 			break;
 		   case CUDA_ERROR:
@@ -715,3 +740,41 @@ cuda_adb_autopoll(device_t dev, uint16_t mask) {
 	return (0);
 }
 
+#define DIFF19041970	2082844800
+
+static int
+cuda_gettime(device_t dev, struct timespec *ts)
+{
+	struct cuda_softc *sc = device_get_softc(dev);
+	uint8_t cmd[] = {CUDA_PSEUDO, CMD_READ_RTC};
+
+	mtx_lock(&sc->sc_mutex);
+	sc->sc_rtc = -1;
+	cuda_send(sc, 1, 2, cmd);
+	if (sc->sc_rtc == -1)
+		mtx_sleep(&sc->sc_rtc, &sc->sc_mutex, 0, "rtc", 100);
+
+	ts->tv_sec = sc->sc_rtc - DIFF19041970;
+	ts->tv_nsec = 0;
+	mtx_unlock(&sc->sc_mutex);
+
+	return (0);
+}
+
+static int
+cuda_settime(device_t dev, struct timespec *ts)
+{
+	struct cuda_softc *sc = device_get_softc(dev);
+	uint8_t cmd[] = {CUDA_PSEUDO, CMD_WRITE_RTC, 0, 0, 0, 0};
+	uint32_t sec;
+
+	sec = ts->tv_sec + DIFF19041970;
+	memcpy(&cmd[2], &sec, sizeof(sec));
+
+	mtx_lock(&sc->sc_mutex);
+	cuda_send(sc, 0, 6, cmd);
+	mtx_unlock(&sc->sc_mutex);
+
+	return (0);
+}
+
diff --git a/sys/powerpc/powermac/cudavar.h b/sys/powerpc/powermac/cudavar.h
index 02791cb08ed..225446494cd 100644
--- a/sys/powerpc/powermac/cudavar.h
+++ b/sys/powerpc/powermac/cudavar.h
@@ -90,6 +90,7 @@ struct cuda_softc {
 	int		sc_polling;
 	int		sc_iic_done;
 	volatile int	sc_autopoll;
+	uint32_t	sc_rtc;
 
 	int sc_i2c_read_len;
 
diff --git a/sys/powerpc/powermac/pmu.c b/sys/powerpc/powermac/pmu.c
index 9ddba9e055f..a980622e0d1 100644
--- a/sys/powerpc/powermac/pmu.c
+++ b/sys/powerpc/powermac/pmu.c
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -55,16 +56,27 @@ __FBSDID("$FreeBSD$");
 
 #include 
 
+#include "clock_if.h"
 #include "pmuvar.h"
 #include "viareg.h"
 
 /*
- * MacIO interface
+ * Bus interface
  */
 static int	pmu_probe(device_t);
 static int	pmu_attach(device_t);
 static int	pmu_detach(device_t);
 
+/*
+ * Clock interface
+ */
+static int	pmu_gettime(device_t dev, struct timespec *ts);
+static int	pmu_settime(device_t dev, struct timespec *ts);
+
+/*
+ * ADB Interface
+ */
+
 static u_int	pmu_adb_send(device_t dev, u_char command_byte, int len, 
 		    u_char *data, u_char poll);
 static u_int	pmu_adb_autopoll(device_t dev, uint16_t mask);
@@ -110,6 +122,10 @@ static device_method_t  pmu_methods[] = {
 	DEVMETHOD(adb_hb_controller_poll,   pmu_poll),
 	DEVMETHOD(adb_hb_set_autopoll_mask, pmu_adb_autopoll),
 
+	/* Clock interface */
+	DEVMETHOD(clock_gettime,	pmu_gettime),
+	DEVMETHOD(clock_settime,	pmu_settime),
+
 	{ 0, 0 },
 };
 
@@ -453,6 +469,12 @@ pmu_attach(device_t dev)
 
 	sc->sc_leddev = led_create(pmu_set_sleepled, sc, "sleepled");
 
+	/*
+	 * Register RTC
+	 */
+
+	clock_register(dev, 1000);
+
 	return (bus_generic_attach(dev));
 }
 
@@ -926,3 +948,38 @@ pmu_battquery_sysctl(SYSCTL_HANDLER_ARGS)
 	return (error);
 }
 
+#define DIFF19041970	2082844800
+
+static int
+pmu_gettime(device_t dev, struct timespec *ts)
+{
+	struct pmu_softc *sc = device_get_softc(dev);
+	uint8_t resp[16];
+	uint32_t sec;
+
+	mtx_lock(&sc->sc_mutex);
+	pmu_send(sc, PMU_READ_RTC, 0, NULL, 16, resp);
+	mtx_unlock(&sc->sc_mutex);
+
+	memcpy(&sec, &resp[1], 4);
+	ts->tv_sec = sec - DIFF19041970;
+	ts->tv_nsec = 0;
+
+	return (0);
+}
+
+static int
+pmu_settime(device_t dev, struct timespec *ts)
+{
+	struct pmu_softc *sc = device_get_softc(dev);
+	uint32_t sec;
+
+	sec = ts->tv_sec + DIFF19041970;
+
+	mtx_lock(&sc->sc_mutex);
+	pmu_send(sc, PMU_SET_RTC, sizeof(sec), (uint8_t *)&sec, 0, NULL);
+	mtx_unlock(&sc->sc_mutex);
+
+	return (0);
+}
+
diff --git a/sys/powerpc/powermac/smu.c b/sys/powerpc/powermac/smu.c
index 6754b3ba7d1..10018767881 100644
--- a/sys/powerpc/powermac/smu.c
+++ b/sys/powerpc/powermac/smu.c
@@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -51,6 +52,8 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
+#include "clock_if.h"
+
 struct smu_cmd {
 	volatile uint8_t cmd;
 	uint8_t		len;
@@ -140,6 +143,10 @@ static int	smu_attach(device_t);
 static void	smu_cpufreq_pre_change(device_t, const struct cf_level *level);
 static void	smu_cpufreq_post_change(device_t, const struct cf_level *level);
 
+/* clock interface */
+static int	smu_gettime(device_t dev, struct timespec *ts);
+static int	smu_settime(device_t dev, struct timespec *ts);
+
 /* utility functions */
 static int	smu_run_cmd(device_t dev, struct smu_cmd *cmd, int wait);
 static int	smu_get_datablock(device_t dev, int8_t id, uint8_t *buf,
@@ -160,6 +167,10 @@ static device_method_t  smu_methods[] = {
 	/* Device interface */
 	DEVMETHOD(device_probe,		smu_probe),
 	DEVMETHOD(device_attach,	smu_attach),
+
+	/* Clock interface */
+	DEVMETHOD(clock_gettime,	smu_gettime),
+	DEVMETHOD(clock_settime,	smu_settime),
 	{ 0, 0 },
 };
 
@@ -192,6 +203,9 @@ MALLOC_DEFINE(M_SMU, "smu", "SMU Sensor Information");
 #define  SMU_PWR_GET_POWERUP	0x00
 #define  SMU_PWR_SET_POWERUP	0x01
 #define  SMU_PWR_CLR_POWERUP	0x02
+#define SMU_RTC			0x8e
+#define  SMU_RTC_GET		0x81
+#define  SMU_RTC_SET		0x80
 
 /* Power event types */
 #define SMU_WAKEUP_KEYPRESS	0x01
@@ -349,6 +363,11 @@ smu_attach(device_t dev)
 	powerpc_config_intr(rman_get_start(sc->sc_doorbellirq),
 	    INTR_TRIGGER_EDGE, INTR_POLARITY_LOW);
 
+	/*
+	 * Connect RTC interface.
+	 */
+	clock_register(dev, 1000);
+
 	return (0);
 }
 
@@ -1043,3 +1062,51 @@ smu_server_mode(SYSCTL_HANDLER_ARGS)
 	return (smu_run_cmd(smu, &cmd, 1));
 }
 
+static int
+smu_gettime(device_t dev, struct timespec *ts)
+{
+	struct smu_cmd cmd;
+	struct clocktime ct;
+
+	cmd.cmd = SMU_RTC;
+	cmd.len = 1;
+	cmd.data[0] = SMU_RTC_GET;
+
+	if (smu_run_cmd(dev, &cmd, 1) != 0)
+		return (ENXIO);
+
+	ct.nsec	= 0;
+	ct.sec	= bcd2bin(cmd.data[0]);
+	ct.min	= bcd2bin(cmd.data[1]);
+	ct.hour	= bcd2bin(cmd.data[2]);
+	ct.dow	= bcd2bin(cmd.data[3]);
+	ct.day	= bcd2bin(cmd.data[4]);
+	ct.mon	= bcd2bin(cmd.data[5]);
+	ct.year	= bcd2bin(cmd.data[6]) + 2000;
+
+	return (clock_ct_to_ts(&ct, ts));
+}
+
+static int
+smu_settime(device_t dev, struct timespec *ts)
+{
+	struct smu_cmd cmd;
+	struct clocktime ct;
+
+	cmd.cmd = SMU_RTC;
+	cmd.len = 8;
+	cmd.data[0] = SMU_RTC_SET;
+
+	clock_ts_to_ct(ts, &ct);
+
+	cmd.data[1] = bin2bcd(ct.sec);
+	cmd.data[2] = bin2bcd(ct.min);
+	cmd.data[3] = bin2bcd(ct.hour);
+	cmd.data[4] = bin2bcd(ct.dow);
+	cmd.data[5] = bin2bcd(ct.day);
+	cmd.data[6] = bin2bcd(ct.mon);
+	cmd.data[7] = bin2bcd(ct.year - 2000);
+
+	return (smu_run_cmd(dev, &cmd, 1));
+}
+

From 42492c2c044de52322b3860fbb0de7ffdcfe85ec Mon Sep 17 00:00:00 2001
From: Joerg Wunsch 
Date: Tue, 23 Mar 2010 06:19:44 +0000
Subject: [PATCH 013/119] Add .snap to daily_clean_tmps_ignore; /tmp/.snap ist
 not supposed to be auto-removed (and /tmp is a filesystem of its own now by
 default).

MFC after:	3 days
---
 etc/defaults/periodic.conf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/etc/defaults/periodic.conf b/etc/defaults/periodic.conf
index b45483894af..de315aeb13e 100644
--- a/etc/defaults/periodic.conf
+++ b/etc/defaults/periodic.conf
@@ -46,7 +46,7 @@ daily_clean_tmps_enable="NO"				# Delete stuff daily
 daily_clean_tmps_dirs="/tmp"				# Delete under here
 daily_clean_tmps_days="3"				# If not accessed for
 daily_clean_tmps_ignore=".X*-lock .X11-unix .ICE-unix .font-unix .XIM-unix"
-daily_clean_tmps_ignore="$daily_clean_tmps_ignore quota.user quota.group"
+daily_clean_tmps_ignore="$daily_clean_tmps_ignore quota.user quota.group .snap"
 							# Don't delete these
 daily_clean_tmps_verbose="YES"				# Mention files deleted
 

From ed11e09daf6d66dec3fdbf511b7ab98b67e8406e Mon Sep 17 00:00:00 2001
From: Rui Paulo 
Date: Tue, 23 Mar 2010 11:33:08 +0000
Subject: [PATCH 014/119] Finish the much belated Intel XScale hwpmc(4) man
 page.

---
 lib/libpmc/pmc.xscale.3 | 121 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 119 insertions(+), 2 deletions(-)

diff --git a/lib/libpmc/pmc.xscale.3 b/lib/libpmc/pmc.xscale.3
index fc9d16ee430..3cb64c36cfb 100644
--- a/lib/libpmc/pmc.xscale.3
+++ b/lib/libpmc/pmc.xscale.3
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2009 Rui Paulo.  All rights reserved.
+.\" Copyright (c) 2009, 2010 Rui Paulo.  All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
 .\" modification, are permitted provided that the following conditions
@@ -9,7 +9,7 @@
 .\"    notice, this list of conditions and the following disclaimer in the
 .\"    documentation and/or other materials provided with the distribution.
 .\"
-.\" This software is provided by Joseph Koshy ``as is'' and
+.\" This software is provided by Rui Paulo ``as is'' and
 .\" any express or implied warranties, including, but not limited to, the
 .\" implied warranties of merchantability and fitness for a particular purpose
 .\" are disclaimed.  in no event shall Joseph Koshy be liable
@@ -37,3 +37,120 @@ family CPUs
 .Sh SYNOPSIS
 .In pmc.h
 .Sh DESCRIPTION
+.Tn Intel XScale
+CPUs are ARM CPUs based on the ARMv5e core.
+.Pp
+Second generation cores have 2 counters, while third generation cores
+have 4 counters.
+Third generation cores also have an increased number of PMC events.
+.Pp
+.Tn Intel XScale
+PMCs are documented in 
+.Rs
+.%B "3rd Generation Intel XScale Microarchitecture Developer's Manual"
+.%D May 2007
+.Re
+.Ss Event Specifiers (Programmable PMCs)
+.Tn Intel XScale
+programmable PMCs support the following events:
+.Bl -tag -width indent
+.It Li IC_FETCH
+External memory fetch due to L1 instruction cache miss.
+.It Li IC_MISS
+Instruction cache or TLB miss.
+.It Li DATA_DEPENDENCY_STALLED
+A data dependency stalled
+.It Li ITLB_MISS
+Instruction TLB miss.
+.It Li DTLB_MISS
+Data TLB miss.
+.It Li BRANCH_RETIRED
+Branch instruction retired (executed).
+.It Li BRANCH_MISPRED
+Branch mispredicted.
+.It Li INSTR_RETIRED
+Instructions retired (executed).
+.It Li DC_FULL_CYCLE
+L1 data cache buffer full stall.
+Event occurs on every cycle the
+condition is present.
+.It Li DC_FULL_CONTIG
+L1 data cache buffer full stall.
+Event occurs once for each contiguous sequence of this type of stall.
+.It Li DC_ACCESS
+L1 data cache access, not including cache operations.
+.It Li DC_MISS
+L1 data cache miss, not including cache operations.
+.It Li DC_WRITEBACK
+L1 data cache write-back.
+Occurs for each cache line that's written back from the cache.
+.It Li PC_CHANGE
+Software changed the program counter.
+.It Li BRANCH_RETIRED_ALL
+Branch instruction retired (executed).
+This event counts all branch instructions, indirect or direct.
+.It Li INSTR_CYCLE
+Count the number of microarchitecture cycles each instruction requires
+to issue.
+.It Li CP_STALL
+Coprocessor stalled the instruction pipeline.
+.It Li PC_CHANGE_ALL
+Software changed the program counter (includes exceptions).
+.It Li PIPELINE_FLUSH
+Pipeline flushes due to mispredictions or exceptions.
+.It Li BACKEND_STALL
+Backend stalled the instruction pipeline.
+.It Li MULTIPLIER_USE
+Multiplier used.
+.It Li MULTIPLIER_STALLED
+Multiplier stalled the instruction pipeline.
+.It Li DATA_CACHE_STALLED
+Data cache stalled the instruction pipeline.
+.It Li L2_CACHE_REQ
+L2 cache request, not inclusing cache operations.
+.It Li L2_CACHE_MISS
+L2 cache miss, not including cache operations.
+.It Li ADDRESS_BUS_TRANS
+Address bus transaction.
+.It Li SELF_ADDRESS_BUS_TRANS
+Self initiated address bus transaction.
+.It Li DATA_BUS_TRANS
+Data bus transaction.
+.El
+.Ss Event Name Aliases  
+The following table shows the mapping between the PMC-independent
+aliases supported by
+.Lb libpmc
+and the underlying hardware events used.
+.Bl -column "branch-mispredicts" "BRANCH_MISPRED"
+.It Em Alias Ta Em Event Ta
+.It Li branches Ta Li BRANCH_RETIRED Ta
+.It Li branch-mispredicts Ta Li BRANCH_MISPRED Ta
+.It Li dc-misses Ta Li DC_MISS Ta
+.It Li ic-misses Ta Li IC_MISS Ta
+.It Li instructions Ta Li INSTR_RETIRED Ta
+.El
+.Sh SEE ALSO
+.Xr pmc 3 ,
+.Xr pmc_cpuinfo 3 ,
+.Xr pmclog 3 ,
+.Xr hwpmc 4
+.Sh CAVEATS
+The Intel XScale code does not yet support sampling.
+.Sh HISTORY
+The
+.Nm pmc
+library first appeared in
+.Fx 6.0 .
+Intel XScale support first appeared in
+.Fx 9.0 .
+.Sh AUTHORS
+The
+.Lb libpmc
+library was written by
+.An "Joseph Koshy"
+.Aq jkoshy@FreeBSD.org .
+.Pp
+Intel XScale support was added by
+.An "Rui Paulo"
+.Aq rpaulo@FreeBSD.org .

From e1d36f83953d08d81b1032c540a9432c6cea094c Mon Sep 17 00:00:00 2001
From: Rui Paulo 
Date: Tue, 23 Mar 2010 12:03:09 +0000
Subject: [PATCH 015/119] Add a new field for extended HT capabilities.

Submitted by:	Alexander Egorenkov 
MFC after:	2 weeks
Sponsored by:	iXsystems, inc.
---
 sys/net80211/ieee80211.c     |  1 +
 sys/net80211/ieee80211_ht.c  | 13 +++++++++++--
 sys/net80211/ieee80211_var.h |  5 ++++-
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/sys/net80211/ieee80211.c b/sys/net80211/ieee80211.c
index f72e10b8414..8a50bc02076 100644
--- a/sys/net80211/ieee80211.c
+++ b/sys/net80211/ieee80211.c
@@ -404,6 +404,7 @@ ieee80211_vap_setup(struct ieee80211com *ic, struct ieee80211vap *vap,
 	vap->iv_flags_ven = ic->ic_flags_ven;
 	vap->iv_caps = ic->ic_caps &~ IEEE80211_C_OPMODE;
 	vap->iv_htcaps = ic->ic_htcaps;
+	vap->iv_htextcaps = ic->ic_htextcaps;
 	vap->iv_opmode = opmode;
 	vap->iv_caps |= ieee80211_opcap[opmode];
 	switch (opmode) {
diff --git a/sys/net80211/ieee80211_ht.c b/sys/net80211/ieee80211_ht.c
index 4dbe9179437..2d44816a540 100644
--- a/sys/net80211/ieee80211_ht.c
+++ b/sys/net80211/ieee80211_ht.c
@@ -2346,7 +2346,7 @@ ieee80211_add_htcap_body(uint8_t *frm, struct ieee80211_node *ni)
 	frm += 2;				\
 } while (0)
 	struct ieee80211vap *vap = ni->ni_vap;
-	uint16_t caps;
+	uint16_t caps, extcaps;
 	int rxmax, density;
 
 	/* HT capabilities */
@@ -2404,8 +2404,17 @@ ieee80211_add_htcap_body(uint8_t *frm, struct ieee80211_node *ni)
 	 */
 	ieee80211_set_htrates(frm, &ieee80211_rateset_11n);
 
-	frm += sizeof(struct ieee80211_ie_htcap) -
+	frm += __offsetof(struct ieee80211_ie_htcap, hc_extcap) -
 		__offsetof(struct ieee80211_ie_htcap, hc_mcsset);
+
+	/* HT extended capabilities */
+	extcaps = vap->iv_htextcaps & 0xffff;
+
+	ADDSHORT(frm, extcaps);
+
+	frm += sizeof(struct ieee80211_ie_htcap) -
+		__offsetof(struct ieee80211_ie_htcap, hc_txbf);
+
 	return frm;
 #undef ADDSHORT
 }
diff --git a/sys/net80211/ieee80211_var.h b/sys/net80211/ieee80211_var.h
index d6f3e6669ec..3916b6c0579 100644
--- a/sys/net80211/ieee80211_var.h
+++ b/sys/net80211/ieee80211_var.h
@@ -137,6 +137,7 @@ struct ieee80211com {
 	uint32_t		ic_flags_ven;	/* vendor state flags */
 	uint32_t		ic_caps;	/* capabilities */
 	uint32_t		ic_htcaps;	/* HT capabilities */
+	uint32_t		ic_htextcaps;	/* HT extended capabilities */
 	uint32_t		ic_cryptocaps;	/* crypto capabilities */
 	uint8_t			ic_modecaps[2];	/* set of mode capabilities */
 	uint8_t			ic_promisc;	/* vap's needing promisc mode */
@@ -313,7 +314,8 @@ struct ieee80211com {
 				    int batimeout, int baseqctl);
 	void			(*ic_ampdu_rx_stop)(struct ieee80211_node *,
 				    struct ieee80211_rx_ampdu *);
-	uint64_t		ic_spare[8];
+	uint64_t		ic_spare[7];
+	uint32_t		ic_spare2;
 };
 
 struct ieee80211_aclator;
@@ -340,6 +342,7 @@ struct ieee80211vap {
 	uint32_t		iv_flags_ven;	/* vendor state flags */
 	uint32_t		iv_caps;	/* capabilities */
 	uint32_t		iv_htcaps;	/* HT capabilities */
+	uint32_t		iv_htextcaps;	/* HT extended capabilities */
 	enum ieee80211_opmode	iv_opmode;	/* operation mode */
 	enum ieee80211_state	iv_state;	/* state machine state */
 	enum ieee80211_state	iv_nstate;	/* pending state */

From 59f6c520f0cac78ff902a4a38b4c7e69c68232bf Mon Sep 17 00:00:00 2001
From: Rui Paulo 
Date: Tue, 23 Mar 2010 12:05:25 +0000
Subject: [PATCH 016/119] Add a missing LINE_BREAK() after printing the roaming
 parameters in verbose mode.

Sponsored by:	iXsystems, inc.
MFC after:	2 weeks
---
 sbin/ifconfig/ifieee80211.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sbin/ifconfig/ifieee80211.c b/sbin/ifconfig/ifieee80211.c
index 07092429b6a..6cb4d2c7ac6 100644
--- a/sbin/ifconfig/ifieee80211.c
+++ b/sbin/ifconfig/ifieee80211.c
@@ -4509,6 +4509,7 @@ end:
 		} else {
 			LINE_BREAK();
 			list_roam(s);
+			LINE_BREAK();
 		}
 	}
 

From 59fe4a8ce650ccf2ce2e0f7f81627c2478848672 Mon Sep 17 00:00:00 2001
From: Rui Paulo 
Date: Tue, 23 Mar 2010 13:15:11 +0000
Subject: [PATCH 017/119] Add MCS to the list of media types.

Sponsored by:	iXsystems, inc.
---
 sys/net/if_media.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/net/if_media.h b/sys/net/if_media.h
index 1db27666e21..c93739276d2 100644
--- a/sys/net/if_media.h
+++ b/sys/net/if_media.h
@@ -462,6 +462,7 @@ struct ifmedia_description {
 	{ IFM_IEEE80211_OFDM3, "OFDM/3Mbps" },				\
 	{ IFM_IEEE80211_OFDM4, "OFDM/4.5Mbps" },			\
 	{ IFM_IEEE80211_OFDM27, "OFDM/27Mbps" },			\
+	{ IFM_IEEE80211_MCS, "MCS" },					\
 	{ 0, NULL },							\
 }
 
@@ -500,6 +501,7 @@ struct ifmedia_description {
 	{ IFM_IEEE80211_OFDM3, "OFDM3" },				\
 	{ IFM_IEEE80211_OFDM4, "OFDM4.5" },				\
 	{ IFM_IEEE80211_OFDM27, "OFDM27" },				\
+	{ IFM_IEEE80211_MCS, "MCS" },					\
 	{ 0, NULL },							\
 }
 

From 323f12abbc028e5fe63fba818cecae6130447fa8 Mon Sep 17 00:00:00 2001
From: Rui Paulo 
Date: Tue, 23 Mar 2010 14:31:31 +0000
Subject: [PATCH 018/119] When receiving a management frame, pass the mbuf to
 bpf before calling iv_recv_mgmt(). iv_recv_mgmt() will generate management
 frame responses and pass them to bpf before the management frame that
 triggered the response.

PR:		144323
Submitted by:	Alexander Egorenkov 
MFC after:	2 weeks
Sponsored by:	iXsystems, inc.
---
 sys/net80211/ieee80211_hostap.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sys/net80211/ieee80211_hostap.c b/sys/net80211/ieee80211_hostap.c
index 8405b4f646b..9f1d3b53974 100644
--- a/sys/net80211/ieee80211_hostap.c
+++ b/sys/net80211/ieee80211_hostap.c
@@ -883,6 +883,9 @@ hostap_input(struct ieee80211_node *ni, struct mbuf *m, int rssi, int nf)
 			wh = mtod(m, struct ieee80211_frame *);
 			wh->i_fc[1] &= ~IEEE80211_FC1_WEP;
 		}
+		if (ieee80211_radiotap_active_vap(vap))
+			ieee80211_radiotap_rx(vap, m);
+		need_tap = 0;
 		vap->iv_recv_mgmt(ni, m, subtype, rssi, nf);
 		goto out;
 

From 67b9e2551d10697ab7d0698f22b0b9566e5600c1 Mon Sep 17 00:00:00 2001
From: Xin LI 
Date: Tue, 23 Mar 2010 18:00:50 +0000
Subject: [PATCH 019/119] Correct cross reference.

MFC after:	2 weeks
---
 share/man/man3/pthread_affinity_np.3 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/share/man/man3/pthread_affinity_np.3 b/share/man/man3/pthread_affinity_np.3
index a04ba97b483..95128c8ebd5 100644
--- a/share/man/man3/pthread_affinity_np.3
+++ b/share/man/man3/pthread_affinity_np.3
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd January 12, 2010
+.Dd March 23, 2010
 .Dt PTHREAD_AFFINITY_NP 3
 .Os
 .Sh NAME
@@ -125,8 +125,8 @@ operation.
 .Xr cpuset_setid 2 ,
 .Xr CPU_SET 3 ,
 .Xr pthread 3 ,
-.Xr pthread_attr_get_affinity_np 3 ,
-.Xr pthread_attr_set_affinity_np 3
+.Xr pthread_attr_getaffinity_np 3 ,
+.Xr pthread_attr_setaffinity_np 3
 .Sh STANDARDS
 The
 .Nm pthread_getaffinity_np

From 33d56ab39b0c56803f89521c771faf7bdab52572 Mon Sep 17 00:00:00 2001
From: Marcel Moolenaar 
Date: Tue, 23 Mar 2010 19:30:56 +0000
Subject: [PATCH 020/119] Enable power management for E500 cores. Use "doze"
 for now to make sure the caches remain coherent. For single-core
 configurations and with busdma changes we could eventually switch to "nap"
 and force a D-cache invalidation as part of the DMA completion. To this end,
 clear PSL_WE until after we handled the decrementer or external interrupt as
 it tells us whether we just woke up or not.

---
 sys/powerpc/booke/interrupt.c |  2 ++
 sys/powerpc/booke/machdep.c   | 16 ++++------------
 sys/powerpc/powerpc/cpu.c     |  7 +++++++
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/sys/powerpc/booke/interrupt.c b/sys/powerpc/booke/interrupt.c
index 2367bf94b33..91ceeb7bf1d 100644
--- a/sys/powerpc/booke/interrupt.c
+++ b/sys/powerpc/booke/interrupt.c
@@ -123,6 +123,7 @@ powerpc_decr_interrupt(struct trapframe *framep)
 	decr_intr(framep);
 	atomic_subtract_int(&td->td_intr_nesting_level, 1);
 	critical_exit();
+	framep->srr1 &= ~PSL_WE;
 }
 
 /*
@@ -135,4 +136,5 @@ powerpc_extr_interrupt(struct trapframe *framep)
 	critical_enter();
 	PIC_DISPATCH(pic, framep);
 	critical_exit();
+	framep->srr1 &= ~PSL_WE;
 }
diff --git a/sys/powerpc/booke/machdep.c b/sys/powerpc/booke/machdep.c
index d2e25e79ded..e9a0099497c 100644
--- a/sys/powerpc/booke/machdep.c
+++ b/sys/powerpc/booke/machdep.c
@@ -706,6 +706,7 @@ cpu_idle (int busy)
 	register_t msr;
 
 	msr = mfmsr();
+
 #ifdef INVARIANTS
 	if ((msr & PSL_EE) != PSL_EE) {
 		struct thread *td = curthread;
@@ -713,19 +714,10 @@ cpu_idle (int busy)
 		panic("ints disabled in idleproc!");
 	}
 #endif
-#if 0
-	/*
-	 * Freescale E500 core RM section 6.4.1
-	 */
-	msr = msr | PSL_WE;
 
-	__asm__("	msync;"
-		"	mtmsr	%0;"
-		"	isync;"
-		"loop:	b	loop" :
-		/* no output */	:
-		"r" (msr));
-#endif
+	/* Freescale E500 core RM section 6.4.1. */
+	msr = msr | PSL_WE;
+	__asm __volatile("msync; mtmsr %0; isync" :: "r" (msr));
 }
 
 int
diff --git a/sys/powerpc/powerpc/cpu.c b/sys/powerpc/powerpc/cpu.c
index d02c15687fc..555172a5e33 100644
--- a/sys/powerpc/powerpc/cpu.c
+++ b/sys/powerpc/powerpc/cpu.c
@@ -433,6 +433,13 @@ cpu_e500_setup(int cpuid, uint16_t vers)
 	register_t hid0;
 
 	hid0 = mfspr(SPR_HID0);
+
+	/* Programe power-management mode. */
+	hid0 &= ~(HID0_DOZE | HID0_NAP | HID0_SLEEP);
+	hid0 |= HID0_DOZE;
+
+	mtspr(SPR_HID0, hid0);
+
 	printf("cpu%d: HID0 %b\n", cpuid, (int)hid0, HID0_E500_BITMASK);
 }
 

From 1fc13a00e8ebd55aace2536a7495b980e6481539 Mon Sep 17 00:00:00 2001
From: Xin LI 
Date: Tue, 23 Mar 2010 20:08:18 +0000
Subject: [PATCH 021/119] Add PCI ID for MCS9901's parallel port.

PR:		kern/144713
Submitted by:	gcooper
MFC after:	2 weeks
---
 sys/dev/ppc/ppc_pci.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sys/dev/ppc/ppc_pci.c b/sys/dev/ppc/ppc_pci.c
index c8e40b56377..ed59413ee9c 100644
--- a/sys/dev/ppc/ppc_pci.c
+++ b/sys/dev/ppc/ppc_pci.c
@@ -89,6 +89,7 @@ static struct pci_id pci_ids[] = {
 	{ 0x84031415, "Oxford Semiconductor OX12PCI840 Parallel port", 0x10 },
 	{ 0x95131415, "Oxford Semiconductor OX16PCI954 Parallel port", 0x10 },
 	{ 0x98059710, "NetMos NM9805 1284 Printer port", 0x10 },
+	{ 0x99019710, "MosChip MCS9901 PCIe to Peripheral Controller", 0x10 },
 	{ 0xffff }
 };
 

From e4ee16b41e570b89450965e9f6e60d9b04124b83 Mon Sep 17 00:00:00 2001
From: Marcel Moolenaar 
Date: Tue, 23 Mar 2010 20:12:53 +0000
Subject: [PATCH 022/119] Add definitions for a 4th PCI host controller. No
 Freescale processor has all 4 implemented, but across the processors we now
 support all the combinations. For example, the MPC8533 doesn't have a PCI
 controller at 0xA0000, but does at 0xB0000.

---
 sys/powerpc/mpc85xx/ocpbus.c | 15 ++++++++++++++-
 sys/powerpc/mpc85xx/ocpbus.h |  2 ++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/sys/powerpc/mpc85xx/ocpbus.c b/sys/powerpc/mpc85xx/ocpbus.c
index 2adec47b25b..6c6515e4be6 100644
--- a/sys/powerpc/mpc85xx/ocpbus.c
+++ b/sys/powerpc/mpc85xx/ocpbus.c
@@ -152,6 +152,10 @@ ocpbus_write_law(int trgt, int type, u_long *startp, u_long *countp)
 			addr = 0xA0000000;
 			size = 0x10000000;
 			break;
+		case OCP85XX_TGTIF_PCI3:
+			addr = 0xB0000000;
+			size = 0x10000000;
+			break;
 		default:
 			return (EINVAL);
 		}
@@ -170,6 +174,10 @@ ocpbus_write_law(int trgt, int type, u_long *startp, u_long *countp)
 			addr = 0xfee20000;
 			size = 0x00010000;
 			break;
+		case OCP85XX_TGTIF_PCI3:
+			addr = 0xfee30000;
+			size = 0x00010000;
+			break;
 		default:
 			return (EINVAL);
 		}
@@ -188,7 +196,7 @@ static int
 ocpbus_probe(device_t dev)
 {
 
-	device_set_desc(dev, "On-Chip Peripherals bus");
+	device_set_desc(dev, "Freescale on-chip peripherals bus");
 	return (BUS_PROBE_DEFAULT);
 }
 
@@ -210,6 +218,7 @@ ocpbus_attach(device_t dev)
 	ocpbus_mk_child(dev, OCPBUS_DEVTYPE_PCIB, 0);
 	ocpbus_mk_child(dev, OCPBUS_DEVTYPE_PCIB, 1);
 	ocpbus_mk_child(dev, OCPBUS_DEVTYPE_PCIB, 2);
+	ocpbus_mk_child(dev, OCPBUS_DEVTYPE_PCIB, 3);
 	ocpbus_mk_child(dev, OCPBUS_DEVTYPE_TSEC, 0);
 	ocpbus_mk_child(dev, OCPBUS_DEVTYPE_TSEC, 1);
 	ocpbus_mk_child(dev, OCPBUS_DEVTYPE_TSEC, 2);
@@ -338,6 +347,10 @@ const struct ocp_resource mpc8555_resources[] = {
 	    OCP85XX_PCI_SIZE},
 	{OCPBUS_DEVTYPE_PCIB, 2, SYS_RES_MEMORY, 1, 0, OCP85XX_TGTIF_PCI2},
 	{OCPBUS_DEVTYPE_PCIB, 2, SYS_RES_IOPORT, 1, 0, OCP85XX_TGTIF_PCI2},
+	{OCPBUS_DEVTYPE_PCIB, 3, SYS_RES_MEMORY, 0, OCP85XX_PCI3_OFF,
+	    OCP85XX_PCI_SIZE},
+	{OCPBUS_DEVTYPE_PCIB, 3, SYS_RES_MEMORY, 1, 0, OCP85XX_TGTIF_PCI3},
+	{OCPBUS_DEVTYPE_PCIB, 3, SYS_RES_IOPORT, 1, 0, OCP85XX_TGTIF_PCI3},
 
 	{OCPBUS_DEVTYPE_LBC, 0, SYS_RES_MEMORY, 0, OCP85XX_LBC_OFF,
 	    OCP85XX_LBC_SIZE},
diff --git a/sys/powerpc/mpc85xx/ocpbus.h b/sys/powerpc/mpc85xx/ocpbus.h
index 6aa6de3b063..fb715da5af1 100644
--- a/sys/powerpc/mpc85xx/ocpbus.h
+++ b/sys/powerpc/mpc85xx/ocpbus.h
@@ -50,6 +50,7 @@
 #define	OCP85XX_TGTIF_PCI0	0
 #define	OCP85XX_TGTIF_PCI1	1
 #define	OCP85XX_TGTIF_PCI2	2
+#define	OCP85XX_TGTIF_PCI3	3
 #define	OCP85XX_TGTIF_LBC	4
 #define	OCP85XX_TGTIF_RAM_INTL	11
 #define	OCP85XX_TGTIF_RIO	12
@@ -86,6 +87,7 @@
 #define	OCP85XX_PCI0_OFF	0x08000
 #define	OCP85XX_PCI1_OFF	0x09000
 #define	OCP85XX_PCI2_OFF	0x0A000
+#define	OCP85XX_PCI3_OFF	0x0B000
 #define	OCP85XX_PCI_SIZE	0x1000
 #define	OCP85XX_TSEC0_OFF	0x24000
 #define	OCP85XX_TSEC1_OFF	0x25000

From 5711bf30daa21bd07829f094ea4110ea301b6721 Mon Sep 17 00:00:00 2001
From: John Baldwin 
Date: Tue, 23 Mar 2010 21:08:07 +0000
Subject: [PATCH 023/119] Reject attempts to create a MAP_ANON mapping with a
 non-zero offset.

PR:		kern/71258
Submitted by:	Alexander Best
MFC after:	2 weeks
---
 lib/libc/sys/mmap.2 | 7 ++++++-
 sys/vm/vm_mmap.c    | 3 +--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/libc/sys/mmap.2 b/lib/libc/sys/mmap.2
index 48499731b58..b633cb11942 100644
--- a/lib/libc/sys/mmap.2
+++ b/lib/libc/sys/mmap.2
@@ -105,7 +105,7 @@ The file descriptor used for creating
 must be \-1.
 The
 .Fa offset
-argument is ignored.
+argument must be 0.
 .\".It Dv MAP_FILE
 .\"Mapped from a regular file or character-special device memory.
 .It Dv MAP_ANONYMOUS
@@ -316,6 +316,11 @@ was equal to zero.
 was specified and the
 .Fa fd
 argument was not -1.
+.It Bq Er EINVAL
+.Dv MAP_ANON
+was specified and the
+.Fa offset
+argument was not 0.
 .It Bq Er ENODEV
 .Dv MAP_ANON
 has not been specified and
diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c
index 4963a603833..a47cd6a0f88 100644
--- a/sys/vm/vm_mmap.c
+++ b/sys/vm/vm_mmap.c
@@ -233,7 +233,7 @@ mmap(td, uap)
 	/* Make sure mapping fits into numeric range, etc. */
 	if ((uap->len == 0 && !SV_CURPROC_FLAG(SV_AOUT) &&
 	     curproc->p_osrel >= 800104) ||
-	    ((flags & MAP_ANON) && uap->fd != -1))
+	    ((flags & MAP_ANON) && (uap->fd != -1 || pos != 0)))
 		return (EINVAL);
 
 	if (flags & MAP_STACK) {
@@ -300,7 +300,6 @@ mmap(td, uap)
 		handle = NULL;
 		handle_type = OBJT_DEFAULT;
 		maxprot = VM_PROT_ALL;
-		pos = 0;
 	} else {
 		/*
 		 * Mapping file, get fp for validation and

From 663072c6d10f414a079f7a12e484fdb74f3eb906 Mon Sep 17 00:00:00 2001
From: John Baldwin 
Date: Tue, 23 Mar 2010 21:49:33 +0000
Subject: [PATCH 024/119] Implement /proc/filesystems.

Submitted by:	Fernando Apesteguia fernando.apesteguia (gmail)
---
 sys/compat/linprocfs/linprocfs.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c
index ba08fd22162..416efcfeff6 100644
--- a/sys/compat/linprocfs/linprocfs.c
+++ b/sys/compat/linprocfs/linprocfs.c
@@ -1227,6 +1227,22 @@ linprocfs_docmdline(PFS_FILL_ARGS)
 	return (0);
 }
 
+/*
+ * Filler function for proc/filesystems
+ */
+static int
+linprocfs_dofilesystems(PFS_FILL_ARGS)
+{
+	struct vfsconf *vfsp;
+
+	TAILQ_FOREACH(vfsp, &vfsconf, vfc_list) {
+		if (vfsp->vfc_flags & VFCF_SYNTHETIC)
+			sbuf_printf(sb, "nodev");
+		sbuf_printf(sb, "\t%s\n", vfsp->vfc_name);
+	}
+	return(0);
+}
+
 #if 0
 /*
  * Filler function for proc/modules
@@ -1276,6 +1292,8 @@ linprocfs_init(PFS_INIT_ARGS)
 	    NULL, NULL, NULL, PFS_RD);
 	pfs_create_file(root, "devices", &linprocfs_dodevices,
 	    NULL, NULL, NULL, PFS_RD);
+	pfs_create_file(root, "filesystems", &linprocfs_dofilesystems,
+	    NULL, NULL, NULL, PFS_RD);
 	pfs_create_file(root, "loadavg", &linprocfs_doloadavg,
 	    NULL, NULL, NULL, PFS_RD);
 	pfs_create_file(root, "meminfo", &linprocfs_domeminfo,

From 4d52abfb0c5f3a8eed47db2d2f3e47ff2d4bed12 Mon Sep 17 00:00:00 2001
From: Jung-uk Kim 
Date: Tue, 23 Mar 2010 22:16:57 +0000
Subject: [PATCH 025/119] Separate 24-bit pixel draw from 32-bit case. 
 Although it is slower, we do not want to write a useless zero to inaccessible
 memory region.

---
 sys/dev/syscons/scvgarndr.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sys/dev/syscons/scvgarndr.c b/sys/dev/syscons/scvgarndr.c
index fd823ce434b..583e51ae9bf 100644
--- a/sys/dev/syscons/scvgarndr.c
+++ b/sys/dev/syscons/scvgarndr.c
@@ -181,9 +181,12 @@ static u_short mouse_or_mask[16] = {
 #define	vga_drawpxl(pos, color)						\
 	switch (scp->sc->adp->va_info.vi_depth) {			\
 		case 32:						\
-		case 24:						\
 			writel(pos, vga_palette32[color]);		\
 			break;						\
+		case 24:						\
+			writew(pos, vga_palette32[color]);		\
+			writeb(pos + 2, vga_palette32[color] >> 16);	\
+			break;						\
 		case 16:						\
 			if (scp->sc->adp->va_info.vi_pixel_fsizes[1] == 5)\
 				writew(pos, vga_palette15[color]);	\

From 5fb3ac06b7f8e9522f4196688711eefbfd84931a Mon Sep 17 00:00:00 2001
From: Jung-uk Kim 
Date: Tue, 23 Mar 2010 22:35:52 +0000
Subject: [PATCH 026/119] Map entire video memory again.  This is a partial
 backout of r203535. Although we do not use them all directly, it seems VGA
 render may access unmapped memory region and cause kernel panic.

---
 sys/dev/fb/vesa.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/sys/dev/fb/vesa.c b/sys/dev/fb/vesa.c
index 26024402d7b..2b11f788fd2 100644
--- a/sys/dev/fb/vesa.c
+++ b/sys/dev/fb/vesa.c
@@ -1209,7 +1209,7 @@ vesa_set_mode(video_adapter_t *adp, int mode)
 			int10_set_mode(adp->va_initial_bios_mode);
 			if (adp->va_info.vi_flags & V_INFO_LINEAR)
 				pmap_unmapdev(adp->va_buffer,
-				    adp->va_buffer_size);
+				    vesa_adp_info->v_memsize * 64 * 1024);
 			/* 
 			 * Once (*prevvidsw->get_info)() succeeded, 
 			 * (*prevvidsw->set_mode)() below won't fail...
@@ -1246,7 +1246,8 @@ vesa_set_mode(video_adapter_t *adp, int mode)
 		adp->va_flags |= V_ADP_DAC8;
 
 	if (adp->va_info.vi_flags & V_INFO_LINEAR)
-		pmap_unmapdev(adp->va_buffer, adp->va_buffer_size);
+		pmap_unmapdev(adp->va_buffer,
+		    vesa_adp_info->v_memsize * 64 * 1024);
 
 #if VESA_DEBUG > 0
 	printf("VESA: mode set!\n");
@@ -1263,7 +1264,7 @@ vesa_set_mode(video_adapter_t *adp, int mode)
 #endif
 		vesa_adp->va_buffer =
 		    (vm_offset_t)pmap_mapdev_attr(info.vi_buffer,
-		    info.vi_buffer_size, PAT_WRITE_COMBINING);
+		    vesa_adp_info->v_memsize * 64 * 1024, PAT_WRITE_COMBINING);
 		vesa_adp->va_window = vesa_adp->va_buffer;
 		vesa_adp->va_window_size = info.vi_buffer_size / info.vi_planes;
 		vesa_adp->va_window_gran = info.vi_buffer_size / info.vi_planes;

From 51cb3184fd5c31add504b57e7bedf5b31f22e90a Mon Sep 17 00:00:00 2001
From: Jung-uk Kim 
Date: Tue, 23 Mar 2010 22:50:22 +0000
Subject: [PATCH 027/119] Fall back to VGA palette functions if VESA function
 failed and DAC is still in 6-bit mode.  Although we have to check non-VGA
 compatibility bit here, it seems there are too many broken VESA BIOSes out to
 rely on it.

---
 sys/dev/fb/vesa.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/sys/dev/fb/vesa.c b/sys/dev/fb/vesa.c
index 2b11f788fd2..1a3542d1e33 100644
--- a/sys/dev/fb/vesa.c
+++ b/sys/dev/fb/vesa.c
@@ -1241,7 +1241,6 @@ vesa_set_mode(video_adapter_t *adp, int mode)
 
 	if ((vesa_adp_info->v_flags & V_DAC8) != 0 &&
 	    (info.vi_flags & V_INFO_GRAPHICS) != 0 &&
-	    (info.vi_flags & V_INFO_NONVGA) != 0 &&
 	    vesa_bios_set_dac(8) > 6)
 		adp->va_flags |= V_ADP_DAC8;
 
@@ -1323,10 +1322,12 @@ vesa_save_palette(video_adapter_t *adp, u_char *palette)
 {
 	int bits;
 
-	if (adp == vesa_adp && VESA_MODE(adp->va_mode) &&
-	    (adp->va_info.vi_flags & V_INFO_NONVGA) != 0) {
+	if (adp == vesa_adp && VESA_MODE(adp->va_mode)) {
 		bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
-		return (vesa_bios_save_palette(0, 256, palette, bits));
+		if (vesa_bios_save_palette(0, 256, palette, bits) == 0)
+			return (0);
+		if (bits > 6)
+			return (1);
 	}
 
 	return ((*prevvidsw->save_palette)(adp, palette));
@@ -1337,10 +1338,12 @@ vesa_load_palette(video_adapter_t *adp, u_char *palette)
 {
 	int bits;
 
-	if (adp == vesa_adp && VESA_MODE(adp->va_mode) &&
-	    (adp->va_info.vi_flags & V_INFO_NONVGA) != 0) {
+	if (adp == vesa_adp && VESA_MODE(adp->va_mode)) {
 		bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
-		return (vesa_bios_load_palette(0, 256, palette, bits));
+		if (vesa_bios_load_palette(0, 256, palette, bits) == 0)
+			return (0);
+		if (bits > 6)
+			return (1);
 	}
 
 	return ((*prevvidsw->load_palette)(adp, palette));
@@ -1545,8 +1548,6 @@ get_palette(video_adapter_t *adp, int base, int count,
 		return (1);
 	if (!VESA_MODE(adp->va_mode))
 		return (1);
-	if ((adp->va_info.vi_flags & V_INFO_NONVGA) == 0)
-		return (1);
 
 	bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
 	r = malloc(count * 3, M_DEVBUF, M_WAITOK);
@@ -1583,8 +1584,6 @@ set_palette(video_adapter_t *adp, int base, int count,
 		return (1);
 	if (!VESA_MODE(adp->va_mode))
 		return (1);
-	if ((adp->va_info.vi_flags & V_INFO_NONVGA) == 0)
-		return (1);
 
 	bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
 	r = malloc(count * 3, M_DEVBUF, M_WAITOK);

From a83f96f1936ee3800ae6434d9099592cbbbbb930 Mon Sep 17 00:00:00 2001
From: Xin LI 
Date: Tue, 23 Mar 2010 22:56:19 +0000
Subject: [PATCH 028/119] Import nc from OpenBSD's OPENBSD_4_7 as of today.

---
 nc.1     | 16 ++++++++++------
 netcat.c | 32 +++++++++++++++++---------------
 2 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/nc.1 b/nc.1
index 68c90d767d1..94a2d43cdbb 100644
--- a/nc.1
+++ b/nc.1
@@ -1,4 +1,4 @@
-.\"     $OpenBSD: nc.1,v 1.50 2009/06/05 06:47:12 jmc Exp $
+.\"     $OpenBSD: nc.1,v 1.53 2010/02/23 23:00:52 schwarze Exp $
 .\"
 .\" Copyright (c) 1996 David Sacerdote
 .\" All rights reserved.
@@ -25,7 +25,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.
 .\"
-.Dd $Mdocdate: June 5 2009 $
+.Dd $Mdocdate: February 23 2010 $
 .Dt NC 1
 .Os
 .Sh NAME
@@ -47,8 +47,8 @@
 .Op Fl X Ar proxy_protocol
 .Oo Xo
 .Fl x Ar proxy_address Ns Oo : Ns
-.Ar port Oc Oc
-.Xc
+.Ar port Oc
+.Xc Oc
 .Op Ar hostname
 .Op Ar port
 .Ek
@@ -174,7 +174,9 @@ This makes it possible to use
 .Nm
 to script telnet sessions.
 .It Fl U
-Specifies to use Unix Domain Sockets.
+Specifies to use
+.Ux Ns -domain
+sockets.
 .It Fl u
 Use UDP instead of the default option of TCP.
 .It Fl V Ar rdomain
@@ -386,7 +388,9 @@ IP for the local end of the connection:
 .Pp
 .Dl $ nc -s 10.1.2.3 host.example.com 42
 .Pp
-Create and listen on a Unix Domain Socket:
+Create and listen on a
+.Ux Ns -domain
+socket:
 .Pp
 .Dl $ nc -lU /var/tmp/dsocket
 .Pp
diff --git a/netcat.c b/netcat.c
index 6700f89cfe5..508712388df 100644
--- a/netcat.c
+++ b/netcat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netcat.c,v 1.93 2009/06/05 00:18:10 claudio Exp $ */
+/* $OpenBSD: netcat.c,v 1.95 2010/02/27 00:58:56 nicm Exp $ */
 /*
  * Copyright (c) 2001 Eric Jackson 
  *
@@ -403,8 +403,10 @@ main(int argc, char *argv[])
 					    uflag ? "udp" : "tcp");
 				}
 
-				printf("Connection to %s %s port [%s/%s] succeeded!\n",
-				    host, portlist[i], uflag ? "udp" : "tcp",
+				fprintf(stderr,
+				    "Connection to %s %s port [%s/%s] "
+				    "succeeded!\n", host, portlist[i],
+				    uflag ? "udp" : "tcp",
 				    sv ? sv->s_name : "*");
 			}
 			if (!zflag)
@@ -681,27 +683,27 @@ atelnet(int nfd, unsigned char *buf, unsigned int size)
 	unsigned char *p, *end;
 	unsigned char obuf[4];
 
-	end = buf + size;
-	obuf[0] = '\0';
+	if (size < 3)
+		return;
+	end = buf + size - 2;
 
 	for (p = buf; p < end; p++) {
 		if (*p != IAC)
-			break;
+			continue;
 
 		obuf[0] = IAC;
 		p++;
 		if ((*p == WILL) || (*p == WONT))
 			obuf[1] = DONT;
-		if ((*p == DO) || (*p == DONT))
+		else if ((*p == DO) || (*p == DONT))
 			obuf[1] = WONT;
-		if (obuf) {
-			p++;
-			obuf[2] = *p;
-			obuf[3] = '\0';
-			if (atomicio(vwrite, nfd, obuf, 3) != 3)
-				warn("Write Error!");
-			obuf[0] = '\0';
-		}
+		else
+			continue;
+
+		p++;
+		obuf[2] = *p;
+		if (atomicio(vwrite, nfd, obuf, 3) != 3)
+			warn("Write Error!");
 	}
 }
 

From 578e600c8d85cd04fd4c014251a56a204f6ddc83 Mon Sep 17 00:00:00 2001
From: Rick Macklem 
Date: Tue, 23 Mar 2010 23:03:30 +0000
Subject: [PATCH 029/119] When the regular NFS server replied to a UDP client
 out of the replay cache, it did not free the request argument mbuf list,
 resulting in a leak. This patch fixes that leak.

Tested by:	danny AT cs.huji.ac.il
PR:		kern/144330
Submitted by:	to.my.trociny AT gmail.com (earlier version)
Reviewed by:	dfr
MFC after:	2 weeks
---
 sys/rpc/svc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/rpc/svc.c b/sys/rpc/svc.c
index a59489457f6..8678a18a3a5 100644
--- a/sys/rpc/svc.c
+++ b/sys/rpc/svc.c
@@ -819,9 +819,11 @@ svc_getreq(SVCXPRT *xprt, struct svc_req **rqstp_ret)
 					free(r->rq_addr, M_SONAME);
 					r->rq_addr = NULL;
 				}
+				m_freem(args);
 				goto call_done;
 
 			default:
+				m_freem(args);
 				goto call_done;
 			}
 		}

From 3b56b13e8e3a3dd1163a57469d27d245b5acb3c2 Mon Sep 17 00:00:00 2001
From: Jung-uk Kim 
Date: Tue, 23 Mar 2010 23:10:17 +0000
Subject: [PATCH 030/119] Be extremely careful when we determine bytes per scan
 line information. First, we compare mode table data against minimum value. 
 If the mode table does not make sense, we set the minimum in the mode info. 
 When we actually set the mode, we try VESA BIOS function and compare it
 against the previous value.  If it makes more sense, update the information.

---
 sys/dev/fb/vesa.c | 65 +++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 54 insertions(+), 11 deletions(-)

diff --git a/sys/dev/fb/vesa.c b/sys/dev/fb/vesa.c
index 1a3542d1e33..287cc6a9dff 100644
--- a/sys/dev/fb/vesa.c
+++ b/sys/dev/fb/vesa.c
@@ -188,9 +188,7 @@ static int vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g,
 #define STATE_ALL	(STATE_HW | STATE_DATA | STATE_DAC | STATE_REG)
 static ssize_t vesa_bios_state_buf_size(void);
 static int vesa_bios_save_restore(int code, void *p, size_t size);
-#if 0
 static int vesa_bios_get_line_length(void);
-#endif
 static int vesa_bios_set_line_length(int pixel, int *bytes, int *lines);
 #if 0
 static int vesa_bios_get_start(int *x, int *y);
@@ -199,6 +197,7 @@ static int vesa_bios_set_start(int x, int y);
 static int vesa_map_gen_mode_num(int type, int color, int mode);
 static int vesa_translate_flags(u_int16_t vflags);
 static int vesa_translate_mmodel(u_int8_t vmodel);
+static int vesa_get_bpscanline(struct vesa_mode *vmode);
 static int vesa_bios_init(void);
 static void vesa_clear_modes(video_info_t *info, int color);
 
@@ -558,7 +557,6 @@ vesa_bios_save_restore(int code, void *p, size_t size)
 	return (regs.R_AX != 0x004f);
 }
 
-#if 0
 static int
 vesa_bios_get_line_length(void)
 {
@@ -575,7 +573,6 @@ vesa_bios_get_line_length(void)
 
 	return (regs.R_BX);
 }
-#endif
 
 static int
 vesa_bios_set_line_length(int pixel, int *bytes, int *lines)
@@ -709,6 +706,43 @@ vesa_translate_mmodel(u_int8_t vmodel)
 	return (V_INFO_MM_OTHER);
 }
 
+static int
+vesa_get_bpscanline(struct vesa_mode *vmode)
+{
+	int bpsl;
+
+	if ((vmode->v_modeattr & V_MODEGRAPHICS) != 0) {
+		/* Find the minimum length. */
+		switch (vmode->v_bpp / vmode->v_planes) {
+		case 1:
+			bpsl = vmode->v_width / 8;
+			break;
+		case 2:
+			bpsl = vmode->v_width / 4;
+			break;
+		case 4:
+			bpsl = vmode->v_width / 2;
+			break;
+		default:
+			bpsl = vmode->v_width * ((vmode->v_bpp + 7) / 8);
+			bpsl /= vmode->v_planes;
+			break;
+		}
+
+		/* Use VBE 3.0 information if it looks sane. */
+		if ((vmode->v_modeattr & V_MODELFB) != 0 &&
+		    vesa_adp_info->v_version >= 0x0300 &&
+		    vmode->v_linbpscanline > bpsl)
+			return (vmode->v_linbpscanline);
+
+		/* Return the minimum if the mode table looks absurd. */
+		if (vmode->v_bpscanline < bpsl)
+			return (bpsl);
+	}
+
+	return (vmode->v_bpscanline);
+}
+
 #define	VESA_MAXSTR		256
 
 #define	VESA_STRCPY(dst, src)	do {				\
@@ -733,7 +767,6 @@ vesa_bios_init(void)
 	void *vmbuf;
 	uint32_t offs;
 	uint16_t vers;
-	int bpsl;
 	int is_via_cle266;
 	int modes;
 	int i;
@@ -858,9 +891,7 @@ vesa_bios_init(void)
 		}
 #endif
 
-		bpsl = (vmode.v_modeattr & V_MODELFB) != 0 && vers >= 0x0300 ?
-		    vmode.v_linbpscanline : vmode.v_bpscanline;
-		bsize = bpsl * vmode.v_height;
+		bsize = vesa_get_bpscanline(&vmode) * vmode.v_height;
 		if ((vmode.v_modeattr & V_MODEGRAPHICS) != 0)
 			bsize *= vmode.v_planes;
 
@@ -1181,6 +1212,7 @@ static int
 vesa_set_mode(video_adapter_t *adp, int mode)
 {
 	video_info_t info;
+	int bpsl;
 
 	if (adp != vesa_adp)
 		return ((*prevvidsw->set_mode)(adp, mode));
@@ -1257,6 +1289,20 @@ vesa_set_mode(video_adapter_t *adp, int mode)
 		(info.vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0;
 	vesa_adp->va_crtc_addr =
 		(vesa_adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC;
+
+	vesa_adp->va_line_width = info.vi_buffer_size / info.vi_height;
+	if ((info.vi_flags & V_INFO_GRAPHICS) != 0)
+		vesa_adp->va_line_width /= info.vi_planes;
+
+	/* If VBE function returns bigger bytes per scan line, use it. */
+	bpsl = vesa_bios_get_line_length();
+	if (bpsl > vesa_adp->va_line_width) {
+		vesa_adp->va_line_width = bpsl;
+		info.vi_buffer_size = bpsl * info.vi_height;
+		if ((info.vi_flags & V_INFO_GRAPHICS) != 0)
+			info.vi_buffer_size *= info.vi_planes;
+	}
+
 	if (info.vi_flags & V_INFO_LINEAR) {
 #if VESA_DEBUG > 1
 		printf("VESA: setting up LFB\n");
@@ -1275,9 +1321,6 @@ vesa_set_mode(video_adapter_t *adp, int mode)
 	}
 	vesa_adp->va_buffer_size = info.vi_buffer_size;
 	vesa_adp->va_window_orig = 0;
-	vesa_adp->va_line_width = info.vi_buffer_size / info.vi_height;
-	if ((info.vi_flags & V_INFO_GRAPHICS) != 0)
-		vesa_adp->va_line_width /= info.vi_planes;
 	vesa_adp->va_disp_start.x = 0;
 	vesa_adp->va_disp_start.y = 0;
 #if VESA_DEBUG > 0

From b266b96af912188c0f5fcffa2dbc74e000ce3ca6 Mon Sep 17 00:00:00 2001
From: Jung-uk Kim 
Date: Tue, 23 Mar 2010 23:19:23 +0000
Subject: [PATCH 031/119] Add my copyright here.  It seems I have contributed
 enough code. :-)

---
 sys/dev/fb/vesa.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sys/dev/fb/vesa.c b/sys/dev/fb/vesa.c
index 287cc6a9dff..733f5b86aa3 100644
--- a/sys/dev/fb/vesa.c
+++ b/sys/dev/fb/vesa.c
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 1998 Kazutaka YOKOTA and Michael Smith
+ * Copyright (c) 2009-2010 Jung-uk Kim 
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

From b41169fdceb26c610babd700cd65c02f5eacf6c9 Mon Sep 17 00:00:00 2001
From: Marcel Moolenaar 
Date: Tue, 23 Mar 2010 23:46:28 +0000
Subject: [PATCH 032/119] Fix an off-by-one bug for the number of slots on a
 PCI/PCI-X bus. We failed to setup PCI devices on slot 31 and that's where the
 SATA controller is for the P2020 eval board.

---
 sys/powerpc/mpc85xx/pci_ocp.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/sys/powerpc/mpc85xx/pci_ocp.c b/sys/powerpc/mpc85xx/pci_ocp.c
index eba3f50d501..cdcf986b940 100644
--- a/sys/powerpc/mpc85xx/pci_ocp.c
+++ b/sys/powerpc/mpc85xx/pci_ocp.c
@@ -264,7 +264,7 @@ pci_ocp_maxslots(device_t dev)
 {
 	struct pci_ocp_softc *sc = device_get_softc(dev);
 
-	return ((sc->sc_pcie_cap) ? 0 : 30);
+	return ((sc->sc_pcie_cap) ? 0 : 31);
 }
 
 static uint32_t
@@ -328,6 +328,7 @@ pci_ocp_probe(device_t dev)
 		return (ENXIO);
 
 	sc = device_get_softc(dev);
+	sc->sc_dev = dev;
 
 	sc->sc_rid = 0;
 	sc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->sc_rid,
@@ -492,7 +493,7 @@ pci_ocp_route_int(struct pci_ocp_softc *sc, u_int bus, u_int slot, u_int func,
 }
 
 static int
-pci_ocp_init(struct pci_ocp_softc *sc, int bus, int maxslot)
+pci_ocp_init(struct pci_ocp_softc *sc, int bus, int nslots)
 {
 	int secbus, slot;
 	int func, maxfunc;
@@ -502,7 +503,7 @@ pci_ocp_init(struct pci_ocp_softc *sc, int bus, int maxslot)
 	uint8_t intline, intpin;
 
 	secbus = bus;
-	for (slot = 0; slot < maxslot; slot++) {
+	for (slot = 0; slot < nslots; slot++) {
 		maxfunc = 0;
 		for (func = 0; func <= maxfunc; func++) {
 			hdrtype = pci_ocp_read_config(sc->sc_dev, bus, slot,
@@ -599,7 +600,7 @@ pci_ocp_init(struct pci_ocp_softc *sc, int bus, int maxslot)
 			    PCIR_SUBBUS_1, 0xff, 1);
 
 			secbus = pci_ocp_init(sc, secbus,
-			    (subclass == PCIS_BRIDGE_PCI) ? 31 : 1);
+			    (subclass == PCIS_BRIDGE_PCI) ? 32 : 1);
 
 			pci_ocp_write_config(sc->sc_dev, bus, slot, func,
 			    PCIR_SUBBUS_1, secbus, 1);
@@ -721,7 +722,7 @@ pci_ocp_attach(device_t dev)
 {
 	struct pci_ocp_softc *sc;
 	uint32_t cfgreg;
-	int error, maxslot;
+	int error, nslots;
 
 	sc = device_get_softc(dev);
 	sc->sc_dev = dev;
@@ -765,8 +766,8 @@ pci_ocp_attach(device_t dev)
 			return (0);
 	}
 
-	maxslot = (sc->sc_pcie_cap) ? 1 : 31;
-	pci_ocp_init(sc, sc->sc_busnr, maxslot);
+	nslots = (sc->sc_pcie_cap) ? 1 : 32;
+	pci_ocp_init(sc, sc->sc_busnr, nslots);
 
 	device_add_child(dev, "pci", -1);
 	return (bus_generic_attach(dev));

From d6655439edcd4ca331615a01aa00605f2737845e Mon Sep 17 00:00:00 2001
From: Xin LI 
Date: Tue, 23 Mar 2010 23:56:22 +0000
Subject: [PATCH 033/119] Update metadata information as well as upgrade
 instructions.

---
 contrib/netcat/FREEBSD-upgrade | 27 +++++++++++----------------
 contrib/netcat/FREEBSD-vendor  |  2 +-
 2 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/contrib/netcat/FREEBSD-upgrade b/contrib/netcat/FREEBSD-upgrade
index 5a52ebc6481..33f5ea2873d 100644
--- a/contrib/netcat/FREEBSD-upgrade
+++ b/contrib/netcat/FREEBSD-upgrade
@@ -1,19 +1,14 @@
 $FreeBSD$
 
-1. Export from OpenBSD's nc(1) into an empty directory (say "v-nc").
-2. while read pattern; do rm ${pattern} ; done < FREEBSD-Xlist
-3. Checkout our contrib/netcat to another directory (say "f-nc"),
-   with -rOPENBSD, and usr.bin/nc to its ../../
-4. copy the files from v-nc to f-nc
-5. do cvs up -A in f-nc
-6. If there is conflicits, try to resolve them.
-7. do build in f-nc/../../usr.bin/nc
-8. If everything seems ok, do the actual import in v-nc:
-	cvs -n import src/contrib/netcat OPENBSD OPENBSD_
-   Everything appears be Ok? Do:
-	cvs import src/contrib/netcat OPENBSD OPENBSD_
-   (note: recently we import from OpenBSD's release branches
-    rather than importing -HEAD snapshots)
-9. Resolve the conflicits with the patchset obtained in step 6.
+Most of the instructions is outlined on FreeBSD wiki at:
 
-delphij@FreeBSD.org - 21 Apr 2008
+	http://wiki.freebsd.org/SubversionPrimer/VendorImports
+
+nc(1) is very small and most of code are just copied as-is from OpenBSD.  With a
+few exceptions:
+
+ * --no-tcpopt: Local feature specific to FreeBSD.
+ * -V: We use FIB to map what OpenBSD do for "rdomain"
+ * -E, -e: These are mostly self contained IPsec extensions
+
+delphij@FreeBSD.org - Mar 23, 2010
diff --git a/contrib/netcat/FREEBSD-vendor b/contrib/netcat/FREEBSD-vendor
index c808f5bbc5a..f54017524c1 100644
--- a/contrib/netcat/FREEBSD-vendor
+++ b/contrib/netcat/FREEBSD-vendor
@@ -1,5 +1,5 @@
 # $FreeBSD$
 Project:	netcat (aka src/usr.bin/nc in OpenBSD)
 ProjectURL:	http://www.openbsd.org/
-Version:	4.6
+Version:	4.7
 License:	BSD

From 3dfe81c6506da76fbc72c93335bfc9672ca869b2 Mon Sep 17 00:00:00 2001
From: Rick Macklem 
Date: Wed, 24 Mar 2010 02:02:02 +0000
Subject: [PATCH 034/119] Fix the experimental NFS subsystem so that it uses
 the correct preprocessor macro name for not requiring strict data alignment.

Suggested by:	marius
MFC after:	2 weeks
---
 sys/fs/nfs/nfs_commonport.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sys/fs/nfs/nfs_commonport.c b/sys/fs/nfs/nfs_commonport.c
index 7f27494bb8b..8092a5d4610 100644
--- a/sys/fs/nfs/nfs_commonport.c
+++ b/sys/fs/nfs/nfs_commonport.c
@@ -117,7 +117,7 @@ struct mtx nfs_slock_mutex;
 /* local functions */
 static int nfssvc_call(struct thread *, struct nfssvc_args *, struct ucred *);
 
-#if defined(__i386__)
+#ifdef __NO_STRICT_ALIGNMENT
 /*
  * These architectures don't need re-alignment, so just return.
  */
@@ -127,7 +127,7 @@ newnfs_realign(struct mbuf **pm)
 
 	return;
 }
-#else
+#else	/* !__NO_STRICT_ALIGNMENT */
 /*
  *	newnfs_realign:
  *
@@ -185,7 +185,7 @@ newnfs_realign(struct mbuf **pm)
 		pm = &m->m_next;
 	}
 }
-#endif	/* !__i386__ */
+#endif	/* __NO_STRICT_ALIGNMENT */
 
 #ifdef notdef
 static void

From e1990590e34591bfc8e1a81bdff0b5cfa5f02910 Mon Sep 17 00:00:00 2001
From: Alan Cox 
Date: Wed, 24 Mar 2010 03:07:35 +0000
Subject: [PATCH 035/119] Adapt r204907 and r205402, the amd64 implementation
 of the workaround for AMD Family 10h Erratum 383, to i386.

Enable machine check exceptions by default, just like r204913 for amd64.

Enable superpage promotion only if the processor actually supports large
pages, i.e., PG_PS.

MFC after:	2 weeks
---
 sys/i386/i386/mca.c           |  35 ++++-
 sys/i386/i386/pmap.c          | 240 ++++++++++++++++++++++++++--------
 sys/i386/include/md_var.h     |   1 +
 sys/i386/include/specialreg.h |   1 +
 4 files changed, 224 insertions(+), 53 deletions(-)

diff --git a/sys/i386/i386/mca.c b/sys/i386/i386/mca.c
index 9b9f9451597..8d33b51b96e 100644
--- a/sys/i386/i386/mca.c
+++ b/sys/i386/i386/mca.c
@@ -60,11 +60,20 @@ static int mca_count;		/* Number of records stored. */
 
 SYSCTL_NODE(_hw, OID_AUTO, mca, CTLFLAG_RD, NULL, "Machine Check Architecture");
 
-static int mca_enabled = 0;
+static int mca_enabled = 1;
 TUNABLE_INT("hw.mca.enabled", &mca_enabled);
 SYSCTL_INT(_hw_mca, OID_AUTO, enabled, CTLFLAG_RDTUN, &mca_enabled, 0,
     "Administrative toggle for machine check support");
 
+static int amd10h_L1TP = 1;
+TUNABLE_INT("hw.mca.amd10h_L1TP", &amd10h_L1TP);
+SYSCTL_INT(_hw_mca, OID_AUTO, amd10h_L1TP, CTLFLAG_RDTUN, &amd10h_L1TP, 0,
+    "Administrative toggle for logging of level one TLB parity (L1TP) errors");
+
+int workaround_erratum383;
+SYSCTL_INT(_hw_mca, OID_AUTO, erratum383, CTLFLAG_RD, &workaround_erratum383, 0,
+    "Is the workaround for Erratum 383 on AMD Family 10h processors enabled?");
+
 static STAILQ_HEAD(, mca_internal) mca_records;
 static struct callout mca_timer;
 static int mca_ticks = 3600;	/* Check hourly by default. */
@@ -527,7 +536,7 @@ void
 mca_init(void)
 {
 	uint64_t mcg_cap;
-	uint64_t ctl;
+	uint64_t ctl, mask;
 	int skip;
 	int i;
 
@@ -535,6 +544,15 @@ mca_init(void)
 	if (!mca_enabled || !(cpu_feature & CPUID_MCE))
 		return;
 
+	/*
+	 * On AMD Family 10h processors, unless logging of level one TLB
+	 * parity (L1TP) errors is disabled, enable the recommended workaround
+	 * for Erratum 383.
+	 */
+	if (cpu_vendor_id == CPU_VENDOR_AMD &&
+	    CPUID_TO_FAMILY(cpu_id) == 0x10 && amd10h_L1TP)
+		workaround_erratum383 = 1;
+
 	if (cpu_feature & CPUID_MCA) {
 		if (PCPU_GET(cpuid) == 0)
 			mca_setup();
@@ -545,6 +563,19 @@ mca_init(void)
 			/* Enable MCA features. */
 			wrmsr(MSR_MCG_CTL, MCG_CTL_ENABLE);
 
+		/*
+		 * Disable logging of level one TLB parity (L1TP) errors by
+		 * the data cache as an alternative workaround for AMD Family
+		 * 10h Erratum 383.  Unlike the recommended workaround, there
+		 * is no performance penalty to this workaround.  However,
+		 * L1TP errors will go unreported.
+		 */
+		if (cpu_vendor_id == CPU_VENDOR_AMD &&
+		    CPUID_TO_FAMILY(cpu_id) == 0x10 && !amd10h_L1TP) {
+			mask = rdmsr(MSR_MC0_CTL_MASK);
+			if ((mask & (1UL << 5)) == 0)
+				wrmsr(MSR_MC0_CTL_MASK, mask | (1UL << 5));
+		}
 		for (i = 0; i < (mcg_cap & MCG_CAP_COUNT); i++) {
 			/* By default enable logging of all errors. */
 			ctl = 0xffffffffffffffffUL;
diff --git a/sys/i386/i386/pmap.c b/sys/i386/i386/pmap.c
index e9dd20716c1..c83e99c2410 100644
--- a/sys/i386/i386/pmap.c
+++ b/sys/i386/i386/pmap.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  * Copyright (c) 1994 David Greenman
  * All rights reserved.
- * Copyright (c) 2005-2008 Alan L. Cox 
+ * Copyright (c) 2005-2010 Alan L. Cox 
  * All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
@@ -297,6 +297,7 @@ static void pmap_insert_pt_page(pmap_t pmap, vm_page_t mpte);
 static void pmap_fill_ptp(pt_entry_t *firstpte, pt_entry_t newpte);
 static boolean_t pmap_is_modified_pvh(struct md_page *pvh);
 static void pmap_kenter_attr(vm_offset_t va, vm_paddr_t pa, int mode);
+static void pmap_kenter_pde(vm_offset_t va, pd_entry_t newpde);
 static vm_page_t pmap_lookup_pt_page(pmap_t pmap, vm_offset_t va);
 static void pmap_pde_attr(pd_entry_t *pde, int cache_bits);
 static void pmap_promote_pde(pmap_t pmap, pd_entry_t *pde, vm_offset_t va);
@@ -315,6 +316,9 @@ static void pmap_remove_entry(struct pmap *pmap, vm_page_t m,
 static void pmap_insert_entry(pmap_t pmap, vm_offset_t va, vm_page_t m);
 static boolean_t pmap_try_insert_pv_entry(pmap_t pmap, vm_offset_t va,
     vm_page_t m);
+static void pmap_update_pde(pmap_t pmap, vm_offset_t va, pd_entry_t *pde,
+    pd_entry_t newpde);
+static void pmap_update_pde_invalidate(vm_offset_t va, pd_entry_t newpde);
 
 static vm_page_t pmap_allocpte(pmap_t pmap, vm_offset_t va, int flags);
 
@@ -380,6 +384,13 @@ pmap_bootstrap(vm_paddr_t firstaddr)
 	kernel_pmap->pm_active = -1;	/* don't allow deactivation */
 	TAILQ_INIT(&kernel_pmap->pm_pvchunk);
 	LIST_INIT(&allpmaps);
+
+	/*
+	 * Request a spin mutex so that changes to allpmaps cannot be
+	 * preempted by smp_rendezvous_cpus().  Otherwise,
+	 * pmap_update_pde_kernel() could access allpmaps while it is
+	 * being changed.
+	 */
 	mtx_init(&allpmaps_lock, "allpmaps", NULL, MTX_SPIN);
 	mtx_lock_spin(&allpmaps_lock);
 	LIST_INSERT_HEAD(&allpmaps, kernel_pmap, pm_list);
@@ -692,19 +703,21 @@ pmap_init(void)
 	pv_entry_high_water = 9 * (pv_entry_max / 10);
 
 	/*
-	 * Disable large page mappings by default if the kernel is running in
-	 * a virtual machine on an AMD Family 10h processor.  This is a work-
-	 * around for Erratum 383.
+	 * If the kernel is running in a virtual machine on an AMD Family 10h
+	 * processor, then it must assume that MCA is enabled by the virtual
+	 * machine monitor.
 	 */
 	if (vm_guest == VM_GUEST_VM && cpu_vendor_id == CPU_VENDOR_AMD &&
 	    CPUID_TO_FAMILY(cpu_id) == 0x10)
-		pg_ps_enabled = 0;
+		workaround_erratum383 = 1;
 
 	/*
-	 * Are large page mappings enabled?
+	 * Are large page mappings supported and enabled?
 	 */
 	TUNABLE_INT_FETCH("vm.pmap.pg_ps_enabled", &pg_ps_enabled);
-	if (pg_ps_enabled) {
+	if (pseflag == 0)
+		pg_ps_enabled = 0;
+	else if (pg_ps_enabled) {
 		KASSERT(MAXPAGESIZES > 1 && pagesizes[1] == 0,
 		    ("pmap_init: can't assign to pagesizes[1]"));
 		pagesizes[1] = NBPDR;
@@ -850,6 +863,66 @@ pmap_cache_bits(int mode, boolean_t is_pde)
 		cache_bits |= PG_NC_PWT;
 	return (cache_bits);
 }
+
+/*
+ * The caller is responsible for maintaining TLB consistency.
+ */
+static void
+pmap_kenter_pde(vm_offset_t va, pd_entry_t newpde)
+{
+	pd_entry_t *pde;
+	pmap_t pmap;
+	boolean_t PTD_updated;
+
+	PTD_updated = FALSE;
+	mtx_lock_spin(&allpmaps_lock);
+	LIST_FOREACH(pmap, &allpmaps, pm_list) {
+		if ((pmap->pm_pdir[PTDPTDI] & PG_FRAME) == (PTDpde[0] &
+		    PG_FRAME))
+			PTD_updated = TRUE;
+		pde = pmap_pde(pmap, va);
+		pde_store(pde, newpde);
+	}
+	mtx_unlock_spin(&allpmaps_lock);
+	KASSERT(PTD_updated,
+	    ("pmap_kenter_pde: current page table is not in allpmaps"));
+}
+
+/*
+ * After changing the page size for the specified virtual address in the page
+ * table, flush the corresponding entries from the processor's TLB.  Only the
+ * calling processor's TLB is affected.
+ *
+ * The calling thread must be pinned to a processor.
+ */
+static void
+pmap_update_pde_invalidate(vm_offset_t va, pd_entry_t newpde)
+{
+	u_long cr4;
+
+	if ((newpde & PG_PS) == 0)
+		/* Demotion: flush a specific 2MB page mapping. */
+		invlpg(va);
+	else if ((newpde & PG_G) == 0)
+		/*
+		 * Promotion: flush every 4KB page mapping from the TLB
+		 * because there are too many to flush individually.
+		 */
+		invltlb();
+	else {
+		/*
+		 * Promotion: flush every 4KB page mapping from the TLB,
+		 * including any global (PG_G) mappings.
+		 */
+		cr4 = rcr4();
+		load_cr4(cr4 & ~CR4_PGE);
+		/*
+		 * Although preemption at this point could be detrimental to
+		 * performance, it would not lead to an error.
+		 */
+		load_cr4(cr4);
+	}
+}
 #ifdef SMP
 /*
  * For SMP, these functions have to use the IPI mechanism for coherence.
@@ -946,6 +1019,92 @@ pmap_invalidate_cache(void)
 	smp_cache_flush();
 	sched_unpin();
 }
+
+struct pde_action {
+	cpumask_t store;	/* processor that updates the PDE */
+	cpumask_t invalidate;	/* processors that invalidate their TLB */
+	vm_offset_t va;
+	pd_entry_t *pde;
+	pd_entry_t newpde;
+};
+
+static void
+pmap_update_pde_kernel(void *arg)
+{
+	struct pde_action *act = arg;
+	pd_entry_t *pde;
+	pmap_t pmap;
+
+	if (act->store == PCPU_GET(cpumask))
+		/*
+		 * Elsewhere, this operation requires allpmaps_lock for
+		 * synchronization.  Here, it does not because it is being
+		 * performed in the context of an all_cpus rendezvous.
+		 */
+		LIST_FOREACH(pmap, &allpmaps, pm_list) {
+			pde = pmap_pde(pmap, act->va);
+			pde_store(pde, act->newpde);
+		}
+}
+
+static void
+pmap_update_pde_user(void *arg)
+{
+	struct pde_action *act = arg;
+
+	if (act->store == PCPU_GET(cpumask))
+		pde_store(act->pde, act->newpde);
+}
+
+static void
+pmap_update_pde_teardown(void *arg)
+{
+	struct pde_action *act = arg;
+
+	if ((act->invalidate & PCPU_GET(cpumask)) != 0)
+		pmap_update_pde_invalidate(act->va, act->newpde);
+}
+
+/*
+ * Change the page size for the specified virtual address in a way that
+ * prevents any possibility of the TLB ever having two entries that map the
+ * same virtual address using different page sizes.  This is the recommended
+ * workaround for Erratum 383 on AMD Family 10h processors.  It prevents a
+ * machine check exception for a TLB state that is improperly diagnosed as a
+ * hardware error.
+ */
+static void
+pmap_update_pde(pmap_t pmap, vm_offset_t va, pd_entry_t *pde, pd_entry_t newpde)
+{
+	struct pde_action act;
+	cpumask_t active, cpumask;
+
+	sched_pin();
+	cpumask = PCPU_GET(cpumask);
+	if (pmap == kernel_pmap)
+		active = all_cpus;
+	else
+		active = pmap->pm_active;
+	if ((active & PCPU_GET(other_cpus)) != 0) {
+		act.store = cpumask;
+		act.invalidate = active;
+		act.va = va;
+		act.pde = pde;
+		act.newpde = newpde;
+		smp_rendezvous_cpus(cpumask | active,
+		    smp_no_rendevous_barrier, pmap == kernel_pmap ?
+		    pmap_update_pde_kernel : pmap_update_pde_user,
+		    pmap_update_pde_teardown, &act);
+	} else {
+		if (pmap == kernel_pmap)
+			pmap_kenter_pde(va, newpde);
+		else
+			pde_store(pde, newpde);
+		if ((active & cpumask) != 0)
+			pmap_update_pde_invalidate(va, newpde);
+	}
+	sched_unpin();
+}
 #else /* !SMP */
 /*
  * Normal, non-SMP, 486+ invalidation functions.
@@ -983,6 +1142,18 @@ pmap_invalidate_cache(void)
 
 	wbinvd();
 }
+
+static void
+pmap_update_pde(pmap_t pmap, vm_offset_t va, pd_entry_t *pde, pd_entry_t newpde)
+{
+
+	if (pmap == kernel_pmap)
+		pmap_kenter_pde(va, newpde);
+	else
+		pde_store(pde, newpde);
+	if (pmap == kernel_pmap || pmap->pm_active)
+		pmap_update_pde_invalidate(va, newpde);
+}
 #endif /* !SMP */
 
 void
@@ -1856,12 +2027,9 @@ SYSCTL_PROC(_vm, OID_AUTO, kvm_free, CTLTYPE_LONG|CTLFLAG_RD,
 void
 pmap_growkernel(vm_offset_t addr)
 {
-	struct pmap *pmap;
 	vm_paddr_t ptppaddr;
 	vm_page_t nkpg;
 	pd_entry_t newpdir;
-	pt_entry_t *pde;
-	boolean_t updated_PTD;
 
 	mtx_assert(&kernel_map->system_mtx, MA_OWNED);
 	if (kernel_vm_end == 0) {
@@ -1903,18 +2071,7 @@ pmap_growkernel(vm_offset_t addr)
 		newpdir = (pd_entry_t) (ptppaddr | PG_V | PG_RW | PG_A | PG_M);
 		pdir_pde(KPTD, kernel_vm_end) = pgeflag | newpdir;
 
-		updated_PTD = FALSE;
-		mtx_lock_spin(&allpmaps_lock);
-		LIST_FOREACH(pmap, &allpmaps, pm_list) {
-			if ((pmap->pm_pdir[PTDPTDI] & PG_FRAME) == (PTDpde[0] &
-			    PG_FRAME))
-				updated_PTD = TRUE;
-			pde = pmap_pde(pmap, kernel_vm_end);
-			pde_store(pde, newpdir);
-		}
-		mtx_unlock_spin(&allpmaps_lock);
-		KASSERT(updated_PTD,
-		    ("pmap_growkernel: current page table is not in allpmaps"));
+		pmap_kenter_pde(kernel_vm_end, newpdir);
 		kernel_vm_end = (kernel_vm_end + PAGE_SIZE * NPTEPG) & ~(PAGE_SIZE * NPTEPG - 1);
 		if (kernel_vm_end - 1 >= kernel_map->max_offset) {
 			kernel_vm_end = kernel_map->max_offset;
@@ -2358,7 +2515,6 @@ static boolean_t
 pmap_demote_pde(pmap_t pmap, pd_entry_t *pde, vm_offset_t va)
 {
 	pd_entry_t newpde, oldpde;
-	pmap_t allpmaps_entry;
 	pt_entry_t *firstpte, newpte;
 	vm_paddr_t mptepa;
 	vm_page_t free, mpte;
@@ -2464,25 +2620,11 @@ pmap_demote_pde(pmap_t pmap, pd_entry_t *pde, vm_offset_t va)
 	 * processor changing the setting of PG_A and/or PG_M between
 	 * the read above and the store below. 
 	 */
-	if (pmap == kernel_pmap) {
-		/*
-		 * A harmless race exists between this loop and the bcopy()
-		 * in pmap_pinit() that initializes the kernel segment of
-		 * the new page table directory.  Specifically, that bcopy()
-		 * may copy the new PDE from the PTD to the new page table
-		 * before this loop updates that new page table.
-		 */
-		mtx_lock_spin(&allpmaps_lock);
-		LIST_FOREACH(allpmaps_entry, &allpmaps, pm_list) {
-			pde = pmap_pde(allpmaps_entry, va);
-			KASSERT(*pde == newpde || (*pde & PG_PTE_PROMOTE) ==
-			    (oldpde & PG_PTE_PROMOTE),
-			    ("pmap_demote_pde: pde was %#jx, expected %#jx",
-			    (uintmax_t)*pde, (uintmax_t)oldpde));
-			pde_store(pde, newpde);
-		}
-		mtx_unlock_spin(&allpmaps_lock);
-	} else
+	if (workaround_erratum383)
+		pmap_update_pde(pmap, va, pde, newpde);
+	else if (pmap == kernel_pmap)
+		pmap_kenter_pde(va, newpde);
+	else
 		pde_store(pde, newpde);	
 	if (firstpte == PADDR2)
 		mtx_unlock(&PMAP2mutex);
@@ -3001,7 +3143,6 @@ static void
 pmap_promote_pde(pmap_t pmap, pd_entry_t *pde, vm_offset_t va)
 {
 	pd_entry_t newpde;
-	pmap_t allpmaps_entry;
 	pt_entry_t *firstpte, oldpte, pa, *pte;
 	vm_offset_t oldpteva;
 	vm_page_t mpte;
@@ -3105,14 +3246,11 @@ setpte:
 	/*
 	 * Map the superpage.
 	 */
-	if (pmap == kernel_pmap) {
-		mtx_lock_spin(&allpmaps_lock);
-		LIST_FOREACH(allpmaps_entry, &allpmaps, pm_list) {
-			pde = pmap_pde(allpmaps_entry, va);
-			pde_store(pde, PG_PS | newpde);
-		}
-		mtx_unlock_spin(&allpmaps_lock);
-	} else
+	if (workaround_erratum383)
+		pmap_update_pde(pmap, va, pde, PG_PS | newpde);
+	else if (pmap == kernel_pmap)
+		pmap_kenter_pde(va, PG_PS | newpde);
+	else
 		pde_store(pde, PG_PS | newpde);
 
 	pmap_pde_promotions++;
diff --git a/sys/i386/include/md_var.h b/sys/i386/include/md_var.h
index e2968e9d4fc..44eb8a6e2ab 100644
--- a/sys/i386/include/md_var.h
+++ b/sys/i386/include/md_var.h
@@ -73,6 +73,7 @@ extern	int	szosigcode;
 #endif
 extern	uint32_t *vm_page_dump;
 extern	int	vm_page_dump_size;
+extern	int	workaround_erratum383;
 
 typedef void alias_for_inthand_t(u_int cs, u_int ef, u_int esp, u_int ss);
 struct	thread;
diff --git a/sys/i386/include/specialreg.h b/sys/i386/include/specialreg.h
index 64a55350391..d2494c72100 100644
--- a/sys/i386/include/specialreg.h
+++ b/sys/i386/include/specialreg.h
@@ -551,6 +551,7 @@
 /* AMD64 MSR's */
 #define	MSR_EFER	0xc0000080	/* extended features */
 #define	MSR_K8_UCODE_UPDATE	0xc0010020	/* update microcode */
+#define	MSR_MC0_CTL_MASK	0xc0010044
 
 /* VIA ACE crypto featureset: for via_feature_rng */
 #define	VIA_HAS_RNG		1	/* cpu has RNG */

From f4e26adefcdf9bb2366b1a04d76c72814325c24f Mon Sep 17 00:00:00 2001
From: Nathan Whitehorn 
Date: Wed, 24 Mar 2010 03:13:24 +0000
Subject: [PATCH 036/119] The nargvstr and nenvstr properties of arginfo are
 ints, not longs, so should be copied to userspace with suword32() instead of
 suword(). This alleviates problems on 64-bit big-endian architectures, and is
 a no-op on all 32-bit architectures.

Tested on:	amd64, sparc64, powerpc64
---
 sys/kern/kern_exec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index dce624d484b..c7a4358270a 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -1260,7 +1260,7 @@ exec_copyout_strings(imgp)
 	 * Fill in "ps_strings" struct for ps, w, etc.
 	 */
 	suword(&arginfo->ps_argvstr, (long)(intptr_t)vectp);
-	suword(&arginfo->ps_nargvstr, argc);
+	suword32(&arginfo->ps_nargvstr, argc);
 
 	/*
 	 * Fill in argument portion of vector table.
@@ -1276,7 +1276,7 @@ exec_copyout_strings(imgp)
 	suword(vectp++, 0);
 
 	suword(&arginfo->ps_envstr, (long)(intptr_t)vectp);
-	suword(&arginfo->ps_nenvstr, envc);
+	suword32(&arginfo->ps_nenvstr, envc);
 
 	/*
 	 * Fill in environment portion of vector table.

From b5f18aa6da1a15ee6bff4bf392e327045a8c7bcb Mon Sep 17 00:00:00 2001
From: Neel Natu 
Date: Wed, 24 Mar 2010 04:52:15 +0000
Subject: [PATCH 037/119] Fix periodic "t_delta 16.01359db7eb5eb3c0 too long"
 messages on the console by accounting for the "lost time" between when the
 timer interrupt fired and when clock_intr() actually started executing.

---
 sys/mips/mips/tick.c | 53 ++++++++++++++++++++++++++++++--------------
 1 file changed, 36 insertions(+), 17 deletions(-)

diff --git a/sys/mips/mips/tick.c b/sys/mips/mips/tick.c
index b83d83f5f74..60b3511e0c0 100644
--- a/sys/mips/mips/tick.c
+++ b/sys/mips/mips/tick.c
@@ -63,17 +63,14 @@ static uint64_t cycles_per_hz, cycles_per_stathz, cycles_per_profhz;
 static u_int32_t counter_upper = 0;
 static u_int32_t counter_lower_last = 0;
 
-struct clk_ticks
-{
+struct clk_ticks {
 	u_long hard_ticks;
 	u_long stat_ticks;
 	u_long prof_ticks;
-	/*
-	 * pad for cache line alignment of pcpu info
-	 * cache-line-size - number of used bytes
-	 */
-	char   pad[32-(3*sizeof (u_long))];
-} static pcpu_ticks[MAXCPU];
+	uint32_t compare_ticks;
+} __aligned(CACHE_LINE_SIZE);
+
+static struct clk_ticks pcpu_ticks[MAXCPU];
 
 /*
  * Device methods
@@ -260,25 +257,47 @@ clock_intr(void *arg)
 {
 	struct clk_ticks *cpu_ticks;
 	struct trapframe *tf;
-	uint32_t ltick;
+	uint32_t count, compare, delta;
+
+	cpu_ticks = &pcpu_ticks[PCPU_GET(cpuid)];
+
 	/*
 	 * Set next clock edge.
 	 */
-	ltick = mips_rd_count();
-	mips_wr_compare(ltick + cycles_per_tick);
-	cpu_ticks = &pcpu_ticks[PCPU_GET(cpuid)];
+	count = mips_rd_count();
+	compare = cpu_ticks->compare_ticks;
+	cpu_ticks->compare_ticks = count + cycles_per_tick;
+	mips_wr_compare(cpu_ticks->compare_ticks);
 	critical_enter();
-	if (ltick < counter_lower_last) {
+	if (count < counter_lower_last) {
 		counter_upper++;
-		counter_lower_last = ltick;
+		counter_lower_last = count;
 	}
 	/*
 	 * Magic.  Setting up with an arg of NULL means we get passed tf.
 	 */
 	tf = (struct trapframe *)arg;
 
+	delta = cycles_per_tick;
+
+	/*
+	 * Account for the "lost time" between when the timer interrupt fired
+	 * and when 'clock_intr' actually started executing.
+	 */
+	delta += count - compare;
+
+	/*
+	 * If the COUNT and COMPARE registers are no longer in sync then make
+	 * up some reasonable value for the 'delta'.
+	 *
+	 * This could happen, for e.g., after we resume normal operations after
+	 * exiting the debugger.
+	 */
+	if (delta > cycles_per_hz)
+		delta = cycles_per_hz;
+
 	/* Fire hardclock at hz. */
-	cpu_ticks->hard_ticks += cycles_per_tick;
+	cpu_ticks->hard_ticks += delta;
 	if (cpu_ticks->hard_ticks >= cycles_per_hz) {
 	        cpu_ticks->hard_ticks -= cycles_per_hz;
 		if (PCPU_GET(cpuid) == 0)
@@ -288,14 +307,14 @@ clock_intr(void *arg)
 	}
 
 	/* Fire statclock at stathz. */
-	cpu_ticks->stat_ticks += cycles_per_tick;
+	cpu_ticks->stat_ticks += delta;
 	if (cpu_ticks->stat_ticks >= cycles_per_stathz) {
 		cpu_ticks->stat_ticks -= cycles_per_stathz;
 		statclock(USERMODE(tf->sr));
 	}
 
 	/* Fire profclock at profhz, but only when needed. */
-	cpu_ticks->prof_ticks += cycles_per_tick;
+	cpu_ticks->prof_ticks += delta;
 	if (cpu_ticks->prof_ticks >= cycles_per_profhz) {
 		cpu_ticks->prof_ticks -= cycles_per_profhz;
 		if (profprocs != 0)

From 126e94687d4c7090d45149bdf4b00f64472f0038 Mon Sep 17 00:00:00 2001
From: Maxim Konovalov 
Date: Wed, 24 Mar 2010 06:08:51 +0000
Subject: [PATCH 038/119] o FreeBSD 7.3 added.

---
 share/misc/bsd-family-tree | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/share/misc/bsd-family-tree b/share/misc/bsd-family-tree
index 6fb2742f1b2..685667fc888 100644
--- a/share/misc/bsd-family-tree
+++ b/share/misc/bsd-family-tree
@@ -228,14 +228,14 @@ FreeBSD 5.2           |      |                 |                       |
  |  FreeBSD 7.1       |      |                 |                       |
  |     |              |      |                 |                DragonFly 2.2.0
  |  FreeBSD 7.2       |   NetBSD 5.0       OpenBSD 4.5                 |
- |     |              |      |                 |                       |
- |     |              |      |                 |                DragonFly 2.4.0
- |     V              |      |             OpenBSD 4.6                 |
- |                    |      |                 |                       |
- *--FreeBSD           |      |                 |                       |
- |    8.0             |      |                 |                       |
- |     |              |      |                 |                       |
- |     V              |      |                 |                       |
+ |             \      |      |                 |                       |
+ |              |     |      |                 |                DragonFly 2.4.0
+ |              |     |      |             OpenBSD 4.6                 |
+ |              |     |      |                 |                       |
+ *--FreeBSD     |     |      |                 |                       |
+ |    8.0       |     |      |                 |                       |
+ |     |    FreeBSD   |      |                 |                       |
+ |     V      7.3     |      |                 |                       |
  |                    |      |                 |                       |
 FreeBSD 9 -current    |  NetBSD -current  OpenBSD -current             |
  |                    |      |                 |                       |
@@ -511,6 +511,7 @@ FreeBSD 7.2		2009-05-04 [FBD]
 DragonFly 2.4.0		2009-09-16 [DFB]
 OpenBSD 4.6		2009-10-18 [OBD]
 FreeBSD 8.0		2009-11-26 [FBD]
+FreeBSD 7.3		2010-03-23 [FBD]
 
 Bibliography
 ------------------------

From ac33b97078443e3033d9818038abae003dc4aa6a Mon Sep 17 00:00:00 2001
From: Poul-Henning Kamp 
Date: Wed, 24 Mar 2010 11:21:33 +0000
Subject: [PATCH 039/119] Use gpart(8) to set the active boot partition.

---
 tools/tools/nanobsd/Files/root/updatep1 | 2 +-
 tools/tools/nanobsd/Files/root/updatep2 | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/tools/nanobsd/Files/root/updatep1 b/tools/tools/nanobsd/Files/root/updatep1
index 6e094fa2fbb..6b83de530a5 100644
--- a/tools/tools/nanobsd/Files/root/updatep1
+++ b/tools/tools/nanobsd/Files/root/updatep1
@@ -51,4 +51,4 @@ dd of=/dev/${NANO_DRIVE}s1 obs=64k
 # Check that it worked
 fsck_ffs -n /dev/${NANO_DRIVE}s1a
 
-boot0cfg -s 1 -v ${NANO_DRIVE}
+gpart set -a active -i 1 ${NANO_DRIVE}
diff --git a/tools/tools/nanobsd/Files/root/updatep2 b/tools/tools/nanobsd/Files/root/updatep2
index b9067eb7b7c..fc5312be0c4 100644
--- a/tools/tools/nanobsd/Files/root/updatep2
+++ b/tools/tools/nanobsd/Files/root/updatep2
@@ -58,4 +58,4 @@ sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/" /mnt/conf/base/etc/fstab
 sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/" /mnt/etc/fstab
 umount /mnt
 trap 1 2 15 EXIT
-boot0cfg -s 2 -v ${NANO_DRIVE}
+gpart set -a active -i 2 ${NANO_DRIVE}

From acfaf56efee71c2096d071673fa9480ebb62bc5d Mon Sep 17 00:00:00 2001
From: John Baldwin 
Date: Wed, 24 Mar 2010 14:20:37 +0000
Subject: [PATCH 040/119] Add missing Giant locking for the vfsconf list.

Submitted by:	kib
---
 sys/compat/linprocfs/linprocfs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c
index 416efcfeff6..c095012e0d9 100644
--- a/sys/compat/linprocfs/linprocfs.c
+++ b/sys/compat/linprocfs/linprocfs.c
@@ -1235,11 +1235,13 @@ linprocfs_dofilesystems(PFS_FILL_ARGS)
 {
 	struct vfsconf *vfsp;
 
+	mtx_lock(&Giant);
 	TAILQ_FOREACH(vfsp, &vfsconf, vfc_list) {
 		if (vfsp->vfc_flags & VFCF_SYNTHETIC)
 			sbuf_printf(sb, "nodev");
 		sbuf_printf(sb, "\t%s\n", vfsp->vfc_name);
 	}
+	mtx_unlock(&Giant);
 	return(0);
 }
 

From 592a685e337043edc9cbf12c51e300c1994cbd7c Mon Sep 17 00:00:00 2001
From: Luigi Rizzo 
Date: Wed, 24 Mar 2010 15:16:59 +0000
Subject: [PATCH 042/119] Honor ip.fw.one_pass when a packet comes out of a
 pipe without being delayed. I forgot to handle this case when i did the mtag
 cleanup three months ago.

PR:		145004
---
 sys/netinet/ipfw/ip_dn_io.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sys/netinet/ipfw/ip_dn_io.c b/sys/netinet/ipfw/ip_dn_io.c
index 70f14ca65d7..ae168ce86b9 100644
--- a/sys/netinet/ipfw/ip_dn_io.c
+++ b/sys/netinet/ipfw/ip_dn_io.c
@@ -762,7 +762,11 @@ dummynet_io(struct mbuf **m0, int dir, struct ip_fw_args *fwa)
 	 *     
 	 */
 	if (/*dn_cfg.io_fast &&*/ m == *m0 && (dir & PROTO_LAYER2) == 0 ) {
-		/* fast io */
+		/* fast io, rename the tag * to carry reinject info. */
+		struct m_tag *tag = m_tag_first(m);
+
+		tag->m_tag_cookie = MTAG_IPFW_RULE;
+		tag->m_tag_id = 0;
 		io_pkt_fast++;
 		if (m->m_nextpkt != NULL) {
 			printf("dummynet: fast io: pkt chain detected!\n");

From 1e161437f8e1defd8dd87315c7fe14317fd568da Mon Sep 17 00:00:00 2001
From: Jung-uk Kim 
Date: Wed, 24 Mar 2010 15:37:47 +0000
Subject: [PATCH 043/119] Teach VGA framebuffer about 8-bit palette format for
 VESA.

---
 sys/dev/fb/vesa.c |  4 ----
 sys/dev/fb/vga.c  | 24 ++++++++++++++++--------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/sys/dev/fb/vesa.c b/sys/dev/fb/vesa.c
index 733f5b86aa3..0c1d5ddce23 100644
--- a/sys/dev/fb/vesa.c
+++ b/sys/dev/fb/vesa.c
@@ -1370,8 +1370,6 @@ vesa_save_palette(video_adapter_t *adp, u_char *palette)
 		bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
 		if (vesa_bios_save_palette(0, 256, palette, bits) == 0)
 			return (0);
-		if (bits > 6)
-			return (1);
 	}
 
 	return ((*prevvidsw->save_palette)(adp, palette));
@@ -1386,8 +1384,6 @@ vesa_load_palette(video_adapter_t *adp, u_char *palette)
 		bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
 		if (vesa_bios_load_palette(0, 256, palette, bits) == 0)
 			return (0);
-		if (bits > 6)
-			return (1);
 	}
 
 	return ((*prevvidsw->load_palette)(adp, palette));
diff --git a/sys/dev/fb/vga.c b/sys/dev/fb/vga.c
index 7d702ad2b8e..1bcf9350755 100644
--- a/sys/dev/fb/vga.c
+++ b/sys/dev/fb/vga.c
@@ -1979,6 +1979,7 @@ vga_show_font(video_adapter_t *adp, int page)
 static int
 vga_save_palette(video_adapter_t *adp, u_char *palette)
 {
+    int bits;
     int i;
 
     prologue(adp, V_ADP_PALETTE, ENODEV);
@@ -1988,8 +1989,9 @@ vga_save_palette(video_adapter_t *adp, u_char *palette)
      * VGA has 6 bit DAC .
      */
     outb(PALRADR, 0x00);
+    bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 0 : 2;
     for (i = 0; i < 256*3; ++i)
-	palette[i] = inb(PALDATA) << 2; 
+	palette[i] = inb(PALDATA) << bits; 
     inb(adp->va_crtc_addr + 6);	/* reset flip/flop */
     return 0;
 }
@@ -1998,15 +2000,17 @@ static int
 vga_save_palette2(video_adapter_t *adp, int base, int count,
 		  u_char *r, u_char *g, u_char *b)
 {
+    int bits;
     int i;
 
     prologue(adp, V_ADP_PALETTE, ENODEV);
 
     outb(PALRADR, base);
+    bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 0 : 2;
     for (i = 0; i < count; ++i) {
-	r[i] = inb(PALDATA) << 2; 
-	g[i] = inb(PALDATA) << 2; 
-	b[i] = inb(PALDATA) << 2; 
+	r[i] = inb(PALDATA) << bits; 
+	g[i] = inb(PALDATA) << bits; 
+	b[i] = inb(PALDATA) << bits;
     }
     inb(adp->va_crtc_addr + 6);		/* reset flip/flop */
     return 0;
@@ -2021,14 +2025,16 @@ vga_save_palette2(video_adapter_t *adp, int base, int count,
 static int
 vga_load_palette(video_adapter_t *adp, u_char *palette)
 {
+    int bits;
     int i;
 
     prologue(adp, V_ADP_PALETTE, ENODEV);
 
     outb(PIXMASK, 0xff);		/* no pixelmask */
     outb(PALWADR, 0x00);
+    bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 0 : 2;
     for (i = 0; i < 256*3; ++i)
-	outb(PALDATA, palette[i] >> 2);
+	outb(PALDATA, palette[i] >> bits);
     inb(adp->va_crtc_addr + 6);	/* reset flip/flop */
     outb(ATC, 0x20);			/* enable palette */
     return 0;
@@ -2038,16 +2044,18 @@ static int
 vga_load_palette2(video_adapter_t *adp, int base, int count,
 		  u_char *r, u_char *g, u_char *b)
 {
+    int bits;
     int i;
 
     prologue(adp, V_ADP_PALETTE, ENODEV);
 
     outb(PIXMASK, 0xff);		/* no pixelmask */
     outb(PALWADR, base);
+    bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 0 : 2;
     for (i = 0; i < count; ++i) {
-	outb(PALDATA, r[i] >> 2);
-	outb(PALDATA, g[i] >> 2);
-	outb(PALDATA, b[i] >> 2);
+	outb(PALDATA, r[i] >> bits);
+	outb(PALDATA, g[i] >> bits);
+	outb(PALDATA, b[i] >> bits);
     }
     inb(adp->va_crtc_addr + 6);		/* reset flip/flop */
     outb(ATC, 0x20);			/* enable palette */

From c2bce7cc39d27cf8d1d7bc23074f8392d1150405 Mon Sep 17 00:00:00 2001
From: Jung-uk Kim 
Date: Wed, 24 Mar 2010 15:40:18 +0000
Subject: [PATCH 044/119] Align memory access of 24-bit pixel renderer to word
 boundary.

---
 sys/dev/syscons/scvgarndr.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/sys/dev/syscons/scvgarndr.c b/sys/dev/syscons/scvgarndr.c
index 583e51ae9bf..dbee6f200d4 100644
--- a/sys/dev/syscons/scvgarndr.c
+++ b/sys/dev/syscons/scvgarndr.c
@@ -184,8 +184,13 @@ static u_short mouse_or_mask[16] = {
 			writel(pos, vga_palette32[color]);		\
 			break;						\
 		case 24:						\
-			writew(pos, vga_palette32[color]);		\
-			writeb(pos + 2, vga_palette32[color] >> 16);	\
+			if (((pos) & 1) == 0) {				\
+				writew(pos, vga_palette32[color]);	\
+				writeb(pos + 2, vga_palette32[color] >> 16);\
+			} else {					\
+				writeb(pos, vga_palette32[color]);	\
+				writew(pos + 1, vga_palette32[color] >> 8);\
+			}						\
 			break;						\
 		case 16:						\
 			if (scp->sc->adp->va_info.vi_pixel_fsizes[1] == 5)\

From 071ab531db55c850dd0b8688c1cb9f9e0b657757 Mon Sep 17 00:00:00 2001
From: Pietro Cerutti 
Date: Wed, 24 Mar 2010 15:59:51 +0000
Subject: [PATCH 045/119] - Remove const'ness from dlerror(3) prototype, for
 consistency with POSIX.

Approved by:	cognet
MFC after:	1 week
---
 include/dlfcn.h         | 3 +--
 lib/libc/gen/dlfcn.c    | 4 ++--
 lib/libc/gen/dlopen.3   | 2 +-
 libexec/rtld-elf/rtld.c | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/include/dlfcn.h b/include/dlfcn.h
index de654f76a31..794fde109b3 100644
--- a/include/dlfcn.h
+++ b/include/dlfcn.h
@@ -113,8 +113,7 @@ typedef struct  dl_serinfo {
 __BEGIN_DECLS
 /* XSI functions first. */
 int	 dlclose(void *);
-const char *
-	 dlerror(void);
+char	*dlerror(void);
 void	*dlopen(const char *, int);
 void	*dlsym(void * __restrict, const char * __restrict);
 
diff --git a/lib/libc/gen/dlfcn.c b/lib/libc/gen/dlfcn.c
index 4be88475a91..a1ca29daceb 100644
--- a/lib/libc/gen/dlfcn.c
+++ b/lib/libc/gen/dlfcn.c
@@ -34,7 +34,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
-static const char sorry[] = "Service unavailable";
+static char sorry[] = "Service unavailable";
 
 /*
  * For ELF, the dynamic linker directly resolves references to its
@@ -69,7 +69,7 @@ dlclose(void *handle)
 }
 
 #pragma weak dlerror
-const char *
+char *
 dlerror(void)
 {
 	return sorry;
diff --git a/lib/libc/gen/dlopen.3 b/lib/libc/gen/dlopen.3
index 6488befeeb5..d4b111a1002 100644
--- a/lib/libc/gen/dlopen.3
+++ b/lib/libc/gen/dlopen.3
@@ -52,7 +52,7 @@
 .Fn dlsym "void * restrict handle" "const char * restrict symbol"
 .Ft dlfunc_t
 .Fn dlfunc "void * restrict handle" "const char * restrict symbol"
-.Ft const char *
+.Ft char *
 .Fn dlerror "void"
 .Ft int
 .Fn dlclose "void *handle"
diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index d91dcee51a7..cb1002cd8d0 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -1961,7 +1961,7 @@ dlclose(void *handle)
     return 0;
 }
 
-const char *
+char *
 dlerror(void)
 {
     char *msg = error_message;

From 438be77d54fb9c88cfa7aa807f3a79aade725971 Mon Sep 17 00:00:00 2001
From: Shteryana Shopova 
Date: Wed, 24 Mar 2010 16:07:33 +0000
Subject: [PATCH 046/119] Now actually implement reading/refreshing/returning
 data from the pfTablesAddrTable and modify the BEGEMOT-PF-MIB to add support
 for IPV6 address' statistics in the PF tables via pfTablesAddrNetType and
 pfTablesAddrNet. While here, upgrade the pf_tree.def file to the new format
 that includes enumerated values. Also make sure to return SNMP_ERR_NOSUCHNAME
 for ALTQ objects, if ALTQ is disabled, so that the agent will know to skip
 the pfAltq subtree when servicing GETNEXT requests from SNMP clients
 (otherwise snmpwalk on begemotPf would stop at the pfAltq subtree with bsnmpd
 returning SNMP_ERR_GENERR).

---
 .../bsnmpd/modules/snmp_pf/BEGEMOT-PF-MIB.txt |  51 ++--
 usr.sbin/bsnmpd/modules/snmp_pf/Makefile      |   1 +
 usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c     | 289 +++++++++++++++++-
 usr.sbin/bsnmpd/modules/snmp_pf/pf_tree.def   |  33 +-
 4 files changed, 334 insertions(+), 40 deletions(-)

diff --git a/usr.sbin/bsnmpd/modules/snmp_pf/BEGEMOT-PF-MIB.txt b/usr.sbin/bsnmpd/modules/snmp_pf/BEGEMOT-PF-MIB.txt
index 5f395f865f2..0b90bb24dbf 100644
--- a/usr.sbin/bsnmpd/modules/snmp_pf/BEGEMOT-PF-MIB.txt
+++ b/usr.sbin/bsnmpd/modules/snmp_pf/BEGEMOT-PF-MIB.txt
@@ -17,11 +17,13 @@ IMPORTS
 	FROM SNMPv2-SMI
     TruthValue
 	FROM SNMPv2-TC
+    InetAddress, InetAddressType, InetAddressPrefixLength
+	FROM INET-ADDRESS-MIB
     begemot
 	FROM BEGEMOT-MIB;
 
 begemotPf MODULE-IDENTITY
-    LAST-UPDATED "201003170000Z"
+    LAST-UPDATED "201003180000Z"
     ORGANIZATION "NixSys BVBA"
     CONTACT-INFO
 	    "		Philip Paeps
@@ -34,6 +36,12 @@ begemotPf MODULE-IDENTITY
 	     E-Mail:	philip@FreeBSD.org"
     DESCRIPTION
 	    "The Begemot MIB for the pf packet filter."
+    REVISION	"201003180000Z"
+    DESCRIPTION
+		"Modified pfTablesAddrEntry to support IPv6
+		addresses - added pfTablesAddrNetType column
+		and modified type of pfTablesAddrNet to
+		InetAddress."
     REVISION	"200912050000Z"
     DESCRIPTION
 	    "Added support for retrieving counters of labeled
@@ -1025,8 +1033,9 @@ pfTablesAddrEntry OBJECT-TYPE
 
 PfTablesAddrEntry ::= SEQUENCE {
     pfTablesAddrIndex		    Integer32,
-    pfTablesAddrNet		    IpAddress,
-    pfTablesAddrMask		    Integer32,
+    pfTablesAddrNetType		    InetAddressType,
+    pfTablesAddrNet		    InetAddress,
+    pfTablesAddrPrefix		    InetAddressPrefixLength,
     pfTablesAddrTZero		    TimeTicks,
     pfTablesAddrBytesInPass	    Counter64,
     pfTablesAddrBytesInBlock	    Counter64,
@@ -1046,21 +1055,29 @@ pfTablesAddrIndex OBJECT-TYPE
         "A unique value, greater than zero, for each address."
     ::= { pfTablesAddrEntry 1 }
 
+pfTablesAddrNetType OBJECT-TYPE
+    SYNTAX	InetAddressType
+    MAX-ACCESS	read-only
+    STATUS	current
+    DESCRIPTION
+	"The type of address in the corresponding pfTablesAddrNet object."
+    ::= { pfTablesAddrEntry 2 }
+
 pfTablesAddrNet OBJECT-TYPE
-    SYNTAX	IpAddress
+    SYNTAX	InetAddress
     MAX-ACCESS  read-only
     STATUS	current
     DESCRIPTION
         "The IP address of this particular table entry."
-    ::= { pfTablesAddrEntry 2 }
+    ::= { pfTablesAddrEntry 3 }
 
-pfTablesAddrMask OBJECT-TYPE
-    SYNTAX	Integer32 (0..32)
+pfTablesAddrPrefix OBJECT-TYPE
+    SYNTAX	InetAddressPrefixLength
     MAX-ACCESS  read-only
     STATUS	current
     DESCRIPTION
         "The CIDR netmask of this particular table entry."
-    ::= { pfTablesAddrEntry 3 }
+    ::= { pfTablesAddrEntry 4 }
 
 pfTablesAddrTZero OBJECT-TYPE
     SYNTAX	TimeTicks
@@ -1071,7 +1088,7 @@ pfTablesAddrTZero OBJECT-TYPE
         "The time passed since this entry's statistics were last
 	cleared, or the time passed since this entry was loaded
 	into the table, whichever is sooner."
-    ::= { pfTablesAddrEntry 4 }
+    ::= { pfTablesAddrEntry 5 }
 
 pfTablesAddrBytesInPass OBJECT-TYPE
     SYNTAX	Counter64
@@ -1079,7 +1096,7 @@ pfTablesAddrBytesInPass OBJECT-TYPE
     STATUS	current
     DESCRIPTION
         "The number of inbound bytes passed as a result of this entry."
-    ::= { pfTablesAddrEntry 5 }
+    ::= { pfTablesAddrEntry 6 }
 
 pfTablesAddrBytesInBlock OBJECT-TYPE
     SYNTAX	Counter64
@@ -1087,7 +1104,7 @@ pfTablesAddrBytesInBlock OBJECT-TYPE
     STATUS	current
     DESCRIPTION
         "The number of inbound bytes blocked as a result of this entry."
-    ::= { pfTablesAddrEntry 6 }
+    ::= { pfTablesAddrEntry 7 }
 
 pfTablesAddrBytesOutPass OBJECT-TYPE
     SYNTAX	Counter64
@@ -1095,7 +1112,7 @@ pfTablesAddrBytesOutPass OBJECT-TYPE
     STATUS	current
     DESCRIPTION
         "The number of outbound bytes passed as a result of this entry."
-    ::= { pfTablesAddrEntry 7 }
+    ::= { pfTablesAddrEntry 8 }
 
 pfTablesAddrBytesOutBlock OBJECT-TYPE
     SYNTAX	Counter64
@@ -1103,7 +1120,7 @@ pfTablesAddrBytesOutBlock OBJECT-TYPE
     STATUS	current
     DESCRIPTION
         "The number of outbound bytes blocked as a result of this entry."
-    ::= { pfTablesAddrEntry 8 }
+    ::= { pfTablesAddrEntry 9 }
 
 pfTablesAddrPktsInPass OBJECT-TYPE
     SYNTAX	Counter64
@@ -1111,7 +1128,7 @@ pfTablesAddrPktsInPass OBJECT-TYPE
     STATUS	current
     DESCRIPTION
         "The number of inbound packets passed as a result of this entry."
-    ::= { pfTablesAddrEntry 9 }
+    ::= { pfTablesAddrEntry 10 }
 
 pfTablesAddrPktsInBlock OBJECT-TYPE
     SYNTAX	Counter64
@@ -1119,7 +1136,7 @@ pfTablesAddrPktsInBlock OBJECT-TYPE
     STATUS	current
     DESCRIPTION
         "The number of inbound packets blocked as a result of this entry."
-    ::= { pfTablesAddrEntry 10 }
+    ::= { pfTablesAddrEntry 11 }
 
 pfTablesAddrPktsOutPass OBJECT-TYPE
     SYNTAX	Counter64
@@ -1127,7 +1144,7 @@ pfTablesAddrPktsOutPass OBJECT-TYPE
     STATUS	current
     DESCRIPTION
         "The number of outbound packets passed as a result of this entry."
-    ::= { pfTablesAddrEntry 11 }
+    ::= { pfTablesAddrEntry 12 }
 
 pfTablesAddrPktsOutBlock OBJECT-TYPE
     SYNTAX	Counter64
@@ -1136,7 +1153,7 @@ pfTablesAddrPktsOutBlock OBJECT-TYPE
     DESCRIPTION
         "The number of outbound packets blocked as a result of this
         entry."
-    ::= { pfTablesAddrEntry 12 }
+    ::= { pfTablesAddrEntry 13 }
 
 -- --------------------------------------------------------------------------
 
diff --git a/usr.sbin/bsnmpd/modules/snmp_pf/Makefile b/usr.sbin/bsnmpd/modules/snmp_pf/Makefile
index 92b0a4ba912..6218932187e 100644
--- a/usr.sbin/bsnmpd/modules/snmp_pf/Makefile
+++ b/usr.sbin/bsnmpd/modules/snmp_pf/Makefile
@@ -4,6 +4,7 @@
 
 MOD=	pf
 SRCS=	pf_snmp.c
+CFLAGS+= -DSNMPTREE_TYPES
 
 XSYM=	begemotPf
 DEFS=	${MOD}_tree.def
diff --git a/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c b/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c
index 4e915f427ee..c7178f3775c 100644
--- a/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c
+++ b/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c
@@ -85,6 +85,19 @@ static int pft_table_count;
 
 #define PFT_TABLE_MAXAGE	5
 
+struct pfa_entry {
+	struct pfr_astats pfas;
+	u_int		index;
+	TAILQ_ENTRY(pfa_entry) link;
+};
+TAILQ_HEAD(pfa_table, pfa_entry);
+
+static struct pfa_table pfa_table;
+static time_t pfa_table_age;
+static int pfa_table_count;
+
+#define	PFA_TABLE_MAXAGE	5
+
 struct pfq_entry {
 	struct pf_altq	altq;
 	u_int		index;
@@ -121,10 +134,12 @@ static int pfi_refresh(void);
 static int pfq_refresh(void);
 static int pfs_refresh(void);
 static int pft_refresh(void);
+static int pfa_refresh(void);
 static int pfl_refresh(void);
 static struct pfi_entry * pfi_table_find(u_int idx);
 static struct pfq_entry * pfq_table_find(u_int idx);
 static struct pft_entry * pft_table_find(u_int idx);
+static struct pfa_entry * pfa_table_find(u_int idx);
 static struct pfl_entry * pfl_table_find(u_int idx);
 
 static int altq_is_enabled(int pfdevice);
@@ -794,7 +809,98 @@ int
 pf_tbladdr(struct snmp_context __unused *ctx, struct snmp_value __unused *val,
 	u_int __unused sub, u_int __unused vindex, enum snmp_op __unused op)
 {
-	return (SNMP_ERR_GENERR);
+	asn_subid_t	which = val->var.subs[sub - 1];
+	struct pfa_entry *e = NULL;
+
+	if ((time(NULL) - pfa_table_age) > PFA_TABLE_MAXAGE)
+		pfa_refresh();
+
+	switch (op) {
+		case SNMP_OP_SET:
+			return (SNMP_ERR_NOT_WRITEABLE);
+		case SNMP_OP_GETNEXT:
+			if ((e = NEXT_OBJECT_INT(&pfa_table,
+			    &val->var, sub)) == NULL)
+				return (SNMP_ERR_NOSUCHNAME);
+			val->var.len = sub + 1;
+			val->var.subs[sub] = e->index;
+			break;
+		case SNMP_OP_GET:
+			if (val->var.len - sub != 1)
+				return (SNMP_ERR_NOSUCHNAME);
+			if ((e = pfa_table_find(val->var.subs[sub])) == NULL)
+				return (SNMP_ERR_NOSUCHNAME);
+			break;
+
+		case SNMP_OP_COMMIT:
+		case SNMP_OP_ROLLBACK:
+		default:
+			abort();
+	}
+
+	switch (which) {
+		case LEAF_pfTablesAddrNetType:
+			if (e->pfas.pfras_a.pfra_af == AF_INET)
+				val->v.integer = pfTablesAddrNetType_ipv4;
+			else if (e->pfas.pfras_a.pfra_af == AF_INET6)
+				val->v.integer = pfTablesAddrNetType_ipv6;
+			else
+				return (SNMP_ERR_GENERR);
+			break;
+		case LEAF_pfTablesAddrNet:
+			if (e->pfas.pfras_a.pfra_af == AF_INET) {
+				return (string_get(val,
+				    (u_char *)&e->pfas.pfras_a.pfra_ip4addr, 4));
+			} else if (e->pfas.pfras_a.pfra_af == AF_INET6)
+				return (string_get(val,
+				    (u_char *)&e->pfas.pfras_a.pfra_ip6addr, 16));
+			else
+				return (SNMP_ERR_GENERR);
+			break;
+		case LEAF_pfTablesAddrPrefix:
+			val->v.integer = (int32_t) e->pfas.pfras_a.pfra_net;
+			break;
+		case LEAF_pfTablesAddrTZero:
+			val->v.uint32 =
+			    (time(NULL) - e->pfas.pfras_tzero) * 100;
+			break;
+		case LEAF_pfTablesAddrBytesInPass:
+			val->v.counter64 =
+			    e->pfas.pfras_bytes[PFR_DIR_IN][PFR_OP_PASS];
+			break;
+		case LEAF_pfTablesAddrBytesInBlock:
+			val->v.counter64 =
+			    e->pfas.pfras_bytes[PFR_DIR_IN][PFR_OP_BLOCK];
+			break;
+		case LEAF_pfTablesAddrBytesOutPass:
+			val->v.counter64 =
+			    e->pfas.pfras_bytes[PFR_DIR_OUT][PFR_OP_PASS];
+			break;
+		case LEAF_pfTablesAddrBytesOutBlock:
+			val->v.counter64 =
+			    e->pfas.pfras_bytes[PFR_DIR_OUT][PFR_OP_BLOCK];
+			break;
+		case LEAF_pfTablesAddrPktsInPass:
+			val->v.counter64 =
+			    e->pfas.pfras_packets[PFR_DIR_IN][PFR_OP_PASS];
+			break;
+		case LEAF_pfTablesAddrPktsInBlock:
+			val->v.counter64 =
+			    e->pfas.pfras_packets[PFR_DIR_IN][PFR_OP_BLOCK];
+			break;
+		case LEAF_pfTablesAddrPktsOutPass:
+			val->v.counter64 =
+			    e->pfas.pfras_packets[PFR_DIR_OUT][PFR_OP_PASS];
+			break;
+		case LEAF_pfTablesAddrPktsOutBlock:
+			val->v.counter64 =
+			    e->pfas.pfras_packets[PFR_DIR_OUT][PFR_OP_BLOCK];
+			break;
+		default:
+			return (SNMP_ERR_NOSUCHNAME);
+	}
+
+	return (SNMP_ERR_NOERROR);
 }
 
 int
@@ -803,9 +909,8 @@ pf_altq(struct snmp_context __unused *ctx, struct snmp_value *val,
 {
 	asn_subid_t	which = val->var.subs[sub - 1];
 
-	if (!altq_enabled) {
-	   return (SNMP_ERR_NOERROR);
-	}
+	if (!altq_enabled)
+	   return (SNMP_ERR_NOSUCHNAME);
 
 	if (op == SNMP_OP_SET)
 		return (SNMP_ERR_NOT_WRITEABLE);
@@ -838,9 +943,8 @@ pf_altqq(struct snmp_context __unused *ctx, struct snmp_value *val,
 	asn_subid_t	which = val->var.subs[sub - 1];
 	struct pfq_entry *e = NULL;
 
-	if (!altq_enabled) {
-	   return (SNMP_ERR_NOERROR);
-	}
+	if (!altq_enabled)
+	   return (SNMP_ERR_NOSUCHNAME);
 
 	if ((time(NULL) - pfq_table_age) > PFQ_TABLE_MAXAGE)
 		pfq_refresh();
@@ -1014,6 +1118,17 @@ pft_table_find(u_int idx)
 	return (NULL);
 }
 
+static struct pfa_entry *
+pfa_table_find(u_int idx)
+{
+	struct pfa_entry *e;
+
+	TAILQ_FOREACH(e, &pfa_table, link)
+		if (e->index == idx)
+			return (e);
+	return (NULL);
+}
+
 static struct pfl_entry *
 pfl_table_find(u_int idx)
 {
@@ -1248,6 +1363,149 @@ err2:
 	return(-1);
 }
 
+static int
+pfa_table_addrs(u_int sidx, struct pfr_table *pt)
+{
+	struct pfioc_table io;
+	struct pfr_astats *t = NULL;
+	struct pfa_entry *e;
+	int i, numaddrs = 1;
+
+	if (pt == NULL)
+		return (-1);
+
+	memset(&io, 0, sizeof(io));
+	strlcpy(io.pfrio_table.pfrt_name, pt->pfrt_name,
+	    sizeof(io.pfrio_table.pfrt_name));
+
+	for (;;) {
+		t = reallocf(t, numaddrs * sizeof(struct pfr_astats));
+		if (t == NULL) {
+			syslog(LOG_ERR, "pfa_table_addrs(): reallocf(): %s",
+			    strerror(errno));
+			numaddrs = -1;
+			goto error;
+		}
+
+		memset(t, 0, sizeof(*t));
+		io.pfrio_size = numaddrs;
+		io.pfrio_buffer = t;
+		io.pfrio_esize = sizeof(struct pfr_astats);
+
+		if (ioctl(dev, DIOCRGETASTATS, &io)) {
+			syslog(LOG_ERR, "pfa_table_addrs(): ioctl() on %s: %s",
+			    pt->pfrt_name, strerror(errno));
+			numaddrs = -1;
+			break;
+		}
+
+		if (numaddrs >= io.pfrio_size)
+			break;
+
+		numaddrs = io.pfrio_size;
+	}
+
+	for (i = 0; i < numaddrs; i++) {
+		if ((t + i)->pfras_a.pfra_af != AF_INET &&
+		    (t + i)->pfras_a.pfra_af != AF_INET6) {
+			numaddrs = i;
+			break;
+		}
+
+		e = (struct pfa_entry *)malloc(sizeof(struct pfa_entry));
+		if (e == NULL) {
+			syslog(LOG_ERR, "pfa_table_addrs(): malloc(): %s",
+			    strerror(errno));
+			numaddrs = -1;
+			break;
+		}
+		e->index = sidx + i;
+		memcpy(&e->pfas, t + i, sizeof(struct pfr_astats));
+		TAILQ_INSERT_TAIL(&pfa_table, e, link);
+	}
+
+	free(t);
+error:
+	return (numaddrs);
+}
+
+static int
+pfa_refresh(void)
+{
+	struct pfioc_table io;
+	struct pfr_table *pt = NULL, *it = NULL;
+	struct pfa_entry *e;
+	int i, numtbls = 1, cidx, naddrs;
+
+	if (started && this_tick <= pf_tick)
+		return (0);
+
+	while (!TAILQ_EMPTY(&pfa_table)) {
+		e = TAILQ_FIRST(&pfa_table);
+		TAILQ_REMOVE(&pfa_table, e, link);
+		free(e);
+	}
+
+	memset(&io, 0, sizeof(io));
+	io.pfrio_esize = sizeof(struct pfr_table);
+
+	for (;;) {
+		pt = reallocf(pt, numtbls * sizeof(struct pfr_table));
+		if (pt == NULL) {
+			syslog(LOG_ERR, "pfa_refresh(): reallocf() %s",
+			    strerror(errno));
+			return (-1);
+		}
+		memset(pt, 0, sizeof(*pt));
+		io.pfrio_size = numtbls;
+		io.pfrio_buffer = pt;
+
+		if (ioctl(dev, DIOCRGETTABLES, &io)) {
+			syslog(LOG_ERR, "pfa_refresh(): ioctl(): %s",
+			    strerror(errno));
+			goto err2;
+		}
+
+		if (numtbls >= io.pfrio_size)
+			break;
+
+		numtbls = io.pfrio_size;
+	}
+
+	cidx = 1;
+
+	for (it = pt, i = 0; i < numtbls; it++, i++) {
+		/*
+		 * Skip the table if not active - ioctl(DIOCRGETASTATS) will
+		 * return ESRCH for this entry anyway.
+		 */
+		if (!(it->pfrt_flags & PFR_TFLAG_ACTIVE))
+			continue;
+
+		if ((naddrs = pfa_table_addrs(cidx, it)) < 0)
+			goto err1;
+
+		cidx += naddrs;
+	}
+
+	pfa_table_age = time(NULL);
+	pfa_table_count = cidx;
+	pf_tick = this_tick;
+
+	free(pt);
+	return (0);
+err1:
+	while (!TAILQ_EMPTY(&pfa_table)) {
+		e = TAILQ_FIRST(&pfa_table);
+		TAILQ_REMOVE(&pfa_table, e, link);
+		free(e);
+	}
+
+err2:
+	free(pt);
+	return (-1);
+}
+
 static int
 pfl_scan_ruleset(const char *path)
 {
@@ -1423,6 +1681,7 @@ pf_init(struct lmodule *mod, int __unused argc, char __unused *argv[])
 	TAILQ_INIT(&pfi_table);
 	TAILQ_INIT(&pfq_table);
 	TAILQ_INIT(&pft_table);
+	TAILQ_INIT(&pfa_table);
 	TAILQ_INIT(&pfl_table);
 
 	pfi_refresh();
@@ -1432,6 +1691,7 @@ pf_init(struct lmodule *mod, int __unused argc, char __unused *argv[])
 
 	pfs_refresh();
 	pft_refresh();
+	pfa_refresh();
 	pfl_refresh();
 
 	started = 1;
@@ -1445,6 +1705,7 @@ pf_fini(void)
 	struct pfi_entry *i1, *i2;
 	struct pfq_entry *q1, *q2;
 	struct pft_entry *t1, *t2;
+	struct pfa_entry *a1, *a2;
 	struct pfl_entry *l1, *l2;
 
 	/* Empty the list of interfaces */
@@ -1471,6 +1732,14 @@ pf_fini(void)
 		t1 = t2;
 	}
 
+	/* List of table addresses */
+	a1 = TAILQ_FIRST(&pfa_table);
+	while (a1 != NULL) {
+		a2 = TAILQ_NEXT(a1, link);
+		free(a1);
+		a1 = a2;
+	}
+
 	/* And the list of labeled filter rules */
 	l1 = TAILQ_FIRST(&pfl_table);
 	while (l1 != NULL) {
@@ -1491,6 +1760,7 @@ pf_dump(void)
 		pfq_refresh();
 	}
 	pft_refresh();
+	pfa_refresh();
 	pfl_refresh();
 
 	syslog(LOG_ERR, "Dump: pfi_table_age = %jd",
@@ -1508,6 +1778,11 @@ pf_dump(void)
 	syslog(LOG_ERR, "Dump: pft_table_count = %d",
 	    pft_table_count);
 
+	syslog(LOG_ERR, "Dump: pfa_table_age = %jd",
+	    (intmax_t)pfa_table_age);
+	syslog(LOG_ERR, "Dump: pfa_table_count = %d",
+	    pfa_table_count);
+
 	syslog(LOG_ERR, "Dump: pfl_table_age = %jd",
 	    (intmax_t)pfl_table_age);
 	syslog(LOG_ERR, "Dump: pfl_table_count = %d",
diff --git a/usr.sbin/bsnmpd/modules/snmp_pf/pf_tree.def b/usr.sbin/bsnmpd/modules/snmp_pf/pf_tree.def
index f7833eb1dae..7b791b3bd3e 100644
--- a/usr.sbin/bsnmpd/modules/snmp_pf/pf_tree.def
+++ b/usr.sbin/bsnmpd/modules/snmp_pf/pf_tree.def
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2005 Philip Paeps 
+# Copyright (c) 2010 Philip Paeps 
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -34,9 +34,9 @@
           (200 begemotPf
             (1 begemotPfObjects
               (1 pfStatus
-                (1 pfStatusRunning INTEGER pf_status GET)
+                (1 pfStatusRunning ENUM ( 1 true 2 false ) pf_status GET)
                 (2 pfStatusRuntime TIMETICKS pf_status GET)
-                (3 pfStatusDebug INTEGER pf_status GET)
+                (3 pfStatusDebug ENUM ( 0 none 1 urgent 2 misc 3 loud ) pf_status GET)
                 (4 pfStatusHostId OCTETSTRING pf_status GET)
               )
               (2 pfCounter
@@ -106,7 +106,7 @@
                   (1 pfInterfacesIfEntry : INTEGER32 pf_iftable
                     (1 pfInterfacesIfIndex INTEGER32)
                     (2 pfInterfacesIfDescr OCTETSTRING GET)
-                    (3 pfInterfacesIfType INTEGER GET)
+                    (3 pfInterfacesIfType ENUM ( 0 group 1 instance 2 detached ) GET)
 		    (4 pfInterfacesIfTZero TIMETICKS GET)
                     (5 pfInterfacesIfRefsState UNSIGNED32 GET)
                     (6 pfInterfacesIfRefsRule UNSIGNED32 GET)
@@ -158,17 +158,18 @@
 		(3 pfTablesAddrTable
 		  (1 pfTablesAddrEntry : INTEGER32 pf_tbladdr
 		    (1 pfTablesAddrIndex INTEGER32)
-		    (2 pfTablesAddrNet IPADDRESS GET)
-		    (3 pfTablesAddrMask INTEGER32 GET)
-		    (4 pfTablesAddrTZero TIMETICKS GET)
-		    (5 pfTablesAddrBytesInPass COUNTER64 GET)
-		    (6 pfTablesAddrBytesInBlock COUNTER64 GET)
-		    (7 pfTablesAddrBytesOutPass COUNTER64 GET)
-		    (8 pfTablesAddrBytesOutBlock COUNTER64 GET)
-		    (9 pfTablesAddrPktsInPass COUNTER64 GET)
-		    (10 pfTablesAddrPktsInBlock COUNTER64 GET)
-		    (11 pfTablesAddrPktsOutPass COUNTER64 GET)
-		    (12 pfTablesAddrPktsOutBlock COUNTER64 GET)
+		    (2 pfTablesAddrNetType ENUM ( 0 unknown 1 ipv4 2 ipv6) GET)
+		    (3 pfTablesAddrNet OCTETSTRING | InetAddress GET)
+		    (4 pfTablesAddrPrefix UNSIGNED32 GET)
+		    (5 pfTablesAddrTZero TIMETICKS GET)
+		    (6 pfTablesAddrBytesInPass COUNTER64 GET)
+		    (7 pfTablesAddrBytesInBlock COUNTER64 GET)
+		    (8 pfTablesAddrBytesOutPass COUNTER64 GET)
+		    (9 pfTablesAddrBytesOutBlock COUNTER64 GET)
+		    (10 pfTablesAddrPktsInPass COUNTER64 GET)
+		    (11 pfTablesAddrPktsInBlock COUNTER64 GET)
+		    (12 pfTablesAddrPktsOutPass COUNTER64 GET)
+		    (13 pfTablesAddrPktsOutBlock COUNTER64 GET)
 		  )
 		)
 	      )
@@ -179,7 +180,7 @@
 		    (1 pfAltqQueueIndex INTEGER32)
 		    (2 pfAltqQueueDescr OCTETSTRING GET)
 		    (3 pfAltqQueueParent OCTETSTRING GET)
-		    (4 pfAltqQueueScheduler INTEGER GET)
+		    (4 pfAltqQueueScheduler ENUM ( 1 cbq 8 hfsc 11 priq ) GET)
 		    (5 pfAltqQueueBandwidth UNSIGNED32 GET)
 		    (6 pfAltqQueuePriority INTEGER32 GET)
 		    (7 pfAltqQueueLimit INTEGER32 GET)

From a5be8eb53064374754863fc2f713d8602e52ecef Mon Sep 17 00:00:00 2001
From: Alexander Motin 
Date: Wed, 24 Mar 2010 18:04:25 +0000
Subject: [PATCH 047/119] Do not fetch precise time of request start when stats
 collection disabled.

Reviewed by:	pjd, phk
---
 sys/geom/geom_io.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sys/geom/geom_io.c b/sys/geom/geom_io.c
index 0b6525e79e8..931b7c30338 100644
--- a/sys/geom/geom_io.c
+++ b/sys/geom/geom_io.c
@@ -443,7 +443,10 @@ g_io_request(struct bio *bp, struct g_consumer *cp)
 	    ("Bio already on queue bp=%p", bp));
 	bp->bio_flags |= BIO_ONQUEUE;
 
-	binuptime(&bp->bio_t0);
+	if (g_collectstats)
+		binuptime(&bp->bio_t0);
+	else
+		getbinuptime(&bp->bio_t0);
 
 	/*
 	 * The statistics collection is lockless, as such, but we

From a9b8ae9a0ca587d2c9c848ecdb067be7173abac0 Mon Sep 17 00:00:00 2001
From: Luigi Rizzo 
Date: Wed, 24 Mar 2010 18:35:31 +0000
Subject: [PATCH 048/119] make the module loadable

Submitted by:	Marcin Wisnicki
---
 sys/modules/dummynet/Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/modules/dummynet/Makefile b/sys/modules/dummynet/Makefile
index c25a7a7b0f4..a8813e277d1 100644
--- a/sys/modules/dummynet/Makefile
+++ b/sys/modules/dummynet/Makefile
@@ -5,6 +5,8 @@
 .PATH:  ${.CURDIR}/../../netinet/ipfw
 KMOD=   dummynet
 SRCS=   ip_dummynet.c
+SRCS+= ip_dn_glue.c ip_dn_io.c
+SRCS+= dn_heap.c dn_sched_fifo.c dn_sched_qfq.c dn_sched_rr.c dn_sched_wf2q.c 
 SRCS+=	opt_inet6.h
 
 .if !defined(KERNBUILDDIR)

From e56900fc9fb203e010ef50b141b7cf70c33bdaff Mon Sep 17 00:00:00 2001
From: Xin LI 
Date: Wed, 24 Mar 2010 18:40:57 +0000
Subject: [PATCH 049/119] Expose MACHINE_CPU while building lib32 target.

---
 Makefile.inc1 | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Makefile.inc1 b/Makefile.inc1
index 03b9b4fa9a5..a772e2861e3 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -283,6 +283,7 @@ LIB32WMAKEENV=	MAKEOBJDIRPREFIX=${OBJTREE}/lib32 \
 		VERSION="${VERSION}" \
 		MACHINE=i386 \
 		MACHINE_ARCH=i386 \
+		MACHINE_CPU="i686 mmx sse sse2" \
 		INSTALL="sh ${.CURDIR}/tools/install.sh" \
 		PATH=${TMPPATH} \
 		CC="${CC} ${LIB32FLAGS}" \

From 2430ab4629cf52c4ed920099365bd2a20c82694a Mon Sep 17 00:00:00 2001
From: "Bjoern A. Zeeb" 
Date: Wed, 24 Mar 2010 19:21:26 +0000
Subject: [PATCH 050/119] Print the pointer to the lock with the panic message.
 The previous 	panic: rw lock not unlocked was not really helpful for
 debugging. Now one can at least call 	show lock  form ddb to learn more
 about the lock.

MFC after:	3 days
---
 sys/kern/kern_rwlock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c
index c1f13e05862..81b4c5f3dcb 100644
--- a/sys/kern/kern_rwlock.c
+++ b/sys/kern/kern_rwlock.c
@@ -199,8 +199,8 @@ void
 rw_destroy(struct rwlock *rw)
 {
 
-	KASSERT(rw->rw_lock == RW_UNLOCKED, ("rw lock not unlocked"));
-	KASSERT(rw->rw_recurse == 0, ("rw lock still recursed"));
+	KASSERT(rw->rw_lock == RW_UNLOCKED, ("rw lock %p not unlocked", rw));
+	KASSERT(rw->rw_recurse == 0, ("rw lock %p still recursed", rw));
 	rw->rw_lock = RW_DESTROYED;
 	lock_destroy(&rw->lock_object);
 }

From 77acdc25650eec0e709bfe7bb6581763923e4e7b Mon Sep 17 00:00:00 2001
From: Randall Stewart 
Date: Wed, 24 Mar 2010 19:45:36 +0000
Subject: [PATCH 051/119] Fix for NR-Sack code. The code was NOT working
 properly when enabled. Basically most of the operations were incorrect
 causing bad sacks when you enabled nr-sack. The fixes range across 4 files
 and unifiy most of the processing so that we only test nr_sack flags to
 decide which type of sack to generate.

Optimization left for this is to combine the sack generation
code and make it capable of generating either sack thus shrinking
out a routine.

Reviewed by:	tuexen@freebsd.org
---
 sys/netinet/sctp_indata.c | 717 +++++++-------------------------------
 sys/netinet/sctp_input.c  |  30 +-
 sys/netinet/sctp_output.c |  72 ++--
 sys/netinet/sctputil.c    |  40 ++-
 4 files changed, 193 insertions(+), 666 deletions(-)

diff --git a/sys/netinet/sctp_indata.c b/sys/netinet/sctp_indata.c
index 65eb08642f5..243d773723d 100644
--- a/sys/netinet/sctp_indata.c
+++ b/sys/netinet/sctp_indata.c
@@ -46,24 +46,13 @@ __FBSDID("$FreeBSD$");
 #include 
 
 #define SCTP_CALC_TSN_TO_GAP(gap, tsn, mapping_tsn) do { \
-					if ((compare_with_wrap(tsn, mapping_tsn, MAX_TSN)) || \
-                        (tsn == mapping_tsn)) { \
+	                if (tsn >= mapping_tsn) { \
 						gap = tsn - mapping_tsn; \
 					} else { \
 						gap = (MAX_TSN - mapping_tsn) + tsn + 1; \
 					} \
                   } while(0)
 
-#define SCTP_REVERSE_OUT_TSN_PRES(nr_gap, tsn, asoc) do { \
-                    if (asoc->mapping_array_base_tsn == asoc->nr_mapping_array_base_tsn) { \
-                       SCTP_UNSET_TSN_PRESENT(asoc->mapping_array, nr_gap); \
-                    } else {\
-                       int lgap; \
-                       SCTP_CALC_TSN_TO_GAP(lgap, tsn, asoc->mapping_array_base_tsn); \
-                       SCTP_UNSET_TSN_PRESENT(asoc->mapping_array, lgap); \
-                    } \
-                  } while(0)
-
 /*
  * NOTES: On the outbound side of things I need to check the sack timer to
  * see if I should generate a sack into the chunk queue (if I have data to
@@ -304,6 +293,44 @@ sctp_build_ctl_cchunk(struct sctp_inpcb *inp,
 	return (buf);
 }
 
+static void
+sctp_mark_non_revokable(struct sctp_association *asoc, uint32_t tsn)
+{
+	uint32_t gap, i;
+	int fnd = 0;
+
+	if (SCTP_BASE_SYSCTL(sctp_do_drain) == 0) {
+		return;
+	}
+	SCTP_CALC_TSN_TO_GAP(gap, tsn, asoc->mapping_array_base_tsn);
+#ifdef INVARIANTS
+	if (!SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap)) {
+		printf("gap:%x tsn:%x\n", gap, tsn);
+		sctp_print_mapping_array(asoc);
+		panic("Things are really messed up now!!");
+	}
+#endif
+	SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap);
+	SCTP_UNSET_TSN_PRESENT(asoc->mapping_array, gap);
+	if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) {
+		asoc->highest_tsn_inside_nr_map = tsn;
+	}
+	if (tsn == asoc->highest_tsn_inside_map) {
+		/* We must back down to see what the new highest is */
+		for (i = tsn - 1; compare_with_wrap(i, asoc->mapping_array_base_tsn, MAX_TSN); i--) {
+			SCTP_CALC_TSN_TO_GAP(gap, i, asoc->mapping_array_base_tsn);
+			if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap)) {
+				asoc->highest_tsn_inside_map = i;
+				fnd = 1;
+				break;
+			}
+		}
+		if (!fnd) {
+			asoc->highest_tsn_inside_map = asoc->mapping_array_base_tsn - 1;
+		}
+	}
+}
+
 
 /*
  * We are delivering currently from the reassembly queue. We must continue to
@@ -319,9 +346,6 @@ sctp_service_reassembly(struct sctp_tcb *stcb, struct sctp_association *asoc)
 	int end = 0;
 	int cntDel;
 
-	/* EY if any out-of-order delivered, then tag it nr on nr_map */
-	uint32_t nr_tsn, nr_gap;
-
 	struct sctp_queued_to_read *control, *ctl, *ctlat;
 
 	if (stcb == NULL)
@@ -430,39 +454,7 @@ abandon:
 		}
 		/* pull it we did it */
 		TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next);
-		/*
-		 * EY this is the chunk that should be tagged nr gapped
-		 * calculate the gap and such then tag this TSN nr
-		 * chk->rec.data.TSN_seq
-		 */
-		/*
-		 * EY!-TODO- this tsn should be tagged nr only if it is
-		 * out-of-order, the if statement should be modified
-		 */
-		if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) &&
-		    asoc->peer_supports_nr_sack) {
-			nr_tsn = chk->rec.data.TSN_seq;
-			SCTP_CALC_TSN_TO_GAP(nr_gap, nr_tsn, asoc->nr_mapping_array_base_tsn);
-			if ((nr_gap >= (uint32_t) (asoc->nr_mapping_array_size << 3))) {
-				/*
-				 * EY The 1st should never happen, as in
-				 * process_a_data_chunk method this check
-				 * should be done
-				 */
-				/*
-				 * EY The 2nd should never happen, because
-				 * nr_mapping_array is always expanded when
-				 * mapping_array is expanded
-				 */
-				printf("Impossible nr_gap ack range failed\n");
-			} else {
-				SCTP_TCB_LOCK_ASSERT(stcb);
-				SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap);
-				SCTP_REVERSE_OUT_TSN_PRES(nr_gap, nr_tsn, asoc);
-				if (compare_with_wrap(nr_tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN))
-					asoc->highest_tsn_inside_nr_map = nr_tsn;
-			}
-		}
+		sctp_mark_non_revokable(asoc, chk->rec.data.TSN_seq);
 		if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) {
 			asoc->fragmented_delivery_inprogress = 0;
 			if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) {
@@ -509,67 +501,11 @@ abandon:
 						asoc->size_on_all_streams -= ctl->length;
 						sctp_ucount_decr(asoc->cnt_on_all_streams);
 						strm->last_sequence_delivered++;
-						/*
-						 * EY will be used to
-						 * calculate nr-gap
-						 */
-						nr_tsn = ctl->sinfo_tsn;
 						sctp_add_to_readq(stcb->sctp_ep, stcb,
 						    ctl,
 						    &stcb->sctp_socket->so_rcv, 1,
 						    SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED);
-						/*
-						 * EY -now something is
-						 * delivered, calculate
-						 * nr_gap and tag this tsn
-						 * NR
-						 */
-						if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) &&
-						    asoc->peer_supports_nr_sack) {
-							SCTP_CALC_TSN_TO_GAP(nr_gap, nr_tsn, asoc->nr_mapping_array_base_tsn);
-							if ((nr_gap >= (SCTP_NR_MAPPING_ARRAY << 3)) ||
-							    (nr_gap >= (uint32_t) (asoc->nr_mapping_array_size << 3))) {
-								/*
-								 * EY The
-								 * 1st
-								 * should
-								 * never
-								 * happen,
-								 * as in
-								 * process_a_
-								 * data_chunk
-								 *  method
-								 * this
-								 * check
-								 * should be
-								 * done
-								 */
-								/*
-								 * EY The
-								 * 2nd
-								 * should
-								 * never
-								 * happen,
-								 * because
-								 * nr_mapping
-								 * _array is
-								 * always
-								 * expanded
-								 * when
-								 * mapping_ar
-								 * ray is
-								 * expanded
-								 */
-							} else {
-								SCTP_TCB_LOCK_ASSERT(stcb);
-								SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap);
-								SCTP_REVERSE_OUT_TSN_PRES(nr_gap, nr_tsn, asoc);
-								if (compare_with_wrap(nr_tsn,
-								    asoc->highest_tsn_inside_nr_map,
-								    MAX_TSN))
-									asoc->highest_tsn_inside_nr_map = nr_tsn;
-							}
-						}
+						sctp_mark_non_revokable(asoc, ctl->sinfo_tsn);
 						ctl = ctlat;
 					} else {
 						break;
@@ -618,9 +554,6 @@ sctp_queue_data_to_stream(struct sctp_tcb *stcb, struct sctp_association *asoc,
 	uint16_t nxt_todel;
 	struct mbuf *oper;
 
-	/* EY- will be used to calculate nr-gap for a tsn */
-	uint32_t nr_tsn, nr_gap;
-
 	queue_needed = 1;
 	asoc->size_on_all_streams += control->length;
 	sctp_ucount_incr(asoc->cnt_on_all_streams);
@@ -682,41 +615,12 @@ protocol_error:
 		asoc->size_on_all_streams -= control->length;
 		sctp_ucount_decr(asoc->cnt_on_all_streams);
 		strm->last_sequence_delivered++;
-		/* EY will be used to calculate nr-gap */
-		nr_tsn = control->sinfo_tsn;
+
 		sctp_add_to_readq(stcb->sctp_ep, stcb,
 		    control,
 		    &stcb->sctp_socket->so_rcv, 1,
 		    SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED);
-		/*
-		 * EY this is the chunk that should be tagged nr gapped
-		 * calculate the gap and such then tag this TSN nr
-		 * chk->rec.data.TSN_seq
-		 */
-		if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) &&
-		    asoc->peer_supports_nr_sack) {
-			SCTP_CALC_TSN_TO_GAP(nr_gap, nr_tsn, asoc->nr_mapping_array_base_tsn);
-			if ((nr_gap >= (SCTP_NR_MAPPING_ARRAY << 3)) ||
-			    (nr_gap >= (uint32_t) (asoc->nr_mapping_array_size << 3))) {
-				printf("Impossible nr_tsn set 2?\n");
-				/*
-				 * EY The 1st should never happen, as in
-				 * process_a_data_chunk method this check
-				 * should be done
-				 */
-				/*
-				 * EY The 2nd should never happen, because
-				 * nr_mapping_array is always expanded when
-				 * mapping_array is expanded
-				 */
-			} else {
-				SCTP_TCB_LOCK_ASSERT(stcb);
-				SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap);
-				SCTP_REVERSE_OUT_TSN_PRES(nr_gap, nr_tsn, asoc);
-				if (compare_with_wrap(nr_tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN))
-					asoc->highest_tsn_inside_nr_map = nr_tsn;
-			}
-		}
+		sctp_mark_non_revokable(asoc, control->sinfo_tsn);
 		control = TAILQ_FIRST(&strm->inqueue);
 		while (control != NULL) {
 			/* all delivered */
@@ -738,47 +642,12 @@ protocol_error:
 					    SCTP_STR_LOG_FROM_IMMED_DEL);
 				}
 				/* EY will be used to calculate nr-gap */
-				nr_tsn = control->sinfo_tsn;
 				sctp_add_to_readq(stcb->sctp_ep, stcb,
 				    control,
 				    &stcb->sctp_socket->so_rcv, 1,
 				    SCTP_READ_LOCK_NOT_HELD,
 				    SCTP_SO_NOT_LOCKED);
-				/*
-				 * EY this is the chunk that should be
-				 * tagged nr gapped calculate the gap and
-				 * such then tag this TSN nr
-				 * chk->rec.data.TSN_seq
-				 */
-				if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) &&
-				    asoc->peer_supports_nr_sack) {
-					SCTP_CALC_TSN_TO_GAP(nr_gap, nr_tsn, asoc->nr_mapping_array_base_tsn);
-					if ((nr_gap >= (SCTP_NR_MAPPING_ARRAY << 3)) ||
-					    (nr_gap >= (uint32_t) (asoc->nr_mapping_array_size << 3))) {
-						/*
-						 * EY The 1st should never
-						 * happen, as in
-						 * process_a_data_chunk
-						 * method this check should
-						 * be done
-						 */
-						/*
-						 * EY The 2nd should never
-						 * happen, because
-						 * nr_mapping_array is
-						 * always expanded when
-						 * mapping_array is expanded
-						 */
-					} else {
-						SCTP_TCB_LOCK_ASSERT(stcb);
-						SCTP_REVERSE_OUT_TSN_PRES(nr_gap, nr_tsn, asoc);
-						SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap);
-						if (compare_with_wrap(nr_tsn,
-						    asoc->highest_tsn_inside_nr_map,
-						    MAX_TSN))
-							asoc->highest_tsn_inside_nr_map = nr_tsn;
-					}
-				}
+				sctp_mark_non_revokable(asoc, control->sinfo_tsn);
 				control = at;
 				continue;
 			}
@@ -1586,9 +1455,6 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
 	/* struct sctp_tmit_chunk *chk; */
 	struct sctp_tmit_chunk *chk;
 	uint32_t tsn, gap;
-
-	/* EY - for nr_sack */
-	uint32_t nr_gap;
 	struct mbuf *dmbuf;
 	int indx, the_len;
 	int need_reasm_check = 0;
@@ -1640,14 +1506,12 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
 			return (0);
 		}
 	}
-	/* EY - for nr_sack */
-	nr_gap = gap;
-
 	if (compare_with_wrap(tsn, *high_tsn, MAX_TSN)) {
 		*high_tsn = tsn;
 	}
 	/* See if we have received this one already */
-	if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap)) {
+	if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap) ||
+	    SCTP_IS_TSN_PRESENT(asoc->nr_mapping_array, gap)) {
 		SCTP_STAT_INCR(sctps_recvdupdata);
 		if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) {
 			/* Record a dup for the next outbound sack */
@@ -1714,7 +1578,8 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
 #endif
 		}
 		/* now is it in the mapping array of what we have accepted? */
-		if (compare_with_wrap(tsn, asoc->highest_tsn_inside_map, MAX_TSN)) {
+		if (compare_with_wrap(tsn, asoc->highest_tsn_inside_map, MAX_TSN) &&
+		    compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) {
 			/* Nope not in the valid range dump it */
 			sctp_set_rwnd(stcb, asoc);
 			if ((asoc->cnt_on_all_streams +
@@ -1758,23 +1623,10 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
 		}
 		SCTP_STAT_INCR(sctps_badsid);
 		SCTP_TCB_LOCK_ASSERT(stcb);
-		SCTP_SET_TSN_PRESENT(asoc->mapping_array, gap);
-		/* EY set this tsn present in  nr_sack's nr_mapping_array */
-		if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) &&
-		    asoc->peer_supports_nr_sack) {
-			SCTP_TCB_LOCK_ASSERT(stcb);
-			SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap);
-			SCTP_REVERSE_OUT_TSN_PRES(gap, tsn, asoc);
-		}
-		if (compare_with_wrap(tsn, asoc->highest_tsn_inside_map, MAX_TSN)) {
-			/* we have a new high score */
-			asoc->highest_tsn_inside_map = tsn;
-			/* EY nr_sack version of the above */
-			if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack)
-				asoc->highest_tsn_inside_nr_map = tsn;
-			if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) {
-				sctp_log_map(0, 2, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT);
-			}
+
+		SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap);
+		if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) {
+			asoc->highest_tsn_inside_nr_map = tsn;
 		}
 		if (tsn == (asoc->cumulative_tsn + 1)) {
 			/* Update cum-ack */
@@ -1925,48 +1777,6 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
 		    control, &stcb->sctp_socket->so_rcv,
 		    1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED);
 
-		/*
-		 * EY here I should check if this delivered tsn is
-		 * out_of_order, if yes then update the nr_map
-		 */
-		if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) {
-			/*
-			 * EY check if the mapping_array and nr_mapping
-			 * array are consistent
-			 */
-			if (asoc->mapping_array_base_tsn != asoc->nr_mapping_array_base_tsn)
-				/*
-				 * printf("EY-IN
-				 * sctp_process_a_data_chunk(5): Something
-				 * is wrong the map base tsn" "\nEY-and
-				 * nr_map base tsn should be equal.");
-				 */
-				/* EY debugging block */
-			{
-				/*
-				 * printf("\nEY-Calculating an
-				 * nr_gap!!\nmapping_array_size = %d
-				 * nr_mapping_array_size = %d"
-				 * "\nEY-mapping_array_base = %d
-				 * nr_mapping_array_base =
-				 * %d\nEY-highest_tsn_inside_map = %d"
-				 * "highest_tsn_inside_nr_map = %d\nEY-TSN =
-				 * %d nr_gap = %d",asoc->mapping_array_size,
-				 * asoc->nr_mapping_array_size,
-				 * asoc->mapping_array_base_tsn,
-				 * asoc->nr_mapping_array_base_tsn,
-				 * asoc->highest_tsn_inside_map,
-				 * asoc->highest_tsn_inside_nr_map,tsn,nr_gap
-				 * );
-				 */
-			}
-			/* EY - not %100 sure about the lock thing */
-			SCTP_TCB_LOCK_ASSERT(stcb);
-			SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap);
-			SCTP_REVERSE_OUT_TSN_PRES(nr_gap, tsn, asoc);
-			if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN))
-				asoc->highest_tsn_inside_nr_map = tsn;
-		}
 		if ((chunk_flags & SCTP_DATA_UNORDERED) == 0) {
 			/* for ordered, bump what we delivered */
 			asoc->strmin[strmno].last_sequence_delivered++;
@@ -1977,6 +1787,10 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
 			    SCTP_STR_LOG_FROM_EXPRS_DEL);
 		}
 		control = NULL;
+		SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap);
+		if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) {
+			asoc->highest_tsn_inside_nr_map = tsn;
+		}
 		goto finish_express_del;
 	}
 failed_express_del:
@@ -2012,39 +1826,9 @@ failed_express_del:
 				SCTP_PRINTF("Append fails end:%d\n", end);
 				goto failed_pdapi_express_del;
 			}
-			/*
-			 * EY It is appended to the read queue in prev if
-			 * block here I should check if this delivered tsn
-			 * is out_of_order, if yes then update the nr_map
-			 */
-			if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) &&
-			    asoc->peer_supports_nr_sack) {
-				/* EY debugging block */
-				{
-					/*
-					 * printf("\nEY-Calculating an
-					 * nr_gap!!\nEY-mapping_array_size =
-					 * %d nr_mapping_array_size = %d"
-					 * "\nEY-mapping_array_base = %d
-					 * nr_mapping_array_base =
-					 * %d\nEY-highest_tsn_inside_map =
-					 * %d" "highest_tsn_inside_nr_map =
-					 * %d\nEY-TSN = %d nr_gap =
-					 * %d",asoc->mapping_array_size,
-					 * asoc->nr_mapping_array_size,
-					 * asoc->mapping_array_base_tsn,
-					 * asoc->nr_mapping_array_base_tsn,
-					 * asoc->highest_tsn_inside_map,
-					 * asoc->highest_tsn_inside_nr_map,ts
-					 * n,nr_gap);
-					 */
-				}
-				/* EY - not %100 sure about the lock thing */
-				SCTP_TCB_LOCK_ASSERT(stcb);
-				SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap);
-				SCTP_REVERSE_OUT_TSN_PRES(nr_gap, tsn, asoc);
-				if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN))
-					asoc->highest_tsn_inside_nr_map = tsn;
+			SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap);
+			if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) {
+				asoc->highest_tsn_inside_nr_map = tsn;
 			}
 			SCTP_STAT_INCR(sctps_recvexpressm);
 			control->sinfo_tsn = tsn;
@@ -2069,12 +1853,27 @@ failed_express_del:
 					need_reasm_check = 1;
 				}
 			}
+			SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap);
+			if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) {
+				asoc->highest_tsn_inside_nr_map = tsn;
+			}
 			control = NULL;
 			goto finish_express_del;
 		}
 	}
 failed_pdapi_express_del:
 	control = NULL;
+	if (SCTP_BASE_SYSCTL(sctp_do_drain) == 0) {
+		SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap);
+		if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) {
+			asoc->highest_tsn_inside_nr_map = tsn;
+		}
+	} else {
+		SCTP_SET_TSN_PRESENT(asoc->mapping_array, gap);
+		if (compare_with_wrap(tsn, asoc->highest_tsn_inside_map, MAX_TSN)) {
+			asoc->highest_tsn_inside_map = tsn;
+		}
+	}
 	if ((chunk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) {
 		sctp_alloc_a_chunk(stcb, chk);
 		if (chk == NULL) {
@@ -2263,56 +2062,7 @@ failed_pdapi_express_del:
 			sctp_add_to_readq(stcb->sctp_ep, stcb,
 			    control,
 			    &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED);
-			/*
-			 * EY It is added to the read queue in prev if block
-			 * here I should check if this delivered tsn is
-			 * out_of_order, if yes then update the nr_map
-			 */
-			if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) &&
-			    asoc->peer_supports_nr_sack) {
-				/*
-				 * EY check if the mapping_array and
-				 * nr_mapping array are consistent
-				 */
-				if (asoc->mapping_array_base_tsn != asoc->nr_mapping_array_base_tsn)
-					/*
-					 * printf("EY-IN
-					 * sctp_process_a_data_chunk(6):
-					 * Something is wrong the map base
-					 * tsn" "\nEY-and nr_map base tsn
-					 * should be equal.");
-					 */
-					/*
-					 * EY - not %100 sure about the lock
-					 * thing, i think we don't need the
-					 * below,
-					 */
-					/* SCTP_TCB_LOCK_ASSERT(stcb); */
-				{
-					/*
-					 * printf("\nEY-Calculating an
-					 * nr_gap!!\nEY-mapping_array_size =
-					 * %d nr_mapping_array_size = %d"
-					 * "\nEY-mapping_array_base = %d
-					 * nr_mapping_array_base =
-					 * %d\nEY-highest_tsn_inside_map =
-					 * %d" "highest_tsn_inside_nr_map =
-					 * %d\nEY-TSN = %d nr_gap =
-					 * %d",asoc->mapping_array_size,
-					 * asoc->nr_mapping_array_size,
-					 * asoc->mapping_array_base_tsn,
-					 * asoc->nr_mapping_array_base_tsn,
-					 * asoc->highest_tsn_inside_map,
-					 * asoc->highest_tsn_inside_nr_map,ts
-					 * n,nr_gap);
-					 */
-				}
-				SCTP_TCB_LOCK_ASSERT(stcb);
-				SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap);
-				SCTP_REVERSE_OUT_TSN_PRES(nr_gap, tsn, asoc);
-				if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN))
-					asoc->highest_tsn_inside_nr_map = tsn;
-			}
+
 		} else {
 			/*
 			 * Special check for when streams are resetting. We
@@ -2384,13 +2134,6 @@ failed_pdapi_express_del:
 		}
 	}
 finish_express_del:
-	if (compare_with_wrap(tsn, asoc->highest_tsn_inside_map, MAX_TSN)) {
-		/* we have a new high score */
-		asoc->highest_tsn_inside_map = tsn;
-		if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) {
-			sctp_log_map(0, 2, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT);
-		}
-	}
 	if (tsn == (asoc->cumulative_tsn + 1)) {
 		/* Update cum-ack */
 		asoc->cumulative_tsn = tsn;
@@ -2412,22 +2155,6 @@ finish_express_del:
 		sctp_log_map(asoc->mapping_array_base_tsn, asoc->cumulative_tsn,
 		    asoc->highest_tsn_inside_map, SCTP_MAP_PREPARE_SLIDE);
 	}
-	SCTP_TCB_LOCK_ASSERT(stcb);
-	SCTP_SET_TSN_PRESENT(asoc->mapping_array, gap);
-
-	/*
-	 * EY - set tsn present in nr-map if  doing nr-sacks and the tsn is
-	 * non-renegable
-	 */
-	if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) &&
-	    asoc->peer_supports_nr_sack &&
-	    (SCTP_BASE_SYSCTL(sctp_do_drain) == 0)) {
-		SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap);
-		SCTP_REVERSE_OUT_TSN_PRES(nr_gap, tsn, asoc);
-		if (compare_with_wrap(tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)) {
-			asoc->highest_tsn_inside_nr_map = tsn;
-		}
-	}
 	/* check the special flag for stream resets */
 	if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) &&
 	    ((compare_with_wrap(asoc->cumulative_tsn, liste->tsn, MAX_TSN)) ||
@@ -2532,7 +2259,6 @@ sctp_sack_check(struct sctp_tcb *stcb, int ok_to_sack, int was_a_gap, int *abort
 	 */
 	struct sctp_association *asoc;
 	int at;
-	uint8_t comb_byte;
 	int last_all_ones = 0;
 	int slide_from, slide_end, lgap, distance;
 
@@ -2540,7 +2266,7 @@ sctp_sack_check(struct sctp_tcb *stcb, int ok_to_sack, int was_a_gap, int *abort
 	/* int nr_at; */
 	/* int nr_last_all_ones = 0; */
 	/* int nr_slide_from, nr_slide_end, nr_lgap, nr_distance; */
-	uint32_t old_cumack, old_base, old_highest;
+	uint32_t old_cumack, old_base, old_highest, highest_tsn;
 
 	asoc = &stcb->asoc;
 	at = 0;
@@ -2553,30 +2279,23 @@ sctp_sack_check(struct sctp_tcb *stcb, int ok_to_sack, int was_a_gap, int *abort
 	 * offset of the current cum-ack as the starting point.
 	 */
 	at = 0;
-	for (slide_from = 0; slide_from < stcb->asoc.mapping_array_size; slide_from++) {
-		/*
-		 * We must combine the renegable and non-renegable arrays
-		 * here to form a unified view of what is acked right now
-		 * (since they are kept separate
-		 */
-		comb_byte = asoc->mapping_array[slide_from] | asoc->nr_mapping_array[slide_from];
-		if (comb_byte == 0xff) {
+	for (slide_from = 0; slide_from < stcb->asoc.nr_mapping_array_size; slide_from++) {
+		if (asoc->nr_mapping_array[slide_from] == 0xff) {
 			at += 8;
 			last_all_ones = 1;
 		} else {
 			/* there is a 0 bit */
-			at += sctp_map_lookup_tab[comb_byte];
+			at += sctp_map_lookup_tab[asoc->nr_mapping_array[slide_from]];
 			last_all_ones = 0;
 			break;
 		}
 	}
-	asoc->cumulative_tsn = asoc->mapping_array_base_tsn + (at - last_all_ones);
-	/* at is one off, since in the table a embedded -1 is present */
+	asoc->cumulative_tsn = asoc->nr_mapping_array_base_tsn + (at - last_all_ones);
 	at++;
 
-	if (compare_with_wrap(asoc->cumulative_tsn,
-	    asoc->highest_tsn_inside_map,
-	    MAX_TSN)) {
+	if (compare_with_wrap(asoc->cumulative_tsn, asoc->highest_tsn_inside_map, MAX_TSN) &&
+	    compare_with_wrap(asoc->cumulative_tsn, asoc->highest_tsn_inside_nr_map, MAX_TSN)
+	    ) {
 #ifdef INVARIANTS
 		panic("huh, cumack 0x%x greater than high-tsn 0x%x in map",
 		    asoc->cumulative_tsn, asoc->highest_tsn_inside_map);
@@ -2591,37 +2310,29 @@ sctp_sack_check(struct sctp_tcb *stcb, int ok_to_sack, int was_a_gap, int *abort
 		asoc->highest_tsn_inside_nr_map = asoc->cumulative_tsn;
 #endif
 	}
-	if ((asoc->cumulative_tsn == asoc->highest_tsn_inside_map) && (at >= 8)) {
+	if (compare_with_wrap(asoc->highest_tsn_inside_nr_map,
+	    asoc->highest_tsn_inside_map,
+	    MAX_TSN)) {
+		highest_tsn = asoc->highest_tsn_inside_nr_map;
+	} else {
+		highest_tsn = asoc->highest_tsn_inside_map;
+	}
+	if ((asoc->cumulative_tsn == highest_tsn) && (at >= 8)) {
 		/* The complete array was completed by a single FR */
-		/* higest becomes the cum-ack */
+		/* highest becomes the cum-ack */
 		int clr;
 
-		asoc->cumulative_tsn = asoc->highest_tsn_inside_map;
 		/* clear the array */
 		clr = (at >> 3) + 1;
 		if (clr > asoc->mapping_array_size) {
 			clr = asoc->mapping_array_size;
 		}
 		memset(asoc->mapping_array, 0, clr);
-		/* base becomes one ahead of the cum-ack */
+		memset(asoc->nr_mapping_array, 0, clr);
+
 		asoc->mapping_array_base_tsn = asoc->cumulative_tsn + 1;
-
-		if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) {
-
-			if (clr > asoc->nr_mapping_array_size)
-				clr = asoc->nr_mapping_array_size;
-
-			memset(asoc->nr_mapping_array, 0, clr);
-			/* base becomes one ahead of the cum-ack */
-			asoc->nr_mapping_array_base_tsn = asoc->cumulative_tsn + 1;
-			asoc->highest_tsn_inside_nr_map = asoc->cumulative_tsn;
-		}
-		if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) {
-			sctp_log_map(old_base, old_cumack, old_highest,
-			    SCTP_MAP_PREPARE_SLIDE);
-			sctp_log_map(asoc->mapping_array_base_tsn, asoc->cumulative_tsn,
-			    asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_CLEARED);
-		}
+		asoc->nr_mapping_array_base_tsn = asoc->cumulative_tsn + 1;
+		asoc->highest_tsn_inside_nr_map = asoc->highest_tsn_inside_map = asoc->cumulative_tsn;
 	} else if (at >= 8) {
 		/* we can slide the mapping array down */
 		/* slide_from holds where we hit the first NON 0xff byte */
@@ -2630,19 +2341,15 @@ sctp_sack_check(struct sctp_tcb *stcb, int ok_to_sack, int was_a_gap, int *abort
 		 * now calculate the ceiling of the move using our highest
 		 * TSN value
 		 */
-		if (asoc->highest_tsn_inside_map >= asoc->mapping_array_base_tsn) {
-			lgap = asoc->highest_tsn_inside_map -
-			    asoc->mapping_array_base_tsn;
-		} else {
-			lgap = (MAX_TSN - asoc->mapping_array_base_tsn) +
-			    asoc->highest_tsn_inside_map + 1;
-		}
-		slide_end = lgap >> 3;
+		SCTP_CALC_TSN_TO_GAP(lgap, highest_tsn, asoc->mapping_array_base_tsn);
+		slide_end = (lgap >> 3);
 		if (slide_end < slide_from) {
+			sctp_print_mapping_array(asoc);
 #ifdef INVARIANTS
 			panic("impossible slide");
 #else
-			printf("impossible slide?\n");
+			printf("impossible slide lgap:%x slide_end:%x slide_from:%x? at:%d\n",
+			    lgap, slide_end, slide_from, at);
 			return;
 #endif
 		}
@@ -2682,30 +2389,21 @@ sctp_sack_check(struct sctp_tcb *stcb, int ok_to_sack, int was_a_gap, int *abort
 			for (ii = 0; ii < distance; ii++) {
 				asoc->mapping_array[ii] =
 				    asoc->mapping_array[slide_from + ii];
+				asoc->nr_mapping_array[ii] =
+				    asoc->nr_mapping_array[slide_from + ii];
+
 			}
 			for (ii = distance; ii <= slide_end; ii++) {
 				asoc->mapping_array[ii] = 0;
+				asoc->nr_mapping_array[ii] = 0;
 			}
 			asoc->mapping_array_base_tsn += (slide_from << 3);
+			asoc->nr_mapping_array_base_tsn += (slide_from << 3);
 			if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) {
 				sctp_log_map(asoc->mapping_array_base_tsn,
 				    asoc->cumulative_tsn, asoc->highest_tsn_inside_map,
 				    SCTP_MAP_SLIDE_RESULT);
 			}
-			/*
-			 * EY if doing nr_sacks then slide the
-			 * nr_mapping_array accordingly please
-			 */
-			if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) {
-				for (ii = 0; ii < distance; ii++) {
-					asoc->nr_mapping_array[ii] =
-					    asoc->nr_mapping_array[slide_from + ii];
-				}
-				for (ii = distance; ii <= slide_end; ii++) {
-					asoc->nr_mapping_array[ii] = 0;
-				}
-				asoc->nr_mapping_array_base_tsn += (slide_from << 3);
-			}
 		}
 	}
 	/*
@@ -2736,8 +2434,7 @@ sctp_sack_check(struct sctp_tcb *stcb, int ok_to_sack, int was_a_gap, int *abort
 			int is_a_gap;
 
 			/* is there a gap now ? */
-			is_a_gap = compare_with_wrap(stcb->asoc.highest_tsn_inside_map,
-			    stcb->asoc.cumulative_tsn, MAX_TSN);
+			is_a_gap = compare_with_wrap(highest_tsn, stcb->asoc.cumulative_tsn, MAX_TSN);
 
 			/*
 			 * CMT DAC algorithm: increase number of packets
@@ -5742,9 +5439,6 @@ sctp_kick_prsctp_reorder_queue(struct sctp_tcb *stcb,
 	struct sctp_association *asoc;
 	int tt;
 
-	/* EY -used to calculate nr_gap information */
-	uint32_t nr_tsn, nr_gap;
-
 	asoc = &stcb->asoc;
 	tt = strmin->last_sequence_delivered;
 	/*
@@ -5764,82 +5458,10 @@ sctp_kick_prsctp_reorder_queue(struct sctp_tcb *stcb,
 			/* deliver it to at least the delivery-q */
 			if (stcb->sctp_socket) {
 				/* EY need the tsn info for calculating nr */
-				nr_tsn = ctl->sinfo_tsn;
 				sctp_add_to_readq(stcb->sctp_ep, stcb,
 				    ctl,
 				    &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_HELD, SCTP_SO_NOT_LOCKED);
-				/*
-				 * EY this is the chunk that should be
-				 * tagged nr gapped calculate the gap and
-				 * such then tag this TSN nr
-				 * chk->rec.data.TSN_seq
-				 */
-				if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) &&
-				    asoc->peer_supports_nr_sack) {
-					SCTP_CALC_TSN_TO_GAP(nr_gap, nr_tsn, asoc->nr_mapping_array_base_tsn);
-					if ((nr_gap >= (SCTP_NR_MAPPING_ARRAY << 3)) ||
-					    (nr_gap >= (uint32_t) (asoc->nr_mapping_array_size << 3))) {
-						/*
-						 * EY These should never
-						 * happen- explained before
-						 */
-					} else {
-						SCTP_TCB_LOCK_ASSERT(stcb);
-						SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap);
-						SCTP_REVERSE_OUT_TSN_PRES(nr_gap, nr_tsn, asoc);
-						if (compare_with_wrap(nr_tsn,
-						    asoc->highest_tsn_inside_nr_map,
-						    MAX_TSN))
-							asoc->highest_tsn_inside_nr_map = nr_tsn;
-					}
-					if (!SCTP_IS_TSN_PRESENT(asoc->mapping_array, nr_gap))
-						/*
-						 * printf("In
-						 * sctp_kick_prsctp_reorder_q
-						 * ueue(7): Something wrong,
-						 * the TSN to be tagged"
-						 * "\nas NR is not even in
-						 * the mapping_array, or map
-						 * and nr_map are
-						 * inconsistent");
-						 */
-						/*
-						 * EY - not %100 sure about
-						 * the lock thing, don't
-						 * think its required
-						 */
-						/*
-						 * SCTP_TCB_LOCK_ASSERT(stcb)
-						 * ;
-						 */
-					{
-						/*
-						 * printf("\nCalculating an
-						 * nr_gap!!\nmapping_array_si
-						 * ze = %d
-						 * nr_mapping_array_size =
-						 * %d" "\nmapping_array_base
-						 * = %d
-						 * nr_mapping_array_base =
-						 * %d\nhighest_tsn_inside_map
-						 *  = %d"
-						 * "highest_tsn_inside_nr_map
-						 *  = %d\nTSN = %d nr_gap =
-						 * %d",asoc->mapping_array_si
-						 * ze,
-						 * asoc->nr_mapping_array_siz
-						 * e,
-						 * asoc->mapping_array_base_t
-						 * sn,
-						 * asoc->nr_mapping_array_bas
-						 * e_tsn,
-						 * asoc->highest_tsn_inside_m
-						 * ap,
-						 * asoc->highest_tsn_inside_n
-						 * r_map,tsn,nr_gap);
-						 */
-					}
-				}
+				sctp_mark_non_revokable(asoc, ctl->sinfo_tsn);
 			}
 		} else {
 			/* no more delivery now. */
@@ -5864,82 +5486,11 @@ sctp_kick_prsctp_reorder_queue(struct sctp_tcb *stcb,
 			/* deliver it to at least the delivery-q */
 			strmin->last_sequence_delivered = ctl->sinfo_ssn;
 			if (stcb->sctp_socket) {
-				/* EY */
-				nr_tsn = ctl->sinfo_tsn;
 				sctp_add_to_readq(stcb->sctp_ep, stcb,
 				    ctl,
 				    &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_HELD, SCTP_SO_NOT_LOCKED);
-				/*
-				 * EY this is the chunk that should be
-				 * tagged nr gapped calculate the gap and
-				 * such then tag this TSN nr
-				 * chk->rec.data.TSN_seq
-				 */
-				if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) &&
-				    asoc->peer_supports_nr_sack) {
-					SCTP_CALC_TSN_TO_GAP(nr_gap, nr_tsn, asoc->nr_mapping_array_base_tsn);
-					if ((nr_gap >= (SCTP_NR_MAPPING_ARRAY << 3)) ||
-					    (nr_gap >= (uint32_t) (asoc->nr_mapping_array_size << 3))) {
-						/*
-						 * EY These should never
-						 * happen, explained before
-						 */
-					} else {
-						SCTP_TCB_LOCK_ASSERT(stcb);
-						SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, nr_gap);
-						SCTP_REVERSE_OUT_TSN_PRES(nr_gap, nr_tsn, asoc);
-						if (compare_with_wrap(nr_tsn, asoc->highest_tsn_inside_nr_map,
-						    MAX_TSN))
-							asoc->highest_tsn_inside_nr_map = nr_tsn;
-					}
-					if (!SCTP_IS_TSN_PRESENT(asoc->mapping_array, nr_gap))
-						/*
-						 * printf("In
-						 * sctp_kick_prsctp_reorder_q
-						 * ueue(8): Something wrong,
-						 * the TSN to be tagged"
-						 * "\nas NR is not even in
-						 * the mapping_array, or map
-						 * and nr_map are
-						 * inconsistent");
-						 */
-						/*
-						 * EY - not %100 sure about
-						 * the lock thing, don't
-						 * think its required
-						 */
-						/*
-						 * SCTP_TCB_LOCK_ASSERT(stcb)
-						 * ;
-						 */
-					{
-						/*
-						 * printf("\nCalculating an
-						 * nr_gap!!\nmapping_array_si
-						 * ze = %d
-						 * nr_mapping_array_size =
-						 * %d" "\nmapping_array_base
-						 * = %d
-						 * nr_mapping_array_base =
-						 * %d\nhighest_tsn_inside_map
-						 *  = %d"
-						 * "highest_tsn_inside_nr_map
-						 *  = %d\nTSN = %d nr_gap =
-						 * %d",asoc->mapping_array_si
-						 * ze,
-						 * asoc->nr_mapping_array_siz
-						 * e,
-						 * asoc->mapping_array_base_t
-						 * sn,
-						 * asoc->nr_mapping_array_bas
-						 * e_tsn,
-						 * asoc->highest_tsn_inside_m
-						 * ap,
-						 * asoc->highest_tsn_inside_n
-						 * r_map,tsn,nr_gap);
-						 */
-					}
-				}
+				sctp_mark_non_revokable(asoc, ctl->sinfo_tsn);
+
 			}
 			tt = strmin->last_sequence_delivered + 1;
 		} else {
@@ -6096,25 +5647,19 @@ sctp_handle_forward_tsn(struct sctp_tcb *stcb,
 	if (compare_with_wrap(new_cum_tsn, asoc->highest_tsn_inside_map,
 	    MAX_TSN)) {
 		asoc->highest_tsn_inside_map = new_cum_tsn;
-		/* EY nr_mapping_array version of the above */
-		/*
-		 * if(SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) &&
-		 * asoc->peer_supports_nr_sack)
-		 */
+
+	}
+	if (compare_with_wrap(new_cum_tsn, asoc->highest_tsn_inside_nr_map,
+	    MAX_TSN)) {
 		asoc->highest_tsn_inside_nr_map = new_cum_tsn;
-		if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) {
-			sctp_log_map(0, 0, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT);
-		}
 	}
 	/*
 	 * now we know the new TSN is more advanced, let's find the actual
 	 * gap
 	 */
-	SCTP_CALC_TSN_TO_GAP(gap, new_cum_tsn, asoc->mapping_array_base_tsn);
+	SCTP_CALC_TSN_TO_GAP(gap, new_cum_tsn, asoc->nr_mapping_array_base_tsn);
+	asoc->cumulative_tsn = new_cum_tsn;
 	if (gap >= m_size) {
-		if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) {
-			sctp_log_map(0, 0, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT);
-		}
 		if ((long)gap > sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv)) {
 			struct mbuf *oper;
 
@@ -6147,23 +5692,15 @@ sctp_handle_forward_tsn(struct sctp_tcb *stcb,
 			return;
 		}
 		SCTP_STAT_INCR(sctps_fwdtsn_map_over);
+
 		memset(stcb->asoc.mapping_array, 0, stcb->asoc.mapping_array_size);
-		cumack_set_flag = 1;
 		asoc->mapping_array_base_tsn = new_cum_tsn + 1;
-		asoc->cumulative_tsn = asoc->highest_tsn_inside_map = new_cum_tsn;
-		/* EY - nr_sack: nr_mapping_array version of the above */
-		if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) {
-			memset(stcb->asoc.nr_mapping_array, 0, stcb->asoc.nr_mapping_array_size);
-			asoc->nr_mapping_array_base_tsn = new_cum_tsn + 1;
-			asoc->highest_tsn_inside_nr_map = new_cum_tsn;
-			if (asoc->nr_mapping_array_size != asoc->mapping_array_size) {
-				/*
-				 * printf("IN sctp_handle_forward_tsn:
-				 * Something is wrong the size of" "map and
-				 * nr_map should be equal!")
-				 */ ;
-			}
-		}
+		asoc->highest_tsn_inside_map = new_cum_tsn;
+
+		memset(stcb->asoc.nr_mapping_array, 0, stcb->asoc.nr_mapping_array_size);
+		asoc->nr_mapping_array_base_tsn = new_cum_tsn + 1;
+		asoc->highest_tsn_inside_nr_map = new_cum_tsn;
+
 		if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) {
 			sctp_log_map(0, 3, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT);
 		}
@@ -6171,12 +5708,8 @@ sctp_handle_forward_tsn(struct sctp_tcb *stcb,
 	} else {
 		SCTP_TCB_LOCK_ASSERT(stcb);
 		for (i = 0; i <= gap; i++) {
-			if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack
-			    && SCTP_BASE_SYSCTL(sctp_do_drain) == 0) {
-				SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, i);
-			} else {
-				SCTP_SET_TSN_PRESENT(asoc->mapping_array, i);
-			}
+			SCTP_UNSET_TSN_PRESENT(asoc->mapping_array, i);
+			SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, i);
 		}
 		/*
 		 * Now after marking all, slide thing forward but no sack
diff --git a/sys/netinet/sctp_input.c b/sys/netinet/sctp_input.c
index ef187377b95..07518e42cf9 100644
--- a/sys/netinet/sctp_input.c
+++ b/sys/netinet/sctp_input.c
@@ -1860,9 +1860,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
 			memset(asoc->mapping_array, 0,
 			    asoc->mapping_array_size);
 		}
-		/* EY 05/13/08 - nr_sack version of the above if statement */
-		if (asoc->nr_mapping_array && SCTP_BASE_SYSCTL(sctp_nr_sack_on_off)
-		    && asoc->peer_supports_nr_sack) {
+		if (asoc->nr_mapping_array) {
 			memset(asoc->nr_mapping_array, 0,
 			    asoc->nr_mapping_array_size);
 		}
@@ -3515,16 +3513,10 @@ sctp_handle_stream_reset_response(struct sctp_tcb *stcb,
 					stcb->asoc.mapping_array_base_tsn = ntohl(resp->senders_next_tsn);
 					memset(stcb->asoc.mapping_array, 0, stcb->asoc.mapping_array_size);
 
-					/*
-					 * EY 05/13/08 - nr_sack: to keep
-					 * nr_mapping array be consistent
-					 * with mapping_array
-					 */
-					if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && stcb->asoc.peer_supports_nr_sack) {
-						stcb->asoc.highest_tsn_inside_nr_map = stcb->asoc.highest_tsn_inside_map;
-						stcb->asoc.nr_mapping_array_base_tsn = stcb->asoc.mapping_array_base_tsn;
-						memset(stcb->asoc.nr_mapping_array, 0, stcb->asoc.nr_mapping_array_size);
-					}
+					stcb->asoc.highest_tsn_inside_nr_map = stcb->asoc.highest_tsn_inside_map;
+					stcb->asoc.nr_mapping_array_base_tsn = stcb->asoc.mapping_array_base_tsn;
+					memset(stcb->asoc.nr_mapping_array, 0, stcb->asoc.nr_mapping_array_size);
+
 					stcb->asoc.sending_seq = ntohl(resp->receivers_next_tsn);
 					stcb->asoc.last_acked_seq = stcb->asoc.cumulative_tsn;
 
@@ -3631,15 +3623,9 @@ sctp_handle_str_reset_request_tsn(struct sctp_tcb *stcb,
 		stcb->asoc.tsn_last_delivered = stcb->asoc.cumulative_tsn = stcb->asoc.highest_tsn_inside_map;
 		stcb->asoc.mapping_array_base_tsn = stcb->asoc.highest_tsn_inside_map + 1;
 		memset(stcb->asoc.mapping_array, 0, stcb->asoc.mapping_array_size);
-		/*
-		 * EY 05/13/08 -nr_sack: to keep nr_mapping array consistent
-		 * with mapping array
-		 */
-		if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && stcb->asoc.peer_supports_nr_sack) {
-			stcb->asoc.highest_tsn_inside_nr_map = stcb->asoc.highest_tsn_inside_map;
-			stcb->asoc.nr_mapping_array_base_tsn = stcb->asoc.highest_tsn_inside_map + 1;
-			memset(stcb->asoc.nr_mapping_array, 0, stcb->asoc.nr_mapping_array_size);
-		}
+		stcb->asoc.highest_tsn_inside_nr_map = stcb->asoc.highest_tsn_inside_map;
+		stcb->asoc.nr_mapping_array_base_tsn = stcb->asoc.highest_tsn_inside_map + 1;
+		memset(stcb->asoc.nr_mapping_array, 0, stcb->asoc.nr_mapping_array_size);
 		atomic_add_int(&stcb->asoc.sending_seq, 1);
 		/* save off historical data for retrans */
 		stcb->asoc.last_sending_seq[1] = stcb->asoc.last_sending_seq[0];
diff --git a/sys/netinet/sctp_output.c b/sys/netinet/sctp_output.c
index be4c3a8633f..b3e5781ff52 100644
--- a/sys/netinet/sctp_output.c
+++ b/sys/netinet/sctp_output.c
@@ -7871,19 +7871,8 @@ again_one_more_time:
 						pf_hbflag = 1;
 					}
 					/* remove these chunks at the end */
-					if (chk->rec.chunk_id.id == SCTP_SELECTIVE_ACK) {
-						/* turn off the timer */
-						if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) {
-							sctp_timer_stop(SCTP_TIMER_TYPE_RECV,
-							    inp, stcb, net, SCTP_FROM_SCTP_OUTPUT + SCTP_LOC_1);
-						}
-					}
-					/*
-					 * EY -Nr-sack version of the above
-					 * if statement
-					 */
-					if ((SCTP_BASE_SYSCTL(sctp_nr_sack_on_off) && asoc->peer_supports_nr_sack) &&
-					    (chk->rec.chunk_id.id == SCTP_NR_SELECTIVE_ACK)) {	/* EY !?! */
+					if ((chk->rec.chunk_id.id == SCTP_SELECTIVE_ACK) ||
+					    (chk->rec.chunk_id.id == SCTP_NR_SELECTIVE_ACK)) {
 						/* turn off the timer */
 						if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) {
 							sctp_timer_stop(SCTP_TIMER_TYPE_RECV,
@@ -9885,6 +9874,7 @@ sctp_send_sack(struct sctp_tcb *stcb)
 	unsigned int num_gap_blocks = 0, space;
 	int num_dups = 0;
 	int space_req;
+	uint32_t highest_tsn;
 
 	a_chk = NULL;
 	asoc = &stcb->asoc;
@@ -9970,7 +9960,12 @@ sctp_send_sack(struct sctp_tcb *stcb)
 	if (a_chk->whoTo) {
 		atomic_add_int(&a_chk->whoTo->ref_count, 1);
 	}
-	if (asoc->highest_tsn_inside_map == asoc->cumulative_tsn) {
+	if (compare_with_wrap(asoc->highest_tsn_inside_map, asoc->highest_tsn_inside_nr_map, MAX_TSN)) {
+		highest_tsn = asoc->highest_tsn_inside_map;
+	} else {
+		highest_tsn = asoc->highest_tsn_inside_nr_map;
+	}
+	if (highest_tsn == asoc->cumulative_tsn) {
 		/* no gaps */
 		space_req = sizeof(struct sctp_sack_chunk);
 	} else {
@@ -10043,10 +10038,10 @@ sctp_send_sack(struct sctp_tcb *stcb)
 
 	gap_descriptor = (struct sctp_gap_ack_block *)((caddr_t)sack + sizeof(struct sctp_sack_chunk));
 
-	if (asoc->highest_tsn_inside_map > asoc->mapping_array_base_tsn)
-		siz = (((asoc->highest_tsn_inside_map - asoc->mapping_array_base_tsn) + 1) + 7) / 8;
+	if (highest_tsn > asoc->mapping_array_base_tsn)
+		siz = (((highest_tsn - asoc->mapping_array_base_tsn) + 1) + 7) / 8;
 	else
-		siz = (((MAX_TSN - asoc->mapping_array_base_tsn) + 1) + asoc->highest_tsn_inside_map + 7) / 8;
+		siz = (((MAX_TSN - highest_tsn) + 1) + highest_tsn + 7) / 8;
 
 	if (compare_with_wrap(asoc->mapping_array_base_tsn, asoc->cumulative_tsn, MAX_TSN)) {
 		offset = 1;
@@ -10063,10 +10058,10 @@ sctp_send_sack(struct sctp_tcb *stcb)
 		 */
 		jstart = 1;
 	}
-	if (compare_with_wrap(asoc->highest_tsn_inside_map, asoc->cumulative_tsn, MAX_TSN)) {
+	if (compare_with_wrap(highest_tsn, asoc->cumulative_tsn, MAX_TSN)) {
 		/* we have a gap .. maybe */
 		for (i = 0; i < siz; i++) {
-			selector = &sack_array[asoc->mapping_array[i]];
+			selector = &sack_array[(asoc->mapping_array[i] | asoc->nr_mapping_array[i])];
 			if (mergeable && selector->right_edge) {
 				/*
 				 * Backup, left and right edges were ok to
@@ -10120,8 +10115,6 @@ sctp_send_sack(struct sctp_tcb *stcb)
 			 */
 			int abort_flag = 0;
 
-			asoc->cumulative_tsn = asoc->highest_tsn_inside_map;
-			sack->sack.cum_tsn_ack = htonl(asoc->cumulative_tsn);
 			sctp_sack_check(stcb, 0, 0, &abort_flag);
 		}
 	}
@@ -10180,13 +10173,13 @@ sctp_send_nr_sack(struct sctp_tcb *stcb)
 	int mergeable = 0;
 	int offset;
 	caddr_t limit;
-	uint32_t *dup;
+	uint32_t *dup, highest_tsn;
 	int limit_reached = 0;
+	int seen_non_zero = 0;
 	unsigned int i, jstart, siz, j;
 	unsigned int num_gap_blocks = 0, num_nr_gap_blocks = 0, space;
 	int num_dups = 0;
 	int space_req;
-	unsigned int reserved = 0;
 
 	a_chk = NULL;
 	asoc = &stcb->asoc;
@@ -10272,7 +10265,12 @@ sctp_send_nr_sack(struct sctp_tcb *stcb)
 	if (a_chk->whoTo) {
 		atomic_add_int(&a_chk->whoTo->ref_count, 1);
 	}
-	if (asoc->highest_tsn_inside_map == asoc->cumulative_tsn) {
+	if (compare_with_wrap(asoc->highest_tsn_inside_map, asoc->highest_tsn_inside_nr_map, MAX_TSN)) {
+		highest_tsn = asoc->highest_tsn_inside_map;
+	} else {
+		highest_tsn = asoc->highest_tsn_inside_nr_map;
+	}
+	if (highest_tsn == asoc->cumulative_tsn) {
 		/* no gaps */
 		space_req = sizeof(struct sctp_nr_sack_chunk);
 	} else {
@@ -10371,6 +10369,7 @@ sctp_send_nr_sack(struct sctp_tcb *stcb)
 	if (compare_with_wrap(asoc->highest_tsn_inside_map, asoc->cumulative_tsn, MAX_TSN)) {
 		/* we have a gap .. maybe */
 		for (i = 0; i < siz; i++) {
+			seen_non_zero = 1;
 			selector = &sack_array[asoc->mapping_array[i]];
 			if (mergeable && selector->right_edge) {
 				/*
@@ -10418,22 +10417,8 @@ sctp_send_nr_sack(struct sctp_tcb *stcb)
 			jstart = 0;
 			offset += 8;
 		}
-		if (num_gap_blocks == 0) {
-			/*
-			 * slide not yet happened, and somehow we got called
-			 * to send a sack. Cumack needs to move up.
-			 */
-			int abort_flag = 0;
-
-			asoc->cumulative_tsn = asoc->highest_tsn_inside_map;
-			nr_sack->nr_sack.cum_tsn_ack = htonl(asoc->cumulative_tsn);
-			sctp_sack_check(stcb, 0, 0, &abort_flag);
-		}
 	}
-	/*---------------------------------------------------------filling the nr_gap_ack blocks----------------------------------------------------*/
-
-	/* EY - there will be gaps + nr_gaps if draining is possible */
-	if ((SCTP_BASE_SYSCTL(sctp_do_drain)) && (limit_reached == 0)) {
+	if (limit_reached == 0) {
 
 		mergeable = 0;
 
@@ -10510,9 +10495,6 @@ sctp_send_nr_sack(struct sctp_tcb *stcb)
 			}
 		}
 	}
-	/*---------------------------------------------End of---filling the nr_gap_ack blocks----------------------------------------------------*/
-
-	/* now we must add any dups we are going to report. */
 	if ((limit_reached == 0) && (asoc->numduptsns)) {
 		dup = (uint32_t *) gap_descriptor;
 		for (i = 0; i < asoc->numduptsns; i++) {
@@ -10530,10 +10512,6 @@ sctp_send_nr_sack(struct sctp_tcb *stcb)
 	 * now that the chunk is prepared queue it to the control chunk
 	 * queue.
 	 */
-	if (SCTP_BASE_SYSCTL(sctp_do_drain) == 0) {
-		num_nr_gap_blocks = num_gap_blocks;
-		num_gap_blocks = 0;
-	}
 	a_chk->send_size = sizeof(struct sctp_nr_sack_chunk) +
 	    (num_gap_blocks + num_nr_gap_blocks) * sizeof(struct sctp_gap_ack_block) +
 	    num_dups * sizeof(int32_t);
@@ -10542,7 +10520,7 @@ sctp_send_nr_sack(struct sctp_tcb *stcb)
 	nr_sack->nr_sack.num_gap_ack_blks = htons(num_gap_blocks);
 	nr_sack->nr_sack.num_nr_gap_ack_blks = htons(num_nr_gap_blocks);
 	nr_sack->nr_sack.num_dup_tsns = htons(num_dups);
-	nr_sack->nr_sack.reserved = htons(reserved);
+	nr_sack->nr_sack.reserved = 0;
 	nr_sack->ch.chunk_length = htons(a_chk->send_size);
 	TAILQ_INSERT_TAIL(&asoc->control_send_queue, a_chk, sctp_next);
 	asoc->ctrl_queue_cnt++;
diff --git a/sys/netinet/sctputil.c b/sys/netinet/sctputil.c
index c03b9d0e245..e9f5aecb998 100644
--- a/sys/netinet/sctputil.c
+++ b/sys/netinet/sctputil.c
@@ -1175,7 +1175,7 @@ sctp_init_asoc(struct sctp_inpcb *m, struct sctp_tcb *stcb,
 	asoc->discontinuity_time = asoc->start_time;
 	/*
 	 * sa_ignore MEMLEAK {memory is put in the assoc mapping array and
-	 * freed later whe the association is freed.
+	 * freed later when the association is freed.
 	 */
 	return (0);
 }
@@ -1183,7 +1183,7 @@ sctp_init_asoc(struct sctp_inpcb *m, struct sctp_tcb *stcb,
 void
 sctp_print_mapping_array(struct sctp_association *asoc)
 {
-	int i;
+	int i, limit;
 
 	printf("Mapping size:%d baseTSN:%8.8x cumAck:%8.8x highestTSN:%8.8x\n",
 	    asoc->mapping_array_size,
@@ -1191,9 +1191,39 @@ sctp_print_mapping_array(struct sctp_association *asoc)
 	    asoc->cumulative_tsn,
 	    asoc->highest_tsn_inside_map
 	    );
-	for (i = 0; i < asoc->mapping_array_size; i++) {
-		printf("%8.8x ", asoc->mapping_array[i]);
-		if (((i + 1) % 8) == 0)
+	limit = asoc->mapping_array_size;
+	for (i = asoc->mapping_array_size; i >= 0; i--) {
+		if (asoc->mapping_array[i]) {
+			limit = i;
+			break;
+		}
+	}
+	if (limit == 0)
+		limit = 1;
+	for (i = 0; i < limit; i++) {
+		printf("%2.2x ", asoc->mapping_array[i]);
+		if (((i + 1) % 16) == 0)
+			printf("\n");
+	}
+	printf("\n");
+	printf("NR Mapping size:%d baseTSN:%8.8x highestTSN:%8.8x\n",
+	    asoc->nr_mapping_array_size,
+	    asoc->nr_mapping_array_base_tsn,
+	    asoc->highest_tsn_inside_nr_map
+	    );
+	limit = asoc->nr_mapping_array_size;
+	for (i = asoc->nr_mapping_array_size; i >= 0; i--) {
+		if (asoc->nr_mapping_array[i]) {
+			limit = i;
+			break;
+		}
+	}
+	if (limit == 0)
+		limit = 1;
+
+	for (i = 0; i < limit; i++) {
+		printf("%2.2x ", asoc->nr_mapping_array[i]);
+		if (((i + 1) % 16) == 0)
 			printf("\n");
 	}
 	printf("\n");

From 7fa19ca6c1e80ce11db4cdcac8f4a79dac57e660 Mon Sep 17 00:00:00 2001
From: Randall Stewart 
Date: Wed, 24 Mar 2010 20:01:14 +0000
Subject: [PATCH 052/119] lagging file I forgot to commit with my nr-sack
 fixes... opps

Reviewed by:	tuexen@freebsd.org
---
 sys/netinet/sctputil.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/sys/netinet/sctputil.h b/sys/netinet/sctputil.h
index 8d663abe2ca..8a6ee6fb213 100644
--- a/sys/netinet/sctputil.h
+++ b/sys/netinet/sctputil.h
@@ -169,8 +169,6 @@ sctp_report_all_outbound(struct sctp_tcb *, int, int
 
 int sctp_expand_mapping_array(struct sctp_association *, uint32_t);
 
-/* EY nr_sack version of the above method, expands nr_mapping_array */
-int sctp_expand_nr_mapping_array(struct sctp_association *, uint32_t);
 void 
 sctp_abort_notification(struct sctp_tcb *, int, int
 #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)

From ff014514ee369a3d8907e5667c0225f2b316a87e Mon Sep 17 00:00:00 2001
From: Randall Stewart 
Date: Wed, 24 Mar 2010 20:02:40 +0000
Subject: [PATCH 053/119] Adds the option of keeping per-cpu statistics in
 SCTP. This may be useful since it gets rid of atomics but I want it to remain
 an option until I can do further testing on if it really speeds things up.

---
 sys/conf/options          |   1 +
 sys/netinet/sctp_pcb.c    |   5 ++
 sys/netinet/sctp_pcb.h    |   4 +
 sys/netinet/sctp_sysctl.c | 160 +++++++++++++++++++++++++++++++++++++-
 sys/netinet/sctp_uio.h    |   6 +-
 5 files changed, 174 insertions(+), 2 deletions(-)

diff --git a/sys/conf/options b/sys/conf/options
index 7869add7a85..fabc0bf772f 100644
--- a/sys/conf/options
+++ b/sys/conf/options
@@ -437,6 +437,7 @@ SCTP_MBCNT_LOGGING	opt_sctp.h # Log to KTR mbcnt activity
 SCTP_PACKET_LOGGING	opt_sctp.h # Log to a packet buffer last N packets
 SCTP_LTRACE_CHUNKS	opt_sctp.h # Log to KTR chunks processed
 SCTP_LTRACE_ERRORS	opt_sctp.h # Log to KTR error returns.
+SCTP_USE_PERCPU_STAT    opt_sctp.h # Use per cpu stats.
 #
 #
 #
diff --git a/sys/netinet/sctp_pcb.c b/sys/netinet/sctp_pcb.c
index 73e7991c659..fa188249a96 100644
--- a/sys/netinet/sctp_pcb.c
+++ b/sys/netinet/sctp_pcb.c
@@ -5425,8 +5425,13 @@ sctp_pcb_init()
 	bzero(&SCTP_BASE_SYSCTL(sctp_log), sizeof(struct sctp_log));
 #endif
 	(void)SCTP_GETTIME_TIMEVAL(&tv);
+#if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
+	SCTP_BASE_STATS[PCPU_GET(cpuid)].sctps_discontinuitytime.tv_sec = (uint32_t) tv.tv_sec;
+	SCTP_BASE_STATS[PCPU_GET(cpuid)].sctps_discontinuitytime.tv_usec = (uint32_t) tv.tv_usec;
+#else
 	SCTP_BASE_STAT(sctps_discontinuitytime).tv_sec = (uint32_t) tv.tv_sec;
 	SCTP_BASE_STAT(sctps_discontinuitytime).tv_usec = (uint32_t) tv.tv_usec;
+#endif
 	/* init the empty list of (All) Endpoints */
 	LIST_INIT(&SCTP_BASE_INFO(listhead));
 
diff --git a/sys/netinet/sctp_pcb.h b/sys/netinet/sctp_pcb.h
index d9e1db6dc05..bf14175cac3 100644
--- a/sys/netinet/sctp_pcb.h
+++ b/sys/netinet/sctp_pcb.h
@@ -246,7 +246,11 @@ struct sctp_base_info {
 	 * All static structures that anchor the system must be here.
 	 */
 	struct sctp_epinfo sctppcbinfo;
+#if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
+	struct sctpstat sctpstat[MAXCPU];
+#else
 	struct sctpstat sctpstat;
+#endif
 	struct sctp_sysctl sctpsysctl;
 	uint8_t first_time;
 	char sctp_pcb_initialized;
diff --git a/sys/netinet/sctp_sysctl.c b/sys/netinet/sctp_sysctl.c
index b4023c68213..c9967eae065 100644
--- a/sys/netinet/sctp_sysctl.c
+++ b/sys/netinet/sctp_sysctl.c
@@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 
 /*
  * sysctl tunable variables
@@ -627,7 +628,158 @@ sysctl_sctp_check(SYSCTL_HANDLER_ARGS)
 	return (error);
 }
 
+#if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
+static int
+sysctl_stat_get(SYSCTL_HANDLER_ARGS)
+{
+	int cpu, error;
+	struct sctpstat sb, *sarry;
 
+	memset(&sb, 0, sizeof(sb));
+	for (cpu = 0; cpu < mp_ncpus; cpu++) {
+		sarry = &SCTP_BASE_STATS[cpu];
+		if (sarry->sctps_discontinuitytime.tv_sec > sb.sctps_discontinuitytime.tv_sec) {
+			sb.sctps_discontinuitytime.tv_sec = sarry->sctps_discontinuitytime.tv_sec;
+			sb.sctps_discontinuitytime.tv_usec = sarry->sctps_discontinuitytime.tv_usec;
+		}
+		sb.sctps_currestab += sarry->sctps_currestab;
+		sb.sctps_activeestab += sarry->sctps_activeestab;
+		sb.sctps_restartestab += sarry->sctps_restartestab;
+		sb.sctps_collisionestab += sarry->sctps_collisionestab;
+		sb.sctps_passiveestab += sarry->sctps_passiveestab;
+		sb.sctps_aborted += sarry->sctps_aborted;
+		sb.sctps_shutdown += sarry->sctps_shutdown;
+		sb.sctps_outoftheblue += sarry->sctps_outoftheblue;
+		sb.sctps_checksumerrors += sarry->sctps_checksumerrors;
+		sb.sctps_outcontrolchunks += sarry->sctps_outcontrolchunks;
+		sb.sctps_outorderchunks += sarry->sctps_outorderchunks;
+		sb.sctps_outunorderchunks += sarry->sctps_outunorderchunks;
+		sb.sctps_incontrolchunks += sarry->sctps_incontrolchunks;
+		sb.sctps_inorderchunks += sarry->sctps_inorderchunks;
+		sb.sctps_inunorderchunks += sarry->sctps_inunorderchunks;
+		sb.sctps_fragusrmsgs += sarry->sctps_fragusrmsgs;
+		sb.sctps_reasmusrmsgs += sarry->sctps_reasmusrmsgs;
+		sb.sctps_outpackets += sarry->sctps_outpackets;
+		sb.sctps_inpackets += sarry->sctps_inpackets;
+		sb.sctps_recvpackets += sarry->sctps_recvpackets;
+		sb.sctps_recvdatagrams += sarry->sctps_recvdatagrams;
+		sb.sctps_recvpktwithdata += sarry->sctps_recvpktwithdata;
+		sb.sctps_recvsacks += sarry->sctps_recvsacks;
+		sb.sctps_recvdata += sarry->sctps_recvdata;
+		sb.sctps_recvdupdata += sarry->sctps_recvdupdata;
+		sb.sctps_recvheartbeat += sarry->sctps_recvheartbeat;
+		sb.sctps_recvheartbeatack += sarry->sctps_recvheartbeatack;
+		sb.sctps_recvecne += sarry->sctps_recvecne;
+		sb.sctps_recvauth += sarry->sctps_recvauth;
+		sb.sctps_recvauthmissing += sarry->sctps_recvauthmissing;
+		sb.sctps_recvivalhmacid += sarry->sctps_recvivalhmacid;
+		sb.sctps_recvivalkeyid += sarry->sctps_recvivalkeyid;
+		sb.sctps_recvauthfailed += sarry->sctps_recvauthfailed;
+		sb.sctps_recvexpress += sarry->sctps_recvexpress;
+		sb.sctps_recvexpressm += sarry->sctps_recvexpressm;
+		sb.sctps_recvnocrc += sarry->sctps_recvnocrc;
+		sb.sctps_recvswcrc += sarry->sctps_recvswcrc;
+		sb.sctps_recvhwcrc += sarry->sctps_recvhwcrc;
+		sb.sctps_sendpackets += sarry->sctps_sendpackets;
+		sb.sctps_sendsacks += sarry->sctps_sendsacks;
+		sb.sctps_senddata += sarry->sctps_senddata;
+		sb.sctps_sendretransdata += sarry->sctps_sendretransdata;
+		sb.sctps_sendfastretrans += sarry->sctps_sendfastretrans;
+		sb.sctps_sendmultfastretrans += sarry->sctps_sendmultfastretrans;
+		sb.sctps_sendheartbeat += sarry->sctps_sendheartbeat;
+		sb.sctps_sendecne += sarry->sctps_sendecne;
+		sb.sctps_sendauth += sarry->sctps_sendauth;
+		sb.sctps_senderrors += sarry->sctps_senderrors;
+		sb.sctps_sendnocrc += sarry->sctps_sendnocrc;
+		sb.sctps_sendswcrc += sarry->sctps_sendswcrc;
+		sb.sctps_sendhwcrc += sarry->sctps_sendhwcrc;
+		sb.sctps_pdrpfmbox += sarry->sctps_pdrpfmbox;
+		sb.sctps_pdrpfehos += sarry->sctps_pdrpfehos;
+		sb.sctps_pdrpmbda += sarry->sctps_pdrpmbda;
+		sb.sctps_pdrpmbct += sarry->sctps_pdrpmbct;
+		sb.sctps_pdrpbwrpt += sarry->sctps_pdrpbwrpt;
+		sb.sctps_pdrpcrupt += sarry->sctps_pdrpcrupt;
+		sb.sctps_pdrpnedat += sarry->sctps_pdrpnedat;
+		sb.sctps_pdrppdbrk += sarry->sctps_pdrppdbrk;
+		sb.sctps_pdrptsnnf += sarry->sctps_pdrptsnnf;
+		sb.sctps_pdrpdnfnd += sarry->sctps_pdrpdnfnd;
+		sb.sctps_pdrpdiwnp += sarry->sctps_pdrpdiwnp;
+		sb.sctps_pdrpdizrw += sarry->sctps_pdrpdizrw;
+		sb.sctps_pdrpbadd += sarry->sctps_pdrpbadd;
+		sb.sctps_pdrpmark += sarry->sctps_pdrpmark;
+		sb.sctps_timoiterator += sarry->sctps_timoiterator;
+		sb.sctps_timodata += sarry->sctps_timodata;
+		sb.sctps_timowindowprobe += sarry->sctps_timowindowprobe;
+		sb.sctps_timoinit += sarry->sctps_timoinit;
+		sb.sctps_timosack += sarry->sctps_timosack;
+		sb.sctps_timoshutdown += sarry->sctps_timoshutdown;
+		sb.sctps_timoheartbeat += sarry->sctps_timoheartbeat;
+		sb.sctps_timocookie += sarry->sctps_timocookie;
+		sb.sctps_timosecret += sarry->sctps_timosecret;
+		sb.sctps_timopathmtu += sarry->sctps_timopathmtu;
+		sb.sctps_timoshutdownack += sarry->sctps_timoshutdownack;
+		sb.sctps_timoshutdownguard += sarry->sctps_timoshutdownguard;
+		sb.sctps_timostrmrst += sarry->sctps_timostrmrst;
+		sb.sctps_timoearlyfr += sarry->sctps_timoearlyfr;
+		sb.sctps_timoasconf += sarry->sctps_timoasconf;
+		sb.sctps_timodelprim += sarry->sctps_timodelprim;
+		sb.sctps_timoautoclose += sarry->sctps_timoautoclose;
+		sb.sctps_timoassockill += sarry->sctps_timoassockill;
+		sb.sctps_timoinpkill += sarry->sctps_timoinpkill;
+		sb.sctps_earlyfrstart += sarry->sctps_earlyfrstart;
+		sb.sctps_earlyfrstop += sarry->sctps_earlyfrstop;
+		sb.sctps_earlyfrmrkretrans += sarry->sctps_earlyfrmrkretrans;
+		sb.sctps_earlyfrstpout += sarry->sctps_earlyfrstpout;
+		sb.sctps_earlyfrstpidsck1 += sarry->sctps_earlyfrstpidsck1;
+		sb.sctps_earlyfrstpidsck2 += sarry->sctps_earlyfrstpidsck2;
+		sb.sctps_earlyfrstpidsck3 += sarry->sctps_earlyfrstpidsck3;
+		sb.sctps_earlyfrstpidsck4 += sarry->sctps_earlyfrstpidsck4;
+		sb.sctps_earlyfrstrid += sarry->sctps_earlyfrstrid;
+		sb.sctps_earlyfrstrout += sarry->sctps_earlyfrstrout;
+		sb.sctps_earlyfrstrtmr += sarry->sctps_earlyfrstrtmr;
+		sb.sctps_hdrops += sarry->sctps_hdrops;
+		sb.sctps_badsum += sarry->sctps_badsum;
+		sb.sctps_noport += sarry->sctps_noport;
+		sb.sctps_badvtag += sarry->sctps_badvtag;
+		sb.sctps_badsid += sarry->sctps_badsid;
+		sb.sctps_nomem += sarry->sctps_nomem;
+		sb.sctps_fastretransinrtt += sarry->sctps_fastretransinrtt;
+		sb.sctps_markedretrans += sarry->sctps_markedretrans;
+		sb.sctps_naglesent += sarry->sctps_naglesent;
+		sb.sctps_naglequeued += sarry->sctps_naglequeued;
+		sb.sctps_maxburstqueued += sarry->sctps_maxburstqueued;
+		sb.sctps_ifnomemqueued += sarry->sctps_ifnomemqueued;
+		sb.sctps_windowprobed += sarry->sctps_windowprobed;
+		sb.sctps_lowlevelerr += sarry->sctps_lowlevelerr;
+		sb.sctps_lowlevelerrusr += sarry->sctps_lowlevelerrusr;
+		sb.sctps_datadropchklmt += sarry->sctps_datadropchklmt;
+		sb.sctps_datadroprwnd += sarry->sctps_datadroprwnd;
+		sb.sctps_ecnereducedcwnd += sarry->sctps_ecnereducedcwnd;
+		sb.sctps_vtagexpress += sarry->sctps_vtagexpress;
+		sb.sctps_vtagbogus += sarry->sctps_vtagbogus;
+		sb.sctps_primary_randry += sarry->sctps_primary_randry;
+		sb.sctps_cmt_randry += sarry->sctps_cmt_randry;
+		sb.sctps_slowpath_sack += sarry->sctps_slowpath_sack;
+		sb.sctps_wu_sacks_sent += sarry->sctps_wu_sacks_sent;
+		sb.sctps_sends_with_flags += sarry->sctps_sends_with_flags;
+		sb.sctps_sends_with_unord += sarry->sctps_sends_with_unord;
+		sb.sctps_sends_with_eof += sarry->sctps_sends_with_eof;
+		sb.sctps_sends_with_abort += sarry->sctps_sends_with_abort;
+		sb.sctps_protocol_drain_calls += sarry->sctps_protocol_drain_calls;
+		sb.sctps_protocol_drains_done += sarry->sctps_protocol_drains_done;
+		sb.sctps_read_peeks += sarry->sctps_read_peeks;
+		sb.sctps_cached_chk += sarry->sctps_cached_chk;
+		sb.sctps_cached_strmoq += sarry->sctps_cached_strmoq;
+		sb.sctps_left_abandon += sarry->sctps_left_abandon;
+		sb.sctps_send_burst_avoid += sarry->sctps_send_burst_avoid;
+		sb.sctps_send_cwnd_avoid += sarry->sctps_send_cwnd_avoid;
+		sb.sctps_fwdtsn_map_over += sarry->sctps_fwdtsn_map_over;
+	}
+	error = SYSCTL_OUT(req, &sb, sizeof(sb));
+	return (error);
+}
+
+#endif
 
 #if defined(SCTP_LOCAL_TRACE_BUF)
 static int
@@ -916,10 +1068,16 @@ SYSCTL_PROC(_net_inet_sctp, OID_AUTO, output_unlocked, CTLTYPE_INT | CTLFLAG_RW,
     &SCTP_BASE_SYSCTL(sctp_output_unlocked), 0, sysctl_sctp_check, "IU",
     SCTPCTL_OUTPUT_UNLOCKED_DESC);
 #endif
-
+#if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
+SYSCTL_PROC(_net_inet_sctp, OID_AUTO, stats,
+    CTLTYPE_STRUCT | CTLFLAG_RD,
+    0, 0, sysctl_stat_get, "S,sctpstat",
+    "SCTP statistics (struct sctp_stat)");
+#else
 SYSCTL_STRUCT(_net_inet_sctp, OID_AUTO, stats, CTLFLAG_RW,
     &SCTP_BASE_STATS_SYSCTL, sctpstat,
     "SCTP statistics (struct sctp_stat)");
+#endif
 
 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, assoclist, CTLFLAG_RD,
     0, 0, sctp_assoclist,
diff --git a/sys/netinet/sctp_uio.h b/sys/netinet/sctp_uio.h
index 19089301411..e3fbc3e6d50 100644
--- a/sys/netinet/sctp_uio.h
+++ b/sys/netinet/sctp_uio.h
@@ -957,9 +957,13 @@ struct sctpstat {
 
 #define SCTP_STAT_INCR(_x) SCTP_STAT_INCR_BY(_x,1)
 #define SCTP_STAT_DECR(_x) SCTP_STAT_DECR_BY(_x,1)
+#if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
+#define SCTP_STAT_INCR_BY(_x,_d) (SCTP_BASE_STATS[PCPU_GET(cpuid)]._x += _d)
+#define SCTP_STAT_DECR_BY(_x,_d) (SCTP_BASE_STATS[PCPU_GET(cpuid)]._x -= _d)
+#else
 #define SCTP_STAT_INCR_BY(_x,_d) atomic_add_int(&SCTP_BASE_STAT(_x), _d)
 #define SCTP_STAT_DECR_BY(_x,_d) atomic_subtract_int(&SCTP_BASE_STAT(_x), _d)
-
+#endif
 /* The following macros are for handling MIB values, */
 #define SCTP_STAT_INCR_COUNTER32(_x) SCTP_STAT_INCR(_x)
 #define SCTP_STAT_INCR_COUNTER64(_x) SCTP_STAT_INCR(_x)

From ebbcc89c45c6731f1d37bfc365d523ed214f814d Mon Sep 17 00:00:00 2001
From: Warner Losh 
Date: Wed, 24 Mar 2010 20:20:28 +0000
Subject: [PATCH 054/119] This broke when we went to gnu99 as the default
 standard.  Fix the build by reverting to the gnu89 standard.

---
 gnu/usr.bin/cpio/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gnu/usr.bin/cpio/Makefile b/gnu/usr.bin/cpio/Makefile
index 60756efa997..c31527be94a 100644
--- a/gnu/usr.bin/cpio/Makefile
+++ b/gnu/usr.bin/cpio/Makefile
@@ -58,6 +58,7 @@ SRCS=   copyin.c \
 	xstrndup.c \
 	alloca.h \
 	getopt.h
+CSTD=gnu89
 
 CLEANFILES+= alloca.h getopt.h
 

From c72c2330d081b2edf2d1dd56ce9efc8e946745a7 Mon Sep 17 00:00:00 2001
From: Luigi Rizzo 
Date: Wed, 24 Mar 2010 23:06:16 +0000
Subject: [PATCH 055/119] fix another bug in "ipfw set N ..."

Submitted by:	Marcin Wisnicki
---
 sbin/ipfw/ipfw2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c
index 1ab827f3e26..9e212fc012a 100644
--- a/sbin/ipfw/ipfw2.c
+++ b/sbin/ipfw/ipfw2.c
@@ -2656,7 +2656,7 @@ ipfw_add(char *av[])
 	}
 
 	/* [set N]	-- set number (0..RESVD_SET), optional */
-	if (av[0] && !av[1] && _substrcmp(*av, "set") == 0) {
+	if (av[0] && av[1] && _substrcmp(*av, "set") == 0) {
 		int set = strtoul(av[1], NULL, 10);
 		if (set < 0 || set > RESVD_SET)
 			errx(EX_DATAERR, "illegal set %s", av[1]);

From cecdd23f87236c250e3ad8fe070c5bf30af19752 Mon Sep 17 00:00:00 2001
From: Gleb Smirnoff 
Date: Thu, 25 Mar 2010 10:13:21 +0000
Subject: [PATCH 056/119] Remove disabled code. In 99% cases exports are send
 to ng_ksocket(4), which already forces queued mode, so what was suggested in
 disabled code is already done.

---
 sys/netgraph/netflow/ng_netflow.c | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/sys/netgraph/netflow/ng_netflow.c b/sys/netgraph/netflow/ng_netflow.c
index cacbd724b0d..8bf484502bf 100644
--- a/sys/netgraph/netflow/ng_netflow.c
+++ b/sys/netgraph/netflow/ng_netflow.c
@@ -286,15 +286,6 @@ ng_netflow_newhook(node_p node, hook_p hook, const char *name)
 
 		priv->export = hook;
 
-#if 0	/* TODO: profile & test first */
-		/*
-		 * We send export dgrams in interrupt handlers and in
-		 * callout threads. We'd better queue data for later
-		 * netgraph ISR processing.
-		 */
-		NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook));
-#endif
-
 		/* Exporter is ready. Let's schedule expiry. */
 		callout_reset(&priv->exp_callout, (1*hz), &ng_netflow_expire,
 		    (void *)priv);

From d715e397f025ec5403bca2337d2e9b189b655b33 Mon Sep 17 00:00:00 2001
From: "Bjoern A. Zeeb" 
Date: Thu, 25 Mar 2010 10:29:00 +0000
Subject: [PATCH 057/119] We are holding a write lock here so avoid aquiring it
 twice calling the "locked" version rather than the wrapper function.

MFC after:	6 days
---
 sys/netinet6/nd6.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c
index a32539b8972..5c250f4417b 100644
--- a/sys/netinet6/nd6.c
+++ b/sys/netinet6/nd6.c
@@ -1168,7 +1168,7 @@ nd6_nud_hint(struct rtentry *rt, struct in6_addr *dst6, int force)
 
  	ln->ln_state = ND6_LLINFO_REACHABLE;
 	if (!ND6_LLINFO_PERMANENT(ln)) {
-		nd6_llinfo_settimer(ln,
+		nd6_llinfo_settimer_locked(ln,
 		    (long)ND_IFINFO(rt->rt_ifp)->reachable * hz);
 	}
 done:

From 627693305a95135ca1ade92b4827e5f3c8208e61 Mon Sep 17 00:00:00 2001
From: Alexander Leidinger 
Date: Thu, 25 Mar 2010 13:47:21 +0000
Subject: [PATCH 058/119] Propagate CONF_CFLAGS (from makeoptions) to the
 module build too.

Discussed with:	jhb (on arch@)
---
 sys/conf/kern.post.mk | 4 ++++
 sys/conf/kmod.mk      | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/sys/conf/kern.post.mk b/sys/conf/kern.post.mk
index ed565686391..f808c953b0f 100644
--- a/sys/conf/kern.post.mk
+++ b/sys/conf/kern.post.mk
@@ -15,6 +15,10 @@ MKMODULESENV+=	DESTDIR="${DESTDIR}"
 SYSDIR?= ${S:C;^[^/];${.CURDIR}/&;}
 MKMODULESENV+=	KERNBUILDDIR="${.CURDIR}" SYSDIR="${SYSDIR}"
 
+.if defined(CONF_CFLAGS)
+MKMODULESENV+=	CONF_CFLAGS="${CONF_CFLAGS}"
+.endif
+
 .MAIN: all
 
 .for target in all clean cleandepend cleandir clobber depend install \
diff --git a/sys/conf/kmod.mk b/sys/conf/kmod.mk
index 6d543e4981a..0f8b4ff22ec 100644
--- a/sys/conf/kmod.mk
+++ b/sys/conf/kmod.mk
@@ -325,6 +325,9 @@ ${_src}:
 .endfor
 .endif
 
+# Repsect configuration-specific C flags.
+CFLAGS+=	${CONF_CFLAGS}
+
 MFILES?= dev/acpica/acpi_if.m dev/acpi_support/acpi_wmi_if.m \
 	dev/agp/agp_if.m dev/ata/ata_if.m dev/eisa/eisa_if.m \
 	dev/iicbus/iicbb_if.m dev/iicbus/iicbus_if.m \

From 920acedb80a15a0c9694d6b2e02195166650ca9e Mon Sep 17 00:00:00 2001
From: Nathan Whitehorn 
Date: Thu, 25 Mar 2010 14:21:22 +0000
Subject: [PATCH 059/119] Change the way text_addr and data_addr are computed
 to use the executable status of segments instead of detecting the main text
 segment by which segment contains the program entry point. This affects
 obreak() and is required for correct operation of that function on 64-bit
 PowerPC systems. The previous behavior was apparently required only for the
 Alpha, which is no longer supported.

Reviewed by:	jhb
Tested on:	amd64, sparc64, powerpc
---
 sys/kern/imgact_elf.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c
index 0fffb9fb4c9..47e1f64b6ce 100644
--- a/sys/kern/imgact_elf.c
+++ b/sys/kern/imgact_elf.c
@@ -832,13 +832,8 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp)
 			    phdr[i].p_vaddr + et_dyn_addr - seg_addr);
 
 			/*
-			 * Is this .text or .data?  We can't use
-			 * VM_PROT_WRITE or VM_PROT_EXEC, it breaks the
-			 * alpha terribly and possibly does other bad
-			 * things so we stick to the old way of figuring
-			 * it out:  If the segment contains the program
-			 * entry point, it's a text segment, otherwise it
-			 * is a data segment.
+			 * Make the largest executable segment the official
+			 * text segment and all others data.
 			 *
 			 * Note that obreak() assumes that data_addr + 
 			 * data_size == end of data load area, and the ELF
@@ -846,12 +841,10 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp)
 			 * address.  If multiple data segments exist, the
 			 * last one will be used.
 			 */
-			if (hdr->e_entry >= phdr[i].p_vaddr &&
-			    hdr->e_entry < (phdr[i].p_vaddr +
-			    phdr[i].p_memsz)) {
+
+			if (phdr[i].p_flags & PF_X && text_size < seg_size) {
 				text_size = seg_size;
 				text_addr = seg_addr;
-				entry = (u_long)hdr->e_entry + et_dyn_addr;
 			} else {
 				data_size = seg_size;
 				data_addr = seg_addr;
@@ -871,6 +864,8 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp)
 		data_size = text_size;
 	}
 
+	entry = (u_long)hdr->e_entry + et_dyn_addr;
+
 	/*
 	 * Check limits.  It should be safe to check the
 	 * limits after loading the segments since we do

From a107d8aac915c953c658426eb0d15c5067dafa60 Mon Sep 17 00:00:00 2001
From: Nathan Whitehorn 
Date: Thu, 25 Mar 2010 14:24:00 +0000
Subject: [PATCH 060/119] Change the arguments of exec_setregs() so that it
 receives a pointer to the image_params struct instead of several members of
 that struct individually. This makes it easier to expand its arguments in the
 future without touching all platforms.

Reviewed by:	jhb
---
 sys/amd64/amd64/machdep.c          |  8 ++------
 sys/amd64/ia32/ia32_signal.c       | 10 +++-------
 sys/amd64/linux32/linux32_sysvec.c | 14 +++++---------
 sys/arm/arm/machdep.c              |  6 +++---
 sys/compat/ia32/ia32_signal.h      |  4 ++--
 sys/i386/i386/machdep.c            | 10 +++-------
 sys/i386/linux/linux_sysvec.c      |  9 ++++-----
 sys/ia64/ia32/ia32_signal.c        |  4 ++--
 sys/ia64/ia64/machdep.c            |  6 +++---
 sys/kern/kern_exec.c               |  7 +++----
 sys/mips/mips/pm_machdep.c         |  8 ++++----
 sys/pc98/pc98/machdep.c            | 10 +++-------
 sys/powerpc/aim/machdep.c          |  4 ++--
 sys/powerpc/booke/machdep.c        |  4 ++--
 sys/sparc64/sparc64/machdep.c      |  6 +++---
 sys/sun4v/sun4v/machdep.c          |  6 +++---
 sys/sys/imgact.h                   |  2 +-
 sys/sys/sysent.h                   |  3 ++-
 18 files changed, 50 insertions(+), 71 deletions(-)

diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c
index 231897509a3..1155eaa8370 100644
--- a/sys/amd64/amd64/machdep.c
+++ b/sys/amd64/amd64/machdep.c
@@ -841,11 +841,7 @@ SYSCTL_PROC(_machdep, OID_AUTO, idle, CTLTYPE_STRING | CTLFLAG_RW, 0, 0,
  * Reset registers to default values on exec.
  */
 void
-exec_setregs(td, entry, stack, ps_strings)
-	struct thread *td;
-	u_long entry;
-	u_long stack;
-	u_long ps_strings;
+exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 {
 	struct trapframe *regs = td->td_frame;
 	struct pcb *pcb = td->td_pcb;
@@ -863,7 +859,7 @@ exec_setregs(td, entry, stack, ps_strings)
 	pcb->pcb_full_iret = 1;
 
 	bzero((char *)regs, sizeof(struct trapframe));
-	regs->tf_rip = entry;
+	regs->tf_rip = imgp->entry_addr;
 	regs->tf_rsp = ((stack - 8) & ~0xFul) + 8;
 	regs->tf_rdi = stack;		/* argv */
 	regs->tf_rflags = PSL_USER | (regs->tf_rflags & PSL_T);
diff --git a/sys/amd64/ia32/ia32_signal.c b/sys/amd64/ia32/ia32_signal.c
index 10ec641bc61..a4293c89a3b 100644
--- a/sys/amd64/ia32/ia32_signal.c
+++ b/sys/amd64/ia32/ia32_signal.c
@@ -701,11 +701,7 @@ freebsd32_sigreturn(td, uap)
  * Clear registers on exec
  */
 void
-ia32_setregs(td, entry, stack, ps_strings)
-	struct thread *td;
-	u_long entry;
-	u_long stack;
-	u_long ps_strings;
+ia32_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 {
 	struct trapframe *regs = td->td_frame;
 	struct pcb *pcb = td->td_pcb;
@@ -721,12 +717,12 @@ ia32_setregs(td, entry, stack, ps_strings)
 	pcb->pcb_initial_fpucw = __INITIAL_FPUCW_I386__;
 
 	bzero((char *)regs, sizeof(struct trapframe));
-	regs->tf_rip = entry;
+	regs->tf_rip = imgp->entry_addr;
 	regs->tf_rsp = stack;
 	regs->tf_rflags = PSL_USER | (regs->tf_rflags & PSL_T);
 	regs->tf_ss = _udatasel;
 	regs->tf_cs = _ucode32sel;
-	regs->tf_rbx = ps_strings;
+	regs->tf_rbx = imgp->ps_strings;
 	regs->tf_ds = _udatasel;
 	regs->tf_es = _udatasel;
 	regs->tf_fs = _ufssel;
diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c
index d967ad70113..06f1e979e33 100644
--- a/sys/amd64/linux32/linux32_sysvec.c
+++ b/sys/amd64/linux32/linux32_sysvec.c
@@ -124,8 +124,8 @@ static register_t *linux_copyout_strings(struct image_params *imgp);
 static void	linux_prepsyscall(struct trapframe *tf, int *args, u_int *code,
 		    caddr_t *params);
 static void     linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask);
-static void	exec_linux_setregs(struct thread *td, u_long entry,
-				   u_long stack, u_long ps_strings);
+static void	exec_linux_setregs(struct thread *td, 
+				   struct image_params *imgp, u_long stack);
 static void	linux32_fixlimit(struct rlimit *rl, int which);
 static boolean_t linux32_trans_osrel(const Elf_Note *note, int32_t *osrel);
 
@@ -828,11 +828,7 @@ exec_linux_imgact_try(struct image_params *imgp)
  * XXX copied from ia32_signal.c.
  */
 static void
-exec_linux_setregs(td, entry, stack, ps_strings)
-	struct thread *td;
-	u_long entry;
-	u_long stack;
-	u_long ps_strings;
+exec_linux_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 {
 	struct trapframe *regs = td->td_frame;
 	struct pcb *pcb = td->td_pcb;
@@ -852,7 +848,7 @@ exec_linux_setregs(td, entry, stack, ps_strings)
 	pcb->pcb_initial_fpucw = __LINUX_NPXCW__;
 
 	bzero((char *)regs, sizeof(struct trapframe));
-	regs->tf_rip = entry;
+	regs->tf_rip = imgp->entry_addr;
 	regs->tf_rsp = stack;
 	regs->tf_rflags = PSL_USER | (regs->tf_rflags & PSL_T);
 	regs->tf_gs = _ugssel;
@@ -862,7 +858,7 @@ exec_linux_setregs(td, entry, stack, ps_strings)
 	regs->tf_ss = _udatasel;
 	regs->tf_flags = TF_HASSEGS;
 	regs->tf_cs = _ucode32sel;
-	regs->tf_rbx = ps_strings;
+	regs->tf_rbx = imgp->ps_strings;
 	td->td_pcb->pcb_full_iret = 1;
 	load_cr0(rcr0() | CR0_MP | CR0_TS);
 	fpstate_drop(td);
diff --git a/sys/arm/arm/machdep.c b/sys/arm/arm/machdep.c
index 49af8e2cdf4..088d2257cee 100644
--- a/sys/arm/arm/machdep.c
+++ b/sys/arm/arm/machdep.c
@@ -516,15 +516,15 @@ spinlock_exit(void)
  * Clear registers on exec
  */
 void
-exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
+exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 {
 	struct trapframe *tf = td->td_frame;
 
 	memset(tf, 0, sizeof(*tf));
 	tf->tf_usr_sp = stack;
-	tf->tf_usr_lr = entry;
+	tf->tf_usr_lr = imgp->entry_addr;
 	tf->tf_svc_lr = 0x77777777;
-	tf->tf_pc = entry;
+	tf->tf_pc = imgp->entry_addr;
 	tf->tf_spsr = PSR_USR32_MODE;
 }
 
diff --git a/sys/compat/ia32/ia32_signal.h b/sys/compat/ia32/ia32_signal.h
index 6ebb0defc63..9daa8d52293 100644
--- a/sys/compat/ia32/ia32_signal.h
+++ b/sys/compat/ia32/ia32_signal.h
@@ -185,5 +185,5 @@ extern char freebsd4_ia32_sigcode[];
 extern int sz_ia32_sigcode;
 extern int sz_freebsd4_ia32_sigcode;
 extern void ia32_sendsig(sig_t, struct ksiginfo *, sigset_t *);
-extern void ia32_setregs(struct thread *td, u_long entry, u_long stack,
-    u_long ps_strings);
+extern void ia32_setregs(struct thread *td, struct image_params *imgp,
+    u_long stack);
diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c
index 1ef94ead8c5..695b656f21b 100644
--- a/sys/i386/i386/machdep.c
+++ b/sys/i386/i386/machdep.c
@@ -1461,11 +1461,7 @@ SYSCTL_PROC(_machdep, OID_AUTO, idle, CTLTYPE_STRING | CTLFLAG_RW, 0, 0,
  * Reset registers to default values on exec.
  */
 void
-exec_setregs(td, entry, stack, ps_strings)
-	struct thread *td;
-	u_long entry;
-	u_long stack;
-	u_long ps_strings;
+exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 {
 	struct trapframe *regs = td->td_frame;
 	struct pcb *pcb = td->td_pcb;
@@ -1481,7 +1477,7 @@ exec_setregs(td, entry, stack, ps_strings)
 		mtx_unlock_spin(&dt_lock);
   
 	bzero((char *)regs, sizeof(struct trapframe));
-	regs->tf_eip = entry;
+	regs->tf_eip = imgp->entry_addr;
 	regs->tf_esp = stack;
 	regs->tf_eflags = PSL_USER | (regs->tf_eflags & PSL_T);
 	regs->tf_ss = _udatasel;
@@ -1491,7 +1487,7 @@ exec_setregs(td, entry, stack, ps_strings)
 	regs->tf_cs = _ucodesel;
 
 	/* PS_STRINGS value for BSD/OS binaries.  It is 0 for non-BSD/OS. */
-	regs->tf_ebx = ps_strings;
+	regs->tf_ebx = imgp->ps_strings;
 
         /*
          * Reset the hardware debug registers if they were in use.
diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c
index 069b5bb8572..3f0c6f4100e 100644
--- a/sys/i386/linux/linux_sysvec.c
+++ b/sys/i386/linux/linux_sysvec.c
@@ -105,8 +105,8 @@ static int	elf_linux_fixup(register_t **stack_base,
 static void	linux_prepsyscall(struct trapframe *tf, int *args, u_int *code,
 		    caddr_t *params);
 static void     linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask);
-static void	exec_linux_setregs(struct thread *td, u_long entry,
-				   u_long stack, u_long ps_strings);
+static void	exec_linux_setregs(struct thread *td,
+		    struct image_params *imgp, u_long stack);
 static register_t *linux_copyout_strings(struct image_params *imgp);
 static boolean_t linux_trans_osrel(const Elf_Note *note, int32_t *osrel);
 
@@ -927,12 +927,11 @@ exec_linux_imgact_try(struct image_params *imgp)
  * override the exec_setregs default(s) here.
  */
 static void
-exec_linux_setregs(struct thread *td, u_long entry,
-		   u_long stack, u_long ps_strings)
+exec_linux_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 {
 	struct pcb *pcb = td->td_pcb;
 
-	exec_setregs(td, entry, stack, ps_strings);
+	exec_setregs(td, imgp, stack);
 
 	/* Linux sets %gs to 0, we default to _udatasel */
 	pcb->pcb_gs = 0;
diff --git a/sys/ia64/ia32/ia32_signal.c b/sys/ia64/ia32/ia32_signal.c
index a981c8444cd..e5eee411ccd 100644
--- a/sys/ia64/ia32/ia32_signal.c
+++ b/sys/ia64/ia32/ia32_signal.c
@@ -120,7 +120,7 @@ freebsd32_sigreturn(struct thread *td, struct freebsd32_sigreturn_args *uap)
 
 
 void
-ia32_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
+ia32_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 {
 	struct trapframe *tf = td->td_frame;
 	vm_offset_t gdt, ldt;
@@ -129,7 +129,7 @@ ia32_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
 	struct segment_descriptor desc;
 	struct vmspace *vmspace = td->td_proc->p_vmspace;
 
-	exec_setregs(td, entry, stack, ps_strings);
+	exec_setregs(td, imgp, stack);
 
 	/* Non-syscall frames are cleared by exec_setregs() */
 	if (tf->tf_flags & FRAME_SYSCALL) {
diff --git a/sys/ia64/ia64/machdep.c b/sys/ia64/ia64/machdep.c
index ec3d612ebac..9f47a9a1803 100644
--- a/sys/ia64/ia64/machdep.c
+++ b/sys/ia64/ia64/machdep.c
@@ -1328,7 +1328,7 @@ set_mcontext(struct thread *td, const mcontext_t *mc)
  * Clear registers on exec.
  */
 void
-exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
+exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 {
 	struct trapframe *tf;
 	uint64_t *ksttop, *kst;
@@ -1366,7 +1366,7 @@ exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
 		*kst-- = 0;
 		if (((uintptr_t)kst & 0x1ff) == 0x1f8)
 			*kst-- = 0;
-		*kst-- = ps_strings;
+		*kst-- = imgp->ps_strings;
 		if (((uintptr_t)kst & 0x1ff) == 0x1f8)
 			*kst-- = 0;
 		*kst = stack;
@@ -1385,7 +1385,7 @@ exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
 		suword((caddr_t)tf->tf_special.bspstore -  8, 0);
 	}
 
-	tf->tf_special.iip = entry;
+	tf->tf_special.iip = imgp->entry_addr;
 	tf->tf_special.sp = (stack & ~15) - 16;
 	tf->tf_special.rsc = 0xf;
 	tf->tf_special.fpsr = IA64_FPSR_DEFAULT;
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index c7a4358270a..17a0ac61865 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -799,11 +799,10 @@ interpret:
 
 	/* Set values passed into the program in registers. */
 	if (p->p_sysent->sv_setregs)
-		(*p->p_sysent->sv_setregs)(td, imgp->entry_addr,
-		    (u_long)(uintptr_t)stack_base, imgp->ps_strings);
+		(*p->p_sysent->sv_setregs)(td, imgp, 
+		    (u_long)(uintptr_t)stack_base);
 	else
-		exec_setregs(td, imgp->entry_addr,
-		    (u_long)(uintptr_t)stack_base, imgp->ps_strings);
+		exec_setregs(td, imgp, (u_long)(uintptr_t)stack_base);
 
 	vfs_mark_atime(imgp->vp, td->td_ucred);
 
diff --git a/sys/mips/mips/pm_machdep.c b/sys/mips/mips/pm_machdep.c
index 712763b1020..03867b0a839 100644
--- a/sys/mips/mips/pm_machdep.c
+++ b/sys/mips/mips/pm_machdep.c
@@ -472,7 +472,7 @@ set_fpregs(struct thread *td, struct fpreg *fpregs)
  * code by the MIPS elf abi).
  */
 void
-exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
+exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 {
 
 	bzero((caddr_t)td->td_frame, sizeof(struct trapframe));
@@ -481,8 +481,8 @@ exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
 	 * Make sp 64-bit aligned.
 	 */
 	td->td_frame->sp = ((register_t) stack) & ~(sizeof(__int64_t) - 1);
-	td->td_frame->pc = entry & ~3;
-	td->td_frame->t9 = entry & ~3; /* abicall req */
+	td->td_frame->pc = imgp->entry_addr & ~3;
+	td->td_frame->t9 = imgp->entry_addr & ~3; /* abicall req */
 #if 0
 //	td->td_frame->sr = SR_KSU_USER | SR_EXL | SR_INT_ENAB;
 //?	td->td_frame->sr |=  idle_mask & ALL_INT_MASK;
@@ -511,7 +511,7 @@ exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
 	td->td_frame->a0 = (register_t) stack;
 	td->td_frame->a1 = 0;
 	td->td_frame->a2 = 0;
-	td->td_frame->a3 = (register_t)ps_strings;
+	td->td_frame->a3 = (register_t)imgp->ps_strings;
 
 	td->td_md.md_flags &= ~MDTD_FPUSED;
 	if (PCPU_GET(fpcurthread) == td)
diff --git a/sys/pc98/pc98/machdep.c b/sys/pc98/pc98/machdep.c
index f17874820b0..f470b5ef5ef 100644
--- a/sys/pc98/pc98/machdep.c
+++ b/sys/pc98/pc98/machdep.c
@@ -1172,11 +1172,7 @@ void (*cpu_idle_hook)(void) = cpu_idle_default;
  * Reset registers to default values on exec.
  */
 void
-exec_setregs(td, entry, stack, ps_strings)
-	struct thread *td;
-	u_long entry;
-	u_long stack;
-	u_long ps_strings;
+exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 {
 	struct trapframe *regs = td->td_frame;
 	struct pcb *pcb = td->td_pcb;
@@ -1192,7 +1188,7 @@ exec_setregs(td, entry, stack, ps_strings)
 		mtx_unlock_spin(&dt_lock);
   
 	bzero((char *)regs, sizeof(struct trapframe));
-	regs->tf_eip = entry;
+	regs->tf_eip = imgp->entry_addr;
 	regs->tf_esp = stack;
 	regs->tf_eflags = PSL_USER | (regs->tf_eflags & PSL_T);
 	regs->tf_ss = _udatasel;
@@ -1202,7 +1198,7 @@ exec_setregs(td, entry, stack, ps_strings)
 	regs->tf_cs = _ucodesel;
 
 	/* PS_STRINGS value for BSD/OS binaries.  It is 0 for non-BSD/OS. */
-	regs->tf_ebx = ps_strings;
+	regs->tf_ebx = imgp->ps_strings;
 
         /*
          * Reset the hardware debug registers if they were in use.
diff --git a/sys/powerpc/aim/machdep.c b/sys/powerpc/aim/machdep.c
index a9cf051b57f..49aae27cfe6 100644
--- a/sys/powerpc/aim/machdep.c
+++ b/sys/powerpc/aim/machdep.c
@@ -951,7 +951,7 @@ cpu_idle_wakeup(int cpu)
  * Set set up registers on exec.
  */
 void
-exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
+exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 {
 	struct trapframe	*tf;
 	struct ps_strings	arginfo;
@@ -995,7 +995,7 @@ exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
 	tf->fixreg[7] = 0;			/* termination vector */
 	tf->fixreg[8] = (register_t)PS_STRINGS;	/* NetBSD extension */
 
-	tf->srr0 = entry;
+	tf->srr0 = imgp->entry_addr;
 	tf->srr1 = PSL_MBO | PSL_USERSET | PSL_FE_DFLT;
 	td->td_pcb->pcb_flags = 0;
 }
diff --git a/sys/powerpc/booke/machdep.c b/sys/powerpc/booke/machdep.c
index e9a0099497c..8a53b7355f9 100644
--- a/sys/powerpc/booke/machdep.c
+++ b/sys/powerpc/booke/machdep.c
@@ -509,7 +509,7 @@ cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t sz)
 
 /* Set set up registers on exec. */
 void
-exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
+exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 {
 	struct trapframe *tf;
 	struct ps_strings arginfo;
@@ -553,7 +553,7 @@ exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
 	tf->fixreg[7] = 0;			/* termination vector */
 	tf->fixreg[8] = (register_t)PS_STRINGS;	/* NetBSD extension */
 
-	tf->srr0 = entry;
+	tf->srr0 = imgp->entry_addr;
 	tf->srr1 = PSL_USERSET;
 	td->td_pcb->pcb_flags = 0;
 }
diff --git a/sys/sparc64/sparc64/machdep.c b/sys/sparc64/sparc64/machdep.c
index 9eab20fce39..a020fb8038f 100644
--- a/sys/sparc64/sparc64/machdep.c
+++ b/sys/sparc64/sparc64/machdep.c
@@ -969,7 +969,7 @@ ptrace_clear_single_step(struct thread *td)
 }
 
 void
-exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
+exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 {
 	struct trapframe *tf;
 	struct pcb *pcb;
@@ -992,8 +992,8 @@ exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
 	tf->tf_out[0] = stack;
 	tf->tf_out[3] = p->p_sysent->sv_psstrings;
 	tf->tf_out[6] = sp - SPOFF - sizeof(struct frame);
-	tf->tf_tnpc = entry + 4;
-	tf->tf_tpc = entry;
+	tf->tf_tnpc = imgp->entry_addr + 4;
+	tf->tf_tpc = imgp->entry_addr;
 	tf->tf_tstate = TSTATE_IE | TSTATE_PEF | TSTATE_MM_TSO;
 
 	td->td_retval[0] = tf->tf_out[0];
diff --git a/sys/sun4v/sun4v/machdep.c b/sys/sun4v/sun4v/machdep.c
index 3913d35ca02..e14eebd9f8c 100644
--- a/sys/sun4v/sun4v/machdep.c
+++ b/sys/sun4v/sun4v/machdep.c
@@ -869,7 +869,7 @@ ptrace_clear_single_step(struct thread *td)
 }
 
 void
-exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
+exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 {
 	struct trapframe *tf;
 	struct pcb *pcb;
@@ -897,8 +897,8 @@ exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
 	tf->tf_out[3] = p->p_sysent->sv_psstrings;
 	tf->tf_out[6] = sp - SPOFF - sizeof(struct frame);
 
-	tf->tf_tnpc = entry + 4;
-	tf->tf_tpc = entry;
+	tf->tf_tnpc = imgp->entry_addr + 4;
+	tf->tf_tpc = imgp->entry_addr;
 	tf->tf_tstate = TSTATE_IE | TSTATE_PEF | TSTATE_MM_TSO;
 
 	td->td_retval[0] = tf->tf_out[0];
diff --git a/sys/sys/imgact.h b/sys/sys/imgact.h
index 79b389ebe38..86984f6cafb 100644
--- a/sys/sys/imgact.h
+++ b/sys/sys/imgact.h
@@ -80,7 +80,7 @@ struct thread;
 int	exec_check_permissions(struct image_params *);
 register_t *exec_copyout_strings(struct image_params *);
 int	exec_new_vmspace(struct image_params *, struct sysentvec *);
-void	exec_setregs(struct thread *, u_long, u_long, u_long);
+void	exec_setregs(struct thread *, struct image_params *, u_long);
 int	exec_shell_imgact(struct image_params *);
 int	exec_copyin_args(struct image_args *, char *, enum uio_seg,
 	char **, char **);
diff --git a/sys/sys/sysent.h b/sys/sys/sysent.h
index 707c00bc444..c3a19d82d16 100644
--- a/sys/sys/sysent.h
+++ b/sys/sys/sysent.h
@@ -98,7 +98,8 @@ struct sysentvec {
 	vm_offset_t	sv_psstrings;	/* PS_STRINGS */
 	int		sv_stackprot;	/* vm protection for stack */
 	register_t	*(*sv_copyout_strings)(struct image_params *);
-	void		(*sv_setregs)(struct thread *, u_long, u_long, u_long);
+	void		(*sv_setregs)(struct thread *, struct image_params *,
+			    u_long);
 	void		(*sv_fixlimit)(struct rlimit *, int);
 	u_long		*sv_maxssiz;
 	u_int		sv_flags;

From a0ea661f5e3a47074e54104f403d8356a5946a8f Mon Sep 17 00:00:00 2001
From: Nathan Whitehorn 
Date: Thu, 25 Mar 2010 14:31:26 +0000
Subject: [PATCH 061/119] Add the ELF relocation base to struct image_params.
 This will be required to correctly relocate the executable entry point's
 function descriptor on powerpc64.

---
 sys/kern/imgact_elf.c | 1 +
 sys/kern/kern_exec.c  | 1 +
 sys/sys/imgact.h      | 1 +
 3 files changed, 3 insertions(+)

diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c
index 47e1f64b6ce..236894f4b2d 100644
--- a/sys/kern/imgact_elf.c
+++ b/sys/kern/imgact_elf.c
@@ -943,6 +943,7 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp)
 
 	imgp->auxargs = elf_auxargs;
 	imgp->interpreted = 0;
+	imgp->reloc_base = addr;
 	imgp->proc->p_osrel = osrel;
 
 	return (error);
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 17a0ac61865..ed22519f693 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -372,6 +372,7 @@ do_execve(td, args, mac_p)
 	imgp->execlabel = NULL;
 	imgp->attr = &attr;
 	imgp->entry_addr = 0;
+	imgp->reloc_base = 0;
 	imgp->vmspace_destroyed = 0;
 	imgp->interpreted = 0;
 	imgp->opened = 0;
diff --git a/sys/sys/imgact.h b/sys/sys/imgact.h
index 86984f6cafb..1d1e3619e0e 100644
--- a/sys/sys/imgact.h
+++ b/sys/sys/imgact.h
@@ -56,6 +56,7 @@ struct image_params {
 	struct vattr *attr;	/* attributes of file */
 	const char *image_header; /* head of file to exec */
 	unsigned long entry_addr; /* entry address of target executable */
+	unsigned long reloc_base; /* load address of image */
 	char vmspace_destroyed;	/* flag - we've blown away original vm space */
 	char interpreted;	/* flag - this executable is interpreted */
 	char opened;		/* flag - we have opened executable vnode */

From ad51361a2ca6c2932e50c867f8be945dd5504ed8 Mon Sep 17 00:00:00 2001
From: Jung-uk Kim 
Date: Thu, 25 Mar 2010 15:56:04 +0000
Subject: [PATCH 062/119] Fix stupid typos.  Some VESA BIOSes directly call
 BIOS interrupt handlers within the VBE interrupt handler.  Unfortunately it
 was causing real mode page faults because we were fetching instructions from
 bogus addresses. Pass me the pointyhat, please.

PR:		kern/144654
MFC after:	3 days
---
 sys/compat/x86bios/x86bios.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/compat/x86bios/x86bios.c b/sys/compat/x86bios/x86bios.c
index af352af3a2f..e90d80bac57 100644
--- a/sys/compat/x86bios/x86bios.c
+++ b/sys/compat/x86bios/x86bios.c
@@ -307,8 +307,8 @@ x86bios_emu_get_intr(struct x86emu *emu, int intno)
 	sp[2] = htole16(emu->x86.R_FLG);
 
 	iv = x86bios_get_intr(intno);
-	emu->x86.R_IP = iv & 0x000f;
-	emu->x86.R_CS = (iv >> 12) & 0xffff;
+	emu->x86.R_IP = iv & 0xffff;
+	emu->x86.R_CS = (iv >> 16) & 0xffff;
 	emu->x86.R_FLG &= ~(F_IF | F_TF);
 }
 

From d7312c88b4ff6375a89830515901de78d2b4c9f7 Mon Sep 17 00:00:00 2001
From: Jung-uk Kim 
Date: Thu, 25 Mar 2010 17:03:52 +0000
Subject: [PATCH 063/119] Optimize real mode page table lookup.

---
 sys/compat/x86bios/x86bios.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/sys/compat/x86bios/x86bios.c b/sys/compat/x86bios/x86bios.c
index e90d80bac57..d4e650ce42d 100644
--- a/sys/compat/x86bios/x86bios.c
+++ b/sys/compat/x86bios/x86bios.c
@@ -112,17 +112,16 @@ x86bios_set_fault(struct x86emu *emu, uint32_t addr)
 static void *
 x86bios_get_pages(uint32_t offset, size_t size)
 {
-	int i;
+	vm_offset_t page;
 
 	if (offset + size > X86BIOS_MEM_SIZE + X86BIOS_IVT_SIZE)
 		return (NULL);
 
 	if (offset >= X86BIOS_MEM_SIZE)
 		offset -= X86BIOS_MEM_SIZE;
-	i = offset / X86BIOS_PAGE_SIZE;
-	if (x86bios_map[i] != 0)
-		return ((void *)(x86bios_map[i] + offset -
-		    i * X86BIOS_PAGE_SIZE));
+	page = x86bios_map[offset / X86BIOS_PAGE_SIZE];
+	if (page != 0)
+		return ((void *)(page + offset % X86BIOS_PAGE_SIZE));
 
 	return (NULL);
 }

From bfd026445f0ca758c1b84780d5049091934f1765 Mon Sep 17 00:00:00 2001
From: Jung-uk Kim 
Date: Thu, 25 Mar 2010 17:14:47 +0000
Subject: [PATCH 064/119] Revert accidentally committed initial real mode %sp
 change of r205347. Note I am keeping %ds change because X.org int10 handler
 does it and it seems reasonable.

---
 sys/compat/x86bios/x86bios.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/sys/compat/x86bios/x86bios.c b/sys/compat/x86bios/x86bios.c
index d4e650ce42d..d5512fc43f3 100644
--- a/sys/compat/x86bios/x86bios.c
+++ b/sys/compat/x86bios/x86bios.c
@@ -68,7 +68,6 @@ __FBSDID("$FreeBSD$");
 
 #define	X86BIOS_R_DS		_pad1
 #define	X86BIOS_R_SS		_pad2
-#define	X86BIOS_R_SP		_pad3.I16_reg.x_reg
 
 static struct x86emu x86bios_emu;
 
@@ -354,7 +353,6 @@ x86bios_init_regs(struct x86regs *regs)
 	bzero(regs, sizeof(*regs));
 	regs->X86BIOS_R_DS = 0x40;
 	regs->X86BIOS_R_SS = x86bios_seg_phys >> 4;
-	regs->X86BIOS_R_SP = 0xfffe;
 }
 
 void

From d2b6e9a0bcc319384ee66ff967aecc58b10affbf Mon Sep 17 00:00:00 2001
From: Pyun YongHyeon 
Date: Thu, 25 Mar 2010 17:17:35 +0000
Subject: [PATCH 065/119] Use pci_get_max_read_req() and pci_set_max_read_req()
 to set maximim read request size.

---
 sys/dev/bge/if_bge.c | 30 ++----------------------------
 1 file changed, 2 insertions(+), 28 deletions(-)

diff --git a/sys/dev/bge/if_bge.c b/sys/dev/bge/if_bge.c
index b21fd72c235..4333f2044b7 100644
--- a/sys/dev/bge/if_bge.c
+++ b/sys/dev/bge/if_bge.c
@@ -421,7 +421,6 @@ static uint32_t bge_readreg_ind(struct bge_softc *, int);
 #endif
 static void bge_writemem_direct(struct bge_softc *, int, int);
 static void bge_writereg_ind(struct bge_softc *, int, int);
-static void bge_set_max_readrq(struct bge_softc *);
 
 static int bge_miibus_readreg(device_t, int, int);
 static int bge_miibus_writereg(device_t, int, int, int);
@@ -561,32 +560,6 @@ bge_writemem_ind(struct bge_softc *sc, int off, int val)
 	pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, 0, 4);
 }
 
-/*
- * PCI Express only
- */
-static void
-bge_set_max_readrq(struct bge_softc *sc)
-{
-	device_t dev;
-	uint16_t val;
-
-	dev = sc->bge_dev;
-
-	val = pci_read_config(dev, sc->bge_expcap + PCIR_EXPRESS_DEVICE_CTL, 2);
-	if ((val & PCIM_EXP_CTL_MAX_READ_REQUEST) !=
-	    BGE_PCIE_DEVCTL_MAX_READRQ_4096) {
-		if (bootverbose)
-			device_printf(dev, "adjust device control 0x%04x ",
-			    val);
-		val &= ~PCIM_EXP_CTL_MAX_READ_REQUEST;
-		val |= BGE_PCIE_DEVCTL_MAX_READRQ_4096;
-		pci_write_config(dev, sc->bge_expcap + PCIR_EXPRESS_DEVICE_CTL,
-		    val, 2);
-		if (bootverbose)
-			printf("-> 0x%04x\n", val);
-	}
-}
-
 #ifdef notdef
 static uint32_t
 bge_readreg_ind(struct bge_softc *sc, int off)
@@ -2695,7 +2668,8 @@ bge_attach(device_t dev)
 		 */
 		sc->bge_flags |= BGE_FLAG_PCIE;
 		sc->bge_expcap = reg;
-		bge_set_max_readrq(sc);
+		if (pci_get_max_read_req(dev) != 4096)
+			pci_set_max_read_req(dev, 4096);
 	} else {
 		/*
 		 * Check if the device is in PCI-X Mode.

From 09fcdf114ee760c1b779e76990aee1cd03b98c11 Mon Sep 17 00:00:00 2001
From: Alan Cox 
Date: Thu, 25 Mar 2010 17:24:03 +0000
Subject: [PATCH 066/119] A ptrace(2) by one processor may trigger a promotion
 in the address space of another process.  Modify pmap_promote_pde() to handle
 this.  (This is not a problem on amd64 due to implementation differences.)

Reported by:	jh@
MFC after:	1 week
---
 sys/i386/i386/pmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/i386/i386/pmap.c b/sys/i386/i386/pmap.c
index c83e99c2410..c5018786433 100644
--- a/sys/i386/i386/pmap.c
+++ b/sys/i386/i386/pmap.c
@@ -3154,7 +3154,7 @@ pmap_promote_pde(pmap_t pmap, pd_entry_t *pde, vm_offset_t va)
 	 * either invalid, unused, or does not map the first 4KB physical page
 	 * within a 2- or 4MB page.
 	 */
-	firstpte = vtopte(trunc_4mpage(va));
+	firstpte = pmap_pte_quick(pmap, trunc_4mpage(va));
 setpde:
 	newpde = *firstpte;
 	if ((newpde & ((PG_FRAME & PDRMASK) | PG_A | PG_V)) != (PG_A | PG_V)) {

From bb6ba5f6b97bf5fb11f2b7baa44580859db7380c Mon Sep 17 00:00:00 2001
From: Jung-uk Kim 
Date: Thu, 25 Mar 2010 17:51:05 +0000
Subject: [PATCH 067/119] Do not penalize correct or correctable VESA mode
 tables by calling another VBE function.  Most problems should be corrected by
 the mode table sanity check and we only need the paranoid in extremely rare
 cases.

---
 sys/dev/fb/vesa.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/sys/dev/fb/vesa.c b/sys/dev/fb/vesa.c
index 0c1d5ddce23..e89ba4b3918 100644
--- a/sys/dev/fb/vesa.c
+++ b/sys/dev/fb/vesa.c
@@ -189,7 +189,9 @@ static int vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g,
 #define STATE_ALL	(STATE_HW | STATE_DATA | STATE_DAC | STATE_REG)
 static ssize_t vesa_bios_state_buf_size(void);
 static int vesa_bios_save_restore(int code, void *p, size_t size);
+#ifdef MODE_TABLE_BROKEN
 static int vesa_bios_get_line_length(void);
+#endif
 static int vesa_bios_set_line_length(int pixel, int *bytes, int *lines);
 #if 0
 static int vesa_bios_get_start(int *x, int *y);
@@ -558,6 +560,7 @@ vesa_bios_save_restore(int code, void *p, size_t size)
 	return (regs.R_AX != 0x004f);
 }
 
+#ifdef MODE_TABLE_BROKEN
 static int
 vesa_bios_get_line_length(void)
 {
@@ -574,6 +577,7 @@ vesa_bios_get_line_length(void)
 
 	return (regs.R_BX);
 }
+#endif
 
 static int
 vesa_bios_set_line_length(int pixel, int *bytes, int *lines)
@@ -1213,7 +1217,6 @@ static int
 vesa_set_mode(video_adapter_t *adp, int mode)
 {
 	video_info_t info;
-	int bpsl;
 
 	if (adp != vesa_adp)
 		return ((*prevvidsw->set_mode)(adp, mode));
@@ -1295,14 +1298,18 @@ vesa_set_mode(video_adapter_t *adp, int mode)
 	if ((info.vi_flags & V_INFO_GRAPHICS) != 0)
 		vesa_adp->va_line_width /= info.vi_planes;
 
+#ifdef MODE_TABLE_BROKEN
 	/* If VBE function returns bigger bytes per scan line, use it. */
-	bpsl = vesa_bios_get_line_length();
-	if (bpsl > vesa_adp->va_line_width) {
-		vesa_adp->va_line_width = bpsl;
-		info.vi_buffer_size = bpsl * info.vi_height;
-		if ((info.vi_flags & V_INFO_GRAPHICS) != 0)
-			info.vi_buffer_size *= info.vi_planes;
+	{
+		int bpsl = vesa_bios_get_line_length();
+		if (bpsl > vesa_adp->va_line_width) {
+			vesa_adp->va_line_width = bpsl;
+			info.vi_buffer_size = bpsl * info.vi_height;
+			if ((info.vi_flags & V_INFO_GRAPHICS) != 0)
+				info.vi_buffer_size *= info.vi_planes;
+		}
 	}
+#endif
 
 	if (info.vi_flags & V_INFO_LINEAR) {
 #if VESA_DEBUG > 1

From 780179e8719c210a27555302dc2e31ebb7b6e7a6 Mon Sep 17 00:00:00 2001
From: Xin LI 
Date: Thu, 25 Mar 2010 20:02:54 +0000
Subject: [PATCH 068/119] The rmt client in GNU cpio could have a heap overflow
 when a malicious remote tape service returns deliberately crafted packets
 containing more data than requested.

Fix this by checking the returned amount of data and bail out when it
is more than what we requested.

PR:		gnu/145010
Submitted by:	naddy
Reviewed by:	imp
MFC after:	immediately
Security:	CVE-2010-0624
---
 contrib/cpio/lib/rtapelib.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/contrib/cpio/lib/rtapelib.c b/contrib/cpio/lib/rtapelib.c
index af19b04c5d4..d73d1364e84 100644
--- a/contrib/cpio/lib/rtapelib.c
+++ b/contrib/cpio/lib/rtapelib.c
@@ -570,7 +570,8 @@ rmt_read__ (int handle, char *buffer, size_t length)
 
   sprintf (command_buffer, "R%lu\n", (unsigned long) length);
   if (do_command (handle, command_buffer) == -1
-      || (status = get_status (handle)) == SAFE_READ_ERROR)
+      || (status = get_status (handle)) == SAFE_READ_ERROR
+      || status > length)
     return SAFE_READ_ERROR;
 
   for (counter = 0; counter < status; counter += rlen, buffer += rlen)

From d56cc5591766aeb662eb92411d2a0ee3c0972997 Mon Sep 17 00:00:00 2001
From: Xin LI 
Date: Thu, 25 Mar 2010 22:41:01 +0000
Subject: [PATCH 069/119] Check that gl_pathc is bigger than zero before
 derefencing gl_pathv. When gl_pathc == 0, the content of gl_pathv is
 undefined.

PR:		bin/144761
Submitted by:	David BERARD 
Obtained from:	OpenBSD
MFC after:	1 week
---
 libexec/ftpd/popen.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libexec/ftpd/popen.c b/libexec/ftpd/popen.c
index 3c187b94daf..8a739dc2ffe 100644
--- a/libexec/ftpd/popen.c
+++ b/libexec/ftpd/popen.c
@@ -110,10 +110,11 @@ ftpd_popen(char *program, char *type)
 		flags |= GLOB_LIMIT;
 		if (glob(argv[argc], flags, NULL, &gl))
 			gargv[gargc++] = strdup(argv[argc]);
-		else
+		else if (gl.gl_pathc > 0) {
 			for (pop = gl.gl_pathv; *pop && gargc < (MAXGLOBARGS-1);
 			     pop++)
 				gargv[gargc++] = strdup(*pop);
+		}
 		globfree(&gl);
 	}
 	gargv[gargc] = NULL;

From 2261a4056ec55ed176e80a39d7c650796bf68562 Mon Sep 17 00:00:00 2001
From: Daniel Gerzo 
Date: Fri, 26 Mar 2010 00:49:06 +0000
Subject: [PATCH 070/119] - update zfs and zpool manual pages to match the
 current state of the source

PR:		144984
Submitted by:	mm@
Approved by:	pjd@
Obtained from:	OpenSolaris
MFC after:	4 days
---
 cddl/contrib/opensolaris/cmd/zfs/zfs.8     | 998 ++++++++++-----------
 cddl/contrib/opensolaris/cmd/zpool/zpool.8 | 205 ++---
 2 files changed, 579 insertions(+), 624 deletions(-)

diff --git a/cddl/contrib/opensolaris/cmd/zfs/zfs.8 b/cddl/contrib/opensolaris/cmd/zfs/zfs.8
index 39445ea13a8..9cda0e55643 100644
--- a/cddl/contrib/opensolaris/cmd/zfs/zfs.8
+++ b/cddl/contrib/opensolaris/cmd/zfs/zfs.8
@@ -1,24 +1,9 @@
 '\" te
-.\" CDDL HEADER START
-.\"
-.\" The contents of this file are subject to the terms of the
-.\" Common Development and Distribution License (the "License").  
-.\" You may not use this file except in compliance with the License.
-.\"
-.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
-.\" or http://www.opensolaris.org/os/licensing.
-.\" See the License for the specific language governing permissions
-.\" and limitations under the License.
-.\"
-.\" When distributing Covered Code, include this CDDL HEADER in each
-.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
-.\" If applicable, add the following below this CDDL HEADER, with the
-.\" fields enclosed by brackets "[]" replaced with your own identifying
-.\" information: Portions Copyright [yyyy] [name of copyright owner]
-.\"
-.\" CDDL HEADER END
-.\" Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
-.TH zfs 1M "8 Apr 2008" "SunOS 5.11" "System Administration Commands"
+.\" Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
+.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
+.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
+.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
+.TH zfs 1M "14 Feb 2009" "SunOS 5.11" "System Administration Commands"
 .SH NAME
 zfs \- configures ZFS file systems
 .SH SYNOPSIS
@@ -44,7 +29,8 @@ zfs \- configures ZFS file systems
 
 .LP
 .nf
-\fBzfs\fR \fBsnapshot\fR [\fB-r\fR] \fIfilesystem@snapname\fR|\fIvolume@snapname\fR
+\fBzfs\fR \fBsnapshot\fR [\fB-r\fR] [\fB-o\fR \fIproperty\fR=\fIvalue\fR]... 
+      \fIfilesystem@snapname\fR|\fIvolume@snapname\fR
 .fi
 
 .LP
@@ -54,7 +40,7 @@ zfs \- configures ZFS file systems
 
 .LP
 .nf
-\fBzfs\fR \fBclone\fR [\fB-p\fR] \fIsnapshot\fR \fIfilesystem\fR|\fIvolume\fR
+\fBzfs\fR \fBclone\fR [\fB-p\fR] [\fB-o\fR \fIproperty\fR=\fIvalue\fR] ... \fIsnapshot\fR \fIfilesystem\fR|\fIvolume\fR
 .fi
 
 .LP
@@ -65,7 +51,7 @@ zfs \- configures ZFS file systems
 .LP
 .nf
 \fBzfs\fR \fBrename\fR \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR 
-    \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR
+     \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR
 .fi
 
 .LP
@@ -81,23 +67,23 @@ zfs \- configures ZFS file systems
 .LP
 .nf
 \fBzfs\fR \fBlist\fR [\fB-rH\fR] [\fB-o\fR \fIproperty\fR[,...]] [\fB-t\fR \fItype\fR[,...]]
-    [\fB-s\fR \fIproperty\fR] ... [\fB-S\fR \fIproperty\fR ... [\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR] ...
+     [\fB-s\fR \fIproperty\fR] ... [\fB-S\fR \fIproperty\fR] ... [\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR] ...
 .fi
 
 .LP
 .nf
-\fBzfs\fR \fBset\fR \fIproperty\fR=\fIvalue\fR \fIfilesystem\fR|\fIvolume\fR ...
+\fBzfs\fR \fBset\fR \fIproperty\fR=\fIvalue\fR \fIfilesystem\fR|\fIvolume\fR|snapshot ...
 .fi
 
 .LP
 .nf
 \fBzfs\fR \fBget\fR [\fB-rHp\fR] [\fB-o\fR \fIfield\fR[,...]] [\fB-s\fR \fIsource\fR[,...]] "\fIall\fR" | \fIproperty\fR[,...]
-     \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ...
+      \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ...
 .fi
 
 .LP
 .nf
-\fBzfs\fR \fBinherit\fR [\fB-r\fR] \fIproperty\fR \fIfilesystem\fR|\fIvolume\fR ...
+\fBzfs\fR \fBinherit\fR [\fB-r\fR] \fIproperty\fR \fIfilesystem\fR|\fIvolume|snapshot\fR ...
 .fi
 
 .LP
@@ -132,12 +118,12 @@ zfs \- configures ZFS file systems
 
 .LP
 .nf
-\fBzfs\fR \fBunshare\fR  \fB-a\fR \fIfilesystem\fR|\fImountpoint\fR
+\fBzfs\fR \fBunshare\fR \fB-a\fR \fIfilesystem\fR|\fImountpoint\fR
 .fi
 
 .LP
 .nf
-\fBzfs\fR \fBsend\fR [\fB-vR\fR] [\fB-\fR[\fB-iI\fR] \fIsnapshot\fR] \fIsnapshot\fR
+\fBzfs\fR \fBsend\fR [\fB-vR\fR] [\fB-\fR[\fBiI\fR] \fIsnapshot\fR] \fIsnapshot\fR
 .fi
 
 .LP
@@ -153,7 +139,7 @@ zfs \- configures ZFS file systems
 .LP
 .nf
 \fBzfs\fR \fBallow\fR [\fB-ldug\fR] "\fIeveryone\fR"|\fIuser\fR|\fIgroup\fR[,...] \fIperm\fR|\fI@setname\fR[,...] 
-    \fIfilesystem\fR|\fIvolume\fR
+     \fIfilesystem\fR|\fIvolume\fR
 .fi
 
 .LP
@@ -174,7 +160,7 @@ zfs \- configures ZFS file systems
 .LP
 .nf
 \fBzfs\fR \fBunallow\fR [\fB-rldug\fR] "\fIeveryone\fR"|\fIuser\fR|\fIgroup\fR[,...] [\fIperm\fR|@\fIsetname\fR[,... ]] 
-    \fIfilesystem\fR|\fIvolume\fR
+     \fIfilesystem\fR|\fIvolume\fR
 .fi
 
 .LP
@@ -192,20 +178,10 @@ zfs \- configures ZFS file systems
 \fBzfs\fR \fBunallow\fR [\fB-r\fR] \fB-s\fR @setname [\fIperm\fR|@\fIsetname\fR[,... ]] \fIfilesystem\fR|\fIvolume\fR
 .fi
 
-.LP
-.nf
-\fBzfs\fR \fBjail\fR \fBjailid\fR \fB\fIfilesystem\fR\fR
-.fi
-.LP
-.nf
-\fBzfs\fR \fBunjail\fR \fBjailid\fR \fB\fIfilesystem\fR\fR
-.fi
-
 .SH DESCRIPTION
 .sp
 .LP
-The \fBzfs\fR command configures \fBZFS\fR datasets within a \fBZFS\fR storage pool, as described in \fBzpool\fR(1M). A
-dataset is identified by a unique path within the \fBZFS\fR namespace. For example:
+The \fBzfs\fR command configures \fBZFS\fR datasets within a \fBZFS\fR storage pool, as described in \fBzpool\fR(1M). A dataset is identified by a unique path within the \fBZFS\fR namespace. For example:
 .sp
 .in +2
 .nf
@@ -226,9 +202,9 @@ A dataset can be one of the following:
 .na
 \fB\fIfile system\fR\fR
 .ad
-.RS 15n
-.rt  
-A standard \fBPOSIX\fR file system. \fBZFS\fR file systems can be mounted within the standard file system namespace and behave like any other file system.
+.sp .6
+.RS 4n
+A \fBZFS\fR dataset of type "filesystem" that can be mounted within the standard system namespace and behaves like other file systems. While \fBZFS\fR file systems are designed to be \fBPOSIX\fR compliant, known issues exist that prevent compliance in some cases. Applications that depend on standards conformance might fail due to nonstandard behavior when checking file system free space.
 .RE
 
 .sp
@@ -237,8 +213,8 @@ A standard \fBPOSIX\fR file system. \fBZFS\fR file systems can be mounted within
 .na
 \fB\fIvolume\fR\fR
 .ad
-.RS 15n
-.rt  
+.sp .6
+.RS 4n
 A logical volume exported as a raw or block device. This type of dataset should only be used under special circumstances. File systems are typically used in most environments. Volumes cannot be used in a non-global zone.
 .RE
 
@@ -248,8 +224,8 @@ A logical volume exported as a raw or block device. This type of dataset should
 .na
 \fB\fIsnapshot\fR\fR
 .ad
-.RS 15n
-.rt  
+.sp .6
+.RS 4n
 A read-only version of a file system or volume at a given point in time. It is specified as \fIfilesystem@name\fR or \fIvolume@name\fR.
 .RE
 
@@ -272,20 +248,17 @@ A snapshot is a read-only copy of a file system or volume. Snapshots can be crea
 Snapshots can have arbitrary names. Snapshots of volumes can be cloned or rolled back, but cannot be accessed independently.
 .sp
 .LP
-File system snapshots can be accessed under the ".zfs/snapshot" directory in the root of the file system. Snapshots are automatically mounted on demand and may be unmounted at regular intervals. The visibility of the ".zfs" directory can be controlled by the "snapdir"
-property.
+File system snapshots can be accessed under the ".zfs/snapshot" directory in the root of the file system. Snapshots are automatically mounted on demand and may be unmounted at regular intervals. The visibility of the ".zfs" directory can be controlled by the "snapdir" property.
 .SS "Clones"
 .sp
 .LP
 A clone is a writable volume or file system whose initial contents are the same as another dataset. As with snapshots, creating a clone is nearly instantaneous, and initially consumes no additional space.
 .sp
 .LP
-Clones can only be created from a snapshot. When a snapshot is cloned, it creates an implicit dependency between the parent and child. Even though the clone is created somewhere else in the dataset hierarchy, the original snapshot cannot be destroyed as long as a clone exists. The "origin"
-property exposes this dependency, and the \fBdestroy\fR command lists any such dependencies, if they exist.
+Clones can only be created from a snapshot. When a snapshot is cloned, it creates an implicit dependency between the parent and child. Even though the clone is created somewhere else in the dataset hierarchy, the original snapshot cannot be destroyed as long as a clone exists. The "origin" property exposes this dependency, and the \fBdestroy\fR command lists any such dependencies, if they exist.
 .sp
 .LP
-The clone parent-child dependency relationship can be reversed by using the "\fBpromote\fR" subcommand. This causes the "origin" file system to become a clone of the specified file system, which makes it possible to destroy the file system that the clone
-was created from.
+The clone parent-child dependency relationship can be reversed by using the "\fBpromote\fR" subcommand. This causes the "origin" file system to become a clone of the specified file system, which makes it possible to destroy the file system that the clone was created from.
 .SS "Mount Points"
 .sp
 .LP
@@ -301,8 +274,7 @@ A file system can also have a mount point set in the "mountpoint" property. This
 A file system mountpoint property of "none" prevents the file system from being mounted.
 .sp
 .LP
-If needed, \fBZFS\fR file systems can also be managed with traditional tools (\fBmount\fR, \fBumount\fR, \fB/etc/vfstab\fR). If a file system's mount point is set to "legacy", \fBZFS\fR makes no attempt to manage
-the file system, and the administrator is responsible for mounting and unmounting the file system.
+If needed, \fBZFS\fR file systems can also be managed with traditional tools (\fBmount\fR, \fBumount\fR, \fB/etc/vfstab\fR). If a file system's mount point is set to "legacy", \fBZFS\fR makes no attempt to manage the file system, and the administrator is responsible for mounting and unmounting the file system.
 .SS "Zones"
 .sp
 .LP
@@ -312,8 +284,7 @@ A \fBZFS\fR file system can be added to a non-global zone by using zonecfg's "\f
 The physical properties of an added file system are controlled by the global administrator. However, the zone administrator can create, modify, or destroy files within the added file system, depending on how the file system is mounted.
 .sp
 .LP
-A dataset can also be delegated to a non-global zone by using zonecfg's "\fBadd dataset\fR" subcommand. You cannot delegate a dataset to one zone and the children of the same dataset to another zone. The zone administrator can change properties of the dataset or
-any of its children. However, the "quota" property is controlled by the global administrator.
+A dataset can also be delegated to a non-global zone by using zonecfg's "\fBadd dataset\fR" subcommand. You cannot delegate a dataset to one zone and the children of the same dataset to another zone. The zone administrator can change properties of the dataset or any of its children. However, the "quota" property is controlled by the global administrator.
 .sp
 .LP
 A \fBZFS\fR volume can be added as a device to a non-global zone by using zonecfg's "\fBadd device\fR" subcommand. However, its physical properties can only be modified by the global administrator.
@@ -329,15 +300,13 @@ The global administrator can forcibly clear the "zoned" property, though this sh
 .SS "Native Properties"
 .sp
 .LP
-Properties are divided into two types, native properties and user defined properties. Native properties either export internal statistics or control \fBZFS\fR behavior. In addition, native properties are either editable or read-only. User properties have no effect on \fBZFS\fR behavior,
-but you can use them to annotate datasets in a way that is meaningful in your environment. For more information about user properties, see the "User Properties" section.
+Properties are divided into two types, native properties and user defined properties. Native properties either export internal statistics or control \fBZFS\fR behavior. In addition, native properties are either editable or read-only. User properties have no effect on \fBZFS\fR behavior, but you can use them to annotate datasets in a way that is meaningful in your environment. For more information about user properties, see the "User Properties" section.
 .sp
 .LP
-Every dataset has a set of properties that export statistics about the dataset as well as control various behavior. Properties are inherited from the parent unless overridden by the child. Snapshot properties can not be edited; they always inherit their inheritable properties. Properties
-that are not applicable to snapshots are not displayed.
+Every dataset has a set of properties that export statistics about the dataset as well as control various behavior. Properties are inherited from the parent unless overridden by the child. Some properties only apply to certain types of datasets (file systems, volumes or snapshots).
 .sp
 .LP
-The values of numeric properties can be specified using the following human-readable suffixes (for example, "k", "KB", "M", "Gb", etc, up to Z for zettabyte). The following are all valid (and equal) specifications: 
+The values of numeric properties can be specified using human-readable suffixes (for example, "k", "KB", "M", "Gb", etc, up to Z for zettabyte). The following are all valid (and equal) specifications: 
 .sp
 .in +2
 .nf
@@ -360,8 +329,7 @@ The following native properties consist of read-only statistics about the datase
 .ad
 .sp .6
 .RS 4n
-The amount of space available to the dataset and all its children, assuming that there is no other activity in the pool. Because space is shared within a pool, availability can be limited by any number of factors, including physical pool size, quotas, reservations, or other datasets
-within the pool.
+The amount of space available to the dataset and all its children, assuming that there is no other activity in the pool. Because space is shared within a pool, availability can be limited by any number of factors, including physical pool size, quotas, reservations, or other datasets within the pool.
 .sp
 This property can also be referred to by its shortened column name, "avail".
 .RE
@@ -418,8 +386,7 @@ For cloned file systems or volumes, the snapshot from which the clone was create
 .ad
 .sp .6
 .RS 4n
-The amount of data that is accessible by this dataset, which may or may not be shared with other datasets in the pool. When a snapshot or clone is created, it initially references the same amount of space as the file system or snapshot it was created from, since its contents are
-identical.
+The amount of data that is accessible by this dataset, which may or may not be shared with other datasets in the pool. When a snapshot or clone is created, it initially references the same amount of space as the file system or snapshot it was created from, since its contents are identical.
 .sp
 This property can also be referred to by its shortened column name, "refer".
 .RE
@@ -432,7 +399,7 @@ This property can also be referred to by its shortened column name, "refer".
 .ad
 .sp .6
 .RS 4n
-The type of dataset: "filesystem", "volume", "snapshot", or "clone".
+The type of dataset: "filesystem", "volume", or "snapshot".
 .RE
 
 .sp
@@ -443,15 +410,68 @@ The type of dataset: "filesystem", "volume", "snapshot", or "clone".
 .ad
 .sp .6
 .RS 4n
-The amount of space consumed by this dataset and all its descendents. This is the value that is checked against this dataset's quota and reservation. The space used does not include this dataset's reservation, but does take into account the reservations of any descendent datasets.
-The amount of space that a dataset consumes from its parent, as well as the amount of space that are freed if this dataset is recursively destroyed, is the greater of its space used and its reservation.
+The amount of space consumed by this dataset and all its descendents. This is the value that is checked against this dataset's quota and reservation. The space used does not include this dataset's reservation, but does take into account the reservations of any descendent datasets. The amount of space that a dataset consumes from its parent, as well as the amount of space that are freed if this dataset is recursively destroyed, is the greater of its space used and its reservation.
 .sp
-When snapshots (see the "Snapshots" section) are created, their space is initially shared between the snapshot and the file system, and possibly with previous snapshots. As the file system changes, space that was previously shared becomes unique to the snapshot, and counted in
-the snapshot's space used. Additionally, deleting snapshots can increase the amount of space unique to (and used by) other snapshots.
+When snapshots (see the "Snapshots" section) are created, their space is initially shared between the snapshot and the file system, and possibly with previous snapshots. As the file system changes, space that was previously shared becomes unique to the snapshot, and counted in the snapshot's space used. Additionally, deleting snapshots can increase the amount of space unique to (and used by) other snapshots.
 .sp
 The amount of space used, available, or referenced does not take into account pending changes. Pending changes are generally accounted for within a few seconds. Committing a change to a disk using \fBfsync\fR(3c) or \fBO_SYNC\fR does not necessarily guarantee that the space usage information is updated immediately.
 .RE
 
+.sp
+.ne 2
+.mk
+.na
+\fBusedby*\fR
+.ad
+.sp .6
+.RS 4n
+The \fBusedby*\fR snapshots decompose the "used" properties into the various reasons that space is used. Specifically, \fBused\fR = \fBusedbychildren\fR + \fBusedbydataset\fR + \fBusedbyrefreservation\fR +, \fBusedbysnapshots\fR. These properties are only available for datasets created on zpool "version 13" pools.
+.RE
+
+.sp
+.ne 2
+.mk
+.na
+\fBusedbychildren\fR
+.ad
+.sp .6
+.RS 4n
+The amount of space used by children of this dataset, which would be freed if all the dataset's children were destroyed.
+.RE
+
+.sp
+.ne 2
+.mk
+.na
+\fBusedbydataset\fR
+.ad
+.sp .6
+.RS 4n
+The amount of space used by this dataset itself, which would be freed if the dataset were destroyed (after first removing any \fBrefreservation\fR and destroying any necessary snapshots or descendents).
+.RE
+
+.sp
+.ne 2
+.mk
+.na
+\fBusedbyrefreservation\fR
+.ad
+.sp .6
+.RS 4n
+The amount of space used by a \fBrefreservation\fR set on this dataset, which would be freed if the \fBrefreservation\fR was removed.
+.RE
+
+.sp
+.ne 2
+.mk
+.na
+\fBusedbysnapshots\fR
+.ad
+.sp .6
+.RS 4n
+The amount of space consumed by snapshots of this dataset. In particular, it is the amount of space that would be freed if all of this dataset's snapshots were destroyed. Note that this is not simply the sum of the snapshots' "used" properties because space can be shared by multiple snapshots
+.RE
+
 .sp
 .ne 2
 .mk
@@ -460,8 +480,7 @@ The amount of space used, available, or referenced does not take into account pe
 .ad
 .sp .6
 .RS 4n
-For volumes, specifies the block size of the volume. The \fBblocksize\fR cannot be changed once the volume has been written, so it should be set at volume creation time. The default \fBblocksize\fR for volumes is 8 Kbytes. Any power of 2 from 512 bytes
-to 128 Kbytes is valid.
+For volumes, specifies the block size of the volume. The \fBblocksize\fR cannot be changed once the volume has been written, so it should be set at volume creation time. The default \fBblocksize\fR for volumes is 8 Kbytes. Any power of 2 from 512 bytes to 128 Kbytes is valid.
 .sp
 This property can also be referred to by its shortened column name, "volblock".
 .RE
@@ -473,15 +492,13 @@ The following native properties can be used to change the behavior of a \fBZFS\f
 .ne 2
 .mk
 .na
-\fBaclinherit=\fBdiscard\fR | \fBnoallow\fR | \fBrestricted\fR | \fBpassthrough\fR\fR
+\fBaclinherit=\fBdiscard\fR | \fBnoallow\fR | \fBrestricted\fR | \fBpassthrough\fR | \fBpassthrough-x\fR\fR
 .ad
 .sp .6
 .RS 4n
-Controls how \fBACL\fR entries are inherited when files and directories are created. A file system with an "aclinherit" property of "\fBdiscard\fR" does not inherit any \fBACL\fR entries. A file system with an "aclinherit"
-property value of "\fBnoallow\fR" only inherits inheritable \fBACL\fR entries that specify "deny" permissions. The property value "\fBrestricted\fR" (the default) removes the "\fBwrite_acl\fR" and "\fBwrite_owner\fR" permissions when the \fBACL\fR entry is inherited. A file system with an "aclinherit" property value of "\fBpassthrough\fR" inherits all inheritable \fBACL\fR entries without any modifications made to the \fBACL\fR entries when they are inherited.
+Controls how \fBACL\fR entries are inherited when files and directories are created. A file system with an "aclinherit" property of "\fBdiscard\fR" does not inherit any \fBACL\fR entries. A file system with an "aclinherit" property value of "\fBnoallow\fR" only inherits inheritable \fBACL\fR entries that specify "deny" permissions. The property value "\fBrestricted\fR" (the default) removes the "\fBwrite_acl\fR" and "\fBwrite_owner\fR" permissions when the \fBACL\fR entry is inherited. A file system with an "aclinherit" property value of "\fBpassthrough\fR" inherits all inheritable \fBACL\fR entries without any modifications made to the \fBACL\fR entries when they are inherited. A file system with an "aclinherit" property value of "\fBpassthrough-x\fR" has the same meaning as "\fBpassthrough\fR", except that the \fBowner@\fR, \fBgroup@\fR, and \fBeveryone@\fR \fBACE\fRs inherit the execute permission only if the file creation mode also requests the execute bit.
 .sp
-When the property value is set to "\fBpassthrough\fR," files are created with a mode determined by the inheritable \fBACE\fRs. If no inheritable \fBACE\fRs exist that affect the mode, then the mode is set in accordance to the requested mode
-from the application.
+When the property value is set to "\fBpassthrough\fR," files are created with a mode determined by the inheritable \fBACE\fRs. If no inheritable \fBACE\fRs exist that affect the mode, then the mode is set in accordance to the requested mode from the application.
 .RE
 
 .sp
@@ -492,9 +509,7 @@ from the application.
 .ad
 .sp .6
 .RS 4n
-Controls how an \fBACL\fR is modified during \fBchmod\fR(2). A file system with an "aclmode" property of "\fBdiscard\fR"
-deletes all \fBACL\fR entries that do not represent the mode of the file. An "aclmode" property of "\fBgroupmask\fR" (the default) reduces user or group permissions. The permissions are reduced, such that they are no greater than the group permission
-bits, unless it is a user entry that has the same \fBUID\fR as the owner of the file or directory. In this case, the \fBACL\fR permissions are reduced so that they are no greater than owner permission bits. A file system with an "aclmode" property of "\fBpassthrough\fR" indicates that no changes are made to the \fBACL\fR other than generating the necessary \fBACL\fR entries to represent the new mode of the file or directory.
+Controls how an \fBACL\fR is modified during \fBchmod\fR(2). A file system with an "aclmode" property of "\fBdiscard\fR" deletes all \fBACL\fR entries that do not represent the mode of the file. An "aclmode" property of "\fBgroupmask\fR" (the default) reduces user or group permissions. The permissions are reduced, such that they are no greater than the group permission bits, unless it is a user entry that has the same \fBUID\fR as the owner of the file or directory. In this case, the \fBACL\fR permissions are reduced so that they are no greater than owner permission bits. A file system with an "aclmode" property of "\fBpassthrough\fR" indicates that no changes are made to the \fBACL\fR other than generating the necessary \fBACL\fR entries to represent the new mode of the file or directory.
 .RE
 
 .sp
@@ -505,8 +520,7 @@ bits, unless it is a user entry that has the same \fBUID\fR as the owner of the
 .ad
 .sp .6
 .RS 4n
-Controls whether the access time for files is updated when they are read. Turning this property off avoids producing write traffic when reading files and can result in significant performance gains, though it might confuse mailers and other similar utilities. The default value
-is "on".
+Controls whether the access time for files is updated when they are read. Turning this property off avoids producing write traffic when reading files and can result in significant performance gains, though it might confuse mailers and other similar utilities. The default value is "on".
 .RE
 
 .sp
@@ -517,12 +531,9 @@ is "on".
 .ad
 .sp .6
 .RS 4n
-If this property is set to "\fBoff\fR", the file system cannot be mounted, and is ignored by "\fBzfs mount -a\fR". Setting this property to "\fBoff\fR" is similar to setting the "mountpoint"
-property to "\fBnone\fR", except that the dataset still has a normal "mountpoint" property, which can be inherited. Setting this property to "\fBoff\fR" allows datasets to be used solely as a mechanism to inherit properties. One example
-of setting canmount=\fBoff\fR is to have two datasets with the same mountpoint, so that the children of both datasets appear in the same directory, but might have different inherited characteristics.
+If this property is set to "\fBoff\fR", the file system cannot be mounted, and is ignored by "\fBzfs mount -a\fR". Setting this property to "\fBoff\fR" is similar to setting the "mountpoint" property to "\fBnone\fR", except that the dataset still has a normal "mountpoint" property, which can be inherited. Setting this property to "\fBoff\fR" allows datasets to be used solely as a mechanism to inherit properties. One example of setting canmount=\fBoff\fR is to have two datasets with the same mountpoint, so that the children of both datasets appear in the same directory, but might have different inherited characteristics.
 .sp
-When the "\fBnoauto\fR" option is set, a dataset can only be mounted and unmounted explicitly. The dataset is not mounted automatically when the dataset is created or imported, nor is it mounted by the "\fBzfs mount -a\fR" command or unmounted
-by the "\fBzfs unmount -a\fR" command. 
+When the "\fBnoauto\fR" option is set, a dataset can only be mounted and unmounted explicitly. The dataset is not mounted automatically when the dataset is created or imported, nor is it mounted by the "\fBzfs mount -a\fR" command or unmounted by the "\fBzfs unmount -a\fR" command. 
 .sp
 This property is not inherited.
 .RE
@@ -535,8 +546,7 @@ This property is not inherited.
 .ad
 .sp .6
 .RS 4n
-Controls the checksum used to verify data integrity. The default value is "on", which automatically selects an appropriate algorithm (currently, \fIfletcher4\fR, but this may change in future releases). The value "off" disables integrity
-checking on user data. Disabling checksums is NOT a recommended practice.
+Controls the checksum used to verify data integrity. The default value is "on", which automatically selects an appropriate algorithm (currently, \fIfletcher2\fR, but this may change in future releases). The value "off" disables integrity checking on user data. Disabling checksums is NOT a recommended practice.
 .RE
 
 .sp
@@ -547,9 +557,7 @@ checking on user data. Disabling checksums is NOT a recommended practice.
 .ad
 .sp .6
 .RS 4n
-Controls the compression algorithm used for this dataset. The "lzjb" compression algorithm is optimized for performance while providing decent data compression. Setting compression to "on" uses the "lzjb" compression algorithm. The "gzip"
-compression algorithm uses the same compression as the \fBgzip\fR(1) command. You can specify the "gzip" level by using the value "gzip-\fIN\fR" where \fIN\fR is
-an integer from 1 (fastest) to 9 (best compression ratio). Currently, "gzip" is equivalent to "gzip-6" (which is also the default for \fBgzip\fR(1)).
+Controls the compression algorithm used for this dataset. The "lzjb" compression algorithm is optimized for performance while providing decent data compression. Setting compression to "on" uses the "lzjb" compression algorithm. The "gzip" compression algorithm uses the same compression as the \fBgzip\fR(1) command. You can specify the "gzip" level by using the value "gzip-\fIN\fR" where \fIN\fR is an integer from 1 (fastest) to 9 (best compression ratio). Currently, "gzip" is equivalent to "gzip-6" (which is also the default for \fBgzip\fR(1)).
 .sp
 This property can also be referred to by its shortened column name "compress".
 .RE
@@ -562,8 +570,7 @@ This property can also be referred to by its shortened column name "compress".
 .ad
 .sp .6
 .RS 4n
-Controls the number of copies of data stored for this dataset. These copies are in addition to any redundancy provided by the pool, for example, mirroring or raid-z. The copies are stored on different disks, if possible. The space used by multiple copies is charged to the associated
-file and dataset, changing the "used" property and counting against quotas and reservations.
+Controls the number of copies of data stored for this dataset. These copies are in addition to any redundancy provided by the pool, for example, mirroring or raid-z. The copies are stored on different disks, if possible. The space used by multiple copies is charged to the associated file and dataset, changing the "used" property and counting against quotas and reservations.
 .sp
 Changing this property only affects newly-written data. Therefore, set this property at file system creation time by using the "\fB-o\fR copies=" option.
 .RE
@@ -600,8 +607,7 @@ Controls whether processes can be executed from within this file system. The def
 .RS 4n
 Controls the mount point used for this file system. See the "Mount Points" section for more information on how this property is used. 
 .sp
-When the mountpoint property is changed for a file system, the file system and any children that inherit the mount point are unmounted. If the new value is "legacy", then they remain unmounted. Otherwise, they are automatically remounted in the new location if the property was
-previously "legacy" or "none", or if they were mounted before the property was changed. In addition, any shared file systems are unshared and shared in the new location.
+When the mountpoint property is changed for a file system, the file system and any children that inherit the mount point are unmounted. If the new value is "legacy", then they remain unmounted. Otherwise, they are automatically remounted in the new location if the property was previously "legacy" or "none", or if they were mounted before the property was changed. In addition, any shared file systems are unshared and shared in the new location.
 .RE
 
 .sp
@@ -612,7 +618,18 @@ previously "legacy" or "none", or if they were mounted before the property was c
 .ad
 .sp .6
 .RS 4n
-Controls whether the file system should be mounted with "\fBnbmand\fR" (Non Blocking mandatory locks). This is used for \fBCIFS\fR clients. 	Changes to this property only take effect when the file system is umounted and remounted. See \fBmount\fR(1M) for more information on "\fBnbmand\fR" mounts.
+Controls whether the file system should be mounted with "\fBnbmand\fR" (Non Blocking mandatory locks). This is used for \fBCIFS\fR clients. Changes to this property only take effect when the file system is umounted and remounted. See \fBmount\fR(1M) for more information on "\fBnbmand\fR" mounts.
+.RE
+
+.sp
+.ne 2
+.mk
+.na
+\fBprimarycache=\fIall\fR | \fInone\fR | \fImetadata\fR\fR
+.ad
+.sp .6
+.RS 4n
+Controls what is cached in the primary cache (ARC). If this property is set to "all", then both user data and metadata is cached. If this property is set to "none", then neither user data nor metadata is cached. If this property is set to "metadata", then only metadata is cached. The default value is "all".
 .RE
 
 .sp
@@ -623,8 +640,7 @@ Controls whether the file system should be mounted with "\fBnbmand\fR" (Non Bloc
 .ad
 .sp .6
 .RS 4n
-Limits the amount of space a dataset and its descendents can consume. This property enforces a hard limit on the amount of space used. This includes all space consumed by descendents, including file systems and snapshots. Setting a quota on a descendent of a dataset that already
-has a quota does not override the ancestor's quota, but rather imposes an additional limit.
+Limits the amount of space a dataset and its descendents can consume. This property enforces a hard limit on the amount of space used. This includes all space consumed by descendents, including file systems and snapshots. Setting a quota on a descendent of a dataset that already has a quota does not override the ancestor's quota, but rather imposes an additional limit.
 .sp
 Quotas cannot be set on volumes, as the "volsize" property acts as an implicit quota.
 .RE
@@ -650,11 +666,9 @@ This property can also be referred to by its shortened column name, "rdonly".
 .ad
 .sp .6
 .RS 4n
-Specifies a suggested block size for files in the file system. This property is designed solely for use with database workloads that access files in fixed-size records. \fBZFS\fR automatically tunes block sizes according to internal algorithms optimized for typical
-access patterns. 
+Specifies a suggested block size for files in the file system. This property is designed solely for use with database workloads that access files in fixed-size records. \fBZFS\fR automatically tunes block sizes according to internal algorithms optimized for typical access patterns. 
 .sp
-For databases that create very large files but access them in small random chunks, these algorithms may be suboptimal. Specifying a "recordsize" greater than or equal to the record size of the database can result in significant performance gains. Use of this property for general
-purpose file systems is strongly discouraged, and may adversely affect performance.
+For databases that create very large files but access them in small random chunks, these algorithms may be suboptimal. Specifying a "recordsize" greater than or equal to the record size of the database can result in significant performance gains. Use of this property for general purpose file systems is strongly discouraged, and may adversely affect performance.
 .sp
 The size specified must be a power of two greater than or equal to 512 and less than or equal to 128 Kbytes.
 .sp
@@ -682,8 +696,7 @@ Limits the amount of space a dataset can consume. This property enforces a hard
 .ad
 .sp .6
 .RS 4n
-The minimum amount of space guaranteed to a dataset, not including its descendents. When the amount of space used is below this value, the dataset is treated as if it were taking up the amount of space specified by \fBrefreservation\fR. The \fBrefreservation\fR reservation
-is accounted for in the parent datasets' space used, and counts against the parent datasets' quotas and reservations.
+The minimum amount of space guaranteed to a dataset, not including its descendents. When the amount of space used is below this value, the dataset is treated as if it were taking up the amount of space specified by \fBrefreservation\fR. The \fBrefreservation\fR reservation is accounted for in the parent datasets' space used, and counts against the parent datasets' quotas and reservations.
 .sp
 If \fBrefreservation\fR is set, a snapshot is only allowed if there is enough free pool space outside of this reservation to accommodate the current number of "referenced" bytes in the dataset.
 .sp
@@ -698,12 +711,22 @@ This property can also be referred to by its shortened column name, "refreserv".
 .ad
 .sp .6
 .RS 4n
-The minimum amount of space guaranteed to a dataset and its descendents. When the amount of space used is below this value, the dataset is treated as if it were taking up the amount of space specified by its reservation. Reservations are accounted for in the parent datasets' space
-used, and count against the parent datasets' quotas and reservations.
+The minimum amount of space guaranteed to a dataset and its descendents. When the amount of space used is below this value, the dataset is treated as if it were taking up the amount of space specified by its reservation. Reservations are accounted for in the parent datasets' space used, and count against the parent datasets' quotas and reservations.
 .sp
 This property can also be referred to by its shortened column name, "reserv".
 .RE
 
+.sp
+.ne 2
+.mk
+.na
+\fBsecondarycache=\fIall\fR | \fInone\fR | \fImetadata\fR\fR
+.ad
+.sp .6
+.RS 4n
+Controls what is cached in the secondary cache (L2ARC). If this property is set to "all", then both user data and metadata is cached. If this property is set to "none", then neither user data nor metadata is cached. If this property is set to "metadata", then only metadata is cached. The default value is "all".
+.RE
+
 .sp
 .ne 2
 .mk
@@ -723,8 +746,7 @@ Controls whether the set-\fBUID\fR bit is respected for the file system. The def
 .ad
 .sp .6
 .RS 4n
-Like the "sharenfs" property, "shareiscsi" indicates whether a \fBZFS\fR volume is exported as an \fBiSCSI\fR target. The acceptable values for this property are "on", "off", and "type=disk".
-The default value is "off". In the future, other target types might be supported. For example, "tape".
+Like the "sharenfs" property, "shareiscsi" indicates whether a \fBZFS\fR volume is exported as an \fBiSCSI\fR target. The acceptable values for this property are "on", "off", and "type=disk". The default value is "off". In the future, other target types might be supported. For example, "tape".
 .sp
 You might want to set "shareiscsi=on" for a file system so that all \fBZFS\fR volumes within the file system are shared by default. Setting this property on a file system has no direct effect, however.
 .RE
@@ -737,15 +759,13 @@ You might want to set "shareiscsi=on" for a file system so that all \fBZFS\fR vo
 .ad
 .sp .6
 .RS 4n
-Controls whether the file system is shared by using the Solaris \fBCIFS\fR service, and what options are to be used. A file system with the "\fBsharesmb\fR" property set to "off" is managed through traditional tools such as \fBsharemgr\fR(1M). Otherwise, the file system is automatically shared and unshared with the "zfs share" and "zfs unshare" commands. If the property is set to "on",
-the \fBsharemgr\fR(1M) command is invoked with no options. Otherwise, the \fBsharemgr\fR(1M) command is invoked with options equivalent to the contents of this property.
+Controls whether the file system is shared by using the Solaris \fBCIFS\fR service, and what options are to be used. A file system with the "\fBsharesmb\fR" property set to "off" is managed through traditional tools such as \fBsharemgr\fR(1M). Otherwise, the file system is automatically shared and unshared with the \fBzfs share\fR and \fBzfs unshare\fR commands. If the property is set to \fBon\fR, the \fBsharemgr\fR(1M) command is invoked with no options. Otherwise, the \fBsharemgr\fR(1M) command is invoked with options equivalent to the contents of this property.
 .sp
-Because \fBSMB\fR shares requires a resource name, a unique resource name is constructed from the dataset name. The constructed name is a copy of the dataset name except that the characters in the dataset name, which would be illegal in the resource name, are replaced with underscore
-(_) characters. A pseudo property "name" is also supported that allows you to replace the data set name with a specified name. The specified name is then used to replace the prefix dataset in the case of inheritance. For example, if the dataset "\fBdata/home/john\fR"
-is set to "name=john", then "\fBdata/home/john\fR" has a resource name of "john". If a child dataset of "\fBdata/home/john/backups\fR", it has a resource name of "john_backups".
+Because \fBSMB\fR shares requires a resource name, a unique resource name is constructed from the dataset name. The constructed name is a copy of the dataset name except that the characters in the dataset name, which would be illegal in the resource name, are replaced with underscore (\fB_\fR) characters. A pseudo property "name" is also supported that allows you to replace the data set name with a specified name. The specified name is then used to replace the prefix dataset in the case of inheritance. For example, if the dataset \fBdata/home/john\fR is set to \fBname=john\fR, then \fBdata/home/john\fR has a resource name of \fBjohn\fR. If a child dataset of \fBdata/home/john/backups\fR, it has a resource name of \fBjohn_backups\fR.
 .sp
-When the "sharesmb" property is changed for a dataset, the dataset and any children inheriting the property are re-shared with the new options, only if the property was previously set to "off", or if they were shared before the property was changed. If the new property
-is set to "off", the file systems are unshared.
+When SMB shares are created, the SMB share name appears as an entry in the \fB\&.zfs/shares\fR directory. You can use the \fBls\fR or \fBchmod\fR command to display the share-level ACLs on the entries in this directory.
+.sp
+When the \fBsharesmb\fR property is changed for a dataset, the dataset and any children inheriting the property are re-shared with the new options, only if the property was previously set to \fBoff\fR, or if they were shared before the property was changed. If the new property is set to \fBoff\fR, the file systems are unshared.
 .RE
 
 .sp
@@ -756,11 +776,9 @@ is set to "off", the file systems are unshared.
 .ad
 .sp .6
 .RS 4n
-Controls whether the file system is shared via \fBNFS\fR, and what options are used. A file system with a"\fBsharenfs\fR" property of "off" is managed through traditional tools such as \fBshare\fR(1M), \fBunshare\fR(1M), and \fBdfstab\fR(4). Otherwise, the file system is automatically shared and unshared with the "\fBzfs share\fR" and "\fBzfs unshare\fR" commands. If the property is set to "on",
-the \fBshare\fR(1M) command is invoked with no options. Otherwise, the \fBshare\fR(1M) command is invoked with options equivalent to the contents of this property.
+Controls whether the file system is shared via \fBNFS\fR, and what options are used. A file system with a"\fBsharenfs\fR" property of "off" is managed through traditional tools such as \fBshare\fR(1M), \fBunshare\fR(1M), and \fBdfstab\fR(4). Otherwise, the file system is automatically shared and unshared with the "\fBzfs share\fR" and "\fBzfs unshare\fR" commands. If the property is set to "on", the \fBshare\fR(1M) command is invoked with no options. Otherwise, the \fBshare\fR(1M) command is invoked with options equivalent to the contents of this property.
 .sp
-When the "sharenfs" property is changed for a dataset, the dataset and any children inheriting the property are re-shared with the new options, only if the property was previously "off", or if they were shared before the property was changed. If the new property is "off",
-the file systems are unshared.
+When the "sharenfs" property is changed for a dataset, the dataset and any children inheriting the property are re-shared with the new options, only if the property was previously "off", or if they were shared before the property was changed. If the new property is "off", the file systems are unshared.
 .RE
 
 .sp
@@ -793,14 +811,11 @@ The on-disk version of this file system, which is independent of the pool versio
 .ad
 .sp .6
 .RS 4n
-For volumes, specifies the logical size of the volume. By default, creating a volume establishes a reservation of equal size. For storage pools with a version number of 9 or higher, a \fBrefreservation\fR is set instead. Any changes to \fBvolsize\fR are
-reflected in an equivalent change to the reservation (or \fBrefreservation\fR). The \fBvolsize\fR can only be set to a multiple of \fBvolblocksize\fR, and cannot be zero.
+For volumes, specifies the logical size of the volume. By default, creating a volume establishes a reservation of equal size. For storage pools with a version number of 9 or higher, a \fBrefreservation\fR is set instead. Any changes to \fBvolsize\fR are reflected in an equivalent change to the reservation (or \fBrefreservation\fR). The \fBvolsize\fR can only be set to a multiple of \fBvolblocksize\fR, and cannot be zero.
 .sp
-The reservation is kept equal to the volume's logical size to prevent unexpected behavior for consumers. Without the reservation, the volume could run out of space, resulting in undefined behavior or data corruption, depending on how the volume is used. These effects can also occur when
-the volume size is changed while it is in use (particularly when shrinking the size). Extreme care should be used when adjusting the volume size.
+The reservation is kept equal to the volume's logical size to prevent unexpected behavior for consumers. Without the reservation, the volume could run out of space, resulting in undefined behavior or data corruption, depending on how the volume is used. These effects can also occur when the volume size is changed while it is in use (particularly when shrinking the size). Extreme care should be used when adjusting the volume size.
 .sp
-Though not recommended, a "sparse volume" (also known as "thin provisioning") can be created by specifying the \fB-s\fR option to the "\fBzfs create -V\fR" command, or by changing the reservation after the volume has been created.
-A "sparse volume" is a volume where the reservation is less then the volume size. Consequently, writes to a sparse volume can fail with \fBENOSPC\fR when the pool is low on space. For a sparse volume, changes to \fBvolsize\fR are not reflected in the reservation.
+Though not recommended, a "sparse volume" (also known as "thin provisioning") can be created by specifying the \fB-s\fR option to the "\fBzfs create -V\fR" command, or by changing the reservation after the volume has been created. A "sparse volume" is a volume where the reservation is less then the volume size. Consequently, writes to a sparse volume can fail with \fBENOSPC\fR when the pool is low on space. For a sparse volume, changes to \fBvolsize\fR are not reflected in the reservation.
 .RE
 
 .sp
@@ -838,8 +853,7 @@ Controls whether the dataset is managed from a non-global zone. See the "Zones"
 
 .sp
 .LP
-The following three properties cannot be changed after the file system is created, and therefore, should be set when the file system is created. If the properties are not set with the "\fBzfs create\fR" command, these properties are inherited from the parent dataset.
-If the parent dataset lacks these properties due to having been created prior to these features being supported, the new file system will have the default values for these properties.
+The following three properties cannot be changed after the file system is created, and therefore, should be set when the file system is created. If the properties are not set with the "\fBzfs create\fR" or "\fBzpool create\fR" commands, these properties are inherited from the parent dataset. If the parent dataset lacks these properties due to having been created prior to these features being supported, the new file system will have the default values for these properties.
 .sp
 .ne 2
 .mk
@@ -848,11 +862,9 @@ If the parent dataset lacks these properties due to having been created prior to
 .ad
 .sp .6
 .RS 4n
-Indicates whether the file name matching algorithm used by the file system should be case-sensitive, case-insensitive, or allow a combination of both styles of matching. The default value for the "\fBcasesensitivity\fR" property is "\fBsensitive\fR."
-Traditionally, UNIX and POSIX file systems have case-sensitive file names.
+Indicates whether the file name matching algorithm used by the file system should be case-sensitive, case-insensitive, or allow a combination of both styles of matching. The default value for the "\fBcasesensitivity\fR" property is "\fBsensitive\fR." Traditionally, UNIX and POSIX file systems have case-sensitive file names.
 .sp
-The "\fBmixed\fR" value for the "\fBcasesensitivity\fR" property indicates that the file system can support requests for both case-sensitive and case-insensitive matching behavior. Currently, case-insensitive matching behavior on a file system
-that supports mixed behavior is limited to the Solaris CIFS server product. For more information about the "mixed" value behavior, see the \fIZFS Administration Guide\fR.
+The "\fBmixed\fR" value for the "\fBcasesensitivity\fR" property indicates that the file system can support requests for both case-sensitive and case-insensitive matching behavior. Currently, case-insensitive matching behavior on a file system that supports mixed behavior is limited to the Solaris CIFS server product. For more information about the "mixed" value behavior, see the \fIZFS Administration Guide\fR.
 .RE
 
 .sp
@@ -863,20 +875,7 @@ that supports mixed behavior is limited to the Solaris CIFS server product. For
 .ad
 .sp .6
 .RS 4n
-Indicates whether the file system should perform a \fBunicode\fR normalization of file names whenever two file names are compared, and which normalization algorithm should be used. File names are always stored unmodified, names are normalized as part of any comparison
-process. If this property is set to a legal value other than "\fBnone\fR," and the "\fButf8only\fR" property was left unspecified, the "\fButf8only\fR" property is automatically set to "\fBon\fR."
-The default value of the "\fBnormalization\fR" property is "\fBnone\fR." This property cannot be changed after the file system is created.
-.RE
-
-.sp
-.ne 2
-.mk
-.na
-\fBjailed =\fIon\fR | \fIoff\fR\fR
-.ad
-.sp .6
-.RS 4n
-Controls whether the dataset is managed from within a jail. The default value is "off".
+Indicates whether the file system should perform a \fBunicode\fR normalization of file names whenever two file names are compared, and which normalization algorithm should be used. File names are always stored unmodified, names are normalized as part of any comparison process. If this property is set to a legal value other than "\fBnone\fR," and the "\fButf8only\fR" property was left unspecified, the "\fButf8only\fR" property is automatically set to "\fBon\fR." The default value of the "\fBnormalization\fR" property is "\fBnone\fR." This property cannot be changed after the file system is created.
 .RE
 
 .sp
@@ -887,63 +886,52 @@ Controls whether the dataset is managed from within a jail. The default value is
 .ad
 .sp .6
 .RS 4n
-Indicates whether the file system should reject file names that include characters that are not present in the \fBUTF-8\fR character code set. If this property is explicitly set to "\fBoff\fR," the normalization property must either not be
-explicitly set or be set to "\fBnone\fR." The default value for the "\fButf8only\fR" property is "off." This property cannot be changed after the file system is created.
+Indicates whether the file system should reject file names that include characters that are not present in the \fBUTF-8\fR character code set. If this property is explicitly set to "\fBoff\fR," the normalization property must either not be explicitly set or be set to "\fBnone\fR." The default value for the "\fButf8only\fR" property is "off." This property cannot be changed after the file system is created.
 .RE
 
 .sp
 .LP
-The "\fBcasesensitivity\fR," "\fBnormalization\fR," and "\fButf8only\fR" properties are also new permissions that can be assigned to non-privileged users by using the \fBZFS\fR delegated administration
-feature.
+The "\fBcasesensitivity\fR," "\fBnormalization\fR," and "\fButf8only\fR" properties are also new permissions that can be assigned to non-privileged users by using the \fBZFS\fR delegated administration feature.
 .SS "Temporary Mount Point Properties"
 .sp
 .LP
-When a file system is mounted, either through \fBmount\fR(1M) for legacy mounts or the "\fBzfs mount\fR" command for normal file systems,
-its mount options are set according to its properties. The correlation between properties and mount options is as follows:
+When a file system is mounted, either through \fBmount\fR(1M) for legacy mounts or the "\fBzfs mount\fR" command for normal file systems, its mount options are set according to its properties. The correlation between properties and mount options is as follows:
 .sp
 .in +2
 .nf
     PROPERTY                MOUNT OPTION
-    devices                 devices/nodevices
-    exec                    exec/noexec
-    readonly                ro/rw
-    setuid                  setuid/nosetuid
-    xattr                   xattr/noxattr
+     devices                 devices/nodevices
+     exec                    exec/noexec
+     readonly                ro/rw
+     setuid                  setuid/nosetuid
+     xattr                   xattr/noxattr
 .fi
 .in -2
 .sp
 
 .sp
 .LP
-In addition, these options can be set on a per-mount basis using the \fB-o\fR option, without affecting the property that is stored on disk. The values specified on the command line override the values stored in the dataset. The \fB-nosuid\fR option is an alias for "nodevices,nosetuid".
-These properties are reported as "temporary" by the "\fBzfs get\fR" command. If the properties are changed while the dataset is mounted, the new setting overrides any temporary settings.
+In addition, these options can be set on a per-mount basis using the \fB-o\fR option, without affecting the property that is stored on disk. The values specified on the command line override the values stored in the dataset. The \fB-nosuid\fR option is an alias for "nodevices,nosetuid". These properties are reported as "temporary" by the "\fBzfs get\fR" command. If the properties are changed while the dataset is mounted, the new setting overrides any temporary settings.
 .SS "User Properties"
 .sp
 .LP
-In addition to the standard native properties, \fBZFS\fR supports arbitrary user properties. User properties have no effect on \fBZFS\fR behavior, but applications or administrators can use them to annotate datasets.
+In addition to the standard native properties, \fBZFS\fR supports arbitrary user properties. User properties have no effect on \fBZFS\fR behavior, but applications or administrators can use them to annotate datasets (file systems, volumes, and snapshots).
 .sp
 .LP
-User property names must contain a colon (":") character, to distinguish them from native properties. They might contain lowercase letters, numbers, and the following punctuation characters: colon (":"), dash ("-"), period ("."), and underscore
-("_"). The expected convention is that the property name is divided into two portions such as "\fImodule\fR:\fIproperty\fR", but this namespace is not enforced by \fBZFS\fR. User property names can be at most 256 characters,
-and cannot begin with a dash ("-").
+User property names must contain a colon (":") character to distinguish them from native properties. They may contain lowercase letters, numbers, and the following punctuation characters: colon (":"), dash ("-"), period ("."), and underscore ("_"). The expected convention is that the property name is divided into two portions such as "\fImodule\fR:\fIproperty\fR", but this namespace is not enforced by \fBZFS\fR. User property names can be at most 256 characters, and cannot begin with a dash ("-").
 .sp
 .LP
-When making programmatic use of user properties, it is strongly suggested to use a reversed \fBDNS\fR domain name for the \fImodule\fR component of property names to reduce the chance that two independently-developed packages use the same property name for
-different purposes. Property names beginning with "com.sun." are reserved for use by Sun Microsystems.
+When making programmatic use of user properties, it is strongly suggested to use a reversed \fBDNS\fR domain name for the \fImodule\fR component of property names to reduce the chance that two independently-developed packages use the same property name for different purposes. Property names beginning with "com.sun." are reserved for use by Sun Microsystems.
 .sp
 .LP
-The values of user properties are arbitrary strings, are always inherited, and are never validated. All of the commands that operate on properties ("zfs list", "zfs get", "zfs set", etc.) can be used to manipulate both native properties and user properties.
-Use the "\fBzfs inherit\fR" command to clear a user property . If the property is not defined in any parent dataset, it is removed entirely. Property values are limited to 1024 characters.
-.SS "Volumes as Swap or Dump Devices"
+The values of user properties are arbitrary strings, are always inherited, and are never validated. All of the commands that operate on properties ("zfs list", "zfs get", "zfs set", etc.) can be used to manipulate both native properties and user properties. Use the "\fBzfs inherit\fR" command to clear a user property . If the property is not defined in any parent dataset, it is removed entirely. Property values are limited to 1024 characters.
+.SS "ZFS Volumes as Swap or Dump Devices"
 .sp
 .LP
-To set up a swap area, create a \fBZFS\fR volume of a specific size and then enable swap on that device. For more information, see the EXAMPLES section.
+During an initial installation or a live upgrade from a \fBUFS\fR file system, a swap device and dump device are created on \fBZFS\fR volumes in the \fBZFS\fR root pool. By default, the swap area size is based on 1/2 the size of physical memory up to 2 Gbytes. The size of the dump device depends on the kernel's requirements at installation time. Separate \fBZFS\fR volumes must be used for the swap area and dump devices. Do not swap to a file on a \fBZFS\fR file system. A \fBZFS\fR swap file configuration is not supported. 
 .sp
 .LP
-Do not swap to a file on a \fBZFS\fR file system. A \fBZFS\fR swap file configuration is not supported.
-.sp
-.LP
-Using a \fBZFS\fR volume as a dump device is not supported.
+If you need to change your swap area or dump device after the system is installed or upgraded, use the \fBswap\fR(1M) and \fBdumpadm\fR(1M) commands. If you need to change the size of your swap area or dump device, see the \fISolaris ZFS Administration Guide\fR.
 .SH SUBCOMMANDS
 .sp
 .LP
@@ -974,10 +962,9 @@ Creates a new \fBZFS\fR file system. The file system is automatically mounted ac
 .na
 \fB\fB-p\fR\fR
 .ad
-.RS 21n
-.rt  
-Creates all the non-existing parent datasets. Datasets created in this manner are automatically mounted according to the "mountpoint" property inherited from their parent. Any property specified on the command line using the \fB-o\fR option is ignored. If
-the target filesystem already exists, the operation completes successfully.
+.sp .6
+.RS 4n
+Creates all the non-existing parent datasets. Datasets created in this manner are automatically mounted according to the "mountpoint" property inherited from their parent. Any property specified on the command line using the \fB-o\fR option is ignored. If the target filesystem already exists, the operation completes successfully.
 .RE
 
 .sp
@@ -986,10 +973,9 @@ the target filesystem already exists, the operation completes successfully.
 .na
 \fB\fB-o\fR \fIproperty\fR=\fIvalue\fR\fR
 .ad
-.RS 21n
-.rt  
-Sets the specified property as if "\fBzfs set property=value\fR" was invoked at the same time the dataset was created. Any editable \fBZFS\fR property can also be set at creation time. Multiple \fB-o\fR options can be specified. An
-error results if the same property is specified in multiple \fB-o\fR options.
+.sp .6
+.RS 4n
+Sets the specified property as if "\fBzfs set property=value\fR" was invoked at the same time the dataset was created. Any editable \fBZFS\fR property can also be set at creation time. Multiple \fB-o\fR options can be specified. An error results if the same property is specified in multiple \fB-o\fR options.
 .RE
 
 .RE
@@ -1002,8 +988,7 @@ error results if the same property is specified in multiple \fB-o\fR options.
 .ad
 .sp .6
 .RS 4n
-Creates a volume of the given size. The volume is exported as a block device in \fB/dev/zvol/{dsk,rdsk}/\fIpath\fR\fR, where \fIpath\fR is the name of the volume in the \fBZFS\fR namespace. The size represents
-the logical size as exported by the device. By default, a reservation of equal size is created.
+Creates a volume of the given size. The volume is exported as a block device in \fB/dev/zvol/{dsk,rdsk}/\fIpath\fR\fR, where \fIpath\fR is the name of the volume in the \fBZFS\fR namespace. The size represents the logical size as exported by the device. By default, a reservation of equal size is created.
 .sp
 \fIsize\fR is automatically rounded up to the nearest 128 Kbytes to ensure that the volume has an integral number of blocks regardless of \fIblocksize\fR.
 .sp
@@ -1012,10 +997,9 @@ the logical size as exported by the device. By default, a reservation of equal s
 .na
 \fB\fB-p\fR\fR
 .ad
-.RS 21n
-.rt  
-Creates all the non-existing parent datasets. Datasets created in this manner are automatically mounted according to the "mountpoint" property inherited from their parent. Any property specified on the command line using the \fB-o\fR option is ignored. If
-the target filesystem already exists, the operation completes successfully.
+.sp .6
+.RS 4n
+Creates all the non-existing parent datasets. Datasets created in this manner are automatically mounted according to the "mountpoint" property inherited from their parent. Any property specified on the command line using the \fB-o\fR option is ignored. If the target filesystem already exists, the operation completes successfully.
 .RE
 
 .sp
@@ -1024,8 +1008,8 @@ the target filesystem already exists, the operation completes successfully.
 .na
 \fB\fB-s\fR\fR
 .ad
-.RS 21n
-.rt  
+.sp .6
+.RS 4n
 Creates a sparse volume with no reservation. See "volsize" in the Native Properties section for more information about sparse volumes.
 .RE
 
@@ -1035,10 +1019,9 @@ Creates a sparse volume with no reservation. See "volsize" in the Native Propert
 .na
 \fB\fB-o\fR \fIproperty\fR=\fIvalue\fR\fR
 .ad
-.RS 21n
-.rt  
-Sets the specified property as if "\fBzfs set property=value\fR" was invoked at the same time the dataset was created. Any editable \fBZFS\fR property can also be set at creation time. Multiple \fB-o\fR options can be specified. An
-error results if the same property is specified in multiple \fB-o\fR options.
+.sp .6
+.RS 4n
+Sets the specified property as if "\fBzfs set property=value\fR" was invoked at the same time the dataset was created. Any editable \fBZFS\fR property can also be set at creation time. Multiple \fB-o\fR options can be specified. An error results if the same property is specified in multiple \fB-o\fR options.
 .RE
 
 .sp
@@ -1047,10 +1030,9 @@ error results if the same property is specified in multiple \fB-o\fR options.
 .na
 \fB\fB-b\fR \fIblocksize\fR\fR
 .ad
-.RS 21n
-.rt  
-Equivalent to "\fB\fR\fB-o\fR \fBvolblocksize=\fIblocksize\fR\fR". If this option is specified in conjunction with "\fB\fR\fB-o\fR \fBvolblocksize\fR", the resulting
-behavior is undefined.
+.sp .6
+.RS 4n
+Equivalent to "\fB\fR\fB-o\fR \fBvolblocksize=\fIblocksize\fR\fR". If this option is specified in conjunction with "\fB\fR\fB-o\fR \fBvolblocksize\fR", the resulting behavior is undefined.
 .RE
 
 .RE
@@ -1070,8 +1052,8 @@ Destroys the given dataset. By default, the command unshares any file systems th
 .na
 \fB\fB-r\fR\fR
 .ad
-.RS 6n
-.rt  
+.sp .6
+.RS 4n
 Recursively destroy all children. If a snapshot is specified, destroy all snapshots with this name in descendent file systems.
 .RE
 
@@ -1081,8 +1063,8 @@ Recursively destroy all children. If a snapshot is specified, destroy all snapsh
 .na
 \fB\fB-R\fR\fR
 .ad
-.RS 6n
-.rt  
+.sp .6
+.RS 4n
 Recursively destroy all dependents, including cloned file systems outside the target hierarchy. If a snapshot is specified, destroy all snapshots with this name in descendent file systems.
 .RE
 
@@ -1092,8 +1074,8 @@ Recursively destroy all dependents, including cloned file systems outside the ta
 .na
 \fB\fB-f\fR\fR
 .ad
-.RS 6n
-.rt  
+.sp .6
+.RS 4n
 Force an unmount of any file systems using the "\fBunmount -f\fR" command. This option has no effect on non-file systems or unmounted file systems.
 .RE
 
@@ -1104,7 +1086,7 @@ Extreme care should be taken when applying either the \fB-r\fR or the \fB-f\fR o
 .ne 2
 .mk
 .na
-\fB\fBzfs snapshot\fR [\fB-r\fR] \fIfilesystem@snapname\fR|\fIvolume@snapname\fR\fR
+\fB\fBzfs snapshot\fR [\fB-r\fR] [\fB-o\fR \fIproperty\fR=\fIvalue\fR] ... \fIfilesystem@snapname\fR|\fIvolume@snapname\fR\fR
 .ad
 .sp .6
 .RS 4n
@@ -1115,11 +1097,22 @@ Creates a snapshot with the given name. See the "Snapshots" section for details.
 .na
 \fB\fB-r\fR\fR
 .ad
-.RS 6n
-.rt  
+.sp .6
+.RS 4n
 Recursively create snapshots of all descendent datasets. Snapshots are taken atomically, so that all recursive snapshots correspond to the same moment in time.
 .RE
 
+.sp
+.ne 2
+.mk
+.na
+\fB\fB-o\fR \fIproperty\fR=\fIvalue\fR\fR
+.ad
+.sp .6
+.RS 4n
+Sets the specified property; see "\fBzfs create\fR" for details.
+.RE
+
 .RE
 
 .sp
@@ -1130,16 +1123,15 @@ Recursively create snapshots of all descendent datasets. Snapshots are taken ato
 .ad
 .sp .6
 .RS 4n
-Roll back the given dataset to a previous snapshot. When a dataset is rolled back, all data that has changed since the snapshot is discarded, and the dataset reverts to the state at the time of the snapshot. By default, the command refuses to roll back to a snapshot other than
-the most recent one. In order to do so, all intermediate snapshots must be destroyed by specifying the \fB-r\fR option.
+Roll back the given dataset to a previous snapshot. When a dataset is rolled back, all data that has changed since the snapshot is discarded, and the dataset reverts to the state at the time of the snapshot. By default, the command refuses to roll back to a snapshot other than the most recent one. In order to do so, all intermediate snapshots must be destroyed by specifying the \fB-r\fR option.
 .sp
 .ne 2
 .mk
 .na
 \fB\fB-r\fR\fR
 .ad
-.RS 6n
-.rt  
+.sp .6
+.RS 4n
 Recursively destroy any snapshots more recent than the one specified.
 .RE
 
@@ -1149,8 +1141,8 @@ Recursively destroy any snapshots more recent than the one specified.
 .na
 \fB\fB-R\fR\fR
 .ad
-.RS 6n
-.rt  
+.sp .6
+.RS 4n
 Recursively destroy any more recent snapshots, as well as any clones of those snapshots.
 .RE
 
@@ -1160,8 +1152,8 @@ Recursively destroy any more recent snapshots, as well as any clones of those sn
 .na
 \fB\fB-f\fR\fR
 .ad
-.RS 6n
-.rt  
+.sp .6
+.RS 4n
 Used with the \fB-R\fR option to force an unmount of any clone file systems that are to be destroyed.
 .RE
 
@@ -1171,7 +1163,7 @@ Used with the \fB-R\fR option to force an unmount of any clone file systems that
 .ne 2
 .mk
 .na
-\fB\fBzfs clone\fR [\fB-p\fR] \fIsnapshot\fR \fIfilesystem\fR|\fIvolume\fR\fR
+\fB\fBzfs clone\fR [\fB-p\fR] [\fB-o\fR \fIproperty\fR=\fIvalue\fR] ... \fIsnapshot\fR \fIfilesystem\fR|\fIvolume\fR\fR
 .ad
 .sp .6
 .RS 4n
@@ -1182,11 +1174,22 @@ Creates a clone of the given snapshot. See the "Clones" section for details. The
 .na
 \fB\fB-p\fR\fR
 .ad
-.RS 6n
-.rt  
+.sp .6
+.RS 4n
 Creates all the non-existing parent datasets. Datasets created in this manner are automatically mounted according to the "mountpoint" property inherited from their parent. If the target filesystem or volume already exists, the operation completes successfully.
 .RE
 
+.sp
+.ne 2
+.mk
+.na
+\fB\fB-o\fR \fIproperty\fR=\fIvalue\fR\fR
+.ad
+.sp .6
+.RS 4n
+Sets the specified property; see "\fBzfs create\fR" for details.
+.RE
+
 .RE
 
 .sp
@@ -1197,11 +1200,9 @@ Creates all the non-existing parent datasets. Datasets created in this manner ar
 .ad
 .sp .6
 .RS 4n
-Promotes a clone file system to no longer be dependent on its "origin" snapshot. This makes it possible to destroy the file system that the clone was created from. The clone parent-child dependency relationship is reversed, so that the "origin" file system
-becomes a clone of the specified file system. 
+Promotes a clone file system to no longer be dependent on its "origin" snapshot. This makes it possible to destroy the file system that the clone was created from. The clone parent-child dependency relationship is reversed, so that the "origin" file system becomes a clone of the specified file system. 
 .sp
-The snapshot that was cloned, and any snapshots previous to this snapshot, are now owned by the promoted clone. The space they use moves from the "origin" file system to the promoted clone, so enough space must be available to accommodate these snapshots. No new space is consumed
-by this operation, but the space accounting is adjusted. The promoted clone must not have any conflicting snapshot names of its own. The "\fBrename\fR" subcommand can be used to rename any conflicting snapshots.
+The snapshot that was cloned, and any snapshots previous to this snapshot, are now owned by the promoted clone. The space they use moves from the "origin" file system to the promoted clone, so enough space must be available to accommodate these snapshots. No new space is consumed by this operation, but the space accounting is adjusted. The promoted clone must not have any conflicting snapshot names of its own. The "\fBrename\fR" subcommand can be used to rename any conflicting snapshots.
 .RE
 
 .sp
@@ -1216,21 +1217,19 @@ by this operation, but the space accounting is adjusted. The promoted clone must
 .ad
 .br
 .na
-\fB\fBzfs
-rename\fR [\fB-p\fR] \fIfilesystem\fR|\fIvolume\fR \fIfilesystem\fR|\fIvolume\fR\fR
+\fB\fBzfs rename\fR [\fB-p\fR] \fIfilesystem\fR|\fIvolume\fR \fIfilesystem\fR|\fIvolume\fR\fR
 .ad
 .sp .6
 .RS 4n
-Renames the given dataset. The new target can be located anywhere in the \fBZFS\fR hierarchy, with the exception of snapshots. Snapshots can only be renamed within the parent file system or volume. When renaming a snapshot, the parent file system of the snapshot does
-not need to be specified as part of the second argument. Renamed file systems can inherit new mount points, in which case they are unmounted and remounted at the new mount point.
+Renames the given dataset. The new target can be located anywhere in the \fBZFS\fR hierarchy, with the exception of snapshots. Snapshots can only be renamed within the parent file system or volume. When renaming a snapshot, the parent file system of the snapshot does not need to be specified as part of the second argument. Renamed file systems can inherit new mount points, in which case they are unmounted and remounted at the new mount point.
 .sp
 .ne 2
 .mk
 .na
 \fB\fB-p\fR\fR
 .ad
-.RS 6n
-.rt  
+.sp .6
+.RS 4n
 Creates all the non-existing parent datasets. Datasets created in this manner are automatically mounted according to the "mountpoint" property inherited from their parent.
 .RE
 
@@ -1259,7 +1258,7 @@ Recursively rename the snapshots of all descendent datasets. Snapshots are the o
 .ad
 .sp .6
 .RS 4n
-Lists the property information for the given datasets in tabular form. If specified, you can list property information by the absolute pathname or the relative pathname. By default, all datasets are displayed and contain the following fields:
+Lists the property information for the given datasets in tabular form. If specified, you can list property information by the absolute pathname or the relative pathname. By default, all file systems and volumes are displayed. Snapshots are displayed if the "listsnaps" property is "on" (the default is "off") . The following fields are displayed:
 .sp
 .in +2
 .nf
@@ -1274,8 +1273,8 @@ name,used,available,referenced,mountpoint
 .na
 \fB\fB-H\fR\fR
 .ad
-.RS 15n
-.rt  
+.sp .6
+.RS 4n
 Used for scripting mode. Do not print headers and separate fields by a single tab instead of arbitrary whitespace.
 .RE
 
@@ -1285,8 +1284,8 @@ Used for scripting mode. Do not print headers and separate fields by a single ta
 .na
 \fB\fB-r\fR\fR
 .ad
-.RS 15n
-.rt  
+.sp .6
+.RS 4n
 Recursively display any children of the dataset on the command line. 
 .RE
 
@@ -1296,9 +1295,33 @@ Recursively display any children of the dataset on the command line.
 .na
 \fB\fB-o\fR \fIproperty\fR\fR
 .ad
-.RS 15n
-.rt  
-A comma-separated list of properties to display. The property must be one of the properties described in the "Native Properties" section, or the special value "name" to display the dataset name.
+.sp .6
+.RS 4n
+A comma-separated list of properties to display. The property must be:
+.RS +4
+.TP
+.ie t \(bu
+.el o
+one of the properties described in the "Native Properties" section.
+.RE
+.RS +4
+.TP
+.ie t \(bu
+.el o
+a user property.
+.RE
+.RS +4
+.TP
+.ie t \(bu
+.el o
+the value "name" to display the dataset name.
+.RE
+.RS +4
+.TP
+.ie t \(bu
+.el o
+the value "space" to display space usage properties on file systems and volumes. This is a shortcut for "\fB-o name,avail,used,usedsnap,usedds, usedrefreserv,usedchild -t filesystem,volume\fR".
+.RE
 .RE
 
 .sp
@@ -1307,10 +1330,9 @@ A comma-separated list of properties to display. The property must be one of the
 .na
 \fB\fB-s\fR \fIproperty\fR\fR
 .ad
-.RS 15n
-.rt  
-A property to use for sorting the output by column in ascending order based on the value of the property. The property must be one of the properties described in the "Properties" section, or the special value "name" to sort by the dataset name. Multiple
-properties can be specified at one time using multiple \fB-s\fR property options. Multiple \fB-s\fR options are evaluated from left to right in decreasing order of importance.
+.sp .6
+.RS 4n
+A property to use for sorting the output by column in ascending order based on the value of the property. The property must be one of the properties described in the "Properties" section, or the special value "name" to sort by the dataset name. Multiple properties can be specified at one time using multiple \fB-s\fR property options. Multiple \fB-s\fR options are evaluated from left to right in decreasing order of importance.
 .sp
 The following is a list of sorting criteria:
 .RS +4
@@ -1345,8 +1367,8 @@ If no sorting options are specified the existing behavior of "\fBzfs list\fR" is
 .na
 \fB\fB-S\fR \fIproperty\fR\fR
 .ad
-.RS 15n
-.rt  
+.sp .6
+.RS 4n
 Same as the \fB-s\fR option, but sorts by property in descending order. 
 .RE
 
@@ -1356,9 +1378,9 @@ Same as the \fB-s\fR option, but sorts by property in descending order.
 .na
 \fB\fB-t\fR \fItype\fR\fR
 .ad
-.RS 15n
-.rt  
-A comma-separated list of types to display, where "type" is one of "filesystem", "snapshot" or "volume". For example, specifying "\fB-t snapshot\fR" displays only snapshots.
+.sp .6
+.RS 4n
+A comma-separated list of types to display, where "type" is one of "filesystem", "snapshot" , "volume" or "all". For example, specifying "\fB-t snapshot\fR" displays only snapshots.
 .RE
 
 .RE
@@ -1367,12 +1389,11 @@ A comma-separated list of types to display, where "type" is one of "filesystem",
 .ne 2
 .mk
 .na
-\fB\fBzfs set\fR \fIproperty\fR=\fIvalue\fR \fIfilesystem\fR|\fIvolume\fR ...\fR
+\fB\fBzfs set\fR \fIproperty\fR=\fIvalue\fR \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ...\fR
 .ad
 .sp .6
 .RS 4n
-Sets the property to the given value for each dataset. Only some properties can be edited. See the "Properties" section for more information on what properties can be set and acceptable values. Numeric values can be specified as exact values, or in a human-readable
-form with a suffix of "B", "K", "M", "G", "T", "P", "E", "Z" (for bytes, Kbytes, Mbytes, gigabytes, terabytes, petabytes, exabytes, or zettabytes, respectively). Properties cannot be set on snapshots.
+Sets the property to the given value for each dataset. Only some properties can be edited. See the "Properties" section for more information on what properties can be set and acceptable values. Numeric values can be specified as exact values, or in a human-readable form with a suffix of "B", "K", "M", "G", "T", "P", "E", "Z" (for bytes, kilobytes, megabytes, gigabytes, terabytes, petabytes, exabytes, or zettabytes, respectively). Properties cannot be set on snapshots.
 .RE
 
 .sp
@@ -1388,25 +1409,25 @@ Displays properties for the given datasets. If no datasets are specified, then t
 .in +2
 .nf
     name      Dataset name
-    property  Property name
-    value     Property value
-    source    Property source. Can either be local, default,
-              temporary, inherited, or none (-).
+     property  Property name
+     value     Property value
+     source    Property source. Can either be local, default,
+               temporary, inherited, or none (-).
 .fi
 .in -2
 .sp
 
 All columns are displayed by default, though this can be controlled by using the \fB-o\fR option. This command takes a comma-separated list of properties as described in the "Native Properties" and "User Properties" sections.
 .sp
-The special value "all" can be used to display all properties for the given dataset.
+The special value "all" can be used to display all properties that apply to the given dataset's type (filesystem, volume or snapshot).
 .sp
 .ne 2
 .mk
 .na
 \fB\fB-r\fR\fR
 .ad
-.RS 13n
-.rt  
+.sp .6
+.RS 4n
 Recursively display properties for any children.
 .RE
 
@@ -1416,8 +1437,8 @@ Recursively display properties for any children.
 .na
 \fB\fB-H\fR\fR
 .ad
-.RS 13n
-.rt  
+.sp .6
+.RS 4n
 Display output in a form more easily parsed by scripts. Any headers are omitted, and fields are explicitly separated by a single tab instead of an arbitrary amount of space.
 .RE
 
@@ -1427,8 +1448,8 @@ Display output in a form more easily parsed by scripts. Any headers are omitted,
 .na
 \fB\fB-o\fR \fIfield\fR\fR
 .ad
-.RS 13n
-.rt  
+.sp .6
+.RS 4n
 A comma-separated list of columns to display. "name,property,value,source" is the default value. 
 .RE
 
@@ -1438,8 +1459,8 @@ A comma-separated list of columns to display. "name,property,value,source" is th
 .na
 \fB\fB-s\fR \fIsource\fR\fR
 .ad
-.RS 13n
-.rt  
+.sp .6
+.RS 4n
 A comma-separated list of sources to display. Those properties coming from a source other than those in this list are ignored. Each source must be one of the following: "local,default,inherited,temporary,none". The default value is all sources.
 .RE
 
@@ -1449,8 +1470,8 @@ A comma-separated list of sources to display. Those properties coming from a sou
 .na
 \fB\fB-p\fR\fR
 .ad
-.RS 13n
-.rt  
+.sp .6
+.RS 4n
 Display numbers in parsable (exact) values.
 .RE
 
@@ -1460,7 +1481,7 @@ Display numbers in parsable (exact) values.
 .ne 2
 .mk
 .na
-\fB\fBzfs inherit\fR [\fB-r\fR] \fIproperty\fR \fIfilesystem\fR|\fIvolume\fR ...\fR
+\fB\fBzfs inherit\fR [\fB-r\fR] \fIproperty\fR \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ...\fR
 .ad
 .sp .6
 .RS 4n
@@ -1471,8 +1492,8 @@ Clears the specified property, causing it to be inherited from an ancestor. If n
 .na
 \fB\fB-r\fR\fR
 .ad
-.RS 6n
-.rt  
+.sp .6
+.RS 4n
 Recursively inherit the given property for all children.
 .RE
 
@@ -1497,8 +1518,7 @@ Displays a list of file systems that are not the most recent version.
 .ad
 .sp .6
 .RS 4n
-Upgrades file systems to a new on-disk version. Once this is done, the file systems will no longer be accessible on systems running older versions of the software. "\fBzfs send\fR" streams generated from new snapshots of these file systems can not be accessed
-on systems running older versions of the software.
+Upgrades file systems to a new on-disk version. Once this is done, the file systems will no longer be accessible on systems running older versions of the software. "\fBzfs send\fR" streams generated from new snapshots of these file systems can not be accessed on systems running older versions of the software.
 .sp
 The file system version is independent of the pool version (see \fBzpool\fR(1M) for information on the "\fBzpool upgrade\fR" command). 
 .sp
@@ -1509,8 +1529,8 @@ The file system version does not have to be upgraded when the pool version is up
 .na
 \fB\fB-a\fR\fR
 .ad
-.RS 14n
-.rt  
+.sp .6
+.RS 4n
 Upgrade all file systems on all imported pools.
 .RE
 
@@ -1520,8 +1540,8 @@ Upgrade all file systems on all imported pools.
 .na
 \fB\fIfilesystem\fR\fR
 .ad
-.RS 14n
-.rt  
+.sp .6
+.RS 4n
 Upgrade the specified file system. 
 .RE
 
@@ -1531,8 +1551,8 @@ Upgrade the specified file system.
 .na
 \fB\fB-r\fR\fR
 .ad
-.RS 14n
-.rt  
+.sp .6
+.RS 4n
 Upgrade the specified file system and all descendent file systems 
 .RE
 
@@ -1542,10 +1562,9 @@ Upgrade the specified file system and all descendent file systems
 .na
 \fB\fB-V\fR \fIversion\fR\fR
 .ad
-.RS 14n
-.rt  
-Upgrade to the specified \fIversion\fR. If the \fB-V\fR flag is not specified, this command upgrades to the most recent version. This option can only be used to increase the version number, and only up to the most recent version supported by this
-software.
+.sp .6
+.RS 4n
+Upgrade to the specified \fIversion\fR. If the \fB-V\fR flag is not specified, this command upgrades to the most recent version. This option can only be used to increase the version number, and only up to the most recent version supported by this software.
 .RE
 
 .RE
@@ -1576,8 +1595,8 @@ Mounts \fBZFS\fR file systems. Invoked automatically as part of the boot process
 .na
 \fB\fB-o\fR \fIoptions\fR\fR
 .ad
-.RS 14n
-.rt  
+.sp .6
+.RS 4n
 An optional comma-separated list of mount options to use temporarily for the duration of the mount. See the "Temporary Mount Point Properties" section for details.
 .RE
 
@@ -1587,8 +1606,8 @@ An optional comma-separated list of mount options to use temporarily for the dur
 .na
 \fB\fB-O\fR\fR
 .ad
-.RS 14n
-.rt  
+.sp .6
+.RS 4n
 Perform an overlay mount. See \fBmount\fR(1M) for more information.
 .RE
 
@@ -1598,8 +1617,8 @@ Perform an overlay mount. See \fBmount\fR(1M) for more information.
 .na
 \fB\fB-v\fR\fR
 .ad
-.RS 14n
-.rt  
+.sp .6
+.RS 4n
 Report mount progress.
 .RE
 
@@ -1609,8 +1628,8 @@ Report mount progress.
 .na
 \fB\fB-a\fR\fR
 .ad
-.RS 14n
-.rt  
+.sp .6
+.RS 4n
 Mount all available \fBZFS\fR file systems. Invoked automatically as part of the boot process. 
 .RE
 
@@ -1620,8 +1639,8 @@ Mount all available \fBZFS\fR file systems. Invoked automatically as part of the
 .na
 \fB\fIfilesystem\fR\fR
 .ad
-.RS 14n
-.rt  
+.sp .6
+.RS 4n
 Mount the specified filesystem.
 .RE
 
@@ -1642,8 +1661,8 @@ Unmounts currently mounted \fBZFS\fR file systems. Invoked automatically as part
 .na
 \fB\fB-f\fR\fR
 .ad
-.RS 25n
-.rt  
+.sp .6
+.RS 4n
 Forcefully unmount the file system, even if it is currently in use.
 .RE
 
@@ -1653,8 +1672,8 @@ Forcefully unmount the file system, even if it is currently in use.
 .na
 \fB\fB-a\fR\fR
 .ad
-.RS 25n
-.rt  
+.sp .6
+.RS 4n
 Unmount all available \fBZFS\fR file systems. Invoked automatically as part of the boot process. 
 .RE
 
@@ -1664,8 +1683,8 @@ Unmount all available \fBZFS\fR file systems. Invoked automatically as part of t
 .na
 \fB\fIfilesystem\fR|\fImountpoint\fR\fR
 .ad
-.RS 25n
-.rt  
+.sp .6
+.RS 4n
 Unmount the specified filesystem. The command can also be given a path to a \fBZFS\fR file system mount point on the system.
 .RE
 
@@ -1686,8 +1705,8 @@ Shares available \fBZFS\fR file systems.
 .na
 \fB\fB-a\fR\fR
 .ad
-.RS 14n
-.rt  
+.sp .6
+.RS 4n
 Share all available \fBZFS\fR file systems. Invoked automatically as part of the boot process. 
 .RE
 
@@ -1697,8 +1716,8 @@ Share all available \fBZFS\fR file systems. Invoked automatically as part of the
 .na
 \fB\fIfilesystem\fR\fR
 .ad
-.RS 14n
-.rt  
+.sp .6
+.RS 4n
 Share the specified filesystem according to the "sharenfs" and "sharesmb" properties. File systems are shared when the "sharenfs" or "sharesmb" property is set.
 .RE
 
@@ -1719,8 +1738,8 @@ Unshares currently shared \fBZFS\fR file systems. This is invoked automatically
 .na
 \fB\fB-a\fR\fR
 .ad
-.RS 25n
-.rt  
+.sp .6
+.RS 4n
 Unshare all available \fBZFS\fR file systems. Invoked automatically as part of the boot process. 
 .RE
 
@@ -1730,8 +1749,8 @@ Unshare all available \fBZFS\fR file systems. Invoked automatically as part of t
 .na
 \fB\fIfilesystem\fR|\fImountpoint\fR\fR
 .ad
-.RS 25n
-.rt  
+.sp .6
+.RS 4n
 Unshare the specified filesystem. The command can also be given a path to a \fBZFS\fR file system shared on the system.
 .RE
 
@@ -1741,7 +1760,7 @@ Unshare the specified filesystem. The command can also be given a path to a \fBZ
 .ne 2
 .mk
 .na
-\fB\fBzfs send\fR [\fB-vR\fR] [\fB-\fR[\fB-iI\fR] \fIsnapshot\fR] \fIsnapshot\fR\fR
+\fB\fBzfs send\fR [\fB-vR\fR] [\fB-\fR[\fBiI\fR] \fIsnapshot\fR] \fIsnapshot\fR\fR
 .ad
 .sp .6
 .RS 4n
@@ -1752,10 +1771,9 @@ Creates a stream representation of the second \fIsnapshot\fR, which is written t
 .na
 \fB\fB-i\fR \fIsnapshot\fR\fR
 .ad
-.RS 15n
-.rt  
-Generate an incremental stream from the first \fIsnapshot\fR to the second \fIsnapshot\fR. The incremental source (the first \fIsnapshot\fR) can be specified as the last component of the snapshot name (for example,
-the part after the "@"), and it is assumed to be from the same file system as the second \fIsnapshot\fR.
+.sp .6
+.RS 4n
+Generate an incremental stream from the first \fIsnapshot\fR to the second \fIsnapshot\fR. The incremental source (the first \fIsnapshot\fR) can be specified as the last component of the snapshot name (for example, the part after the "@"), and it is assumed to be from the same file system as the second \fIsnapshot\fR.
 .sp
 If the destination is a clone, the source may be the origin snapshot, which must be fully specified (for example, "pool/fs@origin", not just "@origin").
 .RE
@@ -1766,10 +1784,9 @@ If the destination is a clone, the source may be the origin snapshot, which must
 .na
 \fB\fB-I\fR \fIsnapshot\fR\fR
 .ad
-.RS 15n
-.rt  
-Generate a stream package that sends all intermediary snapshots from the first snapshot to the second snapshot. For example, "\fB-I @a fs@d\fR" is similar to "\fB-i @a fs@b; -i @b fs@c; -i @c fs@d\fR". The incremental source snapshot
-may be specified as with the \fB-i\fR option.
+.sp .6
+.RS 4n
+Generate a stream package that sends all intermediary snapshots from the first snapshot to the second snapshot. For example, "\fB-I @a fs@d\fR" is similar to "\fB-i @a fs@b; -i @b fs@c; -i @c fs@d\fR". The incremental source snapshot may be specified as with the \fB-i\fR option.
 .RE
 
 .sp
@@ -1778,8 +1795,8 @@ may be specified as with the \fB-i\fR option.
 .na
 \fB\fB-R\fR\fR
 .ad
-.RS 15n
-.rt  
+.sp .6
+.RS 4n
 Generate a replication stream package, which will replicate the specified filesystem, and all descendant file systems, up to the named snapshot. When received, all properties, snapshots, descendent file systems, and clones are preserved.
 .sp
 If the \fB-i\fR or \fB-I\fR flags are used in conjunction with the \fB-R\fR flag, an incremental replication stream is generated. The current values of properties, and current snapshot and file system names are set when the stream is received. If the \fB-F\fR flag is specified when this stream is recieved, snapshots and file systems that do not exist on the sending side are destroyed. 
@@ -1791,8 +1808,8 @@ If the \fB-i\fR or \fB-I\fR flags are used in conjunction with the \fB-R\fR flag
 .na
 \fB\fB-v\fR\fR
 .ad
-.RS 15n
-.rt  
+.sp .6
+.RS 4n
 Print verbose information about the stream package generated.
 .RE
 
@@ -1811,24 +1828,21 @@ The format of the stream is evolving. No backwards compatibility is guaranteed.
 .ad
 .sp .6
 .RS 4n
-Creates a snapshot whose contents are as specified in the stream provided on standard input. If a full stream is received, then a new file system is created as well. Streams are created using the "\fBzfs send\fR" subcommand, which by default creates a full
-stream. "\fBzfs recv\fR" can be used as an alias for "\fBzfs receive\fR".
+Creates a snapshot whose contents are as specified in the stream provided on standard input. If a full stream is received, then a new file system is created as well. Streams are created using the "\fBzfs send\fR" subcommand, which by default creates a full stream. "\fBzfs recv\fR" can be used as an alias for "\fBzfs receive\fR".
 .sp
-If an incremental stream is received, then the destination file system must already exist, and its most recent snapshot must match the incremental stream's source. For \fBzvols\fR, the destination device link is destroyed and re-created, which means the \fBzvol\fR cannot
-be accessed during the \fBreceive\fR operation.
+If an incremental stream is received, then the destination file system must already exist, and its most recent snapshot must match the incremental stream's source. For \fBzvols\fR, the destination device link is destroyed and re-created, which means the \fBzvol\fR cannot be accessed during the \fBreceive\fR operation.
 .sp
 The name of the snapshot (and file system, if a full stream is received) that this subcommand creates depends on the argument type and the \fB-d\fR option.
 .sp
-If the argument is a snapshot name, the specified \fIsnapshot\fR is created. If the argument is a file system or volume name, a snapshot with the same name as the sent snapshot is created within the specified \fIfilesystem\fR or \fIvolume\fR.
-If the \fB-d\fR option is specified, the snapshot name is determined by appending the sent snapshot's name to the specified \fIfilesystem\fR. If the \fB-d\fR option is specified, any required file systems within the specified one are created.
+If the argument is a snapshot name, the specified \fIsnapshot\fR is created. If the argument is a file system or volume name, a snapshot with the same name as the sent snapshot is created within the specified \fIfilesystem\fR or \fIvolume\fR. If the \fB-d\fR option is specified, the snapshot name is determined by appending the sent snapshot's name to the specified \fIfilesystem\fR. If the \fB-d\fR option is specified, any required file systems within the specified one are created.
 .sp
 .ne 2
 .mk
 .na
 \fB\fB-d\fR\fR
 .ad
-.RS 6n
-.rt  
+.sp .6
+.RS 4n
 Use the name of the sent snapshot to determine the name of the new snapshot as described in the paragraph above.
 .RE
 
@@ -1838,8 +1852,8 @@ Use the name of the sent snapshot to determine the name of the new snapshot as d
 .na
 \fB\fB-v\fR\fR
 .ad
-.RS 6n
-.rt  
+.sp .6
+.RS 4n
 Print verbose information about the stream and the time required to perform the receive operation.
 .RE
 
@@ -1849,8 +1863,8 @@ Print verbose information about the stream and the time required to perform the
 .na
 \fB\fB-n\fR\fR
 .ad
-.RS 6n
-.rt  
+.sp .6
+.RS 4n
 Do not actually receive the stream. This can be useful in conjunction with the \fB-v\fR option to verify the name the receive operation would use.
 .RE
 
@@ -1860,10 +1874,9 @@ Do not actually receive the stream. This can be useful in conjunction with the \
 .na
 \fB\fB-F\fR\fR
 .ad
-.RS 6n
-.rt  
-Force a rollback of the file system to the most recent snapshot before performing the receive operation. If receiving an incremental replication stream (for example, one generated by "z\fBfs send -R -[iI]\fR"), destroy snapshots and file systems that do
-not exist on the sending side.
+.sp .6
+.RS 4n
+Force a rollback of the file system to the most recent snapshot before performing the receive operation. If receiving an incremental replication stream (for example, one generated by "z\fBfs send -R -[iI]\fR"), destroy snapshots and file systems that do not exist on the sending side.
 .RE
 
 .RE
@@ -1889,8 +1902,7 @@ Delegates \fBZFS\fR administration permission for the file systems to non-privil
 .ad
 .sp .6
 .RS 4n
-Specifies to whom the permissions are delegated. Multiple entities can be specified as a comma-separated list. If neither of the \fB-ug\fR options are specified, then the argument is interpreted preferentially as the keyword "everyone", then as a user name,
-and lastly as a group name. To specify a user or group named "everyone", use the \fB-u\fR or \fB-g\fR options. To specify a group with the same name as a user, use the \fB-g\fR options.
+Specifies to whom the permissions are delegated. Multiple entities can be specified as a comma-separated list. If neither of the \fB-ug\fR options are specified, then the argument is interpreted preferentially as the keyword "everyone", then as a user name, and lastly as a group name. To specify a user or group named "everyone", use the \fB-u\fR or \fB-g\fR options. To specify a group with the same name as a user, use the \fB-g\fR options.
 .RE
 
 .sp
@@ -1901,8 +1913,7 @@ and lastly as a group name. To specify a user or group named "everyone", use the
 .ad
 .sp .6
 .RS 4n
-Specifies that the permissions be delegated to "everyone." Multiple permissions may be specified as a comma-separated list. Permission names are the same as \fBZFS\fR subcommand and property names. See the property list below. Property set names, which
-begin with an "at sign" ("@") , may be specified. See the \fB-s\fR form below for details.
+Specifies that the permissions be delegated to "everyone." Multiple permissions may be specified as a comma-separated list. Permission names are the same as \fBZFS\fR subcommand and property names. See the property list below. Property set names, which begin with an "at sign" ("@") , may be specified. See the \fB-s\fR form below for details.
 .RE
 
 .sp
@@ -1913,8 +1924,7 @@ begin with an "at sign" ("@") , may be specified. See the \fB-s\fR form below fo
 .ad
 .sp .6
 .RS 4n
-Specifies where the permissions are delegated. If neither of the \fB-ld\fR options are specified, or both are, then the permissions are allowed for the file system or volume, and all of its descendents. If only the \fB-l\fR option is used, then is allowed "locally"
-only for the specified file system. If only the \fB-d\fR option is used, then is allowed only for the descendent file systems.
+Specifies where the permissions are delegated. If neither of the \fB-ld\fR options are specified, or both are, then the permissions are allowed for the file system or volume, and all of its descendents. If only the \fB-l\fR option is used, then is allowed "locally" only for the specified file system. If only the \fB-d\fR option is used, then is allowed only for the descendent file systems.
 .RE
 
 .RE
@@ -1927,49 +1937,51 @@ Permissions are generally the ability to use a \fBZFS\fR subcommand or change a
 .nf
 NAME         TYPE         NOTES
 allow        subcommand   Must also have the permission
-                          that is being allowed.
+                           that is being allowed.
 clone        subcommand   Must also have the 'create' ability
-                          and the 'mount' ability in the origin 
-                          file system.
+                           and the 'mount' ability in the origin 
+                           file system.
 create       subcommand   Must also have the 'mount' ability.
 destroy      subcommand   Must also have the 'mount' ability.     
 mount        subcommand   Allows mount, unmount, and
-                          create/remove zvol device links.
+                           create/remove zvol device links.
 promote      subcommand   Must also have the 'mount' ability and
-                          'promote' ability in the origin file system.    
+                           'promote' ability in the origin file system.    
 receive      subcommand   Must also have the 'mount' ability and 
-                          the 'create' ability.     
+                           the 'create' ability.     
 rename       subcommand   Must also have the 'mount' ability and
-                          the 'create' ability in the new parent.
+                           the 'create' ability in the new parent.
 rollback     subcommand   Must also have the 'mount' ability.      
 snapshot     subcommand   Must also have the 'mount' ability.
 share        subcommand   Allows share and unshare.
 send         subcommand
-      
-      
-aclinherit   property
-aclmode      property
-atime        property
-canmount     property
-checksum     property
-compression  property
-copies       property
-devices      property
-exec         property
-mountpoint   property
-quota        property
-readonly     property
-recordsize   property
-reservation  property
-setuid       property
-shareiscsi   property
-sharenfs     property
-snapdir      property
-version      property
-volsize      property
-xattr        property
-zoned        property
-userprop     other        Allows changing any user property.
+       
+       
+aclinherit       property
+aclmode          property
+atime            property
+canmount         property
+checksum         property
+compression      property
+copies           property
+devices          property
+exec             property
+mountpoint       property
+primarycache     property
+quota            property
+readonly         property
+recordsize       property
+reservation      property
+secondarycache   property
+setuid           property
+shareiscsi       property
+sharenfs         property
+snapdir          property
+version          property
+volsize          property
+xattr            property
+zoned            property
+userprop         other        Allows changing any user property.
 .fi
 .in -2
 .sp
@@ -1993,8 +2005,7 @@ Sets "create time" permissions. These permissions are granted (locally) to the c
 .ad
 .sp .6
 .RS 4n
-Defines or adds permissions to a permission set. The set can be used by other \fBzfs allow\fR commands for the specified file system and its descendents. Sets are evaluated dynamically, so changes to a set are immediately reflected. Permission sets follow the same
-naming restrictions as ZFS file systems, but the name must begin with an "at sign" ("@"), and can be no more than 64 characters long.
+Defines or adds permissions to a permission set. The set can be used by other \fBzfs allow\fR commands for the specified file system and its descendents. Sets are evaluated dynamically, so changes to a set are immediately reflected. Permission sets follow the same naming restrictions as ZFS file systems, but the name must begin with an "at sign" ("@"), and can be no more than 64 characters long.
 .RE
 
 .sp
@@ -2017,17 +2028,15 @@ naming restrictions as ZFS file systems, but the name must begin with an "at sig
 .ad
 .sp .6
 .RS 4n
-Removes permissions that were granted with the "\fBzfs allow\fR" command. No permissions are explicitly denied, so other permissions granted are still in effect. For example, if the permission is granted by an ancestor. If no permissions are specified,
-then all permissions for the specified \fIuser\fR, \fIgroup\fR, or \fIeveryone\fR are removed. Specifying "everyone" (or using the \fB-e\fR option) only removes the permissions that were granted to "everyone",
-not all permissions for every user and group. See the "\fBzfs allow\fR" command for a description of the \fB-ldugec\fR options.
+Removes permissions that were granted with the "\fBzfs allow\fR" command. No permissions are explicitly denied, so other permissions granted are still in effect. For example, if the permission is granted by an ancestor. If no permissions are specified, then all permissions for the specified \fIuser\fR, \fIgroup\fR, or \fIeveryone\fR are removed. Specifying "everyone" (or using the \fB-e\fR option) only removes the permissions that were granted to "everyone", not all permissions for every user and group. See the "\fBzfs allow\fR" command for a description of the \fB-ldugec\fR options.
 .sp
 .ne 2
 .mk
 .na
 \fB\fB-r\fR\fR
 .ad
-.RS 6n
-.rt  
+.sp .6
+.RS 4n
 Recursively remove the permissions from this file system and all descendents.
 .RE
 
@@ -2048,36 +2057,12 @@ Recursively remove the permissions from this file system and all descendents.
 Removes permissions from a permission set. If no permissions are specified, then all permissions are removed, thus removing the set entirely.
 .RE
 
-.sp
-.ne 2
-.mk
-.na
-\fB\fBzfs jail\fR \fIjailid\fR \fIfilesystem\fR\fR
-.ad
-.sp .6
-.RS 4n
-Attaches the given file system to the given jail. From now on this file system tree can be managed from within a jail if the "\fBjailed\fR" property has been set.
-To use this functionality, sysctl \fBsecurity.jail.enforce_statfs\fR should be set to 0 and sysctl \fBsecurity.jail.mount_allowed\fR should be set to 1.
-.RE
-
-.sp
-.ne 2
-.mk
-.na
-\fB\fBzfs unjail\fR \fIjailid\fR \fIfilesystem\fR\fR
-.ad
-.sp .6
-.RS 4n
-Detaches the given file system from the given jail.
-.RE
-
 .SH EXAMPLES
 .LP
 \fBExample 1 \fRCreating a ZFS File System Hierarchy
 .sp
 .LP
-The following commands create a file system named "\fBpool/home\fR" and a file system named "\fBpool/home/bob\fR". The mount point "\fB/export/home\fR" is set for the parent file system, and automatically inherited
-by the child file system.
+The following commands create a file system named "\fBpool/home\fR" and a file system named "\fBpool/home/bob\fR". The mount point "\fB/export/home\fR" is set for the parent file system, and automatically inherited by the child file system.
 
 .sp
 .in +2
@@ -2107,8 +2092,7 @@ The following command creates a snapshot named "yesterday". This snapshot is mou
 \fBExample 3 \fRTaking and destroying multiple snapshots
 .sp
 .LP
-The following command creates snapshots named "\fByesterday\fR" of "\fBpool/home\fR" and all of its descendent file systems. Each snapshot is mounted on demand in the ".zfs/snapshot" directory at the root of its file system. The
-second command destroys the newly created snapshots.
+The following command creates snapshots named "\fByesterday\fR" of "\fBpool/home\fR" and all of its descendent file systems. Each snapshot is mounted on demand in the ".zfs/snapshot" directory at the root of its file system. The second command destroys the newly created snapshots.
 
 .sp
 .in +2
@@ -2138,7 +2122,7 @@ The following commands turn compression off for all file systems under "\fBpool/
 \fBExample 5 \fRListing ZFS Datasets
 .sp
 .LP
-The following command lists all active file systems and volumes in the system.
+The following command lists all active file systems and volumes in the system. Snapshots are displayed if the "listsnaps" property is "on" (the default is "off") . See \fBzpool\fR(1M) for more information on pool properties.
 
 .sp
 .in +2
@@ -2146,12 +2130,11 @@ The following command lists all active file systems and volumes in the system.
 \fB# zfs list\fR
 
 
-  NAME                      USED  AVAIL  REFER  MOUNTPOINT
-  pool                      450K   457G    18K  /pool
-  pool/home                 315K   457G    21K  /export/home
-  pool/home/anne             18K   457G    18K  /export/home/anne
-  pool/home/bob             276K   457G   276K  /export/home/bob
-  pool/home/bob@yesterday      0      -   276K  -
+   NAME                      USED  AVAIL  REFER  MOUNTPOINT
+   pool                      450K   457G    18K  /pool
+   pool/home                 315K   457G    21K  /export/home
+   pool/home/anne             18K   457G    18K  /export/home/anne
+   pool/home/bob             276K   457G   276K  /export/home/bob
 .fi
 .in -2
 .sp
@@ -2182,42 +2165,52 @@ The following command lists all properties for "\fBpool/home/bob\fR".
 \fB# zfs get all pool/home/bob\fR
 
 
-  NAME           PROPERTY       VALUE                  SOURCE
-  pool/home/bob  type           filesystem             -
-  pool/home/bob  creation       Thu Jul 12 14:44 2007  -
-  pool/home/bob  used           276K                   -
-  pool/home/bob  available      50.0G                  -
-  pool/home/bob  referenced     276K                   -
-  pool/home/bob  compressratio  1.00x                  -
-  pool/home/bob  mounted        yes                    -
-  pool/home/bob  quota          50G                    local
-  pool/home/bob  reservation    none                   default
-  pool/home/bob  recordsize     128K                   default
-  pool/home/bob  mountpoint     /export/home/bob       inherited from
-                                                       pool/home
-  pool/home/bob  checksum       on                     default
-  pool/home/bob  compression    off                    default
-  pool/home/bob  atime          on                     default
-  pool/home/bob  devices        on                     default
-  pool/home/bob  exec           on                     default
-  pool/home/bob  setuid         on                     default
-  pool/home/bob  readonly       off                    default
-  pool/home/bob  zoned          off                    default
-  pool/home/bob  snapdir        hidden                 default
-  pool/home/bob  aclmode        groupmask              default
-  pool/home/bob  aclinherit     restricted             default
-  pool/home/bob  canmount       on                     default
-  pool/home/bob  nbmand         off                    default
-  pool/home/bob  shareiscsi     off                    default
-  pool/home/bob  sharesmb       off                    default
-  pool/home/bob  sharenfs       off                    default
-  pool/home/bob  xattr          on                     default
-  pool/home/bob  refquota       10M                    local
-  pool/home/bob  refreservation none                   default
-  pool/home/bob  copies         1                      default
-  pool/home/bob  version        1                      -
-
-   
+NAME           PROPERTY              VALUE                  SOURCE
+pool/home/bob  type                  filesystem             -
+pool/home/bob  creation              Thu Jul 12 14:44 2007  -
+pool/home/bob  used                  276K                   -
+pool/home/bob  available             50.0G                  -
+pool/home/bob  referenced            276K                   -
+pool/home/bob  compressratio         1.00x                  -
+pool/home/bob  mounted               yes                    -
+pool/home/bob  quota                 50G                    local
+pool/home/bob  reservation           none                   default
+pool/home/bob  recordsize            128K                   default
+pool/home/bob  mountpoint            /export/home/bob       inherited 
+                                                            from
+                                                            pool/home
+pool/home/bob  sharenfs              off                    default
+pool/home/bob  checksum              on                     default
+pool/home/bob  compression           off                    default
+pool/home/bob  atime                 on                     default
+pool/home/bob  devices               on                     default
+pool/home/bob  exec                  on                     default
+pool/home/bob  setuid                on                     default
+pool/home/bob  readonly              off                    default
+pool/home/bob  zoned                 off                    default
+pool/home/bob  snapdir               hidden                 default
+pool/home/bob  aclmode               groupmask              default
+pool/home/bob  aclinherit            restricted             default
+pool/home/bob  canmount              on                     default
+pool/home/bob  shareiscsi            off                    default
+pool/home/bob  xattr                 on                     default
+pool/home/bob  copies                1                      default
+pool/home/bob  version               1                      -
+pool/home/bob  utf8only              off                    -
+pool/home/bob  normalization         none                   -
+pool/home/bob  casesensitivity       sensitive              -
+pool/home/bob  vscan                 off                    default
+pool/home/bob  nbmand                off                    default
+pool/home/bob  sharesmb              off                    default
+pool/home/bob  refquota              10M                    local
+pool/home/bob  refreservation        none                   default
+pool/home/bob  primarycache          all                    default
+pool/home/bob  secondarycache        a                      default
+pool/home/bob  usedbysnapshots       0                      -
+pool/home/bob  usedbydataset         18K                    -
+pool/home/bob  usedbychildren        0                      -
+pool/home/bob  usedbyrefreservation  0                      -
+    
 .fi
 .in -2
 .sp
@@ -2244,9 +2237,9 @@ The following command lists all properties with local settings for "\fBpool/home
 .nf
 \fB# zfs get -r -s local -o name,property,value all pool/home/bob\fR
 
-  NAME             PROPERTY      VALUE
-  pool             compression   on
-  pool/home        checksum      off
+   NAME             PROPERTY      VALUE
+   pool             compression   on
+   pool/home        checksum      off
 .fi
 .in -2
 .sp
@@ -2289,15 +2282,15 @@ The following commands illustrate how to test out changes to a file system, and
 .in +2
 .nf
 \fB# zfs create pool/project/production\fR
- populate /pool/project/production with data
+  populate /pool/project/production with data
 \fB# zfs snapshot pool/project/production@today
 # zfs clone pool/project/production@today pool/project/beta\fR
- make changes to /pool/project/beta and test them
+  make changes to /pool/project/beta and test them
 \fB# zfs promote pool/project/beta
 # zfs rename pool/project/production pool/project/legacy
 # zfs rename pool/project/beta pool/project/production\fR
- once the legacy version is no longer needed, it can be
- destroyed
+  once the legacy version is no longer needed, it can be
+  destroyed
 \fB# zfs destroy pool/project/legacy\fR
 .fi
 .in -2
@@ -2321,16 +2314,15 @@ The following command causes "\fBpool/home/bob\fR" and "\fBpool/home/anne\fR" to
 \fBExample 12 \fRRemotely Replicating ZFS Data
 .sp
 .LP
-The following commands send a full stream and then an incremental stream to a remote machine, restoring them into "\fBpoolB/received/fs\fR@a" and "\fBpoolB/received/fs@b\fR", respectively. "\fBpoolB\fR" must contain
-the file system "\fBpoolB/received\fR", and must not initially contain "\fBpoolB/received/fs\fR".
+The following commands send a full stream and then an incremental stream to a remote machine, restoring them into "\fBpoolB/received/fs\fR@a" and "\fBpoolB/received/fs@b\fR", respectively. "\fBpoolB\fR" must contain the file system "\fBpoolB/received\fR", and must not initially contain "\fBpoolB/received/fs\fR".
 
 .sp
 .in +2
 .nf
 # zfs send pool/fs@a | \e
-  ssh host zfs receive poolB/received/fs@a
+   ssh host zfs receive poolB/received/fs@a
 # zfs send -i a pool/fs@b | ssh host \e
-  zfs receive poolB/received/fs
+   zfs receive poolB/received/fs
 .fi
 .in -2
 .sp
@@ -2339,35 +2331,19 @@ the file system "\fBpoolB/received\fR", and must not initially contain "\fBpoolB
 \fBExample 13 \fRUsing the zfs receive -d Option
 .sp
 .LP
-The following command sends a full stream of "\fBpoolA/fsA/fsB@snap\fR" to a remote machine, receiving it into "\fBpoolB/received/fsA/fsB@snap\fR". The "\fBfsA/fsB@snap\fR" portion of the received snapshot's name
-is determined from the name of the sent snapshot. "\fBpoolB\fR" must contain the file system "\fBpoolB/received\fR". If "\fBpoolB/received/fsA\fR" does not exist, it is be created as an empty file system.
+The following command sends a full stream of "\fBpoolA/fsA/fsB@snap\fR" to a remote machine, receiving it into "\fBpoolB/received/fsA/fsB@snap\fR". The "\fBfsA/fsB@snap\fR" portion of the received snapshot's name is determined from the name of the sent snapshot. "\fBpoolB\fR" must contain the file system "\fBpoolB/received\fR". If "\fBpoolB/received/fsA\fR" does not exist, it is be created as an empty file system.
 
 .sp
 .in +2
 .nf
 \fB# zfs send poolA/fsA/fsB@snap | \e
-  ssh host zfs receive -d poolB/received\fR
+   ssh host zfs receive -d poolB/received\fR
 .fi
 .in -2
 .sp
 
 .LP
-\fBExample 14 \fRCreating a ZFS volume as a Swap Device
-.sp
-.LP
-The following example shows how to create a 5-Gbyte ZFS volume and then add the volume as a swap device.
-
-.sp
-.in +2
-.nf
-\fB# zfs create -V 5gb tank/vol
-# swap -a /dev/zvol/dsk/tank/vol\fR
-.fi
-.in -2
-.sp
-
-.LP
-\fBExample 15 \fRSetting User Properties
+\fBExample 14 \fRSetting User Properties
 .sp
 .LP
 The following example sets the user defined "com.example:department" property for a dataset.
@@ -2381,7 +2357,7 @@ The following example sets the user defined "com.example:department" property fo
 .sp
 
 .LP
-\fBExample 16 \fRCreating a ZFS Volume as a iSCSI Target Device
+\fBExample 15 \fRCreating a ZFS Volume as a iSCSI Target Device
 .sp
 .LP
 The following example shows how to create a \fBZFS\fR volume as an \fBiSCSI\fR target. 
@@ -2390,12 +2366,12 @@ The following example shows how to create a \fBZFS\fR volume as an \fBiSCSI\fR t
 .in +2
 .nf
 \fB# zfs create -V 2g pool/volumes/vol1
-# zfs set shareiscsi=on pool/volumes/vol1
-# iscsitadm list target\fR
-Target: pool/volumes/vol1
-iSCSI Name: 
-iqn.1986-03.com.sun:02:7b4b02a6-3277-eb1b-e686-a24762c52a8c
-Connections: 0
+ # zfs set shareiscsi=on pool/volumes/vol1
+ # iscsitadm list target\fR
+ Target: pool/volumes/vol1
+ iSCSI Name: 
+ iqn.1986-03.com.sun:02:7b4b02a6-3277-eb1b-e686-a24762c52a8c
+ Connections: 0
 .fi
 .in -2
 .sp
@@ -2404,7 +2380,7 @@ Connections: 0
 .LP
 After the \fBiSCSI\fR target is created, set up the \fBiSCSI\fR initiator. For more information about the Solaris \fBiSCSI\fR initiator, see the Solaris Administration Guide: Devices and File Systems.
 .LP
-\fBExample 17 \fRPerforming a Rolling Snapshot
+\fBExample 16 \fRPerforming a Rolling Snapshot
 .sp
 .LP
 The following example shows how to maintain a history of snapshots with a consistent naming scheme. To keep a week's worth of snapshots, the user destroys the oldest snapshot, renames the remaining snapshots, and then creates a new snapshot, as follows:
@@ -2424,7 +2400,7 @@ The following example shows how to maintain a history of snapshots with a consis
 .sp
 
 .LP
-\fBExample 18 \fRSetting sharenfs Property Options on a ZFS File System
+\fBExample 17 \fRSetting sharenfs Property Options on a ZFS File System
 .sp
 .LP
 The following commands show how to set "sharenfs" property options to enable \fBrw\fR access for a set of \fBIP\fR addresses and to enable root access for system \fBneo\fR on the \fBtank/home\fR file system.
@@ -2433,7 +2409,7 @@ The following commands show how to set "sharenfs" property options to enable \fB
 .in +2
 .nf
 \fB# zfs set sharenfs='rw=@123.123.0.0/16,root=neo' tank/home\fR
-
+ 
 .fi
 .in -2
 .sp
@@ -2443,7 +2419,7 @@ The following commands show how to set "sharenfs" property options to enable \fB
 If you are using \fBDNS\fR for host name resolution, specify the fully qualified hostname.
 
 .LP
-\fBExample 19 \fRDelegating ZFS Administration Permissions on a ZFS Dataset
+\fBExample 18 \fRDelegating ZFS Administration Permissions on a ZFS Dataset
 .sp
 .LP
 The following example shows how to set permissions so that user "\fBcindys\fR" can create, destroy, mount and take snapshots on \fBtank/cindys\fR. The permissions on \fBtank/cindys\fR are also displayed.
@@ -2455,9 +2431,9 @@ The following example shows how to set permissions so that user "\fBcindys\fR" c
 # zfs allow tank/cindys\fR
 -------------------------------------------------------------
 Local+Descendent permissions on (tank/cindys)
-         user cindys create,destroy,mount,snapshot
+          user cindys create,destroy,mount,snapshot
 -------------------------------------------------------------
-
+ 
 .fi
 .in -2
 .sp
@@ -2474,7 +2450,7 @@ Because the \fBtank/cindys\fR mount point permission is set to 755 by default, u
 .sp
 
 .LP
-\fBExample 20 \fRDelegating Create Time Permissions on a ZFS Dataset
+\fBExample 19 \fRDelegating Create Time Permissions on a ZFS Dataset
 .sp
 .LP
 The following example shows how to grant anyone in the group \fBstaff\fR to create file systems in \fBtank/users\fR. This syntax also allows staff members to destroy their own file systems, but not destroy anyone else's file system. The permissions on \fBtank/users\fR are also displayed.
@@ -2487,16 +2463,16 @@ The following example shows how to grant anyone in the group \fBstaff\fR to crea
 # zfs allow tank/users\fR
 -------------------------------------------------------------
 Create time permissions on (tank/users)
-         create,destroy
+          create,destroy
 Local+Descendent permissions on (tank/users)
-         group staff create,mount
+          group staff create,mount
 ------------------------------------------------------------- 
 .fi
 .in -2
 .sp
 
 .LP
-\fBExample 21 \fRDefining and Granting a Permission Set on a ZFS Dataset
+\fBExample 20 \fRDefining and Granting a Permission Set on a ZFS Dataset
 .sp
 .LP
 The following example shows how to define and grant a permission set on the \fBtank/users\fR file system. The permissions on \fBtank/users\fR are also displayed.
@@ -2509,18 +2485,18 @@ The following example shows how to define and grant a permission set on the \fBt
 # zfs allow tank/users
 -------------------------------------------------------------
 Permission sets on (tank/users)
-       @pset create,destroy,mount,snapshot
+        @pset create,destroy,mount,snapshot
 Create time permissions on (tank/users)
-       create,destroy
+        create,destroy
 Local+Descendent permissions on (tank/users)
-       group staff @pset,create,mount
+        group staff @pset,create,mount
 -------------------------------------------------------------\fR
 .fi
 .in -2
 .sp
 
 .LP
-\fBExample 22 \fRDelegating Property Permissions on a ZFS Dataset
+\fBExample 21 \fRDelegating Property Permissions on a ZFS Dataset
 .sp
 .LP
 The following example shows to grant the ability to set quotas and reservations on the \fBusers/home\fR file system. The permissions on \fBusers/home\fR are also displayed.
@@ -2532,7 +2508,7 @@ The following example shows to grant the ability to set quotas and reservations
 # zfs allow users/home\fR
 -------------------------------------------------------------
 Local+Descendent permissions on (users/home)
-       user cindys quota,reservation
+        user cindys quota,reservation
 -------------------------------------------------------------
 cindys% zfs set quota=10G users/home/marks
 cindys% zfs get quota users/home/marks
@@ -2543,7 +2519,7 @@ users/home/marks  quota     10G               local
 .sp
 
 .LP
-\fBExample 23 \fRRemoving ZFS Delegated Permissions on a ZFS Dataset
+\fBExample 22 \fRRemoving ZFS Delegated Permissions on a ZFS Dataset
 .sp
 .LP
 The following example shows how to remove the snapshot permission from the \fBstaff\fR group on the \fBtank/users\fR file system. The permissions on \fBtank/users\fR are also displayed.
@@ -2555,11 +2531,11 @@ The following example shows how to remove the snapshot permission from the \fBst
 # zfs allow tank/users\fR
 -------------------------------------------------------------
 Permission sets on (tank/users)
-       @pset create,destroy,mount,snapshot
+        @pset create,destroy,mount,snapshot
 Create time permissions on (tank/users)
-       create,destroy
+        create,destroy
 Local+Descendent permissions on (tank/users)
-       group staff @pset,create,mount
+        group staff @pset,create,mount
 ------------------------------------------------------------- 
 .fi
 .in -2
@@ -2575,8 +2551,8 @@ The following exit values are returned:
 .na
 \fB\fB0\fR\fR
 .ad
-.RS 5n
-.rt  
+.sp .6
+.RS 4n
 Successful completion. 
 .RE
 
@@ -2586,8 +2562,8 @@ Successful completion.
 .na
 \fB\fB1\fR\fR
 .ad
-.RS 5n
-.rt  
+.sp .6
+.RS 4n
 An error occurred.
 .RE
 
@@ -2597,8 +2573,8 @@ An error occurred.
 .na
 \fB\fB2\fR\fR
 .ad
-.RS 5n
-.rt  
+.sp .6
+.RS 4n
 Invalid command line options were specified.
 .RE
 
@@ -2627,4 +2603,4 @@ Interface StabilityCommitted
 \fBgzip\fR(1), \fBssh\fR(1), \fBmount\fR(1M), \fBshare\fR(1M), \fBsharemgr\fR(1M), \fBunshare\fR(1M), \fBzonecfg\fR(1M), \fBzpool\fR(1M), \fBchmod\fR(2), \fBstat\fR(2), \fBfsync\fR(3c), \fBdfstab\fR(4), \fBattributes\fR(5)
 .sp
 .LP
-For information about using the \fBZFS\fR web-based management tool and other \fBZFS\fR features, see the \fIZFS Administration Guide\fR.
+For information about using the \fBZFS\fR web-based management tool and other \fBZFS\fR features, see the \fISolaris ZFS Administration Guide\fR.
diff --git a/cddl/contrib/opensolaris/cmd/zpool/zpool.8 b/cddl/contrib/opensolaris/cmd/zpool/zpool.8
index a7967d7330f..b6c97c1a5ef 100644
--- a/cddl/contrib/opensolaris/cmd/zpool/zpool.8
+++ b/cddl/contrib/opensolaris/cmd/zpool/zpool.8
@@ -1,24 +1,9 @@
 '\" te
-.\" CDDL HEADER START
-.\"
-.\" The contents of this file are subject to the terms of the
-.\" Common Development and Distribution License (the "License").  
-.\" You may not use this file except in compliance with the License.
-.\"
-.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
-.\" or http://www.opensolaris.org/os/licensing.
-.\" See the License for the specific language governing permissions
-.\" and limitations under the License.
-.\"
-.\" When distributing Covered Code, include this CDDL HEADER in each
-.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
-.\" If applicable, add the following below this CDDL HEADER, with the
-.\" fields enclosed by brackets "[]" replaced with your own identifying
-.\" information: Portions Copyright [yyyy] [name of copyright owner]
-.\"
-.\" CDDL HEADER END
 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
-.TH zpool 1M "13 Nov 2007" "SunOS 5.11" "System Administration Commands"
+.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
+.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
+.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
+.TH zpool 1M "5 Mar 2009" "SunOS 5.11" "System Administration Commands"
 .SH NAME
 zpool \- configures ZFS storage pools
 .SH SYNOPSIS
@@ -29,8 +14,8 @@ zpool \- configures ZFS storage pools
 
 .LP
 .nf
-\fBzpool create\fR [\fB-fn\fR] [\fB-o\fR \fIproperty=value\fR] ... [\fB-m\fR \fImountpoint\fR] [\fB-R\fR \fIroot\fR]
-    \fIpool\fR \fIvdev\fR ...
+\fBzpool create\fR [\fB-fn\fR] [\fB-o\fR \fIproperty=value\fR] ... [\fB-O\fR \fIfile-system-property=value\fR] 
+     ... [\fB-m\fR \fImountpoint\fR] [\fB-R\fR \fIroot\fR] \fIpool\fR \fIvdev\fR ...
 .fi
 
 .LP
@@ -106,13 +91,13 @@ zpool \- configures ZFS storage pools
 .LP
 .nf
 \fBzpool import\fR [\fB-o \fImntopts\fR\fR] [\fB-p\fR \fIproperty=value\fR] ... [\fB-d\fR \fIdir\fR | \fB-c\fR \fIcachefile\fR] 
-    [\fB-D\fR] [\fB-f\fR] [\fB-R\fR \fIroot\fR] \fB-a\fR
+     [\fB-D\fR] [\fB-f\fR] [\fB-R\fR \fIroot\fR] \fB-a\fR
 .fi
 
 .LP
 .nf
 \fBzpool import\fR [\fB-o \fImntopts\fR\fR] [\fB-o\fR \fIproperty=value\fR] ... [\fB-d\fR \fIdir\fR | \fB-c\fR \fIcachefile\fR]
-    [\fB-D\fR] [\fB-f\fR] [\fB-R\fR \fIroot\fR] \fIpool\fR |\fIid\fR [\fInewpool\fR]
+     [\fB-D\fR] [\fB-f\fR] [\fB-R\fR \fIroot\fR] \fIpool\fR |\fIid\fR [\fInewpool\fR]
 .fi
 
 .LP
@@ -169,8 +154,7 @@ A "virtual device" describes a single device or a collection of devices organize
 .ad
 .RS 10n
 .rt  
-A block device, typically located under "/dev/dsk". \fBZFS\fR can use individual slices or partitions, though the recommended mode of operation is to use whole disks. A disk can be specified by a full path, or it can be a shorthand name (the relative portion
-of the path under "/dev/dsk"). A whole disk can be specified by omitting the slice or partition designation. For example, "c0t0d0" is equivalent to "/dev/dsk/c0t0d0s2". When given a whole disk, \fBZFS\fR automatically labels the disk, if necessary.
+A block device, typically located under "/dev/dsk". \fBZFS\fR can use individual slices or partitions, though the recommended mode of operation is to use whole disks. A disk can be specified by a full path, or it can be a shorthand name (the relative portion of the path under "/dev/dsk"). A whole disk can be specified by omitting the slice or partition designation. For example, "c0t0d0" is equivalent to "/dev/dsk/c0t0d0s2". When given a whole disk, \fBZFS\fR automatically labels the disk, if necessary.
 .RE
 
 .sp
@@ -192,8 +176,7 @@ A regular file. The use of files as a backing store is strongly discouraged. It
 .ad
 .RS 10n
 .rt  
-A mirror of two or more devices. Data is replicated in an identical fashion across all components of a mirror. A mirror with \fIN\fR disks of size \fIX\fR can hold \fIX\fR bytes and can withstand (\fIN-1\fR)
-devices failing before data integrity is compromised.
+A mirror of two or more devices. Data is replicated in an identical fashion across all components of a mirror. A mirror with \fIN\fR disks of size \fIX\fR can hold \fIX\fR bytes and can withstand (\fIN-1\fR) devices failing before data integrity is compromised.
 .RE
 
 .sp
@@ -214,11 +197,9 @@ devices failing before data integrity is compromised.
 .rt  
 A variation on \fBRAID-5\fR that allows for better distribution of parity and eliminates the "\fBRAID-5\fR write hole" (in which data and parity become inconsistent after a power loss). Data and parity is striped across all disks within a \fBraidz\fR group.
 .sp
-A \fBraidz\fR group can have either single- or double-parity, meaning that the \fBraidz\fR group can sustain one or two failures respectively without losing any data. The \fBraidz1\fR \fBvdev\fR type specifies a single-parity \fBraidz\fR group
-and the \fBraidz2\fR \fBvdev\fR type specifies a double-parity \fBraidz\fR group. The \fBraidz\fR \fBvdev\fR type is an alias for \fBraidz1\fR.
+A \fBraidz\fR group can have either single- or double-parity, meaning that the \fBraidz\fR group can sustain one or two failures respectively without losing any data. The \fBraidz1\fR \fBvdev\fR type specifies a single-parity \fBraidz\fR group and the \fBraidz2\fR \fBvdev\fR type specifies a double-parity \fBraidz\fR group. The \fBraidz\fR \fBvdev\fR type is an alias for \fBraidz1\fR.
 .sp
-A \fBraidz\fR group with \fIN\fR disks of size \fIX\fR with \fIP\fR parity disks can hold approximately (\fIN-P\fR)*\fIX\fR bytes and can withstand \fIP\fR device(s)
-failing before data integrity is compromised. The minimum number of devices in a \fBraidz\fR group is one more than the number of parity disks. The recommended number is between 3 and 9 to help increase performance.
+A \fBraidz\fR group with \fIN\fR disks of size \fIX\fR with \fIP\fR parity disks can hold approximately (\fIN-P\fR)*\fIX\fR bytes and can withstand \fIP\fR device(s) failing before data integrity is compromised. The minimum number of devices in a \fBraidz\fR group is one more than the number of parity disks. The recommended number is between 3 and 9 to help increase performance.
 .RE
 
 .sp
@@ -240,8 +221,7 @@ A special pseudo-\fBvdev\fR which keeps track of available hot spares for a pool
 .ad
 .RS 10n
 .rt  
-A separate intent log device. If more than one log device is specified, then writes are load-balanced between devices. Log devices can be mirrored. However, \fBraidz\fR and \fBraidz2\fR are not supported for the intent log. For more information, see the "Intent
-Log" section.
+A separate intent log device. If more than one log device is specified, then writes are load-balanced between devices. Log devices can be mirrored. However, \fBraidz\fR and \fBraidz2\fR are not supported for the intent log. For more information, see the "Intent Log" section.
 .RE
 
 .sp
@@ -260,8 +240,7 @@ A device used to cache storage pool data. A cache device cannot be mirrored or p
 Virtual devices cannot be nested, so a mirror or \fBraidz\fR virtual device can only contain files or disks. Mirrors of mirrors (or other combinations) are not allowed.
 .sp
 .LP
-A pool can have any number of virtual devices at the top of the configuration (known as "root vdevs"). Data is dynamically distributed across all top-level devices to balance data among devices. As new virtual devices are added, \fBZFS\fR automatically places data
-on the newly available devices.
+A pool can have any number of virtual devices at the top of the configuration (known as "root vdevs"). Data is dynamically distributed across all top-level devices to balance data among devices. As new virtual devices are added, \fBZFS\fR automatically places data on the newly available devices.
 .sp
 .LP
 Virtual devices are specified one at a time on the command line, separated by whitespace. The keywords "mirror" and "raidz" are used to distinguish where a group ends and another begins. For example, the following creates two root vdevs, each a mirror of two disks:
@@ -279,12 +258,10 @@ Virtual devices are specified one at a time on the command line, separated by wh
 \fBZFS\fR supports a rich set of mechanisms for handling device failure and data corruption. All metadata and data is checksummed, and \fBZFS\fR automatically repairs bad data from a good copy when corruption is detected.
 .sp
 .LP
-In order to take advantage of these features, a pool must make use of some form of redundancy, using either mirrored or \fBraidz\fR groups. While \fBZFS\fR supports running in a non-redundant configuration, where each root vdev is simply a disk or file, this is
-strongly discouraged. A single case of bit corruption can render some or all of your data unavailable.
+In order to take advantage of these features, a pool must make use of some form of redundancy, using either mirrored or \fBraidz\fR groups. While \fBZFS\fR supports running in a non-redundant configuration, where each root vdev is simply a disk or file, this is strongly discouraged. A single case of bit corruption can render some or all of your data unavailable.
 .sp
 .LP
-A pool's health status is described by one of three states: online, degraded, or faulted. An online pool has all devices operating normally. A degraded pool is one in which one or more devices have failed, but the data is still available due to a redundant configuration. A faulted pool has
-corrupted metadata, or one or more faulted devices, and insufficient replicas to continue functioning. 
+A pool's health status is described by one of three states: online, degraded, or faulted. An online pool has all devices operating normally. A degraded pool is one in which one or more devices have failed, but the data is still available due to a redundant configuration. A faulted pool has corrupted metadata, or one or more faulted devices, and insufficient replicas to continue functioning. 
 .sp
 .LP
 The health of the top-level vdev, such as mirror or \fBraidz\fR device, is potentially impacted by the state of its associated vdevs, or component devices. A top-level vdev or component device is in one of the following states:
@@ -399,8 +376,10 @@ If a device is removed and later re-attached to the system, \fBZFS\fR attempts t
 
 .sp
 .LP
-Spares can be shared across multiple pools, and can be added with the "\fBzpool add\fR" command and removed with the "\fBzpool remove\fR" command. Once a spare replacement is initiated, a new "spare" \fBvdev\fR is
-created within the configuration that will remain there until the original device is replaced. At this point, the hot spare becomes available again if another device fails.
+Spares can be shared across multiple pools, and can be added with the "\fBzpool add\fR" command and removed with the "\fBzpool remove\fR" command. Once a spare replacement is initiated, a new "spare" \fBvdev\fR is created within the configuration that will remain there until the original device is replaced. At this point, the hot spare becomes available again if another device fails.
+.sp
+.LP
+If a pool has a shared spare that is currently being used, the pool can not be exported since other pools may use this shared spare, which may lead to potential data corruption.
 .sp
 .LP
 An in-progress spare replacement can be cancelled by detaching the hot spare. If the original faulted device is detached, then the hot spare assumes its place in the configuration, and is removed from the spare list of all active pools.
@@ -410,9 +389,7 @@ Spares cannot replace log devices.
 .SS "Intent Log"
 .sp
 .LP
-The \fBZFS\fR Intent Log (\fBZIL\fR) satisfies \fBPOSIX\fR requirements for synchronous transactions. For instance, databases often require their transactions to be on stable storage devices when returning from a system call. \fBNFS\fR and
-other applications can also use \fBfsync\fR() to ensure data stability. By default, the intent log is allocated from blocks within the main pool. However, it might be possible to get better performance using separate intent log devices such as \fBNVRAM\fR or a dedicated
-disk. For example:
+The \fBZFS\fR Intent Log (\fBZIL\fR) satisfies \fBPOSIX\fR requirements for synchronous transactions. For instance, databases often require their transactions to be on stable storage devices when returning from a system call. \fBNFS\fR and other applications can also use \fBfsync\fR() to ensure data stability. By default, the intent log is allocated from blocks within the main pool. However, it might be possible to get better performance using separate intent log devices such as \fBNVRAM\fR or a dedicated disk. For example:
 .sp
 .in +2
 .nf
@@ -430,8 +407,7 @@ Log devices can be added, replaced, attached, detached, and imported and exporte
 .SS "Cache Devices"
 .sp
 .LP
-Devices can be added to a storage pool as "cache devices." These devices provide an additional layer of caching between main memory and disk. For read-heavy workloads, where the working set size is much larger than what can be cached in main memory, using cache devices allow
-much more of this working set to be served from low latency media. Using cache devices provides the greatest performance improvement for random read-workloads of mostly static content.
+Devices can be added to a storage pool as "cache devices." These devices provide an additional layer of caching between main memory and disk. For read-heavy workloads, where the working set size is much larger than what can be cached in main memory, using cache devices allow much more of this working set to be served from low latency media. Using cache devices provides the greatest performance improvement for random read-workloads of mostly static content.
 .sp
 .LP
 To create a pool with cache devices, specify a "cache" \fBvdev\fR with any number of devices. For example:
@@ -521,8 +497,7 @@ Amount of storage space used within the pool.
 
 .sp
 .LP
-These space usage properties report actual physical space available to the storage pool. The physical space can be different from the total amount of space that any contained datasets can actually use. The amount of space used in a \fBraidz\fR configuration depends on the characteristics
-of the data being written. In addition, \fBZFS\fR reserves some space for internal accounting that the \fBzfs\fR(1M) command takes into account, but the \fBzpool\fR command does not. For non-full pools of a reasonable size, these effects should be invisible. For small pools, or pools that are close to being completely full, these discrepancies may become more noticeable.
+These space usage properties report actual physical space available to the storage pool. The physical space can be different from the total amount of space that any contained datasets can actually use. The amount of space used in a \fBraidz\fR configuration depends on the characteristics of the data being written. In addition, \fBZFS\fR reserves some space for internal accounting that the \fBzfs\fR(1M) command takes into account, but the \fBzpool\fR command does not. For non-full pools of a reasonable size, these effects should be invisible. For small pools, or pools that are close to being completely full, these discrepancies may become more noticeable.
 .sp
 .LP
 The following property can be set at creation time and import time:
@@ -534,8 +509,7 @@ The following property can be set at creation time and import time:
 .ad
 .sp .6
 .RS 4n
-Alternate root directory. If set, this directory is prepended to any mount points within the pool. This can be used when examining an unknown pool where the mount points cannot be trusted, or in an alternate boot environment, where the typical paths are not valid. \fBaltroot\fR is
-not a persistent property. It is valid only while the system is up. Setting \fBaltroot\fR defaults to using \fBcachefile\fR=none, though this may be overridden	 using an explicit setting.
+Alternate root directory. If set, this directory is prepended to any mount points within the pool. This can be used when examining an unknown pool where the mount points cannot be trusted, or in an alternate boot environment, where the typical paths are not valid. \fBaltroot\fR is not a persistent property. It is valid only while the system is up. Setting \fBaltroot\fR defaults to using \fBcachefile\fR=none, though this may be overridden	 using an explicit setting.
 .RE
 
 .sp
@@ -549,8 +523,7 @@ The following properties can be set at creation time and import time, and later
 .ad
 .sp .6
 .RS 4n
-Controls automatic device replacement. If set to "\fBoff\fR", device replacement must be initiated by the administrator by using the "\fBzpool replace\fR" command. If set to "\fBon\fR", any new device, found
-in the same physical location as a device that previously belonged to the pool, is automatically formatted and replaced. The default behavior is "\fBoff\fR". This property can also be referred to by its shortened column name, "replace".
+Controls automatic device replacement. If set to "\fBoff\fR", device replacement must be initiated by the administrator by using the "\fBzpool replace\fR" command. If set to "\fBon\fR", any new device, found in the same physical location as a device that previously belonged to the pool, is automatically formatted and replaced. The default behavior is "\fBoff\fR". This property can also be referred to by its shortened column name, "replace".
 .RE
 
 .sp
@@ -572,9 +545,7 @@ Identifies the default bootable dataset for the root pool. This property is expe
 .ad
 .sp .6
 .RS 4n
-Controls the location of where the pool configuration is cached. Discovering all pools on system startup requires a cached copy of the configuration data that is stored on the root file system. All pools in this cache are automatically imported when the system boots. Some environments,
-such as install and clustering, need to cache this information in a different location so that pools are not automatically imported. Setting this property caches the pool configuration in a different location that can later be imported with "\fBzpool import -c\fR". Setting
-it to the special value "\fBnone\fR" creates a temporary pool that is never cached, and the special value \fB\&''\fR (empty string) uses the default location. 
+Controls the location of where the pool configuration is cached. Discovering all pools on system startup requires a cached copy of the configuration data that is stored on the root file system. All pools in this cache are automatically imported when the system boots. Some environments, such as install and clustering, need to cache this information in a different location so that pools are not automatically imported. Setting this property caches the pool configuration in a different location that can later be imported with "\fBzpool import -c\fR". Setting it to the special value "\fBnone\fR" creates a temporary pool that is never cached, and the special value \fB\&''\fR (empty string) uses the default location. 
 .sp
 Multiple pools can share the same cache file. Because the kernel destroys and recreates this file when pools are added and removed, care should be taken when attempting to access this file. When the last pool using a \fBcachefile\fR is exported or destroyed, the file is removed.
 .RE
@@ -587,8 +558,7 @@ Multiple pools can share the same cache file. Because the kernel destroys and re
 .ad
 .sp .6
 .RS 4n
-Controls whether a non-privileged user is granted access based on the dataset permissions defined on the dataset. See \fBzfs\fR(1M) for more information
-on \fBZFS\fR delegated administration.
+Controls whether a non-privileged user is granted access based on the dataset permissions defined on the dataset. See \fBzfs\fR(1M) for more information on \fBZFS\fR delegated administration.
 .RE
 
 .sp
@@ -635,6 +605,17 @@ Prints out a message to the console and generates a system crash dump.
 
 .RE
 
+.sp
+.ne 2
+.mk
+.na
+\fB\fBlistsnaps\fR=on | off\fR
+.ad
+.sp .6
+.RS 4n
+Controls whether information about snapshots associated with this pool is output when "\fBzfs list\fR" is run without the  \fB-t\fR option.  The default value is "off".
+.RE
+
 .sp
 .ne 2
 .mk
@@ -643,8 +624,7 @@ Prints out a message to the console and generates a system crash dump.
 .ad
 .sp .6
 .RS 4n
-The current on-disk version of the pool. This can be increased, but never decreased. The preferred method of updating pools is with the "\fBzpool upgrade\fR" command, though this property can be used when a specific version is needed for backwards compatibility.
-This property can be any number between 1 and the current version reported by "\fBzpool upgrade -v\fR". The special value "\fBcurrent\fR" is an alias for the latest supported version.
+The current on-disk version of the pool. This can be increased, but never decreased. The preferred method of updating pools is with the "\fBzpool upgrade\fR" command, though this property can be used when a specific version is needed for backwards compatibility. This property can be any number between 1 and the current version reported by "\fBzpool upgrade -v\fR".
 .RE
 
 .SS "Subcommands"
@@ -669,18 +649,15 @@ Displays a help message.
 .ne 2
 .mk
 .na
-\fB\fBzpool create\fR [\fB-fn\fR] [\fB-o\fR \fIproperty=value\fR] ... [\fB-m\fR \fImountpoint\fR] [\fB-R\fR \fIroot\fR] \fIpool\fR \fIvdev\fR ...\fR
+\fB\fBzpool create\fR [\fB-fn\fR] [\fB-o\fR \fIproperty=value\fR] ... [\fB-O\fR \fIfile-system-property=value\fR] ... [\fB-m\fR \fImountpoint\fR] [\fB-R\fR \fIroot\fR] \fIpool\fR \fIvdev\fR ...\fR
 .ad
 .sp .6
 .RS 4n
-Creates a new storage pool containing the virtual devices specified on the command line. The pool name must begin with a letter, and can only contain alphanumeric characters as well as underscore ("_"), dash ("-"), and period ("."). The pool
-names "mirror", "raidz", "spare" and "log" are reserved, as are names beginning with the pattern "c[0-9]". The \fBvdev\fR specification is described in the "Virtual Devices" section.
+Creates a new storage pool containing the virtual devices specified on the command line. The pool name must begin with a letter, and can only contain alphanumeric characters as well as underscore ("_"), dash ("-"), and period ("."). The pool names "mirror", "raidz", "spare" and "log" are reserved, as are names beginning with the pattern "c[0-9]". The \fBvdev\fR specification is described in the "Virtual Devices" section.
 .sp
-The command verifies that each device specified is accessible and not currently in use by another subsystem. There are some uses, such as being currently mounted, or specified as the dedicated dump device, that prevents a device from ever being used by \fBZFS\fR. Other uses,
-such as having a preexisting \fBUFS\fR file system, can be overridden with the \fB-f\fR option.
+The command verifies that each device specified is accessible and not currently in use by another subsystem. There are some uses, such as being currently mounted, or specified as the dedicated dump device, that prevents a device from ever being used by \fBZFS\fR. Other uses, such as having a preexisting \fBUFS\fR file system, can be overridden with the \fB-f\fR option.
 .sp
-The command also checks that the replication strategy for the pool is consistent. An attempt to combine redundant and non-redundant storage in a single pool, or to mix disks and files, results in an error unless \fB-f\fR is specified. The use of differently sized devices within
-a single \fBraidz\fR or mirror group is also flagged as an error unless \fB-f\fR is specified.
+The command also checks that the replication strategy for the pool is consistent. An attempt to combine redundant and non-redundant storage in a single pool, or to mix disks and files, results in an error unless \fB-f\fR is specified. The use of differently sized devices within a single \fBraidz\fR or mirror group is also flagged as an error unless \fB-f\fR is specified.
 .sp
 Unless the \fB-R\fR option is specified, the default mount point is "/\fIpool\fR". The mount point must not exist or must be empty, or else the root dataset cannot be mounted. This can be overridden with the \fB-m\fR option.
 .sp
@@ -716,6 +693,21 @@ Displays the configuration that would be used without actually creating the pool
 Sets the given pool properties. See the "Properties" section for a list of valid properties that can be set.
 .RE
 
+.sp
+.ne 2
+.mk
+.na
+\fB\fB-O\fR \fIfile-system-property=value\fR\fR
+.ad
+.br
+.na
+\fB[\fB-O\fR \fIfile-system-property=value\fR] ...\fR
+.ad
+.sp .6
+.RS 4n
+Sets the given file system properties in the root file system of the pool. See the "Properties" section of \fBzfs\fR(1M) for a list of valid properties that can be set.
+.RE
+
 .sp
 .ne 2
 .mk
@@ -770,8 +762,7 @@ Forces any active datasets contained within the pool to be unmounted.
 .ad
 .sp .6
 .RS 4n
-Adds the specified virtual devices to the given pool. The \fIvdev\fR specification is described in the "Virtual Devices" section. The behavior of the \fB-f\fR option, and the device checks performed are described in the "zpool create"
-subcommand.
+Adds the specified virtual devices to the given pool. The \fIvdev\fR specification is described in the "Virtual Devices" section. The behavior of the \fB-f\fR option, and the device checks performed are described in the "zpool create" subcommand.
 .sp
 .ne 2
 .mk
@@ -805,8 +796,7 @@ Do not add a disk that is currently configured as a quorum device to a zpool. Af
 .ad
 .sp .6
 .RS 4n
-Removes the specified device from the pool. This command currently only supports removing hot spares and cache devices. Devices that are part of a mirrored configuration can be removed using the "\fBzpool detach\fR" command. Non-redundant and \fBraidz\fR devices
-cannot be removed from a pool.
+Removes the specified device from the pool. This command currently only supports removing hot spares and cache devices. Devices that are part of a mirrored configuration can be removed using the "\fBzpool detach\fR" command. Non-redundant and \fBraidz\fR devices cannot be removed from a pool.
 .RE
 
 .sp
@@ -850,8 +840,7 @@ Comma-separated list of properties to display. See the "Properties" section for
 .ad
 .sp .6
 .RS 4n
-Displays \fBI/O\fR statistics for the given pools. When given an interval, the statistics are printed every \fIinterval\fR seconds until \fBCtrl-C\fR is pressed. If no \fIpools\fR are specified, statistics for
-every pool in the system is shown. If \fIcount\fR is specified, the command exits after \fIcount\fR reports are printed.
+Displays \fBI/O\fR statistics for the given pools. When given an interval, the statistics are printed every \fIinterval\fR seconds until \fBCtrl-C\fR is pressed. If no \fIpools\fR are specified, statistics for every pool in the system is shown. If \fIcount\fR is specified, the command exits after \fIcount\fR reports are printed.
 .sp
 .ne 2
 .mk
@@ -956,8 +945,7 @@ Clears device errors in a pool. If no arguments are specified, all device errors
 .ad
 .sp .6
 .RS 4n
-Attaches \fInew_device\fR to an existing \fBzpool\fR device. The existing device cannot be part of a \fBraidz\fR configuration. If \fIdevice\fR is not currently part of a mirrored configuration, \fIdevice\fR automatically
-transforms into a two-way mirror of \fIdevice\fR and \fInew_device\fR. If \fIdevice\fR is part of a two-way mirror, attaching \fInew_device\fR creates a three-way mirror, and so on. In either case, \fInew_device\fR begins to resilver immediately.
+Attaches \fInew_device\fR to an existing \fBzpool\fR device. The existing device cannot be part of a \fBraidz\fR configuration. If \fIdevice\fR is not currently part of a mirrored configuration, \fIdevice\fR automatically transforms into a two-way mirror of \fIdevice\fR and \fInew_device\fR. If \fIdevice\fR is part of a two-way mirror, attaching \fInew_device\fR creates a three-way mirror, and so on. In either case, \fInew_device\fR begins to resilver immediately.
 .sp
 .ne 2
 .mk
@@ -994,8 +982,7 @@ Replaces \fIold_device\fR with \fInew_device\fR. This is equivalent to attaching
 .sp
 The size of \fInew_device\fR must be greater than or equal to the minimum size of all the devices in a mirror or \fBraidz\fR configuration.
 .sp
-\fInew_device\fR is required if the pool is not redundant. If \fInew_device\fR is not specified, it defaults to \fIold_device\fR. This form of replacement is useful after an existing disk has failed and has been physically replaced.
-In this case, the new disk may have the same \fB/dev/dsk\fR path as the old device, even though it is actually a different disk. \fBZFS\fR recognizes this.
+\fInew_device\fR is required if the pool is not redundant. If \fInew_device\fR is not specified, it defaults to \fIold_device\fR. This form of replacement is useful after an existing disk has failed and has been physically replaced. In this case, the new disk may have the same \fB/dev/dsk\fR path as the old device, even though it is actually a different disk. \fBZFS\fR recognizes this.
 .sp
 .ne 2
 .mk
@@ -1017,11 +1004,9 @@ Forces use of \fInew_device\fR, even if its appears to be in use. Not all device
 .ad
 .sp .6
 .RS 4n
-Begins a scrub. The scrub examines all data in the specified pools to verify that it checksums correctly. For replicated (mirror or \fBraidz\fR) devices, \fBZFS\fR automatically repairs any damage discovered during the scrub. The "\fBzpool
-status\fR" command reports the progress of the scrub and summarizes the results of the scrub upon completion.
+Begins a scrub. The scrub examines all data in the specified pools to verify that it checksums correctly. For replicated (mirror or \fBraidz\fR) devices, \fBZFS\fR automatically repairs any damage discovered during the scrub. The "\fBzpool status\fR" command reports the progress of the scrub and summarizes the results of the scrub upon completion.
 .sp
-Scrubbing and resilvering are very similar operations. The difference is that resilvering only examines data that \fBZFS\fR knows to be out of date (for example, when attaching a new device to a mirror or replacing an existing device), whereas scrubbing examines all data to
-discover silent errors due to hardware faults or disk failure.
+Scrubbing and resilvering are very similar operations. The difference is that resilvering only examines data that \fBZFS\fR knows to be out of date (for example, when attaching a new device to a mirror or replacing an existing device), whereas scrubbing examines all data to discover silent errors due to hardware faults or disk failure.
 .sp
 Because scrubbing and resilvering are \fBI/O\fR-intensive operations, \fBZFS\fR only allows one at a time. If a scrub is already in progress, the "\fBzpool scrub\fR" command terminates it and starts a new scrub. If a resilver is in progress, \fBZFS\fR does not allow a scrub to be started until the resilver completes.
 .sp
@@ -1045,8 +1030,7 @@ Stop scrubbing.
 .ad
 .sp .6
 .RS 4n
-Lists pools available to import. If the \fB-d\fR option is not specified, this command searches for devices in "/dev/dsk". The \fB-d\fR option can be specified multiple times, and all directories are searched. If the device appears to be part of
-an exported pool, this command displays a summary of the pool with the name of the pool, a numeric identifier, as well as the \fIvdev\fR layout and current health of the device for each device or file. Destroyed pools, pools that were previously destroyed with the "\fBzpool destroy\fR" command, are not listed unless the \fB-D\fR option is specified. 
+Lists pools available to import. If the \fB-d\fR option is not specified, this command searches for devices in "/dev/dsk". The \fB-d\fR option can be specified multiple times, and all directories are searched. If the device appears to be part of an exported pool, this command displays a summary of the pool with the name of the pool, a numeric identifier, as well as the \fIvdev\fR layout and current health of the device for each device or file. Destroyed pools, pools that were previously destroyed with the "\fBzpool destroy\fR" command, are not listed unless the \fB-D\fR option is specified. 
 .sp
 The numeric identifier is unique, and can be used instead of the pool name when multiple exported pools of the same name are available.
 .sp
@@ -1088,13 +1072,11 @@ Lists destroyed pools only.
 .ne 2
 .mk
 .na
-\fB\fBzpool import\fR [\fB-o\fR \fImntopts\fR] [ \fB-o\fR \fIproperty\fR=\fIvalue\fR] ... [\fB-d\fR \fIdir\fR | \fB-c\fR \fIcachefile\fR]
-[\fB-D\fR] [\fB-f\fR] [\fB-R\fR \fIroot\fR] \fB-a\fR\fR
+\fB\fBzpool import\fR [\fB-o\fR \fImntopts\fR] [ \fB-o\fR \fIproperty\fR=\fIvalue\fR] ... [\fB-d\fR \fIdir\fR | \fB-c\fR \fIcachefile\fR] [\fB-D\fR] [\fB-f\fR] [\fB-R\fR \fIroot\fR] \fB-a\fR\fR
 .ad
 .sp .6
 .RS 4n
-Imports all pools found in the search directories. Identical to the previous command, except that all pools with a sufficient number of devices available are imported. Destroyed pools, pools that were previously destroyed with the "\fBzpool destroy\fR"
-command, will not be imported unless the \fB-D\fR option is specified.
+Imports all pools found in the search directories. Identical to the previous command, except that all pools with a sufficient number of devices available are imported. Destroyed pools, pools that were previously destroyed with the "\fBzpool destroy\fR" command, will not be imported unless the \fB-D\fR option is specified.
 .sp
 .ne 2
 .mk
@@ -1103,8 +1085,7 @@ command, will not be imported unless the \fB-D\fR option is specified.
 .ad
 .RS 21n
 .rt  
-Comma-separated list of mount options to use when mounting datasets within the pool. See \fBzfs\fR(1M) for a description of dataset properties and mount
-options.
+Comma-separated list of mount options to use when mounting datasets within the pool. See \fBzfs\fR(1M) for a description of dataset properties and mount options.
 .RE
 
 .sp
@@ -1190,15 +1171,13 @@ Sets the "\fBcachefile\fR" property to "\fBnone\fR" and the "\fIaltroot\fR" prop
 .ne 2
 .mk
 .na
-\fB\fBzpool import\fR [\fB-o\fR \fImntopts\fR] [ \fB-o\fR \fIproperty\fR=\fIvalue\fR] ... [\fB-d\fR \fIdir\fR | \fB-c\fR \fIcachefile\fR]
-[\fB-D\fR] [\fB-f\fR] [\fB-R\fR \fIroot\fR] \fIpool\fR | \fIid\fR [\fInewpool\fR]\fR
+\fB\fBzpool import\fR [\fB-o\fR \fImntopts\fR] [ \fB-o\fR \fIproperty\fR=\fIvalue\fR] ... [\fB-d\fR \fIdir\fR | \fB-c\fR \fIcachefile\fR] [\fB-D\fR] [\fB-f\fR] [\fB-R\fR \fIroot\fR] \fIpool\fR | \fIid\fR [\fInewpool\fR]\fR
 .ad
 .sp .6
 .RS 4n
 Imports a specific pool. A pool can be identified by its name or the numeric identifier. If \fInewpool\fR is specified, the pool is imported using the name \fInewpool\fR. Otherwise, it is imported with the same name as its exported name.
 .sp
-If a device is removed from a system without running "\fBzpool export\fR" first, the device appears as potentially active. It cannot be determined if this was a failed export, or whether the device is really in use from another host. To import a pool in this state,
-the \fB-f\fR option is required.
+If a device is removed from a system without running "\fBzpool export\fR" first, the device appears as potentially active. It cannot be determined if this was a failed export, or whether the device is really in use from another host. To import a pool in this state, the \fB-f\fR option is required.
 .sp
 .ne 2
 .mk
@@ -1207,8 +1186,7 @@ the \fB-f\fR option is required.
 .ad
 .sp .6
 .RS 4n
-Comma-separated list of mount options to use when mounting datasets within the pool. See \fBzfs\fR(1M) for a description of dataset properties and mount
-options.
+Comma-separated list of mount options to use when mounting datasets within the pool. See \fBzfs\fR(1M) for a description of dataset properties and mount options.
 .RE
 
 .sp
@@ -1289,7 +1267,7 @@ Sets the "\fBcachefile\fR" property to "\fBnone\fR" and the "\fIaltroot\fR" prop
 .RS 4n
 Exports the given pools from the system. All devices are marked as exported, but are still considered in use by other subsystems. The devices can be moved between systems (even those of different endianness) and imported as long as a sufficient number of devices are present.
 .sp
-Before exporting the pool, all datasets within the pool are unmounted.
+Before exporting the pool, all datasets within the pool are unmounted. A pool can not be exported if it has a shared spare that is currently being used.
 .sp
 For pools to be portable, you must give the \fBzpool\fR command whole disks, not just slices, so that \fBZFS\fR can label the disks with portable \fBEFI\fR labels. Otherwise, disk drivers on platforms of different endianness will not recognize the disks.
 .sp
@@ -1301,6 +1279,8 @@ For pools to be portable, you must give the \fBzpool\fR command whole disks, not
 .RS 6n
 .rt  
 Forcefully unmount all datasets, using the "\fBunmount -f\fR" command.
+.sp
+This command will forcefully export the pool even if it has a shared spare that is currently being used. This may lead to potential data corruption.
 .RE
 
 .RE
@@ -1313,8 +1293,7 @@ Forcefully unmount all datasets, using the "\fBunmount -f\fR" command.
 .ad
 .sp .6
 .RS 4n
-Displays all pools formatted using a different \fBZFS\fR on-disk version. Older versions can continue to be used, but some features may not be available. These pools can be upgraded using "\fBzpool upgrade -a\fR". Pools that are formatted with
-a more recent version are also displayed, although these pools will be inaccessible on the system.
+Displays all pools formatted using a different \fBZFS\fR on-disk version. Older versions can continue to be used, but some features may not be available. These pools can be upgraded using "\fBzpool upgrade -a\fR". Pools that are formatted with a more recent version are also displayed, although these pools will be inaccessible on the system.
 .RE
 
 .sp
@@ -1407,9 +1386,9 @@ Retrieves the given list of properties (or all properties if "\fBall\fR" is used
 .in +2
 .nf
        name          Name of storage pool
-       property      Property name
-       value         Property value
-       source        Property source, either 'default' or 'local'.
+        property      Property name
+        value         Property value
+        source        Property source, either 'default' or 'local'.
 .fi
 .in -2
 .sp
@@ -1421,7 +1400,7 @@ See the "Properties" section for more information on the available pool properti
 .ne 2
 .mk
 .na
-\fB\fBzpool set\fR \fIproperty\fR=\fIvalue\fR \fIpool\fR \fR
+\fB\fBzpool set\fR \fIproperty\fR=\fIvalue\fR \fIpool\fR\fR
 .ad
 .sp .6
 .RS 4n
@@ -1513,10 +1492,10 @@ The results from this command are similar to the following:
 .in +2
 .nf
 \fB# zpool list\fR
-    NAME              SIZE    USED   AVAIL    CAP  HEALTH     ALTROOT
-    pool             67.5G   2.92M   67.5G     0%  ONLINE     -
-    tank             67.5G   2.92M   67.5G     0%  ONLINE     -
-    zion                 -       -       -     0%  FAULTED    -
+     NAME              SIZE    USED   AVAIL    CAP  HEALTH     ALTROOT
+     pool             67.5G   2.92M   67.5G     0%  ONLINE     -
+     tank             67.5G   2.92M   67.5G     0%  ONLINE     -
+     zion                 -       -       -     0%  FAULTED    -
 .fi
 .in -2
 .sp
@@ -1563,16 +1542,16 @@ The results from this command are similar to the following:
 .in +2
 .nf
 \fB# zpool import\fR
- pool: tank
-   id: 15451357997522795478
-state: ONLINE
+  pool: tank
+    id: 15451357997522795478
+ state: ONLINE
 action: The pool can be imported using its name or numeric identifier.
 config:
 
-       tank        ONLINE
-         mirror    ONLINE
-           c1t2d0  ONLINE
-           c1t3d0  ONLINE
+        tank        ONLINE
+          mirror    ONLINE
+            c1t2d0  ONLINE
+            c1t3d0  ONLINE
 
 \fB# zpool import tank\fR
 .fi
@@ -1642,7 +1621,7 @@ The following command creates a ZFS storage pool consisting of two, two-way mirr
 .in +2
 .nf
 \fB# zpool create pool mirror c0d0 c1d0 mirror c2d0 c3d0 log mirror \e
-  c4d0 c5d0\fR
+   c4d0 c5d0\fR
 .fi
 .in -2
 .sp

From d4425a31a50f18bed5d6071df63298581f9d9024 Mon Sep 17 00:00:00 2001
From: Nathan Whitehorn 
Date: Fri, 26 Mar 2010 00:53:13 +0000
Subject: [PATCH 071/119] Fix the ia64 build.

Pointy hat to: me
---
 sys/ia64/ia64/machdep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/ia64/ia64/machdep.c b/sys/ia64/ia64/machdep.c
index 9f47a9a1803..c13adc3181b 100644
--- a/sys/ia64/ia64/machdep.c
+++ b/sys/ia64/ia64/machdep.c
@@ -1381,7 +1381,7 @@ exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
 		 * Assumes that (bspstore & 0x1f8) < 0x1e0.
 		 */
 		suword((caddr_t)tf->tf_special.bspstore - 24, stack);
-		suword((caddr_t)tf->tf_special.bspstore - 16, ps_strings);
+		suword((caddr_t)tf->tf_special.bspstore - 16, imgp->ps_strings);
 		suword((caddr_t)tf->tf_special.bspstore -  8, 0);
 	}
 

From 6cdfa1ce970142c36d42c14b91dcc0cea1c37d5c Mon Sep 17 00:00:00 2001
From: Rick Macklem 
Date: Fri, 26 Mar 2010 01:19:29 +0000
Subject: [PATCH 072/119] Patch the regular NFS server so that it returns
 ESTALE to the client for all errors returned by VFS_FHTOVP(). This is
 required to ensure that EIO doesn't get returned to the client when ZFS is
 used as the server file system.

Tested by:	korvus AT comcast.net
Reviewed by:	jhb
MFC after:	2 weeks
---
 sys/nfsserver/nfs_srvsubs.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sys/nfsserver/nfs_srvsubs.c b/sys/nfsserver/nfs_srvsubs.c
index d84261e8249..f2e9d510e01 100644
--- a/sys/nfsserver/nfs_srvsubs.c
+++ b/sys/nfsserver/nfs_srvsubs.c
@@ -1128,6 +1128,9 @@ nfsrv_fhtovp(fhandle_t *fhp, int lockflag, struct vnode **vpp, int *vfslockedp,
 		}
 	}
 	error = VFS_FHTOVP(mp, &fhp->fh_fid, vpp);
+	if (error != 0)
+		/* Make sure the server replies ESTALE to the client. */
+		error = ESTALE;
 	vfs_unbusy(mp);
 	if (error)
 		goto out;

From 2561854d2b07a771e738d4321ef207173e844509 Mon Sep 17 00:00:00 2001
From: Xin LI 
Date: Fri, 26 Mar 2010 01:30:53 +0000
Subject: [PATCH 073/119] Our boot loader is capable of booting both i386 and
 amd64 kernels so call it "x86" instead of "i386".

Suggested by:	jhb in response to Alexander Best's loader proposal
MFC after:	1 month
---
 sys/boot/i386/boot2/boot2.c     | 2 +-
 sys/boot/i386/gptboot/gptboot.c | 2 +-
 sys/boot/i386/zfsboot/zfsboot.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/sys/boot/i386/boot2/boot2.c b/sys/boot/i386/boot2/boot2.c
index 58f217515df..f521fd7e071 100644
--- a/sys/boot/i386/boot2/boot2.c
+++ b/sys/boot/i386/boot2/boot2.c
@@ -283,7 +283,7 @@ main(void)
 
     for (;;) {
 	if (!autoboot || !OPT_CHECK(RBX_QUIET))
-	    printf("\nFreeBSD/i386 boot\n"
+	    printf("\nFreeBSD/x86 boot\n"
 		   "Default: %u:%s(%u,%c)%s\n"
 		   "boot: ",
 		   dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit,
diff --git a/sys/boot/i386/gptboot/gptboot.c b/sys/boot/i386/gptboot/gptboot.c
index 96efea6a1d5..6939556eb0d 100644
--- a/sys/boot/i386/gptboot/gptboot.c
+++ b/sys/boot/i386/gptboot/gptboot.c
@@ -281,7 +281,7 @@ main(void)
 
     for (;;) {
 	if (!autoboot || !OPT_CHECK(RBX_QUIET))
-	    printf("\nFreeBSD/i386 boot\n"
+	    printf("\nFreeBSD/x86 boot\n"
 		   "Default: %u:%s(%up%u)%s\n"
 		   "boot: ",
 		   dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit,
diff --git a/sys/boot/i386/zfsboot/zfsboot.c b/sys/boot/i386/zfsboot/zfsboot.c
index 07ade3ac61d..d312b2a7246 100644
--- a/sys/boot/i386/zfsboot/zfsboot.c
+++ b/sys/boot/i386/zfsboot/zfsboot.c
@@ -730,7 +730,7 @@ main(void)
 
     for (;;) {
 	if (!autoboot || !OPT_CHECK(RBX_QUIET))
-	    printf("\nFreeBSD/i386 boot\n"
+	    printf("\nFreeBSD/x86 boot\n"
 		   "Default: %s:%s\n"
 		   "boot: ",
 		   spa->spa_name, kname);

From 7482701cd4652c1ae14ed4194b59fe4a9bded52c Mon Sep 17 00:00:00 2001
From: Rick Macklem 
Date: Fri, 26 Mar 2010 01:35:19 +0000
Subject: [PATCH 074/119] Patch the experimental NFS server in a manner
 analagous to r205661 for the regular NFS server, to ensure that ESTALE is
 returned to the client for all errors returned by VFS_FHTOVP().

MFC after:	2 weeks
---
 sys/fs/nfsserver/nfs_nfsdport.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sys/fs/nfsserver/nfs_nfsdport.c b/sys/fs/nfsserver/nfs_nfsdport.c
index ba41780ed98..8ecb5f508b2 100644
--- a/sys/fs/nfsserver/nfs_nfsdport.c
+++ b/sys/fs/nfsserver/nfs_nfsdport.c
@@ -2443,6 +2443,9 @@ nfsvno_fhtovp(struct mount *mp, fhandle_t *fhp, struct sockaddr *nam,
 	*credp = NULL;
 	exp->nes_numsecflavor = 0;
 	error = VFS_FHTOVP(mp, &fhp->fh_fid, vpp);
+	if (error != 0)
+		/* Make sure the server replies ESTALE to the client. */
+		error = ESTALE;
 	if (nam && !error) {
 		error = VFS_CHECKEXP(mp, nam, &exp->nes_exflag, credp,
 		    &exp->nes_numsecflavor, &secflavors);

From f4926eabc28bb720438c1be5820b7aa21f1ef4d3 Mon Sep 17 00:00:00 2001
From: Marcel Moolenaar 
Date: Fri, 26 Mar 2010 02:29:15 +0000
Subject: [PATCH 075/119] Only use the interval timer for clock interrupts on
 the BSP and have the BSP use IPIs to trigger clock interrupts on the APs.
 This allows us to run on hardware configurations for which the ITC has
 non-uniform frequencies across CPUs.

While here, change the clock XIV to type IPI so as to protect
the interrupt delivery against CPU re-balancing once that's
implemented.
---
 sys/ia64/ia64/clock.c      | 98 +++++++++++++++++++++-----------------
 sys/ia64/ia64/mp_machdep.c |  5 +-
 sys/ia64/include/pcpu.h    |  2 -
 3 files changed, 55 insertions(+), 50 deletions(-)

diff --git a/sys/ia64/ia64/clock.c b/sys/ia64/ia64/clock.c
index 2e7f2d87972..33dbb2e3c1e 100644
--- a/sys/ia64/ia64/clock.c
+++ b/sys/ia64/ia64/clock.c
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 
 SYSCTL_NODE(_debug, OID_AUTO, clock, CTLFLAG_RW, 0, "clock statistics");
 
@@ -91,60 +92,63 @@ ia64_ih_clock(struct thread *td, u_int xiv, struct trapframe *tf)
 	int count;
 
 	PCPU_INC(md.stats.pcs_nclks);
-	intrcnt[INTRCNT_CLOCK]++;
 
-	itc = ia64_get_itc();
+	if (PCPU_GET(cpuid) == 0) {
+		/*
+		 * Clock processing on the BSP.
+		 */
+		intrcnt[INTRCNT_CLOCK]++;
 
-	adj = PCPU_GET(md.clockadj);
-	clk = PCPU_GET(md.clock);
+		itc = ia64_get_itc();
 
-	delta = itc - clk;
-	count = 0;
-	while (delta >= ia64_clock_reload) {
-		/* Only the BSP runs the real clock */
-		if (PCPU_GET(cpuid) == 0)
+		adj = PCPU_GET(md.clockadj);
+		clk = PCPU_GET(md.clock);
+
+		delta = itc - clk;
+		count = 0;
+		while (delta >= ia64_clock_reload) {
+#ifdef SMP
+			ipi_all_but_self(ia64_clock_xiv);
+#endif
 			hardclock(TRAPF_USERMODE(tf), TRAPF_PC(tf));
-		else
-			hardclock_cpu(TRAPF_USERMODE(tf));
+			if (profprocs != 0)
+				profclock(TRAPF_USERMODE(tf), TRAPF_PC(tf));
+			statclock(TRAPF_USERMODE(tf));
+			delta -= ia64_clock_reload;
+			clk += ia64_clock_reload;
+			if (adj != 0)
+				adjust_ticks++;
+			count++;
+		}
+		ia64_set_itm(ia64_get_itc() + ia64_clock_reload - adj);
+		ia64_srlz_d();
+		if (count > 0) {
+			adjust_lost += count - 1;
+			if (delta > (ia64_clock_reload >> 3)) {
+				if (adj == 0)
+					adjust_edges++;
+				adj = ia64_clock_reload >> 4;
+			} else
+				adj = 0;
+		} else {
+			adj = 0;
+			adjust_excess++;
+		}
+		PCPU_SET(md.clock, clk);
+		PCPU_SET(md.clockadj, adj);
+	} else {
+		/*
+		 * Clock processing on the BSP.
+		 */
+		hardclock_cpu(TRAPF_USERMODE(tf));
 		if (profprocs != 0)
 			profclock(TRAPF_USERMODE(tf), TRAPF_PC(tf));
 		statclock(TRAPF_USERMODE(tf));
-		delta -= ia64_clock_reload;
-		clk += ia64_clock_reload;
-		if (adj != 0)
-			adjust_ticks++;
-		count++;
 	}
-	ia64_set_itm(ia64_get_itc() + ia64_clock_reload - adj);
-	ia64_srlz_d();
-	if (count > 0) {
-		adjust_lost += count - 1;
-		if (delta > (ia64_clock_reload >> 3)) {
-			if (adj == 0)
-				adjust_edges++;
-			adj = ia64_clock_reload >> 4;
-		} else
-			adj = 0;
-	} else {
-		adj = 0;
-		adjust_excess++;
-	}
-	PCPU_SET(md.clock, clk);
-	PCPU_SET(md.clockadj, adj);
+
 	return (0);
 }
 
-void
-pcpu_initclock(void)
-{
-
-	PCPU_SET(md.clockadj, 0);
-	PCPU_SET(md.clock, ia64_get_itc());
-	ia64_set_itm(PCPU_GET(md.clock) + ia64_clock_reload);
-	ia64_set_itv(ia64_clock_xiv);
-	ia64_srlz_d();
-}
-
 /*
  * Start the real-time and statistics clocks. We use ar.itc and cr.itm
  * to implement a 1000hz clock.
@@ -154,7 +158,7 @@ cpu_initclocks()
 {
 	u_long itc_freq;
 
-	ia64_clock_xiv = ia64_xiv_alloc(PI_REALTIME, IA64_XIV_IRQ,
+	ia64_clock_xiv = ia64_xiv_alloc(PI_REALTIME, IA64_XIV_IPI,
 	    ia64_ih_clock);
 	if (ia64_clock_xiv == 0)
 		panic("No XIV for clock interrupts");
@@ -169,7 +173,11 @@ cpu_initclocks()
 	tc_init(&ia64_timecounter);
 #endif
 
-	pcpu_initclock();
+	PCPU_SET(md.clockadj, 0);
+	PCPU_SET(md.clock, ia64_get_itc());
+	ia64_set_itm(PCPU_GET(md.clock) + ia64_clock_reload);
+	ia64_set_itv(ia64_clock_xiv);
+	ia64_srlz_d();
 }
 
 void
diff --git a/sys/ia64/ia64/mp_machdep.c b/sys/ia64/ia64/mp_machdep.c
index 05a655d8aec..f8d9f6f0c1f 100644
--- a/sys/ia64/ia64/mp_machdep.c
+++ b/sys/ia64/ia64/mp_machdep.c
@@ -206,9 +206,8 @@ ia64_ap_startup(void)
 
 	CTR1(KTR_SMP, "SMP: cpu%d launched", PCPU_GET(cpuid));
 
-	/* kick off the clock on this AP */
-	pcpu_initclock();
-
+	/* Mask interval timer interrupts on APs. */
+	ia64_set_itv(0x10000);
 	ia64_set_tpr(0);
 	ia64_srlz_d();
 	enable_intr();
diff --git a/sys/ia64/include/pcpu.h b/sys/ia64/include/pcpu.h
index 9eb8efba017..3c6e6a762af 100644
--- a/sys/ia64/include/pcpu.h
+++ b/sys/ia64/include/pcpu.h
@@ -91,8 +91,6 @@ __curthread(void)
 #define	PCPU_PTR(member)	(&pcpup->pc_ ## member)
 #define	PCPU_SET(member,value)	(pcpup->pc_ ## member = (value))
 
-void pcpu_initclock(void);
-
 #endif	/* _KERNEL */
 
 #endif	/* !_MACHINE_PCPU_H_ */

From a787a4cbb12f632fedab26c1c71fccf9c399945d Mon Sep 17 00:00:00 2001
From: Maxim Konovalov 
Date: Fri, 26 Mar 2010 05:34:13 +0000
Subject: [PATCH 076/119] o Trim leading w/space.

PR:		docs/145030
Submitted by:	olgeni
MFC after:	1 week
---
 usr.sbin/sysinstall/sysinstall.8 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/usr.sbin/sysinstall/sysinstall.8 b/usr.sbin/sysinstall/sysinstall.8
index cdaec6dcc21..010b9eb45d2 100644
--- a/usr.sbin/sysinstall/sysinstall.8
+++ b/usr.sbin/sysinstall/sysinstall.8
@@ -541,7 +541,7 @@ Commit any rc.conf changes to disk.
 Preserve existing rc.conf parameters.
 This is useful if you have a post-install script which modifies rc.conf.
 .El
- .It installExpress
+.It installExpress
 Start an "express" installation, asking few questions of
 the user.
 .Pp

From 16d1ba4f624b4e81f038a020ffb20574815620d5 Mon Sep 17 00:00:00 2001
From: Maxim Konovalov 
Date: Fri, 26 Mar 2010 05:35:25 +0000
Subject: [PATCH 077/119] o Fix typo.

PR:		docs/145031
Submitted by:	olgeni
MFC after:	1 week
---
 sbin/setkey/setkey.8 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbin/setkey/setkey.8 b/sbin/setkey/setkey.8
index ffb911504f3..c66860f9656 100644
--- a/sbin/setkey/setkey.8
+++ b/sbin/setkey/setkey.8
@@ -674,7 +674,7 @@ add 10.0.11.41 10.0.11.33 esp 0x10001
 	-A hmac-md5 "authentication!!" ;
 
 .Ed
-Get the SA information assocaited with first example above:
+Get the SA information associated with first example above:
 .Bd -literal -offset
 get 3ffe:501:4819::1 3ffe:501:481d::1 ah 123456 ;
 

From bfd506a0244aa29490a6820ee82b3a90b5bb6e6a Mon Sep 17 00:00:00 2001
From: Neel Natu 
Date: Fri, 26 Mar 2010 07:15:27 +0000
Subject: [PATCH 078/119] Replace sb_store64()/sb_load64() with
 mips3_sd()/mips3_ld() respectively.

Obtained from NetBSD.

Suggested by: jmallett@
---
 sys/mips/include/cpufunc.h |  29 ++++++++++
 sys/mips/mips/support.S    | 108 +++++++++++++++++++++++++++++++++++++
 sys/mips/sibyte/sb_asm.S   |  50 -----------------
 sys/mips/sibyte/sb_scd.c   |  11 +++-
 4 files changed, 146 insertions(+), 52 deletions(-)

diff --git a/sys/mips/include/cpufunc.h b/sys/mips/include/cpufunc.h
index d4ca0f198d1..f9100eaeb32 100644
--- a/sys/mips/include/cpufunc.h
+++ b/sys/mips/include/cpufunc.h
@@ -283,6 +283,35 @@ breakpoint(void)
 	__asm __volatile ("break");
 }
 
+#if defined(__GNUC__) && !defined(__mips_o32)
+static inline uint64_t
+mips3_ld(const volatile uint64_t *va)
+{
+	uint64_t rv;
+
+#if defined(_LP64)
+	rv = *va;
+#else
+	__asm volatile("ld	%0,0(%1)" : "=d"(rv) : "r"(va));
+#endif
+
+	return (rv);
+}
+
+static inline void
+mips3_sd(volatile uint64_t *va, uint64_t v)
+{
+#if defined(_LP64)
+	*va = v;
+#else
+	__asm volatile("sd	%0,0(%1)" :: "r"(v), "r"(va));
+#endif
+}
+#else
+uint64_t mips3_ld(volatile uint64_t *va);
+void mips3_sd(volatile uint64_t *, uint64_t);
+#endif	/* __GNUC__ */
+
 #endif /* _KERNEL */
 
 #define	readb(va)	(*(volatile uint8_t *) (va))
diff --git a/sys/mips/mips/support.S b/sys/mips/mips/support.S
index 6282eb0339f..2aed3e613fd 100644
--- a/sys/mips/mips/support.S
+++ b/sys/mips/mips/support.S
@@ -50,6 +50,38 @@
  * $FreeBSD$
  */
 
+/*
+ * Copyright (c) 1997 Jonathan Stone (hereinafter referred to as the author)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Jonathan R. Stone for
+ *      the NetBSD Project.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
 /*
  *	Contains code that is the first executed at boot time plus
  *	assembly language support routines.
@@ -61,6 +93,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "assym.s"
 
@@ -1586,3 +1619,78 @@ LEAF(octeon_get_control)
         .set	mips0
 END(octeon_get_control)
 #endif
+
+LEAF(mips3_ld)
+	.set push
+	.set noreorder
+	.set mips64
+#if defined(__mips_o32)
+	mfc0	t0, MIPS_COP_0_STATUS		# turn off interrupts
+	and	t1, t0, ~(MIPS_SR_INT_IE)
+	mtc0	t1, MIPS_COP_0_STATUS
+	COP0_SYNC
+	nop
+	nop
+	nop
+
+	ld	v0, 0(a0)
+#if _BYTE_ORDER == _BIG_ENDIAN
+	dsll	v1, v0, 32
+	dsra	v1, v1, 32			# low word in v1
+	dsra	v0, v0, 32			# high word in v0
+#else
+	dsra	v1, v0, 32			# high word in v1
+	dsll	v0, v0, 32
+	dsra	v0, v0, 32			# low word in v0
+#endif
+
+	mtc0	t0, MIPS_COP_0_STATUS		# restore intr status.
+	COP0_SYNC
+	nop
+#else /* !__mips_o32 */
+	ld	v0, 0(a0)
+#endif /* !__mips_o32 */
+
+	jr	ra
+	nop
+	.set pop
+END(mips3_ld)
+
+LEAF(mips3_sd)
+	.set push
+	.set mips64
+	.set noreorder
+#if defined(__mips_o32)
+	mfc0	t0, MIPS_COP_0_STATUS		# turn off interrupts
+	and	t1, t0, ~(MIPS_SR_INT_IE)
+	mtc0	t1, MIPS_COP_0_STATUS
+	COP0_SYNC
+	nop
+	nop
+	nop
+
+	# NOTE: a1 is padding!
+
+#if _BYTE_ORDER == _BIG_ENDIAN
+	dsll	a2, a2, 32			# high word in a2
+	dsll	a3, a3, 32			# low word in a3
+	dsrl	a3, a3, 32
+#else
+	dsll	a2, a2, 32			# low word in a2
+	dsrl	a2, a2, 32
+	dsll	a3, a3, 32			# high word in a3
+#endif
+	or	a1, a2, a3
+	sd	a1, 0(a0)
+
+	mtc0	t0, MIPS_COP_0_STATUS		# restore intr status.
+	COP0_SYNC
+	nop
+#else /* !__mips_o32 */
+	sd	a1, 0(a0)
+#endif /* !__mips_o32 */
+
+	jr	ra
+	nop
+	.set pop
+END(mips3_sd)
diff --git a/sys/mips/sibyte/sb_asm.S b/sys/mips/sibyte/sb_asm.S
index 4baa5f39787..312d3a58535 100644
--- a/sys/mips/sibyte/sb_asm.S
+++ b/sys/mips/sibyte/sb_asm.S
@@ -28,61 +28,11 @@
 
 #include 
 #include 
-#include 
-
-/*
- * We compile a 32-bit kernel to run on the SB-1 processor which is a 64-bit
- * processor. It has some registers that must be accessed using 64-bit load
- * and store instructions.
- *
- * So we have to resort to assembly because the compiler does not emit the
- * 'ld' and 'sd' instructions since it thinks that it is compiling for a
- * 32-bit mips processor.
- */
 
 .set	mips64
 .set	noat
 .set	noreorder
 
-/*
- * Parameters:		uint32_t ptr
- * Return value: 	*(uint64_t *)ptr
- */
-LEAF(sb_load64)
-	ld      v1, 0(a0)	/* result = *(uint64_t *)ptr */
-	move	v0, v1
-#if _BYTE_ORDER == _BIG_ENDIAN
-	dsll32	v1, v1, 0
-	dsra32	v1, v1, 0	/* v1 = lower_uint32(result) */
-	jr	ra
-	dsra32	v0, v0, 0	/* v0 = upper_uint32(result) */
-#else
-	dsll32	v0, v0, 0
-	dsra32	v0, v0, 0	/* v0 = lower_uint32(result) */
-	jr	ra
-	dsra32	v1, v1, 0	/* v1 = upper_uint32(result) */
-#endif
-END(sb_load64)
-
-/*
- * Parameters:		uint32_t ptr, uint64_t val
- * Return value:	void
- */
-LEAF(sb_store64)
-#if _BYTE_ORDER == _BIG_ENDIAN
-	dsll32	a2, a2, 0	/* a2 = upper_uint32(val) */
-	dsll32	a3, a3, 0	/* a3 = lower_uint32(val) */
-	dsrl32	a3, a3, 0
-#else
-	dsll32	a3, a3, 0	/* a3 = upper_uint32(val) */
-	dsll32	a2, a2, 0	/* a2 = lower_uint32(val) */
-	dsrl32	a2, a2, 0
-#endif
-	or	t0, a2, a3
-	jr	ra
-	sd	t0, 0(a0)
-END(sb_store64)
-
 #ifdef SMP
 /*
  * This function must be implemented in assembly because it is called early
diff --git a/sys/mips/sibyte/sb_scd.c b/sys/mips/sibyte/sb_scd.c
index c8fec6978a9..bfaa8d471f0 100644
--- a/sys/mips/sibyte/sb_scd.c
+++ b/sys/mips/sibyte/sb_scd.c
@@ -38,8 +38,15 @@ __FBSDID("$FreeBSD$");
 
 #include "sb_scd.h"
 
-extern void	sb_store64(uint32_t addr, uint64_t val);
-extern uint64_t	sb_load64(uint32_t addr);
+/*
+ * We compile a 32-bit kernel to run on the SB-1 processor which is a 64-bit
+ * processor. It has some registers that must be accessed using 64-bit load
+ * and store instructions.
+ *
+ * We use the mips_ld() and mips_sd() functions to do this for us.
+ */
+#define	sb_store64(addr, val)	mips3_sd((uint64_t *)(addr), (val))
+#define	sb_load64(addr)		mips3_ld((uint64_t *)(addr))
 
 /*
  * System Control and Debug (SCD) unit on the Sibyte ZBbus.

From 90782c0a14b8e293013e21d4adb4c2e6d30f4358 Mon Sep 17 00:00:00 2001
From: Alexander Leidinger 
Date: Fri, 26 Mar 2010 08:42:11 +0000
Subject: [PATCH 079/119] Fix some problems which may lead to a panic:  - right
 order of src and dst in memcpy  - NULL out the clips after freeing to prevent
 an accident

Noticed by:	hselasky
---
 sys/compat/linux/linux_ioctl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sys/compat/linux/linux_ioctl.c b/sys/compat/linux/linux_ioctl.c
index c457d12a2e9..66009763404 100644
--- a/sys/compat/linux/linux_ioctl.c
+++ b/sys/compat/linux/linux_ioctl.c
@@ -2711,7 +2711,7 @@ linux_v4l_clip_copy(void *lvc, struct video_clip **ppvc)
 	/* XXX: If there can be no concurrency: s/M_NOWAIT/M_WAITOK/ */
 	if ((*ppvc = malloc(sizeof(**ppvc), M_LINUX, M_NOWAIT)) == NULL)
 		return (ENOMEM);    /* XXX: linux has no ENOMEM here */
-	memcpy(&vclip, *ppvc, sizeof(vclip));
+	memcpy(*ppvc, &vclip, sizeof(vclip));
 	(*ppvc)->next = NULL;
 	return (0);
 }
@@ -2726,6 +2726,8 @@ linux_v4l_cliplist_free(struct video_window *vw)
 		ppvc_next = &((*ppvc)->next);
 		free(*ppvc, M_LINUX);
 	}
+	vw->clips = NULL;
+
 	return (0);
 }
 

From 3fd1e05babc53a0e1ae8886bed845d52dc016255 Mon Sep 17 00:00:00 2001
From: Alexander Leidinger 
Date: Fri, 26 Mar 2010 08:47:07 +0000
Subject: [PATCH 080/119] Fix a typo in a comment.

---
 sys/conf/kmod.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/conf/kmod.mk b/sys/conf/kmod.mk
index 0f8b4ff22ec..2cd75097ba8 100644
--- a/sys/conf/kmod.mk
+++ b/sys/conf/kmod.mk
@@ -325,7 +325,7 @@ ${_src}:
 .endfor
 .endif
 
-# Repsect configuration-specific C flags.
+# Respect configuration-specific C flags.
 CFLAGS+=	${CONF_CFLAGS}
 
 MFILES?= dev/acpica/acpi_if.m dev/acpi_support/acpi_wmi_if.m \

From d542863e480906a79112bbf50f563227308cbcdc Mon Sep 17 00:00:00 2001
From: Alexander Motin 
Date: Fri, 26 Mar 2010 10:18:19 +0000
Subject: [PATCH 081/119] Use last 16 bytes of serial number in metadata
 instead of first ones, same as Intel MatrixRAID does.

PR:		kern/124064
---
 sys/dev/ata/ata-raid.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/sys/dev/ata/ata-raid.c b/sys/dev/ata/ata-raid.c
index a3b1e78a78b..98336786583 100644
--- a/sys/dev/ata/ata-raid.c
+++ b/sys/dev/ata/ata-raid.c
@@ -2568,8 +2568,15 @@ ata_raid_intel_read_meta(device_t dev, struct ar_softc **raidp)
 	if (meta->generation >= raid->generation) {
 	    for (disk = 0; disk < raid->total_disks; disk++) {
 		struct ata_device *atadev = device_get_softc(parent);
+		int len;
 
-		if (!strncmp(raid->disks[disk].serial, atadev->param.serial,
+		for (len = 0; len < sizeof(atadev->param.serial); len++) {
+		    if (atadev->param.serial[len] < 0x20)
+			break;
+		}
+		len = (len > sizeof(raid->disks[disk].serial)) ?
+		    len - sizeof(raid->disks[disk].serial) : 0;
+		if (!strncmp(raid->disks[disk].serial, atadev->param.serial + len,
 		    sizeof(raid->disks[disk].serial))) {
 		    raid->disks[disk].dev = parent;
 		    raid->disks[disk].flags |= (AR_DF_PRESENT | AR_DF_ONLINE);
@@ -2639,8 +2646,15 @@ ata_raid_intel_write_meta(struct ar_softc *rdp)
 		device_get_softc(device_get_parent(rdp->disks[disk].dev));
 	    struct ata_device *atadev =
 		device_get_softc(rdp->disks[disk].dev);
+	    int len;
 
-	    bcopy(atadev->param.serial, meta->disk[disk].serial,
+	    for (len = 0; len < sizeof(atadev->param.serial); len++) {
+		if (atadev->param.serial[len] < 0x20)
+		    break;
+	    }
+	    len = (len > sizeof(rdp->disks[disk].serial)) ?
+	        len - sizeof(rdp->disks[disk].serial) : 0;
+	    bcopy(atadev->param.serial + len, meta->disk[disk].serial,
 		  sizeof(rdp->disks[disk].serial));
 	    meta->disk[disk].sectors = rdp->disks[disk].sectors;
 	    meta->disk[disk].id = (ch->unit << 16) | atadev->unit;

From 2ac4d1f92fed996e4aeb80d89414c61adf587a62 Mon Sep 17 00:00:00 2001
From: Alexander Leidinger 
Date: Fri, 26 Mar 2010 11:02:01 +0000
Subject: [PATCH 082/119] - add some usb devices (scanner, printer, usb
 storage) - add quirks for the usb storage

Reviewed by:	hselasky
---
 sys/dev/usb/quirk/usb_quirk.c | 2 ++
 sys/dev/usb/usbdevs           | 7 +++++++
 2 files changed, 9 insertions(+)

diff --git a/sys/dev/usb/quirk/usb_quirk.c b/sys/dev/usb/quirk/usb_quirk.c
index aa89fdc6011..4090b5683b6 100644
--- a/sys/dev/usb/quirk/usb_quirk.c
+++ b/sys/dev/usb/quirk/usb_quirk.c
@@ -227,6 +227,7 @@ static struct usb_quirk_entry usb_quirks[USB_DEV_QUIRKS_MAX] = {
 	USB_QUIRK(IOMEGA, ZIP100, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
 	    UQ_MSC_FORCE_PROTO_SCSI,
 	    UQ_MSC_NO_TEST_UNIT_READY), /* XXX ZIP drives can also use ATAPI */
+	USB_QUIRK(JMICRON, JM20336, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
 	USB_QUIRK(JMICRON, JM20337, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
 	    UQ_MSC_FORCE_PROTO_SCSI,
 	    UQ_MSC_NO_SYNC_CACHE),
@@ -442,6 +443,7 @@ static struct usb_quirk_entry usb_quirks[USB_DEV_QUIRKS_MAX] = {
 	USB_QUIRK(ACTIONS, MP4, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_SYNC_CACHE),
 	USB_QUIRK(ASUS, GMSC, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
+	USB_QUIRK(UNKNOWN4, USBMEMSTICK, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
 };
 #undef USB_QUIRK_VP
 #undef USB_QUIRK
diff --git a/sys/dev/usb/usbdevs b/sys/dev/usb/usbdevs
index 69fbeafa2a3..f7352f5fc99 100644
--- a/sys/dev/usb/usbdevs
+++ b/sys/dev/usb/usbdevs
@@ -58,6 +58,7 @@ $FreeBSD$
 vendor UNKNOWN1		0x0053	Unknown vendor
 vendor UNKNOWN2		0x0105	Unknown vendor
 vendor EGALAX2		0x0123	eGalax, Inc.
+vendor UNKNOWN4		0x0204	Unknown vendor
 vendor HUMAX		0x02ad	HUMAX
 vendor LTS		0x0386	LTS
 vendor BWCT		0x03da	Bernd Walter Computer Technology
@@ -1098,6 +1099,7 @@ product BROADCOM BCM2033	0x2033	BCM2033 Bluetooth USB dongle
 
 /* Brother Industries products */
 product BROTHER HL1050		0x0002	HL-1050 laser printer
+product BROTHER MFC8600_9650	0x0100	MFC8600/9650 multifunction device
 
 /* Behavior Technology Computer products */
 product BTC BTC7932		0x6782	Keyboard with mouse port
@@ -1812,6 +1814,7 @@ product JABLOTRON PC60B		0x0001	PC-60B
 product JATON EDA		0x5704	Ethernet
 
 /* JMicron products */
+product JMICRON JM20336		0x2336	USB to SATA Bridge
 product JMICRON JM20337		0x2338	USB to ATA/ATAPI Bridge
 
 /* JVC products */
@@ -2127,6 +2130,7 @@ product MUSTEK 1200UB		0x0006	1200 UB scanner
 product MUSTEK 1200USBPLUS	0x0007	1200 USB Plus scanner
 product MUSTEK 1200CUPLUS	0x0008	1200 CU Plus scanner
 product MUSTEK BEARPAW1200F	0x0010	BearPaw 1200F scanner
+product MUSTEK BEARPAW2400TA	0x0218	BearPaw 2400TA scanner
 product MUSTEK BEARPAW1200TA	0x021e	BearPaw 1200TA scanner
 product MUSTEK 600USB		0x0873	600 USB scanner
 product MUSTEK MDC800		0xa800	MDC-800 digital camera
@@ -3023,6 +3027,9 @@ product UMEDIA AR5523_2_NF	0x3206	AR5523 (no firmware)
 /* Universal Access products */
 product UNIACCESS PANACHE	0x0101	Panache Surf USB ISDN Adapter
 
+/* Unknown vendors */
+product UNKNOWN4 USBMEMSTICK	0x6025	Flash Disk CBM
+
 /* U.S. Robotics products */
 product USR USR5423		0x0121	USR5423 WLAN
 

From 246b651054bbe057aac27918e07fc94d35e3190a Mon Sep 17 00:00:00 2001
From: Jaakko Heinonen 
Date: Fri, 26 Mar 2010 11:33:12 +0000
Subject: [PATCH 083/119] Support only LOOKUP operation for "/" in relookup()
 because lookup() can't succeed for CREATE, DELETE and RENAME.

Discussed with:	bde
---
 sys/kern/vfs_lookup.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c
index 6f10b49c418..5b6ccf6ff46 100644
--- a/sys/kern/vfs_lookup.c
+++ b/sys/kern/vfs_lookup.c
@@ -948,19 +948,17 @@ relookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp)
 #endif
 
 	/*
-	 * Check for degenerate name (e.g. / or "")
-	 * which is a way of talking about a directory,
-	 * e.g. like "/." or ".".
+	 * Check for "" which represents the root directory after slash
+	 * removal.
 	 */
 	if (cnp->cn_nameptr[0] == '\0') {
-		if (cnp->cn_nameiop != LOOKUP || wantparent) {
-			error = EISDIR;
-			goto bad;
-		}
-		if (dp->v_type != VDIR) {
-			error = ENOTDIR;
-			goto bad;
-		}
+		/*
+		 * Support only LOOKUP for "/" because lookup()
+		 * can't succeed for CREATE, DELETE and RENAME.
+		 */
+		KASSERT(cnp->cn_nameiop == LOOKUP, ("nameiop must be LOOKUP"));
+		KASSERT(dp->v_type == VDIR, ("dp is not a directory"));
+
 		if (!(cnp->cn_flags & LOCKLEAF))
 			VOP_UNLOCK(dp, 0);
 		*vpp = dp;

From 6cdf931c4698fc46feb3a5a78755e906ea5b54db Mon Sep 17 00:00:00 2001
From: Alexander Leidinger 
Date: Fri, 26 Mar 2010 11:43:15 +0000
Subject: [PATCH 084/119] Fix some bogus values in linprocfs.

Submitted by:	Petr Salinger 
Verified on:	GNU/kFreeBSD debian 8.0-1-686 (by submitter)
PR:		144584
---
 sys/compat/linprocfs/linprocfs.c | 68 +++++++++++++++++++++++++-------
 1 file changed, 54 insertions(+), 14 deletions(-)

diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c
index c095012e0d9..b493614c11d 100644
--- a/sys/compat/linprocfs/linprocfs.c
+++ b/sys/compat/linprocfs/linprocfs.c
@@ -110,13 +110,36 @@ __FBSDID("$FreeBSD$");
 /*
  * Various conversion macros
  */
+
+/* The LINUX_USER_HZ is assumed 100 for now */
+
+#if defined(__i386__) && defined(__GNUCLIKE_ASM)
+/* we need intermediate result as 64 bit, otherwise it overflows too early */
+#define DO64_MULDIV(v,m,d)       \
+({                              \
+   unsigned long rv0;           \
+   unsigned long rv1;           \
+   __asm__ __volatile__(        \
+                "mull %1\n\t"   \
+                "divl %2\n\t"   \
+                :"=a" (rv0), "=d" (rv1) \
+                :"r" (d), "0" (v), "1" (m) \
+                :"cc" ); \
+  rv0; \
+})
+
+#define T2J(x) DO64_MULDIV((x), 100UL, (stathz ? stathz : hz)) /* ticks to jiffies */
+#else
 #define T2J(x) (((x) * 100UL) / (stathz ? stathz : hz))	/* ticks to jiffies */
+#endif
 #define T2S(x) ((x) / (stathz ? stathz : hz))		/* ticks to seconds */
 #define B2K(x) ((x) >> 10)				/* bytes to kbytes */
 #define B2P(x) ((x) >> PAGE_SHIFT)			/* bytes to pages */
 #define P2B(x) ((x) << PAGE_SHIFT)			/* pages to bytes */
 #define P2K(x) ((x) << (PAGE_SHIFT - 10))		/* pages to kbytes */
 
+#define TV2J(x)	(((x)->tv_sec) * 100UL + ((x)->tv_usec) / 10000)
+
 /**
  * @brief Mapping of ki_stat in struct kinfo_proc to the linux state
  *
@@ -502,12 +525,24 @@ linprocfs_douptime(PFS_FILL_ARGS)
 {
 	long cp_time[CPUSTATES];
 	struct timeval tv;
+	int cnt, i;
 
 	getmicrouptime(&tv);
 	read_cpu_time(cp_time);
-	sbuf_printf(sb, "%lld.%02ld %ld.%02ld\n",
+
+	for (cnt = 0, i = 0; i <= mp_maxid; ++i)
+		if (!(CPU_ABSENT(i)))
+		    cnt++;
+
+	if (!cnt)
+	    cnt = 1;
+
+	i = ((cp_time[CP_IDLE])/cnt) % (stathz ? stathz : hz);
+	i = (i * 100) / (stathz ? stathz : hz);
+
+	sbuf_printf(sb, "%lld.%02ld %ld.%02d\n",
 	    (long long)tv.tv_sec, tv.tv_usec / 10000,
-	    T2S(cp_time[CP_IDLE]), T2J(cp_time[CP_IDLE]) % 100);
+	    T2S((cp_time[CP_IDLE]/cnt)), i);
 	return (0);
 }
 
@@ -613,9 +648,17 @@ linprocfs_doprocstat(PFS_FILL_ARGS)
 	struct kinfo_proc kp;
 	char state;
 	static int ratelimit = 0;
+	unsigned long startcode, startdata;
 
 	PROC_LOCK(p);
 	fill_kinfo_proc(p, &kp);
+	if (p->p_vmspace) {
+	   startcode = (unsigned long) p->p_vmspace->vm_taddr;
+	   startdata = (unsigned long) p->p_vmspace->vm_daddr;
+	} else {
+	   startcode = 0;
+	   startdata = 0;
+	};
 	sbuf_printf(sb, "%d", p->p_pid);
 #define PS_ADD(name, fmt, arg) sbuf_printf(sb, " " fmt, arg)
 	PS_ADD("comm",		"(%s)",	p->p_comm);
@@ -634,30 +677,27 @@ linprocfs_doprocstat(PFS_FILL_ARGS)
 	PS_ADD("pgrp",		"%d",	p->p_pgid);
 	PS_ADD("session",	"%d",	p->p_session->s_sid);
 	PROC_UNLOCK(p);
-	PS_ADD("tty",		"%d",	0); /* XXX */
+	PS_ADD("tty",		"%d",	kp.ki_tdev);
 	PS_ADD("tpgid",		"%d",	kp.ki_tpgid);
 	PS_ADD("flags",		"%u",	0); /* XXX */
 	PS_ADD("minflt",	"%lu",	kp.ki_rusage.ru_minflt);
 	PS_ADD("cminflt",	"%lu",	kp.ki_rusage_ch.ru_minflt);
 	PS_ADD("majflt",	"%lu",	kp.ki_rusage.ru_majflt);
 	PS_ADD("cmajflt",	"%lu",	kp.ki_rusage_ch.ru_majflt);
-	PS_ADD("utime",		"%ld",	T2J(tvtohz(&kp.ki_rusage.ru_utime)));
-	PS_ADD("stime",		"%ld",	T2J(tvtohz(&kp.ki_rusage.ru_stime)));
-	PS_ADD("cutime",	"%ld",	T2J(tvtohz(&kp.ki_rusage_ch.ru_utime)));
-	PS_ADD("cstime",	"%ld",	T2J(tvtohz(&kp.ki_rusage_ch.ru_stime)));
+	PS_ADD("utime",		"%ld",	TV2J((&kp.ki_rusage.ru_utime)));
+	PS_ADD("stime",		"%ld",	TV2J((&kp.ki_rusage.ru_stime)));
+	PS_ADD("cutime",	"%ld",	TV2J((&kp.ki_rusage_ch.ru_utime)));
+	PS_ADD("cstime",	"%ld",	TV2J((&kp.ki_rusage_ch.ru_stime)));
 	PS_ADD("priority",	"%d",	kp.ki_pri.pri_user);
 	PS_ADD("nice",		"%d",	kp.ki_nice); /* 19 (nicest) to -19 */
 	PS_ADD("0",		"%d",	0); /* removed field */
 	PS_ADD("itrealvalue",	"%d",	0); /* XXX */
-	/* XXX: starttime is not right, it is the _same_ for _every_ process.
-	   It should be the number of jiffies between system boot and process
-	   start. */
-	PS_ADD("starttime",	"%lu",	T2J(tvtohz(&kp.ki_start)));
+	PS_ADD("starttime",	"%lu",	TV2J((&kp.ki_start)) - TV2J((&boottime)));
 	PS_ADD("vsize",		"%ju",	P2K((uintmax_t)kp.ki_size));
 	PS_ADD("rss",		"%ju",	(uintmax_t)kp.ki_rssize);
 	PS_ADD("rlim",		"%lu",	kp.ki_rusage.ru_maxrss);
-	PS_ADD("startcode",	"%u",	(unsigned)0);
-	PS_ADD("endcode",	"%u",	0); /* XXX */
+	PS_ADD("startcode",	"%lu",	startcode);
+	PS_ADD("endcode",	"%lu",	startdata);
 	PS_ADD("startstack",	"%u",	0); /* XXX */
 	PS_ADD("kstkesp",	"%u",	0); /* XXX */
 	PS_ADD("kstkeip",	"%u",	0); /* XXX */
@@ -800,7 +840,7 @@ linprocfs_doprocstatus(PFS_FILL_ARGS)
 	 */
 	sbuf_printf(sb, "VmSize:\t%8ju kB\n",	B2K((uintmax_t)kp.ki_size));
 	sbuf_printf(sb, "VmLck:\t%8u kB\n",	P2K(0)); /* XXX */
-	sbuf_printf(sb, "VmRss:\t%8ju kB\n",	P2K((uintmax_t)kp.ki_rssize));
+	sbuf_printf(sb, "VmRSS:\t%8ju kB\n",	P2K((uintmax_t)kp.ki_rssize));
 	sbuf_printf(sb, "VmData:\t%8ju kB\n",	P2K((uintmax_t)kp.ki_dsize));
 	sbuf_printf(sb, "VmStk:\t%8ju kB\n",	P2K((uintmax_t)kp.ki_ssize));
 	sbuf_printf(sb, "VmExe:\t%8ju kB\n",	P2K((uintmax_t)kp.ki_tsize));

From 344523ac35ba466eccef48b878d48d2d7397d656 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= 
Date: Fri, 26 Mar 2010 12:59:15 +0000
Subject: [PATCH 085/119] Tighten my grip on pseudofs, procfs, linprocfs.

---
 MAINTAINERS | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index accd8fa3d7f..556dd1b1aee 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -57,9 +57,9 @@ libfetch	des	Advance notification requested.
 fetch		des	Advance notification requested.
 libpam		des	Pre-commit review requested.
 openssh		des	Pre-commit review requested.
-pseudofs	des	Advance notification requested.
-procfs		des	Advance notification requested.
-linprocfs	des	Advance notification requested.
+pseudofs	des	Pre-commit review requested.
+procfs		des	Pre-commit review requested.
+linprocfs	des	Pre-commit review requested.
 lpr		gad	Pre-commit review requested, particularly for
 			lpd/recvjob.c and lpd/printjob.c.
 newsyslog(8)	gad	Heads-up appreciated.  I'm going thru the PR's for it.

From 75109b48f4045ae3dd5d160d06125fe31645cf5c Mon Sep 17 00:00:00 2001
From: Fabien Thomas 
Date: Fri, 26 Mar 2010 14:29:57 +0000
Subject: [PATCH 086/119] Do not overflow the term in the case of multi-line
 display.

MFC after: 3days
---
 usr.sbin/pmcstat/pmcpl_calltree.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/usr.sbin/pmcstat/pmcpl_calltree.c b/usr.sbin/pmcstat/pmcpl_calltree.c
index 404653ebd7c..aac7913c92b 100644
--- a/usr.sbin/pmcstat/pmcpl_calltree.c
+++ b/usr.sbin/pmcstat/pmcpl_calltree.c
@@ -366,7 +366,7 @@ pmcpl_ct_node_cleartag(void)
 
 static int
 pmcpl_ct_node_dumptop(int pmcin, struct pmcpl_ct_node *ct,
-    struct pmcpl_ct_sample *rsamples, int x, int *y)
+    struct pmcpl_ct_sample *rsamples, int x, int *y, int maxy)
 {
 	int i;
 
@@ -387,7 +387,7 @@ pmcpl_ct_node_dumptop(int pmcin, struct pmcpl_ct_node *ct,
 	if (ct->pct_narc == 0) {
 		pmcpl_ct_topscreen[x+1][*y] = NULL;
 		if (*y >= PMCPL_CT_MAXLINE ||
-		    *y >= pmcstat_displayheight)
+		    *y >= maxy)
 			return 1;
 		*y = *y + 1;
 		for (i=0; i < x; i++)
@@ -407,7 +407,7 @@ pmcpl_ct_node_dumptop(int pmcin, struct pmcpl_ct_node *ct,
 		    &ct->pct_arc[i].pcta_samples) > pmcstat_threshold) {
 			if (pmcpl_ct_node_dumptop(pmcin,
 			        ct->pct_arc[i].pcta_child,
-			        rsamples, x+1, y))
+			        rsamples, x+1, y, maxy))
 				return 1;
 		}
 	}
@@ -472,6 +472,9 @@ pmcpl_ct_node_printtop(struct pmcpl_ct_sample *rsamples, int pmcin, int maxy)
 			/* Check for line wrap. */
 			width += ns_len + is_len + vs_len + 1;
 			if (width >= pmcstat_displaywidth) {
+				maxy--;
+				if (y >= maxy)
+					break;
 				PMCSTAT_PRINTW("\n%*s", indentwidth, space);
 				width = indentwidth + ns_len + is_len + vs_len;
 			}
@@ -515,7 +518,7 @@ pmcpl_ct_topdisplay(void)
 		for (i = 0; i < pmcpl_ct_root->pct_narc; i++) {
 			if (pmcpl_ct_node_dumptop(pmcin,
 			        pmcpl_ct_root->pct_arc[i].pcta_child,
-			        &rsamples, x, &y)) {
+			        &rsamples, x, &y, pmcstat_displayheight - 2)) {
 				break;
 			}
 		}

From 662cf719689e01e222eb7cb576e2948ae42678a5 Mon Sep 17 00:00:00 2001
From: Fabien Thomas 
Date: Fri, 26 Mar 2010 14:35:48 +0000
Subject: [PATCH 087/119] Handling SIGPIPE will cause deadlock/crash. Return an
 error immediatly in case of hard shutdown.

MFC after: 3days
---
 sys/dev/hwpmc/hwpmc_logging.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/sys/dev/hwpmc/hwpmc_logging.c b/sys/dev/hwpmc/hwpmc_logging.c
index 055433da4b3..633c6f953b6 100644
--- a/sys/dev/hwpmc/hwpmc_logging.c
+++ b/sys/dev/hwpmc/hwpmc_logging.c
@@ -298,7 +298,6 @@ pmclog_loop(void *arg)
 
 		mtx_unlock(&pmc_kthread_mtx);
 
-sigpipe_retry:
 		/* process the request */
 		PMCDBG(LOG,WRI,2, "po=%p base=%p ptr=%p", po,
 		    lb->plb_base, lb->plb_ptr);
@@ -322,9 +321,6 @@ sigpipe_retry:
 
 		if (error) {
 			/* XXX some errors are recoverable */
-			if (error == EPIPE)
-				goto sigpipe_retry;
-
 			/* send a SIGIO to the owner and exit */
 			PROC_LOCK(p);
 			psignal(p, SIGIO);

From 2e2d757e51acf95e07ef74080e7695cdb2fdc2d6 Mon Sep 17 00:00:00 2001
From: Alexander Leidinger 
Date: Fri, 26 Mar 2010 14:36:16 +0000
Subject: [PATCH 088/119] Revert r205683 to resolve some code quality issues
 which do not affect the build or use of linprocfs, before committing the
 reworked patch again.

Requested by:	des
---
 sys/compat/linprocfs/linprocfs.c | 68 +++++++-------------------------
 1 file changed, 14 insertions(+), 54 deletions(-)

diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c
index b493614c11d..c095012e0d9 100644
--- a/sys/compat/linprocfs/linprocfs.c
+++ b/sys/compat/linprocfs/linprocfs.c
@@ -110,36 +110,13 @@ __FBSDID("$FreeBSD$");
 /*
  * Various conversion macros
  */
-
-/* The LINUX_USER_HZ is assumed 100 for now */
-
-#if defined(__i386__) && defined(__GNUCLIKE_ASM)
-/* we need intermediate result as 64 bit, otherwise it overflows too early */
-#define DO64_MULDIV(v,m,d)       \
-({                              \
-   unsigned long rv0;           \
-   unsigned long rv1;           \
-   __asm__ __volatile__(        \
-                "mull %1\n\t"   \
-                "divl %2\n\t"   \
-                :"=a" (rv0), "=d" (rv1) \
-                :"r" (d), "0" (v), "1" (m) \
-                :"cc" ); \
-  rv0; \
-})
-
-#define T2J(x) DO64_MULDIV((x), 100UL, (stathz ? stathz : hz)) /* ticks to jiffies */
-#else
 #define T2J(x) (((x) * 100UL) / (stathz ? stathz : hz))	/* ticks to jiffies */
-#endif
 #define T2S(x) ((x) / (stathz ? stathz : hz))		/* ticks to seconds */
 #define B2K(x) ((x) >> 10)				/* bytes to kbytes */
 #define B2P(x) ((x) >> PAGE_SHIFT)			/* bytes to pages */
 #define P2B(x) ((x) << PAGE_SHIFT)			/* pages to bytes */
 #define P2K(x) ((x) << (PAGE_SHIFT - 10))		/* pages to kbytes */
 
-#define TV2J(x)	(((x)->tv_sec) * 100UL + ((x)->tv_usec) / 10000)
-
 /**
  * @brief Mapping of ki_stat in struct kinfo_proc to the linux state
  *
@@ -525,24 +502,12 @@ linprocfs_douptime(PFS_FILL_ARGS)
 {
 	long cp_time[CPUSTATES];
 	struct timeval tv;
-	int cnt, i;
 
 	getmicrouptime(&tv);
 	read_cpu_time(cp_time);
-
-	for (cnt = 0, i = 0; i <= mp_maxid; ++i)
-		if (!(CPU_ABSENT(i)))
-		    cnt++;
-
-	if (!cnt)
-	    cnt = 1;
-
-	i = ((cp_time[CP_IDLE])/cnt) % (stathz ? stathz : hz);
-	i = (i * 100) / (stathz ? stathz : hz);
-
-	sbuf_printf(sb, "%lld.%02ld %ld.%02d\n",
+	sbuf_printf(sb, "%lld.%02ld %ld.%02ld\n",
 	    (long long)tv.tv_sec, tv.tv_usec / 10000,
-	    T2S((cp_time[CP_IDLE]/cnt)), i);
+	    T2S(cp_time[CP_IDLE]), T2J(cp_time[CP_IDLE]) % 100);
 	return (0);
 }
 
@@ -648,17 +613,9 @@ linprocfs_doprocstat(PFS_FILL_ARGS)
 	struct kinfo_proc kp;
 	char state;
 	static int ratelimit = 0;
-	unsigned long startcode, startdata;
 
 	PROC_LOCK(p);
 	fill_kinfo_proc(p, &kp);
-	if (p->p_vmspace) {
-	   startcode = (unsigned long) p->p_vmspace->vm_taddr;
-	   startdata = (unsigned long) p->p_vmspace->vm_daddr;
-	} else {
-	   startcode = 0;
-	   startdata = 0;
-	};
 	sbuf_printf(sb, "%d", p->p_pid);
 #define PS_ADD(name, fmt, arg) sbuf_printf(sb, " " fmt, arg)
 	PS_ADD("comm",		"(%s)",	p->p_comm);
@@ -677,27 +634,30 @@ linprocfs_doprocstat(PFS_FILL_ARGS)
 	PS_ADD("pgrp",		"%d",	p->p_pgid);
 	PS_ADD("session",	"%d",	p->p_session->s_sid);
 	PROC_UNLOCK(p);
-	PS_ADD("tty",		"%d",	kp.ki_tdev);
+	PS_ADD("tty",		"%d",	0); /* XXX */
 	PS_ADD("tpgid",		"%d",	kp.ki_tpgid);
 	PS_ADD("flags",		"%u",	0); /* XXX */
 	PS_ADD("minflt",	"%lu",	kp.ki_rusage.ru_minflt);
 	PS_ADD("cminflt",	"%lu",	kp.ki_rusage_ch.ru_minflt);
 	PS_ADD("majflt",	"%lu",	kp.ki_rusage.ru_majflt);
 	PS_ADD("cmajflt",	"%lu",	kp.ki_rusage_ch.ru_majflt);
-	PS_ADD("utime",		"%ld",	TV2J((&kp.ki_rusage.ru_utime)));
-	PS_ADD("stime",		"%ld",	TV2J((&kp.ki_rusage.ru_stime)));
-	PS_ADD("cutime",	"%ld",	TV2J((&kp.ki_rusage_ch.ru_utime)));
-	PS_ADD("cstime",	"%ld",	TV2J((&kp.ki_rusage_ch.ru_stime)));
+	PS_ADD("utime",		"%ld",	T2J(tvtohz(&kp.ki_rusage.ru_utime)));
+	PS_ADD("stime",		"%ld",	T2J(tvtohz(&kp.ki_rusage.ru_stime)));
+	PS_ADD("cutime",	"%ld",	T2J(tvtohz(&kp.ki_rusage_ch.ru_utime)));
+	PS_ADD("cstime",	"%ld",	T2J(tvtohz(&kp.ki_rusage_ch.ru_stime)));
 	PS_ADD("priority",	"%d",	kp.ki_pri.pri_user);
 	PS_ADD("nice",		"%d",	kp.ki_nice); /* 19 (nicest) to -19 */
 	PS_ADD("0",		"%d",	0); /* removed field */
 	PS_ADD("itrealvalue",	"%d",	0); /* XXX */
-	PS_ADD("starttime",	"%lu",	TV2J((&kp.ki_start)) - TV2J((&boottime)));
+	/* XXX: starttime is not right, it is the _same_ for _every_ process.
+	   It should be the number of jiffies between system boot and process
+	   start. */
+	PS_ADD("starttime",	"%lu",	T2J(tvtohz(&kp.ki_start)));
 	PS_ADD("vsize",		"%ju",	P2K((uintmax_t)kp.ki_size));
 	PS_ADD("rss",		"%ju",	(uintmax_t)kp.ki_rssize);
 	PS_ADD("rlim",		"%lu",	kp.ki_rusage.ru_maxrss);
-	PS_ADD("startcode",	"%lu",	startcode);
-	PS_ADD("endcode",	"%lu",	startdata);
+	PS_ADD("startcode",	"%u",	(unsigned)0);
+	PS_ADD("endcode",	"%u",	0); /* XXX */
 	PS_ADD("startstack",	"%u",	0); /* XXX */
 	PS_ADD("kstkesp",	"%u",	0); /* XXX */
 	PS_ADD("kstkeip",	"%u",	0); /* XXX */
@@ -840,7 +800,7 @@ linprocfs_doprocstatus(PFS_FILL_ARGS)
 	 */
 	sbuf_printf(sb, "VmSize:\t%8ju kB\n",	B2K((uintmax_t)kp.ki_size));
 	sbuf_printf(sb, "VmLck:\t%8u kB\n",	P2K(0)); /* XXX */
-	sbuf_printf(sb, "VmRSS:\t%8ju kB\n",	P2K((uintmax_t)kp.ki_rssize));
+	sbuf_printf(sb, "VmRss:\t%8ju kB\n",	P2K((uintmax_t)kp.ki_rssize));
 	sbuf_printf(sb, "VmData:\t%8ju kB\n",	P2K((uintmax_t)kp.ki_dsize));
 	sbuf_printf(sb, "VmStk:\t%8ju kB\n",	P2K((uintmax_t)kp.ki_ssize));
 	sbuf_printf(sb, "VmExe:\t%8ju kB\n",	P2K((uintmax_t)kp.ki_tsize));

From 670508b16af6059f2e0caf467f67751b2a2b21be Mon Sep 17 00:00:00 2001
From: Matt Jacob 
Date: Fri, 26 Mar 2010 15:13:31 +0000
Subject: [PATCH 089/119] Clean up some printing stuff so that we can have a
 bit finer control on debug output. Add a new platform function requirement to
 allow for printing based upon the ITL nexus instead of the isp unit plus
 channel, target and lun. This allows some printouts and error messages from
 the core code to appear in the same format as the platform's subsystem (in
 FreeBSD's case, CAM path).

MFC after:	1 week
---
 sys/dev/isp/isp.c         | 221 +++++++++++++-------------------------
 sys/dev/isp/isp_freebsd.c |  14 +++
 sys/dev/isp/isp_freebsd.h |   5 +-
 sys/dev/isp/ispvar.h      |  10 +-
 4 files changed, 100 insertions(+), 150 deletions(-)

diff --git a/sys/dev/isp/isp.c b/sys/dev/isp/isp.c
index 65e5d864986..a03573a6587 100644
--- a/sys/dev/isp/isp.c
+++ b/sys/dev/isp/isp.c
@@ -74,14 +74,9 @@ __FBSDID("$FreeBSD$");
  */
 static const char fconf[] = "Chan %d PortDB[%d] changed:\n current =(0x%x@0x%06x 0x%08x%08x 0x%08x%08x)\n database=(0x%x@0x%06x 0x%08x%08x 0x%08x%08x)";
 static const char notresp[] = "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
-static const char xact1[] = "HBA attempted queued transaction with disconnect not set for %d.%d.%d";
-static const char xact2[] = "HBA attempted queued transaction to target routine %d on target %d bus %d";
-static const char xact3[] = "HBA attempted queued cmd for %d.%d.%d when queueing disabled";
-static const char pskip[] = "SCSI phase skipped for target %d.%d.%d";
 static const char topology[] = "Chan %d WWPN 0x%08x%08x PortID 0x%06x N-Port Handle %d, Connection '%s'";
-static const char finmsg[] = "%d.%d.%d: FIN dl%d resid %ld STS 0x%x SKEY %c XS_ERR=0x%x";
 static const char sc4[] = "NVRAM";
-static const char bun[] = "bad underrun for %d.%d (count %d, resid %d, status %s)";
+static const char bun[] = "bad underrun (count %d, resid %d, status %s)";
 static const char lipd[] = "Chan %d LIP destroyed %d active commands";
 static const char sacq[] = "unable to acquire scratch area";
 
@@ -107,6 +102,7 @@ static const uint8_t alpa_map[] = {
 /*
  * Local function prototypes.
  */
+static void isp_prt_endcmd(ispsoftc_t *, XS_T *);
 static int isp_parse_async(ispsoftc_t *, uint16_t);
 static int isp_parse_async_fc(ispsoftc_t *, uint16_t);
 static int isp_handle_other_response(ispsoftc_t *, int, isphdr_t *, uint32_t *);
@@ -1431,10 +1427,8 @@ isp_scsi_channel_init(ispsoftc_t *isp, int chan)
 			    (sdp->isp_devparam[tgt].goal_offset << 8) |
 			    (sdp->isp_devparam[tgt].goal_period);
 		}
-		isp_prt(isp, ISP_LOGDEBUG0,
-		    "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
-		    chan, tgt, mbs.param[2], mbs.param[3] >> 8,
-		    mbs.param[3] & 0xff);
+		isp_prt(isp, ISP_LOGDEBUG0, "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
+		    chan, tgt, mbs.param[2], mbs.param[3] >> 8, mbs.param[3] & 0xff);
 		isp_mboxcmd(isp, &mbs);
 		if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
 			sdf = DPARM_SAFE_DFLT;
@@ -1705,8 +1699,7 @@ isp_fibre_init(ispsoftc_t *isp)
 		isp_prt(isp, ISP_LOGERR, sacq);
 		return;
 	}
-	isp_prt(isp, ISP_LOGDEBUG0,
-	    "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
+	isp_prt(isp, ISP_LOGDEBUG0, "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
 	    icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
 
 	isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
@@ -4435,7 +4428,7 @@ isp_start(XS_T *xs)
 		 */
 		return (dmaresult);
 	}
-	isp_prt(isp, ISP_LOGDEBUG0, "START cmd for %d.%d.%d cmd 0x%x datalen %ld", XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), XS_CDBP(xs)[0], (long) XS_XFRLEN(xs));
+	isp_xs_prt(isp, xs, ISP_LOGDEBUG0, "START cmd cdb[0]=0x%x datalen %ld", XS_CDBP(xs)[0], (long) XS_XFRLEN(xs));
 	isp->isp_nactive++;
 	return (CMD_QUEUED);
 }
@@ -5248,7 +5241,7 @@ again:
 				} else {
 					ptr = rnames[resp[FCP_RSPNS_CODE_OFFSET]];
 				}
-				isp_prt(isp, ISP_LOGWARN, "%d.%d.%d FCP RESPONSE, LENGTH %u: %s CDB0=0x%02x", XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), rlen, ptr, XS_CDBP(xs)[0] & 0xff);
+				isp_xs_prt(isp, xs, ISP_LOGWARN, "FCP RESPONSE, LENGTH %u: %s CDB0=0x%02x", rlen, ptr, XS_CDBP(xs)[0] & 0xff);
 				if (resp[FCP_RSPNS_CODE_OFFSET] != 0) {
 					XS_SETERR(xs, HBA_BOTCH);
 				}
@@ -5325,25 +5318,9 @@ again:
 		isp_destroy_handle(isp, sp->req_handle);
 
 		if (((isp->isp_dblev & (ISP_LOGDEBUG1|ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
-		    ((isp->isp_dblev & ISP_LOGDEBUG0) && ((!XS_NOERR(xs)) ||
-		    (*XS_STSP(xs) != SCSI_GOOD)))) {
-			char skey;
-			if (req_state_flags & RQSF_GOT_SENSE) {
-				skey = XS_SNSKEY(xs) & 0xf;
-				if (skey < 10)
-					skey += '0';
-				else
-					skey += 'a' - 10;
-			} else if (*XS_STSP(xs) == SCSI_CHECK) {
-				skey = '?';
-			} else {
-				skey = '.';
-			}
-			isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
-			    XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), (long) XS_GET_RESID(xs),
-			    *XS_STSP(xs), skey, XS_ERR(xs));
+		    ((isp->isp_dblev & (ISP_LOGDEBUG0|ISP_LOG_CWARN) && ((!XS_NOERR(xs)) || (*XS_STSP(xs) != SCSI_GOOD))))) {
+			isp_prt_endcmd(isp, xs);
 		}
-
 		if (isp->isp_nactive > 0) {
 		    isp->isp_nactive--;
 		}
@@ -5393,6 +5370,25 @@ out:
  * Support routines.
  */
 
+static void
+isp_prt_endcmd(ispsoftc_t *isp, XS_T *xs)
+{
+	char cdbstr[16 * 5 + 1];
+	int i, lim;
+
+	lim = XS_CDBLEN(xs) > 16? 16 : XS_CDBLEN(xs);
+	ISP_SNPRINTF(cdbstr, sizeof (cdbstr), "0x%02x ", XS_CDBP(xs)[0]);
+	for (i = 1; i < lim; i++) {
+		ISP_SNPRINTF(cdbstr, sizeof (cdbstr), "%s0x%02x ", cdbstr, XS_CDBP(xs)[i]);
+	}
+	if (XS_SENSE_VALID(xs)) {
+		isp_xs_prt(isp, xs, ISP_LOGALL, "FIN dl%d resid %ld CDB=%s KEY/ASC/ASCQ=0x%02x/0x%02x/0x%02x",
+		    XS_XFRLEN(xs), (long) XS_GET_RESID(xs), cdbstr, XS_SNSKEY(xs), XS_SNSASC(xs), XS_SNSASCQ(xs));
+	} else {
+		isp_xs_prt(isp, xs, ISP_LOGALL, "FIN dl%d resid %ld CDB=%s STS 0x%x XS_ERR=0x%x", XS_XFRLEN(xs), (long) XS_GET_RESID(xs), cdbstr, *XS_STSP(xs), XS_ERR(xs));
+	}
+}
+
 /*
  * Parse an ASYNC mailbox complete
  *
@@ -5937,8 +5933,7 @@ isp_parse_async_fc(ispsoftc_t *isp, uint16_t mbox)
  */
 
 static int
-isp_handle_other_response(ispsoftc_t *isp, int type,
-    isphdr_t *hp, uint32_t *optrp)
+isp_handle_other_response(ispsoftc_t *isp, int type, isphdr_t *hp, uint32_t *optrp)
 {
 	switch (type) {
 	case RQSTYPE_STATUS_CONT:
@@ -6010,24 +6005,18 @@ isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
 
 	case RQCS_INCOMPLETE:
 		if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
-			isp_prt(isp, ISP_LOGDEBUG1,
-			    "Selection Timeout for %d.%d.%d",
-			    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+			isp_xs_prt(isp, xs, ISP_LOGDEBUG1, "Selection Timeout");
 			if (XS_NOERR(xs)) {
 				XS_SETERR(xs, HBA_SELTIMEOUT);
 				*rp = XS_XFRLEN(xs);
 			}
 			return;
 		}
-		isp_prt(isp, ISP_LOGERR,
-		    "command incomplete for %d.%d.%d, state 0x%x",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
-		    sp->req_state_flags);
+		isp_xs_prt(isp, xs, ISP_LOGERR, "Command Incomplete, state 0x%x", sp->req_state_flags);
 		break;
 
 	case RQCS_DMA_ERROR:
-		isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "DMA Error");
 		*rp = XS_XFRLEN(xs);
 		break;
 
@@ -6081,18 +6070,14 @@ isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
 		if (sp->req_status_flags & RQSTF_NEGOTIATION) {
 			ISP_SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
 		}
-		isp_prt(isp, ISP_LOGERR, "%s", buf);
-		isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d:\n%s",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), buf);
+		isp_xs_prt(isp, xs,  ISP_LOGERR, "Transport Error: %s", buf);
 		*rp = XS_XFRLEN(xs);
 		break;
 	}
 	case RQCS_RESET_OCCURRED:
 	{
 		int chan;
-		isp_prt(isp, ISP_LOGWARN,
-		    "bus reset destroyed command for %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGWARN, "Bus Reset destroyed command");
 		for (chan = 0; chan < isp->isp_nchan; chan++) {
 			FCPARAM(isp, chan)->sendmarker = 1;
 		}
@@ -6103,8 +6088,7 @@ isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
 		return;
 	}
 	case RQCS_ABORTED:
-		isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "Command Aborted");
 		ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
 		if (XS_NOERR(xs)) {
 			XS_SETERR(xs, HBA_ABORTED);
@@ -6112,8 +6096,7 @@ isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
 		return;
 
 	case RQCS_TIMEOUT:
-		isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGWARN, "Command timed out");
 		/*
 	 	 * XXX: Check to see if we logged out of the device.
 		 */
@@ -6124,83 +6107,62 @@ isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
 
 	case RQCS_DATA_OVERRUN:
 		XS_SET_RESID(xs, sp->req_resid);
-		isp_prt(isp, ISP_LOGERR, "data overrun (%ld) for command on %d.%d.%d",
-		    (long) XS_GET_RESID(xs), XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "data overrun (%ld)", (long) XS_GET_RESID(xs));
 		if (XS_NOERR(xs)) {
 			XS_SETERR(xs, HBA_DATAOVR);
 		}
 		return;
 
 	case RQCS_COMMAND_OVERRUN:
-		isp_prt(isp, ISP_LOGERR,
-		    "command overrun for command on %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "command overrun");
 		break;
 
 	case RQCS_STATUS_OVERRUN:
-		isp_prt(isp, ISP_LOGERR,
-		    "status overrun for command on %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "status overrun");
 		break;
 
 	case RQCS_BAD_MESSAGE:
-		isp_prt(isp, ISP_LOGERR,
-		    "msg not COMMAND COMPLETE after status %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "msg not COMMAND COMPLETE after status");
 		break;
 
 	case RQCS_NO_MESSAGE_OUT:
-		isp_prt(isp, ISP_LOGERR,
-		    "No MESSAGE OUT phase after selection on %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "No MESSAGE OUT phase after selection");
 		break;
 
 	case RQCS_EXT_ID_FAILED:
-		isp_prt(isp, ISP_LOGERR, "EXTENDED IDENTIFY failed %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "EXTENDED IDENTIFY failed");
 		break;
 
 	case RQCS_IDE_MSG_FAILED:
-		isp_prt(isp, ISP_LOGERR,
-		    "INITIATOR DETECTED ERROR rejected by %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "INITIATOR DETECTED ERROR rejected");
 		break;
 
 	case RQCS_ABORT_MSG_FAILED:
-		isp_prt(isp, ISP_LOGERR, "ABORT OPERATION rejected by %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "ABORT OPERATION rejected");
 		break;
 
 	case RQCS_REJECT_MSG_FAILED:
-		isp_prt(isp, ISP_LOGERR, "MESSAGE REJECT rejected by %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "MESSAGE REJECT rejected");
 		break;
 
 	case RQCS_NOP_MSG_FAILED:
-		isp_prt(isp, ISP_LOGERR, "NOP rejected by %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "NOP rejected");
 		break;
 
 	case RQCS_PARITY_ERROR_MSG_FAILED:
-		isp_prt(isp, ISP_LOGERR,
-		    "MESSAGE PARITY ERROR rejected by %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "MESSAGE PARITY ERROR rejected");
 		break;
 
 	case RQCS_DEVICE_RESET_MSG_FAILED:
-		isp_prt(isp, ISP_LOGWARN,
-		    "BUS DEVICE RESET rejected by %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGWARN, "BUS DEVICE RESET rejected");
 		break;
 
 	case RQCS_ID_MSG_FAILED:
-		isp_prt(isp, ISP_LOGERR, "IDENTIFY rejected by %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "IDENTIFY rejected");
 		break;
 
 	case RQCS_UNEXP_BUS_FREE:
-		isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "Unexpected Bus Free");
 		break;
 
 	case RQCS_DATA_UNDERRUN:
@@ -6208,9 +6170,7 @@ isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
 		if (IS_FC(isp)) {
 			int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
 			if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
-				isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
-				    XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
-				    (ru_marked)? "marked" : "not marked");
+				isp_xs_prt(isp, xs, ISP_LOGWARN, bun, XS_XFRLEN(xs), sp->req_resid, (ru_marked)? "marked" : "not marked");
 				if (XS_NOERR(xs)) {
 					XS_SETERR(xs, HBA_BOTCH);
 				}
@@ -6225,18 +6185,15 @@ isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
 	}
 
 	case RQCS_XACT_ERR1:
-		isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
-		    XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "HBA attempted queued transaction with disconnect not set");
 		break;
 
 	case RQCS_XACT_ERR2:
-		isp_prt(isp, ISP_LOGERR, xact2,
-		    XS_LUN(xs), XS_TGT(xs), XS_CHANNEL(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "HBA attempted queued transaction to target routine %d", XS_LUN(xs));
 		break;
 
 	case RQCS_XACT_ERR3:
-		isp_prt(isp, ISP_LOGERR, xact3,
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "HBA attempted queued cmd when queueing disabled");
 		break;
 
 	case RQCS_BAD_ENTRY:
@@ -6244,9 +6201,7 @@ isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
 		break;
 
 	case RQCS_QUEUE_FULL:
-		isp_prt(isp, ISP_LOGDEBUG0,
-		    "internal queues full for %d.%d.%d status 0x%x",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), *XS_STSP(xs));
+		isp_xs_prt(isp, xs, ISP_LOGDEBUG0, "internal queues full status 0x%x", *XS_STSP(xs));
 
 		/*
 		 * If QFULL or some other status byte is set, then this
@@ -6270,23 +6225,18 @@ isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
 		return;
 
 	case RQCS_PHASE_SKIPPED:
-		isp_prt(isp, ISP_LOGERR, pskip, XS_CHANNEL(xs),
-		    XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "SCSI phase skipped");
 		break;
 
 	case RQCS_ARQS_FAILED:
-		isp_prt(isp, ISP_LOGERR,
-		    "Auto Request Sense failed for %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "Auto Request Sense Failed");
 		if (XS_NOERR(xs)) {
 			XS_SETERR(xs, HBA_ARQFAIL);
 		}
 		return;
 
 	case RQCS_WIDE_FAILED:
-		isp_prt(isp, ISP_LOGERR,
-		    "Wide Negotiation failed for %d.%d.%d",
-		    XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "Wide Negotiation Failed");
 		if (IS_SCSI(isp)) {
 			sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
 			sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
@@ -6299,9 +6249,7 @@ isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
 		return;
 
 	case RQCS_SYNCXFER_FAILED:
-		isp_prt(isp, ISP_LOGERR,
-		    "SDTR Message failed for target %d.%d.%d",
-		    XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "SDTR Message Failed");
 		if (IS_SCSI(isp)) {
 			sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
 			sdp += XS_CHANNEL(xs);
@@ -6312,9 +6260,7 @@ isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
 		break;
 
 	case RQCS_LVD_BUSERR:
-		isp_prt(isp, ISP_LOGERR,
-		    "Bad LVD condition while talking to %d.%d.%d",
-		    XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "Bad LVD condition");
 		break;
 
 	case RQCS_PORT_UNAVAILABLE:
@@ -6384,8 +6330,7 @@ isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
 }
 
 static void
-isp_parse_status_24xx(ispsoftc_t *isp, isp24xx_statusreq_t *sp,
-    XS_T *xs, long *rp)
+isp_parse_status_24xx(ispsoftc_t *isp, isp24xx_statusreq_t *sp, XS_T *xs, long *rp)
 {
 	int ru_marked, sv_marked;
 	int chan = XS_CHANNEL(xs);
@@ -6398,19 +6343,15 @@ isp_parse_status_24xx(ispsoftc_t *isp, isp24xx_statusreq_t *sp,
 		return;
 
 	case RQCS_DMA_ERROR:
-		isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "DMA error");
 		break;
 
 	case RQCS_TRANSPORT_ERROR:
-		isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs,  ISP_LOGERR, "Transport Error");
 		break;
 
 	case RQCS_RESET_OCCURRED:
-		isp_prt(isp, ISP_LOGWARN,
-		    "reset destroyed command for %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGWARN, "reset destroyed command");
 		FCPARAM(isp, chan)->sendmarker = 1;
 		if (XS_NOERR(xs)) {
 			XS_SETERR(xs, HBA_BUSRESET);
@@ -6418,8 +6359,7 @@ isp_parse_status_24xx(ispsoftc_t *isp, isp24xx_statusreq_t *sp,
 		return;
 
 	case RQCS_ABORTED:
-		isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "Command Aborted");
 		FCPARAM(isp, chan)->sendmarker = 1;
 		if (XS_NOERR(xs)) {
 			XS_SETERR(xs, HBA_ABORTED);
@@ -6427,8 +6367,7 @@ isp_parse_status_24xx(ispsoftc_t *isp, isp24xx_statusreq_t *sp,
 		return;
 
 	case RQCS_TIMEOUT:
-		isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGWARN, "Command Timed Out");
 		if (XS_NOERR(xs)) {
 			XS_SETERR(xs, HBA_CMDTIMEOUT);
 		}
@@ -6436,9 +6375,7 @@ isp_parse_status_24xx(ispsoftc_t *isp, isp24xx_statusreq_t *sp,
 
 	case RQCS_DATA_OVERRUN:
 		XS_SET_RESID(xs, sp->req_resid);
-		isp_prt(isp, ISP_LOGERR,
-		    "data overrun for command on %d.%d.%d",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
+		isp_xs_prt(isp, xs, ISP_LOGERR, "Data Overrun");
 		if (XS_NOERR(xs)) {
 			XS_SETERR(xs, HBA_DATAOVR);
 		}
@@ -6471,19 +6408,14 @@ isp_parse_status_24xx(ispsoftc_t *isp, isp24xx_statusreq_t *sp,
 		sv_marked = (sp->req_scsi_status & (RQCS_SV|RQCS_RV)) != 0;
 		if ((ru_marked == 0 && sv_marked == 0) ||
 		    (sp->req_resid > XS_XFRLEN(xs))) {
-			isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
-			    XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
-			    (ru_marked)? "marked" : "not marked");
+			isp_xs_prt(isp, xs, ISP_LOGWARN, bun, XS_XFRLEN(xs), sp->req_resid, (ru_marked)? "marked" : "not marked");
 			if (XS_NOERR(xs)) {
 				XS_SETERR(xs, HBA_BOTCH);
 			}
 			return;
 		}
 		XS_SET_RESID(xs, sp->req_resid);
-		isp_prt(isp, ISP_LOGDEBUG0,
-		    "%d.%d.%d data underrun (%d) for command 0x%x",
-		    XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
-		    sp->req_resid, XS_CDBP(xs)[0] & 0xff);
+		isp_xs_prt(isp, xs, ISP_LOGDEBUG0, "Data Underrun (%d) for command 0x%x", sp->req_resid, XS_CDBP(xs)[0] & 0xff);
 		if (XS_NOERR(xs)) {
 			XS_SETERR(xs, HBA_NOERROR);
 		}
@@ -7384,8 +7316,7 @@ isp_spi_update(ispsoftc_t *isp, int chan)
 		if (sdp->isp_devparam[tgt].dev_enable == 0) {
 			sdp->isp_devparam[tgt].dev_update = 0;
 			sdp->isp_devparam[tgt].dev_refresh = 0;
-			isp_prt(isp, ISP_LOGDEBUG0,
-	 		    "skipping target %d bus %d update", tgt, chan);
+			isp_prt(isp, ISP_LOGDEBUG0, "skipping target %d bus %d update", tgt, chan);
 			continue;
 		}
 		/*
@@ -7441,10 +7372,8 @@ isp_spi_update(ispsoftc_t *isp, int chan)
 			sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
 			sdp->isp_devparam[tgt].actv_flags |=
 			    (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
-			isp_prt(isp, ISP_LOGDEBUG0,
-			    "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
-			    chan, tgt, mbs.param[2], mbs.param[3] >> 8,
-			    mbs.param[3] & 0xff);
+			isp_prt(isp, ISP_LOGDEBUG0, "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
+			    chan, tgt, mbs.param[2], mbs.param[3] >> 8, mbs.param[3] & 0xff);
 			get = 0;
 		} else {
 			continue;
@@ -7778,8 +7707,7 @@ isp_read_nvram(ispsoftc_t *isp, int bus)
 	    nvram_data[2] != 'P') {
 		if (isp->isp_bustype != ISP_BT_SBUS) {
 			isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
-			isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x",
-			    nvram_data[0], nvram_data[1], nvram_data[2]);
+			isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x", nvram_data[0], nvram_data[1], nvram_data[2]);
 		}
 		retval = -1;
 		goto out;
@@ -8294,8 +8222,7 @@ isp_parse_nvram_2100(ispsoftc_t *isp, uint8_t *nvram_data)
 	    ISP2100_NVRAM_TOV(nvram_data));
 	fcp->isp_xfwoptions = ISP2100_XFW_OPTIONS(nvram_data);
 	fcp->isp_zfwoptions = ISP2100_ZFW_OPTIONS(nvram_data);
-	isp_prt(isp, ISP_LOGDEBUG0,
-	    "xfwoptions 0x%x zfw options 0x%x",
+	isp_prt(isp, ISP_LOGDEBUG0, "xfwoptions 0x%x zfw options 0x%x",
 	    ISP2100_XFW_OPTIONS(nvram_data), ISP2100_ZFW_OPTIONS(nvram_data));
 }
 
diff --git a/sys/dev/isp/isp_freebsd.c b/sys/dev/isp/isp_freebsd.c
index ca459f36564..5f64bcd176c 100644
--- a/sys/dev/isp/isp_freebsd.c
+++ b/sys/dev/isp/isp_freebsd.c
@@ -5432,6 +5432,20 @@ isp_prt(ispsoftc_t *isp, int level, const char *fmt, ...)
 	printf("\n");
 }
 
+void
+isp_xs_prt(ispsoftc_t *isp, XS_T *xs, int level, const char *fmt, ...)
+{
+	va_list ap;
+	if (level != ISP_LOGALL && (level & isp->isp_dblev) == 0) {
+		return;
+	}
+	xpt_print_path(xs->ccb_h.path);
+	va_start(ap, fmt);
+	vprintf(fmt, ap);
+	va_end(ap);
+	printf("\n");
+}
+
 uint64_t
 isp_nanotime_sub(struct timespec *b, struct timespec *a)
 {
diff --git a/sys/dev/isp/isp_freebsd.h b/sys/dev/isp/isp_freebsd.h
index dea6266b71d..44c8bdf1ca5 100644
--- a/sys/dev/isp/isp_freebsd.h
+++ b/sys/dev/isp/isp_freebsd.h
@@ -424,6 +424,8 @@ default:							\
 	imin((sizeof((ccb)->sense_data)), ccb->sense_len)
 
 #define	XS_SNSKEY(ccb)		((ccb)->sense_data.flags & 0xf)
+#define	XS_SNSASC(ccb)		((ccb)->sense_data.add_sense_code)
+#define	XS_SNSASCQ(ccb)		((ccb)->sense_data.add_sense_code_qual)
 #define	XS_TAG_P(ccb)	\
 	(((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) && \
 	 (ccb)->tag_action != CAM_TAG_ACTION_NONE)
@@ -461,7 +463,7 @@ default:							\
 	(xs)->ccb_h.status |= CAM_AUTOSNS_VALID;	\
 	memcpy(&(xs)->sense_data, sense_ptr, imin(XS_SNSLEN(xs), sense_len))
 
-#define	XS_SET_STATE_STAT(a, b, c)
+#define	XS_SENSE_VALID(xs)	(((xs)->ccb_h.status & CAM_AUTOSNS_VALID) != 0)
 
 #define	DEFAULT_FRAMESIZE(isp)		isp->isp_osinfo.framesize
 #define	DEFAULT_EXEC_THROTTLE(isp)	isp->isp_osinfo.exec_throttle
@@ -593,6 +595,7 @@ extern int isp_autoconfig;
  * Platform Library Functions
  */
 void isp_prt(ispsoftc_t *, int level, const char *, ...) __printflike(3, 4);
+void isp_xs_prt(ispsoftc_t *, XS_T *, int level, const char *, ...) __printflike(4, 5);
 uint64_t isp_nanotime_sub(struct timespec *, struct timespec *);
 int isp_mbox_acquire(ispsoftc_t *);
 void isp_mbox_wait_complete(ispsoftc_t *, mbreg_t *);
diff --git a/sys/dev/isp/ispvar.h b/sys/dev/isp/ispvar.h
index 5c8508c87c4..e4bf8698670 100644
--- a/sys/dev/isp/ispvar.h
+++ b/sys/dev/isp/ispvar.h
@@ -954,12 +954,13 @@ void isp_async(ispsoftc_t *, ispasync_t, ...);
 /*
  * Platform Dependent Error and Debug Printout
  *
- * Generally this is:
+ * Two required functions for each platform must be provided:
  *
  *    void isp_prt(ispsoftc_t *, int level, const char *, ...)
+ *    void isp_xs_prt(ispsoftc_t *, XS_T *, int level, const char *, ...)
  *
  * but due to compiler differences on different platforms this won't be
- * formally done here. Instead, it goes in each platform definition file.
+ * formally defined here. Instead, they go in each platform definition file.
  */
 
 #define	ISP_LOGALL	0x0	/* log always */
@@ -972,6 +973,7 @@ void isp_async(ispsoftc_t *, ispasync_t, ...);
 #define	ISP_LOGDEBUG2	0x40	/* log most debug messages */
 #define	ISP_LOGDEBUG3	0x80	/* log high frequency debug messages */
 #define	ISP_LOGSANCFG	0x100	/* log SAN configuration */
+#define	ISP_LOG_CWARN	0x200	/* log SCSI command "warnings" (e.g., check conditions) */
 #define	ISP_LOGTINFO	0x1000	/* log informational messages (target mode) */
 #define	ISP_LOGTDEBUG0	0x2000	/* log simple debug messages (target mode) */
 #define	ISP_LOGTDEBUG1	0x4000	/* log intermediate debug messages (target) */
@@ -1045,6 +1047,8 @@ void isp_async(ispsoftc_t *, ispasync_t, ...);
  *	XS_SNSP(xs)		gets a pointer to the associate sense data
  *	XS_SNSLEN(xs)		gets the length of sense data storage
  *	XS_SNSKEY(xs)		dereferences XS_SNSP to get the current stored Sense Key
+ *	XS_SNSASC(xs)		dereferences XS_SNSP to get the current stored Additional Sense Code
+ *	XS_SNSASCQ(xs)		dereferences XS_SNSP to get the current stored Additional Sense Code Qualifier
  *	XS_TAG_P(xs)		predicate of whether this command should be tagged
  *	XS_TAG_TYPE(xs)		which type of tag to use
  *	XS_SETERR(xs)		set error state
@@ -1065,6 +1069,8 @@ void isp_async(ispsoftc_t *, ispasync_t, ...);
  *
  *	XS_SAVE_SENSE(xs, sp, len)	save sense data
  *
+ *	XS_SENSE_VALID(xs)		indicates whether sense is valid
+ *
  *	DEFAULT_FRAMESIZE(ispsoftc_t *)		Default Frame Size
  *	DEFAULT_EXEC_THROTTLE(ispsoftc_t *)	Default Execution Throttle
  *

From 36e60cda45a7797996f2abd6296a20dfdf2cc9b2 Mon Sep 17 00:00:00 2001
From: Xin LI 
Date: Fri, 26 Mar 2010 17:02:32 +0000
Subject: [PATCH 090/119] Remove GNU cpio after fix of CVE-2010-0624.

Note that this is actually a no-op for most users, as this GNU
cpio was broken on -HEAD and 8-STABLE since last March until
the recent fix.

FreeBSD 8.0+ uses BSD cpio by default and the code is being
actively maintained.

Blessed by:	kientzle
With hat:	secteam
MFC after:	3 days
---
 ObsoleteFiles.inc                        |    5 +
 contrib/cpio/ABOUT-NLS                   | 1101 ------------
 contrib/cpio/AUTHORS                     |    6 -
 contrib/cpio/COPYING                     |  340 ----
 contrib/cpio/ChangeLog                   | 1781 --------------------
 contrib/cpio/FREEBSD-upgrade             |   29 -
 contrib/cpio/INSTALL                     |  234 ---
 contrib/cpio/NEWS                        |  155 --
 contrib/cpio/README                      |   71 -
 contrib/cpio/THANKS                      |   20 -
 contrib/cpio/TODO                        |  159 --
 contrib/cpio/doc/cpio.1                  |   41 -
 contrib/cpio/doc/cpio.texi               |  602 -------
 contrib/cpio/doc/version.texi            |    4 -
 contrib/cpio/lib/alloca_.h               |   54 -
 contrib/cpio/lib/argp-ba.c               |   25 -
 contrib/cpio/lib/argp-eexst.c            |   31 -
 contrib/cpio/lib/argp-fmtstream.c        |  435 -----
 contrib/cpio/lib/argp-fmtstream.h        |  301 ----
 contrib/cpio/lib/argp-fs-xinl.c          |   43 -
 contrib/cpio/lib/argp-help.c             | 1954 ----------------------
 contrib/cpio/lib/argp-namefrob.h         |  158 --
 contrib/cpio/lib/argp-parse.c            |  953 -----------
 contrib/cpio/lib/argp-pin.c              |   28 -
 contrib/cpio/lib/argp-pv.c               |   24 -
 contrib/cpio/lib/argp-pvh.c              |   31 -
 contrib/cpio/lib/argp-xinl.c             |   43 -
 contrib/cpio/lib/argp.h                  |  624 -------
 contrib/cpio/lib/basename.c              |  129 --
 contrib/cpio/lib/dirname.c               |   85 -
 contrib/cpio/lib/dirname.h               |   70 -
 contrib/cpio/lib/error.c                 |  338 ----
 contrib/cpio/lib/error.h                 |   66 -
 contrib/cpio/lib/exitfail.c              |   26 -
 contrib/cpio/lib/exitfail.h              |   20 -
 contrib/cpio/lib/fatal.c                 |   27 -
 contrib/cpio/lib/full-write.c            |   81 -
 contrib/cpio/lib/full-write.h            |   35 -
 contrib/cpio/lib/getopt.c                | 1191 -------------
 contrib/cpio/lib/getopt1.c               |  171 --
 contrib/cpio/lib/getopt_.h               |  226 ---
 contrib/cpio/lib/getopt_int.h            |  131 --
 contrib/cpio/lib/gettext.h               |  270 ---
 contrib/cpio/lib/hash.c                  | 1048 ------------
 contrib/cpio/lib/hash.h                  |   88 -
 contrib/cpio/lib/intprops.h              |   78 -
 contrib/cpio/lib/inttostr.c              |   51 -
 contrib/cpio/lib/inttostr.h              |   30 -
 contrib/cpio/lib/mempcpy.c               |   29 -
 contrib/cpio/lib/paxerror.c              |  365 ----
 contrib/cpio/lib/paxexit.c               |   28 -
 contrib/cpio/lib/paxlib.h                |  115 --
 contrib/cpio/lib/paxnames.c              |  156 --
 contrib/cpio/lib/quote.c                 |   41 -
 contrib/cpio/lib/quote.h                 |   22 -
 contrib/cpio/lib/quotearg.c              |  697 --------
 contrib/cpio/lib/quotearg.h              |  140 --
 contrib/cpio/lib/rmt-command.h           |    4 -
 contrib/cpio/lib/rmt.h                   |   99 --
 contrib/cpio/lib/rtapelib.c              |  741 --------
 contrib/cpio/lib/safe-read.c             |   78 -
 contrib/cpio/lib/safe-read.h             |   35 -
 contrib/cpio/lib/safe-write.c            |   19 -
 contrib/cpio/lib/safe-write.h            |   25 -
 contrib/cpio/lib/savedir.c               |  137 --
 contrib/cpio/lib/savedir.h               |   27 -
 contrib/cpio/lib/strchrnul.c             |   32 -
 contrib/cpio/lib/stripslash.c            |   45 -
 contrib/cpio/lib/strndup.c               |   37 -
 contrib/cpio/lib/strnlen.c               |   31 -
 contrib/cpio/lib/system-ioctl.h          |   55 -
 contrib/cpio/lib/system.h                |  475 ------
 contrib/cpio/lib/umaxtostr.c             |    3 -
 contrib/cpio/lib/unlocked-io.h           |  137 --
 contrib/cpio/lib/utimens.c               |  189 ---
 contrib/cpio/lib/utimens.h               |    3 -
 contrib/cpio/lib/xalloc-die.c            |   42 -
 contrib/cpio/lib/xalloc.h                |  271 ---
 contrib/cpio/lib/xmalloc.c               |  123 --
 contrib/cpio/lib/xstrndup.c              |   37 -
 contrib/cpio/lib/xstrndup.h              |   24 -
 contrib/cpio/src/copyin.c                | 1644 ------------------
 contrib/cpio/src/copyout.c               | 1010 -----------
 contrib/cpio/src/copypass.c              |  443 -----
 contrib/cpio/src/cpio.h                  |   72 -
 contrib/cpio/src/cpiohdr.h               |  106 --
 contrib/cpio/src/defer.c                 |   43 -
 contrib/cpio/src/defer.h                 |   26 -
 contrib/cpio/src/dstring.c               |  103 --
 contrib/cpio/src/dstring.h               |   50 -
 contrib/cpio/src/extern.h                |  221 ---
 contrib/cpio/src/filemode.c              |  243 ---
 contrib/cpio/src/filetypes.h             |   85 -
 contrib/cpio/src/global.c                |  201 ---
 contrib/cpio/src/idcache.c               |  207 ---
 contrib/cpio/src/main.c                  |  804 ---------
 contrib/cpio/src/makepath.c              |  267 ---
 contrib/cpio/src/safe-stat.h             |    1 -
 contrib/cpio/src/tar.c                   |  494 ------
 contrib/cpio/src/tar.h                   |  112 --
 contrib/cpio/src/tarhdr.h                |   63 -
 contrib/cpio/src/userspec.c              |  261 ---
 contrib/cpio/src/util.c                  | 1344 ---------------
 gnu/usr.bin/Makefile                     |    5 -
 gnu/usr.bin/cpio/Makefile                |   80 -
 gnu/usr.bin/cpio/config.h                | 1001 -----------
 gnu/usr.bin/cpio/doc/Makefile            |   15 -
 share/man/man5/src.conf.5                |    9 +-
 share/mk/bsd.own.mk                      |    1 -
 tools/build/mk/OptionalObsoleteFiles.inc |    6 -
 tools/build/options/WITH_GNU_CPIO        |    6 -
 usr.bin/cpio/Makefile                    |    2 -
 112 files changed, 6 insertions(+), 26594 deletions(-)
 delete mode 100644 contrib/cpio/ABOUT-NLS
 delete mode 100644 contrib/cpio/AUTHORS
 delete mode 100644 contrib/cpio/COPYING
 delete mode 100644 contrib/cpio/ChangeLog
 delete mode 100644 contrib/cpio/FREEBSD-upgrade
 delete mode 100644 contrib/cpio/INSTALL
 delete mode 100644 contrib/cpio/NEWS
 delete mode 100644 contrib/cpio/README
 delete mode 100644 contrib/cpio/THANKS
 delete mode 100644 contrib/cpio/TODO
 delete mode 100644 contrib/cpio/doc/cpio.1
 delete mode 100644 contrib/cpio/doc/cpio.texi
 delete mode 100644 contrib/cpio/doc/version.texi
 delete mode 100644 contrib/cpio/lib/alloca_.h
 delete mode 100644 contrib/cpio/lib/argp-ba.c
 delete mode 100644 contrib/cpio/lib/argp-eexst.c
 delete mode 100644 contrib/cpio/lib/argp-fmtstream.c
 delete mode 100644 contrib/cpio/lib/argp-fmtstream.h
 delete mode 100644 contrib/cpio/lib/argp-fs-xinl.c
 delete mode 100644 contrib/cpio/lib/argp-help.c
 delete mode 100644 contrib/cpio/lib/argp-namefrob.h
 delete mode 100644 contrib/cpio/lib/argp-parse.c
 delete mode 100644 contrib/cpio/lib/argp-pin.c
 delete mode 100644 contrib/cpio/lib/argp-pv.c
 delete mode 100644 contrib/cpio/lib/argp-pvh.c
 delete mode 100644 contrib/cpio/lib/argp-xinl.c
 delete mode 100644 contrib/cpio/lib/argp.h
 delete mode 100644 contrib/cpio/lib/basename.c
 delete mode 100644 contrib/cpio/lib/dirname.c
 delete mode 100644 contrib/cpio/lib/dirname.h
 delete mode 100644 contrib/cpio/lib/error.c
 delete mode 100644 contrib/cpio/lib/error.h
 delete mode 100644 contrib/cpio/lib/exitfail.c
 delete mode 100644 contrib/cpio/lib/exitfail.h
 delete mode 100644 contrib/cpio/lib/fatal.c
 delete mode 100644 contrib/cpio/lib/full-write.c
 delete mode 100644 contrib/cpio/lib/full-write.h
 delete mode 100644 contrib/cpio/lib/getopt.c
 delete mode 100644 contrib/cpio/lib/getopt1.c
 delete mode 100644 contrib/cpio/lib/getopt_.h
 delete mode 100644 contrib/cpio/lib/getopt_int.h
 delete mode 100644 contrib/cpio/lib/gettext.h
 delete mode 100644 contrib/cpio/lib/hash.c
 delete mode 100644 contrib/cpio/lib/hash.h
 delete mode 100644 contrib/cpio/lib/intprops.h
 delete mode 100644 contrib/cpio/lib/inttostr.c
 delete mode 100644 contrib/cpio/lib/inttostr.h
 delete mode 100644 contrib/cpio/lib/mempcpy.c
 delete mode 100644 contrib/cpio/lib/paxerror.c
 delete mode 100644 contrib/cpio/lib/paxexit.c
 delete mode 100644 contrib/cpio/lib/paxlib.h
 delete mode 100644 contrib/cpio/lib/paxnames.c
 delete mode 100644 contrib/cpio/lib/quote.c
 delete mode 100644 contrib/cpio/lib/quote.h
 delete mode 100644 contrib/cpio/lib/quotearg.c
 delete mode 100644 contrib/cpio/lib/quotearg.h
 delete mode 100644 contrib/cpio/lib/rmt-command.h
 delete mode 100644 contrib/cpio/lib/rmt.h
 delete mode 100644 contrib/cpio/lib/rtapelib.c
 delete mode 100644 contrib/cpio/lib/safe-read.c
 delete mode 100644 contrib/cpio/lib/safe-read.h
 delete mode 100644 contrib/cpio/lib/safe-write.c
 delete mode 100644 contrib/cpio/lib/safe-write.h
 delete mode 100644 contrib/cpio/lib/savedir.c
 delete mode 100644 contrib/cpio/lib/savedir.h
 delete mode 100644 contrib/cpio/lib/strchrnul.c
 delete mode 100644 contrib/cpio/lib/stripslash.c
 delete mode 100644 contrib/cpio/lib/strndup.c
 delete mode 100644 contrib/cpio/lib/strnlen.c
 delete mode 100644 contrib/cpio/lib/system-ioctl.h
 delete mode 100644 contrib/cpio/lib/system.h
 delete mode 100644 contrib/cpio/lib/umaxtostr.c
 delete mode 100644 contrib/cpio/lib/unlocked-io.h
 delete mode 100644 contrib/cpio/lib/utimens.c
 delete mode 100644 contrib/cpio/lib/utimens.h
 delete mode 100644 contrib/cpio/lib/xalloc-die.c
 delete mode 100644 contrib/cpio/lib/xalloc.h
 delete mode 100644 contrib/cpio/lib/xmalloc.c
 delete mode 100644 contrib/cpio/lib/xstrndup.c
 delete mode 100644 contrib/cpio/lib/xstrndup.h
 delete mode 100644 contrib/cpio/src/copyin.c
 delete mode 100644 contrib/cpio/src/copyout.c
 delete mode 100644 contrib/cpio/src/copypass.c
 delete mode 100644 contrib/cpio/src/cpio.h
 delete mode 100644 contrib/cpio/src/cpiohdr.h
 delete mode 100644 contrib/cpio/src/defer.c
 delete mode 100644 contrib/cpio/src/defer.h
 delete mode 100644 contrib/cpio/src/dstring.c
 delete mode 100644 contrib/cpio/src/dstring.h
 delete mode 100644 contrib/cpio/src/extern.h
 delete mode 100644 contrib/cpio/src/filemode.c
 delete mode 100644 contrib/cpio/src/filetypes.h
 delete mode 100644 contrib/cpio/src/global.c
 delete mode 100644 contrib/cpio/src/idcache.c
 delete mode 100644 contrib/cpio/src/main.c
 delete mode 100644 contrib/cpio/src/makepath.c
 delete mode 100644 contrib/cpio/src/safe-stat.h
 delete mode 100644 contrib/cpio/src/tar.c
 delete mode 100644 contrib/cpio/src/tar.h
 delete mode 100644 contrib/cpio/src/tarhdr.h
 delete mode 100644 contrib/cpio/src/userspec.c
 delete mode 100644 contrib/cpio/src/util.c
 delete mode 100644 gnu/usr.bin/cpio/Makefile
 delete mode 100644 gnu/usr.bin/cpio/config.h
 delete mode 100644 gnu/usr.bin/cpio/doc/Makefile
 delete mode 100644 tools/build/options/WITH_GNU_CPIO

diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc
index ee300e0d708..16e9250adec 100644
--- a/ObsoleteFiles.inc
+++ b/ObsoleteFiles.inc
@@ -14,6 +14,11 @@
 # The file is partitioned: OLD_FILES first, then OLD_LIBS and OLD_DIRS last.
 #
 
+# 20100326: gcpio removal
+OLD_FILES+=usr/bin/gcpio
+OLD_FILES+=usr/share/info/cpio.info.gz
+OLD_FILES+=usr/share/man/man1/gcpio.1.gz
+
 # 20100322: libz update
 OLD_LIBS+=lib/libz.so.5
 .if ${TARGET_ARCH} == "amd64"
diff --git a/contrib/cpio/ABOUT-NLS b/contrib/cpio/ABOUT-NLS
deleted file mode 100644
index ec20977e060..00000000000
--- a/contrib/cpio/ABOUT-NLS
+++ /dev/null
@@ -1,1101 +0,0 @@
-1 Notes on the Free Translation Project
-***************************************
-
-Free software is going international!  The Free Translation Project is
-a way to get maintainers of free software, translators, and users all
-together, so that free software will gradually become able to speak many
-languages.  A few packages already provide translations for their
-messages.
-
-   If you found this `ABOUT-NLS' file inside a distribution, you may
-assume that the distributed package does use GNU `gettext' internally,
-itself available at your nearest GNU archive site.  But you do _not_
-need to install GNU `gettext' prior to configuring, installing or using
-this package with messages translated.
-
-   Installers will find here some useful hints.  These notes also
-explain how users should proceed for getting the programs to use the
-available translations.  They tell how people wanting to contribute and
-work on translations can contact the appropriate team.
-
-   When reporting bugs in the `intl/' directory or bugs which may be
-related to internationalization, you should tell about the version of
-`gettext' which is used.  The information can be found in the
-`intl/VERSION' file, in internationalized packages.
-
-1.1 Quick configuration advice
-==============================
-
-If you want to exploit the full power of internationalization, you
-should configure it using
-
-     ./configure --with-included-gettext
-
-to force usage of internationalizing routines provided within this
-package, despite the existence of internationalizing capabilities in the
-operating system where this package is being installed.  So far, only
-the `gettext' implementation in the GNU C library version 2 provides as
-many features (such as locale alias, message inheritance, automatic
-charset conversion or plural form handling) as the implementation here.
-It is also not possible to offer this additional functionality on top
-of a `catgets' implementation.  Future versions of GNU `gettext' will
-very likely convey even more functionality.  So it might be a good idea
-to change to GNU `gettext' as soon as possible.
-
-   So you need _not_ provide this option if you are using GNU libc 2 or
-you have installed a recent copy of the GNU gettext package with the
-included `libintl'.
-
-1.2 INSTALL Matters
-===================
-
-Some packages are "localizable" when properly installed; the programs
-they contain can be made to speak your own native language.  Most such
-packages use GNU `gettext'.  Other packages have their own ways to
-internationalization, predating GNU `gettext'.
-
-   By default, this package will be installed to allow translation of
-messages.  It will automatically detect whether the system already
-provides the GNU `gettext' functions.  If not, the included GNU
-`gettext' library will be used.  This library is wholly contained
-within this package, usually in the `intl/' subdirectory, so prior
-installation of the GNU `gettext' package is _not_ required.
-Installers may use special options at configuration time for changing
-the default behaviour.  The commands:
-
-     ./configure --with-included-gettext
-     ./configure --disable-nls
-
-will, respectively, bypass any pre-existing `gettext' to use the
-internationalizing routines provided within this package, or else,
-_totally_ disable translation of messages.
-
-   When you already have GNU `gettext' installed on your system and run
-configure without an option for your new package, `configure' will
-probably detect the previously built and installed `libintl.a' file and
-will decide to use this.  This might not be desirable.  You should use
-the more recent version of the GNU `gettext' library.  I.e. if the file
-`intl/VERSION' shows that the library which comes with this package is
-more recent, you should use
-
-     ./configure --with-included-gettext
-
-to prevent auto-detection.
-
-   The configuration process will not test for the `catgets' function
-and therefore it will not be used.  The reason is that even an
-emulation of `gettext' on top of `catgets' could not provide all the
-extensions of the GNU `gettext' library.
-
-   Internationalized packages usually have many `po/LL.po' files, where
-LL gives an ISO 639 two-letter code identifying the language.  Unless
-translations have been forbidden at `configure' time by using the
-`--disable-nls' switch, all available translations are installed
-together with the package.  However, the environment variable `LINGUAS'
-may be set, prior to configuration, to limit the installed set.
-`LINGUAS' should then contain a space separated list of two-letter
-codes, stating which languages are allowed.
-
-1.3 Using This Package
-======================
-
-As a user, if your language has been installed for this package, you
-only have to set the `LANG' environment variable to the appropriate
-`LL_CC' combination.  Here `LL' is an ISO 639 two-letter language code,
-and `CC' is an ISO 3166 two-letter country code.  For example, let's
-suppose that you speak German and live in Germany.  At the shell
-prompt, merely execute `setenv LANG de_DE' (in `csh'),
-`export LANG; LANG=de_DE' (in `sh') or `export LANG=de_DE' (in `bash').
-This can be done from your `.login' or `.profile' file, once and for
-all.
-
-   You might think that the country code specification is redundant.
-But in fact, some languages have dialects in different countries.  For
-example, `de_AT' is used for Austria, and `pt_BR' for Brazil.  The
-country code serves to distinguish the dialects.
-
-   The locale naming convention of `LL_CC', with `LL' denoting the
-language and `CC' denoting the country, is the one use on systems based
-on GNU libc.  On other systems, some variations of this scheme are
-used, such as `LL' or `LL_CC.ENCODING'.  You can get the list of
-locales supported by your system for your language by running the
-command `locale -a | grep '^LL''.
-
-   Not all programs have translations for all languages.  By default, an
-English message is shown in place of a nonexistent translation.  If you
-understand other languages, you can set up a priority list of languages.
-This is done through a different environment variable, called
-`LANGUAGE'.  GNU `gettext' gives preference to `LANGUAGE' over `LANG'
-for the purpose of message handling, but you still need to have `LANG'
-set to the primary language; this is required by other parts of the
-system libraries.  For example, some Swedish users who would rather
-read translations in German than English for when Swedish is not
-available, set `LANGUAGE' to `sv:de' while leaving `LANG' to `sv_SE'.
-
-   Special advice for Norwegian users: The language code for Norwegian
-bokma*l changed from `no' to `nb' recently (in 2003).  During the
-transition period, while some message catalogs for this language are
-installed under `nb' and some older ones under `no', it's recommended
-for Norwegian users to set `LANGUAGE' to `nb:no' so that both newer and
-older translations are used.
-
-   In the `LANGUAGE' environment variable, but not in the `LANG'
-environment variable, `LL_CC' combinations can be abbreviated as `LL'
-to denote the language's main dialect.  For example, `de' is equivalent
-to `de_DE' (German as spoken in Germany), and `pt' to `pt_PT'
-(Portuguese as spoken in Portugal) in this context.
-
-1.4 Translating Teams
-=====================
-
-For the Free Translation Project to be a success, we need interested
-people who like their own language and write it well, and who are also
-able to synergize with other translators speaking the same language.
-Each translation team has its own mailing list.  The up-to-date list of
-teams can be found at the Free Translation Project's homepage,
-`http://www.iro.umontreal.ca/contrib/po/HTML/', in the "National teams"
-area.
-
-   If you'd like to volunteer to _work_ at translating messages, you
-should become a member of the translating team for your own language.
-The subscribing address is _not_ the same as the list itself, it has
-`-request' appended.  For example, speakers of Swedish can send a
-message to `sv-request@li.org', having this message body:
-
-     subscribe
-
-   Keep in mind that team members are expected to participate
-_actively_ in translations, or at solving translational difficulties,
-rather than merely lurking around.  If your team does not exist yet and
-you want to start one, or if you are unsure about what to do or how to
-get started, please write to `translation@iro.umontreal.ca' to reach the
-coordinator for all translator teams.
-
-   The English team is special.  It works at improving and uniformizing
-the terminology in use.  Proven linguistic skills are praised more than
-programming skills, here.
-
-1.5 Available Packages
-======================
-
-Languages are not equally supported in all packages.  The following
-matrix shows the current state of internationalization, as of October
-2006.  The matrix shows, in regard of each package, for which languages
-PO files have been submitted to translation coordination, with a
-translation percentage of at least 50%.
-
-     Ready PO files       af am ar az be bg bs ca cs cy da de el en en_GB eo
-                        +----------------------------------------------------+
-     GNUnet             |                                  []                |
-     a2ps               |             []                [] [] []     []      |
-     aegis              |                                  ()                |
-     ant-phone          |                                  ()                |
-     anubis             |                                  []                |
-     ap-utils           |                                                    |
-     aspell             |                      [] []    [] []        []      |
-     bash               |                      []          []             [] |
-     batchelor          |                                  []                |
-     bfd                |                                                    |
-     bibshelf           |                                  []                |
-     binutils           |                               []                   |
-     bison              |                               [] []                |
-     bison-runtime      |                                                    |
-     bluez-pin          | []                      []       [] []          [] |
-     cflow              |                               []                   |
-     clisp              |                                  []    []          |
-     console-tools      |                         []       []                |
-     coreutils          |                []    []          []                |
-     cpio               |                                                    |
-     cpplib             |                      []       [] []                |
-     cryptonit          |                                  []                |
-     darkstat           |                []             () []                |
-     dialog             |                      [] [] [] [] [] []             |
-     diffutils          |                      [] []    [] [] []          [] |
-     doodle             |                                  []                |
-     e2fsprogs          |                         []       []                |
-     enscript           |                      []       [] []        []      |
-     error              |                      []       [] []        []      |
-     fetchmail          |                      []       [] () []             |
-     fileutils          |                               [] []                |
-     findutils          |                []    []       []                   |
-     flex               |                      []       [] []                |
-     fslint             |                                  []                |
-     gas                |                                                    |
-     gawk               |                      []       [] []                |
-     gbiff              |                                  []                |
-     gcal               |                      []                            |
-     gcc                |                                  []                |
-     gettext-examples   | []                   []          [] []          [] |
-     gettext-runtime    |             []       []       [] []             [] |
-     gettext-tools      |                      []          []                |
-     gimp-print         |                         []    [] []        []      |
-     gip                |                []                                  |
-     gliv               |                                  []                |
-     glunarclock        |                []                                  |
-     gmult              | []                               []                |
-     gnubiff            |                                  ()                |
-     gnucash            |                                  () ()     []      |
-     gnucash-glossary   |                               [] ()                |
-     gnuedu             |                                                    |
-     gnulib             | []          [] []    []       [] []                |
-     gnunet-gtk         |                                                    |
-     gnutls             |                                                    |
-     gpe-aerial         |                         []       []                |
-     gpe-beam           |                         []       []                |
-     gpe-calendar       |                                                    |
-     gpe-clock          |                         []       []                |
-     gpe-conf           |                         []       []                |
-     gpe-contacts       |                                                    |
-     gpe-edit           |                         []                         |
-     gpe-filemanager    |                                                    |
-     gpe-go             |                         []                         |
-     gpe-login          |                         []       []                |
-     gpe-ownerinfo      |                         []       []                |
-     gpe-package        |                                                    |
-     gpe-sketchbook     |                         []       []                |
-     gpe-su             |                         []       []                |
-     gpe-taskmanager    |                         []       []                |
-     gpe-timesheet      |                         []                         |
-     gpe-today          |                         []       []                |
-     gpe-todo           |                                                    |
-     gphoto2            |                         []    [] []        []      |
-     gprof              |                               [] []                |
-     gpsdrive           |                                  ()    ()          |
-     gramadoir          | []                               []                |
-     grep               | []          [] []    []          [] []             |
-     gretl              |                                                    |
-     gsasl              |                                                    |
-     gss                |                                                    |
-     gst-plugins        | []                   [] []    []                   |
-     gst-plugins-base   |                []    []       []                   |
-     gst-plugins-good   | []       []    []    [] []    []           []      |
-     gstreamer          | []             []    [] []    [] []        []      |
-     gtick              |                                  ()                |
-     gtkam              |                         []    [] []                |
-     gtkorphan          |                []                []                |
-     gtkspell           |             []                   [] []          [] |
-     gutenprint         |                               []                   |
-     hello              |                []    []       [] []             [] |
-     id-utils           |                               [] []                |
-     impost             |                                                    |
-     indent             |                      []          []             [] |
-     iso_3166           |                                  []             [] |
-     iso_3166_2         |                                                    |
-     iso_4217           |                                  []                |
-     iso_639            |                                  []             [] |
-     jpilot             |                         []                         |
-     jtag               |                                                    |
-     jwhois             |                                                    |
-     kbd                |                         []    [] [] []             |
-     keytouch           |                                                    |
-     keytouch-editor    |                                                    |
-     keytouch-keyboa... |                                                    |
-     latrine            |                                  ()                |
-     ld                 |                               []                   |
-     leafpad            |                []    [] []       [] []             |
-     libc               |                      [] []    [] [] []             |
-     libexif            |                                  []                |
-     libextractor       |                                  []                |
-     libgpewidget       |                         []    [] []                |
-     libgpg-error       |                                  []                |
-     libgphoto2         |                               [] []                |
-     libgphoto2_port    |                               [] []                |
-     libgsasl           |                                                    |
-     libiconv           |                                  []             [] |
-     libidn             |                               []                [] |
-     lifelines          |                               [] ()                |
-     lilypond           |                                  []                |
-     lingoteach         |                                                    |
-     lynx               |                      [] []    [] []                |
-     m4                 |                         []    [] [] []             |
-     mailutils          |                      []                            |
-     make               |                               [] []                |
-     man-db             |                      [] ()    [] []                |
-     minicom            |                         []    [] []                |
-     mysecretdiary      |                               [] []                |
-     nano               |                []    []          []                |
-     nano_1_0           |                      [] ()    [] []                |
-     opcodes            |                                  []                |
-     parted             |                                                    |
-     pilot-qof          |                                            []      |
-     psmisc             |                []                                  |
-     pwdutils           |                                                    |
-     python             |                                                    |
-     qof                |                                                    |
-     radius             |                      []                            |
-     recode             |             []       []       [] [] []          [] |
-     rpm                |                         []    []                   |
-     screem             |                                                    |
-     scrollkeeper       |          [] []       [] [] [] [] []        []      |
-     sed                |                      []          []             [] |
-     sh-utils           |                               [] []                |
-     shared-mime-info   |                []       []                 []   [] |
-     sharutils          |                []    [] []    [] [] []             |
-     shishi             |                                                    |
-     silky              |                                                    |
-     skencil            |                               [] ()                |
-     sketch             |                               [] ()                |
-     solfege            |                                                    |
-     soundtracker       |                               [] []                |
-     sp                 |                                  []                |
-     stardict           |                         []                         |
-     system-tools-ba... |       []       [] [] [] []    [] [] []     []      |
-     tar                |                []                                  |
-     texinfo            |                               [] []             [] |
-     textutils          |                      []       [] []                |
-     tin                |                                  ()        ()      |
-     tp-robot           |                                  []                |
-     tuxpaint           | []             []             [] []        []      |
-     unicode-han-tra... |                                                    |
-     unicode-transla... |                                                    |
-     util-linux         |                      [] []    [] []                |
-     vorbis-tools       |             []          []    []           []      |
-     wastesedge         |                                  ()                |
-     wdiff              |                      []       [] []        []      |
-     wget               |                      []          []                |
-     xchat              |             [] []    []          [] []     []      |
-     xkeyboard-config   |                                                    |
-     xpad               |                []             []                   |
-                        +----------------------------------------------------+
-                          af am ar az be bg bs ca cs cy da de el en en_GB eo
-                          10  0  1  2  9 22  1 42 41  2 60 95 16  1  17   16
-
-                          es et eu fa fi fr  ga gl gu he hi hr hu id is it
-                        +--------------------------------------------------+
-     GNUnet             |                                                  |
-     a2ps               |    []       [] []                             () |
-     aegis              |                                                  |
-     ant-phone          |                []                                |
-     anubis             |                []                                |
-     ap-utils           |             [] []                                |
-     aspell             |                []  []                         [] |
-     bash               | []             []                    []          |
-     batchelor          |                []  []                            |
-     bfd                | []                                               |
-     bibshelf           | []                 []                         [] |
-     binutils           | []          [] []                                |
-     bison              | [] []          []  []                   []    [] |
-     bison-runtime      |    []          []  []                   []    [] |
-     bluez-pin          |             [] []  []                [] []       |
-     cflow              |                    []                            |
-     clisp              | []             []                                |
-     console-tools      |                                                  |
-     coreutils          | [] []       [] []  []                []          |
-     cpio               | []             []  []                            |
-     cpplib             | []             []                                |
-     cryptonit          |                []                                |
-     darkstat           | []             ()  []                [] []       |
-     dialog             | [] [] []    [] []  []                []       [] |
-     diffutils          | []          [] []  [] []    []       [] []    [] |
-     doodle             |                    []                         [] |
-     e2fsprogs          | []             []                             [] |
-     enscript           |                []  []             []             |
-     error              | []          [] []  []                []          |
-     fetchmail          | []                                               |
-     fileutils          | [] []          []  []                []       [] |
-     findutils          |    []          []  []                []          |
-     flex               | []             []  []                            |
-     fslint             |                []                                |
-     gas                | []             []                                |
-     gawk               | []             []  []       []                   |
-     gbiff              |                []                                |
-     gcal               | []             []                                |
-     gcc                | []                                               |
-     gettext-examples   | []             []  []                [] []    [] |
-     gettext-runtime    | []          [] []  []                   []    [] |
-     gettext-tools      | []             []                             [] |
-     gimp-print         | []             []                                |
-     gip                | []    []       []                                |
-     gliv               |                ()                                |
-     glunarclock        |             []     []                []          |
-     gmult              |       []       []                             [] |
-     gnubiff            |                ()                             () |
-     gnucash            | ()             ()                    ()          |
-     gnucash-glossary   | []                                            [] |
-     gnuedu             | []                                               |
-     gnulib             | [] [] []    [] []  [] []             []          |
-     gnunet-gtk         |                                                  |
-     gnutls             |                                                  |
-     gpe-aerial         | []             []                                |
-     gpe-beam           | []             []                                |
-     gpe-calendar       |                                                  |
-     gpe-clock          | []          [] []                    []          |
-     gpe-conf           |                []                                |
-     gpe-contacts       | []             []                                |
-     gpe-edit           | []             []                    [] []       |
-     gpe-filemanager    | []                                               |
-     gpe-go             | []             []                    []          |
-     gpe-login          | []             []                    []          |
-     gpe-ownerinfo      | []          [] []                    [] []       |
-     gpe-package        | []                                               |
-     gpe-sketchbook     | []             []                                |
-     gpe-su             | []          [] []                    []          |
-     gpe-taskmanager    | []          [] []                                |
-     gpe-timesheet      | []             []  []                   []       |
-     gpe-today          | []          [] []  []                            |
-     gpe-todo           | []                                               |
-     gphoto2            | []          [] []                    []       [] |
-     gprof              | []             []  []                   []       |
-     gpsdrive           | ()             ()                    []       () |
-     gramadoir          |                []  []                            |
-     grep               | [] [] []    [] []  [] []    []    [] [] []    [] |
-     gretl              | []             []                             [] |
-     gsasl              |                    []                   []       |
-     gss                |                []                                |
-     gst-plugins        |                []                    []       [] |
-     gst-plugins-base   |                                      []       [] |
-     gst-plugins-good   |       []                             []       [] |
-     gstreamer          |             []                       []       [] |
-     gtick              |                    []                            |
-     gtkam              | []             []                    []       [] |
-     gtkorphan          |                []                             [] |
-     gtkspell           | []    []    [] []  []                         [] |
-     gutenprint         |                                      []          |
-     hello              | [] [] [] [] [] []  [] []    []    [] [] []    [] |
-     id-utils           |                []  []                [] []    [] |
-     impost             |                []  []                            |
-     indent             | [] [] []    [] []  [] []             [] []    [] |
-     iso_3166           |             [] []                    []          |
-     iso_3166_2         |                []                                |
-     iso_4217           |    []       []        []             []          |
-     iso_639            |          [] [] []  []                []          |
-     jpilot             | []             []                                |
-     jtag               |                []                                |
-     jwhois             | []             []                    [] []    [] |
-     kbd                | []             []                                |
-     keytouch           |                    []                            |
-     keytouch-editor    |                    []                            |
-     keytouch-keyboa... |                    []                            |
-     latrine            |                []  []                         [] |
-     ld                 | []             []                                |
-     leafpad            | []             []  []       []       []       [] |
-     libc               | []          [] []     []             []          |
-     libexif            | []                                               |
-     libextractor       |                    []                            |
-     libgpewidget       | []             []  []                [] []       |
-     libgpg-error       |                                                  |
-     libgphoto2         | []             []                             [] |
-     libgphoto2_port    |                []                             [] |
-     libgsasl           |                []  []                            |
-     libiconv           |    []              []                            |
-     libidn             |                []                             [] |
-     lifelines          |                ()                                |
-     lilypond           |                []                                |
-     lingoteach         |                []                       []    [] |
-     lynx               |    []                                []       [] |
-     m4                 |                []  [] []                []       |
-     mailutils          | []             []                                |
-     make               | []          [] []  [] []    []    []    []       |
-     man-db             | ()                                               |
-     minicom            | []          [] []                    []          |
-     mysecretdiary      | []             []                       []       |
-     nano               | []    []       []  []                []       [] |
-     nano_1_0           | []             []     []                []    [] |
-     opcodes            | []          [] []  []                            |
-     parted             | []             []                       []    [] |
-     pilot-qof          |                                                  |
-     psmisc             |       []                             []       [] |
-     pwdutils           |                                                  |
-     python             |                                                  |
-     qof                |                                         []       |
-     radius             | []             []                                |
-     recode             | []             []  [] []    []       [] []    [] |
-     rpm                |                []                       []       |
-     screem             |                                                  |
-     scrollkeeper       | []          []                       []          |
-     sed                | [] []          []  []                []          |
-     sh-utils           | [] []       [] []  []                []       [] |
-     shared-mime-info   | []    []    [] []                    []       [] |
-     sharutils          | [] []       [] []  [] []             []       [] |
-     shishi             |                                                  |
-     silky              |                []                                |
-     skencil            | []             []                                |
-     sketch             | []             []                                |
-     solfege            |                                               [] |
-     soundtracker       | []             []                             [] |
-     sp                 |                []                                |
-     stardict           |                                      []          |
-     system-tools-ba... | []    []    [] []                 [] [] []    [] |
-     tar                | [] []       [] []  []                []       [] |
-     texinfo            |                []           []                   |
-     textutils          | []             []  [] []             []          |
-     tin                |    []          ()                                |
-     tp-robot           |             [] []  []                []          |
-     tuxpaint           |                    []                []          |
-     unicode-han-tra... |                                                  |
-     unicode-transla... |                []  []                            |
-     util-linux         | [] []       [] []                    [] []    [] |
-     vorbis-tools       | []             []                                |
-     wastesedge         |                ()                                |
-     wdiff              | [] []          []  [] []             [] []    [] |
-     wget               |    []       [] []  []             [] [] []    [] |
-     xchat              | []    []    [] []        []    []    []       [] |
-     xkeyboard-config   |             [] []                    []       [] |
-     xpad               | []                 []                []          |
-                        +--------------------------------------------------+
-                          es et eu fa fi fr  ga gl gu he hi hr hu id is it
-                          88 22 14  2 40 115 61 14  1  8  1  6 59 31  0 52
-
-                          ja ko ku ky lg lt lv mk mn ms mt nb ne nl nn no
-                        +-------------------------------------------------+
-     GNUnet             |                                                 |
-     a2ps               |    ()                      []          []    () |
-     aegis              |                                        ()       |
-     ant-phone          |                                        []       |
-     anubis             |                            []    []    []       |
-     ap-utils           |                            []                   |
-     aspell             |                         []             []       |
-     bash               |                                        []       |
-     batchelor          |                            []          []       |
-     bfd                |                                                 |
-     bibshelf           |                            []                   |
-     binutils           |                                                 |
-     bison              |                            []    []    []       |
-     bison-runtime      |                            []    []    []       |
-     bluez-pin          |       []                   []          []       |
-     cflow              |                                                 |
-     clisp              |                                        []       |
-     console-tools      |                                                 |
-     coreutils          |                                        []       |
-     cpio               |                                                 |
-     cpplib             |                                        []       |
-     cryptonit          |                                        []       |
-     darkstat           |                            []          []       |
-     dialog             |                            []          []       |
-     diffutils          | []                         []          []       |
-     doodle             |                                                 |
-     e2fsprogs          |                                        []       |
-     enscript           |                                        []       |
-     error              |                                        []       |
-     fetchmail          | []                                     []       |
-     fileutils          | []          []                                  |
-     findutils          |                                        []       |
-     flex               |    []                                  []       |
-     fslint             |                            []          []       |
-     gas                |                                                 |
-     gawk               | []                                     []       |
-     gbiff              |                                        []       |
-     gcal               |                                                 |
-     gcc                |                                                 |
-     gettext-examples   | []                                     []       |
-     gettext-runtime    | [] []                                  []       |
-     gettext-tools      | [] []                                           |
-     gimp-print         | []                                     []       |
-     gip                |                            []          []       |
-     gliv               |                                        []       |
-     glunarclock        |                            []          []       |
-     gmult              | []                         []                   |
-     gnubiff            |                                                 |
-     gnucash            | ()                               ()             |
-     gnucash-glossary   |                                        []       |
-     gnuedu             |                                                 |
-     gnulib             | [] []                      []          []       |
-     gnunet-gtk         |                                                 |
-     gnutls             |                                                 |
-     gpe-aerial         |                                        []       |
-     gpe-beam           |                                        []       |
-     gpe-calendar       | []                                              |
-     gpe-clock          | [] []                                  []       |
-     gpe-conf           |    []                                  []       |
-     gpe-contacts       |    []                                           |
-     gpe-edit           | [] []                                  []       |
-     gpe-filemanager    | [] []                                           |
-     gpe-go             | [] []                                  []       |
-     gpe-login          | [] []                                  []       |
-     gpe-ownerinfo      | []                                     []       |
-     gpe-package        | [] []                                           |
-     gpe-sketchbook     |    []                                  []       |
-     gpe-su             | [] []                                  []       |
-     gpe-taskmanager    | [] [] []                               []       |
-     gpe-timesheet      |                                        []       |
-     gpe-today          | []                                     []       |
-     gpe-todo           | []                                              |
-     gphoto2            | []                                     []       |
-     gprof              |                                                 |
-     gpsdrive           | ()                                     ()    () |
-     gramadoir          |                                        ()       |
-     grep               | []       []                      []    []       |
-     gretl              |                                                 |
-     gsasl              |                                        []       |
-     gss                |                                                 |
-     gst-plugins        |                                        []       |
-     gst-plugins-base   |                                                 |
-     gst-plugins-good   |                                        []       |
-     gstreamer          |                                        []       |
-     gtick              |                                                 |
-     gtkam              | []                                              |
-     gtkorphan          |                                        []       |
-     gtkspell           |                         []             []       |
-     gutenprint         |                                                 |
-     hello              | [] []                      []    []    [] []    |
-     id-utils           |                                        []       |
-     impost             |                                                 |
-     indent             | []                                     []       |
-     iso_3166           |                                        []       |
-     iso_3166_2         |                                        []       |
-     iso_4217           | []                      []             []       |
-     iso_639            | []                                     []       |
-     jpilot             | ()                                     ()    () |
-     jtag               |                                                 |
-     jwhois             |                                        []       |
-     kbd                |                                        []       |
-     keytouch           |                                        []       |
-     keytouch-editor    |                                                 |
-     keytouch-keyboa... |                                                 |
-     latrine            |                                        []       |
-     ld                 |                                                 |
-     leafpad            | []             []                               |
-     libc               | [] []                            []    []    [] |
-     libexif            |                                                 |
-     libextractor       |                                                 |
-     libgpewidget       |                                        []       |
-     libgpg-error       |                                                 |
-     libgphoto2         | []                                              |
-     libgphoto2_port    | []                                              |
-     libgsasl           |                                        []       |
-     libiconv           |                                                 |
-     libidn             | []                                     []       |
-     lifelines          |                                        []       |
-     lilypond           |                                                 |
-     lingoteach         |                                        []       |
-     lynx               | []                                     []       |
-     m4                 | []                                     []       |
-     mailutils          |                                                 |
-     make               | [] []                                  []       |
-     man-db             | ()                                              |
-     minicom            | []                                              |
-     mysecretdiary      |                                        []       |
-     nano               |                            []    []    []       |
-     nano_1_0           |                            []    []       []    |
-     opcodes            |                                        []       |
-     parted             | []                                     []       |
-     pilot-qof          |                                                 |
-     psmisc             | []                               []    []       |
-     pwdutils           |                                                 |
-     python             |                                                 |
-     qof                |                                                 |
-     radius             |                                                 |
-     recode             |                                        []       |
-     rpm                | [] []                                           |
-     screem             | []                                              |
-     scrollkeeper       |                                  [] [] [] []    |
-     sed                | []                                     []       |
-     sh-utils           | []                               []             |
-     shared-mime-info   |    []          []                []    [] []    |
-     sharutils          | []                                     []       |
-     shishi             |                                                 |
-     silky              |                                        []       |
-     skencil            |                                                 |
-     sketch             |                                                 |
-     solfege            |                                                 |
-     soundtracker       |                                                 |
-     sp                 | ()                                              |
-     stardict           |                      []                []       |
-     system-tools-ba... | [] []          []                      []       |
-     tar                | []       []                            []       |
-     texinfo            | []                               []    []       |
-     textutils          | [] []                            []             |
-     tin                |                                                 |
-     tp-robot           |                                        []       |
-     tuxpaint           |                                           []    |
-     unicode-han-tra... |                                                 |
-     unicode-transla... |                                                 |
-     util-linux         | []                                     []       |
-     vorbis-tools       |                                        []       |
-     wastesedge         |                                        []       |
-     wdiff              |                            []    []             |
-     wget               | []                                     []       |
-     xchat              | [] []                []                []       |
-     xkeyboard-config   |                                        []       |
-     xpad               |    []                      []          []       |
-                        +-------------------------------------------------+
-                          ja ko ku ky lg lt lv mk mn ms mt nb ne nl nn no
-                          52 24  2  2  1  3  0  2  3 21  0 15  1 97  5  1
-
-                          nso or pa pl pt pt_BR rm ro ru rw sk sl sq sr sv  ta
-                        +------------------------------------------------------+
-     GNUnet             |                                                      |
-     a2ps               |           ()     []      [] []       []    [] []     |
-     aegis              |                          () ()                       |
-     ant-phone          |                          []                   []     |
-     anubis             |           []             [] []                       |
-     ap-utils           |           ()                                         |
-     aspell             |                          [] []                       |
-     bash               |                  []      [] []                       |
-     batchelor          |                          []                   []     |
-     bfd                |                                                      |
-     bibshelf           |                                               []     |
-     binutils           |                             []                []     |
-     bison              |           []     []      [] []                []     |
-     bison-runtime      |           []             []          []       []     |
-     bluez-pin          |           []     []   [] [] []    [] []    [] []     |
-     cflow              |           []                                         |
-     clisp              |                             []                       |
-     console-tools      |                             []                       |
-     coreutils          |           []                []       []       []     |
-     cpio               |           []                []                []     |
-     cpplib             |                                               []     |
-     cryptonit          |                  []                           []     |
-     darkstat           |           []     []      []       []       [] []     |
-     dialog             |           [] []  []   [] [] [] []          [] []     |
-     diffutils          |           []     []      [] []             [] []     |
-     doodle             |                                         []    []     |
-     e2fsprogs          |           []                                  []     |
-     enscript           |                  []      [] []       []       []     |
-     error              |                  []      []       []          []     |
-     fetchmail          |           []                []          []           |
-     fileutils          |           []             [] []       []       []     |
-     findutils          |           [] []          []       [] []       []     |
-     flex               |           []     []      [] []                []     |
-     fslint             |                  []      []                [] []     |
-     gas                |                                                      |
-     gawk               |           []     []      []                   []     |
-     gbiff              |                          []                          |
-     gcal               |                                               []     |
-     gcc                |                                               []     |
-     gettext-examples   |           [] []          [] []    [] []    [] []     |
-     gettext-runtime    |           [] []          [] []    [] []    [] []     |
-     gettext-tools      |           []             [] []    [] []    [] []     |
-     gimp-print         |                                   []          []     |
-     gip                |                       []          []       [] []     |
-     gliv               |                  []      []       []          []     |
-     glunarclock        |                  []      [] []    []       [] []     |
-     gmult              |                       [] []                [] []     |
-     gnubiff            |                          ()                          |
-     gnucash            |           ()                                  []     |
-     gnucash-glossary   |              []                   []          []     |
-     gnuedu             |                                                      |
-     gnulib             |           []             [] []       []       []     |
-     gnunet-gtk         |                                               []     |
-     gnutls             |           []                                  []     |
-     gpe-aerial         |              []  []      [] []       []    [] []     |
-     gpe-beam           |              []  []      [] []       []    [] []     |
-     gpe-calendar       |                             []                       |
-     gpe-clock          |              []  []      [] []    [] []    [] []     |
-     gpe-conf           |              []  []      [] []    [] []       []     |
-     gpe-contacts       |                          [] []       []    [] []     |
-     gpe-edit           |              []  []      [] []    [] []    [] []     |
-     gpe-filemanager    |                                      []       []     |
-     gpe-go             |                  []      [] []       []    [] []     |
-     gpe-login          |              []  []      [] []    [] []    [] []     |
-     gpe-ownerinfo      |              []  []      [] []    [] []    [] []     |
-     gpe-package        |                                      []       []     |
-     gpe-sketchbook     |              []  []      [] []    [] []    [] []     |
-     gpe-su             |              []  []      [] []    [] []    [] []     |
-     gpe-taskmanager    |              []  []      [] []    [] []    [] []     |
-     gpe-timesheet      |              []  []      [] []    [] []    [] []     |
-     gpe-today          |              []  []      [] []    [] []    [] []     |
-     gpe-todo           |                             []       []    [] []     |
-     gphoto2            |           []             []       []       [] []     |
-     gprof              |                  []      []                   []     |
-     gpsdrive           |        []                []                   []     |
-     gramadoir          |                                   []          []     |
-     grep               |           [] []  []      [] []       []    [] []     |
-     gretl              |           []                                         |
-     gsasl              |           []                               [] []     |
-     gss                |           []             []                   []     |
-     gst-plugins        |     []                                  [] [] []     |
-     gst-plugins-base   |                                               []     |
-     gst-plugins-good   |     []                                  [] [] []     |
-     gstreamer          |                                         [] [] []     |
-     gtick              |                             []                       |
-     gtkam              |           []     []         []                []     |
-     gtkorphan          |                                               []     |
-     gtkspell           |                  []   [] [] []    [] []    [] []     |
-     gutenprint         |                                               []     |
-     hello              |           []     []      [] []    [] []    [] []     |
-     id-utils           |                  []      [] []                []     |
-     impost             |                                               []     |
-     indent             |                  []      [] []    []       [] []     |
-     iso_3166           |              []                []    [] [] [] []     |
-     iso_3166_2         |                                                      |
-     iso_4217           |                                []    []    [] []     |
-     iso_639            |                                []    []    [] []     |
-     jpilot             |                                                      |
-     jtag               |                                   []                 |
-     jwhois             |           []     []      []                   []     |
-     kbd                |           []             []                   []     |
-     keytouch           |                                               []     |
-     keytouch-editor    |                                               []     |
-     keytouch-keyboa... |                                               []     |
-     latrine            |                          []                   []     |
-     ld                 |                                               []     |
-     leafpad            |           [] []             []    []          []  [] |
-     libc               |           []     []         []    []          []     |
-     libexif            |           []                                         |
-     libextractor       |                          []                   []     |
-     libgpewidget       |              []  []      []       [] []    [] []     |
-     libgpg-error       |           []             []                          |
-     libgphoto2         |           []                                         |
-     libgphoto2_port    |           []                []                []     |
-     libgsasl           |           []             []                [] []     |
-     libiconv           |                                      []    []        |
-     libidn             |           []                               [] ()     |
-     lifelines          |           []                                  []     |
-     lilypond           |                                                      |
-     lingoteach         |                  []                                  |
-     lynx               |                  []         []                []     |
-     m4                 |           []     []      [] []                []     |
-     mailutils          |           []             [] []                []     |
-     make               |           []     []         []                []     |
-     man-db             |                          []                   []     |
-     minicom            |           []     []      [] []                []     |
-     mysecretdiary      |                  []      [] []                []     |
-     nano               |                  []      []                   []     |
-     nano_1_0           |           []             [] []                []     |
-     opcodes            |                          []                   []     |
-     parted             |           []                                         |
-     pilot-qof          |                                               []     |
-     psmisc             |           []                                  []     |
-     pwdutils           |           []                                  []     |
-     python             |                                                      |
-     qof                |                  []                           []     |
-     radius             |           []                []                       |
-     recode             |           [] []  []      [] []       []       []     |
-     rpm                |           [] []             []                []     |
-     screem             |                                                      |
-     scrollkeeper       |           []             [] []    []    [] [] []     |
-     sed                |           [] []  []      [] []    [] []    [] []     |
-     sh-utils           |                             []       []    []        |
-     shared-mime-info   |              []  []                     [] [] []     |
-     sharutils          |           []                []             [] []     |
-     shishi             |           []                                         |
-     silky              |                                   []                 |
-     skencil            |              []  []                           []     |
-     sketch             |              []  []                           []     |
-     solfege            |                                               []     |
-     soundtracker       |                                   []          []     |
-     sp                 |                                                      |
-     stardict           |                             []    []          []     |
-     system-tools-ba... |        [] [] []  []      []             [] [] []  [] |
-     tar                |           []             [] []       []       []     |
-     texinfo            |           []             [] []                []     |
-     textutils          |                             []       []       []     |
-     tin                |                             ()                       |
-     tp-robot           |                             []                       |
-     tuxpaint           |              []                      [] [] [] []     |
-     unicode-han-tra... |                                                      |
-     unicode-transla... |                                                      |
-     util-linux         |                  []         []       []       []     |
-     vorbis-tools       |                          [] []                       |
-     wastesedge         |                                                      |
-     wdiff              |           []     []      [] []    []          []     |
-     wget               |              []             []    []          []     |
-     xchat              |        []                   []    [] [] [] [] []     |
-     xkeyboard-config   |                                      []       []     |
-     xpad               |                                   [] []       []     |
-                        +------------------------------------------------------+
-                          nso or pa pl pt pt_BR rm ro ru rw sk sl sq sr sv  ta
-                           0   2  3 58 30  54    5 73 72  4 40 46 11 50 128  2
-
-                          tg th tk tr uk ven vi  wa xh zh_CN zh_HK zh_TW zu
-                        +---------------------------------------------------+
-     GNUnet             |                    []                             |  2
-     a2ps               |          [] []     []                             | 19
-     aegis              |                                                   |  0
-     ant-phone          |          []        []                             |  6
-     anubis             |          [] []     []                             | 11
-     ap-utils           |             ()     []                             |  4
-     aspell             |             []     []  []                         | 15
-     bash               |                    []                             | 11
-     batchelor          |          []        []                             |  9
-     bfd                |                                                   |  1
-     bibshelf           |                    []                             |  7
-     binutils           |          []        []                     []      |  9
-     bison              |          []        []                     []      | 19
-     bison-runtime      |                    []         []          []      | 15
-     bluez-pin          |          [] []     []  []     []          []      | 28
-     cflow              |             []     []                             |  5
-     clisp              |                                                   |  6
-     console-tools      |          []        []                             |  5
-     coreutils          |          []        []                             | 16
-     cpio               |          [] []     []                             |  9
-     cpplib             |          []        []         []          []      | 11
-     cryptonit          |                                                   |  5
-     darkstat           |                    []         ()          ()      | 15
-     dialog             |          [] []     []         []          []      | 30
-     diffutils          |          []        []         []          []      | 28
-     doodle             |                    []                             |  6
-     e2fsprogs          |          []        []                             | 10
-     enscript           |          [] []     []                             | 16
-     error              |          []        []         []          []      | 18
-     fetchmail          |          []        []                             | 12
-     fileutils          |          []                   []          []      | 18
-     findutils          |          []        []                     []      | 17
-     flex               |          []        []                             | 15
-     fslint             |                    []                             |  9
-     gas                |          []                                       |  3
-     gawk               |          []        []                             | 15
-     gbiff              |                    []                             |  5
-     gcal               |          []                                       |  5
-     gcc                |          []                   []          []      |  6
-     gettext-examples   |          [] []     []         []    []    []      | 27
-     gettext-runtime    |          [] []     []         []    []    []      | 28
-     gettext-tools      |          [] []     []         []          []      | 19
-     gimp-print         |             []     []                             | 12
-     gip                |                    []                     []      | 12
-     gliv               |          []        []                             |  8
-     glunarclock        |                    []  []                 []      | 15
-     gmult              |          []        []         []          []      | 15
-     gnubiff            |                    []                             |  1
-     gnucash            |          ()                                       |  2
-     gnucash-glossary   |                    []                     []      |  9
-     gnuedu             |                    []                             |  2
-     gnulib             |          [] []     []         []          []      | 28
-     gnunet-gtk         |                                                   |  1
-     gnutls             |                                                   |  2
-     gpe-aerial         |                    []         []                  | 14
-     gpe-beam           |                    []         []                  | 14
-     gpe-calendar       |                    []                             |  3
-     gpe-clock          |          []        []  []     []                  | 21
-     gpe-conf           |                    []         []                  | 14
-     gpe-contacts       |                    []         []                  | 10
-     gpe-edit           |          []        []  []                 []      | 20
-     gpe-filemanager    |                    []                             |  6
-     gpe-go             |          []        []                             | 15
-     gpe-login          |          []        []  []     []          []      | 21
-     gpe-ownerinfo      |          []        []         []          []      | 21
-     gpe-package        |                    []                             |  6
-     gpe-sketchbook     |          []        []                             | 16
-     gpe-su             |          []        []         []                  | 20
-     gpe-taskmanager    |          []        []         []                  | 20
-     gpe-timesheet      |          []        []         []          []      | 18
-     gpe-today          |          []        []  []     []          []      | 21
-     gpe-todo           |                    []                             |  7
-     gphoto2            |             []     []         []          []      | 20
-     gprof              |          []        []                             | 11
-     gpsdrive           |                                                   |  4
-     gramadoir          |                    []                             |  7
-     grep               |          [] []     []                     []      | 34
-     gretl              |                                                   |  4
-     gsasl              |                    []         []                  |  8
-     gss                |                    []                             |  5
-     gst-plugins        |             []     []                     []      | 15
-     gst-plugins-base   |             []     []         []                  |  9
-     gst-plugins-good   |             []     []         []    []    []      | 20
-     gstreamer          |          [] []     []                             | 17
-     gtick              |                    []                             |  3
-     gtkam              |                    []                             | 13
-     gtkorphan          |                    []                             |  7
-     gtkspell           |             []     []  []     []    []    []      | 26
-     gutenprint         |                                                   |  3
-     hello              |          [] []     []         []          []      | 37
-     id-utils           |          []        []                             | 14
-     impost             |                    []                             |  4
-     indent             |          []        []         []          []      | 25
-     iso_3166           |       [] []        []               []            | 16
-     iso_3166_2         |                                                   |  2
-     iso_4217           |          []        []                             | 14
-     iso_639            |                    []                             | 14
-     jpilot             |          [] []     []         []                  |  7
-     jtag               |                    []                             |  3
-     jwhois             |          []        []                     []      | 13
-     kbd                |          []        []                             | 12
-     keytouch           |                    []                             |  4
-     keytouch-editor    |                                                   |  2
-     keytouch-keyboa... |                    []                             |  3
-     latrine            |          []        []                             |  8
-     ld                 |          []        []         []          []      |  8
-     leafpad            |          []        []         []          []      | 23
-     libc               |          []                   []          []      | 23
-     libexif            |                    []                             |  4
-     libextractor       |                    []                             |  5
-     libgpewidget       |                    []  []     []                  | 19
-     libgpg-error       |                    []                             |  4
-     libgphoto2         |             []                                    |  8
-     libgphoto2_port    |             []     []                     []      | 11
-     libgsasl           |                    []                             |  8
-     libiconv           |                    []                             |  7
-     libidn             |                    []         []                  | 10
-     lifelines          |                                                   |  4
-     lilypond           |                                                   |  2
-     lingoteach         |                    []                             |  6
-     lynx               |          [] []     []                             | 15
-     m4                 |                    []         []          []      | 18
-     mailutils          |             []                                    |  8
-     make               |          []        []         []                  | 20
-     man-db             |                    []                             |  6
-     minicom            |                    []                             | 14
-     mysecretdiary      |          []        []                             | 12
-     nano               |                    []                     []      | 17
-     nano_1_0           |          [] []     []                             | 18
-     opcodes            |          []        []                             | 10
-     parted             |          [] []                            []      | 10
-     pilot-qof          |                    []                             |  3
-     psmisc             |                    []                             | 10
-     pwdutils           |                    []                             |  3
-     python             |                                                   |  0
-     qof                |                    []                             |  4
-     radius             |             []                                    |  6
-     recode             |          []        []         []                  | 25
-     rpm                |          [] []     []                     []      | 14
-     screem             |                    []                             |  2
-     scrollkeeper       |          [] []     []                     []      | 26
-     sed                |          []        []                     []      | 22
-     sh-utils           |          []                                       | 15
-     shared-mime-info   |             []     []         []          []      | 24
-     sharutils          |          []        []                     []      | 23
-     shishi             |                                                   |  1
-     silky              |                    []                             |  4
-     skencil            |                    []                             |  7
-     sketch             |                                                   |  6
-     solfege            |                                                   |  2
-     soundtracker       |          []        []                             |  9
-     sp                 |          []                                       |  3
-     stardict           |             []     []         []          []      | 11
-     system-tools-ba... |    []    [] []     []     []  []          []      | 37
-     tar                |          [] []     []                     []      | 20
-     texinfo            |          []        []         []                  | 15
-     textutils          |          []                   []          []      | 17
-     tin                |                                                   |  1
-     tp-robot           |                    []         []          []      | 10
-     tuxpaint           |                    []  []                 []      | 16
-     unicode-han-tra... |                                                   |  0
-     unicode-transla... |                                                   |  2
-     util-linux         |          [] []     []                             | 20
-     vorbis-tools       |             []     []                             | 11
-     wastesedge         |                                                   |  1
-     wdiff              |          []        []                             | 22
-     wget               |          []        []                     []      | 19
-     xchat              |             []     []         []          []      | 29
-     xkeyboard-config   |          [] []     []                     []      | 11
-     xpad               |                    []         []          []      | 14
-                        +---------------------------------------------------+
-       77 teams           tg th tk tr uk ven vi  wa xh zh_CN zh_HK zh_TW zu
-      170 domains          0  1  1 77 39  0  136 10  1  48     5    54    0  2028
-
-   Some counters in the preceding matrix are higher than the number of
-visible blocks let us expect.  This is because a few extra PO files are
-used for implementing regional variants of languages, or language
-dialects.
-
-   For a PO file in the matrix above to be effective, the package to
-which it applies should also have been internationalized and
-distributed as such by its maintainer.  There might be an observable
-lag between the mere existence a PO file and its wide availability in a
-distribution.
-
-   If October 2006 seems to be old, you may fetch a more recent copy of
-this `ABOUT-NLS' file on most GNU archive sites.  The most up-to-date
-matrix with full percentage details can be found at
-`http://www.iro.umontreal.ca/contrib/po/HTML/matrix.html'.
-
-1.6 Using `gettext' in new packages
-===================================
-
-If you are writing a freely available program and want to
-internationalize it you are welcome to use GNU `gettext' in your
-package.  Of course you have to respect the GNU Library General Public
-License which covers the use of the GNU `gettext' library.  This means
-in particular that even non-free programs can use `libintl' as a shared
-library, whereas only free software can use `libintl' as a static
-library or use modified versions of `libintl'.
-
-   Once the sources are changed appropriately and the setup can handle
-the use of `gettext' the only thing missing are the translations.  The
-Free Translation Project is also available for packages which are not
-developed inside the GNU project.  Therefore the information given above
-applies also for every other Free Software Project.  Contact
-`translation@iro.umontreal.ca' to make the `.pot' files available to
-the translation teams.
-
diff --git a/contrib/cpio/AUTHORS b/contrib/cpio/AUTHORS
deleted file mode 100644
index 980c8f397b8..00000000000
--- a/contrib/cpio/AUTHORS
+++ /dev/null
@@ -1,6 +0,0 @@
-Authors of GNU cpio
-
-Phil Nelson 
-David MacKenzie 
-John Oleynick 
-Sergey Poznyakoff 
\ No newline at end of file
diff --git a/contrib/cpio/COPYING b/contrib/cpio/COPYING
deleted file mode 100644
index 5c95a60a711..00000000000
--- a/contrib/cpio/COPYING
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    
-    Copyright (C)   
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  , 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/contrib/cpio/ChangeLog b/contrib/cpio/ChangeLog
deleted file mode 100644
index 1307353cba8..00000000000
--- a/contrib/cpio/ChangeLog
+++ /dev/null
@@ -1,1781 +0,0 @@
-2007-06-08  Sergey Poznyakoff  
-
-	* configure.ac, NEWS: Version number 2.8
-	* bootstrap.conf: Update
-
-2007-06-07  Sergey Poznyakoff  
-
-	* NEWS: Update
-	* configure.ac: Raise version to 2.7.90
-	* doc/cpio.texi: Update
-	* src/extern.h (set_perms, set_file_times): Take file descriptor
-	as the first argument.
-	* src/util.c (set_perms): Take file descriptor
-	as the first argument and use fchmod/fchown if available.  Fixes
-	CAN-2005-1111.
-	* src/copyin.c, src/copyout.c, src/copypass.c: Update calls to
-	set_perms.
-	* src/makepath.c: Remove useless includes.
-	
-	* src/util.c (set_perms, stat_to_cpio): Use CPIO_UID and CPIO_GID
-	macros to set uid and gid
-	* src/main.c (process_args): Allow to use --owner in copy-out mode.
-	* THANKS: Add Mike Frysinger
-	
-2007-05-18  Sergey Poznyakoff  
-
-	* bootstrap: Update from tar repository
-	* doc/cpio.texi: Fix typo
-	* src/copyin.c (from_ascii): Bugfix: allow for empty fields
-	* src/copyout.c (process_copy_out): Fix memory leaks on
-	orig_file_name.
-	* src/copypass.c (process_copy_pass): symlink_error takes two
-	arguments.
-	* src/extern.h: Add missing includes.
-
-2006-12-18  Sergey Poznyakoff  
-
-	* README-cvs: New file
-	* lib/Makefile.tmpl, lib/bcopy.c, lib/mkdir.c, lib/strdup.c,
-	lib/strerror.c, lib/.cvsignore, po/.cvsignore,
-	po/Makevars: Removed
-	* lib/Makefile.am: New file
-	* po/POTFILES.in: Update
-	* bootstrap: Synch with tar.
-	* configure.ac: Update
-	* gnulib.modules: Add lchown, strerror
-	* src/Makefile.am: Update
-	* src/main.c, src/mt.c: Include rmt-command.h instead of localedir.h
-	* .cvsignore, doc/.cvsignore: Sort
-	
-	* src/util.c (sparse_write): Static.  Provide a forward
-	declaration. Define enum sparse_write_states inside the function.
-
-	* src/copyin.c (long_format): Use PRIuMAX for printing file size
-	* src/copyout.c (write_out_binary_header): Fix size conversion
-	* src/extern.h (tape_toss_input, warn_if_file_changed): Last
-	argument is off_t
-	* src/util.c (tape_toss_input, warn_if_file_changed): Last
-	argument is off_t
-	(warn_if_file_changed): Use ngettext
-
-2006-11-15  Sergey Poznyakoff  
-
-	* src/copypass.c: Fix setting output file permissions
-
-2006-11-13  Sergey Poznyakoff  
-
-	* doc/cpio.texi: Consistently use @option{} for displaying command
-	line options.
-	Fix formatting in "Invoking `cpio'" section
-	* src/main.c (process_args): Fix usage error diagnostics in
-	copy-pass mode.
-
-2006-10-24  Sergey Poznyakoff  
-
-	* src/copyout.c (process_copy_out): Add terminating zero to the
-	link_name.
-
-	* tests/symlink.at: New testcase
-	* tests/Makefile.am: New test symlink.at
-	* tests/inout.at: Add keywords
-	* tests/testsuite.at (AT_SKIP_TEST): New macro
-	New test symlink.at
-
-2006-10-21  Sergey Poznyakoff  
-
-	* configure.ac, NEWS: Version 2.7
-	* gnulib.modules: Add stdint
-	* src/util.c: Use STRINGIFY_BIGINT to display num_bytes
-
-2006-09-27  Sergey Poznyakoff  
-
-	* TODO: Update
-	* README-alpha: Update
-	* bootstrap: Imported from tar
-	* configure.ac: Require autoconf 2.59 and gettext 1.15
-	* gnulib.modules: add inttypes
-	* doc/cpio.texi: Minor fixes
-	* po/Makevars: Remove automatically generated file
-	* po/.cvsignore: Add Makevars
-	* lib/.cvsignore: Update
-	* src/copyin.c, src/copyout.c, src/copypass.c, src/cpio.h,
-	src/cpiohdr.h, src/defer.c, src/defer.h, src/extern.h,
-	src/global.c, src/main.c, src/makepath.c, src/tar.c,
-	src/util.c: Update copyright year. 
-
-2006-07-04  Sergey Poznyakoff  
-
-	* bootstrap (update_po): Fix single translation update
-	* lib/Makefile.tmpl: Initialize AM_CPPFLAGS
-	(noinst_HEADERS): Add system-ioctl.h
-
-	Start rewriting using a better suited internal representation for
-	the file meta-data.
-	
-	* src/cpiohdr.h (struct old_cpio_header): Remove unused fields
-	c_mtime, c_filesize and c_name.
-	(struct old_ascii_header): New data type
-	(struct new_ascii_header): New data type. Describes the header
-	structure, not its internal representation.
-	(struct cpio_file_stat): New data type. Describes internal
-	representation of a file metadata
-
-	* src/copyin.c (from_ascii): New function
-	Use cpio_file_stat for internal header representation.
-	* src/copyout.c: Use cpio_file_stat for internal header
-	representation. Among other things this fixes bug reported by
-	Peter Vrabec on Mar 2, 2006
-	(http://lists.gnu.org/archive/html/bug-cpio/2006-03/msg00000.html)
-	* src/copypass.c: Use cpio_file_stat for internal header
-	representation.
-	* src/tar.c: Likewise
-	* src/util.c: Likewise
-	* src/defer.c: Likewise
-	* src/defer.h: Likewise
-	* src/extern.h: Likewise
-	(from_ascii): New prototype
-	(LG_8,LG_16,FROM_OCTAL,FROM_HEX): New defines
-	* src/main.c: New command line option --HANG (hidden)
-
-2006-03-12  Sergey Poznyakoff  
-
-	* tests/Makefile.am (AM_CPPFLAGS): Define LOCALEDIR
-
-2006-02-18  Sergey Poznyakoff  
-
-	* gnulib.modules: Add stpcpy. Thanks Benigno B. Junior for
-	reporting.
-	* THANKS: Add Benigno B. Junior
-	* src/makepath.c: Fix indentation.
-
-2005-11-16  Sergey Poznyakoff  
-
-	* src/copyout.c (process_copy_out): Fix typo.
-
-2005-11-12  Sergey Poznyakoff  
-
-	* bootstrap: Minor fix
-	* src/copyout.c (write_out_header): Rewritten using separate
-	functions for each file format. Use to_ascii to convert numbers to
-	ascii representation. Check for overflows and report them if
-	appropriate. Return 0 if it is OK to proceed with archiving this
-	file, 1 otherwise. All callers updated.
-	* src/extern.h (write_out_header): Return int.
-
-2005-10-28  Sergey Poznyakoff  
-
-	* src/util.c: Include paxlib.
-	* bootstrap: If file `.bootstrap' exists in the cwd and is
-        readable, prepend its contents to the command line.
-
-	Fix Debian bug 335580:
-	
-	* src/copyout.c (read_for_checksum,write_out_header): CRC is a
-	32-bit unsigned value. Patch proposed by Jim Castleberry and
-	Peter Vrabec. 
-	* src/extern.h (crc): Change declaration
-	* src/global.c: Likewise
-	* src/tar.c (tar_checksum): Return unsigned int
-
-	* THANKS: Add Jim Castleberry
-	* NEWS: Updated
-	
-2005-09-30  Sergey Poznyakoff  
-
-	* src/copyout.c (process_copy_out): Discern between original and
-	(eventually fixed) file name (in tar terminology, `file name'
-	vs. `member name'.
-
-2005-09-08  Sergey Poznyakoff  
-
-	* gnulib.modules: Add utimens
-	* src/util.c (cpio_safer_name_suffix): Preserve ./ no matter what
-	the value of strip_leading_dots is.
-	(set_file_times): New function
-	* src/extern.h (set_file_times): New function
-	* src/copyin.c: Use set_file_times() to update file atime/mtime
-	* src/copyout.c: Likewise.
-	* src/copypass.c: Likewise.
-
-2005-05-25  Sergey Poznyakoff  
-
-	* src/copyin.c: Use cpio_safer_name_suffix() and CPIO_TRAILER_NAME
-	define instead of hardcoding the trailer file name.
-	* src/copyout.c: Likewise.
-	* src/cpio.h (CPIO_TRAILER_NAME): New define
-	* src/extern.h (cpio_safer_name_suffix): New proto
-	* src/tar.c: Use CPIO_TRAILER_NAME define instead of hardcoding
-	the trailer file name.
-	* src/util.c (cpio_safer_name_suffix): New function
-	(add_cdf_double_slashes): Add FIXME warning.
-	
-	* lib/fatal.c: New file
-	* lib/Makefile.tmpl (libcpio_a_SOURCES): Add fatal.c
-	* src/copyout.c: Use error reporting functions from paxlib
-	* src/makepath.c: Likewise
-	* src/mt.c: Likewise
-	* src/main.c (fatal_exit): Moved to lib/fatal.c
-
-2005-05-24  Sergey Poznyakoff  
-
-	* src/copyin.c (process_copy_in): Use safer_name_suffix no matter
-	what the value of no_abs_paths_flag. The function knows better
-	what to do in any case.
-	* src/copyout.c (process_copy_out): Honor no_abs_paths_flag.
-	* src/main.c (options): Minor fixes.
-
-2005-05-23  Sergey Poznyakoff  
-
-	* bootstrap (copy_files): Create destination directory if it does
-	not exist.
-	Preserve longlong.m4 as longlong_gl.m4 
-	* src/main.c: Include paxlib.h
-	
-2005-05-22  Sergey Poznyakoff  
-
-	* lib/.cvsignore: Updated
-	* gnulib.modules: Add hash
-	* doc/cpio.texi (Reports): New chapter
-	* lib/Makefile.tmpl: Add new paxutils files.
-	* po/POTFILES.in: Likewise
-	* src/copyin.c [!HAVE_LCHOWN] (lchown): Define to 0 to avoid
-	changing ownership of the target file.
-	(process_copy_in): Use safer_name_suffix()
-	* src/main.c (parse_opt): Handle new --absolute-filenames option.
-	(process_args): Updated
-	* src/util.c: Rewrite inode lookup/insertion functions using hash
-	module. 
-
-u2005-05-20  Sergey Poznyakoff  
-
-	* configure.ac: Raised version number to 2.6.90
-	* NEWS: Updated
-	* src/copyin.c: Use set_perms.
-	* src/copypass.c: Likewise.
-	* src/copyout.c (process_copy_out): Use stat_to_cpio() to convert
-	struct stat to struct new_cpio_header.
-	* src/defer.h: Remove legacy P_() stuff.
-	* src/dstring.c: Likewise
-	* src/extern.h: Likewise
-	* src/util.c (stat_to_cpio,set_perms): New functions
-	* doc/.cvsignore: Updated
-	* lib/.cvsignore: Updated
-	* tests/.cvsignore: Updated
-	* .cvsignore: Updated
-	* COPYING: Added to the repository
-
-2005-05-19  Sergey Poznyakoff  
-
-	* po/POTFILES.in: Add paxerror.c paxexit.c paxconvert.c
-
-	* bootstrap (copy_files): Accept optional third argument: a prefix
-	to be appended to destination file names.
-	Import paxutils/paxlib files.
-	* lib/Makefile.tmpl (libcpio_a_SOURCES): Add paxerror.c paxexit.c
-	paxconvert.c
-	* src/copyin.c: Use paxutils error reporting functions
-	* src/copyout.c: Likewise
-	* src/copypass.c: Likewise
-	* src/util.c: Likewise. Add missing includes
-	* src/main.c (USAGE_ERROR): Removed
-	(CHECK_USAGE,parse_opt,process_args): Use error() instead of USAGE_ERROR
-	(fatal_exit): New function
-	* src/tar.c (is_tar_filename_too_long): Removed unused variable
-
-	* Makefile.am, configure.ac, doc/Makefile.am,
-	doc/cpio.texi, doc/gendocs_template, headers/Makefile.am,
-	headers/fnmatch.h, lib/Makefile.tmpl, lib/mkdir.c,
-	lib/strdup.c, lib/strerror.c, src/Makefile.am,
-	src/copyin.c, src/copyout.c, src/copypass.c, src/cpio.h,
-	src/cpiohdr.h, src/defer.c, src/defer.h, src/dstring.c,
-	src/dstring.h, src/extern.h, src/filemode.c,
-	src/filetypes.h, src/global.c, src/idcache.c,
-	src/main.c, src/makepath.c, src/mt.c, src/tar.c,
-	src/tar.h, src/tarhdr.h, src/userspec.c, src/util.c,
-	tests/Makefile.am, tests/inout.at, tests/testsuite.at,
-	tests/version.at: Updated FSF postal mail address.
-
-	* bootstrap: Port recent changes from tar bootstrap.
-	* gnulib.modules: New file
-	* tests/Makefile.am (genfile_SOURCES,LDADD): Updated
-
-	* THANKS: Updated
-	* configure.ac: Remove check for gethostname, it is never used.
-	Remove check for setsockopt, it is provided by paxutils.
-
-	Fix LFS support issues. Proposed by Peter Vrabec and Dmitry V. Levin
-
-	* src/extern.h (copy_files_tape_to_disk, copy_files_disk_to_tape,
-	copy_files_disk_to_disk): Change num_bytes argument type from
-	long to off_t.
-	* src/util.c (copy_files_tape_to_disk, copy_files_disk_to_tape,
-	copy_files_disk_to_disk, disk_fill_input_buffer,
-	write_nuls_to_file): Likewise.
-	(write_nuls_to_file, copy_files_disk_to_tape,
-	copy_files_disk_to_disk): Handle `off_t num_bytes' properly.
-
-	* src/util.c (find_inode_file): Fix typos causing function to
-	occasionally miss inodes and, therefore, to copy out the same
-	(hard-linked) file several times to archive. Proposed by Brian
-	Mays.
-
-2005-03-24  Sergey Poznyakoff  
-
-	* src/main.c (process_args): Fixed discrepancy I have been
-	overlooking so far: cpio still does not handle --sparse option
-	the same way tar is handling it. --sparse is allowed in copy-in
-	and copy-pass modes, just as docs say it. Thanks Dmitry Levin.
-	* THANKS: Updated
-
-2005-03-21  Sergey Poznyakoff  
-
-	* src/util.c (disk_buffered_write): Fix typo introduced
-	2005-01-11.
-	* src/main.c (process_args): Fixed error message
-
-2005-01-31  Sergey Poznyakoff  
-
-	* src/main.c (main): Remove umask(0). Fixes CAN-1999-1572.
-	[__TURBOC__,__EMX__]: Removed
-	* src/copypass.c (process_copy_pass): Set umask 0
-	* src/copyin.c (process_copy_in): Likewise
-	* src/util.c (open_archive): Use MODE_RW.
-	
-2005-01-11  Sergey Poznyakoff  
-
-	* doc/gendocs_template: Template file for gendocs.sh.
-	* doc/Makefile.am: Use gendocs.sh to generate webdocs.
-	* doc/cpio.texi: Updated.
-
-	* src/copyin.c: Use memset instead of bzero, memmove
-	(or memcpy, if appropriate), instead of bcopy, and
-	strchr/strrchr instead of index/rindex.
-	* src/copypass.c: Likewise.
-	* src/main.c: Likewise.
-	* src/makepath.c: Likewise.
-	* src/tar.c: Likewise.
-	* src/util.c: Likewise.
-	(write_nuls_to_file): Made extern. All callers updated
-	
-	* src/copyout.c: Likewise. Use write_nuls_to_file instead
-	of explicitely accessing zeros_512
-	* src/userspec.c: Likewise.
-	Rename isnumber to isnumber_p. Proposed by
-	Albert Chin
-	* src/extern.h (zeros_512): Removed
-	(write_nuls_to_file): New function
-	* src/global.c (zeros_512): Removed
-	
-2005-01-06  Sergey Poznyakoff  
-
-	* bootstrap: Add 'fileblocks' gnulib module
-	Create paxutils.m4
-	* configure.ac: Call cpio_PAXUTILS
-	* src/main.c: Remove ifdef around setlocale
-	* src/mt.c: Likewise
-
-2004-12-21  Sergey Poznyakoff  
-
-	* configure.ac: New option --enable-mt
-	Check for locale.h
-	* doc/cpio.info: Removed
-	* src/mt.c (main): Use argmatch_invalid()
-
-2004-12-20  Sergey Poznyakoff  
-
-	Released version 2.6. Sources up to this point are tagged
-	release_2_6.
-
-	* configure.ac: Raised version number to 2.6
-	* NEWS: Likewise
-	* bootstrap (update_po): Give -r to wget. Always remove index.html
-	Ignore alloca-opt module (it duplicates alloca)
-
-2004-11-23  Sergey Poznyakoff  
-
-	* src/main.c (enum cpio_options): Bugfix: Initialize first enum
-	value to 256.
-	* bootstrap: Add unlocked-io
-	* headers/argp.h: Removed
-	* headers/getopt.h: Removed
-	* headers/Makefile.am: Updated
-
-2004-10-14  Sergey Poznyakoff  
-
-	* src/copyout.c: Add trailing slash to directory names in
-	ustar format.
-	* src/makepath.c: Removed redeclaration of error().
-	* src/tar.c: Fixed deviations from POSIX.1-1988:
-	Properly split long file names. Fill in octal fields with zeros,
-	not spaces. Save only protection modes, not the whole mode.
-	
-	* NEWS: Updated
-
-2004-09-08  Sergey Poznyakoff  
-
-	* NEWS: Updated
-	* TODO: Updated
-	* bootstrap: Install po files by default
-	* po/LINGUAS: Removed. File is generated automatically
-	* po/.cvsignore: Updated
-	* src/copyin.c: Implemented --to-stdout option
-	* src/copyout.c: Display the annoying 'truncating inode number'
-	message only if the user wishes it.
-	* src/extern.h: Added new globals.
-	* src/global.c: Likewise.
-
-	* src/main.c: Added support for --to-stdout and --warning options
-	* src/tar.c (read_in_tar_header): Use warn_junk_bytes()
-	* src/util.c (create_all_directories): Use dir_name.
-
-	* configure.ac: Added support for the test suite
-	* Makefile.am: Likewise
-
-	* tests: New directory
-	* tests/.cvsignore: New file
-	* tests/Makefile.am: New file
-	* tests/testsuite.at: New file
-	* tests/inout.at: New file
-	* tests/version.at: New file
-	* tests/atlocal.in: New file
-	
-2004-09-07  Sergey Poznyakoff  
-
-	* src/main.c (process_args): Bugfix. Allow extra arguments
-	in copy_in mode.
-	* src/util.c (write_nuls_to_file): Use buffered I/O. All
-	callers changed. Thanks Matthew Braithwaite 
-	for noticing.
-	Bugfix: extra_bytes was mistakenly used instead of blocks.
-	* THANKS: Added Matthew Braithwaite.
-
-2004-09-06  Sergey Poznyakoff  
-
-	Started merging with tar into paxutils. Sources before
-	this point are tagged alpha-2_50_90.
-	
-	* bootstrap: New file
-	* autogen.sh: Removed
-	* Makefile.am: Updated
-	* NEWS: Updated
-	* README-alpha: Updated
-	* configure.ac: Updated
-	* doc/cpio.1: Updated
-	* po/POTFILES.in: Updated
-
-	* src/Makefile.am: Updated
-	* src/error.c: Removed
-	* src/dirname.c: Likewise
-	* src/xmalloc.c: Likewise
-	* src/stripslash.c: Likewise
-	* src/xstrdup.c
-	* src/gettext.h: Likewise
-	* src/system.h: Likewise
-	* src/rmt.h: Likewise
-	* src/getopt.c: Likewise
-	* src/getopt1.c: Likewise
-	* src/bcopy.c: Likewise
-	* src/fnmatch.c: Likewise
-	* src/mkdir.c: Likewise
-	* src/strdup.c: Likewise
-	* src/argp-ba.c: Likewise
-	* src/argp-eexst.c: Likewise
-	* src/argp-fmtstream.c: Likewise
-	* src/argp-fs-xinl.c: Likewise
-	* src/argp-help.c: Likewise
-	* src/argp-parse.c: Likewise
-	* src/argp-pv.c: Likewise
-	* src/argp-pvh.c: Likewise
-	* src/argp-xinl.c: Likewise
-	* src/pin.c: Likewise
-	* src/alloca.c: Likewise
-	* src/argmatch.c: Likewise
-	* src/rmt.c: Likewise
-	* src/rtapelib.c: Likewise
-	* src/strerror.c: Likewise
-	
-	* src/copyin.c: Switched to ANSI C (sigh)
-	* src/copyout.c: Likewise
-	* src/copypass.c: Likewise
-	* src/defer.c: Likewise
-	* src/defer.h: Likewise
-	* src/dstring.c: Likewise
-	* src/dstring.h: Likewise
-	* src/extern.h: Likewise
-	* src/filemode.c: Likewise
-	* src/global.c: Likewise
-	* src/idcache.c: Likewise
-	* src/main.c: Likewise
-	* src/makepath.c: Likewise
-	* src/mt.c: Likewise
-	* src/tar.c: Likewise
-	* src/userspec.c: Likewise
-	* src/util.c: Likewise
-
-	* lib: New directory
-	* lib/Makefile.tmpl: New file
-	* lib/bcopy.c: Moved from ../src
-	* lib/mkdir.c: Likewise.
-	* lib/strdup.c: Likewise.
-	* lib/strerror.c: Likewise.
-	
-2004-08-30  Sergey Poznyakoff  
-
-	* Makefile.am: Added headers to SUBDIRS.
-	* configure.ac: Check for AC_SYS_LARGEFILE.
-	Use AC_CONFIG_LINKS to provide for fnmatch.h and getopt.h on
-	the systems where these are missing
-	Check for argp and replace it if necessary.
-	* src/Makefile.am: Updated
-	* src/fnmatch.h: Moved to headers/
-	* src/getopt.h: Likewise.
-	* src/main.c: Option parsing rewritten using argp. Improved
-	option consistency checking.
-	* src/rmt.c: Include getopt.h
-
-	* src/argp-ba.c: New file
-	* src/argp-eexst.c: New file
-	* src/argp-fmtstream.c: New file
-	* src/argp-fs-xinl.c: New file
-	* src/argp-help.c: New file
-	* src/argp-parse.c: New file
-	* src/argp-pv.c: New file
-	* src/argp-pvh.c: New file
-	* src/argp-xinl.c: New file
-	* src/pin.c: New file
-
-	* headers: New directory
-	* headers/Makefile.am: New file
-	* headers/getopt.h: New file
-	* headers/argp.h: New file
-	* headers/fnmatch.h: New file
-	* headers/.cvsignore: New file
-	
-2004-03-02  Sergey Poznyakoff  
-
-	* src/util.c (copy_files_disk_to_disk): Bugfix. If a file
-	grew n bytes in copy-pass mode, these n bytes got prepended
-	to the contents of all subsequent files. Fix provided by
-	Holger Fleischmann 
-	* THANKS: Added Holger Fleischmann.
-
-2004-02-27  Sergey Poznyakoff  
-
-	* src/makepath.c: Remove unneded typedefs
-	
-	* src/copyin.c: Remove __MSDOS__ conditionals
-	* src/copyout.c: Likewise
-	* src/copypass.c: Likewise
-	* src/main.c: Likewise
-	* src/tar.c: Likewise
-	* src/util.c: Likewise
-	
-2004-02-27  Sergey Poznyakoff  
-	
-	Changed from flat to deep package layout. Added the framework
-	for NLS support.
-	
-	* .cvsignore: Updated
-	* Makefile.am: Updated
-	* configure.ac: Updated
-	* NEWS: Updated
-	* README-alpha: Updated
-	* THANKS: Updated
-
-	* autogen.sh: New file
-	
-	* alloca.c: Moved to src
-	* argmatch.c: Likewise
-	* bcopy.c: Likewise
-	* dstring.h: Likewise
-	* copyin.c: Likewise
-	* copyout.c: Likewise
-	* copypass.c: Likewise
-	* cpio.h: Likewise
-	* cpiohdr.h: Likewise
-	* defer.c: Likewise
-	* defer.h: Likewise
-	* dirname.c: Likewise
-	* dstring.c: Likewise
-	* dstring.h: Likewise
-        * error.c: Likewise
-        * extern.h: Likewise
-        * filemode.c: Likewise
-        * filetypes.h: Likewise
-        * fnmatch.c: Likewise
-        * fnmatch.h: Likewise
-        * getopt.c: Likewise
-        * getopt.h: Likewise
-        * getopt1.c: Likewise
-        * global.c: Likewise
-        * idcache.c: Likewise
-        * main.c: Likewise
-        * makepath.c: Likewise
-        * mkdir.c: Likewise
-        * mt.c: Likewise
-        * rmt.c: Likewise
-        * rmt.h: Likewise
-        * rtapelib.c: Likewise
-        * safe-stat.h: Likewise
-        * strdup.c: Likewise
-        * strerror.c: Likewise
-        * stripslash.c: Likewise
-        * system.h: Likewise
-	* tar.c: Likewise
-	* tar.h: Likewise
-	* tarhdr.h: Likewise
-	* userspec.c: Likewise
-	* util.c: Likewise
-	* xmalloc.c: Likewise
-	* xstrdup.c: Likewise
-
- 	* cpio.1: Moved to doc
-	* cpio.texi: Likewise
-        * mt.1: Likewise
-
-	* src: New directory
-        * src/.cvsignore: New file
-        * src/Makefile.am: Likewise
-        * src/alloca.c: Likewise
-        * src/argmatch.c: Likewise
-        * src/bcopy.c: Likewise
-        * src/copyin.c: Likewise
-        * src/copyout.c: Likewise
-        * src/copypass.c: Likewise
-        * src/cpio.h: Likewise
-        * src/cpiohdr.h: Likewise
-        * src/defer.c: Likewise
-        * src/defer.h: Likewise
-        * src/dirname.c: Likewise
-        * src/dstring.c: Likewise
-        * src/dstring.h: Likewise
-        * src/error.c: Likewise
-        * src/extern.h: Likewise
-        * src/filemode.c: Likewise
-        * src/filetypes.h: Likewise
-        * src/fnmatch.c: Likewise
-        * src/fnmatch.h: Likewise
-        * src/getopt.c: Likewise
-        * src/getopt.h: Likewise
-        * src/getopt1.c: Likewise
-        * src/gettext.h: Likewise
-        * src/global.c: Likewise
-        * src/idcache.c: Likewise
-        * src/main.c: Likewise
-        * src/makepath.c: Likewise
-        * src/mkdir.c: Likewise
-        * src/mt.c: Likewise
-        * src/rmt.c: Likewise
-        * src/rmt.h: Likewise
-        * src/rtapelib.c: Likewise
-        * src/safe-stat.h: Likewise
-        * src/strdup.c: Likewise
-        * src/strerror.c: Likewise
-        * src/stripslash.c: Likewise
-        * src/system.h: Likewise
-        * src/tar.c: Likewise
-        * src/tar.h: Likewise
-        * src/tarhdr.h: Likewise
-        * src/userspec.c: Likewise
-        * src/util.c: Likewise
-	* src/xmalloc.c: Likewise
-	* src/xstrdup.c: Likewise
-
-	* doc: New directory
-	* doc/.cvsignore: New file
-	* doc/Makefile.am: New file
-	* doc/cpio.1: New file
-	* doc/cpio.info: New file
-	* doc/cpio.texi: New file
-	* doc/mt.1: New file
-
-	* po: New directory
-	* po/.cvsignore: New file
-	* po/LINGUAS: New file
-	* po/Makevars: New file
-	* po/POTFILES.in: New file
-	
-2003-11-28  Sergey Poznyakoff  
-
-	* configure.ac: Added various checks
-	* Makefile.am (rmt_LDADD): Added.
-	* error.c: Updated
-	* rmt.c: Removed useless private_errstring
-	* system.h: Updated
-	* userspec.c: Changed the way of handling declared vs. undeclared
-	system calls.
-	* strerror.c: New file. Borrowed from GNU Radius.
-
-	* copyin.c: Removed kludgy declaration of delayed_seek_count.
-	* copypass.c: Likewise
-	* extern.h: Declare delayed_seek_count.
-	* mkdir.c: Fixed handling of undeclared errno
-	* mt.c: Likewise
-	* util.c: Likewise
-	* rtapelib.c: Likewise
-	
-2003-11-28  Sergey Poznyakoff  
-
-	* TODO: New file
-
-	* README-alpha: New file
-	* Makefile.am: Require at least version 1.7.1
-	* configure.ac: Check for locale.h
-	* main.c (main): Call setlocale. Thanks
-	Mitsuru Chinen 	for the patch.
-	* THANKS: Updated
-	
-2003-11-21  Sergey Poznyakoff  
-
-	* configure.ac: Added to the repository
-	* Makefile.am: Likewise
-	* NEWS: Likewise
-	* README: Likewise
-	* AUTHORS: Likewise
-	* .cvsignore: Likewise
-	
-	* configure.in: Removed
-	* Makefile.in: Removed
-	* makefile.pc: Removed
-	* configure: Removed
-	
-	* alloca.c: Added to the repository
-	* argmatch.c: Likewise
-	* bcopy.c: Likewise
-	* cpio.h: Likewise
-	* cpiohdr.h: Likewise
-	* defer.c: Likewise
-	* defer.h: Likewise
-	* dirname.c: Likewise
-	* dstring.c: Likewise
-	* dstring.h: Likewise
-	* error.c: Likewise
-	* filemode.c: Likewise
-	* filetypes.h: Likewise
-	* fnmatch.c: Likewise
-	* fnmatch.h: Likewise
-	* getopt.c: Likewise
-	* getopt.h: Likewise
-	* getopt1.c: Likewise
-	* idcache.c: Likewise
-	* mkdir.c: Likewise
-	* rmt.h: Likewise
-	* rtapelib.c: Likewise
-	* safe-stat.h: Likewise
-	* strdup.c: Likewise
-	* stripslash.c: Likewise
-	* tar.c: Likewise
-	* tar.h: Likewise
-	* tarhdr.h: Likewise
-	* xmalloc.c: Likewise
-	* xstrdup.c: Likewise
-	
-	* makepath.c: Updated
-	* mt.c: Likewise.
-	* rmt.c: Likewise.
-	* util.c: Likewise.
-	* copyin.c: Likewise.
-	* copyout.c: Likewise.
-	* copypass.c: Likewise.
-	* global.c: Likewise.
-	* main.c: Likewise.
-	
-Thu Jun 13 20:14:48 2002  John Oleynick  (juo@gnu.org)
-	* copyin.c:  Strip leading / on absolute filenames after
-	comparing to the list of files specified on the command line
-	(instead of before).  Problem reported by Jeff Holt.
-	* Version 2.5 released.
-
-Thu Jun 13 00:20:30 2002  John Oleynick  (juo@gnu.org)
-	* Makefile.in:  Fixed problem of looking in srcdir for info files.
-	Bug reported by Mike Castle.
-	* cpio.texi:  Fixed typo.  Problem reported by Fabrice Bauzac.
-
-Sun Jan 13 18:45:02 2002  John Oleynick  (juo@gnu.org)
-	* copyin.c:  Fixed a problem skipping files with multiple links
-	in a newc or CRC format archive.  If the file with the shared copy
-	of the data was skipped, but other links were not skipped, the
-	other links were created as empty files.  Bug reported by 
-	Hendrik-Jan Thomassen.
-
-Thu Dec  6 20:05:10 2001  John Oleynick  (juo@gnu.org)
-	* mt.c, mt.1:  Merged Debian --rsh-command option and -V fix.
-	* copyout.c, copypass.c, util.c, extern.h:  Modified to warn
-	  if a file grows or its mtime is changed while it is being
-	  copied.
-
-Wed Dec  6 00:02:04 2001  John Oleynick  (juo@gnu.org)
-	* Many files:  Updated FSF's address in copyright notices.
-
-Wed Aug 29 23:57:05 2001  John Oleynick  (juo@gnu.org)
-	* Many files:  Numerous fixes from Debian, Red Hat and SuSE
-	GNU/Linux distributions.
-
-Tue Jan 16 19:03:05 1996  John Oleynick  (juo@wombat.gnu.ai.mit.edu)
-	* util.c: An I/O error reading a file would cause the last byte
-	of the next file to be corrupted in the archive.  Thanks to a
-	buggy NT NFS server for pointing out this problem.
-	* Version 2.4.2 released.
-
-Tue Jan  9 23:19:37 1996  John Oleynick  (juo@wombat.gnu.ai.mit.edu)
-	* copyout.c: missed 1 part of last bug fix.
-
-Mon Jan  8 16:49:01 1996  John Oleynick  (juo@wombat.gnu.ai.mit.edu)
-	* copyout.c, copypass.c: Use result of readlink() as length
-	of link name instead of size from lstat().  On some OS's lstat() 
-	doesn't return the true length in size.  Bug reported by
-	Robert Joop (rj@rainbow.IN-berlin.DE).
-
-Wed Dec 20 10:52:56 1995  John Oleynick  (juo@wombat.gnu.ai.mit.edu)
-	* rmt.c:  Added temporary kludge so make rmt will work on Linux.
-	* configure.in:  Only define HAVE_UTIME_H if utime.h declares
-	struct utimbuf.
-	* Makefile.in:  Change prefix, exec_prefix and bindir to get their
-	values from configure.  Added cpio.info to DISTFILES.
-	* cpio.texi:  Added INFO-DIR-ENTRY.
-	* Version 2.4.1 released.
-
-Wed Nov 22 19:37:05 1995  John Oleynick  (juo@wombat.gnu.ai.mit.edu)
-        * cpio.texi:  Updated release date and FSF's address.
-        * NEWS: Listed major new features for 2.4.
-	* mt.c, mt.1: Added seek and fsfm commands.
-	* Version 2.4 released.
-
-Tue Jun 27 19:14:27 1995  John Oleynick  (juo@wombat.gnu.ai.mit.edu)
-        * configure.in: fixed for new autoconf.  Added check to make
-	sure fnmatch() works.
-        * Makefile.in: changed realclean to maintainer-clean.  Added
-	support to handle fnmatch separate from other LIBOBJS.
-        * cpio.texi:  More changes for 2.4.
-
-Wed Dec 14 16:14:27 1994  John Oleynick  (juo@wombat.gnu.ai.mit.edu)
-	* copypass.h:  When given the -a option, set the access time of
-	the copy to be the access time of the original (instead of the
-	modification time of the original).  Reported by
-	karney@pppl.gov (Charles Karney).
-	* cpio.texi:  Updated with changes for 2.4.
-
-Wed Nov  3 18:18:07 1994  John Oleynick  (juo@wombat.gnu.ai.mit.edu)
-	* safe-stat.h, Makefile.in:  New file used by mkdir.c.  This will go
-	away when we get the real safe-xstat.[ch]in for mkdir.c.
-	* main.c:  Don't mention [--null] twice in -p's usage message.
-	Changed --no-absolute-paths to --no-absolute-filenames.
-	* cpio.1:  Updated man page with new features.
-	* cpio.texi, texinfo.tex, Makefile.in:  Added texi documentation
-	from Robert Carleton (rbc@gnu.ai.mit.edu).
-
-Mon Oct  3 00:46:30 1994  John Oleynick  (juo@wombat.gnu.ai.mit.edu)
-	* makefile.pc, system.h:  Changes to compile with Borland C++ 4.0.
-
-Thu Sep 29 22:15:50 1994  John Oleynick  (juo@wombat.gnu.ai.mit.edu)
-	* makepath.c: Don't #define index if it is already #defined.
-
-	* mt.c:  Check for __hpux defined instead of __hpux__.  Reported
-	by ericb@lsid.hp.com (Eric Backus).
-
-Thu Sep 29 11:21:31 1994  John Oleynick  (juo@wombat.gnu.ai.mit.edu)
-	* extern.h, util.c, copyout.c, copypass.c, main.c, global.c:
-	Never mind --ignore-disk-input-errors flag, we'll just always
-	do that, like tar.
-
-	* global.c, extern.h, main.c, copyin.c, copyout.c, copypass.c:
-	Added --quiet flag to supress printing number of blocks copied.
-
-	* global.c, extern.h:  If compiled with gcc, make input_bytes
-	and output_bytes `long long' instead of `long'.  We need more
-	than 32 bits to keep track of the number of bytes copied to
-	and from tape drives that hold more than 4Gbytes.
-
-	* util.c, copyin.c, main.c, global.c, extern.h:  Added
-	--only-verify-crc flag to read a CRC format archive and verify
-	its contents' CRCs.
-
-	* copyout.c:  Fixed problem with creating oldc format archives
-	on machines with 16 bit ints.  Reported by mpoole@cix.compulink.co.uk
-	(Martin Poole).
-
-	* mt.c: Need to open tape WR_ONLY for erase command (and probably
-	others?).  Reported by robert@hst.e.technik.uni-kl.de (Robert
-	Vogelgesan).  Accept `eject' as a synonym for `offline'.  Accept
-	`-t' as a synonym for `-f' (to be compatible with HPUX mt, which 
-	only accepts `-t').
-
-Wed Sep 28 12:01:55 1994  John Oleynick  (juo@wombat.gnu.ai.mit.edu)
-	* extern.h, global.c, main.c, util.c: only write sparse files
-	when given --sparse flag.
-	* extern.h, util.c, copyout.c, copypass.c, main.c, global.c:
-	Added support for --ignore-disk-input-errors flag.
-
-Wed Aug 24 12:55:38 1994  David J. MacKenzie  (djm@churchy.gnu.ai.mit.edu)
-
-	* configure.in: Replace calls to AC_REMOTE_TAPE and AC_RSH
-	with equivalent code, since those macros are going away.
-
-Sun Feb 13 00:56:48 1994  John Oleynick  (juo@goldman.gnu.ai.mit.edu)
-	* extern.h, global.c, main.c, util.c:  Added code to 
-	tape_buffered_peek() to properly handle large, corrutped 
-	archives, without overrunning the allocated buffer and
-	dumping core.  Also changed the way the input and output 
-	buffers are allocated in initialize_buffers().
-	
-Tue Jan 25 01:04:32 1994  John Oleynick  (juo@goldman.gnu.ai.mit.edu)
-	* copyin.c, copyout.c, copypass.c, extern.h, main.c, tar.c, util.c:
-	Redid i/o buffer code.  Previously, the same routines buffered input and
-	output for accessing the archive and the filesystem.  Now there are
-	separate routines for buffering input and output and for buffering the
-	archive and the filesystem.  This simplifies much of the buffer code
-	(e.g., only input from the archive has to check for end of tape and
-	allow the tape to be changed, only output to the filesystem has to
-	handle byte and word swapping, etc.; previously one routine had to
-	handle all of these special cases) This is how the routines got split
-	and renamed (old name -> new name):
-
-		clear_rest_of_block -> tape_clear_rest_of_block
-		copy_files -> copy_files_tape_to_disk
-		    "      -> copy_files_disk_to_disk
-		    "      -> copy_files_disk_to_tape
-		copy_buf_out -> disk_buffered_write
-		    "        -> tape_buffered_write
-		copy_in_buf -> tape_buffered_read
-		empty_output_buffer -> tape_empty_output_buffer
-		    "               -> disk_empty_output_buffer
-		fill_input_buffer -> tape_fill_input_buffer
-		    "             -> disk_fill_input_buffer
-		pad_output -> tape_pad_output
-		peek_in_buf -> tape_buffered_peek
-		skip_padding -> tape_skip_padding
-		toss_input -> tape_toss_input
-
-	* extern.h, global.c, main.c, util.c:  Added support for
-	writing sparse files.
-
-Tue Dec 28 23:01:36 1993  John Oleynick  (juo@goldman.gnu.ai.mit.edu)
-	* util.c, system.h, makepath.c, extern.h: don't define chown() 
-	and don't typedef uid_t and gid_t if we are being compiled
-	by DJGPP.
-
-	* copyin.c, extern.h, global.c, main.c:  Added support for
-	--rename-batch-file.
-	
-	* copyin.c, copyout.c, extern.h:  Cleaned up to pass gcc -Wall.
-
-Wed Dec 22 02:17:44 1993  John Oleynick  (juo@goldman.gnu.ai.mit.edu)
-
-	* makepath.c, copypass.c, copyin.c:  If cpio was creating a
-	directory that contained `.' in the pathname (e.g. `foo/./bar'),
-	it would complain that it could not create `.', since it already
-	exists.  From schwab@issan.informatik.uni-dortmund.de (Andreas
-	Schwab).
-
-	* mt.c:  Added "eject" as a synonym for "offline".
-
-	* util.c:  Slight modification to when we lseek with
-	BROKEN_LONG_TAPE_DRIVER (do it every 1Gb, instead 
-	of every 2Gb).
-
-	* copyin.c, global.c, extern.h:  Added --no-absolute-paths option, 
-	to ignore absolute paths in archives.
-
-Tue Dec 21 01:30:59 1993  John Oleynick  (juo@goldman.gnu.ai.mit.edu)
-
-	* util.c:  Fix for copying new_media_message_after_number.  From
-	Christian.Kuehnke@arbi.informatik.uni-oldenburg.de (Christian
-	Kuehnke).
-
-Thu Jul 29 20:35:57 1993  David J. MacKenzie  (djm@wookumz.gnu.ai.mit.edu)
-
-	* Makefile.in (config.status): Run config.status --recheck, not
-	configure, to get the right args passed.
-
-Mon Jul 19 23:01:00 1993  David J. MacKenzie  (djm@churchy.gnu.ai.mit.edu)
-
-	* Makefile.in (libdir): Use standard GNU value --
-	$(exec_prefix)/lib, not /etc.
-	(.c.o): Put CFLAGS last.
-
-Thu Jul  8 19:43:39 1993  David J. MacKenzie  (djm@goldman.gnu.ai.mit.edu)
-
-	* Makefile.in: Add rules for remaking Makefile, configure,
-	config.status. 
-
-Mon Jul  5 14:54:08 1993  John Oleynick  (juo@spiff.gnu.ai.mit.edu)
-
-	* cpio.1:  Updated man page for 2.3.
-	* Makefile.in:  Create distribution with .gz extension, instead of .z.
-
-Tue Jun 29 18:54:37 1993  John Oleynick  (juo@goldman.gnu.ai.mit.edu)
-
-	* Makefile.in: Added installdirs target (using mkinstalldirs).
-	* Added mkinstalldirs script.
-	* main.c, mt.c:  Added --help option.  Changed usage() to
-	take a stream and exit value (so --help can print on stdout
-	and return a 0 exit status).
-	* extern.h:  Removed usage()'s prototype (it was out of date,
-	and only used in main.c).
-
-Thu May  6 00:22:22 1993  John Oleynick  (juo@hal.gnu.ai.mit.edu)
-
-	* cpio.1:  Added hpbin and hpodc.
-
-Tue May  4 00:32:29 1993  John Oleynick  (juo@hal.gnu.ai.mit.edu)
-
-	* copyin.c (process_copy_in), copypass.c (process_copy_pass):  When
-	deleting an existing file, if the file is a directory, use rmdir()
-	instead of unlink().
-
-Thu Apr 29 14:43:56 1993  John Oleynick  (juo@goldman.gnu.ai.mit.edu)
-
-	* tar.c (read_in_tar_header):  Clear non-protection bits from
-	mode, in case tar has left some device bits in there.
-
-Wed Apr 28 10:36:53 1993  John Oleynick  (juo@goldman.gnu.ai.mit.edu)
-
-	* util.c: Added code to try and work around broken tape drivers
-	that have problems with tapes > 2Gb.
-
-	* copyout.c (process_copy_out): Pass file_hdr to 
-	writeout_other_defers() and add_link_defer() by reference, 
-	not by value.
-
-	* copyin.c (process_copy_in): Pass file_hdr to defer_copyin()
-	and create_defered_links() by reference, not by value.
-
-	* defer.c: include  (to build on BSD 4.3 on HP300)
-
-Fri Apr 16 18:01:17 1993  John Oleynick  (juo@goldman.gnu.ai.mit.edu)
-
-	* mt.c, util.c: Include  if HAVE_SYS_MTIO_H is 
-	defined, not HAVE_MTIO_H.
-
-Wed Apr 14 17:37:46 1993  John Oleynick  (juo@goldman.gnu.ai.mit.edu)
-
-	* util.c: Include  if HAVE_SYS_IO_TRIOCTL_H
-	is defined.
-
-	* mt.c: Only include  if HAVE_SYS_MTIO_H is defined.
-
-Fri Apr  2 13:09:11 1993  John Oleynick  (juo@goldman.gnu.ai.mit.edu)
-
-	* configure.in: Added fnmatch to AC_REPLACE_FUNCS.  Added
-	sys/io/trioctl.h to AC_HAVE_HEADERS.
-
-	* Makefile.in: Removed fnmatch.o from OBJS.
-
-	* copyin.c: Only include "fnmatch.h" if FNM_PATHNAME isn't
-	defined yet.
-
-	* mt.c: Include  if HAVE_SYS_IO_TRIOCTL_H is
-	defined.
-
-Mon Mar 29 17:04:06 1993  John Oleynick  (juo@hal.gnu.ai.mit.edu)
-
-	* Many changes for supporting HPUX Context Dependent Files;
-	also some bug fixes to fix problems with multiply (hard) linked
-	device files; minor changes to support HPUX format archives
-	(slightly broken?) System V.4 posix tar archives and HPUX
-	posix tar archives.
-
-	* Makefile.in: New files defer.o, defer,c and defer.h; added
-	-DSYMLINK_USES_UMASK and -DHPUX_CDF comments; changed dist rule
-	to use gzip with tar, instead of compress.
-
-	* copyin.c: changes for new arf_hpbinary and arf_hpascii formats;
-	HPUX CDF's; DEBUG_CPIO; fixes to properly handle multiple
-	links in newc and crc format archives (new routines defer_copyin(),
-	create_defered_links(), create_final_defers()); move most
-	multiple (hard) link code to new routines link_name() and
-	link_to_maj_min_ino(); use new macro UMASKED_SYMLINK instead of
-	symlink().
-
-	* copyout.c: fixes to properly handle multiple links in newc
-	and crc format archives (new routines last_link(), 
-	count_defered_links_to_dev_ino(), add_link_defer(),
-	writeout_other_defers(), writeout_final_defers(),
-	writeout_defered_file()); support for new arf_hpbinary and
-	arf_hpascii formats; support for HPUX CDF's.
-
-	* copypass.c: move most multiple link code to new routines
-	link_name() and link_to_maj_min_ino(); use new macro UMASKED_SYMLINK
-	instead of symlink(); support for HPUX CDF's.
-
-	* extern.h: added arf_hpascii and arf_hpbinary archive enum types;
-	added debug_flag.
-
-	* global.c: added debug_flag.
-
-	* main.c: added debug_flag; support for hpodc and hpbin formats.
-
-	* makepath.c: split from standard makpath.c to add support
-	for HPUX CDF's.
-
-	* mt.c: added !defined(__osf__) (from Andrew Marquis
-	).
-
-	* system.h: new macro UMASKED_SYMLINK
-
-	* tar.c: minor changes to read (slightly broken?) System V.4 posix 
-	tar archives and HPUX posix tar archives.
-
-	* util.c: HPUX CDF support (including new routines
-	add_cdf_double_slashes() and islasparentcdf()); new routine
-	umasked_symlink().
-
-Sun Mar 14 23:00:14 1993  Jim Meyering  (meyering@comco.com)
-
-	* copypass.c (process_copy_pass): Use <=, not just <, when comparing
-	mtimes.  From Pieter Bowman .
-
-Fri Jan 15 14:35:37 1993  David J. MacKenzie  (djm@kropotkin.gnu.ai.mit.edu)
-
-	* copyin.c: Move include of fnmatch.h to get right FNM* macros.
-
-Tue Nov 24 08:45:32 1992  David J. MacKenzie  (djm@goldman.gnu.ai.mit.edu)
-
-	* Version 2.2.
-
-	* copyout.c (process_copy_out): Add parens for gcc -Wall.
-	From Jim Meyering.
-
-	* system.h: Use HAVE_FCNTL_H, not USG.
-
-	* dstring.c, mt.c, system.h: Use HAVE_STRING_H, not USG.
-
-Fri Nov 20 22:47:18 1992  David J. MacKenzie  (djm@goldman.gnu.ai.mit.edu)
-
-	* copyin.c (read_in_binary): Copy the dev and ino that are
-	already in `file_hdr' into `short_hdr'.
-	From dao@abars.att.com (David A Oshinsky).
-
-	* system.h [!_POSIX_VERSION]: Declare lseek as off_t, not long.
-	From Karl Berry.
-
-Wed Oct 14 13:53:41 1992  David J. MacKenzie  (djm@goldman.gnu.ai.mit.edu)
-
-	* Version 2.1.
-
-Tue Oct 13 22:51:34 1992  David J. MacKenzie  (djm@goldman.gnu.ai.mit.edu)
-
-	* main.c: Add --swap equivalent to -b.
-
-	* mt.c: Add f_force_local variable and -V --version option.
-
-Fri Oct  2 18:42:27 1992  David J. MacKenzie  (djm@kropotkin.gnu.ai.mit.edu)
-
-	* main.c (long_opts, usage): Add --force-local option.
-
-Thu Oct  1 23:23:43 1992  David J. MacKenzie  (djm@goldman.gnu.ai.mit.edu)
-
-	* main.c (process_args) [__MSDOS__]: Don't call geteuid.
-
-	* copyin.c (read_in_{old,new}_ascii): Use `l' for sscanf into longs.
-	* copyout.c (write_out_header): Ditto for sprintf.
-	* global.c, extern.h: Make input_size and output_size long.
-
-Thu Sep 10 23:39:30 1992  David J. MacKenzie  (djm@nutrimat.gnu.ai.mit.edu)
-
-	* global.c, extern.h: Add new var f_force_local to work with
-	rmt.h change from tar.
-
-Sun Aug 23 00:18:20 1992  David J. MacKenzie  (djm@churchy.gnu.ai.mit.edu)
-
-	* Version 2.0.
-
-	* tar.c (otoa): Compute value in an unsigned long, not an int.
-	* copyout.c (write_out_header) [__MSDOS__]: Don't use dev_t.
-
-	* main.c (process_args): By default, don't chown for non-root users.
-
-Sat Aug 22 14:17:54 1992  David J. MacKenzie  (djm@nutrimat.gnu.ai.mit.edu)
-
-	* global.c, extern.h: Use uid_t and gid_t.
-
-	* main.c (main) [__EMX__]: Expand wildcards.
-	* system.h [__EMX__]: Alias some error names.  From Kai Uwe Rommel.
-
-	* extern.h [__STDC__]: Use prototypes.
-
-	* copyin.c (process_copy_in), copyout.c (process_copy_out),
-	copypass.c (process_copy_pass): Open all files with O_BINARY.
-	Add cast to chmod call.
-	* util.c: Add cast to bcopy calls.  Make hash_insert static.
-	From Kai Uwe Rommel.
-
-Thu Aug 20 22:03:49 1992  David J. MacKenzie  (djm@nutrimat.gnu.ai.mit.edu)
-
-	* util.c (peek_in_buf): Don't print "end of file" before
-	getting the next reel of medium.
-
-	* copyin.c (read_in_old_ascii): Allocate space for NUL terminator.
-	Print newline for dot line when done, even if appending.
-
-Thu Jul 23 16:34:53 1992  David J. MacKenzie  (djm@nutrimat.gnu.ai.mit.edu)
-
-	* tar.c (write_out_tar_header, read_in_tar_header)
-	[__MSDOS__]: Don't try to get user and group names.
-	* extern.h: Don't declare the functions to do it (need uid_t).
-
-	* main.c [__MSDOS__]: Ignore the -R option.
-
-	* system.h: Define makedev if defining major and minor.
-
-	* copyin.c, copyout.c [__MSDOS__]: setmode on archive_des, not
-	0 and 1.
-
-Sat Jul 18 14:30:55 1992  David J. MacKenzie  (djm@nutrimat.gnu.ai.mit.edu)
-
-	* tar.c, stripslash.c, userspec.c, cpiohdr.h, tar.h, tarhdr.h,
-	system.h: New files.
-	* Move portability stuff from various files to system.h.
-	* cpio.h: Rename header structure and members, and add
-	new structure for SVR4 format.
-	* copyin.c, copyout.c: Use the new structure internally, the
-	old one only for I/O in the old formats.
-	* copyin.c (read_in_header): Recognize the new archive formats.
-	(read_in_new_ascii, read_pattern_file, skip_padding): New functions.
-	(swab_array): Do the swapping using char pointers instead of
-	bitwise arithmetic.
-	(process_copy_in): Handle byte and halfword swapping and new formats.
-	Ok if a directory we want to make already exists, but set its perms.
-	Do chmod after chown to fix any set[ug]id bits.
-	Use `struct utimbuf' instead of a long array.
-	* copyout.c (write_out_header): Handle new formats.
-	(process_copy_out): Use `struct utimbuf'.
-	Handle appending and new formats.
-	Remove any leading `./' from filenames.
-	(read_for_checksum, clear_rest_of_block, pad_output): New functions.
-	* copypass.c (process_copy_pass): Use `struct utimbuf'.
-	Ok if a directory we want to make already exists, but set its perms.
-	Do chmod after chown to fix any set[ug]id bits.
-	Don't change perms of `.'.
-	* extern.h, global.c: Replace the separate format flags with
-	one variable.  Add new variables for the new options.
-	* main.c: Add new options -A --append, -H --format, -C --io-size,
-	-M --message, --no-preserve-owner, -R --owner, -E --pattern-file,
-	-V --dot, -s --swap-bytes, -S --swap-halfwords, -b, -I, -k, -O.
-	(usage): Document them.
-	(process_args): Recognize them.  Use open_archive.
-	(initialize_buffers): Allow room for tar archives and double buffers.
-	* util.c (empty_output_buffer_swap): New function.
-	(empty_output_buffer): Call it if swapping current file.
-	Check additional end of media indicators.
-	(swahw_array, peek_in_buf, prepare_append, open_archive,
-	set_new_media_message): New functions.
-	(fill_input_buffer): Don't print error message if end of media.
-	(toss_input): Don't seek, always read.
-	(copy_files): Update crc if needed.
-	(find_inode_file, add_inode): Check major and minor numbers as
-	well as dev.
-	(get_next_reel): Prompt user if archive name is unknown.
-	Print fancy messages.
-	Close the archive and reopen it.
-
-	Above primarily from John Oleynick .
-
-	* util.c (find_inode_file): Use modulus when computing initial
-	loop index.
-	(add_inode): Zero out new entry.
-	From scott@sctc.com (Scott Hammond).
-
-	* cpio.h, copyin.c, copyout.c: Rename `struct cpio_header'
-	members from h_foo to c_foo.
-
-Wed May 20 00:09:26 1992  David J. MacKenzie  (djm@churchy.gnu.ai.mit.edu)
-
-	* copyin.c:  If we include a header file specifically to get
-	major et al., assume we have them.
-
-Mon Mar  9 19:29:20 1992  David J. MacKenzie  (djm@nutrimat.gnu.ai.mit.edu)
-
-	* mt.c (main): rmtclose the tape file descriptor.
-
-	* main.c (main): rmtclose the archive, if not in copy-pass mode.
-
-	* util.c (create_all_directories): Don't print a message when
-	creating a directory, for UNIX compat.
-
-	* copyin.c (process_copy_in), copypass.c (process_copy_pass):
-	Skip file if it has the same timestamp as existing file, not just
-	if it is older than existing file, for UNIX compat.
-
-Tue Mar  3 12:06:58 1992  David J. MacKenzie  (djm@wookumz.gnu.ai.mit.edu)
-
-	* main.c, mt.c (usage): Document long options as starting with
-	-- instead of +.
-
-	* extern.h: Only declare lseek if not _POSIX_VERSION.
-
-Tue Dec 24 00:19:45 1991  David J. MacKenzie  (djm at wookumz.gnu.ai.mit.edu)
-
-	* copyin.c: Use MAJOR_IN_MKDEV and MAJOR_IN_SYSMACROS instead
-	of USG and _POSIX_VERSION to find major and minor macros.
-
-	* mt.c: Use unistd.h and stdlib.h if available.
-
-	* copyin.c, copyout.c, copypass.c, util.c, extern.h: Change
-	POSIX ifdefs to HAVE_UNISTD_H and _POSIX_VERSION.
-
-Sun Aug 25 06:31:08 1991  David J. MacKenzie  (djm at apple-gunkies)
-
-	* Version 1.5.
-
-	* bcopy.c: New file (moved from util.c).
-
-	* mt.c (print_status): Not all hpux machines have mt_fileno
-	and mt_blkno; rather than trying to track HP's product line,
-	just assume none of them have them.
-
-	* util.c (copy_buf_out, copy_in_buf): Use more efficient
-	copying technique for a big speedup.
-
-Fri Aug  2 04:06:45 1991  David J. MacKenzie  (djm at apple-gunkies)
-
-	* configure: Support +srcdir.  Create config.status.
-	Remove it and Makefile if interrupted while creating them.
-
-Thu Jul 18 09:43:40 1991  David J. MacKenzie  (djm at wookumz.gnu.ai.mit.edu)
-
-	* Many files: use __MSDOS__ instead of MSDOS.
-
-	* util.c, configure: Use NO_MTIO instead of HAVE_MTIO, to keep
-	up with tar and rtapelib.c.
-
-Mon Jul 15 13:45:30 1991  David J. MacKenzie  (djm at wookumz.gnu.ai.mit.edu)
-
-	* configure: Also look in sys/signal.h for signal decl.
-
-Thu Jul 11 01:50:32 1991  David J. MacKenzie  (djm at wookumz.gnu.ai.mit.edu)
-
-	* Version 1.4.
-
-	* configure: Remove /etc and /usr/etc from PATH to avoid
-	finding /etc/install.
-
-Wed Jul 10 01:40:07 1991  David J. MacKenzie  (djm at wookumz.gnu.ai.mit.edu)
-
-	* makefile.pc: Rewrite for Turbo C 2.0.
-	* util.c [__TURBOC__] (utime): New function.
-	* alloca.c, tcexparg.c: New files.
-
-	* extern.h [STDC_HEADERS]: Don't declare malloc and realloc.
-
-	* main.c [MSDOS]: Make binary mode the default.
-	* copyin.c, copyout.c: Make stdin or stdout binary mode as
-	appropriate (so cpio archives don't get corrupted).
-
-	* Many files: Use  if STDC_HEADERS as well as if USG.
-
-	* configure, Makefile.in: $(INSTALLPROG) -> $(INSTALL),
-	$(INSTALLTEXT) -> $(INSTALLDATA).
-
-Mon Jul  8 23:18:28 1991  David J. MacKenzie  (djm at wookumz.gnu.ai.mit.edu)
-
-	* configure: For some library functions that might be missing,
-	conditionally add the .o files to Makefile instead of
-	defining func_MISSING.
-	* mkdir.c: Renamed from mkrmdir.c.
-
-Sat Jul  6 02:27:22 1991  David J. MacKenzie  (djm at geech.gnu.ai.mit.edu)
-
-	* configure: echo messages to stdout, not stderr.
-	Use a test program to see if alloca needs -lPW.
-
-Thu Jun 27 16:15:15 1991  David J. MacKenzie  (djm at geech.gnu.ai.mit.edu)
-
-	* copyin.c (process_copy_in), copyout.c (process_copy_out),
-	copypass.c (process_copy_pass): Check close return value for
-	delayed error notification because of NFS.
-
-Thu Jun 20 02:43:33 1991  David J. MacKenzie  (djm at geech.gnu.ai.mit.edu)
-
-	* configure: Include $DEFS when compiling test programs.
-
-	* util.c: Only declare getpwuid and getgrgid if not POSIX.
-
-	* Version 1.3.
-
-	* copyin.c: Use time_t, not long, for time values.
-
-	* mt.c (print_status): Special cases for HP-UX and Ultrix.
-
-	* util.c: Compile bcopy if USG or STDC_HEADERS, not BCOPY_MISSING.
-
-Tue Jun 11 16:40:02 1991  David J. MacKenzie  (djm at geech.gnu.ai.mit.edu)
-
-	* copyin.c: Don't include sys/sysmacros.h if _POSIX_SOURCE.
-
-	* copyin.c, copyout.c, copypass.c: Don't include sys/file.h if POSIX.
-
-	* util.c: Include sys/types.h before, not after, pwd.h and grp.h.
-
-	* configure: New shell script to aid configuration and create
-	Makefile from Makefile.in.
-
-	* copyin.c (process_copy_in): Use POSIX.2 fnmatch instead of
-	glob_match. 
-
-Mon Jun 10 22:11:19 1991  David J. MacKenzie  (djm at geech.gnu.ai.mit.edu)
-
-	* global.c, extern.h: New variable, name_end.
-	* main.c (process_args, usage): Add -0 +null option to set it.
-	* copypass.c (process_copy_pass), copyout.c (process_copy_out): 
-	Use it.
-
-	* dstring.c (ds_fgetstr): New function made from ds_fgets.
-	(ds_fgets, ds_fgetname): Implement as front ends to ds_fgetstr.
-
-Sun Jun  2 15:45:24 1991  David J. MacKenzie  (djm at wheat-chex)
-
-	* most files: use GPL version 2.
-
-Sat May 18 11:39:22 1991  David J. MacKenzie  (djm at geech.gnu.ai.mit.edu)
-
-	* copyin.c, copypass.c: Take out #ifdef MSDOS around chown.
-	* util.c [MSDOS]: Provide dummy chown.
-
-Fri May 17 21:29:05 1991  David J. MacKenzie  (djm at churchy.gnu.ai.mit.edu)
-
-	* Version 1.2.
-
-	* makefile.pc, cpio.cs: Update for new source and object files.
-
-Fri Mar 15 05:48:36 1991  David J. MacKenzie  (djm at geech.ai.mit.edu)
-
-	* global.c, extern.h: New variable `archive_desc'.
-	* main.c (process_args): Set it.
-	* copyout.c (process_copy_out), copyin.c (process_copy_in):
-	Use it.
-
-	* copyout.c (process_copy_out), copyin.c (process_copy_in):
-	Remote tapes are special and not seekable; don't fstat them.
-
-	* main.c (main, usage): Add -F, +file option.  Use rmtopen.
-	(main): Exit after printing version number.
-	* util.c (empty_output_buffer): Use rmtwrite instead of write.
-	(fill_input_buffer): Use rmtread instead of read.
-	(tape_offline): Use rmtioctl instead of ioctl.
-	Test HAVE_MTIO instead of MTIO_MISSING, for tar compatibility.
-
-Thu Mar 14 17:49:57 1991  David J. MacKenzie  (djm at geech.ai.mit.edu)
-
-	* util.c (create_all_directories): Use make_path to do the work.
-
-Sat Jan 12 15:32:15 1991  David J. MacKenzie  (djm at geech.ai.mit.edu)
-
-	* copyin.c, copyout.c, copypass.c, util.c: Only declare
-	`errno' if not MSDOS.  Some Unix errno.h do, some don't . . . .
-
-	* global.c, extern.h: Make `input_size' and `output_size'
-	unsigned, for 16 bit machines.
-
-	* copyin.c (print_name_with_quoting): All non-ctrl chars are
-	printable on MS-DOS.
-
-	* util.c (empty_output_buffer): Never make sparse files;
-	can create unrunnable executables.
-	* copyin.c, copyout.c, copypass.c: Callers changed.
-	* util.c (finish_output_file): Function removed.
-
-Tue Nov  6 15:47:16 1990  David J. MacKenzie  (djm at apple-gunkies)
-
-	* copyin.c, util.c, extern.h: Rename copystring to xstrdup.
-
-Mon Oct 29 02:24:41 1990  David J. MacKenzie  (djm at apple-gunkies)
-
-	* util.c (empty_output_buffer): Only make sparse files if
-	NO_SPARSE_FILES is undefined, to accomodate dumb kernels.
-
-Wed Jul 25 18:48:35 1990  David J. MacKenzie  (djm at albert.ai.mit.edu)
-
-	* util.c (getuser, getgroup): Make uid and gid unsigned short,
-	not int.
-
-Sat Jul 21 00:44:44 1990  David J. MacKenzie  (djm at apple-gunkies)
-
-	* copyin.c, copyout.c, copypass.c, util.c, cpio.h: Add ifdefs
-	for MSDOS.
-
-Sun Jul 15 23:51:48 1990  David J. MacKenzie  (djm at albert.ai.mit.edu)
-
-	* copyin.c, copyout.c, copypass.c, global.c, extern.h, util.c:
-	Use longs where appropriate, for 16 bit machines.
-
-Sun Jul  8 22:58:06 1990  David J. MacKenzie  (djm at apple-gunkies)
-
-	* main.c (process_args, usage): Change -b option to -O (old), to
-	allow adding byte swapping later.
-
-Sat Jul  7 14:48:35 1990  David J. MacKenzie  (dave at edfmd)
-
-	* Version 1.1.
-
-	* cpio.h: Make `mtime' and `filesize' unsigned long.
-	* copyin.c (read_in_binary), copyout.c (write_out_header):
-	High short-word of `mtime' and `filesize' always comes first.
-
-	* (read_in_ascii, read_in_binary): New functions, from code in
-	read_in_header. 
-	(read_in_header): Search for valid magic number, then fill in
-	rest of header using read_in_ascii and read_in_binary.
-	* global.c, extern.h: New variable, `binary_flag'.
-	* main.c (process_args): Recognize new -b +binary option.
-	* util.c [BCOPY_MISSING] (bcopy): New function.
-
-Wed Jul  4 00:40:58 1990  David J. MacKenzie  (djm at apple-gunkies)
-
-	* main.c (process_args): Add local pointers to functions to
-	work around a pcc bug found on a Convex.
-
-	* copyin.c (process_copy_in), util.c (toss_input,
-	create_all_directories, add_inode): Don't use `index' as a
-	variable name. 
-
-Tue Jul  3 02:33:36 1990  David J. MacKenzie  (djm at apple-gunkies)
-
-	* version 1.0.
-
-Mon Jul  2 23:18:56 1990  David J. MacKenzie  (djm at twiddle)
-
-	* copyin.c (process_copy_in), copyout.c (process_copy_out),
-	copypass.c (process_copy_pass): Print "1 block", not "1 blocks".
-
-	* copyin.c (process_copy_in), copypass.c (process_copy_pass):
-	Unlink existing dest. file unless either it is newer and
-	not unconditional, or it is a directory.
-
-Mon Jul  2 03:57:41 1990  David J. MacKenzie  (dave at edfmd)
-
-	* util.c (xrealloc): New function.
-	* dstring.c (ds_resize): Use xrealloc instead of free and
-	xmalloc.  Never shrink the string.
-
-	* copypass.c (process_copy_pass): More efficient
-	string handling while constructing output filename.
-
-	* global.c, extern.h, main.c, cpio.h: Change from an enum,
-	`copy_command', to a pointer to a void function, `copy_function'.
-
-	* cpio.h (struct cpio_header): Make most fields unsigned.
-	Rename h_filesize to h_filesizes and h_mtime to h_mtimes, and
-	add new `long' fields with the old names at the end of the
-	structure.
-	* copyin.c (read_in_header): Set the long fields from the
-	short arrays, making sure longs are aligned properly.
-	(process_copy_in, long_format): Use the long fields.
-	* copyout.c (write_out_header): Set the short arrays from the
-	long fields, making sure longs are aligned properly.
-	(process_copy_out): Use the long fields.
-
-	* global.c, extern.h: New variable `output_is_seekable'.
-	* util.c (empty_output_buffer): If output_is_seekable, use
-	lseek to write blocks of zeros.
-	(finish_output_file): New function.
-	* copyin.c (process_copy_in), copyout.c (process_copy_out),
-	copypass.c (process_copy_pass): Set `output_is_seekable'
-	correctly and call finish_output_file.
-	* main.c (initialize_buffers): Allocate space for sentinel in
-	`output_buffer'. 
-
-	* global.c, extern.h: New variable `numeric_uid'.
-	* main.c (process_args): Accept -n +numeric-uid-gid option, like ls.
-	* copyin.c (long_format): Use numeric_uid.
-
-	* copyin.c (process_copy_in), copyout.c (process_copy_out),
-	copypass.c (process_copy_pass): Don't (for verbose) print the
-	names of files that are not copied because of errors.  Try to
-	create missing directories for all file types.  Free temporary
-	buffers on error.
-
-Sat Jun 30 14:28:45 1990  David J. MacKenzie  (djm at apple-gunkies)
-
-	* version.c: New file.
-	* main.c: Add -V, +version option.
-	* Makefile [dist]: Extract version number from version.c.
-
-Sat Jun 30 12:44:47 1990  David J. MacKenzie  (dave at edfmd)
-
-	* global.c, extern.h, copyin.c, copyout.c, util.c: Rename
-	`{input,output}_is_regular' to `{input,output}_is_special' and
-	reverse the truth value. 
-
-	* global.c, extern.h: New variable `input_is_seekable' to
-	control whether to skip data with lseek or read. 
-	* copyin.c (process_copy_in): Set it.
-	* util.c (toss_input): Use it.
-
-	* global.c, extern.h: New variable `xstat' that selects stat
-	or lstat for input files.
-	* main.c (process_args): New option -L, +dereference to set
-	xstat to stat instead of lstat.
-	(usage): Document it.
-	* copyout.c (process_copy_out), copypass.c
-	(process_copy_pass): Use *xstat on input file.
-
-Sat Jun 30 01:53:12 1990  David J. MacKenzie  (dave at edfmd)
-
-	* dstring.c (ds_init): Return void because return value was
-	never used. 
-	(ds_resize): Ditto, and free old value instead of new one.
-
-	* util.c (empty_output_buffer, fill_input_buffer,
-	copy_out_buf, copy_in_buf, toss_input, copy_files): Return
-	void instead of an error value and make errors fatal
-	immediately instead of several levels up, to prevent printing
-	of multiple error messages by different levels of functions.
-
-	* copyin.c (read_in_header): Return void, because the error
-	handling all happens at lower levels.
-	(print_name_with_quoting): New function.
-	(long_format): Call print_name_with_quoting.  Take additional
-	arg for name of linked-to file, and print it if nonzero.
-	(process_copy_in): For verbose listing of symlinks, read in
-	the linkname and pass it to long_format.
-
-	* extern.h: Declare some more functions.
-
-Thu Jun 28 16:07:15 1990  David J. MacKenzie  (dave at edfmd)
-
-	* copypass.c (process_copy_pass): Warn about unknown file types.
-
-	* copyout.c (process_copy_out): Check fstat return for error.
-	Record filesize of 0 for special files.  Warn about unknown
-	file types.
-
-	* copyin.c (process_copy_in): Warn about unknown file types.
-	(read_in_header): Warn about byte-reversed binary headers.
-
-Sat Jun 23 22:50:45 1990  David J. MacKenzie  (dave at edfmd)
-
-	* main.c (main): Set umask to 0 so permissions of created
-	files are preserved. 
-
-	* copyin.c, copyout.c, copypass.c, util.c: Pass file
-	descriptors as ints, not pointers to ints. 
-	Cast file timestamps and sizes to long *, not int *, for 16
-	bit machines.
-	Use lstat instead of stat, if available.
-	Handle FIFO's, sockets, and symlinks, if supported by O.S.
-
-	* copyin.c (process_copy_in), copyout.c (process_copy_out):
-	Don't consider FIFO'S, sockets, etc. to be possible tape drives.
-
-	* util.c (create_all_directories): Fix incorrect loop
-	termination check.  Only copy string if it contains slashes.
-	Don't check whether directory "" exists.
-	(tape_offline): Code moved from get_next_reel.
-	(get_next_reel): Print message before taking tape offline.
-	Read a line of arbitrary length.
-
-	* copyout.c, copyin.c, copypass.c: Always use utime, not utimes.
-
-	* copyin.c (swab_short): New macro.
-	(swab_array): New function.
-	(read_in_header): In binary mode, if a byte-swapped header is
-	read, swap the bytes back.
-	(process_copy_in, process_copy_pass): Don't stat each file to
-	create unless !unconditional_flag.  Create device files correctly.
-	Don't temporarily allow files being created to be read by
-	other users.  Don't unnecessarily chmod special files.
-
-Thu May 31 20:51:43 1990  David J. MacKenzie  (djm at albert.ai.mit.edu)
-
-	* copyin.c (long_format): Use mode_string to format
-	file protections instead of doing it ourselves.
-	(protections): Function removed.
-
-Sat Apr 14 02:31:01 1990  David J. MacKenzie  (djm at albert.ai.mit.edu)
-
-	* cpio.h (struct cpio_header): Make inode, mode, uid, gid
-	fields unsigned. 
-
-	* util.c (getgroup): New function.
-	* copyin.c (long_format): Print group name of files.
-	Print file size, etc. as unsigned integers, not signed.
-
-	* main.c (process_args): If -t is given and neither -i, -o, or
-	-p is given, assume -i.
-
-	* Add -f, +nonmatching option.
-	* main.c: Rename +out to +create, +in to +extract,
-	+modification-time to +preserve-modification-time,
-	+pass to +pass-through.
-
-	* copyin.c (process_copy_in), copypass.c (process_copy_pass):
-	Don't complain in chown fails because the user doesn't have
-	permission. 
-
-Fri Apr 13 13:53:20 1990  David J. MacKenzie  (djm at albert.ai.mit.edu)
-
-	* Add ifdefs for USG/Xenix.
-	* util.c (cpio_error): Function removed.
-	* Use error instead of cpio_error, so system error messages
-	will be included.
-	* cpio.h: Rename 'hdr_struct' to 'struct cpio_header'.
-	* Move definition of xmalloc from dstring.c to util.c.
-	* global.c, extern.c: Add global `program_name'.
-	* main.c (main): Set program_name.
-	(process_args): Rename +reset-atime to +reset-access-time,
-	+table to +list.
-	Have +block-size take an argument.
-
-Thu Apr 12 13:33:32 1990  David J. MacKenzie  (djm at rice-chex)
-
-	* util.c (find_inode_file): Make inode an int, not a short.
-
-	* Make functions that don't return a value have type void.
-	Add some casts to function calls.
-
-Wed Apr 11 14:55:28 1990  David J. MacKenzie  (djm at albert.ai.mit.edu)
-
-	* main.c (process_args): -i, -o, and -p don't take arguments.
-
-	* main.c (process_args): Get the non-option args from the
-	correct elements of argv.
-
-Tue Apr 10 00:20:26 1990  David J. MacKenzie  (djm at albert.ai.mit.edu)
-
-	* Indent source code and update copyrights.
-
-	* cpio.c (usage): Change `collection' to `archive' in message.
-
-Thu Dec 28 03:03:55 1989  David J. MacKenzie  (djm at hobbes.ai.mit.edu)
-
-	* dstring.c (xmalloc): Don't return a null pointer if size is 0,
-	on the assumption that trying to allocate 0 bytes is a bug that
-	should be trapped.
-
-Wed Dec 20 03:24:48 1989  David J. MacKenzie  (djm at hobbes.ai.mit.edu)
-
-	* All files: Change from GNU CPIO General Public License to
-	GNU General Public License.
-
-Mon Dec 18 13:18:36 1989  David J. MacKenzie  (djm at hobbes.ai.mit.edu)
-
-	* Makefile: Add clean target and defines for CC and LDFLAGS.
-	Add dist target and SRCS, DISTFILES macros.  Add tags and TAGS targets.
-	* dstring.c (ds_fgets): Read characters into an int, not char.
-	(xmalloc): New function.
-	(out_of_memory): Function removed.
-	Global: use xmalloc instead of malloc and out_of_memory.
-	* extern.h, global.c: Make flag variables ints instead of chars for
-	compatibility with getopt_long.
-	* extern.h: Declare more functions.
-	* main.c (usage): Put the whole usage message into a single string
-	and fix errors.
-	* util.c (create_all_directories): Remove unused variable.
-	(get_next_reel): Ditto.
-	* dstring.h: Declare function.
-
-Sat Dec  2 13:22:37 1989  David J. MacKenzie  (djm at hobbes.ai.mit.edu)
-
-	* main.c: Change +copy-pass option to +pass, +copy-in to +in,
-	+copy-out to +out, and +mkdir to +make-directories, and add null
-	option to terminate table.
-	(process_args): Use the same code to handle long and short named 
-	options.
-	(usage): Mention long options in message.
-
-Local Variables:
-mode: change-log
-version-control: never
-End:
diff --git a/contrib/cpio/FREEBSD-upgrade b/contrib/cpio/FREEBSD-upgrade
deleted file mode 100644
index a3e31a0592e..00000000000
--- a/contrib/cpio/FREEBSD-upgrade
+++ /dev/null
@@ -1,29 +0,0 @@
-$FreeBSD$
-
-GNU cpio:
-
-	Originals can be found at: ftp://ftp.gnu.org/pub/gnu/cpio
-
-Configure by:
-
-	./configure --disable-nls --without-libiconv-prefix \
-		--without-libintl-prefix
-
-Trim by:
-
-	rm Makefile.am Makefile.in aclocal.m4 config.h.in configure \
-		configure.ac
-	rm -r headers m4 rmt tests scripts po
-	rm doc/Makefile.am doc/Makefile.in doc/mt.1 doc/cpio.info
-	rm src/Makefile.am src/Makefile.in
-	rm src/mt.c
-	rm lib/Makefile.am lib/Makefile.in lib/Makefile.tmpl lib/alloca.c \
-		lib/argmatch.[ch] lib/bcopy.c lib/fnmatch.c lib/fnmatch_.h \
-		lib/fnmatch_loop.c lib/mkdir.c lib/quote.[ch] \
-		lib/quotearg.[ch] lib/stdbool_.h lib/strcasecmp.c \
-		lib/strdup.c lib/strerror.c lib/strncasecmp.c lib/sysexit_.h
-
-Import by:
-
-         cvs import -m "Import GNU cpio 2.6 (trimmed)" src/contrib/cpio \
-		GNU v2_6
diff --git a/contrib/cpio/INSTALL b/contrib/cpio/INSTALL
deleted file mode 100644
index 5458714e1e2..00000000000
--- a/contrib/cpio/INSTALL
+++ /dev/null
@@ -1,234 +0,0 @@
-Installation Instructions
-*************************
-
-Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
-2006 Free Software Foundation, Inc.
-
-This file is free documentation; the Free Software Foundation gives
-unlimited permission to copy, distribute and modify it.
-
-Basic Installation
-==================
-
-Briefly, the shell commands `./configure; make; make install' should
-configure, build, and install this package.  The following
-more-detailed instructions are generic; see the `README' file for
-instructions specific to this package.
-
-   The `configure' shell script attempts to guess correct values for
-various system-dependent variables used during compilation.  It uses
-those values to create a `Makefile' in each directory of the package.
-It may also create one or more `.h' files containing system-dependent
-definitions.  Finally, it creates a shell script `config.status' that
-you can run in the future to recreate the current configuration, and a
-file `config.log' containing compiler output (useful mainly for
-debugging `configure').
-
-   It can also use an optional file (typically called `config.cache'
-and enabled with `--cache-file=config.cache' or simply `-C') that saves
-the results of its tests to speed up reconfiguring.  Caching is
-disabled by default to prevent problems with accidental use of stale
-cache files.
-
-   If you need to do unusual things to compile the package, please try
-to figure out how `configure' could check whether to do them, and mail
-diffs or instructions to the address given in the `README' so they can
-be considered for the next release.  If you are using the cache, and at
-some point `config.cache' contains results you don't want to keep, you
-may remove or edit it.
-
-   The file `configure.ac' (or `configure.in') is used to create
-`configure' by a program called `autoconf'.  You need `configure.ac' if
-you want to change it or regenerate `configure' using a newer version
-of `autoconf'.
-
-The simplest way to compile this package is:
-
-  1. `cd' to the directory containing the package's source code and type
-     `./configure' to configure the package for your system.
-
-     Running `configure' might take a while.  While running, it prints
-     some messages telling which features it is checking for.
-
-  2. Type `make' to compile the package.
-
-  3. Optionally, type `make check' to run any self-tests that come with
-     the package.
-
-  4. Type `make install' to install the programs and any data files and
-     documentation.
-
-  5. You can remove the program binaries and object files from the
-     source code directory by typing `make clean'.  To also remove the
-     files that `configure' created (so you can compile the package for
-     a different kind of computer), type `make distclean'.  There is
-     also a `make maintainer-clean' target, but that is intended mainly
-     for the package's developers.  If you use it, you may have to get
-     all sorts of other programs in order to regenerate files that came
-     with the distribution.
-
-Compilers and Options
-=====================
-
-Some systems require unusual options for compilation or linking that the
-`configure' script does not know about.  Run `./configure --help' for
-details on some of the pertinent environment variables.
-
-   You can give `configure' initial values for configuration parameters
-by setting variables in the command line or in the environment.  Here
-is an example:
-
-     ./configure CC=c99 CFLAGS=-g LIBS=-lposix
-
-   *Note Defining Variables::, for more details.
-
-Compiling For Multiple Architectures
-====================================
-
-You can compile the package for more than one kind of computer at the
-same time, by placing the object files for each architecture in their
-own directory.  To do this, you can use GNU `make'.  `cd' to the
-directory where you want the object files and executables to go and run
-the `configure' script.  `configure' automatically checks for the
-source code in the directory that `configure' is in and in `..'.
-
-   With a non-GNU `make', it is safer to compile the package for one
-architecture at a time in the source code directory.  After you have
-installed the package for one architecture, use `make distclean' before
-reconfiguring for another architecture.
-
-Installation Names
-==================
-
-By default, `make install' installs the package's commands under
-`/usr/local/bin', include files under `/usr/local/include', etc.  You
-can specify an installation prefix other than `/usr/local' by giving
-`configure' the option `--prefix=PREFIX'.
-
-   You can specify separate installation prefixes for
-architecture-specific files and architecture-independent files.  If you
-pass the option `--exec-prefix=PREFIX' to `configure', the package uses
-PREFIX as the prefix for installing programs and libraries.
-Documentation and other data files still use the regular prefix.
-
-   In addition, if you use an unusual directory layout you can give
-options like `--bindir=DIR' to specify different values for particular
-kinds of files.  Run `configure --help' for a list of the directories
-you can set and what kinds of files go in them.
-
-   If the package supports it, you can cause programs to be installed
-with an extra prefix or suffix on their names by giving `configure' the
-option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
-
-Optional Features
-=================
-
-Some packages pay attention to `--enable-FEATURE' options to
-`configure', where FEATURE indicates an optional part of the package.
-They may also pay attention to `--with-PACKAGE' options, where PACKAGE
-is something like `gnu-as' or `x' (for the X Window System).  The
-`README' should mention any `--enable-' and `--with-' options that the
-package recognizes.
-
-   For packages that use the X Window System, `configure' can usually
-find the X include and library files automatically, but if it doesn't,
-you can use the `configure' options `--x-includes=DIR' and
-`--x-libraries=DIR' to specify their locations.
-
-Specifying the System Type
-==========================
-
-There may be some features `configure' cannot figure out automatically,
-but needs to determine by the type of machine the package will run on.
-Usually, assuming the package is built to be run on the _same_
-architectures, `configure' can figure that out, but if it prints a
-message saying it cannot guess the machine type, give it the
-`--build=TYPE' option.  TYPE can either be a short name for the system
-type, such as `sun4', or a canonical name which has the form:
-
-     CPU-COMPANY-SYSTEM
-
-where SYSTEM can have one of these forms:
-
-     OS KERNEL-OS
-
-   See the file `config.sub' for the possible values of each field.  If
-`config.sub' isn't included in this package, then this package doesn't
-need to know the machine type.
-
-   If you are _building_ compiler tools for cross-compiling, you should
-use the option `--target=TYPE' to select the type of system they will
-produce code for.
-
-   If you want to _use_ a cross compiler, that generates code for a
-platform different from the build platform, you should specify the
-"host" platform (i.e., that on which the generated programs will
-eventually be run) with `--host=TYPE'.
-
-Sharing Defaults
-================
-
-If you want to set default values for `configure' scripts to share, you
-can create a site shell script called `config.site' that gives default
-values for variables like `CC', `cache_file', and `prefix'.
-`configure' looks for `PREFIX/share/config.site' if it exists, then
-`PREFIX/etc/config.site' if it exists.  Or, you can set the
-`CONFIG_SITE' environment variable to the location of the site script.
-A warning: not all `configure' scripts look for a site script.
-
-Defining Variables
-==================
-
-Variables not defined in a site shell script can be set in the
-environment passed to `configure'.  However, some packages may run
-configure again during the build, and the customized values of these
-variables may be lost.  In order to avoid this problem, you should set
-them in the `configure' command line, using `VAR=value'.  For example:
-
-     ./configure CC=/usr/local2/bin/gcc
-
-causes the specified `gcc' to be used as the C compiler (unless it is
-overridden in the site shell script).
-
-Unfortunately, this technique does not work for `CONFIG_SHELL' due to
-an Autoconf bug.  Until the bug is fixed you can use this workaround:
-
-     CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
-
-`configure' Invocation
-======================
-
-`configure' recognizes the following options to control how it operates.
-
-`--help'
-`-h'
-     Print a summary of the options to `configure', and exit.
-
-`--version'
-`-V'
-     Print the version of Autoconf used to generate the `configure'
-     script, and exit.
-
-`--cache-file=FILE'
-     Enable the cache: use and save the results of the tests in FILE,
-     traditionally `config.cache'.  FILE defaults to `/dev/null' to
-     disable caching.
-
-`--config-cache'
-`-C'
-     Alias for `--cache-file=config.cache'.
-
-`--quiet'
-`--silent'
-`-q'
-     Do not print messages saying which checks are being made.  To
-     suppress all normal output, redirect it to `/dev/null' (any error
-     messages will still be shown).
-
-`--srcdir=DIR'
-     Look for the package's source code in directory DIR.  Usually
-     `configure' can determine that directory automatically.
-
-`configure' also accepts some other, not widely useful, options.  Run
-`configure --help' for more details.
-
diff --git a/contrib/cpio/NEWS b/contrib/cpio/NEWS
deleted file mode 100644
index 857ae89ff1a..00000000000
--- a/contrib/cpio/NEWS
+++ /dev/null
@@ -1,155 +0,0 @@
-GNU cpio NEWS -- history of user-visible changes. 2007-06-08
-Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
-See the end of file for copying conditions.
-
-Please send cpio bug reports to .
-
-Version 2.8 - Sergey Poznyakoff, 2007-06-08
-
-* Option --owner can be used in copy-out mode, allowing to uniformly override
-ownership of the files being added to the archive.
-
-* Bugfixes:
-
-** Symlinks were handled incorrectly in copy-out mode.
-** Fix handling of large files.
-** Fix setting the file permissions in copy-out mode.
-** Fix CAN-2005-1111
-
-
-Version 2.7 - Sergey Poznyakoff, 2006-10-21
-
-* Improved error checking and diagnostics
-
-* Bugfixes
-** Fixed CAN-1999-1572
-** Allow to use --sparse in both copy-in and copy-pass.
-** Fix bug that eventually caused copying out the same hard-linked
-file several times to archive.
-** Fix several LFS-related issues.
-** Fix Debian bug 335580.
-
-
-Version 2.6 - Sergey Poznyakoff, 2004-12-20
-
-* Added NLS support
-
-* Improved configure script
-
-* Improved invocation consistency checking and help output
-
-* Printing warning about truncation of inode numbers is suppressed by
-default. See below.
-
-* New option --warning (-W) controls the level of output warnings:
-
-    -Wnone       Disables all warnings
-    -Wtruncate   Enable warning about truncation of the inode number
-    -Wall        Enables all warnings
-
-  To disable a particular warning, prefix its name with 'no-', just
-  like in gcc.
-
-* New option --to-stdout extracts files to standard output.
-
-* The output of `cpio --help' is largely improved.
-       
-* Bugfixes:
-** If a file grew n bytes in copy-pass mode, these n bytes got prepended
-to the contents of all subsequent files.
-** Padding the archive with zero bytes upon truncation of the file being
-archived was broken.
-
-
-Major changes in version 2.5:
-
-* bug fixes from Debian, Red Hat, and SuSE GNU/Linux Distribution patches
-* --rsh-command option
-
-Major changes in version 2.4:
-
-* new texinfo documentation
-* --sparse option to write sparse files
-* --only-verify-crc option to verify a CRC format archive
-* --no-absolute-paths option to ignore absolute paths
-* --quiet option to supress printing number of blocks copied
-* handle disk input errors more gracefully
-
-Major changes in version 2.3:
-
-* in newc and crc format archives, only store 1 copy of multiply linked files
-* handle multiply linked devices properly
-* handle multiply linked files with cpio -pl even when the source and 
-  destination are on different file systems
-* support HPUX Context Dependent Files
-* read and write HPUX cpio archives
-* read System V.4 POSIX tar archives and HPUX POSIX tar archives
-* use rmdir, instead of unlink, to delete existing directories
-
-Major changes in version 2.2:
-
-* handle link counts correctly when reading binary cpio archives
-* configure checks for some libraries that SVR4 needs
-
-Major changes in version 2.1:
-
-* cpio can access remote non-device files as well as remote devices
-* fix bugs in the MS-DOS port
-* add --swap equivalent to -b option
-
-Version 2.0 adds the following features:
-
-Support for the SVR4 cpio formats, which can store inodes >65535, and
-for traditional and POSIX tar archives.  Also adds these options:
-
--A --append		append to instead of replacing the archive
--V --dot		print a dot for each file processed
--H --format		select archive format
--C --io-size		select I/O block size in bytes
--M --message		print a message at end of media volumes
---no-preserve-owner	don't change files' owners when extracting
--R --owner		set files' owners when extracting
--E --pattern-file	list of shell filename patterns to process
--s --swap-bytes		handle byte-order differences when extracting files
--S --swap-halfwords	ditto
--b			like -sS
--I			input archive filename
--k			recognize corrupted archives (we alawys do it, though)
--O			output archive filename
-
-Some options of previous versions have been renamed in 2.0:
-
---binary was replaced by --format=bin
---portability was replaced by --format=odc
-
-Some options have changed meaning in 2.0, for SVR4 compatibility:
-
--O used to select the binary archive format, now selects the output file
--V used to print the version number, now prints a dot for each file
-
-Version 2.0 also fixes several bugs in the handling of files with
-multiple links and of multi-volume archives on floppy disks.
-
-----------------------------------------------------------------------
-Copyright information:
-
-Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
-
-   Permission is granted to anyone to make or distribute verbatim copies
-   of this document as received, in any medium, provided that the
-   copyright notice and this permission notice are preserved,
-   thus giving the recipient permission to redistribute in turn.
-
-   Permission is granted to distribute modified versions
-   of this document, or of portions of it,
-   under the above conditions, provided also that they
-   carry prominent notices stating who last changed them.
-
-Local variables:
-mode: outline
-paragraph-separate: "[ 	]*$"
-eval: (add-hook 'write-file-hooks 'time-stamp)
-time-stamp-start: "changes. "
-time-stamp-format: "%:y-%02m-%02d"
-time-stamp-end: "\n"
-end:
diff --git a/contrib/cpio/README b/contrib/cpio/README
deleted file mode 100644
index fafff13881e..00000000000
--- a/contrib/cpio/README
+++ /dev/null
@@ -1,71 +0,0 @@
-This is GNU cpio, a program to manage archives of files.
-As of version 2.0, it supports the features of the System V release 4
-cpio, including support for tar archives.
-
-This package also includes rmt, the remote tape server, and mt, a tape
-drive control program; these two programs will only be compiled if
-your system supports remote command execution, and tape drive control
-operations, respectively.
-
-See the file INSTALL for compilation and installation instructions for Unix.
-
-For non-Unix systems [ Note:  The non-Unix makefiles have not been tested
-                       for this release ]
-
-makefile.pc is a makefile for Turbo C or C++ or Borland C++ on MS-DOS.
-
-makefile.os2 is a makefile for MS C and GNU C (emx/gcc) on OS/2.
-cpio.def is a linker definition file for the MS C OS/2 version.
-
-
-The main advantages of GNU cpio over Unix versions are:
-
-* It can access tape drives on other hosts using TCP/IP.
-
-* `-o' and `-p' can copy symbolic links either as symbolic links or,
-with `-L', as the files they point to.
-
-* `-i' automatically recognizes the archive format and tries to
-recover from corrupted archives.
-
-* The output of '-itv' looks like 'ls -l'.
-
-* It accepts long-named options as well as traditional
-single-character options.
-
-A few features of other versions of cpio are missing from GNU cpio, including:
-
-* The `-6' option to support Sixth Edition Unix cpio archives with `-i'.
-
-* An option to limit volume size, like afio -s.
-
-
-GNU cpio supports the POSIX.1 "ustar" tar format.  GNU tar supports a
-somewhat different, early draft of that format.  That draft format has
-a slightly different magic number in the tar header and doesn't
-include the path prefix part of the header, which allows storing file
-names that are longer than 100 characters.  GNU cpio knows to
-recognize the nonstandard GNU tar "ustar" archives.
-
-The following patch to GNU tar 1.11.1 makes GNU tar recognize standard
-"ustar" archives, such as GNU cpio produces, except that it won't use
-the path prefix.  Without this patch, GNU tar thinks that standard
-"ustar" archives are old-format tar archives and can not use the extra
-information that "ustar" format contains.  If you use this patch,
-remember that you will lose the beginnings of paths that are longer
-than 100 characters.  That's why it's not an official part of GNU tar.
-(Adding support for the path prefix to GNU tar is not trivial.)
-
---- list.c.orig Mon Sep 14 17:04:03 1992
-+++ list.c      Wed Oct 14 14:02:28 1992
-@@ -439,7 +439,7 @@
-                st->st_ctime = from_oct(1+12, header->header.ctime);
-        }
- 
--       if (0==strcmp(header->header.magic, TMAGIC)) {
-+       if (0==strncmp(header->header.magic, TMAGIC, 5)) {
-                /* Unix Standard tar archive */
-                *stdp = 1;
-                if (wantug) {
-
-Mail suggestions and bug reports for GNU cpio to bug-cpio@gnu.org.
diff --git a/contrib/cpio/THANKS b/contrib/cpio/THANKS
deleted file mode 100644
index 393de057c2a..00000000000
--- a/contrib/cpio/THANKS
+++ /dev/null
@@ -1,20 +0,0 @@
-GNU cpio THANKS file
-
-GNU cpio has originally been written by Phil Nelson 
-and David MacKenzie . It was further modified
-by John Oleynick  and Sergey Poznyakoff 
-who currently maintains it.
-
-The following is a list of people who contributed to GNU cpio by
-reporting problems, suggesting various improvements or submitting actual
-code. Help us keep it complete and exempt of errors.
-
-Benigno B. Junior       
-Brian Mays              
-Dmitry V. Levin         
-Jim Castleberry         
-Holger Fleischmann	
-Matthew Braithwaite     
-Mike Frysinger          
-Mitsuru Chinen		
-Peter Vrabec            
diff --git a/contrib/cpio/TODO b/contrib/cpio/TODO
deleted file mode 100644
index ffd63d5fd96..00000000000
--- a/contrib/cpio/TODO
+++ /dev/null
@@ -1,159 +0,0 @@
-Following is the list of cpio-related reports to bug-gnu-utils.
-Many of them appear to be fixed, but quite a number of them is
-probably still waiting for being handled.  The list is divided
-into two parts, the messages are in somehow arbitrary order.
-
-* Bug reports
---------------
-
-**    cpio -d bug (fwd) (score: 47)
-          Author: Christian Smith 
-          Date: Wed, 14 Nov 2001 02:06:46 +0000 (GMT)
-          This was bounced from bug-cpio@bogus.example.com I guess that
-          isn't set up yet. -- /"\ \ / ASCII RIBBON CAMPAIGN - AGAINST
-          HTML MAIL X - AGAINST MS ATTACHMENTS / \ $ cpio --version GNU
-          cpio version 2
-          /archive/html/bug-gnu-utils/2001-11/msg00170.html (4,548 bytes)
-          
-**    bug in cpio with tapechange in copy-in-mode (score: 34)
-          Author: Bernd =?ISO-8859-1?Q?Sch=FCler?=
-          
-          Date: 05 Aug 2002 18:37:56 +0200
-          Hello, last i made a restore from tape, and no request for next
-          tape happend, only an read-error occured. Here is an quick
-          patch, please verify the problem and the patch-code. I'm not
-          sure, if the pr
-          /archive/html/bug-gnu-utils/2002-08/msg00122.html (4,518 bytes)
-          
-**   Re: bug in cpio? (score: 40)
-          Author: kasal@matsrv.math.cas.cz (Stepan Kasal)
-          Date: Thu, 13 Jun 2002 07:44:14 +0000 (UTC)
-          Hallo, the following option should help: -d, --make-directories
-          Create leading directories where needed. Details: cpio won't
-          create the directory for the file. Observe: kasal$ echo
-          /home/kasal/tmp/db
-          /archive/html/bug-gnu-utils/2002-06/msg00306.html (4,862 bytes)
-          
-**   cpio 2.4.2 bug? (score: 40)
-          Author: "H.J. Thomassen" 
-          Date: Thu, 10 Jan 2002 18:09:10 +0100 (CET)
-          Hello, We use GNU-cpio 2.4.2 and have the following problem:
-          Short: Assume I have a directory with two filenames, which are
-          hardlinks to the same i-node. I make a crc-cpio archive with
-          both files; th
-          /archive/html/bug-gnu-utils/2002-01/msg00161.html (5,624 bytes)
-
-** These two seem to be related: 
-***  cpio copy-in and multiply-linked files (score: 35)
-          Author: Chris Jaeger 
-          Date: Tue, 07 Aug 2001 23:46:04 -0700
-          Hi, I was wondering whether it was a bug or a feature that GNU
-          cpio, while in copy-in mode, will create a multiply-linked set
-          of files all of size 0 if the last linked file is not copied in
-          due to th
-          /archive/html/bug-gnu-utils/2001-08/msg00074.html (4,142 bytes)
-          
-***  (no subject) (score: 2)
-          Author: brian@debian.org (Brian Mays)
-          Date: Sat, 07 Jul 2001 16:35:13 -0400
-          When hard-linked files (along with many other files) are
-          archived to a cpio ustar format archive, the files are _not_
-          all archived as hard links to each other in the archive. When
-          the same set of fil
-          /archive/html/bug-gnu-utils/2001-07/msg00080.html (5,666 bytes)
-          
-** These too:
-
-***   Re: minor problems with slackware-current (score: 7)
-          Author: Cezary Sliwa 
-          Date: Wed, 1 Aug 2001 10:43:37 +0200
-          "cpio --sparse" corrupts data. A fix attached. C.S. Attachment:
-          cpio-2.4.2-sparse.diff Description: Text document
-          /archive/html/bug-gnu-utils/2001-08/msg00000.html (3,989 bytes)
-          
-***   cpio --sparse (score: 34)
-          Author: Cezary Sliwa 
-          Date: Mon, 26 Mar 2001 10:43:34 +0200 (CEST)
-          the '--sparse' option of gnu cpio causes data corruption
-          (blocks of zeros are lost or appended to other files). C.S.
-          /archive/html/bug-gnu-utils/2001-03/msg00235.html (3,671 bytes)
-
-** And these too
-***   cpio-2.4.2: data corruption bug (score: 35)
-          Author: Todd Kelley 
-          Date: Fri, 09 Feb 2001 17:00:06 -0500
-          Hello, Recently at OEone we fixed a bug in GNU cpio-2.4.2: When
-          a file over about 0.5 megabyes grows while it is being
-          archived, it and all files following it in the archive are
-          corrupted. The crc do
-          /archive/html/bug-gnu-utils/2001-02/msg00062.html (4,297 bytes)
-          
-***   cpio pass-through can corrupt files (score: 36)
-          Author: "Parrott, Jeff" 
-          Date: Mon, 16 Oct 2000 13:32:57 -0400
-          I have seen corrupted files as a result of using the
-          pass-through option in cpio. The corruption occurs when
-          active/in-use (and growing) files are being copied. The problem
-          is that the file size has
-          /archive/html/bug-gnu-utils/2000-10/msg00087.html (4,974 bytes)
-          
-**    cpio 2.4.2 unconditionally takes the tape drive offline (score:
-          39)
-          Author: Scott Larson 
-          Date: Thu, 11 Jan 2001 13:15:52 -0800
-          We have been copying multiple volumes to a single tape with the
-          System 5 version of cpio. The gnu version of cpio doesn't
-          support this since it takes the tape offline (i.e. ejects the
-          tape) after rea
-          /archive/html/bug-gnu-utils/2001-01/msg00087.html (4,264 bytes)
-          
-**    cpio -t can see international filenames, find -ls also suffers
-          (score: 35)
-          Author: "Dan Jacobson" 
-          Date: Tue, 26 Dec 2000 07:38:53 +0800
-          GNU cpio version 2.4.2 with cpio -t I can see Chinese [big5]
-          filenames. with -tv, they become \267\247 etc Just like what
-          happens with find . -print vs. find . -ls --
-          http://www.geocities.com/jidanni
-          /archive/html/bug-gnu-utils/2000-12/msg00143.html (4,084 bytes)
-          
-* Suggestions
--------------
-
-** GNU cpio suggestion (score: 42)
-          Author: "H.J.Thomassen" 
-          Date: Mon, 17 Dec 2001 11:27:11 +0100
-          Re: suggestion for GNU-cpio extension (plus reference
-          implementation) We use cpio for our backup purposes. The backup
-          is started automatically in the middle of the night. To chase
-          away all users we d
-          /archive/html/bug-gnu-utils/2001-12/msg00244.html (7,474 bytes)
-          
-** cpio suggestion + patch (score: 38)
-          Author: Taylor Gautier 
-          Date: Fri, 20 Apr 2001 09:40:05 -0700
-          I have a suggestion for cpio. The suggestion is to make it copy
-          files into a temporary name and then rename the file as the
-          last operation. Since UNIX filesystems are supposed to
-          gaurantee atomicity
-          /archive/html/bug-gnu-utils/2001-04/msg00169.html (10,674
-          bytes)
-          
-** [cpio] man page enhancement: a Example section ? (score: 5)
-          Author: Yannick Patois 
-          Date: Wed, 24 Oct 2001 12:48:33 +0200 (CEST)
-          Hello, I seldom use cpio (as I think many people) and only had
-          to use it once or twice. IMHA, would be good to have a small
-          section with an example of most often performed actions
-          (creating an archiv
-          /archive/html/bug-gnu-utils/2001-10/msg00270.html (4,336 bytes)
-
-** Patch to cpio to enable verbose *skipping* of files (score: 40)
-          Author: Tomas Pospisek 
-          Date: Mon, 8 Oct 2001 13:54:14 +0200 (CEST)
-          This patch enables cpio to be verbose about the files that it
-          does not copy, which is very handy for seeing cpio's progress
-          through a tape or simply for debuging. The patch along with a
-          Debian packag
-          /archive/html/bug-gnu-utils/2001-10/msg00083.html (4,548 bytes)
-          
diff --git a/contrib/cpio/doc/cpio.1 b/contrib/cpio/doc/cpio.1
deleted file mode 100644
index a59094aa0c3..00000000000
--- a/contrib/cpio/doc/cpio.1
+++ /dev/null
@@ -1,41 +0,0 @@
-.TH CPIO 1L \" -*- nroff -*-
-.SH NAME
-cpio \- copy files to and from archives
-.SH SYNOPSIS
-.B cpio
-{\-o|\-\-create} [\-0acvABLV] [\-C bytes] [\-H format] [\-M message]
-[\-O [[user@]host:]archive] [\-F [[user@]host:]archive]
-[\-\-file=[[user@]host:]archive] [\-\-format=format] [\-\-message=message]
-[\-\-null] [\-\-reset-access-time] [\-\-verbose] [\-\-dot] [\-\-append]
-[\-\-block-size=blocks] [\-\-dereference] [\-\-io-size=bytes] [\-\-quiet]
-[\-\-force\-local] [\-\-rsh-command=command] [\-\-help] [\-\-version]
-< name-list [> archive]
-
-.B cpio
-{\-i|\-\-extract} [\-bcdfmnrtsuvBSV] [\-C bytes] [\-E file] [\-H format]
-[\-M message] [\-R [user][:.][group]] [\-I [[user@]host:]archive]
-[\-F [[user@]host:]archive] [\-\-file=[[user@]host:]archive]
-[\-\-make-directories] [\-\-nonmatching] [\-\-preserve-modification-time]
-[\-\-numeric-uid-gid] [\-\-rename] [\-t|\-\-list] [\-\-swap-bytes] [\-\-swap] [\-\-dot]
-[\-\-unconditional] [\-\-verbose] [\-\-block-size=blocks] [\-\-swap-halfwords]
-[\-\-io-size=bytes] [\-\-pattern-file=file] [\-\-format=format]
-[\-\-owner=[user][:.][group]] [\-\-no-preserve-owner] [\-\-message=message]
-[\-\-force\-local] [\-\-absolute\-filenames] [\-\-sparse]
-[\-\-only\-verify\-crc] [\-\-quiet] [\-\-rsh-command=command] [\-\-help]
-[\-\-version] [pattern...] [< archive]
-
-.B cpio
-{\-p|\-\-pass-through} [\-0adlmuvLV] [\-R [user][:.][group]]
-[\-\-null] [\-\-reset-access-time] [\-\-make-directories] [\-\-link] [\-\-quiet]
-[\-\-preserve-modification-time] [\-\-unconditional] [\-\-verbose] [\-\-dot]
-[\-\-dereference] [\-\-owner=[user][:.][group]] [\-\-no-preserve-owner]
-[\-\-sparse] [\-\-help] [\-\-version] destination-directory < name-list
-.SH DESCRIPTION
-GNU cpio is fully documented in the texinfo documentation. To access the
-help from your command line, type
-.PP
-\fBinfo cpio
-.PP
-The online copy of the documentation is available at the following address:
-.PP
-http://www.gnu.org/software/cpio/manual
diff --git a/contrib/cpio/doc/cpio.texi b/contrib/cpio/doc/cpio.texi
deleted file mode 100644
index 8bf4ddebb77..00000000000
--- a/contrib/cpio/doc/cpio.texi
+++ /dev/null
@@ -1,602 +0,0 @@
-\input texinfo   @c -*-texinfo-*-
-@c %**start of header
-@setfilename cpio.info
-@settitle cpio
-@setchapternewpage off
-@c %**end of header
-
-@dircategory Archiving
-@direntry
-* Cpio: (cpio).                 Copy-in-copy-out archiver to tape or disk.
-@end direntry
-
-@include version.texi
-
-@copying
-This manual documents GNU cpio (version @value{VERSION}, @value{UPDATED}).
-
-Copyright @copyright{} 1995, 2001, 2002, 2004 Free Software Foundation, Inc.
-@sp 1
-@quotation
-Permission is granted to copy, distribute and/or modify this document
-under the terms of the GNU Free Documentation License, Version 1.2 or
-any later version published by the Free Software Foundation; with no
-Invariant Sections, with the Front-Cover texts being ``A GNU Manual'',
-and with the Back-Cover Texts as in (a) below.  A copy of the license
-is included in the section entitled ``GNU Free Documentation License''.
-
-(a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
-this GNU Manual, like GNU software.  Copies published by the Free
-Software Foundation raise funds for GNU development.''
-@end quotation
-@end copying
-
-@titlepage
-@title GNU CPIO
-@subtitle @value{VERSION} @value{UPDATED}
-@author by Robert Carleton
-@c copyright page
-@page
-@vskip 0pt plus 1filll
-@insertcopying
-@sp 2
-Published by the Free Software Foundation @*
-51 Franklin Street, Fifth Floor, @*
-Boston, MA 02110-1301, USA @*
-@end titlepage
-
-@node Top, Introduction, (dir), (dir)
-@comment  node-name,  next,  previous,  up
-
-@ifinfo
-@top
-
-GNU cpio is a tool for creating and extracting archives, or copying
-files from one place to another.  It handles a number of cpio formats as
-well as reading and writing tar files.  This is the first edition of the 
-GNU cpio documentation and is consistent with @value{VERSION}.
-
-@end ifinfo
-
-@menu
-* Introduction::                
-* Tutorial::                    Getting started.
-* Invoking cpio::               How to invoke @command{cpio}.
-* Media::                       Using tapes and other archive media.
-* Reports::                     Reporting bugs or suggestions
-* Concept Index::               Concept index.
-
-@detailmenu
- --- The Detailed Node Listing ---
-
-Invoking cpio
-
-* Copy-out mode::               
-* Copy-in mode::                
-* Copy-pass mode::              
-* Options::                     
-
-@end detailmenu
-@end menu
-
-@node Introduction, Tutorial, Top, Top
-@comment  node-name,  next,  previous,  up
-@chapter Introduction
-
-GNU cpio copies files into or out of a cpio or tar archive, The archive
-can be another file on the disk, a magnetic tape, or a pipe.
-
-GNU cpio supports the following archive formats: binary, old ASCII, new
-ASCII, crc, HPUX binary, HPUX old ASCII, old tar, and POSIX.1 tar.  The
-tar format is provided for compatibility with the tar program. By
-default, cpio creates binary format archives, for compatibility with
-older cpio programs.  When extracting from archives, cpio automatically
-recognizes which kind of archive it is reading and can read archives
-created on machines with a different byte-order.
-
-@node Tutorial, Invoking cpio, Introduction, Top
-@comment  node-name,  next,  previous,  up
-@chapter Tutorial
-@cindex creating a cpio archive
-@cindex extracting a cpio archive
-@cindex copying directory structures
-@cindex passing directory structures
-
-
-GNU cpio performs three primary functions.  Copying files to an
-archive, Extracting files from an archive, and passing files to another
-directory tree.  An archive can be a file on disk, one or more floppy
-disks, or one or more tapes.
-
-When creating an archive, cpio takes the list of files to be processed
-from the standard input, and then sends the archive to the standard
-output, or to the device defined by the @option{-F} option.
-@xref{Copy-out mode}.  Usually find or ls is used to provide this list
-to the standard input.  In the following example you can see the
-possibilities for archiving the contents of a single directory.
-
-
-@example
-@cartouche
-% ls | cpio -ov > directory.cpio
-@end cartouche
-@end example
-
-The @option{-o} option creates the archive, and the @option{-v} option
-prints the names of the files archived as they are added.  Notice that
-the options can be put together after a single @option{-} or can be placed
-separately on the command line.  The @samp{>} redirects the cpio output
-to the file @samp{directory.cpio}.
-
-
-If you wanted to archive an entire directory tree, the find command can
-provide the file list to cpio:
-
-
-@example
-@cartouche
-% find . -print -depth | cpio -ov > tree.cpio
-@end cartouche
-@end example
-
-
-This will take all the files in the current directory, the directories
-below and place them in the archive tree.cpio.  Again the @option{-o}
-creates an archive, and the @option{-v} option shows you the name of the
-files as they are archived.  @xref{Copy-out mode}.  Using the @samp{.} in the
-find statement will give you more flexibility when doing restores, as it
-will save file names with a relative path vice a hard wired, absolute
-path.  The @option{-depth} option forces @samp{find} to print of the
-entries in a directory before printing the directory itself.  This
-limits the effects of restrictive directory permissions by printing the
-directory entries in a directory before the directory name itself.
-
-
-
-
-Extracting an archive requires a bit more thought because cpio will not
-create directories by default.  Another characteristic, is it will not
-overwrite existing files unless you tell it to.
-
-
-@example
-@cartouche
-% cpio -iv < directory.cpio
-@end cartouche
-@end example
-
-This will retrieve the files archived in the file directory.cpio and
-place them in the present directory.  The @option{-i} option extracts the
-archive and the @option{-v} shows the file names as they are extracted.
-If you are dealing with an archived directory tree, you need to use the
-@option{-d} option to create directories as necessary, something like:
-
-@example
-@cartouche
-% cpio -idv < tree.cpio
-@end cartouche
-@end example
-
-This will take the contents of the archive tree.cpio and extract it to
-the current directory.  If you try to extract the files on top of files
-of the same name that already exist (and have the same or later
-modification time) cpio will not extract the file unless told to do so
-by the -u option.  @xref{Copy-in mode}.
-
-
-In copy-pass mode, cpio copies files from one directory tree to another,
-combining the copy-out and copy-in steps without actually using an
-archive.  It reads the list of files to copy from the standard input;
-the directory into which it will copy them is given as a non-option
-argument.  @xref{Copy-pass mode}.
-
-@example
-@cartouche
-% find . -depth -print0 | cpio --null -pvd new-dir
-@end cartouche
-@end example
-
-
-The example shows copying the files of the present directory, and
-sub-directories to a new directory called new-dir.  Some new options are
-the @option{-print0} available with GNU find, combined with the
-@option{--null} option of cpio.  These two options act together to send
-file names between find and cpio, even if special characters are
-embedded in the file names.  Another is @option{-p}, which tells cpio to
-pass the files it finds to the directory @samp{new-dir}.
-
-@node Invoking cpio, Media, Tutorial, Top
-@comment  node-name,  next,  previous,  up
-@chapter Invoking cpio
-@cindex invoking cpio
-@cindex command line options
-
-@menu
-* Copy-out mode::               
-* Copy-in mode::                
-* Copy-pass mode::              
-* Options::                     
-@end menu
-
-@node Copy-out mode, Copy-in mode, Invoking cpio, Invoking cpio
-@comment  node-name,  next,  previous,  up
-@section Copy-out mode
-
-In copy-out mode, cpio copies files into an archive.  It reads a list
-of filenames, one per line, on the standard input, and writes the
-archive onto the standard output.  A typical way to generate the list
-of filenames is with the find command; you should give find the -depth
-option to minimize problems with permissions on directories that are
-unreadable.
-@xref{Options}.
-
-@example
-cpio @{-o|--create@} [-0acvABLV] [-C bytes] [-H format]
-[-M message] [-O [[user@@]host:]archive] [-F [[user@@]host:]archive]
-[--file=[[user@@]host:]archive] [--format=format]
-[--message=message][--null] [--reset-access-time] [--verbose]
-[--dot] [--append] [--block-size=blocks] [--dereference]
-[--io-size=bytes] [--rsh-command=command] [--help] [--version]
-< name-list [> archive]
-@end example
-
-@node Copy-in mode, Copy-pass mode, Copy-out mode, Invoking cpio
-@comment  node-name,  next,  previous,  up
-@section Copy-in mode
-
-In copy-in mode, cpio copies files out of an archive or lists the
-archive contents.  It reads the archive from the standard input.  Any
-non-option command line arguments are shell globbing patterns; only
-files in the archive whose names match one or more of those patterns are
-copied from the archive.  Unlike in the shell, an initial @samp{.} in a
-filename does match a wildcard at the start of a pattern, and a @samp{/} in a
-filename can match wildcards.  If no patterns are given, all files are
-extracted.  @xref{Options}.
-
-@example
-cpio @{-i|--extract@} [-bcdfmnrtsuvBSV] [-C bytes] [-E file]
-[-H format] [-M message] [-R [user][:.][group]]
-[-I [[user@@]host:]archive] [-F [[user@@]host:]archive]
-[--file=[[user@@]host:]archive] [--make-directories]
-[--nonmatching] [--preserve-modification-time]
-[--numeric-uid-gid] [--rename] [--list] [--swap-bytes] [--swap]
-[--dot] [--unconditional] [--verbose] [--block-size=blocks]
-[--swap-halfwords] [--io-size=bytes] [--pattern-file=file]
-[--format=format] [--owner=[user][:.][group]]
-[--no-preserve-owner] [--message=message] [--help] [--version]
-[--absolute-filenames] [--sparse] [-only-verify-crc] [-quiet]
-[--rsh-command=command] [pattern...] [< archive]
-@end example
-
-@node Copy-pass mode, Options, Copy-in mode, Invoking cpio
-@comment  node-name,  next,  previous,  up
-@section Copy-pass mode
-
-In copy-pass mode, cpio copies files from one directory tree to
-another, combining the copy-out and copy-in steps without actually
-using an archive.  It reads the list of files to copy from the
-standard input; the directory into which it will copy them is given as
-a non-option argument.
-@xref{Options}.
-
-@example
-cpio @{-p|--pass-through@} [-0adlmuvLV] [-R [user][:.][group]]
-[--null] [--reset-access-time] [--make-directories] [--link]
-[--preserve-modification-time] [--unconditional] [--verbose]
-[--dot] [--dereference] [--owner=[user][:.][group]] [--sparse]
-[--no-preserve-owner] [--help] [--version] destination-directory
-< name-list
-@end example
-
-
-
-@node Options,  , Copy-pass mode, Invoking cpio
-@comment  node-name,  next,  previous,  up
-@section Options
-
-
-@table @code
-
-
-@item -0
-@itemx --null
-Read a list of filenames terminated by a null character, instead of a
-newline, so that files whose names contain newlines can be archived.
-GNU find is one way to produce a list of null-terminated filenames.
-This option may be used in copy-out and copy-pass modes.
-
-@item -a
-@itemx --reset-access-time
-Reset the access times of files after reading them, so
-that it does not look like they have just been read.
-
-@item -A
-@itemx --append
-Append to an existing archive.  Only works in copy-out
-mode.  The archive must be a disk file specified with
-the @option{-O} or @option{-F} (@option{--file}) option.
-
-@item -b
-@itemx --swap
-Swap both halfwords of words and bytes of halfwords in the data.
-Equivalent to -sS.  This option may be used in copy-in mode.  Use this
-option to convert 32-bit integers between big-endian and little-endian
-machines.
-
-@item -B   
-Set the I/O block size to 5120 bytes.  Initially the
-block size is 512 bytes.
-
-@item --block-size=@var{block-size}
-Set the I/O block size to @var{block-size} * 512 bytes.
-
-@item -c
-Use the old portable (ASCII) archive format.
-
-@item -C @var{io-size}
-@itemx --io-size=@var{io-size}
-Set the I/O block size to @var{io-size} bytes.
-
-@item -d
-@itemx --make-directories
-Create leading directories where needed.
-
-@item -E @var{file}
-@itemx --pattern-file=@var{file}
-Read additional patterns specifying filenames to extract or list from
-@var{file}.  The lines of @var{file} are treated as if they had been non-option
-arguments to cpio.  This option is used in copy-in mode,
-
-@item -f
-@itemx --nonmatching
-Only copy files that do not match any of the given
-patterns.
-
-@item -F @var{archive}
-@itemx --file=@var{archive}
-Archive filename to use instead of standard input or output.  To use a
-tape drive on another machine as the archive, use a filename that starts
-with @samp{@var{hostname}:}, where @var{hostname} is the name or IP
-address of the machine.  The hostname can be preceded by a username and an
-@samp{@@} to access the remote tape drive as that user, if you have
-permission to do so (typically an entry in that user's @file{~/.rhosts}
-file).
-
-@item --force-local
-With @option{-F}, @option{-I}, or @option{-O}, take the archive file name to be a
-local file even if it contains a colon, which would
-ordinarily indicate a remote host name.
-
-@item -H @var{format}
-@itemx --format=@var{format}
-Use archive format @var{format}.  The valid formats are listed below; the same
-names are also recognized in all-caps.  The default in copy-in mode is
-to automatically detect the archive format, and in copy-out mode is
-@samp{bin}.
-
-@table @samp
-@item bin  
-The obsolete binary format.
-
-@item odc
-The old (POSIX.1) portable format.
-
-@item newc
-The new (SVR4) portable format, which supports file systems having more
-than 65536 i-nodes.
-
-@item crc
-The new (SVR4) portable format with a checksum added.
-
-@item tar
-The old tar format.
-
-@item ustar
-The POSIX.1 tar format.  Also recognizes GNU tar archives, which are
-similar but not identical.
-
-@item hpbin
-The obsolete binary format used by HPUX's cpio (which stores device
-files differently).
-
-@item hpodc
-The portable format used by HPUX's cpio (which stores device files
-differently).
-@end table
-
-@item -i
-@itemx --extract
-Run in copy-in mode.
-@xref{Copy-in mode}.
-
-@item -I @var{archive}
-Archive filename to use instead of standard input.  To use a tape drive
-on another machine as the archive, use a filename that starts with
-@samp{@var{hostname}:}, where @var{hostname} is the name or IP address
-of the remote host.  The hostname can be preceded by a username and an @samp{@@} to
-access the remote tape drive as that user, if you have permission to do
-so (typically an entry in that user's @file{~/.rhosts} file).
-
-@item -k
-Ignored; for compatibility with other versions of cpio.
-
-@item -l
-@itemx --link
-Link files instead of copying them, when possible.
-
-@item -L
-@itemx --dereference
-Copy the file that a symbolic link points to, rather than the symbolic
-link itself.
-
-@item -m
-@itemx --preserve-modification-time
-Retain previous file modification times when creating files.
-
-@item -M @var{message}
-@itemx --message=@var{message}
-Print @var{message} when the end of a volume of the backup media (such as a
-tape or a floppy disk) is reached, to prompt the user to insert a new
-volume.  If @var{message} contains the string @samp{%d}, it is replaced by the
-current volume number (starting at 1).
-
-@item -n
-@itemx --numeric-uid-gid
-Show numeric UID and GID instead of translating them into names when using the
-@option{--verbose} option.
-
-@item --absolute-filenames
-Do not strip leading file name components that contain ".." and
-leading slashes from file names in copy-in mode
-
-@item --no-preserve-owner
-Do not change the ownership of the files; leave them owned by the user
-extracting them.  This is the default for non-root users, so that users
-on System V don't inadvertantly give away files.  This option can be
-used in copy-in mode and copy-pass mode
-
-@item -o
-@itemx --create
-Run in copy-out mode.
-@xref{Copy-out mode}.
-
-@item -O @var{archive}
-Archive filename to use instead of standard output.  To use a tape drive
-on another machine as the archive, use a filename that starts with
-@samp{@var{hostname}:}, where @var{hostname} is the name or IP address
-of the machine.  The hostname can be preceded by a username and an @samp{@@} to
-access the remote tape drive as that user, if you have permission to do
-so (typically an entry in that user's @file{~/.rhosts} file).
-
-@item --only-verify-crc
-Verify the CRC's of each file in the archive, when reading a CRC format
-archive. Don't actually extract the files.
-
-@item -p
-@itemx --pass-through
-Run in copy-pass mode.
-@xref{Copy-pass mode}.
-
-@item --quiet
-Do not print the number of blocks copied.
-
-@item -r
-@itemx --rename
-Interactively rename files.
-
-@item -R @var{owner}
-@itemx --owner @var{owner}
-
-In copy-in and copy-pass mode, set the ownership of all files created
-to the specified @var{owner} (this operation is allowed only for the
-super-user). In copy-out mode, store the supplied owner information in
-the archive. 
-
-The argument can be either the user name or the user name
-and group name, separated by a dot or a colon, or the group name,
-preceeded by a dot or a colon, as shown in the examples below:
-
-@smallexample
-@group
-cpio --owner smith
-cpio --owner smith:
-cpio --owner smith:users
-cpio --owner :users
-@end group
-@end smallexample
-
-@noindent
-If the group is omitted but the @samp{:} or @samp{.} separator is
-given, as in the second example. the given user's login group will be
-used.  
-
-@item --rsh-command=@var{command}
-Notifies cpio that is should use @var{command} to communicate with remote
-devices.
-
-@item -s
-@itemx --swap-bytes
-Swap the bytes of each halfword (pair of bytes) in the files. This option
-can be used in copy-in mode.
-
-@item -S
-@itemx --swap-halfwords
-Swap the halfwords of each word (4 bytes) in the files.  This option may
-be used in copy-in mode.
-
-@item --sparse
-Write files with large blocks of zeros as sparse files.  This option is
-used in copy-in and copy-pass modes.
-
-@item -t
-@itemx --list
-Print a table of contents of the input.
-
-@item -u
-@itemx --unconditional
-Replace all files, without asking whether to replace
-existing newer files with older files.
-
-@item -v
-@itemx --verbose
-List the files processed, or with @option{-t}, give an @samp{ls -l} style
-table of contents listing.  In a verbose table of contents of a ustar
-archive, user and group names in the archive that do not exist on the
-local system are replaced by the names that correspond locally to the
-numeric UID and GID stored in the archive.
-
-@item -V
-@itemx --dot
-Print a @samp{.} for each file processed.
-
-@item --version
-Print the cpio program version number and exit.
-@end table
-
-
-@node Media, Reports, Invoking cpio, Top
-@comment  node-name,  next,  previous,  up
-@chapter Magnetic Media
-@cindex magnetic media
-
-Archives are usually written on removable media--tape cartridges, mag
-tapes, or floppy disks.
-
-The amount of data a tape or disk holds depends not only on its size,
-but also on how it is formatted.  A 2400 foot long reel of mag tape
-holds 40 megabytes of data when formated at 1600 bits per inch.  The
-physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
-
-Magnetic media are re-usable--once the archive on a tape is no longer
-needed, the archive can be erased and the tape or disk used over. Media
-quality does deteriorate with use, however.  Most tapes or disks should
-be disgarded when they begin to produce data errors.
-
-Magnetic media are written and erased using magnetic fields, and should
-be protected from such fields to avoid damage to stored data.  Sticking
-a floppy disk to a filing cabinet using a magnet is probably not a good
-idea.
-
-@node Reports, Concept Index, Media, Top
-@chapter Reporting bugs or suggestions
-
-It is possible you will encounter a bug in @command{cpio}.
-If this happens, we would like to hear about it. As the purpose of bug
-reporting is to improve software, please be sure to include maximum
-information when reporting a bug. The information needed is:
-
-@itemize @bullet
-@item Version of the package you are using.
-@item Compilation options used when configuring the package.
-@item Conditions under which the bug appears.
-@end itemize 
-
-Send your report to . Allow us a couple of
-days to answer.
-
-@node Concept Index, , Reports, Top
-@comment  node-name,  next,  previous,  up
-@unnumbered Concept Index
-@printindex cp
-@contents
-@bye
diff --git a/contrib/cpio/doc/version.texi b/contrib/cpio/doc/version.texi
deleted file mode 100644
index c20cd8cc39c..00000000000
--- a/contrib/cpio/doc/version.texi
+++ /dev/null
@@ -1,4 +0,0 @@
-@set UPDATED 7 June 2007
-@set UPDATED-MONTH June 2007
-@set EDITION 2.8
-@set VERSION 2.8
diff --git a/contrib/cpio/lib/alloca_.h b/contrib/cpio/lib/alloca_.h
deleted file mode 100644
index af274b9e753..00000000000
--- a/contrib/cpio/lib/alloca_.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* Memory allocation on the stack.
-
-   Copyright (C) 1995, 1999, 2001-2004, 2006-2007 Free Software
-   Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU General Public License as published
-   by the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-   USA.  */
-
-/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
-   means there is a real alloca function.  */
-#ifndef _GL_ALLOCA_H
-#define _GL_ALLOCA_H
-
-/* alloca (N) returns a pointer to N bytes of memory
-   allocated on the stack, which will last until the function returns.
-   Use of alloca should be avoided:
-     - inside arguments of function calls - undefined behaviour,
-     - in inline functions - the allocation may actually last until the
-       calling function returns,
-     - for huge N (say, N >= 65536) - you never know how large (or small)
-       the stack is, and when the stack cannot fulfill the memory allocation
-       request, the program just crashes.
- */
-
-#ifndef alloca
-# ifdef __GNUC__
-#  define alloca __builtin_alloca
-# elif defined _AIX
-#  define alloca __alloca
-# elif defined _MSC_VER
-#  include 
-#  define alloca _alloca
-# else
-#  include 
-#  ifdef  __cplusplus
-extern "C"
-#  endif
-void *alloca (size_t);
-# endif
-#endif
-
-#endif /* _GL_ALLOCA_H */
diff --git a/contrib/cpio/lib/argp-ba.c b/contrib/cpio/lib/argp-ba.c
deleted file mode 100644
index 8bb7309fdec..00000000000
--- a/contrib/cpio/lib/argp-ba.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Default definition for ARGP_PROGRAM_BUG_ADDRESS.
-   Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Written by Miles Bader .
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* If set by the user program, it should point to string that is the
-   bug-reporting address for the program.  It will be printed by argp_help if
-   the ARGP_HELP_BUG_ADDR flag is set (as it is by various standard help
-   messages), embedded in a sentence that says something like `Report bugs to
-   ADDR.'.  */
-const char *argp_program_bug_address;
diff --git a/contrib/cpio/lib/argp-eexst.c b/contrib/cpio/lib/argp-eexst.c
deleted file mode 100644
index bcab1c0c17f..00000000000
--- a/contrib/cpio/lib/argp-eexst.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* Default definition for ARGP_ERR_EXIT_STATUS
-   Copyright (C) 1997 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Written by Miles Bader .
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-#ifdef HAVE_CONFIG_H
-# include 
-#endif
-
-#include 
-
-#include "argp.h"
-
-/* The exit status that argp will use when exiting due to a parsing error.
-   If not defined or set by the user program, this defaults to EX_USAGE from
-   .  */
-error_t argp_err_exit_status = EX_USAGE;
diff --git a/contrib/cpio/lib/argp-fmtstream.c b/contrib/cpio/lib/argp-fmtstream.c
deleted file mode 100644
index 0dd9256f570..00000000000
--- a/contrib/cpio/lib/argp-fmtstream.c
+++ /dev/null
@@ -1,435 +0,0 @@
-/* Word-wrapping and line-truncating streams
-   Copyright (C) 1997-1999,2001,2002,2003,2005 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Written by Miles Bader .
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-/* This package emulates glibc `line_wrap_stream' semantics for systems that
-   don't have that.  */
-
-#ifdef HAVE_CONFIG_H
-# include 
-#endif
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "argp-fmtstream.h"
-#include "argp-namefrob.h"
-
-#ifndef ARGP_FMTSTREAM_USE_LINEWRAP
-
-#ifndef isblank
-#define isblank(ch) ((ch)==' ' || (ch)=='\t')
-#endif
-
-#if defined _LIBC && defined USE_IN_LIBIO
-# include 
-# include 
-# define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a)
-#endif
-
-#define INIT_BUF_SIZE 200
-#define PRINTF_SIZE_GUESS 150
-
-/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
-   written on it with LMARGIN spaces and limits them to RMARGIN columns
-   total.  If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
-   replacing the whitespace before them with a newline and WMARGIN spaces.
-   Otherwise, chars beyond RMARGIN are simply dropped until a newline.
-   Returns NULL if there was an error.  */
-argp_fmtstream_t
-__argp_make_fmtstream (FILE *stream,
-		       size_t lmargin, size_t rmargin, ssize_t wmargin)
-{
-  argp_fmtstream_t fs;
-
-  fs = (struct argp_fmtstream *) malloc (sizeof (struct argp_fmtstream));
-  if (fs != NULL)
-    {
-      fs->stream = stream;
-
-      fs->lmargin = lmargin;
-      fs->rmargin = rmargin;
-      fs->wmargin = wmargin;
-      fs->point_col = 0;
-      fs->point_offs = 0;
-
-      fs->buf = (char *) malloc (INIT_BUF_SIZE);
-      if (! fs->buf)
-	{
-	  free (fs);
-	  fs = 0;
-	}
-      else
-	{
-	  fs->p = fs->buf;
-	  fs->end = fs->buf + INIT_BUF_SIZE;
-	}
-    }
-
-  return fs;
-}
-#if 0
-/* Not exported.  */
-#ifdef weak_alias
-weak_alias (__argp_make_fmtstream, argp_make_fmtstream)
-#endif
-#endif
-
-/* Flush FS to its stream, and free it (but don't close the stream).  */
-void
-__argp_fmtstream_free (argp_fmtstream_t fs)
-{
-  __argp_fmtstream_update (fs);
-  if (fs->p > fs->buf)
-    {
-#ifdef USE_IN_LIBIO
-      __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf);
-#else
-      fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
-#endif
-    }
-  free (fs->buf);
-  free (fs);
-}
-#if 0
-/* Not exported.  */
-#ifdef weak_alias
-weak_alias (__argp_fmtstream_free, argp_fmtstream_free)
-#endif
-#endif
-
-/* Process FS's buffer so that line wrapping is done from POINT_OFFS to the
-   end of its buffer.  This code is mostly from glibc stdio/linewrap.c.  */
-void
-__argp_fmtstream_update (argp_fmtstream_t fs)
-{
-  char *buf, *nl;
-  size_t len;
-
-  /* Scan the buffer for newlines.  */
-  buf = fs->buf + fs->point_offs;
-  while (buf < fs->p)
-    {
-      size_t r;
-
-      if (fs->point_col == 0 && fs->lmargin != 0)
-	{
-	  /* We are starting a new line.  Print spaces to the left margin.  */
-	  const size_t pad = fs->lmargin;
-	  if (fs->p + pad < fs->end)
-	    {
-	      /* We can fit in them in the buffer by moving the
-		 buffer text up and filling in the beginning.  */
-	      memmove (buf + pad, buf, fs->p - buf);
-	      fs->p += pad; /* Compensate for bigger buffer. */
-	      memset (buf, ' ', pad); /* Fill in the spaces.  */
-	      buf += pad; /* Don't bother searching them.  */
-	    }
-	  else
-	    {
-	      /* No buffer space for spaces.  Must flush.  */
-	      size_t i;
-	      for (i = 0; i < pad; i++)
-		{
-#ifdef USE_IN_LIBIO
-		  if (_IO_fwide (fs->stream, 0) > 0)
-		    putwc_unlocked (L' ', fs->stream);
-		  else
-#endif
-		    putc_unlocked (' ', fs->stream);
-		}
-	    }
-	  fs->point_col = pad;
-	}
-
-      len = fs->p - buf;
-      nl = memchr (buf, '\n', len);
-
-      if (fs->point_col < 0)
-	fs->point_col = 0;
-
-      if (!nl)
-	{
-	  /* The buffer ends in a partial line.  */
-
-	  if (fs->point_col + len < fs->rmargin)
-	    {
-	      /* The remaining buffer text is a partial line and fits
-		 within the maximum line width.  Advance point for the
-		 characters to be written and stop scanning.  */
-	      fs->point_col += len;
-	      break;
-	    }
-	  else
-	    /* Set the end-of-line pointer for the code below to
-	       the end of the buffer.  */
-	    nl = fs->p;
-	}
-      else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin)
-	{
-	  /* The buffer contains a full line that fits within the maximum
-	     line width.  Reset point and scan the next line.  */
-	  fs->point_col = 0;
-	  buf = nl + 1;
-	  continue;
-	}
-
-      /* This line is too long.  */
-      r = fs->rmargin - 1;
-
-      if (fs->wmargin < 0)
-	{
-	  /* Truncate the line by overwriting the excess with the
-	     newline and anything after it in the buffer.  */
-	  if (nl < fs->p)
-	    {
-	      memmove (buf + (r - fs->point_col), nl, fs->p - nl);
-	      fs->p -= buf + (r - fs->point_col) - nl;
-	      /* Reset point for the next line and start scanning it.  */
-	      fs->point_col = 0;
-	      buf += r + 1; /* Skip full line plus \n. */
-	    }
-	  else
-	    {
-	      /* The buffer ends with a partial line that is beyond the
-		 maximum line width.  Advance point for the characters
-		 written, and discard those past the max from the buffer.  */
-	      fs->point_col += len;
-	      fs->p -= fs->point_col - r;
-	      break;
-	    }
-	}
-      else
-	{
-	  /* Do word wrap.  Go to the column just past the maximum line
-	     width and scan back for the beginning of the word there.
-	     Then insert a line break.  */
-
-	  char *p, *nextline;
-	  int i;
-
-	  p = buf + (r + 1 - fs->point_col);
-	  while (p >= buf && !isblank (*p))
-	    --p;
-	  nextline = p + 1;	/* This will begin the next line.  */
-
-	  if (nextline > buf)
-	    {
-	      /* Swallow separating blanks.  */
-	      if (p >= buf)
-		do
-		  --p;
-		while (p >= buf && isblank (*p));
-	      nl = p + 1;	/* The newline will replace the first blank. */
-	    }
-	  else
-	    {
-	      /* A single word that is greater than the maximum line width.
-		 Oh well.  Put it on an overlong line by itself.  */
-	      p = buf + (r + 1 - fs->point_col);
-	      /* Find the end of the long word.  */
-	      if (p < nl)
-		do
-		  ++p;
-		while (p < nl && !isblank (*p));
-	      if (p == nl)
-		{
-		  /* It already ends a line.  No fussing required.  */
-		  fs->point_col = 0;
-		  buf = nl + 1;
-		  continue;
-		}
-	      /* We will move the newline to replace the first blank.  */
-	      nl = p;
-	      /* Swallow separating blanks.  */
-	      do
-		++p;
-	      while (isblank (*p));
-	      /* The next line will start here.  */
-	      nextline = p;
-	    }
-
-	  /* Note: There are a bunch of tests below for
-	     NEXTLINE == BUF + LEN + 1; this case is where NL happens to fall
-	     at the end of the buffer, and NEXTLINE is in fact empty (and so
-	     we need not be careful to maintain its contents).  */
-
-	  if ((nextline == buf + len + 1
-	       ? fs->end - nl < fs->wmargin + 1
-	       : nextline - (nl + 1) < fs->wmargin)
-	      && fs->p > nextline)
-	    {
-	      /* The margin needs more blanks than we removed.  */
-	      if (fs->end - fs->p > fs->wmargin + 1)
-		/* Make some space for them.  */
-		{
-		  size_t mv = fs->p - nextline;
-		  memmove (nl + 1 + fs->wmargin, nextline, mv);
-		  nextline = nl + 1 + fs->wmargin;
-		  len = nextline + mv - buf;
-		  *nl++ = '\n';
-		}
-	      else
-		/* Output the first line so we can use the space.  */
-		{
-#ifdef _LIBC
-		  __fxprintf (fs->stream, "%.*s\n",
-			      (int) (nl - fs->buf), fs->buf);
-#else
-		  if (nl > fs->buf)
-		    fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream);
-		  putc_unlocked ('\n', fs->stream);
-#endif
-
-		  len += buf - fs->buf;
-		  nl = buf = fs->buf;
-		}
-	    }
-	  else
-	    /* We can fit the newline and blanks in before
-	       the next word.  */
-	    *nl++ = '\n';
-
-	  if (nextline - nl >= fs->wmargin
-	      || (nextline == buf + len + 1 && fs->end - nextline >= fs->wmargin))
-	    /* Add blanks up to the wrap margin column.  */
-	    for (i = 0; i < fs->wmargin; ++i)
-	      *nl++ = ' ';
-	  else
-	    for (i = 0; i < fs->wmargin; ++i)
-#ifdef USE_IN_LIBIO
-	      if (_IO_fwide (fs->stream, 0) > 0)
-		putwc_unlocked (L' ', fs->stream);
-	      else
-#endif
-		putc_unlocked (' ', fs->stream);
-
-	  /* Copy the tail of the original buffer into the current buffer
-	     position.  */
-	  if (nl < nextline)
-	    memmove (nl, nextline, buf + len - nextline);
-	  len -= nextline - buf;
-
-	  /* Continue the scan on the remaining lines in the buffer.  */
-	  buf = nl;
-
-	  /* Restore bufp to include all the remaining text.  */
-	  fs->p = nl + len;
-
-	  /* Reset the counter of what has been output this line.  If wmargin
-	     is 0, we want to avoid the lmargin getting added, so we set
-	     point_col to a magic value of -1 in that case.  */
-	  fs->point_col = fs->wmargin ? fs->wmargin : -1;
-	}
-    }
-
-  /* Remember that we've scanned as far as the end of the buffer.  */
-  fs->point_offs = fs->p - fs->buf;
-}
-
-/* Ensure that FS has space for AMOUNT more bytes in its buffer, either by
-   growing the buffer, or by flushing it.  True is returned iff we succeed. */
-int
-__argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount)
-{
-  if ((size_t) (fs->end - fs->p) < amount)
-    {
-      ssize_t wrote;
-
-      /* Flush FS's buffer.  */
-      __argp_fmtstream_update (fs);
-
-#ifdef _LIBC
-      __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf);
-      wrote = fs->p - fs->buf;
-#else
-      wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
-#endif
-      if (wrote == fs->p - fs->buf)
-	{
-	  fs->p = fs->buf;
-	  fs->point_offs = 0;
-	}
-      else
-	{
-	  fs->p -= wrote;
-	  fs->point_offs -= wrote;
-	  memmove (fs->buf, fs->buf + wrote, fs->p - fs->buf);
-	  return 0;
-	}
-
-      if ((size_t) (fs->end - fs->buf) < amount)
-	/* Gotta grow the buffer.  */
-	{
-	  size_t old_size = fs->end - fs->buf;
-	  size_t new_size = old_size + amount;
-	  char *new_buf;
-
-	  if (new_size < old_size || ! (new_buf = realloc (fs->buf, new_size)))
-	    {
-	      __set_errno (ENOMEM);
-	      return 0;
-	    }
-
-	  fs->buf = new_buf;
-	  fs->end = new_buf + new_size;
-	  fs->p = fs->buf;
-	}
-    }
-
-  return 1;
-}
-
-ssize_t
-__argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...)
-{
-  int out;
-  size_t avail;
-  size_t size_guess = PRINTF_SIZE_GUESS; /* How much space to reserve. */
-
-  do
-    {
-      va_list args;
-
-      if (! __argp_fmtstream_ensure (fs, size_guess))
-	return -1;
-
-      va_start (args, fmt);
-      avail = fs->end - fs->p;
-      out = __vsnprintf (fs->p, avail, fmt, args);
-      va_end (args);
-      if ((size_t) out >= avail)
-	size_guess = out + 1;
-    }
-  while ((size_t) out >= avail);
-
-  fs->p += out;
-
-  return out;
-}
-#if 0
-/* Not exported.  */
-#ifdef weak_alias
-weak_alias (__argp_fmtstream_printf, argp_fmtstream_printf)
-#endif
-#endif
-
-#endif /* !ARGP_FMTSTREAM_USE_LINEWRAP */
diff --git a/contrib/cpio/lib/argp-fmtstream.h b/contrib/cpio/lib/argp-fmtstream.h
deleted file mode 100644
index e045a723da4..00000000000
--- a/contrib/cpio/lib/argp-fmtstream.h
+++ /dev/null
@@ -1,301 +0,0 @@
-/* Word-wrapping and line-truncating streams.
-   Copyright (C) 1997, 2006 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Written by Miles Bader .
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-/* This package emulates glibc `line_wrap_stream' semantics for systems that
-   don't have that.  If the system does have it, it is just a wrapper for
-   that.  This header file is only used internally while compiling argp, and
-   shouldn't be installed.  */
-
-#ifndef _ARGP_FMTSTREAM_H
-#define _ARGP_FMTSTREAM_H
-
-#include 
-#include 
-#include 
-
-#ifndef __attribute__
-/* This feature is available in gcc versions 2.5 and later.  */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
-#  define __attribute__(Spec) /* empty */
-# endif
-/* The __-protected variants of `format' and `printf' attributes
-   are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || __STRICT_ANSI__
-#  define __format__ format
-#  define __printf__ printf
-# endif
-#endif
-
-#if    (_LIBC - 0 && !defined (USE_IN_LIBIO)) \
-    || (defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H))
-/* line_wrap_stream is available, so use that.  */
-#define ARGP_FMTSTREAM_USE_LINEWRAP
-#endif
-
-#ifdef ARGP_FMTSTREAM_USE_LINEWRAP
-/* Just be a simple wrapper for line_wrap_stream; the semantics are
-   *slightly* different, as line_wrap_stream doesn't actually make a new
-   object, it just modifies the given stream (reversibly) to do
-   line-wrapping.  Since we control who uses this code, it doesn't matter.  */
-
-#include 
-
-typedef FILE *argp_fmtstream_t;
-
-#define argp_make_fmtstream line_wrap_stream
-#define __argp_make_fmtstream line_wrap_stream
-#define argp_fmtstream_free line_unwrap_stream
-#define __argp_fmtstream_free line_unwrap_stream
-
-#define __argp_fmtstream_putc(fs,ch) putc(ch,fs)
-#define argp_fmtstream_putc(fs,ch) putc(ch,fs)
-#define __argp_fmtstream_puts(fs,str) fputs(str,fs)
-#define argp_fmtstream_puts(fs,str) fputs(str,fs)
-#define __argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
-#define argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
-#define __argp_fmtstream_printf fprintf
-#define argp_fmtstream_printf fprintf
-
-#define __argp_fmtstream_lmargin line_wrap_lmargin
-#define argp_fmtstream_lmargin line_wrap_lmargin
-#define __argp_fmtstream_set_lmargin line_wrap_set_lmargin
-#define argp_fmtstream_set_lmargin line_wrap_set_lmargin
-#define __argp_fmtstream_rmargin line_wrap_rmargin
-#define argp_fmtstream_rmargin line_wrap_rmargin
-#define __argp_fmtstream_set_rmargin line_wrap_set_rmargin
-#define argp_fmtstream_set_rmargin line_wrap_set_rmargin
-#define __argp_fmtstream_wmargin line_wrap_wmargin
-#define argp_fmtstream_wmargin line_wrap_wmargin
-#define __argp_fmtstream_set_wmargin line_wrap_set_wmargin
-#define argp_fmtstream_set_wmargin line_wrap_set_wmargin
-#define __argp_fmtstream_point line_wrap_point
-#define argp_fmtstream_point line_wrap_point
-
-#else /* !ARGP_FMTSTREAM_USE_LINEWRAP */
-/* Guess we have to define our own version.  */
-
-struct argp_fmtstream
-{
-  FILE *stream;			/* The stream we're outputting to.  */
-
-  size_t lmargin, rmargin;	/* Left and right margins.  */
-  ssize_t wmargin;		/* Margin to wrap to, or -1 to truncate.  */
-
-  /* Point in buffer to which we've processed for wrapping, but not output.  */
-  size_t point_offs;
-  /* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin.  */
-  ssize_t point_col;
-
-  char *buf;			/* Output buffer.  */
-  char *p;			/* Current end of text in BUF. */
-  char *end;			/* Absolute end of BUF.  */
-};
-
-typedef struct argp_fmtstream *argp_fmtstream_t;
-
-/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
-   written on it with LMARGIN spaces and limits them to RMARGIN columns
-   total.  If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
-   replacing the whitespace before them with a newline and WMARGIN spaces.
-   Otherwise, chars beyond RMARGIN are simply dropped until a newline.
-   Returns NULL if there was an error.  */
-extern argp_fmtstream_t __argp_make_fmtstream (FILE *__stream,
-					       size_t __lmargin,
-					       size_t __rmargin,
-					       ssize_t __wmargin);
-extern argp_fmtstream_t argp_make_fmtstream (FILE *__stream,
-					     size_t __lmargin,
-					     size_t __rmargin,
-					     ssize_t __wmargin);
-
-/* Flush __FS to its stream, and free it (but don't close the stream).  */
-extern void __argp_fmtstream_free (argp_fmtstream_t __fs);
-extern void argp_fmtstream_free (argp_fmtstream_t __fs);
-
-extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs,
-					const char *__fmt, ...)
-     __attribute__ ((__format__ (printf, 2, 3)));
-extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs,
-				      const char *__fmt, ...)
-     __attribute__ ((__format__ (printf, 2, 3)));
-
-extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
-extern int argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
-
-extern int __argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str);
-extern int argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str);
-
-extern size_t __argp_fmtstream_write (argp_fmtstream_t __fs,
-				      const char *__str, size_t __len);
-extern size_t argp_fmtstream_write (argp_fmtstream_t __fs,
-				    const char *__str, size_t __len);
-
-/* Access macros for various bits of state.  */
-#define argp_fmtstream_lmargin(__fs) ((__fs)->lmargin)
-#define argp_fmtstream_rmargin(__fs) ((__fs)->rmargin)
-#define argp_fmtstream_wmargin(__fs) ((__fs)->wmargin)
-#define __argp_fmtstream_lmargin argp_fmtstream_lmargin
-#define __argp_fmtstream_rmargin argp_fmtstream_rmargin
-#define __argp_fmtstream_wmargin argp_fmtstream_wmargin
-
-/* Set __FS's left margin to LMARGIN and return the old value.  */
-extern size_t argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
-					  size_t __lmargin);
-extern size_t __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
-					    size_t __lmargin);
-
-/* Set __FS's right margin to __RMARGIN and return the old value.  */
-extern size_t argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
-					  size_t __rmargin);
-extern size_t __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
-					    size_t __rmargin);
-
-/* Set __FS's wrap margin to __WMARGIN and return the old value.  */
-extern size_t argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
-					  size_t __wmargin);
-extern size_t __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
-					    size_t __wmargin);
-
-/* Return the column number of the current output point in __FS.  */
-extern size_t argp_fmtstream_point (argp_fmtstream_t __fs);
-extern size_t __argp_fmtstream_point (argp_fmtstream_t __fs);
-
-/* Internal routines.  */
-extern void _argp_fmtstream_update (argp_fmtstream_t __fs);
-extern void __argp_fmtstream_update (argp_fmtstream_t __fs);
-extern int _argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
-extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
-
-#ifdef __OPTIMIZE__
-/* Inline versions of above routines.  */
-
-#if !_LIBC
-#define __argp_fmtstream_putc argp_fmtstream_putc
-#define __argp_fmtstream_puts argp_fmtstream_puts
-#define __argp_fmtstream_write argp_fmtstream_write
-#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin
-#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin
-#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin
-#define __argp_fmtstream_point argp_fmtstream_point
-#define __argp_fmtstream_update _argp_fmtstream_update
-#define __argp_fmtstream_ensure _argp_fmtstream_ensure
-#endif
-
-#ifndef ARGP_FS_EI
-#define ARGP_FS_EI extern inline
-#endif
-
-ARGP_FS_EI size_t
-__argp_fmtstream_write (argp_fmtstream_t __fs,
-			const char *__str, size_t __len)
-{
-  if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len))
-    {
-      memcpy (__fs->p, __str, __len);
-      __fs->p += __len;
-      return __len;
-    }
-  else
-    return 0;
-}
-
-ARGP_FS_EI int
-__argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str)
-{
-  size_t __len = strlen (__str);
-  if (__len)
-    {
-      size_t __wrote = __argp_fmtstream_write (__fs, __str, __len);
-      return __wrote == __len ? 0 : -1;
-    }
-  else
-    return 0;
-}
-
-ARGP_FS_EI int
-__argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch)
-{
-  if (__fs->p < __fs->end || __argp_fmtstream_ensure (__fs, 1))
-    return *__fs->p++ = __ch;
-  else
-    return EOF;
-}
-
-/* Set __FS's left margin to __LMARGIN and return the old value.  */
-ARGP_FS_EI size_t
-__argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin)
-{
-  size_t __old;
-  if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
-    __argp_fmtstream_update (__fs);
-  __old = __fs->lmargin;
-  __fs->lmargin = __lmargin;
-  return __old;
-}
-
-/* Set __FS's right margin to __RMARGIN and return the old value.  */
-ARGP_FS_EI size_t
-__argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin)
-{
-  size_t __old;
-  if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
-    __argp_fmtstream_update (__fs);
-  __old = __fs->rmargin;
-  __fs->rmargin = __rmargin;
-  return __old;
-}
-
-/* Set FS's wrap margin to __WMARGIN and return the old value.  */
-ARGP_FS_EI size_t
-__argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin)
-{
-  size_t __old;
-  if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
-    __argp_fmtstream_update (__fs);
-  __old = __fs->wmargin;
-  __fs->wmargin = __wmargin;
-  return __old;
-}
-
-/* Return the column number of the current output point in __FS.  */
-ARGP_FS_EI size_t
-__argp_fmtstream_point (argp_fmtstream_t __fs)
-{
-  if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
-    __argp_fmtstream_update (__fs);
-  return __fs->point_col >= 0 ? __fs->point_col : 0;
-}
-
-#if !_LIBC
-#undef __argp_fmtstream_putc
-#undef __argp_fmtstream_puts
-#undef __argp_fmtstream_write
-#undef __argp_fmtstream_set_lmargin
-#undef __argp_fmtstream_set_rmargin
-#undef __argp_fmtstream_set_wmargin
-#undef __argp_fmtstream_point
-#undef __argp_fmtstream_update
-#undef __argp_fmtstream_ensure
-#endif
-
-#endif /* __OPTIMIZE__ */
-
-#endif /* ARGP_FMTSTREAM_USE_LINEWRAP */
-
-#endif /* argp-fmtstream.h */
diff --git a/contrib/cpio/lib/argp-fs-xinl.c b/contrib/cpio/lib/argp-fs-xinl.c
deleted file mode 100644
index 3b4c917e020..00000000000
--- a/contrib/cpio/lib/argp-fs-xinl.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/* Real definitions for extern inline functions in argp-fmtstream.h
-   Copyright (C) 1997, 2003, 2004 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Written by Miles Bader .
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-#ifdef HAVE_CONFIG_H
-# include 
-#endif
-
-#define ARGP_FS_EI
-#undef __OPTIMIZE__
-#define __OPTIMIZE__ 1
-#include "argp-fmtstream.h"
-
-#if 0
-/* Not exported.  */
-/* Add weak aliases.  */
-#if _LIBC - 0 && !defined (ARGP_FMTSTREAM_USE_LINEWRAP) && defined (weak_alias)
-
-weak_alias (__argp_fmtstream_putc, argp_fmtstream_putc)
-weak_alias (__argp_fmtstream_puts, argp_fmtstream_puts)
-weak_alias (__argp_fmtstream_write, argp_fmtstream_write)
-weak_alias (__argp_fmtstream_set_lmargin, argp_fmtstream_set_lmargin)
-weak_alias (__argp_fmtstream_set_rmargin, argp_fmtstream_set_rmargin)
-weak_alias (__argp_fmtstream_set_wmargin, argp_fmtstream_set_wmargin)
-weak_alias (__argp_fmtstream_point, argp_fmtstream_point)
-
-#endif
-#endif
diff --git a/contrib/cpio/lib/argp-help.c b/contrib/cpio/lib/argp-help.c
deleted file mode 100644
index 396e73326f9..00000000000
--- a/contrib/cpio/lib/argp-help.c
+++ /dev/null
@@ -1,1954 +0,0 @@
-/* Hierarchial argument parsing help output
-   Copyright (C) 1995-2005, 2007 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Written by Miles Bader .
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef _GNU_SOURCE
-# define _GNU_SOURCE	1
-#endif
-
-#ifdef HAVE_CONFIG_H
-# include 
-#endif
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#ifdef USE_IN_LIBIO
-# include 
-#endif
-
-#ifdef _LIBC
-# include 
-# undef dgettext
-# define dgettext(domain, msgid) \
-   INTUSE(__dcgettext) (domain, msgid, LC_MESSAGES)
-#else
-# include "gettext.h"
-#endif
-
-#include "argp.h"
-#include "argp-fmtstream.h"
-#include "argp-namefrob.h"
-
-#ifndef SIZE_MAX
-# define SIZE_MAX ((size_t) -1)
-#endif
-
-/* User-selectable (using an environment variable) formatting parameters.
-
-   These may be specified in an environment variable called `ARGP_HELP_FMT',
-   with a contents like:  VAR1=VAL1,VAR2=VAL2,BOOLVAR2,no-BOOLVAR2
-   Where VALn must be a positive integer.  The list of variables is in the
-   UPARAM_NAMES vector, below.  */
-
-/* Default parameters.  */
-#define DUP_ARGS      0		/* True if option argument can be duplicated. */
-#define DUP_ARGS_NOTE 1		/* True to print a note about duplicate args. */
-#define SHORT_OPT_COL 2		/* column in which short options start */
-#define LONG_OPT_COL  6		/* column in which long options start */
-#define DOC_OPT_COL   2		/* column in which doc options start */
-#define OPT_DOC_COL  29		/* column in which option text starts */
-#define HEADER_COL    1		/* column in which group headers are printed */
-#define USAGE_INDENT 12		/* indentation of wrapped usage lines */
-#define RMARGIN      79		/* right margin used for wrapping */
-
-/* User-selectable (using an environment variable) formatting parameters.
-   They must all be of type `int' for the parsing code to work.  */
-struct uparams
-{
-  /* If true, arguments for an option are shown with both short and long
-     options, even when a given option has both, e.g. `-x ARG, --longx=ARG'.
-     If false, then if an option has both, the argument is only shown with
-     the long one, e.g., `-x, --longx=ARG', and a message indicating that
-     this really means both is printed below the options.  */
-  int dup_args;
-
-  /* This is true if when DUP_ARGS is false, and some duplicate arguments have
-     been suppressed, an explanatory message should be printed.  */
-  int dup_args_note;
-
-  /* Various output columns.  */
-  int short_opt_col;      /* column in which short options start */   
-  int long_opt_col;       /* column in which long options start */ 
-  int doc_opt_col;        /* column in which doc options start */
-  int opt_doc_col;        /* column in which option text starts */
-  int header_col;         /* column in which group headers are printed */ 
-  int usage_indent;       /* indentation of wrapped usage lines */
-  int rmargin;            /* right margin used for wrapping */
-
-  int valid;		  /* True when the values in here are valid.  */
-};
-
-/* This is a global variable, as user options are only ever read once.  */
-static struct uparams uparams = {
-  DUP_ARGS, DUP_ARGS_NOTE,
-  SHORT_OPT_COL, LONG_OPT_COL, DOC_OPT_COL, OPT_DOC_COL, HEADER_COL,
-  USAGE_INDENT, RMARGIN,
-  0
-};
-
-/* A particular uparam, and what the user name is.  */
-struct uparam_name
-{
-  const char *name;		/* User name.  */
-  int is_bool;			/* Whether it's `boolean'.  */
-  size_t uparams_offs;		/* Location of the (int) field in UPARAMS.  */
-};
-
-/* The name-field mappings we know about.  */
-static const struct uparam_name uparam_names[] =
-{
-  { "dup-args",       1, offsetof (struct uparams, dup_args) },
-  { "dup-args-note",  1, offsetof (struct uparams, dup_args_note) },
-  { "short-opt-col",  0, offsetof (struct uparams, short_opt_col) },
-  { "long-opt-col",   0, offsetof (struct uparams, long_opt_col) },
-  { "doc-opt-col",    0, offsetof (struct uparams, doc_opt_col) },
-  { "opt-doc-col",    0, offsetof (struct uparams, opt_doc_col) },
-  { "header-col",     0, offsetof (struct uparams, header_col) },
-  { "usage-indent",   0, offsetof (struct uparams, usage_indent) },
-  { "rmargin",        0, offsetof (struct uparams, rmargin) },
-  { 0 }
-};
-
-static void
-validate_uparams (const struct argp_state *state, struct uparams *upptr)
-{
-  const struct uparam_name *up;
-
-  for (up = uparam_names; up->name; up++)
-    {
-      if (up->is_bool
-	  || up->uparams_offs == offsetof (struct uparams, rmargin))
-	continue;
-      if (*(int *)((char *)upptr + up->uparams_offs) >= upptr->rmargin)
-	{
-	  __argp_failure (state, 0, 0,
-			  dgettext (state->root_argp->argp_domain,
-				    "\
-ARGP_HELP_FMT: %s value is less than or equal to %s"),
-			  "rmargin", up->name);
-	  return;
-	}
-    }
-  uparams = *upptr;
-  uparams.valid = 1;
-}
-
-/* Read user options from the environment, and fill in UPARAMS appropiately. */
-static void
-fill_in_uparams (const struct argp_state *state)
-{
-  const char *var = getenv ("ARGP_HELP_FMT");
-  struct uparams new_params = uparams;
-  
-#define SKIPWS(p) do { while (isspace ((unsigned char) *p)) p++; } while (0);
-
-  if (var)
-    {
-      /* Parse var. */
-      while (*var)
-	{
-	  SKIPWS (var);
-	  
-	  if (isalpha ((unsigned char) *var))
-	    {
-	      size_t var_len;
-	      const struct uparam_name *un;
-	      int unspec = 0, val = 0;
-	      const char *arg = var;
-
-	      while (isalnum ((unsigned char) *arg) || *arg == '-' || *arg == '_')
-		arg++;
-	      var_len = arg - var;
-	      
-	      SKIPWS (arg);
-	      
-	      if (*arg == '\0' || *arg == ',')
-		unspec = 1;
-	      else if (*arg == '=')
-		{
-		  arg++;
-		  SKIPWS (arg);
-		}
-	      
-	      if (unspec)
-		{
-		  if (var[0] == 'n' && var[1] == 'o' && var[2] == '-')
-		    {
-		      val = 0;
-		      var += 3;
-		      var_len -= 3;
-		    }
-		  else
-		    val = 1;
-		}
-	      else if (isdigit ((unsigned char) *arg))
-		{
-		  val = atoi (arg);
-		  while (isdigit ((unsigned char) *arg))
-		    arg++;
-		  SKIPWS (arg);
-		}
-	      
-	      for (un = uparam_names; un->name; un++)
-		if (strlen (un->name) == var_len
-		    && strncmp (var, un->name, var_len) == 0)
-		  {
-		    if (unspec && !un->is_bool)
-		      __argp_failure (state, 0, 0,
-				      dgettext (state->root_argp->argp_domain,
-						"\
-%.*s: ARGP_HELP_FMT parameter requires a value"),
-				      (int) var_len, var);
-		    else if (val < 0)
-		      __argp_failure (state, 0, 0,
-				      dgettext (state->root_argp->argp_domain,
-						"\
-%.*s: ARGP_HELP_FMT parameter must be positive"),
-				      (int) var_len, var);
-		    else
-		      *(int *)((char *)&new_params + un->uparams_offs) = val;
-		    break;
-		  }
-	      if (! un->name)
-		__argp_failure (state, 0, 0,
-				dgettext (state->root_argp->argp_domain, "\
-%.*s: Unknown ARGP_HELP_FMT parameter"),
-				(int) var_len, var);
-
-	      var = arg;
-	      if (*var == ',')
-		var++;
-	    }
-	  else if (*var)
-	    {
-	      __argp_failure (state, 0, 0,
-			      dgettext (state->root_argp->argp_domain,
-					"Garbage in ARGP_HELP_FMT: %s"), var);
-	      break;
-	    }
-	}
-      validate_uparams (state, &new_params);
-    }
-}
-
-/* Returns true if OPT hasn't been marked invisible.  Visibility only affects
-   whether OPT is displayed or used in sorting, not option shadowing.  */
-#define ovisible(opt) (! ((opt)->flags & OPTION_HIDDEN))
-
-/* Returns true if OPT is an alias for an earlier option.  */
-#define oalias(opt) ((opt)->flags & OPTION_ALIAS)
-
-/* Returns true if OPT is an documentation-only entry.  */
-#define odoc(opt) ((opt)->flags & OPTION_DOC)
-
-/* Returns true if OPT should not be translated */
-#define onotrans(opt) ((opt)->flags & OPTION_NO_TRANS)
-
-/* Returns true if OPT is the end-of-list marker for a list of options.  */
-#define oend(opt) __option_is_end (opt)
-
-/* Returns true if OPT has a short option.  */
-#define oshort(opt) __option_is_short (opt)
-
-/*
-   The help format for a particular option is like:
-
-     -xARG, -yARG, --long1=ARG, --long2=ARG        Documentation...
-
-   Where ARG will be omitted if there's no argument, for this option, or
-   will be surrounded by "[" and "]" appropiately if the argument is
-   optional.  The documentation string is word-wrapped appropiately, and if
-   the list of options is long enough, it will be started on a separate line.
-   If there are no short options for a given option, the first long option is
-   indented slighly in a way that's supposed to make most long options appear
-   to be in a separate column.
-
-   For example, the following output (from ps):
-
-     -p PID, --pid=PID          List the process PID
-	 --pgrp=PGRP            List processes in the process group PGRP
-     -P, -x, --no-parent        Include processes without parents
-     -Q, --all-fields           Don't elide unusable fields (normally if there's
-				some reason ps can't print a field for any
-				process, it's removed from the output entirely)
-     -r, --reverse, --gratuitously-long-reverse-option
-				Reverse the order of any sort
-	 --session[=SID]        Add the processes from the session SID (which
-				defaults to the sid of the current process)
-
-    Here are some more options:
-     -f ZOT, --foonly=ZOT       Glork a foonly
-     -z, --zaza                 Snit a zar
-
-     -?, --help                 Give this help list
-	 --usage                Give a short usage message
-     -V, --version              Print program version
-
-   The struct argp_option array for the above could look like:
-
-   {
-     {"pid",       'p',      "PID",  0, "List the process PID"},
-     {"pgrp",      OPT_PGRP, "PGRP", 0, "List processes in the process group PGRP"},
-     {"no-parent", 'P',	      0,     0, "Include processes without parents"},
-     {0,           'x',       0,     OPTION_ALIAS},
-     {"all-fields",'Q',       0,     0, "Don't elide unusable fields (normally"
-                                        " if there's some reason ps can't"
-					" print a field for any process, it's"
-                                        " removed from the output entirely)" },
-     {"reverse",   'r',       0,     0, "Reverse the order of any sort"},
-     {"gratuitously-long-reverse-option", 0, 0, OPTION_ALIAS},
-     {"session",   OPT_SESS,  "SID", OPTION_ARG_OPTIONAL,
-                                        "Add the processes from the session"
-					" SID (which defaults to the sid of"
-					" the current process)" },
-
-     {0,0,0,0, "Here are some more options:"},
-     {"foonly", 'f', "ZOT", 0, "Glork a foonly"},
-     {"zaza", 'z', 0, 0, "Snit a zar"},
-
-     {0}
-   }
-
-   Note that the last three options are automatically supplied by argp_parse,
-   unless you tell it not to with ARGP_NO_HELP.
-
-*/
-
-/* Returns true if CH occurs between BEG and END.  */
-static int
-find_char (char ch, char *beg, char *end)
-{
-  while (beg < end)
-    if (*beg == ch)
-      return 1;
-    else
-      beg++;
-  return 0;
-}
-
-struct hol_cluster;		/* fwd decl */
-
-struct hol_entry
-{
-  /* First option.  */
-  const struct argp_option *opt;
-  /* Number of options (including aliases).  */
-  unsigned num;
-
-  /* A pointers into the HOL's short_options field, to the first short option
-     letter for this entry.  The order of the characters following this point
-     corresponds to the order of options pointed to by OPT, and there are at
-     most NUM.  A short option recorded in a option following OPT is only
-     valid if it occurs in the right place in SHORT_OPTIONS (otherwise it's
-     probably been shadowed by some other entry).  */
-  char *short_options;
-
-  /* Entries are sorted by their group first, in the order:
-       1, 2, ..., n, 0, -m, ..., -2, -1
-     and then alphabetically within each group.  The default is 0.  */
-  int group;
-
-  /* The cluster of options this entry belongs to, or 0 if none.  */
-  struct hol_cluster *cluster;
-
-  /* The argp from which this option came.  */
-  const struct argp *argp;
-
-  /* Position in the array */
-  unsigned ord;
-};
-
-/* A cluster of entries to reflect the argp tree structure.  */
-struct hol_cluster
-{
-  /* A descriptive header printed before options in this cluster.  */
-  const char *header;
-
-  /* Used to order clusters within the same group with the same parent,
-     according to the order in which they occurred in the parent argp's child
-     list.  */
-  int index;
-
-  /* How to sort this cluster with respect to options and other clusters at the
-     same depth (clusters always follow options in the same group).  */
-  int group;
-
-  /* The cluster to which this cluster belongs, or 0 if it's at the base
-     level.  */
-  struct hol_cluster *parent;
-
-  /* The argp from which this cluster is (eventually) derived.  */
-  const struct argp *argp;
-
-  /* The distance this cluster is from the root.  */
-  int depth;
-
-  /* Clusters in a given hol are kept in a linked list, to make freeing them
-     possible.  */
-  struct hol_cluster *next;
-};
-
-/* A list of options for help.  */
-struct hol
-{
-  /* An array of hol_entry's.  */
-  struct hol_entry *entries;
-  /* The number of entries in this hol.  If this field is zero, the others
-     are undefined.  */
-  unsigned num_entries;
-
-  /* A string containing all short options in this HOL.  Each entry contains
-     pointers into this string, so the order can't be messed with blindly.  */
-  char *short_options;
-
-  /* Clusters of entries in this hol.  */
-  struct hol_cluster *clusters;
-};
-
-/* Create a struct hol from the options in ARGP.  CLUSTER is the
-   hol_cluster in which these entries occur, or 0, if at the root.  */
-static struct hol *
-make_hol (const struct argp *argp, struct hol_cluster *cluster)
-{
-  char *so;
-  const struct argp_option *o;
-  const struct argp_option *opts = argp->options;
-  struct hol_entry *entry;
-  unsigned num_short_options = 0;
-  struct hol *hol = malloc (sizeof (struct hol));
-
-  assert (hol);
-
-  hol->num_entries = 0;
-  hol->clusters = 0;
-
-  if (opts)
-    {
-      int cur_group = 0;
-
-      /* The first option must not be an alias.  */
-      assert (! oalias (opts));
-
-      /* Calculate the space needed.  */
-      for (o = opts; ! oend (o); o++)
-	{
-	  if (! oalias (o))
-	    hol->num_entries++;
-	  if (oshort (o))
-	    num_short_options++;	/* This is an upper bound.  */
-	}
-
-      hol->entries = malloc (sizeof (struct hol_entry) * hol->num_entries);
-      hol->short_options = malloc (num_short_options + 1);
-
-      assert (hol->entries && hol->short_options);
-      if (SIZE_MAX <= UINT_MAX)
-	assert (hol->num_entries <= SIZE_MAX / sizeof (struct hol_entry));
-
-      /* Fill in the entries.  */
-      so = hol->short_options;
-      for (o = opts, entry = hol->entries; ! oend (o); entry++)
-	{
-	  entry->opt = o;
-	  entry->num = 0;
-	  entry->short_options = so;
-	  entry->group = cur_group =
-	    o->group
-	    ? o->group
-	    : ((!o->name && !o->key)
-	       ? cur_group + 1
-	       : cur_group);
-	  entry->cluster = cluster;
-	  entry->argp = argp;
-
-	  do
-	    {
-	      entry->num++;
-	      if (oshort (o) && ! find_char (o->key, hol->short_options, so))
-		/* O has a valid short option which hasn't already been used.*/
-		*so++ = o->key;
-	      o++;
-	    }
-	  while (! oend (o) && oalias (o));
-	}
-      *so = '\0';		/* null terminated so we can find the length */
-    }
-
-  return hol;
-}
-
-/* Add a new cluster to HOL, with the given GROUP and HEADER (taken from the
-   associated argp child list entry), INDEX, and PARENT, and return a pointer
-   to it.  ARGP is the argp that this cluster results from.  */
-static struct hol_cluster *
-hol_add_cluster (struct hol *hol, int group, const char *header, int index,
-		 struct hol_cluster *parent, const struct argp *argp)
-{
-  struct hol_cluster *cl = malloc (sizeof (struct hol_cluster));
-  if (cl)
-    {
-      cl->group = group;
-      cl->header = header;
-
-      cl->index = index;
-      cl->parent = parent;
-      cl->argp = argp;
-      cl->depth = parent ? parent->depth + 1 : 0;
-
-      cl->next = hol->clusters;
-      hol->clusters = cl;
-    }
-  return cl;
-}
-
-/* Free HOL and any resources it uses.  */
-static void
-hol_free (struct hol *hol)
-{
-  struct hol_cluster *cl = hol->clusters;
-
-  while (cl)
-    {
-      struct hol_cluster *next = cl->next;
-      free (cl);
-      cl = next;
-    }
-
-  if (hol->num_entries > 0)
-    {
-      free (hol->entries);
-      free (hol->short_options);
-    }
-
-  free (hol);
-}
-
-static int
-hol_entry_short_iterate (const struct hol_entry *entry,
-			 int (*func)(const struct argp_option *opt,
-				     const struct argp_option *real,
-				     const char *domain, void *cookie),
-			 const char *domain, void *cookie)
-{
-  unsigned nopts;
-  int val = 0;
-  const struct argp_option *opt, *real = entry->opt;
-  char *so = entry->short_options;
-
-  for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--)
-    if (oshort (opt) && *so == opt->key)
-      {
-	if (!oalias (opt))
-	  real = opt;
-	if (ovisible (opt))
-	  val = (*func)(opt, real, domain, cookie);
-	so++;
-      }
-
-  return val;
-}
-
-static inline int
-__attribute__ ((always_inline))
-hol_entry_long_iterate (const struct hol_entry *entry,
-			int (*func)(const struct argp_option *opt,
-				    const struct argp_option *real,
-				    const char *domain, void *cookie),
-			const char *domain, void *cookie)
-{
-  unsigned nopts;
-  int val = 0;
-  const struct argp_option *opt, *real = entry->opt;
-
-  for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--)
-    if (opt->name)
-      {
-	if (!oalias (opt))
-	  real = opt;
-	if (ovisible (opt))
-	  val = (*func)(opt, real, domain, cookie);
-      }
-
-  return val;
-}
-
-/* Iterator that returns true for the first short option.  */
-static inline int
-until_short (const struct argp_option *opt, const struct argp_option *real,
-	     const char *domain, void *cookie)
-{
-  return oshort (opt) ? opt->key : 0;
-}
-
-/* Returns the first valid short option in ENTRY, or 0 if there is none.  */
-static char
-hol_entry_first_short (const struct hol_entry *entry)
-{
-  return hol_entry_short_iterate (entry, until_short,
-				  entry->argp->argp_domain, 0);
-}
-
-/* Returns the first valid long option in ENTRY, or 0 if there is none.  */
-static const char *
-hol_entry_first_long (const struct hol_entry *entry)
-{
-  const struct argp_option *opt;
-  unsigned num;
-  for (opt = entry->opt, num = entry->num; num > 0; opt++, num--)
-    if (opt->name && ovisible (opt))
-      return opt->name;
-  return 0;
-}
-
-/* Returns the entry in HOL with the long option name NAME, or 0 if there is
-   none.  */
-static struct hol_entry *
-hol_find_entry (struct hol *hol, const char *name)
-{
-  struct hol_entry *entry = hol->entries;
-  unsigned num_entries = hol->num_entries;
-
-  while (num_entries-- > 0)
-    {
-      const struct argp_option *opt = entry->opt;
-      unsigned num_opts = entry->num;
-
-      while (num_opts-- > 0)
-	if (opt->name && ovisible (opt) && strcmp (opt->name, name) == 0)
-	  return entry;
-	else
-	  opt++;
-
-      entry++;
-    }
-
-  return 0;
-}
-
-/* If an entry with the long option NAME occurs in HOL, set it's special
-   sort position to GROUP.  */
-static void
-hol_set_group (struct hol *hol, const char *name, int group)
-{
-  struct hol_entry *entry = hol_find_entry (hol, name);
-  if (entry)
-    entry->group = group;
-}
-
-/* Order by group:  0, 1, 2, ..., n, -m, ..., -2, -1.
-   EQ is what to return if GROUP1 and GROUP2 are the same.  */
-static int
-group_cmp (int group1, int group2, int eq)
-{
-  if (group1 == group2)
-    return eq;
-  else if ((group1 < 0 && group2 < 0) || (group1 >= 0 && group2 >= 0))
-    return group1 - group2;
-  else
-    return group2 - group1;
-}
-
-/* Compare clusters CL1 & CL2 by the order that they should appear in
-   output.  */
-static int
-hol_cluster_cmp (const struct hol_cluster *cl1, const struct hol_cluster *cl2)
-{
-  /* If one cluster is deeper than the other, use its ancestor at the same
-     level, so that finding the common ancestor is straightforward.
-     
-     clN->depth > 0 means that clN->parent != NULL (see hol_add_cluster) */
-  while (cl1->depth > cl2->depth)
-    cl1 = cl1->parent;
-  while (cl2->depth > cl1->depth)
-    cl2 = cl2->parent;
-
-  /* Now reduce both clusters to their ancestors at the point where both have
-     a common parent; these can be directly compared.  */
-  while (cl1->parent != cl2->parent)
-    cl1 = cl1->parent, cl2 = cl2->parent;
-
-  return group_cmp (cl1->group, cl2->group, cl2->index - cl1->index);
-}
-
-/* Return the ancestor of CL that's just below the root (i.e., has a parent
-   of 0).  */
-static struct hol_cluster *
-hol_cluster_base (struct hol_cluster *cl)
-{
-  while (cl->parent)
-    cl = cl->parent;
-  return cl;
-}
-
-/* Return true if CL1 is a child of CL2.  */
-static int
-hol_cluster_is_child (const struct hol_cluster *cl1,
-		      const struct hol_cluster *cl2)
-{
-  while (cl1 && cl1 != cl2)
-    cl1 = cl1->parent;
-  return cl1 == cl2;
-}
-
-/* Given the name of a OPTION_DOC option, modifies NAME to start at the tail
-   that should be used for comparisons, and returns true iff it should be
-   treated as a non-option.  */
-static int
-canon_doc_option (const char **name)
-{
-  int non_opt;
-
-  if (!*name)
-    non_opt = 1;
-  else
-    {
-      /* Skip initial whitespace.  */
-      while (isspace ((unsigned char) **name))
-	(*name)++;
-      /* Decide whether this looks like an option (leading `-') or not.  */
-      non_opt = (**name != '-');
-      /* Skip until part of name used for sorting.  */
-      while (**name && !isalnum ((unsigned char) **name))
-	(*name)++;
-    }
-  return non_opt;
-}
-
-#define HOL_ENTRY_PTRCMP(a,b) ((a)->ord < (b)->ord ? -1 : 1)
-
-/* Order ENTRY1 & ENTRY2 by the order which they should appear in a help
-   listing.  */
-static int
-hol_entry_cmp (const struct hol_entry *entry1,
-	       const struct hol_entry *entry2)
-{
-  /* The group numbers by which the entries should be ordered; if either is
-     in a cluster, then this is just the group within the cluster.  */
-  int group1 = entry1->group, group2 = entry2->group;
-  int rc;
-
-  if (entry1->cluster != entry2->cluster)
-    {
-      /* The entries are not within the same cluster, so we can't compare them
-	 directly, we have to use the appropiate clustering level too.  */
-      if (! entry1->cluster)
-	/* ENTRY1 is at the `base level', not in a cluster, so we have to
-	   compare it's group number with that of the base cluster in which
-	   ENTRY2 resides.  Note that if they're in the same group, the
-	   clustered option always comes laster.  */
-	return group_cmp (group1, hol_cluster_base (entry2->cluster)->group, -1);
-      else if (! entry2->cluster)
-	/* Likewise, but ENTRY2's not in a cluster.  */
-	return group_cmp (hol_cluster_base (entry1->cluster)->group, group2, 1);
-      else
-	/* Both entries are in clusters, we can just compare the clusters.  */
-	return (rc = hol_cluster_cmp (entry1->cluster, entry2->cluster)) ?
-	        rc : HOL_ENTRY_PTRCMP(entry1, entry2);
-    }
-  else if (group1 == group2)
-    /* The entries are both in the same cluster and group, so compare them
-       alphabetically.  */
-    {
-      int short1 = hol_entry_first_short (entry1);
-      int short2 = hol_entry_first_short (entry2);
-      int doc1 = odoc (entry1->opt);
-      int doc2 = odoc (entry2->opt);
-      const char *long1 = hol_entry_first_long (entry1);
-      const char *long2 = hol_entry_first_long (entry2);
-
-      if (doc1)
-	doc1 = canon_doc_option (&long1);
-      if (doc2)
-	doc2 = canon_doc_option (&long2);
-
-      if (doc1 != doc2)
-	/* `documentation' options always follow normal options (or
-	   documentation options that *look* like normal options).  */
-	return doc1 - doc2;
-      else if (!short1 && !short2 && long1 && long2)
-	/* Only long options.  */
-	return (rc = __strcasecmp (long1, long2)) ?
-                 rc : HOL_ENTRY_PTRCMP(entry1, entry2);
-      else
-	/* Compare short/short, long/short, short/long, using the first
-	   character of long options.  Entries without *any* valid
-	   options (such as options with OPTION_HIDDEN set) will be put
-	   first, but as they're not displayed, it doesn't matter where
-	   they are.  */
-	{
-	  char first1 = short1 ? short1 : long1 ? *long1 : 0;
-	  char first2 = short2 ? short2 : long2 ? *long2 : 0;
-#ifdef _tolower
-	  int lower_cmp = _tolower (first1) - _tolower (first2);
-#else
-	  int lower_cmp = tolower (first1) - tolower (first2);
-#endif
-	  /* Compare ignoring case, except when the options are both the
-	     same letter, in which case lower-case always comes first.  */
-	  return lower_cmp ? lower_cmp : 
-                    (rc = first2 - first1) ?
-	             rc : HOL_ENTRY_PTRCMP(entry1, entry2);
-	}
-    }
-  else
-    /* Within the same cluster, but not the same group, so just compare
-       groups.  */
-    return group_cmp (group1, group2, HOL_ENTRY_PTRCMP(entry1, entry2));
-}
-
-/* Version of hol_entry_cmp with correct signature for qsort.  */
-static int
-hol_entry_qcmp (const void *entry1_v, const void *entry2_v)
-{
-  return hol_entry_cmp (entry1_v, entry2_v);
-}
-
-/* Sort HOL by group and alphabetically by option name (with short options
-   taking precedence over long).  Since the sorting is for display purposes
-   only, the shadowing of options isn't effected.  */
-static void
-hol_sort (struct hol *hol)
-{
-  if (hol->num_entries > 0)
-    {
-      unsigned i;
-      struct hol_entry *e;
-      for (i = 0, e = hol->entries; i < hol->num_entries; i++, e++)
-	e->ord = i;
-      qsort (hol->entries, hol->num_entries, sizeof (struct hol_entry),
-	     hol_entry_qcmp);
-    }
-}
-
-/* Append MORE to HOL, destroying MORE in the process.  Options in HOL shadow
-   any in MORE with the same name.  */
-static void
-hol_append (struct hol *hol, struct hol *more)
-{
-  struct hol_cluster **cl_end = &hol->clusters;
-
-  /* Steal MORE's cluster list, and add it to the end of HOL's.  */
-  while (*cl_end)
-    cl_end = &(*cl_end)->next;
-  *cl_end = more->clusters;
-  more->clusters = 0;
-
-  /* Merge entries.  */
-  if (more->num_entries > 0)
-    {
-      if (hol->num_entries == 0)
-	{
-	  hol->num_entries = more->num_entries;
-	  hol->entries = more->entries;
-	  hol->short_options = more->short_options;
-	  more->num_entries = 0;	/* Mark MORE's fields as invalid.  */
-	}
-      else
-	/* Append the entries in MORE to those in HOL, taking care to only add
-	   non-shadowed SHORT_OPTIONS values.  */
-	{
-	  unsigned left;
-	  char *so, *more_so;
-	  struct hol_entry *e;
-	  unsigned num_entries = hol->num_entries + more->num_entries;
-	  struct hol_entry *entries =
-	    malloc (num_entries * sizeof (struct hol_entry));
-	  unsigned hol_so_len = strlen (hol->short_options);
-	  char *short_options =
-	    malloc (hol_so_len + strlen (more->short_options) + 1);
-
-	  assert (entries && short_options);
-	  if (SIZE_MAX <= UINT_MAX)
-	    assert (num_entries <= SIZE_MAX / sizeof (struct hol_entry));
-
-	  __mempcpy (__mempcpy (entries, hol->entries,
-				hol->num_entries * sizeof (struct hol_entry)),
-		     more->entries,
-		     more->num_entries * sizeof (struct hol_entry));
-
-	  __mempcpy (short_options, hol->short_options, hol_so_len);
-
-	  /* Fix up the short options pointers from HOL.  */
-	  for (e = entries, left = hol->num_entries; left > 0; e++, left--)
-	    e->short_options += (short_options - hol->short_options);
-
-	  /* Now add the short options from MORE, fixing up its entries
-	     too.  */
-	  so = short_options + hol_so_len;
-	  more_so = more->short_options;
-	  for (left = more->num_entries; left > 0; e++, left--)
-	    {
-	      int opts_left;
-	      const struct argp_option *opt;
-
-	      e->short_options = so;
-
-	      for (opts_left = e->num, opt = e->opt; opts_left; opt++, opts_left--)
-		{
-		  int ch = *more_so;
-		  if (oshort (opt) && ch == opt->key)
-		    /* The next short option in MORE_SO, CH, is from OPT.  */
-		    {
-		      if (! find_char (ch, short_options,
-				       short_options + hol_so_len))
-			/* The short option CH isn't shadowed by HOL's options,
-			   so add it to the sum.  */
-			*so++ = ch;
-		      more_so++;
-		    }
-		}
-	    }
-
-	  *so = '\0';
-
-	  free (hol->entries);
-	  free (hol->short_options);
-
-	  hol->entries = entries;
-	  hol->num_entries = num_entries;
-	  hol->short_options = short_options;
-	}
-    }
-
-  hol_free (more);
-}
-
-/* Inserts enough spaces to make sure STREAM is at column COL.  */
-static void
-indent_to (argp_fmtstream_t stream, unsigned col)
-{
-  int needed = col - __argp_fmtstream_point (stream);
-  while (needed-- > 0)
-    __argp_fmtstream_putc (stream, ' ');
-}
-
-/* Output to STREAM either a space, or a newline if there isn't room for at
-   least ENSURE characters before the right margin.  */
-static void
-space (argp_fmtstream_t stream, size_t ensure)
-{
-  if (__argp_fmtstream_point (stream) + ensure
-      >= __argp_fmtstream_rmargin (stream))
-    __argp_fmtstream_putc (stream, '\n');
-  else
-    __argp_fmtstream_putc (stream, ' ');
-}
-
-/* If the option REAL has an argument, we print it in using the printf
-   format REQ_FMT or OPT_FMT depending on whether it's a required or
-   optional argument.  */
-static void
-arg (const struct argp_option *real, const char *req_fmt, const char *opt_fmt,
-     const char *domain, argp_fmtstream_t stream)
-{
-  if (real->arg)
-    {
-      if (real->flags & OPTION_ARG_OPTIONAL)
-	__argp_fmtstream_printf (stream, opt_fmt,
-				 dgettext (domain, real->arg));
-      else
-	__argp_fmtstream_printf (stream, req_fmt,
-				 dgettext (domain, real->arg));
-    }
-}
-
-/* Helper functions for hol_entry_help.  */
-
-/* State used during the execution of hol_help.  */
-struct hol_help_state
-{
-  /* PREV_ENTRY should contain the previous entry printed, or 0.  */
-  struct hol_entry *prev_entry;
-
-  /* If an entry is in a different group from the previous one, and SEP_GROUPS
-     is true, then a blank line will be printed before any output. */
-  int sep_groups;
-
-  /* True if a duplicate option argument was suppressed (only ever set if
-     UPARAMS.dup_args is false).  */
-  int suppressed_dup_arg;
-};
-
-/* Some state used while printing a help entry (used to communicate with
-   helper functions).  See the doc for hol_entry_help for more info, as most
-   of the fields are copied from its arguments.  */
-struct pentry_state
-{
-  const struct hol_entry *entry;
-  argp_fmtstream_t stream;
-  struct hol_help_state *hhstate;
-
-  /* True if nothing's been printed so far.  */
-  int first;
-
-  /* If non-zero, the state that was used to print this help.  */
-  const struct argp_state *state;
-};
-
-/* If a user doc filter should be applied to DOC, do so.  */
-static const char *
-filter_doc (const char *doc, int key, const struct argp *argp,
-	    const struct argp_state *state)
-{
-  if (argp->help_filter)
-    /* We must apply a user filter to this output.  */
-    {
-      void *input = __argp_input (argp, state);
-      return (*argp->help_filter) (key, doc, input);
-    }
-  else
-    /* No filter.  */
-    return doc;
-}
-
-/* Prints STR as a header line, with the margin lines set appropiately, and
-   notes the fact that groups should be separated with a blank line.  ARGP is
-   the argp that should dictate any user doc filtering to take place.  Note
-   that the previous wrap margin isn't restored, but the left margin is reset
-   to 0.  */
-static void
-print_header (const char *str, const struct argp *argp,
-	      struct pentry_state *pest)
-{
-  const char *tstr = dgettext (argp->argp_domain, str);
-  const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_HEADER, argp, pest->state);
-
-  if (fstr)
-    {
-      if (*fstr)
-	{
-	  if (pest->hhstate->prev_entry)
-	    /* Precede with a blank line.  */
-	    __argp_fmtstream_putc (pest->stream, '\n');
-	  indent_to (pest->stream, uparams.header_col);
-	  __argp_fmtstream_set_lmargin (pest->stream, uparams.header_col);
-	  __argp_fmtstream_set_wmargin (pest->stream, uparams.header_col);
-	  __argp_fmtstream_puts (pest->stream, fstr);
-	  __argp_fmtstream_set_lmargin (pest->stream, 0);
-	  __argp_fmtstream_putc (pest->stream, '\n');
-	}
-
-      pest->hhstate->sep_groups = 1; /* Separate subsequent groups. */
-    }
-
-  if (fstr != tstr)
-    free ((char *) fstr);
-}
-
-/* Inserts a comma if this isn't the first item on the line, and then makes
-   sure we're at least to column COL.  If this *is* the first item on a line,
-   prints any pending whitespace/headers that should precede this line. Also
-   clears FIRST.  */
-static void
-comma (unsigned col, struct pentry_state *pest)
-{
-  if (pest->first)
-    {
-      const struct hol_entry *pe = pest->hhstate->prev_entry;
-      const struct hol_cluster *cl = pest->entry->cluster;
-
-      if (pest->hhstate->sep_groups && pe && pest->entry->group != pe->group)
-	__argp_fmtstream_putc (pest->stream, '\n');
-
-      if (cl && cl->header && *cl->header
-	  && (!pe
-	      || (pe->cluster != cl
-		  && !hol_cluster_is_child (pe->cluster, cl))))
-	/* If we're changing clusters, then this must be the start of the
-	   ENTRY's cluster unless that is an ancestor of the previous one
-	   (in which case we had just popped into a sub-cluster for a bit).
-	   If so, then print the cluster's header line.  */
-	{
-	  int old_wm = __argp_fmtstream_wmargin (pest->stream);
-	  print_header (cl->header, cl->argp, pest);
-	  __argp_fmtstream_set_wmargin (pest->stream, old_wm);
-	}
-
-      pest->first = 0;
-    }
-  else
-    __argp_fmtstream_puts (pest->stream, ", ");
-
-  indent_to (pest->stream, col);
-}
-
-/* Print help for ENTRY to STREAM.  */
-static void
-hol_entry_help (struct hol_entry *entry, const struct argp_state *state,
-		argp_fmtstream_t stream, struct hol_help_state *hhstate)
-{
-  unsigned num;
-  const struct argp_option *real = entry->opt, *opt;
-  char *so = entry->short_options;
-  int have_long_opt = 0;	/* We have any long options.  */
-  /* Saved margins.  */
-  int old_lm = __argp_fmtstream_set_lmargin (stream, 0);
-  int old_wm = __argp_fmtstream_wmargin (stream);
-  /* PEST is a state block holding some of our variables that we'd like to
-     share with helper functions.  */
-  struct pentry_state pest;
-
-  pest.entry = entry;
-  pest.stream = stream;
-  pest.hhstate = hhstate;
-  pest.first = 1;
-  pest.state = state;
-
-  if (! odoc (real))
-    for (opt = real, num = entry->num; num > 0; opt++, num--)
-      if (opt->name && ovisible (opt))
-	{
-	  have_long_opt = 1;
-	  break;
-	}
-
-  /* First emit short options.  */
-  __argp_fmtstream_set_wmargin (stream, uparams.short_opt_col); /* For truly bizarre cases. */
-  for (opt = real, num = entry->num; num > 0; opt++, num--)
-    if (oshort (opt) && opt->key == *so)
-      /* OPT has a valid (non shadowed) short option.  */
-      {
-	if (ovisible (opt))
-	  {
-	    comma (uparams.short_opt_col, &pest);
-	    __argp_fmtstream_putc (stream, '-');
-	    __argp_fmtstream_putc (stream, *so);
-	    if (!have_long_opt || uparams.dup_args)
-	      arg (real, " %s", "[%s]", state->root_argp->argp_domain, stream);
-	    else if (real->arg)
-	      hhstate->suppressed_dup_arg = 1;
-	  }
-	so++;
-      }
-
-  /* Now, long options.  */
-  if (odoc (real))
-    /* A `documentation' option.  */
-    {
-      __argp_fmtstream_set_wmargin (stream, uparams.doc_opt_col);
-      for (opt = real, num = entry->num; num > 0; opt++, num--)
-	if (opt->name && *opt->name && ovisible (opt))
-	  {
-	    comma (uparams.doc_opt_col, &pest);
-	    /* Calling dgettext here isn't quite right, since sorting will
-	       have been done on the original; but documentation options
-	       should be pretty rare anyway...  */
-	    __argp_fmtstream_puts (stream,
-				   onotrans (opt) ?
-				             opt->name :
-				   dgettext (state->root_argp->argp_domain,
-					     opt->name));
-	  }
-    }
-  else
-    /* A real long option.  */
-    {
-      int first_long_opt = 1;
-
-      __argp_fmtstream_set_wmargin (stream, uparams.long_opt_col);
-      for (opt = real, num = entry->num; num > 0; opt++, num--)
-	if (opt->name && ovisible (opt))
-	  {
-	    comma (uparams.long_opt_col, &pest);
-	    __argp_fmtstream_printf (stream, "--%s", opt->name);
-	    if (first_long_opt || uparams.dup_args)
-	      arg (real, "=%s", "[=%s]", state->root_argp->argp_domain,
-		   stream);
-	    else if (real->arg)
-	      hhstate->suppressed_dup_arg = 1;
-	  }
-    }
-
-  /* Next, documentation strings.  */
-  __argp_fmtstream_set_lmargin (stream, 0);
-
-  if (pest.first)
-    {
-      /* Didn't print any switches, what's up?  */
-      if (!oshort (real) && !real->name)
-	/* This is a group header, print it nicely.  */
-	print_header (real->doc, entry->argp, &pest);
-      else
-	/* Just a totally shadowed option or null header; print nothing.  */
-	goto cleanup;		/* Just return, after cleaning up.  */
-    }
-  else
-    {
-      const char *tstr = real->doc ? dgettext (state->root_argp->argp_domain,
-					       real->doc) : 0;
-      const char *fstr = filter_doc (tstr, real->key, entry->argp, state);
-      if (fstr && *fstr)
-	{
-	  unsigned int col = __argp_fmtstream_point (stream);
-
-	  __argp_fmtstream_set_lmargin (stream, uparams.opt_doc_col);
-	  __argp_fmtstream_set_wmargin (stream, uparams.opt_doc_col);
-
-	  if (col > (unsigned int) (uparams.opt_doc_col + 3))
-	    __argp_fmtstream_putc (stream, '\n');
-	  else if (col >= (unsigned int) uparams.opt_doc_col)
-	    __argp_fmtstream_puts (stream, "   ");
-	  else
-	    indent_to (stream, uparams.opt_doc_col);
-
-	  __argp_fmtstream_puts (stream, fstr);
-	}
-      if (fstr && fstr != tstr)
-	free ((char *) fstr);
-
-      /* Reset the left margin.  */
-      __argp_fmtstream_set_lmargin (stream, 0);
-      __argp_fmtstream_putc (stream, '\n');
-    }
-
-  hhstate->prev_entry = entry;
-
-cleanup:
-  __argp_fmtstream_set_lmargin (stream, old_lm);
-  __argp_fmtstream_set_wmargin (stream, old_wm);
-}
-
-/* Output a long help message about the options in HOL to STREAM.  */
-static void
-hol_help (struct hol *hol, const struct argp_state *state,
-	  argp_fmtstream_t stream)
-{
-  unsigned num;
-  struct hol_entry *entry;
-  struct hol_help_state hhstate = { 0, 0, 0 };
-
-  for (entry = hol->entries, num = hol->num_entries; num > 0; entry++, num--)
-    hol_entry_help (entry, state, stream, &hhstate);
-
-  if (hhstate.suppressed_dup_arg && uparams.dup_args_note)
-    {
-      const char *tstr = dgettext (state->root_argp->argp_domain, "\
-Mandatory or optional arguments to long options are also mandatory or \
-optional for any corresponding short options.");
-      const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_DUP_ARGS_NOTE,
-				     state ? state->root_argp : 0, state);
-      if (fstr && *fstr)
-	{
-	  __argp_fmtstream_putc (stream, '\n');
-	  __argp_fmtstream_puts (stream, fstr);
-	  __argp_fmtstream_putc (stream, '\n');
-	}
-      if (fstr && fstr != tstr)
-	free ((char *) fstr);
-    }
-}
-
-/* Helper functions for hol_usage.  */
-
-/* If OPT is a short option without an arg, append its key to the string
-   pointer pointer to by COOKIE, and advance the pointer.  */
-static int
-add_argless_short_opt (const struct argp_option *opt,
-		       const struct argp_option *real,
-		       const char *domain, void *cookie)
-{
-  char **snao_end = cookie;
-  if (!(opt->arg || real->arg)
-      && !((opt->flags | real->flags) & OPTION_NO_USAGE))
-    *(*snao_end)++ = opt->key;
-  return 0;
-}
-
-/* If OPT is a short option with an arg, output a usage entry for it to the
-   stream pointed at by COOKIE.  */
-static int
-usage_argful_short_opt (const struct argp_option *opt,
-			const struct argp_option *real,
-			const char *domain, void *cookie)
-{
-  argp_fmtstream_t stream = cookie;
-  const char *arg = opt->arg;
-  int flags = opt->flags | real->flags;
-
-  if (! arg)
-    arg = real->arg;
-
-  if (arg && !(flags & OPTION_NO_USAGE))
-    {
-      arg = dgettext (domain, arg);
-
-      if (flags & OPTION_ARG_OPTIONAL)
-	__argp_fmtstream_printf (stream, " [-%c[%s]]", opt->key, arg);
-      else
-	{
-	  /* Manually do line wrapping so that it (probably) won't
-	     get wrapped at the embedded space.  */
-	  space (stream, 6 + strlen (arg));
-	  __argp_fmtstream_printf (stream, "[-%c %s]", opt->key, arg);
-	}
-    }
-
-  return 0;
-}
-
-/* Output a usage entry for the long option opt to the stream pointed at by
-   COOKIE.  */
-static int
-usage_long_opt (const struct argp_option *opt,
-		const struct argp_option *real,
-		const char *domain, void *cookie)
-{
-  argp_fmtstream_t stream = cookie;
-  const char *arg = opt->arg;
-  int flags = opt->flags | real->flags;
-
-  if (! arg)
-    arg = real->arg;
-
-  if (! (flags & OPTION_NO_USAGE) && !odoc (opt))
-    {
-      if (arg)
-	{
-	  arg = dgettext (domain, arg);
-	  if (flags & OPTION_ARG_OPTIONAL)
-	    __argp_fmtstream_printf (stream, " [--%s[=%s]]", opt->name, arg);
-	  else
-	    __argp_fmtstream_printf (stream, " [--%s=%s]", opt->name, arg);
-	}
-      else
-	__argp_fmtstream_printf (stream, " [--%s]", opt->name);
-    }
-
-  return 0;
-}
-
-/* Print a short usage description for the arguments in HOL to STREAM.  */
-static void
-hol_usage (struct hol *hol, argp_fmtstream_t stream)
-{
-  if (hol->num_entries > 0)
-    {
-      unsigned nentries;
-      struct hol_entry *entry;
-      char *short_no_arg_opts = alloca (strlen (hol->short_options) + 1);
-      char *snao_end = short_no_arg_opts;
-
-      /* First we put a list of short options without arguments.  */
-      for (entry = hol->entries, nentries = hol->num_entries
-	   ; nentries > 0
-	   ; entry++, nentries--)
-	hol_entry_short_iterate (entry, add_argless_short_opt,
-				 entry->argp->argp_domain, &snao_end);
-      if (snao_end > short_no_arg_opts)
-	{
-	  *snao_end++ = 0;
-	  __argp_fmtstream_printf (stream, " [-%s]", short_no_arg_opts);
-	}
-
-      /* Now a list of short options *with* arguments.  */
-      for (entry = hol->entries, nentries = hol->num_entries
-	   ; nentries > 0
-	   ; entry++, nentries--)
-	hol_entry_short_iterate (entry, usage_argful_short_opt,
-				 entry->argp->argp_domain, stream);
-
-      /* Finally, a list of long options (whew!).  */
-      for (entry = hol->entries, nentries = hol->num_entries
-	   ; nentries > 0
-	   ; entry++, nentries--)
-	hol_entry_long_iterate (entry, usage_long_opt,
-				entry->argp->argp_domain, stream);
-    }
-}
-
-/* Make a HOL containing all levels of options in ARGP.  CLUSTER is the
-   cluster in which ARGP's entries should be clustered, or 0.  */
-static struct hol *
-argp_hol (const struct argp *argp, struct hol_cluster *cluster)
-{
-  const struct argp_child *child = argp->children;
-  struct hol *hol = make_hol (argp, cluster);
-  if (child)
-    while (child->argp)
-      {
-	struct hol_cluster *child_cluster =
-	  ((child->group || child->header)
-	   /* Put CHILD->argp within its own cluster.  */
-	   ? hol_add_cluster (hol, child->group, child->header,
-			      child - argp->children, cluster, argp)
-	   /* Just merge it into the parent's cluster.  */
-	   : cluster);
-	hol_append (hol, argp_hol (child->argp, child_cluster)) ;
-	child++;
-      }
-  return hol;
-}
-
-/* Calculate how many different levels with alternative args strings exist in
-   ARGP.  */
-static size_t
-argp_args_levels (const struct argp *argp)
-{
-  size_t levels = 0;
-  const struct argp_child *child = argp->children;
-
-  if (argp->args_doc && strchr (argp->args_doc, '\n'))
-    levels++;
-
-  if (child)
-    while (child->argp)
-      levels += argp_args_levels ((child++)->argp);
-
-  return levels;
-}
-
-/* Print all the non-option args documented in ARGP to STREAM.  Any output is
-   preceded by a space.  LEVELS is a pointer to a byte vector the length
-   returned by argp_args_levels; it should be initialized to zero, and
-   updated by this routine for the next call if ADVANCE is true.  True is
-   returned as long as there are more patterns to output.  */
-static int
-argp_args_usage (const struct argp *argp, const struct argp_state *state,
-		 char **levels, int advance, argp_fmtstream_t stream)
-{
-  char *our_level = *levels;
-  int multiple = 0;
-  const struct argp_child *child = argp->children;
-  const char *tdoc = dgettext (argp->argp_domain, argp->args_doc), *nl = 0;
-  const char *fdoc = filter_doc (tdoc, ARGP_KEY_HELP_ARGS_DOC, argp, state);
-
-  if (fdoc)
-    {
-      const char *cp = fdoc;
-      nl = __strchrnul (cp, '\n');
-      if (*nl != '\0')
-	/* This is a `multi-level' args doc; advance to the correct position
-	   as determined by our state in LEVELS, and update LEVELS.  */
-	{
-	  int i;
-	  multiple = 1;
-	  for (i = 0; i < *our_level; i++)
-	    cp = nl + 1, nl = __strchrnul (cp, '\n');
-	  (*levels)++;
-	}
-
-      /* Manually do line wrapping so that it (probably) won't get wrapped at
-	 any embedded spaces.  */
-      space (stream, 1 + nl - cp);
-
-      __argp_fmtstream_write (stream, cp, nl - cp);
-    }
-  if (fdoc && fdoc != tdoc)
-    free ((char *)fdoc);	/* Free user's modified doc string.  */
-
-  if (child)
-    while (child->argp)
-      advance = !argp_args_usage ((child++)->argp, state, levels, advance, stream);
-
-  if (advance && multiple)
-    {
-      /* Need to increment our level.  */
-      if (*nl)
-	/* There's more we can do here.  */
-	{
-	  (*our_level)++;
-	  advance = 0;		/* Our parent shouldn't advance also. */
-	}
-      else if (*our_level > 0)
-	/* We had multiple levels, but used them up; reset to zero.  */
-	*our_level = 0;
-    }
-
-  return !advance;
-}
-
-/* Print the documentation for ARGP to STREAM; if POST is false, then
-   everything preceeding a `\v' character in the documentation strings (or
-   the whole string, for those with none) is printed, otherwise, everything
-   following the `\v' character (nothing for strings without).  Each separate
-   bit of documentation is separated a blank line, and if PRE_BLANK is true,
-   then the first is as well.  If FIRST_ONLY is true, only the first
-   occurrence is output.  Returns true if anything was output.  */
-static int
-argp_doc (const struct argp *argp, const struct argp_state *state,
-	  int post, int pre_blank, int first_only,
-	  argp_fmtstream_t stream)
-{
-  const char *text;
-  const char *inp_text;
-  size_t inp_text_len = 0;
-  const char *trans_text;
-  void *input = 0;
-  int anything = 0;
-  const struct argp_child *child = argp->children;
-
-  if (argp->doc)
-    {
-      char *vt = strchr (argp->doc, '\v');
-      if (vt)
-	{
-	  if (post)
-	    inp_text = vt + 1;
-	  else
-	    {
-	      inp_text_len = vt - argp->doc;
-	      inp_text = __strndup (argp->doc, inp_text_len);
-	    }
-	}
-      else
-	inp_text = post ? 0 : argp->doc;
-      trans_text = inp_text ? dgettext (argp->argp_domain, inp_text) : NULL;
-    }
-  else
-    trans_text = inp_text = 0;
-
-  if (argp->help_filter)
-    /* We have to filter the doc strings.  */
-    {
-      input = __argp_input (argp, state);
-      text =
-	(*argp->help_filter) (post
-			      ? ARGP_KEY_HELP_POST_DOC
-			      : ARGP_KEY_HELP_PRE_DOC,
-			      trans_text, input);
-    }
-  else
-    text = (const char *) trans_text;
-
-  if (text)
-    {
-      if (pre_blank)
-	__argp_fmtstream_putc (stream, '\n');
-
-      __argp_fmtstream_puts (stream, text);
-
-      if (__argp_fmtstream_point (stream) > __argp_fmtstream_lmargin (stream))
-	__argp_fmtstream_putc (stream, '\n');
-
-      anything = 1;
-    }
-
-  if (text && text != trans_text)
-    free ((char *) text);	/* Free TEXT returned from the help filter.  */
-
-  if (inp_text && inp_text_len)
-    free ((char *) inp_text);	/* We copied INP_TEXT, so free it now.  */
-
-  if (post && argp->help_filter)
-    /* Now see if we have to output a ARGP_KEY_HELP_EXTRA text.  */
-    {
-      text = (*argp->help_filter) (ARGP_KEY_HELP_EXTRA, 0, input);
-      if (text)
-	{
-	  if (anything || pre_blank)
-	    __argp_fmtstream_putc (stream, '\n');
-	  __argp_fmtstream_puts (stream, text);
-	  free ((char *) text);
-	  if (__argp_fmtstream_point (stream)
-	      > __argp_fmtstream_lmargin (stream))
-	    __argp_fmtstream_putc (stream, '\n');
-	  anything = 1;
-	}
-    }
-
-  if (child)
-    while (child->argp && !(first_only && anything))
-      anything |=
-	argp_doc ((child++)->argp, state,
-		  post, anything || pre_blank, first_only,
-		  stream);
-
-  return anything;
-}
-
-/* Output a usage message for ARGP to STREAM.  If called from
-   argp_state_help, STATE is the relevent parsing state.  FLAGS are from the
-   set ARGP_HELP_*.  NAME is what to use wherever a `program name' is
-   needed. */
-static void
-_help (const struct argp *argp, const struct argp_state *state, FILE *stream,
-       unsigned flags, char *name)
-{
-  int anything = 0;		/* Whether we've output anything.  */
-  struct hol *hol = 0;
-  argp_fmtstream_t fs;
-
-  if (! stream)
-    return;
-
-#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
-  __flockfile (stream);
-#endif
-
-  if (! uparams.valid)
-    fill_in_uparams (state);
-
-  fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0);
-  if (! fs)
-    {
-#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
-      __funlockfile (stream);
-#endif
-      return;
-    }
-
-  if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG))
-    {
-      hol = argp_hol (argp, 0);
-
-      /* If present, these options always come last.  */
-      hol_set_group (hol, "help", -1);
-      hol_set_group (hol, "version", -1);
-
-      hol_sort (hol);
-    }
-
-  if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE))
-    /* Print a short `Usage:' message.  */
-    {
-      int first_pattern = 1, more_patterns;
-      size_t num_pattern_levels = argp_args_levels (argp);
-      char *pattern_levels = alloca (num_pattern_levels);
-
-      memset (pattern_levels, 0, num_pattern_levels);
-
-      do
-	{
-	  int old_lm;
-	  int old_wm = __argp_fmtstream_set_wmargin (fs, uparams.usage_indent);
-	  char *levels = pattern_levels;
-
-	  if (first_pattern)
-	    __argp_fmtstream_printf (fs, "%s %s",
-				     dgettext (argp->argp_domain, "Usage:"),
-				     name);
-	  else
-	    __argp_fmtstream_printf (fs, "%s %s",
-				     dgettext (argp->argp_domain, "  or: "),
-				     name);
-
-	  /* We set the lmargin as well as the wmargin, because hol_usage
-	     manually wraps options with newline to avoid annoying breaks.  */
-	  old_lm = __argp_fmtstream_set_lmargin (fs, uparams.usage_indent);
-
-	  if (flags & ARGP_HELP_SHORT_USAGE)
-	    /* Just show where the options go.  */
-	    {
-	      if (hol->num_entries > 0)
-		__argp_fmtstream_puts (fs, dgettext (argp->argp_domain,
-						     " [OPTION...]"));
-	    }
-	  else
-	    /* Actually print the options.  */
-	    {
-	      hol_usage (hol, fs);
-	      flags |= ARGP_HELP_SHORT_USAGE; /* But only do so once.  */
-	    }
-
-	  more_patterns = argp_args_usage (argp, state, &levels, 1, fs);
-
-	  __argp_fmtstream_set_wmargin (fs, old_wm);
-	  __argp_fmtstream_set_lmargin (fs, old_lm);
-
-	  __argp_fmtstream_putc (fs, '\n');
-	  anything = 1;
-
-	  first_pattern = 0;
-	}
-      while (more_patterns);
-    }
-
-  if (flags & ARGP_HELP_PRE_DOC)
-    anything |= argp_doc (argp, state, 0, 0, 1, fs);
-
-  if (flags & ARGP_HELP_SEE)
-    {
-      __argp_fmtstream_printf (fs, dgettext (argp->argp_domain, "\
-Try `%s --help' or `%s --usage' for more information.\n"),
-			       name, name);
-      anything = 1;
-    }
-
-  if (flags & ARGP_HELP_LONG)
-    /* Print a long, detailed help message.  */
-    {
-      /* Print info about all the options.  */
-      if (hol->num_entries > 0)
-	{
-	  if (anything)
-	    __argp_fmtstream_putc (fs, '\n');
-	  hol_help (hol, state, fs);
-	  anything = 1;
-	}
-    }
-
-  if (flags & ARGP_HELP_POST_DOC)
-    /* Print any documentation strings at the end.  */
-    anything |= argp_doc (argp, state, 1, anything, 0, fs);
-
-  if ((flags & ARGP_HELP_BUG_ADDR) && argp_program_bug_address)
-    {
-      if (anything)
-	__argp_fmtstream_putc (fs, '\n');
-      __argp_fmtstream_printf (fs, dgettext (argp->argp_domain,
-					     "Report bugs to %s.\n"),
- 			       argp_program_bug_address);
-      anything = 1;
-    }
-
-#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
-  __funlockfile (stream);
-#endif
-
-  if (hol)
-    hol_free (hol);
-
-  __argp_fmtstream_free (fs);
-}
-
-/* Output a usage message for ARGP to STREAM.  FLAGS are from the set
-   ARGP_HELP_*.  NAME is what to use wherever a `program name' is needed. */
-void __argp_help (const struct argp *argp, FILE *stream,
-		  unsigned flags, char *name)
-{
-  struct argp_state state;
-  memset (&state, 0, sizeof state);
-  state.root_argp = argp;
-  _help (argp, &state, stream, flags, name);
-}
-#ifdef weak_alias
-weak_alias (__argp_help, argp_help)
-#endif
-
-#if ! (defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME)
-char *
-__argp_short_program_name (void)
-{
-# if HAVE_DECL_PROGRAM_INVOCATION_NAME
-  return __argp_base_name (program_invocation_name);
-# else
-  /* FIXME: What now? Miles suggests that it is better to use NULL,
-     but currently the value is passed on directly to fputs_unlocked,
-     so that requires more changes. */
-# if __GNUC__
-#  warning No reasonable value to return
-# endif /* __GNUC__ */
-  return "";
-# endif
-}
-#endif
-
-/* Output, if appropriate, a usage message for STATE to STREAM.  FLAGS are
-   from the set ARGP_HELP_*.  */
-void
-__argp_state_help (const struct argp_state *state, FILE *stream, unsigned flags)
-{
-  if ((!state || ! (state->flags & ARGP_NO_ERRS)) && stream)
-    {
-      if (state && (state->flags & ARGP_LONG_ONLY))
-	flags |= ARGP_HELP_LONG_ONLY;
-
-      _help (state ? state->root_argp : 0, state, stream, flags,
-	     state ? state->name : __argp_short_program_name ());
-
-      if (!state || ! (state->flags & ARGP_NO_EXIT))
-	{
-	  if (flags & ARGP_HELP_EXIT_ERR)
-	    exit (argp_err_exit_status);
-	  if (flags & ARGP_HELP_EXIT_OK)
-	    exit (0);
-	}
-  }
-}
-#ifdef weak_alias
-weak_alias (__argp_state_help, argp_state_help)
-#endif
-
-/* If appropriate, print the printf string FMT and following args, preceded
-   by the program name and `:', to stderr, and followed by a `Try ... --help'
-   message, then exit (1).  */
-void
-__argp_error (const struct argp_state *state, const char *fmt, ...)
-{
-  if (!state || !(state->flags & ARGP_NO_ERRS))
-    {
-      FILE *stream = state ? state->err_stream : stderr;
-
-      if (stream)
-	{
-	  va_list ap;
-
-#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
-	  __flockfile (stream);
-#endif
-
-	  va_start (ap, fmt);
-
-#ifdef USE_IN_LIBIO
-	  if (_IO_fwide (stream, 0) > 0)
-	    {
-	      char *buf;
-
-	      if (__asprintf (&buf, fmt, ap) < 0)
-		buf = NULL;
-
-	      __fwprintf (stream, L"%s: %s\n",
-			  state ? state->name : __argp_short_program_name (),
-			  buf);
-
-	      free (buf);
-	    }
-	  else
-#endif
-	    {
-	      fputs_unlocked (state
-			      ? state->name : __argp_short_program_name (),
-			      stream);
-	      putc_unlocked (':', stream);
-	      putc_unlocked (' ', stream);
-
-	      vfprintf (stream, fmt, ap);
-
-	      putc_unlocked ('\n', stream);
-	    }
-
-	  __argp_state_help (state, stream, ARGP_HELP_STD_ERR);
-
-	  va_end (ap);
-
-#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
-	  __funlockfile (stream);
-#endif
-	}
-    }
-}
-#ifdef weak_alias
-weak_alias (__argp_error, argp_error)
-#endif
-
-/* Similar to the standard gnu error-reporting function error(), but will
-   respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print
-   to STATE->err_stream.  This is useful for argument parsing code that is
-   shared between program startup (when exiting is desired) and runtime
-   option parsing (when typically an error code is returned instead).  The
-   difference between this function and argp_error is that the latter is for
-   *parsing errors*, and the former is for other problems that occur during
-   parsing but don't reflect a (syntactic) problem with the input.  */
-void
-__argp_failure (const struct argp_state *state, int status, int errnum,
-		const char *fmt, ...)
-{
-  if (!state || !(state->flags & ARGP_NO_ERRS))
-    {
-      FILE *stream = state ? state->err_stream : stderr;
-
-      if (stream)
-	{
-#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
-	  __flockfile (stream);
-#endif
-
-#ifdef USE_IN_LIBIO
-	  if (_IO_fwide (stream, 0) > 0)
-	    __fwprintf (stream, L"%s",
-			state ? state->name : __argp_short_program_name ());
-	  else
-#endif
-	    fputs_unlocked (state
-			    ? state->name : __argp_short_program_name (),
-			    stream);
-
-	  if (fmt)
-	    {
-	      va_list ap;
-
-	      va_start (ap, fmt);
-#ifdef USE_IN_LIBIO
-	      if (_IO_fwide (stream, 0) > 0)
-		{
-		  char *buf;
-
-		  if (__asprintf (&buf, fmt, ap) < 0)
-		    buf = NULL;
-
-		  __fwprintf (stream, L": %s", buf);
-
-		  free (buf);
-		}
-	      else
-#endif
-		{
-		  putc_unlocked (':', stream);
-		  putc_unlocked (' ', stream);
-
-		  vfprintf (stream, fmt, ap);
-		}
-
-	      va_end (ap);
-	    }
-
-	  if (errnum)
-	    {
-	      char buf[200];
-
-#ifdef USE_IN_LIBIO
-	      if (_IO_fwide (stream, 0) > 0)
-		__fwprintf (stream, L": %s",
-			    __strerror_r (errnum, buf, sizeof (buf)));
-	      else
-#endif
-		{
-		  char const *s = NULL;
-		  putc_unlocked (':', stream);
-		  putc_unlocked (' ', stream);
-#if _LIBC || (HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P)
-		  s = __strerror_r (errnum, buf, sizeof buf);
-#elif HAVE_DECL_STRERROR_R
-		  if (__strerror_r (errnum, buf, sizeof buf) == 0)
-		    s = buf;
-#endif
-#if !_LIBC
-		  if (! s && ! (s = strerror (errnum)))
-		    s = dgettext (state->root_argp->argp_domain,
-				  "Unknown system error");
-#endif
-		  fputs (s, stream);
-		}
-	    }
-
-#ifdef USE_IN_LIBIO
-	  if (_IO_fwide (stream, 0) > 0)
-	    putwc_unlocked (L'\n', stream);
-	  else
-#endif
-	    putc_unlocked ('\n', stream);
-
-#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
-	  __funlockfile (stream);
-#endif
-
-	  if (status && (!state || !(state->flags & ARGP_NO_EXIT)))
-	    exit (status);
-	}
-    }
-}
-#ifdef weak_alias
-weak_alias (__argp_failure, argp_failure)
-#endif
diff --git a/contrib/cpio/lib/argp-namefrob.h b/contrib/cpio/lib/argp-namefrob.h
deleted file mode 100644
index 6fe99cd7aaf..00000000000
--- a/contrib/cpio/lib/argp-namefrob.h
+++ /dev/null
@@ -1,158 +0,0 @@
-/* Name frobnication for compiling argp outside of glibc
-   Copyright (C) 1997, 2003, 2007 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Written by Miles Bader .
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-#if !_LIBC
-/* This code is written for inclusion in gnu-libc, and uses names in the
-   namespace reserved for libc.  If we're not compiling in libc, define those
-   names to be the normal ones instead.  */
-
-/* argp-parse functions */
-#undef __argp_parse
-#define __argp_parse argp_parse
-#undef __option_is_end
-#define __option_is_end _option_is_end
-#undef __option_is_short
-#define __option_is_short _option_is_short
-#undef __argp_input
-#define __argp_input _argp_input
-
-/* argp-help functions */
-#undef __argp_help
-#define __argp_help argp_help
-#undef __argp_error
-#define __argp_error argp_error
-#undef __argp_failure
-#define __argp_failure argp_failure
-#undef __argp_state_help
-#define __argp_state_help argp_state_help
-#undef __argp_usage
-#define __argp_usage argp_usage
-
-/* argp-fmtstream functions */
-#undef __argp_make_fmtstream
-#define __argp_make_fmtstream argp_make_fmtstream
-#undef __argp_fmtstream_free
-#define __argp_fmtstream_free argp_fmtstream_free
-#undef __argp_fmtstream_putc
-#define __argp_fmtstream_putc argp_fmtstream_putc
-#undef __argp_fmtstream_puts
-#define __argp_fmtstream_puts argp_fmtstream_puts
-#undef __argp_fmtstream_write
-#define __argp_fmtstream_write argp_fmtstream_write
-#undef __argp_fmtstream_printf
-#define __argp_fmtstream_printf argp_fmtstream_printf
-#undef __argp_fmtstream_set_lmargin
-#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin
-#undef __argp_fmtstream_set_rmargin
-#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin
-#undef __argp_fmtstream_set_wmargin
-#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin
-#undef __argp_fmtstream_point
-#define __argp_fmtstream_point argp_fmtstream_point
-#undef __argp_fmtstream_update
-#define __argp_fmtstream_update _argp_fmtstream_update
-#undef __argp_fmtstream_ensure
-#define __argp_fmtstream_ensure _argp_fmtstream_ensure
-#undef __argp_fmtstream_lmargin
-#define __argp_fmtstream_lmargin argp_fmtstream_lmargin
-#undef __argp_fmtstream_rmargin
-#define __argp_fmtstream_rmargin argp_fmtstream_rmargin
-#undef __argp_fmtstream_wmargin
-#define __argp_fmtstream_wmargin argp_fmtstream_wmargin
-
-/* normal libc functions we call */
-#undef __flockfile
-#define __flockfile flockfile
-#undef __funlockfile
-#define __funlockfile funlockfile
-#undef __mempcpy
-#define __mempcpy mempcpy
-#undef __sleep
-#define __sleep sleep
-#undef __strcasecmp
-#define __strcasecmp strcasecmp
-#undef __strchrnul
-#define __strchrnul strchrnul
-#undef __strerror_r
-#define __strerror_r strerror_r
-#undef __strndup
-#define __strndup strndup
-#undef __vsnprintf
-#define __vsnprintf vsnprintf
-
-#if defined(HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED
-# define clearerr_unlocked(x) clearerr (x)
-#endif
-#if defined(HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED
-# define feof_unlocked(x) feof (x)
-# endif
-#if defined(HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED
-# define ferror_unlocked(x) ferror (x)
-# endif
-#if defined(HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED
-# define fflush_unlocked(x) fflush (x)
-# endif
-#if defined(HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED
-# define fgets_unlocked(x,y,z) fgets (x,y,z)
-# endif
-#if defined(HAVE_DECL_FPUTC_UNLOCKED) && !HAVE_DECL_FPUTC_UNLOCKED
-# define fputc_unlocked(x,y) fputc (x,y)
-# endif
-#if defined(HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
-# define fputs_unlocked(x,y) fputs (x,y)
-# endif
-#if defined(HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED
-# define fread_unlocked(w,x,y,z) fread (w,x,y,z)
-# endif
-#if defined(HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
-# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
-# endif
-#if defined(HAVE_DECL_GETC_UNLOCKED) && !HAVE_DECL_GETC_UNLOCKED
-# define getc_unlocked(x) getc (x)
-# endif
-#if defined(HAVE_DECL_GETCHAR_UNLOCKED) && !HAVE_DECL_GETCHAR_UNLOCKED
-#  define getchar_unlocked() getchar ()
-# endif
-#if defined(HAVE_DECL_PUTC_UNLOCKED) && !HAVE_DECL_PUTC_UNLOCKED
-# define putc_unlocked(x,y) putc (x,y)
-# endif
-#if defined(HAVE_DECL_PUTCHAR_UNLOCKED) && !HAVE_DECL_PUTCHAR_UNLOCKED
-# define putchar_unlocked(x) putchar (x)
-# endif
-
-#endif /* !_LIBC */
-
-#ifndef __set_errno
-#define __set_errno(e) (errno = (e))
-#endif
-
-#if defined GNULIB_ARGP_DISABLE_DIRNAME
-# define __argp_base_name(arg) arg
-#elif defined GNULIB_ARGP_EXTERN_BASENAME
-extern char *__argp_base_name(const char *arg);
-#else
-# include "dirname.h"
-# define __argp_base_name base_name
-#endif
-
-#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
-# define __argp_short_program_name()	(program_invocation_short_name)
-#else
-extern char *__argp_short_program_name (void);
-#endif
diff --git a/contrib/cpio/lib/argp-parse.c b/contrib/cpio/lib/argp-parse.c
deleted file mode 100644
index a7de72902aa..00000000000
--- a/contrib/cpio/lib/argp-parse.c
+++ /dev/null
@@ -1,953 +0,0 @@
-/* Hierarchial argument parsing, layered over getopt
-   Copyright (C) 1995-2000, 2002, 2003, 2004 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Written by Miles Bader .
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifdef HAVE_CONFIG_H
-# include 
-#endif
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#ifdef _LIBC
-# include 
-# undef dgettext
-# define dgettext(domain, msgid) \
-   INTUSE(__dcgettext) (domain, msgid, LC_MESSAGES)
-#else
-# include "gettext.h"
-#endif
-#define N_(msgid) msgid
-
-#include "argp.h"
-#include "argp-namefrob.h"
-
-#define alignof(type) offsetof (struct { char c; type x; }, x)
-#define alignto(n, d) ((((n) + (d) - 1) / (d)) * (d))
-
-/* Getopt return values.  */
-#define KEY_END (-1)		/* The end of the options.  */
-#define KEY_ARG 1		/* A non-option argument.  */
-#define KEY_ERR '?'		/* An error parsing the options.  */
-
-/* The meta-argument used to prevent any further arguments being interpreted
-   as options.  */
-#define QUOTE "--"
-
-/* The number of bits we steal in a long-option value for our own use.  */
-#define GROUP_BITS CHAR_BIT
-
-/* The number of bits available for the user value.  */
-#define USER_BITS ((sizeof ((struct option *)0)->val * CHAR_BIT) - GROUP_BITS)
-#define USER_MASK ((1 << USER_BITS) - 1)
-
-/* EZ alias for ARGP_ERR_UNKNOWN.  */
-#define EBADKEY ARGP_ERR_UNKNOWN
-
-/* Default options.  */
-
-/* When argp is given the --HANG switch, _ARGP_HANG is set and argp will sleep
-   for one second intervals, decrementing _ARGP_HANG until it's zero.  Thus
-   you can force the program to continue by attaching a debugger and setting
-   it to 0 yourself.  */
-static volatile int _argp_hang;
-
-#define OPT_PROGNAME	-2
-#define OPT_USAGE	-3
-#define OPT_HANG	-4
-
-static const struct argp_option argp_default_options[] =
-{
-  {"help",	  '?',    	0, 0,  N_("give this help list"), -1},
-  {"usage",	  OPT_USAGE,	0, 0,  N_("give a short usage message"), 0},
-  {"program-name",OPT_PROGNAME,N_("NAME"), OPTION_HIDDEN, N_("set the program name"), 0},
-  {"HANG",	  OPT_HANG,    N_("SECS"), OPTION_ARG_OPTIONAL | OPTION_HIDDEN,
-     N_("hang for SECS seconds (default 3600)"), 0},
-  {NULL, 0, 0, 0, NULL, 0}
-};
-
-static error_t
-argp_default_parser (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case '?':
-      __argp_state_help (state, state->out_stream, ARGP_HELP_STD_HELP);
-      break;
-    case OPT_USAGE:
-      __argp_state_help (state, state->out_stream,
-			 ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
-      break;
-
-    case OPT_PROGNAME:		/* Set the program name.  */
-#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_NAME
-      program_invocation_name = arg;
-#endif
-      /* [Note that some systems only have PROGRAM_INVOCATION_SHORT_NAME (aka
-	 __PROGNAME), in which case, PROGRAM_INVOCATION_NAME is just defined
-	 to be that, so we have to be a bit careful here.]  */
-
-      /* Update what we use for messages.  */
-      state->name = __argp_base_name (arg);
-
-#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
-      program_invocation_short_name = state->name;
-#endif
-
-      if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS))
-	  == ARGP_PARSE_ARGV0)
-	/* Update what getopt uses too.  */
-	state->argv[0] = arg;
-
-      break;
-
-    case OPT_HANG:
-      _argp_hang = atoi (arg ? arg : "3600");
-      while (_argp_hang-- > 0)
-	__sleep (1);
-      break;
-
-    default:
-      return EBADKEY;
-    }
-  return 0;
-}
-
-static const struct argp argp_default_argp =
-  {argp_default_options, &argp_default_parser, NULL, NULL, NULL, NULL, "libc"};
-
-
-static const struct argp_option argp_version_options[] =
-{
-  {"version",	  'V',    	0, 0,  N_("print program version"), -1},
-  {NULL, 0, 0, 0, NULL, 0}
-};
-
-static error_t
-argp_version_parser (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case 'V':
-      if (argp_program_version_hook)
-	(*argp_program_version_hook) (state->out_stream, state);
-      else if (argp_program_version)
-	fprintf (state->out_stream, "%s\n", argp_program_version);
-      else
-	__argp_error (state, dgettext (state->root_argp->argp_domain,
-				       "(PROGRAM ERROR) No version known!?"));
-      if (! (state->flags & ARGP_NO_EXIT))
-	exit (0);
-      break;
-    default:
-      return EBADKEY;
-    }
-  return 0;
-}
-
-static const struct argp argp_version_argp =
-  {argp_version_options, &argp_version_parser, NULL, NULL, NULL, NULL, "libc"};
-
-/* Returns the offset into the getopt long options array LONG_OPTIONS of a
-   long option with called NAME, or -1 if none is found.  Passing NULL as
-   NAME will return the number of options.  */
-static int
-find_long_option (struct option *long_options, const char *name)
-{
-  struct option *l = long_options;
-  while (l->name != NULL)
-    if (name != NULL && strcmp (l->name, name) == 0)
-      return l - long_options;
-    else
-      l++;
-  if (name == NULL)
-    return l - long_options;
-  else
-    return -1;
-}
-
-
-/* The state of a `group' during parsing.  Each group corresponds to a
-   particular argp structure from the tree of such descending from the top
-   level argp passed to argp_parse.  */
-struct group
-{
-  /* This group's parsing function.  */
-  argp_parser_t parser;
-
-  /* Which argp this group is from.  */
-  const struct argp *argp;
-
-  /* Points to the point in SHORT_OPTS corresponding to the end of the short
-     options for this group.  We use it to determine from which group a
-     particular short options is from.  */
-  char *short_end;
-
-  /* The number of non-option args sucessfully handled by this parser.  */
-  unsigned args_processed;
-
-  /* This group's parser's parent's group.  */
-  struct group *parent;
-  unsigned parent_index;	/* And the our position in the parent.   */
-
-  /* These fields are swapped into and out of the state structure when
-     calling this group's parser.  */
-  void *input, **child_inputs;
-  void *hook;
-};
-
-/* Call GROUP's parser with KEY and ARG, swapping any group-specific info
-   from STATE before calling, and back into state afterwards.  If GROUP has
-   no parser, EBADKEY is returned.  */
-static error_t
-group_parse (struct group *group, struct argp_state *state, int key, char *arg)
-{
-  if (group->parser)
-    {
-      error_t err;
-      state->hook = group->hook;
-      state->input = group->input;
-      state->child_inputs = group->child_inputs;
-      state->arg_num = group->args_processed;
-      err = (*group->parser)(key, arg, state);
-      group->hook = state->hook;
-      return err;
-    }
-  else
-    return EBADKEY;
-}
-
-struct parser
-{
-  const struct argp *argp;
-
-  /* SHORT_OPTS is the getopt short options string for the union of all the
-     groups of options.  */
-  char *short_opts;
-  /* LONG_OPTS is the array of getop long option structures for the union of
-     all the groups of options.  */
-  struct option *long_opts;
-  /* OPT_DATA is the getopt data used for the re-entrant getopt.  */
-  struct _getopt_data opt_data;
-
-  /* States of the various parsing groups.  */
-  struct group *groups;
-  /* The end of the GROUPS array.  */
-  struct group *egroup;
-  /* An vector containing storage for the CHILD_INPUTS field in all groups.  */
-  void **child_inputs;
-
-  /* True if we think using getopt is still useful; if false, then
-     remaining arguments are just passed verbatim with ARGP_KEY_ARG.  This is
-     cleared whenever getopt returns KEY_END, but may be set again if the user
-     moves the next argument pointer backwards.  */
-  int try_getopt;
-
-  /* State block supplied to parsing routines.  */
-  struct argp_state state;
-
-  /* Memory used by this parser.  */
-  void *storage;
-};
-
-/* The next usable entries in the various parser tables being filled in by
-   convert_options.  */
-struct parser_convert_state
-{
-  struct parser *parser;
-  char *short_end;
-  struct option *long_end;
-  void **child_inputs_end;
-};
-
-/* Converts all options in ARGP (which is put in GROUP) and ancestors
-   into getopt options stored in SHORT_OPTS and LONG_OPTS; SHORT_END and
-   CVT->LONG_END are the points at which new options are added.  Returns the
-   next unused group entry.  CVT holds state used during the conversion.  */
-static struct group *
-convert_options (const struct argp *argp,
-		 struct group *parent, unsigned parent_index,
-		 struct group *group, struct parser_convert_state *cvt)
-{
-  /* REAL is the most recent non-alias value of OPT.  */
-  const struct argp_option *real = argp->options;
-  const struct argp_child *children = argp->children;
-
-  if (real || argp->parser)
-    {
-      const struct argp_option *opt;
-
-      if (real)
-	for (opt = real; !__option_is_end (opt); opt++)
-	  {
-	    if (! (opt->flags & OPTION_ALIAS))
-	      /* OPT isn't an alias, so we can use values from it.  */
-	      real = opt;
-
-	    if (! (real->flags & OPTION_DOC))
-	      /* A real option (not just documentation).  */
-	      {
-		if (__option_is_short (opt))
-		  /* OPT can be used as a short option.  */
-		  {
-		    *cvt->short_end++ = opt->key;
-		    if (real->arg)
-		      {
-			*cvt->short_end++ = ':';
-			if (real->flags & OPTION_ARG_OPTIONAL)
-			  *cvt->short_end++ = ':';
-		      }
-		    *cvt->short_end = '\0'; /* keep 0 terminated */
-		  }
-
-		if (opt->name
-		    && find_long_option (cvt->parser->long_opts, opt->name) < 0)
-		  /* OPT can be used as a long option.  */
-		  {
-		    cvt->long_end->name = opt->name;
-		    cvt->long_end->has_arg =
-		      (real->arg
-		       ? (real->flags & OPTION_ARG_OPTIONAL
-			  ? optional_argument
-			  : required_argument)
-		       : no_argument);
-		    cvt->long_end->flag = 0;
-		    /* we add a disambiguating code to all the user's
-		       values (which is removed before we actually call
-		       the function to parse the value); this means that
-		       the user loses use of the high 8 bits in all his
-		       values (the sign of the lower bits is preserved
-		       however)...  */
-		    cvt->long_end->val =
-		      ((opt->key | real->key) & USER_MASK)
-		      + (((group - cvt->parser->groups) + 1) << USER_BITS);
-
-		    /* Keep the LONG_OPTS list terminated.  */
-		    (++cvt->long_end)->name = NULL;
-		  }
-	      }
-	    }
-
-      group->parser = argp->parser;
-      group->argp = argp;
-      group->short_end = cvt->short_end;
-      group->args_processed = 0;
-      group->parent = parent;
-      group->parent_index = parent_index;
-      group->input = 0;
-      group->hook = 0;
-      group->child_inputs = 0;
-
-      if (children)
-	/* Assign GROUP's CHILD_INPUTS field some space from
-           CVT->child_inputs_end.*/
-	{
-	  unsigned num_children = 0;
-	  while (children[num_children].argp)
-	    num_children++;
-	  group->child_inputs = cvt->child_inputs_end;
-	  cvt->child_inputs_end += num_children;
-	}
-
-      parent = group++;
-    }
-  else
-    parent = 0;
-
-  if (children)
-    {
-      unsigned index = 0;
-      while (children->argp)
-	group =
-	  convert_options (children++->argp, parent, index++, group, cvt);
-    }
-
-  return group;
-}
-
-/* Find the merged set of getopt options, with keys appropiately prefixed. */
-static void
-parser_convert (struct parser *parser, const struct argp *argp, int flags)
-{
-  struct parser_convert_state cvt;
-
-  cvt.parser = parser;
-  cvt.short_end = parser->short_opts;
-  cvt.long_end = parser->long_opts;
-  cvt.child_inputs_end = parser->child_inputs;
-
-  if (flags & ARGP_IN_ORDER)
-    *cvt.short_end++ = '-';
-  else if (flags & ARGP_NO_ARGS)
-    *cvt.short_end++ = '+';
-  *cvt.short_end = '\0';
-
-  cvt.long_end->name = NULL;
-
-  parser->argp = argp;
-
-  if (argp)
-    parser->egroup = convert_options (argp, 0, 0, parser->groups, &cvt);
-  else
-    parser->egroup = parser->groups; /* No parsers at all! */
-}
-
-/* Lengths of various parser fields which we will allocated.  */
-struct parser_sizes
-{
-  size_t short_len;		/* Getopt short options string.  */
-  size_t long_len;		/* Getopt long options vector.  */
-  size_t num_groups;		/* Group structures we allocate.  */
-  size_t num_child_inputs;	/* Child input slots.  */
-};
-
-/* For ARGP, increments the NUM_GROUPS field in SZS by the total number of
- argp structures descended from it, and the SHORT_LEN & LONG_LEN fields by
- the maximum lengths of the resulting merged getopt short options string and
- long-options array, respectively.  */
-static void
-calc_sizes (const struct argp *argp,  struct parser_sizes *szs)
-{
-  const struct argp_child *child = argp->children;
-  const struct argp_option *opt = argp->options;
-
-  if (opt || argp->parser)
-    {
-      szs->num_groups++;
-      if (opt)
-	{
-	  int num_opts = 0;
-	  while (!__option_is_end (opt++))
-	    num_opts++;
-	  szs->short_len += num_opts * 3; /* opt + up to 2 `:'s */
-	  szs->long_len += num_opts;
-	}
-    }
-
-  if (child)
-    while (child->argp)
-      {
-	calc_sizes ((child++)->argp, szs);
-	szs->num_child_inputs++;
-      }
-}
-
-/* Initializes PARSER to parse ARGP in a manner described by FLAGS.  */
-static error_t
-parser_init (struct parser *parser, const struct argp *argp,
-	     int argc, char **argv, int flags, void *input)
-{
-  error_t err = 0;
-  struct group *group;
-  struct parser_sizes szs;
-  struct _getopt_data opt_data = _GETOPT_DATA_INITIALIZER;
-  char *storage;
-  size_t glen, gsum;
-  size_t clen, csum;
-  size_t llen, lsum;
-  size_t slen, ssum;
-
-  szs.short_len = (flags & ARGP_NO_ARGS) ? 0 : 1;
-  szs.long_len = 0;
-  szs.num_groups = 0;
-  szs.num_child_inputs = 0;
-
-  if (argp)
-    calc_sizes (argp, &szs);
-
-  /* Lengths of the various bits of storage used by PARSER.  */
-  glen = (szs.num_groups + 1) * sizeof (struct group);
-  clen = szs.num_child_inputs * sizeof (void *);
-  llen = (szs.long_len + 1) * sizeof (struct option);
-  slen = szs.short_len + 1;
-
-  /* Sums of previous lengths, properly aligned.  There's no need to
-     align gsum, since struct group is aligned at least as strictly as
-     void * (since it contains a void * member).  And there's no need
-     to align lsum, since struct option is aligned at least as
-     strictly as char.  */
-  gsum = glen;
-  csum = alignto (gsum + clen, alignof (struct option));
-  lsum = csum + llen;
-  ssum = lsum + slen;
-
-  parser->storage = malloc (ssum);
-  if (! parser->storage)
-    return ENOMEM;
-
-  storage = parser->storage;
-  parser->groups = parser->storage;
-  parser->child_inputs = (void **) (storage + gsum);
-  parser->long_opts = (struct option *) (storage + csum);
-  parser->short_opts = storage + lsum;
-  parser->opt_data = opt_data;
-
-  memset (parser->child_inputs, 0, clen);
-  parser_convert (parser, argp, flags);
-
-  memset (&parser->state, 0, sizeof (struct argp_state));
-  parser->state.root_argp = parser->argp;
-  parser->state.argc = argc;
-  parser->state.argv = argv;
-  parser->state.flags = flags;
-  parser->state.err_stream = stderr;
-  parser->state.out_stream = stdout;
-  parser->state.next = 0;	/* Tell getopt to initialize.  */
-  parser->state.pstate = parser;
-
-  parser->try_getopt = 1;
-
-  /* Call each parser for the first time, giving it a chance to propagate
-     values to child parsers.  */
-  if (parser->groups < parser->egroup)
-    parser->groups->input = input;
-  for (group = parser->groups;
-       group < parser->egroup && (!err || err == EBADKEY);
-       group++)
-    {
-      if (group->parent)
-	/* If a child parser, get the initial input value from the parent. */
-	group->input = group->parent->child_inputs[group->parent_index];
-
-      if (!group->parser
-	  && group->argp->children && group->argp->children->argp)
-	/* For the special case where no parsing function is supplied for an
-	   argp, propagate its input to its first child, if any (this just
-	   makes very simple wrapper argps more convenient).  */
-	group->child_inputs[0] = group->input;
-
-      err = group_parse (group, &parser->state, ARGP_KEY_INIT, 0);
-    }
-  if (err == EBADKEY)
-    err = 0;			/* Some parser didn't understand.  */
-
-  if (err)
-    return err;
-
-  if (parser->state.flags & ARGP_NO_ERRS)
-    {
-      parser->opt_data.opterr = 0;
-      if (parser->state.flags & ARGP_PARSE_ARGV0)
-	/* getopt always skips ARGV[0], so we have to fake it out.  As long
-	   as OPTERR is 0, then it shouldn't actually try to access it.  */
-	parser->state.argv--, parser->state.argc++;
-    }
-  else
-    parser->opt_data.opterr = 1;	/* Print error messages.  */
-
-  if (parser->state.argv == argv && argv[0])
-    /* There's an argv[0]; use it for messages.  */
-    parser->state.name = __argp_base_name (argv[0]);
-  else
-    parser->state.name = __argp_short_program_name ();
-
-  return 0;
-}
-
-/* Free any storage consumed by PARSER (but not PARSER itself).  */
-static error_t
-parser_finalize (struct parser *parser,
-		 error_t err, int arg_ebadkey, int *end_index)
-{
-  struct group *group;
-
-  if (err == EBADKEY && arg_ebadkey)
-    /* Suppress errors generated by unparsed arguments.  */
-    err = 0;
-
-  if (! err)
-    {
-      if (parser->state.next == parser->state.argc)
-	/* We successfully parsed all arguments!  Call all the parsers again,
-	   just a few more times... */
-	{
-	  for (group = parser->groups;
-	       group < parser->egroup && (!err || err==EBADKEY);
-	       group++)
-	    if (group->args_processed == 0)
-	      err = group_parse (group, &parser->state, ARGP_KEY_NO_ARGS, 0);
-	  for (group = parser->egroup - 1;
-	       group >= parser->groups && (!err || err==EBADKEY);
-	       group--)
-	    err = group_parse (group, &parser->state, ARGP_KEY_END, 0);
-
-	  if (err == EBADKEY)
-	    err = 0;		/* Some parser didn't understand.  */
-
-	  /* Tell the user that all arguments are parsed.  */
-	  if (end_index)
-	    *end_index = parser->state.next;
-	}
-      else if (end_index)
-	/* Return any remaining arguments to the user.  */
-	*end_index = parser->state.next;
-      else
-	/* No way to return the remaining arguments, they must be bogus. */
-	{
-	  if (!(parser->state.flags & ARGP_NO_ERRS)
-	      && parser->state.err_stream)
-	    fprintf (parser->state.err_stream,
-		     dgettext (parser->argp->argp_domain,
-			       "%s: Too many arguments\n"),
-		     parser->state.name);
-	  err = EBADKEY;
-	}
-    }
-
-  /* Okay, we're all done, with either an error or success; call the parsers
-     to indicate which one.  */
-
-  if (err)
-    {
-      /* Maybe print an error message.  */
-      if (err == EBADKEY)
-	/* An appropriate message describing what the error was should have
-	   been printed earlier.  */
-	__argp_state_help (&parser->state, parser->state.err_stream,
-			   ARGP_HELP_STD_ERR);
-
-      /* Since we didn't exit, give each parser an error indication.  */
-      for (group = parser->groups; group < parser->egroup; group++)
-	group_parse (group, &parser->state, ARGP_KEY_ERROR, 0);
-    }
-  else
-    /* Notify parsers of success, and propagate back values from parsers.  */
-    {
-      /* We pass over the groups in reverse order so that child groups are
-	 given a chance to do there processing before passing back a value to
-	 the parent.  */
-      for (group = parser->egroup - 1
-	   ; group >= parser->groups && (!err || err == EBADKEY)
-	   ; group--)
-	err = group_parse (group, &parser->state, ARGP_KEY_SUCCESS, 0);
-      if (err == EBADKEY)
-	err = 0;		/* Some parser didn't understand.  */
-    }
-
-  /* Call parsers once more, to do any final cleanup.  Errors are ignored.  */
-  for (group = parser->egroup - 1; group >= parser->groups; group--)
-    group_parse (group, &parser->state, ARGP_KEY_FINI, 0);
-
-  if (err == EBADKEY)
-    err = EINVAL;
-
-  free (parser->storage);
-
-  return err;
-}
-
-/* Call the user parsers to parse the non-option argument VAL, at the current
-   position, returning any error.  The state NEXT pointer is assumed to have
-   been adjusted (by getopt) to point after this argument; this function will
-   adjust it correctly to reflect however many args actually end up being
-   consumed.  */
-static error_t
-parser_parse_arg (struct parser *parser, char *val)
-{
-  /* Save the starting value of NEXT, first adjusting it so that the arg
-     we're parsing is again the front of the arg vector.  */
-  int index = --parser->state.next;
-  error_t err = EBADKEY;
-  struct group *group;
-  int key = 0;			/* Which of ARGP_KEY_ARG[S] we used.  */
-
-  /* Try to parse the argument in each parser.  */
-  for (group = parser->groups
-       ; group < parser->egroup && err == EBADKEY
-       ; group++)
-    {
-      parser->state.next++;	/* For ARGP_KEY_ARG, consume the arg.  */
-      key = ARGP_KEY_ARG;
-      err = group_parse (group, &parser->state, key, val);
-
-      if (err == EBADKEY)
-	/* This parser doesn't like ARGP_KEY_ARG; try ARGP_KEY_ARGS instead. */
-	{
-	  parser->state.next--;	/* For ARGP_KEY_ARGS, put back the arg.  */
-	  key = ARGP_KEY_ARGS;
-	  err = group_parse (group, &parser->state, key, 0);
-	}
-    }
-
-  if (! err)
-    {
-      if (key == ARGP_KEY_ARGS)
-	/* The default for ARGP_KEY_ARGS is to assume that if NEXT isn't
-	   changed by the user, *all* arguments should be considered
-	   consumed.  */
-	parser->state.next = parser->state.argc;
-
-      if (parser->state.next > index)
-	/* Remember that we successfully processed a non-option
-	   argument -- but only if the user hasn't gotten tricky and set
-	   the clock back.  */
-	(--group)->args_processed += (parser->state.next - index);
-      else
-	/* The user wants to reparse some args, give getopt another try.  */
-	parser->try_getopt = 1;
-    }
-
-  return err;
-}
-
-/* Call the user parsers to parse the option OPT, with argument VAL, at the
-   current position, returning any error.  */
-static error_t
-parser_parse_opt (struct parser *parser, int opt, char *val)
-{
-  /* The group key encoded in the high bits; 0 for short opts or
-     group_number + 1 for long opts.  */
-  int group_key = opt >> USER_BITS;
-  error_t err = EBADKEY;
-
-  if (group_key == 0)
-    /* A short option.  By comparing OPT's position in SHORT_OPTS to the
-       various starting positions in each group's SHORT_END field, we can
-       determine which group OPT came from.  */
-    {
-      struct group *group;
-      char *short_index = strchr (parser->short_opts, opt);
-
-      if (short_index)
-	for (group = parser->groups; group < parser->egroup; group++)
-	  if (group->short_end > short_index)
-	    {
-	      err = group_parse (group, &parser->state, opt,
-				 parser->opt_data.optarg);
-	      break;
-	    }
-    }
-  else
-    /* A long option.  We use shifts instead of masking for extracting
-       the user value in order to preserve the sign.  */
-    err =
-      group_parse (&parser->groups[group_key - 1], &parser->state,
-		   (opt << GROUP_BITS) >> GROUP_BITS,
-		   parser->opt_data.optarg);
-
-  if (err == EBADKEY)
-    /* At least currently, an option not recognized is an error in the
-       parser, because we pre-compute which parser is supposed to deal
-       with each option.  */
-    {
-      static const char bad_key_err[] =
-	N_("(PROGRAM ERROR) Option should have been recognized!?");
-      if (group_key == 0)
-	__argp_error (&parser->state, "-%c: %s", opt,
-		      dgettext (parser->argp->argp_domain, bad_key_err));
-      else
-	{
-	  struct option *long_opt = parser->long_opts;
-	  while (long_opt->val != opt && long_opt->name)
-	    long_opt++;
-	  __argp_error (&parser->state, "--%s: %s",
-			long_opt->name ? long_opt->name : "???",
-			dgettext (parser->argp->argp_domain, bad_key_err));
-	}
-    }
-
-  return err;
-}
-
-/* Parse the next argument in PARSER (as indicated by PARSER->state.next).
-   Any error from the parsers is returned, and *ARGP_EBADKEY indicates
-   whether a value of EBADKEY is due to an unrecognized argument (which is
-   generally not fatal).  */
-static error_t
-parser_parse_next (struct parser *parser, int *arg_ebadkey)
-{
-  int opt;
-  error_t err = 0;
-
-  if (parser->state.quoted && parser->state.next < parser->state.quoted)
-    /* The next argument pointer has been moved to before the quoted
-       region, so pretend we never saw the quoting `--', and give getopt
-       another chance.  If the user hasn't removed it, getopt will just
-       process it again.  */
-    parser->state.quoted = 0;
-
-  if (parser->try_getopt && !parser->state.quoted)
-    /* Give getopt a chance to parse this.  */
-    {
-      /* Put it back in OPTIND for getopt.  */
-      parser->opt_data.optind = parser->state.next;
-      /* Distinguish KEY_ERR from a real option.  */
-      parser->opt_data.optopt = KEY_END;
-      if (parser->state.flags & ARGP_LONG_ONLY)
-	opt = _getopt_long_only_r (parser->state.argc, parser->state.argv,
-				   parser->short_opts, parser->long_opts, 0,
-				   &parser->opt_data);
-      else
-	opt = _getopt_long_r (parser->state.argc, parser->state.argv,
-			      parser->short_opts, parser->long_opts, 0,
-			      &parser->opt_data);
-      /* And see what getopt did.  */
-      parser->state.next = parser->opt_data.optind;
-
-      if (opt == KEY_END)
-	/* Getopt says there are no more options, so stop using
-	   getopt; we'll continue if necessary on our own.  */
-	{
-	  parser->try_getopt = 0;
-	  if (parser->state.next > 1
-	      && strcmp (parser->state.argv[parser->state.next - 1], QUOTE)
-	           == 0)
-	    /* Not only is this the end of the options, but it's a
-	       `quoted' region, which may have args that *look* like
-	       options, so we definitely shouldn't try to use getopt past
-	       here, whatever happens.  */
-	    parser->state.quoted = parser->state.next;
-	}
-      else if (opt == KEY_ERR && parser->opt_data.optopt != KEY_END)
-	/* KEY_ERR can have the same value as a valid user short
-	   option, but in the case of a real error, getopt sets OPTOPT
-	   to the offending character, which can never be KEY_END.  */
-	{
-	  *arg_ebadkey = 0;
-	  return EBADKEY;
-	}
-    }
-  else
-    opt = KEY_END;
-
-  if (opt == KEY_END)
-    {
-      /* We're past what getopt considers the options.  */
-      if (parser->state.next >= parser->state.argc
-	  || (parser->state.flags & ARGP_NO_ARGS))
-	/* Indicate that we're done.  */
-	{
-	  *arg_ebadkey = 1;
-	  return EBADKEY;
-	}
-      else
-	/* A non-option arg; simulate what getopt might have done.  */
-	{
-	  opt = KEY_ARG;
-	  parser->opt_data.optarg = parser->state.argv[parser->state.next++];
-	}
-    }
-
-  if (opt == KEY_ARG)
-    /* A non-option argument; try each parser in turn.  */
-    err = parser_parse_arg (parser, parser->opt_data.optarg);
-  else
-    err = parser_parse_opt (parser, opt, parser->opt_data.optarg);
-
-  if (err == EBADKEY)
-    *arg_ebadkey = (opt == KEY_END || opt == KEY_ARG);
-
-  return err;
-}
-
-/* Parse the options strings in ARGC & ARGV according to the argp in ARGP.
-   FLAGS is one of the ARGP_ flags above.  If END_INDEX is non-NULL, the
-   index in ARGV of the first unparsed option is returned in it.  If an
-   unknown option is present, EINVAL is returned; if some parser routine
-   returned a non-zero value, it is returned; otherwise 0 is returned.  */
-error_t
-__argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags,
-	      int *end_index, void *input)
-{
-  error_t err;
-  struct parser parser;
-
-  /* If true, then err == EBADKEY is a result of a non-option argument failing
-     to be parsed (which in some cases isn't actually an error).  */
-  int arg_ebadkey = 0;
-
-#ifndef _LIBC
-  if (!(flags & ARGP_PARSE_ARGV0))
-    {
-#ifdef HAVE_DECL_PROGRAM_INVOCATION_NAME
-      if (!program_invocation_name)
-	program_invocation_name = argv[0];
-#endif
-#ifdef HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
-      if (!program_invocation_short_name)
-	program_invocation_short_name = __argp_base_name (argv[0]);
-#endif
-    }
-#endif
-	
-  if (! (flags & ARGP_NO_HELP))
-    /* Add our own options.  */
-    {
-      struct argp_child *child = alloca (4 * sizeof (struct argp_child));
-      struct argp *top_argp = alloca (sizeof (struct argp));
-
-      /* TOP_ARGP has no options, it just serves to group the user & default
-	 argps.  */
-      memset (top_argp, 0, sizeof (*top_argp));
-      top_argp->children = child;
-
-      memset (child, 0, 4 * sizeof (struct argp_child));
-
-      if (argp)
-	(child++)->argp = argp;
-      (child++)->argp = &argp_default_argp;
-      if (argp_program_version || argp_program_version_hook)
-	(child++)->argp = &argp_version_argp;
-      child->argp = 0;
-
-      argp = top_argp;
-    }
-
-  /* Construct a parser for these arguments.  */
-  err = parser_init (&parser, argp, argc, argv, flags, input);
-
-  if (! err)
-    /* Parse! */
-    {
-      while (! err)
-	err = parser_parse_next (&parser, &arg_ebadkey);
-      err = parser_finalize (&parser, err, arg_ebadkey, end_index);
-    }
-
-  return err;
-}
-#ifdef weak_alias
-weak_alias (__argp_parse, argp_parse)
-#endif
-
-/* Return the input field for ARGP in the parser corresponding to STATE; used
-   by the help routines.  */
-void *
-__argp_input (const struct argp *argp, const struct argp_state *state)
-{
-  if (state)
-    {
-      struct group *group;
-      struct parser *parser = state->pstate;
-
-      for (group = parser->groups; group < parser->egroup; group++)
-	if (group->argp == argp)
-	  return group->input;
-    }
-
-  return 0;
-}
-#ifdef weak_alias
-weak_alias (__argp_input, _argp_input)
-#endif
diff --git a/contrib/cpio/lib/argp-pin.c b/contrib/cpio/lib/argp-pin.c
deleted file mode 100644
index 852c6d6d938..00000000000
--- a/contrib/cpio/lib/argp-pin.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Full and short program names for argp module
-   Copyright (C) 2005 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifdef HAVE_CONFIG_H
-# include 
-#endif
-
-#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
-char *program_invocation_short_name = 0;
-#endif
-#ifndef HAVE_PROGRAM_INVOCATION_NAME
-char *program_invocation_name = 0;
-#endif
-
diff --git a/contrib/cpio/lib/argp-pv.c b/contrib/cpio/lib/argp-pv.c
deleted file mode 100644
index a11298bfabd..00000000000
--- a/contrib/cpio/lib/argp-pv.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Default definition for ARGP_PROGRAM_VERSION.
-   Copyright (C) 1996, 1997, 1999, 2006 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Written by Miles Bader .
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* If set by the user program to a non-zero value, then a default option
-   --version is added (unless the ARGP_NO_HELP flag is used), which will
-   print this string followed by a newline and exit (unless the
-   ARGP_NO_EXIT flag is used).  Overridden by ARGP_PROGRAM_VERSION_HOOK.  */
-const char *argp_program_version;
diff --git a/contrib/cpio/lib/argp-pvh.c b/contrib/cpio/lib/argp-pvh.c
deleted file mode 100644
index 6bf7c49b814..00000000000
--- a/contrib/cpio/lib/argp-pvh.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* Default definition for ARGP_PROGRAM_VERSION_HOOK.
-   Copyright (C) 1996, 1997, 1999, 2004 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Written by Miles Bader .
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifdef HAVE_CONFIG_H
-# include 
-#endif
-
-#include "argp.h"
-
-/* If set by the user program to a non-zero value, then a default option
-   --version is added (unless the ARGP_NO_HELP flag is used), which calls
-   this function with a stream to print the version to and a pointer to the
-   current parsing state, and then exits (unless the ARGP_NO_EXIT flag is
-   used).  This variable takes precedent over ARGP_PROGRAM_VERSION.  */
-void (*argp_program_version_hook) (FILE *stream, struct argp_state *state) = NULL;
diff --git a/contrib/cpio/lib/argp-xinl.c b/contrib/cpio/lib/argp-xinl.c
deleted file mode 100644
index a6afb1f739a..00000000000
--- a/contrib/cpio/lib/argp-xinl.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/* Real definitions for extern inline functions in argp.h
-   Copyright (C) 1997, 1998, 2004 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Written by Miles Bader .
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-#ifdef HAVE_CONFIG_H
-# include 
-#endif
-
-#if defined _LIBC || defined HAVE_FEATURES_H
-# include 
-#endif
-
-#ifndef __USE_EXTERN_INLINES
-# define __USE_EXTERN_INLINES	1
-#endif
-#define ARGP_EI
-#undef __OPTIMIZE__
-#define __OPTIMIZE__ 1
-#include "argp.h"
-
-/* Add weak aliases.  */
-#if _LIBC - 0 && defined (weak_alias)
-
-weak_alias (__argp_usage, argp_usage)
-weak_alias (__option_is_short, _option_is_short)
-weak_alias (__option_is_end, _option_is_end)
-
-#endif
diff --git a/contrib/cpio/lib/argp.h b/contrib/cpio/lib/argp.h
deleted file mode 100644
index b5aadcfcac5..00000000000
--- a/contrib/cpio/lib/argp.h
+++ /dev/null
@@ -1,624 +0,0 @@
-/* $FreeBSD$ */
-
-/* Hierarchial argument parsing, layered over getopt.
-   Copyright (C) 1995-1999,2003-2007 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Written by Miles Bader .
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef _ARGP_H
-#define _ARGP_H
-
-#include 
-#include 
-#include 
-#include 
-
-#define __need_error_t
-#include 
-
-#ifndef __THROW
-# define __THROW
-#endif
-#ifndef __NTH
-# define __NTH(fct) fct __THROW
-#endif
-
-#ifndef __attribute__
-/* This feature is available in gcc versions 2.5 and later.  */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
-#  define __attribute__(Spec) /* empty */
-# endif
-/* The __-protected variants of `format' and `printf' attributes
-   are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || __STRICT_ANSI__
-#  define __format__ format
-#  define __printf__ printf
-# endif
-#endif
-
-/* GCC 2.95 and later have "__restrict"; C99 compilers have
-   "restrict", and "configure" may have defined "restrict".
-   Other compilers use __restrict, __restrict__, and _Restrict, and
-   'configure' might #define 'restrict' to those words.  */
-#ifndef __restrict
-# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
-#  if 199901L <= __STDC_VERSION__
-#   define __restrict restrict
-#  else
-#   define __restrict
-#  endif
-# endif
-#endif
-
-#ifndef __error_t_defined
-typedef int error_t;
-# define __error_t_defined
-#endif
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-/* A description of a particular option.  A pointer to an array of
-   these is passed in the OPTIONS field of an argp structure.  Each option
-   entry can correspond to one long option and/or one short option; more
-   names for the same option can be added by following an entry in an option
-   array with options having the OPTION_ALIAS flag set.  */
-struct argp_option
-{
-  /* The long option name.  For more than one name for the same option, you
-     can use following options with the OPTION_ALIAS flag set.  */
-  const char *name;
-
-  /* What key is returned for this option.  If > 0 and printable, then it's
-     also accepted as a short option.  */
-  int key;
-
-  /* If non-NULL, this is the name of the argument associated with this
-     option, which is required unless the OPTION_ARG_OPTIONAL flag is set. */
-  const char *arg;
-
-  /* OPTION_ flags.  */
-  int flags;
-
-  /* The doc string for this option.  If both NAME and KEY are 0, This string
-     will be printed outdented from the normal option column, making it
-     useful as a group header (it will be the first thing printed in its
-     group); in this usage, it's conventional to end the string with a `:'.
-
-     Write the initial value as N_("TEXT") if you want xgettext to collect
-     it into a POT file.  */
-  const char *doc;
-
-  /* The group this option is in.  In a long help message, options are sorted
-     alphabetically within each group, and the groups presented in the order
-     0, 1, 2, ..., n, -m, ..., -2, -1.  Every entry in an options array with
-     if this field 0 will inherit the group number of the previous entry, or
-     zero if it's the first one, unless its a group header (NAME and KEY both
-     0), in which case, the previous entry + 1 is the default.  Automagic
-     options such as --help are put into group -1.  */
-  int group;
-};
-
-/* The argument associated with this option is optional.  */
-#define OPTION_ARG_OPTIONAL	0x1
-
-/* This option isn't displayed in any help messages.  */
-#define OPTION_HIDDEN	       	0x2
-
-/* This option is an alias for the closest previous non-alias option.  This
-   means that it will be displayed in the same help entry, and will inherit
-   fields other than NAME and KEY from the aliased option.  */
-#define OPTION_ALIAS		0x4
-
-/* This option isn't actually an option (and so should be ignored by the
-   actual option parser), but rather an arbitrary piece of documentation that
-   should be displayed in much the same manner as the options.  If this flag
-   is set, then the option NAME field is displayed unmodified (e.g., no `--'
-   prefix is added) at the left-margin (where a *short* option would normally
-   be displayed), and the documentation string in the normal place. The NAME
-   field will be translated using gettext, unless OPTION_NO_TRANS is set (see
-   below). For purposes of sorting, any leading whitespace and punctuation is
-   ignored, except that if the first non-whitespace character is not `-', this
-   entry is displayed after all options (and OPTION_DOC entries with a leading
-   `-') in the same group.  */
-#define OPTION_DOC		0x8
-
-/* This option shouldn't be included in `long' usage messages (but is still
-   included in help messages).  This is mainly intended for options that are
-   completely documented in an argp's ARGS_DOC field, in which case including
-   the option in the generic usage list would be redundant.  For instance,
-   if ARGS_DOC is "FOO BAR\n-x BLAH", and the `-x' option's purpose is to
-   distinguish these two cases, -x should probably be marked
-   OPTION_NO_USAGE.  */
-#define OPTION_NO_USAGE		0x10
-
-/* Valid only in conjunction with OPTION_DOC. This option disables translation
-   of option name. */
-#define OPTION_NO_TRANS         0x20
-
-
-struct argp;			/* fwd declare this type */
-struct argp_state;		/* " */
-struct argp_child;		/* " */
-
-/* The type of a pointer to an argp parsing function.  */
-typedef error_t (*argp_parser_t) (int key, char *arg,
-				  struct argp_state *state);
-
-/* What to return for unrecognized keys.  For special ARGP_KEY_ keys, such
-   returns will simply be ignored.  For user keys, this error will be turned
-   into EINVAL (if the call to argp_parse is such that errors are propagated
-   back to the user instead of exiting); returning EINVAL itself would result
-   in an immediate stop to parsing in *all* cases.  */
-#define ARGP_ERR_UNKNOWN	E2BIG /* Hurd should never need E2BIG.  XXX */
-
-/* Special values for the KEY argument to an argument parsing function.
-   ARGP_ERR_UNKNOWN should be returned if they aren't understood.
-
-   The sequence of keys to a parsing function is either (where each
-   uppercased word should be prefixed by `ARGP_KEY_' and opt is a user key):
-
-       INIT opt... NO_ARGS END SUCCESS  -- No non-option arguments at all
-   or  INIT (opt | ARG)... END SUCCESS  -- All non-option args parsed
-   or  INIT (opt | ARG)... SUCCESS      -- Some non-option arg unrecognized
-
-   The third case is where every parser returned ARGP_KEY_UNKNOWN for an
-   argument, in which case parsing stops at that argument (returning the
-   unparsed arguments to the caller of argp_parse if requested, or stopping
-   with an error message if not).
-
-   If an error occurs (either detected by argp, or because the parsing
-   function returned an error value), then the parser is called with
-   ARGP_KEY_ERROR, and no further calls are made.  */
-
-/* This is not an option at all, but rather a command line argument.  If a
-   parser receiving this key returns success, the fact is recorded, and the
-   ARGP_KEY_NO_ARGS case won't be used.  HOWEVER, if while processing the
-   argument, a parser function decrements the NEXT field of the state it's
-   passed, the option won't be considered processed; this is to allow you to
-   actually modify the argument (perhaps into an option), and have it
-   processed again.  */
-#define ARGP_KEY_ARG		0
-/* There are remaining arguments not parsed by any parser, which may be found
-   starting at (STATE->argv + STATE->next).  If success is returned, but
-   STATE->next left untouched, it's assumed that all arguments were consume,
-   otherwise, the parser should adjust STATE->next to reflect any arguments
-   consumed.  */
-#define ARGP_KEY_ARGS		0x1000006
-/* There are no more command line arguments at all.  */
-#define ARGP_KEY_END		0x1000001
-/* Because it's common to want to do some special processing if there aren't
-   any non-option args, user parsers are called with this key if they didn't
-   successfully process any non-option arguments.  Called just before
-   ARGP_KEY_END (where more general validity checks on previously parsed
-   arguments can take place).  */
-#define ARGP_KEY_NO_ARGS	0x1000002
-/* Passed in before any parsing is done.  Afterwards, the values of each
-   element of the CHILD_INPUT field, if any, in the state structure is
-   copied to each child's state to be the initial value of the INPUT field.  */
-#define ARGP_KEY_INIT		0x1000003
-/* Use after all other keys, including SUCCESS & END.  */
-#define ARGP_KEY_FINI		0x1000007
-/* Passed in when parsing has successfully been completed (even if there are
-   still arguments remaining).  */
-#define ARGP_KEY_SUCCESS	0x1000004
-/* Passed in if an error occurs.  */
-#define ARGP_KEY_ERROR		0x1000005
-
-/* An argp structure contains a set of options declarations, a function to
-   deal with parsing one, documentation string, a possible vector of child
-   argp's, and perhaps a function to filter help output.  When actually
-   parsing options, getopt is called with the union of all the argp
-   structures chained together through their CHILD pointers, with conflicts
-   being resolved in favor of the first occurrence in the chain.  */
-struct argp
-{
-  /* An array of argp_option structures, terminated by an entry with both
-     NAME and KEY having a value of 0.  */
-  const struct argp_option *options;
-
-  /* What to do with an option from this structure.  KEY is the key
-     associated with the option, and ARG is any associated argument (NULL if
-     none was supplied).  If KEY isn't understood, ARGP_ERR_UNKNOWN should be
-     returned.  If a non-zero, non-ARGP_ERR_UNKNOWN value is returned, then
-     parsing is stopped immediately, and that value is returned from
-     argp_parse().  For special (non-user-supplied) values of KEY, see the
-     ARGP_KEY_ definitions below.  */
-  argp_parser_t parser;
-
-  /* A string describing what other arguments are wanted by this program.  It
-     is only used by argp_usage to print the `Usage:' message.  If it
-     contains newlines, the strings separated by them are considered
-     alternative usage patterns, and printed on separate lines (lines after
-     the first are prefix by `  or: ' instead of `Usage:').  */
-  const char *args_doc;
-
-  /* If non-NULL, a string containing extra text to be printed before and
-     after the options in a long help message (separated by a vertical tab
-     `\v' character).
-     Write the initial value as N_("BEFORE-TEXT") "\v" N_("AFTER-TEXT") if
-     you want xgettext to collect the two pieces of text into a POT file.  */
-  const char *doc;
-
-  /* A vector of argp_children structures, terminated by a member with a 0
-     argp field, pointing to child argps should be parsed with this one.  Any
-     conflicts are resolved in favor of this argp, or early argps in the
-     CHILDREN list.  This field is useful if you use libraries that supply
-     their own argp structure, which you want to use in conjunction with your
-     own.  */
-  const struct argp_child *children;
-
-  /* If non-zero, this should be a function to filter the output of help
-     messages.  KEY is either a key from an option, in which case TEXT is
-     that option's help text, or a special key from the ARGP_KEY_HELP_
-     defines, below, describing which other help text TEXT is.  The function
-     should return either TEXT, if it should be used as-is, a replacement
-     string, which should be malloced, and will be freed by argp, or NULL,
-     meaning `print nothing'.  The value for TEXT is *after* any translation
-     has been done, so if any of the replacement text also needs translation,
-     that should be done by the filter function.  INPUT is either the input
-     supplied to argp_parse, or NULL, if argp_help was called directly.  */
-  char *(*help_filter) (int __key, const char *__text, void *__input);
-
-  /* If non-zero the strings used in the argp library are translated using
-     the domain described by this string.  Otherwise the currently installed
-     default domain is used.  */
-  const char *argp_domain;
-};
-
-/* Possible KEY arguments to a help filter function.  */
-#define ARGP_KEY_HELP_PRE_DOC	0x2000001 /* Help text preceeding options. */
-#define ARGP_KEY_HELP_POST_DOC	0x2000002 /* Help text following options. */
-#define ARGP_KEY_HELP_HEADER	0x2000003 /* Option header string. */
-#define ARGP_KEY_HELP_EXTRA	0x2000004 /* After all other documentation;
-					     TEXT is NULL for this key.  */
-/* Explanatory note emitted when duplicate option arguments have been
-   suppressed.  */
-#define ARGP_KEY_HELP_DUP_ARGS_NOTE 0x2000005
-#define ARGP_KEY_HELP_ARGS_DOC	0x2000006 /* Argument doc string.  */
-
-/* When an argp has a non-zero CHILDREN field, it should point to a vector of
-   argp_child structures, each of which describes a subsidiary argp.  */
-struct argp_child
-{
-  /* The child parser.  */
-  const struct argp *argp;
-
-  /* Flags for this child.  */
-  int flags;
-
-  /* If non-zero, an optional header to be printed in help output before the
-     child options.  As a side-effect, a non-zero value forces the child
-     options to be grouped together; to achieve this effect without actually
-     printing a header string, use a value of "".  */
-  const char *header;
-
-  /* Where to group the child options relative to the other (`consolidated')
-     options in the parent argp; the values are the same as the GROUP field
-     in argp_option structs, but all child-groupings follow parent options at
-     a particular group level.  If both this field and HEADER are zero, then
-     they aren't grouped at all, but rather merged with the parent options
-     (merging the child's grouping levels with the parents).  */
-  int group;
-};
-
-/* Parsing state.  This is provided to parsing functions called by argp,
-   which may examine and, as noted, modify fields.  */
-struct argp_state
-{
-  /* The top level ARGP being parsed.  */
-  const struct argp *root_argp;
-
-  /* The argument vector being parsed.  May be modified.  */
-  int argc;
-  char **argv;
-
-  /* The index in ARGV of the next arg that to be parsed.  May be modified. */
-  int next;
-
-  /* The flags supplied to argp_parse.  May be modified.  */
-  unsigned flags;
-
-  /* While calling a parsing function with a key of ARGP_KEY_ARG, this is the
-     number of the current arg, starting at zero, and incremented after each
-     such call returns.  At all other times, this is the number of such
-     arguments that have been processed.  */
-  unsigned arg_num;
-
-  /* If non-zero, the index in ARGV of the first argument following a special
-     `--' argument (which prevents anything following being interpreted as an
-     option).  Only set once argument parsing has proceeded past this point. */
-  int quoted;
-
-  /* An arbitrary pointer passed in from the user.  */
-  void *input;
-  /* Values to pass to child parsers.  This vector will be the same length as
-     the number of children for the current parser.  */
-  void **child_inputs;
-
-  /* For the parser's use.  Initialized to 0.  */
-  void *hook;
-
-  /* The name used when printing messages.  This is initialized to ARGV[0],
-     or PROGRAM_INVOCATION_NAME if that is unavailable.  */
-  char *name;
-
-  /* Streams used when argp prints something.  */
-  FILE *err_stream;		/* For errors; initialized to stderr. */
-  FILE *out_stream;		/* For information; initialized to stdout. */
-
-  void *pstate;			/* Private, for use by argp.  */
-};
-
-/* Flags for argp_parse (note that the defaults are those that are
-   convenient for program command line parsing): */
-
-/* Don't ignore the first element of ARGV.  Normally (and always unless
-   ARGP_NO_ERRS is set) the first element of the argument vector is
-   skipped for option parsing purposes, as it corresponds to the program name
-   in a command line.  */
-#define ARGP_PARSE_ARGV0  0x01
-
-/* Don't print error messages for unknown options to stderr; unless this flag
-   is set, ARGP_PARSE_ARGV0 is ignored, as ARGV[0] is used as the program
-   name in the error messages.  This flag implies ARGP_NO_EXIT (on the
-   assumption that silent exiting upon errors is bad behaviour).  */
-#define ARGP_NO_ERRS	0x02
-
-/* Don't parse any non-option args.  Normally non-option args are parsed by
-   calling the parse functions with a key of ARGP_KEY_ARG, and the actual arg
-   as the value.  Since it's impossible to know which parse function wants to
-   handle it, each one is called in turn, until one returns 0 or an error
-   other than ARGP_ERR_UNKNOWN; if an argument is handled by no one, the
-   argp_parse returns prematurely (but with a return value of 0).  If all
-   args have been parsed without error, all parsing functions are called one
-   last time with a key of ARGP_KEY_END.  This flag needn't normally be set,
-   as the normal behavior is to stop parsing as soon as some argument can't
-   be handled.  */
-#define ARGP_NO_ARGS	0x04
-
-/* Parse options and arguments in the same order they occur on the command
-   line -- normally they're rearranged so that all options come first. */
-#define ARGP_IN_ORDER	0x08
-
-/* Don't provide the standard long option --help, which causes usage and
-      option help information to be output to stdout, and exit (0) called. */
-#define ARGP_NO_HELP	0x10
-
-/* Don't exit on errors (they may still result in error messages).  */
-#define ARGP_NO_EXIT	0x20
-
-/* Use the gnu getopt `long-only' rules for parsing arguments.  */
-#define ARGP_LONG_ONLY	0x40
-
-/* Turns off any message-printing/exiting options.  */
-#define ARGP_SILENT    (ARGP_NO_EXIT | ARGP_NO_ERRS | ARGP_NO_HELP)
-
-/* Parse the options strings in ARGC & ARGV according to the options in ARGP.
-   FLAGS is one of the ARGP_ flags above.  If ARG_INDEX is non-NULL, the
-   index in ARGV of the first unparsed option is returned in it.  If an
-   unknown option is present, ARGP_ERR_UNKNOWN is returned; if some parser
-   routine returned a non-zero value, it is returned; otherwise 0 is
-   returned.  This function may also call exit unless the ARGP_NO_HELP flag
-   is set.  INPUT is a pointer to a value to be passed in to the parser.  */
-extern error_t argp_parse (const struct argp *__restrict __argp,
-			   int /*argc*/, char **__restrict /*argv*/,
-			   unsigned __flags, int *__restrict __arg_index,
-			   void *__restrict __input);
-extern error_t __argp_parse (const struct argp *__restrict __argp,
-			     int /*argc*/, char **__restrict /*argv*/,
-			     unsigned __flags, int *__restrict __arg_index,
-			     void *__restrict __input);
-
-/* Global variables.  */
-
-/* GNULIB makes sure both program_invocation_name and
-   program_invocation_short_name are available */
-#ifdef GNULIB_PROGRAM_INVOCATION_NAME
-extern char *program_invocation_name;
-# undef HAVE_DECL_PROGRAM_INVOCATION_NAME
-# define HAVE_DECL_PROGRAM_INVOCATION_NAME 1
-#endif
-
-#ifdef GNULIB_PROGRAM_INVOCATION_SHORT_NAME
-extern char *program_invocation_short_name;
-# undef HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
-# define HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME 1
-#endif
-
-/* If defined or set by the user program to a non-zero value, then a default
-   option --version is added (unless the ARGP_NO_HELP flag is used), which
-   will print this string followed by a newline and exit (unless the
-   ARGP_NO_EXIT flag is used).  Overridden by ARGP_PROGRAM_VERSION_HOOK.  */
-extern const char *argp_program_version;
-
-/* If defined or set by the user program to a non-zero value, then a default
-   option --version is added (unless the ARGP_NO_HELP flag is used), which
-   calls this function with a stream to print the version to and a pointer to
-   the current parsing state, and then exits (unless the ARGP_NO_EXIT flag is
-   used).  This variable takes precedent over ARGP_PROGRAM_VERSION.  */
-extern void (*argp_program_version_hook) (FILE *__restrict __stream,
-					  struct argp_state *__restrict
-					  __state);
-
-/* If defined or set by the user program, it should point to string that is
-   the bug-reporting address for the program.  It will be printed by
-   argp_help if the ARGP_HELP_BUG_ADDR flag is set (as it is by various
-   standard help messages), embedded in a sentence that says something like
-   `Report bugs to ADDR.'.  */
-extern const char *argp_program_bug_address;
-
-/* The exit status that argp will use when exiting due to a parsing error.
-   If not defined or set by the user program, this defaults to EX_USAGE from
-   .  */
-extern error_t argp_err_exit_status;
-
-/* Flags for argp_help.  */
-#define ARGP_HELP_USAGE		0x01 /* a Usage: message. */
-#define ARGP_HELP_SHORT_USAGE	0x02 /*  " but don't actually print options. */
-#define ARGP_HELP_SEE		0x04 /* a `Try ... for more help' message. */
-#define ARGP_HELP_LONG		0x08 /* a long help message. */
-#define ARGP_HELP_PRE_DOC	0x10 /* doc string preceding long help.  */
-#define ARGP_HELP_POST_DOC	0x20 /* doc string following long help.  */
-#define ARGP_HELP_DOC		(ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC)
-#define ARGP_HELP_BUG_ADDR	0x40 /* bug report address */
-#define ARGP_HELP_LONG_ONLY	0x80 /* modify output appropriately to
-					reflect ARGP_LONG_ONLY mode.  */
-
-/* These ARGP_HELP flags are only understood by argp_state_help.  */
-#define ARGP_HELP_EXIT_ERR	0x100 /* Call exit(1) instead of returning.  */
-#define ARGP_HELP_EXIT_OK	0x200 /* Call exit(0) instead of returning.  */
-
-/* The standard thing to do after a program command line parsing error, if an
-   error message has already been printed.  */
-#define ARGP_HELP_STD_ERR \
-  (ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)
-/* The standard thing to do after a program command line parsing error, if no
-   more specific error message has been printed.  */
-#define ARGP_HELP_STD_USAGE \
-  (ARGP_HELP_SHORT_USAGE | ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)
-/* The standard thing to do in response to a --help option.  */
-#define ARGP_HELP_STD_HELP \
-  (ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_EXIT_OK \
-   | ARGP_HELP_DOC | ARGP_HELP_BUG_ADDR)
-
-/* Output a usage message for ARGP to STREAM.  FLAGS are from the set
-   ARGP_HELP_*.  */
-extern void argp_help (const struct argp *__restrict __argp,
-		       FILE *__restrict __stream,
-		       unsigned __flags, char *__restrict __name);
-extern void __argp_help (const struct argp *__restrict __argp,
-			 FILE *__restrict __stream, unsigned __flags,
-			 char *__name);
-
-/* The following routines are intended to be called from within an argp
-   parsing routine (thus taking an argp_state structure as the first
-   argument).  They may or may not print an error message and exit, depending
-   on the flags in STATE -- in any case, the caller should be prepared for
-   them *not* to exit, and should return an appropiate error after calling
-   them.  [argp_usage & argp_error should probably be called argp_state_...,
-   but they're used often enough that they should be short]  */
-
-/* Output, if appropriate, a usage message for STATE to STREAM.  FLAGS are
-   from the set ARGP_HELP_*.  */
-extern void argp_state_help (const struct argp_state *__restrict __state,
-			     FILE *__restrict __stream,
-			     unsigned int __flags);
-extern void __argp_state_help (const struct argp_state *__restrict __state,
-			       FILE *__restrict __stream,
-			       unsigned int __flags);
-
-/* Possibly output the standard usage message for ARGP to stderr and exit.  */
-extern void argp_usage (const struct argp_state *__state);
-extern void __argp_usage (const struct argp_state *__state);
-
-/* If appropriate, print the printf string FMT and following args, preceded
-   by the program name and `:', to stderr, and followed by a `Try ... --help'
-   message, then exit (1).  */
-extern void argp_error (const struct argp_state *__restrict __state,
-			const char *__restrict __fmt, ...)
-     __attribute__ ((__format__ (__printf__, 2, 3)));
-extern void __argp_error (const struct argp_state *__restrict __state,
-			  const char *__restrict __fmt, ...)
-     __attribute__ ((__format__ (__printf__, 2, 3)));
-
-/* Similar to the standard gnu error-reporting function error(), but will
-   respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print
-   to STATE->err_stream.  This is useful for argument parsing code that is
-   shared between program startup (when exiting is desired) and runtime
-   option parsing (when typically an error code is returned instead).  The
-   difference between this function and argp_error is that the latter is for
-   *parsing errors*, and the former is for other problems that occur during
-   parsing but don't reflect a (syntactic) problem with the input.  */
-extern void argp_failure (const struct argp_state *__restrict __state,
-			  int __status, int __errnum,
-			  const char *__restrict __fmt, ...)
-     __attribute__ ((__format__ (__printf__, 4, 5)));
-extern void __argp_failure (const struct argp_state *__restrict __state,
-			    int __status, int __errnum,
-			    const char *__restrict __fmt, ...)
-     __attribute__ ((__format__ (__printf__, 4, 5)));
-
-/* Returns true if the option OPT is a valid short option.  */
-extern int _option_is_short (const struct argp_option *__opt) __THROW;
-extern int __option_is_short (const struct argp_option *__opt) __THROW;
-
-/* Returns true if the option OPT is in fact the last (unused) entry in an
-   options array.  */
-extern int _option_is_end (const struct argp_option *__opt) __THROW;
-extern int __option_is_end (const struct argp_option *__opt) __THROW;
-
-/* Return the input field for ARGP in the parser corresponding to STATE; used
-   by the help routines.  */
-extern void *_argp_input (const struct argp *__restrict __argp,
-			  const struct argp_state *__restrict __state)
-     __THROW;
-extern void *__argp_input (const struct argp *__restrict __argp,
-			   const struct argp_state *__restrict __state)
-     __THROW;
-
-#ifdef __USE_EXTERN_INLINES
-
-# if !_LIBC
-#  define __argp_usage argp_usage
-#  define __argp_state_help argp_state_help
-#  define __option_is_short _option_is_short
-#  define __option_is_end _option_is_end
-# endif
-
-# ifndef ARGP_EI
-#  define ARGP_EI extern __inline__
-# endif
-
-ARGP_EI void
-__argp_usage (const struct argp_state *__state)
-{
-  __argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE);
-}
-
-ARGP_EI int
-__NTH (__option_is_short (const struct argp_option *__opt))
-{
-  if (__opt->flags & OPTION_DOC)
-    return 0;
-  else
-    {
-      int __key = __opt->key;
-      return __key > 0 && __key <= UCHAR_MAX && isprint (__key);
-    }
-}
-
-ARGP_EI int
-__NTH (__option_is_end (const struct argp_option *__opt))
-{
-  return !__opt->key && !__opt->name && !__opt->doc && !__opt->group;
-}
-
-# if !_LIBC
-#  undef __argp_usage
-#  undef __argp_state_help
-#  undef __option_is_short
-#  undef __option_is_end
-# endif
-#endif /* Use extern inlines.  */
-
-#ifdef  __cplusplus
-}
-#endif
-
-#endif /* argp.h */
diff --git a/contrib/cpio/lib/basename.c b/contrib/cpio/lib/basename.c
deleted file mode 100644
index fbe17ff910c..00000000000
--- a/contrib/cpio/lib/basename.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/* basename.c -- return the last element in a file name
-
-   Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006 Free
-   Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-#include "dirname.h"
-
-#include 
-#include "xalloc.h"
-#include "xstrndup.h"
-
-/* Return the address of the last file name component of NAME.  If
-   NAME has no relative file name components because it is a file
-   system root, return the empty string.  */
-
-char *
-last_component (char const *name)
-{
-  char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
-  char const *p;
-  bool saw_slash = false;
-
-  while (ISSLASH (*base))
-    base++;
-
-  for (p = base; *p; p++)
-    {
-      if (ISSLASH (*p))
-	saw_slash = true;
-      else if (saw_slash)
-	{
-	  base = p;
-	  saw_slash = false;
-	}
-    }
-
-  return (char *) base;
-}
-
-
-/* In general, we can't use the builtin `basename' function if available,
-   since it has different meanings in different environments.
-   In some environments the builtin `basename' modifies its argument.
-
-   Return the last file name component of NAME, allocated with
-   xmalloc.  On systems with drive letters, a leading "./"
-   distinguishes relative names that would otherwise look like a drive
-   letter.  Unlike POSIX basename(), NAME cannot be NULL,
-   base_name("") returns "", and the first trailing slash is not
-   stripped.
-
-   If lstat (NAME) would succeed, then { chdir (dir_name (NAME));
-   lstat (base_name (NAME)); } will access the same file.  Likewise,
-   if the sequence { chdir (dir_name (NAME));
-   rename (base_name (NAME), "foo"); } succeeds, you have renamed NAME
-   to "foo" in the same directory NAME was in.  */
-
-char *
-base_name (char const *name)
-{
-  char const *base = last_component (name);
-  size_t length;
-
-  /* If there is no last component, then name is a file system root or the
-     empty string.  */
-  if (! *base)
-    return xstrndup (name, base_len (name));
-
-  /* Collapse a sequence of trailing slashes into one.  */
-  length = base_len (base);
-  if (ISSLASH (base[length]))
-    length++;
-
-  /* On systems with drive letters, `a/b:c' must return `./b:c' rather
-     than `b:c' to avoid confusion with a drive letter.  On systems
-     with pure POSIX semantics, this is not an issue.  */
-  if (FILE_SYSTEM_PREFIX_LEN (base))
-    {
-      char *p = xmalloc (length + 3);
-      p[0] = '.';
-      p[1] = '/';
-      memcpy (p + 2, base, length);
-      p[length + 2] = '\0';
-      return p;
-    }
-
-  /* Finally, copy the basename.  */
-  return xstrndup (base, length);
-}
-
-/* Return the length of the basename NAME.  Typically NAME is the
-   value returned by base_name or last_component.  Act like strlen
-   (NAME), except omit all trailing slashes.  */
-
-size_t
-base_len (char const *name)
-{
-  size_t len;
-  size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
-
-  for (len = strlen (name);  1 < len && ISSLASH (name[len - 1]);  len--)
-    continue;
-
-  if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1
-      && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
-    return 2;
-
-  if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
-      && len == prefix_len && ISSLASH (name[prefix_len]))
-    return prefix_len + 1;
-
-  return len;
-}
diff --git a/contrib/cpio/lib/dirname.c b/contrib/cpio/lib/dirname.c
deleted file mode 100644
index 16552c64d2a..00000000000
--- a/contrib/cpio/lib/dirname.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/* dirname.c -- return all but the last element in a file name
-
-   Copyright (C) 1990, 1998, 2000, 2001, 2003, 2004, 2005, 2006 Free Software
-   Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-#include "dirname.h"
-
-#include 
-#include "xalloc.h"
-
-/* Return the length of the prefix of FILE that will be used by
-   dir_name.  If FILE is in the working directory, this returns zero
-   even though `dir_name (FILE)' will return ".".  Works properly even
-   if there are trailing slashes (by effectively ignoring them).  */
-
-size_t
-dir_len (char const *file)
-{
-  size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file);
-  size_t length;
-
-  /* Advance prefix_length beyond important leading slashes.  */
-  prefix_length += (prefix_length != 0
-		    ? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
-		       && ISSLASH (file[prefix_length]))
-		    : (ISSLASH (file[0])
-		       ? ((DOUBLE_SLASH_IS_DISTINCT_ROOT
-			   && ISSLASH (file[1]) && ! ISSLASH (file[2])
-			   ? 2 : 1))
-		       : 0));
-
-  /* Strip the basename and any redundant slashes before it.  */
-  for (length = last_component (file) - file;
-       prefix_length < length; length--)
-    if (! ISSLASH (file[length - 1]))
-      break;
-  return length;
-}
-
-
-/* In general, we can't use the builtin `dirname' function if available,
-   since it has different meanings in different environments.
-   In some environments the builtin `dirname' modifies its argument.
-
-   Return the leading directories part of FILE, allocated with xmalloc.
-   Works properly even if there are trailing slashes (by effectively
-   ignoring them).  Unlike POSIX dirname(), FILE cannot be NULL.
-
-   If lstat (FILE) would succeed, then { chdir (dir_name (FILE));
-   lstat (base_name (FILE)); } will access the same file.  Likewise,
-   if the sequence { chdir (dir_name (FILE));
-   rename (base_name (FILE), "foo"); } succeeds, you have renamed FILE
-   to "foo" in the same directory FILE was in.  */
-
-char *
-dir_name (char const *file)
-{
-  size_t length = dir_len (file);
-  bool append_dot = (length == 0
-		     || (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
-			 && length == FILE_SYSTEM_PREFIX_LEN (file)
-			 && file[2] != '\0' && ! ISSLASH (file[2])));
-  char *dir = xmalloc (length + append_dot + 1);
-  memcpy (dir, file, length);
-  if (append_dot)
-    dir[length++] = '.';
-  dir[length] = '\0';
-  return dir;
-}
diff --git a/contrib/cpio/lib/dirname.h b/contrib/cpio/lib/dirname.h
deleted file mode 100644
index 91e7ed33666..00000000000
--- a/contrib/cpio/lib/dirname.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*  Take file names apart into directory and base names.
-
-    Copyright (C) 1998, 2001, 2003-2006 Free Software Foundation, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2, or (at your option)
-    any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software Foundation,
-    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef DIRNAME_H_
-# define DIRNAME_H_ 1
-
-# include 
-# include 
-
-# ifndef DIRECTORY_SEPARATOR
-#  define DIRECTORY_SEPARATOR '/'
-# endif
-
-# ifndef ISSLASH
-#  define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
-# endif
-
-# ifndef FILE_SYSTEM_PREFIX_LEN
-#  if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX
-    /* This internal macro assumes ASCII, but all hosts that support drive
-       letters use ASCII.  */
-#   define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' \
-				<= 'z' - 'a')
-#   define FILE_SYSTEM_PREFIX_LEN(Filename) \
-	   (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0)
-#  else
-#   define FILE_SYSTEM_PREFIX_LEN(Filename) 0
-#  endif
-# endif
-
-# ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
-#  define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
-# endif
-
-# ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
-#  define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
-# endif
-
-# if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
-#  define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)])
-# else
-#  define IS_ABSOLUTE_FILE_NAME(F) \
-	  (ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F))
-# endif
-# define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F))
-
-char *base_name (char const *file);
-char *dir_name (char const *file);
-size_t base_len (char const *file);
-size_t dir_len (char const *file);
-char *last_component (char const *file);
-
-bool strip_trailing_slashes (char *file);
-
-#endif /* not DIRNAME_H_ */
diff --git a/contrib/cpio/lib/error.c b/contrib/cpio/lib/error.c
deleted file mode 100644
index cf863433202..00000000000
--- a/contrib/cpio/lib/error.c
+++ /dev/null
@@ -1,338 +0,0 @@
-/* Error handler for noninteractive utilities
-   Copyright (C) 1990-1998, 2000-2005, 2006 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by David MacKenzie .  */
-
-#if !_LIBC
-# include 
-#endif
-
-#include "error.h"
-
-#include 
-#include 
-#include 
-#include 
-
-#if !_LIBC && ENABLE_NLS
-# include "gettext.h"
-#endif
-
-#ifdef _LIBC
-# include 
-# include 
-# include 
-# include 
-# define mbsrtowcs __mbsrtowcs
-#endif
-
-#if USE_UNLOCKED_IO
-# include "unlocked-io.h"
-#endif
-
-#ifndef _
-# define _(String) String
-#endif
-
-/* If NULL, error will flush stdout, then print on stderr the program
-   name, a colon and a space.  Otherwise, error will call this
-   function without parameters instead.  */
-void (*error_print_progname) (void);
-
-/* This variable is incremented each time `error' is called.  */
-unsigned int error_message_count;
-
-#ifdef _LIBC
-/* In the GNU C library, there is a predefined variable for this.  */
-
-# define program_name program_invocation_name
-# include 
-# include 
-# include 
-
-/* In GNU libc we want do not want to use the common name `error' directly.
-   Instead make it a weak alias.  */
-extern void __error (int status, int errnum, const char *message, ...)
-     __attribute__ ((__format__ (__printf__, 3, 4)));
-extern void __error_at_line (int status, int errnum, const char *file_name,
-			     unsigned int line_number, const char *message,
-			     ...)
-     __attribute__ ((__format__ (__printf__, 5, 6)));;
-# define error __error
-# define error_at_line __error_at_line
-
-# include 
-# define fflush(s) INTUSE(_IO_fflush) (s)
-# undef putc
-# define putc(c, fp) INTUSE(_IO_putc) (c, fp)
-
-# include 
-
-#else /* not _LIBC */
-
-# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P
-#  ifndef HAVE_DECL_STRERROR_R
-"this configure-time declaration test was not run"
-#  endif
-char *strerror_r ();
-# endif
-
-/* The calling program should define program_name and set it to the
-   name of the executing program.  */
-extern char *program_name;
-
-# if HAVE_STRERROR_R || defined strerror_r
-#  define __strerror_r strerror_r
-# endif	/* HAVE_STRERROR_R || defined strerror_r */
-#endif	/* not _LIBC */
-
-static void
-print_errno_message (int errnum)
-{
-  char const *s;
-
-#if defined HAVE_STRERROR_R || _LIBC
-  char errbuf[1024];
-# if STRERROR_R_CHAR_P || _LIBC
-  s = __strerror_r (errnum, errbuf, sizeof errbuf);
-# else
-  if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0)
-    s = errbuf;
-  else
-    s = 0;
-# endif
-#else
-  s = strerror (errnum);
-#endif
-
-#if !_LIBC
-  if (! s)
-    s = _("Unknown system error");
-#endif
-
-#if _LIBC
-  __fxprintf (NULL, ": %s", s);
-#else
-  fprintf (stderr, ": %s", s);
-#endif
-}
-
-static void
-error_tail (int status, int errnum, const char *message, va_list args)
-{
-#if _LIBC
-  if (_IO_fwide (stderr, 0) > 0)
-    {
-# define ALLOCA_LIMIT 2000
-      size_t len = strlen (message) + 1;
-      wchar_t *wmessage = NULL;
-      mbstate_t st;
-      size_t res;
-      const char *tmp;
-      bool use_malloc = false;
-
-      while (1)
-	{
-	  if (__libc_use_alloca (len * sizeof (wchar_t)))
-	    wmessage = (wchar_t *) alloca (len * sizeof (wchar_t));
-	  else
-	    {
-	      if (!use_malloc)
-		wmessage = NULL;
-
-	      wchar_t *p = (wchar_t *) realloc (wmessage,
-						len * sizeof (wchar_t));
-	      if (p == NULL)
-		{
-		  free (wmessage);
-		  fputws_unlocked (L"out of memory\n", stderr);
-		  return;
-		}
-	      wmessage = p;
-	      use_malloc = true;
-	    }
-
-	  memset (&st, '\0', sizeof (st));
-	  tmp = message;
-
-	  res = mbsrtowcs (wmessage, &tmp, len, &st);
-	  if (res != len)
-	    break;
-
-	  if (__builtin_expect (len >= SIZE_MAX / 2, 0))
-	    {
-	      /* This really should not happen if everything is fine.  */
-	      res = (size_t) -1;
-	      break;
-	    }
-
-	  len *= 2;
-	}
-
-      if (res == (size_t) -1)
-	{
-	  /* The string cannot be converted.  */
-	  if (use_malloc)
-	    {
-	      free (wmessage);
-	      use_malloc = false;
-	    }
-	  wmessage = (wchar_t *) L"???";
-	}
-
-      __vfwprintf (stderr, wmessage, args);
-
-      if (use_malloc)
-	free (wmessage);
-    }
-  else
-#endif
-    vfprintf (stderr, message, args);
-  va_end (args);
-
-  ++error_message_count;
-  if (errnum)
-    print_errno_message (errnum);
-#if _LIBC
-  __fxprintf (NULL, "\n");
-#else
-  putc ('\n', stderr);
-#endif
-  fflush (stderr);
-  if (status)
-    exit (status);
-}
-
-
-/* Print the program name and error message MESSAGE, which is a printf-style
-   format string with optional args.
-   If ERRNUM is nonzero, print its corresponding system error message.
-   Exit with status STATUS if it is nonzero.  */
-void
-error (int status, int errnum, const char *message, ...)
-{
-  va_list args;
-
-#if defined _LIBC && defined __libc_ptf_call
-  /* We do not want this call to be cut short by a thread
-     cancellation.  Therefore disable cancellation for now.  */
-  int state = PTHREAD_CANCEL_ENABLE;
-  __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
-		   0);
-#endif
-
-  fflush (stdout);
-#ifdef _LIBC
-  _IO_flockfile (stderr);
-#endif
-  if (error_print_progname)
-    (*error_print_progname) ();
-  else
-    {
-#if _LIBC
-      __fxprintf (NULL, "%s: ", program_name);
-#else
-      fprintf (stderr, "%s: ", program_name);
-#endif
-    }
-
-  va_start (args, message);
-  error_tail (status, errnum, message, args);
-
-#ifdef _LIBC
-  _IO_funlockfile (stderr);
-# ifdef __libc_ptf_call
-  __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
-# endif
-#endif
-}
-
-/* Sometimes we want to have at most one error per line.  This
-   variable controls whether this mode is selected or not.  */
-int error_one_per_line;
-
-void
-error_at_line (int status, int errnum, const char *file_name,
-	       unsigned int line_number, const char *message, ...)
-{
-  va_list args;
-
-  if (error_one_per_line)
-    {
-      static const char *old_file_name;
-      static unsigned int old_line_number;
-
-      if (old_line_number == line_number
-	  && (file_name == old_file_name
-	      || strcmp (old_file_name, file_name) == 0))
-	/* Simply return and print nothing.  */
-	return;
-
-      old_file_name = file_name;
-      old_line_number = line_number;
-    }
-
-#if defined _LIBC && defined __libc_ptf_call
-  /* We do not want this call to be cut short by a thread
-     cancellation.  Therefore disable cancellation for now.  */
-  int state = PTHREAD_CANCEL_ENABLE;
-  __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
-		   0);
-#endif
-
-  fflush (stdout);
-#ifdef _LIBC
-  _IO_flockfile (stderr);
-#endif
-  if (error_print_progname)
-    (*error_print_progname) ();
-  else
-    {
-#if _LIBC
-      __fxprintf (NULL, "%s:", program_name);
-#else
-      fprintf (stderr, "%s:", program_name);
-#endif
-    }
-
-#if _LIBC
-  __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ",
-	      file_name, line_number);
-#else
-  fprintf (stderr, file_name != NULL ? "%s:%d: " : " ",
-	   file_name, line_number);
-#endif
-
-  va_start (args, message);
-  error_tail (status, errnum, message, args);
-
-#ifdef _LIBC
-  _IO_funlockfile (stderr);
-# ifdef __libc_ptf_call
-  __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
-# endif
-#endif
-}
-
-#ifdef _LIBC
-/* Make the weak alias.  */
-# undef error
-# undef error_at_line
-weak_alias (__error, error)
-weak_alias (__error_at_line, error_at_line)
-#endif
diff --git a/contrib/cpio/lib/error.h b/contrib/cpio/lib/error.h
deleted file mode 100644
index 5a5f2476583..00000000000
--- a/contrib/cpio/lib/error.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/* Declaration for error-reporting function
-   Copyright (C) 1995, 1996, 1997, 2003, 2006 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef _ERROR_H
-#define _ERROR_H 1
-
-#ifndef __attribute__
-/* This feature is available in gcc versions 2.5 and later.  */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
-#  define __attribute__(Spec) /* empty */
-# endif
-/* The __-protected variants of `format' and `printf' attributes
-   are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-#  define __format__ format
-#  define __printf__ printf
-# endif
-#endif
-
-#ifdef	__cplusplus
-extern "C" {
-#endif
-
-/* Print a message with `fprintf (stderr, FORMAT, ...)';
-   if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
-   If STATUS is nonzero, terminate the program with `exit (STATUS)'.  */
-
-extern void error (int __status, int __errnum, const char *__format, ...)
-     __attribute__ ((__format__ (__printf__, 3, 4)));
-
-extern void error_at_line (int __status, int __errnum, const char *__fname,
-			   unsigned int __lineno, const char *__format, ...)
-     __attribute__ ((__format__ (__printf__, 5, 6)));
-
-/* If NULL, error will flush stdout, then print on stderr the program
-   name, a colon and a space.  Otherwise, error will call this
-   function without parameters instead.  */
-extern void (*error_print_progname) (void);
-
-/* This variable is incremented each time `error' is called.  */
-extern unsigned int error_message_count;
-
-/* Sometimes we want to have at most one error per line.  This
-   variable controls whether this mode is selected or not.  */
-extern int error_one_per_line;
-
-#ifdef	__cplusplus
-}
-#endif
-
-#endif /* error.h */
diff --git a/contrib/cpio/lib/exitfail.c b/contrib/cpio/lib/exitfail.c
deleted file mode 100644
index 373d325c5ad..00000000000
--- a/contrib/cpio/lib/exitfail.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/* Failure exit status
-
-   Copyright (C) 2002, 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; see the file COPYING.
-   If not, write to the Free Software Foundation,
-   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-#include "exitfail.h"
-
-#include 
-
-int volatile exit_failure = EXIT_FAILURE;
diff --git a/contrib/cpio/lib/exitfail.h b/contrib/cpio/lib/exitfail.h
deleted file mode 100644
index e46cf9c1665..00000000000
--- a/contrib/cpio/lib/exitfail.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* Failure exit status
-
-   Copyright (C) 2002 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; see the file COPYING.
-   If not, write to the Free Software Foundation,
-   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-extern int volatile exit_failure;
diff --git a/contrib/cpio/lib/fatal.c b/contrib/cpio/lib/fatal.c
deleted file mode 100644
index bcce42c090a..00000000000
--- a/contrib/cpio/lib/fatal.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/* This file is part of GNU cpio.
-   Copyright (C) 2005 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-#include 
-#include 
-
-void
-fatal_exit ()
-{
-  exit (PAXEXIT_FAILURE);
-}
-
diff --git a/contrib/cpio/lib/full-write.c b/contrib/cpio/lib/full-write.c
deleted file mode 100644
index cc168720eae..00000000000
--- a/contrib/cpio/lib/full-write.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/* An interface to read and write that retries (if necessary) until complete.
-
-   Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-   2004, 2005, 2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-/* Specification.  */
-#ifdef FULL_READ
-# include "full-read.h"
-#else
-# include "full-write.h"
-#endif
-
-#include 
-
-#ifdef FULL_READ
-# include "safe-read.h"
-# define safe_rw safe_read
-# define full_rw full_read
-# undef const
-# define const /* empty */
-#else
-# include "safe-write.h"
-# define safe_rw safe_write
-# define full_rw full_write
-#endif
-
-#ifdef FULL_READ
-/* Set errno to zero upon EOF.  */
-# define ZERO_BYTE_TRANSFER_ERRNO 0
-#else
-/* Some buggy drivers return 0 when one tries to write beyond
-   a device's end.  (Example: Linux 1.2.13 on /dev/fd0.)
-   Set errno to ENOSPC so they get a sensible diagnostic.  */
-# define ZERO_BYTE_TRANSFER_ERRNO ENOSPC
-#endif
-
-/* Write(read) COUNT bytes at BUF to(from) descriptor FD, retrying if
-   interrupted or if a partial write(read) occurs.  Return the number
-   of bytes transferred.
-   When writing, set errno if fewer than COUNT bytes are written.
-   When reading, if fewer than COUNT bytes are read, you must examine
-   errno to distinguish failure from EOF (errno == 0).  */
-size_t
-full_rw (int fd, const void *buf, size_t count)
-{
-  size_t total = 0;
-  const char *ptr = (const char *) buf;
-
-  while (count > 0)
-    {
-      size_t n_rw = safe_rw (fd, ptr, count);
-      if (n_rw == (size_t) -1)
-	break;
-      if (n_rw == 0)
-	{
-	  errno = ZERO_BYTE_TRANSFER_ERRNO;
-	  break;
-	}
-      total += n_rw;
-      ptr += n_rw;
-      count -= n_rw;
-    }
-
-  return total;
-}
diff --git a/contrib/cpio/lib/full-write.h b/contrib/cpio/lib/full-write.h
deleted file mode 100644
index d20d2fe4abd..00000000000
--- a/contrib/cpio/lib/full-write.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* An interface to write() that writes all it is asked to write.
-
-   Copyright (C) 2002-2003 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Write COUNT bytes at BUF to descriptor FD, retrying if interrupted
-   or if partial writes occur.  Return the number of bytes successfully
-   written, setting errno if that is less than COUNT.  */
-extern size_t full_write (int fd, const void *buf, size_t count);
-
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/contrib/cpio/lib/getopt.c b/contrib/cpio/lib/getopt.c
deleted file mode 100644
index 3580ad825c6..00000000000
--- a/contrib/cpio/lib/getopt.c
+++ /dev/null
@@ -1,1191 +0,0 @@
-/* Getopt for GNU.
-   NOTE: getopt is now part of the C library, so if you don't know what
-   "Keep this file name-space clean" means, talk to drepper@gnu.org
-   before changing it!
-   Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002,2003,2004,2006
-	Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef _LIBC
-# include 
-#endif
-
-#include "getopt.h"
-
-#include 
-#include 
-#include 
-#include 
-
-#ifdef __VMS
-# include 
-#endif
-
-#ifdef _LIBC
-# include 
-#else
-# include "gettext.h"
-# define _(msgid) gettext (msgid)
-#endif
-
-#if defined _LIBC && defined USE_IN_LIBIO
-# include 
-#endif
-
-#ifndef attribute_hidden
-# define attribute_hidden
-#endif
-
-/* Unlike standard Unix `getopt', functions like `getopt_long'
-   let the user intersperse the options with the other arguments.
-
-   As `getopt_long' works, it permutes the elements of ARGV so that,
-   when it is done, all the options precede everything else.  Thus
-   all application programs are extended to handle flexible argument order.
-
-   Using `getopt' or setting the environment variable POSIXLY_CORRECT
-   disables permutation.
-   Then the application's behavior is completely standard.
-
-   GNU application programs can use a third alternative mode in which
-   they can distinguish the relative order of options and other arguments.  */
-
-#include "getopt_int.h"
-
-/* For communication from `getopt' to the caller.
-   When `getopt' finds an option that takes an argument,
-   the argument value is returned here.
-   Also, when `ordering' is RETURN_IN_ORDER,
-   each non-option ARGV-element is returned here.  */
-
-char *optarg;
-
-/* Index in ARGV of the next element to be scanned.
-   This is used for communication to and from the caller
-   and for communication between successive calls to `getopt'.
-
-   On entry to `getopt', zero means this is the first call; initialize.
-
-   When `getopt' returns -1, this is the index of the first of the
-   non-option elements that the caller should itself scan.
-
-   Otherwise, `optind' communicates from one call to the next
-   how much of ARGV has been scanned so far.  */
-
-/* 1003.2 says this must be 1 before any call.  */
-int optind = 1;
-
-/* Callers store zero here to inhibit the error message
-   for unrecognized options.  */
-
-int opterr = 1;
-
-/* Set to an option character which was unrecognized.
-   This must be initialized on some systems to avoid linking in the
-   system's own getopt implementation.  */
-
-int optopt = '?';
-
-/* Keep a global copy of all internal members of getopt_data.  */
-
-static struct _getopt_data getopt_data;
-
-
-#if defined HAVE_DECL_GETENV && !HAVE_DECL_GETENV
-extern char *getenv ();
-#endif
-
-#ifdef _LIBC
-/* Stored original parameters.
-   XXX This is no good solution.  We should rather copy the args so
-   that we can compare them later.  But we must not use malloc(3).  */
-extern int __libc_argc;
-extern char **__libc_argv;
-
-/* Bash 2.0 gives us an environment variable containing flags
-   indicating ARGV elements that should not be considered arguments.  */
-
-# ifdef USE_NONOPTION_FLAGS
-/* Defined in getopt_init.c  */
-extern char *__getopt_nonoption_flags;
-# endif
-
-# ifdef USE_NONOPTION_FLAGS
-#  define SWAP_FLAGS(ch1, ch2) \
-  if (d->__nonoption_flags_len > 0)					      \
-    {									      \
-      char __tmp = __getopt_nonoption_flags[ch1];			      \
-      __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2];	      \
-      __getopt_nonoption_flags[ch2] = __tmp;				      \
-    }
-# else
-#  define SWAP_FLAGS(ch1, ch2)
-# endif
-#else	/* !_LIBC */
-# define SWAP_FLAGS(ch1, ch2)
-#endif	/* _LIBC */
-
-/* Exchange two adjacent subsequences of ARGV.
-   One subsequence is elements [first_nonopt,last_nonopt)
-   which contains all the non-options that have been skipped so far.
-   The other is elements [last_nonopt,optind), which contains all
-   the options processed since those non-options were skipped.
-
-   `first_nonopt' and `last_nonopt' are relocated so that they describe
-   the new indices of the non-options in ARGV after they are moved.  */
-
-static void
-exchange (char **argv, struct _getopt_data *d)
-{
-  int bottom = d->__first_nonopt;
-  int middle = d->__last_nonopt;
-  int top = d->optind;
-  char *tem;
-
-  /* Exchange the shorter segment with the far end of the longer segment.
-     That puts the shorter segment into the right place.
-     It leaves the longer segment in the right place overall,
-     but it consists of two parts that need to be swapped next.  */
-
-#if defined _LIBC && defined USE_NONOPTION_FLAGS
-  /* First make sure the handling of the `__getopt_nonoption_flags'
-     string can work normally.  Our top argument must be in the range
-     of the string.  */
-  if (d->__nonoption_flags_len > 0 && top >= d->__nonoption_flags_max_len)
-    {
-      /* We must extend the array.  The user plays games with us and
-	 presents new arguments.  */
-      char *new_str = malloc (top + 1);
-      if (new_str == NULL)
-	d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0;
-      else
-	{
-	  memset (__mempcpy (new_str, __getopt_nonoption_flags,
-			     d->__nonoption_flags_max_len),
-		  '\0', top + 1 - d->__nonoption_flags_max_len);
-	  d->__nonoption_flags_max_len = top + 1;
-	  __getopt_nonoption_flags = new_str;
-	}
-    }
-#endif
-
-  while (top > middle && middle > bottom)
-    {
-      if (top - middle > middle - bottom)
-	{
-	  /* Bottom segment is the short one.  */
-	  int len = middle - bottom;
-	  register int i;
-
-	  /* Swap it with the top part of the top segment.  */
-	  for (i = 0; i < len; i++)
-	    {
-	      tem = argv[bottom + i];
-	      argv[bottom + i] = argv[top - (middle - bottom) + i];
-	      argv[top - (middle - bottom) + i] = tem;
-	      SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
-	    }
-	  /* Exclude the moved bottom segment from further swapping.  */
-	  top -= len;
-	}
-      else
-	{
-	  /* Top segment is the short one.  */
-	  int len = top - middle;
-	  register int i;
-
-	  /* Swap it with the bottom part of the bottom segment.  */
-	  for (i = 0; i < len; i++)
-	    {
-	      tem = argv[bottom + i];
-	      argv[bottom + i] = argv[middle + i];
-	      argv[middle + i] = tem;
-	      SWAP_FLAGS (bottom + i, middle + i);
-	    }
-	  /* Exclude the moved top segment from further swapping.  */
-	  bottom += len;
-	}
-    }
-
-  /* Update records for the slots the non-options now occupy.  */
-
-  d->__first_nonopt += (d->optind - d->__last_nonopt);
-  d->__last_nonopt = d->optind;
-}
-
-/* Initialize the internal data when the first call is made.  */
-
-static const char *
-_getopt_initialize (int argc, char **argv, const char *optstring,
-		    int posixly_correct, struct _getopt_data *d)
-{
-  /* Start processing options with ARGV-element 1 (since ARGV-element 0
-     is the program name); the sequence of previously skipped
-     non-option ARGV-elements is empty.  */
-
-  d->__first_nonopt = d->__last_nonopt = d->optind;
-
-  d->__nextchar = NULL;
-
-  d->__posixly_correct = posixly_correct || !!getenv ("POSIXLY_CORRECT");
-
-  /* Determine how to handle the ordering of options and nonoptions.  */
-
-  if (optstring[0] == '-')
-    {
-      d->__ordering = RETURN_IN_ORDER;
-      ++optstring;
-    }
-  else if (optstring[0] == '+')
-    {
-      d->__ordering = REQUIRE_ORDER;
-      ++optstring;
-    }
-  else if (d->__posixly_correct)
-    d->__ordering = REQUIRE_ORDER;
-  else
-    d->__ordering = PERMUTE;
-
-#if defined _LIBC && defined USE_NONOPTION_FLAGS
-  if (!d->__posixly_correct
-      && argc == __libc_argc && argv == __libc_argv)
-    {
-      if (d->__nonoption_flags_max_len == 0)
-	{
-	  if (__getopt_nonoption_flags == NULL
-	      || __getopt_nonoption_flags[0] == '\0')
-	    d->__nonoption_flags_max_len = -1;
-	  else
-	    {
-	      const char *orig_str = __getopt_nonoption_flags;
-	      int len = d->__nonoption_flags_max_len = strlen (orig_str);
-	      if (d->__nonoption_flags_max_len < argc)
-		d->__nonoption_flags_max_len = argc;
-	      __getopt_nonoption_flags =
-		(char *) malloc (d->__nonoption_flags_max_len);
-	      if (__getopt_nonoption_flags == NULL)
-		d->__nonoption_flags_max_len = -1;
-	      else
-		memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
-			'\0', d->__nonoption_flags_max_len - len);
-	    }
-	}
-      d->__nonoption_flags_len = d->__nonoption_flags_max_len;
-    }
-  else
-    d->__nonoption_flags_len = 0;
-#endif
-
-  return optstring;
-}
-
-/* Scan elements of ARGV (whose length is ARGC) for option characters
-   given in OPTSTRING.
-
-   If an element of ARGV starts with '-', and is not exactly "-" or "--",
-   then it is an option element.  The characters of this element
-   (aside from the initial '-') are option characters.  If `getopt'
-   is called repeatedly, it returns successively each of the option characters
-   from each of the option elements.
-
-   If `getopt' finds another option character, it returns that character,
-   updating `optind' and `nextchar' so that the next call to `getopt' can
-   resume the scan with the following option character or ARGV-element.
-
-   If there are no more option characters, `getopt' returns -1.
-   Then `optind' is the index in ARGV of the first ARGV-element
-   that is not an option.  (The ARGV-elements have been permuted
-   so that those that are not options now come last.)
-
-   OPTSTRING is a string containing the legitimate option characters.
-   If an option character is seen that is not listed in OPTSTRING,
-   return '?' after printing an error message.  If you set `opterr' to
-   zero, the error message is suppressed but we still return '?'.
-
-   If a char in OPTSTRING is followed by a colon, that means it wants an arg,
-   so the following text in the same ARGV-element, or the text of the following
-   ARGV-element, is returned in `optarg'.  Two colons mean an option that
-   wants an optional arg; if there is text in the current ARGV-element,
-   it is returned in `optarg', otherwise `optarg' is set to zero.
-
-   If OPTSTRING starts with `-' or `+', it requests different methods of
-   handling the non-option ARGV-elements.
-   See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
-
-   Long-named options begin with `--' instead of `-'.
-   Their names may be abbreviated as long as the abbreviation is unique
-   or is an exact match for some defined option.  If they have an
-   argument, it follows the option name in the same ARGV-element, separated
-   from the option name by a `=', or else the in next ARGV-element.
-   When `getopt' finds a long-named option, it returns 0 if that option's
-   `flag' field is nonzero, the value of the option's `val' field
-   if the `flag' field is zero.
-
-   LONGOPTS is a vector of `struct option' terminated by an
-   element containing a name which is zero.
-
-   LONGIND returns the index in LONGOPT of the long-named option found.
-   It is only valid when a long-named option has been found by the most
-   recent call.
-
-   If LONG_ONLY is nonzero, '-' as well as '--' can introduce
-   long-named options.
-
-   If POSIXLY_CORRECT is nonzero, behave as if the POSIXLY_CORRECT
-   environment variable were set.  */
-
-int
-_getopt_internal_r (int argc, char **argv, const char *optstring,
-		    const struct option *longopts, int *longind,
-		    int long_only, int posixly_correct, struct _getopt_data *d)
-{
-  int print_errors = d->opterr;
-  if (optstring[0] == ':')
-    print_errors = 0;
-
-  if (argc < 1)
-    return -1;
-
-  d->optarg = NULL;
-
-  if (d->optind == 0 || !d->__initialized)
-    {
-      if (d->optind == 0)
-	d->optind = 1;	/* Don't scan ARGV[0], the program name.  */
-      optstring = _getopt_initialize (argc, argv, optstring,
-				      posixly_correct, d);
-      d->__initialized = 1;
-    }
-
-  /* Test whether ARGV[optind] points to a non-option argument.
-     Either it does not have option syntax, or there is an environment flag
-     from the shell indicating it is not an option.  The later information
-     is only used when the used in the GNU libc.  */
-#if defined _LIBC && defined USE_NONOPTION_FLAGS
-# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0' \
-		      || (d->optind < d->__nonoption_flags_len		      \
-			  && __getopt_nonoption_flags[d->optind] == '1'))
-#else
-# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0')
-#endif
-
-  if (d->__nextchar == NULL || *d->__nextchar == '\0')
-    {
-      /* Advance to the next ARGV-element.  */
-
-      /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
-	 moved back by the user (who may also have changed the arguments).  */
-      if (d->__last_nonopt > d->optind)
-	d->__last_nonopt = d->optind;
-      if (d->__first_nonopt > d->optind)
-	d->__first_nonopt = d->optind;
-
-      if (d->__ordering == PERMUTE)
-	{
-	  /* If we have just processed some options following some non-options,
-	     exchange them so that the options come first.  */
-
-	  if (d->__first_nonopt != d->__last_nonopt
-	      && d->__last_nonopt != d->optind)
-	    exchange ((char **) argv, d);
-	  else if (d->__last_nonopt != d->optind)
-	    d->__first_nonopt = d->optind;
-
-	  /* Skip any additional non-options
-	     and extend the range of non-options previously skipped.  */
-
-	  while (d->optind < argc && NONOPTION_P)
-	    d->optind++;
-	  d->__last_nonopt = d->optind;
-	}
-
-      /* The special ARGV-element `--' means premature end of options.
-	 Skip it like a null option,
-	 then exchange with previous non-options as if it were an option,
-	 then skip everything else like a non-option.  */
-
-      if (d->optind != argc && !strcmp (argv[d->optind], "--"))
-	{
-	  d->optind++;
-
-	  if (d->__first_nonopt != d->__last_nonopt
-	      && d->__last_nonopt != d->optind)
-	    exchange ((char **) argv, d);
-	  else if (d->__first_nonopt == d->__last_nonopt)
-	    d->__first_nonopt = d->optind;
-	  d->__last_nonopt = argc;
-
-	  d->optind = argc;
-	}
-
-      /* If we have done all the ARGV-elements, stop the scan
-	 and back over any non-options that we skipped and permuted.  */
-
-      if (d->optind == argc)
-	{
-	  /* Set the next-arg-index to point at the non-options
-	     that we previously skipped, so the caller will digest them.  */
-	  if (d->__first_nonopt != d->__last_nonopt)
-	    d->optind = d->__first_nonopt;
-	  return -1;
-	}
-
-      /* If we have come to a non-option and did not permute it,
-	 either stop the scan or describe it to the caller and pass it by.  */
-
-      if (NONOPTION_P)
-	{
-	  if (d->__ordering == REQUIRE_ORDER)
-	    return -1;
-	  d->optarg = argv[d->optind++];
-	  return 1;
-	}
-
-      /* We have found another option-ARGV-element.
-	 Skip the initial punctuation.  */
-
-      d->__nextchar = (argv[d->optind] + 1
-		  + (longopts != NULL && argv[d->optind][1] == '-'));
-    }
-
-  /* Decode the current option-ARGV-element.  */
-
-  /* Check whether the ARGV-element is a long option.
-
-     If long_only and the ARGV-element has the form "-f", where f is
-     a valid short option, don't consider it an abbreviated form of
-     a long option that starts with f.  Otherwise there would be no
-     way to give the -f short option.
-
-     On the other hand, if there's a long option "fubar" and
-     the ARGV-element is "-fu", do consider that an abbreviation of
-     the long option, just like "--fu", and not "-f" with arg "u".
-
-     This distinction seems to be the most useful approach.  */
-
-  if (longopts != NULL
-      && (argv[d->optind][1] == '-'
-	  || (long_only && (argv[d->optind][2]
-			    || !strchr (optstring, argv[d->optind][1])))))
-    {
-      char *nameend;
-      const struct option *p;
-      const struct option *pfound = NULL;
-      int exact = 0;
-      int ambig = 0;
-      int indfound = -1;
-      int option_index;
-
-      for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++)
-	/* Do nothing.  */ ;
-
-      /* Test all long options for either exact match
-	 or abbreviated matches.  */
-      for (p = longopts, option_index = 0; p->name; p++, option_index++)
-	if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
-	  {
-	    if ((unsigned int) (nameend - d->__nextchar)
-		== (unsigned int) strlen (p->name))
-	      {
-		/* Exact match found.  */
-		pfound = p;
-		indfound = option_index;
-		exact = 1;
-		break;
-	      }
-	    else if (pfound == NULL)
-	      {
-		/* First nonexact match found.  */
-		pfound = p;
-		indfound = option_index;
-	      }
-	    else if (long_only
-		     || pfound->has_arg != p->has_arg
-		     || pfound->flag != p->flag
-		     || pfound->val != p->val)
-	      /* Second or later nonexact match found.  */
-	      ambig = 1;
-	  }
-
-      if (ambig && !exact)
-	{
-	  if (print_errors)
-	    {
-#if defined _LIBC && defined USE_IN_LIBIO
-	      char *buf;
-
-	      if (__asprintf (&buf, _("%s: option `%s' is ambiguous\n"),
-			      argv[0], argv[d->optind]) >= 0)
-		{
-		  _IO_flockfile (stderr);
-
-		  int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-		  ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
-
-		  __fxprintf (NULL, "%s", buf);
-
-		  ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-		  _IO_funlockfile (stderr);
-
-		  free (buf);
-		}
-#else
-	      fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
-		       argv[0], argv[d->optind]);
-#endif
-	    }
-	  d->__nextchar += strlen (d->__nextchar);
-	  d->optind++;
-	  d->optopt = 0;
-	  return '?';
-	}
-
-      if (pfound != NULL)
-	{
-	  option_index = indfound;
-	  d->optind++;
-	  if (*nameend)
-	    {
-	      /* Don't test has_arg with >, because some C compilers don't
-		 allow it to be used on enums.  */
-	      if (pfound->has_arg)
-		d->optarg = nameend + 1;
-	      else
-		{
-		  if (print_errors)
-		    {
-#if defined _LIBC && defined USE_IN_LIBIO
-		      char *buf;
-		      int n;
-#endif
-
-		      if (argv[d->optind - 1][1] == '-')
-			{
-			  /* --option */
-#if defined _LIBC && defined USE_IN_LIBIO
-			  n = __asprintf (&buf, _("\
-%s: option `--%s' doesn't allow an argument\n"),
-					  argv[0], pfound->name);
-#else
-			  fprintf (stderr, _("\
-%s: option `--%s' doesn't allow an argument\n"),
-				   argv[0], pfound->name);
-#endif
-			}
-		      else
-			{
-			  /* +option or -option */
-#if defined _LIBC && defined USE_IN_LIBIO
-			  n = __asprintf (&buf, _("\
-%s: option `%c%s' doesn't allow an argument\n"),
-					  argv[0], argv[d->optind - 1][0],
-					  pfound->name);
-#else
-			  fprintf (stderr, _("\
-%s: option `%c%s' doesn't allow an argument\n"),
-				   argv[0], argv[d->optind - 1][0],
-				   pfound->name);
-#endif
-			}
-
-#if defined _LIBC && defined USE_IN_LIBIO
-		      if (n >= 0)
-			{
-			  _IO_flockfile (stderr);
-
-			  int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-			  ((_IO_FILE *) stderr)->_flags2
-			    |= _IO_FLAGS2_NOTCANCEL;
-
-			  __fxprintf (NULL, "%s", buf);
-
-			  ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-			  _IO_funlockfile (stderr);
-
-			  free (buf);
-			}
-#endif
-		    }
-
-		  d->__nextchar += strlen (d->__nextchar);
-
-		  d->optopt = pfound->val;
-		  return '?';
-		}
-	    }
-	  else if (pfound->has_arg == 1)
-	    {
-	      if (d->optind < argc)
-		d->optarg = argv[d->optind++];
-	      else
-		{
-		  if (print_errors)
-		    {
-#if defined _LIBC && defined USE_IN_LIBIO
-		      char *buf;
-
-		      if (__asprintf (&buf, _("\
-%s: option `%s' requires an argument\n"),
-				      argv[0], argv[d->optind - 1]) >= 0)
-			{
-			  _IO_flockfile (stderr);
-
-			  int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-			  ((_IO_FILE *) stderr)->_flags2
-			    |= _IO_FLAGS2_NOTCANCEL;
-
-			  __fxprintf (NULL, "%s", buf);
-
-			  ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-			  _IO_funlockfile (stderr);
-
-			  free (buf);
-			}
-#else
-		      fprintf (stderr,
-			       _("%s: option `%s' requires an argument\n"),
-			       argv[0], argv[d->optind - 1]);
-#endif
-		    }
-		  d->__nextchar += strlen (d->__nextchar);
-		  d->optopt = pfound->val;
-		  return optstring[0] == ':' ? ':' : '?';
-		}
-	    }
-	  d->__nextchar += strlen (d->__nextchar);
-	  if (longind != NULL)
-	    *longind = option_index;
-	  if (pfound->flag)
-	    {
-	      *(pfound->flag) = pfound->val;
-	      return 0;
-	    }
-	  return pfound->val;
-	}
-
-      /* Can't find it as a long option.  If this is not getopt_long_only,
-	 or the option starts with '--' or is not a valid short
-	 option, then it's an error.
-	 Otherwise interpret it as a short option.  */
-      if (!long_only || argv[d->optind][1] == '-'
-	  || strchr (optstring, *d->__nextchar) == NULL)
-	{
-	  if (print_errors)
-	    {
-#if defined _LIBC && defined USE_IN_LIBIO
-	      char *buf;
-	      int n;
-#endif
-
-	      if (argv[d->optind][1] == '-')
-		{
-		  /* --option */
-#if defined _LIBC && defined USE_IN_LIBIO
-		  n = __asprintf (&buf, _("%s: unrecognized option `--%s'\n"),
-				  argv[0], d->__nextchar);
-#else
-		  fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
-			   argv[0], d->__nextchar);
-#endif
-		}
-	      else
-		{
-		  /* +option or -option */
-#if defined _LIBC && defined USE_IN_LIBIO
-		  n = __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"),
-				  argv[0], argv[d->optind][0], d->__nextchar);
-#else
-		  fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
-			   argv[0], argv[d->optind][0], d->__nextchar);
-#endif
-		}
-
-#if defined _LIBC && defined USE_IN_LIBIO
-	      if (n >= 0)
-		{
-		  _IO_flockfile (stderr);
-
-		  int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-		  ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
-
-		  __fxprintf (NULL, "%s", buf);
-
-		  ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-		  _IO_funlockfile (stderr);
-
-		  free (buf);
-		}
-#endif
-	    }
-	  d->__nextchar = (char *) "";
-	  d->optind++;
-	  d->optopt = 0;
-	  return '?';
-	}
-    }
-
-  /* Look at and handle the next short option-character.  */
-
-  {
-    char c = *d->__nextchar++;
-    char *temp = strchr (optstring, c);
-
-    /* Increment `optind' when we start to process its last character.  */
-    if (*d->__nextchar == '\0')
-      ++d->optind;
-
-    if (temp == NULL || c == ':')
-      {
-	if (print_errors)
-	  {
-#if defined _LIBC && defined USE_IN_LIBIO
-	      char *buf;
-	      int n;
-#endif
-
-	    if (d->__posixly_correct)
-	      {
-		/* 1003.2 specifies the format of this message.  */
-#if defined _LIBC && defined USE_IN_LIBIO
-		n = __asprintf (&buf, _("%s: illegal option -- %c\n"),
-				argv[0], c);
-#else
-		fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c);
-#endif
-	      }
-	    else
-	      {
-#if defined _LIBC && defined USE_IN_LIBIO
-		n = __asprintf (&buf, _("%s: invalid option -- %c\n"),
-				argv[0], c);
-#else
-		fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c);
-#endif
-	      }
-
-#if defined _LIBC && defined USE_IN_LIBIO
-	    if (n >= 0)
-	      {
-		_IO_flockfile (stderr);
-
-		int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-		((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
-
-		__fxprintf (NULL, "%s", buf);
-
-		((_IO_FILE *) stderr)->_flags2 = old_flags2;
-		_IO_funlockfile (stderr);
-
-		free (buf);
-	      }
-#endif
-	  }
-	d->optopt = c;
-	return '?';
-      }
-    /* Convenience. Treat POSIX -W foo same as long option --foo */
-    if (temp[0] == 'W' && temp[1] == ';')
-      {
-	char *nameend;
-	const struct option *p;
-	const struct option *pfound = NULL;
-	int exact = 0;
-	int ambig = 0;
-	int indfound = 0;
-	int option_index;
-
-	/* This is an option that requires an argument.  */
-	if (*d->__nextchar != '\0')
-	  {
-	    d->optarg = d->__nextchar;
-	    /* If we end this ARGV-element by taking the rest as an arg,
-	       we must advance to the next element now.  */
-	    d->optind++;
-	  }
-	else if (d->optind == argc)
-	  {
-	    if (print_errors)
-	      {
-		/* 1003.2 specifies the format of this message.  */
-#if defined _LIBC && defined USE_IN_LIBIO
-		char *buf;
-
-		if (__asprintf (&buf,
-				_("%s: option requires an argument -- %c\n"),
-				argv[0], c) >= 0)
-		  {
-		    _IO_flockfile (stderr);
-
-		    int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-		    ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
-
-		    __fxprintf (NULL, "%s", buf);
-
-		    ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-		    _IO_funlockfile (stderr);
-
-		    free (buf);
-		  }
-#else
-		fprintf (stderr, _("%s: option requires an argument -- %c\n"),
-			 argv[0], c);
-#endif
-	      }
-	    d->optopt = c;
-	    if (optstring[0] == ':')
-	      c = ':';
-	    else
-	      c = '?';
-	    return c;
-	  }
-	else
-	  /* We already incremented `d->optind' once;
-	     increment it again when taking next ARGV-elt as argument.  */
-	  d->optarg = argv[d->optind++];
-
-	/* optarg is now the argument, see if it's in the
-	   table of longopts.  */
-
-	for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '=';
-	     nameend++)
-	  /* Do nothing.  */ ;
-
-	/* Test all long options for either exact match
-	   or abbreviated matches.  */
-	for (p = longopts, option_index = 0; p->name; p++, option_index++)
-	  if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
-	    {
-	      if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name))
-		{
-		  /* Exact match found.  */
-		  pfound = p;
-		  indfound = option_index;
-		  exact = 1;
-		  break;
-		}
-	      else if (pfound == NULL)
-		{
-		  /* First nonexact match found.  */
-		  pfound = p;
-		  indfound = option_index;
-		}
-	      else
-		/* Second or later nonexact match found.  */
-		ambig = 1;
-	    }
-	if (ambig && !exact)
-	  {
-	    if (print_errors)
-	      {
-#if defined _LIBC && defined USE_IN_LIBIO
-		char *buf;
-
-		if (__asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"),
-				argv[0], argv[d->optind]) >= 0)
-		  {
-		    _IO_flockfile (stderr);
-
-		    int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-		    ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
-
-		    __fxprintf (NULL, "%s", buf);
-
-		    ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-		    _IO_funlockfile (stderr);
-
-		    free (buf);
-		  }
-#else
-		fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
-			 argv[0], argv[d->optind]);
-#endif
-	      }
-	    d->__nextchar += strlen (d->__nextchar);
-	    d->optind++;
-	    return '?';
-	  }
-	if (pfound != NULL)
-	  {
-	    option_index = indfound;
-	    if (*nameend)
-	      {
-		/* Don't test has_arg with >, because some C compilers don't
-		   allow it to be used on enums.  */
-		if (pfound->has_arg)
-		  d->optarg = nameend + 1;
-		else
-		  {
-		    if (print_errors)
-		      {
-#if defined _LIBC && defined USE_IN_LIBIO
-			char *buf;
-
-			if (__asprintf (&buf, _("\
-%s: option `-W %s' doesn't allow an argument\n"),
-					argv[0], pfound->name) >= 0)
-			  {
-			    _IO_flockfile (stderr);
-
-			    int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-			    ((_IO_FILE *) stderr)->_flags2
-			      |= _IO_FLAGS2_NOTCANCEL;
-
-			    __fxprintf (NULL, "%s", buf);
-
-			    ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-			    _IO_funlockfile (stderr);
-
-			    free (buf);
-			  }
-#else
-			fprintf (stderr, _("\
-%s: option `-W %s' doesn't allow an argument\n"),
-				 argv[0], pfound->name);
-#endif
-		      }
-
-		    d->__nextchar += strlen (d->__nextchar);
-		    return '?';
-		  }
-	      }
-	    else if (pfound->has_arg == 1)
-	      {
-		if (d->optind < argc)
-		  d->optarg = argv[d->optind++];
-		else
-		  {
-		    if (print_errors)
-		      {
-#if defined _LIBC && defined USE_IN_LIBIO
-			char *buf;
-
-			if (__asprintf (&buf, _("\
-%s: option `%s' requires an argument\n"),
-					argv[0], argv[d->optind - 1]) >= 0)
-			  {
-			    _IO_flockfile (stderr);
-
-			    int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-			    ((_IO_FILE *) stderr)->_flags2
-			      |= _IO_FLAGS2_NOTCANCEL;
-
-			    __fxprintf (NULL, "%s", buf);
-
-			    ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-			    _IO_funlockfile (stderr);
-
-			    free (buf);
-			  }
-#else
-			fprintf (stderr,
-				 _("%s: option `%s' requires an argument\n"),
-				 argv[0], argv[d->optind - 1]);
-#endif
-		      }
-		    d->__nextchar += strlen (d->__nextchar);
-		    return optstring[0] == ':' ? ':' : '?';
-		  }
-	      }
-	    d->__nextchar += strlen (d->__nextchar);
-	    if (longind != NULL)
-	      *longind = option_index;
-	    if (pfound->flag)
-	      {
-		*(pfound->flag) = pfound->val;
-		return 0;
-	      }
-	    return pfound->val;
-	  }
-	  d->__nextchar = NULL;
-	  return 'W';	/* Let the application handle it.   */
-      }
-    if (temp[1] == ':')
-      {
-	if (temp[2] == ':')
-	  {
-	    /* This is an option that accepts an argument optionally.  */
-	    if (*d->__nextchar != '\0')
-	      {
-		d->optarg = d->__nextchar;
-		d->optind++;
-	      }
-	    else
-	      d->optarg = NULL;
-	    d->__nextchar = NULL;
-	  }
-	else
-	  {
-	    /* This is an option that requires an argument.  */
-	    if (*d->__nextchar != '\0')
-	      {
-		d->optarg = d->__nextchar;
-		/* If we end this ARGV-element by taking the rest as an arg,
-		   we must advance to the next element now.  */
-		d->optind++;
-	      }
-	    else if (d->optind == argc)
-	      {
-		if (print_errors)
-		  {
-		    /* 1003.2 specifies the format of this message.  */
-#if defined _LIBC && defined USE_IN_LIBIO
-		    char *buf;
-
-		    if (__asprintf (&buf, _("\
-%s: option requires an argument -- %c\n"),
-				    argv[0], c) >= 0)
-		      {
-			_IO_flockfile (stderr);
-
-			int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-			((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
-
-			__fxprintf (NULL, "%s", buf);
-
-			((_IO_FILE *) stderr)->_flags2 = old_flags2;
-			_IO_funlockfile (stderr);
-
-			free (buf);
-		      }
-#else
-		    fprintf (stderr,
-			     _("%s: option requires an argument -- %c\n"),
-			     argv[0], c);
-#endif
-		  }
-		d->optopt = c;
-		if (optstring[0] == ':')
-		  c = ':';
-		else
-		  c = '?';
-	      }
-	    else
-	      /* We already incremented `optind' once;
-		 increment it again when taking next ARGV-elt as argument.  */
-	      d->optarg = argv[d->optind++];
-	    d->__nextchar = NULL;
-	  }
-      }
-    return c;
-  }
-}
-
-int
-_getopt_internal (int argc, char **argv, const char *optstring,
-		  const struct option *longopts, int *longind,
-		  int long_only, int posixly_correct)
-{
-  int result;
-
-  getopt_data.optind = optind;
-  getopt_data.opterr = opterr;
-
-  result = _getopt_internal_r (argc, argv, optstring, longopts, longind,
-			       long_only, posixly_correct, &getopt_data);
-
-  optind = getopt_data.optind;
-  optarg = getopt_data.optarg;
-  optopt = getopt_data.optopt;
-
-  return result;
-}
-
-/* glibc gets a LSB-compliant getopt.
-   Standalone applications get a POSIX-compliant getopt.  */
-#if _LIBC
-enum { POSIXLY_CORRECT = 0 };
-#else
-enum { POSIXLY_CORRECT = 1 };
-#endif
-
-int
-getopt (int argc, char *const *argv, const char *optstring)
-{
-  return _getopt_internal (argc, (char **) argv, optstring, NULL, NULL, 0,
-			   POSIXLY_CORRECT);
-}
-
-
-#ifdef TEST
-
-/* Compile with -DTEST to make an executable for use in testing
-   the above definition of `getopt'.  */
-
-int
-main (int argc, char **argv)
-{
-  int c;
-  int digit_optind = 0;
-
-  while (1)
-    {
-      int this_option_optind = optind ? optind : 1;
-
-      c = getopt (argc, argv, "abc:d:0123456789");
-      if (c == -1)
-	break;
-
-      switch (c)
-	{
-	case '0':
-	case '1':
-	case '2':
-	case '3':
-	case '4':
-	case '5':
-	case '6':
-	case '7':
-	case '8':
-	case '9':
-	  if (digit_optind != 0 && digit_optind != this_option_optind)
-	    printf ("digits occur in two different argv-elements.\n");
-	  digit_optind = this_option_optind;
-	  printf ("option %c\n", c);
-	  break;
-
-	case 'a':
-	  printf ("option a\n");
-	  break;
-
-	case 'b':
-	  printf ("option b\n");
-	  break;
-
-	case 'c':
-	  printf ("option c with value `%s'\n", optarg);
-	  break;
-
-	case '?':
-	  break;
-
-	default:
-	  printf ("?? getopt returned character code 0%o ??\n", c);
-	}
-    }
-
-  if (optind < argc)
-    {
-      printf ("non-option ARGV-elements: ");
-      while (optind < argc)
-	printf ("%s ", argv[optind++]);
-      printf ("\n");
-    }
-
-  exit (0);
-}
-
-#endif /* TEST */
diff --git a/contrib/cpio/lib/getopt1.c b/contrib/cpio/lib/getopt1.c
deleted file mode 100644
index cc0746ea43c..00000000000
--- a/contrib/cpio/lib/getopt1.c
+++ /dev/null
@@ -1,171 +0,0 @@
-/* getopt_long and getopt_long_only entry points for GNU getopt.
-   Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98,2004,2006
-     Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifdef _LIBC
-# include 
-#else
-# include 
-# include "getopt.h"
-#endif
-#include "getopt_int.h"
-
-#include 
-
-/* This needs to come after some library #include
-   to get __GNU_LIBRARY__ defined.  */
-#ifdef __GNU_LIBRARY__
-#include 
-#endif
-
-#ifndef	NULL
-#define NULL 0
-#endif
-
-int
-getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
-	     const struct option *long_options, int *opt_index)
-{
-  return _getopt_internal (argc, (char **) argv, options, long_options,
-			   opt_index, 0, 0);
-}
-
-int
-_getopt_long_r (int argc, char **argv, const char *options,
-		const struct option *long_options, int *opt_index,
-		struct _getopt_data *d)
-{
-  return _getopt_internal_r (argc, argv, options, long_options, opt_index,
-			     0, 0, d);
-}
-
-/* Like getopt_long, but '-' as well as '--' can indicate a long option.
-   If an option that starts with '-' (not '--') doesn't match a long option,
-   but does match a short option, it is parsed as a short option
-   instead.  */
-
-int
-getopt_long_only (int argc, char *__getopt_argv_const *argv,
-		  const char *options,
-		  const struct option *long_options, int *opt_index)
-{
-  return _getopt_internal (argc, (char **) argv, options, long_options,
-			   opt_index, 1, 0);
-}
-
-int
-_getopt_long_only_r (int argc, char **argv, const char *options,
-		     const struct option *long_options, int *opt_index,
-		     struct _getopt_data *d)
-{
-  return _getopt_internal_r (argc, argv, options, long_options, opt_index,
-			     1, 0, d);
-}
-
-
-#ifdef TEST
-
-#include 
-
-int
-main (int argc, char **argv)
-{
-  int c;
-  int digit_optind = 0;
-
-  while (1)
-    {
-      int this_option_optind = optind ? optind : 1;
-      int option_index = 0;
-      static struct option long_options[] =
-      {
-	{"add", 1, 0, 0},
-	{"append", 0, 0, 0},
-	{"delete", 1, 0, 0},
-	{"verbose", 0, 0, 0},
-	{"create", 0, 0, 0},
-	{"file", 1, 0, 0},
-	{0, 0, 0, 0}
-      };
-
-      c = getopt_long (argc, argv, "abc:d:0123456789",
-		       long_options, &option_index);
-      if (c == -1)
-	break;
-
-      switch (c)
-	{
-	case 0:
-	  printf ("option %s", long_options[option_index].name);
-	  if (optarg)
-	    printf (" with arg %s", optarg);
-	  printf ("\n");
-	  break;
-
-	case '0':
-	case '1':
-	case '2':
-	case '3':
-	case '4':
-	case '5':
-	case '6':
-	case '7':
-	case '8':
-	case '9':
-	  if (digit_optind != 0 && digit_optind != this_option_optind)
-	    printf ("digits occur in two different argv-elements.\n");
-	  digit_optind = this_option_optind;
-	  printf ("option %c\n", c);
-	  break;
-
-	case 'a':
-	  printf ("option a\n");
-	  break;
-
-	case 'b':
-	  printf ("option b\n");
-	  break;
-
-	case 'c':
-	  printf ("option c with value `%s'\n", optarg);
-	  break;
-
-	case 'd':
-	  printf ("option d with value `%s'\n", optarg);
-	  break;
-
-	case '?':
-	  break;
-
-	default:
-	  printf ("?? getopt returned character code 0%o ??\n", c);
-	}
-    }
-
-  if (optind < argc)
-    {
-      printf ("non-option ARGV-elements: ");
-      while (optind < argc)
-	printf ("%s ", argv[optind++]);
-      printf ("\n");
-    }
-
-  exit (0);
-}
-
-#endif /* TEST */
diff --git a/contrib/cpio/lib/getopt_.h b/contrib/cpio/lib/getopt_.h
deleted file mode 100644
index 615ef9a3b6f..00000000000
--- a/contrib/cpio/lib/getopt_.h
+++ /dev/null
@@ -1,226 +0,0 @@
-/* Declarations for getopt.
-   Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005,2006,2007
-   Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef _GETOPT_H
-
-#ifndef __need_getopt
-# define _GETOPT_H 1
-#endif
-
-/* Standalone applications should #define __GETOPT_PREFIX to an
-   identifier that prefixes the external functions and variables
-   defined in this header.  When this happens, include the
-   headers that might declare getopt so that they will not cause
-   confusion if included after this file.  Then systematically rename
-   identifiers so that they do not collide with the system functions
-   and variables.  Renaming avoids problems with some compilers and
-   linkers.  */
-#if defined __GETOPT_PREFIX && !defined __need_getopt
-# include 
-# include 
-# include 
-# undef __need_getopt
-# undef getopt
-# undef getopt_long
-# undef getopt_long_only
-# undef optarg
-# undef opterr
-# undef optind
-# undef optopt
-# define __GETOPT_CONCAT(x, y) x ## y
-# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
-# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
-# define getopt __GETOPT_ID (getopt)
-# define getopt_long __GETOPT_ID (getopt_long)
-# define getopt_long_only __GETOPT_ID (getopt_long_only)
-# define optarg __GETOPT_ID (optarg)
-# define opterr __GETOPT_ID (opterr)
-# define optind __GETOPT_ID (optind)
-# define optopt __GETOPT_ID (optopt)
-#endif
-
-/* Standalone applications get correct prototypes for getopt_long and
-   getopt_long_only; they declare "char **argv".  libc uses prototypes
-   with "char *const *argv" that are incorrect because getopt_long and
-   getopt_long_only can permute argv; this is required for backward
-   compatibility (e.g., for LSB 2.0.1).
-
-   This used to be `#if defined __GETOPT_PREFIX && !defined __need_getopt',
-   but it caused redefinition warnings if both unistd.h and getopt.h were
-   included, since unistd.h includes getopt.h having previously defined
-   __need_getopt.
-
-   The only place where __getopt_argv_const is used is in definitions
-   of getopt_long and getopt_long_only below, but these are visible
-   only if __need_getopt is not defined, so it is quite safe to rewrite
-   the conditional as follows:
-*/
-#if !defined __need_getopt
-# if defined __GETOPT_PREFIX
-#  define __getopt_argv_const /* empty */
-# else
-#  define __getopt_argv_const const
-# endif
-#endif
-
-/* If __GNU_LIBRARY__ is not already defined, either we are being used
-   standalone, or this is the first header included in the source file.
-   If we are being used with glibc, we need to include , but
-   that does not exist if we are standalone.  So: if __GNU_LIBRARY__ is
-   not defined, include , which will pull in  for us
-   if it's from glibc.  (Why ctype.h?  It's guaranteed to exist and it
-   doesn't flood the namespace with stuff the way some other headers do.)  */
-#if !defined __GNU_LIBRARY__
-# include 
-#endif
-
-#ifndef __THROW
-# ifndef __GNUC_PREREQ
-#  define __GNUC_PREREQ(maj, min) (0)
-# endif
-# if defined __cplusplus && __GNUC_PREREQ (2,8)
-#  define __THROW	throw ()
-# else
-#  define __THROW
-# endif
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* For communication from `getopt' to the caller.
-   When `getopt' finds an option that takes an argument,
-   the argument value is returned here.
-   Also, when `ordering' is RETURN_IN_ORDER,
-   each non-option ARGV-element is returned here.  */
-
-extern char *optarg;
-
-/* Index in ARGV of the next element to be scanned.
-   This is used for communication to and from the caller
-   and for communication between successive calls to `getopt'.
-
-   On entry to `getopt', zero means this is the first call; initialize.
-
-   When `getopt' returns -1, this is the index of the first of the
-   non-option elements that the caller should itself scan.
-
-   Otherwise, `optind' communicates from one call to the next
-   how much of ARGV has been scanned so far.  */
-
-extern int optind;
-
-/* Callers store zero here to inhibit the error message `getopt' prints
-   for unrecognized options.  */
-
-extern int opterr;
-
-/* Set to an option character which was unrecognized.  */
-
-extern int optopt;
-
-#ifndef __need_getopt
-/* Describe the long-named options requested by the application.
-   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
-   of `struct option' terminated by an element containing a name which is
-   zero.
-
-   The field `has_arg' is:
-   no_argument		(or 0) if the option does not take an argument,
-   required_argument	(or 1) if the option requires an argument,
-   optional_argument	(or 2) if the option takes an optional argument.
-
-   If the field `flag' is not NULL, it points to a variable that is set
-   to the value given in the field `val' when the option is found, but
-   left unchanged if the option is not found.
-
-   To have a long-named option do something other than set an `int' to
-   a compiled-in constant, such as set a value from `optarg', set the
-   option's `flag' field to zero and its `val' field to a nonzero
-   value (the equivalent single-letter option character, if there is
-   one).  For long options that have a zero `flag' field, `getopt'
-   returns the contents of the `val' field.  */
-
-struct option
-{
-  const char *name;
-  /* has_arg can't be an enum because some compilers complain about
-     type mismatches in all the code that assumes it is an int.  */
-  int has_arg;
-  int *flag;
-  int val;
-};
-
-/* Names for the values of the `has_arg' field of `struct option'.  */
-
-# define no_argument		0
-# define required_argument	1
-# define optional_argument	2
-#endif	/* need getopt */
-
-
-/* Get definitions and prototypes for functions to process the
-   arguments in ARGV (ARGC of them, minus the program name) for
-   options given in OPTS.
-
-   Return the option character from OPTS just read.  Return -1 when
-   there are no more options.  For unrecognized options, or options
-   missing arguments, `optopt' is set to the option letter, and '?' is
-   returned.
-
-   The OPTS string is a list of characters which are recognized option
-   letters, optionally followed by colons, specifying that that letter
-   takes an argument, to be placed in `optarg'.
-
-   If a letter in OPTS is followed by two colons, its argument is
-   optional.  This behavior is specific to the GNU `getopt'.
-
-   The argument `--' causes premature termination of argument
-   scanning, explicitly telling `getopt' that there are no more
-   options.
-
-   If OPTS begins with `-', then non-option arguments are treated as
-   arguments to the option '\1'.  This behavior is specific to the GNU
-   `getopt'.  If OPTS begins with `+', or POSIXLY_CORRECT is set in
-   the environment, then do not permute arguments.  */
-
-extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
-       __THROW;
-
-#ifndef __need_getopt
-extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
-			const char *__shortopts,
-		        const struct option *__longopts, int *__longind)
-       __THROW;
-extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
-			     const char *__shortopts,
-		             const struct option *__longopts, int *__longind)
-       __THROW;
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-/* Make sure we later can get all the definitions and declarations.  */
-#undef __need_getopt
-
-#endif /* getopt.h */
diff --git a/contrib/cpio/lib/getopt_int.h b/contrib/cpio/lib/getopt_int.h
deleted file mode 100644
index 401579fd289..00000000000
--- a/contrib/cpio/lib/getopt_int.h
+++ /dev/null
@@ -1,131 +0,0 @@
-/* Internal declarations for getopt.
-   Copyright (C) 1989-1994,1996-1999,2001,2003,2004
-   Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef _GETOPT_INT_H
-#define _GETOPT_INT_H	1
-
-extern int _getopt_internal (int ___argc, char **___argv,
-			     const char *__shortopts,
-		             const struct option *__longopts, int *__longind,
-			     int __long_only, int __posixly_correct);
-
-
-/* Reentrant versions which can handle parsing multiple argument
-   vectors at the same time.  */
-
-/* Data type for reentrant functions.  */
-struct _getopt_data
-{
-  /* These have exactly the same meaning as the corresponding global
-     variables, except that they are used for the reentrant
-     versions of getopt.  */
-  int optind;
-  int opterr;
-  int optopt;
-  char *optarg;
-
-  /* Internal members.  */
-
-  /* True if the internal members have been initialized.  */
-  int __initialized;
-
-  /* The next char to be scanned in the option-element
-     in which the last option character we returned was found.
-     This allows us to pick up the scan where we left off.
-
-     If this is zero, or a null string, it means resume the scan
-     by advancing to the next ARGV-element.  */
-  char *__nextchar;
-
-  /* Describe how to deal with options that follow non-option ARGV-elements.
-
-     If the caller did not specify anything,
-     the default is REQUIRE_ORDER if the environment variable
-     POSIXLY_CORRECT is defined, PERMUTE otherwise.
-
-     REQUIRE_ORDER means don't recognize them as options;
-     stop option processing when the first non-option is seen.
-     This is what Unix does.
-     This mode of operation is selected by either setting the environment
-     variable POSIXLY_CORRECT, or using `+' as the first character
-     of the list of option characters, or by calling getopt.
-
-     PERMUTE is the default.  We permute the contents of ARGV as we
-     scan, so that eventually all the non-options are at the end.
-     This allows options to be given in any order, even with programs
-     that were not written to expect this.
-
-     RETURN_IN_ORDER is an option available to programs that were
-     written to expect options and other ARGV-elements in any order
-     and that care about the ordering of the two.  We describe each
-     non-option ARGV-element as if it were the argument of an option
-     with character code 1.  Using `-' as the first character of the
-     list of option characters selects this mode of operation.
-
-     The special argument `--' forces an end of option-scanning regardless
-     of the value of `ordering'.  In the case of RETURN_IN_ORDER, only
-     `--' can cause `getopt' to return -1 with `optind' != ARGC.  */
-
-  enum
-    {
-      REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
-    } __ordering;
-
-  /* If the POSIXLY_CORRECT environment variable is set
-     or getopt was called.  */
-  int __posixly_correct;
-
-
-  /* Handle permutation of arguments.  */
-
-  /* Describe the part of ARGV that contains non-options that have
-     been skipped.  `first_nonopt' is the index in ARGV of the first
-     of them; `last_nonopt' is the index after the last of them.  */
-
-  int __first_nonopt;
-  int __last_nonopt;
-
-#if defined _LIBC && defined USE_NONOPTION_FLAGS
-  int __nonoption_flags_max_len;
-  int __nonoption_flags_len;
-# endif
-};
-
-/* The initializer is necessary to set OPTIND and OPTERR to their
-   default values and to clear the initialization flag.  */
-#define _GETOPT_DATA_INITIALIZER	{ 1, 1 }
-
-extern int _getopt_internal_r (int ___argc, char **___argv,
-			       const char *__shortopts,
-			       const struct option *__longopts, int *__longind,
-			       int __long_only, int __posixly_correct,
-			       struct _getopt_data *__data);
-
-extern int _getopt_long_r (int ___argc, char **___argv,
-			   const char *__shortopts,
-			   const struct option *__longopts, int *__longind,
-			   struct _getopt_data *__data);
-
-extern int _getopt_long_only_r (int ___argc, char **___argv,
-				const char *__shortopts,
-				const struct option *__longopts,
-				int *__longind,
-				struct _getopt_data *__data);
-
-#endif /* getopt_int.h */
diff --git a/contrib/cpio/lib/gettext.h b/contrib/cpio/lib/gettext.h
deleted file mode 100644
index 9d76ec9afcc..00000000000
--- a/contrib/cpio/lib/gettext.h
+++ /dev/null
@@ -1,270 +0,0 @@
-/* Convenience header for conditional use of GNU .
-   Copyright (C) 1995-1998, 2000-2002, 2004-2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef _LIBGETTEXT_H
-#define _LIBGETTEXT_H 1
-
-/* NLS can be disabled through the configure --disable-nls option.  */
-#if ENABLE_NLS
-
-/* Get declarations of GNU message catalog functions.  */
-# include 
-
-/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
-   the gettext() and ngettext() macros.  This is an alternative to calling
-   textdomain(), and is useful for libraries.  */
-# ifdef DEFAULT_TEXT_DOMAIN
-#  undef gettext
-#  define gettext(Msgid) \
-     dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
-#  undef ngettext
-#  define ngettext(Msgid1, Msgid2, N) \
-     dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
-# endif
-
-#else
-
-/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
-   chokes if dcgettext is defined as a macro.  So include it now, to make
-   later inclusions of  a NOP.  We don't include 
-   as well because people using "gettext.h" will not include ,
-   and also including  would fail on SunOS 4, whereas 
-   is OK.  */
-#if defined(__sun)
-# include 
-#endif
-
-/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
-   , which chokes if dcgettext is defined as a macro.  So include
-   it now, to make later inclusions of  a NOP.  */
-#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
-# include 
-# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H
-#  include 
-# endif
-#endif
-
-/* Disabled NLS.
-   The casts to 'const char *' serve the purpose of producing warnings
-   for invalid uses of the value returned from these functions.
-   On pre-ANSI systems without 'const', the config.h file is supposed to
-   contain "#define const".  */
-# define gettext(Msgid) ((const char *) (Msgid))
-# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
-# define dcgettext(Domainname, Msgid, Category) \
-    ((void) (Category), dgettext (Domainname, Msgid))
-# define ngettext(Msgid1, Msgid2, N) \
-    ((N) == 1 \
-     ? ((void) (Msgid2), (const char *) (Msgid1)) \
-     : ((void) (Msgid1), (const char *) (Msgid2)))
-# define dngettext(Domainname, Msgid1, Msgid2, N) \
-    ((void) (Domainname), ngettext (Msgid1, Msgid2, N))
-# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
-    ((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N))
-# define textdomain(Domainname) ((const char *) (Domainname))
-# define bindtextdomain(Domainname, Dirname) \
-    ((void) (Domainname), (const char *) (Dirname))
-# define bind_textdomain_codeset(Domainname, Codeset) \
-    ((void) (Domainname), (const char *) (Codeset))
-
-#endif
-
-/* A pseudo function call that serves as a marker for the automated
-   extraction of messages, but does not call gettext().  The run-time
-   translation is done at a different place in the code.
-   The argument, String, should be a literal string.  Concatenated strings
-   and other string expressions won't work.
-   The macro's expansion is not parenthesized, so that it is suitable as
-   initializer for static 'char[]' or 'const char[]' variables.  */
-#define gettext_noop(String) String
-
-/* The separator between msgctxt and msgid in a .mo file.  */
-#define GETTEXT_CONTEXT_GLUE "\004"
-
-/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
-   MSGID.  MSGCTXT and MSGID must be string literals.  MSGCTXT should be
-   short and rarely need to change.
-   The letter 'p' stands for 'particular' or 'special'.  */
-#ifdef DEFAULT_TEXT_DOMAIN
-# define pgettext(Msgctxt, Msgid) \
-   pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
-#else
-# define pgettext(Msgctxt, Msgid) \
-   pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
-#endif
-#define dpgettext(Domainname, Msgctxt, Msgid) \
-  pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
-#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
-  pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
-#ifdef DEFAULT_TEXT_DOMAIN
-# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
-   npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
-#else
-# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
-   npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
-#endif
-#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
-  npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
-#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
-  npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
-
-#ifdef __GNUC__
-__inline
-#else
-#ifdef __cplusplus
-inline
-#endif
-#endif
-static const char *
-pgettext_aux (const char *domain,
-	      const char *msg_ctxt_id, const char *msgid,
-	      int category)
-{
-  const char *translation = dcgettext (domain, msg_ctxt_id, category);
-  if (translation == msg_ctxt_id)
-    return msgid;
-  else
-    return translation;
-}
-
-#ifdef __GNUC__
-__inline
-#else
-#ifdef __cplusplus
-inline
-#endif
-#endif
-static const char *
-npgettext_aux (const char *domain,
-	       const char *msg_ctxt_id, const char *msgid,
-	       const char *msgid_plural, unsigned long int n,
-	       int category)
-{
-  const char *translation =
-    dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
-  if (translation == msg_ctxt_id || translation == msgid_plural)
-    return (n == 1 ? msgid : msgid_plural);
-  else
-    return translation;
-}
-
-/* The same thing extended for non-constant arguments.  Here MSGCTXT and MSGID
-   can be arbitrary expressions.  But for string literals these macros are
-   less efficient than those above.  */
-
-#include 
-
-#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \
-  (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \
-   /* || __STDC_VERSION__ >= 199901L */ )
-
-#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
-#include 
-#endif
-
-#define pgettext_expr(Msgctxt, Msgid) \
-  dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
-#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
-  dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
-
-#ifdef __GNUC__
-__inline
-#else
-#ifdef __cplusplus
-inline
-#endif
-#endif
-static const char *
-dcpgettext_expr (const char *domain,
-		 const char *msgctxt, const char *msgid,
-		 int category)
-{
-  size_t msgctxt_len = strlen (msgctxt) + 1;
-  size_t msgid_len = strlen (msgid) + 1;
-  const char *translation;
-#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
-  char msg_ctxt_id[msgctxt_len + msgid_len];
-#else
-  char buf[1024];
-  char *msg_ctxt_id =
-    (msgctxt_len + msgid_len <= sizeof (buf)
-     ? buf
-     : (char *) malloc (msgctxt_len + msgid_len));
-  if (msg_ctxt_id != NULL)
-#endif
-    {
-      memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
-      msg_ctxt_id[msgctxt_len - 1] = '\004';
-      memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
-      translation = dcgettext (domain, msg_ctxt_id, category);
-#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
-      if (msg_ctxt_id != buf)
-	free (msg_ctxt_id);
-#endif
-      if (translation != msg_ctxt_id)
-	return translation;
-    }
-  return msgid;
-}
-
-#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
-  dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
-#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
-  dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
-
-#ifdef __GNUC__
-__inline
-#else
-#ifdef __cplusplus
-inline
-#endif
-#endif
-static const char *
-dcnpgettext_expr (const char *domain,
-		  const char *msgctxt, const char *msgid,
-		  const char *msgid_plural, unsigned long int n,
-		  int category)
-{
-  size_t msgctxt_len = strlen (msgctxt) + 1;
-  size_t msgid_len = strlen (msgid) + 1;
-  const char *translation;
-#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
-  char msg_ctxt_id[msgctxt_len + msgid_len];
-#else
-  char buf[1024];
-  char *msg_ctxt_id =
-    (msgctxt_len + msgid_len <= sizeof (buf)
-     ? buf
-     : (char *) malloc (msgctxt_len + msgid_len));
-  if (msg_ctxt_id != NULL)
-#endif
-    {
-      memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
-      msg_ctxt_id[msgctxt_len - 1] = '\004';
-      memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
-      translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
-#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
-      if (msg_ctxt_id != buf)
-	free (msg_ctxt_id);
-#endif
-      if (!(translation == msg_ctxt_id || translation == msgid_plural))
-	return translation;
-    }
-  return (n == 1 ? msgid : msgid_plural);
-}
-
-#endif /* _LIBGETTEXT_H */
diff --git a/contrib/cpio/lib/hash.c b/contrib/cpio/lib/hash.c
deleted file mode 100644
index f4ab12f487d..00000000000
--- a/contrib/cpio/lib/hash.c
+++ /dev/null
@@ -1,1048 +0,0 @@
-/* hash - hashing table processing.
-
-   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006 Free
-   Software Foundation, Inc.
-
-   Written by Jim Meyering, 1992.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* A generic hash table package.  */
-
-/* Define USE_OBSTACK to 1 if you want the allocator to use obstacks instead
-   of malloc.  If you change USE_OBSTACK, you have to recompile!  */
-
-#include 
-
-#include "hash.h"
-#include "xalloc.h"
-
-#include 
-#include 
-#include 
-
-#if USE_OBSTACK
-# include "obstack.h"
-# ifndef obstack_chunk_alloc
-#  define obstack_chunk_alloc malloc
-# endif
-# ifndef obstack_chunk_free
-#  define obstack_chunk_free free
-# endif
-#endif
-
-#ifndef SIZE_MAX
-# define SIZE_MAX ((size_t) -1)
-#endif
-
-struct hash_table
-  {
-    /* The array of buckets starts at BUCKET and extends to BUCKET_LIMIT-1,
-       for a possibility of N_BUCKETS.  Among those, N_BUCKETS_USED buckets
-       are not empty, there are N_ENTRIES active entries in the table.  */
-    struct hash_entry *bucket;
-    struct hash_entry const *bucket_limit;
-    size_t n_buckets;
-    size_t n_buckets_used;
-    size_t n_entries;
-
-    /* Tuning arguments, kept in a physicaly separate structure.  */
-    const Hash_tuning *tuning;
-
-    /* Three functions are given to `hash_initialize', see the documentation
-       block for this function.  In a word, HASHER randomizes a user entry
-       into a number up from 0 up to some maximum minus 1; COMPARATOR returns
-       true if two user entries compare equally; and DATA_FREER is the cleanup
-       function for a user entry.  */
-    Hash_hasher hasher;
-    Hash_comparator comparator;
-    Hash_data_freer data_freer;
-
-    /* A linked list of freed struct hash_entry structs.  */
-    struct hash_entry *free_entry_list;
-
-#if USE_OBSTACK
-    /* Whenever obstacks are used, it is possible to allocate all overflowed
-       entries into a single stack, so they all can be freed in a single
-       operation.  It is not clear if the speedup is worth the trouble.  */
-    struct obstack entry_stack;
-#endif
-  };
-
-/* A hash table contains many internal entries, each holding a pointer to
-   some user provided data (also called a user entry).  An entry indistinctly
-   refers to both the internal entry and its associated user entry.  A user
-   entry contents may be hashed by a randomization function (the hashing
-   function, or just `hasher' for short) into a number (or `slot') between 0
-   and the current table size.  At each slot position in the hash table,
-   starts a linked chain of entries for which the user data all hash to this
-   slot.  A bucket is the collection of all entries hashing to the same slot.
-
-   A good `hasher' function will distribute entries rather evenly in buckets.
-   In the ideal case, the length of each bucket is roughly the number of
-   entries divided by the table size.  Finding the slot for a data is usually
-   done in constant time by the `hasher', and the later finding of a precise
-   entry is linear in time with the size of the bucket.  Consequently, a
-   larger hash table size (that is, a larger number of buckets) is prone to
-   yielding shorter chains, *given* the `hasher' function behaves properly.
-
-   Long buckets slow down the lookup algorithm.  One might use big hash table
-   sizes in hope to reduce the average length of buckets, but this might
-   become inordinate, as unused slots in the hash table take some space.  The
-   best bet is to make sure you are using a good `hasher' function (beware
-   that those are not that easy to write! :-), and to use a table size
-   larger than the actual number of entries.  */
-
-/* If an insertion makes the ratio of nonempty buckets to table size larger
-   than the growth threshold (a number between 0.0 and 1.0), then increase
-   the table size by multiplying by the growth factor (a number greater than
-   1.0).  The growth threshold defaults to 0.8, and the growth factor
-   defaults to 1.414, meaning that the table will have doubled its size
-   every second time 80% of the buckets get used.  */
-#define DEFAULT_GROWTH_THRESHOLD 0.8
-#define DEFAULT_GROWTH_FACTOR 1.414
-
-/* If a deletion empties a bucket and causes the ratio of used buckets to
-   table size to become smaller than the shrink threshold (a number between
-   0.0 and 1.0), then shrink the table by multiplying by the shrink factor (a
-   number greater than the shrink threshold but smaller than 1.0).  The shrink
-   threshold and factor default to 0.0 and 1.0, meaning that the table never
-   shrinks.  */
-#define DEFAULT_SHRINK_THRESHOLD 0.0
-#define DEFAULT_SHRINK_FACTOR 1.0
-
-/* Use this to initialize or reset a TUNING structure to
-   some sensible values. */
-static const Hash_tuning default_tuning =
-  {
-    DEFAULT_SHRINK_THRESHOLD,
-    DEFAULT_SHRINK_FACTOR,
-    DEFAULT_GROWTH_THRESHOLD,
-    DEFAULT_GROWTH_FACTOR,
-    false
-  };
-
-/* Information and lookup.  */
-
-/* The following few functions provide information about the overall hash
-   table organization: the number of entries, number of buckets and maximum
-   length of buckets.  */
-
-/* Return the number of buckets in the hash table.  The table size, the total
-   number of buckets (used plus unused), or the maximum number of slots, are
-   the same quantity.  */
-
-size_t
-hash_get_n_buckets (const Hash_table *table)
-{
-  return table->n_buckets;
-}
-
-/* Return the number of slots in use (non-empty buckets).  */
-
-size_t
-hash_get_n_buckets_used (const Hash_table *table)
-{
-  return table->n_buckets_used;
-}
-
-/* Return the number of active entries.  */
-
-size_t
-hash_get_n_entries (const Hash_table *table)
-{
-  return table->n_entries;
-}
-
-/* Return the length of the longest chain (bucket).  */
-
-size_t
-hash_get_max_bucket_length (const Hash_table *table)
-{
-  struct hash_entry const *bucket;
-  size_t max_bucket_length = 0;
-
-  for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
-    {
-      if (bucket->data)
-	{
-	  struct hash_entry const *cursor = bucket;
-	  size_t bucket_length = 1;
-
-	  while (cursor = cursor->next, cursor)
-	    bucket_length++;
-
-	  if (bucket_length > max_bucket_length)
-	    max_bucket_length = bucket_length;
-	}
-    }
-
-  return max_bucket_length;
-}
-
-/* Do a mild validation of a hash table, by traversing it and checking two
-   statistics.  */
-
-bool
-hash_table_ok (const Hash_table *table)
-{
-  struct hash_entry const *bucket;
-  size_t n_buckets_used = 0;
-  size_t n_entries = 0;
-
-  for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
-    {
-      if (bucket->data)
-	{
-	  struct hash_entry const *cursor = bucket;
-
-	  /* Count bucket head.  */
-	  n_buckets_used++;
-	  n_entries++;
-
-	  /* Count bucket overflow.  */
-	  while (cursor = cursor->next, cursor)
-	    n_entries++;
-	}
-    }
-
-  if (n_buckets_used == table->n_buckets_used && n_entries == table->n_entries)
-    return true;
-
-  return false;
-}
-
-void
-hash_print_statistics (const Hash_table *table, FILE *stream)
-{
-  size_t n_entries = hash_get_n_entries (table);
-  size_t n_buckets = hash_get_n_buckets (table);
-  size_t n_buckets_used = hash_get_n_buckets_used (table);
-  size_t max_bucket_length = hash_get_max_bucket_length (table);
-
-  fprintf (stream, "# entries:         %lu\n", (unsigned long int) n_entries);
-  fprintf (stream, "# buckets:         %lu\n", (unsigned long int) n_buckets);
-  fprintf (stream, "# buckets used:    %lu (%.2f%%)\n",
-	   (unsigned long int) n_buckets_used,
-	   (100.0 * n_buckets_used) / n_buckets);
-  fprintf (stream, "max bucket length: %lu\n",
-	   (unsigned long int) max_bucket_length);
-}
-
-/* If ENTRY matches an entry already in the hash table, return the
-   entry from the table.  Otherwise, return NULL.  */
-
-void *
-hash_lookup (const Hash_table *table, const void *entry)
-{
-  struct hash_entry const *bucket
-    = table->bucket + table->hasher (entry, table->n_buckets);
-  struct hash_entry const *cursor;
-
-  if (! (bucket < table->bucket_limit))
-    abort ();
-
-  if (bucket->data == NULL)
-    return NULL;
-
-  for (cursor = bucket; cursor; cursor = cursor->next)
-    if (table->comparator (entry, cursor->data))
-      return cursor->data;
-
-  return NULL;
-}
-
-/* Walking.  */
-
-/* The functions in this page traverse the hash table and process the
-   contained entries.  For the traversal to work properly, the hash table
-   should not be resized nor modified while any particular entry is being
-   processed.  In particular, entries should not be added or removed.  */
-
-/* Return the first data in the table, or NULL if the table is empty.  */
-
-void *
-hash_get_first (const Hash_table *table)
-{
-  struct hash_entry const *bucket;
-
-  if (table->n_entries == 0)
-    return NULL;
-
-  for (bucket = table->bucket; ; bucket++)
-    if (! (bucket < table->bucket_limit))
-      abort ();
-    else if (bucket->data)
-      return bucket->data;
-}
-
-/* Return the user data for the entry following ENTRY, where ENTRY has been
-   returned by a previous call to either `hash_get_first' or `hash_get_next'.
-   Return NULL if there are no more entries.  */
-
-void *
-hash_get_next (const Hash_table *table, const void *entry)
-{
-  struct hash_entry const *bucket
-    = table->bucket + table->hasher (entry, table->n_buckets);
-  struct hash_entry const *cursor;
-
-  if (! (bucket < table->bucket_limit))
-    abort ();
-
-  /* Find next entry in the same bucket.  */
-  for (cursor = bucket; cursor; cursor = cursor->next)
-    if (cursor->data == entry && cursor->next)
-      return cursor->next->data;
-
-  /* Find first entry in any subsequent bucket.  */
-  while (++bucket < table->bucket_limit)
-    if (bucket->data)
-      return bucket->data;
-
-  /* None found.  */
-  return NULL;
-}
-
-/* Fill BUFFER with pointers to active user entries in the hash table, then
-   return the number of pointers copied.  Do not copy more than BUFFER_SIZE
-   pointers.  */
-
-size_t
-hash_get_entries (const Hash_table *table, void **buffer,
-		  size_t buffer_size)
-{
-  size_t counter = 0;
-  struct hash_entry const *bucket;
-  struct hash_entry const *cursor;
-
-  for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
-    {
-      if (bucket->data)
-	{
-	  for (cursor = bucket; cursor; cursor = cursor->next)
-	    {
-	      if (counter >= buffer_size)
-		return counter;
-	      buffer[counter++] = cursor->data;
-	    }
-	}
-    }
-
-  return counter;
-}
-
-/* Call a PROCESSOR function for each entry of a hash table, and return the
-   number of entries for which the processor function returned success.  A
-   pointer to some PROCESSOR_DATA which will be made available to each call to
-   the processor function.  The PROCESSOR accepts two arguments: the first is
-   the user entry being walked into, the second is the value of PROCESSOR_DATA
-   as received.  The walking continue for as long as the PROCESSOR function
-   returns nonzero.  When it returns zero, the walking is interrupted.  */
-
-size_t
-hash_do_for_each (const Hash_table *table, Hash_processor processor,
-		  void *processor_data)
-{
-  size_t counter = 0;
-  struct hash_entry const *bucket;
-  struct hash_entry const *cursor;
-
-  for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
-    {
-      if (bucket->data)
-	{
-	  for (cursor = bucket; cursor; cursor = cursor->next)
-	    {
-	      if (!(*processor) (cursor->data, processor_data))
-		return counter;
-	      counter++;
-	    }
-	}
-    }
-
-  return counter;
-}
-
-/* Allocation and clean-up.  */
-
-/* Return a hash index for a NUL-terminated STRING between 0 and N_BUCKETS-1.
-   This is a convenience routine for constructing other hashing functions.  */
-
-#if USE_DIFF_HASH
-
-/* About hashings, Paul Eggert writes to me (FP), on 1994-01-01: "Please see
-   B. J. McKenzie, R. Harries & T. Bell, Selecting a hashing algorithm,
-   Software--practice & experience 20, 2 (Feb 1990), 209-224.  Good hash
-   algorithms tend to be domain-specific, so what's good for [diffutils'] io.c
-   may not be good for your application."  */
-
-size_t
-hash_string (const char *string, size_t n_buckets)
-{
-# define ROTATE_LEFT(Value, Shift) \
-  ((Value) << (Shift) | (Value) >> ((sizeof (size_t) * CHAR_BIT) - (Shift)))
-# define HASH_ONE_CHAR(Value, Byte) \
-  ((Byte) + ROTATE_LEFT (Value, 7))
-
-  size_t value = 0;
-  unsigned char ch;
-
-  for (; (ch = *string); string++)
-    value = HASH_ONE_CHAR (value, ch);
-  return value % n_buckets;
-
-# undef ROTATE_LEFT
-# undef HASH_ONE_CHAR
-}
-
-#else /* not USE_DIFF_HASH */
-
-/* This one comes from `recode', and performs a bit better than the above as
-   per a few experiments.  It is inspired from a hashing routine found in the
-   very old Cyber `snoop', itself written in typical Greg Mansfield style.
-   (By the way, what happened to this excellent man?  Is he still alive?)  */
-
-size_t
-hash_string (const char *string, size_t n_buckets)
-{
-  size_t value = 0;
-  unsigned char ch;
-
-  for (; (ch = *string); string++)
-    value = (value * 31 + ch) % n_buckets;
-  return value;
-}
-
-#endif /* not USE_DIFF_HASH */
-
-/* Return true if CANDIDATE is a prime number.  CANDIDATE should be an odd
-   number at least equal to 11.  */
-
-static bool
-is_prime (size_t candidate)
-{
-  size_t divisor = 3;
-  size_t square = divisor * divisor;
-
-  while (square < candidate && (candidate % divisor))
-    {
-      divisor++;
-      square += 4 * divisor;
-      divisor++;
-    }
-
-  return (candidate % divisor ? true : false);
-}
-
-/* Round a given CANDIDATE number up to the nearest prime, and return that
-   prime.  Primes lower than 10 are merely skipped.  */
-
-static size_t
-next_prime (size_t candidate)
-{
-  /* Skip small primes.  */
-  if (candidate < 10)
-    candidate = 10;
-
-  /* Make it definitely odd.  */
-  candidate |= 1;
-
-  while (!is_prime (candidate))
-    candidate += 2;
-
-  return candidate;
-}
-
-void
-hash_reset_tuning (Hash_tuning *tuning)
-{
-  *tuning = default_tuning;
-}
-
-/* For the given hash TABLE, check the user supplied tuning structure for
-   reasonable values, and return true if there is no gross error with it.
-   Otherwise, definitively reset the TUNING field to some acceptable default
-   in the hash table (that is, the user loses the right of further modifying
-   tuning arguments), and return false.  */
-
-static bool
-check_tuning (Hash_table *table)
-{
-  const Hash_tuning *tuning = table->tuning;
-
-  /* Be a bit stricter than mathematics would require, so that
-     rounding errors in size calculations do not cause allocations to
-     fail to grow or shrink as they should.  The smallest allocation
-     is 11 (due to next_prime's algorithm), so an epsilon of 0.1
-     should be good enough.  */
-  float epsilon = 0.1f;
-
-  if (epsilon < tuning->growth_threshold
-      && tuning->growth_threshold < 1 - epsilon
-      && 1 + epsilon < tuning->growth_factor
-      && 0 <= tuning->shrink_threshold
-      && tuning->shrink_threshold + epsilon < tuning->shrink_factor
-      && tuning->shrink_factor <= 1
-      && tuning->shrink_threshold + epsilon < tuning->growth_threshold)
-    return true;
-
-  table->tuning = &default_tuning;
-  return false;
-}
-
-/* Allocate and return a new hash table, or NULL upon failure.  The initial
-   number of buckets is automatically selected so as to _guarantee_ that you
-   may insert at least CANDIDATE different user entries before any growth of
-   the hash table size occurs.  So, if have a reasonably tight a-priori upper
-   bound on the number of entries you intend to insert in the hash table, you
-   may save some table memory and insertion time, by specifying it here.  If
-   the IS_N_BUCKETS field of the TUNING structure is true, the CANDIDATE
-   argument has its meaning changed to the wanted number of buckets.
-
-   TUNING points to a structure of user-supplied values, in case some fine
-   tuning is wanted over the default behavior of the hasher.  If TUNING is
-   NULL, the default tuning parameters are used instead.
-
-   The user-supplied HASHER function should be provided.  It accepts two
-   arguments ENTRY and TABLE_SIZE.  It computes, by hashing ENTRY contents, a
-   slot number for that entry which should be in the range 0..TABLE_SIZE-1.
-   This slot number is then returned.
-
-   The user-supplied COMPARATOR function should be provided.  It accepts two
-   arguments pointing to user data, it then returns true for a pair of entries
-   that compare equal, or false otherwise.  This function is internally called
-   on entries which are already known to hash to the same bucket index.
-
-   The user-supplied DATA_FREER function, when not NULL, may be later called
-   with the user data as an argument, just before the entry containing the
-   data gets freed.  This happens from within `hash_free' or `hash_clear'.
-   You should specify this function only if you want these functions to free
-   all of your `data' data.  This is typically the case when your data is
-   simply an auxiliary struct that you have malloc'd to aggregate several
-   values.  */
-
-Hash_table *
-hash_initialize (size_t candidate, const Hash_tuning *tuning,
-		 Hash_hasher hasher, Hash_comparator comparator,
-		 Hash_data_freer data_freer)
-{
-  Hash_table *table;
-
-  if (hasher == NULL || comparator == NULL)
-    return NULL;
-
-  table = malloc (sizeof *table);
-  if (table == NULL)
-    return NULL;
-
-  if (!tuning)
-    tuning = &default_tuning;
-  table->tuning = tuning;
-  if (!check_tuning (table))
-    {
-      /* Fail if the tuning options are invalid.  This is the only occasion
-	 when the user gets some feedback about it.  Once the table is created,
-	 if the user provides invalid tuning options, we silently revert to
-	 using the defaults, and ignore further request to change the tuning
-	 options.  */
-      goto fail;
-    }
-
-  if (!tuning->is_n_buckets)
-    {
-      float new_candidate = candidate / tuning->growth_threshold;
-      if (SIZE_MAX <= new_candidate)
-	goto fail;
-      candidate = new_candidate;
-    }
-
-  if (xalloc_oversized (candidate, sizeof *table->bucket))
-    goto fail;
-  table->n_buckets = next_prime (candidate);
-  if (xalloc_oversized (table->n_buckets, sizeof *table->bucket))
-    goto fail;
-
-  table->bucket = calloc (table->n_buckets, sizeof *table->bucket);
-  table->bucket_limit = table->bucket + table->n_buckets;
-  table->n_buckets_used = 0;
-  table->n_entries = 0;
-
-  table->hasher = hasher;
-  table->comparator = comparator;
-  table->data_freer = data_freer;
-
-  table->free_entry_list = NULL;
-#if USE_OBSTACK
-  obstack_init (&table->entry_stack);
-#endif
-  return table;
-
- fail:
-  free (table);
-  return NULL;
-}
-
-/* Make all buckets empty, placing any chained entries on the free list.
-   Apply the user-specified function data_freer (if any) to the datas of any
-   affected entries.  */
-
-void
-hash_clear (Hash_table *table)
-{
-  struct hash_entry *bucket;
-
-  for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
-    {
-      if (bucket->data)
-	{
-	  struct hash_entry *cursor;
-	  struct hash_entry *next;
-
-	  /* Free the bucket overflow.  */
-	  for (cursor = bucket->next; cursor; cursor = next)
-	    {
-	      if (table->data_freer)
-		(*table->data_freer) (cursor->data);
-	      cursor->data = NULL;
-
-	      next = cursor->next;
-	      /* Relinking is done one entry at a time, as it is to be expected
-		 that overflows are either rare or short.  */
-	      cursor->next = table->free_entry_list;
-	      table->free_entry_list = cursor;
-	    }
-
-	  /* Free the bucket head.  */
-	  if (table->data_freer)
-	    (*table->data_freer) (bucket->data);
-	  bucket->data = NULL;
-	  bucket->next = NULL;
-	}
-    }
-
-  table->n_buckets_used = 0;
-  table->n_entries = 0;
-}
-
-/* Reclaim all storage associated with a hash table.  If a data_freer
-   function has been supplied by the user when the hash table was created,
-   this function applies it to the data of each entry before freeing that
-   entry.  */
-
-void
-hash_free (Hash_table *table)
-{
-  struct hash_entry *bucket;
-  struct hash_entry *cursor;
-  struct hash_entry *next;
-
-  /* Call the user data_freer function.  */
-  if (table->data_freer && table->n_entries)
-    {
-      for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
-	{
-	  if (bucket->data)
-	    {
-	      for (cursor = bucket; cursor; cursor = cursor->next)
-		{
-		  (*table->data_freer) (cursor->data);
-		}
-	    }
-	}
-    }
-
-#if USE_OBSTACK
-
-  obstack_free (&table->entry_stack, NULL);
-
-#else
-
-  /* Free all bucket overflowed entries.  */
-  for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
-    {
-      for (cursor = bucket->next; cursor; cursor = next)
-	{
-	  next = cursor->next;
-	  free (cursor);
-	}
-    }
-
-  /* Also reclaim the internal list of previously freed entries.  */
-  for (cursor = table->free_entry_list; cursor; cursor = next)
-    {
-      next = cursor->next;
-      free (cursor);
-    }
-
-#endif
-
-  /* Free the remainder of the hash table structure.  */
-  free (table->bucket);
-  free (table);
-}
-
-/* Insertion and deletion.  */
-
-/* Get a new hash entry for a bucket overflow, possibly by reclying a
-   previously freed one.  If this is not possible, allocate a new one.  */
-
-static struct hash_entry *
-allocate_entry (Hash_table *table)
-{
-  struct hash_entry *new;
-
-  if (table->free_entry_list)
-    {
-      new = table->free_entry_list;
-      table->free_entry_list = new->next;
-    }
-  else
-    {
-#if USE_OBSTACK
-      new = obstack_alloc (&table->entry_stack, sizeof *new);
-#else
-      new = malloc (sizeof *new);
-#endif
-    }
-
-  return new;
-}
-
-/* Free a hash entry which was part of some bucket overflow,
-   saving it for later recycling.  */
-
-static void
-free_entry (Hash_table *table, struct hash_entry *entry)
-{
-  entry->data = NULL;
-  entry->next = table->free_entry_list;
-  table->free_entry_list = entry;
-}
-
-/* This private function is used to help with insertion and deletion.  When
-   ENTRY matches an entry in the table, return a pointer to the corresponding
-   user data and set *BUCKET_HEAD to the head of the selected bucket.
-   Otherwise, return NULL.  When DELETE is true and ENTRY matches an entry in
-   the table, unlink the matching entry.  */
-
-static void *
-hash_find_entry (Hash_table *table, const void *entry,
-		 struct hash_entry **bucket_head, bool delete)
-{
-  struct hash_entry *bucket
-    = table->bucket + table->hasher (entry, table->n_buckets);
-  struct hash_entry *cursor;
-
-  if (! (bucket < table->bucket_limit))
-    abort ();
-
-  *bucket_head = bucket;
-
-  /* Test for empty bucket.  */
-  if (bucket->data == NULL)
-    return NULL;
-
-  /* See if the entry is the first in the bucket.  */
-  if ((*table->comparator) (entry, bucket->data))
-    {
-      void *data = bucket->data;
-
-      if (delete)
-	{
-	  if (bucket->next)
-	    {
-	      struct hash_entry *next = bucket->next;
-
-	      /* Bump the first overflow entry into the bucket head, then save
-		 the previous first overflow entry for later recycling.  */
-	      *bucket = *next;
-	      free_entry (table, next);
-	    }
-	  else
-	    {
-	      bucket->data = NULL;
-	    }
-	}
-
-      return data;
-    }
-
-  /* Scan the bucket overflow.  */
-  for (cursor = bucket; cursor->next; cursor = cursor->next)
-    {
-      if ((*table->comparator) (entry, cursor->next->data))
-	{
-	  void *data = cursor->next->data;
-
-	  if (delete)
-	    {
-	      struct hash_entry *next = cursor->next;
-
-	      /* Unlink the entry to delete, then save the freed entry for later
-		 recycling.  */
-	      cursor->next = next->next;
-	      free_entry (table, next);
-	    }
-
-	  return data;
-	}
-    }
-
-  /* No entry found.  */
-  return NULL;
-}
-
-/* For an already existing hash table, change the number of buckets through
-   specifying CANDIDATE.  The contents of the hash table are preserved.  The
-   new number of buckets is automatically selected so as to _guarantee_ that
-   the table may receive at least CANDIDATE different user entries, including
-   those already in the table, before any other growth of the hash table size
-   occurs.  If TUNING->IS_N_BUCKETS is true, then CANDIDATE specifies the
-   exact number of buckets desired.  */
-
-bool
-hash_rehash (Hash_table *table, size_t candidate)
-{
-  Hash_table *new_table;
-  struct hash_entry *bucket;
-  struct hash_entry *cursor;
-  struct hash_entry *next;
-
-  new_table = hash_initialize (candidate, table->tuning, table->hasher,
-			       table->comparator, table->data_freer);
-  if (new_table == NULL)
-    return false;
-
-  /* Merely reuse the extra old space into the new table.  */
-#if USE_OBSTACK
-  obstack_free (&new_table->entry_stack, NULL);
-  new_table->entry_stack = table->entry_stack;
-#endif
-  new_table->free_entry_list = table->free_entry_list;
-
-  for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
-    if (bucket->data)
-      for (cursor = bucket; cursor; cursor = next)
-	{
-	  void *data = cursor->data;
-	  struct hash_entry *new_bucket
-	    = (new_table->bucket
-	       + new_table->hasher (data, new_table->n_buckets));
-
-	  if (! (new_bucket < new_table->bucket_limit))
-	    abort ();
-
-	  next = cursor->next;
-
-	  if (new_bucket->data)
-	    {
-	      if (cursor == bucket)
-		{
-		  /* Allocate or recycle an entry, when moving from a bucket
-		     header into a bucket overflow.  */
-		  struct hash_entry *new_entry = allocate_entry (new_table);
-
-		  if (new_entry == NULL)
-		    return false;
-
-		  new_entry->data = data;
-		  new_entry->next = new_bucket->next;
-		  new_bucket->next = new_entry;
-		}
-	      else
-		{
-		  /* Merely relink an existing entry, when moving from a
-		     bucket overflow into a bucket overflow.  */
-		  cursor->next = new_bucket->next;
-		  new_bucket->next = cursor;
-		}
-	    }
-	  else
-	    {
-	      /* Free an existing entry, when moving from a bucket
-		 overflow into a bucket header.  Also take care of the
-		 simple case of moving from a bucket header into a bucket
-		 header.  */
-	      new_bucket->data = data;
-	      new_table->n_buckets_used++;
-	      if (cursor != bucket)
-		free_entry (new_table, cursor);
-	    }
-	}
-
-  free (table->bucket);
-  table->bucket = new_table->bucket;
-  table->bucket_limit = new_table->bucket_limit;
-  table->n_buckets = new_table->n_buckets;
-  table->n_buckets_used = new_table->n_buckets_used;
-  table->free_entry_list = new_table->free_entry_list;
-  /* table->n_entries already holds its value.  */
-#if USE_OBSTACK
-  table->entry_stack = new_table->entry_stack;
-#endif
-  free (new_table);
-
-  return true;
-}
-
-/* If ENTRY matches an entry already in the hash table, return the pointer
-   to the entry from the table.  Otherwise, insert ENTRY and return ENTRY.
-   Return NULL if the storage required for insertion cannot be allocated.  */
-
-void *
-hash_insert (Hash_table *table, const void *entry)
-{
-  void *data;
-  struct hash_entry *bucket;
-
-  /* The caller cannot insert a NULL entry.  */
-  if (! entry)
-    abort ();
-
-  /* If there's a matching entry already in the table, return that.  */
-  if ((data = hash_find_entry (table, entry, &bucket, false)) != NULL)
-    return data;
-
-  /* ENTRY is not matched, it should be inserted.  */
-
-  if (bucket->data)
-    {
-      struct hash_entry *new_entry = allocate_entry (table);
-
-      if (new_entry == NULL)
-	return NULL;
-
-      /* Add ENTRY in the overflow of the bucket.  */
-
-      new_entry->data = (void *) entry;
-      new_entry->next = bucket->next;
-      bucket->next = new_entry;
-      table->n_entries++;
-      return (void *) entry;
-    }
-
-  /* Add ENTRY right in the bucket head.  */
-
-  bucket->data = (void *) entry;
-  table->n_entries++;
-  table->n_buckets_used++;
-
-  /* If the growth threshold of the buckets in use has been reached, increase
-     the table size and rehash.  There's no point in checking the number of
-     entries:  if the hashing function is ill-conditioned, rehashing is not
-     likely to improve it.  */
-
-  if (table->n_buckets_used
-      > table->tuning->growth_threshold * table->n_buckets)
-    {
-      /* Check more fully, before starting real work.  If tuning arguments
-	 became invalid, the second check will rely on proper defaults.  */
-      check_tuning (table);
-      if (table->n_buckets_used
-	  > table->tuning->growth_threshold * table->n_buckets)
-	{
-	  const Hash_tuning *tuning = table->tuning;
-	  float candidate =
-	    (tuning->is_n_buckets
-	     ? (table->n_buckets * tuning->growth_factor)
-	     : (table->n_buckets * tuning->growth_factor
-		* tuning->growth_threshold));
-
-	  if (SIZE_MAX <= candidate)
-	    return NULL;
-
-	  /* If the rehash fails, arrange to return NULL.  */
-	  if (!hash_rehash (table, candidate))
-	    entry = NULL;
-	}
-    }
-
-  return (void *) entry;
-}
-
-/* If ENTRY is already in the table, remove it and return the just-deleted
-   data (the user may want to deallocate its storage).  If ENTRY is not in the
-   table, don't modify the table and return NULL.  */
-
-void *
-hash_delete (Hash_table *table, const void *entry)
-{
-  void *data;
-  struct hash_entry *bucket;
-
-  data = hash_find_entry (table, entry, &bucket, true);
-  if (!data)
-    return NULL;
-
-  table->n_entries--;
-  if (!bucket->data)
-    {
-      table->n_buckets_used--;
-
-      /* If the shrink threshold of the buckets in use has been reached,
-	 rehash into a smaller table.  */
-
-      if (table->n_buckets_used
-	  < table->tuning->shrink_threshold * table->n_buckets)
-	{
-	  /* Check more fully, before starting real work.  If tuning arguments
-	     became invalid, the second check will rely on proper defaults.  */
-	  check_tuning (table);
-	  if (table->n_buckets_used
-	      < table->tuning->shrink_threshold * table->n_buckets)
-	    {
-	      const Hash_tuning *tuning = table->tuning;
-	      size_t candidate =
-		(tuning->is_n_buckets
-		 ? table->n_buckets * tuning->shrink_factor
-		 : (table->n_buckets * tuning->shrink_factor
-		    * tuning->growth_threshold));
-
-	      hash_rehash (table, candidate);
-	    }
-	}
-    }
-
-  return data;
-}
-
-/* Testing.  */
-
-#if TESTING
-
-void
-hash_print (const Hash_table *table)
-{
-  struct hash_entry const *bucket;
-
-  for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
-    {
-      struct hash_entry *cursor;
-
-      if (bucket)
-	printf ("%lu:\n", (unsigned long int) (bucket - table->bucket));
-
-      for (cursor = bucket; cursor; cursor = cursor->next)
-	{
-	  char const *s = cursor->data;
-	  /* FIXME */
-	  if (s)
-	    printf ("  %s\n", s);
-	}
-    }
-}
-
-#endif /* TESTING */
diff --git a/contrib/cpio/lib/hash.h b/contrib/cpio/lib/hash.h
deleted file mode 100644
index ab63a863fd0..00000000000
--- a/contrib/cpio/lib/hash.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/* hash - hashing table processing.
-   Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc.
-   Written by Jim Meyering , 1998.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* A generic hash table package.  */
-
-/* Make sure USE_OBSTACK is defined to 1 if you want the allocator to use
-   obstacks instead of malloc, and recompile `hash.c' with same setting.  */
-
-#ifndef HASH_H_
-# define HASH_H_
-
-# include 
-# include 
-
-typedef size_t (*Hash_hasher) (const void *, size_t);
-typedef bool (*Hash_comparator) (const void *, const void *);
-typedef void (*Hash_data_freer) (void *);
-typedef bool (*Hash_processor) (void *, void *);
-
-struct hash_entry
-  {
-    void *data;
-    struct hash_entry *next;
-  };
-
-struct hash_tuning
-  {
-    /* This structure is mainly used for `hash_initialize', see the block
-       documentation of `hash_reset_tuning' for more complete comments.  */
-
-    float shrink_threshold;	/* ratio of used buckets to trigger a shrink */
-    float shrink_factor;	/* ratio of new smaller size to original size */
-    float growth_threshold;	/* ratio of used buckets to trigger a growth */
-    float growth_factor;	/* ratio of new bigger size to original size */
-    bool is_n_buckets;		/* if CANDIDATE really means table size */
-  };
-
-typedef struct hash_tuning Hash_tuning;
-
-struct hash_table;
-
-typedef struct hash_table Hash_table;
-
-/* Information and lookup.  */
-size_t hash_get_n_buckets (const Hash_table *);
-size_t hash_get_n_buckets_used (const Hash_table *);
-size_t hash_get_n_entries (const Hash_table *);
-size_t hash_get_max_bucket_length (const Hash_table *);
-bool hash_table_ok (const Hash_table *);
-void hash_print_statistics (const Hash_table *, FILE *);
-void *hash_lookup (const Hash_table *, const void *);
-
-/* Walking.  */
-void *hash_get_first (const Hash_table *);
-void *hash_get_next (const Hash_table *, const void *);
-size_t hash_get_entries (const Hash_table *, void **, size_t);
-size_t hash_do_for_each (const Hash_table *, Hash_processor, void *);
-
-/* Allocation and clean-up.  */
-size_t hash_string (const char *, size_t);
-void hash_reset_tuning (Hash_tuning *);
-Hash_table *hash_initialize (size_t, const Hash_tuning *,
-			     Hash_hasher, Hash_comparator,
-			     Hash_data_freer);
-void hash_clear (Hash_table *);
-void hash_free (Hash_table *);
-
-/* Insertion and deletion.  */
-bool hash_rehash (Hash_table *, size_t);
-void *hash_insert (Hash_table *, const void *);
-void *hash_delete (Hash_table *, const void *);
-
-#endif
diff --git a/contrib/cpio/lib/intprops.h b/contrib/cpio/lib/intprops.h
deleted file mode 100644
index 34f971cbaad..00000000000
--- a/contrib/cpio/lib/intprops.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/* intprops.h -- properties of integer types
-
-   Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Paul Eggert.  */
-
-#include 
-
-/* The extra casts in the following macros work around compiler bugs,
-   e.g., in Cray C 5.0.3.0.  */
-
-/* True if the arithmetic type T is an integer type.  bool counts as
-   an integer.  */
-#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
-
-/* True if negative values of the signed integer type T use two's
-   complement, ones' complement, or signed magnitude representation,
-   respectively.  Much GNU code assumes two's complement, but some
-   people like to be portable to all possible C hosts.  */
-#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
-#define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
-#define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
-
-/* True if the arithmetic type T is signed.  */
-#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
-
-/* The maximum and minimum values for the integer type T.  These
-   macros have undefined behavior if T is signed and has padding bits.
-   If this is a problem for you, please let us know how to fix it for
-   your host.  */
-#define TYPE_MINIMUM(t) \
-  ((t) (! TYPE_SIGNED (t) \
-	? (t) 0 \
-	: TYPE_SIGNED_MAGNITUDE (t) \
-	? ~ (t) 0 \
-	: ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))
-#define TYPE_MAXIMUM(t) \
-  ((t) (! TYPE_SIGNED (t) \
-	? (t) -1 \
-	: ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
-
-/* Return zero if T can be determined to be an unsigned type.
-   Otherwise, return 1.
-   When compiling with GCC, INT_STRLEN_BOUND uses this macro to obtain a
-   tighter bound.  Otherwise, it overestimates the true bound by one byte
-   when applied to unsigned types of size 2, 4, 16, ... bytes.
-   The symbol signed_type_or_expr__ is private to this header file.  */
-#if __GNUC__ >= 2
-# define signed_type_or_expr__(t) TYPE_SIGNED (__typeof__ (t))
-#else
-# define signed_type_or_expr__(t) 1
-#endif
-
-/* Bound on length of the string representing an integer type or expression T.
-   Subtract 1 for the sign bit if T is signed; log10 (2.0) < 146/485;
-   add 1 for integer division truncation; add 1 more for a minus sign
-   if needed.  */
-#define INT_STRLEN_BOUND(t) \
-  ((sizeof (t) * CHAR_BIT - signed_type_or_expr__ (t)) * 146 / 485 \
-   + signed_type_or_expr__ (t) + 1)
-
-/* Bound on buffer size needed to represent an integer type or expression T,
-   including the terminating null.  */
-#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
diff --git a/contrib/cpio/lib/inttostr.c b/contrib/cpio/lib/inttostr.c
deleted file mode 100644
index 246d6583507..00000000000
--- a/contrib/cpio/lib/inttostr.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/* inttostr.c -- convert integers to printable strings
-
-   Copyright (C) 2001, 2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Paul Eggert */
-
-#include 
-
-#include "inttostr.h"
-
-/* Convert I to a printable string in BUF, which must be at least
-   INT_BUFSIZE_BOUND (INTTYPE) bytes long.  Return the address of the
-   printable string, which need not start at BUF.  */
-
-char *
-inttostr (inttype i, char *buf)
-{
-  char *p = buf + INT_STRLEN_BOUND (inttype);
-  *p = 0;
-
-  if (i < 0)
-    {
-      do
-	*--p = '0' - i % 10;
-      while ((i /= 10) != 0);
-
-      *--p = '-';
-    }
-  else
-    {
-      do
-	*--p = '0' + i % 10;
-      while ((i /= 10) != 0);
-    }
-
-  return p;
-}
diff --git a/contrib/cpio/lib/inttostr.h b/contrib/cpio/lib/inttostr.h
deleted file mode 100644
index 31258cad35b..00000000000
--- a/contrib/cpio/lib/inttostr.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* inttostr.h -- convert integers to printable strings
-
-   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software
-   Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Paul Eggert */
-
-#include 
-#include 
-
-#include "intprops.h"
-
-char *offtostr (off_t, char *);
-char *imaxtostr (intmax_t, char *);
-char *umaxtostr (uintmax_t, char *);
-char *uinttostr (unsigned int, char *);
diff --git a/contrib/cpio/lib/mempcpy.c b/contrib/cpio/lib/mempcpy.c
deleted file mode 100644
index 1c702c7f4cb..00000000000
--- a/contrib/cpio/lib/mempcpy.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* Copy memory area and return pointer after last written byte.
-   Copyright (C) 2003, 2007 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-/* Specification.  */
-#include 
-
-/* Copy N bytes of SRC to DEST, return pointer to bytes after the
-   last written byte.  */
-void *
-mempcpy (void *dest, const void *src, size_t n)
-{
-  return (char *) memcpy (dest, src, n) + n;
-}
diff --git a/contrib/cpio/lib/paxerror.c b/contrib/cpio/lib/paxerror.c
deleted file mode 100644
index 000d9e44981..00000000000
--- a/contrib/cpio/lib/paxerror.c
+++ /dev/null
@@ -1,365 +0,0 @@
-/* Miscellaneous error functions
-
-   Copyright (C) 2005 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU General Public License as published by the
-   Free Software Foundation; either version 2, or (at your option) any later
-   version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
-   Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation, Inc.,
-   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-#include 
-#include 
-#include 
-
-/* Decode MODE from its binary form in a stat structure, and encode it
-   into a 9-byte string STRING, terminated with a NUL.  */
-
-void
-pax_decode_mode (mode_t mode, char *string)
-{
-  *string++ = mode & S_IRUSR ? 'r' : '-';
-  *string++ = mode & S_IWUSR ? 'w' : '-';
-  *string++ = (mode & S_ISUID
-	       ? (mode & S_IXUSR ? 's' : 'S')
-	       : (mode & S_IXUSR ? 'x' : '-'));
-  *string++ = mode & S_IRGRP ? 'r' : '-';
-  *string++ = mode & S_IWGRP ? 'w' : '-';
-  *string++ = (mode & S_ISGID
-	       ? (mode & S_IXGRP ? 's' : 'S')
-	       : (mode & S_IXGRP ? 'x' : '-'));
-  *string++ = mode & S_IROTH ? 'r' : '-';
-  *string++ = mode & S_IWOTH ? 'w' : '-';
-  *string++ = (mode & S_ISVTX
-	       ? (mode & S_IXOTH ? 't' : 'T')
-	       : (mode & S_IXOTH ? 'x' : '-'));
-  *string = '\0';
-}
-
-/* Report an error associated with the system call CALL and the
-   optional name NAME.  */
-void
-call_arg_error (char const *call, char const *name)
-{
-  int e = errno;
-  /* TRANSLATORS: %s after `Cannot' is a function name, e.g. `Cannot open'.
-     Directly translating this to another language will not work, first because
-     %s itself is not translated.
-     Translate it as `%s: Function %s failed'. */
-  ERROR ((0, e, _("%s: Cannot %s"), quotearg_colon (name), call));
-}
-
-/* Report a fatal error associated with the system call CALL and
-   the optional file name NAME.  */
-void
-call_arg_fatal (char const *call, char const *name)
-{
-  int e = errno;
-  /* TRANSLATORS: %s after `Cannot' is a function name, e.g. `Cannot open'.
-     Directly translating this to another language will not work, first because
-     %s itself is not translated.
-     Translate it as `%s: Function %s failed'. */
-  FATAL_ERROR ((0, e, _("%s: Cannot %s"), quotearg_colon (name),  call));
-}
-
-/* Report a warning associated with the system call CALL and
-   the optional file name NAME.  */
-void
-call_arg_warn (char const *call, char const *name)
-{
-  int e = errno;
-  /* TRANSLATORS: %s after `Cannot' is a function name, e.g. `Cannot open'.
-     Directly translating this to another language will not work, first because
-     %s itself is not translated.
-     Translate it as `%s: Function %s failed'. */
-  WARN ((0, e, _("%s: Warning: Cannot %s"), quotearg_colon (name), call));
-}
-
-void
-chmod_error_details (char const *name, mode_t mode)
-{
-  int e = errno;
-  char buf[10];
-  pax_decode_mode (mode, buf);
-  ERROR ((0, e, _("%s: Cannot change mode to %s"),
-	  quotearg_colon (name), buf));
-}
-
-void
-chown_error_details (char const *name, uid_t uid, gid_t gid)
-{
-  int e = errno;
-  ERROR ((0, e, _("%s: Cannot change ownership to uid %lu, gid %lu"),
-	  quotearg_colon (name), (unsigned long) uid, (unsigned long) gid));
-}
-
-void
-close_error (char const *name)
-{
-  call_arg_error ("close", name);
-}
-
-void
-close_warn (char const *name)
-{
-  call_arg_warn ("close", name);
-}
-
-void
-exec_fatal (char const *name)
-{
-  call_arg_fatal ("exec", name);
-}
-
-void
-link_error (char const *target, char const *source)
-{
-  int e = errno;
-  ERROR ((0, e, _("%s: Cannot hard link to %s"),
-	  quotearg_colon (source), quote_n (1, target)));
-}
-
-void
-mkdir_error (char const *name)
-{
-  call_arg_error ("mkdir", name);
-}
-
-void
-mkfifo_error (char const *name)
-{
-  call_arg_error ("mkfifo", name);
-}
-
-void
-mknod_error (char const *name)
-{
-  call_arg_error ("mknod", name);
-}
-
-void
-open_error (char const *name)
-{
-  call_arg_error ("open", name);
-}
-
-void
-open_fatal (char const *name)
-{
-  call_arg_fatal ("open", name);
-}
-
-void
-open_warn (char const *name)
-{
-  call_arg_warn ("open", name);
-}
-
-void
-read_error (char const *name)
-{
-  call_arg_error ("read", name);
-}
-
-void
-read_error_details (char const *name, off_t offset, size_t size)
-{
-  char buf[UINTMAX_STRSIZE_BOUND];
-  int e = errno;
-  ERROR ((0, e,
-	  ngettext ("%s: Read error at byte %s, while reading %lu byte",
-		    "%s: Read error at byte %s, while reading %lu bytes",
-		    size),
-	  quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
-	  (unsigned long) size));
-}
-
-void
-read_warn_details (char const *name, off_t offset, size_t size)
-{
-  char buf[UINTMAX_STRSIZE_BOUND];
-  int e = errno;
-  WARN ((0, e,
-	 ngettext ("%s: Warning: Read error at byte %s, while reading %lu byte",
-		   "%s: Warning: Read error at byte %s, while reading %lu bytes",
-		   size),
-	 quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
-	 (unsigned long) size));
-}
-
-void
-read_fatal (char const *name)
-{
-  call_arg_fatal ("read", name);
-}
-
-void
-read_fatal_details (char const *name, off_t offset, size_t size)
-{
-  char buf[UINTMAX_STRSIZE_BOUND];
-  int e = errno;
-  FATAL_ERROR ((0, e,
-		ngettext ("%s: Read error at byte %s, while reading %lu byte",
-			  "%s: Read error at byte %s, while reading %lu bytes",
-			  size),
-		quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
-		(unsigned long) size));
-}
-
-void
-readlink_error (char const *name)
-{
-  call_arg_error ("readlink", name);
-}
-
-void
-readlink_warn (char const *name)
-{
-  call_arg_warn ("readlink", name);
-}
-
-void
-rmdir_error (char const *name)
-{
-  call_arg_error ("rmdir", name);
-}
-
-void
-savedir_error (char const *name)
-{
-  call_arg_error ("savedir", name);
-}
-
-void
-savedir_warn (char const *name)
-{
-  call_arg_warn ("savedir", name);
-}
-
-void
-seek_error (char const *name)
-{
-  call_arg_error ("seek", name);
-}
-
-void
-seek_error_details (char const *name, off_t offset)
-{
-  char buf[UINTMAX_STRSIZE_BOUND];
-  int e = errno;
-  ERROR ((0, e, _("%s: Cannot seek to %s"),
-	  quotearg_colon (name),
-	  STRINGIFY_BIGINT (offset, buf)));
-}
-
-void
-seek_warn (char const *name)
-{
-  call_arg_warn ("seek", name);
-}
-
-void
-seek_warn_details (char const *name, off_t offset)
-{
-  char buf[UINTMAX_STRSIZE_BOUND];
-  int e = errno;
-  WARN ((0, e, _("%s: Warning: Cannot seek to %s"),
-	 quotearg_colon (name),
-	 STRINGIFY_BIGINT (offset, buf)));
-}
-
-void
-symlink_error (char const *contents, char const *name)
-{
-  int e = errno;
-  ERROR ((0, e, _("%s: Cannot create symlink to %s"),
-	  quotearg_colon (name), quote_n (1, contents)));
-}
-
-void
-stat_fatal (char const *name)
-{
-  call_arg_fatal ("stat", name);
-}
-
-void
-stat_error (char const *name)
-{
-  call_arg_error ("stat", name);
-}
-
-void
-stat_warn (char const *name)
-{
-  call_arg_warn ("stat", name);
-}
-
-void
-truncate_error (char const *name)
-{
-  call_arg_error ("truncate", name);
-}
-
-void
-truncate_warn (char const *name)
-{
-  call_arg_warn ("truncate", name);
-}
-
-void
-unlink_error (char const *name)
-{
-  call_arg_error ("unlink", name);
-}
-
-void
-utime_error (char const *name)
-{
-  call_arg_error ("utime", name);
-}
-
-void
-waitpid_error (char const *name)
-{
-  call_arg_error ("waitpid", name);
-}
-
-void
-write_error (char const *name)
-{
-  call_arg_error ("write", name);
-}
-
-void
-write_error_details (char const *name, size_t status, size_t size)
-{
-  if (status == 0)
-    write_error (name);
-  else
-    ERROR ((0, 0,
-	    ngettext ("%s: Wrote only %lu of %lu byte",
-		      "%s: Wrote only %lu of %lu bytes",
-		      size),
-	    name, (unsigned long int) status, (unsigned long int) size));
-}
-
-void
-write_fatal (char const *name)
-{
-  call_arg_fatal ("write", name);
-}
-
-void
-chdir_fatal (char const *name)
-{
-  call_arg_fatal ("chdir", name);
-}
diff --git a/contrib/cpio/lib/paxexit.c b/contrib/cpio/lib/paxexit.c
deleted file mode 100644
index a511f79cf17..00000000000
--- a/contrib/cpio/lib/paxexit.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Miscellaneous error functions
-
-   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU General Public License as published by the
-   Free Software Foundation; either version 2, or (at your option) any later
-   version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
-   Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation, Inc.,
-   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-#include 
-
-int exit_status = PAXEXIT_SUCCESS;
-
-void
-pax_exit ()
-{
-  exit (exit_status);
-}
diff --git a/contrib/cpio/lib/paxlib.h b/contrib/cpio/lib/paxlib.h
deleted file mode 100644
index 381c4c70299..00000000000
--- a/contrib/cpio/lib/paxlib.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/* This file is part of GNU paxutils
-
-   Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003,
-   2005 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*/
-
-#ifndef _paxlib_h_
-#define _paxlib_h_
-
-#include 
-#include 
-
-/* Error reporting functions and definitions */
-
-/* Exit status for paxutils app.  Let's try to keep this list as simple as
-   possible. tar -d option strongly invites a status different for unequal
-   comparison and other errors.  */
-#define PAXEXIT_SUCCESS 0
-#define PAXEXIT_DIFFERS 1
-#define PAXEXIT_FAILURE 2
-
-/* Both WARN and ERROR write a message on stderr and continue processing,
-   however ERROR manages so tar will exit unsuccessfully.  FATAL_ERROR
-   writes a message on stderr and aborts immediately, with another message
-   line telling so.  USAGE_ERROR works like FATAL_ERROR except that the
-   other message line suggests trying --help.  All four macros accept a
-   single argument of the form ((0, errno, _("FORMAT"), Args...)).  errno
-   is zero when the error is not being detected by the system.  */
-
-#define WARN(Args) \
-  error Args
-#define ERROR(Args) \
-  (error Args, exit_status = PAXEXIT_FAILURE)
-#define FATAL_ERROR(Args) \
-  (error Args, fatal_exit ())
-#define USAGE_ERROR(Args) \
-  (error Args, usage (PAXEXIT_FAILURE))
-
-extern int exit_status;
-
-void pax_decode_mode (mode_t mode, char *string);
-void call_arg_error (char const *call, char const *name);
-void call_arg_fatal (char const *call, char const *name) __attribute__ ((noreturn));
-void call_arg_warn (char const *call, char const *name);
-void chmod_error_details (char const *name, mode_t mode);
-void chown_error_details (char const *name, uid_t uid, gid_t gid);
-
-void decode_mode (mode_t, char *);
-
-void chdir_fatal (char const *) __attribute__ ((noreturn));
-void chmod_error_details (char const *, mode_t);
-void chown_error_details (char const *, uid_t, gid_t);
-void close_error (char const *);
-void close_warn (char const *);
-void exec_fatal (char const *) __attribute__ ((noreturn));
-void link_error (char const *, char const *);
-void mkdir_error (char const *);
-void mkfifo_error (char const *);
-void mknod_error (char const *);
-void open_error (char const *);
-void open_fatal (char const *) __attribute__ ((noreturn));
-void open_warn (char const *);
-void read_error (char const *);
-void read_error_details (char const *, off_t, size_t);
-void read_fatal (char const *) __attribute__ ((noreturn));
-void read_fatal_details (char const *, off_t, size_t) __attribute__ ((noreturn));
-void read_warn_details (char const *, off_t, size_t);
-void readlink_error (char const *);
-void readlink_warn (char const *);
-void rmdir_error (char const *);
-void savedir_error (char const *);
-void savedir_warn (char const *);
-void seek_error (char const *);
-void seek_error_details (char const *, off_t);
-void seek_warn (char const *);
-void seek_warn_details (char const *, off_t);
-void stat_fatal (char const *);
-void stat_error (char const *);
-void stat_warn (char const *);
-void symlink_error (char const *, char const *);
-void truncate_error (char const *);
-void truncate_warn (char const *);
-void unlink_error (char const *);
-void utime_error (char const *);
-void waitpid_error (char const *);
-void write_error (char const *);
-
-void pax_exit (void);
-void fatal_exit (void) __attribute__ ((noreturn));
-
-#define STRINGIFY_BIGINT(i, b) umaxtostr (i, b)
-
-
-/* Name-related functions */
-bool hash_string_insert (Hash_table **table, char const *string);
-bool hash_string_lookup (Hash_table const *table, char const *string);
-
-bool removed_prefixes_p (void);
-char *safer_name_suffix (char const *file_name, bool link_target, bool absolute_names);
-
-#endif
diff --git a/contrib/cpio/lib/paxnames.c b/contrib/cpio/lib/paxnames.c
deleted file mode 100644
index 3ca8bfaa7f9..00000000000
--- a/contrib/cpio/lib/paxnames.c
+++ /dev/null
@@ -1,156 +0,0 @@
-/* This file is part of GNU paxutils
-   Copyright (C) 2005 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU General Public License as published by the
-   Free Software Foundation; either version 2, or (at your option) any later
-   version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
-   Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation, Inc.,
-   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-#include 
-#include 
-
-
-/* Hash tables of strings.  */
-
-/* Calculate the hash of a string.  */
-static size_t
-hash_string_hasher (void const *name, size_t n_buckets)
-{
-  return hash_string (name, n_buckets);
-}
-
-/* Compare two strings for equality.  */
-static bool
-hash_string_compare (void const *name1, void const *name2)
-{
-  return strcmp (name1, name2) == 0;
-}
-
-/* Return zero if TABLE contains a copy of STRING; otherwise, insert a
-   copy of STRING to TABLE and return 1.  */
-bool
-hash_string_insert (Hash_table **table, char const *string)
-{
-  Hash_table *t = *table;
-  char *s = xstrdup (string);
-  char *e;
-
-  if (! ((t
-	  || (*table = t = hash_initialize (0, 0, hash_string_hasher,
-					    hash_string_compare, 0)))
-	 && (e = hash_insert (t, s))))
-    xalloc_die ();
-
-  if (e == s)
-    return 1;
-  else
-    {
-      free (s);
-      return 0;
-    }
-}
-
-/* Return 1 if TABLE contains STRING.  */
-bool
-hash_string_lookup (Hash_table const *table, char const *string)
-{
-  return table && hash_lookup (table, string);
-}
-
-
-static Hash_table *prefix_table[2];
-
-/* Return true if file names of some members in the archive were stripped off
-   their leading components. We could have used
-        return prefix_table[0] || prefix_table[1]
-   but the following seems to be safer: */
-bool
-removed_prefixes_p (void)
-{
-  return (prefix_table[0] && hash_get_n_entries (prefix_table[0]) != 0)
-         || (prefix_table[1] && hash_get_n_entries (prefix_table[1]) != 0);
-}
-
-/* Return a safer suffix of FILE_NAME, or "." if it has no safer
-   suffix.  Check for fully specified file names and other atrocities.
-   Warn the user if we do not return NAME.  If LINK_TARGET is 1,
-   FILE_NAME is the target of a hard link, not a member name.
-   If ABSOLUTE_NAMES is 0, strip filesystem prefix from the file name. */
-
-char *
-safer_name_suffix (char const *file_name, bool link_target, bool absolute_names)
-{
-  char const *p;
-
-  if (absolute_names)
-    p = file_name;
-  else
-    {
-      /* Skip file system prefixes, leading file name components that contain
-	 "..", and leading slashes.  */
-
-      size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (file_name);
-
-      for (p = file_name + prefix_len; *p; )
-	{
-          if (p[0] == '.' && p[1] == '.' && (ISSLASH (p[2]) || !p[2]))
-	    prefix_len = p + 2 - file_name;
-
-	  do
-	    {
-	      char c = *p++;
-	      if (ISSLASH (c))
-		break;
-	    }
-	  while (*p);
-	}
-
-      for (p = file_name + prefix_len; ISSLASH (*p); p++)
-	continue;
-      prefix_len = p - file_name;
-
-      if (prefix_len)
-	{
-	  char *prefix = alloca (prefix_len + 1);
-	  memcpy (prefix, file_name, prefix_len);
-	  prefix[prefix_len] = '\0';
-
-	  if (hash_string_insert (&prefix_table[link_target], prefix))
-	    {
-	      static char const *const diagnostic[] =
-	      {
-		N_("Removing leading `%s' from member names"),
-		N_("Removing leading `%s' from hard link targets")
-	      };
-	      WARN ((0, 0, _(diagnostic[link_target]), prefix));
-	    }
-	}
-    }
-
-  if (! *p)
-    {
-      if (p == file_name)
-	{
-	  static char const *const diagnostic[] =
-	  {
-	    N_("Substituting `.' for empty member name"),
-	    N_("Substituting `.' for empty hard link target")
-	  };
-	  WARN ((0, 0, "%s", _(diagnostic[link_target])));
-	}
-
-      p = ".";
-    }
-
-  return (char *) p;
-}
diff --git a/contrib/cpio/lib/quote.c b/contrib/cpio/lib/quote.c
deleted file mode 100644
index 119be72ae0a..00000000000
--- a/contrib/cpio/lib/quote.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/* quote.c - quote arguments for output
-
-   Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005, 2006 Free
-   Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Paul Eggert  */
-
-#include 
-
-#include "quotearg.h"
-#include "quote.h"
-
-/* Return an unambiguous printable representation of NAME,
-   allocated in slot N, suitable for diagnostics.  */
-char const *
-quote_n (int n, char const *name)
-{
-  return quotearg_n_style (n, locale_quoting_style, name);
-}
-
-/* Return an unambiguous printable representation of NAME,
-   suitable for diagnostics.  */
-char const *
-quote (char const *name)
-{
-  return quote_n (0, name);
-}
diff --git a/contrib/cpio/lib/quote.h b/contrib/cpio/lib/quote.h
deleted file mode 100644
index 5400eadb657..00000000000
--- a/contrib/cpio/lib/quote.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/* quote.h - prototypes for quote.c
-
-   Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software
-   Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-
-char const *quote_n (int n, char const *name);
-char const *quote (char const *name);
diff --git a/contrib/cpio/lib/quotearg.c b/contrib/cpio/lib/quotearg.c
deleted file mode 100644
index f7f326ac501..00000000000
--- a/contrib/cpio/lib/quotearg.c
+++ /dev/null
@@ -1,697 +0,0 @@
-/* quotearg.c - quote arguments for output
-
-   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007 Free
-   Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Paul Eggert  */
-
-#include 
-
-#include "quotearg.h"
-
-#include "xalloc.h"
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-#define N_(msgid) msgid
-
-#if !HAVE_MBRTOWC
-/* Disable multibyte processing entirely.  Since MB_CUR_MAX is 1, the
-   other macros are defined only for documentation and to satisfy C
-   syntax.  */
-# undef MB_CUR_MAX
-# define MB_CUR_MAX 1
-# undef mbstate_t
-# define mbstate_t int
-# define mbrtowc(pwc, s, n, ps) ((*(pwc) = *(s)) != 0)
-# define iswprint(wc) isprint ((unsigned char) (wc))
-# undef HAVE_MBSINIT
-#endif
-
-#if !defined mbsinit && !HAVE_MBSINIT
-# define mbsinit(ps) 1
-#endif
-
-#ifndef SIZE_MAX
-# define SIZE_MAX ((size_t) -1)
-#endif
-
-#define INT_BITS (sizeof (int) * CHAR_BIT)
-
-struct quoting_options
-{
-  /* Basic quoting style.  */
-  enum quoting_style style;
-
-  /* Quote the characters indicated by this bit vector even if the
-     quoting style would not normally require them to be quoted.  */
-  unsigned int quote_these_too[(UCHAR_MAX / INT_BITS) + 1];
-};
-
-/* Names of quoting styles.  */
-char const *const quoting_style_args[] =
-{
-  "literal",
-  "shell",
-  "shell-always",
-  "c",
-  "escape",
-  "locale",
-  "clocale",
-  0
-};
-
-/* Correspondences to quoting style names.  */
-enum quoting_style const quoting_style_vals[] =
-{
-  literal_quoting_style,
-  shell_quoting_style,
-  shell_always_quoting_style,
-  c_quoting_style,
-  escape_quoting_style,
-  locale_quoting_style,
-  clocale_quoting_style
-};
-
-/* The default quoting options.  */
-static struct quoting_options default_quoting_options;
-
-/* Allocate a new set of quoting options, with contents initially identical
-   to O if O is not null, or to the default if O is null.
-   It is the caller's responsibility to free the result.  */
-struct quoting_options *
-clone_quoting_options (struct quoting_options *o)
-{
-  int e = errno;
-  struct quoting_options *p = xmemdup (o ? o : &default_quoting_options,
-				       sizeof *o);
-  errno = e;
-  return p;
-}
-
-/* Get the value of O's quoting style.  If O is null, use the default.  */
-enum quoting_style
-get_quoting_style (struct quoting_options *o)
-{
-  return (o ? o : &default_quoting_options)->style;
-}
-
-/* In O (or in the default if O is null),
-   set the value of the quoting style to S.  */
-void
-set_quoting_style (struct quoting_options *o, enum quoting_style s)
-{
-  (o ? o : &default_quoting_options)->style = s;
-}
-
-/* In O (or in the default if O is null),
-   set the value of the quoting options for character C to I.
-   Return the old value.  Currently, the only values defined for I are
-   0 (the default) and 1 (which means to quote the character even if
-   it would not otherwise be quoted).  */
-int
-set_char_quoting (struct quoting_options *o, char c, int i)
-{
-  unsigned char uc = c;
-  unsigned int *p =
-    (o ? o : &default_quoting_options)->quote_these_too + uc / INT_BITS;
-  int shift = uc % INT_BITS;
-  int r = (*p >> shift) & 1;
-  *p ^= ((i & 1) ^ r) << shift;
-  return r;
-}
-
-/* MSGID approximates a quotation mark.  Return its translation if it
-   has one; otherwise, return either it or "\"", depending on S.  */
-static char const *
-gettext_quote (char const *msgid, enum quoting_style s)
-{
-  char const *translation = _(msgid);
-  if (translation == msgid && s == clocale_quoting_style)
-    translation = "\"";
-  return translation;
-}
-
-/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
-   argument ARG (of size ARGSIZE), using QUOTING_STYLE and the
-   non-quoting-style part of O to control quoting.
-   Terminate the output with a null character, and return the written
-   size of the output, not counting the terminating null.
-   If BUFFERSIZE is too small to store the output string, return the
-   value that would have been returned had BUFFERSIZE been large enough.
-   If ARGSIZE is SIZE_MAX, use the string length of the argument for ARGSIZE.
-
-   This function acts like quotearg_buffer (BUFFER, BUFFERSIZE, ARG,
-   ARGSIZE, O), except it uses QUOTING_STYLE instead of the quoting
-   style specified by O, and O may not be null.  */
-
-static size_t
-quotearg_buffer_restyled (char *buffer, size_t buffersize,
-			  char const *arg, size_t argsize,
-			  enum quoting_style quoting_style,
-			  struct quoting_options const *o)
-{
-  size_t i;
-  size_t len = 0;
-  char const *quote_string = 0;
-  size_t quote_string_len = 0;
-  bool backslash_escapes = false;
-  bool unibyte_locale = MB_CUR_MAX == 1;
-
-#define STORE(c) \
-    do \
-      { \
-	if (len < buffersize) \
-	  buffer[len] = (c); \
-	len++; \
-      } \
-    while (0)
-
-  switch (quoting_style)
-    {
-    case c_quoting_style:
-      STORE ('"');
-      backslash_escapes = true;
-      quote_string = "\"";
-      quote_string_len = 1;
-      break;
-
-    case escape_quoting_style:
-      backslash_escapes = true;
-      break;
-
-    case locale_quoting_style:
-    case clocale_quoting_style:
-      {
-	/* TRANSLATORS:
-	   Get translations for open and closing quotation marks.
-
-	   The message catalog should translate "`" to a left
-	   quotation mark suitable for the locale, and similarly for
-	   "'".  If the catalog has no translation,
-	   locale_quoting_style quotes `like this', and
-	   clocale_quoting_style quotes "like this".
-
-	   For example, an American English Unicode locale should
-	   translate "`" to U+201C (LEFT DOUBLE QUOTATION MARK), and
-	   should translate "'" to U+201D (RIGHT DOUBLE QUOTATION
-	   MARK).  A British English Unicode locale should instead
-	   translate these to U+2018 (LEFT SINGLE QUOTATION MARK) and
-	   U+2019 (RIGHT SINGLE QUOTATION MARK), respectively.
-
-	   If you don't know what to put here, please see
-	   
-	   and use glyphs suitable for your language.  */
-
-	char const *left = gettext_quote (N_("`"), quoting_style);
-	char const *right = gettext_quote (N_("'"), quoting_style);
-	for (quote_string = left; *quote_string; quote_string++)
-	  STORE (*quote_string);
-	backslash_escapes = true;
-	quote_string = right;
-	quote_string_len = strlen (quote_string);
-      }
-      break;
-
-    case shell_always_quoting_style:
-      STORE ('\'');
-      quote_string = "'";
-      quote_string_len = 1;
-      break;
-
-    default:
-      break;
-    }
-
-  for (i = 0;  ! (argsize == SIZE_MAX ? arg[i] == '\0' : i == argsize);  i++)
-    {
-      unsigned char c;
-      unsigned char esc;
-
-      if (backslash_escapes
-	  && quote_string_len
-	  && i + quote_string_len <= argsize
-	  && memcmp (arg + i, quote_string, quote_string_len) == 0)
-	STORE ('\\');
-
-      c = arg[i];
-      switch (c)
-	{
-	case '\0':
-	  if (backslash_escapes)
-	    {
-	      STORE ('\\');
-	      STORE ('0');
-	      STORE ('0');
-	      c = '0';
-	    }
-	  break;
-
-	case '?':
-	  switch (quoting_style)
-	    {
-	    case shell_quoting_style:
-	      goto use_shell_always_quoting_style;
-
-	    case c_quoting_style:
-	      if (i + 2 < argsize && arg[i + 1] == '?')
-		switch (arg[i + 2])
-		  {
-		  case '!': case '\'':
-		  case '(': case ')': case '-': case '/':
-		  case '<': case '=': case '>':
-		    /* Escape the second '?' in what would otherwise be
-		       a trigraph.  */
-		    c = arg[i + 2];
-		    i += 2;
-		    STORE ('?');
-		    STORE ('\\');
-		    STORE ('?');
-		    break;
-
-		  default:
-		    break;
-		  }
-	      break;
-
-	    default:
-	      break;
-	    }
-	  break;
-
-	case '\a': esc = 'a'; goto c_escape;
-	case '\b': esc = 'b'; goto c_escape;
-	case '\f': esc = 'f'; goto c_escape;
-	case '\n': esc = 'n'; goto c_and_shell_escape;
-	case '\r': esc = 'r'; goto c_and_shell_escape;
-	case '\t': esc = 't'; goto c_and_shell_escape;
-	case '\v': esc = 'v'; goto c_escape;
-	case '\\': esc = c; goto c_and_shell_escape;
-
-	c_and_shell_escape:
-	  if (quoting_style == shell_quoting_style)
-	    goto use_shell_always_quoting_style;
-	c_escape:
-	  if (backslash_escapes)
-	    {
-	      c = esc;
-	      goto store_escape;
-	    }
-	  break;
-
-	case '{': case '}': /* sometimes special if isolated */
-	  if (! (argsize == SIZE_MAX ? arg[1] == '\0' : argsize == 1))
-	    break;
-	  /* Fall through.  */
-	case '#': case '~':
-	  if (i != 0)
-	    break;
-	  /* Fall through.  */
-	case ' ':
-	case '!': /* special in bash */
-	case '"': case '$': case '&':
-	case '(': case ')': case '*': case ';':
-	case '<':
-	case '=': /* sometimes special in 0th or (with "set -k") later args */
-	case '>': case '[':
-	case '^': /* special in old /bin/sh, e.g. SunOS 4.1.4 */
-	case '`': case '|':
-	  /* A shell special character.  In theory, '$' and '`' could
-	     be the first bytes of multibyte characters, which means
-	     we should check them with mbrtowc, but in practice this
-	     doesn't happen so it's not worth worrying about.  */
-	  if (quoting_style == shell_quoting_style)
-	    goto use_shell_always_quoting_style;
-	  break;
-
-	case '\'':
-	  switch (quoting_style)
-	    {
-	    case shell_quoting_style:
-	      goto use_shell_always_quoting_style;
-
-	    case shell_always_quoting_style:
-	      STORE ('\'');
-	      STORE ('\\');
-	      STORE ('\'');
-	      break;
-
-	    default:
-	      break;
-	    }
-	  break;
-
-	case '%': case '+': case ',': case '-': case '.': case '/':
-	case '0': case '1': case '2': case '3': case '4': case '5':
-	case '6': case '7': case '8': case '9': case ':':
-	case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
-	case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
-	case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
-	case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
-	case 'Y': case 'Z': case ']': case '_': case 'a': case 'b':
-	case 'c': case 'd': case 'e': case 'f': case 'g': case 'h':
-	case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
-	case 'o': case 'p': case 'q': case 'r': case 's': case 't':
-	case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
-	  /* These characters don't cause problems, no matter what the
-	     quoting style is.  They cannot start multibyte sequences.  */
-	  break;
-
-	default:
-	  /* If we have a multibyte sequence, copy it until we reach
-	     its end, find an error, or come back to the initial shift
-	     state.  For C-like styles, if the sequence has
-	     unprintable characters, escape the whole sequence, since
-	     we can't easily escape single characters within it.  */
-	  {
-	    /* Length of multibyte sequence found so far.  */
-	    size_t m;
-
-	    bool printable;
-
-	    if (unibyte_locale)
-	      {
-		m = 1;
-		printable = isprint (c) != 0;
-	      }
-	    else
-	      {
-		mbstate_t mbstate;
-		memset (&mbstate, 0, sizeof mbstate);
-
-		m = 0;
-		printable = true;
-		if (argsize == SIZE_MAX)
-		  argsize = strlen (arg);
-
-		do
-		  {
-		    wchar_t w;
-		    size_t bytes = mbrtowc (&w, &arg[i + m],
-					    argsize - (i + m), &mbstate);
-		    if (bytes == 0)
-		      break;
-		    else if (bytes == (size_t) -1)
-		      {
-			printable = false;
-			break;
-		      }
-		    else if (bytes == (size_t) -2)
-		      {
-			printable = false;
-			while (i + m < argsize && arg[i + m])
-			  m++;
-			break;
-		      }
-		    else
-		      {
-			/* Work around a bug with older shells that "see" a '\'
-			   that is really the 2nd byte of a multibyte character.
-			   In practice the problem is limited to ASCII
-			   chars >= '@' that are shell special chars.  */
-			if ('[' == 0x5b && quoting_style == shell_quoting_style)
-			  {
-			    size_t j;
-			    for (j = 1; j < bytes; j++)
-			      switch (arg[i + m + j])
-				{
-				case '[': case '\\': case '^':
-				case '`': case '|':
-				  goto use_shell_always_quoting_style;
-
-				default:
-				  break;
-				}
-			  }
-
-			if (! iswprint (w))
-			  printable = false;
-			m += bytes;
-		      }
-		  }
-		while (! mbsinit (&mbstate));
-	      }
-
-	    if (1 < m || (backslash_escapes && ! printable))
-	      {
-		/* Output a multibyte sequence, or an escaped
-		   unprintable unibyte character.  */
-		size_t ilim = i + m;
-
-		for (;;)
-		  {
-		    if (backslash_escapes && ! printable)
-		      {
-			STORE ('\\');
-			STORE ('0' + (c >> 6));
-			STORE ('0' + ((c >> 3) & 7));
-			c = '0' + (c & 7);
-		      }
-		    if (ilim <= i + 1)
-		      break;
-		    STORE (c);
-		    c = arg[++i];
-		  }
-
-		goto store_c;
-	      }
-	  }
-	}
-
-      if (! (backslash_escapes
-	     && o->quote_these_too[c / INT_BITS] & (1 << (c % INT_BITS))))
-	goto store_c;
-
-    store_escape:
-      STORE ('\\');
-
-    store_c:
-      STORE (c);
-    }
-
-  if (i == 0 && quoting_style == shell_quoting_style)
-    goto use_shell_always_quoting_style;
-
-  if (quote_string)
-    for (; *quote_string; quote_string++)
-      STORE (*quote_string);
-
-  if (len < buffersize)
-    buffer[len] = '\0';
-  return len;
-
- use_shell_always_quoting_style:
-  return quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
-				   shell_always_quoting_style, o);
-}
-
-/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
-   argument ARG (of size ARGSIZE), using O to control quoting.
-   If O is null, use the default.
-   Terminate the output with a null character, and return the written
-   size of the output, not counting the terminating null.
-   If BUFFERSIZE is too small to store the output string, return the
-   value that would have been returned had BUFFERSIZE been large enough.
-   If ARGSIZE is SIZE_MAX, use the string length of the argument for
-   ARGSIZE.  */
-size_t
-quotearg_buffer (char *buffer, size_t buffersize,
-		 char const *arg, size_t argsize,
-		 struct quoting_options const *o)
-{
-  struct quoting_options const *p = o ? o : &default_quoting_options;
-  int e = errno;
-  size_t r = quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
-				       p->style, p);
-  errno = e;
-  return r;
-}
-
-/* Like quotearg_buffer (..., ARG, ARGSIZE, O), except return newly
-   allocated storage containing the quoted string.  */
-char *
-quotearg_alloc (char const *arg, size_t argsize,
-		struct quoting_options const *o)
-{
-  int e = errno;
-  size_t bufsize = quotearg_buffer (0, 0, arg, argsize, o) + 1;
-  char *buf = xcharalloc (bufsize);
-  quotearg_buffer (buf, bufsize, arg, argsize, o);
-  errno = e;
-  return buf;
-}
-
-/* A storage slot with size and pointer to a value.  */
-struct slotvec
-{
-  size_t size;
-  char *val;
-};
-
-/* Preallocate a slot 0 buffer, so that the caller can always quote
-   one small component of a "memory exhausted" message in slot 0.  */
-static char slot0[256];
-static unsigned int nslots = 1;
-static struct slotvec slotvec0 = {sizeof slot0, slot0};
-static struct slotvec *slotvec = &slotvec0;
-
-void
-quotearg_free (void)
-{
-  struct slotvec *sv = slotvec;
-  unsigned int i;
-  for (i = 1; i < nslots; i++)
-    free (sv[i].val);
-  if (sv[0].val != slot0)
-    {
-      free (sv[0].val);
-      slotvec0.size = sizeof slot0;
-      slotvec0.val = slot0;
-    }
-  if (sv != &slotvec0)
-    {
-      free (sv);
-      slotvec = &slotvec0;
-    }
-  nslots = 1;
-}
-
-/* Use storage slot N to return a quoted version of argument ARG.
-   ARG is of size ARGSIZE, but if that is SIZE_MAX, ARG is a
-   null-terminated string.
-   OPTIONS specifies the quoting options.
-   The returned value points to static storage that can be
-   reused by the next call to this function with the same value of N.
-   N must be nonnegative.  N is deliberately declared with type "int"
-   to allow for future extensions (using negative values).  */
-static char *
-quotearg_n_options (int n, char const *arg, size_t argsize,
-		    struct quoting_options const *options)
-{
-  int e = errno;
-
-  unsigned int n0 = n;
-  struct slotvec *sv = slotvec;
-
-  if (n < 0)
-    abort ();
-
-  if (nslots <= n0)
-    {
-      /* FIXME: technically, the type of n1 should be `unsigned int',
-	 but that evokes an unsuppressible warning from gcc-4.0.1 and
-	 older.  If gcc ever provides an option to suppress that warning,
-	 revert to the original type, so that the test in xalloc_oversized
-	 is once again performed only at compile time.  */
-      size_t n1 = n0 + 1;
-      bool preallocated = (sv == &slotvec0);
-
-      if (xalloc_oversized (n1, sizeof *sv))
-	xalloc_die ();
-
-      slotvec = sv = xrealloc (preallocated ? NULL : sv, n1 * sizeof *sv);
-      if (preallocated)
-	*sv = slotvec0;
-      memset (sv + nslots, 0, (n1 - nslots) * sizeof *sv);
-      nslots = n1;
-    }
-
-  {
-    size_t size = sv[n].size;
-    char *val = sv[n].val;
-    size_t qsize = quotearg_buffer (val, size, arg, argsize, options);
-
-    if (size <= qsize)
-      {
-	sv[n].size = size = qsize + 1;
-	if (val != slot0)
-	  free (val);
-	sv[n].val = val = xcharalloc (size);
-	quotearg_buffer (val, size, arg, argsize, options);
-      }
-
-    errno = e;
-    return val;
-  }
-}
-
-char *
-quotearg_n (int n, char const *arg)
-{
-  return quotearg_n_options (n, arg, SIZE_MAX, &default_quoting_options);
-}
-
-char *
-quotearg (char const *arg)
-{
-  return quotearg_n (0, arg);
-}
-
-/* Return quoting options for STYLE, with no extra quoting.  */
-static struct quoting_options
-quoting_options_from_style (enum quoting_style style)
-{
-  struct quoting_options o;
-  o.style = style;
-  memset (o.quote_these_too, 0, sizeof o.quote_these_too);
-  return o;
-}
-
-char *
-quotearg_n_style (int n, enum quoting_style s, char const *arg)
-{
-  struct quoting_options const o = quoting_options_from_style (s);
-  return quotearg_n_options (n, arg, SIZE_MAX, &o);
-}
-
-char *
-quotearg_n_style_mem (int n, enum quoting_style s,
-		      char const *arg, size_t argsize)
-{
-  struct quoting_options const o = quoting_options_from_style (s);
-  return quotearg_n_options (n, arg, argsize, &o);
-}
-
-char *
-quotearg_style (enum quoting_style s, char const *arg)
-{
-  return quotearg_n_style (0, s, arg);
-}
-
-char *
-quotearg_char (char const *arg, char ch)
-{
-  struct quoting_options options;
-  options = default_quoting_options;
-  set_char_quoting (&options, ch, 1);
-  return quotearg_n_options (0, arg, SIZE_MAX, &options);
-}
-
-char *
-quotearg_colon (char const *arg)
-{
-  return quotearg_char (arg, ':');
-}
diff --git a/contrib/cpio/lib/quotearg.h b/contrib/cpio/lib/quotearg.h
deleted file mode 100644
index 4887df3b6d5..00000000000
--- a/contrib/cpio/lib/quotearg.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/* quotearg.h - quote arguments for output
-
-   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2006 Free
-   Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Paul Eggert  */
-
-#ifndef QUOTEARG_H_
-# define QUOTEARG_H_ 1
-
-# include 
-
-/* Basic quoting styles.  */
-enum quoting_style
-  {
-    /* Output names as-is (ls --quoting-style=literal).  */
-    literal_quoting_style,
-
-    /* Quote names for the shell if they contain shell metacharacters
-       or would cause ambiguous output (ls --quoting-style=shell).  */
-    shell_quoting_style,
-
-    /* Quote names for the shell, even if they would normally not
-       require quoting (ls --quoting-style=shell-always).  */
-    shell_always_quoting_style,
-
-    /* Quote names as for a C language string (ls --quoting-style=c).  */
-    c_quoting_style,
-
-    /* Like c_quoting_style except omit the surrounding double-quote
-       characters (ls --quoting-style=escape).  */
-    escape_quoting_style,
-
-    /* Like clocale_quoting_style, but quote `like this' instead of
-       "like this" in the default C locale (ls --quoting-style=locale).  */
-    locale_quoting_style,
-
-    /* Like c_quoting_style except use quotation marks appropriate for
-       the locale (ls --quoting-style=clocale).  */
-    clocale_quoting_style
-  };
-
-/* For now, --quoting-style=literal is the default, but this may change.  */
-# ifndef DEFAULT_QUOTING_STYLE
-#  define DEFAULT_QUOTING_STYLE literal_quoting_style
-# endif
-
-/* Names of quoting styles and their corresponding values.  */
-extern char const *const quoting_style_args[];
-extern enum quoting_style const quoting_style_vals[];
-
-struct quoting_options;
-
-/* The functions listed below set and use a hidden variable
-   that contains the default quoting style options.  */
-
-/* Allocate a new set of quoting options, with contents initially identical
-   to O if O is not null, or to the default if O is null.
-   It is the caller's responsibility to free the result.  */
-struct quoting_options *clone_quoting_options (struct quoting_options *o);
-
-/* Get the value of O's quoting style.  If O is null, use the default.  */
-enum quoting_style get_quoting_style (struct quoting_options *o);
-
-/* In O (or in the default if O is null),
-   set the value of the quoting style to S.  */
-void set_quoting_style (struct quoting_options *o, enum quoting_style s);
-
-/* In O (or in the default if O is null),
-   set the value of the quoting options for character C to I.
-   Return the old value.  Currently, the only values defined for I are
-   0 (the default) and 1 (which means to quote the character even if
-   it would not otherwise be quoted).  */
-int set_char_quoting (struct quoting_options *o, char c, int i);
-
-/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
-   argument ARG (of size ARGSIZE), using O to control quoting.
-   If O is null, use the default.
-   Terminate the output with a null character, and return the written
-   size of the output, not counting the terminating null.
-   If BUFFERSIZE is too small to store the output string, return the
-   value that would have been returned had BUFFERSIZE been large enough.
-   If ARGSIZE is -1, use the string length of the argument for ARGSIZE.  */
-size_t quotearg_buffer (char *buffer, size_t buffersize,
-			char const *arg, size_t argsize,
-			struct quoting_options const *o);
-
-/* Like quotearg_buffer, except return the result in a newly allocated
-   buffer.  It is the caller's responsibility to free the result.  */
-char *quotearg_alloc (char const *arg, size_t argsize,
-		      struct quoting_options const *o);
-
-/* Use storage slot N to return a quoted version of the string ARG.
-   Use the default quoting options.
-   The returned value points to static storage that can be
-   reused by the next call to this function with the same value of N.
-   N must be nonnegative.  */
-char *quotearg_n (int n, char const *arg);
-
-/* Equivalent to quotearg_n (0, ARG).  */
-char *quotearg (char const *arg);
-
-/* Use style S and storage slot N to return a quoted version of the string ARG.
-   This is like quotearg_n (N, ARG), except that it uses S with no other
-   options to specify the quoting method.  */
-char *quotearg_n_style (int n, enum quoting_style s, char const *arg);
-
-/* Use style S and storage slot N to return a quoted version of the
-   argument ARG of size ARGSIZE.  This is like quotearg_n_style
-   (N, S, ARG), except it can quote null bytes.  */
-char *quotearg_n_style_mem (int n, enum quoting_style s,
-			    char const *arg, size_t argsize);
-
-/* Equivalent to quotearg_n_style (0, S, ARG).  */
-char *quotearg_style (enum quoting_style s, char const *arg);
-
-/* Like quotearg (ARG), except also quote any instances of CH.  */
-char *quotearg_char (char const *arg, char ch);
-
-/* Equivalent to quotearg_char (ARG, ':').  */
-char *quotearg_colon (char const *arg);
-
-/* Free any dynamically allocated memory.  */
-void quotearg_free (void);
-
-#endif /* !QUOTEARG_H_ */
diff --git a/contrib/cpio/lib/rmt-command.h b/contrib/cpio/lib/rmt-command.h
deleted file mode 100644
index 7460e6fc962..00000000000
--- a/contrib/cpio/lib/rmt-command.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#define LOCALEDIR "/usr/local/share/locale"
-#ifndef DEFAULT_RMT_COMMAND
-# define DEFAULT_RMT_COMMAND "/usr/local/libexec/rmt"
-#endif
diff --git a/contrib/cpio/lib/rmt.h b/contrib/cpio/lib/rmt.h
deleted file mode 100644
index 9f96cdb9b5f..00000000000
--- a/contrib/cpio/lib/rmt.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/* Definitions for communicating with a remote tape drive.
-
-   Copyright (C) 1988, 1992, 1996, 1997, 2001, 2003, 2004 Free
-   Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-extern char *rmt_command;
-extern char *rmt_dev_name__;
-
-int rmt_open__ (const char *, int, int, const char *);
-int rmt_close__ (int);
-size_t rmt_read__ (int, char *, size_t);
-size_t rmt_write__ (int, char *, size_t);
-off_t rmt_lseek__ (int, off_t, int);
-int rmt_ioctl__ (int, int, char *);
-
-extern bool force_local_option;
-
-/* A filename is remote if it contains a colon not preceded by a slash,
-   to take care of `/:/' which is a shorthand for `/...//fs'
-   on machines running OSF's Distributing Computing Environment (DCE) and
-   Distributed File System (DFS).  However, when --force-local, a
-   filename is never remote.  */
-
-#define _remdev(dev_name) \
-  (!force_local_option && (rmt_dev_name__ = strchr (dev_name, ':')) \
-   && rmt_dev_name__ > (dev_name) \
-   && ! memchr (dev_name, '/', rmt_dev_name__ - (dev_name)))
-
-#define _isrmt(fd) \
-  ((fd) >= __REM_BIAS)
-
-#define __REM_BIAS (1 << 30)
-
-#ifndef O_CREAT
-# define O_CREAT 01000
-#endif
-
-#define rmtopen(dev_name, oflag, mode, command) \
-  (_remdev (dev_name) ? rmt_open__ (dev_name, oflag, __REM_BIAS, command) \
-   : open (dev_name, oflag, mode))
-
-#define rmtaccess(dev_name, amode) \
-  (_remdev (dev_name) ? 0 : access (dev_name, amode))
-
-#define rmtstat(dev_name, buffer) \
-  (_remdev (dev_name) ? (errno = EOPNOTSUPP), -1 : stat (dev_name, buffer))
-
-#define rmtcreat(dev_name, mode, command) \
-   (_remdev (dev_name) \
-    ? rmt_open__ (dev_name, 1 | O_CREAT, __REM_BIAS, command) \
-    : creat (dev_name, mode))
-
-#define rmtlstat(dev_name, muffer) \
-  (_remdev (dev_name) ? (errno = EOPNOTSUPP), -1 : lstat (dev_name, buffer))
-
-#define rmtread(fd, buffer, length) \
-  (_isrmt (fd) ? rmt_read__ (fd - __REM_BIAS, buffer, length) \
-   : safe_read (fd, buffer, length))
-
-#define rmtwrite(fd, buffer, length) \
-  (_isrmt (fd) ? rmt_write__ (fd - __REM_BIAS, buffer, length) \
-   : full_write (fd, buffer, length))
-
-#define rmtlseek(fd, offset, where) \
-  (_isrmt (fd) ? rmt_lseek__ (fd - __REM_BIAS, offset, where) \
-   : lseek (fd, offset, where))
-
-#define rmtclose(fd) \
-  (_isrmt (fd) ? rmt_close__ (fd - __REM_BIAS) : close (fd))
-
-#define rmtioctl(fd, request, argument) \
-  (_isrmt (fd) ? rmt_ioctl__ (fd - __REM_BIAS, request, argument) \
-   : ioctl (fd, request, argument))
-
-#define rmtdup(fd) \
-  (_isrmt (fd) ? (errno = EOPNOTSUPP), -1 : dup (fd))
-
-#define rmtfstat(fd, buffer) \
-  (_isrmt (fd) ? (errno = EOPNOTSUPP), -1 : fstat (fd, buffer))
-
-#define rmtfcntl(cd, command, argument) \
-  (_isrmt (fd) ? (errno = EOPNOTSUPP), -1 : fcntl (fd, command, argument))
-
-#define rmtisatty(fd) \
-  (_isrmt (fd) ? 0 : isatty (fd))
diff --git a/contrib/cpio/lib/rtapelib.c b/contrib/cpio/lib/rtapelib.c
deleted file mode 100644
index d73d1364e84..00000000000
--- a/contrib/cpio/lib/rtapelib.c
+++ /dev/null
@@ -1,741 +0,0 @@
-/* Functions for communicating with a remote tape drive.
-
-   Copyright (C) 1988, 1992, 1994, 1996, 1997, 1999, 2000, 2001, 2004,
-   2005, 2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* The man page rmt(8) for /etc/rmt documents the remote mag tape protocol
-   which rdump and rrestore use.  Unfortunately, the man page is *WRONG*.
-   The author of the routines I'm including originally wrote his code just
-   based on the man page, and it didn't work, so he went to the rdump source
-   to figure out why.  The only thing he had to change was to check for the
-   'F' return code in addition to the 'E', and to separate the various
-   arguments with \n instead of a space.  I personally don't think that this
-   is much of a problem, but I wanted to point it out. -- Arnold Robbins
-
-   Originally written by Jeff Lee, modified some by Arnold Robbins.  Redone
-   as a library that can replace open, read, write, etc., by Fred Fish, with
-   some additional work by Arnold Robbins.  Modified to make all rmt* calls
-   into macros for speed by Jay Fenlason.  Use -DWITH_REXEC for rexec
-   code, courtesy of Dan Kegel.  */
-
-#include "system.h"
-#include "system-ioctl.h"
-
-#include 
-#include 
-
-/* Try hard to get EOPNOTSUPP defined.  486/ISC has it in net/errno.h,
-   3B2/SVR3 has it in sys/inet.h.  Otherwise, like on MSDOS, use EINVAL.  */
-
-#ifndef EOPNOTSUPP
-# if HAVE_NET_ERRNO_H
-#  include 
-# endif
-# if HAVE_SYS_INET_H
-#  include 
-# endif
-# ifndef EOPNOTSUPP
-#  define EOPNOTSUPP EINVAL
-# endif
-#endif
-
-#include 
-
-#if HAVE_NETDB_H
-# include 
-#endif
-
-#include 
-#include 
-
-/* Exit status if exec errors.  */
-#define EXIT_ON_EXEC_ERROR 128
-
-/* FIXME: Size of buffers for reading and writing commands to rmt.  */
-#define COMMAND_BUFFER_SIZE 64
-
-#ifndef RETSIGTYPE
-# define RETSIGTYPE void
-#endif
-
-/* FIXME: Maximum number of simultaneous remote tape connections.  */
-#define MAXUNIT	4
-
-#define	PREAD 0			/* read  file descriptor from pipe() */
-#define	PWRITE 1		/* write file descriptor from pipe() */
-
-/* Return the parent's read side of remote tape connection Fd.  */
-#define READ_SIDE(Fd) (from_remote[Fd][PREAD])
-
-/* Return the parent's write side of remote tape connection Fd.  */
-#define WRITE_SIDE(Fd) (to_remote[Fd][PWRITE])
-
-/* The pipes for receiving data from remote tape drives.  */
-static int from_remote[MAXUNIT][2] = {{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}};
-
-/* The pipes for sending data to remote tape drives.  */
-static int to_remote[MAXUNIT][2] = {{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}};
-
-char *rmt_command = DEFAULT_RMT_COMMAND;
-
-/* Temporary variable used by macros in rmt.h.  */
-char *rmt_dev_name__;
-
-/* If true, always consider file names to be local, even if they contain
-   colons */
-bool force_local_option;
-
-
-
-/* Close remote tape connection HANDLE, and reset errno to ERRNO_VALUE.  */
-static void
-_rmt_shutdown (int handle, int errno_value)
-{
-  close (READ_SIDE (handle));
-  close (WRITE_SIDE (handle));
-  READ_SIDE (handle) = -1;
-  WRITE_SIDE (handle) = -1;
-  errno = errno_value;
-}
-
-/* Attempt to perform the remote tape command specified in BUFFER on
-   remote tape connection HANDLE.  Return 0 if successful, -1 on
-   error.  */
-static int
-do_command (int handle, const char *buffer)
-{
-  /* Save the current pipe handler and try to make the request.  */
-
-  size_t length = strlen (buffer);
-  RETSIGTYPE (*pipe_handler) () = signal (SIGPIPE, SIG_IGN);
-  ssize_t written = full_write (WRITE_SIDE (handle), buffer, length);
-  signal (SIGPIPE, pipe_handler);
-
-  if (written == length)
-    return 0;
-
-  /* Something went wrong.  Close down and go home.  */
-
-  _rmt_shutdown (handle, EIO);
-  return -1;
-}
-
-static char *
-get_status_string (int handle, char *command_buffer)
-{
-  char *cursor;
-  int counter;
-
-  /* Read the reply command line.  */
-
-  for (counter = 0, cursor = command_buffer;
-       counter < COMMAND_BUFFER_SIZE;
-       counter++, cursor++)
-    {
-      if (safe_read (READ_SIDE (handle), cursor, 1) != 1)
-	{
-	  _rmt_shutdown (handle, EIO);
-	  return 0;
-	}
-      if (*cursor == '\n')
-	{
-	  *cursor = '\0';
-	  break;
-	}
-    }
-
-  if (counter == COMMAND_BUFFER_SIZE)
-    {
-      _rmt_shutdown (handle, EIO);
-      return 0;
-    }
-
-  /* Check the return status.  */
-
-  for (cursor = command_buffer; *cursor; cursor++)
-    if (*cursor != ' ')
-      break;
-
-  if (*cursor == 'E' || *cursor == 'F')
-    {
-      /* Skip the error message line.  */
-
-      /* FIXME: there is better to do than merely ignoring error messages
-	 coming from the remote end.  Translate them, too...  */
-
-      {
-	char character;
-
-	while (safe_read (READ_SIDE (handle), &character, 1) == 1)
-	  if (character == '\n')
-	    break;
-      }
-
-      errno = atoi (cursor + 1);
-
-      if (*cursor == 'F')
-	_rmt_shutdown (handle, errno);
-
-      return 0;
-    }
-
-  /* Check for mis-synced pipes.  */
-
-  if (*cursor != 'A')
-    {
-      _rmt_shutdown (handle, EIO);
-      return 0;
-    }
-
-  /* Got an `A' (success) response.  */
-
-  return cursor + 1;
-}
-
-/* Read and return the status from remote tape connection HANDLE.  If
-   an error occurred, return -1 and set errno.  */
-static long int
-get_status (int handle)
-{
-  char command_buffer[COMMAND_BUFFER_SIZE];
-  const char *status = get_status_string (handle, command_buffer);
-  if (status)
-    {
-      long int result = atol (status);
-      if (0 <= result)
-	return result;
-      errno = EIO;
-    }
-  return -1;
-}
-
-static off_t
-get_status_off (int handle)
-{
-  char command_buffer[COMMAND_BUFFER_SIZE];
-  const char *status = get_status_string (handle, command_buffer);
-
-  if (! status)
-    return -1;
-  else
-    {
-      /* Parse status, taking care to check for overflow.
-	 We can't use standard functions,
-	 since off_t might be longer than long.  */
-
-      off_t count = 0;
-      int negative;
-
-      for (;  *status == ' ' || *status == '\t';  status++)
-	continue;
-
-      negative = *status == '-';
-      status += negative || *status == '+';
-
-      for (;;)
-	{
-	  int digit = *status++ - '0';
-	  if (9 < (unsigned) digit)
-	    break;
-	  else
-	    {
-	      off_t c10 = 10 * count;
-	      off_t nc = negative ? c10 - digit : c10 + digit;
-	      if (c10 / 10 != count || (negative ? c10 < nc : nc < c10))
-		return -1;
-	      count = nc;
-	    }
-	}
-
-      return count;
-    }
-}
-
-#if WITH_REXEC
-
-/* Execute /etc/rmt as user USER on remote system HOST using rexec.
-   Return a file descriptor of a bidirectional socket for stdin and
-   stdout.  If USER is zero, use the current username.
-
-   By default, this code is not used, since it requires that the user
-   have a .netrc file in his/her home directory, or that the
-   application designer be willing to have rexec prompt for login and
-   password info.  This may be unacceptable, and .rhosts files for use
-   with rsh are much more common on BSD systems.  */
-static int
-_rmt_rexec (char *host, char *user)
-{
-  int saved_stdin = dup (STDIN_FILENO);
-  int saved_stdout = dup (STDOUT_FILENO);
-  struct servent *rexecserv;
-  int result;
-
-  /* When using cpio -o < filename, stdin is no longer the tty.  But the
-     rexec subroutine reads the login and the passwd on stdin, to allow
-     remote execution of the command.  So, reopen stdin and stdout on
-     /dev/tty before the rexec and give them back their original value
-     after.  */
-
-  if (! freopen ("/dev/tty", "r", stdin))
-    freopen ("/dev/null", "r", stdin);
-  if (! freopen ("/dev/tty", "w", stdout))
-    freopen ("/dev/null", "w", stdout);
-
-  if (rexecserv = getservbyname ("exec", "tcp"), !rexecserv)
-    error (EXIT_ON_EXEC_ERROR, 0, _("exec/tcp: Service not available"));
-
-  result = rexec (&host, rexecserv->s_port, user, 0, rmt_command, 0);
-  if (fclose (stdin) == EOF)
-    error (0, errno, _("stdin"));
-  fdopen (saved_stdin, "r");
-  if (fclose (stdout) == EOF)
-    error (0, errno, _("stdout"));
-  fdopen (saved_stdout, "w");
-
-  return result;
-}
-
-#endif /* WITH_REXEC */
-
-/* Place into BUF a string representing OFLAG, which must be suitable
-   as argument 2 of `open'.  BUF must be large enough to hold the
-   result.  This function should generate a string that decode_oflag
-   can parse.  */
-static void
-encode_oflag (char *buf, int oflag)
-{
-  sprintf (buf, "%d ", oflag);
-
-  switch (oflag & O_ACCMODE)
-    {
-    case O_RDONLY: strcat (buf, "O_RDONLY"); break;
-    case O_RDWR: strcat (buf, "O_RDWR"); break;
-    case O_WRONLY: strcat (buf, "O_WRONLY"); break;
-    default: abort ();
-    }
-
-#ifdef O_APPEND
-  if (oflag & O_APPEND) strcat (buf, "|O_APPEND");
-#endif
-  if (oflag & O_CREAT) strcat (buf, "|O_CREAT");
-#ifdef O_DSYNC
-  if (oflag & O_DSYNC) strcat (buf, "|O_DSYNC");
-#endif
-  if (oflag & O_EXCL) strcat (buf, "|O_EXCL");
-#ifdef O_LARGEFILE
-  if (oflag & O_LARGEFILE) strcat (buf, "|O_LARGEFILE");
-#endif
-#ifdef O_NOCTTY
-  if (oflag & O_NOCTTY) strcat (buf, "|O_NOCTTY");
-#endif
-  if (oflag & O_NONBLOCK) strcat (buf, "|O_NONBLOCK");
-#ifdef O_RSYNC
-  if (oflag & O_RSYNC) strcat (buf, "|O_RSYNC");
-#endif
-#ifdef O_SYNC
-  if (oflag & O_SYNC) strcat (buf, "|O_SYNC");
-#endif
-  if (oflag & O_TRUNC) strcat (buf, "|O_TRUNC");
-}
-
-/* Open a file (a magnetic tape device?) on the system specified in
-   FILE_NAME, as the given user. FILE_NAME has the form `[USER@]HOST:FILE'.
-   OPEN_MODE is O_RDONLY, O_WRONLY, etc.  If successful, return the
-   remote pipe number plus BIAS.  REMOTE_SHELL may be overridden.  On
-   error, return -1.  */
-int
-rmt_open__ (const char *file_name, int open_mode, int bias,
-            const char *remote_shell)
-{
-  int remote_pipe_number;	/* pseudo, biased file descriptor */
-  char *file_name_copy;		/* copy of file_name string */
-  char *remote_host;		/* remote host name */
-  char *remote_file;		/* remote file name (often a device) */
-  char *remote_user;		/* remote user name */
-
-  /* Find an unused pair of file descriptors.  */
-
-  for (remote_pipe_number = 0;
-       remote_pipe_number < MAXUNIT;
-       remote_pipe_number++)
-    if (READ_SIDE (remote_pipe_number) == -1
-	&& WRITE_SIDE (remote_pipe_number) == -1)
-      break;
-
-  if (remote_pipe_number == MAXUNIT)
-    {
-      errno = EMFILE;
-      return -1;
-    }
-
-  /* Pull apart the system and device, and optional user.  */
-
-  {
-    char *cursor;
-
-    file_name_copy = xstrdup (file_name);
-    remote_host = file_name_copy;
-    remote_user = 0;
-    remote_file = 0;
-
-    for (cursor = file_name_copy; *cursor; cursor++)
-      switch (*cursor)
-	{
-	default:
-	  break;
-
-	case '\n':
-	  /* Do not allow newlines in the file_name, since the protocol
-	     uses newline delimiters.  */
-	  free (file_name_copy);
-	  errno = ENOENT;
-	  return -1;
-
-	case '@':
-	  if (!remote_user)
-	    {
-	      remote_user = remote_host;
-	      *cursor = '\0';
-	      remote_host = cursor + 1;
-	    }
-	  break;
-
-	case ':':
-	  if (!remote_file)
-	    {
-	      *cursor = '\0';
-	      remote_file = cursor + 1;
-	    }
-	  break;
-	}
-  }
-
-  /* FIXME: Should somewhat validate the decoding, here.  */
-
-  if (remote_user && *remote_user == '\0')
-    remote_user = 0;
-
-#if WITH_REXEC
-
-  /* Execute the remote command using rexec.  */
-
-  READ_SIDE (remote_pipe_number) = _rmt_rexec (remote_host, remote_user);
-  if (READ_SIDE (remote_pipe_number) < 0)
-    {
-      int e = errno;
-      free (file_name_copy);
-      errno = e;
-      return -1;
-    }
-
-  WRITE_SIDE (remote_pipe_number) = READ_SIDE (remote_pipe_number);
-
-#else /* not WITH_REXEC */
-  {
-    const char *remote_shell_basename;
-    pid_t status;
-
-    /* Identify the remote command to be executed.  */
-
-    if (!remote_shell)
-      {
-#ifdef REMOTE_SHELL
-	remote_shell = REMOTE_SHELL;
-#else
-	free (file_name_copy);
-	errno = EIO;
-	return -1;
-#endif
-      }
-    remote_shell_basename = base_name (remote_shell);
-
-    /* Set up the pipes for the `rsh' command, and fork.  */
-
-    if (pipe (to_remote[remote_pipe_number]) == -1
-	|| pipe (from_remote[remote_pipe_number]) == -1)
-      {
-	int e = errno;
-	free (file_name_copy);
-	errno = e;
-	return -1;
-      }
-
-    status = fork ();
-    if (status == -1)
-      {
-	int e = errno;
-	free (file_name_copy);
-	errno = e;
-	return -1;
-      }
-
-    if (status == 0)
-      {
-	/* Child.  */
-
-	close (STDIN_FILENO);
-	dup (to_remote[remote_pipe_number][PREAD]);
-	close (to_remote[remote_pipe_number][PREAD]);
-	close (to_remote[remote_pipe_number][PWRITE]);
-
-	close (STDOUT_FILENO);
-	dup (from_remote[remote_pipe_number][PWRITE]);
-	close (from_remote[remote_pipe_number][PREAD]);
-	close (from_remote[remote_pipe_number][PWRITE]);
-
-	sys_reset_uid_gid ();
-
-	if (remote_user)
-	  execl (remote_shell, remote_shell_basename, remote_host,
-		 "-l", remote_user, rmt_command, (char *) 0);
-	else
-	  execl (remote_shell, remote_shell_basename, remote_host,
-		 rmt_command, (char *) 0);
-
-	/* Bad problems if we get here.  */
-
-	/* In a previous version, _exit was used here instead of exit.  */
-	error (EXIT_ON_EXEC_ERROR, errno, _("Cannot execute remote shell"));
-      }
-
-    /* Parent.  */
-
-    close (from_remote[remote_pipe_number][PWRITE]);
-    close (to_remote[remote_pipe_number][PREAD]);
-  }
-#endif /* not WITH_REXEC */
-
-  /* Attempt to open the tape device.  */
-
-  {
-    size_t remote_file_len = strlen (remote_file);
-    char *command_buffer = xmalloc (remote_file_len + 1000);
-    sprintf (command_buffer, "O%s\n", remote_file);
-    encode_oflag (command_buffer + remote_file_len + 2, open_mode);
-    strcat (command_buffer, "\n");
-    if (do_command (remote_pipe_number, command_buffer) == -1
-	|| get_status (remote_pipe_number) == -1)
-      {
-	int e = errno;
-	free (command_buffer);
-	free (file_name_copy);
-	_rmt_shutdown (remote_pipe_number, e);
-	return -1;
-      }
-    free (command_buffer);
-  }
-
-  free (file_name_copy);
-  return remote_pipe_number + bias;
-}
-
-/* Close remote tape connection HANDLE and shut down.  Return 0 if
-   successful, -1 on error.  */
-int
-rmt_close__ (int handle)
-{
-  long int status;
-
-  if (do_command (handle, "C\n") == -1)
-    return -1;
-
-  status = get_status (handle);
-  _rmt_shutdown (handle, errno);
-  return status;
-}
-
-/* Read up to LENGTH bytes into BUFFER from remote tape connection HANDLE.
-   Return the number of bytes read on success, SAFE_READ_ERROR on error.  */
-size_t
-rmt_read__ (int handle, char *buffer, size_t length)
-{
-  char command_buffer[COMMAND_BUFFER_SIZE];
-  size_t status;
-  size_t rlen;
-  size_t counter;
-
-  sprintf (command_buffer, "R%lu\n", (unsigned long) length);
-  if (do_command (handle, command_buffer) == -1
-      || (status = get_status (handle)) == SAFE_READ_ERROR
-      || status > length)
-    return SAFE_READ_ERROR;
-
-  for (counter = 0; counter < status; counter += rlen, buffer += rlen)
-    {
-      rlen = safe_read (READ_SIDE (handle), buffer, status - counter);
-      if (rlen == SAFE_READ_ERROR || rlen == 0)
-	{
-	  _rmt_shutdown (handle, EIO);
-	  return SAFE_READ_ERROR;
-	}
-    }
-
-  return status;
-}
-
-/* Write LENGTH bytes from BUFFER to remote tape connection HANDLE.
-   Return the number of bytes written.  */
-size_t
-rmt_write__ (int handle, char *buffer, size_t length)
-{
-  char command_buffer[COMMAND_BUFFER_SIZE];
-  RETSIGTYPE (*pipe_handler) ();
-  size_t written;
-
-  sprintf (command_buffer, "W%lu\n", (unsigned long) length);
-  if (do_command (handle, command_buffer) == -1)
-    return 0;
-
-  pipe_handler = signal (SIGPIPE, SIG_IGN);
-  written = full_write (WRITE_SIDE (handle), buffer, length);
-  signal (SIGPIPE, pipe_handler);
-  if (written == length)
-    {
-      long int r = get_status (handle);
-      if (r < 0)
-	return 0;
-      if (r == length)
-	return length;
-      written = r;
-    }
-
-  /* Write error.  */
-
-  _rmt_shutdown (handle, EIO);
-  return written;
-}
-
-/* Perform an imitation lseek operation on remote tape connection
-   HANDLE.  Return the new file offset if successful, -1 if on error.  */
-off_t
-rmt_lseek__ (int handle, off_t offset, int whence)
-{
-  char command_buffer[COMMAND_BUFFER_SIZE];
-  char operand_buffer[UINTMAX_STRSIZE_BOUND];
-  uintmax_t u = offset < 0 ? - (uintmax_t) offset : (uintmax_t) offset;
-  char *p = operand_buffer + sizeof operand_buffer;
-
-  *--p = 0;
-  do
-    *--p = '0' + (int) (u % 10);
-  while ((u /= 10) != 0);
-  if (offset < 0)
-    *--p = '-';
-
-  switch (whence)
-    {
-    case SEEK_SET: whence = 0; break;
-    case SEEK_CUR: whence = 1; break;
-    case SEEK_END: whence = 2; break;
-    default: abort ();
-    }
-
-  sprintf (command_buffer, "L%s\n%d\n", p, whence);
-
-  if (do_command (handle, command_buffer) == -1)
-    return -1;
-
-  return get_status_off (handle);
-}
-
-/* Perform a raw tape operation on remote tape connection HANDLE.
-   Return the results of the ioctl, or -1 on error.  */
-int
-rmt_ioctl__ (int handle, int operation, char *argument)
-{
-  switch (operation)
-    {
-    default:
-      errno = EOPNOTSUPP;
-      return -1;
-
-#ifdef MTIOCTOP
-    case MTIOCTOP:
-      {
-	char command_buffer[COMMAND_BUFFER_SIZE];
-	char operand_buffer[UINTMAX_STRSIZE_BOUND];
-	uintmax_t u = (((struct mtop *) argument)->mt_count < 0
-		       ? - (uintmax_t) ((struct mtop *) argument)->mt_count
-		       : (uintmax_t) ((struct mtop *) argument)->mt_count);
-	char *p = operand_buffer + sizeof operand_buffer;
-
-        *--p = 0;
-	do
-	  *--p = '0' + (int) (u % 10);
-	while ((u /= 10) != 0);
-	if (((struct mtop *) argument)->mt_count < 0)
-	  *--p = '-';
-
-	/* MTIOCTOP is the easy one.  Nothing is transferred in binary.  */
-
-	sprintf (command_buffer, "I%d\n%s\n",
-		 ((struct mtop *) argument)->mt_op, p);
-	if (do_command (handle, command_buffer) == -1)
-	  return -1;
-
-	return get_status (handle);
-      }
-#endif /* MTIOCTOP */
-
-#ifdef MTIOCGET
-    case MTIOCGET:
-      {
-	ssize_t status;
-	size_t counter;
-
-	/* Grab the status and read it directly into the structure.  This
-	   assumes that the status buffer is not padded and that 2 shorts
-	   fit in a long without any word alignment problems; i.e., the
-	   whole struct is contiguous.  NOTE - this is probably NOT a good
-	   assumption.  */
-
-	if (do_command (handle, "S") == -1
-	    || (status = get_status (handle), status == -1))
-	  return -1;
-
-	for (; status > 0; status -= counter, argument += counter)
-	  {
-	    counter = safe_read (READ_SIDE (handle), argument, status);
-	    if (counter == SAFE_READ_ERROR || counter == 0)
-	      {
-		_rmt_shutdown (handle, EIO);
-		return -1;
-	      }
-	  }
-
-	/* Check for byte position.  mt_type (or mt_model) is a small integer
-	   field (normally) so we will check its magnitude.  If it is larger
-	   than 256, we will assume that the bytes are swapped and go through
-	   and reverse all the bytes.  */
-
-	if (((struct mtget *) argument)->MTIO_CHECK_FIELD < 256)
-	  return 0;
-
-	for (counter = 0; counter < status; counter += 2)
-	  {
-	    char copy = argument[counter];
-
-	    argument[counter] = argument[counter + 1];
-	    argument[counter + 1] = copy;
-	  }
-
-	return 0;
-      }
-#endif /* MTIOCGET */
-
-    }
-}
diff --git a/contrib/cpio/lib/safe-read.c b/contrib/cpio/lib/safe-read.c
deleted file mode 100644
index b7bf1d5cd60..00000000000
--- a/contrib/cpio/lib/safe-read.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/* An interface to read and write that retries after interrupts.
-
-   Copyright (C) 1993, 1994, 1998, 2002, 2003, 2004, 2005, 2006 Free
-   Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-/* Specification.  */
-#ifdef SAFE_WRITE
-# include "safe-write.h"
-#else
-# include "safe-read.h"
-#endif
-
-/* Get ssize_t.  */
-#include 
-#include 
-
-#include 
-
-#ifdef EINTR
-# define IS_EINTR(x) ((x) == EINTR)
-#else
-# define IS_EINTR(x) 0
-#endif
-
-#include 
-
-#ifdef SAFE_WRITE
-# define safe_rw safe_write
-# define rw write
-#else
-# define safe_rw safe_read
-# define rw read
-# undef const
-# define const /* empty */
-#endif
-
-/* Read(write) up to COUNT bytes at BUF from(to) descriptor FD, retrying if
-   interrupted.  Return the actual number of bytes read(written), zero for EOF,
-   or SAFE_READ_ERROR(SAFE_WRITE_ERROR) upon error.  */
-size_t
-safe_rw (int fd, void const *buf, size_t count)
-{
-  /* Work around a bug in Tru64 5.1.  Attempting to read more than
-     INT_MAX bytes fails with errno == EINVAL.  See
-     .
-     When decreasing COUNT, keep it block-aligned.  */
-  enum { BUGGY_READ_MAXIMUM = INT_MAX & ~8191 };
-
-  for (;;)
-    {
-      ssize_t result = rw (fd, buf, count);
-
-      if (0 <= result)
-	return result;
-      else if (IS_EINTR (errno))
-	continue;
-      else if (errno == EINVAL && BUGGY_READ_MAXIMUM < count)
-	count = BUGGY_READ_MAXIMUM;
-      else
-	return result;
-    }
-}
diff --git a/contrib/cpio/lib/safe-read.h b/contrib/cpio/lib/safe-read.h
deleted file mode 100644
index 3451955ad4f..00000000000
--- a/contrib/cpio/lib/safe-read.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* An interface to read() that retries after interrupts.
-   Copyright (C) 2002, 2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#define SAFE_READ_ERROR ((size_t) -1)
-
-/* Read up to COUNT bytes at BUF from descriptor FD, retrying if interrupted.
-   Return the actual number of bytes read, zero for EOF, or SAFE_READ_ERROR
-   upon error.  */
-extern size_t safe_read (int fd, void *buf, size_t count);
-
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/contrib/cpio/lib/safe-write.c b/contrib/cpio/lib/safe-write.c
deleted file mode 100644
index 4c375a6ca19..00000000000
--- a/contrib/cpio/lib/safe-write.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/* An interface to write that retries after interrupts.
-   Copyright (C) 2002 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#define SAFE_WRITE
-#include "safe-read.c"
diff --git a/contrib/cpio/lib/safe-write.h b/contrib/cpio/lib/safe-write.h
deleted file mode 100644
index c194636209f..00000000000
--- a/contrib/cpio/lib/safe-write.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* An interface to write() that retries after interrupts.
-   Copyright (C) 2002 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-#define SAFE_WRITE_ERROR ((size_t) -1)
-
-/* Write up to COUNT bytes at BUF to descriptor FD, retrying if interrupted.
-   Return the actual number of bytes written, zero for EOF, or SAFE_WRITE_ERROR
-   upon error.  */
-extern size_t safe_write (int fd, const void *buf, size_t count);
diff --git a/contrib/cpio/lib/savedir.c b/contrib/cpio/lib/savedir.c
deleted file mode 100644
index d930fb4af27..00000000000
--- a/contrib/cpio/lib/savedir.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/* savedir.c -- save the list of files in a directory in a string
-
-   Copyright (C) 1990, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
-   2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by David MacKenzie . */
-
-#include 
-
-#include "savedir.h"
-
-#include 
-
-#include 
-
-#include 
-#ifndef _D_EXACT_NAMLEN
-# define _D_EXACT_NAMLEN(dp)	strlen ((dp)->d_name)
-#endif
-
-#include 
-#include 
-#include 
-
-#include "openat.h"
-#include "xalloc.h"
-
-#ifndef NAME_SIZE_DEFAULT
-# define NAME_SIZE_DEFAULT 512
-#endif
-
-/* The results of opendir() in this file are not used with dirfd and fchdir,
-   therefore save some unnecessary work in fchdir.c.  */
-#undef opendir
-#undef closedir
-
-/* Return a freshly allocated string containing the file names
-   in directory DIRP, separated by '\0' characters;
-   the end is marked by two '\0' characters in a row.
-   Return NULL (setting errno) if DIRP cannot be read or closed.
-   If DIRP is NULL, return NULL without affecting errno.  */
-
-static char *
-savedirstream (DIR *dirp)
-{
-  char *name_space;
-  size_t allocated = NAME_SIZE_DEFAULT;
-  size_t used = 0;
-  int save_errno;
-
-  if (dirp == NULL)
-    return NULL;
-
-  name_space = xmalloc (allocated);
-
-  for (;;)
-    {
-      struct dirent const *dp;
-      char const *entry;
-
-      errno = 0;
-      dp = readdir (dirp);
-      if (! dp)
-	break;
-
-      /* Skip "", ".", and "..".  "" is returned by at least one buggy
-         implementation: Solaris 2.4 readdir on NFS file systems.  */
-      entry = dp->d_name;
-      if (entry[entry[0] != '.' ? 0 : entry[1] != '.' ? 1 : 2] != '\0')
-	{
-	  size_t entry_size = _D_EXACT_NAMLEN (dp) + 1;
-	  if (used + entry_size < used)
-	    xalloc_die ();
-	  if (allocated <= used + entry_size)
-	    {
-	      do
-		{
-		  if (2 * allocated < allocated)
-		    xalloc_die ();
-		  allocated *= 2;
-		}
-	      while (allocated <= used + entry_size);
-
-	      name_space = xrealloc (name_space, allocated);
-	    }
-	  memcpy (name_space + used, entry, entry_size);
-	  used += entry_size;
-	}
-    }
-  name_space[used] = '\0';
-  save_errno = errno;
-  if (closedir (dirp) != 0)
-    save_errno = errno;
-  if (save_errno != 0)
-    {
-      free (name_space);
-      errno = save_errno;
-      return NULL;
-    }
-  return name_space;
-}
-
-/* Return a freshly allocated string containing the file names
-   in directory DIR, separated by '\0' characters;
-   the end is marked by two '\0' characters in a row.
-   Return NULL (setting errno) if DIR cannot be opened, read, or closed.  */
-
-char *
-savedir (char const *dir)
-{
-  return savedirstream (opendir (dir));
-}
-
-/* Return a freshly allocated string containing the file names
-   in directory FD, separated by '\0' characters;
-   the end is marked by two '\0' characters in a row.
-   Return NULL (setting errno) if FD cannot be read or closed.  */
-
-char *
-fdsavedir (int fd)
-{
-  return savedirstream (fdopendir (fd));
-}
diff --git a/contrib/cpio/lib/savedir.h b/contrib/cpio/lib/savedir.h
deleted file mode 100644
index 5b7bef97134..00000000000
--- a/contrib/cpio/lib/savedir.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Save the list of files in a directory in a string.
-
-   Copyright (C) 1997, 1999, 2001, 2003, 2005 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by David MacKenzie . */
-
-#if !defined SAVEDIR_H_
-# define SAVEDIR_H_
-
-char *savedir (char const *dir);
-char *fdsavedir (int fd);
-
-#endif
diff --git a/contrib/cpio/lib/strchrnul.c b/contrib/cpio/lib/strchrnul.c
deleted file mode 100644
index 07014be17af..00000000000
--- a/contrib/cpio/lib/strchrnul.c
+++ /dev/null
@@ -1,32 +0,0 @@
-/* Searching in a string.
-   Copyright (C) 2003, 2007 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-/* Specification.  */
-#include 
-
-/* Find the first occurrence of C in S or the final NUL byte.  */
-char *
-strchrnul (const char *s, int c_in)
-{
-  char c = c_in;
-  while (*s && (*s != c))
-    s++;
-
-  return (char *) s;
-}
diff --git a/contrib/cpio/lib/stripslash.c b/contrib/cpio/lib/stripslash.c
deleted file mode 100644
index 342d497c899..00000000000
--- a/contrib/cpio/lib/stripslash.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/* stripslash.c -- remove redundant trailing slashes from a file name
-
-   Copyright (C) 1990, 2001, 2003-2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-#include "dirname.h"
-
-/* Remove trailing slashes from FILE.  Return true if a trailing slash
-   was removed.  This is useful when using file name completion from a
-   shell that adds a "/" after directory names (such as tcsh and
-   bash), because on symlinks to directories, several system calls
-   have different semantics according to whether a trailing slash is
-   present.  */
-
-bool
-strip_trailing_slashes (char *file)
-{
-  char *base = last_component (file);
-  char *base_lim;
-  bool had_slash;
-
-  /* last_component returns "" for file system roots, but we need to turn
-     `///' into `/'.  */
-  if (! *base)
-    base = file;
-  base_lim = base + base_len (base);
-  had_slash = (*base_lim != '\0');
-  *base_lim = '\0';
-  return had_slash;
-}
diff --git a/contrib/cpio/lib/strndup.c b/contrib/cpio/lib/strndup.c
deleted file mode 100644
index 3a1b0eae2e0..00000000000
--- a/contrib/cpio/lib/strndup.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* A replacement function, for systems that lack strndup.
-
-   Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006, 2007
-   Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU General Public License as published by the
-   Free Software Foundation; either version 2, or (at your option) any
-   later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-#include 
-
-#include 
-
-char *
-strndup (char const *s, size_t n)
-{
-  size_t len = strnlen (s, n);
-  char *new = malloc (len + 1);
-
-  if (new == NULL)
-    return NULL;
-
-  new[len] = '\0';
-  return memcpy (new, s, len);
-}
diff --git a/contrib/cpio/lib/strnlen.c b/contrib/cpio/lib/strnlen.c
deleted file mode 100644
index d346d3272c2..00000000000
--- a/contrib/cpio/lib/strnlen.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* Find the length of STRING, but scan at most MAXLEN characters.
-   Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
-   Written by Simon Josefsson.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-#include 
-
-/* Find the length of STRING, but scan at most MAXLEN characters.
-   If no '\0' terminator is found in that many characters, return MAXLEN.  */
-
-size_t
-strnlen (const char *string, size_t maxlen)
-{
-  const char *end = memchr (string, '\0', maxlen);
-  return end ? (size_t) (end - string) : maxlen;
-}
diff --git a/contrib/cpio/lib/system-ioctl.h b/contrib/cpio/lib/system-ioctl.h
deleted file mode 100644
index a61c5fdfb01..00000000000
--- a/contrib/cpio/lib/system-ioctl.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/* System dependent definitions for GNU tar's use of ioctl macros.
-
-   Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003,
-   2004, 2005, 2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* This is a real challenge to properly get MTIO* symbols :-(.  ISC uses
-   .  SCO and BSDi uses ; BSDi also requires
-    and  for defining tp_dev and tpr_t.  It
-   seems that the rest use , which itself requires other files,
-   depending on systems.  Pyramid defines _IOW in , for example.  */
-
-#if HAVE_SYS_GENTAPE_H
-# include 
-#else
-# if HAVE_SYS_TAPE_H
-#  if HAVE_SYS_DEVICE_H
-#   include 
-#  endif
-#  if HAVE_SYS_PARAM_H
-#   include 
-#  endif
-#  if HAVE_SYS_BUF_H
-#   include 
-#  endif
-#  if HAVE_SYS_TPRINTF_H
-#   include 
-#  endif
-#  include 
-# else
-#  if HAVE_SYS_MTIO_H
-#   include 
-#   if HAVE_SGTTY_H
-#    include 
-#   endif
-#   if HAVE_SYS_IO_TRIOCTL_H
-#    include 
-#   endif
-#   include 
-#  endif
-# endif
-#endif
diff --git a/contrib/cpio/lib/system.h b/contrib/cpio/lib/system.h
deleted file mode 100644
index 7602263f139..00000000000
--- a/contrib/cpio/lib/system.h
+++ /dev/null
@@ -1,475 +0,0 @@
-/* System dependent definitions for GNU tar.
-
-   Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003,
-   2004, 2005, 2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#if HAVE_CONFIG_H
-# include 
-#endif
-
-#include 
-
-#ifndef __attribute__
-/* This feature is available in gcc versions 2.5 and later.  */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
-#  define __attribute__(spec) /* empty */
-# endif
-#endif
-
-#include 
-#include 
-
-/* IN_CTYPE_DOMAIN (C) is nonzero if the unsigned char C can safely be given
-   as an argument to  macros like `isspace'.  */
-#if STDC_HEADERS
-# define IN_CTYPE_DOMAIN(c) 1
-#else
-# define IN_CTYPE_DOMAIN(c) ((unsigned) (c) <= 0177)
-#endif
-
-#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
-#define ISODIGIT(c) ((unsigned) (c) - '0' <= 7)
-#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
-#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
-
-/* Declare string and memory handling routines.  Take care that an ANSI
-   string.h and pre-ANSI memory.h might conflict, and that memory.h and
-   strings.h conflict on some systems.  */
-
-#if STDC_HEADERS || HAVE_STRING_H
-# include 
-# if !STDC_HEADERS && HAVE_MEMORY_H
-#  include 
-# endif
-#else
-# include 
-# ifndef strchr
-#  define strchr index
-# endif
-# ifndef strrchr
-#  define strrchr rindex
-# endif
-# ifndef memcpy
-#  define memcpy(d, s, n) bcopy ((char const *) (s), (char *) (d), n)
-# endif
-# ifndef memcmp
-#  define memcmp(a, b, n) bcmp ((char const *) (a), (char const *) (b), n)
-# endif
-#endif
-
-/* Declare errno.  */
-
-#include 
-#ifndef errno
-extern int errno;
-#endif
-
-/* Declare open parameters.  */
-
-#if HAVE_FCNTL_H
-# include 
-#else
-# include 
-#endif
-				/* Pick only one of the next three: */
-#ifndef O_RDONLY
-# define O_RDONLY	0	/* only allow read */
-#endif
-#ifndef O_WRONLY
-# define O_WRONLY	1	/* only allow write */
-#endif
-#ifndef O_RDWR
-# define O_RDWR		2	/* both are allowed */
-#endif
-#ifndef O_ACCMODE
-# define O_ACCMODE (O_RDONLY | O_RDWR | O_WRONLY)
-#endif
-				/* The rest can be OR-ed in to the above: */
-#ifndef O_CREAT
-# define O_CREAT	8	/* create file if needed */
-#endif
-#ifndef O_EXCL
-# define O_EXCL		16	/* file cannot already exist */
-#endif
-#ifndef O_TRUNC
-# define O_TRUNC	32	/* truncate file on open */
-#endif
-
-#ifndef O_BINARY
-# define O_BINARY 0
-#endif
-#ifndef O_DIRECTORY
-# define O_DIRECTORY 0
-#endif
-#ifndef O_NOATIME
-# define O_NOATIME 0
-#endif
-#ifndef O_NONBLOCK
-# define O_NONBLOCK 0
-#endif
-
-/* Declare file status routines and bits.  */
-
-#include 
-
-#if !HAVE_LSTAT && !defined lstat
-# define lstat stat
-#endif
-
-#if STX_HIDDEN && !_LARGE_FILES /* AIX */
-# ifdef stat
-#  undef stat
-# endif
-# define stat(file_name, buf) statx (file_name, buf, STATSIZE, STX_HIDDEN)
-# ifdef lstat
-#  undef lstat
-# endif
-# define lstat(file_name, buf) statx (file_name, buf, STATSIZE, STX_HIDDEN | STX_LINK)
-#endif
-
-#if STAT_MACROS_BROKEN
-# undef S_ISBLK
-# undef S_ISCHR
-# undef S_ISCTG
-# undef S_ISDIR
-# undef S_ISFIFO
-# undef S_ISLNK
-# undef S_ISREG
-# undef S_ISSOCK
-#endif
-
-/* On MSDOS, there are missing things from .  */
-#if MSDOS
-# define S_ISUID 0
-# define S_ISGID 0
-# define S_ISVTX 0
-#endif
-
-#ifndef S_ISDIR
-# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
-#endif
-#ifndef S_ISREG
-# define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
-#endif
-
-#ifndef S_ISBLK
-# ifdef S_IFBLK
-#  define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
-# else
-#  define S_ISBLK(mode) 0
-# endif
-#endif
-#ifndef S_ISCHR
-# ifdef S_IFCHR
-#  define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
-# else
-#  define S_ISCHR(mode) 0
-# endif
-#endif
-#ifndef S_ISCTG
-# ifdef S_IFCTG
-#  define S_ISCTG(mode) (((mode) & S_IFMT) == S_IFCTG)
-# else
-#  define S_ISCTG(mode) 0
-# endif
-#endif
-#ifndef S_ISDOOR
-# define S_ISDOOR(mode) 0
-#endif
-#ifndef S_ISFIFO
-# ifdef S_IFIFO
-#  define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
-# else
-#  define S_ISFIFO(mode) 0
-# endif
-#endif
-#ifndef S_ISLNK
-# ifdef S_IFLNK
-#  define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
-# else
-#  define S_ISLNK(mode) 0
-# endif
-#endif
-#ifndef S_ISSOCK
-# ifdef S_IFSOCK
-#  define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
-# else
-#  define S_ISSOCK(mode) 0
-# endif
-#endif
-
-#if !HAVE_MKFIFO && !defined mkfifo && defined S_IFIFO
-# define mkfifo(file_name, mode) (mknod (file_name, (mode) | S_IFIFO, 0))
-#endif
-
-#ifndef S_ISUID
-# define S_ISUID 0004000
-#endif
-#ifndef S_ISGID
-# define S_ISGID 0002000
-#endif
-#ifndef S_ISVTX
-# define S_ISVTX 0001000
-#endif
-#ifndef S_IRUSR
-# define S_IRUSR 0000400
-#endif
-#ifndef S_IWUSR
-# define S_IWUSR 0000200
-#endif
-#ifndef S_IXUSR
-# define S_IXUSR 0000100
-#endif
-#ifndef S_IRGRP
-# define S_IRGRP 0000040
-#endif
-#ifndef S_IWGRP
-# define S_IWGRP 0000020
-#endif
-#ifndef S_IXGRP
-# define S_IXGRP 0000010
-#endif
-#ifndef S_IROTH
-# define S_IROTH 0000004
-#endif
-#ifndef S_IWOTH
-# define S_IWOTH 0000002
-#endif
-#ifndef S_IXOTH
-# define S_IXOTH 0000001
-#endif
-
-#define MODE_WXUSR	(S_IWUSR | S_IXUSR)
-#define MODE_R		(S_IRUSR | S_IRGRP | S_IROTH)
-#define MODE_RW		(S_IWUSR | S_IWGRP | S_IWOTH | MODE_R)
-#define MODE_RWX	(S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW)
-#define MODE_ALL	(S_ISUID | S_ISGID | S_ISVTX | MODE_RWX)
-
-/* Include  before any preprocessor test of _POSIX_VERSION.  */
-#include 
-
-#ifndef SEEK_SET
-# define SEEK_SET 0
-#endif
-#ifndef SEEK_CUR
-# define SEEK_CUR 1
-#endif
-#ifndef SEEK_END
-# define SEEK_END 2
-#endif
-
-#ifndef STDIN_FILENO
-# define STDIN_FILENO 0
-#endif
-#ifndef STDOUT_FILENO
-# define STDOUT_FILENO 1
-#endif
-#ifndef STDERR_FILENO
-# define STDERR_FILENO 2
-#endif
-
-/* Declare make device, major and minor.  Since major is a function on
-   SVR4, we have to resort to GOT_MAJOR instead of just testing if
-   major is #define'd.  */
-
-#if MAJOR_IN_MKDEV
-# include 
-# if !defined(makedev) && defined(mkdev)
-#  define makedev(a,b) mkdev((a),(b))
-# endif
-# define GOT_MAJOR
-#endif
-
-#if MAJOR_IN_SYSMACROS
-# include 
-# define GOT_MAJOR
-#endif
-
-/* Some  defines the macros. */
-#ifdef major
-# define GOT_MAJOR
-#endif
-
-#ifndef GOT_MAJOR
-# if MSDOS
-#  define major(device)		(device)
-#  define minor(device)		(device)
-#  define makedev(major, minor)	(((major) << 8) | (minor))
-#  define GOT_MAJOR
-# endif
-#endif
-
-/* For HP-UX before HP-UX 8, major/minor are not in .  */
-#ifndef GOT_MAJOR
-# if defined(hpux) || defined(__hpux__) || defined(__hpux)
-#  include 
-#  define GOT_MAJOR
-# endif
-#endif
-
-#ifndef GOT_MAJOR
-# define major(device)		(((device) >> 8) & 0xff)
-# define minor(device)		((device) & 0xff)
-# define makedev(major, minor)	(((major) << 8) | (minor))
-#endif
-
-#undef GOT_MAJOR
-
-/* Declare wait status.  */
-
-#if HAVE_SYS_WAIT_H
-# include 
-#endif
-#ifndef WEXITSTATUS
-# define WEXITSTATUS(s)	(((s) >> 8) & 0xff)
-#endif
-#ifndef WIFSIGNALED
-# define WIFSIGNALED(s)	(((s) & 0xffff) - 1 < (unsigned) 0xff)
-#endif
-#ifndef WTERMSIG
-# define WTERMSIG(s)	((s) & 0x7f)
-#endif
-
-/* FIXME: It is wrong to use BLOCKSIZE for buffers when the logical block
-   size is greater than 512 bytes; so ST_BLKSIZE code below, in preparation
-   for some cleanup in this area, later.  */
-
-/* Extract or fake data from a `struct stat'.  ST_BLKSIZE gives the
-   optimal I/O blocksize for the file, in bytes.  Some systems, like
-   Sequents, return st_blksize of 0 on pipes.  */
-
-#define DEFAULT_ST_BLKSIZE 512
-
-#if !HAVE_ST_BLKSIZE
-# define ST_BLKSIZE(statbuf) DEFAULT_ST_BLKSIZE
-#else
-# define ST_BLKSIZE(statbuf) \
-    ((statbuf).st_blksize > 0 ? (statbuf).st_blksize : DEFAULT_ST_BLKSIZE)
-#endif
-
-/* Extract or fake data from a `struct stat'.  ST_NBLOCKS gives the
-   number of ST_NBLOCKSIZE-byte blocks in the file (including indirect blocks).
-   HP-UX counts st_blocks in 1024-byte units,
-   this loses when mixing HP-UX and BSD filesystems with NFS.  AIX PS/2
-   counts st_blocks in 4K units.  */
-
-#if !HAVE_ST_BLOCKS
-# if defined(_POSIX_SOURCE) || !defined(BSIZE)
-#  define ST_NBLOCKS(statbuf) ((statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 0))
-# else
-   off_t st_blocks ();
-#  define ST_NBLOCKS(statbuf) (st_blocks ((statbuf).st_size))
-# endif
-#else
-# define ST_NBLOCKS(statbuf) ((statbuf).st_blocks)
-# if defined(hpux) || defined(__hpux__) || defined(__hpux)
-#  define ST_NBLOCKSIZE 1024
-# else
-#  if defined(_AIX) && defined(_I386)
-#   define ST_NBLOCKSIZE (4 * 1024)
-#  endif
-# endif
-#endif
-
-#ifndef ST_NBLOCKSIZE
-# define ST_NBLOCKSIZE 512
-#endif
-
-#define ST_IS_SPARSE(st)                                  \
-  (ST_NBLOCKS (st)                                        \
-    < ((st).st_size / ST_NBLOCKSIZE + ((st).st_size % ST_NBLOCKSIZE != 0)))
-
-/* Declare standard functions.  */
-
-#if STDC_HEADERS
-# include 
-#else
-void *malloc ();
-char *getenv ();
-#endif
-
-#include 
-#include 
-
-#include 
-#if !defined _POSIX_VERSION && MSDOS
-# include 
-#endif
-
-#if WITH_DMALLOC
-# define DMALLOC_FUNC_CHECK
-# include 
-#endif
-
-#include 
-
-#ifndef MB_LEN_MAX
-# define MB_LEN_MAX 1
-#endif
-
-#include 
-
-#include 
-
-#define UINTMAX_STRSIZE_BOUND INT_BUFSIZE_BOUND (uintmax_t)
-
-/* Prototypes for external functions.  */
-
-#if HAVE_LOCALE_H
-# include 
-#endif
-#if !HAVE_SETLOCALE
-# define setlocale(category, locale) /* empty */
-#endif
-
-#include 
-#ifdef TIME_WITH_SYS_TIME
-# include 
-#endif
-
-/* Library modules.  */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#define _(msgid) gettext (msgid)
-#define N_(msgid) msgid
-
-#if MSDOS
-# include 
-# define SET_BINARY_MODE(arc) setmode(arc, O_BINARY)
-# define ERRNO_IS_EACCES errno == EACCES
-# define mkdir(file, mode) (mkdir) (file)
-# define TTY_NAME "con"
-# define sys_reset_uid_gid()
-#else
-# include 
-# include 
-# define SET_BINARY_MODE(arc)
-# define ERRNO_IS_EACCES 0
-# define TTY_NAME "/dev/tty"
-# define sys_reset_uid_gid() \
- do { setuid (getuid ()); setgid (getgid ()); } while (0)
-#endif
-
-#if XENIX
-# include 
-#endif
diff --git a/contrib/cpio/lib/umaxtostr.c b/contrib/cpio/lib/umaxtostr.c
deleted file mode 100644
index 4f49a7f8ddd..00000000000
--- a/contrib/cpio/lib/umaxtostr.c
+++ /dev/null
@@ -1,3 +0,0 @@
-#define inttostr umaxtostr
-#define inttype uintmax_t
-#include "inttostr.c"
diff --git a/contrib/cpio/lib/unlocked-io.h b/contrib/cpio/lib/unlocked-io.h
deleted file mode 100644
index d00930361c2..00000000000
--- a/contrib/cpio/lib/unlocked-io.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/* Prefer faster, non-thread-safe stdio functions if available.
-
-   Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Jim Meyering.  */
-
-#ifndef UNLOCKED_IO_H
-# define UNLOCKED_IO_H 1
-
-/* These are wrappers for functions/macros from the GNU C library, and
-   from other C libraries supporting POSIX's optional thread-safe functions.
-
-   The standard I/O functions are thread-safe.  These *_unlocked ones are
-   more efficient but not thread-safe.  That they're not thread-safe is
-   fine since all of the applications in this package are single threaded.
-
-   Also, some code that is shared with the GNU C library may invoke
-   the *_unlocked functions directly.  On hosts that lack those
-   functions, invoke the non-thread-safe versions instead.  */
-
-# include 
-
-# if HAVE_DECL_CLEARERR_UNLOCKED
-#  undef clearerr
-#  define clearerr(x) clearerr_unlocked (x)
-# else
-#  define clearerr_unlocked(x) clearerr (x)
-# endif
-
-# if HAVE_DECL_FEOF_UNLOCKED
-#  undef feof
-#  define feof(x) feof_unlocked (x)
-# else
-#  define feof_unlocked(x) feof (x)
-# endif
-
-# if HAVE_DECL_FERROR_UNLOCKED
-#  undef ferror
-#  define ferror(x) ferror_unlocked (x)
-# else
-#  define ferror_unlocked(x) ferror (x)
-# endif
-
-# if HAVE_DECL_FFLUSH_UNLOCKED
-#  undef fflush
-#  define fflush(x) fflush_unlocked (x)
-# else
-#  define fflush_unlocked(x) fflush (x)
-# endif
-
-# if HAVE_DECL_FGETS_UNLOCKED
-#  undef fgets
-#  define fgets(x,y,z) fgets_unlocked (x,y,z)
-# else
-#  define fgets_unlocked(x,y,z) fgets (x,y,z)
-# endif
-
-# if HAVE_DECL_FPUTC_UNLOCKED
-#  undef fputc
-#  define fputc(x,y) fputc_unlocked (x,y)
-# else
-#  define fputc_unlocked(x,y) fputc (x,y)
-# endif
-
-# if HAVE_DECL_FPUTS_UNLOCKED
-#  undef fputs
-#  define fputs(x,y) fputs_unlocked (x,y)
-# else
-#  define fputs_unlocked(x,y) fputs (x,y)
-# endif
-
-# if HAVE_DECL_FREAD_UNLOCKED
-#  undef fread
-#  define fread(w,x,y,z) fread_unlocked (w,x,y,z)
-# else
-#  define fread_unlocked(w,x,y,z) fread (w,x,y,z)
-# endif
-
-# if HAVE_DECL_FWRITE_UNLOCKED
-#  undef fwrite
-#  define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z)
-# else
-#  define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
-# endif
-
-# if HAVE_DECL_GETC_UNLOCKED
-#  undef getc
-#  define getc(x) getc_unlocked (x)
-# else
-#  define getc_unlocked(x) getc (x)
-# endif
-
-# if HAVE_DECL_GETCHAR_UNLOCKED
-#  undef getchar
-#  define getchar() getchar_unlocked ()
-# else
-#  define getchar_unlocked() getchar ()
-# endif
-
-# if HAVE_DECL_PUTC_UNLOCKED
-#  undef putc
-#  define putc(x,y) putc_unlocked (x,y)
-# else
-#  define putc_unlocked(x,y) putc (x,y)
-# endif
-
-# if HAVE_DECL_PUTCHAR_UNLOCKED
-#  undef putchar
-#  define putchar(x) putchar_unlocked (x)
-# else
-#  define putchar_unlocked(x) putchar (x)
-# endif
-
-# undef flockfile
-# define flockfile(x) ((void) 0)
-
-# undef ftrylockfile
-# define ftrylockfile(x) 0
-
-# undef funlockfile
-# define funlockfile(x) ((void) 0)
-
-#endif /* UNLOCKED_IO_H */
diff --git a/contrib/cpio/lib/utimens.c b/contrib/cpio/lib/utimens.c
deleted file mode 100644
index 7e3175a4951..00000000000
--- a/contrib/cpio/lib/utimens.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/* Set file access and modification times.
-
-   Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software
-   Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU General Public License as published by the
-   Free Software Foundation; either version 2, or (at your option) any
-   later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Paul Eggert.  */
-
-/* derived from a function in touch.c */
-
-#include 
-
-#include "utimens.h"
-
-#include 
-#include 
-#include 
-#include 
-
-#if HAVE_UTIME_H
-# include 
-#endif
-
-/* Some systems (even some that do have ) don't declare this
-   structure anywhere.  */
-#ifndef HAVE_STRUCT_UTIMBUF
-struct utimbuf
-{
-  long actime;
-  long modtime;
-};
-#endif
-
-/* Some systems don't have ENOSYS.  */
-#ifndef ENOSYS
-# ifdef ENOTSUP
-#  define ENOSYS ENOTSUP
-# else
-/* Some systems don't have ENOTSUP either.  */
-#  define ENOSYS EINVAL
-# endif
-#endif
-
-#ifndef __attribute__
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
-#  define __attribute__(x)
-# endif
-#endif
-
-#ifndef ATTRIBUTE_UNUSED
-# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
-#endif
-
-/* Set the access and modification time stamps of FD (a.k.a. FILE) to be
-   TIMESPEC[0] and TIMESPEC[1], respectively.
-   FD must be either negative -- in which case it is ignored --
-   or a file descriptor that is open on FILE.
-   If FD is nonnegative, then FILE can be NULL, which means
-   use just futimes (or equivalent) instead of utimes (or equivalent),
-   and fail if on an old system without futimes (or equivalent).
-   If TIMESPEC is null, set the time stamps to the current time.
-   Return 0 on success, -1 (setting errno) on failure.  */
-
-int
-gl_futimens (int fd ATTRIBUTE_UNUSED,
-	     char const *file, struct timespec const timespec[2])
-{
-  /* Some Linux-based NFS clients are buggy, and mishandle time stamps
-     of files in NFS file systems in some cases.  We have no
-     configure-time test for this, but please see
-      for references to
-     some of the problems with Linux 2.6.16.  If this affects you,
-     compile with -DHAVE_BUGGY_NFS_TIME_STAMPS; this is reported to
-     help in some cases, albeit at a cost in performance.  But you
-     really should upgrade your kernel to a fixed version, since the
-     problem affects many applications.  */
-
-#if HAVE_BUGGY_NFS_TIME_STAMPS
-  if (fd < 0)
-    sync ();
-  else
-    fsync (fd);
-#endif
-
-  /* There's currently no interface to set file timestamps with
-     nanosecond resolution, so do the best we can, discarding any
-     fractional part of the timestamp.  */
-#if HAVE_FUTIMESAT || HAVE_WORKING_UTIMES
-  struct timeval timeval[2];
-  struct timeval const *t;
-  if (timespec)
-    {
-      timeval[0].tv_sec = timespec[0].tv_sec;
-      timeval[0].tv_usec = timespec[0].tv_nsec / 1000;
-      timeval[1].tv_sec = timespec[1].tv_sec;
-      timeval[1].tv_usec = timespec[1].tv_nsec / 1000;
-      t = timeval;
-    }
-  else
-    t = NULL;
-
-
-  if (fd < 0)
-    {
-# if HAVE_FUTIMESAT
-      return futimesat (AT_FDCWD, file, t);
-# endif
-    }
-  else
-    {
-      /* If futimesat or futimes fails here, don't try to speed things
-	 up by returning right away.  glibc can incorrectly fail with
-	 errno == ENOENT if /proc isn't mounted.  Also, Mandrake 10.0
-	 in high security mode doesn't allow ordinary users to read
-	 /proc/self, so glibc incorrectly fails with errno == EACCES.
-	 If errno == EIO, EPERM, or EROFS, it's probably safe to fail
-	 right away, but these cases are rare enough that they're not
-	 worth optimizing, and who knows what other messed-up systems
-	 are out there?  So play it safe and fall back on the code
-	 below.  */
-# if HAVE_FUTIMESAT
-      if (futimesat (fd, NULL, t) == 0)
-	return 0;
-# elif HAVE_FUTIMES
-      if (futimes (fd, t) == 0)
-	return 0;
-# endif
-    }
-#endif
-
-  if (!file)
-    {
-#if ! (HAVE_FUTIMESAT || (HAVE_WORKING_UTIMES && HAVE_FUTIMES))
-      errno = ENOSYS;
-#endif
-
-      /* Prefer EBADF to ENOSYS if both error numbers apply.  */
-      if (errno == ENOSYS)
-	{
-	  int fd2 = dup (fd);
-	  int dup_errno = errno;
-	  if (0 <= fd2)
-	    close (fd2);
-	  errno = (fd2 < 0 && dup_errno == EBADF ? EBADF : ENOSYS);
-	}
-
-      return -1;
-    }
-
-#if HAVE_WORKING_UTIMES
-  return utimes (file, t);
-#else
-  {
-    struct utimbuf utimbuf;
-    struct utimbuf const *ut;
-    if (timespec)
-      {
-	utimbuf.actime = timespec[0].tv_sec;
-	utimbuf.modtime = timespec[1].tv_sec;
-	ut = &utimbuf;
-      }
-    else
-      ut = NULL;
-
-    return utime (file, ut);
-  }
-#endif
-}
-
-/* Set the access and modification time stamps of FILE to be
-   TIMESPEC[0] and TIMESPEC[1], respectively.  */
-int
-utimens (char const *file, struct timespec const timespec[2])
-{
-  return gl_futimens (-1, file, timespec);
-}
diff --git a/contrib/cpio/lib/utimens.h b/contrib/cpio/lib/utimens.h
deleted file mode 100644
index 169521da73a..00000000000
--- a/contrib/cpio/lib/utimens.h
+++ /dev/null
@@ -1,3 +0,0 @@
-#include 
-int gl_futimens (int, char const *, struct timespec const [2]);
-int utimens (char const *, struct timespec const [2]);
diff --git a/contrib/cpio/lib/xalloc-die.c b/contrib/cpio/lib/xalloc-die.c
deleted file mode 100644
index 090f060df78..00000000000
--- a/contrib/cpio/lib/xalloc-die.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/* Report a memory allocation failure and exit.
-
-   Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2006 Free
-   Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-#include "xalloc.h"
-
-#include 
-
-#include "error.h"
-#include "exitfail.h"
-
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-
-void
-xalloc_die (void)
-{
-  error (exit_failure, 0, "%s", _("memory exhausted"));
-
-  /* The `noreturn' cannot be given to error, since it may return if
-     its first argument is 0.  To help compilers understand the
-     xalloc_die does not return, call abort.  Also, the abort is a
-     safety feature if exit_failure is 0 (which shouldn't happen).  */
-  abort ();
-}
diff --git a/contrib/cpio/lib/xalloc.h b/contrib/cpio/lib/xalloc.h
deleted file mode 100644
index 0c6d8dcf508..00000000000
--- a/contrib/cpio/lib/xalloc.h
+++ /dev/null
@@ -1,271 +0,0 @@
-/* xalloc.h -- malloc with out-of-memory checking
-
-   Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef XALLOC_H_
-# define XALLOC_H_
-
-# include 
-
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-
-# ifndef __attribute__
-#  if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
-#   define __attribute__(x)
-#  endif
-# endif
-
-# ifndef ATTRIBUTE_NORETURN
-#  define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
-# endif
-
-/* This function is always triggered when memory is exhausted.
-   It must be defined by the application, either explicitly
-   or by using gnulib's xalloc-die module.  This is the
-   function to call when one wants the program to die because of a
-   memory allocation failure.  */
-extern void xalloc_die (void) ATTRIBUTE_NORETURN;
-
-void *xmalloc (size_t s);
-void *xzalloc (size_t s);
-void *xcalloc (size_t n, size_t s);
-void *xrealloc (void *p, size_t s);
-void *x2realloc (void *p, size_t *pn);
-void *xmemdup (void const *p, size_t s);
-char *xstrdup (char const *str);
-
-/* Return 1 if an array of N objects, each of size S, cannot exist due
-   to size arithmetic overflow.  S must be positive and N must be
-   nonnegative.  This is a macro, not an inline function, so that it
-   works correctly even when SIZE_MAX < N.
-
-   By gnulib convention, SIZE_MAX represents overflow in size
-   calculations, so the conservative dividend to use here is
-   SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
-   However, malloc (SIZE_MAX) fails on all known hosts where
-   sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
-   exactly-SIZE_MAX allocations on such hosts; this avoids a test and
-   branch when S is known to be 1.  */
-# define xalloc_oversized(n, s) \
-    ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
-
-
-/* In the following macros, T must be an elementary or structure/union or
-   typedef'ed type, or a pointer to such a type.  To apply one of the
-   following macros to a function pointer or array type, you need to typedef
-   it first and use the typedef name.  */
-
-/* Allocate an object of type T dynamically, with error checking.  */
-/* extern t *XMALLOC (typename t); */
-# define XMALLOC(t) ((t *) xmalloc (sizeof (t)))
-
-/* Allocate memory for N elements of type T, with error checking.  */
-/* extern t *XNMALLOC (size_t n, typename t); */
-# define XNMALLOC(n, t) \
-    ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t))))
-
-/* Allocate an object of type T dynamically, with error checking,
-   and zero it.  */
-/* extern t *XZALLOC (typename t); */
-# define XZALLOC(t) ((t *) xzalloc (sizeof (t)))
-
-/* Allocate memory for N elements of type T, with error checking,
-   and zero it.  */
-/* extern t *XCALLOC (size_t n, typename t); */
-# define XCALLOC(n, t) \
-    ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t))))
-
-
-# if HAVE_INLINE
-#  define static_inline static inline
-# else
-   void *xnmalloc (size_t n, size_t s);
-   void *xnrealloc (void *p, size_t n, size_t s);
-   void *x2nrealloc (void *p, size_t *pn, size_t s);
-   char *xcharalloc (size_t n);
-# endif
-
-# ifdef static_inline
-
-/* Allocate an array of N objects, each with S bytes of memory,
-   dynamically, with error checking.  S must be nonzero.  */
-
-static_inline void *
-xnmalloc (size_t n, size_t s)
-{
-  if (xalloc_oversized (n, s))
-    xalloc_die ();
-  return xmalloc (n * s);
-}
-
-/* Change the size of an allocated block of memory P to an array of N
-   objects each of S bytes, with error checking.  S must be nonzero.  */
-
-static_inline void *
-xnrealloc (void *p, size_t n, size_t s)
-{
-  if (xalloc_oversized (n, s))
-    xalloc_die ();
-  return xrealloc (p, n * s);
-}
-
-/* If P is null, allocate a block of at least *PN such objects;
-   otherwise, reallocate P so that it contains more than *PN objects
-   each of S bytes.  *PN must be nonzero unless P is null, and S must
-   be nonzero.  Set *PN to the new number of objects, and return the
-   pointer to the new block.  *PN is never set to zero, and the
-   returned pointer is never null.
-
-   Repeated reallocations are guaranteed to make progress, either by
-   allocating an initial block with a nonzero size, or by allocating a
-   larger block.
-
-   In the following implementation, nonzero sizes are increased by a
-   factor of approximately 1.5 so that repeated reallocations have
-   O(N) overall cost rather than O(N**2) cost, but the
-   specification for this function does not guarantee that rate.
-
-   Here is an example of use:
-
-     int *p = NULL;
-     size_t used = 0;
-     size_t allocated = 0;
-
-     void
-     append_int (int value)
-       {
-	 if (used == allocated)
-	   p = x2nrealloc (p, &allocated, sizeof *p);
-	 p[used++] = value;
-       }
-
-   This causes x2nrealloc to allocate a block of some nonzero size the
-   first time it is called.
-
-   To have finer-grained control over the initial size, set *PN to a
-   nonzero value before calling this function with P == NULL.  For
-   example:
-
-     int *p = NULL;
-     size_t used = 0;
-     size_t allocated = 0;
-     size_t allocated1 = 1000;
-
-     void
-     append_int (int value)
-       {
-	 if (used == allocated)
-	   {
-	     p = x2nrealloc (p, &allocated1, sizeof *p);
-	     allocated = allocated1;
-	   }
-	 p[used++] = value;
-       }
-
-   */
-
-static_inline void *
-x2nrealloc (void *p, size_t *pn, size_t s)
-{
-  size_t n = *pn;
-
-  if (! p)
-    {
-      if (! n)
-	{
-	  /* The approximate size to use for initial small allocation
-	     requests, when the invoking code specifies an old size of
-	     zero.  64 bytes is the largest "small" request for the
-	     GNU C library malloc.  */
-	  enum { DEFAULT_MXFAST = 64 };
-
-	  n = DEFAULT_MXFAST / s;
-	  n += !n;
-	}
-    }
-  else
-    {
-      /* Set N = ceil (1.5 * N) so that progress is made if N == 1.
-	 Check for overflow, so that N * S stays in size_t range.
-	 The check is slightly conservative, but an exact check isn't
-	 worth the trouble.  */
-      if ((size_t) -1 / 3 * 2 / s <= n)
-	xalloc_die ();
-      n += (n + 1) / 2;
-    }
-
-  *pn = n;
-  return xrealloc (p, n * s);
-}
-
-/* Return a pointer to a new buffer of N bytes.  This is like xmalloc,
-   except it returns char *.  */
-
-static_inline char *
-xcharalloc (size_t n)
-{
-  return XNMALLOC (n, char);
-}
-
-# endif
-
-# ifdef __cplusplus
-}
-
-/* C++ does not allow conversions from void * to other pointer types
-   without a cast.  Use templates to work around the problem when
-   possible.  */
-
-template  inline T *
-xrealloc (T *p, size_t s)
-{
-  return (T *) xrealloc ((void *) p, s);
-}
-
-template  inline T *
-xnrealloc (T *p, size_t n, size_t s)
-{
-  return (T *) xnrealloc ((void *) p, n, s);
-}
-
-template  inline T *
-x2realloc (T *p, size_t *pn)
-{
-  return (T *) x2realloc ((void *) p, pn);
-}
-
-template  inline T *
-x2nrealloc (T *p, size_t *pn, size_t s)
-{
-  return (T *) x2nrealloc ((void *) p, pn, s);
-}
-
-template  inline T *
-xmemdup (T const *p, size_t s)
-{
-  return (T *) xmemdup ((void const *) p, s);
-}
-
-# endif
-
-
-#endif /* !XALLOC_H_ */
diff --git a/contrib/cpio/lib/xmalloc.c b/contrib/cpio/lib/xmalloc.c
deleted file mode 100644
index 318e0ddb5a7..00000000000
--- a/contrib/cpio/lib/xmalloc.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/* xmalloc.c -- malloc with out of memory checking
-
-   Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
-   Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-#if ! HAVE_INLINE
-# define static_inline
-#endif
-#include "xalloc.h"
-#undef static_inline
-
-#include 
-#include 
-
-#ifndef SIZE_MAX
-# define SIZE_MAX ((size_t) -1)
-#endif
-
-/* 1 if calloc is known to be compatible with GNU calloc.  This
-   matters if we are not also using the calloc module, which defines
-   HAVE_CALLOC and supports the GNU API even on non-GNU platforms.  */
-#if defined HAVE_CALLOC || defined __GLIBC__
-enum { HAVE_GNU_CALLOC = 1 };
-#else
-enum { HAVE_GNU_CALLOC = 0 };
-#endif
-
-/* Allocate N bytes of memory dynamically, with error checking.  */
-
-void *
-xmalloc (size_t n)
-{
-  void *p = malloc (n);
-  if (!p && n != 0)
-    xalloc_die ();
-  return p;
-}
-
-/* Change the size of an allocated block of memory P to N bytes,
-   with error checking.  */
-
-void *
-xrealloc (void *p, size_t n)
-{
-  p = realloc (p, n);
-  if (!p && n != 0)
-    xalloc_die ();
-  return p;
-}
-
-/* If P is null, allocate a block of at least *PN bytes; otherwise,
-   reallocate P so that it contains more than *PN bytes.  *PN must be
-   nonzero unless P is null.  Set *PN to the new block's size, and
-   return the pointer to the new block.  *PN is never set to zero, and
-   the returned pointer is never null.  */
-
-void *
-x2realloc (void *p, size_t *pn)
-{
-  return x2nrealloc (p, pn, 1);
-}
-
-/* Allocate S bytes of zeroed memory dynamically, with error checking.
-   There's no need for xnzalloc (N, S), since it would be equivalent
-   to xcalloc (N, S).  */
-
-void *
-xzalloc (size_t s)
-{
-  return memset (xmalloc (s), 0, s);
-}
-
-/* Allocate zeroed memory for N elements of S bytes, with error
-   checking.  S must be nonzero.  */
-
-void *
-xcalloc (size_t n, size_t s)
-{
-  void *p;
-  /* Test for overflow, since some calloc implementations don't have
-     proper overflow checks.  But omit overflow and size-zero tests if
-     HAVE_GNU_CALLOC, since GNU calloc catches overflow and never
-     returns NULL if successful.  */
-  if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s))
-      || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0)))
-    xalloc_die ();
-  return p;
-}
-
-/* Clone an object P of size S, with error checking.  There's no need
-   for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any
-   need for an arithmetic overflow check.  */
-
-void *
-xmemdup (void const *p, size_t s)
-{
-  return memcpy (xmalloc (s), p, s);
-}
-
-/* Clone STRING.  */
-
-char *
-xstrdup (char const *string)
-{
-  return xmemdup (string, strlen (string) + 1);
-}
diff --git a/contrib/cpio/lib/xstrndup.c b/contrib/cpio/lib/xstrndup.c
deleted file mode 100644
index 7ccefd798a0..00000000000
--- a/contrib/cpio/lib/xstrndup.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* Duplicate a bounded initial segment of a string, with out-of-memory
-   checking.
-   Copyright (C) 2003, 2006, 2007 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-/* Specification.  */
-#include "xstrndup.h"
-
-#include 
-#include "xalloc.h"
-
-/* Return a newly allocated copy of at most N bytes of STRING.
-   In other words, return a copy of the initial segment of length N of
-   STRING.  */
-char *
-xstrndup (const char *string, size_t n)
-{
-  char *s = strndup (string, n);
-  if (! s)
-    xalloc_die ();
-  return s;
-}
diff --git a/contrib/cpio/lib/xstrndup.h b/contrib/cpio/lib/xstrndup.h
deleted file mode 100644
index 88354cfd43a..00000000000
--- a/contrib/cpio/lib/xstrndup.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Duplicate a bounded initial segment of a string, with out-of-memory
-   checking.
-   Copyright (C) 2003 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include 
-
-/* Return a newly allocated copy of at most N bytes of STRING.
-   In other words, return a copy of the initial segment of length N of
-   STRING.  */
-extern char *xstrndup (const char *string, size_t n);
diff --git a/contrib/cpio/src/copyin.c b/contrib/cpio/src/copyin.c
deleted file mode 100644
index 56591362325..00000000000
--- a/contrib/cpio/src/copyin.c
+++ /dev/null
@@ -1,1644 +0,0 @@
-/* $FreeBSD$ */
-
-/* copyin.c - extract or list a cpio archive
-   Copyright (C) 1990,1991,1992,2001,2002,2003,2004,
-   2005, 2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-#include 
-
-#include 
-#include 
-#include 
-#include "filetypes.h"
-#include "cpiohdr.h"
-#include "dstring.h"
-#include "extern.h"
-#include "defer.h"
-#include "dirname.h"
-#include 
-#ifndef	FNM_PATHNAME
-# include 
-#endif
-#include 
-
-#ifndef HAVE_LCHOWN
-# define lchown(f,u,g) 0
-#endif
-
-static void copyin_regular_file(struct cpio_file_stat* file_hdr,
-				int in_file_des);
-
-void
-warn_junk_bytes (long bytes_skipped)
-{
-  error (0, 0, ngettext ("warning: skipped %ld byte of junk",
-			 "warning: skipped %ld bytes of junk", bytes_skipped),
-	 bytes_skipped);
-}
-
-
-static int
-query_rename(struct cpio_file_stat* file_hdr, FILE *tty_in, FILE *tty_out,
-	     FILE *rename_in)
-{
-  char *str_res;		/* Result for string function.  */
-  static dynamic_string new_name;	/* New file name for rename option.  */
-  static int initialized_new_name = false;
-  if (!initialized_new_name)
-  {
-    ds_init (&new_name, 128);
-    initialized_new_name = true;
-  }
-
-  if (rename_flag)
-    {
-      fprintf (tty_out, _("rename %s -> "), file_hdr->c_name);
-      fflush (tty_out);
-      str_res = ds_fgets (tty_in, &new_name);
-    }
-  else
-    {
-      str_res = ds_fgetstr (rename_in, &new_name, '\n');
-    }
-  if (str_res == NULL || str_res[0] == 0)
-    {
-      return -1;
-    }
-  else
-  /* Debian hack: file_hrd.c_name is sometimes set to
-     point to static memory by code in tar.c.  This
-     causes a segfault.  This has been fixed and an
-     additional check to ensure that the file name
-     is not too long has been added.  (Reported by
-     Horst Knobloch.)  This bug has been reported to
-     "bug-gnu-utils@prep.ai.mit.edu". (99/1/6) -BEM */
-    {
-      if (archive_format != arf_tar && archive_format != arf_ustar)
-	{
-	  free (file_hdr->c_name);
-	  file_hdr->c_name = xstrdup (new_name.ds_string);
-	}
-      else
-	{
-	  if (is_tar_filename_too_long (new_name.ds_string))
-	    error (0, 0, _("%s: file name too long"),
-		   new_name.ds_string);
-	  else
-	    strcpy (file_hdr->c_name, new_name.ds_string);
-	}
-    }
-  return 0;
-}
-
-/* Skip the padding on IN_FILE_DES after a header or file,
-   up to the next header.
-   The number of bytes skipped is based on OFFSET -- the current offset
-   from the last start of a header (or file) -- and the current
-   header type.  */
-
-static void
-tape_skip_padding (int in_file_des, int offset)
-{
-  int pad;
-
-  if (archive_format == arf_crcascii || archive_format == arf_newascii)
-    pad = (4 - (offset % 4)) % 4;
-  else if (archive_format == arf_binary || archive_format == arf_hpbinary)
-    pad = (2 - (offset % 2)) % 2;
-  else if (archive_format == arf_tar || archive_format == arf_ustar)
-    pad = (512 - (offset % 512)) % 512;
-  else
-    pad = 0;
-
-  if (pad != 0)
-    tape_toss_input (in_file_des, pad);
-}
-
-
-static void
-list_file(struct cpio_file_stat* file_hdr, int in_file_des)
-{
-  if (verbose_flag)
-    {
-#ifdef CP_IFLNK
-      if ((file_hdr->c_mode & CP_IFMT) == CP_IFLNK)
-	{
-	  if (archive_format != arf_tar && archive_format != arf_ustar)
-	    {
-	      char *link_name = NULL;	/* Name of hard and symbolic links.  */
-
-	      link_name = (char *) xmalloc ((unsigned int) file_hdr->c_filesize + 1);
-	      link_name[file_hdr->c_filesize] = '\0';
-	      tape_buffered_read (link_name, in_file_des, file_hdr->c_filesize);
-	      long_format (file_hdr, link_name);
-	      free (link_name);
-	      tape_skip_padding (in_file_des, file_hdr->c_filesize);
-	      return;
-	    }
-	  else
-	    {
-	      long_format (file_hdr, file_hdr->c_tar_linkname);
-	      return;
-	    }
-	}
-      else
-#endif
-	long_format (file_hdr, (char *) 0);
-    }
-  else
-    {
-      /* Debian hack: Modified to print a list of filenames
-	 terminiated by a null character when the -t and -0
-	 flags are used.  This has been submitted as a
-	 suggestion to "bug-gnu-utils@prep.ai.mit.edu".  -BEM */
-      printf ("%s%c", file_hdr->c_name, name_end);
-    }
-
-  crc = 0;
-  tape_toss_input (in_file_des, file_hdr->c_filesize);
-  tape_skip_padding (in_file_des, file_hdr->c_filesize);
-  if (only_verify_crc_flag)
-    {
-#ifdef CP_IFLNK
-      if ((file_hdr->c_mode & CP_IFMT) == CP_IFLNK)
-	{
-	  return;   /* links don't have a checksum */
-	}
-#endif
-      if (crc != file_hdr->c_chksum)
-	{
-	  error (0, 0, _("%s: checksum error (0x%lx, should be 0x%lx)"),
-		 file_hdr->c_name, crc, file_hdr->c_chksum);
-	}
-    }
-}
-
-static int
-try_existing_file (struct cpio_file_stat* file_hdr, int in_file_des,
-		   int *existing_dir)
-{
-  struct stat file_stat;
-
-  *existing_dir = false;
-  if (lstat (file_hdr->c_name, &file_stat) == 0)
-    {
-      if (S_ISDIR (file_stat.st_mode)
-	  && ((file_hdr->c_mode & CP_IFMT) == CP_IFDIR))
-	{
-	  /* If there is already a directory there that
-	     we are trying to create, don't complain about
-	     it.  */
-	  *existing_dir = true;
-	  return 0;
-	}
-      else if (!unconditional_flag
-	       && file_hdr->c_mtime <= file_stat.st_mtime)
-	{
-	  error (0, 0, _("%s not created: newer or same age version exists"),
-		 file_hdr->c_name);
-	  tape_toss_input (in_file_des, file_hdr->c_filesize);
-	  tape_skip_padding (in_file_des, file_hdr->c_filesize);
-	  return -1;	/* Go to the next file.  */
-	}
-      else if (S_ISDIR (file_stat.st_mode) 
-		? rmdir (file_hdr->c_name)
-		: unlink (file_hdr->c_name))
-	{
-	  error (0, errno, _("cannot remove current %s"),
-		 file_hdr->c_name);
-	  tape_toss_input (in_file_des, file_hdr->c_filesize);
-	  tape_skip_padding (in_file_des, file_hdr->c_filesize);
-	  return -1;	/* Go to the next file.  */
-	}
-    }
-  return 0;
-}
-
-/* The newc and crc formats store multiply linked copies of the same file 
-   in the archive only once.  The actual data is attached to the last link 
-   in the archive, and the other links all have a filesize of 0.  When a 
-   file in the archive has multiple links and a filesize of 0, its data is 
-   probably "attatched" to another file in the archive, so we can't create
-   it right away.  We have to "defer" creating it until we have created
-   the file that has the data "attatched" to it.  We keep a list of the
-   "defered" links on deferments.  */
-
-struct deferment *deferments = NULL;
-
-/* Add a file header to the deferments list.  For now they all just
-   go on one list, although we could optimize this if necessary.  */
-
-static void
-defer_copyin (struct cpio_file_stat *file_hdr)
-{
-  struct deferment *d;
-  d = create_deferment (file_hdr);
-  d->next = deferments;
-  deferments = d;
-  return;
-}
-
-/* We just created a file that (probably) has some other links to it
-   which have been defered.  Go through all of the links on the deferments
-   list and create any which are links to this file.  */
-
-static void
-create_defered_links (struct cpio_file_stat *file_hdr)
-{
-  struct deferment *d;
-  struct deferment *d_prev;
-  int	ino;
-  int 	maj;
-  int   min;
-  int 	link_res;
-  ino = file_hdr->c_ino;
-  maj = file_hdr->c_dev_maj;
-  min = file_hdr->c_dev_min;
-  d = deferments;
-  d_prev = NULL;
-  while (d != NULL)
-    {
-      if ( (d->header.c_ino == ino) && (d->header.c_dev_maj == maj)
-	  && (d->header.c_dev_min == min) )
-	{
-	  struct deferment *d_free;
-	  link_res = link_to_name (d->header.c_name, file_hdr->c_name);
-	  if (link_res < 0)
-	    {
-	      error (0, errno, _("cannot link %s to %s"),
-		     d->header.c_name, file_hdr->c_name);
-	    }
-	  if (d_prev != NULL)
-	    d_prev->next = d->next;
-	  else
-	    deferments = d->next;
-	  d_free = d;
-	  d = d->next;
-	  free_deferment (d_free);
-	}
-      else
-	{
-	  d_prev = d;
-	  d = d->next;
-	}
-    }
-}
-
-/* We are skipping a file but there might be other links to it that we
-   did not skip, so we have to copy its data for the other links.  Find
-   the first link that we didn't skip and try to create that.  That will
-   then create the other deferred links.  */
-
-static int
-create_defered_links_to_skipped (struct cpio_file_stat *file_hdr,
-				 int in_file_des)
-{
-  struct deferment *d;
-  struct deferment *d_prev;
-  int	ino;
-  int 	maj;
-  int   min;
-  if (file_hdr->c_filesize == 0)
-    {
-      /* The file doesn't have any data attached to it so we don't have
-         to bother.  */
-      return -1;
-    }
-  ino = file_hdr->c_ino;
-  maj = file_hdr->c_dev_maj;
-  min = file_hdr->c_dev_min;
-  d = deferments;
-  d_prev = NULL;
-  while (d != NULL)
-    {
-      if ( (d->header.c_ino == ino) && (d->header.c_dev_maj == maj)
-	  && (d->header.c_dev_min == min) )
-	{
-	  if (d_prev != NULL)
-	    d_prev->next = d->next;
-	  else
-	    deferments = d->next;
-	  free (file_hdr->c_name);
-	  file_hdr->c_name = xstrdup(d->header.c_name);
-	  free_deferment (d);
-	  copyin_regular_file(file_hdr, in_file_des);
-	  return 0;
-	}
-      else
-	{
-	  d_prev = d;
-	  d = d->next;
-	}
-    }
-  return -1;
-}
-
-/* If we had a multiply linked file that really was empty then we would
-   have defered all of its links, since we never found any with data
-   "attached", and they will still be on the deferment list even when
-   we are done reading the whole archive.  Write out all of these
-   empty links that are still on the deferments list.  */
-
-static void
-create_final_defers ()
-{
-  struct deferment *d;
-  int	link_res;
-  int	out_file_des;
-
-  for (d = deferments; d != NULL; d = d->next)
-    {
-      /* Debian hack: A line, which could cause an endless loop, was
-         removed (97/1/2).  It was reported by Ronald F. Guilmette to
-         the upstream maintainers. -BEM */
-      /* Debian hack:  This was reported by Horst Knobloch. This bug has
-         been reported to "bug-gnu-utils@prep.ai.mit.edu". (99/1/6) -BEM
-         */
-      link_res = link_to_maj_min_ino (d->header.c_name, 
-		    d->header.c_dev_maj, d->header.c_dev_min,
-		    d->header.c_ino);
-      if (link_res == 0)
-	{
-	  continue;
-	}
-      out_file_des = open (d->header.c_name,
-			   O_CREAT | O_WRONLY | O_BINARY, 0600);
-      if (out_file_des < 0 && create_dir_flag)
-	{
-	  create_all_directories (d->header.c_name);
-	  out_file_des = open (d->header.c_name,
-			       O_CREAT | O_WRONLY | O_BINARY,
-			       0600);
-	}
-      if (out_file_des < 0)
-	{
-	  open_error (d->header.c_name);
-	  continue;
-	}
-
-      set_perms (out_file_des, &d->header);
-
-      if (close (out_file_des) < 0)
-	close_error (d->header.c_name);
-
-    }
-}
-
-static void
-copyin_regular_file (struct cpio_file_stat* file_hdr, int in_file_des)
-{
-  int out_file_des;		/* Output file descriptor.  */
-
-  if (to_stdout_option)
-    out_file_des = STDOUT_FILENO;
-  else
-    {
-      /* Can the current file be linked to a previously copied file? */
-      if (file_hdr->c_nlink > 1
-	  && (archive_format == arf_newascii
-	      || archive_format == arf_crcascii) )
-	{
-	  int link_res;
-	  if (file_hdr->c_filesize == 0)
-	    {
-	      /* The newc and crc formats store multiply linked copies
-		 of the same file in the archive only once.  The
-		 actual data is attached to the last link in the
-		 archive, and the other links all have a filesize
-		 of 0.  Since this file has multiple links and a
-		 filesize of 0, its data is probably attatched to
-		 another file in the archive.  Save the link, and
-		 process it later when we get the actual data.  We
-		 can't just create it with length 0 and add the
-		 data later, in case the file is readonly.  We still
-		 lose if its parent directory is readonly (and we aren't
-		 running as root), but there's nothing we can do about
-		 that.  */
-	      defer_copyin (file_hdr);
-	      tape_toss_input (in_file_des, file_hdr->c_filesize);
-	      tape_skip_padding (in_file_des, file_hdr->c_filesize);
-	      return;
-	    }
-	  /* If the file has data (filesize != 0), then presumably
-	     any other links have already been defer_copyin'ed(),
-	     but GNU cpio version 2.0-2.2 didn't do that, so we
-	     still have to check for links here (and also in case
-	     the archive was created and later appeneded to). */
-	  /* Debian hack: (97/1/2) This was reported by Ronald
-	     F. Guilmette to the upstream maintainers. -BEM */
-	  link_res = link_to_maj_min_ino (file_hdr->c_name, 
-		    file_hdr->c_dev_maj, file_hdr->c_dev_min,
-					  file_hdr->c_ino);
-	  if (link_res == 0)
-	    {
-	      tape_toss_input (in_file_des, file_hdr->c_filesize);
-	      tape_skip_padding (in_file_des, file_hdr->c_filesize);
-	      return;
-	    }
-	}
-      else if (file_hdr->c_nlink > 1
-	       && archive_format != arf_tar
-	       && archive_format != arf_ustar)
-	{
-	  int link_res;
-	  /* Debian hack: (97/1/2) This was reported by Ronald
-	     F. Guilmette to the upstream maintainers. -BEM */
-	  link_res = link_to_maj_min_ino (file_hdr->c_name, 
-					  file_hdr->c_dev_maj,
-					  file_hdr->c_dev_min,
-					  file_hdr->c_ino);
-	  if (link_res == 0)
-	    {
-	      tape_toss_input (in_file_des, file_hdr->c_filesize);
-	      tape_skip_padding (in_file_des, file_hdr->c_filesize);
-	      return;
-	    }
-	}
-      else if ((archive_format == arf_tar || archive_format == arf_ustar)
-	       && file_hdr->c_tar_linkname
-	       && file_hdr->c_tar_linkname[0] != '\0')
-	{
-	  int	link_res;
-	  link_res = link_to_name (file_hdr->c_name, file_hdr->c_tar_linkname);
-	  if (link_res < 0)
-	    {
-	      error (0, errno, _("cannot link %s to %s"),
-		     file_hdr->c_tar_linkname, file_hdr->c_name);
-	    }
-	  return;
-	}
-    
-      /* If not linked, copy the contents of the file.  */
-      out_file_des = open (file_hdr->c_name,
-			   O_CREAT | O_WRONLY | O_BINARY, 0600);
-  
-      if (out_file_des < 0 && create_dir_flag)
-	{
-	  create_all_directories (file_hdr->c_name);
-	  out_file_des = open (file_hdr->c_name,
-			       O_CREAT | O_WRONLY | O_BINARY,
-			       0600);
-	}
-      
-      if (out_file_des < 0)
-	{
-	  open_error (file_hdr->c_name);
-	  tape_toss_input (in_file_des, file_hdr->c_filesize);
-	  tape_skip_padding (in_file_des, file_hdr->c_filesize);
-	  return;
-	}
-    }
-  
-  crc = 0;
-  if (swap_halfwords_flag)
-    {
-      if ((file_hdr->c_filesize % 4) == 0)
-	swapping_halfwords = true;
-      else
-	error (0, 0, _("cannot swap halfwords of %s: odd number of halfwords"),
-	       file_hdr->c_name);
-    }
-  if (swap_bytes_flag)
-    {
-      if ((file_hdr->c_filesize % 2) == 0)
-	swapping_bytes = true;
-      else
-	error (0, 0, _("cannot swap bytes of %s: odd number of bytes"),
-	       file_hdr->c_name);
-    }
-  copy_files_tape_to_disk (in_file_des, out_file_des, file_hdr->c_filesize);
-  disk_empty_output_buffer (out_file_des);
-  
-  if (to_stdout_option)
-    {
-      if (archive_format == arf_crcascii)
-	{
-	  if (crc != file_hdr->c_chksum)
-	    error (0, 0, _("%s: checksum error (0x%lx, should be 0x%lx)"),
-		   file_hdr->c_name, crc, file_hdr->c_chksum);
-	}
-      tape_skip_padding (in_file_des, file_hdr->c_filesize);
-      return;
-    }
-      
-  /* Debian hack to fix a bug in the --sparse option.
-     This bug has been reported to
-     "bug-gnu-utils@prep.ai.mit.edu".  (96/7/10) -BEM */
-  if (delayed_seek_count > 0)
-    {
-      lseek (out_file_des, delayed_seek_count-1, SEEK_CUR);
-      write (out_file_des, "", 1);
-      delayed_seek_count = 0;
-    }
-
-  set_perms (out_file_des, file_hdr);
-
-  if (close (out_file_des) < 0)
-    close_error (file_hdr->c_name);
-
-  if (archive_format == arf_crcascii)
-    {
-      if (crc != file_hdr->c_chksum)
-	error (0, 0, _("%s: checksum error (0x%lx, should be 0x%lx)"),
-	       file_hdr->c_name, crc, file_hdr->c_chksum);
-    }
-
-  tape_skip_padding (in_file_des, file_hdr->c_filesize);
-  if (file_hdr->c_nlink > 1
-      && (archive_format == arf_newascii || archive_format == arf_crcascii) )
-    {
-      /* (see comment above for how the newc and crc formats 
-	 store multiple links).  Now that we have the data 
-	 for this file, create any other links to it which
-	 we defered.  */
-      create_defered_links (file_hdr);
-    }
-}
-
-static void
-copyin_directory (struct cpio_file_stat *file_hdr, int existing_dir)
-{
-  int res;			/* Result of various function calls.  */
-#ifdef HPUX_CDF
-  int cdf_flag;                 /* True if file is a CDF.  */
-  int cdf_char;                 /* Index of `+' char indicating a CDF.  */
-#endif
-
-  if (to_stdout_option)
-    return;
-  
-  /* Strip any trailing `/'s off the filename; tar puts
-     them on.  We might as well do it here in case anybody
-     else does too, since they cause strange things to happen.  */
-  strip_trailing_slashes (file_hdr->c_name);
-
-  /* Ignore the current directory.  It must already exist,
-     and we don't want to change its permission, ownership
-     or time.  */
-  if (file_hdr->c_name[0] == '.' && file_hdr->c_name[1] == '\0')
-    {
-      return;
-    }
-
-#ifdef HPUX_CDF
-  cdf_flag = 0;
-#endif
-  if (!existing_dir)
-
-    {
-#ifdef HPUX_CDF
-      /* If the directory name ends in a + and is SUID,
-	 then it is a CDF.  Strip the trailing + from
-	 the name before creating it.  */
-      cdf_char = strlen (file_hdr->c_name) - 1;
-      if ( (cdf_char > 0) &&
-	   (file_hdr->c_mode & 04000) && 
-	   (file_hdr->c_name [cdf_char] == '+') )
-	{
-	  file_hdr->c_name [cdf_char] = '\0';
-	  cdf_flag = 1;
-	}
-#endif
-      res = mkdir (file_hdr->c_name, file_hdr->c_mode);
-    }
-  else
-    res = 0;
-  if (res < 0 && create_dir_flag)
-    {
-      create_all_directories (file_hdr->c_name);
-      res = mkdir (file_hdr->c_name, file_hdr->c_mode);
-    }
-  if (res < 0)
-    {
-      /* In some odd cases where the file_hdr->c_name includes `.',
-	 the directory may have actually been created by
-	 create_all_directories(), so the mkdir will fail
-	 because the directory exists.  If that's the case,
-	 don't complain about it.  */
-      struct stat file_stat;
-      if (errno != EEXIST)
-	{
-	  mkdir_error (file_hdr->c_name);
-	  return;
-	}
-      if (lstat (file_hdr->c_name, &file_stat))
-	{
-	  stat_error (file_hdr->c_name);
-	  return;
-	}
-      if (!(S_ISDIR (file_stat.st_mode)))
-	{
-	  error (0, 0, _("%s is not a directory"),
-		 quotearg_colon (file_hdr->c_name));
-	  return;
-	}
-    }
-
-  set_perms (-1, file_hdr); 
-}
-
-static void
-copyin_device (struct cpio_file_stat* file_hdr)
-{
-  int res;			/* Result of various function calls.  */
-
-  if (to_stdout_option)
-    return;
-
-  if (file_hdr->c_nlink > 1 && archive_format != arf_tar
-      && archive_format != arf_ustar)
-    {
-      int link_res;
-      /* Debian hack:  This was reported by Horst
-	 Knobloch. This bug has been reported to
-	 "bug-gnu-utils@prep.ai.mit.edu". (99/1/6) -BEM */
-      link_res = link_to_maj_min_ino (file_hdr->c_name, 
-		    file_hdr->c_dev_maj, file_hdr->c_dev_min,
-		    file_hdr->c_ino);
-      if (link_res == 0)
-	{
-	  return;
-	}
-    }
-  else if (archive_format == arf_ustar &&
-	   file_hdr->c_tar_linkname && 
-	   file_hdr->c_tar_linkname [0] != '\0')
-    {
-      int	link_res;
-      link_res = link_to_name (file_hdr->c_name,
-			       file_hdr->c_tar_linkname);
-      if (link_res < 0)
-	{
-	  error (0, errno, _("cannot link %s to %s"),
-		 file_hdr->c_tar_linkname, file_hdr->c_name);
-	  /* Something must be wrong, because we couldn't
-	     find the file to link to.  But can we assume
-	     that the device maj/min numbers are correct
-	     and fall through to the mknod?  It's probably
-	     safer to just return, rather than possibly
-	     creating a bogus device file.  */
-	}
-      return;
-    }
-  
-#ifdef CP_IFIFO
-  if ((file_hdr->c_mode & CP_IFMT) == CP_IFIFO)
-    res = mkfifo (file_hdr->c_name, file_hdr->c_mode);
-  else
-#endif
-    res = mknod (file_hdr->c_name, file_hdr->c_mode,
-	      makedev (file_hdr->c_rdev_maj, file_hdr->c_rdev_min));
-  if (res < 0 && create_dir_flag)
-    {
-      create_all_directories (file_hdr->c_name);
-#ifdef CP_IFIFO
-      if ((file_hdr->c_mode & CP_IFMT) == CP_IFIFO)
-	res = mkfifo (file_hdr->c_name, file_hdr->c_mode);
-      else
-#endif
-	res = mknod (file_hdr->c_name, file_hdr->c_mode,
-	      makedev (file_hdr->c_rdev_maj, file_hdr->c_rdev_min));
-    }
-  if (res < 0)
-    {
-      mknod_error (file_hdr->c_name);
-      return;
-    }
-  if (!no_chown_flag)
-    {
-      uid_t uid = set_owner_flag ? set_owner : file_hdr->c_uid;
-      gid_t gid = set_group_flag ? set_group : file_hdr->c_gid;
-      if ((chown (file_hdr->c_name, uid, gid) < 0)
-	  && errno != EPERM)
-        chown_error_details (file_hdr->c_name, uid, gid);
-    }
-  /* chown may have turned off some permissions we wanted. */
-  if (chmod (file_hdr->c_name, file_hdr->c_mode) < 0)
-    chmod_error_details (file_hdr->c_name, file_hdr->c_mode);
-  if (retain_time_flag)
-    set_file_times (-1, file_hdr->c_name, file_hdr->c_mtime,
-		    file_hdr->c_mtime);
-}
-
-static void
-copyin_link(struct cpio_file_stat *file_hdr, int in_file_des)
-{
-  char *link_name = NULL;	/* Name of hard and symbolic links.  */
-  int res;			/* Result of various function calls.  */
-
-  if (to_stdout_option)
-    return;
-
-  if (archive_format != arf_tar && archive_format != arf_ustar)
-    {
-      link_name = (char *) xmalloc ((unsigned int) file_hdr->c_filesize + 1);
-      link_name[file_hdr->c_filesize] = '\0';
-      tape_buffered_read (link_name, in_file_des, file_hdr->c_filesize);
-      tape_skip_padding (in_file_des, file_hdr->c_filesize);
-    }
-  else
-    {
-      link_name = xstrdup (file_hdr->c_tar_linkname);
-    }
-
-  res = UMASKED_SYMLINK (link_name, file_hdr->c_name,
-			 file_hdr->c_mode);
-  if (res < 0 && create_dir_flag)
-    {
-      create_all_directories (file_hdr->c_name);
-      res = UMASKED_SYMLINK (link_name, file_hdr->c_name,
-			     file_hdr->c_mode);
-    }
-  if (res < 0)
-    {
-      error (0, errno, _("%s: Cannot symlink to %s"),
-	     quotearg_colon (link_name), quote_n (1, file_hdr->c_name));
-      free (link_name);
-      return;
-    }
-  if (!no_chown_flag)
-    {
-      uid_t uid = set_owner_flag ? set_owner : file_hdr->c_uid;
-      gid_t gid = set_group_flag ? set_group : file_hdr->c_gid;
-      if ((lchown (file_hdr->c_name, uid, gid) < 0)
-  	  && errno != EPERM)
-	chown_error_details (file_hdr->c_name, uid, gid);
-    }
-  free (link_name);
-}
-
-static void
-copyin_file (struct cpio_file_stat* file_hdr, int in_file_des)
-{
-  int existing_dir;
-
-  if (!to_stdout_option
-      && try_existing_file (file_hdr, in_file_des, &existing_dir) < 0)
-    return;
-
-  /* Do the real copy or link.  */
-  switch (file_hdr->c_mode & CP_IFMT)
-    {
-    case CP_IFREG:
-      copyin_regular_file (file_hdr, in_file_des);
-      break;
-
-    case CP_IFDIR:
-      copyin_directory (file_hdr, existing_dir);
-      break;
-
-    case CP_IFCHR:
-    case CP_IFBLK:
-#ifdef CP_IFSOCK
-    case CP_IFSOCK:
-#endif
-#ifdef CP_IFIFO
-    case CP_IFIFO:
-#endif
-      copyin_device (file_hdr);
-      break;
-
-#ifdef CP_IFLNK
-    case CP_IFLNK:
-      copyin_link (file_hdr, in_file_des);
-      break;
-#endif
-
-    default:
-      error (0, 0, _("%s: unknown file type"), file_hdr->c_name);
-      tape_toss_input (in_file_des, file_hdr->c_filesize);
-      tape_skip_padding (in_file_des, file_hdr->c_filesize);
-    }
-}
-
-
-/* Current time for verbose table.  */
-static time_t current_time;
-
-
-/* Print the file described by FILE_HDR in long format.
-   If LINK_NAME is nonzero, it is the name of the file that
-   this file is a symbolic link to.  */
-
-void
-long_format (struct cpio_file_stat *file_hdr, char *link_name)
-{
-  char mbuf[11];
-  char tbuf[40];
-  time_t when;
-  char *ptbuf;
-  static int d_first = -1;
-
-  mode_string (file_hdr->c_mode, mbuf);
-  mbuf[10] = '\0';
-
-  /* Get time values ready to print.  */
-  when = file_hdr->c_mtime;
-  if (d_first < 0)
-    d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
-  if (current_time - when > 6L * 30L * 24L * 60L * 60L
-      || current_time - when < 0L)
-	ptbuf = d_first ? "%e %b  %Y" : "%b %e  %Y";
-  else
-	ptbuf = d_first ? "%e %b %R" : "%b %e %R";
-  strftime(tbuf, sizeof(tbuf), ptbuf, localtime(&when));
-  ptbuf = tbuf;
-
-  printf ("%s %3lu ", mbuf, file_hdr->c_nlink);
-
-  if (numeric_uid)
-    printf ("%-8u %-8u ", (unsigned int) file_hdr->c_uid,
-	    (unsigned int) file_hdr->c_gid);
-  else
-    printf ("%-8.8s %-8.8s ", getuser (file_hdr->c_uid),
-	    getgroup (file_hdr->c_gid));
-
-  if ((file_hdr->c_mode & CP_IFMT) == CP_IFCHR
-      || (file_hdr->c_mode & CP_IFMT) == CP_IFBLK)
-    printf ("%3lu, %3lu ", file_hdr->c_rdev_maj,
-	    file_hdr->c_rdev_min);
-  else
-    printf ("%8"PRIuMAX" ", (uintmax_t) file_hdr->c_filesize);
-
-  printf ("%s ", ptbuf);
-
-  print_name_with_quoting (file_hdr->c_name);
-  if (link_name)
-    {
-      printf (" -> ");
-      print_name_with_quoting (link_name);
-    }
-  putc ('\n', stdout);
-}
-
-void
-print_name_with_quoting (register char *p)
-{
-  register unsigned char c;
-
-  while ( (c = *p++) )
-    {
-      switch (c)
-	{
-	case '\\':
-	  printf ("\\\\");
-	  break;
-
-	case '\n':
-	  printf ("\\n");
-	  break;
-
-	case '\b':
-	  printf ("\\b");
-	  break;
-
-	case '\r':
-	  printf ("\\r");
-	  break;
-
-	case '\t':
-	  printf ("\\t");
-	  break;
-
-	case '\f':
-	  printf ("\\f");
-	  break;
-
-	case ' ':
-	  printf ("\\ ");
-	  break;
-
-	case '"':
-	  printf ("\\\"");
-	  break;
-
-	default:
-	  if (isprint (c))
-	    putchar (c);
-	  else
-	    printf ("\\%03o", (unsigned int) c);
-	}
-    }
-}
-
-/* Read a pattern file (for the -E option).  Put a list of
-   `num_patterns' elements in `save_patterns'.  Any patterns that were
-   already in `save_patterns' (from the command line) are preserved.  */
-
-static void
-read_pattern_file ()
-{
-  int max_new_patterns;
-  char **new_save_patterns;
-  int new_num_patterns;
-  int i;
-  dynamic_string pattern_name;
-  FILE *pattern_fp;
-
-  if (num_patterns < 0)
-    num_patterns = 0;
-  max_new_patterns = 1 + num_patterns;
-  new_save_patterns = (char **) xmalloc (max_new_patterns * sizeof (char *));
-  new_num_patterns = num_patterns;
-  ds_init (&pattern_name, 128);
-
-  pattern_fp = fopen (pattern_file_name, "r");
-  if (pattern_fp == NULL)
-    open_error (pattern_file_name);
-  while (ds_fgetstr (pattern_fp, &pattern_name, '\n') != NULL)
-    {
-      if (new_num_patterns >= max_new_patterns)
-	{
-	  max_new_patterns += 1;
-	  new_save_patterns = (char **)
-	    xrealloc ((char *) new_save_patterns,
-		      max_new_patterns * sizeof (char *));
-	}
-      new_save_patterns[new_num_patterns] = xstrdup (pattern_name.ds_string);
-      ++new_num_patterns;
-    }
-  if (ferror (pattern_fp) || fclose (pattern_fp) == EOF)
-    close_error (pattern_file_name);
-
-  for (i = 0; i < num_patterns; ++i)
-    new_save_patterns[i] = save_patterns[i];
-
-  save_patterns = new_save_patterns;
-  num_patterns = new_num_patterns;
-}
-
-
-uintmax_t
-from_ascii (char const *where, size_t digs, unsigned logbase)
-{
-  uintmax_t value = 0;
-  char const *buf = where;
-  char const *end = buf + digs;
-  int overflow = 0;
-  static char codetab[] = "0123456789ABCDEF";
-
-  for (; *buf == ' '; buf++)
-    {
-      if (buf == end)
-	return 0;
-    }
-
-  if (buf == end || *buf == 0)
-    return 0;
-  while (1)
-    {
-      unsigned d;
-      
-      char *p = strchr (codetab, toupper (*buf));
-      if (!p)
-	{
-	  error (0, 0, _("Malformed number %.*s"), digs, where);
-	  break;
-	}
-      
-      d = p - codetab;
-      if ((d >> logbase) > 1)
-	{
-	  error (0, 0, _("Malformed number %.*s"), digs, where);
-	  break;
-	}
-      value += d;
-      if (++buf == end || *buf == 0)
-	break;
-      overflow |= value ^ (value << logbase >> logbase);
-      value <<= logbase;
-    }
-  if (overflow)
-    error (0, 0, _("Archive value %.*s is out of range"),
-	   digs, where);
-  return value;
-}
-
-
-
-/* Return 16-bit integer I with the bytes swapped.  */
-#define swab_short(i) ((((i) << 8) & 0xff00) | (((i) >> 8) & 0x00ff))
-
-/* Read the header, including the name of the file, from file
-   descriptor IN_DES into FILE_HDR.  */
-
-void
-read_in_header (struct cpio_file_stat *file_hdr, int in_des)
-{
-  union {
-    char str[6];
-    unsigned short num;
-    struct old_cpio_header old_header;
-  } magic;
-  long bytes_skipped = 0;	/* Bytes of junk found before magic number.  */
-
-  /* Search for a valid magic number.  */
-
-  if (archive_format == arf_unknown)
-    {
-      char tmpbuf[512];
-      int check_tar;
-      int peeked_bytes;
-
-      while (archive_format == arf_unknown)
-	{
-	  peeked_bytes = tape_buffered_peek (tmpbuf, in_des, 512);
-	  if (peeked_bytes < 6)
-	    error (1, 0, _("premature end of archive"));
-
-	  if (!strncmp (tmpbuf, "070701", 6))
-	    archive_format = arf_newascii;
-	  else if (!strncmp (tmpbuf, "070707", 6))
-	    archive_format = arf_oldascii;
-	  else if (!strncmp (tmpbuf, "070702", 6))
-	    {
-	      archive_format = arf_crcascii;
-	      crc_i_flag = true;
-	    }
-	  else if ((*((unsigned short *) tmpbuf) == 070707) ||
-		   (*((unsigned short *) tmpbuf) == swab_short ((unsigned short) 070707)))
-	    archive_format = arf_binary;
-	  else if (peeked_bytes >= 512
-		   && (check_tar = is_tar_header (tmpbuf)))
-	    {
-	      if (check_tar == 2)
-		archive_format = arf_ustar;
-	      else
-		archive_format = arf_tar;
-	    }
-	  else
-	    {
-	      tape_buffered_read ((char *) tmpbuf, in_des, 1L);
-	      ++bytes_skipped;
-	    }
-	}
-    }
-
-  if (archive_format == arf_tar || archive_format == arf_ustar)
-    {
-      if (append_flag)
-	last_header_start = input_bytes - io_block_size +
-	  (in_buff - input_buffer);
-      if (bytes_skipped > 0)
-	warn_junk_bytes (bytes_skipped);
-
-      read_in_tar_header (file_hdr, in_des);
-      return;
-    }
-
-  file_hdr->c_tar_linkname = NULL;
-
-  tape_buffered_read (magic.str, in_des, 6L);
-  while (1)
-    {
-      if (append_flag)
-	last_header_start = input_bytes - io_block_size
-	  + (in_buff - input_buffer) - 6;
-      if (archive_format == arf_newascii
-	  && !strncmp (magic.str, "070701", 6))
-	{
-	  if (bytes_skipped > 0)
-	    warn_junk_bytes (bytes_skipped);
-	  file_hdr->c_magic = 070701;
-	  read_in_new_ascii (file_hdr, in_des);
-	  break;
-	}
-      if (archive_format == arf_crcascii
-	  && !strncmp (magic.str, "070702", 6))
-	{
-	  if (bytes_skipped > 0)
-	    warn_junk_bytes (bytes_skipped);
-	  file_hdr->c_magic = 070702;
-	  read_in_new_ascii (file_hdr, in_des);
-	  break;
-	}
-      if ( (archive_format == arf_oldascii || archive_format == arf_hpoldascii)
-	  && !strncmp (magic.str, "070707", 6))
-	{
-	  if (bytes_skipped > 0)
-	    warn_junk_bytes (bytes_skipped);
-	  file_hdr->c_magic = 070707;
-	  read_in_old_ascii (file_hdr, in_des);
-	  break;
-	}
-      if ( (archive_format == arf_binary || archive_format == arf_hpbinary)
-	  && (magic.num == 070707
-	      || magic.num == swab_short ((unsigned short) 070707)))
-	{
-	  /* Having to skip 1 byte because of word alignment is normal.  */
-	  if (bytes_skipped > 0)
-	    warn_junk_bytes (bytes_skipped);
-	  file_hdr->c_magic = 070707;
-	  read_in_binary (file_hdr, &magic.old_header, in_des);
-	  break;
-	}
-      bytes_skipped++;
-      memmove (magic.str, magic.str + 1, 5);
-      tape_buffered_read (magic.str, in_des, 1L);
-    }
-}
-
-/* Fill in FILE_HDR by reading an old-format ASCII format cpio header from
-   file descriptor IN_DES, except for the magic number, which is
-   already filled in.  */
-
-void
-read_in_old_ascii (struct cpio_file_stat *file_hdr, int in_des)
-{
-  struct old_ascii_header ascii_header;
-  unsigned long dev;
-
-  tape_buffered_read (ascii_header.c_dev, in_des,
-		      sizeof ascii_header - sizeof ascii_header.c_magic);
-  dev = FROM_OCTAL (ascii_header.c_dev);
-  file_hdr->c_dev_maj = major (dev);
-  file_hdr->c_dev_min = minor (dev);
-
-  file_hdr->c_ino = FROM_OCTAL (ascii_header.c_ino);
-  file_hdr->c_mode = FROM_OCTAL (ascii_header.c_mode);
-  file_hdr->c_uid = FROM_OCTAL (ascii_header.c_uid);
-  file_hdr->c_gid = FROM_OCTAL (ascii_header.c_gid);
-  file_hdr->c_nlink = FROM_OCTAL (ascii_header.c_nlink);
-  dev = FROM_OCTAL (ascii_header.c_rdev);
-  file_hdr->c_rdev_maj = major (dev);
-  file_hdr->c_rdev_min = minor (dev);
-
-  file_hdr->c_mtime = FROM_OCTAL (ascii_header.c_mtime);
-  file_hdr->c_namesize = FROM_OCTAL (ascii_header.c_namesize);
-  file_hdr->c_filesize = FROM_OCTAL (ascii_header.c_filesize);
-  
-  /* Read file name from input.  */
-  if (file_hdr->c_name != NULL)
-    free (file_hdr->c_name);
-  file_hdr->c_name = (char *) xmalloc (file_hdr->c_namesize + 1);
-  tape_buffered_read (file_hdr->c_name, in_des, (long) file_hdr->c_namesize);
-
-  /* HP/UX cpio creates archives that look just like ordinary archives,
-     but for devices it sets major = 0, minor = 1, and puts the
-     actual major/minor number in the filesize field.  See if this
-     is an HP/UX cpio archive, and if so fix it.  We have to do this
-     here because process_copy_in() assumes filesize is always 0
-     for devices.  */
-  switch (file_hdr->c_mode & CP_IFMT)
-    {
-      case CP_IFCHR:
-      case CP_IFBLK:
-#ifdef CP_IFSOCK
-      case CP_IFSOCK:
-#endif
-#ifdef CP_IFIFO
-      case CP_IFIFO:
-#endif
-	if (file_hdr->c_filesize != 0
-	    && file_hdr->c_rdev_maj == 0
-	    && file_hdr->c_rdev_min == 1)
-	  {
-	    file_hdr->c_rdev_maj = major (file_hdr->c_filesize);
-	    file_hdr->c_rdev_min = minor (file_hdr->c_filesize);
-	    file_hdr->c_filesize = 0;
-	  }
-	break;
-      default:
-	break;
-    }
-}
-
-/* Fill in FILE_HDR by reading a new-format ASCII format cpio header from
-   file descriptor IN_DES, except for the magic number, which is
-   already filled in.  */
-
-void
-read_in_new_ascii (struct cpio_file_stat *file_hdr, int in_des)
-{
-  struct new_ascii_header ascii_header;
-
-  tape_buffered_read (ascii_header.c_ino, in_des,
-		      sizeof ascii_header - sizeof ascii_header.c_magic);
-
-  file_hdr->c_ino = FROM_HEX (ascii_header.c_ino);
-  file_hdr->c_mode = FROM_HEX (ascii_header.c_mode);
-  file_hdr->c_uid = FROM_HEX (ascii_header.c_uid);
-  file_hdr->c_gid = FROM_HEX (ascii_header.c_gid);
-  file_hdr->c_nlink = FROM_HEX (ascii_header.c_nlink);
-  file_hdr->c_mtime = FROM_HEX (ascii_header.c_mtime);
-  file_hdr->c_filesize = FROM_HEX (ascii_header.c_filesize);
-  file_hdr->c_dev_maj = FROM_HEX (ascii_header.c_dev_maj);
-  file_hdr->c_dev_min = FROM_HEX (ascii_header.c_dev_min);
-  file_hdr->c_rdev_maj = FROM_HEX (ascii_header.c_rdev_maj);
-  file_hdr->c_rdev_min = FROM_HEX (ascii_header.c_rdev_min);
-  file_hdr->c_namesize = FROM_HEX (ascii_header.c_namesize);
-  file_hdr->c_chksum = FROM_HEX (ascii_header.c_chksum);
-  
-  /* Read file name from input.  */
-  if (file_hdr->c_name != NULL)
-    free (file_hdr->c_name);
-  file_hdr->c_name = (char *) xmalloc (file_hdr->c_namesize);
-  tape_buffered_read (file_hdr->c_name, in_des, (long) file_hdr->c_namesize);
-
-  /* In SVR4 ASCII format, the amount of space allocated for the header
-     is rounded up to the next long-word, so we might need to drop
-     1-3 bytes.  */
-  tape_skip_padding (in_des, file_hdr->c_namesize + 110);
-}
-
-/* Fill in FILE_HDR by reading a binary format cpio header from
-   file descriptor IN_DES, except for the first 6 bytes (the magic
-   number, device, and inode number), which are already filled in.  */
-
-void
-read_in_binary (struct cpio_file_stat *file_hdr,
-		struct old_cpio_header *short_hdr,
-		int in_des)
-{
-  file_hdr->c_magic = short_hdr->c_magic;
-
-  tape_buffered_read (((char *) short_hdr) + 6, in_des,
-		      sizeof *short_hdr - 6 /* = 20 */);
-
-  /* If the magic number is byte swapped, fix the header.  */
-  if (file_hdr->c_magic == swab_short ((unsigned short) 070707))
-    {
-      static int warned = 0;
-
-      /* Alert the user that they might have to do byte swapping on
-	 the file contents.  */
-      if (warned == 0)
-	{
-	  error (0, 0, _("warning: archive header has reverse byte-order"));
-	  warned = 1;
-	}
-      swab_array ((char *) &short_hdr, 13);
-    }
-
-  file_hdr->c_dev_maj = major (short_hdr->c_dev);
-  file_hdr->c_dev_min = minor (short_hdr->c_dev);
-  file_hdr->c_ino = short_hdr->c_ino;
-  file_hdr->c_mode = short_hdr->c_mode;
-  file_hdr->c_uid = short_hdr->c_uid;
-  file_hdr->c_gid = short_hdr->c_gid;
-  file_hdr->c_nlink = short_hdr->c_nlink;
-  file_hdr->c_rdev_maj = major (short_hdr->c_rdev);
-  file_hdr->c_rdev_min = minor (short_hdr->c_rdev);
-  file_hdr->c_mtime = (unsigned long) short_hdr->c_mtimes[0] << 16
-                      | short_hdr->c_mtimes[1];
-
-  file_hdr->c_namesize = short_hdr->c_namesize;
-  file_hdr->c_filesize = (unsigned long) short_hdr->c_filesizes[0] << 16
-                      | short_hdr->c_filesizes[1];
-
-  /* Read file name from input.  */
-  if (file_hdr->c_name != NULL)
-    free (file_hdr->c_name);
-  file_hdr->c_name = (char *) xmalloc (file_hdr->c_namesize);
-  tape_buffered_read (file_hdr->c_name, in_des, (long) file_hdr->c_namesize);
-
-  /* In binary mode, the amount of space allocated in the header for
-     the filename is `c_namesize' rounded up to the next short-word,
-     so we might need to drop a byte.  */
-  if (file_hdr->c_namesize % 2)
-    tape_toss_input (in_des, 1L);
-
-  /* HP/UX cpio creates archives that look just like ordinary archives,
-     but for devices it sets major = 0, minor = 1, and puts the
-     actual major/minor number in the filesize field.  See if this
-     is an HP/UX cpio archive, and if so fix it.  We have to do this
-     here because process_copy_in() assumes filesize is always 0
-     for devices.  */
-  switch (file_hdr->c_mode & CP_IFMT)
-    {
-      case CP_IFCHR:
-      case CP_IFBLK:
-#ifdef CP_IFSOCK
-      case CP_IFSOCK:
-#endif
-#ifdef CP_IFIFO
-      case CP_IFIFO:
-#endif
-	if (file_hdr->c_filesize != 0
-	    && file_hdr->c_rdev_maj == 0
-	    && file_hdr->c_rdev_min == 1)
-	  {
-	    file_hdr->c_rdev_maj = major (file_hdr->c_filesize);
-	    file_hdr->c_rdev_min = minor (file_hdr->c_filesize);
-	    file_hdr->c_filesize = 0;
-	  }
-	break;
-      default:
-	break;
-    }
-}
-
-/* Exchange the bytes of each element of the array of COUNT shorts
-   starting at PTR.  */
-
-void
-swab_array (char *ptr, int count)
-{
-  char tmp;
-
-  while (count-- > 0)
-    {
-      tmp = *ptr;
-      *ptr = *(ptr + 1);
-      ++ptr;
-      *ptr = tmp;
-      ++ptr;
-    }
-}
-
-#if 0	/* Now in util.c, but different */
-/* Return a safer suffix of FILE_NAME, or "." if it has no safer
-   suffix.  Check for fully specified file names and other atrocities.  */
-
-static const char *
-safer_name_suffix (char const *file_name)
-{
-  char const *p;
-
-  /* Skip file system prefixes, leading file name components that contain
-     "..", and leading slashes.  */
-
-  size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (file_name);
-
-  for (p = file_name + prefix_len; *p;)
-    {
-      if (p[0] == '.' && p[1] == '.' && (ISSLASH (p[2]) || !p[2]))
-	prefix_len = p + 2 - file_name;
-
-      do
-	{
-	  char c = *p++;
-	  if (ISSLASH (c))
-	    break;
-	}
-      while (*p);
-    }
-
-  for (p = file_name + prefix_len; ISSLASH (*p); p++)
-    continue;
-  prefix_len = p - file_name;
-
-  if (prefix_len)
-    {
-      char *prefix = alloca (prefix_len + 1);
-      memcpy (prefix, file_name, prefix_len);
-      prefix[prefix_len] = '\0';
-
-
-      error (0, 0, _("Removing leading `%s' from member names"), prefix);
-    }
-
-  if (!*p)
-    p = ".";
-
-  return p;
-}
-#endif
-
-/* Read the collection from standard input and create files
-   in the file system.  */
-
-void
-process_copy_in ()
-{
-  char done = false;		/* True if trailer reached.  */
-  FILE *tty_in = NULL;		/* Interactive file for rename option.  */
-  FILE *tty_out = NULL;		/* Interactive file for rename option.  */
-  FILE *rename_in = NULL;	/* Batch file for rename option.  */
-  struct stat file_stat;	/* Output file stat record.  */
-  struct cpio_file_stat file_hdr;	/* Output header information.  */
-  int in_file_des;		/* Input file descriptor.  */
-  char skip_file;		/* Flag for use with patterns.  */
-  int i;			/* Loop index variable.  */
-
-  umask (0);                    /* Reset umask to preserve modes of
-				   created files  */
-  
-  /* Initialize the copy in.  */
-  if (pattern_file_name)
-    {
-      read_pattern_file ();
-    }
-  file_hdr.c_name = NULL;
-
-  if (rename_batch_file)
-    {
-      rename_in = fopen (rename_batch_file, "r");
-      if (rename_in == NULL)
-	{
-	  error (2, errno, TTY_NAME);
-	}
-    }
-  else if (rename_flag)
-    {
-      /* Open interactive file pair for rename operation.  */
-      tty_in = fopen (TTY_NAME, "r");
-      if (tty_in == NULL)
-	{
-	  error (2, errno, TTY_NAME);
-	}
-      tty_out = fopen (TTY_NAME, "w");
-      if (tty_out == NULL)
-	{
-	  error (2, errno, TTY_NAME);
-	}
-    }
-
-  /* Get date and time if needed for processing the table option.  */
-  if (table_flag && verbose_flag)
-    {
-      time (¤t_time);
-    }
-
-  /* Check whether the input file might be a tape.  */
-  in_file_des = archive_des;
-  if (_isrmt (in_file_des))
-    {
-      input_is_special = 1;
-      input_is_seekable = 0;
-    }
-  else
-    {
-      if (fstat (in_file_des, &file_stat))
-	error (1, errno, _("standard input is closed"));
-      input_is_special =
-#ifdef S_ISBLK
-	S_ISBLK (file_stat.st_mode) ||
-#endif
-	S_ISCHR (file_stat.st_mode);
-      input_is_seekable = S_ISREG (file_stat.st_mode);
-    }
-  output_is_seekable = true;
-
-  /* While there is more input in the collection, process the input.  */
-  while (!done)
-    {
-      swapping_halfwords = swapping_bytes = false;
-
-      /* Start processing the next file by reading the header.  */
-      read_in_header (&file_hdr, in_file_des);
-
-#ifdef DEBUG_CPIO
-      if (debug_flag)
-	{
-	  struct cpio_file_stat *h;
-	  h = &file_hdr;
-	  fprintf (stderr, 
-		"magic = 0%o, ino = %d, mode = 0%o, uid = %d, gid = %d\n",
-		h->c_magic, h->c_ino, h->c_mode, h->c_uid, h->c_gid);
-	  fprintf (stderr, 
-		"nlink = %d, mtime = %d, filesize = %d, dev_maj = 0x%x\n",
-		h->c_nlink, h->c_mtime, h->c_filesize, h->c_dev_maj);
-	  fprintf (stderr, 
-	        "dev_min = 0x%x, rdev_maj = 0x%x, rdev_min = 0x%x, namesize = %d\n",
-		h->c_dev_min, h->c_rdev_maj, h->c_rdev_min, h->c_namesize);
-	  fprintf (stderr, 
-		"chksum = %d, name = \"%s\", tar_linkname = \"%s\"\n",
-		h->c_chksum, h->c_name, 
-		h->c_tar_linkname ? h->c_tar_linkname : "(null)" );
-
-	}
-#endif
-      /* Is this the header for the TRAILER file?  */
-      if (strcmp (CPIO_TRAILER_NAME, file_hdr.c_name) == 0)
-	{
-	  done = true;
-	  break;
-	}
-
-      cpio_safer_name_suffix (file_hdr.c_name, false, abs_paths_flag,
-			      false);
-      
-      /* Does the file name match one of the given patterns?  */
-      if (num_patterns <= 0)
-	skip_file = false;
-      else
-	{
-	  skip_file = copy_matching_files;
-	  for (i = 0; i < num_patterns
-	       && skip_file == copy_matching_files; i++)
-	    {
-	      if (fnmatch (save_patterns[i], file_hdr.c_name, 0) == 0)
-		skip_file = !copy_matching_files;
-	    }
-	}
-
-      if (skip_file)
-	{
-	  /* If we're skipping a file with links, there might be other
-	     links that we didn't skip, and this file might have the
-	     data for the links.  If it does, we'll copy in the data
-	     to the links, but not to this file.  */
-	  if (file_hdr.c_nlink > 1 && (archive_format == arf_newascii
-	      || archive_format == arf_crcascii) )
-	    {
-	      if (create_defered_links_to_skipped(&file_hdr, in_file_des) < 0)
-	        {
-		  tape_toss_input (in_file_des, file_hdr.c_filesize);
-		  tape_skip_padding (in_file_des, file_hdr.c_filesize);
-		}
-	    }
-	  else
-	    {
-	      tape_toss_input (in_file_des, file_hdr.c_filesize);
-	      tape_skip_padding (in_file_des, file_hdr.c_filesize);
-	    }
-	}
-      else if (table_flag)
-	{
-	  list_file(&file_hdr, in_file_des);
-	}
-      else if (append_flag)
-	{
-	  tape_toss_input (in_file_des, file_hdr.c_filesize);
-	  tape_skip_padding (in_file_des, file_hdr.c_filesize);
-	}
-      else if (only_verify_crc_flag)
-	{
-#ifdef CP_IFLNK
-	  if ((file_hdr.c_mode & CP_IFMT) == CP_IFLNK)
-	    {
-	      if (archive_format != arf_tar && archive_format != arf_ustar)
-		{
-		  tape_toss_input (in_file_des, file_hdr.c_filesize);
-		  tape_skip_padding (in_file_des, file_hdr.c_filesize);
-		  continue;
-		}
-	    }
-#endif
-	    crc = 0;
-	    tape_toss_input (in_file_des, file_hdr.c_filesize);
-	    tape_skip_padding (in_file_des, file_hdr.c_filesize);
-	    if (crc != file_hdr.c_chksum)
-	      {
-		error (0, 0, _("%s: checksum error (0x%lx, should be 0x%lx)"),
-		       file_hdr.c_name, crc, file_hdr.c_chksum);
-	      }
-         /* Debian hack: -v and -V now work with --only-verify-crc.
-            (99/11/10) -BEM */
-	    if (verbose_flag)
-	      {
-		fprintf (stderr, "%s\n", file_hdr.c_name);
-	      }
-	    if (dot_flag)
-	      {
-		fputc ('.', stderr);
-	      }
-	}
-      else
-	{
-	  /* Copy the input file into the directory structure.  */
-
-	  /* Do we need to rename the file? */
-	  if (rename_flag || rename_batch_file)
-	    {
-	      if (query_rename(&file_hdr, tty_in, tty_out, rename_in) < 0)
-	        {
-		  tape_toss_input (in_file_des, file_hdr.c_filesize);
-		  tape_skip_padding (in_file_des, file_hdr.c_filesize);
-		  continue;
-		}
-	    }
-
-	  copyin_file(&file_hdr, in_file_des);
-
-	  if (verbose_flag)
-	    fprintf (stderr, "%s\n", file_hdr.c_name);
-	  if (dot_flag)
-	    fputc ('.', stderr);
-	}
-    }
-
-  if (dot_flag)
-    fputc ('\n', stderr);
-
-  if (append_flag)
-    return;
-
-  if (archive_format == arf_newascii || archive_format == arf_crcascii)
-    {
-      create_final_defers ();
-    }
-  if (!quiet_flag)
-    {
-      int blocks;
-      blocks = (input_bytes + io_block_size - 1) / io_block_size;
-      fprintf (stderr, ngettext ("%d block\n", "%d blocks\n", blocks), blocks);
-    }
-}
-
diff --git a/contrib/cpio/src/copyout.c b/contrib/cpio/src/copyout.c
deleted file mode 100644
index 5e429faa9da..00000000000
--- a/contrib/cpio/src/copyout.c
+++ /dev/null
@@ -1,1010 +0,0 @@
-/* $FreeBSD$ */
-
-/* copyout.c - create a cpio archive
-   Copyright (C) 1990, 1991, 1992, 2001, 2003, 2004,
-   2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-#include 
-
-#include 
-#include 
-#include 
-#include "filetypes.h"
-#include "cpiohdr.h"
-#include "dstring.h"
-#include "extern.h"
-#include "defer.h"
-#include 
-#include 
-
-static int check_rdev ();
-
-/* Read FILE_SIZE bytes of FILE_NAME from IN_FILE_DES and
-   compute and return a checksum for them.  */
-
-static unsigned int
-read_for_checksum (int in_file_des, int file_size, char *file_name)
-{
-  unsigned int crc;
-  char buf[BUFSIZ];
-  int bytes_left;
-  int bytes_read;
-  int i;
-
-  crc = 0;
-
-  for (bytes_left = file_size; bytes_left > 0; bytes_left -= bytes_read)
-    {
-      bytes_read = read (in_file_des, buf, BUFSIZ);
-      if (bytes_read < 0)
-	error (1, errno, _("cannot read checksum for %s"), file_name);
-      if (bytes_read == 0)
-	break;
-      if (bytes_left < bytes_read)
-        bytes_read = bytes_left;
-      for (i = 0; i < bytes_read; ++i)
-	crc += buf[i] & 0xff;
-    }
-  if (lseek (in_file_des, 0L, SEEK_SET))
-    error (1, errno, _("cannot read checksum for %s"), file_name);
-
-  return crc;
-}
-
-/* Write out NULs to fill out the rest of the current block on
-   OUT_FILE_DES.  */
-
-static void
-tape_clear_rest_of_block (int out_file_des)
-{
-  write_nuls_to_file (io_block_size - output_size, out_file_des, 
-                      tape_buffered_write);
-}
-
-/* Write NULs on OUT_FILE_DES to move from OFFSET (the current location)
-   to the end of the header.  */
-
-static void
-tape_pad_output (int out_file_des, int offset)
-{
-  size_t pad;
-
-  if (archive_format == arf_newascii || archive_format == arf_crcascii)
-    pad = (4 - (offset % 4)) % 4;
-  else if (archive_format == arf_tar || archive_format == arf_ustar)
-    pad = (512 - (offset % 512)) % 512;
-  else if (archive_format != arf_oldascii && archive_format != arf_hpoldascii)
-    pad = (2 - (offset % 2)) % 2;
-  else
-    pad = 0;
-
-  if (pad != 0)
-    write_nuls_to_file (pad, out_file_des, tape_buffered_write);
-}
-
-
-/* When creating newc and crc archives if a file has multiple (hard)
-   links, we don't put any of them into the archive until we have seen
-   all of them (or until we get to the end of the list of files that
-   are going into the archive and know that we have seen all of the links
-   to the file that we will see).  We keep these "defered" files on
-   this list.   */
-
-struct deferment *deferouts = NULL;
-
-/* Count the number of other (hard) links to this file that have
-   already been defered.  */
-
-static int
-count_defered_links_to_dev_ino (struct cpio_file_stat *file_hdr)
-{
-  struct deferment *d;
-  int	ino;
-  int 	maj;
-  int   min;
-  int 	count;
-  ino = file_hdr->c_ino;
-  maj = file_hdr->c_dev_maj;
-  min = file_hdr->c_dev_min;
-  count = 0;
-  for (d = deferouts; d != NULL; d = d->next)
-    {
-      if ( (d->header.c_ino == ino) && (d->header.c_dev_maj == maj)
-	  && (d->header.c_dev_min == min) )
-	++count;
-    }
-  return count;
-}
-
-/* Is this file_hdr the last (hard) link to a file?  I.e., have
-   we already seen and defered all of the other links?  */
-
-static int
-last_link (struct cpio_file_stat *file_hdr)
-{
-  int	other_files_sofar;
-
-  other_files_sofar = count_defered_links_to_dev_ino (file_hdr);
-  if (file_hdr->c_nlink == (other_files_sofar + 1) )
-    {
-      return 1;
-    }
-  return 0;
-}
-
-
-/* Add the file header for a link that is being defered to the deferouts
-   list.  */
-
-static void
-add_link_defer (struct cpio_file_stat *file_hdr)
-{
-  struct deferment *d;
-  d = create_deferment (file_hdr);
-  d->next = deferouts;
-  deferouts = d;
-}
-
-/* We are about to put a file into a newc or crc archive that is
-   multiply linked.  We have already seen and deferred all of the
-   other links to the file but haven't written them into the archive.
-   Write the other links into the archive, and remove them from the
-   deferouts list.  */
-
-static void
-writeout_other_defers (struct cpio_file_stat *file_hdr, int out_des)
-{
-  struct deferment *d;
-  struct deferment *d_prev;
-  int	ino;
-  int 	maj;
-  int   min;
-  ino = file_hdr->c_ino;
-  maj = file_hdr->c_dev_maj;
-  min = file_hdr->c_dev_min;
-  d_prev = NULL;
-  d = deferouts;
-  while (d != NULL)
-    {
-      if ( (d->header.c_ino == ino) && (d->header.c_dev_maj == maj)
-	  && (d->header.c_dev_min == min) )
-	{
-	  struct deferment *d_free;
-	  d->header.c_filesize = 0;
-	  write_out_header (&d->header, out_des);
-	  if (d_prev != NULL)
-	    d_prev->next = d->next;
-	  else
-	    deferouts = d->next;
-	  d_free = d;
-	  d = d->next;
-	  free_deferment (d_free);
-	}
-      else
-	{
-	  d_prev = d;
-	  d = d->next;
-	}
-    }
-  return;
-}
-
-/* Write a file into the archive.  This code is the same as
-   the code in process_copy_out(), but we need it here too
-   for writeout_final_defers() to call.  */
-
-static void
-writeout_defered_file (struct cpio_file_stat *header, int out_file_des)
-{
-  int in_file_des;
-  struct cpio_file_stat file_hdr;
-
-  file_hdr = *header;
-
-
-  in_file_des = open (header->c_name,
-		      O_RDONLY | O_BINARY, 0);
-  if (in_file_des < 0)
-    {
-      open_error (header->c_name);
-      return;
-    }
-
-  if (archive_format == arf_crcascii)
-    file_hdr.c_chksum = read_for_checksum (in_file_des,
-					   file_hdr.c_filesize,
-					   header->c_name);
-
-  if (write_out_header (&file_hdr, out_file_des))
-    return;
-  copy_files_disk_to_tape (in_file_des, out_file_des, file_hdr.c_filesize,
-			   header->c_name);
-  warn_if_file_changed(header->c_name, file_hdr.c_filesize, file_hdr.c_mtime);
-
-  if (archive_format == arf_tar || archive_format == arf_ustar)
-    add_inode (file_hdr.c_ino, file_hdr.c_name, file_hdr.c_dev_maj,
-	       file_hdr.c_dev_min);
-
-  tape_pad_output (out_file_des, file_hdr.c_filesize);
-
-  if (reset_time_flag)
-    set_file_times (in_file_des, file_hdr.c_name, file_hdr.c_mtime,
-		    file_hdr.c_mtime);
-  if (close (in_file_des) < 0)
-    close_error (header->c_name);
-}
-
-/* When writing newc and crc format archives we defer multiply linked
-   files until we have seen all of the links to the file.  If a file
-   has links to it that aren't going into the archive, then we will
-   never see the "last" link to the file, so at the end we just write 
-   all of the leftover defered files into the archive.  */
-
-static void
-writeout_final_defers (int out_des)
-{
-  struct deferment *d;
-  int other_count;
-  while (deferouts != NULL)
-    {
-      d = deferouts;
-      other_count = count_defered_links_to_dev_ino (&d->header);
-      if (other_count == 1)
-	{
-	  writeout_defered_file (&d->header, out_des);
-	}
-      else
-	{
-	  struct cpio_file_stat file_hdr;
-	  file_hdr = d->header;
-	  file_hdr.c_filesize = 0;
-	  write_out_header (&file_hdr, out_des);
-	}
-      deferouts = deferouts->next;
-    }
-}
-
-/* FIXME: to_ascii could be used instead of to_oct() and to_octal() from tar,
-   so it should be moved to paxutils too.
-   Allowed values for logbase are: 1 (binary), 2, 3 (octal), 4 (hex) */
-int
-to_ascii (char *where, uintmax_t v, size_t digits, unsigned logbase)
-{
-  static char codetab[] = "0123456789ABCDEF";
-  int i = digits;
-  
-  do
-    {
-      where[--i] = codetab[(v & ((1 << logbase) - 1))];
-      v >>= logbase;
-    }
-  while (i);
-
-  return v != 0;
-}
-
-static void
-field_width_error (const char *filename, const char *fieldname)
-{
-  error (0, 0, _("%s: field width not sufficient for storing %s"),
-	 filename, fieldname);
-}
-
-static void
-field_width_warning (const char *filename, const char *fieldname)
-{
-  if (warn_option & CPIO_WARN_TRUNCATE)
-    error (0, 0, _("%s: truncating %s"), filename, fieldname);
-}
-
-void
-to_ascii_or_warn (char *where, uintmax_t n, size_t digits,
-		  unsigned logbase,
-		  const char *filename, const char *fieldname)
-{
-  if (to_ascii (where, n, digits, logbase))
-    field_width_warning (filename, fieldname);
-}    
-
-int
-to_ascii_or_error (char *where, uintmax_t n, size_t digits,
-		   unsigned logbase,
-		   const char *filename, const char *fieldname)
-{
-  if (to_ascii (where, n, digits, logbase))
-    {
-      field_width_error (filename, fieldname);
-      return 1;
-    }
-  return 0;
-}    
-
-
-int
-write_out_new_ascii_header (const char *magic_string,
-			    struct cpio_file_stat *file_hdr, int out_des)
-{
-  char ascii_header[110];
-  char *p;
-
-  p = stpcpy (ascii_header, magic_string);
-  to_ascii_or_warn (p, file_hdr->c_ino, 8, LG_16,
-		    file_hdr->c_name, _("inode number"));
-  p += 8;
-  to_ascii_or_warn (p, file_hdr->c_mode, 8, LG_16, file_hdr->c_name,
-		    _("file mode"));
-  p += 8;
-  to_ascii_or_warn (p, file_hdr->c_uid, 8, LG_16, file_hdr->c_name,
-		    _("uid"));
-  p += 8;
-  to_ascii_or_warn (p, file_hdr->c_gid, 8, LG_16, file_hdr->c_name,
-		    _("gid"));
-  p += 8;
-  to_ascii_or_warn (p, file_hdr->c_nlink, 8, LG_16, file_hdr->c_name,
-		    _("number of links"));
-  p += 8;
-  to_ascii_or_warn (p, file_hdr->c_mtime, 8, LG_16, file_hdr->c_name,
-		    _("modification time"));
-  p += 8;
-  if (to_ascii_or_error (p, file_hdr->c_filesize, 8, LG_16, file_hdr->c_name,
-			 _("file size")))
-    return 1;
-  p += 8;
-  if (to_ascii_or_error (p, file_hdr->c_dev_maj, 8, LG_16, file_hdr->c_name,
-			 _("device major number")))
-    return 1;
-  p += 8;
-  if (to_ascii_or_error (p, file_hdr->c_dev_min, 8, LG_16, file_hdr->c_name,
-			 _("device minor number")))
-    return 1;
-  p += 8;
-  if (to_ascii_or_error (p, file_hdr->c_rdev_maj, 8, LG_16, file_hdr->c_name,
-			 _("rdev major")))
-    return 1;
-  p += 8;
-  if (to_ascii_or_error (p, file_hdr->c_rdev_min, 8, LG_16, file_hdr->c_name,
-			 _("rdev minor")))
-    return 1;
-  p += 8;
-  if (to_ascii_or_error (p, file_hdr->c_namesize, 8, LG_16, file_hdr->c_name,
-			 _("name size")))
-    return 1;
-  p += 8;
-  to_ascii (p, file_hdr->c_chksum & 0xffffffff, 8, LG_16);
-
-  tape_buffered_write (ascii_header, out_des, sizeof ascii_header);
-
-  /* Write file name to output.  */
-  tape_buffered_write (file_hdr->c_name, out_des, (long) file_hdr->c_namesize);
-  tape_pad_output (out_des, file_hdr->c_namesize + sizeof ascii_header);
-  return 0;
-}  
-
-int
-write_out_old_ascii_header (dev_t dev, dev_t rdev,
-			    struct cpio_file_stat *file_hdr, int out_des)
-{
-  char ascii_header[76];
-  char *p = ascii_header;
-  
-  to_ascii (p, file_hdr->c_magic, 6, LG_8);
-  p += 6;
-  to_ascii_or_warn (p, dev, 6, LG_8, file_hdr->c_name, _("device number"));
-  p += 6;
-  to_ascii_or_warn (p, file_hdr->c_ino, 6, LG_8, file_hdr->c_name,
-		    _("inode number"));
-  p += 6;
-  to_ascii_or_warn (p, file_hdr->c_mode, 6, LG_8, file_hdr->c_name,
-		    _("file mode"));
-  p += 6;
-  to_ascii_or_warn (p, file_hdr->c_uid, 6, LG_8, file_hdr->c_name, _("uid"));
-  p += 6;
-  to_ascii_or_warn (p, file_hdr->c_gid, 6, LG_8, file_hdr->c_name, _("gid"));
-  p += 6;
-  to_ascii_or_warn (p, file_hdr->c_nlink, 6, LG_8, file_hdr->c_name,
-		    _("number of links"));
-  p += 6;
-  to_ascii_or_warn (p, rdev, 6, LG_8, file_hdr->c_name, _("rdev"));
-  p += 6;
-  to_ascii_or_warn (p, file_hdr->c_mtime, 11, LG_8, file_hdr->c_name,
-		    _("modification time"));
-  p += 11;
-  if (to_ascii_or_error (p, file_hdr->c_namesize, 6, LG_8, file_hdr->c_name,
-			 _("name size")))
-    return 1;
-  p += 6;
-  if (to_ascii_or_error (p, file_hdr->c_filesize, 11, LG_8, file_hdr->c_name,
-			 _("file size")))
-    return 1;
-
-  tape_buffered_write (ascii_header, out_des, sizeof ascii_header);
-
-  /* Write file name to output.  */
-  tape_buffered_write (file_hdr->c_name, out_des, file_hdr->c_namesize);
-  return 0;
-}
-
-void
-hp_compute_dev (struct cpio_file_stat *file_hdr, dev_t *pdev, dev_t *prdev)
-{
-  /* HP/UX cpio creates archives that look just like ordinary archives,
-     but for devices it sets major = 0, minor = 1, and puts the
-     actual major/minor number in the filesize field.  */
-  switch (file_hdr->c_mode & CP_IFMT)
-    {
-    case CP_IFCHR:
-    case CP_IFBLK:
-#ifdef CP_IFSOCK
-    case CP_IFSOCK:
-#endif
-#ifdef CP_IFIFO
-    case CP_IFIFO:
-#endif
-      file_hdr->c_filesize = makedev (file_hdr->c_rdev_maj,
-				      file_hdr->c_rdev_min);
-      *pdev = *prdev = makedev (0, 1);
-      break;
-
-    default:
-      *pdev = makedev (file_hdr->c_dev_maj, file_hdr->c_dev_min);
-      *prdev = makedev (file_hdr->c_rdev_maj, file_hdr->c_rdev_min);
-      break;
-    }
-}
-
-int
-write_out_binary_header (dev_t rdev,
-			 struct cpio_file_stat *file_hdr, int out_des)
-{
-  struct old_cpio_header short_hdr;
-
-  short_hdr.c_magic = 070707;
-  short_hdr.c_dev = makedev (file_hdr->c_dev_maj, file_hdr->c_dev_min);
-
-  if ((warn_option & CPIO_WARN_TRUNCATE) && (file_hdr->c_ino >> 16) != 0)
-    error (0, 0, _("%s: truncating inode number"), file_hdr->c_name);
-
-  short_hdr.c_ino = file_hdr->c_ino & 0xFFFF;
-  if (short_hdr.c_ino != file_hdr->c_ino)
-    field_width_warning (file_hdr->c_name, _("inode number"));
-  
-  short_hdr.c_mode = file_hdr->c_mode & 0xFFFF;
-  if (short_hdr.c_mode != file_hdr->c_mode)
-    field_width_warning (file_hdr->c_name, _("file mode"));
-  
-  short_hdr.c_uid = file_hdr->c_uid & 0xFFFF;
-  if (short_hdr.c_uid != file_hdr->c_uid)
-    field_width_warning (file_hdr->c_name, _("uid"));
-  
-  short_hdr.c_gid = file_hdr->c_gid & 0xFFFF;
-  if (short_hdr.c_gid != file_hdr->c_gid)
-    field_width_warning (file_hdr->c_name, _("gid"));
-  
-  short_hdr.c_nlink = file_hdr->c_nlink & 0xFFFF;
-  if (short_hdr.c_nlink != file_hdr->c_nlink)
-    field_width_warning (file_hdr->c_name, _("number of links"));
-		      
-  short_hdr.c_rdev = rdev;
-  short_hdr.c_mtimes[0] = file_hdr->c_mtime >> 16;
-  short_hdr.c_mtimes[1] = file_hdr->c_mtime & 0xFFFF;
-
-  short_hdr.c_namesize = file_hdr->c_namesize & 0xFFFF;
-  if (short_hdr.c_namesize != file_hdr->c_namesize)
-    {
-      field_width_error (file_hdr->c_name, _("name size"));
-      return 1;
-    }
-		      
-  short_hdr.c_filesizes[0] = file_hdr->c_filesize >> 16;
-  short_hdr.c_filesizes[1] = file_hdr->c_filesize & 0xFFFF;
-
-  if (((off_t)short_hdr.c_filesizes[0] << 16) + short_hdr.c_filesizes[1]
-       != file_hdr->c_filesize)
-    {
-      field_width_error (file_hdr->c_name, _("file size"));
-      return 1;
-    }
-		      
-  /* Output the file header.  */
-  tape_buffered_write ((char *) &short_hdr, out_des, 26);
-
-  /* Write file name to output.  */
-  tape_buffered_write (file_hdr->c_name, out_des, file_hdr->c_namesize);
-
-  tape_pad_output (out_des, file_hdr->c_namesize + 26);
-  return 0;
-}
-
-
-/* Write out header FILE_HDR, including the file name, to file
-   descriptor OUT_DES.  */
-
-int 
-write_out_header (struct cpio_file_stat *file_hdr, int out_des)
-{
-  dev_t dev;
-  dev_t rdev;
-  
-  switch (archive_format)
-    {
-    case arf_newascii:
-      return write_out_new_ascii_header ("070701", file_hdr, out_des);
-      
-    case arf_crcascii:
-      return write_out_new_ascii_header ("070702", file_hdr, out_des);
-      
-    case arf_oldascii:
-      return write_out_old_ascii_header (makedev (file_hdr->c_dev_maj,
-						  file_hdr->c_dev_min),
-					 makedev (file_hdr->c_rdev_maj,
-						  file_hdr->c_rdev_min),
-					 file_hdr, out_des);
-      
-    case arf_hpoldascii:
-      hp_compute_dev (file_hdr, &dev, &rdev);
-      return write_out_old_ascii_header (dev, rdev, file_hdr, out_des);
-      
-    case arf_tar:
-    case arf_ustar:
-      if (is_tar_filename_too_long (file_hdr->c_name))
-	{
-	  error (0, 0, _("%s: file name too long"), file_hdr->c_name);
-	  return 1;
-	}
-      write_out_tar_header (file_hdr, out_des); /* FIXME: No error checking */
-      return 0;
-
-    case arf_binary:
-      return write_out_binary_header (makedev (file_hdr->c_rdev_maj,
-					       file_hdr->c_rdev_min),
-				      file_hdr, out_des);
-
-    case arf_hpbinary:
-      hp_compute_dev (file_hdr, &dev, &rdev);
-      /* FIXME: dev ignored. Should it be? */
-      return write_out_binary_header (rdev, file_hdr, out_des);
-
-    default:
-      abort ();
-    }
-}
-
-static void
-assign_string (char **pvar, char *value)
-{
-  char *p = xrealloc (*pvar, strlen (value) + 1);
-  strcpy (p, value);
-  *pvar = p;
-}
-
-/* Read a list of file names from the standard input
-   and write a cpio collection on the standard output.
-   The format of the header depends on the compatibility (-c) flag.  */
-
-void
-process_copy_out ()
-{
-  int res;			/* Result of functions.  */
-  dynamic_string input_name;	/* Name of file read from stdin.  */
-  struct stat file_stat;	/* Stat record for file.  */
-  struct cpio_file_stat file_hdr; /* Output header information.  */
-  int in_file_des;		/* Source file descriptor.  */
-  int out_file_des;		/* Output file descriptor.  */
-  char *orig_file_name = NULL;
-
-  /* Initialize the copy out.  */
-  ds_init (&input_name, 128);
-  file_hdr.c_magic = 070707;
-
-  /* Check whether the output file might be a tape.  */
-  out_file_des = archive_des;
-  if (_isrmt (out_file_des))
-    {
-      output_is_special = 1;
-      output_is_seekable = 0;
-    }
-  else
-    {
-      if (fstat (out_file_des, &file_stat))
-	error (1, errno, _("standard output is closed"));
-      output_is_special =
-#ifdef S_ISBLK
-	S_ISBLK (file_stat.st_mode) ||
-#endif
-	S_ISCHR (file_stat.st_mode);
-      output_is_seekable = S_ISREG (file_stat.st_mode);
-    }
-
-  if (append_flag)
-    {
-      process_copy_in ();
-      prepare_append (out_file_des);
-    }
-
-  /* Copy files with names read from stdin.  */
-  while (ds_fgetstr (stdin, &input_name, name_end) != NULL)
-    {
-      /* Check for blank line.  */
-      if (input_name.ds_string[0] == 0)
-	{
-	  error (0, 0, _("blank line ignored"));
-	  continue;
-	}
-
-      /* Process next file.  */
-      if ((*xstat) (input_name.ds_string, &file_stat) < 0)
-	stat_error (input_name.ds_string);
-      else
-	{
-	  /* Set values in output header.  */
-	  stat_to_cpio (&file_hdr, &file_stat);
-	  
-	  if (archive_format == arf_tar || archive_format == arf_ustar)
-	    {
-	      if (file_hdr.c_mode & CP_IFDIR)
-		{
-		  int len = strlen (input_name.ds_string);
-		  /* Make sure the name ends with a slash */
-		  if (input_name.ds_string[len-1] != '/')
-		    {
-		      ds_resize (&input_name, len + 2);
-		      input_name.ds_string[len] = '/';
-		      input_name.ds_string[len+1] = 0;
-		    }
-		}
-	    }
-
-	  switch (check_rdev (&file_hdr))
-	    {
-	      case 1:
-		error (0, 0, "%s not dumped: major number would be truncated",
-		       file_hdr.c_name);
-		continue;
-	      case 2:
-		error (0, 0, "%s not dumped: minor number would be truncated",
-		       file_hdr.c_name);
-		continue;
-	      case 4:
-		error (0, 0, "%s not dumped: device number would be truncated",
-		       file_hdr.c_name);
-		continue;
-	    }
-
-	  assign_string (&orig_file_name, input_name.ds_string);
-	  cpio_safer_name_suffix (input_name.ds_string, false,
-				  abs_paths_flag, true);
-#ifndef HPUX_CDF
-	  file_hdr.c_name = input_name.ds_string;
-	  file_hdr.c_namesize = strlen (input_name.ds_string) + 1;
-#else
-	  if ( (archive_format != arf_tar) && (archive_format != arf_ustar) )
-	    {
-	      /* We mark CDF's in cpio files by adding a 2nd `/' after the
-		 "hidden" directory name.  We need to do this so we can
-		 properly recreate the directory as hidden (in case the
-		 files of a directory go into the archive before the
-		 directory itself (e.g from "find ... -depth ... | cpio")).  */
-	      file_hdr.c_name = add_cdf_double_slashes (input_name.ds_string);
-	      file_hdr.c_namesize = strlen (file_hdr.c_name) + 1;
-	    }
-	  else
-	    {
-	      /* We don't mark CDF's in tar files.  We assume the "hidden"
-		 directory will always go into the archive before any of
-		 its files.  */
-	      file_hdr.c_name = input_name.ds_string;
-	      file_hdr.c_namesize = strlen (input_name.ds_string) + 1;
-	    }
-#endif
-
-	  /* Copy the named file to the output.  */
-	  switch (file_hdr.c_mode & CP_IFMT)
-	    {
-	    case CP_IFREG:
-	      if (archive_format == arf_tar || archive_format == arf_ustar)
-		{
-		  char *otherfile;
-		  if ((otherfile = find_inode_file (file_hdr.c_ino,
-						    file_hdr.c_dev_maj,
-						    file_hdr.c_dev_min)))
-		    {
-		      file_hdr.c_tar_linkname = otherfile;
-		      if (write_out_header (&file_hdr, out_file_des))
-			continue;
-		      break;
-		    }
-		}
-	      if ( (archive_format == arf_newascii || archive_format == arf_crcascii)
-		  && (file_hdr.c_nlink > 1) )
-		{
-		  if (last_link (&file_hdr) )
-		    {
-		      writeout_other_defers (&file_hdr, out_file_des);
-		    }
-		  else
-		    {
-		      add_link_defer (&file_hdr);
-		      break;
-		    }
-		}
-	      in_file_des = open (orig_file_name,
-				  O_RDONLY | O_BINARY, 0);
-	      if (in_file_des < 0)
-		{
-		  open_error (orig_file_name);
-		  continue;
-		}
-
-	      if (archive_format == arf_crcascii)
-		file_hdr.c_chksum = read_for_checksum (in_file_des,
-						       file_hdr.c_filesize,
-						       orig_file_name);
-
-	      if (write_out_header (&file_hdr, out_file_des))
-		continue;
-	      copy_files_disk_to_tape (in_file_des,
-				       out_file_des, file_hdr.c_filesize,
-				       orig_file_name);
-	      warn_if_file_changed(orig_file_name, file_hdr.c_filesize,
-                                   file_hdr.c_mtime);
-
-	      if (archive_format == arf_tar || archive_format == arf_ustar)
-		add_inode (file_hdr.c_ino, orig_file_name, file_hdr.c_dev_maj,
-			   file_hdr.c_dev_min);
-
-	      tape_pad_output (out_file_des, file_hdr.c_filesize);
-
-	      if (reset_time_flag)
-                set_file_times (in_file_des,
-				orig_file_name,
-                                file_stat.st_atime, file_stat.st_mtime);
-	      if (close (in_file_des) < 0)
-		close_error (orig_file_name);
-	      break;
-
-	    case CP_IFDIR:
-	      file_hdr.c_filesize = 0;
-	      if (write_out_header (&file_hdr, out_file_des))
-		continue;
-	      break;
-
-	    case CP_IFCHR:
-	    case CP_IFBLK:
-#ifdef CP_IFSOCK
-	    case CP_IFSOCK:
-#endif
-#ifdef CP_IFIFO
-	    case CP_IFIFO:
-#endif
-	      if (archive_format == arf_tar)
-		{
-		  error (0, 0, _("%s not dumped: not a regular file"),
-			 orig_file_name);
-		  continue;
-		}
-	      else if (archive_format == arf_ustar)
-		{
-		  char *otherfile;
-		  if ((otherfile = find_inode_file (file_hdr.c_ino,
-						    file_hdr.c_dev_maj,
-						    file_hdr.c_dev_min)))
-		    {
-		      /* This file is linked to another file already in the 
-		         archive, so write it out as a hard link. */
-		      file_hdr.c_mode = (file_stat.st_mode & 07777);
-		      file_hdr.c_mode |= CP_IFREG;
-		      file_hdr.c_tar_linkname = otherfile;
-		      if (write_out_header (&file_hdr, out_file_des))
-			continue;
-		      break;
-		    }
-		  add_inode (file_hdr.c_ino, orig_file_name, 
-			     file_hdr.c_dev_maj, file_hdr.c_dev_min);
-		}
-	      file_hdr.c_filesize = 0;
-	      if (write_out_header (&file_hdr, out_file_des))
-		continue;
-	      break;
-
-#ifdef CP_IFLNK
-	    case CP_IFLNK:
-	      {
-		char *link_name = (char *) xmalloc (file_stat.st_size + 1);
-		int link_size;
-
-		link_size = readlink (orig_file_name, link_name,
-			              file_stat.st_size);
-		if (link_size < 0)
-		  {
-		    readlink_warn (orig_file_name);
-		    free (link_name);
-		    continue;
-		  }
-		link_name[link_size] = 0;
-		cpio_safer_name_suffix (link_name, false,
-					abs_paths_flag, true);
-		link_size = strlen (link_name);
-		file_hdr.c_filesize = link_size;
-		if (archive_format == arf_tar || archive_format == arf_ustar)
-		  {
-		    if (link_size + 1 > 100)
-		      {
-			error (0, 0, _("%s: symbolic link too long"),
-			       file_hdr.c_name);
-		      }
-		    else
-		      {
-			link_name[link_size] = '\0';
-			file_hdr.c_tar_linkname = link_name;
-			if (write_out_header (&file_hdr, out_file_des))
-			  continue;
-		      }
-		  }
-		else
-		  {
-		    if (write_out_header (&file_hdr, out_file_des))
-		      continue;
-		    tape_buffered_write (link_name, out_file_des, link_size);
-		    tape_pad_output (out_file_des, link_size);
-		  }
-		free (link_name);
-	      }
-	      break;
-#endif
-
-	    default:
-	      error (0, 0, _("%s: unknown file type"), orig_file_name);
-	    }
-	  
-	  if (verbose_flag)
-	    fprintf (stderr, "%s\n", orig_file_name);
-	  if (dot_flag)
-	    fputc ('.', stderr);
-	}
-    }
-
-  free (orig_file_name);
-  
-  writeout_final_defers(out_file_des);
-  /* The collection is complete; append the trailer.  */
-  file_hdr.c_ino = 0;
-  file_hdr.c_mode = 0;
-  file_hdr.c_uid = 0;
-  file_hdr.c_gid = 0;
-  file_hdr.c_nlink = 1;		/* Must be 1 for crc format.  */
-  file_hdr.c_dev_maj = 0;
-  file_hdr.c_dev_min = 0;
-  file_hdr.c_rdev_maj = 0;
-  file_hdr.c_rdev_min = 0;
-  file_hdr.c_mtime = 0;
-  file_hdr.c_chksum = 0;
-
-  file_hdr.c_filesize = 0;
-  file_hdr.c_namesize = 11;
-  file_hdr.c_name = CPIO_TRAILER_NAME;
-  if (archive_format != arf_tar && archive_format != arf_ustar)
-    write_out_header (&file_hdr, out_file_des);
-  else
-    write_nuls_to_file (1024, out_file_des, tape_buffered_write);
-
-  /* Fill up the output block.  */
-  tape_clear_rest_of_block (out_file_des);
-  tape_empty_output_buffer (out_file_des);
-  if (dot_flag)
-    fputc ('\n', stderr);
-  if (!quiet_flag)
-    {
-      res = (output_bytes + io_block_size - 1) / io_block_size;
-      fprintf (stderr, ngettext ("%d block\n", "%d blocks\n", res), res);
-    }
-}
-
-static int
-check_rdev (file_hdr)
-     struct cpio_file_stat *file_hdr;
-{
-  if (archive_format == arf_newascii || archive_format == arf_crcascii)
-    {
-      if ((file_hdr->c_rdev_maj & 0xFFFFFFFF) != file_hdr->c_rdev_maj)
-        return 1;
-      if ((file_hdr->c_rdev_min & 0xFFFFFFFF) != file_hdr->c_rdev_min)
-        return 2;
-    }
-  else if (archive_format == arf_oldascii || archive_format == arf_hpoldascii)
-    {
-#ifndef __MSDOS__
-      dev_t rdev;
-
-      rdev = makedev (file_hdr->c_rdev_maj, file_hdr->c_rdev_min);
-      if (archive_format == arf_oldascii)
-	{
-	  if ((rdev & 0xFFFF) != rdev)
-	    return 4;
-	}
-      else
-	{
-	  switch (file_hdr->c_mode & CP_IFMT)
-	    {
-	      case CP_IFCHR:
-	      case CP_IFBLK:
-#ifdef CP_IFSOCK
-	      case CP_IFSOCK:
-#endif
-#ifdef CP_IFIFO
-	      case CP_IFIFO:
-#endif
-		/* We could handle one more bit if longs are >= 33 bits.  */
-		if ((rdev & 037777777777) != rdev)
-		  return 4;
-		break;
-	      default:
-		if ((rdev & 0xFFFF) != rdev)
-		  return 4;
-		break;
-	    }
-	}
-#endif
-    }
-  else if (archive_format == arf_tar || archive_format == arf_ustar)
-    {
-      /* The major and minor formats are limited to 7 octal digits in ustar
-	 format, and to_oct () adds a gratuitous trailing blank to further
-	 limit the format to 6 octal digits.  */
-      if ((file_hdr->c_rdev_maj & 0777777) != file_hdr->c_rdev_maj)
-        return 1;
-      if ((file_hdr->c_rdev_min & 0777777) != file_hdr->c_rdev_min)
-        return 2;
-    }
-  else
-    {
-#ifndef __MSDOS__
-      dev_t rdev;
-
-      rdev = makedev (file_hdr->c_rdev_maj, file_hdr->c_rdev_min);
-      if (archive_format != arf_hpbinary)
-	{
-	  if ((rdev & 0xFFFF) != rdev)
-	return 4;
-    }
-  else
-    {
-      switch (file_hdr->c_mode & CP_IFMT)
-	{
-	  case CP_IFCHR:
-	  case CP_IFBLK:
-#ifdef CP_IFSOCK
-	  case CP_IFSOCK:
-#endif
-#ifdef CP_IFIFO
-	  case CP_IFIFO:
-#endif
-	    if ((rdev & 0xFFFFFFFF) != rdev)
-	      return 4;
-	    file_hdr->c_filesize = rdev;
-	    rdev = makedev (0, 1);
-	    break;
-	  default:
-	    if ((rdev & 0xFFFF) != rdev)
-	      return 4;
-	    break;
-	}
-    }
-#endif
-  }
-  return 0;
-}
diff --git a/contrib/cpio/src/copypass.c b/contrib/cpio/src/copypass.c
deleted file mode 100644
index bdcbbeba740..00000000000
--- a/contrib/cpio/src/copypass.c
+++ /dev/null
@@ -1,443 +0,0 @@
-/* $FreeBSD$ */
-
-/* copypass.c - cpio copy pass sub-function.
-   Copyright (C) 1990, 1991, 1992, 2001, 2003, 2004,
-   2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-#include 
-
-#include 
-#include 
-#include 
-#include "filetypes.h"
-#include "cpiohdr.h"
-#include "dstring.h"
-#include "extern.h"
-#include "paxlib.h"
-
-#ifndef HAVE_LCHOWN
-# define lchown chown
-#endif
-
-
-/* A wrapper around set_perms using another set of arguments */
-static void
-set_copypass_perms (int fd, const char *name, struct stat *st)
-{
-  struct cpio_file_stat header;
-  header.c_name = name;
-  stat_to_cpio (&header, st);
-  set_perms (fd, &header);
-}
-
-/* Copy files listed on the standard input into directory `directory_name'.
-   If `link_flag', link instead of copying.  */
-
-void
-process_copy_pass ()
-{
-  dynamic_string input_name;	/* Name of file from stdin.  */
-  dynamic_string output_name;	/* Name of new file.  */
-  int dirname_len;		/* Length of `directory_name'.  */
-  int res;			/* Result of functions.  */
-  char *slash;			/* For moving past slashes in input name.  */
-  struct stat in_file_stat;	/* Stat record for input file.  */
-  struct stat out_file_stat;	/* Stat record for output file.  */
-  int in_file_des;		/* Input file descriptor.  */
-  int out_file_des;		/* Output file descriptor.  */
-  int existing_dir;		/* True if file is a dir & already exists.  */
-#ifdef HPUX_CDF
-  int cdf_flag;
-  int cdf_char;
-#endif
-
-  umask (0);                    /* Reset umask to preserve modes of
-				   created files  */
-
-  /* Initialize the copy pass.  */
-  dirname_len = strlen (directory_name);
-  ds_init (&input_name, 128);
-  ds_init (&output_name, dirname_len + 2);
-  strcpy (output_name.ds_string, directory_name);
-  output_name.ds_string[dirname_len] = '/';
-  output_is_seekable = true;
-
-  /* Copy files with names read from stdin.  */
-  while (ds_fgetstr (stdin, &input_name, name_end) != NULL)
-    {
-      int link_res = -1;
-
-      /* Check for blank line and ignore it if found.  */
-      if (input_name.ds_string[0] == '\0')
-	{
-	  error (0, 0, _("blank line ignored"));
-	  continue;
-	}
-
-      /* Check for current directory and ignore it if found.  */
-      if (input_name.ds_string[0] == '.'
-	  && (input_name.ds_string[1] == '\0'
-	      || (input_name.ds_string[1] == '/'
-		  && input_name.ds_string[2] == '\0')))
-	continue;
-
-      if ((*xstat) (input_name.ds_string, &in_file_stat) < 0)
-	{
-	  stat_error (input_name.ds_string);
-	  continue;
-	}
-
-      /* Make the name of the new file.  */
-      for (slash = input_name.ds_string; *slash == '/'; ++slash)
-	;
-#ifdef HPUX_CDF
-      /* For CDF's we add a 2nd `/' after all "hidden" directories.
-	 This kind of a kludge, but it's what we do when creating
-	 archives, and it's easier to do this than to separately
-	 keep track of which directories in a path are "hidden".  */
-      slash = add_cdf_double_slashes (slash);
-#endif
-      ds_resize (&output_name, dirname_len + strlen (slash) + 2);
-      strcpy (output_name.ds_string + dirname_len + 1, slash);
-
-      existing_dir = false;
-      if (lstat (output_name.ds_string, &out_file_stat) == 0)
-	{
-	  if (S_ISDIR (out_file_stat.st_mode)
-	      && S_ISDIR (in_file_stat.st_mode))
-	    {
-	      /* If there is already a directory there that
-		 we are trying to create, don't complain about it.  */
-	      existing_dir = true;
-	    }
-	  else if (!unconditional_flag
-		   && in_file_stat.st_mtime <= out_file_stat.st_mtime)
-	    {
-	      error (0, 0, _("%s not created: newer or same age version exists"),
-		     output_name.ds_string);
-	      continue;		/* Go to the next file.  */
-	    }
-	  else if (S_ISDIR (out_file_stat.st_mode)
-			? rmdir (output_name.ds_string)
-			: unlink (output_name.ds_string))
-	    {
-	      error (0, errno, _("cannot remove current %s"),
-		     output_name.ds_string);
-	      continue;		/* Go to the next file.  */
-	    }
-	}
-
-      /* Do the real copy or link.  */
-      if (S_ISREG (in_file_stat.st_mode))
-	{
-	  /* Can the current file be linked to a another file?
-	     Set link_name to the original file name.  */
-	  if (link_flag)
-	    /* User said to link it if possible.  Try and link to
-	       the original copy.  If that fails we'll still try
-	       and link to a copy we've already made.  */
-	    link_res = link_to_name (output_name.ds_string, 
-				     input_name.ds_string);
-	  if ( (link_res < 0) && (in_file_stat.st_nlink > 1) )
-	    link_res = link_to_maj_min_ino (output_name.ds_string, 
-				major (in_file_stat.st_dev), 
-				minor (in_file_stat.st_dev), 
-				in_file_stat.st_ino);
-
-	  /* If the file was not linked, copy contents of file.  */
-	  if (link_res < 0)
-	    {
-	      in_file_des = open (input_name.ds_string,
-				  O_RDONLY | O_BINARY, 0);
-	      if (in_file_des < 0)
-		{
-		  open_error (input_name.ds_string);
-		  continue;
-		}
-	      out_file_des = open (output_name.ds_string,
-				   O_CREAT | O_WRONLY | O_BINARY, 0600);
-	      if (out_file_des < 0 && create_dir_flag)
-		{
-		  create_all_directories (output_name.ds_string);
-		  out_file_des = open (output_name.ds_string,
-				       O_CREAT | O_WRONLY | O_BINARY, 0600);
-		}
-	      if (out_file_des < 0)
-		{
-		  open_error (output_name.ds_string);
-		  close (in_file_des);
-		  continue;
-		}
-
-	      copy_files_disk_to_disk (in_file_des, out_file_des, in_file_stat.st_size, input_name.ds_string);
-	      disk_empty_output_buffer (out_file_des);
-	      /* Debian hack to fix a bug in the --sparse option.
-                 This bug has been reported to
-                 "bug-gnu-utils@prep.ai.mit.edu".  (96/7/10) -BEM */
-	      if (delayed_seek_count > 0)
-		{
-		  lseek (out_file_des, delayed_seek_count-1, SEEK_CUR);
-		  write (out_file_des, "", 1);
-		  delayed_seek_count = 0;
-		}
-
-	      set_copypass_perms (out_file_des,
-				  output_name.ds_string, &in_file_stat);
-
-	      if (reset_time_flag)
-                {
-                  set_file_times (in_file_des,
-				  input_name.ds_string,
-                                  in_file_stat.st_atime,
-                                  in_file_stat.st_mtime);
-                  set_file_times (out_file_des,
-				  output_name.ds_string,
-                                  in_file_stat.st_atime,
-                                  in_file_stat.st_mtime);
-	        } 
-
-	      if (close (in_file_des) < 0)
-		close_error (input_name.ds_string);
-
-	      if (close (out_file_des) < 0)
-		close_error (output_name.ds_string);
-
-	      warn_if_file_changed(input_name.ds_string, in_file_stat.st_size,
-                                   in_file_stat.st_mtime);
-	    }
-	}
-      else if (S_ISDIR (in_file_stat.st_mode))
-	{
-#ifdef HPUX_CDF
-	  cdf_flag = 0;
-#endif
-	  if (!existing_dir)
-	    {
-#ifdef HPUX_CDF
-	      /* If the directory name ends in a + and is SUID,
-		 then it is a CDF.  Strip the trailing + from the name
-		 before creating it.  */
-	      cdf_char = strlen (output_name.ds_string) - 1;
-	      if ( (cdf_char > 0) &&
-		   (in_file_stat.st_mode & 04000) &&
-		   (output_name.ds_string [cdf_char] == '+') )
-		{
-		  output_name.ds_string [cdf_char] = '\0';
-		  cdf_flag = 1;
-		}
-#endif
-	      res = mkdir (output_name.ds_string, in_file_stat.st_mode);
-
-	    }
-	  else
-	    res = 0;
-	  if (res < 0 && create_dir_flag)
-	    {
-	      create_all_directories (output_name.ds_string);
-	      res = mkdir (output_name.ds_string, in_file_stat.st_mode);
-	    }
-	  if (res < 0)
-	    {
-	      /* In some odd cases where the output_name includes `.',
-	         the directory may have actually been created by
-	         create_all_directories(), so the mkdir will fail
-	         because the directory exists.  If that's the case,
-	         don't complain about it.  */
-	      if ( (errno != EEXIST) ||
-      		   (lstat (output_name.ds_string, &out_file_stat) != 0) ||
-	           !(S_ISDIR (out_file_stat.st_mode) ) )
-		{
-		  stat_error (output_name.ds_string);
-		  continue;
-		}
-	    }
-	  set_copypass_perms (-1, output_name.ds_string, &in_file_stat);
-	}
-      else if (S_ISCHR (in_file_stat.st_mode) ||
-	       S_ISBLK (in_file_stat.st_mode) ||
-#ifdef S_ISFIFO
-	       S_ISFIFO (in_file_stat.st_mode) ||
-#endif
-#ifdef S_ISSOCK
-	       S_ISSOCK (in_file_stat.st_mode) ||
-#endif
-	       0)
-	{
-	  /* Can the current file be linked to a another file?
-	     Set link_name to the original file name.  */
-	  if (link_flag)
-	    /* User said to link it if possible.  */
-	    link_res = link_to_name (output_name.ds_string, 
-				     input_name.ds_string);
-	  if ( (link_res < 0) && (in_file_stat.st_nlink > 1) )
-	    link_res = link_to_maj_min_ino (output_name.ds_string, 
-			major (in_file_stat.st_dev),
-			minor (in_file_stat.st_dev),
-			in_file_stat.st_ino);
-
-	  if (link_res < 0)
-	    {
-#ifdef S_ISFIFO
-	      if (S_ISFIFO (in_file_stat.st_mode))
-		res = mkfifo (output_name.ds_string, in_file_stat.st_mode);
-	      else
-#endif
-		res = mknod (output_name.ds_string, in_file_stat.st_mode,
-			     in_file_stat.st_rdev);
-	      if (res < 0 && create_dir_flag)
-		{
-		  create_all_directories (output_name.ds_string);
-#ifdef S_ISFIFO
-		  if (S_ISFIFO (in_file_stat.st_mode))
-		    res = mkfifo (output_name.ds_string, in_file_stat.st_mode);
-		  else
-#endif
-		    res = mknod (output_name.ds_string, in_file_stat.st_mode,
-				 in_file_stat.st_rdev);
-		}
-	      if (res < 0)
-		{
-		  mknod_error (output_name.ds_string);
-		  continue;
-		}
-	      set_copypass_perms (-1, output_name.ds_string, &in_file_stat);
-	    }
-	}
-
-#ifdef S_ISLNK
-      else if (S_ISLNK (in_file_stat.st_mode))
-	{
-	  char *link_name;
-	  int link_size;
-	  link_name = (char *) xmalloc ((unsigned int) in_file_stat.st_size + 1);
-
-	  link_size = readlink (input_name.ds_string, link_name,
-			        in_file_stat.st_size);
-	  if (link_size < 0)
-	    {
-	      readlink_error (input_name.ds_string);
-	      free (link_name);
-	      continue;
-	    }
-	  link_name[link_size] = '\0';
-
-	  res = UMASKED_SYMLINK (link_name, output_name.ds_string,
-				 in_file_stat.st_mode);
-	  if (res < 0 && create_dir_flag)
-	    {
-	      create_all_directories (output_name.ds_string);
-	      res = UMASKED_SYMLINK (link_name, output_name.ds_string,
-				     in_file_stat.st_mode);
-	    }
-	  if (res < 0)
-	    {
-	      symlink_error (output_name.ds_string, link_name);
-	      free (link_name);
-	      continue;
-	    }
-
-	  /* Set the attributes of the new link.  */
-	  if (!no_chown_flag)
-            {
-              uid_t uid = set_owner_flag ? set_owner : in_file_stat.st_uid;
-              gid_t gid = set_group_flag ? set_group : in_file_stat.st_gid;
-	      if ((lchown (output_name.ds_string, uid, gid) < 0)
-		  && errno != EPERM)
-	        chown_error_details (output_name.ds_string, uid, gid);
-            }
-	  free (link_name);
-	}
-#endif
-      else
-	{
-	  error (0, 0, _("%s: unknown file type"), input_name.ds_string);
-	}
-
-      if (verbose_flag)
-	fprintf (stderr, "%s\n", output_name.ds_string);
-      if (dot_flag)
-	fputc ('.', stderr);
-    }
-
-  if (dot_flag)
-    fputc ('\n', stderr);
-  if (!quiet_flag)
-    {
-      res = (output_bytes + io_block_size - 1) / io_block_size;
-      fprintf (stderr, ngettext ("%d block\n", "%d blocks\n", res), res);
-    }
-}
-
-/* Try and create a hard link from FILE_NAME to another file 
-   with the given major/minor device number and inode.  If no other
-   file with the same major/minor/inode numbers is known, add this file
-   to the list of known files and associated major/minor/inode numbers
-   and return -1.  If another file with the same major/minor/inode
-   numbers is found, try and create another link to it using
-   link_to_name, and return 0 for success and -1 for failure.  */
-
-int
-link_to_maj_min_ino (char *file_name, int st_dev_maj, int st_dev_min,
-		     int st_ino)
-{
-  int	link_res;
-  char *link_name;
-  link_res = -1;
-  /* Is the file a link to a previously copied file?  */
-  link_name = find_inode_file (st_ino,
-			       st_dev_maj,
-			       st_dev_min);
-  if (link_name == NULL)
-    add_inode (st_ino, file_name,
-	       st_dev_maj,
-	       st_dev_min);
-  else
-    link_res = link_to_name (file_name, link_name);
-  return link_res;
-}
-
-/* Try and create a hard link from LINK_NAME to LINK_TARGET.  If
-   `create_dir_flag' is set, any non-existent (parent) directories 
-   needed by LINK_NAME will be created.  If the link is successfully
-   created and `verbose_flag' is set, print "LINK_TARGET linked to LINK_NAME\n".
-   If the link can not be created and `link_flag' is set, print
-   "cannot link LINK_TARGET to LINK_NAME\n".  Return 0 if the link
-   is created, -1 otherwise.  */
-
-int
-link_to_name (char *link_name, char *link_target)
-{
-  int res = link (link_target, link_name);
-  if (res < 0 && create_dir_flag)
-    {
-      create_all_directories (link_name);
-      res = link (link_target, link_name);
-    }
-  if (res == 0)
-    {
-      if (verbose_flag)
-	error (0, 0, _("%s linked to %s"),
-	       link_target, link_name);
-    }
-  else if (link_flag)
-    {
-      error (0, errno, _("cannot link %s to %s (will copy instead)"),
-	     link_target, link_name);
-    }
-  return res;
-}
diff --git a/contrib/cpio/src/cpio.h b/contrib/cpio/src/cpio.h
deleted file mode 100644
index 34d1cf10e40..00000000000
--- a/contrib/cpio/src/cpio.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/* Extended cpio format from POSIX.1.
-   Copyright (C) 1992, 2005 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-#ifndef _CPIO_H
-
-#define _CPIO_H 1
-
-/* A cpio archive consists of a sequence of files.
-   Each file has a 76 byte header,
-   a variable length, NUL terminated filename,
-   and variable length file data.
-   A header for a filename "TRAILER!!!" indicates the end of the archive.  */
-
-#define CPIO_TRAILER_NAME "TRAILER!!!"
-
-/* All the fields in the header are ISO 646 (approximately ASCII) strings
-   of octal numbers, left padded, not NUL terminated.
-
-   Field Name	Length in Bytes	Notes
-   c_magic	6		must be "070707"
-   c_dev	6
-   c_ino	6
-   c_mode	6		see below for value
-   c_uid	6
-   c_gid	6
-   c_nlink	6
-   c_rdev	6		only valid for chr and blk special files
-   c_mtime	11
-   c_namesize	6		count includes terminating NUL in pathname
-   c_filesize	11		must be 0 for FIFOs and directories  */
-
-/* Values for c_mode, OR'd together: */
-
-#define C_IRUSR		000400
-#define C_IWUSR		000200
-#define C_IXUSR		000100
-#define C_IRGRP		000040
-#define C_IWGRP		000020
-#define C_IXGRP		000010
-#define C_IROTH		000004
-#define C_IWOTH		000002
-#define C_IXOTH		000001
-
-#define C_ISUID		004000
-#define C_ISGID		002000
-#define C_ISVTX		001000
-
-#define C_ISBLK		060000
-#define C_ISCHR		020000
-#define C_ISDIR		040000
-#define C_ISFIFO	010000
-#define C_ISSOCK	0140000
-#define C_ISLNK		0120000
-#define C_ISCTG		0110000
-#define C_ISREG		0100000
-
-#endif /* cpio.h */
diff --git a/contrib/cpio/src/cpiohdr.h b/contrib/cpio/src/cpiohdr.h
deleted file mode 100644
index 503563f8440..00000000000
--- a/contrib/cpio/src/cpiohdr.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/* Extended cpio header from POSIX.1.
-   Copyright (C) 1992, 2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-#ifndef _CPIOHDR_H
-
-#define _CPIOHDR_H 1
-
-#include 
-
-struct old_cpio_header
-{
-  unsigned short c_magic;
-  short c_dev;
-  unsigned short c_ino;
-  unsigned short c_mode;
-  unsigned short c_uid;
-  unsigned short c_gid;
-  unsigned short c_nlink;
-  short c_rdev;
-  unsigned short c_mtimes[2];
-  unsigned short c_namesize;
-  unsigned short c_filesizes[2];
-};
-
-struct old_ascii_header
-{
-  char c_magic[6];
-  char c_dev[6];
-  char c_ino[6];
-  char c_mode[6];
-  char c_uid[6];
-  char c_gid[6];
-  char c_nlink[6];
-  char c_rdev[6];
-  char c_mtime[11];
-  char c_namesize[6];
-  char c_filesize[11];
-};
-
-/* "New" portable format and CRC format:
-
-   Each file has a 110 byte header,
-   a variable length, NUL terminated filename,
-   and variable length file data.
-   A header for a filename "TRAILER!!!" indicates the end of the archive.  */
-
-/* All the fields in the header are ISO 646 (approximately ASCII) strings
-   of hexadecimal numbers, left padded, not NUL terminated: */
-
-struct new_ascii_header
-{
-  char c_magic[6];     /* "070701" for "new" portable format
-			  "070702" for CRC format */
-  char c_ino[8];
-  char c_mode[8];
-  char c_uid[8];
-  char c_gid[8];
-  char c_nlink[8];
-  char c_mtime[8];
-  char c_filesize[8];  /* must be 0 for FIFOs and directories */
-  char c_dev_maj[8];
-  char c_dev_min[8];
-  char c_rdev_maj[8];      /* only valid for chr and blk special files */
-  char c_rdev_min[8];      /* only valid for chr and blk special files */
-  char c_namesize[8];  /* count includes terminating NUL in pathname */
-  char c_chksum[8];    /* 0 for "new" portable format; for CRC format
-			  the sum of all the bytes in the file  */
-};
-
-struct cpio_file_stat /* Internal representation of a CPIO header */
-{
-  unsigned short c_magic;
-  ino_t c_ino;
-  mode_t c_mode;
-  uid_t c_uid;
-  gid_t c_gid;
-  size_t c_nlink;
-  time_t c_mtime;
-  off_t c_filesize;
-  long c_dev_maj;
-  long c_dev_min;
-  long c_rdev_maj;
-  long c_rdev_min;
-  size_t c_namesize;
-  unsigned long c_chksum;
-  char *c_name;
-  char *c_tar_linkname;
-};
-
-
-#endif /* cpiohdr.h */
diff --git a/contrib/cpio/src/defer.c b/contrib/cpio/src/defer.c
deleted file mode 100644
index 83e15dd7c3d..00000000000
--- a/contrib/cpio/src/defer.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/* defer.c - handle "defered" links in newc and crc archives
-   Copyright (C) 1993, 2003, 2004, 2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-#include 
-
-#include 
-#include 
-#include "cpiohdr.h"
-#include "extern.h"
-#include "defer.h"
-
-struct deferment *
-create_deferment (struct cpio_file_stat *file_hdr)
-{
-  struct deferment *d;
-  d = (struct deferment *) xmalloc (sizeof (struct deferment) );
-  d->header = *file_hdr;
-  d->header.c_name = (char *) xmalloc (strlen (file_hdr->c_name) + 1);
-  strcpy (d->header.c_name, file_hdr->c_name);
-  return d;
-}
-
-void
-free_deferment (struct deferment *d)
-{
-  free (d->header.c_name);
-  free (d);
-}
diff --git a/contrib/cpio/src/defer.h b/contrib/cpio/src/defer.h
deleted file mode 100644
index 00aafecc01b..00000000000
--- a/contrib/cpio/src/defer.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/* defer.h
-   Copyright (C) 1993, 2001, 2004, 2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-struct deferment
-  {
-    struct deferment *next;
-    struct cpio_file_stat header;
-  };
-
-struct deferment *create_deferment (struct cpio_file_stat *file_hdr);
-void free_deferment (struct deferment *d);
diff --git a/contrib/cpio/src/dstring.c b/contrib/cpio/src/dstring.c
deleted file mode 100644
index aefeab88ce8..00000000000
--- a/contrib/cpio/src/dstring.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/* dstring.c - The dynamic string handling routines used by cpio.
-   Copyright (C) 1990, 1991, 1992, 2004 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-#if defined(HAVE_CONFIG_H)
-# include 
-#endif
-
-#include 
-#if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
-#include 
-#else
-#include 
-#endif
-#include "dstring.h"
-
-char *xmalloc (unsigned n);
-char *xrealloc (char *p, unsigned n);
-
-/* Initialiaze dynamic string STRING with space for SIZE characters.  */
-
-void
-ds_init (dynamic_string *string, int size)
-{
-  string->ds_length = size;
-  string->ds_string = (char *) xmalloc (size);
-}
-
-/* Expand dynamic string STRING, if necessary, to hold SIZE characters.  */
-
-void
-ds_resize (dynamic_string *string, int size)
-{
-  if (size > string->ds_length)
-    {
-      string->ds_length = size;
-      string->ds_string = (char *) xrealloc ((char *) string->ds_string, size);
-    }
-}
-
-/* Dynamic string S gets a string terminated by the EOS character
-   (which is removed) from file F.  S will increase
-   in size during the function if the string from F is longer than
-   the current size of S.
-   Return NULL if end of file is detected.  Otherwise,
-   Return a pointer to the null-terminated string in S.  */
-
-char *
-ds_fgetstr (FILE *f, dynamic_string *s, char eos)
-{
-  int insize;			/* Amount needed for line.  */
-  int strsize;			/* Amount allocated for S.  */
-  int next_ch;
-
-  /* Initialize.  */
-  insize = 0;
-  strsize = s->ds_length;
-
-  /* Read the input string.  */
-  next_ch = getc (f);
-  while (next_ch != eos && next_ch != EOF)
-    {
-      if (insize >= strsize - 1)
-	{
-	  ds_resize (s, strsize * 2 + 2);
-	  strsize = s->ds_length;
-	}
-      s->ds_string[insize++] = next_ch;
-      next_ch = getc (f);
-    }
-  s->ds_string[insize++] = '\0';
-
-  if (insize == 1 && next_ch == EOF)
-    return NULL;
-  else
-    return s->ds_string;
-}
-
-char *
-ds_fgets (FILE *f, dynamic_string *s)
-{
-  return ds_fgetstr (f, s, '\n');
-}
-
-char *
-ds_fgetname (FILE *f, dynamic_string *s)
-{
-  return ds_fgetstr (f, s, '\0');
-}
diff --git a/contrib/cpio/src/dstring.h b/contrib/cpio/src/dstring.h
deleted file mode 100644
index 3628b99b3f6..00000000000
--- a/contrib/cpio/src/dstring.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* dstring.h - Dynamic string handling include file.  Requires strings.h.
-   Copyright (C) 1990, 1991, 1992, 2004 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-#ifndef NULL
-#define NULL 0
-#endif
-
-/* A dynamic string consists of record that records the size of an
-   allocated string and the pointer to that string.  The actual string
-   is a normal zero byte terminated string that can be used with the
-   usual string functions.  The major difference is that the
-   dynamic_string routines know how to get more space if it is needed
-   by allocating new space and copying the current string.  */
-
-typedef struct
-{
-  int ds_length;		/* Actual amount of storage allocated.  */
-  char *ds_string;		/* String.  */
-} dynamic_string;
-
-
-/* Macros that look similar to the original string functions.
-   WARNING:  These macros work only on pointers to dynamic string records.
-   If used with a real record, an "&" must be used to get the pointer.  */
-#define ds_strlen(s)		strlen ((s)->ds_string)
-#define ds_strcmp(s1, s2)	strcmp ((s1)->ds_string, (s2)->ds_string)
-#define ds_strncmp(s1, s2, n)	strncmp ((s1)->ds_string, (s2)->ds_string, n)
-#define ds_index(s, c)		index ((s)->ds_string, c)
-#define ds_rindex(s, c)		rindex ((s)->ds_string, c)
-
-void ds_init (dynamic_string *string, int size);
-void ds_resize (dynamic_string *string, int size);
-char *ds_fgetname (FILE *f, dynamic_string *s);
-char *ds_fgets (FILE *f, dynamic_string *s);
-char *ds_fgetstr (FILE *f, dynamic_string *s, char eos);
diff --git a/contrib/cpio/src/extern.h b/contrib/cpio/src/extern.h
deleted file mode 100644
index cc5bf89f12e..00000000000
--- a/contrib/cpio/src/extern.h
+++ /dev/null
@@ -1,221 +0,0 @@
-/* extern.h - External declarations for cpio.  Requires system.h.
-   Copyright (C) 1990, 1991, 1992, 2001, 2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-#include "paxlib.h"
-#include "quotearg.h"
-#include "quote.h"
-
-enum archive_format
-{
-  arf_unknown, arf_binary, arf_oldascii, arf_newascii, arf_crcascii,
-  arf_tar, arf_ustar, arf_hpoldascii, arf_hpbinary
-};
-
-extern enum archive_format archive_format;
-extern int reset_time_flag;
-extern int io_block_size;
-extern int create_dir_flag;
-extern int rename_flag;
-extern char *rename_batch_file;
-extern int table_flag;
-extern int unconditional_flag;
-extern int verbose_flag;
-extern int dot_flag;
-extern int link_flag;
-extern int retain_time_flag;
-extern int crc_i_flag;
-extern int append_flag;
-extern int swap_bytes_flag;
-extern int swap_halfwords_flag;
-extern int swapping_bytes;
-extern int swapping_halfwords;
-extern int set_owner_flag;
-extern uid_t set_owner;
-extern int set_group_flag;
-extern gid_t set_group;
-extern int no_chown_flag;
-extern int sparse_flag;
-extern int quiet_flag;
-extern int only_verify_crc_flag;
-extern int abs_paths_flag;
-extern unsigned int warn_option;
-
-/* Values for warn_option */
-#define CPIO_WARN_NONE     0
-#define CPIO_WARN_TRUNCATE 0x01
-#define CPIO_WARN_ALL      (unsigned int)-1
-
-extern bool to_stdout_option;
-
-extern int last_header_start;
-extern int copy_matching_files;
-extern int numeric_uid;
-extern char *pattern_file_name;
-extern char *new_media_message;
-extern char *new_media_message_with_number;
-extern char *new_media_message_after_number;
-extern int archive_des;
-extern char *archive_name;
-extern char *rsh_command_option;
-extern unsigned int crc;
-extern int delayed_seek_count;
-#ifdef DEBUG_CPIO
-extern int debug_flag;
-#endif
-
-extern char *input_buffer, *output_buffer;
-extern char *in_buff, *out_buff;
-extern long input_buffer_size;
-extern long input_size, output_size;
-#ifdef __GNUC__
-extern long long input_bytes, output_bytes;
-#else
-extern long input_bytes, output_bytes;
-#endif
-extern char *directory_name;
-extern char **save_patterns;
-extern int num_patterns;
-extern char name_end;
-extern char input_is_special;
-extern char output_is_special;
-extern char input_is_seekable;
-extern char output_is_seekable;
-extern char *program_name;
-extern int (*xstat) ();
-extern void (*copy_function) ();
-
-
-/* copyin.c */
-void warn_junk_bytes (long bytes_skipped);
-/* FIXME: make read_* static in copyin.c */
-void read_in_header (struct cpio_file_stat *file_hdr, int in_des);
-void read_in_old_ascii (struct cpio_file_stat *file_hdr, int in_des);
-void read_in_new_ascii (struct cpio_file_stat *file_hdr, int in_des);
-void read_in_binary (struct cpio_file_stat *file_hdr,
-		     struct old_cpio_header *short_hdr, int in_des);
-void swab_array (char *arg, int count);
-void process_copy_in (void);
-void long_format (struct cpio_file_stat *file_hdr, char *link_name);
-void print_name_with_quoting (char *p);
-
-/* copyout.c */
-int write_out_header (struct cpio_file_stat *file_hdr, int out_des);
-void process_copy_out (void);
-
-/* copypass.c */
-void process_copy_pass (void);
-int link_to_maj_min_ino (char *file_name, int st_dev_maj, 
-			 int st_dev_min, int st_ino);
-int link_to_name (char *link_name, char *link_target);
-
-/* dirname.c */
-char *dirname (char *path);
-
-/* filemode.c */
-void mode_string (unsigned int mode, char *str);
-
-/* idcache.c */
-#ifndef __MSDOS__
-char *getgroup ();
-char *getuser ();
-uid_t *getuidbyname ();
-gid_t *getgidbyname ();
-#endif
-
-/* main.c */
-void process_args (int argc, char *argv[]);
-void initialize_buffers (void);
-
-/* makepath.c */
-int make_path (char *argpath, int mode, int parent_mode,
-	       uid_t owner, gid_t group, char *verbose_fmt_string);
-
-/* tar.c */
-void write_out_tar_header (struct cpio_file_stat *file_hdr, int out_des);
-int null_block (long *block, int size);
-void read_in_tar_header (struct cpio_file_stat *file_hdr, int in_des);
-int otoa (char *s, unsigned long *n);
-int is_tar_header (char *buf);
-int is_tar_filename_too_long (char *name);
-
-/* userspec.c */
-#ifndef __MSDOS__
-char *parse_user_spec (char *name, uid_t *uid, gid_t *gid,
-		       char **username, char **groupname);
-#endif
-
-/* util.c */
-void tape_empty_output_buffer (int out_des);
-void disk_empty_output_buffer (int out_des);
-void swahw_array (char *ptr, int count);
-void tape_buffered_write (char *in_buf, int out_des, off_t num_bytes);
-void tape_buffered_read (char *in_buf, int in_des, off_t num_bytes);
-int tape_buffered_peek (char *peek_buf, int in_des, int num_bytes);
-void tape_toss_input (int in_des, off_t num_bytes);
-void copy_files_tape_to_disk (int in_des, int out_des, off_t num_bytes);
-void copy_files_disk_to_tape (int in_des, int out_des, off_t num_bytes, char *filename);
-void copy_files_disk_to_disk (int in_des, int out_des, off_t num_bytes, char *filename);
-void warn_if_file_changed (char *file_name, unsigned long old_file_size,
-                           off_t old_file_mtime);
-void create_all_directories (char *name);
-void prepare_append (int out_file_des);
-char *find_inode_file (unsigned long node_num,
-		       unsigned long major_num, unsigned long minor_num);
-void add_inode (unsigned long node_num, char *file_name,
-	        unsigned long major_num, unsigned long minor_num);
-int open_archive (char *file);
-void tape_offline (int tape_des);
-void get_next_reel (int tape_des);
-void set_new_media_message (char *message);
-#if defined(__MSDOS__) && !defined(__GNUC__)
-int chown (char *path, int owner, int group);
-#endif
-#ifdef __TURBOC__
-int utime (char *filename, struct utimbuf *utb);
-#endif
-#ifdef HPUX_CDF
-char *add_cdf_double_slashes (char *filename);
-#endif
-void write_nuls_to_file (off_t num_bytes, int out_des, 
-			 void (*writer) (char *in_buf,
-					 int out_des, off_t num_bytes));
-#define DISK_IO_BLOCK_SIZE	512
-
-/* FIXME: Move to system.h? */
-#ifndef SYMLINK_USES_UMASK
-# define UMASKED_SYMLINK(name1,name2,mode)    symlink(name1,name2)
-#else
-# define UMASKED_SYMLINK(name1,name2,mode)    umasked_symlink(name1,name2,mode)
-#endif /* SYMLINK_USES_UMASK */
-
-void set_perms (int fd, struct cpio_file_stat *header);
-void set_file_times (int fd, const char *name, unsigned long atime,
-		     unsigned long mtime);
-void stat_to_cpio (struct cpio_file_stat *hdr, struct stat *st);
-void cpio_safer_name_suffix (char *name, bool link_target,
-			     bool absolute_names, bool strip_leading_dots);
-
-/* FIXME: These two defines should be defined in paxutils */
-#define LG_8  3
-#define LG_16 4
-
-uintmax_t from_ascii (char const *where, size_t digs, unsigned logbase);
-
-#define FROM_OCTAL(f) from_ascii (f, sizeof f, LG_8)
-#define FROM_HEX(f) from_ascii (f, sizeof f, LG_16)
-	    
diff --git a/contrib/cpio/src/filemode.c b/contrib/cpio/src/filemode.c
deleted file mode 100644
index 98f281370dd..00000000000
--- a/contrib/cpio/src/filemode.c
+++ /dev/null
@@ -1,243 +0,0 @@
-/* filemode.c -- make a string describing file modes
-   Copyright (C) 1985, 1990, 1993, 2004 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-#ifdef HAVE_CONFIG_H
-#include 
-#endif
-
-#include 
-#include 
-
-#if !S_IRUSR
-# if S_IREAD
-#  define S_IRUSR S_IREAD
-# else
-#  define S_IRUSR 00400
-# endif
-#endif
-
-#if !S_IWUSR
-# if S_IWRITE
-#  define S_IWUSR S_IWRITE
-# else
-#  define S_IWUSR 00200
-# endif
-#endif
-
-#if !S_IXUSR
-# if S_IEXEC
-#  define S_IXUSR S_IEXEC
-# else
-#  define S_IXUSR 00100
-# endif
-#endif
-
-#ifdef STAT_MACROS_BROKEN
-#undef S_ISBLK
-#undef S_ISCHR
-#undef S_ISDIR
-#undef S_ISFIFO
-#undef S_ISLNK
-#undef S_ISMPB
-#undef S_ISMPC
-#undef S_ISNWK
-#undef S_ISREG
-#undef S_ISSOCK
-#endif /* STAT_MACROS_BROKEN.  */
-
-#if !defined(S_ISBLK) && defined(S_IFBLK)
-#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
-#endif
-#if !defined(S_ISCHR) && defined(S_IFCHR)
-#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
-#endif
-#if !defined(S_ISDIR) && defined(S_IFDIR)
-#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
-#endif
-#if !defined(S_ISREG) && defined(S_IFREG)
-#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
-#endif
-#if !defined(S_ISFIFO) && defined(S_IFIFO)
-#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
-#endif
-#if !defined(S_ISLNK) && defined(S_IFLNK)
-#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
-#endif
-#if !defined(S_ISSOCK) && defined(S_IFSOCK)
-#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
-#endif
-#if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
-#define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
-#define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
-#endif
-#if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
-#define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
-#endif
-
-/* Return a character indicating the type of file described by
-   file mode BITS:
-   'd' for directories
-   'b' for block special files
-   'c' for character special files
-   'm' for multiplexor files
-   'l' for symbolic links
-   's' for sockets
-   'p' for fifos
-   '-' for regular files
-   '?' for any other file type.  */
-
-static char
-ftypelet (long bits)
-{
-#ifdef S_ISBLK
-  if (S_ISBLK (bits))
-    return 'b';
-#endif
-  if (S_ISCHR (bits))
-    return 'c';
-  if (S_ISDIR (bits))
-    return 'd';
-  if (S_ISREG (bits))
-    return '-';
-#ifdef S_ISFIFO
-  if (S_ISFIFO (bits))
-    return 'p';
-#endif
-#ifdef S_ISLNK
-  if (S_ISLNK (bits))
-    return 'l';
-#endif
-#ifdef S_ISSOCK
-  if (S_ISSOCK (bits))
-    return 's';
-#endif
-#ifdef S_ISMPC
-  if (S_ISMPC (bits))
-    return 'm';
-#endif
-#ifdef S_ISNWK
-  if (S_ISNWK (bits))
-    return 'n';
-#endif
-  return '?';
-}
-
-/* Look at read, write, and execute bits in BITS and set
-   flags in CHARS accordingly.  */
-
-static void
-rwx (unsigned short bits, char *chars)
-{
-  chars[0] = (bits & S_IRUSR) ? 'r' : '-';
-  chars[1] = (bits & S_IWUSR) ? 'w' : '-';
-  chars[2] = (bits & S_IXUSR) ? 'x' : '-';
-}
-
-/* Set the 's' and 't' flags in file attributes string CHARS,
-   according to the file mode BITS.  */
-
-static void
-setst (unsigned short bits, char *chars)
-{
-#ifdef S_ISUID
-  if (bits & S_ISUID)
-    {
-      if (chars[3] != 'x')
-	/* Set-uid, but not executable by owner.  */
-	chars[3] = 'S';
-      else
-	chars[3] = 's';
-    }
-#endif
-#ifdef S_ISGID
-  if (bits & S_ISGID)
-    {
-      if (chars[6] != 'x')
-	/* Set-gid, but not executable by group.  */
-	chars[6] = 'S';
-      else
-	chars[6] = 's';
-    }
-#endif
-#ifdef S_ISVTX
-  if (bits & S_ISVTX)
-    {
-      if (chars[9] != 'x')
-	/* Sticky, but not executable by others.  */
-	chars[9] = 'T';
-      else
-	chars[9] = 't';
-    }
-#endif
-}
-
-/* Like filemodestring (see below), but only the relevant part of the
-   `struct stat' is given as an argument.  */
-
-void
-mode_string (unsigned short mode, char *str)
-{
-  str[0] = ftypelet ((long) mode);
-  rwx ((mode & 0700) << 0, &str[1]);
-  rwx ((mode & 0070) << 3, &str[4]);
-  rwx ((mode & 0007) << 6, &str[7]);
-  setst (mode, str);
-}
-
-/* filemodestring - fill in string STR with an ls-style ASCII
-   representation of the st_mode field of file stats block STATP.
-   10 characters are stored in STR; no terminating null is added.
-   The characters stored in STR are:
-
-   0	File type.  'd' for directory, 'c' for character
-	special, 'b' for block special, 'm' for multiplex,
-	'l' for symbolic link, 's' for socket, 'p' for fifo,
-	'-' for regular, '?' for any other file type
-
-   1	'r' if the owner may read, '-' otherwise.
-
-   2	'w' if the owner may write, '-' otherwise.
-
-   3	'x' if the owner may execute, 's' if the file is
-	set-user-id, '-' otherwise.
-	'S' if the file is set-user-id, but the execute
-	bit isn't set.
-
-   4	'r' if group members may read, '-' otherwise.
-
-   5	'w' if group members may write, '-' otherwise.
-
-   6	'x' if group members may execute, 's' if the file is
-	set-group-id, '-' otherwise.
-	'S' if it is set-group-id but not executable.
-
-   7	'r' if any user may read, '-' otherwise.
-
-   8	'w' if any user may write, '-' otherwise.
-
-   9	'x' if any user may execute, 't' if the file is "sticky"
-	(will be retained in swap space after execution), '-'
-	otherwise.
-	'T' if the file is sticky but not executable.  */
-
-void
-filemodestring (struct stat *statp, char *str)
-{
-  mode_string (statp->st_mode, str);
-}
-
diff --git a/contrib/cpio/src/filetypes.h b/contrib/cpio/src/filetypes.h
deleted file mode 100644
index de6d77f6284..00000000000
--- a/contrib/cpio/src/filetypes.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/* filetypes.h - deal with POSIX annoyances
-   Copyright (C) 1991 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-/* Include sys/types.h and sys/stat.h before this file.  */
-
-#ifndef S_ISREG			/* Doesn't have POSIX.1 stat stuff.  */
-#define mode_t unsigned short
-#endif
-
-/* Define the POSIX macros for systems that lack them.  */
-#if !defined(S_ISBLK) && defined(S_IFBLK)
-#define	S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
-#endif
-#if !defined(S_ISCHR) && defined(S_IFCHR)
-#define	S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
-#endif
-#if !defined(S_ISDIR) && defined(S_IFDIR)
-#define	S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
-#endif
-#if !defined(S_ISREG) && defined(S_IFREG)
-#define	S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
-#endif
-#if !defined(S_ISFIFO) && defined(S_IFIFO)
-#define	S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
-#endif
-#if !defined(S_ISLNK) && defined(S_IFLNK)
-#define	S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
-#endif
-#if !defined(S_ISSOCK) && defined(S_IFSOCK)
-#define	S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
-#endif
-#if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX network special */
-#define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
-#endif
-
-/* Define the file type bits used in cpio archives.
-   They have the same values as the S_IF bits in traditional Unix.  */
-
-#define	CP_IFMT 0170000		/* Mask for all file type bits.  */
-
-#if defined(S_ISBLK)
-#define CP_IFBLK 0060000
-#endif
-#if defined(S_ISCHR)
-#define CP_IFCHR 0020000
-#endif
-#if defined(S_ISDIR)
-#define CP_IFDIR 0040000
-#endif
-#if defined(S_ISREG)
-#define CP_IFREG 0100000
-#endif
-#if defined(S_ISFIFO)
-#define CP_IFIFO 0010000
-#endif
-#if defined(S_ISLNK)
-#define CP_IFLNK 0120000
-#endif
-#if defined(S_ISSOCK)
-#define CP_IFSOCK 0140000
-#endif
-#if defined(S_ISNWK)
-#define CP_IFNWK 0110000
-#endif
-
-#ifndef S_ISLNK
-#define lstat stat
-#endif
-int lstat ();
-int stat ();
diff --git a/contrib/cpio/src/global.c b/contrib/cpio/src/global.c
deleted file mode 100644
index fdee7be34d7..00000000000
--- a/contrib/cpio/src/global.c
+++ /dev/null
@@ -1,201 +0,0 @@
-/* global.c - global variables and initial values for cpio.
-   Copyright (C) 1990, 1991, 1992, 2001, 2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-#include 
-
-#include 
-#include "cpiohdr.h"
-#include "dstring.h"
-#include "extern.h"
-
-/* If true, reset access times after reading files (-a).  */
-int reset_time_flag = false;
-
-/* Block size value, initially 512.  -B sets to 5120.  */
-int io_block_size = 512;
-
-/* The header format to recognize and produce.  */
-enum archive_format archive_format = arf_unknown;
-
-/* If true, create directories as needed. (-d with -i or -p) */
-int create_dir_flag = false;
-
-/* If true, interactively rename files. (-r) */
-int rename_flag = false;
-
-/* If non-NULL, the name of a file that will be read to
-   rename all of the files in the archive.  --rename-batch-file.  */
-char *rename_batch_file = NULL;
-
-/* If true, print a table of contents of input. (-t) */
-int table_flag = false;
-
-/* If true, copy unconditionally (older replaces newer). (-u) */
-int unconditional_flag = false;
-
-/* If true, list the files processed, or ls -l style output with -t. (-v) */
-int verbose_flag = false;
-
-/* If true, print a . for each file processed. (-V) */
-int dot_flag = false;
-
-/* If true, link files whenever possible.  Used with -p option. (-l) */
-int link_flag = false;
-
-/* If true, retain previous file modification time. (-m) */
-int retain_time_flag = false;
-
-/* Set true if crc_flag is true and we are doing a cpio -i.  Used
-   by copy_files so it knows whether to compute the crc.  */
-int crc_i_flag = false;
-
-/* If true, append to end of archive. (-A) */
-int append_flag = false;
-
-/* If true, swap bytes of each file during cpio -i.  */
-int swap_bytes_flag = false;
-
-/* If true, swap halfwords of each file during cpio -i.  */
-int swap_halfwords_flag = false;
-
-/* If true, we are swapping halfwords on the current file.  */
-int swapping_halfwords = false;
-
-/* If true, we are swapping bytes on the current file.  */
-int swapping_bytes = false;
-
-/* If true, set ownership of all files to UID `set_owner'.  */
-int set_owner_flag = false;
-uid_t set_owner;
-
-/* If true, set group ownership of all files to GID `set_group'.  */
-int set_group_flag = false;
-gid_t set_group;
-
-/* If true, do not chown the files.  */
-int no_chown_flag = false;
-
-/* If true, try to write sparse ("holey") files.  */
-int sparse_flag = false;
-
-/* If true, don't report number of blocks copied.  */
-int quiet_flag = false;
-
-/* If true, only read the archive and verify the files' CRC's, don't
-   actually extract the files. */
-int only_verify_crc_flag = false;
-
-/* If true, don't use any absolute paths, prefix them by `./'.  */
-int abs_paths_flag = false;
-
-#ifdef DEBUG_CPIO
-/* If true, print debugging information.  */
-int debug_flag = false;
-#endif
-
-/* File position of last header read.  Only used during -A to determine
-   where the old TRAILER!!! record started.  */
-int last_header_start = 0;
-
-/* With -i; if true, copy only files that match any of the given patterns;
-   if false, copy only files that do not match any of the patterns. (-f) */
-int copy_matching_files = true;
-
-/* With -itv; if true, list numeric uid and gid instead of translating them
-   into names.  */
-int numeric_uid = false;
-
-/* Name of file containing additional patterns (-E).  */
-char *pattern_file_name = NULL;
-
-/* Message to print when end of medium is reached (-M).  */
-char *new_media_message = NULL;
-
-/* With -M with %d, message to print when end of medium is reached.  */
-char *new_media_message_with_number = NULL;
-char *new_media_message_after_number = NULL;
-
-/* File descriptor containing the archive.  */
-int archive_des;
-
-/* Name of file containing the archive, if known; NULL if stdin/out.  */
-char *archive_name = NULL;
-
-/* Name of the remote shell command, if known; NULL otherwise.  */
-char *rsh_command_option = NULL;
-
-/* CRC checksum.  */
-unsigned int crc;
-
-/* Input and output buffers.  */
-char *input_buffer, *output_buffer;
-
-/* The size of the input buffer.  */
-long input_buffer_size;
-
-/* Current locations in `input_buffer' and `output_buffer'.  */
-char *in_buff, *out_buff;
-
-/* Current number of bytes stored at `input_buff' and `output_buff'.  */
-long input_size, output_size;
-
-/* Total number of bytes read and written for all files.  
-   Now that many tape drives hold more than 4Gb we need more than 32
-   bits to hold input_bytes and output_bytes.  But it's not worth
-   the trouble of adding special multi-precision arithmetic if the 
-   compiler doesn't support 64 bit ints since input_bytes and
-   output_bytes are only used to print the number of blocks copied.  */
-#ifdef __GNUC__
-long long input_bytes, output_bytes;
-#else
-long input_bytes, output_bytes;
-#endif
-
-/* Saving of argument values for later reference.  */
-char *directory_name = NULL;
-char **save_patterns;
-int num_patterns;
-
-/* Character that terminates file names read from stdin.  */
-char name_end = '\n';
-
-/* true if input (cpio -i) or output (cpio -o) is a device node.  */
-char input_is_special = false;
-char output_is_special = false;
-
-/* true if lseek works on the input.  */
-char input_is_seekable = false;
-
-/* true if lseek works on the output.  */
-char output_is_seekable = false;
-
-/* Print extra warning messages */
-unsigned int warn_option = 0;
-
-/* Extract to standard output? */
-bool to_stdout_option = false;
-
-/* The name this program was run with.  */
-char *program_name;
-
-/* A pointer to either lstat or stat, depending on whether
-   dereferencing of symlinks is done for input files.  */
-int (*xstat) ();
-
-/* Which copy operation to perform. (-i, -o, -p) */
-void (*copy_function) () = 0;
diff --git a/contrib/cpio/src/idcache.c b/contrib/cpio/src/idcache.c
deleted file mode 100644
index 17fcc04e238..00000000000
--- a/contrib/cpio/src/idcache.c
+++ /dev/null
@@ -1,207 +0,0 @@
-/* idcache.c -- map user and group IDs, cached for speed
-   Copyright (C) 1985, 1988, 1989, 1990, 2004 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-#ifdef HAVE_CONFIG_H
-#include 
-#endif
-
-#include 
-#include 
-#include 
-#include 
-
-#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
-#include 
-#else
-#include 
-#endif
-
-#ifdef HAVE_UNISTD_H
-#include 
-#endif
-#ifndef _POSIX_VERSION
-struct passwd *getpwuid ();
-struct passwd *getpwnam ();
-struct group *getgrgid ();
-struct group *getgrnam ();
-#endif
-
-char *xmalloc ();
-char *xstrdup ();
-
-struct userid
-{
-  union
-    {
-      uid_t u;
-      gid_t g;
-    } id;
-  char *name;
-  struct userid *next;
-};
-
-static struct userid *user_alist;
-
-/* The members of this list have names not in the local passwd file.  */
-static struct userid *nouser_alist;
-
-/* Translate UID to a login name or a stringified number,
-   with cache.  */
-
-char *
-getuser (uid_t uid)
-{
-  register struct userid *tail;
-  struct passwd *pwent;
-  char usernum_string[20];
-
-  for (tail = user_alist; tail; tail = tail->next)
-    if (tail->id.u == uid)
-      return tail->name;
-
-  pwent = getpwuid (uid);
-  tail = (struct userid *) xmalloc (sizeof (struct userid));
-  tail->id.u = uid;
-  if (pwent == 0)
-    {
-      sprintf (usernum_string, "%u", (unsigned) uid);
-      tail->name = xstrdup (usernum_string);
-    }
-  else
-    tail->name = xstrdup (pwent->pw_name);
-
-  /* Add to the head of the list, so most recently used is first.  */
-  tail->next = user_alist;
-  user_alist = tail;
-  return tail->name;
-}
-
-/* Translate USER to a UID, with cache.
-   Return NULL if there is no such user.
-   (We also cache which user names have no passwd entry,
-   so we don't keep looking them up.)  */
-
-uid_t *
-getuidbyname (char *user)
-{
-  register struct userid *tail;
-  struct passwd *pwent;
-
-  for (tail = user_alist; tail; tail = tail->next)
-    /* Avoid a function call for the most common case.  */
-    if (*tail->name == *user && !strcmp (tail->name, user))
-      return &tail->id.u;
-
-  for (tail = nouser_alist; tail; tail = tail->next)
-    /* Avoid a function call for the most common case.  */
-    if (*tail->name == *user && !strcmp (tail->name, user))
-      return 0;
-
-  pwent = getpwnam (user);
-
-  tail = (struct userid *) xmalloc (sizeof (struct userid));
-  tail->name = xstrdup (user);
-
-  /* Add to the head of the list, so most recently used is first.  */
-  if (pwent)
-    {
-      tail->id.u = pwent->pw_uid;
-      tail->next = user_alist;
-      user_alist = tail;
-      return &tail->id.u;
-    }
-
-  tail->next = nouser_alist;
-  nouser_alist = tail;
-  return 0;
-}
-
-/* Use the same struct as for userids.  */
-static struct userid *group_alist;
-static struct userid *nogroup_alist;
-
-/* Translate GID to a group name or a stringified number,
-   with cache.  */
-
-char *
-getgroup (gid_t gid)
-{
-  register struct userid *tail;
-  struct group *grent;
-  char groupnum_string[20];
-
-  for (tail = group_alist; tail; tail = tail->next)
-    if (tail->id.g == gid)
-      return tail->name;
-
-  grent = getgrgid (gid);
-  tail = (struct userid *) xmalloc (sizeof (struct userid));
-  tail->id.g = gid;
-  if (grent == 0)
-    {
-      sprintf (groupnum_string, "%u", (unsigned int) gid);
-      tail->name = xstrdup (groupnum_string);
-    }
-  else
-    tail->name = xstrdup (grent->gr_name);
-
-  /* Add to the head of the list, so most recently used is first.  */
-  tail->next = group_alist;
-  group_alist = tail;
-  return tail->name;
-}
-
-/* Translate GROUP to a UID, with cache.
-   Return NULL if there is no such group.
-   (We also cache which group names have no group entry,
-   so we don't keep looking them up.)  */
-
-gid_t *
-getgidbyname (char *group)
-{
-  register struct userid *tail;
-  struct group *grent;
-
-  for (tail = group_alist; tail; tail = tail->next)
-    /* Avoid a function call for the most common case.  */
-    if (*tail->name == *group && !strcmp (tail->name, group))
-      return &tail->id.g;
-
-  for (tail = nogroup_alist; tail; tail = tail->next)
-    /* Avoid a function call for the most common case.  */
-    if (*tail->name == *group && !strcmp (tail->name, group))
-      return 0;
-
-  grent = getgrnam (group);
-
-  tail = (struct userid *) xmalloc (sizeof (struct userid));
-  tail->name = xstrdup (group);
-
-  /* Add to the head of the list, so most recently used is first.  */
-  if (grent)
-    {
-      tail->id.g = grent->gr_gid;
-      tail->next = group_alist;
-      group_alist = tail;
-      return &tail->id.g;
-    }
-
-  tail->next = nogroup_alist;
-  nogroup_alist = tail;
-  return 0;
-}
diff --git a/contrib/cpio/src/main.c b/contrib/cpio/src/main.c
deleted file mode 100644
index 675f61e1820..00000000000
--- a/contrib/cpio/src/main.c
+++ /dev/null
@@ -1,804 +0,0 @@
-/* $FreeBSD$ */
-
-/* main.c - main program and argument processing for cpio.
-   Copyright (C) 1990, 1991, 1992, 2001, 2003, 2004, 2005, 2006
-   Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-/* Written by Phil Nelson ,
-   David MacKenzie ,
-   John Oleynick ,
-   and Sergey Poznyakoff  */
-
-#include 
-#include 
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#ifdef HAVE_LOCALE_H
-# include 
-#endif
-
-#include "filetypes.h"
-#include "cpiohdr.h"
-#include "dstring.h"
-#include "extern.h"
-#include 
-#include 
-
-enum cpio_options {
-  NO_ABSOLUTE_FILENAMES_OPTION=256,
-  ABSOLUTE_FILENAMES_OPTION,  
-  NO_PRESERVE_OWNER_OPTION,      
-  ONLY_VERIFY_CRC_OPTION,        
-  RENAME_BATCH_FILE_OPTION,      
-  RSH_COMMAND_OPTION,            
-  QUIET_OPTION,                  
-  SPARSE_OPTION,                 
-  FORCE_LOCAL_OPTION,            
-  DEBUG_OPTION,                  
-  BLOCK_SIZE_OPTION,             
-  TO_STDOUT_OPTION,
-  
-  HANG_OPTION,
-  USAGE_OPTION,               
-  LICENSE_OPTION,             
-  VERSION_OPTION
-};
-
-const char *argp_program_version = "cpio (" PACKAGE_NAME ") " VERSION;
-const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">";
-static char doc[] = N_("GNU `cpio' copies files to and from archives\n\
-\n\
-Examples:\n\
-  # Copy files named in name-list to the archive\n\
-  cpio -o < name-list [> archive]\n\
-  # Extract files from the archive\n\
-  cpio -i [< archive]\n\
-  # Copy files named in name-list to destination-directory\n\
-  cpio -p destination-directory < name-list\n");
-
-/*  Print usage error message and exit with error.  */
-
-#define CHECK_USAGE(cond, opt, mode_opt) \
- if (cond) \
-   ERROR((PAXEXIT_FAILURE, 0, _("%s is meaningless with %s"), opt, mode_opt));
-
-static struct argp_option options[] = {
-  /* ********** */
-#define GRID 10
-  {NULL, 0, NULL, 0,
-   N_("Main operation mode:"), GRID },
-  {"create", 'o', 0, 0,
-   N_("Create the archive (run in copy-out mode)"), GRID },
-  {"extract", 'i', 0, 0,
-   N_("Extract files from an archive (run in copy-in mode)"), GRID },
-  {"pass-through", 'p', 0, 0,
-   N_("Run in copy-pass mode"), GRID },
-  {"list", 't', 0, 0,
-   N_("Print a table of contents of the input"), GRID },
-#undef GRID
-  
-  /* ********** */
-#define GRID 100  
-  {NULL, 0, NULL, 0,
-   N_("Operation modifiers valid in any mode:"), GRID },
-
-  {"file", 'F', N_("[[USER@]HOST:]FILE-NAME"), 0,
-   N_("Use this FILE-NAME instead of standard input or output. Optional USER and HOST specify the user and host names in case of a remote archive"), GRID+1 },
-  {"force-local", FORCE_LOCAL_OPTION, 0, 0,
-   N_("Archive file is local, even if its name contains colons"), GRID+1 },
-  {"format", 'H', N_("FORMAT"), 0,
-   N_("Use given archive FORMAT"), GRID+1 },
-  {NULL, 'B', NULL, 0,
-   N_("Set the I/O block size to 5120 bytes"), GRID+1 },
-  {"block-size", BLOCK_SIZE_OPTION, N_("BLOCK-SIZE"), 0,
-   N_("Set the I/O block size to BLOCK-SIZE * 512 bytes"), GRID+1 },
-  {NULL, 'c', NULL, 0,
-   N_("Use the old portable (ASCII) archive format"), GRID+1 },
-  {"dot", 'V', NULL, 0, 
-   N_("Print a \".\" for each file processed"), GRID+1 },
-  {"io-size", 'C', N_("NUMBER"), 0,
-   N_("Set the I/O block size to the given NUMBER of bytes"), GRID+1 },
-  {"message", 'M', N_("STRING"), 0,
-   N_("Print STRING when the end of a volume of the backup media is reached"),
-   GRID+1 },
-  {"nonmatching", 'f', 0, 0,
-   N_("Only copy files that do not match any of the given patterns"), GRID+1 },
-  {"numeric-uid-gid", 'n', 0, 0,
-   N_("In the verbose table of contents listing, show numeric UID and GID"),
-   GRID+1 },
-  {"rsh-command", RSH_COMMAND_OPTION, N_("COMMAND"), 0,
-   N_("Use remote COMMAND instead of rsh"), GRID+1 },
-  {"quiet", QUIET_OPTION, NULL, 0,
-   N_("Do not print the number of blocks copied"), GRID+1 },
-  {"verbose", 'v', NULL, 0,
-   N_("Verbosely list the files processed"), GRID+1 },
-#ifdef DEBUG_CPIO
-  {"debug", DEBUG_OPTION, NULL, 0,
-   N_("Enable debugging info"), GRID+1 },
-#endif
-  {"warning", 'W', N_("FLAG"), 0,
-   N_("Control warning display. Currently FLAG is one of 'none', 'truncate', 'all'. Multiple options accumulate."), GRID+1 },
-#undef GRID
-  
-  /* ********** */
-#define GRID 200  
-  {NULL, 0, NULL, 0,
-   N_("Operation modifiers valid only in copy-in mode:"), GRID },
-  {"pattern-file", 'E', N_("FILE"), 0,
-   N_("Read additional patterns specifying filenames to extract or list from FILE"), 210},
-  {"absolute-filenames", ABSOLUTE_FILENAMES_OPTION, 0, 0,
-   N_("do not strip leading file name components that contain \"..\" and leading slashes from file names"), 210},
-  {"only-verify-crc", ONLY_VERIFY_CRC_OPTION, 0, 0,
-   N_("When reading a CRC format archive, only verify the CRC's of each file in the archive, don't actually extract the files"), 210},
-  {"rename", 'r', 0, 0,
-   N_("Interactively rename files"), GRID+1 },
-  {"rename-batch-file", RENAME_BATCH_FILE_OPTION, N_("FILE"), OPTION_HIDDEN,
-   "", GRID+1 },
-  {"swap", 'b', NULL, 0,
-   N_("Swap both halfwords of words and bytes of halfwords in the data. Equivalent to -sS"), GRID+1 },
-  {"swap-bytes", 's', NULL, 0,
-   N_("Swap the bytes of each halfword in the files"), GRID+1 },
-  {"swap-halfwords", 'S', NULL, 0,
-   N_("Swap the halfwords of each word (4 bytes) in the files"),
-   GRID+1 },
-  {"to-stdout", TO_STDOUT_OPTION, NULL, 0,
-   N_("Extract files to standard output"), GRID+1 },
-#undef GRID   
-
-  /* ********** */
-#define GRID 300
-  {NULL, 0, NULL, 0,
-   N_("Operation modifiers valid only in copy-out mode:"), GRID },
-  {"append", 'A', 0, 0,
-   N_("Append to an existing archive."), GRID+1 },
-  {NULL, 'O', N_("[[USER@]HOST:]FILE-NAME"), 0,
-   N_("Archive filename to use instead of standard output. Optional USER and HOST specify the user and host names in case of a remote archive"), GRID+1 },
-#undef GRID
-  
-  /* ********** */
-#define GRID 400
-  {NULL, 0, NULL, 0,
-   N_("Operation modifiers valid only in copy-pass mode:"), GRID},
-  {"link", 'l', 0, 0,
-   N_("Link files instead of copying them, when  possible"), GRID+1 },
-
-#undef GRID
-  
-  /* ********** */
-#define GRID 500
-  {NULL, 0, NULL, 0,
-   N_("Operation modifiers valid in copy-in and copy-out modes:"), GRID },
-  {"absolute-filenames", ABSOLUTE_FILENAMES_OPTION, 0, 0,
-   N_("Do not strip file system prefix components from the file names"),
-   GRID+1 },
-  {"no-absolute-filenames", NO_ABSOLUTE_FILENAMES_OPTION, 0, 0,
-   N_("Create all files relative to the current directory"), GRID+1 },
-#undef GRID  
-  /* ********** */
-#define GRID 600
-  {NULL, 0, NULL, 0,
-   N_("Operation modifiers valid in copy-out and copy-pass modes:"), GRID },
-  {"null", '0', 0, 0,
-   N_("A list of filenames is terminated by a null character instead of a newline"), GRID+1 },
-  {NULL, 'I', N_("[[USER@]HOST:]FILE-NAME"), 0,
-   N_("Archive filename to use instead of standard input. Optional USER and HOST specify the user and host names in case of a remote archive"), GRID+1 },
-  {"dereference", 'L', 0, 0,
-   N_("Dereference  symbolic  links  (copy  the files that they point to instead of copying the links)."), GRID+1 },
-  {"owner", 'R', N_("[USER][:.][GROUP]"), 0,
-   N_("Set the ownership of all files created to the specified USER and/or GROUP"), GRID+1 },
-  {"reset-access-time", 'a', NULL, 0,
-   N_("Reset the access times of files after reading them"), GRID+1 },
-
-#undef GRID   
-  /* ********** */
-#define GRID 700
-  {NULL, 0, NULL, 0,
-   N_("Operation modifiers valid in copy-in and copy-pass modes:"), GRID },
-  {"preserve-modification-time", 'm', 0, 0,
-   N_("Retain previous file modification times when creating files"), GRID+1 },
-  {"make-directories", 'd', 0, 0,
-   N_("Create leading directories where needed"), GRID+1 },
-  {"no-preserve-owner", NO_PRESERVE_OWNER_OPTION, 0, 0,
-   N_("Do not change the ownership of the files"), GRID+1 },
-  {"unconditional", 'u', NULL, 0,
-   N_("Replace all files unconditionally"), GRID+1 },
-  {"sparse", SPARSE_OPTION, NULL, 0,
-   N_("Write files with large blocks of zeros as sparse files"), GRID+1 },
-#undef GRID
-  
-  /* ********** */
-#define GRID 800
-  {NULL, 0, NULL, 0,
-   N_("Informative options:"), GRID },
-
-  {"help",  '?', 0, 0,  N_("Give this help list"), -1},
-  {"usage", USAGE_OPTION, 0, 0,  N_("Give a short usage message"), -1},
-  {"license", LICENSE_OPTION, 0, 0, N_("Print license and exit"), -1},
-  {"version", VERSION_OPTION, 0, 0,  N_("Print program version"), -1},
-  /* FIXME -V (--dot) conflicts with the default short option for
-     --version */
-  {"HANG",	  HANG_OPTION,    "SECS", OPTION_ARG_OPTIONAL | OPTION_HIDDEN,
-   N_("hang for SECS seconds (default 3600)"), 0},
-#undef GRID     
-  {0, 0, 0, 0}
-};
-
-static char *input_archive_name = 0;
-static char *output_archive_name = 0;
-
-static void
-license ()
-{
-  printf ("%s (%s) %s\n%s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION,
-	  "Copyright (C) 2004 Free Software Foundation, Inc.\n");
-  printf (_("   GNU cpio is free software; you can redistribute it and/or modify\n"
-    "   it under the terms of the GNU General Public License as published by\n"
-    "   the Free Software Foundation; either version 2 of the License, or\n"
-    "   (at your option) any later version.\n"
-    "\n"
-    "   GNU cpio is distributed in the hope that it will be useful,\n"
-    "   but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
-    "   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
-    "   GNU General Public License for more details.\n"
-    "\n"
-    "   You should have received a copy of the GNU General Public License\n"
-    "   along with GNU cpio; if not, write to the Free Software Foundation,\n"
-    "   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n\n"));
-  exit (0);
-}
-
-static int
-warn_control (char *arg)
-{
-  static struct warn_tab {
-    char *name;
-    int flag;
-  } warn_tab[] = {
-    { "none",       CPIO_WARN_ALL       },
-    { "truncate",   CPIO_WARN_TRUNCATE  },
-    { "all",        CPIO_WARN_ALL       },
-    { NULL }
-  };
-  struct warn_tab *wt;
-  int offset = 0;
-
-  if (strcmp (arg, "none") == 0)
-    {
-      warn_option = 0;
-      return 0;
-    }
-  
-  if (strlen (arg) > 2 && memcmp (arg, "no-", 3) == 0)
-    offset = 3;
-      
-  for (wt = warn_tab; wt->name; wt++)
-    if (strcmp (arg + offset, wt->name) == 0)
-      {
-	if (offset)
-	  warn_option &= ~wt->flag;
-	else
-	  warn_option |= wt->flag;
-	return 0;
-      }
-
-  return 1;
-}
-
-static error_t
-parse_opt (int key, char *arg, struct argp_state *state)
-{
-  static volatile int _argp_hang;
-  switch (key)
-    {
-    case '0':		/* Read null-terminated filenames.  */
-      name_end = '\0';
-      break;
-
-    case 'a':		/* Reset access times.  */
-      reset_time_flag = true;
-      break;
-
-    case 'A':		/* Append to the archive.  */
-      append_flag = true;
-      break;
-
-    case 'b':		/* Swap bytes and halfwords.  */
-      swap_bytes_flag = true;
-      swap_halfwords_flag = true;
-      break;
-
-    case 'B':		/* Set block size to 5120.  */
-      io_block_size = 5120;
-      break;
-
-    case BLOCK_SIZE_OPTION:		/* --block-size */
-      io_block_size = atoi (arg);
-      if (io_block_size < 1)
-	error (2, 0, _("invalid block size"));
-      io_block_size *= 512;
-      break;
-
-    case 'c':		/* Use the old portable ASCII format.  */
-      if (archive_format != arf_unknown)
-	error (0, EXIT_FAILURE, _("Archive format multiply defined"));
-#ifdef SVR4_COMPAT
-      archive_format = arf_newascii; /* -H newc.  */
-#else
-      archive_format = arf_oldascii; /* -H odc.  */
-#endif
-      break;
-
-    case 'C':		/* Block size.  */
-      io_block_size = atoi (arg);
-      if (io_block_size < 1)
-	error (2, 0, _("invalid block size"));
-      break;
-
-    case 'd':		/* Create directories where needed.  */
-      create_dir_flag = true;
-      break;
-
-    case 'f':		/* Only copy files not matching patterns.  */
-      copy_matching_files = false;
-      break;
-
-    case 'E':		/* Pattern file name.  */
-      pattern_file_name = arg;
-      break;
-
-    case 'F':		/* Archive file name.  */
-      archive_name = arg;
-      break;
-
-    case 'H':		/* Header format name.  */
-      if (archive_format != arf_unknown)
-	error (PAXEXIT_FAILURE, 0, _("Archive format multiply defined"));
-      if (!strcasecmp (arg, "crc"))
-	archive_format = arf_crcascii;
-      else if (!strcasecmp (arg, "newc"))
-	archive_format = arf_newascii;
-      else if (!strcasecmp (arg, "odc"))
-	archive_format = arf_oldascii;
-      else if (!strcasecmp (arg, "bin"))
-	archive_format = arf_binary;
-      else if (!strcasecmp (arg, "ustar"))
-	archive_format = arf_ustar;
-      else if (!strcasecmp (arg, "tar"))
-	archive_format = arf_tar;
-      else if (!strcasecmp (arg, "hpodc"))
-	archive_format = arf_hpoldascii;
-      else if (!strcasecmp (arg, "hpbin"))
-	archive_format = arf_hpbinary;
-      else
-	error (2, 0, _("\
-invalid archive format `%s'; valid formats are:\n\
-crc newc odc bin ustar tar (all-caps also recognized)"), arg);
-      break;
-	  
-    case 'i':		/* Copy-in mode.  */
-      if (copy_function != 0)
-	error (PAXEXIT_FAILURE, 0, _("Mode already defined"));
-      copy_function = process_copy_in;
-      break;
-
-    case 'I':		/* Input archive file name.  */
-      input_archive_name = arg;
-      break;
-
-    case 'k':		/* Handle corrupted archives.  We always handle
-			   corrupted archives, but recognize this
-			   option for compatability.  */
-      break;
-
-    case 'l':		/* Link files when possible.  */
-      link_flag = true;
-      break;
-
-    case 'L':		/* Dereference symbolic links.  */
-      xstat = stat;
-      break;
-
-    case 'm':		/* Retain previous file modify times.  */
-      retain_time_flag = true;
-      break;
-
-    case 'M':		/* New media message.  */
-      set_new_media_message (arg);
-      break;
-
-    case 'n':		/* Long list owner and group as numbers.  */
-      numeric_uid = true;
-      break;
-
-    case NO_ABSOLUTE_FILENAMES_OPTION:		/* --no-absolute-filenames */
-      abs_paths_flag = false;
-      break;
-
-    case ABSOLUTE_FILENAMES_OPTION:		/* --absolute-filenames */
-      abs_paths_flag = true;
-      break;
-	
-    case NO_PRESERVE_OWNER_OPTION:		/* --no-preserve-owner */
-      if (set_owner_flag || set_group_flag)
-	error (PAXEXIT_FAILURE, 0, 
-               _("--no-preserve-owner cannot be used with --owner"));
-      no_chown_flag = true;
-      break;
-
-    case 'o':		/* Copy-out mode.  */
-      if (copy_function != 0)
-	error (PAXEXIT_FAILURE, 0, _("Mode already defined"));
-      copy_function = process_copy_out;
-      break;
-
-    case 'O':		/* Output archive file name.  */
-      output_archive_name = arg;
-      break;
-
-    case ONLY_VERIFY_CRC_OPTION:
-      only_verify_crc_flag = true;
-      break;
-
-    case 'p':		/* Copy-pass mode.  */
-      if (copy_function != 0)
-	error (PAXEXIT_FAILURE, 0, _("Mode already defined"));
-      copy_function = process_copy_pass;
-      break;
-	  
-    case RSH_COMMAND_OPTION:
-      rsh_command_option = arg;
-      break;
-
-    case 'r':		/* Interactively rename.  */
-      rename_flag = true;
-      break;
-
-    case RENAME_BATCH_FILE_OPTION:
-      rename_batch_file = arg;
-      break;
-
-    case QUIET_OPTION:
-      quiet_flag = true;
-      break;
-
-    case 'R':		/* Set the owner.  */
-      if (no_chown_flag)
-	error (PAXEXIT_FAILURE, 0, 
-	       _("--owner cannot be used with --no-preserve-owner"));
-      else
-	{
-	  char *e, *u, *g;
-	  
-	  e = parse_user_spec (arg, &set_owner, &set_group, &u, &g);
-	  if (e)
-	    error (PAXEXIT_FAILURE, 0, "%s: %s", arg, e);
-	  if (u)
-	    {
-	      free (u);
-	      set_owner_flag = true;
-	    }
-	  if (g)
-	    {
-	      free (g);
-	      set_group_flag = true;
-	    }
-	}
-      break;
-
-    case 's':		/* Swap bytes.  */
-      swap_bytes_flag = true;
-      break;
-
-    case 'S':		/* Swap halfwords.  */
-      swap_halfwords_flag = true;
-      break;
-
-    case 't':		/* Only print a list.  */
-      table_flag = true;
-      break;
-
-    case 'u':		/* Replace all!  Unconditionally!  */
-      unconditional_flag = true;
-      break;
-
-    case 'v':		/* Verbose!  */
-      verbose_flag = true;
-      break;
-
-    case 'V':		/* Print `.' for each file.  */
-      dot_flag = true;
-      break;
-
-    case 'W':
-      if (warn_control (arg))
-	argp_error (state, _("Invalid value for --warning option: %s"), arg);
-      break;
-      
-    case SPARSE_OPTION:
-      sparse_flag = true;
-      break;
-
-    case FORCE_LOCAL_OPTION:
-      force_local_option = 1;
-      break;
-
-#ifdef DEBUG_CPIO
-    case DEBUG_OPTION:
-      debug_flag = true;
-      break;
-#endif
-
-    case TO_STDOUT_OPTION:
-      to_stdout_option = true;
-      break;
-
-    case HANG_OPTION:
-      _argp_hang = atoi (arg ? arg : "3600");
-      while (_argp_hang-- > 0)
-	sleep (1);
-      break;
-      
-    case '?':
-      argp_state_help (state, state->out_stream, ARGP_HELP_STD_HELP);
-      break;
-
-    case USAGE_OPTION:
-      argp_state_help (state, state->out_stream,
-		       ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
-      break;
-
-    case VERSION_OPTION:
-      fprintf (state->out_stream, "%s\n", argp_program_version);
-      exit (0);
-
-    case LICENSE_OPTION:
-      license ();
-      break;
-
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-static struct argp argp = {
-  options,
-  parse_opt,
-  N_("[destination-directory]"),
-  doc,
-  NULL,
-  NULL,
-  NULL
-};
-
-/* Process the arguments.  Set all options and set up the copy pass
-   directory or the copy in patterns.  */
-
-void
-process_args (int argc, char *argv[])
-{
-  void (*copy_in) ();		/* Work around for pcc bug.  */
-  void (*copy_out) ();
-  int index;
-
-  if (argc < 2)
-    error (PAXEXIT_FAILURE, 0, 
-	   _("You must specify one of -oipt options.\nTry `%s --help' or `%s --usage' for more information.\n"),
-	   program_name, program_name);
-
-  xstat = lstat;
-
-  if (argp_parse (&argp, argc, argv, ARGP_IN_ORDER|ARGP_NO_HELP, &index, NULL))
-    exit (1); 
-
-  /* Do error checking and look at other args.  */
-
-  if (copy_function == 0)
-    {
-      if (table_flag)
-	copy_function = process_copy_in;
-      else
-	error (PAXEXIT_FAILURE, 0, 
-	       _("You must specify one of -oipt options.\nTry `%s --help' or `%s --usage' for more information.\n"),
-	       program_name, program_name);
-    }
-
-  /* Work around for pcc bug.  */
-  copy_in = process_copy_in;
-  copy_out = process_copy_out;
-
-  if (copy_function == copy_in)
-    {
-      archive_des = 0;
-      CHECK_USAGE(link_flag, "--link", "--extract");
-      CHECK_USAGE(reset_time_flag, "--reset", "--extract");
-      CHECK_USAGE(xstat != lstat, "--dereference", "--extract");
-      CHECK_USAGE(append_flag, "--append", "--extract");
-      CHECK_USAGE(output_archive_name, "-O", "--extract");
-      if (to_stdout_option)
-	{
-	  CHECK_USAGE(create_dir_flag, "--make-directories", "--to-stdout");
-	  CHECK_USAGE(rename_flag, "--rename", "--to-stdout");
-	  CHECK_USAGE(no_chown_flag, "--no-preserve-owner", "--to-stdout");
-	  CHECK_USAGE(set_owner_flag||set_group_flag, "--owner", "--to-stdout");
-	  CHECK_USAGE(retain_time_flag, "--preserve-modification-time",
-		      "--to-stdout");
-	}
-      
-      if (archive_name && input_archive_name)
-	error (PAXEXIT_FAILURE, 0, 
-	       _("Both -I and -F are used in copy-in mode"));
-
-      if (archive_format == arf_crcascii)
-	crc_i_flag = true;
-      num_patterns = argc - index;
-      save_patterns = &argv[index];
-      if (input_archive_name)
-	archive_name = input_archive_name;
-    }
-  else if (copy_function == copy_out)
-    {
-      if (index != argc)
-	error (PAXEXIT_FAILURE, 0, _("Too many arguments"));
-
-      archive_des = 1;
-      CHECK_USAGE(create_dir_flag, "--make-directories", "--create");
-      CHECK_USAGE(rename_flag, "--rename", "--create");
-      CHECK_USAGE(table_flag, "--list", "--create");
-      CHECK_USAGE(unconditional_flag, "--unconditional", "--create");
-      CHECK_USAGE(link_flag, "--link", "--create");
-      CHECK_USAGE(sparse_flag, "--sparse", "--create");
-      CHECK_USAGE(retain_time_flag, "--preserve-modification-time",
-		  "--create");
-      CHECK_USAGE(no_chown_flag, "--no-preserve-owner", "--create");
-      CHECK_USAGE(swap_bytes_flag, "--swap-bytes (--swap)", "--create");
-      CHECK_USAGE(swap_halfwords_flag, "--swap-halfwords (--swap)",
-		  "--create");
-      CHECK_USAGE(to_stdout_option, "--to-stdout", "--create");
-      
-      if (append_flag && !(archive_name || output_archive_name))
-	error (PAXEXIT_FAILURE, 0, 
-	       _("--append is used but no archive file name is given (use -F or -O options)"));
-
-      CHECK_USAGE(rename_batch_file, "--rename-batch-file", "--create");
-      CHECK_USAGE(abs_paths_flag, "--absolute-pathnames", "--create");
-      CHECK_USAGE(input_archive_name, "-I", "--create");
-      if (archive_name && output_archive_name)
-	error (PAXEXIT_FAILURE, 0, 
-	       _("Both -O and -F are used in copy-out mode"));
-
-      if (archive_format == arf_unknown)
-	archive_format = arf_binary;
-      if (output_archive_name)
-	archive_name = output_archive_name;
-    }
-  else
-    {
-      /* Copy pass.  */
-      if (index < argc - 1)
-	error (PAXEXIT_FAILURE, 0, _("Too many arguments"));
-      else if (index > argc - 1)
-	error (PAXEXIT_FAILURE, 0, _("Not enough arguments"));
-
-      if (archive_format != arf_unknown)
-	error (PAXEXIT_FAILURE, 0, 
-	       _("Archive format is not specified in copy-pass mode (use --format option)"));
-
-      CHECK_USAGE(swap_bytes_flag, "--swap-bytes (--swap)", "--pass-through");
-      CHECK_USAGE(swap_halfwords_flag, "--swap-halfwords (--swap)",
-		  "--pass-through");
-      CHECK_USAGE(table_flag, "--list", "--pass-through");
-      CHECK_USAGE(rename_flag, "--rename", "--pass-through");
-      CHECK_USAGE(append_flag, "--append", "--pass-through");
-      CHECK_USAGE(rename_batch_file, "--rename-batch-file", "--pass-through");
-      CHECK_USAGE(abs_paths_flag, "--absolute-pathnames",
-		  "--pass-through");
-      CHECK_USAGE(to_stdout_option, "--to-stdout", "--pass-through");
-      
-      directory_name = argv[index];
-    }
-
-  if (archive_name)
-    {
-      if (copy_function != copy_in && copy_function != copy_out)
-	error (PAXEXIT_FAILURE, 0, 
-	       _("-F can be used only with --create or --extract"));
-      archive_des = open_archive (archive_name);
-      if (archive_des < 0)
-	error (PAXEXIT_FAILURE, errno, _("Cannot open %s"), 
-               quotearg_colon (archive_name));
-    }
-		     
-  /* Prevent SysV non-root users from giving away files inadvertantly.
-     This happens automatically on BSD, where only root can give
-     away files.  */
-  if (set_owner_flag == false && set_group_flag == false && geteuid ())
-    no_chown_flag = true;
-}
-
-/* Initialize the input and output buffers to their proper size and
-   initialize all variables associated with the input and output
-   buffers.  */
-
-void
-initialize_buffers ()
-{
-  int in_buf_size, out_buf_size;
-
-  if (copy_function == process_copy_in)
-    {
-      /* Make sure the input buffer can always hold 2 blocks and that it
-	 is big enough to hold 1 tar record (512 bytes) even if it
-	 is not aligned on a block boundary.  The extra buffer space
-	 is needed by process_copyin and peek_in_buf to automatically
-	 figure out what kind of archive it is reading.  */
-      if (io_block_size >= 512)
-	in_buf_size = 2 * io_block_size;
-      else
-	in_buf_size = 1024;
-      out_buf_size = DISK_IO_BLOCK_SIZE;
-    }
-  else if (copy_function == process_copy_out)
-    {
-      in_buf_size = DISK_IO_BLOCK_SIZE;
-      out_buf_size = io_block_size;
-    }
-  else
-    {
-      in_buf_size = DISK_IO_BLOCK_SIZE;
-      out_buf_size = DISK_IO_BLOCK_SIZE;
-    }
-
-  input_buffer = (char *) xmalloc (in_buf_size);
-  in_buff = input_buffer;
-  input_buffer_size = in_buf_size;
-  input_size = 0;
-  input_bytes = 0;
-
-  output_buffer = (char *) xmalloc (out_buf_size);
-  out_buff = output_buffer;
-  output_size = 0;
-  output_bytes = 0;
-}
-
-int
-main (int argc, char *argv[])
-{
-  setlocale (LC_ALL, "");
-  bindtextdomain (PACKAGE, LOCALEDIR);
-  textdomain (PACKAGE);
-
-  program_name = argv[0];
-
-  process_args (argc, argv);
-  umask (0);
-
-  initialize_buffers ();
-
-  (*copy_function) ();
-
-  if (archive_des >= 0 && rmtclose (archive_des) == -1)
-    error (1, errno, _("error closing archive"));
-
-  exit (0);
-}
diff --git a/contrib/cpio/src/makepath.c b/contrib/cpio/src/makepath.c
deleted file mode 100644
index ff4c25f72c8..00000000000
--- a/contrib/cpio/src/makepath.c
+++ /dev/null
@@ -1,267 +0,0 @@
-/* makepath.c -- Ensure that a directory path exists.
-   Copyright (C) 1990, 2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-/* Written by David MacKenzie  and
-   Jim Meyering .  */
-
-/* This copy of makepath is almost like the fileutils one, but has
-   changes for HPUX CDF's.  Maybe the 2 versions of makepath can
-   come together again in the future.  */
-
-#include 
-#include 
-
-#include 
-#include 
-#include 
-
-/* Ensure that the directory ARGPATH exists.
-   Remove any trailing slashes from ARGPATH before calling this function.
-
-   Make any leading directories that don't already exist, with
-   permissions PARENT_MODE.
-   If the last element of ARGPATH does not exist, create it as
-   a new directory with permissions MODE.
-   If OWNER and GROUP are non-negative, make them the UID and GID of
-   created directories.
-   If VERBOSE_FMT_STRING is nonzero, use it as a printf format
-   string for printing a message after successfully making a directory,
-   with the name of the directory that was just made as an argument.
-
-   Return 0 if ARGPATH exists as a directory with the proper
-   ownership and permissions when done, otherwise 1.  */
-
-int
-make_path (char *argpath,
-	   int mode,
-	   int parent_mode,
-	   uid_t owner,
-	   gid_t group,
-	   char *verbose_fmt_string)
-{
-  char *dirpath;		/* A copy we can scribble NULs on.  */
-  struct stat stats;
-  int retval = 0;
-  int oldmask = umask (0);
-  dirpath = alloca (strlen (argpath) + 1);
-  strcpy (dirpath, argpath);
-
-  if (stat (dirpath, &stats))
-    {
-      char *slash;
-      int tmp_mode;		/* Initial perms for leading dirs.  */
-      int re_protect;		/* Should leading dirs be unwritable? */
-      struct ptr_list
-      {
-	char *dirname_end;
-	struct ptr_list *next;
-      };
-      struct ptr_list *p, *leading_dirs = NULL;
-
-      /* If leading directories shouldn't be writable or executable,
-	 or should have set[ug]id or sticky bits set and we are setting
-	 their owners, we need to fix their permissions after making them.  */
-      if (((parent_mode & 0300) != 0300)
-	  || (owner != (uid_t) -1 && group != (gid_t) -1
-	      && (parent_mode & 07000) != 0))
-	{
-	  tmp_mode = 0700;
-	  re_protect = 1;
-	}
-      else
-	{
-	  tmp_mode = parent_mode;
-	  re_protect = 0;
-	}
-
-      slash = dirpath;
-      while (*slash == '/')
-	slash++;
-      while ((slash = strchr (slash, '/')))
-	{
-#ifdef HPUX_CDF
-	  int	iscdf;
-	  iscdf = 0;
-#endif
-	  *slash = '\0';
-	  if (stat (dirpath, &stats))
-	    {
-#ifdef HPUX_CDF
-	      /* If this component of the pathname ends in `+' and is
-		 followed by 2 `/'s, then this is a CDF.  We remove the
-		 `+' from the name and create the directory.  Later
-		 we will "hide" the directory.  */
-	      if ( (*(slash +1) == '/') && (*(slash -1) == '+') )
-		{ 
-		  iscdf = 1;
-		  *(slash -1) = '\0';
-		}
-#endif
-	      if (mkdir (dirpath, tmp_mode))
-		{
-		  error (0, errno, _("cannot make directory `%s'"), dirpath);
-		  umask (oldmask);
-		  return 1;
-		}
-	      else
-		{
-		  if (verbose_fmt_string != NULL)
-		    error (0, 0, verbose_fmt_string, dirpath);
-
-		  if (owner != (uid_t) -1 && group != (gid_t) -1
-		      && chown (dirpath, owner, group)
-#ifdef AFS
-		      && errno != EPERM
-#endif
-		      )
-		    {
-		      chown_error_details (dirpath, owner, group);
-		      retval = 1;
-		    }
-		  if (re_protect)
-		    {
-		      struct ptr_list *new = (struct ptr_list *)
-			alloca (sizeof (struct ptr_list));
-		      new->dirname_end = slash;
-		      new->next = leading_dirs;
-		      leading_dirs = new;
-		    }
-#ifdef HPUX_CDF
-		  if (iscdf)
-		    {
-		      /*  If this is a CDF, "hide" the directory by setting
-			  its hidden/setuid bit.  Also add the `+' back to
-			  its name (since once it's "hidden" we must refer
-			  to as `name+' instead of `name').  */
-		      chmod (dirpath, 04700);
-		      *(slash - 1) = '+';
-		    }
-#endif
-		}
-	    }
-	  else if (!S_ISDIR (stats.st_mode))
-	    {
-	      error (0, 0, _("`%s' exists but is not a directory"), dirpath);
-	      umask (oldmask);
-	      return 1;
-	    }
-
-	  *slash++ = '/';
-
-	  /* Avoid unnecessary calls to `stat' when given
-	     pathnames containing multiple adjacent slashes.  */
-	  while (*slash == '/')
-	    slash++;
-	}
-
-      /* We're done making leading directories.
-	 Make the final component of the path. */
-
-      if (mkdir (dirpath, mode))
-	{
-	  /* In some cases, if the final component in dirpath was `.' then we 
-	     just got an EEXIST error from that last mkdir().  If that's
-	     the case, ignore it.  */
-	  if ( (errno != EEXIST) ||
-	       (stat (dirpath, &stats) != 0) ||
-	       (!S_ISDIR (stats.st_mode) ) )
-	    {
-	      error (0, errno, _("cannot make directory `%s'"), dirpath);
-	      umask (oldmask);
-	      return 1;
-	    }
-	}
-      if (verbose_fmt_string != NULL)
-	error (0, 0, verbose_fmt_string, dirpath);
-
-      if (owner != (uid_t) -1 && group != (gid_t) -1)
-	{
-	  if (chown (dirpath, owner, group)
-#ifdef AFS
-	      && errno != EPERM
-#endif
-	      )
-	    {
-	      chown_error_details (dirpath, owner, group);
-	      retval = 1;
-	    }
-	}
-      /* chown may have turned off some permission bits we wanted.  */
-      if ((mode & 07000) != 0 && chmod (dirpath, mode))
-	{
-	  chmod_error_details (dirpath, mode);
-	  retval = 1;
-	}
-
-      /* If the mode for leading directories didn't include owner "wx"
-	 privileges, we have to reset their protections to the correct
-	 value.  */
-      for (p = leading_dirs; p != NULL; p = p->next)
-	{
-	  *p->dirname_end = '\0';
-#if 0
-	  /* cpio always calls make_path with parent mode 0700, so
-	     we don't have to do this.  If we ever do have to do this,
-	     we have to stat the directory first to get the setuid
-	     bit so we don't break HP CDF's.  */
-	  if (chmod (dirpath, parent_mode))
-	    {
-	      chmod_error_details (dirpath, parent_mode);
-	      retval = 1;
-	    }
-#endif
-
-	}
-    }
-  else
-    {
-      /* We get here if the entire path already exists.  */
-
-      if (!S_ISDIR (stats.st_mode))
-	{
-	  error (0, 0, _("`%s' exists but is not a directory"), dirpath);
-	  umask (oldmask);
-	  return 1;
-	}
-
-      /* chown must precede chmod because on some systems,
-	 chown clears the set[ug]id bits for non-superusers,
-	 resulting in incorrect permissions.
-	 On System V, users can give away files with chown and then not
-	 be able to chmod them.  So don't give files away.  */
-
-      if (owner != (uid_t) -1 && group != (gid_t) -1
-	  && chown (dirpath, owner, group)
-#ifdef AFS
-	  && errno != EPERM
-#endif
-	  )
-	{
-	  chown_error_details (dirpath, owner, group);
-	  retval = 1;
-	}
-      if (chmod (dirpath, mode))
-	{
-	  chmod_error_details (dirpath, mode);
-	  retval = 1;
-	}
-    }
-
-  umask (oldmask);
-  return retval;
-}
diff --git a/contrib/cpio/src/safe-stat.h b/contrib/cpio/src/safe-stat.h
deleted file mode 100644
index 3a379703cf6..00000000000
--- a/contrib/cpio/src/safe-stat.h
+++ /dev/null
@@ -1 +0,0 @@
-#define SAFE_STAT(path,pbuf) stat(path,pbuf)
diff --git a/contrib/cpio/src/tar.c b/contrib/cpio/src/tar.c
deleted file mode 100644
index 9340372807e..00000000000
--- a/contrib/cpio/src/tar.c
+++ /dev/null
@@ -1,494 +0,0 @@
-/* $FreeBSD$ */
-
-/* tar.c - read in write tar headers for cpio
-   Copyright (C) 1992, 2001, 2004, 2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-#include 
-
-#include 
-#include 
-#include 
-#include "filetypes.h"
-#include "cpiohdr.h"
-#include "dstring.h"
-#include "extern.h"
-#include 
-#include "tarhdr.h"
-
-/* Stash the tar linkname in static storage.  */
-
-static char *
-stash_tar_linkname (char *linkname)
-{
-  static char hold_tar_linkname[TARLINKNAMESIZE + 1];
-
-  strncpy (hold_tar_linkname, linkname, TARLINKNAMESIZE);
-  hold_tar_linkname[TARLINKNAMESIZE] = '\0';
-  return hold_tar_linkname;
-}
-
-/* Try to split a long file name into prefix and suffix parts separated
-   by a slash. Return the length of the prefix (not counting the slash). */
-   
-static size_t
-split_long_name (const char *name, size_t length)
-{
-  size_t i;
-
-  if (length > TARPREFIXSIZE)
-    length = TARPREFIXSIZE+2;
-  for (i = length - 1; i > 0; i--)
-    if (name[i] == '/')
-      break;
-  return i;
-}
-
-/* Stash the tar filename and optional prefix in static storage.  */
-
-static char *
-stash_tar_filename (char *prefix, char *filename)
-{
-  static char hold_tar_filename[TARNAMESIZE + TARPREFIXSIZE + 2];
-  if (prefix == NULL || *prefix == '\0')
-    {
-      strncpy (hold_tar_filename, filename, TARNAMESIZE);
-      hold_tar_filename[TARNAMESIZE] = '\0';
-    }
-  else
-    {
-      strncpy (hold_tar_filename, prefix, TARPREFIXSIZE);
-      hold_tar_filename[TARPREFIXSIZE] = '\0';
-      strcat (hold_tar_filename, "/");
-      strncat (hold_tar_filename, filename, TARNAMESIZE);
-      hold_tar_filename[TARPREFIXSIZE + TARNAMESIZE] = '\0';
-    }
-  return hold_tar_filename;
-}
-
-/* Convert a number into a string of octal digits.
-   Convert long VALUE into a DIGITS-digit field at WHERE,
-   including a trailing space and room for a NUL.  DIGITS==3 means
-   1 digit, a space, and room for a NUL.
-
-   We assume the trailing NUL is already there and don't fill it in.
-   This fact is used by start_header and finish_header, so don't change it!
-
-   This is be equivalent to:
-   sprintf (where, "%*lo ", digits - 2, value);
-   except that sprintf fills in the trailing NUL and we don't.  */
-
-static void
-to_oct (register long value, register int digits, register char *where)
-{
-  --digits;			/* Leave the trailing NUL slot alone.  */
-
-  /* Produce the digits -- at least one.  */
-  do
-    {
-      where[--digits] = '0' + (char) (value & 7); /* One octal digit.  */
-      value >>= 3;
-    }
-  while (digits > 0 && value != 0);
-
-  /* Add leading zeroes, if necessary.  */
-  while (digits > 0)
-    where[--digits] = '0';
-}
-
-
-
-/* Compute and return a checksum for TAR_HDR,
-   counting the checksum bytes as if they were spaces.  */
-
-unsigned int
-tar_checksum (struct tar_header *tar_hdr)
-{
-  unsigned int sum = 0;
-  char *p = (char *) tar_hdr;
-  char *q = p + TARRECORDSIZE;
-  int i;
-
-  while (p < tar_hdr->chksum)
-    sum += *p++ & 0xff;
-  for (i = 0; i < 8; ++i)
-    {
-      sum += ' ';
-      ++p;
-    }
-  while (p < q)
-    sum += *p++ & 0xff;
-  return sum;
-}
-
-/* Write out header FILE_HDR, including the file name, to file
-   descriptor OUT_DES.  */
-
-void
-write_out_tar_header (struct cpio_file_stat *file_hdr, int out_des)
-{
-  int name_len;
-  union tar_record tar_rec;
-  struct tar_header *tar_hdr = (struct tar_header *) &tar_rec;
-
-  memset (&tar_rec, 0, sizeof tar_rec);
-
-  /* process_copy_out must ensure that file_hdr->c_name is short enough,
-     or we will lose here.  */
-
-  name_len = strlen (file_hdr->c_name);
-  if (name_len <= TARNAMESIZE)
-    {
-      strncpy (tar_hdr->name, file_hdr->c_name, name_len);
-    }
-  else
-    {
-      /* Fit as much as we can into `name', the rest into `prefix'.  */
-      int prefix_len = split_long_name (file_hdr->c_name, name_len);
-
-      strncpy (tar_hdr->prefix, file_hdr->c_name, prefix_len);
-      strncpy (tar_hdr->name, file_hdr->c_name + prefix_len + 1,
-	       name_len - prefix_len - 1);
-    }
-
-  /* Ustar standard (POSIX.1-1988) requires the mode to contain only 3 octal
-     digits */
-  to_oct (file_hdr->c_mode & MODE_ALL, 8, tar_hdr->mode);
-  to_oct (file_hdr->c_uid, 8, tar_hdr->uid);
-  to_oct (file_hdr->c_gid, 8, tar_hdr->gid);
-  to_oct (file_hdr->c_filesize, 12, tar_hdr->size);
-  to_oct (file_hdr->c_mtime, 12, tar_hdr->mtime);
-
-  switch (file_hdr->c_mode & CP_IFMT)
-    {
-    case CP_IFREG:
-      if (file_hdr->c_tar_linkname)
-	{
-	  /* process_copy_out makes sure that c_tar_linkname is shorter
-	     than TARLINKNAMESIZE.  */
-	  strncpy (tar_hdr->linkname, file_hdr->c_tar_linkname,
-		   TARLINKNAMESIZE);
-	  tar_hdr->typeflag = LNKTYPE;
-	  to_oct (0, 12, tar_hdr->size);
-	}
-      else
-	tar_hdr->typeflag = REGTYPE;
-      break;
-    case CP_IFDIR:
-      tar_hdr->typeflag = DIRTYPE;
-      break;
-    case CP_IFCHR:
-      tar_hdr->typeflag = CHRTYPE;
-      break;
-    case CP_IFBLK:
-      tar_hdr->typeflag = BLKTYPE;
-      break;
-#ifdef CP_IFIFO
-    case CP_IFIFO:
-      tar_hdr->typeflag = FIFOTYPE;
-      break;
-#endif /* CP_IFIFO */
-#ifdef CP_IFLNK
-    case CP_IFLNK:
-      tar_hdr->typeflag = SYMTYPE;
-      /* process_copy_out makes sure that c_tar_linkname is shorter
-	 than TARLINKNAMESIZE.  */
-      strncpy (tar_hdr->linkname, file_hdr->c_tar_linkname,
-	       TARLINKNAMESIZE);
-      to_oct (0, 12, tar_hdr->size);
-      break;
-#endif /* CP_IFLNK */
-    }
-
-  if (archive_format == arf_ustar)
-    {
-      char *name;
-
-      strncpy (tar_hdr->magic, TMAGIC, TMAGLEN);
-      strncpy (tar_hdr->magic + TMAGLEN, TVERSION, TVERSLEN);
-
-      name = getuser (file_hdr->c_uid);
-      if (name)
-	strcpy (tar_hdr->uname, name);
-      name = getgroup (file_hdr->c_gid);
-      if (name)
-	strcpy (tar_hdr->gname, name);
-
-      to_oct (file_hdr->c_rdev_maj, 8, tar_hdr->devmajor);
-      to_oct (file_hdr->c_rdev_min, 8, tar_hdr->devminor);
-    }
-
-  to_oct (tar_checksum (tar_hdr), 8, tar_hdr->chksum);
-
-  tape_buffered_write ((char *) &tar_rec, out_des, TARRECORDSIZE);
-}
-
-/* Return nonzero iff all the bytes in BLOCK are NUL.
-   SIZE is the number of bytes to check in BLOCK; it must be a
-   multiple of sizeof (long).  */
-
-int
-null_block (long *block, int size)
-{
-  register long *p = block;
-  register int i = size / sizeof (long);
-
-  while (i--)
-    if (*p++)
-      return 0;
-  return 1;
-}
-
-/* Read a tar header, including the file name, from file descriptor IN_DES
-   into FILE_HDR.  */
-
-void
-read_in_tar_header (struct cpio_file_stat *file_hdr, int in_des)
-{
-  long bytes_skipped = 0;
-  int warned = false;
-  union tar_record tar_rec;
-  struct tar_header *tar_hdr = (struct tar_header *) &tar_rec;
-  uid_t *uidp;
-  gid_t *gidp;
-
-  tape_buffered_read ((char *) &tar_rec, in_des, TARRECORDSIZE);
-
-  /* Check for a block of 0's.  */
-  if (null_block ((long *) &tar_rec, TARRECORDSIZE))
-    {
-#if 0
-      /* Found one block of 512 0's.  If the next block is also all 0's
-	 then this is the end of the archive.  If not, assume the
-	 previous block was all corruption and continue reading
-	 the archive.  */
-      /* Commented out because GNU tar sometimes creates archives with
-	 only one block of 0's at the end.  This happened for the
-	 cpio 2.0 distribution!  */
-      tape_buffered_read ((char *) &tar_rec, in_des, TARRECORDSIZE);
-      if (null_block ((long *) &tar_rec, TARRECORDSIZE))
-#endif
-	{
-	  file_hdr->c_name = CPIO_TRAILER_NAME;
-	  return;
-	}
-#if 0
-      bytes_skipped = TARRECORDSIZE;
-#endif
-    }
-
-  while (1)
-    {
-      file_hdr->c_chksum = FROM_OCTAL (tar_hdr->chksum);
-
-      if (file_hdr->c_chksum != tar_checksum (tar_hdr))
-	{
-	  /* If the checksum is bad, skip 1 byte and try again.  When
-	     we try again we do not look for an EOF record (all zeros),
-	     because when we start skipping bytes in a corrupted archive
-	     the chances are pretty good that we might stumble across
-	     2 blocks of 512 zeros (that probably is not really the last
-	     record) and it is better to miss the EOF and give the user
-	     a "premature EOF" error than to give up too soon on a corrupted
-	     archive.  */
-	  if (!warned)
-	    {
-	      error (0, 0, _("invalid header: checksum error"));
-	      warned = true;
-	    }
-	  memmove (&tar_rec, ((char *) &tar_rec) + 1, TARRECORDSIZE - 1);
-	  tape_buffered_read (((char *) &tar_rec) + (TARRECORDSIZE - 1), in_des, 1);
-	  ++bytes_skipped;
-	  continue;
-	}
-
-      if (archive_format != arf_ustar)
-	file_hdr->c_name = stash_tar_filename (NULL, tar_hdr->name);
-      else
-	file_hdr->c_name = stash_tar_filename (tar_hdr->prefix, tar_hdr->name);
-      file_hdr->c_nlink = 1;
-      file_hdr->c_mode = FROM_OCTAL (tar_hdr->mode);
-      file_hdr->c_mode = file_hdr->c_mode & 07777;
-  /* Debian hack: This version of cpio uses the -n flag also to extract
-     tar archives using the numeric UID/GID instead of the user/group
-     names in /etc/passwd and /etc/groups.  (98/10/15) -BEM */
-      if (archive_format == arf_ustar && !numeric_uid
-	  && (uidp = getuidbyname (tar_hdr->uname)))
-	file_hdr->c_uid = *uidp;
-      else
-	file_hdr->c_uid = FROM_OCTAL (tar_hdr->uid);
-
-      if (archive_format == arf_ustar && !numeric_uid
-	  && (gidp = getgidbyname (tar_hdr->gname)))
-	file_hdr->c_gid = *gidp;
-      else
-	file_hdr->c_gid = FROM_OCTAL (tar_hdr->gid);
-      file_hdr->c_filesize = FROM_OCTAL (tar_hdr->size);
-      file_hdr->c_mtime = FROM_OCTAL (tar_hdr->mtime);
-      file_hdr->c_rdev_maj = FROM_OCTAL (tar_hdr->devmajor);
-      file_hdr->c_rdev_min = FROM_OCTAL (tar_hdr->devminor);
-      file_hdr->c_tar_linkname = NULL;
-
-      switch (tar_hdr->typeflag)
-	{
-	case REGTYPE:
-	case CONTTYPE:		/* For now, punt.  */
-	default:
-	  file_hdr->c_mode |= CP_IFREG;
-	  break;
-	case DIRTYPE:
-	  file_hdr->c_mode |= CP_IFDIR;
-	  break;
-	case CHRTYPE:
-	  file_hdr->c_mode |= CP_IFCHR;
-	  /* If a POSIX tar header has a valid linkname it's always supposed
-	     to set typeflag to be LNKTYPE.  System V.4 tar seems to
-	     be broken, and for device files with multiple links it
-	     puts the name of the link into linkname, but leaves typeflag 
-	     as CHRTYPE, BLKTYPE, FIFOTYPE, etc.  */
-	  file_hdr->c_tar_linkname = stash_tar_linkname (tar_hdr->linkname);
-
-	  /* Does POSIX say that the filesize must be 0 for devices?  We
-	     assume so, but HPUX's POSIX tar sets it to be 1 which causes
-	     us problems (when reading an archive we assume we can always
-	     skip to the next file by skipping filesize bytes).  For 
-	     now at least, it's easier to clear filesize for devices,
-	     rather than check everywhere we skip in copyin.c.  */
-	  file_hdr->c_filesize = 0;
-	  break;
-	case BLKTYPE:
-	  file_hdr->c_mode |= CP_IFBLK;
-	  file_hdr->c_tar_linkname = stash_tar_linkname (tar_hdr->linkname);
-	  file_hdr->c_filesize = 0;
-	  break;
-#ifdef CP_IFIFO
-	case FIFOTYPE:
-	  file_hdr->c_mode |= CP_IFIFO;
-	  file_hdr->c_tar_linkname = stash_tar_linkname (tar_hdr->linkname);
-	  file_hdr->c_filesize = 0;
-	  break;
-#endif
-	case SYMTYPE:
-#ifdef CP_IFLNK
-	  file_hdr->c_mode |= CP_IFLNK;
-	  file_hdr->c_tar_linkname = stash_tar_linkname (tar_hdr->linkname);
-	  file_hdr->c_filesize = 0;
-	  break;
-	  /* Else fall through.  */
-#endif
-	case LNKTYPE:
-	  file_hdr->c_mode |= CP_IFREG;
-	  file_hdr->c_tar_linkname = stash_tar_linkname (tar_hdr->linkname);
-	  file_hdr->c_filesize = 0;
-	  break;
-
-	case AREGTYPE:
-	  /* Old tar format; if the last char in filename is '/' then it is
-	     a directory, otherwise it's a regular file.  */
-	  if (file_hdr->c_name[strlen (file_hdr->c_name) - 1] == '/')
-	    file_hdr->c_mode |= CP_IFDIR;
-	  else
-	    file_hdr->c_mode |= CP_IFREG;
-	  break;
-	case 'x': case 'g':
-	  /* Ignore pax 'x' and 'g' extension entries. */
-	  /* Skip body of this entry. */
-	  while (file_hdr->c_filesize > 0) {
-	    tape_buffered_read(((char *) &tar_rec), in_des, TARRECORDSIZE);
-	    if (file_hdr->c_filesize > TARRECORDSIZE)
-		    file_hdr->c_filesize -= TARRECORDSIZE;
-	    else
-		    file_hdr->c_filesize = 0;
-	  }
-	  /* Read next header and return that instead. */
-	  read_in_tar_header(file_hdr, in_des);
-	  break;
-	}
-      break;
-    }
-  if (bytes_skipped > 0)
-    warn_junk_bytes (bytes_skipped);
-}
-
-/* Return
-   2 if BUF is a valid POSIX tar header (the checksum is correct
-   and it has the "ustar" magic string),
-   1 if BUF is a valid old tar header (the checksum is correct),
-   0 otherwise.  */
-
-int
-is_tar_header (char *buf)
-{
-  struct tar_header *tar_hdr = (struct tar_header *) buf;
-  unsigned long chksum;
-
-  chksum = FROM_OCTAL (tar_hdr->chksum);
-
-  if (chksum != tar_checksum (tar_hdr))
-    return 0;
-
-  /* GNU tar 1.10 and previous set the magic field to be "ustar " instead
-     of "ustar\0".  Only look at the first 5 characters of the magic
-     field so we can recognize old GNU tar ustar archives.  */
-  if (!strncmp (tar_hdr->magic, TMAGIC, TMAGLEN - 1))
-      return 2;
-  return 1;
-}
-
-/* Return true if the filename is too long to fit in a tar header.
-   For old tar headers, if the filename's length is less than or equal
-   to 100 then it will fit, otherwise it will not.  For POSIX tar headers,
-   if the filename's length is less than or equal to 100 then it
-   will definitely fit, and if it is greater than 256 then it
-   will definitely not fit.  If the length is between 100 and 256,
-   then the filename will fit only if it is possible to break it
-   into a 155 character "prefix" and 100 character "name".  There
-   must be a slash between the "prefix" and the "name", although
-   the slash is not stored or counted in either the "prefix" or
-   the "name", and there must be at least one character in both
-   the "prefix" and the "name".  If it is not possible to break down
-   the filename like this then it will not fit.  */
-
-int
-is_tar_filename_too_long (char *name)
-{
-  int whole_name_len;
-  int prefix_name_len;
-
-  whole_name_len = strlen (name);
-  if (whole_name_len <= TARNAMESIZE)
-    return false;
-
-  if (archive_format != arf_ustar)
-    return true;
-
-  if (whole_name_len > TARNAMESIZE + TARPREFIXSIZE + 1)
-    return true;
-
-  /* See whether we can split up the name into acceptably-sized
-     `prefix' and `name' (`p') pieces. */
-  prefix_name_len = split_long_name (name, whole_name_len);
-
-  /* Interestingly, a name consisting of a slash followed by
-     TARNAMESIZE characters can't be stored, because the prefix
-     would be empty, and thus ignored.  */
-  if (prefix_name_len == 0
-      || whole_name_len - prefix_name_len - 1 > TARNAMESIZE)
-    return true;
-
-  return false;
-}
diff --git a/contrib/cpio/src/tar.h b/contrib/cpio/src/tar.h
deleted file mode 100644
index 7b27e86a56f..00000000000
--- a/contrib/cpio/src/tar.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/* Extended tar format from POSIX.1.
-   Copyright (C) 1992 Free Software Foundation, Inc.
-   Written by David J. MacKenzie.
-
-This file is part of the GNU C Library.
-
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
-
-The GNU C Library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General
-Public License along with this library; see the file COPYING.LIB.
-If not, write to the Free Software Foundation, Inc., 51 Franklin
-Street, Fifth Floor, Boston, MA 02110-1301 USA.  */
-
-#ifndef	_TAR_H
-
-#define	_TAR_H	1
-
-
-/* A tar archive consists of 512-byte blocks.
-   Each file in the archive has a header block followed by 0+ data blocks.
-   Two blocks of NUL bytes indicate the end of the archive.  */
-
-/* The fields of header blocks:
-   All strings are stored as ISO 646 (approximately ASCII) strings.
-
-   Fields are numeric unless otherwise noted below; numbers are ISO 646
-   representations of octal numbers, with leading zeros as needed.
-
-   linkname is only valid when typeflag==LNKTYPE.  It doesn't use prefix;
-   files that are links to pathnames >100 chars long can not be stored
-   in a tar archive.
-
-   If typeflag=={LNKTYPE,SYMTYPE,DIRTYPE} then size must be 0.
-
-   devmajor and devminor are only valid for typeflag=={BLKTYPE,CHRTYPE}.
-
-   chksum contains the sum of all 512 bytes in the header block,
-   treating each byte as an 8-bit unsigned value and treating the
-   8 bytes of chksum as blank characters.
-
-   uname and gname are used in preference to uid and gid, if those
-   names exist locally.
-
-   Field Name	Byte Offset	Length in Bytes	Field Type
-   name		0		100		NUL-terminated if NUL fits
-   mode		100		8
-   uid		108		8
-   gid		116		8
-   size		124		12
-   mtime	136		12
-   chksum	148		8
-   typeflag	156		1		see below
-   linkname	157		100		NUL-terminated if NUL fits
-   magic	257		6		must be TMAGIC (NUL term.)
-   version	263		2		must be TVERSION
-   uname	265		32		NUL-terminated
-   gname	297		32		NUL-terminated
-   devmajor	329		8
-   devminor	337		8
-   prefix	345		155		NUL-terminated if NUL fits
-
-   If the first character of prefix is '\0', the file name is name;
-   otherwise, it is prefix/name.  Files whose pathnames don't fit in that
-   length can not be stored in a tar archive.  */
-
-/* The bits in mode: */
-#define TSUID	04000
-#define TSGID	02000
-#define TSVTX	01000
-#define TUREAD	00400
-#define TUWRITE	00200
-#define TUEXEC	00100
-#define TGREAD	00040
-#define TGWRITE	00020
-#define TGEXEC	00010
-#define TOREAD	00004
-#define TOWRITE	00002
-#define TOEXEC	00001
-
-/* The values for typeflag:
-   Values 'A'-'Z' are reserved for custom implementations.
-   All other values are reserved for future POSIX.1 revisions.  */
-
-#define REGTYPE		'0'	/* Regular file (preferred code).  */
-#define AREGTYPE	'\0'	/* Regular file (alternate code).  */
-#define LNKTYPE		'1'	/* Hard link.  */
-#define SYMTYPE		'2'	/* Symbolic link (hard if not supported).  */
-#define CHRTYPE		'3'	/* Character special.  */
-#define BLKTYPE		'4'	/* Block special.  */
-#define DIRTYPE		'5'	/* Directory.  */
-#define FIFOTYPE	'6'	/* Named pipe.  */
-#define CONTTYPE	'7'	/* Contiguous file */
-				/* (regular file if not supported).  */
-
-/* Contents of magic field and its length.  */
-#define TMAGIC	"ustar"
-#define TMAGLEN	6
-
-/* Contents of the version field and its length.  */
-#define TVERSION "00"
-#define TVERSLEN 2
-
-
-#endif	/* tar.h */
diff --git a/contrib/cpio/src/tarhdr.h b/contrib/cpio/src/tarhdr.h
deleted file mode 100644
index b901739c19c..00000000000
--- a/contrib/cpio/src/tarhdr.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* Extended tar header from POSIX.1.
-   Copyright (C) 1992 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-#ifndef _TARHDR_H
-
-#define _TARHDR_H 1
-
-#include 
-
-/* Size of `name' field.  */
-#define TARNAMESIZE 100
-
-/* Size of `linkname' field.  */
-#define TARLINKNAMESIZE 100
-
-/* Size of `prefix' field.  */
-#define TARPREFIXSIZE 155
-
-/* Size of entire tar header.  */
-#define TARRECORDSIZE 512
-
-struct tar_header
-{
-  char name[TARNAMESIZE];
-  char mode[8];
-  char uid[8];
-  char gid[8];
-  char size[12];
-  char mtime[12];
-  char chksum[8];
-  char typeflag;
-  char linkname[TARLINKNAMESIZE];
-  char magic[6];
-  char version[2];
-  char uname[32];
-  char gname[32];
-  char devmajor[8];
-  char devminor[8];
-  char prefix[TARPREFIXSIZE];
-};
-
-union tar_record
-{
-  struct tar_header header;
-  char buffer[TARRECORDSIZE];
-};
-
-#endif /* tarhdr.h */
diff --git a/contrib/cpio/src/userspec.c b/contrib/cpio/src/userspec.c
deleted file mode 100644
index c33d6e2c21d..00000000000
--- a/contrib/cpio/src/userspec.c
+++ /dev/null
@@ -1,261 +0,0 @@
-/* $FreeBSD$ */
-
-/* userspec.c -- Parse a user and group string.
-   Copyright (C) 1989, 1990, 1991, 1992, 2001, 
-   2004, 2005 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-/* Written by David MacKenzie .  */
-
-#include 
-
-#ifdef __GNUC__
-#define alloca __builtin_alloca
-#else
-#ifdef HAVE_ALLOCA_H
-#include 
-#else
-#ifdef _AIX
- #pragma alloca
-#else
-char *alloca ();
-#endif
-#endif
-#endif
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#if !HAVE_DECL_GETPWNAM
-extern struct passwd *getpwnam (const char *name);
-#endif
-#if !HAVE_DECL_GETGRNAM
-extern struct group *getgrnam (const char *name);
-#endif
-#if !HAVE_DECL_GETGRGID
-extern struct group *getgrgid (gid_t gid);
-#endif
-
-#ifndef HAVE_ENDPWENT
-# define endpwent()
-#endif
-#ifndef HAVE_ENDGRENT
-# define endgrent()
-#endif
-
-/* Perform the equivalent of the statement `dest = strdup (src);',
-   but obtaining storage via alloca instead of from the heap.  */
-
-#define V_STRDUP(dest, src)						\
-  do									\
-    {									\
-      int _len = strlen ((src));					\
-      (dest) = (char *) alloca (_len + 1);				\
-      strcpy (dest, src);						\
-    }									\
-  while (0)
-
-/* Return nonzero if STR represents an unsigned decimal integer,
-   otherwise return 0. */
-
-static int
-isnumber_p (const char *str)
-{
-  for (; *str; str++)
-    if (!isdigit (*str))
-      return 0;
-  return 1;
-}
-
-/* Extract from NAME, which has the form "[user][:.][group]",
-   a USERNAME, UID U, GROUPNAME, and GID G.
-   Either user or group, or both, must be present.
-   If the group is omitted but the ":" or "." separator is given,
-   use the given user's login group.
-
-   USERNAME and GROUPNAME will be in newly malloc'd memory.
-   Either one might be NULL instead, indicating that it was not
-   given and the corresponding numeric ID was left unchanged.
-
-   Return NULL if successful, a static error message string if not.  */
-
-const char *
-parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid,
-		 char **username_arg, char **groupname_arg)
-{
-  static const char *tired = "virtual memory exhausted";
-  const char *error_msg;
-  char *spec;			/* A copy we can write on.  */
-  struct passwd *pwd;
-  struct group *grp;
-  char *g, *u, *separator;
-  char *groupname;
-
-  error_msg = NULL;
-  *username_arg = *groupname_arg = NULL;
-  groupname = NULL;
-
-  V_STRDUP (spec, spec_arg);
-
-  /* Find the separator if there is one.  */
-  separator = strchr (spec, ':');
-  if (separator == NULL)
-    separator = strchr (spec, '.');
-
-  /* Replace separator with a NUL.  */
-  if (separator != NULL)
-    *separator = '\0';
-
-  /* Set U and G to non-zero length strings corresponding to user and
-     group specifiers or to NULL.  */
-  u = (*spec == '\0' ? NULL : spec);
-
-  g = (separator == NULL || *(separator + 1) == '\0'
-       ? NULL
-       : separator + 1);
-
-  if (u == NULL && g == NULL)
-    return "can not omit both user and group";
-
-  if (u != NULL)
-    {
-      pwd = getpwnam (u);
-      if (pwd == NULL)
-	{
-
-	  if (!isnumber_p (u))
-	    error_msg = _("invalid user");
-	  else
-	    {
-	      int use_login_group;
-	      use_login_group = (separator != NULL && g == NULL);
-	      if (use_login_group)
-		error_msg = _("cannot get the login group of a numeric UID");
-	      else
-		*uid = atoi (u);
-	    }
-	}
-      else
-	{
-	  *uid = pwd->pw_uid;
-	  if (g == NULL && separator != NULL)
-	    {
-	      /* A separator was given, but a group was not specified,
-	         so get the login group.  */
-	      *gid = pwd->pw_gid;
-	      grp = getgrgid (pwd->pw_gid);
-	      if (grp == NULL)
-		{
-		  /* This is enough room to hold the unsigned decimal
-		     representation of any 32-bit quantity and the trailing
-		     zero byte.  */
-		  char uint_buf[21];
-		  sprintf (uint_buf, "%u", (unsigned) (pwd->pw_gid));
-		  V_STRDUP (groupname, uint_buf);
-		}
-	      else
-		{
-		  V_STRDUP (groupname, grp->gr_name);
-		}
-	      endgrent ();
-	    }
-	}
-      endpwent ();
-    }
-
-  if (g != NULL && error_msg == NULL)
-    {
-      /* Explicit group.  */
-      grp = getgrnam (g);
-      if (grp == NULL)
-	{
-	  if (!isnumber_p (g))
-	    error_msg = _("invalid group");
-	  else
-	    *gid = atoi (g);
-	}
-      else
-	*gid = grp->gr_gid;
-      endgrent ();		/* Save a file descriptor.  */
-
-      if (error_msg == NULL)
-	V_STRDUP (groupname, g);
-    }
-
-  if (error_msg == NULL)
-    {
-      if (u != NULL)
-	{
-	  *username_arg = strdup (u);
-	  if (*username_arg == NULL)
-	    error_msg = tired;
-	}
-
-      if (groupname != NULL && error_msg == NULL)
-	{
-	  *groupname_arg = strdup (groupname);
-	  if (*groupname_arg == NULL)
-	    {
-	      if (*username_arg != NULL)
-		{
-		  free (*username_arg);
-		  *username_arg = NULL;
-		}
-	      error_msg = tired;
-	    }
-	}
-    }
-
-  return error_msg;
-}
-
-#ifdef TEST
-
-#define NULL_CHECK(s) ((s) == NULL ? "(null)" : (s))
-
-int
-main (int argc, char **argv)
-{
-  int i;
-
-  for (i = 1; i < argc; i++)
-    {
-      const char *e;
-      char *username, *groupname;
-      uid_t uid;
-      gid_t gid;
-      char *tmp;
-
-      tmp = strdup (argv[i]);
-      e = parse_user_spec (tmp, &uid, &gid, &username, &groupname);
-      free (tmp);
-      printf ("%s: %u %u %s %s %s\n",
-	      argv[i],
-	      (unsigned int) uid,
-	      (unsigned int) gid,
-	      NULL_CHECK (username),
-	      NULL_CHECK (groupname),
-	      NULL_CHECK (e));
-    }
-
-  exit (0);
-}
-
-#endif
diff --git a/contrib/cpio/src/util.c b/contrib/cpio/src/util.c
deleted file mode 100644
index 8773f7521ac..00000000000
--- a/contrib/cpio/src/util.c
+++ /dev/null
@@ -1,1344 +0,0 @@
-/* $FreeBSD$ */
-
-/* util.c - Several utility routines for cpio.
-   Copyright (C) 1990, 1991, 1992, 2001, 2004,
-   2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA.  */
-
-#include 
-
-#include 
-#include 
-#include 
-#include "cpiohdr.h"
-#include "dstring.h"
-#include "extern.h"
-#include 
-#include "filetypes.h"
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-
-#ifdef HAVE_SYS_MTIO_H
-# ifdef HAVE_SYS_IO_TRIOCTL_H
-#  include 
-# endif
-# include 
-#endif
-
-#if !HAVE_DECL_ERRNO
-extern int errno;
-#endif
-
-/* Write `output_size' bytes of `output_buffer' to file
-   descriptor OUT_DES and reset `output_size' and `out_buff'.  */
-
-void
-tape_empty_output_buffer (int out_des)
-{
-  int bytes_written;
-
-#ifdef BROKEN_LONG_TAPE_DRIVER
-  static long output_bytes_before_lseek = 0;
-
-  /* Some tape drivers seem to have a signed internal seek pointer and
-     they lose if it overflows and becomes negative (e.g. when writing 
-     tapes > 2Gb).  Doing an lseek (des, 0, SEEK_SET) seems to reset the 
-     seek pointer and prevent it from overflowing.  */
-  if (output_is_special
-     && ( (output_bytes_before_lseek += output_size) >= 1073741824L) )
-    {
-      lseek(out_des, 0L, SEEK_SET);
-      output_bytes_before_lseek = 0;
-    }
-#endif
-
-  bytes_written = rmtwrite (out_des, output_buffer, output_size);
-  if (bytes_written != output_size)
-    {
-      int rest_bytes_written;
-      int rest_output_size;
-
-      if (output_is_special
-	  && (bytes_written >= 0
-	      || (bytes_written < 0
-		  && (errno == ENOSPC || errno == EIO || errno == ENXIO))))
-	{
-	  get_next_reel (out_des);
-	  if (bytes_written > 0)
-	    rest_output_size = output_size - bytes_written;
-	  else
-	    rest_output_size = output_size;
-	  rest_bytes_written = rmtwrite (out_des, output_buffer,
-					 rest_output_size);
-	  if (rest_bytes_written != rest_output_size)
-	    error (1, errno, _("write error"));
-	}
-      else
-	error (1, errno, _("write error"));
-    }
-  output_bytes += output_size;
-  out_buff = output_buffer;
-  output_size = 0;
-}
-
-static int sparse_write (int fildes, char *buf, unsigned int nbyte);
-
-/* Write `output_size' bytes of `output_buffer' to file
-   descriptor OUT_DES and reset `output_size' and `out_buff'.
-   If `swapping_halfwords' or `swapping_bytes' is set,
-   do the appropriate swapping first.  Our callers have
-   to make sure to only set these flags if `output_size' 
-   is appropriate (a multiple of 4 for `swapping_halfwords',
-   2 for `swapping_bytes').  The fact that DISK_IO_BLOCK_SIZE
-   must always be a multiple of 4 helps us (and our callers)
-   insure this.  */
-
-void
-disk_empty_output_buffer (int out_des)
-{
-  int bytes_written;
-
-  if (swapping_halfwords || swapping_bytes)
-    {
-      if (swapping_halfwords)
-	{
-	  int complete_words;
-	  complete_words = output_size / 4;
-	  swahw_array (output_buffer, complete_words);
-	  if (swapping_bytes)
-	    swab_array (output_buffer, 2 * complete_words);
-	}
-      else
-	{
-	  int complete_halfwords;
-	  complete_halfwords = output_size /2;
-	  swab_array (output_buffer, complete_halfwords);
-	}
-    }
-
-  if (sparse_flag)
-    bytes_written = sparse_write (out_des, output_buffer, output_size);
-  else
-    bytes_written = write (out_des, output_buffer, output_size);
-
-  if (bytes_written != output_size)
-    {
-      error (1, errno, _("write error"));
-    }
-  output_bytes += output_size;
-  out_buff = output_buffer;
-  output_size = 0;
-}
-
-/* Exchange the halfwords of each element of the array of COUNT longs
-   starting at PTR.  PTR does not have to be aligned at a word
-   boundary.  */
-
-void
-swahw_array (char *ptr, int count)
-{
-  char tmp;
-
-  for (; count > 0; --count)
-    {
-      tmp = *ptr;
-      *ptr = *(ptr + 2);
-      *(ptr + 2) = tmp;
-      ++ptr;
-      tmp = *ptr;
-      *ptr = *(ptr + 2);
-      *(ptr + 2) = tmp;
-      ptr += 3;
-    }
-}
-
-/* Read at most NUM_BYTES or `io_block_size' bytes, whichever is smaller,
-   into the start of `input_buffer' from file descriptor IN_DES.
-   Set `input_size' to the number of bytes read and reset `in_buff'.
-   Exit with an error if end of file is reached.  */
-
-#ifdef BROKEN_LONG_TAPE_DRIVER
-static long input_bytes_before_lseek = 0;
-#endif
-
-static void
-tape_fill_input_buffer (int in_des, int num_bytes)
-{
-#ifdef BROKEN_LONG_TAPE_DRIVER
-  /* Some tape drivers seem to have a signed internal seek pointer and
-     they lose if it overflows and becomes negative (e.g. when writing 
-     tapes > 4Gb).  Doing an lseek (des, 0, SEEK_SET) seems to reset the 
-     seek pointer and prevent it from overflowing.  */
-  if (input_is_special
-      && ( (input_bytes_before_lseek += num_bytes) >= 1073741824L) )
-    {
-      lseek(in_des, 0L, SEEK_SET);
-      input_bytes_before_lseek = 0;
-    }
-#endif
-  in_buff = input_buffer;
-  num_bytes = (num_bytes < io_block_size) ? num_bytes : io_block_size;
-  input_size = rmtread (in_des, input_buffer, num_bytes);
-  if (input_size == 0 && input_is_special)
-    {
-      get_next_reel (in_des);
-      input_size = rmtread (in_des, input_buffer, num_bytes);
-    }
-  if (input_size < 0)
-    error (1, errno, _("read error"));
-  if (input_size == 0)
-    {
-      error (0, 0, _("premature end of file"));
-      exit (1);
-    }
-  input_bytes += input_size;
-}
-
-/* Read at most NUM_BYTES or `DISK_IO_BLOCK_SIZE' bytes, whichever is smaller,
-   into the start of `input_buffer' from file descriptor IN_DES.
-   Set `input_size' to the number of bytes read and reset `in_buff'.
-   Exit with an error if end of file is reached.  */
-
-static int
-disk_fill_input_buffer (int in_des, off_t num_bytes)
-{
-  in_buff = input_buffer;
-  num_bytes = (num_bytes < DISK_IO_BLOCK_SIZE) ? num_bytes : DISK_IO_BLOCK_SIZE;
-  input_size = read (in_des, input_buffer, num_bytes);
-  if (input_size < 0) 
-    {
-      input_size = 0;
-      return (-1);
-    }
-  else if (input_size == 0)
-    return (1);
-  input_bytes += input_size;
-  return (0);
-}
-
-/* Copy NUM_BYTES of buffer IN_BUF to `out_buff', which may be partly full.
-   When `out_buff' fills up, flush it to file descriptor OUT_DES.  */
-
-void
-tape_buffered_write (char *in_buf, int out_des, off_t num_bytes)
-{
-  off_t bytes_left = num_bytes;	/* Bytes needing to be copied.  */
-  off_t space_left;	/* Room left in output buffer.  */
-
-  while (bytes_left > 0)
-    {
-      space_left = io_block_size - output_size;
-      if (space_left == 0)
-	tape_empty_output_buffer (out_des);
-      else
-	{
-	  if (bytes_left < space_left)
-	    space_left = bytes_left;
-	  memcpy (out_buff, in_buf, (unsigned) space_left);
-	  out_buff += space_left;
-	  output_size += space_left;
-	  in_buf += space_left;
-	  bytes_left -= space_left;
-	}
-    }
-}
-
-/* Copy NUM_BYTES of buffer IN_BUF to `out_buff', which may be partly full.
-   When `out_buff' fills up, flush it to file descriptor OUT_DES.  */
-
-void
-disk_buffered_write (char *in_buf, int out_des, off_t num_bytes)
-{
-  off_t bytes_left = num_bytes;	/* Bytes needing to be copied.  */
-  off_t space_left;	/* Room left in output buffer.  */
-
-  while (bytes_left > 0)
-    {
-      space_left = DISK_IO_BLOCK_SIZE - output_size;
-      if (space_left == 0)
-	disk_empty_output_buffer (out_des);
-      else
-	{
-	  if (bytes_left < space_left)
-	    space_left = bytes_left;
-	  memcpy (out_buff, in_buf, (unsigned) space_left);
-	  out_buff += space_left;
-	  output_size += space_left;
-	  in_buf += space_left;
-	  bytes_left -= space_left;
-	}
-    }
-}
-
-/* Copy NUM_BYTES of buffer `in_buff' into IN_BUF.
-   `in_buff' may be partly full.
-   When `in_buff' is exhausted, refill it from file descriptor IN_DES.  */
-
-void
-tape_buffered_read (char *in_buf, int in_des, off_t num_bytes)
-{
-  off_t bytes_left = num_bytes;	/* Bytes needing to be copied.  */
-  off_t space_left;	/* Bytes to copy from input buffer.  */
-
-  while (bytes_left > 0)
-    {
-      if (input_size == 0)
-	tape_fill_input_buffer (in_des, io_block_size);
-      if (bytes_left < input_size)
-	space_left = bytes_left;
-      else
-	space_left = input_size;
-      memcpy (in_buf, in_buff, (unsigned) space_left);
-      in_buff += space_left;
-      in_buf += space_left;
-      input_size -= space_left;
-      bytes_left -= space_left;
-    }
-}
-
-/* Copy the the next NUM_BYTES bytes of `input_buffer' into PEEK_BUF.
-   If NUM_BYTES bytes are not available, read the next `io_block_size' bytes
-   into the end of `input_buffer' and update `input_size'.
-
-   Return the number of bytes copied into PEEK_BUF.
-   If the number of bytes returned is less than NUM_BYTES,
-   then EOF has been reached.  */
-
-int
-tape_buffered_peek (char *peek_buf, int in_des, int num_bytes)
-{
-  long tmp_input_size;
-  long got_bytes;
-  char *append_buf;
-
-#ifdef BROKEN_LONG_TAPE_DRIVER
-  /* Some tape drivers seem to have a signed internal seek pointer and
-     they lose if it overflows and becomes negative (e.g. when writing 
-     tapes > 4Gb).  Doing an lseek (des, 0, SEEK_SET) seems to reset the 
-     seek pointer and prevent it from overflowing.  */
-  if (input_is_special
-      && ( (input_bytes_before_lseek += num_bytes) >= 1073741824L) )
-    {
-      lseek(in_des, 0L, SEEK_SET);
-      input_bytes_before_lseek = 0;
-    }
-#endif
-
-  while (input_size < num_bytes)
-    {
-      append_buf = in_buff + input_size;
-      if ( (append_buf - input_buffer) >= input_buffer_size)
-	{
-	  /* We can keep up to 2 "blocks" (either the physical block size
-	     or 512 bytes(the size of a tar record), which ever is
-	     larger) in the input buffer when we are peeking.  We
-	     assume that our caller will never be interested in peeking
-	     ahead at more than 512 bytes, so we know that by the time
-	     we need a 3rd "block" in the buffer we can throw away the
-	     first block to make room.  */
-	  int half;
-	  half = input_buffer_size / 2;
-	  memmove (input_buffer, input_buffer + half, half);
-	  in_buff = in_buff - half;
-	  append_buf = append_buf - half;
-	}
-      tmp_input_size = rmtread (in_des, append_buf, io_block_size);
-      if (tmp_input_size == 0)
-	{
-	  if (input_is_special)
-	    {
-	      get_next_reel (in_des);
-	      tmp_input_size = rmtread (in_des, append_buf, io_block_size);
-	    }
-	  else
-	    break;
-	}
-      if (tmp_input_size < 0)
-	error (1, errno, _("read error"));
-      input_bytes += tmp_input_size;
-      input_size += tmp_input_size;
-    }
-  if (num_bytes <= input_size)
-    got_bytes = num_bytes;
-  else
-    got_bytes = input_size;
-  memcpy (peek_buf, in_buff, (unsigned) got_bytes);
-  return got_bytes;
-}
-
-/* Skip the next NUM_BYTES bytes of file descriptor IN_DES.  */
-
-void
-tape_toss_input (int in_des, off_t num_bytes)
-{
-  off_t bytes_left = num_bytes;	/* Bytes needing to be copied.  */
-  off_t space_left;	/* Bytes to copy from input buffer.  */
-
-  while (bytes_left > 0)
-    {
-      if (input_size == 0)
-	tape_fill_input_buffer (in_des, io_block_size);
-      if (bytes_left < input_size)
-	space_left = bytes_left;
-      else
-	space_left = input_size;
-
-      if (crc_i_flag && only_verify_crc_flag)
-	{
- 	  int k;
-	  for (k = 0; k < space_left; ++k)
-	    crc += in_buff[k] & 0xff;
-	}
-
-      in_buff += space_left;
-      input_size -= space_left;
-      bytes_left -= space_left;
-    }
-}
-
-void
-write_nuls_to_file (off_t num_bytes, int out_des, 
-                    void (*writer) (char *in_buf, int out_des, off_t num_bytes))
-{
-  off_t	blocks;
-  off_t	extra_bytes;
-  off_t	i;
-  static char zeros_512[512];
-  
-  blocks = num_bytes / sizeof zeros_512;
-  extra_bytes = num_bytes % sizeof zeros_512;
-  for (i = 0; i < blocks; ++i)
-    writer (zeros_512, out_des, sizeof zeros_512);
-  if (extra_bytes)
-    writer (zeros_512, out_des, extra_bytes);
-}
-
-/* Copy a file using the input and output buffers, which may start out
-   partly full.  After the copy, the files are not closed nor the last
-   block flushed to output, and the input buffer may still be partly
-   full.  If `crc_i_flag' is set, add each byte to `crc'.
-   IN_DES is the file descriptor for input;
-   OUT_DES is the file descriptor for output;
-   NUM_BYTES is the number of bytes to copy.  */
-
-void
-copy_files_tape_to_disk (int in_des, int out_des, off_t num_bytes)
-{
-  long size;
-  long k;
-
-  while (num_bytes > 0)
-    {
-      if (input_size == 0)
-	tape_fill_input_buffer (in_des, io_block_size);
-      size = (input_size < num_bytes) ? input_size : num_bytes;
-      if (crc_i_flag)
-	{
-	  for (k = 0; k < size; ++k)
-	    crc += in_buff[k] & 0xff;
-	}
-      disk_buffered_write (in_buff, out_des, size);
-      num_bytes -= size;
-      input_size -= size;
-      in_buff += size;
-    }
-}
-/* Copy a file using the input and output buffers, which may start out
-   partly full.  After the copy, the files are not closed nor the last
-   block flushed to output, and the input buffer may still be partly
-   full.  If `crc_i_flag' is set, add each byte to `crc'.
-   IN_DES is the file descriptor for input;
-   OUT_DES is the file descriptor for output;
-   NUM_BYTES is the number of bytes to copy.  */
-
-void
-copy_files_disk_to_tape (int in_des, int out_des, off_t num_bytes,
-			 char *filename)
-{
-  long size;
-  long k;
-  int rc;
-  off_t original_num_bytes;
-
-  original_num_bytes = num_bytes;
-
-  while (num_bytes > 0)
-    {
-      if (input_size == 0)
-	if (rc = disk_fill_input_buffer (in_des,
-					 num_bytes < DISK_IO_BLOCK_SIZE ?
-					 num_bytes : DISK_IO_BLOCK_SIZE))
-	  {
-	    if (rc > 0)
-	      {
-		  char buf[UINTMAX_STRSIZE_BOUND];
-		  error (0, 0,
-			 ngettext ("File %s shrunk by %s byte, padding with zeros",
-				   "File %s shrunk by %s bytes, padding with zeros",
-				   num_bytes),
-			 filename,  STRINGIFY_BIGINT (num_bytes, buf));
-	      }
-	    else
-	      error (0, 0, _("Read error at byte %lld in file %s, padding with zeros"),
-			original_num_bytes - num_bytes, filename);
-	    write_nuls_to_file (num_bytes, out_des, tape_buffered_write);
-	    break;
-	  }
-      size = (input_size < num_bytes) ? input_size : num_bytes;
-      if (crc_i_flag)
-	{
-	  for (k = 0; k < size; ++k)
-	    crc += in_buff[k] & 0xff;
-	}
-      tape_buffered_write (in_buff, out_des, size);
-      num_bytes -= size;
-      input_size -= size;
-      in_buff += size;
-    }
-}
-/* Copy a file using the input and output buffers, which may start out
-   partly full.  After the copy, the files are not closed nor the last
-   block flushed to output, and the input buffer may still be partly
-   full.  If `crc_i_flag' is set, add each byte to `crc'.
-   IN_DES is the file descriptor for input;
-   OUT_DES is the file descriptor for output;
-   NUM_BYTES is the number of bytes to copy.  */
-
-void
-copy_files_disk_to_disk (int in_des, int out_des, off_t num_bytes,
-			 char *filename)
-{
-  long size;
-  long k;
-  off_t original_num_bytes;
-  int rc;
-
-  original_num_bytes = num_bytes;
-  while (num_bytes > 0)
-    {
-      if (input_size == 0)
-	if (rc = disk_fill_input_buffer (in_des, num_bytes))
-	  {
-	    if (rc > 0)
-	      {
-		char buf[UINTMAX_STRSIZE_BOUND];
-		error (0, 0,
-		       ngettext ("File %s shrunk by %s byte, padding with zeros",
-				 "File %s shrunk by %s bytes, padding with zeros",
-				 num_bytes),
-		       filename,  STRINGIFY_BIGINT (num_bytes, buf));
-	      }
-	    else
-	      error (0, 0, _("Read error at byte %lld in file %s, padding with zeros"),
-			original_num_bytes - num_bytes, filename);
-	    write_nuls_to_file (num_bytes, out_des, disk_buffered_write);
-	    break;
-	  }
-      size = (input_size < num_bytes) ? input_size : num_bytes;
-      if (crc_i_flag)
-	{
-	  for (k = 0; k < size; ++k)
-	    crc += in_buff[k] & 0xff;
-	}
-      disk_buffered_write (in_buff, out_des, size);
-      num_bytes -= size;
-      input_size -= size;
-      in_buff += size;
-    }
-}
-
-/* Warn if file changed while it was being copied.  */
-
-void
-warn_if_file_changed (char *file_name, unsigned long old_file_size,
-		      off_t old_file_mtime)
-{
-  struct stat new_file_stat;
-  if ((*xstat) (file_name, &new_file_stat) < 0)
-    {
-      stat_error (file_name);
-      return;
-    }
-
-  /* Only check growth, shrinkage detected in copy_files_disk_to_{disk,tape}()
-   */
-  if (new_file_stat.st_size > old_file_size)
-    error (0, 0,
-	   ngettext ("File %s grew, %"PRIuMAX" new byte not copied",
-		     "File %s grew, %"PRIuMAX" new bytes not copied",
-		     (long)(new_file_stat.st_size - old_file_size)),
-	   file_name, (uintmax_t) (new_file_stat.st_size - old_file_size));
-
-  else if (new_file_stat.st_mtime != old_file_mtime)
-    error (0, 0, _("File %s was modified while being copied"), file_name);
-}
-
-/* Create all directories up to but not including the last part of NAME.
-   Do not destroy any nondirectories while creating directories.  */
-
-void
-create_all_directories (char *name)
-{
-  char *dir;
-  int   mode;
-#ifdef HPUX_CDF
-  int   cdf;
-#endif
-
-  dir = dir_name (name);
-  mode = 0700;
-#ifdef HPUX_CDF
-  cdf = islastparentcdf (name);
-  if (cdf)
-    {
-      dir [strlen (dir) - 1] = '\0';	/* remove final + */
-      mode = 04700;
-    }
-  
-#endif
-  
-  if (dir == NULL)
-    error (2, 0, _("virtual memory exhausted"));
-
-  if (dir[0] != '.' || dir[1] != '\0')
-    make_path (dir, mode, 0700, -1, -1, (char *) NULL);
-
-  free (dir);
-}
-
-/* Prepare to append to an archive.  We have been in
-   process_copy_in, keeping track of the position where
-   the last header started in `last_header_start'.  Now we
-   have the starting position of the last header (the TRAILER!!!
-   header, or blank record for tar archives) and we want to start
-   writing (appending) over the last header.  The last header may
-   be in the middle of a block, so to keep the buffering in sync
-   we lseek back to the start of the block, read everything up
-   to but not including the last header, lseek back to the start
-   of the block, and then do a copy_buf_out of what we read.
-   Actually, we probably don't have to worry so much about keeping the
-   buffering perfect since you can only append to archives that
-   are disk files.  */
-
-void
-prepare_append (int out_file_des)
-{
-  int start_of_header;
-  int start_of_block;
-  int useful_bytes_in_block;
-  char *tmp_buf;
-
-  start_of_header = last_header_start;
-  /* Figure out how many bytes we will rewrite, and where they start.  */
-  useful_bytes_in_block = start_of_header % io_block_size;
-  start_of_block = start_of_header - useful_bytes_in_block;
-
-  if (lseek (out_file_des, start_of_block, SEEK_SET) < 0)
-    error (1, errno, _("cannot seek on output"));
-  if (useful_bytes_in_block > 0)
-    {
-      tmp_buf = (char *) xmalloc (useful_bytes_in_block);
-      read (out_file_des, tmp_buf, useful_bytes_in_block);
-      if (lseek (out_file_des, start_of_block, SEEK_SET) < 0)
-	error (1, errno, _("cannot seek on output"));
-      /* fix juo -- is this copy_tape_buf_out?  or copy_disk? */
-      tape_buffered_write (tmp_buf, out_file_des, useful_bytes_in_block);
-      free (tmp_buf);
-    }
-
-  /* We are done reading the archive, so clear these since they
-     will now be used for reading in files that we are appending
-     to the archive.  */
-  input_size = 0;
-  input_bytes = 0;
-  in_buff = input_buffer;
-}
-
-/* Support for remembering inodes with multiple links.  Used in the
-   "copy in" and "copy pass" modes for making links instead of copying
-   the file.  */
-
-struct inode_val
-{
-  unsigned long inode;
-  unsigned long major_num;
-  unsigned long minor_num;
-  char *file_name;
-};
-
-/* Inode hash table.  Allocated by first call to add_inode.  */
-static Hash_table *hash_table = NULL;
-
-static size_t
-inode_val_hasher (const void *val, size_t n_buckets)
-{
-  const struct inode_val *ival = val;
-  return ival->inode % n_buckets;
-}
-
-static bool
-inode_val_compare (const void *val1, const void *val2)
-{
-  const struct inode_val *ival1 = val1;
-  const struct inode_val *ival2 = val2;
-  return ival1->inode == ival2->inode
-         && ival1->major_num == ival2->major_num
-         && ival1->minor_num == ival2->minor_num;
-}
-
-char *
-find_inode_file (unsigned long node_num, unsigned long major_num,
-		 unsigned long minor_num)
-{
-  struct inode_val sample;
-  struct inode_val *ival;
-  
-  if (!hash_table)
-    return NULL;
-  
-  sample.inode = node_num;
-  sample.major_num = major_num;
-  sample.minor_num = minor_num;
-  ival = hash_lookup (hash_table, &sample);
-  return ival ? ival->file_name : NULL;
-}
-
-/* Associate FILE_NAME with the inode NODE_NUM.  (Insert into hash table.)  */
-
-void
-add_inode (unsigned long node_num, char *file_name, unsigned long major_num,
-	   unsigned long minor_num)
-{
-  struct inode_val *temp;
-  struct inode_val *e;
-  
-  /* Create new inode record.  */
-  temp = (struct inode_val *) xmalloc (sizeof (struct inode_val));
-  temp->inode = node_num;
-  temp->major_num = major_num;
-  temp->minor_num = minor_num;
-  temp->file_name = xstrdup (file_name);
-
-  if (!((hash_table
-	 || (hash_table = hash_initialize (0, 0, inode_val_hasher,
-					   inode_val_compare, 0)))
-	&& (e = hash_insert (hash_table, temp))))
-    xalloc_die ();
-  /* FIXME: e is not used */
-}
-
-
-/* Open FILE in the mode specified by the command line options
-   and return an open file descriptor for it,
-   or -1 if it can't be opened.  */
-
-int
-open_archive (char *file)
-{
-  int fd;
-  void (*copy_in) ();		/* Workaround for pcc bug.  */
-
-  copy_in = process_copy_in;
-
-  if (copy_function == copy_in)
-    fd = rmtopen (file, O_RDONLY | O_BINARY, MODE_RW, rsh_command_option);
-  else
-    {
-      if (!append_flag)
-	fd = rmtopen (file, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, MODE_RW,
-			rsh_command_option);
-      else
-	fd = rmtopen (file, O_RDWR | O_BINARY, MODE_RW, rsh_command_option);
-    }
-
-  return fd;
-}
-
-/* Attempt to rewind the tape drive on file descriptor TAPE_DES
-   and take it offline.  */
-
-void
-tape_offline (int tape_des)
-{
-#if defined(MTIOCTOP) && defined(MTOFFL)
-  struct mtop control;
-
-  control.mt_op = MTOFFL;
-  control.mt_count = 1;
-  rmtioctl (tape_des, MTIOCTOP, (char*) &control);	/* Don't care if it fails.  */
-#endif
-}
-
-/* The file on file descriptor TAPE_DES is assumed to be magnetic tape
-   (or floppy disk or other device) and the end of the medium
-   has been reached.  Ask the user for to mount a new "tape" to continue
-   the processing.  If the user specified the device name on the
-   command line (with the -I, -O, -F or --file options), then we can
-   automatically re-open the same device to use the next medium.  If the
-   user did not specify the device name, then we have to ask them which
-   device to use.  */
-
-void
-get_next_reel (int tape_des)
-{
-  static int reel_number = 1;
-  FILE *tty_in;			/* File for interacting with user.  */
-  FILE *tty_out;		/* File for interacting with user.  */
-  int old_tape_des;
-  char *next_archive_name;
-  dynamic_string new_name;
-  char *str_res;
-
-  ds_init (&new_name, 128);
-
-  /* Open files for interactive communication.  */
-  tty_in = fopen (TTY_NAME, "r");
-  if (tty_in == NULL)
-    error (2, errno, TTY_NAME);
-  tty_out = fopen (TTY_NAME, "w");
-  if (tty_out == NULL)
-    error (2, errno, TTY_NAME);
-
-  old_tape_des = tape_des;
-  tape_offline (tape_des);
-  rmtclose (tape_des);
-
-  /* Give message and wait for carrage return.  User should hit carrage return
-     only after loading the next tape.  */
-  ++reel_number;
-  if (new_media_message)
-    fprintf (tty_out, "%s", new_media_message);
-  else if (new_media_message_with_number)
-    fprintf (tty_out, "%s%d%s", new_media_message_with_number, reel_number,
-	     new_media_message_after_number);
-  else if (archive_name)
-    fprintf (tty_out, _("Found end of volume.  Load next volume and press RETURN. "));
-  else
-    fprintf (tty_out, _("Found end of volume.  To continue, type device/file name when ready.\n"));
-
-  fflush (tty_out);
-
-  if (archive_name)
-    {
-      int c;
-
-      do
-	c = getc (tty_in);
-      while (c != EOF && c != '\n');
-
-      tape_des = open_archive (archive_name);
-      if (tape_des == -1)
-	open_error (archive_name);
-    }
-  else
-    {
-      do
-	{
-	  if (tape_des < 0)
-	    {
-	      fprintf (tty_out,
-		       _("To continue, type device/file name when ready.\n"));
-	      fflush (tty_out);
-	    }
-
-	  str_res = ds_fgets (tty_in, &new_name);
-	  if (str_res == NULL || str_res[0] == '\0')
-	    exit (1);
-	  next_archive_name = str_res;
-
-	  tape_des = open_archive (next_archive_name);
-	  if (tape_des == -1)
-	    open_error (next_archive_name);
-	}
-      while (tape_des < 0);
-    }
-
-  /* We have to make sure that `tape_des' has not changed its value even
-     though we closed it and reopened it, since there are local
-     copies of it in other routines.  This works fine on Unix (even with
-     rmtread and rmtwrite) since open will always return the lowest
-     available file descriptor and we haven't closed any files (e.g.,
-     stdin, stdout or stderr) that were opened before we originally opened
-     the archive.  */
-
-  if (tape_des != old_tape_des)
-    error (1, 0, _("internal error: tape descriptor changed from %d to %d"),
-	   old_tape_des, tape_des);
-
-  free (new_name.ds_string);
-  fclose (tty_in);
-  fclose (tty_out);
-}
-
-/* If MESSAGE does not contain the string "%d", make `new_media_message'
-   a copy of MESSAGE.  If MESSAGES does contain the string "%d", make
-   `new_media_message_with_number' a copy of MESSAGE up to, but
-   not including, the string "%d", and make `new_media_message_after_number'
-   a copy of MESSAGE after the string "%d".  */
-
-void
-set_new_media_message (char *message)
-{
-  char *p;
-  int prev_was_percent;
-
-  p = message;
-  prev_was_percent = 0;
-  while (*p != '\0')
-    {
-      if (*p == 'd' && prev_was_percent)
-	break;
-      prev_was_percent = (*p == '%');
-      ++p;
-    }
-  if (*p == '\0')
-    {
-      new_media_message = xstrdup (message);
-    }
-  else
-    {
-      int length = p - message - 1;
-
-      new_media_message_with_number = xmalloc (length + 1);
-      strncpy (new_media_message_with_number, message, length);
-      new_media_message_with_number[length] = '\0';
-      length = strlen (p + 1);
-      new_media_message_after_number = xmalloc (length + 1);
-      strcpy (new_media_message_after_number, p + 1);
-    }
-}
-
-#ifdef SYMLINK_USES_UMASK
-/* Most machines always create symlinks with rwxrwxrwx protection,
-   but some (HP/UX 8.07; maybe DEC's OSF on MIPS, too?) use the
-   umask when creating symlinks, so if your umask is 022 you end
-   up with rwxr-xr-x symlinks (although HP/UX seems to completely
-   ignore the protection).  There doesn't seem to be any way to
-   manipulate the modes once the symlinks are created (e.g.
-   a hypothetical "lchmod"), so to create them with the right
-   modes we have to set the umask first.  */
-
-int
-umasked_symlink (char *name1, char *name2, int mode)
-{
-  int	old_umask;
-  int	rc;
-  mode = ~(mode & 0777) & 0777;
-  old_umask = umask (mode);
-  rc = symlink (name1, name2);
-  umask (old_umask);
-  return rc;
-}
-#endif /* SYMLINK_USES_UMASK */
-
-#ifdef HPUX_CDF
-/* When we create a cpio archive we mark CDF's by putting an extra `/'
-   after their component name so we can distinguish the CDF's when we
-   extract the archive (in case the "hidden" directory's files appear
-   in the archive before the directory itself).  E.g., in the path
-   "a/b+/c", if b+ is a CDF, we will write this path as "a/b+//c" in
-   the archive so when we extract the archive we will know that b+
-   is actually a CDF, and not an ordinary directory whose name happens
-   to end in `+'.  We also do the same thing internally in copypass.c.  */
-
-
-/* Take an input pathname and check it for CDF's.  Insert an extra
-   `/' in the pathname after each "hidden" directory.  If we add
-   any `/'s, return a malloced string instead of the original input
-   string.
-   FIXME: This creates a memory leak.
-*/
-
-char *
-add_cdf_double_slashes (char *input_name)
-{
-  static char *ret_name = NULL;	/* re-usuable return buffer (malloc'ed)  */
-  static int ret_size = -1;	/* size of return buffer.  */
-  char *p;
-  char *q;
-  int n;
-  struct stat dir_stat;
-
-  /*  Search for a `/' preceeded by a `+'.  */
-
-  for (p = input_name; *p != '\0'; ++p)
-    {
-      if ( (*p == '+') && (*(p + 1) == '/') )
-	break;
-    }
-
-  /* If we didn't find a `/' preceeded by a `+' then there are
-     no CDF's in this pathname.  Return the original pathname.  */
-
-  if (*p == '\0')
-    return input_name;
-
-  /* There was a `/' preceeded by a `+' in the pathname.  If it is a CDF 
-     then we will need to copy the input pathname to our return
-     buffer so we can insert the extra `/'s.  Since we can't tell
-     yet whether or not it is a CDF we will just always copy the
-     string to the return buffer.  First we have to make sure the
-     buffer is large enough to hold the string and any number of
-     extra `/'s we might add.  */
-
-  n = 2 * (strlen (input_name) + 1);
-  if (n >= ret_size)
-    {
-      if (ret_size < 0)
-	ret_name = (char *) malloc (n);
-      else
-	ret_name = (char *)realloc (ret_name, n);
-      ret_size = n;
-    }
-
-  /* Clear the `/' after this component, so we can stat the pathname 
-     up to and including this component.  */
-  ++p;
-  *p = '\0';
-  if ((*xstat) (input_name, &dir_stat) < 0)
-    {
-      stat_error (input_name);
-      return input_name;
-    }
-
-  /* Now put back the `/' after this component and copy the pathname up to
-     and including this component and its trailing `/' to the return
-     buffer.  */
-  *p++ = '/';
-  strncpy (ret_name, input_name, p - input_name);
-  q = ret_name + (p - input_name);
-
-  /* If it was a CDF, add another `/'.  */
-  if (S_ISDIR (dir_stat.st_mode) && (dir_stat.st_mode & 04000) )
-    *q++ = '/';
-
-  /* Go through the rest of the input pathname, copying it to the
-     return buffer, and adding an extra `/' after each CDF.  */
-  while (*p != '\0')
-    {
-      if ( (*p == '+') && (*(p + 1) == '/') )
-	{
-	  *q++ = *p++;
-
-	  *p = '\0';
-	  if ((*xstat) (input_name, &dir_stat) < 0)
-	    {
-	      stat_error (input_name);
-	      return input_name;
-	    }
-	  *p = '/';
-
-	  if (S_ISDIR (dir_stat.st_mode) && (dir_stat.st_mode & 04000) )
-	    *q++ = '/';
-	}
-      *q++ = *p++;
-    }
-  *q = '\0';
-
-  return ret_name;
-}
-
-/* Is the last parent directory (e.g., c in a/b/c/d) a CDF?  If the
-   directory name ends in `+' and is followed by 2 `/'s instead of 1
-   then it is.  This is only the case for cpio archives, but we don't
-   have to worry about tar because tar always has the directory before
-   its files (or else we lose).  */
-int
-islastparentcdf (char *path)
-{
-  char *newpath;
-  char *slash;
-  int slash_count;
-  int length;			/* Length of result, not including NUL.  */
-
-  slash = strrchr (path, '/');
-  if (slash == 0)
-    return 0;
-  else
-    {
-      slash_count = 0;
-      while (slash > path && *slash == '/')
-	{
-	  ++slash_count;
-	  --slash;
-	}
-
-
-      if ( (*slash == '+') && (slash_count >= 2) )
-	return 1;
-    }
-  return 0;
-}
-#endif
-
-#define DISKBLOCKSIZE	(512)
-
-static int
-buf_all_zeros (char *buf, int bufsize)
-{
-  int	i;
-  for (i = 0; i < bufsize; ++i)
-    {
-      if (*buf++ != '\0')
-	return 0;
-    }
-  return 1;
-}
-
-int delayed_seek_count = 0;
-
-/* Write NBYTE bytes from BUF to remote tape connection FILDES.
-   Return the number of bytes written on success, -1 on error.  */
-
-static int
-sparse_write (int fildes, char *buf, unsigned int nbyte)
-{
-  int complete_block_count;
-  int leftover_bytes_count;
-  int seek_count;
-  int write_count;
-  char *cur_write_start;
-  int lseek_rc;
-  int write_rc;
-  int i;
-  enum { begin, in_zeros, not_in_zeros } state;
-
-  complete_block_count = nbyte / DISKBLOCKSIZE;
-  leftover_bytes_count = nbyte % DISKBLOCKSIZE;
-
-  if (delayed_seek_count != 0)
-    state = in_zeros;
-  else
-    state = begin;
-
-  seek_count = delayed_seek_count;
-
-  for (i = 0; i < complete_block_count; ++i)
-    {
-      switch (state)
-	{
-	  case begin :
-	    if (buf_all_zeros (buf, DISKBLOCKSIZE))
-	      {
-		seek_count = DISKBLOCKSIZE;
-		state = in_zeros;
-	      }
-	    else
-	      {
-		cur_write_start = buf;
-		write_count = DISKBLOCKSIZE;
-		state = not_in_zeros;
-	      }
-	    buf += DISKBLOCKSIZE;
-	    break;
-	    
-	  case in_zeros :
-	    if (buf_all_zeros (buf, DISKBLOCKSIZE))
-	      {
-		seek_count += DISKBLOCKSIZE;
-	      }
-	    else
-	      {
-		lseek (fildes, seek_count, SEEK_CUR);
-		cur_write_start = buf;
-		write_count = DISKBLOCKSIZE;
-		state = not_in_zeros;
-	      }
-	    buf += DISKBLOCKSIZE;
-	    break;
-	    
-	  case not_in_zeros :
-	    if (buf_all_zeros (buf, DISKBLOCKSIZE))
-	      {
-		write_rc = write (fildes, cur_write_start, write_count);
-		seek_count = DISKBLOCKSIZE;
-		state = in_zeros;
-	      }
-	    else
-	      {
-		write_count += DISKBLOCKSIZE;
-	      }
-	    buf += DISKBLOCKSIZE;
-	    break;
-	}
-    }
-
-  switch (state)
-    {
-      case begin :
-      case in_zeros :
-	delayed_seek_count = seek_count;
-	break;
-	
-      case not_in_zeros :
-	write_rc = write (fildes, cur_write_start, write_count);
-	delayed_seek_count = 0;
-	break;
-    }
-
-  if (leftover_bytes_count != 0)
-    {
-      if (delayed_seek_count != 0)
-	{
-	  lseek_rc = lseek (fildes, delayed_seek_count, SEEK_CUR);
-	  delayed_seek_count = 0;
-	}
-      write_rc = write (fildes, buf, leftover_bytes_count);
-    }
-  return nbyte;
-}
-
-#define CPIO_UID(uid) (set_owner_flag ? set_owner : (uid))
-#define CPIO_GID(gid) (set_group_flag ? set_group : (gid))
-
-void
-stat_to_cpio (struct cpio_file_stat *hdr, struct stat *st)
-{
-  hdr->c_dev_maj = major (st->st_dev);
-  hdr->c_dev_min = minor (st->st_dev);
-  hdr->c_ino = st->st_ino;
-  /* For POSIX systems that don't define the S_IF macros,
-     we can't assume that S_ISfoo means the standard Unix
-     S_IFfoo bit(s) are set.  So do it manually, with a
-     different name.  Bleah.  */
-  hdr->c_mode = (st->st_mode & 07777);
-  if (S_ISREG (st->st_mode))
-    hdr->c_mode |= CP_IFREG;
-  else if (S_ISDIR (st->st_mode))
-    hdr->c_mode |= CP_IFDIR;
-#ifdef S_ISBLK
-  else if (S_ISBLK (st->st_mode))
-    hdr->c_mode |= CP_IFBLK;
-#endif
-#ifdef S_ISCHR
-  else if (S_ISCHR (st->st_mode))
-    hdr->c_mode |= CP_IFCHR;
-#endif
-#ifdef S_ISFIFO
-  else if (S_ISFIFO (st->st_mode))
-    hdr->c_mode |= CP_IFIFO;
-#endif
-#ifdef S_ISLNK
-  else if (S_ISLNK (st->st_mode))
-    hdr->c_mode |= CP_IFLNK;
-#endif
-#ifdef S_ISSOCK
-  else if (S_ISSOCK (st->st_mode))
-    hdr->c_mode |= CP_IFSOCK;
-#endif
-#ifdef S_ISNWK
-  else if (S_ISNWK (st->st_mode))
-    hdr->c_mode |= CP_IFNWK;
-#endif
-  hdr->c_uid = CPIO_UID (st->st_uid);
-  hdr->c_gid = CPIO_GID (st->st_gid);
-  hdr->c_nlink = st->st_nlink;
-  hdr->c_rdev_maj = major (st->st_rdev);
-  hdr->c_rdev_min = minor (st->st_rdev);
-  hdr->c_mtime = st->st_mtime;
-  hdr->c_filesize = st->st_size;
-  hdr->c_chksum = 0;
-  hdr->c_tar_linkname = NULL;
-}
-
-#ifndef HAVE_FCHOWN
-# define fchown(fd, uid, gid) (-1)
-#endif
-
-int
-fchown_or_chown (int fd, const char *name, uid_t uid, uid_t gid)
-{
-  if (HAVE_FCHOWN && fd != -1)
-    return fchown (fd, uid, gid);
-  else
-    return chown (name, uid, gid);
-}
-
-int
-fchmod_or_chmod (int fd, const char *name, mode_t mode)
-{
-  if (HAVE_FCHMOD && fd != -1)
-    return fchmod (fd, mode);
-  else
-    return chmod(name, mode);
-}
-
-void
-set_perms (int fd, struct cpio_file_stat *header)
-{
-  if (!no_chown_flag)
-    {
-      uid_t uid = CPIO_UID (header->c_uid);
-      gid_t gid = CPIO_GID (header->c_gid); 
-      if ((fchown_or_chown (fd, header->c_name, uid, gid) < 0)
-	  && errno != EPERM)
-	chown_error_details (header->c_name, uid, gid);
-    }
-  /* chown may have turned off some permissions we wanted. */
-  if (fchmod_or_chmod (fd, header->c_name, header->c_mode) < 0)
-    chmod_error_details (header->c_name, header->c_mode);
-#ifdef HPUX_CDF
-  if ((header->c_mode & CP_IFMT) && cdf_flag)
-    /* Once we "hide" the directory with the chmod(),
-       we have to refer to it using name+ instead of name.  */
-    file_hdr->c_name [cdf_char] = '+';
-#endif
-  if (retain_time_flag)
-    set_file_times (fd, header->c_name, header->c_mtime, header->c_mtime);
-}
-
-void
-set_file_times (int fd,
-		const char *name, unsigned long atime, unsigned long mtime)
-{
-  struct timespec ts[2];
-  
-  memset (&ts, 0, sizeof ts);
-
-  ts[0].tv_sec = atime;
-  ts[1].tv_sec = mtime;
-
-  /* Silently ignore EROFS because reading the file won't have upset its 
-     timestamp if it's on a read-only filesystem. */
-  if (gl_futimens (fd, name, ts) < 0 && errno != EROFS)
-    utime_error (name);
-}
-
-/* Do we have to ignore absolute paths, and if so, does the filename
-   have an absolute path?  */
-void
-cpio_safer_name_suffix (char *name, bool link_target, bool absolute_names,
-			bool strip_leading_dots)
-{
-  char *p = safer_name_suffix (name, link_target, absolute_names);
-  if (strip_leading_dots && strcmp (p, "./"))
-    /* strip leading `./' from the filename.  */
-    while (*p == '.' && *(p + 1) == '/')
-      {
-	++p;
-	while (*p == '/')
-	  ++p;
-      }
-  if (p != name)
-    memmove (name, p, (size_t)(strlen (p) + 1));
-}
-
diff --git a/gnu/usr.bin/Makefile b/gnu/usr.bin/Makefile
index bfb4d93a0b7..18add27e527 100644
--- a/gnu/usr.bin/Makefile
+++ b/gnu/usr.bin/Makefile
@@ -4,7 +4,6 @@
 
 SUBDIR= ${_binutils} \
 	${_cc} \
-	${_cpio} \
 	${_cvs} \
 	dialog \
 	diff \
@@ -28,10 +27,6 @@ _groff=		groff
 .endif
 .endif
 
-.if ${MK_GNU_CPIO} == "yes"
-_cpio=		cpio
-.endif
-
 .if ${MK_CVS} != "no"
 _cvs=		cvs
 .endif
diff --git a/gnu/usr.bin/cpio/Makefile b/gnu/usr.bin/cpio/Makefile
deleted file mode 100644
index c31527be94a..00000000000
--- a/gnu/usr.bin/cpio/Makefile
+++ /dev/null
@@ -1,80 +0,0 @@
-# $FreeBSD$
-
-CPIODIR= ${.CURDIR}/../../../contrib/cpio
-.PATH: ${CPIODIR}/lib ${CPIODIR}/src ${CPIODIR}/doc
-
-SUBDIR=	doc
-
-PROG=	gcpio
-SRCS=   copyin.c \
-	copyout.c \
-	copypass.c \
-	defer.c \
-	dstring.c \
-	filemode.c \
-	global.c \
-	idcache.c \
-	main.c \
-	makepath.c \
-	tar.c \
-	userspec.c \
-	util.c \
-	argp-ba.c \
-	argp-eexst.c \
-	argp-fmtstream.c \
-	argp-fs-xinl.c \
-	argp-help.c \
-	argp-parse.c \
-	argp-pin.c \
-	argp-pv.c \
-	argp-pvh.c \
-	argp-xinl.c \
-	basename.c \
-	dirname.c \
-	error.c \
-	exitfail.c \
-	fatal.c \
-	full-write.c \
-	getopt.c \
-	getopt1.c \
-	hash.c \
-	mempcpy.c \
-	paxerror.c \
-	paxexit.c \
-	paxnames.c \
-	quote.c \
-	quotearg.c \
-	rtapelib.c \
-	safe-read.c \
-	safe-write.c \
-	strchrnul.c \
-	stripslash.c \
-	strndup.c \
-	strnlen.c \
-	umaxtostr.c \
-	utimens.c \
-	xalloc-die.c \
-	xmalloc.c \
-	xstrndup.c \
-	alloca.h \
-	getopt.h
-CSTD=gnu89
-
-CLEANFILES+= alloca.h getopt.h
-
-getopt.h: getopt_.h
-	ln -fs ${.ALLSRC} ${.TARGET}
-
-alloca.h: alloca_.h
-	ln -fs ${.ALLSRC} ${.TARGET}
-
-CFLAGS+=-I${.OBJDIR} -I${.CURDIR} -I${CPIODIR}/lib -I${CPIODIR}/src \
-	-DHAVE_CONFIG_H -DHAVE_MKFIFO -DHAVE_SETLOCALE -DHAVE_LSTAT
-
-gcpio.1: ${CPIODIR}/doc/cpio.1
-	cat ${CPIODIR}/doc/cpio.1 >gcpio.1
-
-SYMLINKS=gcpio ${BINDIR}/cpio
-MLINKS=gcpio.1 cpio.1
-
-.include 
diff --git a/gnu/usr.bin/cpio/config.h b/gnu/usr.bin/cpio/config.h
deleted file mode 100644
index 36a88f0a72c..00000000000
--- a/gnu/usr.bin/cpio/config.h
+++ /dev/null
@@ -1,1001 +0,0 @@
-/* $FreeBSD$ */
-
-/* config.h.  Generated from config.h.in by configure.  */
-/* config.h.in.  Generated from configure.ac by autoheader.  */
-
-/* Define this to an absolute name of . */
-/* #undef ABSOLUTE_DIRENT_H */
-
-/* Define this to an absolute name of . */
-#define ABSOLUTE_FCNTL_H "///usr/include/fcntl.h"
-
-/* Define this to an absolute name of . */
-/* #undef ABSOLUTE_FLOAT_H */
-
-/* Define this to an absolute name of . */
-#define ABSOLUTE_INTTYPES_H "///usr/include/inttypes.h"
-
-/* Define this to an absolute name of . */
-#define ABSOLUTE_STDINT_H "///usr/include/stdint.h"
-
-/* Define this to an absolute name of . */
-#define ABSOLUTE_STDIO_H "///usr/include/stdio.h"
-
-/* Define this to an absolute name of . */
-#define ABSOLUTE_STDLIB_H "///usr/include/stdlib.h"
-
-/* Define this to an absolute name of . */
-#define ABSOLUTE_STRING_H "///usr/include/string.h"
-
-/* Define this to an absolute name of . */
-#define ABSOLUTE_SYSEXITS_H "///usr/include/sysexits.h"
-
-/* Define this to an absolute name of . */
-#define ABSOLUTE_SYS_STAT_H "///usr/include/sys/stat.h"
-
-/* Define this to an absolute name of . */
-#define ABSOLUTE_SYS_TIME_H "///usr/include/sys/time.h"
-
-/* Define this to an absolute name of . */
-#define ABSOLUTE_TIME_H "///usr/include/time.h"
-
-/* Define this to an absolute name of . */
-#define ABSOLUTE_UNISTD_H "///usr/include/unistd.h"
-
-/* Define this to an absolute name of . */
-/* #undef ABSOLUTE_WCHAR_H */
-
-/* Define this to an absolute name of . */
-#define ABSOLUTE_WCTYPE_H "///usr/include/wctype.h"
-
-/* Define to the number of bits in type 'ptrdiff_t'. */
-/* #undef BITSIZEOF_PTRDIFF_T */
-
-/* Define to the number of bits in type 'sig_atomic_t'. */
-/* #undef BITSIZEOF_SIG_ATOMIC_T */
-
-/* Define to the number of bits in type 'size_t'. */
-/* #undef BITSIZEOF_SIZE_T */
-
-/* Define to the number of bits in type 'wchar_t'. */
-/* #undef BITSIZEOF_WCHAR_T */
-
-/* Define to the number of bits in type 'wint_t'. */
-/* #undef BITSIZEOF_WINT_T */
-
-/* Define if chown is not POSIX compliant regarding IDs of -1. */
-/* #undef CHOWN_FAILS_TO_HONOR_ID_OF_NEGATIVE_ONE */
-
-/* Define if chown modifies symlinks. */
-/* #undef CHOWN_MODIFIES_SYMLINK */
-
-/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
-   systems. This function is required for `alloca.c' support on those systems.
-   */
-/* #undef CRAY_STACKSEG_END */
-
-/* Define to 1 if using `alloca.c'. */
-/* #undef C_ALLOCA */
-
-/* Define full file name of rmt program. */
-#define DEFAULT_RMT_COMMAND "/etc/rmt"
-
-/* the name of the file descriptor member of DIR */
-/* #undef DIR_FD_MEMBER_NAME */
-
-#ifdef DIR_FD_MEMBER_NAME
-# define DIR_TO_FD(Dir_p) ((Dir_p)->DIR_FD_MEMBER_NAME)
-#else
-# define DIR_TO_FD(Dir_p) -1
-#endif
-
-
-/* Define to 1 if // is a file system root distinct from /. */
-/* #undef DOUBLE_SLASH_IS_DISTINCT_ROOT */
-
-/* Define if struct dirent has a member d_ino that actually works. */
-#define D_INO_IN_DIRENT 1
-
-/* Define to 1 if translation of program messages to the user's native
-   language is requested. */
-/* #undef ENABLE_NLS */
-
-/* Define as good substitute value for EOVERFLOW. */
-/* #undef EOVERFLOW */
-
-/* Define if gnulib's fchdir() replacement is used. */
-/* #undef FCHDIR_REPLACEMENT */
-
-/* Define on systems for which file names may have a so-called `drive letter'
-   prefix, define this to compute the length of that prefix, including the
-   colon. */
-#define FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX 0
-
-/* Define if the backslash character may also serve as a file name component
-   separator. */
-#define FILE_SYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR 0
-
-/* Define if a drive letter prefix denotes a relative path if it is not
-   followed by a file name component separator. */
-#define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
-
-/* Define if gettimeofday clobbers the localtime buffer. */
-/* #undef GETTIMEOFDAY_CLOBBERS_LOCALTIME */
-
-/* Define to 1 when using the gnulib module close-stream. */
-#define GNULIB_CLOSE_STREAM 1
-
-/* Define to 1 when using the gnulib module fcntl-safer. */
-#define GNULIB_FCNTL_SAFER 1
-
-/* Define to 1 to add extern declaration of program_invocation_name to argp.h
-   */
-#define GNULIB_PROGRAM_INVOCATION_NAME 1
-
-/* Define to 1 to add extern declaration of program_invocation_short_name to
-   argp.h */
-#define GNULIB_PROGRAM_INVOCATION_SHORT_NAME 1
-
-/* Define to 1 if you have the `alarm' function. */
-#define HAVE_ALARM 1
-
-/* Define to 1 if you have 'alloca' after including , a header that
-   may be supplied by this distribution. */
-#define HAVE_ALLOCA 1
-
-/* Define HAVE_ALLOCA_H for backward compatibility with older code that
-   includes  only if HAVE_ALLOCA_H is defined. */
-#define HAVE_ALLOCA_H 1
-
-/* Define to 1 if you have the `btowc' function. */
-#define HAVE_BTOWC 1
-
-/* Define to 1 if you have the `canonicalize_file_name' function. */
-/* #undef HAVE_CANONICALIZE_FILE_NAME */
-
-/* Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the
-   CoreFoundation framework. */
-/* #undef HAVE_CFLOCALECOPYCURRENT */
-
-/* Define to 1 if you have the MacOS X function CFPreferencesCopyAppValue in
-   the CoreFoundation framework. */
-/* #undef HAVE_CFPREFERENCESCOPYAPPVALUE */
-
-/* Define to 1 if your system has a working `chown' function. */
-#define HAVE_CHOWN 1
-
-/* Define to 1 if you have the `clock_gettime' function. */
-#define HAVE_CLOCK_GETTIME 1
-
-/* Define to 1 if you have the `clock_settime' function. */
-#define HAVE_CLOCK_SETTIME 1
-
-/* Define if you have compound literals. */
-/* #undef HAVE_COMPOUND_LITERALS */
-
-/* Define if the GNU dcgettext() function is already present or preinstalled.
-   */
-/* #undef HAVE_DCGETTEXT */
-
-/* Define to 1 if you have the declaration of `atoi', and to 0 if you don't.
-   */
-#define HAVE_DECL_ATOI 1
-
-/* Define to 1 if you have the declaration of `canonicalize_file_name', and to
-   0 if you don't. */
-#define HAVE_DECL_CANONICALIZE_FILE_NAME 0
-
-/* Define to 1 if you have the declaration of `clearerr_unlocked', and to 0 if
-   you don't. */
-#define HAVE_DECL_CLEARERR_UNLOCKED 1
-
-/* Define to 1 if you have the declaration of `dirfd', and to 0 if you don't.
-   */
-#define HAVE_DECL_DIRFD 1
-
-/* Define to 1 if you have the declaration of `errno', and to 0 if you don't.
-   */
-#define HAVE_DECL_ERRNO 1
-
-/* Define to 1 if you have the declaration of `exit', and to 0 if you don't.
-   */
-#define HAVE_DECL_EXIT 1
-
-/* Define to 1 if you have the declaration of `feof_unlocked', and to 0 if you
-   don't. */
-#define HAVE_DECL_FEOF_UNLOCKED 1
-
-/* Define to 1 if you have the declaration of `ferror_unlocked', and to 0 if
-   you don't. */
-#define HAVE_DECL_FERROR_UNLOCKED 1
-
-/* Define to 1 if you have the declaration of `fflush_unlocked', and to 0 if
-   you don't. */
-#define HAVE_DECL_FFLUSH_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `fgets_unlocked', and to 0 if
-   you don't. */
-#define HAVE_DECL_FGETS_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `fputc_unlocked', and to 0 if
-   you don't. */
-#define HAVE_DECL_FPUTC_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `fputs_unlocked', and to 0 if
-   you don't. */
-#define HAVE_DECL_FPUTS_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `fread_unlocked', and to 0 if
-   you don't. */
-#define HAVE_DECL_FREAD_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `fwrite_unlocked', and to 0 if
-   you don't. */
-#define HAVE_DECL_FWRITE_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `getchar_unlocked', and to 0 if
-   you don't. */
-#define HAVE_DECL_GETCHAR_UNLOCKED 1
-
-/* Define to 1 if you have the declaration of `getcwd', and to 0 if you don't.
-   */
-#define HAVE_DECL_GETCWD 1
-
-/* Define to 1 if you have the declaration of `getc_unlocked', and to 0 if you
-   don't. */
-#define HAVE_DECL_GETC_UNLOCKED 1
-
-/* Define to 1 if you have the declaration of `getenv', and to 0 if you don't.
-   */
-#define HAVE_DECL_GETENV 1
-
-/* Define to 1 if you have the declaration of `getgrgid', and to 0 if you
-   don't. */
-#define HAVE_DECL_GETGRGID 1
-
-/* Define to 1 if you have the declaration of `getgrnam', and to 0 if you
-   don't. */
-#define HAVE_DECL_GETGRNAM 1
-
-/* Define to 1 if you have the declaration of `getpwnam', and to 0 if you
-   don't. */
-#define HAVE_DECL_GETPWNAM 1
-
-/* Define to 1 if you have the declaration of `imaxabs', and to 0 if you
-   don't. */
-#define HAVE_DECL_IMAXABS 1
-
-/* Define to 1 if you have the declaration of `imaxdiv', and to 0 if you
-   don't. */
-#define HAVE_DECL_IMAXDIV 1
-
-/* Define to 1 if you have the declaration of `isblank', and to 0 if you
-   don't. */
-#define HAVE_DECL_ISBLANK 1
-
-/* Define to 1 if you have the declaration of `lchown', and to 0 if you don't.
-   */
-#define HAVE_DECL_LCHOWN 1
-
-/* Define to 1 if you have the declaration of `memrchr', and to 0 if you
-   don't. */
-#define HAVE_DECL_MEMRCHR 0
-
-/* Define to 1 if you have the declaration of `mkdir', and to 0 if you don't.
-   */
-#define HAVE_DECL_MKDIR 1
-
-/* Define if program_invocation_name is declared */
-/* #undef HAVE_DECL_PROGRAM_INVOCATION_NAME */
-
-/* Define if program_invocation_short_name is declared */
-/* #undef HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME */
-
-/* Define to 1 if you have the declaration of `putchar_unlocked', and to 0 if
-   you don't. */
-#define HAVE_DECL_PUTCHAR_UNLOCKED 1
-
-/* Define to 1 if you have the declaration of `putc_unlocked', and to 0 if you
-   don't. */
-#define HAVE_DECL_PUTC_UNLOCKED 1
-
-/* Define to 1 if you have the declaration of `strdup', and to 0 if you don't.
-   */
-#define HAVE_DECL_STRDUP 1
-
-/* Define to 1 if you have the declaration of `strerror', and to 0 if you
-   don't. */
-#define HAVE_DECL_STRERROR 1
-
-/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you
-   don't. */
-#define HAVE_DECL_STRERROR_R 1
-
-/* Define to 1 if you have the declaration of `strncasecmp', and to 0 if you
-   don't. */
-#define HAVE_DECL_STRNCASECMP 1
-
-/* Define to 1 if you have the declaration of `strndup', and to 0 if you
-   don't. */
-#define HAVE_DECL_STRNDUP 0
-
-/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
-   don't. */
-#define HAVE_DECL_STRNLEN 0
-
-/* Define to 1 if you have the declaration of `strtoimax', and to 0 if you
-   don't. */
-#define HAVE_DECL_STRTOIMAX 1
-
-/* Define to 1 if you have the declaration of `strtoumax', and to 0 if you
-   don't. */
-#define HAVE_DECL_STRTOUMAX 1
-
-/* Define to 1 if you have the declaration of `tzname', and to 0 if you don't.
-   */
-/* #undef HAVE_DECL_TZNAME */
-
-/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
-   don't. */
-#define HAVE_DECL_VSNPRINTF 1
-
-/* Define to 1 if you have the declaration of `__fpending', and to 0 if you
-   don't. */
-#define HAVE_DECL___FPENDING 0
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_DIRENT_H 1
-
-/* Define to 1 if you have the `dirfd' function. */
-/* #undef HAVE_DIRFD */
-
-/* Define to 1 if you have the `dup2' function. */
-#define HAVE_DUP2 1
-
-/* Define if you have the declaration of environ. */
-/* #undef HAVE_ENVIRON_DECL */
-
-/* Define to 1 if you have the `fchdir' function. */
-#define HAVE_FCHDIR 1
-
-/* Define to 1 if you have the `fchmod' function. */
-#define HAVE_FCHMOD 1
-
-/* Define to 1 if you have the `fchmodat' function. */
-/* #undef HAVE_FCHMODAT */
-
-/* Define to 1 if you have the `fchown' function. */
-#define HAVE_FCHOWN 1
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_FCNTL_H 1
-
-/* Define to 1 if you have the `fdopendir' function. */
-/* #undef HAVE_FDOPENDIR */
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_FEATURES_H */
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_FLOAT_H 1
-
-/* Define to 1 if you have the `flockfile' function. */
-#define HAVE_FLOCKFILE 1
-
-/* Define to 1 if you have the `funlockfile' function. */
-#define HAVE_FUNLOCKFILE 1
-
-/* Define to 1 if you have the `futimes' function. */
-#define HAVE_FUTIMES 1
-
-/* Define to 1 if you have the `futimesat' function. */
-/* #undef HAVE_FUTIMESAT */
-
-/* Define to 1 if you have the `getcwd' function. */
-#define HAVE_GETCWD 1
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_GETOPT_H 1
-
-/* Define to 1 if you have the `getopt_long_only' function. */
-#define HAVE_GETOPT_LONG_ONLY 1
-
-/* Define to 1 if you have the `getpagesize' function. */
-#define HAVE_GETPAGESIZE 1
-
-/* Define if the GNU gettext() function is already present or preinstalled. */
-/* #undef HAVE_GETTEXT */
-
-/* Define to 1 if you have the `gettimeofday' function. */
-#define HAVE_GETTIMEOFDAY 1
-
-/* Define if you have the iconv() function and it works. */
-/* #undef HAVE_ICONV */
-
-/* Define to 1 if the compiler supports one of the keywords 'inline',
-   '__inline__', '__inline' and effectively inlines functions marked as such.
-   */
-#define HAVE_INLINE 1
-
-/* Define if you have the 'intmax_t' type in  or . */
-#define HAVE_INTMAX_T 1
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_INTTYPES_H 1
-
-/* Define if  exists, doesn't clash with , and
-   declares uintmax_t. */
-#define HAVE_INTTYPES_H_WITH_UINTMAX 1
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_IO_H */
-
-/* Define to 1 if you have the `iswcntrl' function. */
-#define HAVE_ISWCNTRL 1
-
-/* Define to 1 if you have the `iswctype' function. */
-#define HAVE_ISWCTYPE 1
-
-/* Define to 1 if you have the `lchmod' function. */
-#define HAVE_LCHMOD 1
-
-/* Define to 1 if you have the `lchown' function. */
-#define HAVE_LCHOWN 1
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_LIBINTL_H */
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_LINEWRAP_H */
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_LOCALE_H 1
-
-/* Define if you have the 'long long' type. */
-#define HAVE_LONG_LONG 1
-
-/* Define to 1 if the system has the type `long long int'. */
-#define HAVE_LONG_LONG_INT 1
-
-/* Define to 1 if you have the `lstat' function. */
-#define HAVE_LSTAT 1
-
-/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
-   to 0 otherwise. */
-#define HAVE_MALLOC 1
-
-/* Define to 1 if mbrtowc and mbstate_t are properly declared. */
-#define HAVE_MBRTOWC 1
-
-/* Define to 1 if you have the `mbsinit' function. */
-#define HAVE_MBSINIT 1
-
-/* Define to 1 if you have the `mbsrtowcs' function. */
-#define HAVE_MBSRTOWCS 1
-
-/* Define to 1 if  declares mbstate_t. */
-#define HAVE_MBSTATE_T 1
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_MEMORY_H 1
-
-/* Define to 1 if you have the `mempcpy' function. */
-/* #undef HAVE_MEMPCPY */
-
-/* Define to 1 if you have the `memrchr' function. */
-/* #undef HAVE_MEMRCHR */
-
-/* Define to 1 if you have the `mkdirat' function. */
-/* #undef HAVE_MKDIRAT */
-
-/* Define to 1 if you have the `mkfifo' function. */
-#define HAVE_MKFIFO 1
-
-/* Define to 1 if you have the `nanotime' function. */
-/* #undef HAVE_NANOTIME */
-
-/* Define to 1 if you have the  header file, and it defines `DIR'. */
-/* #undef HAVE_NDIR_H */
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_NETDB_H 1
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_NET_ERRNO_H */
-
-/* Define to 1 if libc includes obstacks. */
-/* #undef HAVE_OBSTACK */
-
-/* Define to 1 if you have the `openat' function. */
-/* #undef HAVE_OPENAT */
-
-/* Define to 1 if getcwd works, except it sometimes fails when it shouldn't,
-   setting errno to ERANGE, ENAMETOOLONG, or ENOENT. If __GETCWD_PREFIX is not
-   defined, it doesn't matter whether HAVE_PARTLY_WORKING_GETCWD is defined.
-   */
-#define HAVE_PARTLY_WORKING_GETCWD 1
-
-/* Define to 1 if you have the `pipe' function. */
-#define HAVE_PIPE 1
-
-/* Define if program_invocation_name is defined */
-/* #undef HAVE_PROGRAM_INVOCATION_NAME */
-
-/* Define if program_invocation_short_name is defined */
-/* #undef HAVE_PROGRAM_INVOCATION_SHORT_NAME */
-
-/* Define to 1 if the system has the type `ptrdiff_t'. */
-#define HAVE_PTRDIFF_T 1
-
-/* Define to 1 if you have the `readlink' function. */
-#define HAVE_READLINK 1
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_SEARCH_H */
-
-/* Define to 1 if you have the `setenv' function. */
-#define HAVE_SETENV 1
-
-/* Define to 1 if you have the `setlocale' function. */
-#define HAVE_SETLOCALE 1
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_SGTTY_H */
-
-/* Define to 1 if 'sig_atomic_t' is a signed integer type. */
-/* #undef HAVE_SIGNED_SIG_ATOMIC_T */
-
-/* Define to 1 if 'wchar_t' is a signed integer type. */
-/* #undef HAVE_SIGNED_WCHAR_T */
-
-/* Define to 1 if 'wint_t' is a signed integer type. */
-/* #undef HAVE_SIGNED_WINT_T */
-
-/* Define to 1 if you have the `sleep' function. */
-#define HAVE_SLEEP 1
-
-/* Define to 1 if you have the `snprintf' function. */
-#define HAVE_SNPRINTF 1
-
-/* Define to 1 if stdbool.h conforms to C99. */
-#define HAVE_STDBOOL_H 1
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_STDINT_H 1
-
-/* Define if  exists, doesn't clash with , and declares
-   uintmax_t. */
-#define HAVE_STDINT_H_WITH_UINTMAX 1
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_STDIO_EXT_H */
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_STDIO_H 1
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_STDLIB_H 1
-
-/* Define to 1 if you have the `stpcpy' function. */
-#define HAVE_STPCPY 1
-
-/* Define to 1 if you have the `strcasecmp' function. */
-#define HAVE_STRCASECMP 1
-
-/* Define to 1 if you have the `strchrnul' function. */
-/* #undef HAVE_STRCHRNUL */
-
-/* Define to 1 if you have the `strdup' function. */
-#define HAVE_STRDUP 1
-
-/* Define to 1 if you have the `strerror' function. */
-#define HAVE_STRERROR 1
-
-/* Define to 1 if you have the `strerror_r' function. */
-#define HAVE_STRERROR_R 1
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_STRINGS_H 1
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_STRING_H 1
-
-/* Define to 1 if you have the `strncasecmp' function. */
-#define HAVE_STRNCASECMP 1
-
-/* Define if you have the strndup() function and it works. */
-/* #undef HAVE_STRNDUP */
-
-/* Define to 1 if you have the `strtol' function. */
-#define HAVE_STRTOL 1
-
-/* Define to 1 if `st_blksize' is member of `struct stat'. */
-#define HAVE_STRUCT_STAT_ST_BLKSIZE 1
-
-/* Define to 1 if `st_blocks' is member of `struct stat'. */
-#define HAVE_STRUCT_STAT_ST_BLOCKS 1
-
-/* Define to 1 if `tm_zone' is member of `struct tm'. */
-#define HAVE_STRUCT_TM_TM_ZONE 1
-
-/* Define if struct utimbuf is declared -- usually in . Some systems
-   have utime.h but don't declare the struct anywhere. */
-#define HAVE_STRUCT_UTIMBUF 1
-
-/* Define to 1 if your `struct stat' has `st_blksize'. Deprecated, use
-   `HAVE_STRUCT_STAT_ST_BLKSIZE' instead. */
-#define HAVE_ST_BLKSIZE 1
-
-/* Define to 1 if your `struct stat' has `st_blocks'. Deprecated, use
-   `HAVE_STRUCT_STAT_ST_BLOCKS' instead. */
-#define HAVE_ST_BLOCKS 1
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_SYSEXITS_H 1
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_SYS_BITYPES_H */
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_SYS_BUF_H 1
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_SYS_DEVICE_H */
-
-/* Define to 1 if you have the  header file, and it defines `DIR'.
-   */
-/* #undef HAVE_SYS_DIR_H */
-
-/* Define if your system has sys_errlist global variable */
-#define HAVE_SYS_ERRLIST 1
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_SYS_GENTAPE_H */
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_SYS_INET_H */
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_SYS_INTTYPES_H */
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_SYS_IO_TRIOCTL_H */
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_SYS_MTIO_H 1
-
-/* Define to 1 if you have the  header file, and it defines `DIR'.
-   */
-/* #undef HAVE_SYS_NDIR_H */
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_SYS_PARAM_H 1
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_SYS_STAT_H 1
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_SYS_TAPE_H */
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_SYS_TIMEB_H */
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_SYS_TIME_H 1
-
-/* Define to 1 if you have the  header file. */
-/* #undef HAVE_SYS_TPRINTF_H */
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_SYS_TYPES_H 1
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_SYS_WAIT_H 1
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_TIME_H 1
-
-/* Define if struct tm has the tm_gmtoff member. */
-#define HAVE_TM_GMTOFF 1
-
-/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
-   `HAVE_STRUCT_TM_TM_ZONE' instead. */
-#define HAVE_TM_ZONE 1
-
-/* Define to 1 if you have the `tsearch' function. */
-/* #undef HAVE_TSEARCH */
-
-/* Define to 1 if you don't have `tm_zone' but do have the external array
-   `tzname'. */
-/* #undef HAVE_TZNAME */
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_UNISTD_H 1
-
-/* Define to 1 if you have the `unsetenv' function. */
-#define HAVE_UNSETENV 1
-
-/* Define to 1 if the system has the type `unsigned long long int'. */
-#define HAVE_UNSIGNED_LONG_LONG_INT 1
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_UTIME_H 1
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_UTMP_H 1
-
-/* Define to 1 if you have the `vasnprintf' function. */
-/* #undef HAVE_VASNPRINTF */
-
-/* Define to 1 if you have the `vsnprintf' function. */
-#define HAVE_VSNPRINTF 1
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_WCHAR_H 1
-
-/* Define if you have the 'wchar_t' type. */
-#define HAVE_WCHAR_T 1
-
-/* Define to 1 if you have the `wcslen' function. */
-#define HAVE_WCSLEN 1
-
-/* Define to 1 if you have the  header file. */
-#define HAVE_WCTYPE_H 1
-
-/* Define if you have the 'wint_t' type. */
-#define HAVE_WINT_T 1
-
-/* Define to 1 if you have the `wmemchr' function. */
-#define HAVE_WMEMCHR 1
-
-/* Define to 1 if you have the `wmemcpy' function. */
-#define HAVE_WMEMCPY 1
-
-/* Define to 1 if you have the `wmempcpy' function. */
-/* #undef HAVE_WMEMPCPY */
-
-/* Define to 1 if O_NOATIME works. */
-#define HAVE_WORKING_O_NOATIME 0
-
-/* Define to 1 if O_NOFOLLOW works. */
-#define HAVE_WORKING_O_NOFOLLOW 1
-
-/* Define if utimes works properly. */
-#define HAVE_WORKING_UTIMES 1
-
-/* Define to 1 if the system has the type `_Bool'. */
-#define HAVE__BOOL 1
-
-/* Define to 1 if you have the `_ftime' function. */
-/* #undef HAVE__FTIME */
-
-/* Define to 1 if you have the `__fpending' function. */
-/* #undef HAVE___FPENDING */
-
-#if FILE_SYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR
-# define ISSLASH(C) ((C) == '/' || (C) == '\\')
-#else
-# define ISSLASH(C) ((C) == '/')
-#endif
-
-/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
-   slash. */
-/* #undef LSTAT_FOLLOWS_SLASHED_SYMLINK */
-
-/* Define to 1 if `major', `minor', and `makedev' are declared in .
-   */
-/* #undef MAJOR_IN_MKDEV */
-
-/* Define to 1 if `major', `minor', and `makedev' are declared in
-   . */
-/* #undef MAJOR_IN_SYSMACROS */
-
-/* If malloc(0) is != NULL, define this to 1. Otherwise define this to 0. */
-#define MALLOC_0_IS_NONNULL 1
-
-/* Define to mt_model (v.g., for DG/UX), else to mt_type. */
-#define MTIO_CHECK_FIELD mt_type
-
-/* Name of package */
-#define PACKAGE "cpio"
-
-/* Define to the address where bug reports for this package should be sent. */
-#define PACKAGE_BUGREPORT "bug-cpio@gnu.org"
-
-/* Define to the full name of this package. */
-#define PACKAGE_NAME "GNU cpio"
-
-/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "GNU cpio 2.8-FreeBSD"
-
-/* Define to the one symbol short name of this package. */
-#define PACKAGE_TARNAME "cpio"
-
-/* Define to the version of this package. */
-#define PACKAGE_VERSION "2.8-FreeBSD"
-
-/* the number of pending output bytes on stream `fp' */
-#define PENDING_OUTPUT_N_BYTES fp->_p - fp->_bf._base
-
-/* Define if  exists and defines unusable PRI* macros. */
-/* #undef PRI_MACROS_BROKEN */
-
-/* Define to 1 if the C compiler supports function prototypes. */
-#define PROTOTYPES 1
-
-/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
-   'ptrdiff_t'. */
-/* #undef PTRDIFF_T_SUFFIX */
-
-/* Define if vasnprintf exists but is overridden by gnulib. */
-/* #undef REPLACE_VASNPRINTF */
-
-/* Define as the return type of signal handlers (`int' or `void'). */
-#define RETSIGTYPE void
-
-/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
-   'sig_atomic_t'. */
-/* #undef SIG_ATOMIC_T_SUFFIX */
-
-/* Define as the maximum value of type 'size_t', if the system doesn't define
-   it. */
-/* #undef SIZE_MAX */
-
-/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
-   'size_t'. */
-/* #undef SIZE_T_SUFFIX */
-
-/* If using the C implementation of alloca, define if you know the
-   direction of stack growth for your system; otherwise it will be
-   automatically deduced at runtime.
-	STACK_DIRECTION > 0 => grows toward higher addresses
-	STACK_DIRECTION < 0 => grows toward lower addresses
-	STACK_DIRECTION = 0 => direction of growth unknown */
-/* #undef STACK_DIRECTION */
-
-/* Define to 1 if the `S_IS*' macros in  do not work properly. */
-/* #undef STAT_MACROS_BROKEN */
-
-/* Define to 1 if you have the ANSI C header files. */
-#define STDC_HEADERS 1
-
-/* Define to 1 if strerror_r returns char *. */
-/* #undef STRERROR_R_CHAR_P */
-
-/* Define to 1 if you can safely include both  and . */
-#define TIME_WITH_SYS_TIME 1
-
-/* Define to 1 if your  declares `struct tm'. */
-/* #undef TM_IN_SYS_TIME */
-
-/* Define to 1 if you want getc etc. to use unlocked I/O if available.
-   Unlocked I/O can improve performance in unithreaded apps, but it is not
-   safe for multithreaded apps. */
-#define USE_UNLOCKED_IO 1
-
-/* Version number of package */
-#define VERSION "2.8-FreeBSD"
-
-/* Define if unsetenv() returns void, not int. */
-/* #undef VOID_UNSETENV */
-
-/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
-   'wchar_t'. */
-/* #undef WCHAR_T_SUFFIX */
-
-/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
-   'wint_t'. */
-/* #undef WINT_T_SUFFIX */
-
-/* Define to 1 if on AIX 3.
-   System headers sometimes define this.
-   We just want to avoid a redefinition error message.  */
-#ifndef _ALL_SOURCE
-/* # undef _ALL_SOURCE */
-#endif
-
-/* Number of bits in a file offset, on hosts where this is settable. */
-/* #undef _FILE_OFFSET_BITS */
-
-/* Enable GNU extensions on systems that have them.  */
-#ifndef _GNU_SOURCE
-# define _GNU_SOURCE 1
-#endif
-
-/* Define for large files, on AIX-style hosts. */
-/* #undef _LARGE_FILES */
-
-/* Define to 1 if on MINIX. */
-/* #undef _MINIX */
-
-/* Define to 2 if the system does not provide POSIX.1 features except with
-   this defined. */
-/* #undef _POSIX_1_SOURCE */
-
-/* Define to 1 if you need to in order for `stat' and other things to work. */
-/* #undef _POSIX_SOURCE */
-
-/* Enable extensions on Solaris.  */
-#ifndef __EXTENSIONS__
-# define __EXTENSIONS__ 1
-#endif
-#ifndef _POSIX_PTHREAD_SEMANTICS
-# define _POSIX_PTHREAD_SEMANTICS 1
-#endif
-#ifndef _TANDEM_SOURCE
-# define _TANDEM_SOURCE 1
-#endif
-
-/* Define to rpl_ if the getopt replacement functions and variables should be
-   used. */
-#define __GETOPT_PREFIX rpl_
-
-/* Define to rpl_ if the openat replacement function should be used. */
-#define __OPENAT_PREFIX rpl_
-
-/* Define like PROTOTYPES; this can be used by system headers. */
-#define __PROTOTYPES 1
-
-/* Define to empty if `const' does not conform to ANSI C. */
-/* #undef const */
-
-/* Define to rpl_fchownat if the replacement function should be used. */
-#define fchownat rpl_fchownat
-
-/* Define to a replacement function name for fnmatch(). */
-/* #define fnmatch gnu_fnmatch */
-
-/* Define to `int' if  does not define. */
-/* #undef gid_t */
-
-/* A replacement for va_copy, if needed.  */
-#define gl_va_copy(a,b) ((a) = (b))
-
-/* Define to rpl_gmtime if the replacement function should be used. */
-/* #undef gmtime */
-
-/* Define to `__inline__' or `__inline' if that's what the C compiler
-   calls it, or to nothing if 'inline' is not supported under any name.  */
-#ifndef __cplusplus
-/* #undef inline */
-#endif
-
-/* Define to long or long long if  and  don't define. */
-/* #undef intmax_t */
-
-/* Define to rpl_localtime if the replacement function should be used. */
-/* #undef localtime */
-
-/* Define to rpl_malloc if the replacement function should be used. */
-/* #undef malloc */
-
-/* Define to a type if  does not define. */
-/* #undef mbstate_t */
-
-/* Define to rpl_mktime if the replacement function should be used. */
-#define mktime rpl_mktime
-
-/* Define to `long int' if  does not define. */
-/* #undef off_t */
-
-/* Define to a replacement function name for realpath(). */
-#define realpath rpl_realpath
-
-/* Define to equivalent of C99 restrict keyword, or to nothing if this is not
-   supported. Do not define if restrict is supported directly. */
-/* #undef restrict */
-
-/* Define to `unsigned int' if  does not define. */
-/* #undef size_t */
-
-/* Define as a signed type of the same size as size_t. */
-/* #undef ssize_t */
-
-/* Define to rpl_strnlen if the replacement function should be used. */
-#define strnlen rpl_strnlen
-
-/* Define to `int' if  doesn't define. */
-/* #undef uid_t */
-
-/* Define as a macro for copying va_list variables. */
-/* #undef va_copy */
diff --git a/gnu/usr.bin/cpio/doc/Makefile b/gnu/usr.bin/cpio/doc/Makefile
deleted file mode 100644
index 220de5fdf82..00000000000
--- a/gnu/usr.bin/cpio/doc/Makefile
+++ /dev/null
@@ -1,15 +0,0 @@
-# Note that this files is under a "BSD" copyright (c) by David O'Brien 1997, 
-# even though it may live in src/gnu/...
-
-# $FreeBSD$
-
-.PATH:	${.CURDIR}/../../../../contrib/cpio/doc
-
-INFO = cpio
-
-INFOSECTION= "Cpio Documentation"
-INFOENTRY_cpio="* CPIO: (cpio).                 Making tape (or disk) archives."
-
-SRCDIR= ${.CURDIR}/../../../../contrib/cpio/doc
-
-.include 
diff --git a/share/man/man5/src.conf.5 b/share/man/man5/src.conf.5
index 241d1018e5d..8720a7253d9 100644
--- a/share/man/man5/src.conf.5
+++ b/share/man/man5/src.conf.5
@@ -1,7 +1,7 @@
 .\" DO NOT EDIT-- this file is automatically generated.
 .\" from FreeBSD: head/tools/build/options/makeman 188848 2009-02-20 11:09:55Z mtm
 .\" $FreeBSD$
-.Dd January 16, 2010
+.Dd March 26, 2010
 .Dt SRC.CONF 5
 .Os
 .Sh NAME
@@ -339,13 +339,6 @@ When set, it also enforces the following options:
 .It
 .Va WITHOUT_GNU_SUPPORT
 .El
-.It Va WITH_GNU_CPIO
-.\" from FreeBSD: head/tools/build/options/WITH_GNU_CPIO 179813 2008-06-16 05:48:15Z dougb
-Set to build GNU cpio as a part of the base system,
-and symlink
-.Pa /usr/bin/cpio
-to this version.
-(This will override the symlink to the BSD version.)
 .It Va WITHOUT_GNU_GREP
 .\" from FreeBSD: head/tools/build/options/WITHOUT_GNU_GREP 179813 2008-06-16 05:48:15Z dougb
 Set to not build GNU grep as a part of the base system.
diff --git a/share/mk/bsd.own.mk b/share/mk/bsd.own.mk
index 84ae433b16b..777ff3634a7 100644
--- a/share/mk/bsd.own.mk
+++ b/share/mk/bsd.own.mk
@@ -407,7 +407,6 @@ MK_${var}:=	yes
     BIND_LIBS \
     BIND_SIGCHASE \
     BIND_XML \
-    GNU_CPIO \
     HESIOD \
     IDEA
 .if defined(WITH_${var}) && defined(WITHOUT_${var})
diff --git a/tools/build/mk/OptionalObsoleteFiles.inc b/tools/build/mk/OptionalObsoleteFiles.inc
index dd5497e01c3..78d32d7fffc 100644
--- a/tools/build/mk/OptionalObsoleteFiles.inc
+++ b/tools/build/mk/OptionalObsoleteFiles.inc
@@ -776,12 +776,6 @@ OLD_FILES+=usr/share/man/man1/gdbserver.1.gz
 OLD_FILES+=usr/share/man/man1/kgdb.1.gz
 .endif
 
-.if ${MK_GNU_CPIO} == no
-OLD_FILES+=usr/bin/gcpio
-OLD_FILES+=usr/share/info/cpio.info.gz
-OLD_FILES+=usr/share/man/man1/gcpio.1.gz
-.endif
-
 .if ${MK_GPIB} == no
 OLD_FILES+=usr/include/dev/ieee488/ibfoo_int.h
 OLD_FILES+=usr/include/dev/ieee488/ugpib.h
diff --git a/tools/build/options/WITH_GNU_CPIO b/tools/build/options/WITH_GNU_CPIO
deleted file mode 100644
index b4e756ae18b..00000000000
--- a/tools/build/options/WITH_GNU_CPIO
+++ /dev/null
@@ -1,6 +0,0 @@
-.\" $FreeBSD$
-Set to build GNU cpio as a part of the base system,
-and symlink
-.Pa /usr/bin/cpio
-to this version.
-(This will override the symlink to the BSD version.)
diff --git a/usr.bin/cpio/Makefile b/usr.bin/cpio/Makefile
index bfcbe973429..499b173f64d 100644
--- a/usr.bin/cpio/Makefile
+++ b/usr.bin/cpio/Makefile
@@ -19,10 +19,8 @@ DPADD+=	${LIBCRYPTO}
 LDADD+= -lcrypto
 .endif
 
-.if ${MK_GNU_CPIO} != "yes"
 SYMLINKS=bsdcpio ${BINDIR}/cpio
 MLINKS= bsdcpio.1 cpio.1
-.endif
 
 .PHONY: check test
 

From c0873717d4a0563197da4134df21bb27083e79c0 Mon Sep 17 00:00:00 2001
From: Rui Paulo 
Date: Fri, 26 Mar 2010 18:49:43 +0000
Subject: [PATCH 091/119] Pass the correct pointer to fled_cb().

---
 sys/arm/xscale/ixp425/cambria_fled.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/arm/xscale/ixp425/cambria_fled.c b/sys/arm/xscale/ixp425/cambria_fled.c
index 7f678c89896..c2f214d9837 100644
--- a/sys/arm/xscale/ixp425/cambria_fled.c
+++ b/sys/arm/xscale/ixp425/cambria_fled.c
@@ -74,7 +74,7 @@ fled_attach(device_t dev)
 
 	sc->sc_led = led_create(fled_cb, dev, "front");
 
-	fled_cb(sc, 1);		/* Turn on LED */
+	fled_cb(dev, 1);		/* Turn on LED */
 
 	return 0;
 }

From 10da4aa60181a9f02db09d0b02ca2dc4528f0fd1 Mon Sep 17 00:00:00 2001
From: Marcel Moolenaar 
Date: Fri, 26 Mar 2010 19:40:53 +0000
Subject: [PATCH 092/119] Handle cross-builds for gdbserver.

---
 gnu/usr.bin/gdb/Makefile | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gnu/usr.bin/gdb/Makefile b/gnu/usr.bin/gdb/Makefile
index 81a1d6c17cc..b4ec8230d48 100644
--- a/gnu/usr.bin/gdb/Makefile
+++ b/gnu/usr.bin/gdb/Makefile
@@ -2,7 +2,9 @@
 
 SUBDIR=	doc libgdb gdb gdbtui kgdb
 
-.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "arm" || ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "powerpc"
+TARGET_ARCH?= ${MACHINE_ARCH}
+.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "arm" || \
+    ${TARGET_ARCH} == "i386" || ${TARGET_ARCH} == "powerpc"
 SUBDIR+=gdbserver
 .endif
 

From 2a4510e122dc80d80599cc6d02ac4843f22c3c13 Mon Sep 17 00:00:00 2001
From: Marcel Moolenaar 
Date: Fri, 26 Mar 2010 19:41:40 +0000
Subject: [PATCH 093/119] Allow building a cross-kgdb for ia64.

---
 gnu/usr.bin/gdb/Makefile.inc     | 2 +-
 gnu/usr.bin/gdb/kgdb/trgt_ia64.c | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/gnu/usr.bin/gdb/Makefile.inc b/gnu/usr.bin/gdb/Makefile.inc
index abb5296dd05..0bd4ec48404 100644
--- a/gnu/usr.bin/gdb/Makefile.inc
+++ b/gnu/usr.bin/gdb/Makefile.inc
@@ -41,7 +41,7 @@ CFLAGS+= -I${CNTRB_BU}/bfd
 GENSRCS+= nm.h tm.h
 
 .if defined(GDB_CROSS_DEBUGGER)
-CFLAGS+= -DCROSS_DEBUGGER
+CFLAGS+= -DCROSS_DEBUGGER -I${BMAKE_ROOT}/../..
 GDB_SUFFIX= -${TARGET_ARCH}
 NO_MAN=
 .endif
diff --git a/gnu/usr.bin/gdb/kgdb/trgt_ia64.c b/gnu/usr.bin/gdb/kgdb/trgt_ia64.c
index 4d5cea6cebb..4efa6eb5f6c 100644
--- a/gnu/usr.bin/gdb/kgdb/trgt_ia64.c
+++ b/gnu/usr.bin/gdb/kgdb/trgt_ia64.c
@@ -28,9 +28,16 @@
 __FBSDID("$FreeBSD$");
 
 #include 
+#ifdef CROSS_DEBUGGER
+#include 
+#include 
+#include 
+#include 
+#else
 #include 
 #include 
 #include 
+#endif
 #include 
 #include 
 #include 

From 739fd8c5335d98d7c473d3fbdff03bf8d9807a85 Mon Sep 17 00:00:00 2001
From: Matt Jacob 
Date: Fri, 26 Mar 2010 20:22:18 +0000
Subject: [PATCH 094/119] D'oh- isp_handle_index' logic was reversed (not used
 in FreeBSD).

MFC after:	1 week
---
 sys/dev/isp/isp_library.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/dev/isp/isp_library.c b/sys/dev/isp/isp_library.c
index 43c161d2782..020193394d9 100644
--- a/sys/dev/isp/isp_library.c
+++ b/sys/dev/isp/isp_library.c
@@ -294,10 +294,10 @@ uint32_t
 isp_handle_index(ispsoftc_t *isp, uint32_t handle)
 {
 	if (!ISP_VALID_HANDLE(isp, handle)) {
-		return (handle & ISP_HANDLE_CMD_MASK);
-	} else {
 		isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle);
 		return (ISP_BAD_HANDLE_INDEX);
+	} else {
+		return (handle & ISP_HANDLE_CMD_MASK);
 	}
 }
 

From 1764e57174705ac12de7a47b55a99706a4a7b999 Mon Sep 17 00:00:00 2001
From: Marcel Moolenaar 
Date: Fri, 26 Mar 2010 21:22:02 +0000
Subject: [PATCH 095/119] Rename disable_intr() to ia64_disable_intr() and
 rename enable_intr() to ia64_enable_intr(). This reduces confusion with
 intr_disable() and intr_restore().

Have configure_final() call ia64_finalize_intr() instead of enable_intr()
in preparation of adding support for binding interrupts to all CPUs.
---
 sys/ia64/ia64/autoconf.c          | 19 +++++--------------
 sys/ia64/ia64/interrupt.c         | 11 +++++++++--
 sys/ia64/ia64/mp_machdep.c        |  2 +-
 sys/ia64/ia64/trap.c              |  6 +++---
 sys/ia64/include/acpica_machdep.h |  4 ++--
 sys/ia64/include/cpufunc.h        |  9 +++++----
 sys/ia64/include/intr.h           |  1 +
 7 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/sys/ia64/ia64/autoconf.c b/sys/ia64/ia64/autoconf.c
index 5a380516320..acac159df7e 100644
--- a/sys/ia64/ia64/autoconf.c
+++ b/sys/ia64/ia64/autoconf.c
@@ -39,15 +39,9 @@
 #include 
 #include 
 
-#include 
 #include 
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
+#include 
+#include 
 
 static void	configure_first(void *);
 static void	configure(void *);
@@ -97,12 +91,9 @@ static void
 configure_final(void *dummy)
 {
 
-	/*
-	 * Now we're ready to handle (pending) interrupts.
-	 * XXX this is slightly misplaced.
-	 */
-	enable_intr();
-
 	cninit_finish();
+
+	ia64_finalize_intr();
+
 	cold = 0;
 }
diff --git a/sys/ia64/ia64/interrupt.c b/sys/ia64/ia64/interrupt.c
index 3376111fd16..82ac35fb43a 100644
--- a/sys/ia64/ia64/interrupt.c
+++ b/sys/ia64/ia64/interrupt.c
@@ -280,6 +280,13 @@ ia64_teardown_intr(void *cookie)
 	return (intr_event_remove_handler(cookie));
 }
 
+void
+ia64_finalize_intr(void)
+{
+
+	ia64_enable_intr();
+}
+
 /*
  * Interrupt handlers.
  */
@@ -318,9 +325,9 @@ ia64_handle_intr(struct trapframe *tf)
  out:
 	if (TRAPF_USERMODE(tf)) {
 		while (td->td_flags & (TDF_ASTPENDING|TDF_NEEDRESCHED)) {
-			enable_intr();
+			ia64_enable_intr();
 			ast(tf);
-			disable_intr();
+			ia64_disable_intr();
 		}
 	}
 }
diff --git a/sys/ia64/ia64/mp_machdep.c b/sys/ia64/ia64/mp_machdep.c
index f8d9f6f0c1f..60ad43a1b29 100644
--- a/sys/ia64/ia64/mp_machdep.c
+++ b/sys/ia64/ia64/mp_machdep.c
@@ -210,7 +210,7 @@ ia64_ap_startup(void)
 	ia64_set_itv(0x10000);
 	ia64_set_tpr(0);
 	ia64_srlz_d();
-	enable_intr();
+	ia64_enable_intr();
 
 	sched_throw(NULL);
 	/* NOTREACHED */
diff --git a/sys/ia64/ia64/trap.c b/sys/ia64/ia64/trap.c
index 62644622d79..f539097c265 100644
--- a/sys/ia64/ia64/trap.c
+++ b/sys/ia64/ia64/trap.c
@@ -334,11 +334,11 @@ int
 do_ast(struct trapframe *tf)
 {
 
-	disable_intr();
+	ia64_disable_intr();
 	while (curthread->td_flags & (TDF_ASTPENDING|TDF_NEEDRESCHED)) {
-		enable_intr();
+		ia64_enable_intr();
 		ast(tf);
-		disable_intr();
+		ia64_disable_intr();
 	}
 	/*
 	 * Keep interrupts disabled. We return r10 as a favor to the EPC
diff --git a/sys/ia64/include/acpica_machdep.h b/sys/ia64/include/acpica_machdep.h
index 26191c0a527..38efffdfd79 100644
--- a/sys/ia64/include/acpica_machdep.h
+++ b/sys/ia64/include/acpica_machdep.h
@@ -56,8 +56,8 @@
 
 #define	ACPI_ASM_MACROS
 #define	BREAKPOINT3
-#define	ACPI_DISABLE_IRQS() disable_intr()
-#define	ACPI_ENABLE_IRQS()  enable_intr()
+#define	ACPI_DISABLE_IRQS()	ia64_disable_intr()
+#define	ACPI_ENABLE_IRQS()	ia64_enable_intr()
 
 #define	ACPI_FLUSH_CPU_CACHE()	/* XXX ia64_fc()? */
 
diff --git a/sys/ia64/include/cpufunc.h b/sys/ia64/include/cpufunc.h
index 9ae06a2253d..925d4bafa4a 100644
--- a/sys/ia64/include/cpufunc.h
+++ b/sys/ia64/include/cpufunc.h
@@ -56,13 +56,13 @@ breakpoint(void)
 
 
 static __inline void
-disable_intr(void)
+ia64_disable_intr(void)
 {
 	__asm __volatile ("rsm psr.i");
 }
 
 static __inline void
-enable_intr(void)
+ia64_enable_intr(void)
 {
 	__asm __volatile ("ssm psr.i;; srlz.d");
 }
@@ -71,8 +71,9 @@ static __inline register_t
 intr_disable(void)
 {
 	register_t psr;
+
 	__asm __volatile ("mov %0=psr;;" : "=r"(psr));
-	disable_intr();
+	ia64_disable_intr();
 	return ((psr & IA64_PSR_I) ? 1 : 0);
 }
 
@@ -80,7 +81,7 @@ static __inline void
 intr_restore(register_t ie)
 {
 	if (ie)
-		enable_intr();
+		ia64_enable_intr();
 }
 
 #endif /* __GNUCLIKE_ASM */
diff --git a/sys/ia64/include/intr.h b/sys/ia64/include/intr.h
index b26190c52fd..2ea858c345f 100644
--- a/sys/ia64/include/intr.h
+++ b/sys/ia64/include/intr.h
@@ -65,6 +65,7 @@ typedef u_int (ia64_ihtype)(struct thread *, u_int, struct trapframe *);
 
 extern struct ia64_pib *ia64_pib;
 
+void	ia64_finalize_intr(void);
 void	ia64_handle_intr(struct trapframe *);
 int	ia64_setup_intr(const char *, int, driver_filter_t, driver_intr_t,
 	    void *, enum intr_type, void **);

From c00148556a4cbd3d8fd249c1d32968d95dcdfe29 Mon Sep 17 00:00:00 2001
From: Jack F Vogel 
Date: Sat, 27 Mar 2010 00:21:40 +0000
Subject: [PATCH 096/119] Update the driver to Intel version 2.1.6 	- add
 some new hardware support for 82599 	- Big change to interrupt
 architecture, it now 	  uses a queue which contains an RX/TX pair as 	  the
 recipient of the interrupt. This will reduce 	  overall system
 interrupts/msix usage. 	- Improved RX mbuf handling: the old get_buf
 routine 	  is no longer synchronized with rxeof, this allows 	  the
 elimination of packet discards due to mbuf 	  allocation failure. 	- Much
 simplified and improved AIM code, it now 	  happens in the queue
 interrupt context and takes 	  into account both the traffic on the RX AND
 TX 	  side. 	- variety of small tweaks, like ring size, that have 
   been seen as performance improvements. 	- Thanks to those that
 provided feedback or suggested 	  changes, I hope I've caught all of
 them.

---
 sys/dev/ixgbe/LICENSE        |    2 +-
 sys/dev/ixgbe/ixgbe.c        | 1438 +++++++++++++---------------------
 sys/dev/ixgbe/ixgbe.h        |  162 ++--
 sys/dev/ixgbe/ixgbe_82598.c  |   84 +-
 sys/dev/ixgbe/ixgbe_82599.c  |  158 +++-
 sys/dev/ixgbe/ixgbe_api.c    |   17 +-
 sys/dev/ixgbe/ixgbe_api.h    |    4 +-
 sys/dev/ixgbe/ixgbe_common.c |  159 +++-
 sys/dev/ixgbe/ixgbe_phy.c    |  134 +++-
 sys/dev/ixgbe/ixgbe_phy.h    |   10 +-
 sys/dev/ixgbe/ixgbe_type.h   |   80 +-
 sys/modules/ixgbe/Makefile   |    2 +-
 12 files changed, 1157 insertions(+), 1093 deletions(-)

diff --git a/sys/dev/ixgbe/LICENSE b/sys/dev/ixgbe/LICENSE
index 39264e087be..0cf44c8581e 100644
--- a/sys/dev/ixgbe/LICENSE
+++ b/sys/dev/ixgbe/LICENSE
@@ -1,6 +1,6 @@
 /******************************************************************************
 
-  Copyright (c) 2001-2009, Intel Corporation 
+  Copyright (c) 2001-2010, Intel Corporation 
   All rights reserved.
   
   Redistribution and use in source and binary forms, with or without 
diff --git a/sys/dev/ixgbe/ixgbe.c b/sys/dev/ixgbe/ixgbe.c
index f66443ae77f..2c303d95ade 100644
--- a/sys/dev/ixgbe/ixgbe.c
+++ b/sys/dev/ixgbe/ixgbe.c
@@ -1,6 +1,6 @@
 /******************************************************************************
 
-  Copyright (c) 2001-2009, Intel Corporation 
+  Copyright (c) 2001-2010, Intel Corporation 
   All rights reserved.
   
   Redistribution and use in source and binary forms, with or without 
@@ -46,7 +46,7 @@ int             ixgbe_display_debug_stats = 0;
 /*********************************************************************
  *  Driver version
  *********************************************************************/
-char ixgbe_driver_version[] = "2.0.7";
+char ixgbe_driver_version[] = "2.1.6";
 
 /*********************************************************************
  *  PCI Device ID Table
@@ -76,6 +76,7 @@ static ixgbe_vendor_info_t ixgbe_vendor_info_array[] =
 	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP, 0, 0, 0},
 	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_XAUI_LOM, 0, 0, 0},
 	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_CX4, 0, 0, 0},
+	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_T3_LOM, 0, 0, 0},
 	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_COMBO_BACKPLANE, 0, 0, 0},
 	/* required last entry */
 	{0, 0, 0, 0, 0}
@@ -136,12 +137,11 @@ static void     ixgbe_free_receive_structures(struct adapter *);
 static void     ixgbe_free_receive_buffers(struct rx_ring *);
 static void	ixgbe_setup_hw_rsc(struct rx_ring *);
 
-static void	ixgbe_init_moderation(struct adapter *);
 static void     ixgbe_enable_intr(struct adapter *);
 static void     ixgbe_disable_intr(struct adapter *);
 static void     ixgbe_update_stats_counters(struct adapter *);
 static bool	ixgbe_txeof(struct tx_ring *);
-static bool	ixgbe_rxeof(struct rx_ring *, int);
+static bool	ixgbe_rxeof(struct ix_queue *, int);
 static void	ixgbe_rx_checksum(u32, struct mbuf *);
 static void     ixgbe_set_promisc(struct adapter *);
 static void     ixgbe_disable_promisc(struct adapter *);
@@ -149,7 +149,7 @@ static void     ixgbe_set_multi(struct adapter *);
 static void     ixgbe_print_hw_stats(struct adapter *);
 static void	ixgbe_print_debug_info(struct adapter *);
 static void     ixgbe_update_link_status(struct adapter *);
-static int	ixgbe_get_buf(struct rx_ring *, int, int);
+static void	ixgbe_refresh_mbufs(struct rx_ring *, int);
 static int      ixgbe_xmit(struct tx_ring *, struct mbuf **);
 static int      ixgbe_sysctl_stats(SYSCTL_HANDLER_ARGS);
 static int	ixgbe_sysctl_debug(SYSCTL_HANDLER_ARGS);
@@ -169,7 +169,9 @@ static void	ixgbe_setup_vlan_hw_support(struct adapter *);
 static void	ixgbe_register_vlan(void *, struct ifnet *, u16);
 static void	ixgbe_unregister_vlan(void *, struct ifnet *, u16);
 
-static void	ixgbe_update_aim(struct rx_ring *);
+static __inline void ixgbe_rx_discard(struct rx_ring *, int);
+static __inline void ixgbe_rx_input(struct rx_ring *, struct ifnet *,
+		    struct mbuf *, u32);
 
 /* Support for pluggable optic modules */
 static bool	ixgbe_sfp_probe(struct adapter *);
@@ -178,13 +180,11 @@ static bool	ixgbe_sfp_probe(struct adapter *);
 static void	ixgbe_legacy_irq(void *);
 
 /* The MSI/X Interrupt handlers */
-static void	ixgbe_msix_tx(void *);
-static void	ixgbe_msix_rx(void *);
+static void	ixgbe_msix_que(void *);
 static void	ixgbe_msix_link(void *);
 
 /* Deferred interrupt tasklets */
-static void	ixgbe_handle_tx(void *, int);
-static void	ixgbe_handle_rx(void *, int);
+static void	ixgbe_handle_que(void *, int);
 static void	ixgbe_handle_link(void *, int);
 static void	ixgbe_handle_msf(void *, int);
 static void	ixgbe_handle_mod(void *, int);
@@ -222,23 +222,16 @@ MODULE_DEPEND(ixgbe, ether, 1, 1, 1);
 */
 
 /*
-** These  parameters are used in Adaptive 
-** Interrupt Moderation. The value is set
-** into EITR and controls the interrupt
-** frequency. They can be modified but 
-** be careful in tuning them.
+** AIM: Adaptive Interrupt Moderation
+** which means that the interrupt rate
+** is varied over time based on the
+** traffic for that interrupt vector
 */
 static int ixgbe_enable_aim = TRUE;
 TUNABLE_INT("hw.ixgbe.enable_aim", &ixgbe_enable_aim);
-static int ixgbe_low_latency = IXGBE_LOW_LATENCY;
-TUNABLE_INT("hw.ixgbe.low_latency", &ixgbe_low_latency);
-static int ixgbe_ave_latency = IXGBE_AVE_LATENCY;
-TUNABLE_INT("hw.ixgbe.ave_latency", &ixgbe_ave_latency);
-static int ixgbe_bulk_latency = IXGBE_BULK_LATENCY;
-TUNABLE_INT("hw.ixgbe.bulk_latency", &ixgbe_bulk_latency);
 
 /* How many packets rxeof tries to clean at a time */
-static int ixgbe_rx_process_limit = 100;
+static int ixgbe_rx_process_limit = 128;
 TUNABLE_INT("hw.ixgbe.rx_process_limit", &ixgbe_rx_process_limit);
 
 /* Flow control setting, default to full */
@@ -271,20 +264,24 @@ static bool ixgbe_header_split = TRUE;
 TUNABLE_INT("hw.ixgbe.hdr_split", &ixgbe_header_split);
 
 /*
- * Number of Queues, should normally
- * be left at 0, it then autoconfigures to
- * the number of cpus. Each queue is a pair
- * of RX and TX rings with a dedicated interrupt
+ * Number of Queues, can be set to 0,
+ * it then autoconfigures based on the
+ * number of cpus. Each queue is a pair
+ * of RX and TX rings with a msix vector
  */
 static int ixgbe_num_queues = 0;
 TUNABLE_INT("hw.ixgbe.num_queues", &ixgbe_num_queues);
 
-/* Number of TX descriptors per ring */
-static int ixgbe_txd = DEFAULT_TXD;
+/*
+** Number of TX descriptors per ring,
+** setting higher than RX as this seems
+** the better performing choice.
+*/
+static int ixgbe_txd = PERFORM_TXD;
 TUNABLE_INT("hw.ixgbe.txd", &ixgbe_txd);
 
 /* Number of RX descriptors per ring */
-static int ixgbe_rxd = DEFAULT_RXD;
+static int ixgbe_rxd = PERFORM_RXD;
 TUNABLE_INT("hw.ixgbe.rxd", &ixgbe_rxd);
 
 /* Keep running tab on them for sanity check */
@@ -420,9 +417,11 @@ ixgbe_attach(device_t dev)
 		case IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM :
 		case IXGBE_DEV_ID_82598EB_SFP_LOM :
 		case IXGBE_DEV_ID_82598AT :
-		case IXGBE_DEV_ID_82598AT2 :
 			adapter->optics = IFM_10G_SR;
 			break;
+		case IXGBE_DEV_ID_82598AT2 :
+			adapter->optics = IFM_10G_T;
+			break;
 		case IXGBE_DEV_ID_82598EB_XF_LR :
 			adapter->optics = IFM_10G_LR;
 			break;
@@ -439,6 +438,10 @@ ixgbe_attach(device_t dev)
 		case IXGBE_DEV_ID_82599_XAUI_LOM :
 		case IXGBE_DEV_ID_82599_COMBO_BACKPLANE :
 			ixgbe_num_segs = IXGBE_82599_SCATTER;
+			break;
+		case IXGBE_DEV_ID_82599_T3_LOM:
+			ixgbe_num_segs = IXGBE_82599_SCATTER;
+			adapter->optics = IFM_10G_T;
 		default:
 			break;
 	}
@@ -464,21 +467,6 @@ ixgbe_attach(device_t dev)
 			OID_AUTO, "enable_aim", CTLTYPE_INT|CTLFLAG_RW,
 			&ixgbe_enable_aim, 1, "Interrupt Moderation");
 
-        SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
-			SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
-			OID_AUTO, "low_latency", CTLTYPE_INT|CTLFLAG_RW,
-			&ixgbe_low_latency, 1, "Low Latency");
-
-        SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
-			SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
-			OID_AUTO, "ave_latency", CTLTYPE_INT|CTLFLAG_RW,
-			&ixgbe_ave_latency, 1, "Average Latency");
-
-        SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
-			SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
-			OID_AUTO, "bulk_latency", CTLTYPE_INT|CTLFLAG_RW,
-			&ixgbe_bulk_latency, 1, "Bulk Latency");
-
 	/* Set up the timer callout */
 	callout_init_mtx(&adapter->timer, &adapter->core_mtx, 0);
 
@@ -592,22 +580,6 @@ ixgbe_attach(device_t dev)
 	/* Setup OS specific network interface */
 	ixgbe_setup_interface(dev, adapter);
 
-#ifdef IXGBE_IEEE1588
-	/*
-	** Setup the timer: IEEE 1588 support
-	*/
-	adapter->cycles.read = ixgbe_read_clock;
-	adapter->cycles.mask = (u64)-1;
-	adapter->cycles.mult = 1;
-	adapter->cycles.shift = IXGBE_TSYNC_SHIFT;
-	IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, (1<<24) |
-	    IXGBE_TSYNC_CYCLE_TIME * IXGBE_TSYNC_SHIFT);
-	IXGBE_WRITE_REG(hw, IXGBE_SYSTIML, 0x00000000);
-	IXGBE_WRITE_REG(hw, IXGBE_SYSTIMH, 0xFF800000);
-
-        // JFV - this is not complete yet
-#endif
-
 	/* Sysctl for limiting the amount of work done in the taskqueue */
 	ixgbe_add_rx_process_limit(adapter, "rx_processing_limit",
 	    "max number of rx packets to process", &adapter->rx_process_limit,
@@ -632,12 +604,13 @@ ixgbe_attach(device_t dev)
 	    (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
 	    ("Unknown"));
 
-	if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
+	if ((hw->bus.width <= ixgbe_bus_width_pcie_x4) &&
+	    (hw->bus.speed == ixgbe_bus_speed_2500)) {
 		device_printf(dev, "PCI-Express bandwidth available"
 		    " for this card\n     is not sufficient for"
 		    " optimal performance.\n");
 		device_printf(dev, "For optimal performance a x8 "
-		    "PCI-Express slot is required.\n");
+		    "PCIE, or x4 PCIE 2 slot is required.\n");
         }
 
 	/* let hardware know driver is loaded */
@@ -670,8 +643,7 @@ static int
 ixgbe_detach(device_t dev)
 {
 	struct adapter *adapter = device_get_softc(dev);
-	struct tx_ring *txr = adapter->tx_rings;
-	struct rx_ring *rxr = adapter->rx_rings;
+	struct ix_queue *que = adapter->queues;
 	u32	ctrl_ext;
 
 	INIT_DEBUGOUT("ixgbe_detach: begin");
@@ -686,17 +658,10 @@ ixgbe_detach(device_t dev)
 	ixgbe_stop(adapter);
 	IXGBE_CORE_UNLOCK(adapter);
 
-	for (int i = 0; i < adapter->num_queues; i++, txr++) {
-		if (txr->tq) {
-			taskqueue_drain(txr->tq, &txr->tx_task);
-			taskqueue_free(txr->tq);
-		}
-	}
-
-	for (int i = 0; i < adapter->num_queues; i++, rxr++) {
-		if (rxr->tq) {
-			taskqueue_drain(rxr->tq, &rxr->rx_task);
-			taskqueue_free(rxr->tq);
+	for (int i = 0; i < adapter->num_queues; i++, que++) {
+		if (que->tq) {
+			taskqueue_drain(que->tq, &que->que_task);
+			taskqueue_free(que->tq);
 		}
 	}
 
@@ -833,6 +798,9 @@ ixgbe_mq_start(struct ifnet *ifp, struct mbuf *m)
 	/* Which queue to use */
 	if ((m->m_flags & M_FLOWID) != 0)
 		i = m->m_pkthdr.flowid % adapter->num_queues;
+	else	/* use the cpu we're on */
+		i = curcpu % adapter->num_queues;
+
 	txr = &adapter->tx_rings[i];
 
 	if (IXGBE_TX_TRYLOCK(txr)) {
@@ -849,59 +817,43 @@ ixgbe_mq_start_locked(struct ifnet *ifp, struct tx_ring *txr, struct mbuf *m)
 {
 	struct adapter  *adapter = txr->adapter;
         struct mbuf     *next;
-        int             err = 0;
+        int             enqueued, err = 0;
 
-	if (((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) ||
-	    (!adapter->link_active)) {
-		err = drbr_enqueue(ifp, txr->br, m);
+	if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) !=
+	    IFF_DRV_RUNNING || adapter->link_active == 0) {
+		if (m != NULL)
+			err = drbr_enqueue(ifp, txr->br, m);
 		return (err);
 	}
 
-	if (m == NULL) /* Called by tasklet */
-		goto process;
-
-	/* If nothing queued go right to xmit */
-	if (!drbr_needs_enqueue(ifp, txr->br)) {
-		if ((err = ixgbe_xmit(txr, &m)) != 0) {
-			if (m != NULL)
-				err = drbr_enqueue(ifp, txr->br, m);
-			return (err);
-		} else {
-			/* Success, update stats */
-			drbr_stats_update(ifp, m->m_pkthdr.len, m->m_flags);
-			/* Send a copy of the frame to the BPF listener */
-			ETHER_BPF_MTAP(ifp, m);
-			/* Set the watchdog */
-			txr->watchdog_check = TRUE;
-                }
-
-        } else if ((err = drbr_enqueue(ifp, txr->br, m)) != 0)
-		return (err);
-
-process:
-	if (drbr_empty(ifp, txr->br))
-		return (err);
+	enqueued = 0;
+	if (m == NULL)
+		next = drbr_dequeue(ifp, txr->br);
+	else
+		next = m;
 
 	/* Process the queue */
-	while (TRUE) {
-		if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
-			break;
-		next = drbr_dequeue(ifp, txr->br);
-		if (next == NULL)
-			break;
+	while (next != NULL) {
 		if ((err = ixgbe_xmit(txr, &next)) != 0) {
 			if (next != NULL)
 				err = drbr_enqueue(ifp, txr->br, next);
 			break;
 		}
+		enqueued++;
 		drbr_stats_update(ifp, next->m_pkthdr.len, next->m_flags);
+		/* Send a copy of the frame to the BPF listener */
 		ETHER_BPF_MTAP(ifp, next);
-		/* Set the watchdog */
-		txr->watchdog_check = TRUE;
+		if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
+			break;
+		if (txr->tx_avail <= IXGBE_TX_OP_THRESHOLD) {
+			ifp->if_drv_flags |= IFF_DRV_OACTIVE;
+			break;
+		}
+		next = drbr_dequeue(ifp, txr->br);
 	}
-		
-	if (txr->tx_avail <= IXGBE_TX_OP_THRESHOLD)
-		ifp->if_drv_flags |= IFF_DRV_OACTIVE;
+
+	if (enqueued > 0) 
+		txr->watchdog_check = TRUE;
 
 	return (err);
 }
@@ -938,8 +890,8 @@ ixgbe_qflush(struct ifnet *ifp)
 static int
 ixgbe_ioctl(struct ifnet * ifp, u_long command, caddr_t data)
 {
-	struct adapter *adapter = ifp->if_softc;
-	struct ifreq   *ifr = (struct ifreq *) data;
+	struct adapter	*adapter = ifp->if_softc;
+	struct ifreq	*ifr = (struct ifreq *) data;
 	int             error = 0;
 
 	switch (command) {
@@ -999,8 +951,7 @@ ixgbe_ioctl(struct ifnet * ifp, u_long command, caddr_t data)
 			ifp->if_capenable ^= IFCAP_HWCSUM;
 		if (mask & IFCAP_TSO4)
 			ifp->if_capenable ^= IFCAP_TSO4;
-		/* Only allow changing when using header split */
-		if ((mask & IFCAP_LRO) && (ixgbe_header_split))
+		if (mask & IFCAP_LRO)
 			ifp->if_capenable ^= IFCAP_LRO;
 		if (mask & IFCAP_VLAN_HWTAGGING)
 			ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
@@ -1010,15 +961,6 @@ ixgbe_ioctl(struct ifnet * ifp, u_long command, caddr_t data)
 		break;
 	}
 
-#ifdef IXGBE_IEEE1588
-	/*
-	** IOCTL support for Precision Time (IEEE 1588) Support
-	*/
-	case SIOCSHWTSTAMP:
-		error = ixgbe_hwtstamp_ioctl(adapter, ifp);
-		break;
-#endif
-
 	default:
 		IOCTL_DEBUGOUT1("ioctl: UNKNOWN (0x%X)\n", (int)command);
 		error = ether_ioctl(ifp, command, data);
@@ -1045,15 +987,20 @@ ixgbe_init_locked(struct adapter *adapter)
 {
 	struct ifnet   *ifp = adapter->ifp;
 	device_t 	dev = adapter->dev;
-	struct ixgbe_hw *hw;
+	struct ixgbe_hw *hw = &adapter->hw;
 	u32		k, txdctl, mhadd, gpie;
 	u32		rxdctl, rxctrl;
 	int		err;
 
-	INIT_DEBUGOUT("ixgbe_init: begin");
-
-	hw = &adapter->hw;
 	mtx_assert(&adapter->core_mtx, MA_OWNED);
+	INIT_DEBUGOUT("ixgbe_init: begin");
+	ixgbe_reset_hw(hw);
+	hw->adapter_stopped = FALSE;
+	ixgbe_stop_adapter(hw);
+        callout_stop(&adapter->timer);
+
+        /* reprogram the RAR[0] in case user changed it. */
+        ixgbe_set_rar(hw, 0, adapter->hw.mac.addr, 0, IXGBE_RAH_AV);
 
 	/* Get the latest mac address, User can use a LAA */
 	bcopy(IF_LLADDR(adapter->ifp), hw->mac.addr,
@@ -1061,9 +1008,6 @@ ixgbe_init_locked(struct adapter *adapter)
 	ixgbe_set_rar(hw, 0, hw->mac.addr, 0, 1);
 	hw->addr_ctrl.rar_used_count = 1;
 
-	/* Do a warm reset */
-	ixgbe_reset_hw(hw);
-
 	/* Prepare transmit descriptors and buffers */
 	if (ixgbe_setup_transmit_structures(adapter)) {
 		device_printf(dev,"Could not setup transmit structures\n");
@@ -1071,6 +1015,7 @@ ixgbe_init_locked(struct adapter *adapter)
 		return;
 	}
 
+	ixgbe_init_hw(hw);
 	ixgbe_initialize_transmit_units(adapter);
 
 	/* Setup Multicast table */
@@ -1095,9 +1040,6 @@ ixgbe_init_locked(struct adapter *adapter)
 	/* Configure RX settings */
 	ixgbe_initialize_receive_units(adapter);
 
-	/* Configure Interrupt Moderation */
-	ixgbe_init_moderation(adapter);
-
 	gpie = IXGBE_READ_REG(&adapter->hw, IXGBE_GPIE);
 
 	if (hw->mac.type == ixgbe_mac_82599EB) {
@@ -1174,7 +1116,7 @@ ixgbe_init_locked(struct adapter *adapter)
 	if (hw->mac.type == ixgbe_mac_82598EB)
 		rxctrl |= IXGBE_RXCTRL_DMBYPS;
 	rxctrl |= IXGBE_RXCTRL_RXEN;
-	IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl);
+	ixgbe_enable_rx_dma(hw, rxctrl);
 
 	callout_reset(&adapter->timer, hz, ixgbe_local_timer, adapter);
 
@@ -1291,34 +1233,22 @@ ixgbe_rearm_queues(struct adapter *adapter, u64 queues)
 	}
 }
 
-static void
-ixgbe_handle_rx(void *context, int pending)
-{
-	struct rx_ring  *rxr = context;
-	struct adapter  *adapter = rxr->adapter;
-	u32		loop = MAX_LOOP;
-	bool		more;
-
-	do {
-		more = ixgbe_rxeof(rxr, -1);
-	} while (loop-- && more);
-        /* Reenable this interrupt */
-	ixgbe_enable_queue(adapter, rxr->msix);
-}
 
 static void
-ixgbe_handle_tx(void *context, int pending)
+ixgbe_handle_que(void *context, int pending)
 {
-	struct tx_ring  *txr = context;
-	struct adapter  *adapter = txr->adapter;
+	struct ix_queue *que = context;
+	struct adapter  *adapter = que->adapter;
+	struct tx_ring  *txr = que->txr;
 	struct ifnet    *ifp = adapter->ifp;
 	u32		loop = MAX_LOOP;
-	bool		more;
+	bool		more_rx, more_tx;
 
 	IXGBE_TX_LOCK(txr);
 	do {
-		more = ixgbe_txeof(txr);
-	} while (loop-- && more);
+		more_rx = ixgbe_rxeof(que, adapter->rx_process_limit);
+		more_tx = ixgbe_txeof(txr);
+	} while (loop-- && (more_rx || more_tx));
 
 	if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
 #if __FreeBSD_version >= 800000
@@ -1332,7 +1262,7 @@ ixgbe_handle_tx(void *context, int pending)
 
 	IXGBE_TX_UNLOCK(txr);
 	/* Reenable this interrupt */
-	ixgbe_enable_queue(adapter, txr->msix);
+	ixgbe_enable_queue(adapter, que->msix);
 }
 
 
@@ -1345,33 +1275,32 @@ ixgbe_handle_tx(void *context, int pending)
 static void
 ixgbe_legacy_irq(void *arg)
 {
-	struct adapter	*adapter = arg;
+	struct ix_queue *que = arg;
+	struct adapter	*adapter = que->adapter;
 	struct ixgbe_hw	*hw = &adapter->hw;
 	struct 		tx_ring *txr = adapter->tx_rings;
-	struct		rx_ring *rxr = adapter->rx_rings;
-	bool		more;
+	bool		more_tx, more_rx;
 	u32       	reg_eicr, loop = MAX_LOOP;
 
 
 	reg_eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
 
+	++que->irqs;
 	if (reg_eicr == 0) {
 		ixgbe_enable_intr(adapter);
 		return;
 	}
 
-	if (ixgbe_rxeof(rxr, adapter->rx_process_limit))
-		taskqueue_enqueue(rxr->tq, &rxr->rx_task);
+	more_rx = ixgbe_rxeof(que, adapter->rx_process_limit);
 
 	IXGBE_TX_LOCK(txr);
-	++txr->tx_irq;
 	do {
-		more = ixgbe_txeof(txr);
-	} while (loop-- && more);
+		more_tx = ixgbe_txeof(txr);
+	} while (loop-- && more_tx);
 	IXGBE_TX_UNLOCK(txr);
 
-	if (more)
-		taskqueue_enqueue(txr->tq, &txr->tx_task);
+	if (more_rx || more_tx)
+		taskqueue_enqueue(que->tq, &que->que_task);
 
 	/* Check for fan failure */
 	if ((hw->phy.media_type == ixgbe_media_type_copper) &&
@@ -1382,15 +1311,8 @@ ixgbe_legacy_irq(void *arg)
 	}
 
 	/* Link status change */
-	if (reg_eicr & IXGBE_EICR_LSC) {
-		ixgbe_check_link(&adapter->hw,
-		    &adapter->link_speed, &adapter->link_up, 0);
-        	ixgbe_update_link_status(adapter);
-	}
-
-	/* Update interrupt rate */
-	if (ixgbe_enable_aim == TRUE)
-		ixgbe_update_aim(rxr);
+	if (reg_eicr & IXGBE_EICR_LSC)
+		taskqueue_enqueue(adapter->tq, &adapter->link_task);
 
 	ixgbe_enable_intr(adapter);
 	return;
@@ -1399,55 +1321,85 @@ ixgbe_legacy_irq(void *arg)
 
 /*********************************************************************
  *
- *  MSI TX Interrupt Service routine
+ *  MSI Queue Interrupt Service routine
  *
  **********************************************************************/
 void
-ixgbe_msix_tx(void *arg)
+ixgbe_msix_que(void *arg)
 {
-	struct tx_ring	*txr = arg;
-	struct adapter  *adapter = txr->adapter;
-	bool		more;
+	struct ix_queue	*que = arg;
+	struct adapter  *adapter = que->adapter;
+	struct tx_ring	*txr = que->txr;
+	struct rx_ring	*rxr = que->rxr;
+	bool		more_tx, more_rx;
+	u32		newitr = 0;
 
-	ixgbe_disable_queue(adapter, txr->msix);
+	ixgbe_disable_queue(adapter, que->msix);
+	++que->irqs;
+
+	more_rx = ixgbe_rxeof(que, adapter->rx_process_limit);
 
 	IXGBE_TX_LOCK(txr);
-	++txr->tx_irq;
-	more = ixgbe_txeof(txr);
+	more_tx = ixgbe_txeof(txr);
 	IXGBE_TX_UNLOCK(txr);
-	if (more)
-		taskqueue_enqueue(txr->tq, &txr->tx_task);
-	else /* Reenable this interrupt */
-		ixgbe_enable_queue(adapter, txr->msix);
-	return;
-}
 
+	more_rx = ixgbe_rxeof(que, adapter->rx_process_limit);
 
-/*********************************************************************
- *
- *  MSIX RX Interrupt Service routine
- *
- **********************************************************************/
-static void
-ixgbe_msix_rx(void *arg)
-{
-	struct rx_ring	*rxr = arg;
-	struct adapter  *adapter = rxr->adapter;
-	bool		more;
+	/* Do AIM now? */
 
-	ixgbe_disable_queue(adapter, rxr->msix);
+	if (ixgbe_enable_aim == FALSE)
+		goto no_calc;
+	/*
+	** Do Adaptive Interrupt Moderation:
+        **  - Write out last calculated setting
+	**  - Calculate based on average size over
+	**    the last interval.
+	*/
+        if (que->eitr_setting)
+                IXGBE_WRITE_REG(&adapter->hw,
+                    IXGBE_EITR(que->msix), que->eitr_setting);
+ 
+        que->eitr_setting = 0;
 
-	++rxr->rx_irq;
-	more = ixgbe_rxeof(rxr, adapter->rx_process_limit);
+        /* Idle, do nothing */
+        if ((txr->bytes == 0) && (rxr->bytes == 0))
+                goto no_calc;
+                                
+	if ((txr->bytes) && (txr->packets))
+               	newitr = txr->bytes/txr->packets;
+	if ((rxr->bytes) && (rxr->packets))
+		newitr = max(newitr,
+		    (rxr->bytes / rxr->packets));
+	newitr += 24; /* account for hardware frame, crc */
 
-	/* Update interrupt rate */
-	if (ixgbe_enable_aim == TRUE)
-		ixgbe_update_aim(rxr);
+	/* set an upper boundary */
+	newitr = min(newitr, 3000);
 
-	if (more)
-		taskqueue_enqueue(rxr->tq, &rxr->rx_task);
+	/* Be nice to the mid range */
+	if ((newitr > 300) && (newitr < 1200))
+		newitr = (newitr / 3);
 	else
-		ixgbe_enable_queue(adapter, rxr->msix);
+		newitr = (newitr / 2);
+
+        if (adapter->hw.mac.type == ixgbe_mac_82598EB)
+                newitr |= newitr << 16;
+        else
+                newitr |= IXGBE_EITR_CNT_WDIS;
+                 
+        /* save for next interrupt */
+        que->eitr_setting = newitr;
+
+        /* Reset state */
+        txr->bytes = 0;
+        txr->packets = 0;
+        rxr->bytes = 0;
+        rxr->packets = 0;
+
+no_calc:
+	if (more_tx || more_rx)
+		taskqueue_enqueue(que->tq, &que->que_task);
+	else /* Reenable this interrupt */
+		ixgbe_enable_queue(adapter, que->msix);
 	return;
 }
 
@@ -1512,84 +1464,6 @@ ixgbe_msix_link(void *arg)
 	return;
 }
 
-/*
-** Routine to do adjust the RX EITR value based on traffic,
-** its a simple three state model, but seems to help.
-**
-** Note that the three EITR values are tuneable using
-** sysctl in real time. The feature can be effectively
-** nullified by setting them equal.
-*/
-#define BULK_THRESHOLD	10000
-#define AVE_THRESHOLD	1600
-
-static void
-ixgbe_update_aim(struct rx_ring *rxr)
-{
-	struct adapter  *adapter = rxr->adapter;
-	u32             olditr, newitr;
-
-	/* Update interrupt moderation based on traffic */
-	olditr = rxr->eitr_setting;
-	newitr = olditr;
-
-	/* Idle, don't change setting */
-	if (rxr->bytes == 0)   
-		return;
-                
-	if (olditr == ixgbe_low_latency) {
-		if (rxr->bytes > AVE_THRESHOLD)
-			newitr = ixgbe_ave_latency;
-	} else if (olditr == ixgbe_ave_latency) {
-		if (rxr->bytes < AVE_THRESHOLD)
-			newitr = ixgbe_low_latency;
-		else if (rxr->bytes > BULK_THRESHOLD)
-			newitr = ixgbe_bulk_latency;
-	} else if (olditr == ixgbe_bulk_latency) {
-		if (rxr->bytes < BULK_THRESHOLD)
-			newitr = ixgbe_ave_latency;
-	}
-
-	if (olditr != newitr) {
-		/* Change interrupt rate */
-		rxr->eitr_setting = newitr;
-		IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(rxr->me),
-		    newitr | (newitr << 16));
-	}
-
-	rxr->bytes = 0;
-	return;
-}
-
-static void
-ixgbe_init_moderation(struct adapter *adapter)
-{
-	struct rx_ring *rxr = adapter->rx_rings;
-	struct tx_ring *txr = adapter->tx_rings;
-
-	/* Single interrupt - MSI or Legacy? */
-	if (adapter->msix < 2) {
-		IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(0), 100);
-		return;
-	}
-
-	/* TX irq moderation rate is fixed */
-	for (int i = 0; i < adapter->num_queues; i++, txr++)
-		IXGBE_WRITE_REG(&adapter->hw,
-		    IXGBE_EITR(txr->msix), ixgbe_ave_latency);
-
-	/* RX moderation will be adapted over time, set default */
-	for (int i = 0; i < adapter->num_queues; i++, rxr++) {
-		IXGBE_WRITE_REG(&adapter->hw,
-		    IXGBE_EITR(rxr->msix), ixgbe_low_latency);
-	}
-
-	/* Set Link moderation */
-	IXGBE_WRITE_REG(&adapter->hw,
-	    IXGBE_EITR(adapter->linkvec), IXGBE_LINK_ITR);
-
-}
-
 /*********************************************************************
  *
  *  Media Ioctl callback
@@ -1665,11 +1539,10 @@ ixgbe_media_change(struct ifnet * ifp)
 
 /*********************************************************************
  *
- *  This routine maps the mbufs to tx descriptors.
- *    WARNING: while this code is using an MQ style infrastructure,
- *    it would NOT work as is with more than 1 queue.
+ *  This routine maps the mbufs to tx descriptors, allowing the
+ *  TX engine to transmit the packets. 
+ *  	- return 0 on success, positive on failure
  *
- *  return 0 on success, positive on failure
  **********************************************************************/
 
 static int
@@ -1695,14 +1568,6 @@ ixgbe_xmit(struct tx_ring *txr, struct mbuf **m_headp)
 	if (m_head->m_flags & M_VLANTAG)
         	cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
 
-	/* Do a clean if descriptors are low */
-	if (txr->tx_avail <= IXGBE_TX_CLEANUP_THRESHOLD) {
-		ixgbe_txeof(txr);
-		/* Now do we at least have a minimal? */
-		if (txr->tx_avail <= IXGBE_TX_OP_THRESHOLD)
-			return (ENOBUFS);
-        }
-
         /*
          * Important to capture the first descriptor
          * used because it will contain the index of
@@ -1756,7 +1621,7 @@ ixgbe_xmit(struct tx_ring *txr, struct mbuf **m_headp)
 
 	/* Make certain there are enough descriptors */
 	if (nsegs > txr->tx_avail - 2) {
-		txr->no_tx_desc_avail++;
+		txr->no_desc_avail++;
 		error = ENOBUFS;
 		goto xmit_fail;
 	}
@@ -1814,7 +1679,7 @@ ixgbe_xmit(struct tx_ring *txr, struct mbuf **m_headp)
 		txd->read.cmd_type_len = htole32(txr->txd_cmd |
 		    cmd_type_len |seglen);
 		txd->read.olinfo_status = htole32(olinfo_status);
-		last = i; /* Next descriptor that will get completed */
+		last = i; /* descriptor that will get completion IRQ */
 
 		if (++i == adapter->num_tx_desc)
 			i = 0;
@@ -1843,7 +1708,13 @@ ixgbe_xmit(struct tx_ring *txr, struct mbuf **m_headp)
 	 * hardware that this frame is available to transmit.
 	 */
 	++txr->total_packets;
+	txr->watchdog_time = ticks;
 	IXGBE_WRITE_REG(&adapter->hw, IXGBE_TDT(txr->me), i);
+
+	/* Do a clean if descriptors are low */
+	if (txr->tx_avail <= IXGBE_TX_CLEANUP_THRESHOLD)
+		ixgbe_txeof(txr);
+
 	return (0);
 
 xmit_fail:
@@ -1978,7 +1849,6 @@ ixgbe_local_timer(void *arg)
 	struct ifnet   *ifp = adapter->ifp;
 	device_t	dev = adapter->dev;
 	struct tx_ring *txr = adapter->tx_rings;
-	bool   tx_hung = FALSE;
 
 	mtx_assert(&adapter->core_mtx, MA_OWNED);
 
@@ -1989,21 +1859,32 @@ ixgbe_local_timer(void *arg)
 
 	ixgbe_update_link_status(adapter);
 	ixgbe_update_stats_counters(adapter);
-	if (ixgbe_display_debug_stats && ifp->if_drv_flags & IFF_DRV_RUNNING) {
+
+	/* Debug display */
+	if (ixgbe_display_debug_stats && ifp->if_drv_flags & IFF_DRV_RUNNING)
 		ixgbe_print_hw_stats(adapter);
-	}
+
+	/*
+	 * If the interface has been paused
+	 * then don't do the watchdog check
+	 */
+	if (IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)
+		goto out;
 	/*
 	** Check for time since any descriptor was cleaned
 	*/
         for (int i = 0; i < adapter->num_queues; i++, txr++) {
-		if (txr->watchdog_check == FALSE)
+		IXGBE_TX_LOCK(txr);
+		if (txr->watchdog_check == FALSE) {
+			IXGBE_TX_UNLOCK(txr);
 			continue;
-		if ((ticks - txr->watchdog_time) > IXGBE_WATCHDOG) {
-			tx_hung = TRUE;
-			goto hung;
 		}
+		if ((ticks - txr->watchdog_time) > IXGBE_WATCHDOG)
+			goto hung;
+		IXGBE_TX_UNLOCK(txr);
 	}
 out:
+       	ixgbe_rearm_queues(adapter, adapter->que_mask);
 	callout_reset(&adapter->timer, hz, ixgbe_local_timer, adapter);
 	return;
 
@@ -2017,6 +1898,7 @@ hung:
 	    txr->me, txr->tx_avail, txr->next_to_clean);
 	adapter->ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
 	adapter->watchdog_events++;
+	IXGBE_TX_UNLOCK(txr);
 	ixgbe_init_locked(adapter);
 }
 
@@ -2123,8 +2005,7 @@ static int
 ixgbe_allocate_legacy(struct adapter *adapter)
 {
 	device_t dev = adapter->dev;
-	struct 		tx_ring *txr = adapter->tx_rings;
-	struct		rx_ring *rxr = adapter->rx_rings;
+	struct		ix_queue *que = adapter->queues;
 	int error, rid = 0;
 
 	/* MSI RID at 1 */
@@ -2144,15 +2025,10 @@ ixgbe_allocate_legacy(struct adapter *adapter)
 	 * Try allocating a fast interrupt and the associated deferred
 	 * processing contexts.
 	 */
-	TASK_INIT(&txr->tx_task, 0, ixgbe_handle_tx, txr);
-	TASK_INIT(&rxr->rx_task, 0, ixgbe_handle_rx, rxr);
-	txr->tq = taskqueue_create_fast("ixgbe_txq", M_NOWAIT,
-            taskqueue_thread_enqueue, &txr->tq);
-	rxr->tq = taskqueue_create_fast("ixgbe_rxq", M_NOWAIT,
-            taskqueue_thread_enqueue, &rxr->tq);
-	taskqueue_start_threads(&txr->tq, 1, PI_NET, "%s txq",
-            device_get_nameunit(adapter->dev));
-	taskqueue_start_threads(&rxr->tq, 1, PI_NET, "%s rxq",
+	TASK_INIT(&que->que_task, 0, ixgbe_handle_que, que);
+	que->tq = taskqueue_create_fast("ixgbe_que", M_NOWAIT,
+            taskqueue_thread_enqueue, &que->tq);
+	taskqueue_start_threads(&que->tq, 1, PI_NET, "%s ixq",
             device_get_nameunit(adapter->dev));
 
 	/* Tasklets for Link, SFP and Multispeed Fiber */
@@ -2169,15 +2045,17 @@ ixgbe_allocate_legacy(struct adapter *adapter)
 
 	if ((error = bus_setup_intr(dev, adapter->res,
             INTR_TYPE_NET | INTR_MPSAFE, NULL, ixgbe_legacy_irq,
-            adapter, &adapter->tag)) != 0) {
+            que, &adapter->tag)) != 0) {
 		device_printf(dev, "Failed to register fast interrupt "
 		    "handler: %d\n", error);
-		taskqueue_free(txr->tq);
-		taskqueue_free(rxr->tq);
-		txr->tq = NULL;
-		rxr->tq = NULL;
+		taskqueue_free(que->tq);
+		taskqueue_free(adapter->tq);
+		que->tq = NULL;
+		adapter->tq = NULL;
 		return (error);
 	}
+	/* For simplicity in the handlers */
+	adapter->que_mask = IXGBE_EIMS_ENABLE_MASK;
 
 	return (0);
 }
@@ -2192,83 +2070,44 @@ static int
 ixgbe_allocate_msix(struct adapter *adapter)
 {
 	device_t        dev = adapter->dev;
-	struct 		tx_ring *txr = adapter->tx_rings;
-	struct		rx_ring *rxr = adapter->rx_rings;
+	struct 		ix_queue *que = adapter->queues;
 	int 		error, rid, vector = 0;
 
-	/* TX setup: the code is here for multi tx,
-	   there are other parts of the driver not ready for it */
-	for (int i = 0; i < adapter->num_queues; i++, vector++, txr++) {
+	for (int i = 0; i < adapter->num_queues; i++, vector++, que++) {
 		rid = vector + 1;
-		txr->res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
+		que->res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
 		    RF_SHAREABLE | RF_ACTIVE);
-		if (!txr->res) {
+		if (que->res == NULL) {
 			device_printf(dev,"Unable to allocate"
-		    	    " bus resource: tx interrupt [%d]\n", vector);
+		    	    " bus resource: que interrupt [%d]\n", vector);
 			return (ENXIO);
 		}
 		/* Set the handler function */
-		error = bus_setup_intr(dev, txr->res,
+		error = bus_setup_intr(dev, que->res,
 		    INTR_TYPE_NET | INTR_MPSAFE, NULL,
-		    ixgbe_msix_tx, txr, &txr->tag);
+		    ixgbe_msix_que, que, &que->tag);
 		if (error) {
-			txr->res = NULL;
-			device_printf(dev, "Failed to register TX handler");
+			que->res = NULL;
+			device_printf(dev, "Failed to register QUE handler");
 			return (error);
 		}
-		txr->msix = vector;
+		que->msix = vector;
+        	adapter->que_mask |= (u64)(1 << que->msix);
 		/*
 		** Bind the msix vector, and thus the
 		** ring to the corresponding cpu.
 		*/
 		if (adapter->num_queues > 1)
-			bus_bind_intr(dev, txr->res, i);
+			bus_bind_intr(dev, que->res, i);
 
-		TASK_INIT(&txr->tx_task, 0, ixgbe_handle_tx, txr);
-		txr->tq = taskqueue_create_fast("ixgbe_txq", M_NOWAIT,
-		    taskqueue_thread_enqueue, &txr->tq);
-		taskqueue_start_threads(&txr->tq, 1, PI_NET, "%s txq",
+		TASK_INIT(&que->que_task, 0, ixgbe_handle_que, que);
+		que->tq = taskqueue_create_fast("ixgbe_que", M_NOWAIT,
+		    taskqueue_thread_enqueue, &que->tq);
+		taskqueue_start_threads(&que->tq, 1, PI_NET, "%s que",
 		    device_get_nameunit(adapter->dev));
 	}
 
-	/* RX setup */
-	for (int i = 0; i < adapter->num_queues; i++, vector++, rxr++) {
-		rid = vector + 1;
-		rxr->res = bus_alloc_resource_any(dev,
-	    	    SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE);
-		if (!rxr->res) {
-			device_printf(dev,"Unable to allocate"
-		    	    " bus resource: rx interrupt [%d],"
-			    "rid = %d\n", i, rid);
-			return (ENXIO);
-		}
-		/* Set the handler function */
-		error = bus_setup_intr(dev, rxr->res,
-		    INTR_TYPE_NET | INTR_MPSAFE, NULL,
-		    ixgbe_msix_rx, rxr, &rxr->tag);
-		if (error) {
-			rxr->res = NULL;
-			device_printf(dev, "Failed to register RX handler");
-			return (error);
-		}
-		rxr->msix = vector;
-		/* used in local timer */
-		adapter->rx_mask |= (u64)(1 << vector);
-		/*
-		** Bind the msix vector, and thus the
-		** ring to the corresponding cpu.
-		*/
-		if (adapter->num_queues > 1)
-			bus_bind_intr(dev, rxr->res, i);
-
-		TASK_INIT(&rxr->rx_task, 0, ixgbe_handle_rx, rxr);
-		rxr->tq = taskqueue_create_fast("ixgbe_rxq", M_NOWAIT,
-		    taskqueue_thread_enqueue, &rxr->tq);
-		taskqueue_start_threads(&rxr->tq, 1, PI_NET, "%s rxq",
-		    device_get_nameunit(adapter->dev));
-	}
-
-	/* Now for Link changes */
+	/* and Link */
 	rid = vector + 1;
 	adapter->res = bus_alloc_resource_any(dev,
     	    SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE);
@@ -2340,15 +2179,15 @@ ixgbe_setup_msix(struct adapter *adapter)
 	}
 
 	/* Figure out a reasonable auto config value */
-	queues = (mp_ncpus > ((msgs-1)/2)) ? (msgs-1)/2 : mp_ncpus;
+	queues = (mp_ncpus > (msgs-1)) ? (msgs-1) : mp_ncpus;
 
 	if (ixgbe_num_queues == 0)
 		ixgbe_num_queues = queues;
 	/*
-	** Want two vectors (RX/TX) per queue
+	** Want one vector (RX/TX pair) per queue
 	** plus an additional for Link.
 	*/
-	want = (ixgbe_num_queues * 2) + 1;
+	want = ixgbe_num_queues + 1;
 	if (msgs >= want)
 		msgs = want;
 	else {
@@ -2409,8 +2248,7 @@ ixgbe_allocate_pci_resources(struct adapter *adapter)
 static void
 ixgbe_free_pci_resources(struct adapter * adapter)
 {
-	struct 		tx_ring *txr = adapter->tx_rings;
-	struct		rx_ring *rxr = adapter->rx_rings;
+	struct 		ix_queue *que = adapter->queues;
 	device_t	dev = adapter->dev;
 	int		rid, memrid;
 
@@ -2431,29 +2269,18 @@ ixgbe_free_pci_resources(struct adapter * adapter)
 		goto mem;
 
 	/*
-	**  Release all the interrupt resources:
-	**  notice this is harmless for Legacy or
-	**  MSI since pointers will always be NULL
+	**  Release all msix queue resources:
 	*/
-	for (int i = 0; i < adapter->num_queues; i++, txr++) {
-		rid = txr->msix + 1;
-		if (txr->tag != NULL) {
-			bus_teardown_intr(dev, txr->res, txr->tag);
-			txr->tag = NULL;
+	for (int i = 0; i < adapter->num_queues; i++, que++) {
+		rid = que->msix + 1;
+		if (que->tag != NULL) {
+			bus_teardown_intr(dev, que->res, que->tag);
+			que->tag = NULL;
 		}
-		if (txr->res != NULL)
-			bus_release_resource(dev, SYS_RES_IRQ, rid, txr->res);
+		if (que->res != NULL)
+			bus_release_resource(dev, SYS_RES_IRQ, rid, que->res);
 	}
 
-	for (int i = 0; i < adapter->num_queues; i++, rxr++) {
-		rid = rxr->msix + 1;
-		if (rxr->tag != NULL) {
-			bus_teardown_intr(dev, rxr->res, rxr->tag);
-			rxr->tag = NULL;
-		}
-		if (rxr->res != NULL)
-			bus_release_resource(dev, SYS_RES_IRQ, rid, rxr->res);
-	}
 
 	/* Clean the Legacy or Link interrupt last */
 	if (adapter->linkvec) /* we are doing MSIX */
@@ -2467,6 +2294,7 @@ ixgbe_free_pci_resources(struct adapter * adapter)
 	}
 	if (adapter->res != NULL)
 		bus_release_resource(dev, SYS_RES_IRQ, rid, adapter->res);
+
 mem:
 	if (adapter->msix)
 		pci_release_msi(dev);
@@ -2524,9 +2352,7 @@ ixgbe_setup_interface(device_t dev, struct adapter *adapter)
 
 	ifp->if_capabilities |= IFCAP_HWCSUM | IFCAP_TSO4 | IFCAP_VLAN_HWCSUM;
 	ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU;
-	ifp->if_capabilities |= IFCAP_JUMBO_MTU;
-	if (ixgbe_header_split)
-		ifp->if_capabilities |= IFCAP_LRO;
+	ifp->if_capabilities |= IFCAP_JUMBO_MTU | IFCAP_LRO;
 
 	ifp->if_capenable = ifp->if_capabilities;
 
@@ -2546,6 +2372,7 @@ ixgbe_setup_interface(device_t dev, struct adapter *adapter)
 	}
 	ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL);
 	ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO);
+
 	return;
 }
 
@@ -2556,17 +2383,7 @@ ixgbe_config_link(struct adapter *adapter)
 	u32	autoneg, err = 0;
 	bool	sfp, negotiate;
 
-	switch (hw->phy.type) {
-	case ixgbe_phy_sfp_avago:
-	case ixgbe_phy_sfp_ftl:
-	case ixgbe_phy_sfp_intel:
-	case ixgbe_phy_sfp_unknown:
-	case ixgbe_phy_tw_tyco:
-	case ixgbe_phy_tw_unknown:
-                sfp = TRUE;
-	default:
-                sfp = FALSE;
-        }
+	sfp = ixgbe_is_sfp(hw);
 
 	if (sfp) { 
 		if (hw->phy.multispeed_fiber) {
@@ -2613,8 +2430,8 @@ ixgbe_dma_malloc(struct adapter *adapter, bus_size_t size,
 	device_t dev = adapter->dev;
 	int             r;
 
-	r = bus_dma_tag_create(NULL,	/* parent */
-			       1, 0,	/* alignment, bounds */
+	r = bus_dma_tag_create(bus_get_dma_tag(adapter->dev),	/* parent */
+			       DBA_ALIGN, 0,	/* alignment, bounds */
 			       BUS_SPACE_MAXADDR,	/* lowaddr */
 			       BUS_SPACE_MAXADDR,	/* highaddr */
 			       NULL, NULL,	/* filter, filterarg */
@@ -2679,21 +2496,30 @@ ixgbe_dma_free(struct adapter *adapter, struct ixgbe_dma_alloc *dma)
 static int
 ixgbe_allocate_queues(struct adapter *adapter)
 {
-	device_t dev = adapter->dev;
-	struct tx_ring *txr;
-	struct rx_ring *rxr;
+	device_t	dev = adapter->dev;
+	struct ix_queue	*que;
+	struct tx_ring	*txr;
+	struct rx_ring	*rxr;
 	int rsize, tsize, error = IXGBE_SUCCESS;
 	int txconf = 0, rxconf = 0;
 
+        /* First allocate the top level queue structs */
+        if (!(adapter->queues =
+            (struct ix_queue *) malloc(sizeof(struct ix_queue) *
+            adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
+                device_printf(dev, "Unable to allocate queue memory\n");
+                error = ENOMEM;
+                goto fail;
+        }
+
 	/* First allocate the TX ring struct memory */
 	if (!(adapter->tx_rings =
 	    (struct tx_ring *) malloc(sizeof(struct tx_ring) *
 	    adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
 		device_printf(dev, "Unable to allocate TX ring memory\n");
 		error = ENOMEM;
-		goto fail;
+		goto tx_fail;
 	}
-	txr = adapter->tx_rings;
 
 	/* Next allocate the RX */
 	if (!(adapter->rx_rings =
@@ -2703,11 +2529,10 @@ ixgbe_allocate_queues(struct adapter *adapter)
 		error = ENOMEM;
 		goto rx_fail;
 	}
-	rxr = adapter->rx_rings;
 
 	/* For the ring itself */
 	tsize = roundup2(adapter->num_tx_desc *
-	    sizeof(union ixgbe_adv_tx_desc), 4096);
+	    sizeof(union ixgbe_adv_tx_desc), DBA_ALIGN);
 
 	/*
 	 * Now set up the TX queues, txconf is needed to handle the
@@ -2746,6 +2571,12 @@ ixgbe_allocate_queues(struct adapter *adapter)
 		/* Allocate a buf ring */
 		txr->br = buf_ring_alloc(IXGBE_BR_SIZE, M_DEVBUF,
 		    M_WAITOK, &txr->tx_mtx);
+		if (txr->br == NULL) {
+			device_printf(dev,
+			    "Critical Failure setting up buf ring\n");
+			error = ENOMEM;
+			goto err_tx_desc;
+        	}
 #endif
 	}
 
@@ -2753,7 +2584,7 @@ ixgbe_allocate_queues(struct adapter *adapter)
 	 * Next the RX queues...
 	 */ 
 	rsize = roundup2(adapter->num_rx_desc *
-	    sizeof(union ixgbe_adv_rx_desc), 4096);
+	    sizeof(union ixgbe_adv_rx_desc), DBA_ALIGN);
 	for (int i = 0; i < adapter->num_queues; i++, rxconf++) {
 		rxr = &adapter->rx_rings[i];
 		/* Set up some basics */
@@ -2784,6 +2615,16 @@ ixgbe_allocate_queues(struct adapter *adapter)
 		}
 	}
 
+	/*
+	** Finally set up the queue holding structs
+	*/
+	for (int i = 0; i < adapter->num_queues; i++) {
+		que = &adapter->queues[i];
+		que->adapter = adapter;
+		que->txr = &adapter->tx_rings[i];
+		que->rxr = &adapter->rx_rings[i];
+	}
+
 	return (0);
 
 err_rx_desc:
@@ -2795,6 +2636,8 @@ err_tx_desc:
 	free(adapter->rx_rings, M_DEVBUF);
 rx_fail:
 	free(adapter->tx_rings, M_DEVBUF);
+tx_fail:
+	free(adapter->queues, M_DEVBUF);
 fail:
 	return (error);
 }
@@ -2871,6 +2714,7 @@ ixgbe_setup_transmit_ring(struct tx_ring *txr)
 	int i;
 
 	/* Clear the old ring contents */
+	IXGBE_TX_LOCK(txr);
 	bzero((void *)txr->tx_base,
 	      (sizeof(union ixgbe_adv_tx_desc)) * adapter->num_tx_desc);
 	/* Reset indices */
@@ -2902,6 +2746,7 @@ ixgbe_setup_transmit_ring(struct tx_ring *txr)
 
 	bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
 	    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
+	IXGBE_TX_UNLOCK(txr);
 }
 
 /*********************************************************************
@@ -3281,6 +3126,7 @@ static void
 ixgbe_atr(struct tx_ring *txr, struct mbuf *mp)
 {
 	struct adapter			*adapter = txr->adapter;
+	struct ix_queue			*que;
 	struct ixgbe_atr_input		atr_input;
 	struct ip			*ip;
 	struct tcphdr			*th;
@@ -3331,6 +3177,7 @@ ixgbe_atr(struct tx_ring *txr, struct mbuf *mp)
 	src_ipv4_addr = ip->ip_src.s_addr;
 	dst_ipv4_addr = ip->ip_dst.s_addr;
 	flex_bytes = etype;
+	que = &adapter->queues[txr->me];
 
 	ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id);
 	ixgbe_atr_set_src_port_82599(&atr_input, dst_port);
@@ -3343,7 +3190,7 @@ ixgbe_atr(struct tx_ring *txr, struct mbuf *mp)
 
 	/* This assumes the Rx queue and Tx queue are bound to the same CPU */
 	ixgbe_fdir_add_signature_filter_82599(&adapter->hw,
-	    &atr_input, txr->msix);
+	    &atr_input, que->msix);
 }
 #endif
 
@@ -3401,7 +3248,8 @@ ixgbe_txeof(struct tx_ring *txr)
 			++txr->tx_avail;
 
 			if (tx_buffer->m_head) {
-				ifp->if_opackets++;
+				txr->bytes +=
+				    tx_buffer->m_head->m_pkthdr.len;
 				bus_dmamap_sync(txr->txtag,
 				    tx_buffer->map,
 				    BUS_DMASYNC_POSTWRITE);
@@ -3421,6 +3269,8 @@ ixgbe_txeof(struct tx_ring *txr)
 			tx_desc =
 			    (struct ixgbe_legacy_tx_desc *)&txr->tx_base[first];
 		}
+		++txr->packets;
+		++ifp->if_opackets;
 		/* See if there is more work now */
 		last = tx_buffer->eop_index;
 		if (last != -1) {
@@ -3456,27 +3306,32 @@ ixgbe_txeof(struct tx_ring *txr)
 
 /*********************************************************************
  *
- *  Refresh mbuf buffers for a range of descriptors
+ *  Refresh mbuf buffers for RX descriptor rings
+ *   - now keeps its own state so discards due to resource
+ *     exhaustion are unnecessary, if an mbuf cannot be obtained
+ *     it just returns, keeping its placeholder, thus it can simply
+ *     be recalled to try again.
  *
  **********************************************************************/
-static int
-ixgbe_get_buf(struct rx_ring *rxr, int first, int limit)
+static void
+ixgbe_refresh_mbufs(struct rx_ring *rxr, int limit)
 {
 	struct adapter		*adapter = rxr->adapter;
 	bus_dma_segment_t	seg[2];
 	struct ixgbe_rx_buf	*rxbuf;
 	struct mbuf		*mh, *mp;
 	bus_dmamap_t		map;
-	int			i, nsegs, error;
+	int			i, nsegs, error, cleaned;
 
-	i = first;
+	i = rxr->next_to_refresh;
+	cleaned = -1; /* Signify no completions */
 	while (i != limit) {
 		rxbuf = &rxr->rx_buffers[i];
 
 		if (rxbuf->m_head == NULL) {
 			mh = m_gethdr(M_DONTWAIT, MT_DATA);
 			if (mh == NULL)
-				goto failure;
+				goto update;
 		} else  /* reuse */
 			mh = rxbuf->m_head;
 
@@ -3487,13 +3342,14 @@ ixgbe_get_buf(struct rx_ring *rxr, int first, int limit)
 			mp = m_getjcl(M_DONTWAIT, MT_DATA,
 			    M_PKTHDR, adapter->rx_mbuf_sz);
 			if (mp == NULL)
-				goto failure;
+				goto update;
 			mp->m_len = adapter->rx_mbuf_sz;
 			mp->m_flags &= ~M_PKTHDR;
 		} else {	/* reusing */
 			mp = rxbuf->m_pack;
 			mp->m_len = adapter->rx_mbuf_sz;
 			mp->m_flags &= ~M_PKTHDR;
+			mp->m_next = NULL;
 		}
 
 		/*
@@ -3509,7 +3365,7 @@ ixgbe_get_buf(struct rx_ring *rxr, int first, int limit)
 		if (error != 0) {
 			printf("GET BUF: dmamap load failure - %d\n", error);
 			m_free(mh);
-			return (error);
+			goto update;
 		}
 
 		/* Unload old mapping and update buffer struct */
@@ -3527,52 +3383,21 @@ ixgbe_get_buf(struct rx_ring *rxr, int first, int limit)
 		rxr->rx_base[i].read.hdr_addr = htole64(seg[0].ds_addr);
 		rxr->rx_base[i].read.pkt_addr = htole64(seg[1].ds_addr);
 
+		cleaned = i;
 		/* Calculate next index */
 		if (++i == adapter->num_rx_desc)
 			i = 0;
+		/* This is the work marker for refresh */
+		rxr->next_to_refresh = i;
 	}
+update:
+	if (cleaned != -1) /* If we refreshed some, bump tail */
+		IXGBE_WRITE_REG(&adapter->hw, IXGBE_RDT(rxr->me), cleaned);
 
-	return (0);
-
-failure:
-	panic("GET BUF: ENOBUFS\n");
-
-#if 0
-	/*
-	** If we get here, we have an mbuf resource
-	** issue, so we discard the incoming packet
-	** and attempt to reuse existing mbufs next
-	** pass thru the ring, but to do so we must
-	** fix up the descriptor which had the address
-	** clobbered with writeback info.
-	*/
-remap:
-	adapter->mbuf_header_failed++;
-	merr = ENOBUFS;
-	/* Is there a reusable buffer? */
-	mh = rxr->rx_buffers[i].m_head;
-	if (mh == NULL) /* Nope, init error */
-		return (merr);
-	mp = rxr->rx_buffers[i].m_pack;
-	if (mp == NULL) /* Nope, init error */
-		return (merr);
-	/* Get our old mapping */
-	rxbuf = &rxr->rx_buffers[i];
-	error = bus_dmamap_load_mbuf_sg(rxr->rxtag,
-	    rxbuf->map, mh, seg, &nsegs, BUS_DMA_NOWAIT);
-	if (error != 0) {
-		/* We really have a problem */
-		m_free(mh);
-		return (error);
-	}
-	/* Now fix the descriptor as needed */
-	rxr->rx_base[i].read.hdr_addr = htole64(seg[0].ds_addr);
-	rxr->rx_base[i].read.pkt_addr = htole64(seg[1].ds_addr);
-
-	return (merr);
-#endif
+	return;
 }
 
+
 /*********************************************************************
  *
  *  Allocate memory for rx_buffer structures. Since we use one
@@ -3603,7 +3428,7 @@ ixgbe_allocate_receive_buffers(struct rx_ring *rxr)
 	** with packet split (hence the two segments, even though
 	** it may not always use this.
 	*/
-	if ((error = bus_dma_tag_create(NULL,		/* parent */
+	if ((error = bus_dma_tag_create(bus_get_dma_tag(dev),	/* parent */
 				   1, 0,	/* alignment, bounds */
 				   BUS_SPACE_MAXADDR,	/* lowaddr */
 				   BUS_SPACE_MAXADDR,	/* highaddr */
@@ -3646,7 +3471,6 @@ fail:
 	return (error);
 }
 
-
 /*
 ** Used to detect a descriptor that has
 ** been merged by Hardware RSC.
@@ -3670,11 +3494,12 @@ ixgbe_setup_hw_rsc(struct rx_ring *rxr)
 {
 	struct	adapter 	*adapter = rxr->adapter;
 	struct	ixgbe_hw	*hw = &adapter->hw;
-	u32	rscctrl, rdrxctl;
+	u32			rscctrl, rdrxctl;
 
 	rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
 	rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
 	rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
+	rdrxctl |= IXGBE_RDRXCTL_RSCACKC;
 	IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
 
 	rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(rxr->me));
@@ -3723,6 +3548,7 @@ ixgbe_setup_receive_ring(struct rx_ring *rxr)
 	dev = adapter->dev;
 
 	/* Clear the ring contents */
+	IXGBE_RX_LOCK(rxr);
 	rsize = roundup2(adapter->num_rx_desc *
 	    sizeof(union ixgbe_adv_rx_desc), DBA_ALIGN);
 	bzero((void *)rxr->rx_base, rsize);
@@ -3781,14 +3607,12 @@ ixgbe_setup_receive_ring(struct rx_ring *rxr)
 
 	/* Setup our descriptor indices */
 	rxr->next_to_check = 0;
-	rxr->last_refreshed = 0;
+	rxr->next_to_refresh = 0;
 	rxr->lro_enabled = FALSE;
 
 	/* Use header split if configured */
 	if (ixgbe_header_split)
 		rxr->hdr_split = TRUE;
-	else
-		ifp->if_capabilities &= ~IFCAP_LRO;
 
 	bus_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
 	    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
@@ -3796,40 +3620,25 @@ ixgbe_setup_receive_ring(struct rx_ring *rxr)
 	/*
 	** Now set up the LRO interface:
 	** 82598 uses software LRO, the
-	** 82599 on the other hand uses a
-	** hardware assist to do the same.
-	** We only do LRO when header split
-	** is enabled, its simpler that way.
+	** 82599 additionally uses a
+	** hardware assist.
+	**
+	** Disable RSC when RXCSUM is off
 	*/
-	if ((ifp->if_capenable & IFCAP_LRO) && (rxr->hdr_split)) {
+	if ((adapter->hw.mac.type == ixgbe_mac_82599EB) &&
+	    (ifp->if_capenable & IFCAP_RXCSUM))
+		ixgbe_setup_hw_rsc(rxr);
+	else if (ifp->if_capenable & IFCAP_LRO) {
 		int err = tcp_lro_init(lro);
 		if (err)
 			panic("LRO Initialization failed!\n");
 		INIT_DEBUGOUT("RX Soft LRO Initialized\n");
 		rxr->lro_enabled = TRUE;
 		lro->ifp = adapter->ifp;
-		ixgbe_setup_hw_rsc(rxr);
 	}
 
+	IXGBE_RX_UNLOCK(rxr);
 	return (0);
-#if 0
-fail:
-	/*
-	 * We need to clean up any buffers allocated
-	 * so far, 'j' is the failing index.
-	 */
-	for (int i = 0; i < j; i++) {
-		rxbuf = &rxr->rx_buffers[i];
-		if (rxbuf->m_head != NULL) {
-			bus_dmamap_sync(rxr->rxtag, rxbuf->map,
-			    BUS_DMASYNC_POSTREAD);
-			bus_dmamap_unload(rxr->rxtag, rxbuf->map);
-			m_freem(rxbuf->m_head);
-			rxbuf->m_head = NULL;
-		}
-	}
-	return (ENOBUFS);
-#endif
 }
 
 /*********************************************************************
@@ -4025,6 +3834,7 @@ ixgbe_free_receive_structures(struct adapter *adapter)
 	free(adapter->rx_rings, M_DEVBUF);
 }
 
+
 /*********************************************************************
  *
  *  Free receive ring data structures
@@ -4065,6 +3875,61 @@ ixgbe_free_receive_buffers(struct rx_ring *rxr)
 	return;
 }
 
+static __inline void
+ixgbe_rx_input(struct rx_ring *rxr, struct ifnet *ifp, struct mbuf *m, u32 ptype)
+{
+                 
+        /*
+         * ATM LRO is only for IPv4/TCP packets and TCP checksum of the packet
+         * should be computed by hardware. Also it should not have VLAN tag in
+         * ethernet header.
+         */
+        if (rxr->lro_enabled &&
+            (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) != 0 &&
+            (ptype & IXGBE_RXDADV_PKTTYPE_ETQF) == 0 &&
+            (ptype & (IXGBE_RXDADV_PKTTYPE_IPV4 | IXGBE_RXDADV_PKTTYPE_TCP)) ==
+            (IXGBE_RXDADV_PKTTYPE_IPV4 | IXGBE_RXDADV_PKTTYPE_TCP) &&
+            (m->m_pkthdr.csum_flags & (CSUM_DATA_VALID | CSUM_PSEUDO_HDR)) ==
+            (CSUM_DATA_VALID | CSUM_PSEUDO_HDR)) {
+                /*
+                 * Send to the stack if:
+                 **  - LRO not enabled, or
+                 **  - no LRO resources, or
+                 **  - lro enqueue fails
+                 */
+                if (rxr->lro.lro_cnt != 0)
+                        if (tcp_lro_rx(&rxr->lro, m, 0) == 0)
+                                return;
+        }
+        (*ifp->if_input)(ifp, m);
+}
+
+static __inline void
+ixgbe_rx_discard(struct rx_ring *rxr, int i)
+{
+	struct adapter		*adapter = rxr->adapter;
+	struct ixgbe_rx_buf	*rbuf;
+	struct mbuf		*mh, *mp;
+
+	rbuf = &rxr->rx_buffers[i];
+        if (rbuf->fmp != NULL) /* Partial chain ? */
+                m_freem(rbuf->fmp);
+
+	mh = rbuf->m_head;
+	mp = rbuf->m_pack;
+
+	/* Reuse loaded DMA map and just update mbuf chain */
+	mh->m_len = MHLEN;
+	mh->m_flags |= M_PKTHDR;
+	mh->m_next = NULL;
+
+	mp->m_len = mp->m_pkthdr.len = adapter->rx_mbuf_sz;
+	mp->m_data = mp->m_ext.ext_buf;
+	mp->m_next = NULL;
+	return;
+}
+
+
 /*********************************************************************
  *
  *  This routine executes in interrupt context. It replenishes
@@ -4077,154 +3942,176 @@ ixgbe_free_receive_buffers(struct rx_ring *rxr)
  *  Return TRUE for more work, FALSE for all clean.
  *********************************************************************/
 static bool
-ixgbe_rxeof(struct rx_ring *rxr, int count)
+ixgbe_rxeof(struct ix_queue *que, int count)
 {
-	struct adapter 		*adapter = rxr->adapter;
-	struct ifnet   		*ifp = adapter->ifp;
+	struct adapter		*adapter = que->adapter;
+	struct rx_ring		*rxr = que->rxr;
+	struct ifnet		*ifp = adapter->ifp;
 	struct lro_ctrl		*lro = &rxr->lro;
 	struct lro_entry	*queued;
-	int             	i, processed = 0;
-	u32			staterr;
+	int			i, nextp, processed = 0;
+	u32			staterr = 0;
 	union ixgbe_adv_rx_desc	*cur;
-
+	struct ixgbe_rx_buf	*rbuf, *nbuf;
 
 	IXGBE_RX_LOCK(rxr);
-	i = rxr->next_to_check;
-	cur = &rxr->rx_base[i];
-	staterr = cur->wb.upper.status_error;
 
-	if (!(staterr & IXGBE_RXD_STAT_DD)) {
-		IXGBE_RX_UNLOCK(rxr);
-		return FALSE;
-	}
+	for (i = rxr->next_to_check; count != 0;) {
+		struct mbuf	*sendmp, *mh, *mp;
+		u32		rsc, ptype;
+		u16		hlen, plen, hdr, vtag;
+		bool		eop;
+ 
+		/* Sync the ring. */
+		bus_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
+		    BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
 
-	/* Sync the ring */
-	bus_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
-	    BUS_DMASYNC_POSTREAD);
+		cur = &rxr->rx_base[i];
+		staterr = le32toh(cur->wb.upper.status_error);
 
-	while ((staterr & IXGBE_RXD_STAT_DD) && (count != 0) &&
-	    (ifp->if_drv_flags & IFF_DRV_RUNNING)) {
-		struct mbuf	*sendmp, *mh, *mp, *nh, *np;
-		struct ixgbe_rx_buf	*nxtbuf;
-		u32		rsc;
-		u16		hlen, plen, hdr, nextp, vtag;	
-		bool		accept_frame, eop;
+		if ((staterr & IXGBE_RXD_STAT_DD) == 0)
+			break;
+		if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
+			break;
 
+		count--;
+		sendmp = NULL;
+		nbuf = NULL;
+		rsc = 0;
+		cur->wb.upper.status_error = 0;
+		rbuf = &rxr->rx_buffers[i];
+		mh = rbuf->m_head;
+		mp = rbuf->m_pack;
 
-		accept_frame = TRUE;
-		hlen = plen = rsc = nextp = 0;
-		sendmp = mh = mp = nh = np = NULL;
-
-		/* Sync the buffers */
-		bus_dmamap_sync(rxr->rxtag, rxr->rx_buffers[i].map,
-			    BUS_DMASYNC_POSTREAD);
-		mh = rxr->rx_buffers[i].m_head;
-		mp = rxr->rx_buffers[i].m_pack;
+		plen = le16toh(cur->wb.upper.length);
+		ptype = le32toh(cur->wb.lower.lo_dword.data) &
+		    IXGBE_RXDADV_PKTTYPE_MASK;
+		hdr = le16toh(cur->wb.lower.lo_dword.hs_rss.hdr_info);
 		vtag = le16toh(cur->wb.upper.vlan);
 		eop = ((staterr & IXGBE_RXD_STAT_EOP) != 0);
 
+		/* Make sure all parts of a bad packet are discarded */
+		if (((staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) != 0) ||
+		    (rxr->discard)) {
+			ifp->if_ierrors++;
+			rxr->rx_discarded++;
+			if (!eop)
+				rxr->discard = TRUE;
+			else
+				rxr->discard = FALSE;
+			ixgbe_rx_discard(rxr, i);
+			goto next_desc;
+		}
+
+		/*
+		** On 82599 which supports a hardware
+		** LRO (called HW RSC), packets need
+		** not be fragmented across sequential
+		** descriptors, rather the next descriptor
+		** is indicated in bits of the descriptor.
+		** This also means that we might proceses
+		** more than one packet at a time, something
+		** that has never been true before, it
+		** required eliminating global chain pointers
+		** in favor of what we are doing here.  -jfv
+		*/
 		if (!eop) {
 			/*
-			** On 82599 which supports a hardware
-			** LRO (called HW RSC), packets need 
-			** not be fragmented across sequential
-			** descriptors, rather the next descriptor
-			** is indicated in bits of the current.
-			** This also means that we might proceses
-			** more than one packet at a time, something
-			** that has never been true before, it 
-			** required eliminating global chain pointers
-			** in favor of what we are doing here.  -jfv
+			** Figure out the next descriptor
+			** of this frame.
 			*/
 			if (rxr->hw_rsc == TRUE) {
 				rsc = ixgbe_rsc_count(cur);
 				rxr->rsc_num += (rsc - 1);
 			}
-			if (rsc) {
+			if (rsc) { /* Get hardware index */
 				nextp = ((staterr &
 				    IXGBE_RXDADV_NEXTP_MASK) >>
 				    IXGBE_RXDADV_NEXTP_SHIFT);
-			} else {
+			} else { /* Just sequential */
 				nextp = i + 1;
 				if (nextp == adapter->num_rx_desc)
 					nextp = 0;
 			}
-			nxtbuf = &rxr->rx_buffers[nextp];
-			prefetch(nxtbuf);
+			nbuf = &rxr->rx_buffers[nextp];
+			prefetch(nbuf);
 		}
-
 		/*
-		** The way the hardware is configured to
-		** split, it will ONLY use the header buffer
-		** when header split is enabled, otherwise we
-		** get legacy behavior, ie, both header and
-		** payload are DMA'd into JUST the payload buffer.
+		** The header mbuf is ONLY used when header 
+		** split is enabled, otherwise we get normal 
+		** behavior, ie, both header and payload
+		** are DMA'd into the payload buffer.
 		**
 		** Rather than using the fmp/lmp global pointers
 		** we now keep the head of a packet chain in the
-		** m_nextpkt pointer and pass this along from one
+		** buffer struct and pass this along from one
 		** descriptor to the next, until we get EOP.
-		**
 		*/
-		if ((rxr->hdr_split) && (mh->m_nextpkt == NULL)) {
-			hdr = le16toh(cur->
-			    wb.lower.lo_dword.hs_rss.hdr_info);
+		if (rxr->hdr_split && (rbuf->fmp == NULL)) {
+			/* This must be an initial descriptor */
 			hlen = (hdr & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
 			    IXGBE_RXDADV_HDRBUFLEN_SHIFT;
 			if (hlen > IXGBE_RX_HDR)
 				hlen = IXGBE_RX_HDR;
-			plen = le16toh(cur->wb.upper.length);
 			mh->m_len = hlen;
 			mh->m_flags |= M_PKTHDR;
 			mh->m_next = NULL;
 			mh->m_pkthdr.len = mh->m_len;
-			/* Null this so getbuf replenishes */
-			rxr->rx_buffers[i].m_head = NULL;
+			/* Null buf pointer so it is refreshed */
+			rbuf->m_head = NULL;
 			/*
-			** Get the payload length, this
+			** Check the payload length, this
 			** could be zero if its a small
 			** packet.
 			*/
-			if (plen) {
+			if (plen > 0) {
 				mp->m_len = plen;
 				mp->m_next = NULL;
 				mp->m_flags &= ~M_PKTHDR;
 				mh->m_next = mp;
 				mh->m_pkthdr.len += mp->m_len;
-				/* Null this so getbuf replenishes */
-				rxr->rx_buffers[i].m_pack = NULL;
+				/* Null buf pointer so it is refreshed */
+				rbuf->m_pack = NULL;
 				rxr->rx_split_packets++;
 			}
-			/* Setup the forward chain */
-			if (eop == 0) {
-				nh = rxr->rx_buffers[nextp].m_head;
-				np = rxr->rx_buffers[nextp].m_pack;
-				nh->m_nextpkt = mh;
-				if (plen)
-					mp->m_next = np;
-				else
-					mh->m_next = np;
-			} else {
-				sendmp = mh;
-				if (staterr & IXGBE_RXD_STAT_VP) {
-					sendmp->m_pkthdr.ether_vtag = vtag;
-					sendmp->m_flags |= M_VLANTAG;
-				}
-			}
+			/*
+			** Now create the forward
+			** chain so when complete 
+			** we wont have to.
+			*/
+                        if (eop == 0) {
+				/* stash the chain head */
+                                nbuf->fmp = mh;
+				/* Make forward chain */
+                                if (plen)
+                                        mp->m_next = nbuf->m_pack;
+                                else
+                                        mh->m_next = nbuf->m_pack;
+                        } else {
+				/* Singlet, prepare to send */
+                                sendmp = mh;
+                                if (staterr & IXGBE_RXD_STAT_VP) {
+                                        sendmp->m_pkthdr.ether_vtag = vtag;
+                                        sendmp->m_flags |= M_VLANTAG;
+                                }
+                        }
 		} else {
 			/*
 			** Either no header split, or a
 			** secondary piece of a fragmented
-			** packet.
+			** split packet.
 			*/
-			mp->m_len = le16toh(cur->wb.upper.length);
-			rxr->rx_buffers[i].m_pack = NULL;
-			/* stored head pointer */
-			sendmp = mh->m_nextpkt;
-			if (sendmp != NULL) {
+			mp->m_len = plen;
+			/*
+			** See if there is a stored head
+			** that determines what we are
+			*/
+			sendmp = rbuf->fmp;
+			rbuf->m_pack = rbuf->fmp = NULL;
+
+			if (sendmp != NULL) /* secondary frag */
 				sendmp->m_pkthdr.len += mp->m_len;
-				sendmp->m_nextpkt = NULL;
-			} else { 
+			else {
 				/* first desc of a non-ps chain */
 				sendmp = mp;
 				sendmp->m_flags |= M_PKTHDR;
@@ -4233,106 +4120,53 @@ ixgbe_rxeof(struct rx_ring *rxr, int count)
 					sendmp->m_pkthdr.ether_vtag = vtag;
 					sendmp->m_flags |= M_VLANTAG;
 				}
-			}
-			/* Carry head forward */
+                        }
+			/* Pass the head pointer on */
 			if (eop == 0) {
-				nh = rxr->rx_buffers[nextp].m_head;
-				np = rxr->rx_buffers[nextp].m_pack;
-				nh->m_nextpkt = sendmp;
-				mp->m_next = np;
+				nbuf->fmp = sendmp;
 				sendmp = NULL;
+				mp->m_next = nbuf->m_pack;
 			}
-			mh->m_nextpkt = NULL;
 		}
-
-		if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)
-			accept_frame = FALSE;
-
-		if (accept_frame) {
-			++processed;
-			if (eop) {
-				--count;
-				sendmp->m_pkthdr.rcvif = ifp;
-				ifp->if_ipackets++;
-				rxr->rx_packets++;
-				/* capture data for AIM */
-				rxr->bytes += sendmp->m_pkthdr.len;
-				rxr->rx_bytes += rxr->bytes;
-				if (ifp->if_capenable & IFCAP_RXCSUM)
-					ixgbe_rx_checksum(staterr, sendmp);
-				else
-					sendmp->m_pkthdr.csum_flags = 0;
+		++processed;
+		/* Sending this frame? */
+		if (eop) {
+			sendmp->m_pkthdr.rcvif = ifp;
+			ifp->if_ipackets++;
+			rxr->rx_packets++;
+			/* capture data for AIM */
+			rxr->bytes += sendmp->m_pkthdr.len;
+			rxr->rx_bytes += sendmp->m_pkthdr.len;
+			if ((ifp->if_capenable & IFCAP_RXCSUM) != 0)
+				ixgbe_rx_checksum(staterr, sendmp);
 #if __FreeBSD_version >= 800000
-				/* Get the RSS Hash */
-				sendmp->m_pkthdr.flowid =
-				    le16toh(cur->wb.lower.hi_dword.rss);
-				sendmp->m_flags |= M_FLOWID;
+			sendmp->m_pkthdr.flowid = que->msix;
+			sendmp->m_flags |= M_FLOWID;
 #endif
-			}
-		} else {
-			ifp->if_ierrors++;
-			/* Reuse loaded DMA map and just update mbuf chain */
-			mh->m_len = MHLEN;
-			mh->m_flags |= M_PKTHDR;
-			mh->m_next = NULL;
-			mp->m_len = mp->m_pkthdr.len = adapter->rx_mbuf_sz;
-			mp->m_data = mp->m_ext.ext_buf;
-			if (mp->m_next) { /* Free chain */
-				sendmp = mp->m_next;
-				m_free(sendmp);
-			}
-			mp->m_next = NULL;
-			if (adapter->max_frame_size <=
-			    (MCLBYTES - ETHER_ALIGN))
-				m_adj(mp, ETHER_ALIGN);
-			sendmp = NULL;
 		}
+next_desc:
 		bus_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
 		    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
 
-		rxr->last_refreshed = i; /* for updating tail */
+		/* Advance our pointers to the next descriptor. */
 		if (++i == adapter->num_rx_desc)
 			i = 0;
-		/* Prefetch next descriptor */
-		cur = &rxr->rx_base[i];
-		prefetch(cur);
 
-		/*
-		** Now send up to the stack,
-		** note that the RX lock is
-		** held thru this call.
-		*/
-                if (sendmp != NULL) {
-			/*
-			** Send to the stack if:
-			**  - Soft LRO not enabled, or
-			**  - no Soft LRO resources, or
-			**  - soft lro enqueue fails
-			*/
-			if ((!rxr->lro_enabled) ||
-			    ((!lro->lro_cnt) || (tcp_lro_rx(lro, sendmp, 0))))
-	                        (*ifp->if_input)(ifp, sendmp);
-                }
+		/* Now send to the stack or do LRO */
+		if (sendmp != NULL)
+			ixgbe_rx_input(rxr, ifp, sendmp, ptype);
 
-		/* Replenish every 8 max */
+               /* Every 8 descriptors we go to refresh mbufs */
 		if (processed == 8) {
-			ixgbe_get_buf(rxr, rxr->next_to_check, i);
+			ixgbe_refresh_mbufs(rxr, i);
 			processed = 0;
-			IXGBE_WRITE_REG(&adapter->hw,
-			    IXGBE_RDT(rxr->me), rxr->last_refreshed);
-			rxr->next_to_check = i;
 		}
-
-		/* Next iteration */
-		staterr = cur->wb.upper.status_error;
 	}
 
-	/* Replenish remaining work */
+	/* Refresh any remaining buf structs */
 	if (processed != 0) {
-		ixgbe_get_buf(rxr, rxr->next_to_check, i);
+		ixgbe_refresh_mbufs(rxr, i);
 		processed = 0;
-		IXGBE_WRITE_REG(&adapter->hw,
-		    IXGBE_RDT(rxr->me), rxr->last_refreshed);
 	}
 
 	rxr->next_to_check = i;
@@ -4340,8 +4174,7 @@ ixgbe_rxeof(struct rx_ring *rxr, int count)
 	/*
 	 * Flush any outstanding LRO work
 	 */
-	while (!SLIST_EMPTY(&lro->lro_active)) {
-		queued = SLIST_FIRST(&lro->lro_active);
+	while ((queued = SLIST_FIRST(&lro->lro_active)) != NULL) {
 		SLIST_REMOVE_HEAD(&lro->lro_active, next);
 		tcp_lro_flush(lro, queued);
 	}
@@ -4349,17 +4182,18 @@ ixgbe_rxeof(struct rx_ring *rxr, int count)
 	IXGBE_RX_UNLOCK(rxr);
 
 	/*
-	** Leaving with more to clean?
-	** then schedule another interrupt.
+	** We still have cleaning to do?
+	** Schedule another interrupt if so.
 	*/
-	if (staterr & IXGBE_RXD_STAT_DD) {
-        	ixgbe_rearm_queues(adapter, (u64)(1 << rxr->msix));
-		return TRUE;
+	if ((staterr & IXGBE_RXD_STAT_DD) != 0) {
+		ixgbe_rearm_queues(adapter, (u64)(1 << que->msix));
+		return (TRUE);
 	}
 
-	return FALSE;
+	return (FALSE);
 }
 
+
 /*********************************************************************
  *
  *  Verify that the hardware indicated that the checksum is valid.
@@ -4374,7 +4208,6 @@ ixgbe_rx_checksum(u32 staterr, struct mbuf * mp)
 	u8  errors = (u8) (staterr >> 24);
 
 	if (status & IXGBE_RXD_STAT_IPCS) {
-		/* Did it pass? */
 		if (!(errors & IXGBE_RXD_ERR_IPE)) {
 			/* IP Checksum Good */
 			mp->m_pkthdr.csum_flags = CSUM_IP_CHECKED;
@@ -4384,7 +4217,6 @@ ixgbe_rx_checksum(u32 staterr, struct mbuf * mp)
 			mp->m_pkthdr.csum_flags = 0;
 	}
 	if (status & IXGBE_RXD_STAT_L4CS) {
-		/* Did it pass? */
 		if (!(errors & IXGBE_RXD_ERR_TCPE)) {
 			mp->m_pkthdr.csum_flags |=
 				(CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
@@ -4493,8 +4325,7 @@ static void
 ixgbe_enable_intr(struct adapter *adapter)
 {
 	struct ixgbe_hw *hw = &adapter->hw;
-	struct tx_ring *txr = adapter->tx_rings;
-	struct rx_ring *rxr = adapter->rx_rings;
+	struct ix_queue *que = adapter->queues;
 	u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
 
 
@@ -4528,10 +4359,8 @@ ixgbe_enable_intr(struct adapter *adapter)
 	** allow for handling the extended (beyond 32) MSIX
 	** vectors that can be used by 82599
 	*/
-        for (int i = 0; i < adapter->num_queues; i++, rxr++)
-                ixgbe_enable_queue(adapter, rxr->msix);
-        for (int i = 0; i < adapter->num_queues; i++, txr++)
-		ixgbe_enable_queue(adapter, txr->msix);
+        for (int i = 0; i < adapter->num_queues; i++, que++)
+                ixgbe_enable_queue(adapter, que->msix);
 
 	IXGBE_WRITE_FLUSH(hw);
 
@@ -4626,14 +4455,17 @@ ixgbe_set_ivar(struct adapter *adapter, u8 entry, u8 vector, s8 type)
 static void
 ixgbe_configure_ivars(struct adapter *adapter)
 {
-	struct  tx_ring *txr = adapter->tx_rings;
-	struct  rx_ring *rxr = adapter->rx_rings;
+	struct  ix_queue *que = adapter->queues;
 
-        for (int i = 0; i < adapter->num_queues; i++, rxr++)
-                ixgbe_set_ivar(adapter, i, rxr->msix, 0);
-
-        for (int i = 0; i < adapter->num_queues; i++, txr++)
-		ixgbe_set_ivar(adapter, i, txr->msix, 1);
+        for (int i = 0; i < adapter->num_queues; i++, que++) {
+		/* First the RX queue entry */
+                ixgbe_set_ivar(adapter, i, que->msix, 0);
+		/* ... and the TX */
+		ixgbe_set_ivar(adapter, i, que->msix, 1);
+		/* Set an Initial EITR value */
+                IXGBE_WRITE_REG(&adapter->hw,
+                    IXGBE_EITR(que->msix), IXGBE_LOW_LATENCY);
+	}
 
 	/* For the Link interrupt */
         ixgbe_set_ivar(adapter, 1, adapter->linkvec, -1);
@@ -4922,44 +4754,43 @@ static void
 ixgbe_print_debug_info(struct adapter *adapter)
 {
 	device_t dev = adapter->dev;
-	struct rx_ring *rxr = adapter->rx_rings;
-	struct tx_ring *txr = adapter->tx_rings;
-	struct ixgbe_hw *hw = &adapter->hw;
+	struct ixgbe_hw		*hw = &adapter->hw;
+	struct ix_queue		*que = adapter->queues;
+	struct rx_ring		*rxr;
+	struct tx_ring		*txr;
+	struct lro_ctrl		*lro;
  
 	device_printf(dev,"Error Byte Count = %u \n",
 	    IXGBE_READ_REG(hw, IXGBE_ERRBC));
 
-	for (int i = 0; i < adapter->num_queues; i++, rxr++) {
-		struct lro_ctrl		*lro = &rxr->lro;
-		device_printf(dev,"Queue[%d]: rdh = %d, hw rdt = %d\n",
+	for (int i = 0; i < adapter->num_queues; i++, que++) {
+		txr = que->txr;
+		rxr = que->rxr;
+		lro = &rxr->lro;
+		device_printf(dev,"QUE(%d) IRQs Handled: %lu\n",
+		    que->msix, (long)que->irqs);
+		device_printf(dev,"RX[%d]: rdh = %d, hw rdt = %d\n",
 	    	    i, IXGBE_READ_REG(hw, IXGBE_RDH(i)),
 	    	    IXGBE_READ_REG(hw, IXGBE_RDT(i)));
+		device_printf(dev,"TX[%d] tdh = %d, hw tdt = %d\n", i,
+		    IXGBE_READ_REG(hw, IXGBE_TDH(i)),
+		    IXGBE_READ_REG(hw, IXGBE_TDT(i)));
 		device_printf(dev,"RX(%d) Packets Received: %lld\n",
 	    	    rxr->me, (long long)rxr->rx_packets);
 		device_printf(dev,"RX(%d) Split RX Packets: %lld\n",
 	    	    rxr->me, (long long)rxr->rx_split_packets);
 		device_printf(dev,"RX(%d) Bytes Received: %lu\n",
 	    	    rxr->me, (long)rxr->rx_bytes);
-		device_printf(dev,"RX(%d) IRQ Handled: %lu\n",
-	    	    rxr->me, (long)rxr->rx_irq);
 		device_printf(dev,"RX(%d) LRO Queued= %d\n",
 		    rxr->me, lro->lro_queued);
 		device_printf(dev,"RX(%d) LRO Flushed= %d\n",
 		    rxr->me, lro->lro_flushed);
 		device_printf(dev,"RX(%d) HW LRO Merges= %lu\n",
 		    rxr->me, (long)rxr->rsc_num);
-	}
-
-	for (int i = 0; i < adapter->num_queues; i++, txr++) {
-		device_printf(dev,"Queue(%d) tdh = %d, hw tdt = %d\n", i,
-		    IXGBE_READ_REG(hw, IXGBE_TDH(i)),
-		    IXGBE_READ_REG(hw, IXGBE_TDT(i)));
 		device_printf(dev,"TX(%d) Packets Sent: %lu\n",
 		    txr->me, (long)txr->total_packets);
-		device_printf(dev,"TX(%d) IRQ Handled: %lu\n",
-		    txr->me, (long)txr->tx_irq);
 		device_printf(dev,"TX(%d) NO Desc Avail: %lu\n",
-		    txr->me, (long)txr->no_tx_desc_avail);
+		    txr->me, (long)txr->no_desc_avail);
 	}
 
 	device_printf(dev,"Link IRQ Handled: %lu\n",
@@ -5050,174 +4881,3 @@ ixgbe_add_rx_process_limit(struct adapter *adapter, const char *name,
             SYSCTL_CHILDREN(device_get_sysctl_tree(adapter->dev)),
             OID_AUTO, name, CTLTYPE_INT|CTLFLAG_RW, limit, value, description);
 }
-
-#ifdef IXGBE_IEEE1588
-
-/*
-** ixgbe_hwtstamp_ioctl - control hardware time stamping
-**
-** Outgoing time stamping can be enabled and disabled. Play nice and
-** disable it when requested, although it shouldn't case any overhead
-** when no packet needs it. At most one packet in the queue may be
-** marked for time stamping, otherwise it would be impossible to tell
-** for sure to which packet the hardware time stamp belongs.
-**
-** Incoming time stamping has to be configured via the hardware
-** filters. Not all combinations are supported, in particular event
-** type has to be specified. Matching the kind of event packet is
-** not supported, with the exception of "all V2 events regardless of
-** level 2 or 4".
-**
-*/
-static int
-ixgbe_hwtstamp_ioctl(struct adapter *adapter, struct ifreq *ifr)
-{
-	struct ixgbe_hw *hw = &adapter->hw;
-	struct hwtstamp_ctrl *config;
-	u32 tsync_tx_ctl_bit = IXGBE_TSYNCTXCTL_ENABLED;
-	u32 tsync_rx_ctl_bit = IXGBE_TSYNCRXCTL_ENABLED;
-	u32 tsync_rx_ctl_type = 0;
-	u32 tsync_rx_cfg = 0;
-	int is_l4 = 0;
-	int is_l2 = 0;
-	u16 port = 319; /* PTP */
-	u32 regval;
-
-	config = (struct hwtstamp_ctrl *) ifr->ifr_data;
-
-	/* reserved for future extensions */
-	if (config->flags)
-		return (EINVAL);
-
-	switch (config->tx_type) {
-	case HWTSTAMP_TX_OFF:
-		tsync_tx_ctl_bit = 0;
-		break;
-	case HWTSTAMP_TX_ON:
-		tsync_tx_ctl_bit = IXGBE_TSYNCTXCTL_ENABLED;
-		break;
-	default:
-		return (ERANGE);
-	}
-
-	switch (config->rx_filter) {
-	case HWTSTAMP_FILTER_NONE:
-		tsync_rx_ctl_bit = 0;
-		break;
-	case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
-	case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
-	case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
-	case HWTSTAMP_FILTER_ALL:
-		/*
-		 * register TSYNCRXCFG must be set, therefore it is not
-		 * possible to time stamp both Sync and Delay_Req messages
-		 * => fall back to time stamping all packets
-		 */
-		tsync_rx_ctl_type = IXGBE_TSYNCRXCTL_TYPE_ALL;
-		config->rx_filter = HWTSTAMP_FILTER_ALL;
-		break;
-	case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
-		tsync_rx_ctl_type = IXGBE_TSYNCRXCTL_TYPE_L4_V1;
-		tsync_rx_cfg = IXGBE_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE;
-		is_l4 = 1;
-		break;
-	case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
-		tsync_rx_ctl_type = IXGBE_TSYNCRXCTL_TYPE_L4_V1;
-		tsync_rx_cfg = IXGBE_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE;
-		is_l4 = 1;
-		break;
-	case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
-	case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
-		tsync_rx_ctl_type = IXGBE_TSYNCRXCTL_TYPE_L2_L4_V2;
-		tsync_rx_cfg = IXGBE_TSYNCRXCFG_PTP_V2_SYNC_MESSAGE;
-		is_l2 = 1;
-		is_l4 = 1;
-		config->rx_filter = HWTSTAMP_FILTER_SOME;
-		break;
-	case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
-	case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
-		tsync_rx_ctl_type = IXGBE_TSYNCRXCTL_TYPE_L2_L4_V2;
-		tsync_rx_cfg = IXGBE_TSYNCRXCFG_PTP_V2_DELAY_REQ_MESSAGE;
-		is_l2 = 1;
-		is_l4 = 1;
-		config->rx_filter = HWTSTAMP_FILTER_SOME;
-		break;
-	case HWTSTAMP_FILTER_PTP_V2_EVENT:
-	case HWTSTAMP_FILTER_PTP_V2_SYNC:
-	case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
-		tsync_rx_ctl_type = IXGBE_TSYNCRXCTL_TYPE_EVENT_V2;
-		config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
-		is_l2 = 1;
-		break;
-	default:
-		return -ERANGE;
-	}
-
-	/* enable/disable TX */
-	regval = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
-	regval = (regval & ~IXGBE_TSYNCTXCTL_ENABLED) | tsync_tx_ctl_bit;
-	IXGBE_WRITE_REG(hw, IXGBE_TSYNCTXCTL, regval);
-
-	/* enable/disable RX, define which PTP packets are time stamped */
-	regval = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
-	regval = (regval & ~IXGBE_TSYNCRXCTL_ENABLED) | tsync_rx_ctl_bit;
-	regval = (regval & ~0xE) | tsync_rx_ctl_type;
-	IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, regval);
-	IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCFG, tsync_rx_cfg);
-
-	/*
-	 * Ethertype Filter Queue Filter[0][15:0] = 0x88F7
-	 *                                          (Ethertype to filter on)
-	 * Ethertype Filter Queue Filter[0][26] = 0x1 (Enable filter)
-	 * Ethertype Filter Queue Filter[0][30] = 0x1 (Enable Timestamping)
-	 */
-	IXGBE_WRITE_REG(hw, IXGBE_ETQF0, is_l2 ? 0x440088f7 : 0);
-
-	/* L4 Queue Filter[0]: only filter by source and destination port */
-	IXGBE_WRITE_REG(hw, IXGBE_SPQF0, htons(port));
-	IXGBE_WRITE_REG(hw, IXGBE_IMIREXT(0), is_l4 ?
-	     ((1<<12) | (1<<19) /* bypass size and control flags */) : 0);
-	IXGBE_WRITE_REG(hw, IXGBE_IMIR(0), is_l4 ?
-	     (htons(port)
-	      | (0<<16) /* immediate interrupt disabled */
-	      | 0 /* (1<<17) bit cleared: do not bypass
-		     destination port check */)
-		: 0);
-	IXGBE_WRITE_REG(hw, IXGBE_FTQF0, is_l4 ?
-	     (0x11 /* UDP */
-	      | (1<<15) /* VF not compared */
-	      | (1<<27) /* Enable Timestamping */
-	      | (7<<28) /* only source port filter enabled,
-			   source/target address and protocol
-			   masked */)
-	     : ((1<<15) | (15<<28) /* all mask bits set = filter not
-				      enabled */));
-
-	wrfl();
-
-	adapter->hwtstamp_ctrl = config;
-
-	/* clear TX/RX time stamp registers, just to be sure */
-	regval = IXGBE_READ_REG(hw, IXGBE_TXSTMPH);
-	regval = IXGBE_READ_REG(hw, IXGBE_RXSTMPH);
-
-	return (error);
-}
-
-/*
-** ixgbe_read_clock - read raw cycle counter (to be used by time counter)
-*/
-static cycle_t ixgbe_read_clock(const struct cyclecounter *tc)
-{
-       struct adapter *adapter =
-               container_of(tc, struct igb_adapter, cycles);
-       struct ixgbe_hw *hw = &adapter->hw;
-       u64 stamp;
-
-       stamp =  IXGBE_READ_REG(hw, IXGBE_SYSTIML);
-       stamp |= (u64)IXGBE_READ_REG(hw, IXGBE_SYSTIMH) << 32ULL;
-
-       return (stamp);
-}
-
-#endif /* IXGBE_IEEE1588 */
diff --git a/sys/dev/ixgbe/ixgbe.h b/sys/dev/ixgbe/ixgbe.h
index d52eed3a07e..008d2c8cb01 100644
--- a/sys/dev/ixgbe/ixgbe.h
+++ b/sys/dev/ixgbe/ixgbe.h
@@ -1,6 +1,6 @@
 /******************************************************************************
 
-  Copyright (c) 2001-2009, Intel Corporation 
+  Copyright (c) 2001-2010, Intel Corporation 
   All rights reserved.
   
   Redistribution and use in source and binary forms, with or without 
@@ -176,7 +176,7 @@
 #define MSIX_82599_BAR			4
 #define IXGBE_TSO_SIZE			65535
 #define IXGBE_TX_BUFFER_SIZE		((u32) 1514)
-#define IXGBE_RX_HDR			256
+#define IXGBE_RX_HDR			128
 #define IXGBE_VFTA_SIZE			128
 #define IXGBE_BR_SIZE			4096
 #define CSUM_OFFLOAD			7	/* Bits in csum flags */
@@ -231,6 +231,7 @@ struct ixgbe_tx_buf {
 struct ixgbe_rx_buf {
 	struct mbuf	*m_head;
 	struct mbuf	*m_pack;
+	struct mbuf	*fmp;
 	bus_dmamap_t	map;
 };
 
@@ -248,20 +249,34 @@ struct ixgbe_dma_alloc {
 };
 
 /*
- * The transmit ring, one per tx queue
+** Driver queue struct: this is the interrupt container
+**  for the associated tx and rx ring.
+*/
+struct ix_queue {
+	struct adapter		*adapter;
+	u32			msix;           /* This queue's MSIX vector */
+	u32			eims;           /* This queue's EIMS bit */
+	u32			eitr_setting;
+	struct resource		*res;
+	void			*tag;
+	struct tx_ring		*txr;
+	struct rx_ring		*rxr;
+	struct task		que_task;
+	struct taskqueue	*tq;
+	u64			irqs;
+};
+
+/*
+ * The transmit ring, one per queue
  */
 struct tx_ring {
         struct adapter		*adapter;
 	struct mtx		tx_mtx;
 	u32			me;
-	u32			msix;
 	bool			watchdog_check;
 	int			watchdog_time;
 	union ixgbe_adv_tx_desc	*tx_base;
-	volatile u32		tx_hwb;
 	struct ixgbe_dma_alloc	txdma;
-	struct task     	tx_task;
-	struct taskqueue	*tq;
 	u32			next_avail_desc;
 	u32			next_to_clean;
 	struct ixgbe_tx_buf	*tx_buffers;
@@ -272,17 +287,14 @@ struct tx_ring {
 #if __FreeBSD_version >= 800000
 	struct buf_ring		*br;
 #endif
-	/* Interrupt resources */
-	void			*tag;
-	struct resource		*res;
 #ifdef IXGBE_FDIR
 	u16			atr_sample;
 	u16			atr_count;
 #endif
+	u32			bytes;  /* used for AIM */
+	u32			packets;
 	/* Soft Stats */
-	u32			no_tx_desc_avail;
-	u32			no_tx_desc_late;
-	u64			tx_irq;
+	u64			no_desc_avail;
 	u64			total_packets;
 };
 
@@ -294,35 +306,29 @@ struct rx_ring {
         struct adapter		*adapter;
 	struct mtx		rx_mtx;
 	u32			me;
-	u32			msix;
-	u32			payload;
-	struct task     	rx_task;
-	struct taskqueue	*tq;
 	union ixgbe_adv_rx_desc	*rx_base;
 	struct ixgbe_dma_alloc	rxdma;
 	struct lro_ctrl		lro;
 	bool			lro_enabled;
 	bool			hdr_split;
 	bool			hw_rsc;
-        unsigned int		last_refreshed;
-        unsigned int		next_to_check;
+	bool			discard;
+        u32			next_to_refresh;
+        u32 			next_to_check;
+	char			mtx_name[16];
 	struct ixgbe_rx_buf	*rx_buffers;
 	bus_dma_tag_t		rxtag;
 	bus_dmamap_t		spare_map;
-	char			mtx_name[16];
 
 	u32			bytes; /* Used for AIM calc */
-	u32			eitr_setting;
-
-	/* Interrupt resources */
-	void			*tag;
-	struct resource		*res;
+	u32			packets;
 
 	/* Soft stats */
 	u64			rx_irq;
 	u64			rx_split_packets;
 	u64			rx_packets;
 	u64 			rx_bytes;
+	u64 			rx_discarded;
 	u64 			rsc_num;
 #ifdef IXGBE_FDIR
 	u64			flm;
@@ -331,94 +337,94 @@ struct rx_ring {
 
 /* Our adapter structure */
 struct adapter {
-	struct ifnet	*ifp;
-	struct ixgbe_hw	hw;
+	struct ifnet		*ifp;
+	struct ixgbe_hw		hw;
 
 	struct ixgbe_osdep	osdep;
-	struct device	*dev;
+	struct device		*dev;
 
-	struct resource	*pci_mem;
-	struct resource	*msix_mem;
+	struct resource		*pci_mem;
+	struct resource		*msix_mem;
 
 	/*
 	 * Interrupt resources: this set is
 	 * either used for legacy, or for Link
 	 * when doing MSIX
 	 */
-	void		*tag;
-	struct resource *res;
+	void			*tag;
+	struct resource 	*res;
 
-	struct ifmedia	media;
-	struct callout	timer;
-	int		msix;
-	int		if_flags;
+	struct ifmedia		media;
+	struct callout		timer;
+	int			msix;
+	int			if_flags;
 
-	struct mtx	core_mtx;
+	struct mtx		core_mtx;
 
-	eventhandler_tag vlan_attach;
-	eventhandler_tag vlan_detach;
+	eventhandler_tag 	vlan_attach;
+	eventhandler_tag 	vlan_detach;
 
-	u16		num_vlans;
-	u16		num_queues;
+	u16			num_vlans;
+	u16			num_queues;
 
 	/* Info about the board itself */
-	u32		optics;
-	bool		link_active;
-	u16		max_frame_size;
-	u32		link_speed;
-	bool		link_up;
-	u32 		linkvec;
+	u32			optics;
+	bool			link_active;
+	u16			max_frame_size;
+	u32			link_speed;
+	bool			link_up;
+	u32 			linkvec;
 
 	/* Mbuf cluster size */
-	u32		rx_mbuf_sz;
+	u32			rx_mbuf_sz;
 
 	/* Support for pluggable optics */
-	bool		sfp_probe;
-	struct task     link_task; 	/* Link tasklet */
-	struct task     mod_task; 	/* SFP tasklet */
-	struct task     msf_task; 	/* Multispeed Fiber tasklet */
+	bool			sfp_probe;
+	struct task     	link_task;  /* Link tasklet */
+	struct task     	mod_task;   /* SFP tasklet */
+	struct task     	msf_task;   /* Multispeed Fiber */
 #ifdef IXGBE_FDIR
 	int			fdir_reinit;
 	struct task     	fdir_task;
 #endif
 	struct taskqueue	*tq;
 
+	/*
+	** Queues: 
+	**   This is the irq holder, it has
+	**   and RX/TX pair or rings associated
+	**   with it.
+	*/
+	struct ix_queue		*queues;
+
 	/*
 	 * Transmit rings:
 	 *	Allocated at run time, an array of rings.
 	 */
-	struct tx_ring	*tx_rings;
-	int		num_tx_desc;
+	struct tx_ring		*tx_rings;
+	int			num_tx_desc;
 
 	/*
 	 * Receive rings:
 	 *	Allocated at run time, an array of rings.
 	 */
-	struct rx_ring	*rx_rings;
-	int		num_rx_desc;
-	u64		rx_mask;
-	u32		rx_process_limit;
-
-#ifdef IXGBE_IEEE1588
-	/* IEEE 1588 precision time support */
-	struct cyclecounter     cycles;
-	struct nettimer         clock;
-	struct nettime_compare  compare;
-	struct hwtstamp_ctrl    hwtstamp;
-#endif
+	struct rx_ring		*rx_rings;
+	int			num_rx_desc;
+	u64			que_mask;
+	u32			rx_process_limit;
 
 	/* Misc stats maintained by the driver */
-	unsigned long   dropped_pkts;
-	unsigned long   mbuf_defrag_failed;
-	unsigned long   mbuf_header_failed;
-	unsigned long   mbuf_packet_failed;
-	unsigned long   no_tx_map_avail;
-	unsigned long   no_tx_dma_setup;
-	unsigned long   watchdog_events;
-	unsigned long   tso_tx;
-	unsigned long	link_irq;
+	unsigned long   	dropped_pkts;
+	unsigned long   	mbuf_defrag_failed;
+	unsigned long   	mbuf_header_failed;
+	unsigned long   	mbuf_packet_failed;
+	unsigned long   	no_tx_map_avail;
+	unsigned long   	no_tx_dma_setup;
+	unsigned long   	watchdog_events;
+	unsigned long   	tso_tx;
+	unsigned long		link_irq;
 
-	struct ixgbe_hw_stats stats;
+	struct ixgbe_hw_stats 	stats;
 };
 
 /* Precision Time Sync (IEEE 1588) defines */
@@ -452,8 +458,8 @@ ixgbe_is_sfp(struct ixgbe_hw *hw)
 	case ixgbe_phy_sfp_ftl:
 	case ixgbe_phy_sfp_intel:
 	case ixgbe_phy_sfp_unknown:
-	case ixgbe_phy_tw_tyco:
-	case ixgbe_phy_tw_unknown:
+	case ixgbe_phy_sfp_passive_tyco:
+	case ixgbe_phy_sfp_passive_unknown:
 		return TRUE;
 	default:
 		return FALSE;
diff --git a/sys/dev/ixgbe/ixgbe_82598.c b/sys/dev/ixgbe/ixgbe_82598.c
index 12711b0a9b4..0570aa5c588 100644
--- a/sys/dev/ixgbe/ixgbe_82598.c
+++ b/sys/dev/ixgbe/ixgbe_82598.c
@@ -1,6 +1,6 @@
 /******************************************************************************
 
-  Copyright (c) 2001-2009, Intel Corporation 
+  Copyright (c) 2001-2010, Intel Corporation 
   All rights reserved.
   
   Redistribution and use in source and binary forms, with or without 
@@ -59,6 +59,7 @@ static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw,
                                                bool autoneg_wait_to_complete);
 static s32 ixgbe_reset_hw_82598(struct ixgbe_hw *hw);
 s32 ixgbe_start_hw_82598(struct ixgbe_hw *hw);
+void ixgbe_enable_relaxed_ordering_82598(struct ixgbe_hw *hw);
 s32 ixgbe_set_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq);
 static s32 ixgbe_clear_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq);
 s32 ixgbe_set_vfta_82598(struct ixgbe_hw *hw, u32 vlan,
@@ -164,6 +165,7 @@ s32 ixgbe_init_ops_82598(struct ixgbe_hw *hw)
 
 	/* MAC */
 	mac->ops.start_hw = &ixgbe_start_hw_82598;
+	mac->ops.enable_relaxed_ordering = &ixgbe_enable_relaxed_ordering_82598;
 	mac->ops.reset_hw = &ixgbe_reset_hw_82598;
 	mac->ops.get_media_type = &ixgbe_get_media_type_82598;
 	mac->ops.get_supported_physical_layer =
@@ -273,7 +275,8 @@ out:
  *  @hw: pointer to hardware structure
  *
  *  Starts the hardware using the generic start_hw function.
- *  Then set pcie completion timeout
+ *  Disables relaxed ordering Then set pcie completion timeout
+ *
  **/
 s32 ixgbe_start_hw_82598(struct ixgbe_hw *hw)
 {
@@ -287,17 +290,17 @@ s32 ixgbe_start_hw_82598(struct ixgbe_hw *hw)
 
 	/* Disable relaxed ordering */
 	for (i = 0; ((i < hw->mac.max_tx_queues) &&
-		     (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) {
+	     (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) {
 		regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i));
 		regval &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
 		IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(i), regval);
 	}
 
 	for (i = 0; ((i < hw->mac.max_rx_queues) &&
-		     (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) {
+	     (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) {
 		regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
 		regval &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
-			    IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
+		            IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
 		IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
 	}
 
@@ -439,15 +442,23 @@ s32 ixgbe_fc_enable_82598(struct ixgbe_hw *hw, s32 packetbuf_num)
 	DEBUGFUNC("ixgbe_fc_enable_82598");
 
 	/*
-	 * On 82598 backplane having FC on causes resets while doing
-	 * KX, so turn off here.
+	 * On 82598 having Rx FC on causes resets while doing 1G
+	 * so if it's on turn it off once we know link_speed. For
+	 * more details see 82598 Specification update.
 	 */
 	hw->mac.ops.check_link(hw, &link_speed, &link_up, FALSE);
-	if (link_up &&
-	    link_speed == IXGBE_LINK_SPEED_1GB_FULL &&
-	    hw->mac.ops.get_media_type(hw) == ixgbe_media_type_backplane) {
-		hw->fc.disable_fc_autoneg = TRUE;
-		hw->fc.requested_mode = ixgbe_fc_none;
+	if (link_up && link_speed == IXGBE_LINK_SPEED_1GB_FULL) {
+		switch (hw->fc.requested_mode) {
+		case ixgbe_fc_full:
+			hw->fc.requested_mode = ixgbe_fc_tx_pause;
+			break;
+		case ixgbe_fc_rx_pause:
+			hw->fc.requested_mode = ixgbe_fc_none;
+			break;
+		default:
+			/* no change */
+			break;
+		}
 	}
 
 	/* Negotiate the fc mode to use */
@@ -842,12 +853,9 @@ no_phy_reset:
 	 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
 	 * access and verify no pending requests before reset
 	 */
-	status = ixgbe_disable_pcie_master(hw);
-	if (status != IXGBE_SUCCESS) {
-		status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
-		DEBUGOUT("PCI-E Master disable polling has failed.\n");
-	}
+	ixgbe_disable_pcie_master(hw);
 
+mac_reset_top:
 	/*
 	 * Issue global reset to the MAC.  This needs to be a SW reset.
 	 * If link reset is used, it might reset the MAC when mng is using it
@@ -868,6 +876,19 @@ no_phy_reset:
 		DEBUGOUT("Reset polling failed to complete.\n");
 	}
 
+	/*
+	 * Double resets are required for recovery from certain error
+	 * conditions.  Between resets, it is necessary to stall to allow time
+	 * for any pending HW events to complete.  We use 1usec since that is
+	 * what is needed for ixgbe_disable_pcie_master().  The second reset
+	 * then clears out any effects of those events.
+	 */
+	if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
+		hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
+		usec_delay(1);
+		goto mac_reset_top;
+	}
+
 	msec_delay(50);
 
 	gheccr = IXGBE_READ_REG(hw, IXGBE_GHECCR);
@@ -1299,3 +1320,32 @@ static s32 ixgbe_validate_link_ready(struct ixgbe_hw *hw)
 	return IXGBE_SUCCESS;
 }
 
+/**
+ *  ixgbe_enable_relaxed_ordering_82598 - enable relaxed ordering
+ *  @hw: pointer to hardware structure
+ *
+ **/
+void ixgbe_enable_relaxed_ordering_82598(struct ixgbe_hw *hw)
+{
+	u32 regval;
+	u32 i;
+
+	DEBUGFUNC("ixgbe_enable_relaxed_ordering_82598");
+
+	/* Enable relaxed ordering */
+	for (i = 0; ((i < hw->mac.max_tx_queues) &&
+	     (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) {
+		regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i));
+		regval |= IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
+		IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(i), regval);
+	}
+
+	for (i = 0; ((i < hw->mac.max_rx_queues) &&
+	     (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) {
+		regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
+		regval |= (IXGBE_DCA_RXCTRL_DESC_WRO_EN |
+		           IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
+		IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
+	}
+
+}
diff --git a/sys/dev/ixgbe/ixgbe_82599.c b/sys/dev/ixgbe/ixgbe_82599.c
index 97b655a26ac..8c5ff21200d 100644
--- a/sys/dev/ixgbe/ixgbe_82599.c
+++ b/sys/dev/ixgbe/ixgbe_82599.c
@@ -1,6 +1,6 @@
 /******************************************************************************
 
-  Copyright (c) 2001-2009, Intel Corporation 
+  Copyright (c) 2001-2010, Intel Corporation 
   All rights reserved.
   
   Redistribution and use in source and binary forms, with or without 
@@ -64,6 +64,7 @@ s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw);
 s32 ixgbe_read_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 *val);
 s32 ixgbe_write_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 val);
 s32 ixgbe_start_hw_rev_1_82599(struct ixgbe_hw *hw);
+void ixgbe_enable_relaxed_ordering_82599(struct ixgbe_hw *hw);
 s32 ixgbe_identify_phy_82599(struct ixgbe_hw *hw);
 s32 ixgbe_init_phy_ops_82599(struct ixgbe_hw *hw);
 u32 ixgbe_get_supported_physical_layer_82599(struct ixgbe_hw *hw);
@@ -267,6 +268,8 @@ s32 ixgbe_get_link_capabilities_82599(struct ixgbe_hw *hw,
 
 	DEBUGFUNC("ixgbe_get_link_capabilities_82599");
 
+
+
 	/*
 	 * Determine link capabilities based on the stored value of AUTOC,
 	 * which represents EEPROM defaults.  If AUTOC value has not
@@ -878,7 +881,7 @@ static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
 s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw)
 {
 	s32 status = IXGBE_SUCCESS;
-	u32 ctrl, ctrl_ext;
+	u32 ctrl;
 	u32 i;
 	u32 autoc;
 	u32 autoc2;
@@ -913,12 +916,9 @@ s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw)
 	 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
 	 * access and verify no pending requests before reset
 	 */
-	status = ixgbe_disable_pcie_master(hw);
-	if (status != IXGBE_SUCCESS) {
-		status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
-		DEBUGOUT("PCI-E Master disable polling has failed.\n");
-	}
+	ixgbe_disable_pcie_master(hw);
 
+mac_reset_top:
 	/*
 	 * Issue global reset to the MAC.  This needs to be a SW reset.
 	 * If link reset is used, it might reset the MAC when mng is using it
@@ -938,10 +938,19 @@ s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw)
 		status = IXGBE_ERR_RESET_FAILED;
 		DEBUGOUT("Reset polling failed to complete.\n");
 	}
-	/* Clear PF Reset Done bit so PF/VF Mail Ops can work */
-	ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
-	ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
-	IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
+
+	/*
+	 * Double resets are required for recovery from certain error
+	 * conditions.  Between resets, it is necessary to stall to allow time
+	 * for any pending HW events to complete.  We use 1usec since that is
+	 * what is needed for ixgbe_disable_pcie_master().  The second reset
+	 * then clears out any effects of those events.
+	 */
+	if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
+		hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
+		usec_delay(1);
+		goto mac_reset_top;
+	}
 
 	msec_delay(50);
 
@@ -981,8 +990,6 @@ s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw)
 	hw->mac.num_rar_entries = 128;
 	hw->mac.ops.init_rx_addrs(hw);
 
-
-
 	/* Store the permanent SAN mac address */
 	hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr);
 
@@ -1207,6 +1214,9 @@ s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 pballoc)
 	/* Send interrupt when 64 filters are left */
 	fdirctrl |= 4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT;
 
+	/* Initialize the drop queue to Rx queue 127 */
+	fdirctrl |= (127 << IXGBE_FDIRCTRL_DROP_Q_SHIFT);
+
 	switch (pballoc) {
 	case IXGBE_FDIR_PBALLOC_64K:
 		/* 2k - 1 perfect filters */
@@ -1886,23 +1896,26 @@ s32 ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw,
  *  ixgbe_fdir_add_perfect_filter_82599 - Adds a perfect filter
  *  @hw: pointer to hardware structure
  *  @input: input bitstream
+ *  @input_masks: masks for the input bitstream
+ *  @soft_id: software index for the filters
  *  @queue: queue index to direct traffic to
  *
  *  Note that the caller to this function must lock before calling, since the
  *  hardware writes must be protected from one another.
  **/
 s32 ixgbe_fdir_add_perfect_filter_82599(struct ixgbe_hw *hw,
-                                        struct ixgbe_atr_input *input,
-                                        u16 soft_id,
-                                        u8 queue)
+                                      struct ixgbe_atr_input *input,
+                                      struct ixgbe_atr_input_masks *input_masks,
+                                      u16 soft_id, u8 queue)
 {
 	u32 fdircmd = 0;
 	u32 fdirhash;
-	u32 src_ipv4, dst_ipv4;
+	u32 src_ipv4 = 0, dst_ipv4 = 0;
 	u32 src_ipv6_1, src_ipv6_2, src_ipv6_3, src_ipv6_4;
 	u16 src_port, dst_port, vlan_id, flex_bytes;
 	u16 bucket_hash;
 	u8  l4type;
+	u8  fdirm = 0;
 
 	DEBUGFUNC("ixgbe_fdir_add_perfect_filter_82599");
 
@@ -1959,7 +1972,6 @@ s32 ixgbe_fdir_add_perfect_filter_82599(struct ixgbe_hw *hw,
 		/* IPv4 */
 		ixgbe_atr_get_src_ipv4_82599(input, &src_ipv4);
 		IXGBE_WRITE_REG(hw, IXGBE_FDIRIPSA, src_ipv4);
-
 	}
 
 	ixgbe_atr_get_dst_ipv4_82599(input, &dst_ipv4);
@@ -1968,7 +1980,78 @@ s32 ixgbe_fdir_add_perfect_filter_82599(struct ixgbe_hw *hw,
 	IXGBE_WRITE_REG(hw, IXGBE_FDIRVLAN, (vlan_id |
 	                            (flex_bytes << IXGBE_FDIRVLAN_FLEX_SHIFT)));
 	IXGBE_WRITE_REG(hw, IXGBE_FDIRPORT, (src_port |
-	                       (dst_port << IXGBE_FDIRPORT_DESTINATION_SHIFT)));
+	              (dst_port << IXGBE_FDIRPORT_DESTINATION_SHIFT)));
+
+	/*
+	 * Program the relevant mask registers.  If src/dst_port or src/dst_addr
+	 * are zero, then assume a full mask for that field.  Also assume that
+	 * a VLAN of 0 is unspecified, so mask that out as well.  L4type
+	 * cannot be masked out in this implementation.
+	 *
+	 * This also assumes IPv4 only.  IPv6 masking isn't supported at this
+	 * point in time.
+	 */
+	if (src_ipv4 == 0)
+		IXGBE_WRITE_REG(hw, IXGBE_FDIRSIP4M, 0xffffffff);
+	else
+		IXGBE_WRITE_REG(hw, IXGBE_FDIRSIP4M, input_masks->src_ip_mask);
+
+	if (dst_ipv4 == 0)
+		IXGBE_WRITE_REG(hw, IXGBE_FDIRDIP4M, 0xffffffff);
+	else
+		IXGBE_WRITE_REG(hw, IXGBE_FDIRDIP4M, input_masks->dst_ip_mask);
+
+	switch (l4type & IXGBE_ATR_L4TYPE_MASK) {
+	case IXGBE_ATR_L4TYPE_TCP:
+		if (src_port == 0)
+			IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM, 0xffff);
+		else
+			IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM,
+			                input_masks->src_port_mask);
+
+		if (dst_port == 0)
+			IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM,
+			               (IXGBE_READ_REG(hw, IXGBE_FDIRTCPM) |
+			                (0xffff << 16)));
+		else
+			IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM,
+			               (IXGBE_READ_REG(hw, IXGBE_FDIRTCPM) |
+			                (input_masks->dst_port_mask << 16)));
+		break;
+	case IXGBE_ATR_L4TYPE_UDP:
+		if (src_port == 0)
+			IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM, 0xffff);
+		else
+			IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM,
+			                input_masks->src_port_mask);
+
+		if (dst_port == 0)
+			IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM,
+			               (IXGBE_READ_REG(hw, IXGBE_FDIRUDPM) |
+			                (0xffff << 16)));
+		else
+			IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM,
+			               (IXGBE_READ_REG(hw, IXGBE_FDIRUDPM) |
+			                (input_masks->src_port_mask << 16)));
+		break;
+	default:
+		/* this already would have failed above */
+		break;
+	}
+
+	/* Program the last mask register, FDIRM */
+	if (input_masks->vlan_id_mask || !vlan_id)
+		/* Mask both VLAN and VLANP - bits 0 and 1 */
+		fdirm |= (IXGBE_FDIRM_VLANID | IXGBE_FDIRM_VLANP);
+
+	if (input_masks->data_mask || !flex_bytes)
+		/* Flex bytes need masking, so mask the whole thing - bit 4 */
+		fdirm |= IXGBE_FDIRM_FLEX;
+
+	/* Now mask VM pool and destination IPv6 - bits 5 and 2 */
+	fdirm |= (IXGBE_FDIRM_POOL | IXGBE_FDIRM_DIPv6);
+
+	IXGBE_WRITE_REG(hw, IXGBE_FDIRM, fdirm);
 
 	fdircmd |= IXGBE_FDIRCMD_CMD_ADD_FLOW;
 	fdircmd |= IXGBE_FDIRCMD_FILTER_UPDATE;
@@ -2063,7 +2146,7 @@ s32 ixgbe_start_hw_rev_1_82599(struct ixgbe_hw *hw)
 	for (i = 0; i < hw->mac.max_rx_queues; i++) {
 		regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
 		regval &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
-			    IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
+		            IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
 		IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
 	}
 
@@ -2192,10 +2275,14 @@ sfp_check:
 		goto out;
 
 	switch (hw->phy.type) {
-	case ixgbe_phy_tw_tyco:
-	case ixgbe_phy_tw_unknown:
+	case ixgbe_phy_sfp_passive_tyco:
+	case ixgbe_phy_sfp_passive_unknown:
 		physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
 		break;
+	case ixgbe_phy_sfp_ftl_active:
+	case ixgbe_phy_sfp_active_unknown:
+		physical_layer = IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA;
+		break;
 	case ixgbe_phy_sfp_avago:
 	case ixgbe_phy_sfp_ftl:
 	case ixgbe_phy_sfp_intel:
@@ -2328,3 +2415,30 @@ static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw)
 fw_version_out:
 	return status;
 }
+/**
+ *  ixgbe_enable_relaxed_ordering_82599 - Enable relaxed ordering
+ *  @hw: pointer to hardware structure
+ *
+ **/
+void ixgbe_enable_relaxed_ordering_82599(struct ixgbe_hw *hw)
+{
+	u32 regval;
+	u32 i;
+
+	DEBUGFUNC("ixgbe_enable_relaxed_ordering_82599");
+
+	/* Enable relaxed ordering */
+	for (i = 0; i < hw->mac.max_tx_queues; i++) {
+		regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
+		regval |= IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
+		IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval);
+	}
+
+	for (i = 0; i < hw->mac.max_rx_queues; i++) {
+		regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
+		regval |= (IXGBE_DCA_RXCTRL_DESC_WRO_EN |
+		           IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
+		IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
+	}
+
+}
diff --git a/sys/dev/ixgbe/ixgbe_api.c b/sys/dev/ixgbe/ixgbe_api.c
index 44644574860..a65686e29f2 100644
--- a/sys/dev/ixgbe/ixgbe_api.c
+++ b/sys/dev/ixgbe/ixgbe_api.c
@@ -1,6 +1,6 @@
 /******************************************************************************
 
-  Copyright (c) 2001-2009, Intel Corporation 
+  Copyright (c) 2001-2010, Intel Corporation 
   All rights reserved.
   
   Redistribution and use in source and binary forms, with or without 
@@ -111,6 +111,7 @@ s32 ixgbe_set_mac_type(struct ixgbe_hw *hw)
 		case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
 		case IXGBE_DEV_ID_82599_SFP:
 		case IXGBE_DEV_ID_82599_CX4:
+		case IXGBE_DEV_ID_82599_T3_LOM:
 			hw->mac.type = ixgbe_mac_82599EB;
 			break;
 		default:
@@ -167,6 +168,20 @@ s32 ixgbe_start_hw(struct ixgbe_hw *hw)
 	                       IXGBE_NOT_IMPLEMENTED);
 }
 
+/**
+ *  ixgbe_enable_relaxed_ordering - Enables tx relaxed ordering,
+ *  which is disabled by default in ixgbe_start_hw();
+ *
+ *  @hw: pointer to hardware structure
+ *
+ *   Enable relaxed ordering;
+ **/
+void ixgbe_enable_relaxed_ordering(struct ixgbe_hw *hw)
+{
+	if (hw->mac.ops.enable_relaxed_ordering)
+		hw->mac.ops.enable_relaxed_ordering(hw);
+}
+
 /**
  *  ixgbe_clear_hw_cntrs - Clear hardware counters
  *  @hw: pointer to hardware structure
diff --git a/sys/dev/ixgbe/ixgbe_api.h b/sys/dev/ixgbe/ixgbe_api.h
index 8ab78ad8720..48c523c1897 100644
--- a/sys/dev/ixgbe/ixgbe_api.h
+++ b/sys/dev/ixgbe/ixgbe_api.h
@@ -1,6 +1,6 @@
 /******************************************************************************
 
-  Copyright (c) 2001-2009, Intel Corporation 
+  Copyright (c) 2001-2010, Intel Corporation 
   All rights reserved.
   
   Redistribution and use in source and binary forms, with or without 
@@ -43,6 +43,7 @@ s32 ixgbe_set_mac_type(struct ixgbe_hw *hw);
 s32 ixgbe_init_hw(struct ixgbe_hw *hw);
 s32 ixgbe_reset_hw(struct ixgbe_hw *hw);
 s32 ixgbe_start_hw(struct ixgbe_hw *hw);
+void ixgbe_enable_relaxed_ordering(struct ixgbe_hw *hw);
 s32 ixgbe_clear_hw_cntrs(struct ixgbe_hw *hw);
 enum ixgbe_media_type ixgbe_get_media_type(struct ixgbe_hw *hw);
 s32 ixgbe_get_mac_addr(struct ixgbe_hw *hw, u8 *mac_addr);
@@ -122,6 +123,7 @@ s32 ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw,
                                           u8 queue);
 s32 ixgbe_fdir_add_perfect_filter_82599(struct ixgbe_hw *hw,
                                         struct ixgbe_atr_input *input,
+                                        struct ixgbe_atr_input_masks *masks,
                                         u16 soft_id,
                                         u8 queue);
 u16 ixgbe_atr_compute_hash_82599(struct ixgbe_atr_input *input, u32 key);
diff --git a/sys/dev/ixgbe/ixgbe_common.c b/sys/dev/ixgbe/ixgbe_common.c
index 89e57d83dab..217c477a6c6 100644
--- a/sys/dev/ixgbe/ixgbe_common.c
+++ b/sys/dev/ixgbe/ixgbe_common.c
@@ -1,6 +1,6 @@
 /******************************************************************************
 
-  Copyright (c) 2001-2009, Intel Corporation 
+  Copyright (c) 2001-2010, Intel Corporation 
   All rights reserved.
   
   Redistribution and use in source and binary forms, with or without 
@@ -474,8 +474,7 @@ s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
 	 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
 	 * access and verify no pending requests
 	 */
-	if (ixgbe_disable_pcie_master(hw) != IXGBE_SUCCESS)
-		DEBUGOUT("PCI-E Master disable polling has failed.\n");
+	ixgbe_disable_pcie_master(hw);
 
 	return IXGBE_SUCCESS;
 }
@@ -2198,10 +2197,14 @@ s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
 	u32 i;
 	u32 reg_val;
 	u32 number_of_queues;
-	s32 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
+	s32 status = IXGBE_SUCCESS;
 
 	DEBUGFUNC("ixgbe_disable_pcie_master");
 
+	/* Just jump out if bus mastering is already disabled */
+	if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
+		goto out;
+
 	/* Disable the receive unit by stopping each queue */
 	number_of_queues = hw->mac.max_rx_queues;
 	for (i = 0; i < number_of_queues; i++) {
@@ -2217,13 +2220,42 @@ s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
 	IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val);
 
 	for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
-		if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) {
-			status = IXGBE_SUCCESS;
-			break;
-		}
+		if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
+			goto out;
 		usec_delay(100);
 	}
 
+	DEBUGOUT("GIO Master Disable bit didn't clear - requesting resets\n");
+	status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
+
+	/*
+	 * The GIO Master Disable bit didn't clear.  There are multiple reasons
+	 * for this listed in the datasheet 5.2.5.3.2 Master Disable, and they
+	 * all require a double reset to recover from.  Before proceeding, we
+	 * first wait a little more to try to ensure that, at a minimum, the
+	 * PCIe block has no transactions pending.
+	 */
+	for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
+		if (!(IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_DEVICE_STATUS) &
+			IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
+			break;
+		usec_delay(100);
+	}
+
+	if (i == IXGBE_PCI_MASTER_DISABLE_TIMEOUT)
+		DEBUGOUT("PCIe transaction pending bit also did not clear.\n");
+
+	/*
+	 * Two consecutive resets are required via CTRL.RST per datasheet
+	 * 5.2.5.3.2 Master Disable.  We set a flag to inform the reset routine
+	 * of this need.  The first reset prevents new master requests from
+	 * being issued by our device.  We then must wait 1usec for any
+	 * remaining completions from the PCIe bus to trickle in, and then reset
+	 * again to clear out any effects they may have had on our device.
+	 */
+	 hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
+
+out:
 	return status;
 }
 
@@ -2695,6 +2727,10 @@ s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan)
 	u32 first_empty_slot = 0;
 	s32 regindex;
 
+	/* short cut the special case */
+	if (vlan == 0)
+		return 0;
+
 	/*
 	  * Search for the vlan id in the VLVF entries. Save off the first empty
 	  * slot found along the way
@@ -2717,7 +2753,7 @@ s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan)
 			regindex = first_empty_slot;
 		else {
 			DEBUGOUT("No space in VLVF.\n");
-			regindex = -1;
+			regindex = IXGBE_ERR_NO_SPACE;
 		}
 	}
 
@@ -2738,8 +2774,11 @@ s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
 {
 	s32 regindex;
 	u32 bitindex;
+	u32 vfta;
 	u32 bits;
 	u32 vt;
+	u32 targetbit;
+	bool vfta_changed = FALSE;
 
 	DEBUGFUNC("ixgbe_set_vfta_generic");
 
@@ -2749,6 +2788,7 @@ s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
 	/*
 	 * this is a 2 part operation - first the VFTA, then the
 	 * VLVF and VLVFB if VT Mode is set
+	 * We don't write the VFTA until we know the VLVF part succeeded.
 	 */
 
 	/* Part 1
@@ -2759,13 +2799,20 @@ s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
 	 */
 	regindex = (vlan >> 5) & 0x7F;
 	bitindex = vlan & 0x1F;
-	bits = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
-	if (vlan_on)
-		bits |= (1 << bitindex);
-	else
-		bits &= ~(1 << bitindex);
-	IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), bits);
+	targetbit = (1 << bitindex);
+	vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
 
+	if (vlan_on) {
+		if (!(vfta & targetbit)) {
+			vfta |= targetbit;
+			vfta_changed = TRUE;
+		}
+	} else {
+		if ((vfta & targetbit)) {
+			vfta &= ~targetbit;
+			vfta_changed = TRUE;
+		}
+	}
 
 	/* Part 2
 	 * If VT Mode is set
@@ -2777,61 +2824,84 @@ s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
 	 */
 	vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
 	if (vt & IXGBE_VT_CTL_VT_ENABLE) {
-		if (vlan == 0) {
-			regindex = 0;
-		} else {
-			regindex = ixgbe_find_vlvf_slot(hw, vlan);
-			if (regindex < 0)
-				goto out;
-		}
+		s32 vlvf_index;
+
+		vlvf_index = ixgbe_find_vlvf_slot(hw, vlan);
+		if (vlvf_index < 0)
+			return vlvf_index;
 
 		if (vlan_on) {
 			/* set the pool bit */
 			if (vind < 32) {
 				bits = IXGBE_READ_REG(hw,
-						IXGBE_VLVFB(regindex*2));
+						IXGBE_VLVFB(vlvf_index*2));
 				bits |= (1 << vind);
 				IXGBE_WRITE_REG(hw,
-						IXGBE_VLVFB(regindex*2),
+						IXGBE_VLVFB(vlvf_index*2),
 						bits);
 			} else {
 				bits = IXGBE_READ_REG(hw,
-						IXGBE_VLVFB((regindex*2)+1));
-				bits |= (1 << vind);
+						IXGBE_VLVFB((vlvf_index*2)+1));
+				bits |= (1 << (vind-32));
 				IXGBE_WRITE_REG(hw,
-						IXGBE_VLVFB((regindex*2)+1),
+						IXGBE_VLVFB((vlvf_index*2)+1),
 						bits);
 			}
 		} else {
 			/* clear the pool bit */
 			if (vind < 32) {
 				bits = IXGBE_READ_REG(hw,
-						IXGBE_VLVFB(regindex*2));
+						IXGBE_VLVFB(vlvf_index*2));
 				bits &= ~(1 << vind);
 				IXGBE_WRITE_REG(hw,
-						IXGBE_VLVFB(regindex*2),
+						IXGBE_VLVFB(vlvf_index*2),
 						bits);
 				bits |= IXGBE_READ_REG(hw,
-						IXGBE_VLVFB((regindex*2)+1));
+						IXGBE_VLVFB((vlvf_index*2)+1));
 			} else {
 				bits = IXGBE_READ_REG(hw,
-						IXGBE_VLVFB((regindex*2)+1));
-				bits &= ~(1 << vind);
+						IXGBE_VLVFB((vlvf_index*2)+1));
+				bits &= ~(1 << (vind-32));
 				IXGBE_WRITE_REG(hw,
-						IXGBE_VLVFB((regindex*2)+1),
+						IXGBE_VLVFB((vlvf_index*2)+1),
 						bits);
 				bits |= IXGBE_READ_REG(hw,
-						IXGBE_VLVFB(regindex*2));
+						IXGBE_VLVFB(vlvf_index*2));
 			}
 		}
 
-		if (bits)
-			IXGBE_WRITE_REG(hw, IXGBE_VLVF(regindex),
+		/*
+		 * If there are still bits set in the VLVFB registers
+		 * for the VLAN ID indicated we need to see if the
+		 * caller is requesting that we clear the VFTA entry bit.
+		 * If the caller has requested that we clear the VFTA
+		 * entry bit but there are still pools/VFs using this VLAN
+		 * ID entry then ignore the request.  We're not worried
+		 * about the case where we're turning the VFTA VLAN ID
+		 * entry bit on, only when requested to turn it off as
+		 * there may be multiple pools and/or VFs using the
+		 * VLAN ID entry.  In that case we cannot clear the
+		 * VFTA bit until all pools/VFs using that VLAN ID have also
+		 * been cleared.  This will be indicated by "bits" being
+		 * zero.
+		 */
+		if (bits) {
+			IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
 					(IXGBE_VLVF_VIEN | vlan));
+			if (!vlan_on) {
+				/* someone wants to clear the vfta entry
+				 * but some pools/VFs are still using it.
+				 * Ignore it. */
+				vfta_changed = FALSE;
+			}
+		}
 		else
-			IXGBE_WRITE_REG(hw, IXGBE_VLVF(regindex), 0);
+			IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
 	}
-out:
+
+	if (vfta_changed)
+		IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta);
+
 	return IXGBE_SUCCESS;
 }
 
@@ -2869,14 +2939,23 @@ s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
  *  Reads the links register to determine if link is up and the current speed
  **/
 s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
-                               bool *link_up, bool link_up_wait_to_complete)
+                                 bool *link_up, bool link_up_wait_to_complete)
 {
-	u32 links_reg;
+	u32 links_reg, links_orig;
 	u32 i;
 
 	DEBUGFUNC("ixgbe_check_mac_link_generic");
 
+	/* clear the old state */
+	links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
+
 	links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
+
+	if (links_orig != links_reg) {
+		DEBUGOUT2("LINKS changed from %08X to %08X\n",
+		          links_orig, links_reg);
+	}
+
 	if (link_up_wait_to_complete) {
 		for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
 			if (links_reg & IXGBE_LINKS_UP) {
diff --git a/sys/dev/ixgbe/ixgbe_phy.c b/sys/dev/ixgbe/ixgbe_phy.c
index 9bab98d2952..7ec2981d4c2 100644
--- a/sys/dev/ixgbe/ixgbe_phy.c
+++ b/sys/dev/ixgbe/ixgbe_phy.c
@@ -1,6 +1,6 @@
 /******************************************************************************
 
-  Copyright (c) 2001-2009, Intel Corporation 
+  Copyright (c) 2001-2010, Intel Corporation 
   All rights reserved.
   
   Redistribution and use in source and binary forms, with or without 
@@ -77,7 +77,8 @@ s32 ixgbe_init_phy_ops_generic(struct ixgbe_hw *hw)
 	phy->ops.i2c_bus_clear = &ixgbe_i2c_bus_clear;
 	phy->ops.identify_sfp = &ixgbe_identify_sfp_module_generic;
 	phy->sfp_type = ixgbe_sfp_type_unknown;
-
+	phy->ops.check_overtemp = &ixgbe_tn_check_overtemp;
+	phy->ops.set_low_power_state = &ixgbe_tn_set_low_power_state;
 	return IXGBE_SUCCESS;
 }
 
@@ -241,13 +242,19 @@ s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
 	                      IXGBE_MDIO_PHY_XS_DEV_TYPE,
 	                      IXGBE_MDIO_PHY_XS_RESET);
 
-	/* Poll for reset bit to self-clear indicating reset is complete */
-	for (i = 0; i < 500; i++) {
-		msec_delay(1);
+	/*
+	 * Poll for reset bit to self-clear indicating reset is complete.
+	 * Some PHYs could take up to 3 seconds to complete and need about
+	 * 1.7 usec delay after the reset is complete.
+	 */
+	for (i = 0; i < 30; i++) {
+		msec_delay(100);
 		hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
 		                     IXGBE_MDIO_PHY_XS_DEV_TYPE, &ctrl);
-		if (!(ctrl & IXGBE_MDIO_PHY_XS_RESET))
+		if (!(ctrl & IXGBE_MDIO_PHY_XS_RESET)) {
+			usec_delay(2);
 			break;
+		}
 	}
 
 	if (ctrl & IXGBE_MDIO_PHY_XS_RESET) {
@@ -922,6 +929,7 @@ s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
 	u8 comp_codes_10g = 0;
 	u8 oui_bytes[3] = {0, 0, 0};
 	u8 cable_tech = 0;
+	u8 cable_spec = 0;
 	u16 enforce_sfp = 0;
 
 	DEBUGFUNC("ixgbe_identify_sfp_module_generic");
@@ -968,6 +976,8 @@ s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
 		  * 4   SFP_DA_CORE1 - 82599-specific
 		  * 5   SFP_SR/LR_CORE0 - 82599-specific
 		  * 6   SFP_SR/LR_CORE1 - 82599-specific
+		  * 7   SFP_act_lmt_DA_CORE0 - 82599-specific
+		  * 8   SFP_act_lmt_DA_CORE1 - 82599-specific
 		  */
 		if (hw->mac.type == ixgbe_mac_82598EB) {
 			if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
@@ -979,29 +989,40 @@ s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
 			else
 				hw->phy.sfp_type = ixgbe_sfp_type_unknown;
 		} else if (hw->mac.type == ixgbe_mac_82599EB) {
-			if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
+			if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
 				if (hw->bus.lan_id == 0)
 					hw->phy.sfp_type =
 					             ixgbe_sfp_type_da_cu_core0;
 				else
 					hw->phy.sfp_type =
 					             ixgbe_sfp_type_da_cu_core1;
-			else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
+			} else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
+				hw->phy.ops.read_i2c_eeprom(
+						hw, IXGBE_SFF_CABLE_SPEC_COMP,
+						&cable_spec);
+				if (cable_spec &
+					    IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
+					if (hw->bus.lan_id == 0)
+						hw->phy.sfp_type =
+						ixgbe_sfp_type_da_act_lmt_core0;
+					else
+						hw->phy.sfp_type =
+						ixgbe_sfp_type_da_act_lmt_core1;
+				} else
+					hw->phy.sfp_type =
+						ixgbe_sfp_type_unknown;
+			} else if (comp_codes_10g &
+				   (IXGBE_SFF_10GBASESR_CAPABLE |
+				   IXGBE_SFF_10GBASELR_CAPABLE)) {
 				if (hw->bus.lan_id == 0)
 					hw->phy.sfp_type =
 					              ixgbe_sfp_type_srlr_core0;
 				else
 					hw->phy.sfp_type =
 					              ixgbe_sfp_type_srlr_core1;
-			else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
-				if (hw->bus.lan_id == 0)
-					hw->phy.sfp_type =
-					              ixgbe_sfp_type_srlr_core0;
-				else
-					hw->phy.sfp_type =
-					              ixgbe_sfp_type_srlr_core1;
-			else
+			} else {
 				hw->phy.sfp_type = ixgbe_sfp_type_unknown;
+			}
 		}
 
 		if (hw->phy.sfp_type != stored_sfp_type)
@@ -1036,10 +1057,14 @@ s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
 			switch (vendor_oui) {
 			case IXGBE_SFF_VENDOR_OUI_TYCO:
 				if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
-					hw->phy.type = ixgbe_phy_tw_tyco;
+					hw->phy.type =
+					            ixgbe_phy_sfp_passive_tyco;
 				break;
 			case IXGBE_SFF_VENDOR_OUI_FTL:
-				hw->phy.type = ixgbe_phy_sfp_ftl;
+				if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
+					hw->phy.type = ixgbe_phy_sfp_ftl_active;
+				else
+					hw->phy.type = ixgbe_phy_sfp_ftl;
 				break;
 			case IXGBE_SFF_VENDOR_OUI_AVAGO:
 				hw->phy.type = ixgbe_phy_sfp_avago;
@@ -1049,15 +1074,20 @@ s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
 				break;
 			default:
 				if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
-					hw->phy.type = ixgbe_phy_tw_unknown;
+					hw->phy.type =
+					         ixgbe_phy_sfp_passive_unknown;
+				else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
+					hw->phy.type =
+						ixgbe_phy_sfp_active_unknown;
 				else
 					hw->phy.type = ixgbe_phy_sfp_unknown;
 				break;
 			}
 		}
 
-		/* All passive DA cables are supported */
-		if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
+		/* Allow any DA cable vendor */
+		if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
+		    IXGBE_SFF_DA_ACTIVE_CABLE)) {
 			status = IXGBE_SUCCESS;
 			goto out;
 		}
@@ -1108,6 +1138,7 @@ s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
                                         u16 *data_offset)
 {
 	u16 sfp_id;
+	u16 sfp_type = hw->phy.sfp_type;
 
 	DEBUGFUNC("ixgbe_get_sfp_init_sequence_offsets");
 
@@ -1121,6 +1152,12 @@ s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
 	    (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
 		return IXGBE_ERR_SFP_NOT_SUPPORTED;
 
+	/* Limiting active cables must be initialized as SR modules */
+	if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0)
+		sfp_type = ixgbe_sfp_type_srlr_core0;
+	else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1)
+		sfp_type = ixgbe_sfp_type_srlr_core1;
+
 	/* Read offset to PHY init contents */
 	hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset);
 
@@ -1137,7 +1174,7 @@ s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
 	hw->eeprom.ops.read(hw, *list_offset, &sfp_id);
 
 	while (sfp_id != IXGBE_PHY_INIT_END_NL) {
-		if (sfp_id == hw->phy.sfp_type) {
+		if (sfp_id == sfp_type) {
 			(*list_offset)++;
 			hw->eeprom.ops.read(hw, *list_offset, data_offset);
 			if ((!*data_offset) || (*data_offset == 0xFFFF)) {
@@ -1722,3 +1759,56 @@ void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
 	/* Put the i2c bus back to default state */
 	ixgbe_i2c_stop(hw);
 }
+
+/**
+ *  ixgbe_check_overtemp - Checks if an overtemp occured.
+ *  @hw: pointer to hardware structure
+ *
+ *  Checks if the LASI temp alarm status was triggered due to overtemp
+ **/
+s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
+{
+	s32 status = IXGBE_SUCCESS;
+	u16 phy_data = 0;
+
+	DEBUGFUNC("ixgbe_tn_check_overtemp");
+
+	if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
+		goto out;
+
+	/* Check that the LASI temp alarm status was triggered */
+	hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
+			     IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_data);
+
+	if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
+		goto out;
+
+	status = IXGBE_ERR_OVERTEMP;
+out:
+	return status;
+}
+
+
+/**
+ *  ixgbe_set_tn_low_power_state - Sets the teranetics phy into low power state
+ *  @hw: pointer to hardware structure
+ *
+ *  Sets the phy into low power mode when LASI temp alarm status is triggered
+ **/
+s32 ixgbe_tn_set_low_power_state(struct ixgbe_hw *hw)
+{
+	s32 status = IXGBE_SUCCESS;
+	u16 phy_data = 0;
+
+	DEBUGFUNC("ixgbe_set_tn_low_power_state");
+
+	/* Set the phy into low power mode */
+	hw->phy.ops.read_reg(hw, IXGBE_MDIO_PMA_PMD_CONTROL_ADDR,
+			     IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_data);
+	phy_data |= IXGBE_MDIO_PHY_LOW_POWER_MODE;
+	hw->phy.ops.write_reg(hw, IXGBE_MDIO_PMA_PMD_CONTROL_ADDR,
+			      IXGBE_MDIO_PMA_PMD_DEV_TYPE, phy_data);
+
+	return status;
+}
+
diff --git a/sys/dev/ixgbe/ixgbe_phy.h b/sys/dev/ixgbe/ixgbe_phy.h
index 39f3bc83f0a..8f49aa83e8f 100644
--- a/sys/dev/ixgbe/ixgbe_phy.h
+++ b/sys/dev/ixgbe/ixgbe_phy.h
@@ -1,6 +1,6 @@
 /******************************************************************************
 
-  Copyright (c) 2001-2009, Intel Corporation 
+  Copyright (c) 2001-2010, Intel Corporation 
   All rights reserved.
   
   Redistribution and use in source and binary forms, with or without 
@@ -47,9 +47,12 @@
 #define IXGBE_SFF_1GBE_COMP_CODES    0x6
 #define IXGBE_SFF_10GBE_COMP_CODES   0x3
 #define IXGBE_SFF_CABLE_TECHNOLOGY   0x8
+#define IXGBE_SFF_CABLE_SPEC_COMP    0x3C
 
 /* Bitmasks */
 #define IXGBE_SFF_DA_PASSIVE_CABLE           0x4
+#define IXGBE_SFF_DA_ACTIVE_CABLE            0x8
+#define IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING   0x4
 #define IXGBE_SFF_1GBASESX_CAPABLE           0x1
 #define IXGBE_SFF_1GBASELX_CAPABLE           0x2
 #define IXGBE_SFF_10GBASESR_CAPABLE          0x10
@@ -84,6 +87,9 @@
 #define IXGBE_I2C_T_SU_STO  4
 #define IXGBE_I2C_T_BUF     5
 
+#define IXGBE_TN_LASI_STATUS_REG        0x9005
+#define IXGBE_TN_LASI_STATUS_TEMP_ALARM 0x0008
+
 
 s32 ixgbe_init_phy_ops_generic(struct ixgbe_hw *hw);
 bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr);
@@ -119,6 +125,8 @@ s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw);
 s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
                                         u16 *list_offset,
                                         u16 *data_offset);
+s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw);
+s32 ixgbe_tn_set_low_power_state(struct ixgbe_hw *hw);
 s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
                                 u8 dev_addr, u8 *data);
 s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
diff --git a/sys/dev/ixgbe/ixgbe_type.h b/sys/dev/ixgbe/ixgbe_type.h
index 0b101197709..2e1f0623b42 100644
--- a/sys/dev/ixgbe/ixgbe_type.h
+++ b/sys/dev/ixgbe/ixgbe_type.h
@@ -1,6 +1,6 @@
 /******************************************************************************
 
-  Copyright (c) 2001-2009, Intel Corporation 
+  Copyright (c) 2001-2010, Intel Corporation 
   All rights reserved.
   
   Redistribution and use in source and binary forms, with or without 
@@ -57,9 +57,11 @@
 #define IXGBE_DEV_ID_82599_KX4     0x10F7
 #define IXGBE_DEV_ID_82599_KX4_MEZZ 0x1514
 #define IXGBE_DEV_ID_82599_COMBO_BACKPLANE 0x10F8
+#define IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ  0x000C
 #define IXGBE_DEV_ID_82599_CX4 0x10F9
 #define IXGBE_DEV_ID_82599_SFP 0x10FB
 #define IXGBE_DEV_ID_82599_XAUI_LOM 0x10FC
+#define IXGBE_DEV_ID_82599_T3_LOM   0x151C
 
 /* General Registers */
 #define IXGBE_CTRL      0x00000
@@ -89,7 +91,7 @@
 
 /* General Receive Control */
 #define IXGBE_GRC_MNG  0x00000001 /* Manageability Enable */
-#define IXGBE_GRC_APME 0x00000002 /* Advanced Power Management Enable */
+#define IXGBE_GRC_APME 0x00000002 /* APM enabled in EEPROM */
 
 #define IXGBE_VPDDIAG0  0x10204
 #define IXGBE_VPDDIAG1  0x10208
@@ -198,6 +200,7 @@
 #define IXGBE_RFCTL     0x05008
 #define IXGBE_DRECCCTL  0x02F08
 #define IXGBE_DRECCCTL_DISABLE 0
+
 /* Multicast Table Array - 128 entries */
 #define IXGBE_MTA(_i)   (0x05200 + ((_i) * 4))
 #define IXGBE_RAL(_i)   (((_i) <= 15) ? (0x05400 + ((_i) * 8)) : \
@@ -334,7 +337,7 @@
 /* Wake Up Control */
 #define IXGBE_WUC_PME_EN     0x00000002 /* PME Enable */
 #define IXGBE_WUC_PME_STATUS 0x00000004 /* PME Status */
-#define IXGBE_WUC_ADVD3WUC   0x00000010 /* D3Cold wake up cap. enable*/
+#define IXGBE_WUC_WKEN       0x00000010 /* Enable PE_WAKE_N pin assertion  */
 
 /* Wake Up Filter Control */
 #define IXGBE_WUFC_LNKC 0x00000001 /* Link Status Change Wakeup Enable */
@@ -736,6 +739,12 @@
 #define IXGBE_GCR_CMPL_TMOUT_RESEND     0x00010000
 #define IXGBE_GCR_CAP_VER2              0x00040000
 
+#define IXGBE_GCR_EXT_MSIX_EN           0x80000000
+#define IXGBE_GCR_EXT_VT_MODE_16        0x00000001
+#define IXGBE_GCR_EXT_VT_MODE_32        0x00000002
+#define IXGBE_GCR_EXT_VT_MODE_64        0x00000003
+#define IXGBE_GCR_EXT_SRIOV             (IXGBE_GCR_EXT_MSIX_EN | \
+                                         IXGBE_GCR_EXT_VT_MODE_64)
 /* Time Sync Registers */
 #define IXGBE_TSYNCRXCTL 0x05188 /* Rx Time Sync Control register - RW */
 #define IXGBE_TSYNCTXCTL 0x08C00 /* Tx Time Sync Control register - RW */
@@ -889,6 +898,8 @@
 #define IXGBE_RDRXCTL_AGGDIS        0x00010000 /* Aggregation disable */
 #define IXGBE_RDRXCTL_RSCFRSTSIZE   0x003E0000 /* RSC First packet size */
 #define IXGBE_RDRXCTL_RSCLLIDIS     0x00800000 /* Disable RSC compl on LLI */
+#define IXGBE_RDRXCTL_RSCACKC       0x02000000 /* must set 1 when RSC enabled */
+#define IXGBE_RDRXCTL_FCOE_WRFIX    0x04000000 /* must set 1 when RSC enabled */
 
 /* RQTC Bit Masks and Shifts */
 #define IXGBE_RQTC_SHIFT_TC(_i)     ((_i) * 4)
@@ -1020,7 +1031,9 @@
 #define IXGBE_MDIO_PHY_10GBASET_ABILITY   0x0004 /* 10GBaseT capable */
 #define IXGBE_MDIO_PHY_1000BASET_ABILITY  0x0020 /* 1000BaseT capable */
 #define IXGBE_MDIO_PHY_100BASETX_ABILITY  0x0080 /* 100BaseTX capable */
+#define IXGBE_MDIO_PHY_SET_LOW_POWER_MODE 0x0800 /* Set low power mode */
 
+#define IXGBE_MDIO_PMA_PMD_CONTROL_ADDR     0x0000 /* PMA/PMD Control Reg */
 #define IXGBE_MDIO_PMA_PMD_SDA_SCL_ADDR     0xC30A /* PHY_XS SDA/SCL Addr Reg */
 #define IXGBE_MDIO_PMA_PMD_SDA_SCL_DATA     0xC30B /* PHY_XS SDA/SCL Data Reg */
 #define IXGBE_MDIO_PMA_PMD_SDA_SCL_STAT     0xC30C /* PHY_XS SDA/SCL Status Reg */
@@ -1369,10 +1382,12 @@
  *    EAPOL 802.1x (0x888e): Filter 0
  *    FCoE (0x8906):         Filter 2
  *    1588 (0x88f7):         Filter 3
+ *    FIP  (0x8914):         Filter 4
  */
 #define IXGBE_ETQF_FILTER_EAPOL          0
 #define IXGBE_ETQF_FILTER_FCOE           2
 #define IXGBE_ETQF_FILTER_1588           3
+#define IXGBE_ETQF_FILTER_FIP            4
 /* VLAN Control Bit Masks */
 #define IXGBE_VLNCTRL_VET       0x0000FFFF  /* bits 0-15 */
 #define IXGBE_VLNCTRL_CFI       0x10000000  /* bit 28 */
@@ -1476,6 +1491,7 @@
 #define IXGBE_AUTOC2_10G_XFI (0x1 << IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_SHIFT)
 #define IXGBE_AUTOC2_10G_SFI (0x2 << IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_SHIFT)
 
+
 /* LINKS Bit Masks */
 #define IXGBE_LINKS_KX_AN_COMP  0x80000000
 #define IXGBE_LINKS_UP          0x40000000
@@ -1655,6 +1671,8 @@
 #define IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN  0x1 /* Alt. WWN base exists */
 
 /* PCI Bus Info */
+#define IXGBE_PCI_DEVICE_STATUS   0xAA
+#define IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING   0x0020
 #define IXGBE_PCI_LINK_STATUS     0xB2
 #define IXGBE_PCI_DEVICE_CONTROL2 0xC8
 #define IXGBE_PCI_LINK_WIDTH      0x3F0
@@ -1787,6 +1805,7 @@
 #define IXGBE_MTQC_64Q_1PB      0x0 /* 64 queues 1 pack buffer */
 #define IXGBE_MTQC_32VF         0x8 /* 4 TX Queues per pool w/32VF's */
 #define IXGBE_MTQC_64VF         0x4 /* 2 TX Queues per pool w/64VF's */
+#define IXGBE_MTQC_4TC_4TQ      0x8 /* 4 TC if RT_ENA and VT_ENA */
 #define IXGBE_MTQC_8TC_8TQ      0xC /* 8 TC if RT_ENA or 8 TQ if VT_ENA */
 
 /* Receive Descriptor bit definitions */
@@ -2000,10 +2019,9 @@ enum ixgbe_fdir_pballoc_type {
 #define IXGBE_FDIRM_VLANID                      0x00000001
 #define IXGBE_FDIRM_VLANP                       0x00000002
 #define IXGBE_FDIRM_POOL                        0x00000004
-#define IXGBE_FDIRM_L3P                         0x00000008
-#define IXGBE_FDIRM_L4P                         0x00000010
-#define IXGBE_FDIRM_FLEX                        0x00000020
-#define IXGBE_FDIRM_DIPv6                       0x00000040
+#define IXGBE_FDIRM_L4P                         0x00000008
+#define IXGBE_FDIRM_FLEX                        0x00000010
+#define IXGBE_FDIRM_DIPv6                       0x00000020
 
 #define IXGBE_FDIRFREE_FREE_MASK                0xFFFF
 #define IXGBE_FDIRFREE_FREE_SHIFT               0
@@ -2218,6 +2236,8 @@ typedef u32 ixgbe_physical_layer;
 #define IXGBE_PHYSICAL_LAYER_1000BASE_BX  0x0400
 #define IXGBE_PHYSICAL_LAYER_10GBASE_KR   0x0800
 #define IXGBE_PHYSICAL_LAYER_10GBASE_XAUI 0x1000
+#define IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA 0x2000
+
 
 /* Software ATR hash keys */
 #define IXGBE_ATR_BUCKET_HASH_KEY    0xE214AD3D
@@ -2258,6 +2278,15 @@ struct ixgbe_atr_input {
 	u8 byte_stream[42];
 };
 
+struct ixgbe_atr_input_masks {
+	u32 src_ip_mask;
+	u32 dst_ip_mask;
+	u16 src_port_mask;
+	u16 dst_port_mask;
+	u16 vlan_id_mask;
+	u16 data_mask;
+};
+
 enum ixgbe_eeprom_type {
 	ixgbe_eeprom_uninitialized = 0,
 	ixgbe_eeprom_spi,
@@ -2281,10 +2310,12 @@ enum ixgbe_phy_type {
 	ixgbe_phy_qt,
 	ixgbe_phy_xaui,
 	ixgbe_phy_nl,
-	ixgbe_phy_tw_tyco,
-	ixgbe_phy_tw_unknown,
+	ixgbe_phy_sfp_passive_tyco,
+	ixgbe_phy_sfp_passive_unknown,
+	ixgbe_phy_sfp_active_unknown,
 	ixgbe_phy_sfp_avago,
 	ixgbe_phy_sfp_ftl,
+	ixgbe_phy_sfp_ftl_active,
 	ixgbe_phy_sfp_unknown,
 	ixgbe_phy_sfp_intel,
 	ixgbe_phy_sfp_unsupported, /*Enforce bit set with unsupported module*/
@@ -2312,6 +2343,8 @@ enum ixgbe_sfp_type {
 	ixgbe_sfp_type_da_cu_core1 = 4,
 	ixgbe_sfp_type_srlr_core0 = 5,
 	ixgbe_sfp_type_srlr_core1 = 6,
+	ixgbe_sfp_type_da_act_lmt_core0 = 7,
+	ixgbe_sfp_type_da_act_lmt_core1 = 8,
 	ixgbe_sfp_type_not_present = 0xFFFE,
 	ixgbe_sfp_type_unknown = 0xFFFF
 };
@@ -2354,25 +2387,25 @@ enum ixgbe_bus_type {
 /* PCI bus speeds */
 enum ixgbe_bus_speed {
 	ixgbe_bus_speed_unknown = 0,
-	ixgbe_bus_speed_33,
-	ixgbe_bus_speed_66,
-	ixgbe_bus_speed_100,
-	ixgbe_bus_speed_120,
-	ixgbe_bus_speed_133,
-	ixgbe_bus_speed_2500,
-	ixgbe_bus_speed_5000,
+	ixgbe_bus_speed_33      = 33,
+	ixgbe_bus_speed_66      = 66,
+	ixgbe_bus_speed_100     = 100,
+	ixgbe_bus_speed_120     = 120,
+	ixgbe_bus_speed_133     = 133,
+	ixgbe_bus_speed_2500    = 2500,
+	ixgbe_bus_speed_5000    = 5000,
 	ixgbe_bus_speed_reserved
 };
 
 /* PCI bus widths */
 enum ixgbe_bus_width {
 	ixgbe_bus_width_unknown = 0,
-	ixgbe_bus_width_pcie_x1,
-	ixgbe_bus_width_pcie_x2,
+	ixgbe_bus_width_pcie_x1 = 1,
+	ixgbe_bus_width_pcie_x2 = 2,
 	ixgbe_bus_width_pcie_x4 = 4,
 	ixgbe_bus_width_pcie_x8 = 8,
-	ixgbe_bus_width_32,
-	ixgbe_bus_width_64,
+	ixgbe_bus_width_32      = 32,
+	ixgbe_bus_width_64      = 64,
 	ixgbe_bus_width_reserved
 };
 
@@ -2503,6 +2536,7 @@ struct ixgbe_mac_operations {
 	s32 (*reset_hw)(struct ixgbe_hw *);
 	s32 (*start_hw)(struct ixgbe_hw *);
 	s32 (*clear_hw_cntrs)(struct ixgbe_hw *);
+	void (*enable_relaxed_ordering)(struct ixgbe_hw *);
 	enum ixgbe_media_type (*get_media_type)(struct ixgbe_hw *);
 	u32 (*get_supported_physical_layer)(struct ixgbe_hw *);
 	s32 (*get_mac_addr)(struct ixgbe_hw *, u8 *);
@@ -2570,6 +2604,8 @@ struct ixgbe_phy_operations {
 	s32 (*read_i2c_eeprom)(struct ixgbe_hw *, u8 , u8 *);
 	s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
 	void (*i2c_bus_clear)(struct ixgbe_hw *);
+	s32 (*check_overtemp)(struct ixgbe_hw *);
+	s32 (*set_low_power_state)(struct ixgbe_hw *);
 };
 
 struct ixgbe_eeprom_info {
@@ -2580,6 +2616,7 @@ struct ixgbe_eeprom_info {
 	u16                             address_bits;
 };
 
+#define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED	0x01
 struct ixgbe_mac_info {
 	struct ixgbe_mac_operations     ops;
 	enum ixgbe_mac_type             type;
@@ -2603,6 +2640,7 @@ struct ixgbe_mac_info {
 	u32                             orig_autoc2;
 	bool                            orig_link_settings_stored;
 	bool                            autotry_restart;
+	u8                              flags;
 };
 
 struct ixgbe_phy_info {
@@ -2668,6 +2706,8 @@ struct ixgbe_hw {
 #define IXGBE_ERR_NO_SAN_ADDR_PTR               -22
 #define IXGBE_ERR_FDIR_REINIT_FAILED            -23
 #define IXGBE_ERR_EEPROM_VERSION                -24
+#define IXGBE_ERR_NO_SPACE                      -25
+#define IXGBE_ERR_OVERTEMP                      -26
 #define IXGBE_NOT_IMPLEMENTED                   0x7FFFFFFF
 
 
diff --git a/sys/modules/ixgbe/Makefile b/sys/modules/ixgbe/Makefile
index 844ac7c5e55..2de7549a581 100644
--- a/sys/modules/ixgbe/Makefile
+++ b/sys/modules/ixgbe/Makefile
@@ -6,7 +6,7 @@ SRCS    += ixgbe.c
 # Shared source
 SRCS    += ixgbe_common.c ixgbe_api.c ixgbe_phy.c
 SRCS    += ixgbe_82599.c ixgbe_82598.c
-CFLAGS+= -I${.CURDIR}/../../dev/ixgbe -DSMP
+CFLAGS+= -I${.CURDIR}/../../dev/ixgbe -DSMP -DIXGBE_FDIR
 
 clean:
 	rm -f device_if.h bus_if.h pci_if.h setdef* *_StripErr

From 1adf3cbdb7ff7871ec96390fc5ede2517d2c1163 Mon Sep 17 00:00:00 2001
From: Marcel Moolenaar 
Date: Sat, 27 Mar 2010 03:15:34 +0000
Subject: [PATCH 097/119] Remove nx_pcibus from the nexus resource. Nexus is
 not involved with PCI busses. Remove nexus_read_ivar() and nexus_write_ivar()
 to give default behaviour. Remove  as well, because
 there's nothing in it that's being used.

---
 sys/ia64/ia64/nexus.c       | 40 ----------------------------------
 sys/ia64/include/nexusvar.h | 43 -------------------------------------
 2 files changed, 83 deletions(-)
 delete mode 100644 sys/ia64/include/nexusvar.h

diff --git a/sys/ia64/ia64/nexus.c b/sys/ia64/ia64/nexus.c
index 69f62a9b2fb..889c3d622c5 100644
--- a/sys/ia64/ia64/nexus.c
+++ b/sys/ia64/ia64/nexus.c
@@ -56,7 +56,6 @@
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -73,7 +72,6 @@
 static MALLOC_DEFINE(M_NEXUSDEV, "nexusdev", "Nexus device");
 struct nexus_device {
 	struct resource_list	nx_resources;
-	int			nx_pcibus;
 };
 
 #define DEVTONX(dev)	((struct nexus_device *)device_get_ivars(dev))
@@ -87,8 +85,6 @@ static device_t nexus_add_child(device_t bus, int order, const char *name,
 				int unit);
 static	struct resource *nexus_alloc_resource(device_t, device_t, int, int *,
 					      u_long, u_long, u_long, u_int);
-static	int nexus_read_ivar(device_t, device_t, int, uintptr_t *);
-static	int nexus_write_ivar(device_t, device_t, int, uintptr_t);
 static	int nexus_activate_resource(device_t, device_t, int, int,
 				    struct resource *);
 static	int nexus_deactivate_resource(device_t, device_t, int, int,
@@ -123,8 +119,6 @@ static device_method_t nexus_methods[] = {
 	/* Bus interface */
 	DEVMETHOD(bus_print_child,	nexus_print_child),
 	DEVMETHOD(bus_add_child,	nexus_add_child),
-	DEVMETHOD(bus_read_ivar,	nexus_read_ivar),
-	DEVMETHOD(bus_write_ivar,	nexus_write_ivar),
 	DEVMETHOD(bus_alloc_resource,	nexus_alloc_resource),
 	DEVMETHOD(bus_release_resource,	nexus_release_resource),
 	DEVMETHOD(bus_activate_resource, nexus_activate_resource),
@@ -215,8 +209,6 @@ nexus_print_child(device_t bus, device_t child)
 	retval += resource_list_print_type(rl, "port", SYS_RES_IOPORT, "%#lx");
 	retval += resource_list_print_type(rl, "iomem", SYS_RES_MEMORY, "%#lx");
 	retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld");
-	if (ndev->nx_pcibus != -1)
-		retval += printf(" pcibus %d", ndev->nx_pcibus);
 	if (device_get_flags(child))
 		retval += printf(" flags %#x", device_get_flags(child));
 	retval += printf(" on motherboard\n");	/* XXX "motherboard", ick */
@@ -234,7 +226,6 @@ nexus_add_child(device_t bus, int order, const char *name, int unit)
 	if (!ndev)
 		return(0);
 	resource_list_init(&ndev->nx_resources);
-	ndev->nx_pcibus = -1;
 
 	child = device_add_child_ordered(bus, order, name, unit); 
 
@@ -244,37 +235,6 @@ nexus_add_child(device_t bus, int order, const char *name, int unit)
 	return(child);
 }
 
-static int
-nexus_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
-{
-	struct	nexus_device *ndev = DEVTONX(child);
-
-	switch (which) {
-	case NEXUS_IVAR_PCIBUS:
-		*result = ndev->nx_pcibus;
-		break;
-	default:
-		return ENOENT;
-	}
-	return 0;
-}
-	
-
-static int
-nexus_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
-{
-	struct	nexus_device *ndev = DEVTONX(child);
-
-	switch (which) {
-	case NEXUS_IVAR_PCIBUS:
-		ndev->nx_pcibus = value;
-		break;
-	default:
-		return ENOENT;
-	}
-	return 0;
-}
-
 
 /*
  * Allocate a resource on behalf of child.  NB: child is usually going to be a
diff --git a/sys/ia64/include/nexusvar.h b/sys/ia64/include/nexusvar.h
deleted file mode 100644
index be38f33a075..00000000000
--- a/sys/ia64/include/nexusvar.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*-
- * Copyright (c) 2000 Peter Wemm 
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (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$
- */
-
-#ifndef _MACHINE_NEXUSVAR_H_
-#define	_MACHINE_NEXUSVAR_H_	1
-
-enum nexus_device_ivars {
-	NEXUS_IVAR_PCIBUS
-};
-
-#define NEXUS_ACCESSOR(var, ivar, type)					\
-    __BUS_ACCESSOR(nexus, var, NEXUS, ivar, type)
-
-NEXUS_ACCESSOR(pcibus,			PCIBUS,		u_int32_t)
-
-#undef NEXUS_ACCESSOR
-
-#endif /* !_MACHINE_NEXUSVAR_H_ */

From a29917e0755993c66ffe0c0698b0ad7349258d89 Mon Sep 17 00:00:00 2001
From: Marcel Moolenaar 
Date: Sat, 27 Mar 2010 03:17:39 +0000
Subject: [PATCH 098/119]  removed on ia64.

---
 ObsoleteFiles.inc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc
index 16e9250adec..b18c0ea52d3 100644
--- a/ObsoleteFiles.inc
+++ b/ObsoleteFiles.inc
@@ -14,11 +14,14 @@
 # The file is partitioned: OLD_FILES first, then OLD_LIBS and OLD_DIRS last.
 #
 
+# 20100326: [ia64] removed 
+.if ${TARGET_ARCH} == "ia64"
+OLD_FILES+=usr/include/machine/nexusvar.h
+.endif
 # 20100326: gcpio removal
 OLD_FILES+=usr/bin/gcpio
 OLD_FILES+=usr/share/info/cpio.info.gz
 OLD_FILES+=usr/share/man/man1/gcpio.1.gz
-
 # 20100322: libz update
 OLD_LIBS+=lib/libz.so.5
 .if ${TARGET_ARCH} == "amd64"

From 9280895b488c9151e99f1a5974f50a80afffccf2 Mon Sep 17 00:00:00 2001
From: Marcel Moolenaar 
Date: Sat, 27 Mar 2010 05:40:50 +0000
Subject: [PATCH 099/119] Implement interrupt to CPU binding. Assign interrupts
 to CPUs in a round-robin fashion, starting with the highest priority
 interrupt on the highest-numbered CPU and cycling downwards.

---
 sys/ia64/ia64/autoconf.c   |  2 +-
 sys/ia64/ia64/interrupt.c  | 22 ++++++++++++++++++----
 sys/ia64/ia64/mp_machdep.c |  6 ++++++
 sys/ia64/ia64/nexus.c      | 14 ++++++++++++++
 sys/ia64/ia64/sapic.c      | 21 +++++++++++++++++++++
 sys/ia64/include/intr.h    |  4 +++-
 6 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/sys/ia64/ia64/autoconf.c b/sys/ia64/ia64/autoconf.c
index acac159df7e..cf073c83509 100644
--- a/sys/ia64/ia64/autoconf.c
+++ b/sys/ia64/ia64/autoconf.c
@@ -93,7 +93,7 @@ configure_final(void *dummy)
 
 	cninit_finish();
 
-	ia64_finalize_intr();
+	ia64_enable_intr();
 
 	cold = 0;
 }
diff --git a/sys/ia64/ia64/interrupt.c b/sys/ia64/ia64/interrupt.c
index 82ac35fb43a..adb16ece9d5 100644
--- a/sys/ia64/ia64/interrupt.c
+++ b/sys/ia64/ia64/interrupt.c
@@ -122,7 +122,7 @@ ia64_xiv_reserve(u_int xiv, enum ia64_xiv_use what, ia64_ihtype ih)
 		return (EBUSY);
 	ia64_xiv[xiv] = what;
 	ia64_handler[xiv] = (ih == NULL) ? ia64_ih_invalid: ih;
-	if (1 || bootverbose)
+	if (bootverbose)
 		printf("XIV %u: use=%u, IH=%p\n", xiv, what, ih);
 	return (0);
 }
@@ -139,7 +139,7 @@ ia64_xiv_alloc(u_int prio, enum ia64_xiv_use what, ia64_ihtype ih)
 
 	xiv0 = IA64_NXIVS - (hwprio + 1) * 16;
 
-	KASSERT(xiv0 > IA64_MIN_XIV, ("%s: min XIV", __func__));
+	KASSERT(xiv0 >= IA64_MIN_XIV, ("%s: min XIV", __func__));
 	KASSERT(xiv0 < IA64_NXIVS, ("%s: max XIV", __func__));
 
 	xiv = xiv0;
@@ -281,10 +281,24 @@ ia64_teardown_intr(void *cookie)
 }
 
 void
-ia64_finalize_intr(void)
+ia64_bind_intr(void)
 {
+	struct ia64_intr *i;
+	struct pcpu *pc;
+	u_int xiv;
+	int cpu;
 
-	ia64_enable_intr();
+	cpu = MAXCPU;
+	for (xiv = IA64_NXIVS - 1; xiv >= IA64_MIN_XIV; xiv--) {
+		if (ia64_xiv[xiv] != IA64_XIV_IRQ)
+			continue;
+		i = ia64_intrs[xiv];
+		do {
+			cpu = (cpu == 0) ? MAXCPU - 1 : cpu - 1;
+			pc = cpuid_to_pcpu[cpu];
+		} while (pc == NULL || !pc->pc_md.awake);
+		sapic_bind_intr(i->irq, pc);
+	}
 }
 
 /*
diff --git a/sys/ia64/ia64/mp_machdep.c b/sys/ia64/ia64/mp_machdep.c
index 60ad43a1b29..600803a74b4 100644
--- a/sys/ia64/ia64/mp_machdep.c
+++ b/sys/ia64/ia64/mp_machdep.c
@@ -382,6 +382,12 @@ cpu_mp_unleash(void *dummy)
 
 	smp_active = 1;
 	smp_started = 1;
+
+	/*
+	 * Now that all CPUs are up and running, bind interrupts to each of
+	 * them.
+	 */
+	ia64_bind_intr();
 }
 
 /*
diff --git a/sys/ia64/ia64/nexus.c b/sys/ia64/ia64/nexus.c
index 889c3d622c5..9885b747aa2 100644
--- a/sys/ia64/ia64/nexus.c
+++ b/sys/ia64/ia64/nexus.c
@@ -50,6 +50,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -101,6 +102,7 @@ static	int nexus_set_resource(device_t, device_t, int, int, u_long, u_long);
 static	int nexus_get_resource(device_t, device_t, int, int, u_long *,
 			       u_long *);
 static void nexus_delete_resource(device_t, device_t, int, int);
+static int nexus_bind_intr(device_t, device_t, struct resource *, int);
 static	int nexus_config_intr(device_t, int, enum intr_trigger,
 			      enum intr_polarity);
 
@@ -129,6 +131,7 @@ static device_method_t nexus_methods[] = {
 	DEVMETHOD(bus_set_resource,	nexus_set_resource),
 	DEVMETHOD(bus_get_resource,	nexus_get_resource),
 	DEVMETHOD(bus_delete_resource,	nexus_delete_resource),
+	DEVMETHOD(bus_bind_intr,	nexus_bind_intr),
 	DEVMETHOD(bus_config_intr,	nexus_config_intr),
 
 	/* Clock interface */
@@ -461,6 +464,17 @@ nexus_config_intr(device_t dev, int irq, enum intr_trigger trig,
 	return (sapic_config_intr(irq, trig, pol));
 }
 
+static int
+nexus_bind_intr(device_t dev, device_t child, struct resource *irq, int cpu)
+{
+	struct pcpu *pc;
+
+	pc = cpuid_to_pcpu[cpu];
+	if (pc == NULL)
+		return (EINVAL);
+	return (sapic_bind_intr(rman_get_start(irq), pc));
+}
+
 static int
 nexus_gettime(device_t dev, struct timespec *ts)
 {
diff --git a/sys/ia64/ia64/sapic.c b/sys/ia64/ia64/sapic.c
index cb8a1c305ea..5aa14493e77 100644
--- a/sys/ia64/ia64/sapic.c
+++ b/sys/ia64/ia64/sapic.c
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -171,6 +172,26 @@ sapic_lookup(u_int irq, u_int *vecp)
 }
 
 
+int
+sapic_bind_intr(u_int irq, struct pcpu *pc)
+{
+	struct sapic_rte rte;
+	struct sapic *sa;
+
+	sa = sapic_lookup(irq, NULL);
+	if (sa == NULL)
+		return (EINVAL);
+
+	mtx_lock_spin(&sa->sa_mtx);
+	sapic_read_rte(sa, irq - sa->sa_base, &rte);
+	rte.rte_destination_id = (pc->pc_md.lid >> 24) & 255;
+	rte.rte_destination_eid = (pc->pc_md.lid >> 16) & 255;
+	rte.rte_delivery_mode = SAPIC_DELMODE_FIXED;
+	sapic_write_rte(sa, irq - sa->sa_base, &rte);
+	mtx_unlock_spin(&sa->sa_mtx);
+	return (0);
+}
+
 int
 sapic_config_intr(u_int irq, enum intr_trigger trig, enum intr_polarity pol)
 {
diff --git a/sys/ia64/include/intr.h b/sys/ia64/include/intr.h
index 2ea858c345f..81603cfabfd 100644
--- a/sys/ia64/include/intr.h
+++ b/sys/ia64/include/intr.h
@@ -35,6 +35,7 @@
 
 #define	IA64_MAX_HWPRIO		14
 
+struct pcpu;
 struct sapic;
 struct thread;
 struct trapframe;
@@ -65,7 +66,7 @@ typedef u_int (ia64_ihtype)(struct thread *, u_int, struct trapframe *);
 
 extern struct ia64_pib *ia64_pib;
 
-void	ia64_finalize_intr(void);
+void	ia64_bind_intr(void);
 void	ia64_handle_intr(struct trapframe *);
 int	ia64_setup_intr(const char *, int, driver_filter_t, driver_intr_t,
 	    void *, enum intr_type, void **);
@@ -76,6 +77,7 @@ u_int	ia64_xiv_alloc(u_int, enum ia64_xiv_use, ia64_ihtype);
 int	ia64_xiv_free(u_int, enum ia64_xiv_use);
 int	ia64_xiv_reserve(u_int, enum ia64_xiv_use, ia64_ihtype);
 
+int	sapic_bind_intr(u_int, struct pcpu *);
 int	sapic_config_intr(u_int, enum intr_trigger, enum intr_polarity);
 struct sapic *sapic_create(u_int, u_int, uint64_t);
 int	sapic_enable(struct sapic *, u_int, u_int);

From 8d02363b0cb81835de847c78788e01c00d102ddb Mon Sep 17 00:00:00 2001
From: Marcel Moolenaar 
Date: Sat, 27 Mar 2010 06:53:11 +0000
Subject: [PATCH 100/119] Bring up-to-date: o   Switch to ITANIUM2 has the cpu.
 This has absolutely no effect     on the code, but makes for a better
 example. o   Drop COMPAT_FREEBSD6. We're tier 2, so you're supposed to run   
  8-stable or newer. o   Add PREEMPTION. It works now. o   Remove HWPMC_HOOKS.
 We don't have support for hwpmc yet.

o   Add a bunch of new devices: atapist, hptiop, amr, ips, twa, igb,
    ixgbe, ae, age, alc, ale, bce, bfe, et, jme, msk, nge, sk, ste,
    stge, tx, vge, axe, rue, udav, fwip, and all USB serial.
o   Remove "legacy" devices: le, vx, dc, pcn, rl, sis.

Make sure to the module list is a superset of what goes into GENERIC.
---
 sys/ia64/conf/GENERIC | 59 ++++++++++++++++++++++++++++++++-----------
 sys/modules/Makefile  | 11 +++++---
 2 files changed, 51 insertions(+), 19 deletions(-)

diff --git a/sys/ia64/conf/GENERIC b/sys/ia64/conf/GENERIC
index 1df2e00829c..9b53bf3f1f7 100644
--- a/sys/ia64/conf/GENERIC
+++ b/sys/ia64/conf/GENERIC
@@ -20,20 +20,21 @@
 #
 # $FreeBSD$
 
-cpu		ITANIUM
+cpu		ITANIUM2
 ident		GENERIC
 
 makeoptions	DEBUG=-g	# Build kernel with debug information.
 
 options 	AUDIT		# Security event auditing
 options 	CD9660		# ISO 9660 Filesystem
-options 	COMPAT_FREEBSD6	# Compatible with FreeBSD6
 options 	COMPAT_FREEBSD7	# Compatible with FreeBSD7
 options 	DDB		# Support DDB
 options 	DEADLKRES	# Enable the deadlock resolver
 options 	FFS		# Berkeley Fast Filesystem
+options 	FLOWTABLE	# per-cpu routing cache
 options 	GDB		# Support remote GDB
 options 	GEOM_LABEL	# Provides labelization
+options 	INCLUDE_CONFIG_FILE     # Include this file in kernel
 options 	INET		# InterNETworking
 options 	INET6		# IPv6 communications protocols
 options 	INVARIANTS	# Enable calls of extra sanity checking
@@ -44,9 +45,11 @@ options 	MAC		# TrustedBSD MAC Framework
 options 	MD_ROOT		# MD usable as root device
 options 	MSDOSFS		# MSDOS Filesystem
 options 	NFSCLIENT	# Network Filesystem Client
-options 	NFSSERVER	# Network Filesystem Server
 options 	NFSLOCKD	# Network Lock Manager
+options 	NFSSERVER	# Network Filesystem Server
 options 	NFS_ROOT	# NFS usable as root device
+options 	P1003_1B_SEMAPHORES	# POSIX-style semaphores
+options 	PREEMPTION	# Enable kernel thread preemption
 options 	PRINTF_BUFR_SIZE=128  # Printf buffering to limit interspersion
 options 	PROCFS		# Process filesystem (/proc)
 options 	PSEUDOFS	# Pseudo-filesystem framework
@@ -59,15 +62,12 @@ options 	STACK		# stack(9) support
 options 	SYSVMSG		# SYSV-style message queues
 options 	SYSVSEM		# SYSV-style semaphores
 options 	SYSVSHM		# SYSV-style shared memory
-options 	P1003_1B_SEMAPHORES	# POSIX-style semaphores
 options 	UFS_ACL		# Support for access control lists
 options 	UFS_DIRHASH	# Hash-based directory lookup scheme
 options 	UFS_GJOURNAL	# Enable gjournal-based UFS journaling
 options 	WITNESS		# Enable checks to detect deadlocks and cycles
 options 	WITNESS_SKIPSPIN # Don't run witness on spinlocks for speed
 options 	_KPOSIX_PRIORITY_SCHEDULING	# Posix P1003_1B RT extensions
-options 	HWPMC_HOOKS	# Necessary kernel hooks for hwpmc(4)
-options 	INCLUDE_CONFIG_FILE     # Include this file in kernel
 
 # Various "busses"
 device		firewire	# FireWire bus code
@@ -81,20 +81,25 @@ device		ata		# ATA controller
 device		atadisk		# ATA disk drives
 device		atapicd		# ATAPI CDROM drives
 device		atapifd		# ATAPI floppy drives
+device		atapist		# ATAPI tape drives
 device		ataraid		# ATA RAID drives
 
 # SCSI Controllers
 device		ahc		# AHA2940 and AIC7xxx devices
 device		ahd		# AHA39320/29320 and AIC79xx devices
+device		hptiop		# Highpoint RocketRaid 3xxx series
 device		isp		# Qlogic family
 device		mpt		# LSI-Logic MPT-Fusion
 device		sym		# NCR/Symbios Logic
 
 # RAID controllers interfaced to the SCSI subsystem
+device		amr		# AMI MegaRAID
 device		ciss		# Compaq Smart RAID 5*
 device		dpt		# DPT Smartcache III, IV
 device		iir		# Intel Integrated RAID
+device		ips		# IBM (Adaptec) ServeRAID
 device		mly		# Mylex AcceleRAID/eXtremeRAID
+device		twa		# 3ware 9000 series PATA/SATA RAID
 
 # SCSI peripherals
 device		cd		# CD-ROM, DVD-ROM etc.
@@ -107,7 +112,6 @@ device		ses		# Environmental Services (and SAF-TE)
 # RAID controllers
 device		aac		# Adaptec FSA RAID
 device		aacp		# SCSI passthrough for aac (requires CAM)
-device		amr		# AMI MegaRAID
 device		ida		# Compaq Smart RAID
 device		mlx		# Mylex DAC960 family
 
@@ -123,34 +127,58 @@ device		ums		# Mouse
 
 # PCI Ethernet NICs.
 device		de		# DEC/Intel DC21x4x (``Tulip'')
-device		em		# Intel PRO/1000 adapter Gigabit Ethernet Card
-device		le		# AMD Am7900 LANCE and Am79C9xx PCnet
+device		em		# Intel PRO/1000 Gigabit Ethernet Family
+device		igb		# Intel PRO/1000 PCIE Server Gigabit Family
+device		ixgbe		# Intel PRO/10GbE PCIE Ethernet Family
 device		txp		# 3Com 3cR990 (``Typhoon'')
-device		vx		# 3Com 3c590, 3c595 (``Vortex'')
 
 # PCI Ethernet NICs that use the common MII bus controller code.
+device		ae		# Attansic/Atheros L2 FastEthernet
+device		age		# Attansic/Atheros L1 Gigabit Ethernet
+device		alc		# Atheros AR8131/AR8132 Ethernet
+device		ale		# Atheros AR8121/AR8113/AR8114 Ethernet
+device		bce		# Broadcom BCM5706/BCM5708 Gigabit Ethernet
+device		bfe		# Broadcom BCM440x 10/100 Ethernet
 device		bge		# Broadcom BCM570xx Gigabit Ethernet
-device		dc		# DEC/Intel 21143 and various workalikes
+device		et		# Agere ET1310 10/100/Gigabit Ethernet
+device		jme		# JMicron JMC250 Gigabit/JMC260 Fast Ethernet
+device		msk		# Marvell/SysKonnect Yukon II Gigabit Ethernet
+device		nge		# NatSemi DP83820 gigabit Ethernet
 device		fxp		# Intel EtherExpress PRO/100B (82557, 82558)
-device		pcn		# AMD Am79C97x PCI 10/100 (precedence over 'le')
 device		re		# RealTek 8139C+/8169/8169S/8110S
-device		rl		# RealTek 8129/8139
 device		sf		# Adaptec AIC-6915 (``Starfire'')
-device		sis		# Silicon Integrated Systems SiS 900/SiS 7016
+device		sk		# SysKonnect SK-984x & SK-982x gigabit Ethernet
+device		ste		# Sundance ST201 (D-Link DFE-550TX)
+device		stge		# Sundance/Tamarack TC9021 gigabit Ethernet
+device		tx		# SMC EtherPower II (83c170 ``EPIC'')
+device		vge		# VIA VT612x gigabit Ethernet
 device		xl		# 3Com 3c90x ("Boomerang", "Cyclone")
 
 # USB Ethernet
 device		aue		# ADMtek USB Ethernet
+device		axe		# ASIX Electronics USB Ethernet
 device		cdce		# Generic USB over Ethernet
 device		cue		# CATC USB Ethernet
 device		kue		# Kawasaki LSI USB Ethernet
+device		rue		# RealTek RTL8150 USB Ethernet
+device		udav		# Davicom DM9601E USB
+
+# USB Serial
+device		uark		# Technologies ARK3116 based serial adapters
+device		ubsa		# Belkin F5U103 and compatible serial adapters
+device		uftdi		# For FTDI usb serial adapters
+device		uipaq		# Some WinCE based devices
+device		uplcom		# Prolific PL-2303 serial adapters
+device		uslcom		# SI Labs CP2101/CP2102 serial adapters
+device		uvisor		# Visor and Palm devices
+device		uvscom		# USB serial support for DDI pocket's PHS
 
 # FireWire support
+device		fwip		# IP over FireWire (RFC 2734,3146)
 device		sbp		# SCSI over FireWire (need scbus & da)
 
 # Various (pseudo) devices
 device		ether		# Ethernet support
-device		vlan		# 802.1Q VLAN support
 device		faith		# IPv6-to-IPv4 relaying (translation)
 device		gif		# IPv6 and IPv4 tunneling
 device		loop		# Network loopback
@@ -160,6 +188,7 @@ device		puc		# Multi I/O cards and multi-channel UARTs
 device		random		# Entropy device
 device		tun		# Packet tunnel.
 device		uart		# Serial port (UART)
+device		vlan		# 802.1Q VLAN support
 device		firmware	# firmware assist module
 
 # The `bpf' device enables the Berkeley Packet Filter.
diff --git a/sys/modules/Makefile b/sys/modules/Makefile
index 72c126ac563..47800c30ed1 100644
--- a/sys/modules/Makefile
+++ b/sys/modules/Makefile
@@ -565,10 +565,7 @@ _zfs=		zfs
 .endif
 
 .if ${MACHINE_ARCH} == "ia64"
-# Modules not enabled on ia64 (as compared to i386) include:
-#	aac acpi aout apm atspeaker drm ibcs2 linprocfs linux ncv
-#	nsp s3 sbni stg vesa
-# acpi is not enabled because it is broken as a module on ia64
+_aac=		aac
 _aic=		aic
 _an=		an
 _arcnet=	arcnet
@@ -581,12 +578,17 @@ _cm=		cm
 _cmx=		cmx
 _coff=		coff
 _cpufreq=	cpufreq
+_dpt=		dpt
 _em=		em
 _ep=		ep
+_et=		et
 _exca=		exca
 _fe=		fe
+_hptiop=	hptiop
+_ida=		ida
 _igb=		igb
 _iir=		iir
+_ips=		ips
 _mly=		mly
 _pccard=	pccard
 _scsi_low=	scsi_low
@@ -595,6 +597,7 @@ _sound=		sound
 _splash=	splash
 _sppp=		sppp
 _streams=	streams
+_twa=		twa
 _wi=		wi
 _xe=		xe
 .endif

From cde587816c2ff5ad53212af4f0f1497832ba1776 Mon Sep 17 00:00:00 2001
From: Kai Wang 
Date: Sat, 27 Mar 2010 08:00:16 +0000
Subject: [PATCH 101/119] Merge improvements from kernel HID parser to the
 userland usbhid(3) parser.  This merge does not change any API and should not
 break any native or thirdparty applications.

Changes include:

* Merge multiple report ID support and other improvements from kernel
  HID parser.
* Ignore rid argument in hid_start_parser, parse all the report items since
  we now support multiple report ID.
* Skip report ID byte in hid_get_data() and set report ID byte in
  hid_set_data(), if report ID is non-zero.
* Reimplement hid_get_report_id: instead get report id from uhid device
  (which is always 0), try parsing the report descriptor and return the
  first report ID encountered.

Reviewed by:	hps
Silent on:	-usb mailing list
---
 lib/libusbhid/data.c   |  31 ++-
 lib/libusbhid/descr.c  |  22 +-
 lib/libusbhid/parse.c  | 542 +++++++++++++++++++++++++----------------
 lib/libusbhid/usage.c  |   1 +
 lib/libusbhid/usbhid.h |  63 +++--
 lib/libusbhid/usbvar.h |   4 +-
 6 files changed, 409 insertions(+), 254 deletions(-)

diff --git a/lib/libusbhid/data.c b/lib/libusbhid/data.c
index d278ddb8d87..049c88b634b 100644
--- a/lib/libusbhid/data.c
+++ b/lib/libusbhid/data.c
@@ -29,6 +29,7 @@
 #include 
 __FBSDID("$FreeBSD$");
 
+#include 
 #include 
 #include 
 #include "usbhid.h"
@@ -36,18 +37,27 @@ __FBSDID("$FreeBSD$");
 int
 hid_get_data(const void *p, const hid_item_t *h)
 {
-	const unsigned char *buf;
-	unsigned int hpos;
-	unsigned int hsize;
-	int data;
+	const uint8_t *buf;
+	uint32_t hpos;
+	uint32_t hsize;
+	uint32_t data;
 	int i, end, offs;
 
 	buf = p;
+
+	/* Skip report ID byte. */
+	if (h->report_ID > 0)
+		buf++;
+
 	hpos = h->pos;			/* bit position of data */
 	hsize = h->report_size;		/* bit length of data */
 
+	/* Range check and limit */
 	if (hsize == 0)
 		return (0);
+	if (hsize > 32)
+		hsize = 32;
+
 	offs = hpos / 8;
 	end = (hpos + hsize) / 8 - offs;
 	data = 0;
@@ -66,12 +76,17 @@ hid_get_data(const void *p, const hid_item_t *h)
 void
 hid_set_data(void *p, const hid_item_t *h, int data)
 {
-	unsigned char *buf;
-	unsigned int hpos;
-	unsigned int hsize;
+	uint8_t *buf;
+	uint32_t hpos;
+	uint32_t hsize;
 	int i, end, offs, mask;
 
 	buf = p;
+
+	/* Set report ID byte. */
+	if (h->report_ID > 0)
+		*buf++ = h->report_ID & 0xff;
+
 	hpos = h->pos;			/* bit position of data */
 	hsize = h->report_size;		/* bit length of data */
 
@@ -90,5 +105,5 @@ hid_set_data(void *p, const hid_item_t *h, int data)
 
 	for (i = 0; i <= end; i++)
 		buf[offs + i] = (buf[offs + i] & (mask >> (i*8))) |
-			((data >> (i*8)) & 0xff);
+		    ((data >> (i*8)) & 0xff);
 }
diff --git a/lib/libusbhid/descr.c b/lib/libusbhid/descr.c
index 2ce1bf01b47..a5c033abfdc 100644
--- a/lib/libusbhid/descr.c
+++ b/lib/libusbhid/descr.c
@@ -38,7 +38,6 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
-
 #include 
 
 #include "usbhid.h"
@@ -59,9 +58,30 @@ hid_set_immed(int fd, int enable)
 int
 hid_get_report_id(int fd)
 {
+	report_desc_t rep;
+	hid_data_t d;
+	hid_item_t h;
+	int kindset;
 	int temp = -1;
 	int ret;
 
+	if ((rep = hid_get_report_desc(fd)) == NULL)
+		goto use_ioctl;
+	kindset = 1 << hid_input | 1 << hid_output | 1 << hid_feature;
+	for (d = hid_start_parse(rep, kindset, 0); hid_get_item(d, &h); ) {
+		/* Return the first report ID we met. */
+		if (h.report_ID != 0) {
+			temp = h.report_ID;
+			break;
+		}
+	}
+	hid_end_parse(d);
+	hid_dispose_report_desc(rep);
+
+	if (temp > 0)
+		return (temp);
+
+use_ioctl:
 	ret = ioctl(fd, USB_GET_REPORT_ID, &temp);
 #ifdef HID_COMPAT7
 	if (ret < 0)
diff --git a/lib/libusbhid/parse.c b/lib/libusbhid/parse.c
index 3abc036644b..ce034b191a6 100644
--- a/lib/libusbhid/parse.c
+++ b/lib/libusbhid/parse.c
@@ -40,42 +40,43 @@ __FBSDID("$FreeBSD$");
 #include "usbhid.h"
 #include "usbvar.h"
 
-#define MAXUSAGE 100
-struct hid_data {
-	u_char *start;
-	u_char *end;
-	u_char *p;
-	hid_item_t cur;
-	unsigned int usages[MAXUSAGE];
-	int nusage;
-	int minset;
-	int logminsize;
-	int multi;
-	int multimax;
-	int kindset;
-	int reportid;
+#define	MAXUSAGE 100
+#define	MAXPUSH 4
+#define	MAXID 64
 
-	/*
-	 * The start of collection item has no report ID set, so save
-	 * it until we know the ID.
-	 */
-	hid_item_t savedcoll;
-	u_char hassavedcoll;
-	/*
-	 * Absolute data position (bits) for input/output/feature.
-	 *  Assumes that hid_input, hid_output and hid_feature have
-	 *  values 0, 1 and 2.
-	 */
-	unsigned int kindpos[3];
+struct hid_pos_data {
+	int32_t rid;
+	uint32_t pos;
 };
 
-static int min(int x, int y) { return x < y ? x : y; }
-
-static int hid_get_item_raw(hid_data_t s, hid_item_t *h);
+struct hid_data {
+	const uint8_t *start;
+	const uint8_t *end;
+	const uint8_t *p;
+	struct hid_item cur[MAXPUSH];
+	struct hid_pos_data last_pos[MAXID];
+	int32_t usages_min[MAXUSAGE];
+	int32_t usages_max[MAXUSAGE];
+	int32_t usage_last;	/* last seen usage */
+	uint32_t loc_size;	/* last seen size */
+	uint32_t loc_count;	/* last seen count */
+	uint8_t	kindset;	/* we have 5 kinds so 8 bits are enough */
+	uint8_t	pushlevel;	/* current pushlevel */
+	uint8_t	ncount;		/* end usage item count */
+	uint8_t icount;		/* current usage item count */
+	uint8_t	nusage;		/* end "usages_min/max" index */
+	uint8_t	iusage;		/* current "usages_min/max" index */
+	uint8_t ousage;		/* current "usages_min/max" offset */
+	uint8_t	susage;		/* usage set flags */
+};
 
+/*------------------------------------------------------------------------*
+ *	hid_clear_local
+ *------------------------------------------------------------------------*/
 static void
 hid_clear_local(hid_item_t *c)
 {
+
 	c->usage = 0;
 	c->usage_minimum = 0;
 	c->usage_maximum = 0;
@@ -88,8 +89,61 @@ hid_clear_local(hid_item_t *c)
 	c->set_delimiter = 0;
 }
 
+static void
+hid_switch_rid(struct hid_data *s, struct hid_item *c, int32_t next_rID)
+{
+	uint8_t i;
+
+	/* check for same report ID - optimise */
+
+	if (c->report_ID == next_rID)
+		return;
+
+	/* save current position for current rID */
+
+	if (c->report_ID == 0) {
+		i = 0;
+	} else {
+		for (i = 1; i != MAXID; i++) {
+			if (s->last_pos[i].rid == c->report_ID)
+				break;
+			if (s->last_pos[i].rid == 0)
+				break;
+		}
+	}
+	if (i != MAXID) {
+		s->last_pos[i].rid = c->report_ID;
+		s->last_pos[i].pos = c->pos;
+	}
+
+	/* store next report ID */
+
+	c->report_ID = next_rID;
+
+	/* lookup last position for next rID */
+
+	if (next_rID == 0) {
+		i = 0;
+	} else {
+		for (i = 1; i != MAXID; i++) {
+			if (s->last_pos[i].rid == next_rID)
+				break;
+			if (s->last_pos[i].rid == 0)
+				break;
+		}
+	}
+	if (i != MAXID) {
+		s->last_pos[i].rid = next_rID;
+		c->pos = s->last_pos[i].pos;
+	} else
+		c->pos = 0;	/* Out of RID entries. */
+}
+
+/*------------------------------------------------------------------------*
+ *	hid_start_parse
+ *------------------------------------------------------------------------*/
 hid_data_t
-hid_start_parse(report_desc_t d, int kindset, int id)
+hid_start_parse(report_desc_t d, int kindset, int id __unused)
 {
 	struct hid_data *s;
 
@@ -98,213 +152,207 @@ hid_start_parse(report_desc_t d, int kindset, int id)
 	s->start = s->p = d->data;
 	s->end = d->data + d->size;
 	s->kindset = kindset;
-	s->reportid = id;
-	s->hassavedcoll = 0;
 	return (s);
 }
 
+/*------------------------------------------------------------------------*
+ *	hid_end_parse
+ *------------------------------------------------------------------------*/
 void
 hid_end_parse(hid_data_t s)
 {
-	while (s->cur.next) {
-		hid_item_t *hi = s->cur.next->next;
-		free(s->cur.next);
-		s->cur.next = hi;
-	}
+
+	if (s == NULL)
+		return;
+
 	free(s);
 }
 
+/*------------------------------------------------------------------------*
+ *	get byte from HID descriptor
+ *------------------------------------------------------------------------*/
+static uint8_t
+hid_get_byte(struct hid_data *s, const uint16_t wSize)
+{
+	const uint8_t *ptr;
+	uint8_t retval;
+
+	ptr = s->p;
+
+	/* check if end is reached */
+	if (ptr == s->end)
+		return (0);
+
+	/* read out a byte */
+	retval = *ptr;
+
+	/* check if data pointer can be advanced by "wSize" bytes */
+	if ((s->end - ptr) < wSize)
+		ptr = s->end;
+	else
+		ptr += wSize;
+
+	/* update pointer */
+	s->p = ptr;
+
+	return (retval);
+}
+
+/*------------------------------------------------------------------------*
+ *	hid_get_item
+ *------------------------------------------------------------------------*/
 int
 hid_get_item(hid_data_t s, hid_item_t *h)
-{
-	int r;
-
-	for (;;) {
-		r = hid_get_item_raw(s, h);
-		if (r <= 0)
-			break;
-		if (h->report_ID == s->reportid || s->reportid == -1)
-			break;
-	}
-	return (r);
-}
-
-#define REPORT_SAVED_COLL \
-	do { \
-		if (s->hassavedcoll) { \
-			*h = s->savedcoll; \
-			h->report_ID = c->report_ID; \
-			s->hassavedcoll = 0; \
-			return (1); \
-		} \
-	} while(/*LINTED*/ 0)
-
-static int
-hid_get_item_raw(hid_data_t s, hid_item_t *h)
 {
 	hid_item_t *c;
-	unsigned int bTag = 0, bType = 0, bSize;
-	unsigned char *data;
-	int dval;
-	unsigned char *p;
-	hid_item_t *hi;
-	hid_item_t nc;
-	int i;
-	hid_kind_t retkind;
+	unsigned int bTag, bType, bSize;
+	uint32_t oldpos;
+	int32_t mask;
+	int32_t dval;
 
-	c = &s->cur;
+	if (s == NULL)
+		return (0);
+
+	c = &s->cur[s->pushlevel];
 
  top:
-	if (s->multimax) {
-		REPORT_SAVED_COLL;
-		if (c->logical_minimum >= c->logical_maximum) {
-			if (s->logminsize == 1)
-				c->logical_minimum =(int8_t)c->logical_minimum;
-			else if (s->logminsize == 2)
-				c->logical_minimum =(int16_t)c->logical_minimum;
-		}
-		if (s->multi < s->multimax) {
-			c->usage = s->usages[min(s->multi, s->nusage-1)];
-			s->multi++;
-			*h = *c;
-			/*
-			 * 'multimax' is only non-zero if the current
-                         *  item kind is input/output/feature
-			 */
-			h->pos = s->kindpos[c->kind];
-			s->kindpos[c->kind] += c->report_size;
-			h->next = 0;
-			return (1);
+	/* check if there is an array of items */
+	if (s->icount < s->ncount) {
+		/* get current usage */
+		if (s->iusage < s->nusage) {
+			dval = s->usages_min[s->iusage] + s->ousage;
+			c->usage = dval;
+			s->usage_last = dval;
+			if (dval == s->usages_max[s->iusage]) {
+				s->iusage ++;
+				s->ousage = 0;
+			} else {
+				s->ousage ++;
+			}
 		} else {
-			c->report_count = s->multimax;
-			s->multimax = 0;
-			s->nusage = 0;
-			hid_clear_local(c);
+			/* Using last usage */
+			dval = s->usage_last;
+		}
+		s->icount ++;
+		/* 
+		 * Only copy HID item, increment position and return
+		 * if correct kindset!
+		 */
+		if (s->kindset & (1 << c->kind)) {
+			*h = *c;
+			c->pos += c->report_size * c->report_count;
+			return (1);
 		}
 	}
-	for (;;) {
-		p = s->p;
-		if (p >= s->end)
-			return (0);
 
-		bSize = *p++;
+	/* reset state variables */
+	s->icount = 0;
+	s->ncount = 0;
+	s->iusage = 0;
+	s->nusage = 0;
+	s->susage = 0;
+	s->ousage = 0;
+	hid_clear_local(c);
+
+	/* get next item */
+	while (s->p != s->end) {
+
+		bSize = hid_get_byte(s, 1);
 		if (bSize == 0xfe) {
 			/* long item */
-			bSize = *p++;
-			bSize |= *p++ << 8;
-			bTag = *p++;
-			data = p;
-			p += bSize;
+			bSize = hid_get_byte(s, 1);
+			bSize |= hid_get_byte(s, 1) << 8;
+			bTag = hid_get_byte(s, 1);
+			bType = 0xff;	/* XXX what should it be */
 		} else {
 			/* short item */
 			bTag = bSize >> 4;
 			bType = (bSize >> 2) & 3;
 			bSize &= 3;
-			if (bSize == 3) bSize = 4;
-			data = p;
-			p += bSize;
+			if (bSize == 3)
+				bSize = 4;
 		}
-		s->p = p;
-		/*
-		 * The spec is unclear if the data is signed or unsigned.
-		 */
+
 		switch(bSize) {
 		case 0:
 			dval = 0;
+			mask = 0;
 			break;
 		case 1:
-			dval = *data++;
+			dval = (int8_t)hid_get_byte(s, 1);
+			mask = 0xFF;
 			break;
 		case 2:
-			dval = *data++;
-			dval |= *data++ << 8;
+			dval = hid_get_byte(s, 1);
+			dval |= hid_get_byte(s, 1) << 8;
+			dval = (int16_t)dval;
+			mask = 0xFFFF;
 			break;
 		case 4:
-			dval = *data++;
-			dval |= *data++ << 8;
-			dval |= *data++ << 16;
-			dval |= *data++ << 24;
+			dval = hid_get_byte(s, 1);
+			dval |= hid_get_byte(s, 1) << 8;
+			dval |= hid_get_byte(s, 1) << 16;
+			dval |= hid_get_byte(s, 1) << 24;
+			mask = 0xFFFFFFFF;
 			break;
 		default:
-			return (-1);
+			dval = hid_get_byte(s, bSize);
+			continue;
 		}
 
 		switch (bType) {
-		case 0:			/* Main */
+		case 0:		/* Main */
 			switch (bTag) {
-			case 8:		/* Input */
-				retkind = hid_input;
-			ret:
-				if (!(s->kindset & (1 << retkind))) {
-					/* Drop the items of this kind */
-					s->nusage = 0;
-					continue;
-				}
-				c->kind = retkind;
+			case 8:	/* Input */
+				c->kind = hid_input;
 				c->flags = dval;
+		ret:
+				c->report_count = s->loc_count;
+				c->report_size = s->loc_size;
+
 				if (c->flags & HIO_VARIABLE) {
-					s->multimax = c->report_count;
-					s->multi = 0;
+					/* range check usage count */
+					if (c->report_count > 255) {
+						s->ncount = 255;
+					} else
+						s->ncount = c->report_count;
+
+					/* 
+					 * The "top" loop will return
+					 * one and one item:
+					 */
 					c->report_count = 1;
-					if (s->minset) {
-						for (i = c->usage_minimum;
-						     i <= c->usage_maximum;
-						     i++) {
-							s->usages[s->nusage] = i;
-							if (s->nusage < MAXUSAGE-1)
-								s->nusage++;
-						}
-						c->usage_minimum = 0;
-						c->usage_maximum = 0;
-						s->minset = 0;
-					}
-					goto top;
 				} else {
-					if (s->minset)
-						c->usage = c->usage_minimum;
-					*h = *c;
-					h->next = 0;
-					h->pos = s->kindpos[c->kind];
-					s->kindpos[c->kind] +=
-					    c->report_size * c->report_count;
-					hid_clear_local(c);
-					s->minset = 0;
-					return (1);
+					s->ncount = 1;
 				}
-			case 9:		/* Output */
-				retkind = hid_output;
+				goto top;
+
+			case 9:	/* Output */
+				c->kind = hid_output;
+				c->flags = dval;
 				goto ret;
 			case 10:	/* Collection */
 				c->kind = hid_collection;
 				c->collection = dval;
 				c->collevel++;
-				nc = *c;
-				hid_clear_local(c);
-				/*c->report_ID = NO_REPORT_ID;*/
-				s->nusage = 0;
-				if (s->hassavedcoll) {
-					*h = s->savedcoll;
-					h->report_ID = nc.report_ID;
-					s->savedcoll = nc;
-					return (1);
-				} else {
-					s->hassavedcoll = 1;
-					s->savedcoll = nc;
-				}
-				break;
+				c->usage = s->usage_last;
+				*h = *c;
+				return (1);
 			case 11:	/* Feature */
-				retkind = hid_feature;
+				c->kind = hid_feature;
+				c->flags = dval;
 				goto ret;
 			case 12:	/* End collection */
-				REPORT_SAVED_COLL;
 				c->kind = hid_endcollection;
+				if (c->collevel == 0) {
+					/* Invalid end collection. */
+					return (0);
+				}
 				c->collevel--;
 				*h = *c;
-				/*hid_clear_local(c);*/
-				s->nusage = 0;
 				return (1);
 			default:
-				return (-2);
+				break;
 			}
 			break;
 
@@ -315,13 +363,12 @@ hid_get_item_raw(hid_data_t s, hid_item_t *h)
 				break;
 			case 1:
 				c->logical_minimum = dval;
-				s->logminsize = bSize;
 				break;
 			case 2:
 				c->logical_maximum = dval;
 				break;
 			case 3:
-				c->physical_maximum = dval;
+				c->physical_minimum = dval;
 				break;
 			case 4:
 				c->physical_maximum = dval;
@@ -333,45 +380,97 @@ hid_get_item_raw(hid_data_t s, hid_item_t *h)
 				c->unit = dval;
 				break;
 			case 7:
-				c->report_size = dval;
+				/* mask because value is unsigned */
+				s->loc_size = dval & mask;
 				break;
 			case 8:
-				c->report_ID = dval;
-				s->kindpos[hid_input] =
-				    s->kindpos[hid_output] =
-				    s->kindpos[hid_feature] = 0;
+				hid_switch_rid(s, c, dval);
 				break;
 			case 9:
-				c->report_count = dval;
+				/* mask because value is unsigned */
+				s->loc_count = dval & mask;
 				break;
-			case 10: /* Push */
-				hi = malloc(sizeof *hi);
-				*hi = s->cur;
-				c->next = hi;
+			case 10:	/* Push */
+				s->pushlevel ++;
+				if (s->pushlevel < MAXPUSH) {
+					s->cur[s->pushlevel] = *c;
+					/* store size and count */
+					c->report_size = s->loc_size;
+					c->report_count = s->loc_count;
+					/* update current item pointer */
+					c = &s->cur[s->pushlevel];
+				}
 				break;
-			case 11: /* Pop */
-				hi = c->next;
-				s->cur = *hi;
-				free(hi);
+			case 11:	/* Pop */
+				s->pushlevel --;
+				if (s->pushlevel < MAXPUSH) {
+					/* preserve position */
+					oldpos = c->pos;
+					c = &s->cur[s->pushlevel];
+					/* restore size and count */
+					s->loc_size = c->report_size;
+					s->loc_count = c->report_count;
+					/* set default item location */
+					c->pos = oldpos;
+					c->report_size = 0;
+					c->report_count = 0;
+				}
 				break;
 			default:
-				return (-3);
+				break;
 			}
 			break;
 		case 2:		/* Local */
 			switch (bTag) {
 			case 0:
-				c->usage = c->_usage_page | dval;
-				if (s->nusage < MAXUSAGE)
-					s->usages[s->nusage++] = c->usage;
+				if (bSize != 4)
+					dval = (dval & mask) | c->_usage_page;
+
+				/* set last usage, in case of a collection */
+				s->usage_last = dval;
+
+				if (s->nusage < MAXUSAGE) {
+					s->usages_min[s->nusage] = dval;
+					s->usages_max[s->nusage] = dval;
+					s->nusage ++;
+				}
 				/* else XXX */
+
+				/* clear any pending usage sets */
+				s->susage = 0;
 				break;
 			case 1:
-				s->minset = 1;
-				c->usage_minimum = c->_usage_page | dval;
-				break;
+				s->susage |= 1;
+
+				if (bSize != 4)
+					dval = (dval & mask) | c->_usage_page;
+				c->usage_minimum = dval;
+
+				goto check_set;
 			case 2:
-				c->usage_maximum = c->_usage_page | dval;
+				s->susage |= 2;
+
+				if (bSize != 4)
+					dval = (dval & mask) | c->_usage_page;
+				c->usage_maximum = dval;
+
+			check_set:
+				if (s->susage != 3)
+					break;
+
+				/* sanity check */
+				if ((s->nusage < MAXUSAGE) &&
+				    (c->usage_minimum <= c->usage_maximum)) {
+					/* add usage range */
+					s->usages_min[s->nusage] = 
+					    c->usage_minimum;
+					s->usages_max[s->nusage] = 
+					    c->usage_maximum;
+					s->nusage ++;
+				}
+				/* else XXX */
+
+				s->susage = 0;
 				break;
 			case 3:
 				c->designator_index = dval;
@@ -395,40 +494,63 @@ hid_get_item_raw(hid_data_t s, hid_item_t *h)
 				c->set_delimiter = dval;
 				break;
 			default:
-				return (-4);
+				break;
 			}
 			break;
 		default:
-			return (-5);
+			break;
 		}
 	}
+	return (0);
 }
 
 int
 hid_report_size(report_desc_t r, enum hid_kind k, int id)
 {
 	struct hid_data *d;
-	hid_item_t h;
-	int size;
+	struct hid_item h;
+	uint32_t temp;
+	uint32_t hpos;
+	uint32_t lpos;
+
+	hpos = 0;
+	lpos = 0xFFFFFFFF;
 
 	memset(&h, 0, sizeof h);
-	size = 0;
-	for (d = hid_start_parse(r, 1<kindpos[k];
+			/* compute minimum */
+			if (lpos > h.pos)
+				lpos = h.pos;
+			/* compute end position */
+			temp = h.pos + (h.report_size * h.report_count);
+			/* compute maximum */
+			if (hpos < temp)
+				hpos = temp;
 		}
 	}
 	hid_end_parse(d);
-	return ((size + 7) / 8);
+
+	/* safety check - can happen in case of currupt descriptors */
+	if (lpos > hpos)
+		temp = 0;
+	else
+		temp = hpos - lpos;
+
+	if (id)
+		temp += 8;
+
+	/* return length in bytes rounded up */
+	return ((temp + 7) / 8);
 }
 
 int
 hid_locate(report_desc_t desc, unsigned int u, enum hid_kind k,
 	   hid_item_t *h, int id)
 {
-	hid_data_t d;
+	struct hid_data *d;
 
-	for (d = hid_start_parse(desc, 1<kind == k && !(h->flags & HIO_CONST) && h->usage == u) {
 			hid_end_parse(d);
 			return (1);
diff --git a/lib/libusbhid/usage.c b/lib/libusbhid/usage.c
index 280ef69aae8..eeff818afed 100644
--- a/lib/libusbhid/usage.c
+++ b/lib/libusbhid/usage.c
@@ -29,6 +29,7 @@
 #include 
 __FBSDID("$FreeBSD$");
 
+#include 
 #include 
 #include 
 #include 
diff --git a/lib/libusbhid/usbhid.h b/lib/libusbhid/usbhid.h
index b8751cd456a..d1d3bf0ebbd 100644
--- a/lib/libusbhid/usbhid.h
+++ b/lib/libusbhid/usbhid.h
@@ -29,52 +29,48 @@
  *
  */
 
-#include 
+#include 
 
 typedef struct report_desc *report_desc_t;
 
 typedef struct hid_data *hid_data_t;
 
 typedef enum hid_kind {
-	hid_input = 0,
-	hid_output = 1,
-	hid_feature = 2,
-	hid_collection,
-	hid_endcollection
+	hid_input, hid_output, hid_feature, hid_collection, hid_endcollection
 } hid_kind_t;
 
 typedef struct hid_item {
 	/* Global */
-	unsigned int _usage_page;
-	int logical_minimum;
-	int logical_maximum;
-	int physical_minimum;
-	int physical_maximum;
-	int unit_exponent;
-	int unit;
-	int report_size;
-	int report_ID;
+	uint32_t _usage_page;
+	int32_t logical_minimum;
+	int32_t logical_maximum;
+	int32_t physical_minimum;
+	int32_t physical_maximum;
+	int32_t unit_exponent;
+	int32_t unit;
+	int32_t report_size;
+	int32_t report_ID;
 #define NO_REPORT_ID 0
-	int report_count;
+	int32_t report_count;
 	/* Local */
-	unsigned int usage;
-	int usage_minimum;
-	int usage_maximum;
-	int designator_index;
-	int designator_minimum;
-	int designator_maximum;
-	int string_index;
-	int string_minimum;
-	int string_maximum;
-	int set_delimiter;
+	uint32_t usage;
+	int32_t usage_minimum;
+	int32_t usage_maximum;
+	int32_t designator_index;
+	int32_t designator_minimum;
+	int32_t designator_maximum;
+	int32_t string_index;
+	int32_t string_minimum;
+	int32_t string_maximum;
+	int32_t set_delimiter;
 	/* Misc */
-	int collection;
-	int collevel;
+	int32_t collection;
+	int	collevel;
 	enum hid_kind kind;
-	unsigned int flags;
-	/* Absolute data position (bits) */
-	unsigned int pos;
-	/* */
+	uint32_t flags;
+	/* Location */
+	uint32_t pos;
+	/* unused */
 	struct hid_item *next;
 } hid_item_t;
 
@@ -95,7 +91,8 @@ hid_data_t hid_start_parse(report_desc_t d, int kindset, int id);
 void hid_end_parse(hid_data_t s);
 int hid_get_item(hid_data_t s, hid_item_t *h);
 int hid_report_size(report_desc_t d, enum hid_kind k, int id);
-int hid_locate(report_desc_t d, unsigned int usage, enum hid_kind k, hid_item_t *h, int id);
+int hid_locate(report_desc_t d, unsigned int usage, enum hid_kind k,
+    hid_item_t *h, int id);
 
 /* Conversion to/from usage names, usage.c: */
 const char *hid_usage_page(int i);
diff --git a/lib/libusbhid/usbvar.h b/lib/libusbhid/usbvar.h
index d43700538d5..96051061a73 100644
--- a/lib/libusbhid/usbvar.h
+++ b/lib/libusbhid/usbvar.h
@@ -30,8 +30,8 @@
  */
 
 struct report_desc {
-	unsigned int size;
-	unsigned char data[1];
+	uint32_t size;
+	uint8_t data[1];
 };
 
 /* internal backwards compatibility functions */

From 5a64472b2a8809ef54eeba54a754796afeffe4e6 Mon Sep 17 00:00:00 2001
From: Antoine Brodin 
Date: Sat, 27 Mar 2010 13:43:18 +0000
Subject: [PATCH 102/119] (S)LIST_HEAD_INITIALIZER takes a (S)LIST_HEAD as an
 argument. Fix some wrong usages. Note: this does not affect generated
 binaries as this argument is not used.

Approved by:	harti@
---
 contrib/bsnmp/gensnmpdef/gensnmpdef.c | 2 +-
 contrib/bsnmp/snmpd/config.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/bsnmp/gensnmpdef/gensnmpdef.c b/contrib/bsnmp/gensnmpdef/gensnmpdef.c
index 55c02c7191a..e4f1e5ce7d9 100644
--- a/contrib/bsnmp/gensnmpdef/gensnmpdef.c
+++ b/contrib/bsnmp/gensnmpdef/gensnmpdef.c
@@ -59,7 +59,7 @@ struct tdef {
 	SLIST_ENTRY(tdef) link;
 };
 
-static SLIST_HEAD(, tdef) tdefs = SLIST_HEAD_INITIALIZER(tdef);
+static SLIST_HEAD(, tdef) tdefs = SLIST_HEAD_INITIALIZER(tdefs);
 static int do_typedef = 0;
 
 static void print_node(SmiNode *n, u_int level);
diff --git a/contrib/bsnmp/snmpd/config.c b/contrib/bsnmp/snmpd/config.c
index 6480d204ded..48044ec978a 100644
--- a/contrib/bsnmp/snmpd/config.c
+++ b/contrib/bsnmp/snmpd/config.c
@@ -134,7 +134,7 @@ struct macro {
 	LIST_ENTRY(macro) link;
 	int	perm;
 };
-static LIST_HEAD(, macro) macros = LIST_HEAD_INITIALIZER(¯os);
+static LIST_HEAD(, macro) macros = LIST_HEAD_INITIALIZER(macros);
 
 enum {
 	TOK_EOF	= 0200,

From 42d008a11cb954ef09e986c2991f2110ae7c530b Mon Sep 17 00:00:00 2001
From: Alexander Motin 
Date: Sat, 27 Mar 2010 15:39:19 +0000
Subject: [PATCH 103/119] Fix lock leakage.

PR:		kern/145081
---
 sys/dev/sound/pcm/dsp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c
index d0ebfad0071..19801b2e694 100644
--- a/sys/dev/sound/pcm/dsp.c
+++ b/sys/dev/sound/pcm/dsp.c
@@ -1071,6 +1071,7 @@ dsp_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode,
 	if (IOCGROUP(cmd) == 'M') {
 		if (cmd == OSS_GETVERSION) {
 			*arg_i = SOUND_VERSION;
+			PCM_GIANT_EXIT(d);
 			return (0);
 		}
 		ret = dsp_ioctl_channel(i_dev, PCM_VOLCH(i_dev), cmd, arg);

From 0d9014f354f23efdd8e929c505b11788a1ac019f Mon Sep 17 00:00:00 2001
From: Pawel Jakub Dawidek 
Date: Sat, 27 Mar 2010 16:35:07 +0000
Subject: [PATCH 104/119] Don't hold connection lock when doing reconnects as
 it makes I/Os wait for connection timeouts.

Reported by:	Kevin Day 
---
 sbin/hastd/primary.c | 76 +++++++++++++++++++++++++++++---------------
 1 file changed, 50 insertions(+), 26 deletions(-)

diff --git a/sbin/hastd/primary.c b/sbin/hastd/primary.c
index ed6e91ca8b8..20af0b983c1 100644
--- a/sbin/hastd/primary.c
+++ b/sbin/hastd/primary.c
@@ -460,9 +460,11 @@ init_local(struct hast_resource *res)
 		exit(EX_NOINPUT);
 }
 
-static void
-init_remote(struct hast_resource *res)
+static bool
+init_remote(struct hast_resource *res, struct proto_conn **inp,
+    struct proto_conn **outp)
 {
+	struct proto_conn *in, *out;
 	struct nv *nvout, *nvin;
 	const unsigned char *token;
 	unsigned char *map;
@@ -472,13 +474,17 @@ init_remote(struct hast_resource *res)
 	uint32_t mapsize;
 	size_t size;
 
+	assert((inp == NULL && outp == NULL) || (inp != NULL && outp != NULL));
+
+	in = out = NULL;
+
 	/* Prepare outgoing connection with remote node. */
-	if (proto_client(res->hr_remoteaddr, &res->hr_remoteout) < 0) {
+	if (proto_client(res->hr_remoteaddr, &out) < 0) {
 		primary_exit(EX_OSERR, "Unable to create connection to %s",
 		    res->hr_remoteaddr);
 	}
 	/* Try to connect, but accept failure. */
-	if (proto_connect(res->hr_remoteout) < 0) {
+	if (proto_connect(out) < 0) {
 		pjdlog_errno(LOG_WARNING, "Unable to connect to %s",
 		    res->hr_remoteaddr);
 		goto close;
@@ -496,7 +502,7 @@ init_remote(struct hast_resource *res)
 		nv_free(nvout);
 		goto close;
 	}
-	if (hast_proto_send(res, res->hr_remoteout, nvout, NULL, 0) < 0) {
+	if (hast_proto_send(res, out, nvout, NULL, 0) < 0) {
 		pjdlog_errno(LOG_WARNING,
 		    "Unable to send handshake header to %s",
 		    res->hr_remoteaddr);
@@ -504,7 +510,7 @@ init_remote(struct hast_resource *res)
 		goto close;
 	}
 	nv_free(nvout);
-	if (hast_proto_recv_hdr(res->hr_remoteout, &nvin) < 0) {
+	if (hast_proto_recv_hdr(out, &nvin) < 0) {
 		pjdlog_errno(LOG_WARNING,
 		    "Unable to receive handshake header from %s",
 		    res->hr_remoteaddr);
@@ -536,12 +542,12 @@ init_remote(struct hast_resource *res)
 	 * Second handshake step.
 	 * Setup incoming connection with remote node.
 	 */
-	if (proto_client(res->hr_remoteaddr, &res->hr_remotein) < 0) {
+	if (proto_client(res->hr_remoteaddr, &in) < 0) {
 		pjdlog_errno(LOG_WARNING, "Unable to create connection to %s",
 		    res->hr_remoteaddr);
 	}
 	/* Try to connect, but accept failure. */
-	if (proto_connect(res->hr_remotein) < 0) {
+	if (proto_connect(in) < 0) {
 		pjdlog_errno(LOG_WARNING, "Unable to connect to %s",
 		    res->hr_remoteaddr);
 		goto close;
@@ -560,7 +566,7 @@ init_remote(struct hast_resource *res)
 		nv_free(nvout);
 		goto close;
 	}
-	if (hast_proto_send(res, res->hr_remotein, nvout, NULL, 0) < 0) {
+	if (hast_proto_send(res, in, nvout, NULL, 0) < 0) {
 		pjdlog_errno(LOG_WARNING,
 		    "Unable to send handshake header to %s",
 		    res->hr_remoteaddr);
@@ -568,7 +574,7 @@ init_remote(struct hast_resource *res)
 		goto close;
 	}
 	nv_free(nvout);
-	if (hast_proto_recv_hdr(res->hr_remoteout, &nvin) < 0) {
+	if (hast_proto_recv_hdr(out, &nvin) < 0) {
 		pjdlog_errno(LOG_WARNING,
 		    "Unable to receive handshake header from %s",
 		    res->hr_remoteaddr);
@@ -611,7 +617,7 @@ init_remote(struct hast_resource *res)
 		 * Remote node have some dirty extents on its own, lets
 		 * download its activemap.
 		 */
-		if (hast_proto_recv_data(res, res->hr_remoteout, nvin, map,
+		if (hast_proto_recv_data(res, out, nvin, map,
 		    mapsize) < 0) {
 			pjdlog_errno(LOG_ERR,
 			    "Unable to receive remote activemap");
@@ -631,18 +637,29 @@ init_remote(struct hast_resource *res)
 		(void)hast_activemap_flush(res);
 	}
 	pjdlog_info("Connected to %s.", res->hr_remoteaddr);
+	if (inp != NULL && outp != NULL) {
+		*inp = in;
+		*outp = out;
+	} else {
+		res->hr_remotein = in;
+		res->hr_remoteout = out;
+	}
+	return (true);
+close:
+	proto_close(out);
+	if (in != NULL)
+		proto_close(in);
+	return (false);
+}
+
+static void
+sync_start(void)
+{
+
 	mtx_lock(&sync_lock);
 	sync_inprogress = true;
 	mtx_unlock(&sync_lock);
 	cv_signal(&sync_cond);
-	return;
-close:
-	proto_close(res->hr_remoteout);
-	res->hr_remoteout = NULL;
-	if (res->hr_remotein != NULL) {
-		proto_close(res->hr_remotein);
-		res->hr_remotein = NULL;
-	}
 }
 
 static void
@@ -735,7 +752,8 @@ hastd_primary(struct hast_resource *res)
 	setproctitle("%s (primary)", res->hr_name);
 
 	init_local(res);
-	init_remote(res);
+	if (init_remote(res, NULL, NULL))
+		sync_start();
 	init_ggate(res);
 	init_environment(res);
 	error = pthread_create(&td, NULL, ggate_recv_thread, res);
@@ -1695,6 +1713,7 @@ static void *
 guard_thread(void *arg)
 {
 	struct hast_resource *res = arg;
+	struct proto_conn *in, *out;
 	unsigned int ii, ncomps;
 	int timeout;
 
@@ -1738,26 +1757,31 @@ guard_thread(void *arg)
 				 * connected.
 				 */
 				rw_unlock(&hio_remote_lock[ii]);
-				rw_wlock(&hio_remote_lock[ii]);
-				assert(res->hr_remotein == NULL);
-				assert(res->hr_remoteout == NULL);
 				pjdlog_debug(2,
 				    "remote_guard: Reconnecting to %s.",
 				    res->hr_remoteaddr);
-				init_remote(res);
-				if (ISCONNECTED(res, ii)) {
+				in = out = NULL;
+				if (init_remote(res, &in, &out)) {
+					rw_wlock(&hio_remote_lock[ii]);
+					assert(res->hr_remotein == NULL);
+					assert(res->hr_remoteout == NULL);
+					assert(in != NULL && out != NULL);
+					res->hr_remotein = in;
+					res->hr_remoteout = out;
+					rw_unlock(&hio_remote_lock[ii]);
 					pjdlog_info("Successfully reconnected to %s.",
 					    res->hr_remoteaddr);
+					sync_start();
 				} else {
 					/* Both connections should be NULL. */
 					assert(res->hr_remotein == NULL);
 					assert(res->hr_remoteout == NULL);
+					assert(in == NULL && out == NULL);
 					pjdlog_debug(2,
 					    "remote_guard: Reconnect to %s failed.",
 					    res->hr_remoteaddr);
 					timeout = RECONNECT_SLEEP;
 				}
-				rw_unlock(&hio_remote_lock[ii]);
 			}
 		}
 		(void)cv_timedwait(&hio_guard_cond, &hio_guard_lock, timeout);

From a57d0d8e1d6338620bdf6e101c40736cf76c6028 Mon Sep 17 00:00:00 2001
From: Alan Cox 
Date: Sat, 27 Mar 2010 18:24:27 +0000
Subject: [PATCH 105/119] Simplify pmap_growkernel(), making the i386 version
 more like the amd64 version.

MFC after:	3 weeks
---
 sys/i386/i386/pmap.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/sys/i386/i386/pmap.c b/sys/i386/i386/pmap.c
index c5018786433..ff7eff1563d 100644
--- a/sys/i386/i386/pmap.c
+++ b/sys/i386/i386/pmap.c
@@ -207,8 +207,8 @@ vm_offset_t virtual_end;	/* VA of last avail page (end of kernel AS) */
 int pgeflag = 0;		/* PG_G or-in */
 int pseflag = 0;		/* PG_PS or-in */
 
-static int nkpt;
-vm_offset_t kernel_vm_end;
+static int nkpt = NKPT;
+vm_offset_t kernel_vm_end = KERNBASE + NKPT * NBPDR;
 extern u_int32_t KERNend;
 extern u_int32_t KPTphys;
 
@@ -395,7 +395,6 @@ pmap_bootstrap(vm_paddr_t firstaddr)
 	mtx_lock_spin(&allpmaps_lock);
 	LIST_INSERT_HEAD(&allpmaps, kernel_pmap, pm_list);
 	mtx_unlock_spin(&allpmaps_lock);
-	nkpt = NKPT;
 
 	/*
 	 * Reserve some special page table entries/VA space for temporary
@@ -2032,24 +2031,12 @@ pmap_growkernel(vm_offset_t addr)
 	pd_entry_t newpdir;
 
 	mtx_assert(&kernel_map->system_mtx, MA_OWNED);
-	if (kernel_vm_end == 0) {
-		kernel_vm_end = KERNBASE;
-		nkpt = 0;
-		while (pdir_pde(PTD, kernel_vm_end)) {
-			kernel_vm_end = (kernel_vm_end + PAGE_SIZE * NPTEPG) & ~(PAGE_SIZE * NPTEPG - 1);
-			nkpt++;
-			if (kernel_vm_end - 1 >= kernel_map->max_offset) {
-				kernel_vm_end = kernel_map->max_offset;
-				break;
-			}
-		}
-	}
-	addr = roundup2(addr, PAGE_SIZE * NPTEPG);
+	addr = roundup2(addr, NBPDR);
 	if (addr - 1 >= kernel_map->max_offset)
 		addr = kernel_map->max_offset;
 	while (kernel_vm_end < addr) {
 		if (pdir_pde(PTD, kernel_vm_end)) {
-			kernel_vm_end = (kernel_vm_end + PAGE_SIZE * NPTEPG) & ~(PAGE_SIZE * NPTEPG - 1);
+			kernel_vm_end = (kernel_vm_end + NBPDR) & ~PDRMASK;
 			if (kernel_vm_end - 1 >= kernel_map->max_offset) {
 				kernel_vm_end = kernel_map->max_offset;
 				break;
@@ -2072,7 +2059,7 @@ pmap_growkernel(vm_offset_t addr)
 		pdir_pde(KPTD, kernel_vm_end) = pgeflag | newpdir;
 
 		pmap_kenter_pde(kernel_vm_end, newpdir);
-		kernel_vm_end = (kernel_vm_end + PAGE_SIZE * NPTEPG) & ~(PAGE_SIZE * NPTEPG - 1);
+		kernel_vm_end = (kernel_vm_end + NBPDR) & ~PDRMASK;
 		if (kernel_vm_end - 1 >= kernel_map->max_offset) {
 			kernel_vm_end = kernel_map->max_offset;
 			break;

From 3792de2e870d51bf312b1aa3ab7b5427b78687e2 Mon Sep 17 00:00:00 2001
From: Alan Cox 
Date: Sat, 27 Mar 2010 23:53:47 +0000
Subject: [PATCH 106/119] Correctly handle preemption of
 pmap_update_pde_invalidate().

X-MFC after:	r205573
---
 sys/amd64/amd64/pmap.c | 7 +++++--
 sys/i386/i386/pmap.c   | 7 +++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c
index d6cddb01441..4b3f0413191 100644
--- a/sys/amd64/amd64/pmap.c
+++ b/sys/amd64/amd64/pmap.c
@@ -880,9 +880,12 @@ pmap_update_pde_invalidate(vm_offset_t va, pd_entry_t newpde)
 		load_cr4(cr4 & ~CR4_PGE);
 		/*
 		 * Although preemption at this point could be detrimental to
-		 * performance, it would not lead to an error.
+		 * performance, it would not lead to an error.  PG_G is simply
+		 * ignored if CR4.PGE is clear.  Moreover, in case this block
+		 * is re-entered, the load_cr4() either above or below will
+		 * modify CR4.PGE flushing the TLB.
 		 */
-		load_cr4(cr4);
+		load_cr4(cr4 | CR4_PGE);
 	}
 }
 #ifdef SMP
diff --git a/sys/i386/i386/pmap.c b/sys/i386/i386/pmap.c
index ff7eff1563d..7c74f00bb2c 100644
--- a/sys/i386/i386/pmap.c
+++ b/sys/i386/i386/pmap.c
@@ -917,9 +917,12 @@ pmap_update_pde_invalidate(vm_offset_t va, pd_entry_t newpde)
 		load_cr4(cr4 & ~CR4_PGE);
 		/*
 		 * Although preemption at this point could be detrimental to
-		 * performance, it would not lead to an error.
+		 * performance, it would not lead to an error.  PG_G is simply
+		 * ignored if CR4.PGE is clear.  Moreover, in case this block
+		 * is re-entered, the load_cr4() either above or below will
+		 * modify CR4.PGE flushing the TLB.
 		 */
-		load_cr4(cr4);
+		load_cr4(cr4 | CR4_PGE);
 	}
 }
 #ifdef SMP

From 3905e2089818d977626dfaa82cce249b33c24b75 Mon Sep 17 00:00:00 2001
From: "Justin T. Gibbs" 
Date: Sun, 28 Mar 2010 00:10:09 +0000
Subject: [PATCH 107/119] Use standard types in preference to BSD types so that
 these header files can be used in applications compiled with only POSIX types
 visible.

MFC after: 2 weeks
---
 sys/dev/bktr/ioctl_bt848.h  | 14 +++++++-------
 sys/dev/bktr/ioctl_meteor.h | 26 +++++++++++++-------------
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/sys/dev/bktr/ioctl_bt848.h b/sys/dev/bktr/ioctl_bt848.h
index 3731e7d2b34..6e50b615deb 100644
--- a/sys/dev/bktr/ioctl_bt848.h
+++ b/sys/dev/bktr/ioctl_bt848.h
@@ -89,9 +89,9 @@
  * EEProm stuff
  */
 struct eeProm {
-	short	offset;
-	short	count;
-	u_char	bytes[ 256 ];
+	short		offset;
+	short		count;
+	unsigned char	bytes[ 256 ];
 };
 
 
@@ -147,7 +147,7 @@ struct eeProm {
  * b23-b16:  i2c addr (write)
  * b31-b24:  1 = write, 0 = read 
  */
-#define BT848_I2CWR     _IOWR('x', 57, u_long)    /* i2c read-write */
+#define BT848_I2CWR     _IOWR('x', 57, unsigned long)    /* i2c read-write */
 
 struct bktr_msp_control {
 	unsigned char function;
@@ -192,10 +192,10 @@ typedef enum { METEOR_PIXTYPE_RGB, METEOR_PIXTYPE_YUV,
 
 
 struct meteor_pixfmt {
-	u_int          index;         /* Index in supported pixfmt list     */
+	unsigned int   index;         /* Index in supported pixfmt list     */
 	METEOR_PIXTYPE type;          /* What's the board gonna feed us     */
-	u_int          Bpp;           /* Bytes per pixel                    */
-	u_long         masks[3];      /* R,G,B or Y,U,V masks, respectively */
+	unsigned int   Bpp;           /* Bytes per pixel                    */
+	unsigned long  masks[3];      /* R,G,B or Y,U,V masks, respectively */
 	unsigned       swap_bytes :1; /* Bytes  swapped within shorts       */
 	unsigned       swap_shorts:1; /* Shorts swapped within longs        */
 };
diff --git a/sys/dev/bktr/ioctl_meteor.h b/sys/dev/bktr/ioctl_meteor.h
index 681990aa03c..8e769ecbe92 100644
--- a/sys/dev/bktr/ioctl_meteor.h
+++ b/sys/dev/bktr/ioctl_meteor.h
@@ -50,27 +50,27 @@ struct meteor_capframe {
 
 /* structure for METEOR[GS]ETGEO - get/set geometry  */
 struct meteor_geomet {
-	u_short		rows;
-	u_short		columns;
-	u_short		frames;
-	u_long		oformat;
+	unsigned short		rows;
+	unsigned short		columns;
+	unsigned short		frames;
+	unsigned long		oformat;
 } ;
 
 /* structure for METEORGCOUNT-get count of frames, fifo errors and dma errors */
 struct meteor_counts {
-	u_long fifo_errors;	/* count of fifo errors since open */
-	u_long dma_errors;	/* count of dma errors since open */
-	u_long frames_captured;	/* count of frames captured since open */
-	u_long even_fields_captured; /* count of even fields captured */
-	u_long odd_fields_captured; /* count of odd fields captured */
+	unsigned long fifo_errors;	/* count of fifo errors since open */
+	unsigned long dma_errors;	/* count of dma errors since open */
+	unsigned long frames_captured;	/* count of frames captured since open */
+	unsigned long even_fields_captured; /* count of even fields captured */
+	unsigned long odd_fields_captured; /* count of odd fields captured */
 } ;
 
 /* structure for getting and setting direct transfers to vram */
 struct meteor_video {
-	u_long	addr;	/* Address of location to dma to */
-	u_long	width;	/* Width of memory area */
-	u_long	banksize;	/* Size of Vram bank */
-	u_long	ramsize;	/* Size of Vram */
+	unsigned long	addr;		/* Address of location to dma to */
+	unsigned long	width;		/* Width of memory area */
+	unsigned long	banksize;	/* Size of Vram bank */
+	unsigned long	ramsize;	/* Size of Vram */
 };
 
 #define METEORCAPTUR _IOW('x', 1, int)			 /* capture a frame */

From 8b7893b056cf070eb88621171640f3930cdd5c4f Mon Sep 17 00:00:00 2001
From: "Bjoern A. Zeeb" 
Date: Sun, 28 Mar 2010 06:51:50 +0000
Subject: [PATCH 108/119] When tearing down IPsec as part of a (virtual)
 network stack, do not try to free the same list twice but free both the
 acquiring list and the security policy acquiring list.

Reviewed by:	anchie
MFC after:	3 days
---
 sys/netipsec/key.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/sys/netipsec/key.c b/sys/netipsec/key.c
index c5aa4b78ba8..e3a61aced00 100644
--- a/sys/netipsec/key.c
+++ b/sys/netipsec/key.c
@@ -7779,7 +7779,8 @@ void
 key_destroy(void)
 {
 	struct secpolicy *sp, *nextsp;
-	struct secspacq *acq, *nextacq;
+	struct secacq *acq, *nextacq;
+	struct secspacq *spacq, *nextspacq;
 	struct secashead *sah, *nextsah;
 	struct secreg *reg;
 	int i;
@@ -7820,7 +7821,7 @@ key_destroy(void)
 	REGTREE_UNLOCK();
 
 	ACQ_LOCK();
-	for (acq = LIST_FIRST(&V_spacqtree); acq != NULL; acq = nextacq) {
+	for (acq = LIST_FIRST(&V_acqtree); acq != NULL; acq = nextacq) {
 		nextacq = LIST_NEXT(acq, chain);
 		if (__LIST_CHAINED(acq)) {
 			LIST_REMOVE(acq, chain);
@@ -7830,11 +7831,12 @@ key_destroy(void)
 	ACQ_UNLOCK();
 
 	SPACQ_LOCK();
-	for (acq = LIST_FIRST(&V_spacqtree); acq != NULL; acq = nextacq) {
-		nextacq = LIST_NEXT(acq, chain);
-		if (__LIST_CHAINED(acq)) {
-			LIST_REMOVE(acq, chain);
-			free(acq, M_IPSEC_SAQ);
+	for (spacq = LIST_FIRST(&V_spacqtree); spacq != NULL;
+	    spacq = nextspacq) {
+		nextspacq = LIST_NEXT(spacq, chain);
+		if (__LIST_CHAINED(spacq)) {
+			LIST_REMOVE(spacq, chain);
+			free(spacq, M_IPSEC_SAQ);
 		}
 	}
 	SPACQ_UNLOCK();

From 4e87d54a579146edac6c6b431a2e97ae05a885b9 Mon Sep 17 00:00:00 2001
From: Rui Paulo 
Date: Sun, 28 Mar 2010 12:55:31 +0000
Subject: [PATCH 109/119] Add a comment explaining the previous commit.

Submitted by:	sam
---
 sys/net80211/ieee80211_hostap.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/sys/net80211/ieee80211_hostap.c b/sys/net80211/ieee80211_hostap.c
index 9f1d3b53974..63bcd3c9a14 100644
--- a/sys/net80211/ieee80211_hostap.c
+++ b/sys/net80211/ieee80211_hostap.c
@@ -883,6 +883,11 @@ hostap_input(struct ieee80211_node *ni, struct mbuf *m, int rssi, int nf)
 			wh = mtod(m, struct ieee80211_frame *);
 			wh->i_fc[1] &= ~IEEE80211_FC1_WEP;
 		}
+		/*
+		 * Pass the packet to radiotap before calling iv_recv_mgmt().
+		 * Otherwise iv_recv_mgmt() might pass another packet to
+		 * radiotap, resulting in out of order packet captures.
+		 */
 		if (ieee80211_radiotap_active_vap(vap))
 			ieee80211_radiotap_rx(vap, m);
 		need_tap = 0;

From 510ea843baf66ae678ca6ddbbbca9816177be5b0 Mon Sep 17 00:00:00 2001
From: Ed Schouten 
Date: Sun, 28 Mar 2010 13:13:22 +0000
Subject: [PATCH 110/119] Rename st_*timespec fields to st_*tim for POSIX 2008
 compliance.

A nice thing about POSIX 2008 is that it finally standardizes a way to
obtain file access/modification/change times in sub-second precision,
namely using struct timespec, which we already have for a very long
time. Unfortunately POSIX uses different names.

This commit adds compatibility macros, so existing code should still
build properly. Also change all source code in the kernel to work
without any of the compatibility macros. This makes it all a less
ambiguous.

I am also renaming st_birthtime to st_birthtim, even though it was a
local extension anyway. It seems Cygwin also has a st_birthtim.
---
 lib/libc/sys/stat.2                   | 28 ++++++-----
 sys/amd64/linux32/linux.h             | 18 +++----
 sys/compat/freebsd32/freebsd32.h      |  8 +--
 sys/compat/freebsd32/freebsd32_misc.c |  6 +--
 sys/compat/linux/linux_stats.c        | 27 ++++++----
 sys/compat/svr4/svr4_stat.c           | 18 +++----
 sys/i386/ibcs2/ibcs2_stat.c           |  6 +--
 sys/i386/linux/linux.h                | 18 +++----
 sys/kern/sys_pipe.c                   |  6 +--
 sys/kern/tty_pts.c                    |  6 +--
 sys/kern/uipc_mqueue.c                |  8 +--
 sys/kern/uipc_sem.c                   |  8 +--
 sys/kern/uipc_shm.c                   |  8 +--
 sys/kern/vfs_syscalls.c               | 14 +++---
 sys/kern/vfs_vnops.c                  |  8 +--
 sys/sys/_timespec.h                   | 26 ++++------
 sys/sys/stat.h                        | 71 +++++++++++----------------
 sys/sys/timespec.h                    | 15 +-----
 18 files changed, 140 insertions(+), 159 deletions(-)

diff --git a/lib/libc/sys/stat.2 b/lib/libc/sys/stat.2
index 3085ef0f6d4..917b6befcdf 100644
--- a/lib/libc/sys/stat.2
+++ b/lib/libc/sys/stat.2
@@ -149,8 +149,8 @@ fields together identify the file uniquely within the system.
 The time-related fields of
 .Vt "struct stat"
 are as follows:
-.Bl -tag -width ".Va st_birthtime"
-.It Va st_atime
+.Bl -tag -width ".Va st_birthtim"
+.It Va st_atim
 Time when file data last accessed.
 Changed by the
 .Xr mknod 2 ,
@@ -159,7 +159,7 @@ Changed by the
 and
 .Xr readv 2
 system calls.
-.It Va st_mtime
+.It Va st_mtim
 Time when file data last modified.
 Changed by the
 .Xr mkdir 2 ,
@@ -170,7 +170,7 @@ Changed by the
 and
 .Xr writev 2
 system calls.
-.It Va st_ctime
+.It Va st_ctim
 Time when file status was last changed (inode data modification).
 Changed by the
 .Xr chflags 2 ,
@@ -191,18 +191,24 @@ Changed by the
 and
 .Xr writev 2
 system calls.
-.It Va st_birthtime
+.It Va st_birthtim
 Time when the inode was created.
 .El
 .Pp
-If
-.Dv _POSIX_SOURCE
-is not defined, the time-related fields are defined as:
+The following time-related macros are defined for compatibility:
 .Bd -literal
+#define	st_atime		st_atim.tv_sec
+#define	st_mtime		st_mtim.tv_sec
+#define	st_ctime		st_ctim.tv_sec
 #ifndef _POSIX_SOURCE
-#define st_atime st_atimespec.tv_sec
-#define st_mtime st_mtimespec.tv_sec
-#define st_ctime st_ctimespec.tv_sec
+#define	st_birthtime		st_birthtim.tv_sec
+#endif
+
+#ifndef _POSIX_SOURCE
+#define	st_atimespec		st_atim
+#define	st_mtimespec		st_mtim
+#define	st_ctimespec		st_ctim
+#define	st_birthtimespec	st_birthtim
 #endif
 .Ed
 .Pp
diff --git a/sys/amd64/linux32/linux.h b/sys/amd64/linux32/linux.h
index 350e773144a..239412cdf96 100644
--- a/sys/amd64/linux32/linux.h
+++ b/sys/amd64/linux32/linux.h
@@ -203,9 +203,9 @@ struct l_newstat {
 	l_ulong		st_size;
 	l_ulong		st_blksize;
 	l_ulong		st_blocks;
-	struct l_timespec	st_atimespec;
-	struct l_timespec	st_mtimespec;
-	struct l_timespec	st_ctimespec;
+	struct l_timespec	st_atim;
+	struct l_timespec	st_mtim;
+	struct l_timespec	st_ctim;
 	l_ulong		__unused4;
 	l_ulong		__unused5;
 } __packed;
@@ -219,9 +219,9 @@ struct l_stat {
 	l_ushort	st_gid;
 	l_ushort	st_rdev;
 	l_long		st_size;
-	struct l_timespec	st_atimespec;
-	struct l_timespec	st_mtimespec;
-	struct l_timespec	st_ctimespec;
+	struct l_timespec	st_atim;
+	struct l_timespec	st_mtim;
+	struct l_timespec	st_ctim;
 	l_long		st_blksize;
 	l_long		st_blocks;
 	l_ulong		st_flags;
@@ -242,9 +242,9 @@ struct l_stat64 {
 	l_ulong		st_blksize;
 	l_ulong		st_blocks;
 	l_ulong		__pad4;
-	struct l_timespec	st_atimespec;
-	struct l_timespec	st_mtimespec;
-	struct l_timespec	st_ctimespec;
+	struct l_timespec	st_atim;
+	struct l_timespec	st_mtim;
+	struct l_timespec	st_ctim;
 	l_ulonglong	st_ino;
 } __packed;
 
diff --git a/sys/compat/freebsd32/freebsd32.h b/sys/compat/freebsd32/freebsd32.h
index b68f8fbbc03..e74da64ecf1 100644
--- a/sys/compat/freebsd32/freebsd32.h
+++ b/sys/compat/freebsd32/freebsd32.h
@@ -143,15 +143,15 @@ struct stat32 {
 	uid_t	st_uid;
 	gid_t	st_gid;
 	dev_t	st_rdev;
-	struct timespec32 st_atimespec;
-	struct timespec32 st_mtimespec;
-	struct timespec32 st_ctimespec;
+	struct timespec32 st_atim;
+	struct timespec32 st_mtim;
+	struct timespec32 st_ctim;
 	off_t	st_size;
 	int64_t	st_blocks;
 	u_int32_t st_blksize;
 	u_int32_t st_flags;
 	u_int32_t st_gen;
-	struct timespec32 st_birthtimespec;
+	struct timespec32 st_birthtim;
 	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec32));
 	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec32));
 };
diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c
index 1284e386cdd..7cc27be5ff3 100644
--- a/sys/compat/freebsd32/freebsd32_misc.c
+++ b/sys/compat/freebsd32/freebsd32_misc.c
@@ -1634,9 +1634,9 @@ copy_stat( struct stat *in, struct stat32 *out)
 	CP(*in, *out, st_uid);
 	CP(*in, *out, st_gid);
 	CP(*in, *out, st_rdev);
-	TS_CP(*in, *out, st_atimespec);
-	TS_CP(*in, *out, st_mtimespec);
-	TS_CP(*in, *out, st_ctimespec);
+	TS_CP(*in, *out, st_atim);
+	TS_CP(*in, *out, st_mtim);
+	TS_CP(*in, *out, st_ctim);
 	CP(*in, *out, st_size);
 	CP(*in, *out, st_blocks);
 	CP(*in, *out, st_blksize);
diff --git a/sys/compat/linux/linux_stats.c b/sys/compat/linux/linux_stats.c
index 8e8936ce016..907d2014c1e 100644
--- a/sys/compat/linux/linux_stats.c
+++ b/sys/compat/linux/linux_stats.c
@@ -173,9 +173,12 @@ newstat_copyout(struct stat *buf, void *ubuf)
 	tbuf.st_gid = buf->st_gid;
 	tbuf.st_rdev = buf->st_rdev;
 	tbuf.st_size = buf->st_size;
-	tbuf.st_atime = buf->st_atime;
-	tbuf.st_mtime = buf->st_mtime;
-	tbuf.st_ctime = buf->st_ctime;
+	tbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
+	tbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
+	tbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec;
+	tbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec;
+	tbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec;
+	tbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec;
 	tbuf.st_blksize = buf->st_blksize;
 	tbuf.st_blocks = buf->st_blocks;
 
@@ -260,9 +263,12 @@ stat_copyout(struct stat *buf, void *ubuf)
 		lbuf.st_size = buf->st_size;
 	else
 		lbuf.st_size = -2;
-	lbuf.st_atime = buf->st_atime;
-	lbuf.st_mtime = buf->st_mtime;
-	lbuf.st_ctime = buf->st_ctime;
+	lbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
+	lbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
+	lbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec;
+	lbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec;
+	lbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec;
+	lbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec;
 	lbuf.st_blksize = buf->st_blksize;
 	lbuf.st_blocks = buf->st_blocks;
 	lbuf.st_flags = buf->st_flags;
@@ -498,9 +504,12 @@ stat64_copyout(struct stat *buf, void *ubuf)
 	lbuf.st_gid = buf->st_gid;
 	lbuf.st_rdev = buf->st_rdev;
 	lbuf.st_size = buf->st_size;
-	lbuf.st_atime = buf->st_atime;
-	lbuf.st_mtime = buf->st_mtime;
-	lbuf.st_ctime = buf->st_ctime;
+	lbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
+	lbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
+	lbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec;
+	lbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec;
+	lbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec;
+	lbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec;
 	lbuf.st_blksize = buf->st_blksize;
 	lbuf.st_blocks = buf->st_blocks;
 
diff --git a/sys/compat/svr4/svr4_stat.c b/sys/compat/svr4/svr4_stat.c
index cfb8276cee4..cc84396a999 100644
--- a/sys/compat/svr4/svr4_stat.c
+++ b/sys/compat/svr4/svr4_stat.c
@@ -106,9 +106,9 @@ bsd_to_svr4_stat(st, st4)
 	st4->st_gid = st->st_gid;
 	st4->st_rdev = bsd_to_svr4_odev_t(st->st_rdev);
 	st4->st_size = st->st_size;
-	st4->st_atim = st->st_atimespec.tv_sec;
-	st4->st_mtim = st->st_mtimespec.tv_sec;
-	st4->st_ctim = st->st_ctimespec.tv_sec;
+	st4->st_atim = st->st_atim.tv_sec;
+	st4->st_mtim = st->st_mtim.tv_sec;
+	st4->st_ctim = st->st_ctim.tv_sec;
 }
 #endif
 
@@ -127,9 +127,9 @@ bsd_to_svr4_xstat(st, st4)
 	st4->st_gid = st->st_gid;
 	st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
 	st4->st_size = st->st_size;
-	st4->st_atim = st->st_atimespec;
-	st4->st_mtim = st->st_mtimespec;
-	st4->st_ctim = st->st_ctimespec;
+	st4->st_atim = st->st_atim;
+	st4->st_mtim = st->st_mtim;
+	st4->st_ctim = st->st_ctim;
 	st4->st_blksize = st->st_blksize;
 	st4->st_blocks = st->st_blocks;
 	strcpy(st4->st_fstype, "unknown");
@@ -150,9 +150,9 @@ bsd_to_svr4_stat64(st, st4)
 	st4->st_gid = st->st_gid;
 	st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
 	st4->st_size = st->st_size;
-	st4->st_atim = st->st_atimespec;
-	st4->st_mtim = st->st_mtimespec;
-	st4->st_ctim = st->st_ctimespec;
+	st4->st_atim = st->st_atim;
+	st4->st_mtim = st->st_mtim;
+	st4->st_ctim = st->st_ctim;
 	st4->st_blksize = st->st_blksize;
 	st4->st_blocks = st->st_blocks;
 	strcpy(st4->st_fstype, "unknown");
diff --git a/sys/i386/ibcs2/ibcs2_stat.c b/sys/i386/ibcs2/ibcs2_stat.c
index 92530715635..b61e45ef4bf 100644
--- a/sys/i386/ibcs2/ibcs2_stat.c
+++ b/sys/i386/ibcs2/ibcs2_stat.c
@@ -72,9 +72,9 @@ bsd_stat2ibcs_stat(st, st4)
 		st4->st_size = (ibcs2_off_t)st->st_size;
 	else
 		st4->st_size = -2;
-	st4->st_atim = (ibcs2_time_t)st->st_atime;
-	st4->st_mtim = (ibcs2_time_t)st->st_mtime;
-	st4->st_ctim = (ibcs2_time_t)st->st_ctime;
+	st4->st_atim = (ibcs2_time_t)st->st_atim.tv_sec;
+	st4->st_mtim = (ibcs2_time_t)st->st_mtim.tv_sec;
+	st4->st_ctim = (ibcs2_time_t)st->st_ctim.tv_sec;
 }
 
 static int
diff --git a/sys/i386/linux/linux.h b/sys/i386/linux/linux.h
index d614716dcb8..fe84c063ba9 100644
--- a/sys/i386/linux/linux.h
+++ b/sys/i386/linux/linux.h
@@ -178,9 +178,9 @@ struct l_newstat {
 	l_ulong		st_size;
 	l_ulong		st_blksize;
 	l_ulong		st_blocks;
-	struct l_timespec	st_atimespec;
-	struct l_timespec	st_mtimespec;
-	struct l_timespec	st_ctimespec;
+	struct l_timespec	st_atim;
+	struct l_timespec	st_mtim;
+	struct l_timespec	st_ctim;
 	l_ulong		__unused4;
 	l_ulong		__unused5;
 };
@@ -194,9 +194,9 @@ struct l_stat {
 	l_ushort	st_gid;
 	l_ushort	st_rdev;
 	l_long		st_size;
-	struct l_timespec	st_atimespec;
-	struct l_timespec	st_mtimespec;
-	struct l_timespec	st_ctimespec;
+	struct l_timespec	st_atim;
+	struct l_timespec	st_mtim;
+	struct l_timespec	st_ctim;
 	l_long		st_blksize;
 	l_long		st_blocks;
 	l_ulong		st_flags;
@@ -217,9 +217,9 @@ struct l_stat64 {
 	l_ulong		st_blksize;
 	l_ulong		st_blocks;
 	l_ulong		__pad4;
-	struct l_timespec	st_atimespec;
-	struct l_timespec	st_mtimespec;
-	struct l_timespec	st_ctimespec;
+	struct l_timespec	st_atim;
+	struct l_timespec	st_mtim;
+	struct l_timespec	st_ctim;
 	l_ulonglong	st_ino;
 };
 
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c
index fcfb226ea71..e098648a669 100644
--- a/sys/kern/sys_pipe.c
+++ b/sys/kern/sys_pipe.c
@@ -1428,9 +1428,9 @@ pipe_stat(fp, ub, active_cred, td)
 	else
 		ub->st_size = pipe->pipe_buffer.cnt;
 	ub->st_blocks = (ub->st_size + ub->st_blksize - 1) / ub->st_blksize;
-	ub->st_atimespec = pipe->pipe_atime;
-	ub->st_mtimespec = pipe->pipe_mtime;
-	ub->st_ctimespec = pipe->pipe_ctime;
+	ub->st_atim = pipe->pipe_atime;
+	ub->st_mtim = pipe->pipe_mtime;
+	ub->st_ctim = pipe->pipe_ctime;
 	ub->st_uid = fp->f_cred->cr_uid;
 	ub->st_gid = fp->f_cred->cr_gid;
 	/*
diff --git a/sys/kern/tty_pts.c b/sys/kern/tty_pts.c
index 290fdc2ec15..5cfbc713be5 100644
--- a/sys/kern/tty_pts.c
+++ b/sys/kern/tty_pts.c
@@ -556,9 +556,9 @@ ptsdev_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
 #endif /* PTS_EXTERNAL */
 		sb->st_ino = sb->st_rdev = tty_udev(tp);
 
-	sb->st_atimespec = dev->si_atime;
-	sb->st_ctimespec = dev->si_ctime;
-	sb->st_mtimespec = dev->si_mtime;
+	sb->st_atim = dev->si_atime;
+	sb->st_ctim = dev->si_ctime;
+	sb->st_mtim = dev->si_mtime;
 	sb->st_uid = dev->si_uid;
 	sb->st_gid = dev->si_gid;
 	sb->st_mode = dev->si_mode | S_IFCHR;
diff --git a/sys/kern/uipc_mqueue.c b/sys/kern/uipc_mqueue.c
index a34c22859a2..1319666e2c9 100644
--- a/sys/kern/uipc_mqueue.c
+++ b/sys/kern/uipc_mqueue.c
@@ -2447,10 +2447,10 @@ mqf_stat(struct file *fp, struct stat *st, struct ucred *active_cred,
 	struct mqfs_node *pn = fp->f_data;
 
 	bzero(st, sizeof *st);
-	st->st_atimespec = pn->mn_atime;
-	st->st_mtimespec = pn->mn_mtime;
-	st->st_ctimespec = pn->mn_ctime;
-	st->st_birthtimespec = pn->mn_birth;
+	st->st_atim = pn->mn_atime;
+	st->st_mtim = pn->mn_mtime;
+	st->st_ctim = pn->mn_ctime;
+	st->st_birthtim = pn->mn_birth;
 	st->st_uid = pn->mn_uid;
 	st->st_gid = pn->mn_gid;
 	st->st_mode = S_IFIFO | pn->mn_mode;
diff --git a/sys/kern/uipc_sem.c b/sys/kern/uipc_sem.c
index a6b2f75f401..d9229ead170 100644
--- a/sys/kern/uipc_sem.c
+++ b/sys/kern/uipc_sem.c
@@ -219,10 +219,10 @@ ksem_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
 	bzero(sb, sizeof(*sb));
 	sb->st_mode = S_IFREG | ks->ks_mode;		/* XXX */
 
-	sb->st_atimespec = ks->ks_atime;
-	sb->st_ctimespec = ks->ks_ctime;
-	sb->st_mtimespec = ks->ks_mtime;
-	sb->st_birthtimespec = ks->ks_birthtime;	
+	sb->st_atim = ks->ks_atime;
+	sb->st_ctim = ks->ks_ctime;
+	sb->st_mtim = ks->ks_mtime;
+	sb->st_birthtim = ks->ks_birthtime;	
 	sb->st_uid = ks->ks_uid;
 	sb->st_gid = ks->ks_gid;
 
diff --git a/sys/kern/uipc_shm.c b/sys/kern/uipc_shm.c
index 32bfd2d0769..fe1a224d2c5 100644
--- a/sys/kern/uipc_shm.c
+++ b/sys/kern/uipc_shm.c
@@ -219,10 +219,10 @@ shm_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
 	sb->st_blksize = PAGE_SIZE;
 	sb->st_size = shmfd->shm_size;
 	sb->st_blocks = (sb->st_size + sb->st_blksize - 1) / sb->st_blksize;
-	sb->st_atimespec = shmfd->shm_atime;
-	sb->st_ctimespec = shmfd->shm_ctime;
-	sb->st_mtimespec = shmfd->shm_mtime;
-	sb->st_birthtimespec = shmfd->shm_birthtime;	
+	sb->st_atim = shmfd->shm_atime;
+	sb->st_ctim = shmfd->shm_ctime;
+	sb->st_mtim = shmfd->shm_mtime;
+	sb->st_birthtim = shmfd->shm_birthtime;	
 	sb->st_uid = shmfd->shm_uid;
 	sb->st_gid = shmfd->shm_gid;
 
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index bcc3cbb45b1..c329adc9480 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -2269,9 +2269,9 @@ cvtstat(st, ost)
 		ost->st_size = st->st_size;
 	else
 		ost->st_size = -2;
-	ost->st_atime = st->st_atime;
-	ost->st_mtime = st->st_mtime;
-	ost->st_ctime = st->st_ctime;
+	ost->st_atim = st->st_atim;
+	ost->st_mtim = st->st_mtim;
+	ost->st_ctim = st->st_ctim;
 	ost->st_blksize = st->st_blksize;
 	ost->st_blocks = st->st_blocks;
 	ost->st_flags = st->st_flags;
@@ -2431,15 +2431,15 @@ cvtnstat(sb, nsb)
 	nsb->st_uid = sb->st_uid;
 	nsb->st_gid = sb->st_gid;
 	nsb->st_rdev = sb->st_rdev;
-	nsb->st_atimespec = sb->st_atimespec;
-	nsb->st_mtimespec = sb->st_mtimespec;
-	nsb->st_ctimespec = sb->st_ctimespec;
+	nsb->st_atim = sb->st_atim;
+	nsb->st_mtim = sb->st_mtim;
+	nsb->st_ctim = sb->st_ctim;
 	nsb->st_size = sb->st_size;
 	nsb->st_blocks = sb->st_blocks;
 	nsb->st_blksize = sb->st_blksize;
 	nsb->st_flags = sb->st_flags;
 	nsb->st_gen = sb->st_gen;
-	nsb->st_birthtimespec = sb->st_birthtimespec;
+	nsb->st_birthtim = sb->st_birthtim;
 }
 
 #ifndef _SYS_SYSPROTO_H_
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index a16fa6762a5..74e6c0221fb 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -782,10 +782,10 @@ vn_stat(vp, sb, active_cred, file_cred, td)
 	if (vap->va_size > OFF_MAX)
 		return (EOVERFLOW);
 	sb->st_size = vap->va_size;
-	sb->st_atimespec = vap->va_atime;
-	sb->st_mtimespec = vap->va_mtime;
-	sb->st_ctimespec = vap->va_ctime;
-	sb->st_birthtimespec = vap->va_birthtime;
+	sb->st_atim = vap->va_atime;
+	sb->st_mtim = vap->va_mtime;
+	sb->st_ctim = vap->va_ctime;
+	sb->st_birthtim = vap->va_birthtime;
 
         /*
 	 * According to www.opengroup.org, the meaning of st_blksize is 
diff --git a/sys/sys/_timespec.h b/sys/sys/_timespec.h
index 9dcd5f8910d..d51559c2a41 100644
--- a/sys/sys/_timespec.h
+++ b/sys/sys/_timespec.h
@@ -31,26 +31,18 @@
  *	$FreeBSD$
  */
 
-/*
- * Prerequisite: 
- *
- * This file must be kept synchronized with .
- * It defines a structure which must be a type pun for
- * `struct timespec'; this structure is used in header files where
- * the ABI uses a `struct timespec' but standards prohibit its
- * definition.  (Currently only .)
- *
- * XXX should just declare struct __timespec as necessary.  It's simple,
- * so is easy to keep synchronized, and hopefully not needed in as many
- * places as struct timespec, so we don't need this extra header.
- * Perhaps we don't need timespec.h either.
- */
-
 #ifndef _SYS__TIMESPEC_H_
 #define	_SYS__TIMESPEC_H_
 
-struct __timespec {
-	__time_t tv_sec;	/* seconds */
+#include 
+
+#ifndef _TIME_T_DECLARED
+typedef	__time_t	time_t;
+#define	_TIME_T_DECLARED
+#endif
+
+struct timespec {
+	time_t	tv_sec;		/* seconds */
 	long	tv_nsec;	/* and nanoseconds */
 };
 
diff --git a/sys/sys/stat.h b/sys/sys/stat.h
index 856d674046d..1b03bd26c60 100644
--- a/sys/sys/stat.h
+++ b/sys/sys/stat.h
@@ -39,6 +39,7 @@
 #define	_SYS_STAT_H_
 
 #include 
+#include 
 #include 
 
 #ifndef _BLKSIZE_T_DECLARED
@@ -86,11 +87,6 @@ typedef	__off_t		off_t;
 #define	_OFF_T_DECLARED
 #endif
 
-#ifndef _TIME_T_DECLARED
-typedef	__time_t	time_t;
-#define	_TIME_T_DECLARED
-#endif
-
 #ifndef _UID_T_DECLARED
 typedef	__uid_t		uid_t;
 #define	_UID_T_DECLARED
@@ -98,16 +94,11 @@ typedef	__uid_t		uid_t;
 
 #if !defined(_KERNEL) && __BSD_VISIBLE
 /*
- * XXX we need this for struct timespec.  We get miscellaneous namespace
- * pollution with it.
+ * XXX We get miscellaneous namespace pollution with this.
  */
 #include 
 #endif
 
-#if !__BSD_VISIBLE
-#include 
-#endif
-
 #if __BSD_VISIBLE
 struct ostat {
 	__uint16_t st_dev;		/* inode's device */
@@ -118,9 +109,9 @@ struct ostat {
 	__uint16_t st_gid;		/* group ID of the file's group */
 	__uint16_t st_rdev;		/* device type */
 	__int32_t st_size;		/* file size, in bytes */
-	struct	timespec st_atimespec;	/* time of last access */
-	struct	timespec st_mtimespec;	/* time of last data modification */
-	struct	timespec st_ctimespec;	/* time of last file status change */
+	struct	timespec st_atim;	/* time of last access */
+	struct	timespec st_mtim;	/* time of last data modification */
+	struct	timespec st_ctim;	/* time of last file status change */
 	__int32_t st_blksize;		/* optimal blocksize for I/O */
 	__int32_t st_blocks;		/* blocks allocated for file */
 	fflags_t  st_flags;		/* user defined flags for file */
@@ -136,28 +127,18 @@ struct stat {
 	uid_t	  st_uid;		/* user ID of the file's owner */
 	gid_t	  st_gid;		/* group ID of the file's group */
 	__dev_t   st_rdev;		/* device type */
-#if __BSD_VISIBLE
-	struct	timespec st_atimespec;	/* time of last access */
-	struct	timespec st_mtimespec;	/* time of last data modification */
-	struct	timespec st_ctimespec;	/* time of last file status change */
-#else
-	time_t	  st_atime;		/* time of last access */
-	long	  __st_atimensec;	/* nsec of last access */
-	time_t	  st_mtime;		/* time of last data modification */
-	long	  __st_mtimensec;	/* nsec of last data modification */
-	time_t	  st_ctime;		/* time of last file status change */
-	long	  __st_ctimensec;	/* nsec of last file status change */
-#endif
+	struct	timespec st_atim;	/* time of last access */
+	struct	timespec st_mtim;	/* time of last data modification */
+	struct	timespec st_ctim;	/* time of last file status change */
 	off_t	  st_size;		/* file size, in bytes */
 	blkcnt_t st_blocks;		/* blocks allocated for file */
 	blksize_t st_blksize;		/* optimal blocksize for I/O */
 	fflags_t  st_flags;		/* user defined flags for file */
 	__uint32_t st_gen;		/* file generation number */
 	__int32_t st_lspare;
-#if __BSD_VISIBLE
-	struct timespec st_birthtimespec; /* time of file creation */
+	struct timespec st_birthtim;	/* time of file creation */
 	/*
-	 * Explicitly pad st_birthtimespec to 16 bytes so that the size of
+	 * Explicitly pad st_birthtim to 16 bytes so that the size of
 	 * struct stat is backwards compatible.  We use bitfields instead
 	 * of an array of chars so that this doesn't require a C99 compiler
 	 * to compile if the size of the padding is 0.  We use 2 bitfields
@@ -166,12 +147,6 @@ struct stat {
 	 */
 	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
 	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
-#else
-	time_t	  st_birthtime;		/* time of file creation */
-	long	  st_birthtimensec;	/* nsec of file creation */
-	unsigned int :(8 / 2) * (16 - (int)sizeof(struct __timespec));
-	unsigned int :(8 / 2) * (16 - (int)sizeof(struct __timespec));
-#endif
 };
 
 #if __BSD_VISIBLE
@@ -183,15 +158,15 @@ struct nstat {
 	uid_t	  st_uid;		/* user ID of the file's owner */
 	gid_t	  st_gid;		/* group ID of the file's group */
 	__dev_t   st_rdev;		/* device type */
-	struct	timespec st_atimespec;	/* time of last access */
-	struct	timespec st_mtimespec;	/* time of last data modification */
-	struct	timespec st_ctimespec;	/* time of last file status change */
+	struct	timespec st_atim;	/* time of last access */
+	struct	timespec st_mtim;	/* time of last data modification */
+	struct	timespec st_ctim;	/* time of last file status change */
 	off_t	  st_size;		/* file size, in bytes */
 	blkcnt_t st_blocks;		/* blocks allocated for file */
 	blksize_t st_blksize;		/* optimal blocksize for I/O */
 	fflags_t  st_flags;		/* user defined flags for file */
 	__uint32_t st_gen;		/* file generation number */
-	struct timespec st_birthtimespec; /* time of file creation */
+	struct timespec st_birthtim;	/* time of file creation */
 	/*
 	 * See above about the following padding.
 	 */
@@ -200,13 +175,23 @@ struct nstat {
 };
 #endif
 
+#ifndef _KERNEL
+#define	st_atime		st_atim.tv_sec
+#define	st_mtime		st_mtim.tv_sec
+#define	st_ctime		st_ctim.tv_sec
 #if __BSD_VISIBLE
-#define st_atime st_atimespec.tv_sec
-#define st_mtime st_mtimespec.tv_sec
-#define st_ctime st_ctimespec.tv_sec
-#define st_birthtime st_birthtimespec.tv_sec
+#define	st_birthtime		st_birthtim.tv_sec
 #endif
 
+/* For compatibility. */
+#if __BSD_VISIBLE
+#define	st_atimespec		st_atim
+#define	st_mtimespec		st_mtim
+#define	st_ctimespec		st_ctim
+#define	st_birthtimespec	st_birthtim
+#endif
+#endif /* !_KERNEL */
+
 #define	S_ISUID	0004000			/* set user id on execution */
 #define	S_ISGID	0002000			/* set group id on execution */
 #if __BSD_VISIBLE
diff --git a/sys/sys/timespec.h b/sys/sys/timespec.h
index 8986c094c6a..2505cef893e 100644
--- a/sys/sys/timespec.h
+++ b/sys/sys/timespec.h
@@ -31,22 +31,11 @@
  *	$FreeBSD$
  */
 
-/*
- * Prerequisites: , 
- */
-
 #ifndef _SYS_TIMESPEC_H_
 #define _SYS_TIMESPEC_H_
 
-#ifndef _TIME_T_DECLARED
-typedef	__time_t	time_t;
-#define	_TIME_T_DECLARED
-#endif
-
-struct timespec {
-	time_t	tv_sec;		/* seconds */
-	long	tv_nsec;	/* and nanoseconds */
-};
+#include 
+#include 
 
 #if __BSD_VISIBLE
 #define	TIMEVAL_TO_TIMESPEC(tv, ts)					\

From 99742a231f9bc662d03fb37ee620500cc1b4a8a7 Mon Sep 17 00:00:00 2001
From: Ed Schouten 
Date: Sun, 28 Mar 2010 13:16:08 +0000
Subject: [PATCH 111/119] Change all our own code to use st_*tim instead of
 st_*timespec.

Also remove some local patches to diff(1) which are now unneeded.
---
 bin/cp/utils.c                  |  4 +--
 bin/ls/cmp.c                    | 64 ++++++++++++++++-----------------
 bin/rcp/rcp.c                   |  8 ++---
 bin/test/test.c                 |  6 ++--
 gnu/usr.bin/diff/context.c.diff |  2 +-
 gnu/usr.bin/diff/diff.c.diff    | 18 ----------
 usr.bin/compress/compress.c     |  4 +--
 usr.bin/gzip/gzip.c             |  4 +--
 usr.bin/kdump/kdump.c           | 32 ++++++++---------
 usr.bin/mail/util.c             |  2 +-
 usr.bin/touch/touch.c           | 12 +++----
 usr.sbin/mtree/compare.c        |  6 ++--
 usr.sbin/mtree/create.c         |  4 +--
 13 files changed, 74 insertions(+), 92 deletions(-)

diff --git a/bin/cp/utils.c b/bin/cp/utils.c
index b075eac46d0..d729bd5b340 100644
--- a/bin/cp/utils.c
+++ b/bin/cp/utils.c
@@ -323,8 +323,8 @@ setfile(struct stat *fs, int fd)
 	fs->st_mode &= S_ISUID | S_ISGID | S_ISVTX |
 		       S_IRWXU | S_IRWXG | S_IRWXO;
 
-	TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec);
-	TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec);
+	TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atim);
+	TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtim);
 	if (islink ? lutimes(to.p_path, tv) : utimes(to.p_path, tv)) {
 		warn("%sutimes: %s", islink ? "l" : "", to.p_path);
 		rval = 1;
diff --git a/bin/ls/cmp.c b/bin/ls/cmp.c
index badd1086746..84fb0388193 100644
--- a/bin/ls/cmp.c
+++ b/bin/ls/cmp.c
@@ -66,17 +66,17 @@ int
 modcmp(const FTSENT *a, const FTSENT *b)
 {
 
-	if (b->fts_statp->st_mtimespec.tv_sec >
-	    a->fts_statp->st_mtimespec.tv_sec)
+	if (b->fts_statp->st_mtim.tv_sec >
+	    a->fts_statp->st_mtim.tv_sec)
 		return (1);
-	if (b->fts_statp->st_mtimespec.tv_sec <
-	    a->fts_statp->st_mtimespec.tv_sec)
+	if (b->fts_statp->st_mtim.tv_sec <
+	    a->fts_statp->st_mtim.tv_sec)
 		return (-1);
-	if (b->fts_statp->st_mtimespec.tv_nsec >
-	    a->fts_statp->st_mtimespec.tv_nsec)
+	if (b->fts_statp->st_mtim.tv_nsec >
+	    a->fts_statp->st_mtim.tv_nsec)
 		return (1);
-	if (b->fts_statp->st_mtimespec.tv_nsec <
-	    a->fts_statp->st_mtimespec.tv_nsec)
+	if (b->fts_statp->st_mtim.tv_nsec <
+	    a->fts_statp->st_mtim.tv_nsec)
 		return (-1);
 	return (strcoll(a->fts_name, b->fts_name));
 }
@@ -92,17 +92,17 @@ int
 acccmp(const FTSENT *a, const FTSENT *b)
 {
 
-	if (b->fts_statp->st_atimespec.tv_sec >
-	    a->fts_statp->st_atimespec.tv_sec)
+	if (b->fts_statp->st_atim.tv_sec >
+	    a->fts_statp->st_atim.tv_sec)
 		return (1);
-	if (b->fts_statp->st_atimespec.tv_sec <
-	    a->fts_statp->st_atimespec.tv_sec)
+	if (b->fts_statp->st_atim.tv_sec <
+	    a->fts_statp->st_atim.tv_sec)
 		return (-1);
-	if (b->fts_statp->st_atimespec.tv_nsec >
-	    a->fts_statp->st_atimespec.tv_nsec)
+	if (b->fts_statp->st_atim.tv_nsec >
+	    a->fts_statp->st_atim.tv_nsec)
 		return (1);
-	if (b->fts_statp->st_atimespec.tv_nsec <
-	    a->fts_statp->st_atimespec.tv_nsec)
+	if (b->fts_statp->st_atim.tv_nsec <
+	    a->fts_statp->st_atim.tv_nsec)
 		return (-1);
 	return (strcoll(a->fts_name, b->fts_name));
 }
@@ -118,17 +118,17 @@ int
 birthcmp(const FTSENT *a, const FTSENT *b)
 {
 
-	if (b->fts_statp->st_birthtimespec.tv_sec >
-	    a->fts_statp->st_birthtimespec.tv_sec)
+	if (b->fts_statp->st_birthtim.tv_sec >
+	    a->fts_statp->st_birthtim.tv_sec)
 		return (1);
-	if (b->fts_statp->st_birthtimespec.tv_sec <
-	    a->fts_statp->st_birthtimespec.tv_sec)
+	if (b->fts_statp->st_birthtim.tv_sec <
+	    a->fts_statp->st_birthtim.tv_sec)
 		return (-1);
-	if (b->fts_statp->st_birthtimespec.tv_nsec >
-	    a->fts_statp->st_birthtimespec.tv_nsec)
+	if (b->fts_statp->st_birthtim.tv_nsec >
+	    a->fts_statp->st_birthtim.tv_nsec)
 		return (1);
-	if (b->fts_statp->st_birthtimespec.tv_nsec <
-	    a->fts_statp->st_birthtimespec.tv_nsec)
+	if (b->fts_statp->st_birthtim.tv_nsec <
+	    a->fts_statp->st_birthtim.tv_nsec)
 		return (-1);
 	return (strcoll(a->fts_name, b->fts_name));
 }
@@ -144,17 +144,17 @@ int
 statcmp(const FTSENT *a, const FTSENT *b)
 {
 
-	if (b->fts_statp->st_ctimespec.tv_sec >
-	    a->fts_statp->st_ctimespec.tv_sec)
+	if (b->fts_statp->st_ctim.tv_sec >
+	    a->fts_statp->st_ctim.tv_sec)
 		return (1);
-	if (b->fts_statp->st_ctimespec.tv_sec <
-	    a->fts_statp->st_ctimespec.tv_sec)
+	if (b->fts_statp->st_ctim.tv_sec <
+	    a->fts_statp->st_ctim.tv_sec)
 		return (-1);
-	if (b->fts_statp->st_ctimespec.tv_nsec >
-	    a->fts_statp->st_ctimespec.tv_nsec)
+	if (b->fts_statp->st_ctim.tv_nsec >
+	    a->fts_statp->st_ctim.tv_nsec)
 		return (1);
-	if (b->fts_statp->st_ctimespec.tv_nsec <
-	    a->fts_statp->st_ctimespec.tv_nsec)
+	if (b->fts_statp->st_ctim.tv_nsec <
+	    a->fts_statp->st_ctim.tv_nsec)
 		return (-1);
 	return (strcoll(a->fts_name, b->fts_name));
 }
diff --git a/bin/rcp/rcp.c b/bin/rcp/rcp.c
index 0a9b7ba2ff6..2c27b639f21 100644
--- a/bin/rcp/rcp.c
+++ b/bin/rcp/rcp.c
@@ -390,8 +390,8 @@ syserr:			run_err("%s: %s", name, strerror(errno));
 			 * versions expecting microseconds.
 			 */
 			(void)snprintf(buf, sizeof(buf), "T%ld 0 %ld 0\n",
-			    (long)stb.st_mtimespec.tv_sec,
-			    (long)stb.st_atimespec.tv_sec);
+			    (long)stb.st_mtim.tv_sec,
+			    (long)stb.st_atim.tv_sec);
 			(void)write(rem, buf, strlen(buf));
 			if (response() < 0)
 				goto next;
@@ -454,8 +454,8 @@ rsource(char *name, struct stat *statp)
 		last++;
 	if (pflag) {
 		(void)snprintf(path, sizeof(path), "T%ld 0 %ld 0\n",
-		    (long)statp->st_mtimespec.tv_sec,
-		    (long)statp->st_atimespec.tv_sec);
+		    (long)statp->st_mtim.tv_sec,
+		    (long)statp->st_atim.tv_sec);
 		(void)write(rem, path, strlen(path));
 		if (response() < 0) {
 			closedir(dirp);
diff --git a/bin/test/test.c b/bin/test/test.c
index d7d1eec39b3..e2062d1cef5 100644
--- a/bin/test/test.c
+++ b/bin/test/test.c
@@ -572,12 +572,12 @@ newerf (const char *f1, const char *f2)
 	if (stat(f1, &b1) != 0 || stat(f2, &b2) != 0)
 		return 0;
 
-	if (b1.st_mtimespec.tv_sec > b2.st_mtimespec.tv_sec)
+	if (b1.st_mtim.tv_sec > b2.st_mtim.tv_sec)
 		return 1;
-	if (b1.st_mtimespec.tv_sec < b2.st_mtimespec.tv_sec)
+	if (b1.st_mtim.tv_sec < b2.st_mtim.tv_sec)
 		return 0;
 
-       return (b1.st_mtimespec.tv_nsec > b2.st_mtimespec.tv_nsec);
+       return (b1.st_mtim.tv_nsec > b2.st_mtim.tv_nsec);
 }
 
 static int
diff --git a/gnu/usr.bin/diff/context.c.diff b/gnu/usr.bin/diff/context.c.diff
index ee1ab21165d..06cfb12b545 100644
--- a/gnu/usr.bin/diff/context.c.diff
+++ b/gnu/usr.bin/diff/context.c.diff
@@ -15,7 +15,7 @@ $FreeBSD$
  		    INT_STRLEN_BOUND (time_t) + 11)];
        struct tm const *tm = localtime (&inf->stat.st_mtime);
 -      int nsec = TIMESPEC_NS (inf->stat.st_mtim);
-+      long nsec = TIMESPEC_NS (inf->stat.st_mtimespec);
++      long nsec = TIMESPEC_NS (inf->stat.st_mtim);
        if (! (tm && nstrftime (buf, sizeof buf, time_format, tm, 0, nsec)))
  	{
 -	  long int sec = inf->stat.st_mtime;
diff --git a/gnu/usr.bin/diff/diff.c.diff b/gnu/usr.bin/diff/diff.c.diff
index 884a9c49d2e..28b90ab0ee8 100644
--- a/gnu/usr.bin/diff/diff.c.diff
+++ b/gnu/usr.bin/diff/diff.c.diff
@@ -49,21 +49,3 @@ $FreeBSD$
        output_style = style;
      }
  }
-@@ -997,7 +1001,7 @@
- #ifdef ST_MTIM_NSEC
- 
- # if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME
--  if (clock_gettime (CLOCK_REALTIME, &st->st_mtim) == 0)
-+  if (clock_gettime (CLOCK_REALTIME, &st->st_mtimespec) == 0)
-     return;
- # endif
- 
-@@ -1007,7 +1011,7 @@
-     if (gettimeofday (&timeval, 0) == 0)
-       {
- 	st->st_mtime = timeval.tv_sec;
--	st->st_mtim.ST_MTIM_NSEC = timeval.tv_usec * 1000;
-+	st->st_mtimespec.ST_MTIM_NSEC = timeval.tv_usec * 1000;
- 	return;
-       }
-   }
diff --git a/usr.bin/compress/compress.c b/usr.bin/compress/compress.c
index 584f283ffb8..6f674c2a7ce 100644
--- a/usr.bin/compress/compress.c
+++ b/usr.bin/compress/compress.c
@@ -368,8 +368,8 @@ setfile(const char *name, struct stat *fs)
 
 	fs->st_mode &= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
 
-	TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec);
-	TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec);
+	TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atim);
+	TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtim);
 	if (utimes(name, tv))
 		cwarn("utimes: %s", name);
 
diff --git a/usr.bin/gzip/gzip.c b/usr.bin/gzip/gzip.c
index e9371d2c47c..e8e75aadfd6 100644
--- a/usr.bin/gzip/gzip.c
+++ b/usr.bin/gzip/gzip.c
@@ -1088,8 +1088,8 @@ copymodes(int fd, const struct stat *sbp, const char *file)
 	if (fchmod(fd, sb.st_mode) < 0)
 		maybe_warn("couldn't fchmod: %s", file);
 
-	TIMESPEC_TO_TIMEVAL(×[0], &sb.st_atimespec);
-	TIMESPEC_TO_TIMEVAL(×[1], &sb.st_mtimespec);
+	TIMESPEC_TO_TIMEVAL(×[0], &sb.st_atim);
+	TIMESPEC_TO_TIMEVAL(×[1], &sb.st_mtim);
 	if (futimes(fd, times) < 0)
 		maybe_warn("couldn't utimes: %s", file);
 
diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c
index 9c86fff189b..ec32ee7996f 100644
--- a/usr.bin/kdump/kdump.c
+++ b/usr.bin/kdump/kdump.c
@@ -1270,50 +1270,50 @@ ktrstat(struct stat *statp)
 	printf("rdev=%ju, ", (uintmax_t)statp->st_rdev);
 	printf("atime=");
 	if (resolv == 0)
-		printf("%jd", (intmax_t)statp->st_atimespec.tv_sec);
+		printf("%jd", (intmax_t)statp->st_atim.tv_sec);
 	else {
-		tm = localtime(&statp->st_atimespec.tv_sec);
+		tm = localtime(&statp->st_atim.tv_sec);
 		(void)strftime(timestr, sizeof(timestr), TIME_FORMAT, tm);
 		printf("\"%s\"", timestr);
 	}
-	if (statp->st_atimespec.tv_nsec != 0)
-		printf(".%09ld, ", statp->st_atimespec.tv_nsec);
+	if (statp->st_atim.tv_nsec != 0)
+		printf(".%09ld, ", statp->st_atim.tv_nsec);
 	else
 		printf(", ");
 	printf("stime=");
 	if (resolv == 0)
-		printf("%jd", (intmax_t)statp->st_mtimespec.tv_sec);
+		printf("%jd", (intmax_t)statp->st_mtim.tv_sec);
 	else {
-		tm = localtime(&statp->st_mtimespec.tv_sec);
+		tm = localtime(&statp->st_mtim.tv_sec);
 		(void)strftime(timestr, sizeof(timestr), TIME_FORMAT, tm);
 		printf("\"%s\"", timestr);
 	}
-	if (statp->st_mtimespec.tv_nsec != 0)
-		printf(".%09ld, ", statp->st_mtimespec.tv_nsec);
+	if (statp->st_mtim.tv_nsec != 0)
+		printf(".%09ld, ", statp->st_mtim.tv_nsec);
 	else
 		printf(", ");
 	printf("ctime=");
 	if (resolv == 0)
-		printf("%jd", (intmax_t)statp->st_ctimespec.tv_sec);
+		printf("%jd", (intmax_t)statp->st_ctim.tv_sec);
 	else {
-		tm = localtime(&statp->st_ctimespec.tv_sec);
+		tm = localtime(&statp->st_ctim.tv_sec);
 		(void)strftime(timestr, sizeof(timestr), TIME_FORMAT, tm);
 		printf("\"%s\"", timestr);
 	}
-	if (statp->st_ctimespec.tv_nsec != 0)
-		printf(".%09ld, ", statp->st_ctimespec.tv_nsec);
+	if (statp->st_ctim.tv_nsec != 0)
+		printf(".%09ld, ", statp->st_ctim.tv_nsec);
 	else
 		printf(", ");
 	printf("birthtime=");
 	if (resolv == 0)
-		printf("%jd", (intmax_t)statp->st_birthtimespec.tv_sec);
+		printf("%jd", (intmax_t)statp->st_birthtim.tv_sec);
 	else {
-		tm = localtime(&statp->st_birthtimespec.tv_sec);
+		tm = localtime(&statp->st_birthtim.tv_sec);
 		(void)strftime(timestr, sizeof(timestr), TIME_FORMAT, tm);
 		printf("\"%s\"", timestr);
 	}
-	if (statp->st_birthtimespec.tv_nsec != 0)
-		printf(".%09ld, ", statp->st_birthtimespec.tv_nsec);
+	if (statp->st_birthtim.tv_nsec != 0)
+		printf(".%09ld, ", statp->st_birthtim.tv_nsec);
 	else
 		printf(", ");
 	printf("size=%jd, blksize=%ju, blocks=%jd, flags=0x%x",
diff --git a/usr.bin/mail/util.c b/usr.bin/mail/util.c
index e764aacd000..df2d840428b 100644
--- a/usr.bin/mail/util.c
+++ b/usr.bin/mail/util.c
@@ -349,7 +349,7 @@ alter(name)
 		return;
 	(void)gettimeofday(&tv[0], (struct timezone *)NULL);
 	tv[0].tv_sec++;
-	TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtimespec);
+	TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtim);
 	(void)utimes(name, tv);
 }
 
diff --git a/usr.bin/touch/touch.c b/usr.bin/touch/touch.c
index 5ceb1757201..2148939148f 100644
--- a/usr.bin/touch/touch.c
+++ b/usr.bin/touch/touch.c
@@ -187,9 +187,9 @@ main(int argc, char *argv[])
 		}
 
 		if (!aflag)
-			TIMESPEC_TO_TIMEVAL(&tv[0], &sb.st_atimespec);
+			TIMESPEC_TO_TIMEVAL(&tv[0], &sb.st_atim);
 		if (!mflag)
-			TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtimespec);
+			TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtim);
 
 		/*
 		 * We're adjusting the times based on the file times, not a
@@ -197,11 +197,11 @@ main(int argc, char *argv[])
 		 */
 		if (Aflag) {
 			if (aflag) {
-				TIMESPEC_TO_TIMEVAL(&tv[0], &sb.st_atimespec);
+				TIMESPEC_TO_TIMEVAL(&tv[0], &sb.st_atim);
 				tv[0].tv_sec += Aflag;
 			}
 			if (mflag) {
-				TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtimespec);
+				TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtim);
 				tv[1].tv_sec += Aflag;
 			}
 		}
@@ -368,8 +368,8 @@ stime_file(char *fname, struct timeval *tvp)
 
 	if (stat(fname, &sb))
 		err(1, "%s", fname);
-	TIMESPEC_TO_TIMEVAL(tvp, &sb.st_atimespec);
-	TIMESPEC_TO_TIMEVAL(tvp + 1, &sb.st_mtimespec);
+	TIMESPEC_TO_TIMEVAL(tvp, &sb.st_atim);
+	TIMESPEC_TO_TIMEVAL(tvp + 1, &sb.st_mtim);
 }
 
 int
diff --git a/usr.sbin/mtree/compare.c b/usr.sbin/mtree/compare.c
index 44556d67a0e..fdd37679c6e 100644
--- a/usr.sbin/mtree/compare.c
+++ b/usr.sbin/mtree/compare.c
@@ -181,13 +181,13 @@ typeerr:		LABEL;
 	 * Catches nano-second differences, but doesn't display them.
 	 */
 	if ((s->flags & F_TIME) &&
-	     ((s->st_mtimespec.tv_sec != p->fts_statp->st_mtimespec.tv_sec) ||
-	     (s->st_mtimespec.tv_nsec != p->fts_statp->st_mtimespec.tv_nsec))) {
+	     ((s->st_mtimespec.tv_sec != p->fts_statp->st_mtim.tv_sec) ||
+	     (s->st_mtimespec.tv_nsec != p->fts_statp->st_mtim.tv_nsec))) {
 		LABEL;
 		(void)printf("%smodification time expected %.24s ",
 		    tab, ctime(&s->st_mtimespec.tv_sec));
 		(void)printf("found %.24s",
-		    ctime(&p->fts_statp->st_mtimespec.tv_sec));
+		    ctime(&p->fts_statp->st_mtim.tv_sec));
 		if (uflag) {
 			tv[0].tv_sec = s->st_mtimespec.tv_sec;
 			tv[0].tv_usec = s->st_mtimespec.tv_nsec / 1000;
diff --git a/usr.sbin/mtree/create.c b/usr.sbin/mtree/create.c
index eee5037c266..da72fc6beae 100644
--- a/usr.sbin/mtree/create.c
+++ b/usr.sbin/mtree/create.c
@@ -213,8 +213,8 @@ statf(int indent, FTSENT *p)
 		    (intmax_t)p->fts_statp->st_size);
 	if (keys & F_TIME)
 		output(indent, &offset, "time=%ld.%09ld",
-		    (long)p->fts_statp->st_mtimespec.tv_sec,
-		    p->fts_statp->st_mtimespec.tv_nsec);
+		    (long)p->fts_statp->st_mtim.tv_sec,
+		    p->fts_statp->st_mtim.tv_nsec);
 	if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) {
 		if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 ||
 		    crc(fd, &val, &len))

From 435d2674235e507dc0957d47870166547648105f Mon Sep 17 00:00:00 2001
From: Ed Schouten 
Date: Sun, 28 Mar 2010 13:40:13 +0000
Subject: [PATCH 112/119] Don't forget to bump the date in the man page.

---
 lib/libc/sys/stat.2 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/libc/sys/stat.2 b/lib/libc/sys/stat.2
index 917b6befcdf..85f0cf0b0c8 100644
--- a/lib/libc/sys/stat.2
+++ b/lib/libc/sys/stat.2
@@ -28,7 +28,7 @@
 .\"     @(#)stat.2	8.4 (Berkeley) 5/1/95
 .\" $FreeBSD$
 .\"
-.Dd April 10, 2008
+.Dd March 28, 2010
 .Dt STAT 2
 .Os
 .Sh NAME

From e0cbed6815793dc0c6533113f9e3e6afa6c2876f Mon Sep 17 00:00:00 2001
From: Nathan Whitehorn 
Date: Sun, 28 Mar 2010 17:17:32 +0000
Subject: [PATCH 113/119] Set hw.ofwfb.relax_mmap=1 by default. While these
 checks may be a good idea in principle, X does not work without them on
 basically any hardware, and this is probably the most frequent problem people
 run into on PowerPC.

Prodded by:	rnoland
MFC after:	1 week
---
 sys/powerpc/ofw/ofw_syscons.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/powerpc/ofw/ofw_syscons.c b/sys/powerpc/ofw/ofw_syscons.c
index 56d0ca8da1d..d85cee55920 100644
--- a/sys/powerpc/ofw/ofw_syscons.c
+++ b/sys/powerpc/ofw/ofw_syscons.c
@@ -55,10 +55,10 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
-static int ofwfb_ignore_mmap_checks;
+static int ofwfb_ignore_mmap_checks = 1;
 SYSCTL_NODE(_hw, OID_AUTO, ofwfb, CTLFLAG_RD, 0, "ofwfb");
 SYSCTL_INT(_hw_ofwfb, OID_AUTO, relax_mmap, CTLFLAG_RW,
-    &ofwfb_ignore_mmap_checks, 0, "relax mmap bounds checking");
+    &ofwfb_ignore_mmap_checks, 0, "relaxed mmap bounds checking");
 
 extern u_char dflt_font_16[];
 extern u_char dflt_font_14[];

From 48463a674764ae889f51a47a4ff2aaf299d9d876 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala 
Date: Sun, 28 Mar 2010 17:29:15 +0000
Subject: [PATCH 114/119] Make acl_to_text_np(3) not crash on long group or
 user names in NFSv4 ACLs.

PR:		amd64/145091
MFC after:	2 weeks
---
 lib/libc/posix1e/acl_to_text_nfs4.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/lib/libc/posix1e/acl_to_text_nfs4.c b/lib/libc/posix1e/acl_to_text_nfs4.c
index 3adbfb4bd92..5d0aa319143 100644
--- a/lib/libc/posix1e/acl_to_text_nfs4.c
+++ b/lib/libc/posix1e/acl_to_text_nfs4.c
@@ -167,7 +167,7 @@ format_additional_id(char *str, size_t size, const acl_entry_t entry)
 static int
 format_entry(char *str, size_t size, const acl_entry_t entry, int flags)
 {
-	size_t off = 0, padding_length, maximum_who_field_length = 18;
+	size_t off = 0, min_who_field_length = 18;
 	acl_permset_t permset;
 	acl_flagset_t flagset;
 	int error, len;
@@ -188,12 +188,9 @@ format_entry(char *str, size_t size, const acl_entry_t entry, int flags)
 	if (error)
 		return (error);
 	len = strlen(buf);
-	padding_length = maximum_who_field_length - len;
-	if (padding_length > 0) {
-		memset(str, ' ', padding_length);
-		off += padding_length;
-	}
-	off += snprintf(str + off, size - off, "%s:", buf);
+	if (len < min_who_field_length)
+		len = min_who_field_length;
+	off += snprintf(str + off, size - off, "%*s:", len, buf);
 
 	error = _nfs4_format_access_mask(buf, sizeof(buf), *permset,
 	    flags & ACL_TEXT_VERBOSE);

From 208f52dae62368ae361f39e82904d976486f2e19 Mon Sep 17 00:00:00 2001
From: Andrew Thompson 
Date: Sun, 28 Mar 2010 20:02:13 +0000
Subject: [PATCH 115/119] Add a couple of usb product IDs.

Submitted by:	Dmitry Luhtionov @ gmail.com
---
 sys/dev/usb/usbdevs | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sys/dev/usb/usbdevs b/sys/dev/usb/usbdevs
index f7352f5fc99..64327689bdc 100644
--- a/sys/dev/usb/usbdevs
+++ b/sys/dev/usb/usbdevs
@@ -2516,12 +2516,14 @@ product QUALCOMMINC E2003	0x2003	3G modem
 
 /* Quanta products */
 /* Quanta products */
+product QUANTA RW6815_1		0x00ce	HP iPAQ rw6815
 product QUANTA RT3070		0x0304	RT3070
 product QUANTA Q101		0xea02	HSDPA modem
 product QUANTA Q111		0xea03	HSDPA modem
 product QUANTA GLX		0xea04	HSDPA modem
 product QUANTA GKE		0xea05	HSDPA modem
 product QUANTA GLE		0xea06	HSDPA modem
+product QUANTA RW6815_2		0xf003	HP iPAQ rw6815
 
 /* Qtronix products */
 product QTRONIX 980N		0x2011	Scorpion-980N keyboard
@@ -2729,6 +2731,7 @@ product SIERRA AIRCARD875	0x6820	Aircard 875 HSDPA
 product SIERRA TRUINSTALL	0x0fff	Aircard Tru Installer
 
 /* Sigmatel products */
+product SIGMATEL WBT_3052	0x4200	WBT-3052 IrDA/USB Bridge
 product SIGMATEL I_BEAD100	0x8008	i-Bead 100 MP3 Player
 
 /* SIIG products */

From 4a4bd31b4487b7012f898e9be042fad27eb25376 Mon Sep 17 00:00:00 2001
From: Andrew Thompson 
Date: Sun, 28 Mar 2010 20:02:50 +0000
Subject: [PATCH 116/119] Add PCI IDs for two more nForce controllers.

Submitted by:	Dmitry Luhtionov @ gmail.com
---
 sys/dev/usb/controller/ehci_pci.c | 2 ++
 sys/dev/usb/controller/ohci_pci.c | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/sys/dev/usb/controller/ehci_pci.c b/sys/dev/usb/controller/ehci_pci.c
index 3c0663ddce5..c8d2d61a670 100644
--- a/sys/dev/usb/controller/ehci_pci.c
+++ b/sys/dev/usb/controller/ehci_pci.c
@@ -208,6 +208,8 @@ ehci_pci_match(device_t self)
 		return "NVIDIA nForce3 250 USB 2.0 controller";
 	case 0x005b10de:
 		return "NVIDIA nForce4 USB 2.0 controller";
+	case 0x036d10de:
+		return "NVIDIA nForce MCP55 USB 2.0 controller";
 	case 0x03f210de:
 		return "NVIDIA nForce MCP61 USB 2.0 controller";
 	case 0x0aa610de:
diff --git a/sys/dev/usb/controller/ohci_pci.c b/sys/dev/usb/controller/ohci_pci.c
index 962aacd67ed..b37fc3348aa 100644
--- a/sys/dev/usb/controller/ohci_pci.c
+++ b/sys/dev/usb/controller/ohci_pci.c
@@ -166,6 +166,8 @@ ohci_pci_match(device_t self)
 	case 0x00d710de:
 		return ("nVidia nForce3 USB Controller");
 
+	case 0x036c10de:
+		return ("nVidia nForce MCP55 USB Controller");
 	case 0x03f110de:
 		return ("nVidia nForce MCP61 USB Controller");
 	case 0x0aa510de:

From 79491ae83769479fe3cb51e321d2622a8f958254 Mon Sep 17 00:00:00 2001
From: Andrew Thompson 
Date: Sun, 28 Mar 2010 20:04:03 +0000
Subject: [PATCH 117/119] Make sure the bsd_urb_list gets initialised and that
 new URB's are queued at the end of the list.

Submitted by:	Hans Petter Selasky
---
 sys/dev/usb/usb_compat_linux.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys/dev/usb/usb_compat_linux.c b/sys/dev/usb/usb_compat_linux.c
index b95a4f6f349..fc28a1c5060 100644
--- a/sys/dev/usb/usb_compat_linux.c
+++ b/sys/dev/usb/usb_compat_linux.c
@@ -435,7 +435,7 @@ usb_submit_urb(struct urb *urb, uint16_t mem_flags)
 	    uhe->bsd_xfer[1]) {
 		/* we are ready! */
 
-		TAILQ_INSERT_HEAD(&uhe->bsd_urb_list, urb, bsd_urb_list);
+		TAILQ_INSERT_TAIL(&uhe->bsd_urb_list, urb, bsd_urb_list);
 
 		urb->status = -EINPROGRESS;
 
@@ -908,6 +908,7 @@ usb_linux_create_usb_device(struct usb_device *udev, device_t dev)
 				if (p_uhe) {
 					bcopy(ed, &p_uhe->desc, sizeof(p_uhe->desc));
 					p_uhe->bsd_iface_index = iface_index - 1;
+					TAILQ_INIT(&p_uhe->bsd_urb_list);
 					p_uhe++;
 				}
 				if (p_uhi) {

From 9e5d4aec14a32124871622adde2e889fee2375a2 Mon Sep 17 00:00:00 2001
From: Andrew Thompson 
Date: Sun, 28 Mar 2010 20:07:08 +0000
Subject: [PATCH 118/119] Do not swap Apple keys when detecting Apple-FN
 keyboards.

Reported by:	Steven Noonan
Submitted by:	Hans Petter Selasky
---
 sys/dev/usb/input/ukbd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/sys/dev/usb/input/ukbd.c b/sys/dev/usb/input/ukbd.c
index 399cd591b6a..8584f8d505d 100644
--- a/sys/dev/usb/input/ukbd.c
+++ b/sys/dev/usb/input/ukbd.c
@@ -896,8 +896,7 @@ ukbd_attach(device_t dev)
 		    hid_input, 0, &sc->sc_loc_apple_fn, &flags,
 		    &temp_id)) {
 			if (flags & HIO_VARIABLE)
-				sc->sc_flags |= UKBD_FLAG_APPLE_FN |
-				    UKBD_FLAG_APPLE_SWAP;
+				sc->sc_flags |= UKBD_FLAG_APPLE_FN;
 			DPRINTFN(1, "Found Apple FN-key\n");
 			apple_keys = 1;
 			sc->sc_kbd_id = temp_id;

From b4eb1a01cf5bd711af517a411bab4de83e468115 Mon Sep 17 00:00:00 2001
From: Andrew Thompson 
Date: Sun, 28 Mar 2010 20:09:04 +0000
Subject: [PATCH 119/119] Do not sync cache for the PL2506

PR:		usb/144915
Submitted by:	Monty Hall
---
 sys/dev/usb/quirk/usb_quirk.c | 2 ++
 sys/dev/usb/usbdevs           | 1 +
 2 files changed, 3 insertions(+)

diff --git a/sys/dev/usb/quirk/usb_quirk.c b/sys/dev/usb/quirk/usb_quirk.c
index 4090b5683b6..b829ac1d307 100644
--- a/sys/dev/usb/quirk/usb_quirk.c
+++ b/sys/dev/usb/quirk/usb_quirk.c
@@ -318,6 +318,8 @@ static struct usb_quirk_entry usb_quirks[USB_DEV_QUIRKS_MAX] = {
 	USB_QUIRK(PNY, ATTACHE2, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE,
 	    UQ_MSC_NO_START_STOP),
+	USB_QUIRK(PROLIFIC, PL2506, 0x0000, 0xffff,
+	    UQ_MSC_NO_SYNC_CACHE),
 	USB_QUIRK_VP(USB_VENDOR_SAMSUNG_TECHWIN,
 	    USB_PRODUCT_SAMSUNG_TECHWIN_DIGIMAX_410, UQ_MSC_FORCE_WIRE_BBB,
 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
diff --git a/sys/dev/usb/usbdevs b/sys/dev/usb/usbdevs
index 64327689bdc..e4128515567 100644
--- a/sys/dev/usb/usbdevs
+++ b/sys/dev/usb/usbdevs
@@ -2416,6 +2416,7 @@ product PROLIFIC PL2303		0x2303	PL2303 Serial (ATEN/IOGEAR UC232A)
 product PROLIFIC PL2305		0x2305	Parallel printer
 product PROLIFIC ATAPI4		0x2307	ATAPI-4 Controller
 product PROLIFIC PL2501		0x2501	PL2501 Host-Host interface
+product PROLIFIC PL2506		0x2506	PL2506 USB to IDE Bridge
 product PROLIFIC PHAROS		0xaaa0	Prolific Pharos
 product PROLIFIC RSAQ3		0xaaa2	PL2303 Serial Adapter (IODATA USB-RSAQ3)
 product PROLIFIC2 WSIM		0x2001	Willcom WSIM