From ed1bfa0c21257609fd636056c75558c212dfa83e Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Mon, 7 Oct 2013 08:14:58 +0000 Subject: [PATCH 01/26] Add the definition of DF_1_INTERPOSE flag. Reviewed by: kan Sponsored by: The FreeBSD Foundation MFC after: 1 week Approved by: re (glebius) --- sys/sys/elf_common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/sys/elf_common.h b/sys/sys/elf_common.h index bbcd3cd70e7..000035cd053 100644 --- a/sys/sys/elf_common.h +++ b/sys/sys/elf_common.h @@ -487,6 +487,7 @@ typedef struct { #define DF_1_LOADFLTR 0x00000010 /* Immediate loading of filtees */ #define DF_1_NOOPEN 0x00000040 /* Do not allow loading on dlopen() */ #define DF_1_ORIGIN 0x00000080 /* Process $ORIGIN */ +#define DF_1_INTERPOSE 0x00000400 /* Interpose all objects but main */ #define DF_1_NODEFLIB 0x00000800 /* Do not search default paths */ /* Values for n_type. Used in core files. */ From 3cf98c19e84cfcefb75a295201e39c43215ca328 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Mon, 7 Oct 2013 08:19:30 +0000 Subject: [PATCH 02/26] Implement support for the interpose dso flag. Requested by: bf Reviewed by: kan Sponsored by: The FreeBSD Foundation MFC after: 1 week Approved by: re (glebius) --- libexec/rtld-elf/rtld.c | 34 ++++++++++++++++++++++++++++++++-- libexec/rtld-elf/rtld.h | 1 + 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index f690d75f134..fa6dc2a0c2c 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -116,6 +116,7 @@ static Objlist_Entry *objlist_find(Objlist *, const Obj_Entry *); static void objlist_init(Objlist *); static void objlist_push_head(Objlist *, Obj_Entry *); static void objlist_push_tail(Objlist *, Obj_Entry *); +static void objlist_put_after(Objlist *, Obj_Entry *, Obj_Entry *); static void objlist_remove(Objlist *, Obj_Entry *); static void *path_enumerate(const char *, path_enum_proc, void *); static int relocate_object_dag(Obj_Entry *root, bool bind_now, @@ -323,6 +324,7 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp) Objlist_Entry *entry; Obj_Entry *obj; Obj_Entry **preload_tail; + Obj_Entry *last_interposer; Objlist initlist; RtldLockState lockstate; char *library_path_rpath; @@ -537,8 +539,14 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp) die(); /* Make a list of all objects loaded at startup. */ + last_interposer = obj_main; for (obj = obj_list; obj != NULL; obj = obj->next) { - objlist_push_tail(&list_main, obj); + if (obj->z_interpose && obj != obj_main) { + objlist_put_after(&list_main, last_interposer, obj); + last_interposer = obj; + } else { + objlist_push_tail(&list_main, obj); + } obj->refcount++; } @@ -1128,6 +1136,8 @@ digest_dynamic1(Obj_Entry *obj, int early, const Elf_Dyn **dyn_rpath, obj->z_nodelete = true; if (dynp->d_un.d_val & DF_1_LOADFLTR) obj->z_loadfltr = true; + if (dynp->d_un.d_val & DF_1_INTERPOSE) + obj->z_interpose = true; if (dynp->d_un.d_val & DF_1_NODEFLIB) obj->z_nodeflib = true; break; @@ -1976,6 +1986,7 @@ static int load_preload_objects(void) { char *p = ld_preload; + Obj_Entry *obj; static const char delim[] = " \t:;"; if (p == NULL) @@ -1988,8 +1999,10 @@ load_preload_objects(void) savech = p[len]; p[len] = '\0'; - if (load_object(p, -1, NULL, 0) == NULL) + obj = load_object(p, -1, NULL, 0); + if (obj == NULL) return -1; /* XXX - cleanup */ + obj->z_interpose = true; p[len] = savech; p += len; p += strspn(p, delim); @@ -2377,6 +2390,23 @@ objlist_push_tail(Objlist *list, Obj_Entry *obj) STAILQ_INSERT_TAIL(list, elm, link); } +static void +objlist_put_after(Objlist *list, Obj_Entry *listobj, Obj_Entry *obj) +{ + Objlist_Entry *elm, *listelm; + + STAILQ_FOREACH(listelm, list, link) { + if (listelm->obj == listobj) + break; + } + elm = NEW(Objlist_Entry); + elm->obj = obj; + if (listelm != NULL) + STAILQ_INSERT_AFTER(list, listelm, elm, link); + else + STAILQ_INSERT_TAIL(list, elm, link); +} + static void objlist_remove(Objlist *list, Obj_Entry *obj) { diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h index 0aba7cdc2fb..083f5a4f673 100644 --- a/libexec/rtld-elf/rtld.h +++ b/libexec/rtld-elf/rtld.h @@ -259,6 +259,7 @@ typedef struct Struct_Obj_Entry { bool z_nodelete : 1; /* Do not unload the object and dependencies */ bool z_noopen : 1; /* Do not load on dlopen */ bool z_loadfltr : 1; /* Immediately load filtees */ + bool z_interpose : 1; /* Interpose all objects but main */ bool z_nodeflib : 1; /* Don't search default library path */ bool ref_nodel : 1; /* Refcount increased to prevent dlclose */ bool init_scanned: 1; /* Object is already on init list. */ From eafc73a8a9799fde9dd81d2a548c051a88936afc Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Mon, 7 Oct 2013 10:01:23 +0000 Subject: [PATCH 03/26] Add a va_copy() to our fall-back stdarg implementation for use with lint(1) Approved by: re@ (glebius@) --- sys/x86/include/stdarg.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys/x86/include/stdarg.h b/sys/x86/include/stdarg.h index c315dfcee13..95bd02a37bb 100644 --- a/sys/x86/include/stdarg.h +++ b/sys/x86/include/stdarg.h @@ -64,6 +64,8 @@ typedef __va_list va_list; (((sizeof(type) + sizeof(long) - 1) / sizeof(long)) * sizeof(long)) #define va_start(ap, last) \ ((ap) = (va_list)&(last) + __va_size(last)) +#define va_copy(dst, src) \ + ((dst) = (src)) #define va_arg(ap, type) \ (*(type *)((ap) += __va_size(type), (ap) - __va_size(type))) #define va_end(ap) From e5abbf165ec154f1b9537ced0b383587ad8926c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Mon, 7 Oct 2013 10:26:38 +0000 Subject: [PATCH 04/26] Introduce the /libexec/freebsd-version script, which is intended to be used by auditing tools to determine the userland patch level when it differs from what `uname -r` reports. This can happen when the system is kept up-to-date using freebsd-update and the last SA did not touch the kernel, or when a new kernel has been installed but the system has not yet rebooted. Approved by: re (glebius) --- libexec/Makefile | 1 + libexec/freebsd-version/Makefile | 21 +++ libexec/freebsd-version/freebsd-version.1 | 124 +++++++++++++++++ libexec/freebsd-version/freebsd-version.sh.in | 126 ++++++++++++++++++ 4 files changed, 272 insertions(+) create mode 100644 libexec/freebsd-version/Makefile create mode 100644 libexec/freebsd-version/freebsd-version.1 create mode 100644 libexec/freebsd-version/freebsd-version.sh.in diff --git a/libexec/Makefile b/libexec/Makefile index 0b9c9618a1b..1039b24691d 100644 --- a/libexec/Makefile +++ b/libexec/Makefile @@ -8,6 +8,7 @@ SUBDIR= ${_atf} \ bootpd \ ${_comsat} \ fingerd \ + freebsd-version \ ftpd \ getty \ ${_mail.local} \ diff --git a/libexec/freebsd-version/Makefile b/libexec/freebsd-version/Makefile new file mode 100644 index 00000000000..96685c43788 --- /dev/null +++ b/libexec/freebsd-version/Makefile @@ -0,0 +1,21 @@ +# $FreeBSD$ + +SCRIPTS = freebsd-version +MAN = freebsd-version.1 +BINDIR = /libexec +CLEANFILES = freebsd-version.sh +NEWVERS = ${.CURDIR}/../../sys/conf/newvers.sh + +freebsd-version.sh.in: ${NEWVERS} +freebsd-version.sh: freebsd-version.sh.in + eval $$(egrep '^(TYPE|REVISION|BRANCH)=' ${NEWVERS}) ; \ + if ! sed -e "\ + s/@@TYPE@@/$${TYPE}/g; \ + s/@@REVISION@@/$${REVISION}/g; \ + s/@@BRANCH@@/$${BRANCH}/g; \ + " ${.ALLSRC} >${.TARGET} ; then \ + rm -f ${.TARGET} ; \ + exit 1 ; \ + fi + +.include diff --git a/libexec/freebsd-version/freebsd-version.1 b/libexec/freebsd-version/freebsd-version.1 new file mode 100644 index 00000000000..ee3f748f128 --- /dev/null +++ b/libexec/freebsd-version/freebsd-version.1 @@ -0,0 +1,124 @@ +.\"- +.\" Copyright (c) 2013 Dag-Erling Smørgrav +.\" 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$ +.\" +.Dd October 5, 2013 +.Dt FREEBSD-VERSION 1 +.Os +.Sh NAME +.Nm freebsd-version +.Nd print the version and patch level of the installed system +.Sh SYNOPSIS +.Nm +.Op Fl ku +.Sh DESCRIPTION +The +.Nm +utility makes a best effort to determine the version and patch level +of the installed kernel and / or userland. +.Pp +The following options are available: +.Bl -tag -width Fl +.It Fl k +Print the version and patch level of the installed kernel. +Unlike +.Xr uname 1 , +if a new kernel has been installed but the system has not yet +rebooted, +.Nm +will print the version and patch level of the new kernel. +.It Fl u +Print the version and patch level of the installed userland. +These are hardcoded into +.Nm +during the build. +.El +.Pp +If both +.Fl k +and +.Fl u +are specified, +.Nm +will print the kernel version first, then the userland version, on +separate lines. +If neither is specified, it will print the userland version only. +.Sh IMPLEMENTATION NOTES +The +.Nm +utility should provide the correct answer in the vast majority of +cases, including on systems kept up-to-date using +.Xr freebsd-update 8 , +which does not update the kernel version unless the kernel itself was +affected by the latest patch. +.Pp +To determine the name (and hence the location) of a custom kernel, the +.Nm +utility will attempt to parse +.Pa /boot/defaults/loader.conf +and +.Pa /boot/loader.conf , +looking for definitions of the +.Va kernel +and +.Va bootfile +variables, both with a default value of +.Dq kernel . +It may however fail to locate the correct kernel if either or both of +these variables are defined in a non-standard location, such as in +.Pa /boot/loader.rc . +.Sh ENVIRONMENT +.Bl -tag -width ROOT +.It Ev ROOT +Path to the root of the filesystem in which to look for +.Pa loader.conf +and the kernel. +.El +.Sh EXAMPLES +To determine the version of the currently running userland: +.Bd -literal -offset indent +/libexec/freebsd-version -u +.Ed +.Pp +To inspect a system being repaired using a live CD: +.Bd -literal -offset indent +mount -rt ufs /dev/ada0p2 /mnt +env ROOT=/mnt /mnt/libexec/freebsd-version -ku +.Ed +.Sh SEE ALSO +.Xr uname 1 , +.Xr loader.conf 5 , +.Xr freebsd-version 8 +.Sh HISTORY +The +.Nm +command appeared in +.Fx 10.0 . +.Sh AUTHORS +The +.Nm +utility and this manual page were written by +.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org . diff --git a/libexec/freebsd-version/freebsd-version.sh.in b/libexec/freebsd-version/freebsd-version.sh.in new file mode 100644 index 00000000000..0f9a46823fb --- /dev/null +++ b/libexec/freebsd-version/freebsd-version.sh.in @@ -0,0 +1,126 @@ +#!/bin/sh +#- +# Copyright (c) 2013 Dag-Erling Smørgrav +# 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$ +# + +set -e + +USERLAND_VERSION="@@REVISION@@-@@BRANCH@@" + +: ${ROOT:=} +: ${LOADER_DIR:=$ROOT/boot} +: ${LOADER_CONF_FILES:=$LOADER_DIR/defaults/loader.conf $LOADER_DIR/loader.conf $LOADER_DIR/loader.conf.local} +LOADER_RE1='^\([A-Z_a-z][0-9A-Z_a-z]*=[-./0-9A-Z_a-z]\{1,\}\).*$' +LOADER_RE2='^\([A-Z_a-z][0-9A-Z_a-z]*="[-./0-9A-Z_a-z]\{1,\}"\).*$' +KERNEL_RE='^@(#)@@TYPE@@ \([-.0-9A-Za-z]\{1,\}\) .*$' + +progname=$(basename $0) + +# +# Print an error message and exit. +# +error() { + echo "$progname: $*" >&2 + exit 1 +} + +# +# Try to get the name of the installed kernel from loader.conf and +# return the full path. If loader.conf does not exist or we could not +# read it, return the path to the default kernel. +# +kernel_file() { + eval $(sed -n "s/$LOADER_RE1/\\1;/p; s/$LOADER_RE2/\\1;/p" \ + $LOADER_CONF_FILES 2>/dev/null) + echo "$LOADER_DIR/${kernel:-kernel}/${bootfile:-kernel}" +} + +# +# Extract the kernel version from the installed kernel. +# +kernel_version() { + kernfile=$(kernel_file) + if [ ! -f "$kernfile" -o ! -r "$kernfile" ] ; then + error "unable to locate kernel" + fi + strings "$kernfile" | sed -n "s/$KERNEL_RE/\\1/p" +} + +# +# Print the hardcoded userland version. +# +userland_version() { + echo $USERLAND_VERSION +} + +# +# Print a usage string and exit. +# +usage() { + echo "usage: $progname [-ku]\n" >&2 + exit 1 +} + +# +# Main program. +# +main() { + # parse command-line arguments + while getopts "ku" option ; do + case $option in + k) + opt_k=1 + ;; + u) + opt_u=1 + ;; + *) + usage + ;; + esac + done + if [ $OPTIND -le $# ] ; then + usage + fi + + # default is -u + if [ $((opt_k + opt_u)) -eq 0 ] ; then + opt_u=1 + fi + + # print kernel version + if [ $opt_k ] ; then + kernel_version + fi + + # print userland version + if [ $opt_u ] ; then + userland_version + fi +} + +main "$@" From 56f0ad0dcc28368b3feaf18e949f61bb94dbb6b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Mon, 7 Oct 2013 11:23:01 +0000 Subject: [PATCH 05/26] When displaying a struct stat, if the -r option was not specified, display the numeric rather than symbolic representation of st_mode. Approved by: re (glebius) MFC after: 1 week --- usr.bin/kdump/kdump.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c index e3e6927510c..24bb0fd34e0 100644 --- a/usr.bin/kdump/kdump.c +++ b/usr.bin/kdump/kdump.c @@ -1655,10 +1655,15 @@ ktrstat(struct stat *statp) * buffer exactly sizeof(struct stat) bytes long. */ printf("struct stat {"); - strmode(statp->st_mode, mode); - printf("dev=%ju, ino=%ju, mode=%s, nlink=%ju, ", - (uintmax_t)statp->st_dev, (uintmax_t)statp->st_ino, mode, - (uintmax_t)statp->st_nlink); + printf("dev=%ju, ino=%ju, ", + (uintmax_t)statp->st_dev, (uintmax_t)statp->st_ino); + if (resolv == 0) + printf("mode=0%jo, ", (uintmax_t)statp->st_mode); + else { + strmode(statp->st_mode, mode); + printf("mode=%s, ", mode); + } + printf("nlink=%ju, ", (uintmax_t)statp->st_nlink); if (resolv == 0 || (pwd = getpwuid(statp->st_uid)) == NULL) printf("uid=%ju, ", (uintmax_t)statp->st_uid); else From 491b52017498b2ee85b6cad27b9ddbbae5fd96c3 Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Mon, 7 Oct 2013 12:07:40 +0000 Subject: [PATCH 06/26] Fix mbuf leak. Submitted by: Loganaden Velvindron Obtained from: NetBSD Approved by: re (kib) --- sys/netinet6/ip6_mroute.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c index 36d0d6f183d..6a5fb88d86b 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -616,7 +616,7 @@ X_ip6_mrouter_done(void) for (rte = rt->mf6c_stall; rte != NULL; ) { struct rtdetq *n = rte->next; - m_free(rte->m); + m_freem(rte->m); free(rte, M_MRTABLE6); rte = n; } From 8a675a639645546f27b42a3c3f7f2388a010c8f8 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 7 Oct 2013 14:22:19 +0000 Subject: [PATCH 07/26] Fix implicit declaration of jail_getid() Approved by: re --- cddl/contrib/opensolaris/cmd/zfs/zfs_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c b/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c index 3779b2996fb..a2d497370ee 100644 --- a/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c +++ b/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include From e1a5a8a74add9e8b580df228e15048a8e6329763 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 7 Oct 2013 16:33:16 +0000 Subject: [PATCH 08/26] Add support for assembling and disassembling Intel Random Number Generator extensions (e.g. the 'rdrand' mnemonic) to our copy of binutils. Approved by: re (kib) Obtained from: OpenBSD, via pfg MFC after: 1 week --- contrib/binutils/opcodes/i386-dis.c | 22 +++++++++++++++------- contrib/binutils/opcodes/i386-opc.h | 3 ++- contrib/binutils/opcodes/i386-opc.tbl | 18 ++++++++++++++++++ contrib/binutils/opcodes/i386-tbl.h | 5 +++++ 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/contrib/binutils/opcodes/i386-dis.c b/contrib/binutils/opcodes/i386-dis.c index eb33089a407..a1342130456 100644 --- a/contrib/binutils/opcodes/i386-dis.c +++ b/contrib/binutils/opcodes/i386-dis.c @@ -6438,14 +6438,22 @@ VMX_Fixup (int extrachar ATTRIBUTE_UNUSED, int sizeflag) static void OP_VMX (int bytemode, int sizeflag) { - used_prefixes |= (prefixes & (PREFIX_DATA | PREFIX_REPZ)); - if (prefixes & PREFIX_DATA) - strcpy (obuf, "vmclear"); - else if (prefixes & PREFIX_REPZ) - strcpy (obuf, "vmxon"); + if (modrm.mod == 3) + { + strcpy (obuf, "rdrand"); + OP_E (v_mode, sizeflag); + } else - strcpy (obuf, "vmptrld"); - OP_E (bytemode, sizeflag); + { + used_prefixes |= (prefixes & (PREFIX_DATA | PREFIX_REPZ)); + if (prefixes & PREFIX_DATA) + strcpy (obuf, "vmclear"); + else if (prefixes & PREFIX_REPZ) + strcpy (obuf, "vmxon"); + else + strcpy (obuf, "vmptrld"); + OP_E (bytemode, sizeflag); + } } static void diff --git a/contrib/binutils/opcodes/i386-opc.h b/contrib/binutils/opcodes/i386-opc.h index 27c1dab2aae..8d6fd8a15f9 100644 --- a/contrib/binutils/opcodes/i386-opc.h +++ b/contrib/binutils/opcodes/i386-opc.h @@ -79,6 +79,7 @@ typedef struct template #define CpuNo64 0x8000000 /* Not supported in the 64bit mode */ #define CpuPCLMUL 0x10000000 /* Carry-less Multiplication extensions */ +#define CpuRdRnd 0x20000000 /* Intel Random Number Generator extensions */ /* SSE4.1/4.2 Instructions required */ #define CpuSSE4 (CpuSSE4_1|CpuSSE4_2) @@ -87,7 +88,7 @@ typedef struct template #define CpuUnknownFlags (Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686 \ |CpuP4|CpuSledgehammer|CpuMMX|CpuMMX2|CpuSSE|CpuSSE2|CpuSSE3|CpuVMX \ |Cpu3dnow|Cpu3dnowA|CpuK6|CpuPadLock|CpuSVME|CpuSSSE3|CpuSSE4_1 \ - |CpuSSE4_2|CpuABM|CpuSSE4a|CpuXSAVE|CpuAES|CpuPCLMUL) + |CpuSSE4_2|CpuABM|CpuSSE4a|CpuXSAVE|CpuAES|CpuPCLMUL|CpuRdRnd) /* the bits in opcode_modifier are used to generate the final opcode from the base_opcode. These bits also are used to detect alternate forms of diff --git a/contrib/binutils/opcodes/i386-opc.tbl b/contrib/binutils/opcodes/i386-opc.tbl index 6cb72199fd4..ea188ddca8f 100644 --- a/contrib/binutils/opcodes/i386-opc.tbl +++ b/contrib/binutils/opcodes/i386-opc.tbl @@ -1502,3 +1502,21 @@ xrstor, 1, 0xfae, 0x5, CpuXSAVE, Modrm|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_xSuf, // INVPCID invpcid, 2, 0x660f3882, None, CpuNo64, Modrm|IgnoreSize|No_bSuf|No_wSuf|No_sSuf|No_qSuf|No_xSuf|NoRex64, { BaseIndex|Disp8|Disp16|Disp32|Disp32S, Reg32 } invpcid, 2, 0x660f3882, None, Cpu64, Modrm|IgnoreSize|No_bSuf|No_wSuf|No_sSuf|No_qSuf|No_xSuf|NoRex64, { BaseIndex|Disp8|Disp16|Disp32|Disp32S, Reg64 } + +// Intel AES extensions +aesdec, 2, 0x660f38de, None, CpuAES, Modrm|IgnoreSize|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf|No_xSuf, { RegXMM|LLongMem, RegXMM } +aesdeclast, 2, 0x660f38df, None, CpuAES, Modrm|IgnoreSize|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf|No_xSuf, { RegXMM|LLongMem, RegXMM } +aesenc, 2, 0x660f38dc, None, CpuAES, Modrm|IgnoreSize|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf|No_xSuf, { RegXMM|LLongMem, RegXMM } +aesenclast, 2, 0x660f38dd, None, CpuAES, Modrm|IgnoreSize|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf|No_xSuf, { RegXMM|LLongMem, RegXMM } +aesimc, 2, 0x660f38db, None, CpuAES, Modrm|IgnoreSize|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf|No_xSuf, { RegXMM|LLongMem, RegXMM } +aeskeygenassist, 3, 0x660f3adf, None, CpuAES, Modrm|IgnoreSize|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf|No_xSuf, { Imm8, RegXMM|LLongMem, RegXMM } + +// Intel Carry-less Multiplication extensions +pclmulqdq, 3, 0x660f3a44, None, CpuPCLMUL, Modrm|IgnoreSize|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf|No_xSuf, { Imm8, RegXMM|LLongMem, RegXMM } +pclmullqlqdq, 2, 0x660f3a44, 0x0, CpuPCLMUL, Modrm|IgnoreSize|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf|No_xSuf|ImmExt, { RegXMM|LLongMem, RegXMM } +pclmulhqlqdq, 2, 0x660f3a44, 0x1, CpuPCLMUL, Modrm|IgnoreSize|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf|No_xSuf|ImmExt, { RegXMM|LLongMem, RegXMM } +pclmullqhqdq, 2, 0x660f3a44, 0x10, CpuPCLMUL, Modrm|IgnoreSize|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf|No_xSuf|ImmExt, { RegXMM|LLongMem, RegXMM } +pclmulhqhqdq, 2, 0x660f3a44, 0x11, CpuPCLMUL, Modrm|IgnoreSize|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf|No_xSuf|ImmExt, { RegXMM|LLongMem, RegXMM } + +// Intel Random Number Generator extensions +rdrand, 1, 0x0fc7, 0x6, CpuRdRnd, Modrm|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf|No_xSuf, { Reg16|Reg32|Reg64 } diff --git a/contrib/binutils/opcodes/i386-tbl.h b/contrib/binutils/opcodes/i386-tbl.h index c42f56591bc..ec19f109ae4 100644 --- a/contrib/binutils/opcodes/i386-tbl.h +++ b/contrib/binutils/opcodes/i386-tbl.h @@ -4374,6 +4374,11 @@ const template i386_optab[] = Modrm|IgnoreSize|NoSuf|ImmExt, { RegXMM|LLongMem, RegXMM } }, + + /* Intel Random Number Generator extensions */ + {"rdrand", 1, 0x0fc7, 0x6, CpuRdRnd, + Modrm|NoSuf, + { Reg16|Reg32|Reg64 } }, { NULL, 0, 0, 0, 0, 0, { 0 } } }; From 9d85dfae1e8f79ce7073f8520f7ee6b25442fad2 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Mon, 7 Oct 2013 16:45:16 +0000 Subject: [PATCH 09/26] Fix resource leaks Found by: Coverity Scan, CID 1016673, 1007118 Approved by: re --- sbin/camcontrol/fwdownload.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sbin/camcontrol/fwdownload.c b/sbin/camcontrol/fwdownload.c index 7e57d320772..181c2344a63 100644 --- a/sbin/camcontrol/fwdownload.c +++ b/sbin/camcontrol/fwdownload.c @@ -224,6 +224,7 @@ fw_read_img(const char *fw_img_path, const struct fw_vendor *vp, int *num_bytes) goto bailout; } *num_bytes = img_size; + close(fd); return (buf); bailout: free(buf); @@ -286,6 +287,7 @@ fw_download_img(struct cam_device *cam_dev, const struct fw_vendor *vp, ata_28bit_cmd(&ccb->ataio, ATA_ATA_IDENTIFY, 0, 0, 0); } else { warnx("weird disk type '%s'", type); + cam_freeccb(ccb); return 1; } /* Disable freezing the device queue. */ From 2a6b4327c288b6a121f131f7ef09b871b9a14f96 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Mon, 7 Oct 2013 16:49:53 +0000 Subject: [PATCH 10/26] add missing sections, de-Xr non-existent page, properly space punctuation.. Approved by: re (joel) MFC after: 3 days --- share/man/man4/altera_avgen.4 | 8 ++++---- share/man/man4/rsu.4 | 4 ++-- share/man/man8/picobsd.8 | 12 ++++-------- share/man/man9/firmware.9 | 4 ++-- share/man/man9/vm_page_grab.9 | 2 +- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/share/man/man4/altera_avgen.4 b/share/man/man4/altera_avgen.4 index fee8f54fd81..2ba9360b7fc 100644 --- a/share/man/man4/altera_avgen.4 +++ b/share/man/man4/altera_avgen.4 @@ -56,11 +56,11 @@ entries configure the address, size, I/O disposition, and .Pa /dev device node name that will be used. The -.Xr open , -.Xr read , -.Xr write , +.Xr open 2 , +.Xr read 2 , +.Xr write 2 , and -.Xr mmap +.Xr mmap 2 system calls (and variations) may be used on .Nm device nodes, subject to constraints imposed using diff --git a/share/man/man4/rsu.4 b/share/man/man4/rsu.4 index fa9767a540a..5d5c56c3006 100644 --- a/share/man/man4/rsu.4 +++ b/share/man/man4/rsu.4 @@ -35,9 +35,9 @@ place the following lines in your kernel configuration file: .Pp Alternatively, to load the driver as a module at boot time, place the following line in -.Xr loader.conf 5: +.Xr loader.conf 5 : .Bd -literal -offset indent -.Xr if_rsu_load="YES" +if_rsu_load="YES" .Ed .Pp After you have read the license in /usr/share/doc/legal/realtek diff --git a/share/man/man8/picobsd.8 b/share/man/man8/picobsd.8 index d1d8c46c296..e117fe447e8 100644 --- a/share/man/man8/picobsd.8 +++ b/share/man/man8/picobsd.8 @@ -20,7 +20,7 @@ utility is a script which produces a minimal implementation of which typically fits on a small media such as a floppy disk, or can be downloaded as a single image file from some media such as CDROM, flash memory, or through -.Xr etherboot . +etherboot. .Pp The .Nm @@ -64,7 +64,7 @@ kernel. This is the default behaviour, and is extremely useful as the kernel itself can be loaded, using -.Xr etherboot +etherboot or .Xr pxeboot 8 , .\" @@ -378,9 +378,7 @@ If the build is successful, the directory .Pa build_dir-bridge/ will contain a .Pa kernel -that can be downloaded with -.Xr etherboot , -a floppy image called +that can be downloaded with etherboot, a floppy image called .Pa picobsd.bin , plus the products of the compilation in other directories. If you want to modify the source tree in @@ -480,9 +478,7 @@ Booting from a floppy is normally rather slow (in the order of 1-2 minutes), things are much faster if you store your image on a hard disk, Compact Flash, or CDROM. .Pp -You can also use -.Xr etherboot -to load the preloaded, uncompressed kernel image +You can also use etherboot to load the preloaded, uncompressed kernel image which is a byproduct of the .Nm build. diff --git a/share/man/man9/firmware.9 b/share/man/man9/firmware.9 index 807099d50a7..48119213e23 100644 --- a/share/man/man9/firmware.9 +++ b/share/man/man9/firmware.9 @@ -254,8 +254,8 @@ IxNpeMicrocode.dat optional npe_fw \\ .Pp Note that generating the firmware modules in this way requires the availability of the following tools: -.Xr awk , -.Xr make , +.Xr awk 1 , +.Xr make 1 , the compiler and the linker. .Sh SEE ALSO .Xr kld 4 , diff --git a/share/man/man9/vm_page_grab.9 b/share/man/man9/vm_page_grab.9 index cfab9def326..ff9aae902de 100644 --- a/share/man/man9/vm_page_grab.9 +++ b/share/man/man9/vm_page_grab.9 @@ -64,7 +64,7 @@ function sleeps for any reason, the object lock is temporary dropped. The .Fn vm_page_grab supports all of the flags supported by -.Xr vm_page_alloc . +.Xr vm_page_alloc 9 . In addition, .Fn vm_page_grab supports the following flags: From d359802e10f28366bb2657603949f8d59e37526d Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 7 Oct 2013 16:53:26 +0000 Subject: [PATCH 11/26] Remove redundant declaration of force_evtchn_callback() in the i386-specific xen-os.h, to silence a gcc warning. Approved by: re (gjb) MFC after: 3 days --- sys/i386/include/xen/xen-os.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/sys/i386/include/xen/xen-os.h b/sys/i386/include/xen/xen-os.h index e15d6687006..a8fba61bde7 100644 --- a/sys/i386/include/xen/xen-os.h +++ b/sys/i386/include/xen/xen-os.h @@ -37,9 +37,6 @@ /* Everything below this point is not included by assembler (.S) files. */ #ifndef __ASSEMBLY__ -/* Force a proper event-channel callback from Xen. */ -void force_evtchn_callback(void); - /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */ static inline void rep_nop(void) { From 7ea82d6741969b89418a48fbf6ce2ff8b58ef110 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 7 Oct 2013 16:54:29 +0000 Subject: [PATCH 12/26] Give an unnamed union in sys/ofed/include/rdma/ib_verbs.h a name, to silence a gcc warning. Approved by: re (gjb) MFC after: 3 days --- sys/ofed/include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/ofed/include/rdma/ib_verbs.h b/sys/ofed/include/rdma/ib_verbs.h index 0145cb2965a..7c1700715c8 100644 --- a/sys/ofed/include/rdma/ib_verbs.h +++ b/sys/ofed/include/rdma/ib_verbs.h @@ -660,7 +660,7 @@ struct ib_qp_init_attr { union { struct ib_qp *qpg_parent; /* see qpg_type */ struct ib_qpg_init_attrib parent_attrib; - }; + } pp; enum ib_sig_type sq_sig_type; enum ib_qp_type qp_type; enum ib_qp_create_flags create_flags; From faf8ff5faaea900ca06ff01f41ea61b9cdc07f93 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 7 Oct 2013 16:55:34 +0000 Subject: [PATCH 13/26] Initialize a variable in sys/dev/xen/control/control.c, to silence a gcc warning. Approved by: re (gjb) MFC after: 3 days --- sys/dev/xen/control/control.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/dev/xen/control/control.c b/sys/dev/xen/control/control.c index a74042bf225..a9f8d1b6097 100644 --- a/sys/dev/xen/control/control.c +++ b/sys/dev/xen/control/control.c @@ -371,6 +371,7 @@ xctrl_suspend() mtx_unlock(&Giant); #ifdef SMP + CPU_ZERO(&cpu_suspend_map); /* silence gcc */ if (smp_started) { /* * Suspend other CPUs. This prevents IPIs while we From 42355a4ff6f8b35832528a91436759892c499444 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 7 Oct 2013 16:56:56 +0000 Subject: [PATCH 14/26] Remove redundant declaration of cpu_clflush_line_size in sys/dev/cxgbe/t4_sge.c, to silence a gcc warning. Approved by: re (gjb) MFC after: 3 days --- sys/dev/cxgbe/t4_sge.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sys/dev/cxgbe/t4_sge.c b/sys/dev/cxgbe/t4_sge.c index 776b6c5a734..417843c61ae 100644 --- a/sys/dev/cxgbe/t4_sge.c +++ b/sys/dev/cxgbe/t4_sge.c @@ -215,10 +215,6 @@ static int handle_fw_msg(struct sge_iq *, const struct rss_header *, static int sysctl_uint16(SYSCTL_HANDLER_ARGS); -#if defined(__i386__) || defined(__amd64__) -extern u_int cpu_clflush_line_size; -#endif - /* * Called on MOD_LOAD. Validates and calculates the SGE tunables. */ From e38c5308a28458cff5fdce09d87e78794c73b2a7 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 7 Oct 2013 16:57:48 +0000 Subject: [PATCH 15/26] Remove redundant declarations of szsigcode and sigcode in sys/i386/ibcs2/ibcs2_sysvec.c, to silence two gcc warnings. Approved by: re (gjb) MFC after: 3 days --- sys/i386/ibcs2/ibcs2_sysvec.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/sys/i386/ibcs2/ibcs2_sysvec.c b/sys/i386/ibcs2/ibcs2_sysvec.c index 5b6f680cb13..5d007c7958d 100644 --- a/sys/i386/ibcs2/ibcs2_sysvec.c +++ b/sys/i386/ibcs2/ibcs2_sysvec.c @@ -54,8 +54,6 @@ MODULE_VERSION(ibcs2, 1); extern int bsd_to_ibcs2_errno[]; extern struct sysent ibcs2_sysent[IBCS2_SYS_MAXSYSCALL]; -extern int szsigcode; -extern char sigcode[]; static int ibcs2_fixup(register_t **, struct image_params *); struct sysentvec ibcs2_svr3_sysvec = { From 18bb1b08e527f91d4b6b6c81d3d39d26166c87be Mon Sep 17 00:00:00 2001 From: Eitan Adler Date: Mon, 7 Oct 2013 19:22:53 +0000 Subject: [PATCH 16/26] This regenerates src.conf.5 for both the RCS removal as well as r255784. Approved by: re (glebius) --- share/man/man5/src.conf.5 | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/share/man/man5/src.conf.5 b/share/man/man5/src.conf.5 index 78dfc679624..a176bb75b64 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 253304 2013-07-12 23:08:44Z bapt +.\" from FreeBSD: head/tools/build/options/makeman 255964 2013-10-01 07:22:04Z des .\" $FreeBSD$ -.Dd September 30, 2013 +.Dd October 6, 2013 .Dt SRC.CONF 5 .Os .Sh NAME @@ -200,7 +200,7 @@ When set, it also enforces the following options: Set to not build the Clang C/C++ compiler. .Pp It is a default setting on -arm/armeb, arm/armv6eb, ia64/ia64, mips/mipsel, mips/mips, mips/mips64el, mips/mips64, mips/mipsn32 and sparc64/sparc64. +arm/armeb, ia64/ia64, mips/mipsel, mips/mips, mips/mips64el, mips/mips64, mips/mipsn32 and sparc64/sparc64. When set, it also enforces the following options: .Pp .Bl -item -compact @@ -228,7 +228,7 @@ Set to avoid building the ARCMigrate, Rewriter and StaticAnalyzer components of the Clang C/C++ compiler. .Pp It is a default setting on -arm/arm, arm/armeb, arm/armv6, arm/armv6eb, ia64/ia64, mips/mipsel, mips/mips, mips/mips64el, mips/mips64, mips/mipsn32 and sparc64/sparc64. +arm/arm, arm/armeb, arm/armv6, ia64/ia64, mips/mipsel, mips/mips, mips/mips64el, mips/mips64, mips/mipsn32 and sparc64/sparc64. .It Va WITH_CLANG_FULL .\" from FreeBSD: head/tools/build/options/WITH_CLANG_FULL 246259 2013-02-02 22:28:29Z dim Set to build the ARCMigrate, Rewriter and StaticAnalyzer components of the @@ -245,7 +245,7 @@ and .Pa /usr/bin/cpp . .Pp It is a default setting on -arm/armeb, arm/armv6eb, ia64/ia64, mips/mipsel, mips/mips, mips/mips64el, mips/mips64, mips/mipsn32, powerpc/powerpc, powerpc/powerpc64 and sparc64/sparc64. +arm/armeb, ia64/ia64, mips/mipsel, mips/mips, mips/mips64el, mips/mips64, mips/mipsn32, powerpc/powerpc, powerpc/powerpc64 and sparc64/sparc64. When set, it also enforces the following options: .Pp .Bl -item -compact @@ -369,7 +369,7 @@ Set to build Flattened Device Tree support as part of the base system. This includes the device tree compiler (dtc) and libfdt support library. .Pp It is a default setting on -arm/arm, arm/armeb, arm/armv6, arm/armv6eb, mips/mipsel, mips/mips, mips/mips64el, mips/mips64, mips/mipsn32, powerpc/powerpc and powerpc/powerpc64. +arm/arm, arm/armeb, arm/armv6, mips/mipsel, mips/mips, mips/mips64el, mips/mips64, mips/mipsn32, powerpc/powerpc and powerpc/powerpc64. .It Va WITHOUT_FLOPPY .\" from FreeBSD: head/tools/build/options/WITHOUT_FLOPPY 221540 2011-05-06 19:13:03Z ru Set to not build or install programs @@ -406,7 +406,7 @@ amd64/amd64, arm/arm, arm/armv6 and i386/i386. Set to build and install gcc and g++. .Pp It is a default setting on -arm/armeb, arm/armv6eb, ia64/ia64, mips/mipsel, mips/mips, mips/mips64el, mips/mips64, mips/mipsn32, pc98/i386, powerpc/powerpc, powerpc/powerpc64 and sparc64/sparc64. +arm/armeb, ia64/ia64, mips/mipsel, mips/mips, mips/mips64el, mips/mips64, mips/mipsn32, pc98/i386, powerpc/powerpc, powerpc/powerpc64 and sparc64/sparc64. .It Va WITHOUT_GCOV .\" from FreeBSD: head/tools/build/options/WITHOUT_GCOV 156932 2006-03-21 07:50:50Z ru Set to not build the @@ -443,7 +443,7 @@ Build the GNU C++ stack (g++, libstdc++). This is the default on platforms where gcc is the system compiler. .Pp It is a default setting on -arm/armeb, arm/armv6eb, ia64/ia64, mips/mipsel, mips/mips, mips/mips64el, mips/mips64, mips/mipsn32, powerpc/powerpc, powerpc/powerpc64 and sparc64/sparc64. +arm/armeb, ia64/ia64, mips/mipsel, mips/mips, mips/mips64el, mips/mips64, mips/mipsn32, powerpc/powerpc, powerpc/powerpc64 and sparc64/sparc64. .It Va WITHOUT_GNU_SUPPORT .\" from FreeBSD: head/tools/build/options/WITHOUT_GNU_SUPPORT 156932 2006-03-21 07:50:50Z ru Set to build some programs without optional GNU support. @@ -909,11 +909,6 @@ This includes .Xr rlogin 1 , .Xr rsh 1 , etc. -.It Va WITHOUT_RCS -.\" from FreeBSD: head/tools/build/options/WITHOUT_RCS 156932 2006-03-21 07:50:50Z ru -Set to not build -.Xr rcs 1 -and related utilities. .It Va WITHOUT_RESCUE .\" from FreeBSD: head/tools/build/options/WITHOUT_RESCUE 156932 2006-03-21 07:50:50Z ru Set to not build From 3adb4d6fe55c8aae89fc8817c8c61e376d4fb3a7 Mon Sep 17 00:00:00 2001 From: Eitan Adler Date: Mon, 7 Oct 2013 19:23:43 +0000 Subject: [PATCH 17/26] Add an UPDATING entry for the RCS removal. Requested by: kargl Approved by: re (glebius) --- UPDATING | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/UPDATING b/UPDATING index 1c7646c2742..ebf000bab9e 100644 --- a/UPDATING +++ b/UPDATING @@ -31,6 +31,10 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 10.x IS SLOW: disable the most expensive debugging functionality run "ln -s 'abort:false,junk:false' /etc/malloc.conf".) +20131006: + RCS has been removed from the base system. If you need RCS + install either devel/rcs or devel/rcs57. + 20130930: BIND has been removed from the base system. If all you need is a local resolver, simply enable and start the local_unbound From 3bad2eaa9863b03c105fe37dc6c11e6b915a995f Mon Sep 17 00:00:00 2001 From: Eitan Adler Date: Mon, 7 Oct 2013 19:27:54 +0000 Subject: [PATCH 18/26] Add the latest NetBSD and FreeBSD releases. Approved by: re (glebius) --- share/misc/bsd-family-tree | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/share/misc/bsd-family-tree b/share/misc/bsd-family-tree index 7d0ae943808..74a9287a289 100644 --- a/share/misc/bsd-family-tree +++ b/share/misc/bsd-family-tree @@ -270,17 +270,23 @@ FreeBSD 5.2 | | | | | | | | | | \ | | | | | | | | NetBSD | | | | | | | | 6.0.1 | | + | | | | | | | | | + | | | | | | NetBSD | | + | | | | | | 6.0.2 | | | | | | | | | OpenBSD 5.3 DragonFly 3.4.1 | | | | | | NetBSD | | | | | | | | 6.0.2 | | | | | | | | | | - | | | | | `-NetBSD 6.1 | | - | | FreeBSD | | | | - | | 8.4 | | | | - | | | | | | - | FreeBSD | | | | + | | | | | |`-NetBSD 6.1 | | + | | FreeBSD | | | | | + | | 8.4 | | NetBSD 6.1.1 | | + | | | | | | | + | FreeBSD | | NetBSD 6.1.2 | | | 9.2 | | | | | | | | | + | | | | | + | | | | | + | | | | | FreeBSD 10 -current | NetBSD -current OpenBSD -current | | | | | | v v v v v @@ -588,9 +594,12 @@ OpenBSD 5.3 2013-05-01 [OBD] NetBSD 6.0.2 2013-05-18 [NBD] (security/critical release) NetBSD 6.1 2013-05-18 [NBD] FreeBSD 8.4 2013-06-07 [FBD] +NetBSD 6.1.1 2013-08-22 [NBD] NetBSD 5.1.3 2013-09-29 [NBD] NetBSD 5.2.1 2013-09-29 [NBD] FreeBSD 9.2 2013-09-30 [FBD] +NetBSD 6.0.3 2013-09-30 [NBD] +NetBSD 6.1.2 2013-09-30 [NBD] Bibliography ------------------------ From 80adee135aece9465111241dfd6c1e7b3d28d5b6 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Mon, 7 Oct 2013 20:29:31 +0000 Subject: [PATCH 19/26] Remove a stale comment. Approved by: re (gjb) --- share/man/man9/VOP_FSYNC.9 | 9 --------- 1 file changed, 9 deletions(-) diff --git a/share/man/man9/VOP_FSYNC.9 b/share/man/man9/VOP_FSYNC.9 index e457f846640..76e114ff609 100644 --- a/share/man/man9/VOP_FSYNC.9 +++ b/share/man/man9/VOP_FSYNC.9 @@ -65,15 +65,6 @@ Push data not written by file system syncer. .It Fa td The calling thread. .El -.Pp -The argument -.Fa waitfor -is either -.Dv MNT_WAIT -or -.Dv MNT_NOWAIT -and specifies whether or not the function should wait for the writes -to finish before returning. .Sh LOCKS The file should be locked on entry. .Sh RETURN VALUES From ea41f49fc5516590544503f6d1a29a87ee62c485 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Mon, 7 Oct 2013 20:30:05 +0000 Subject: [PATCH 20/26] Add manpages for VOP_ADVISE() and VOP_ALLOCATE(). Approved by: re (gjb) --- share/man/man9/Makefile | 2 + share/man/man9/VOP_ADVISE.9 | 88 +++++++++++++++++++++++++++++++++++ share/man/man9/VOP_ALLOCATE.9 | 84 +++++++++++++++++++++++++++++++++ share/man/man9/vnode.9 | 2 + 4 files changed, 176 insertions(+) create mode 100644 share/man/man9/VOP_ADVISE.9 create mode 100644 share/man/man9/VOP_ALLOCATE.9 diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile index 8ce940f9055..026ffea5445 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -343,7 +343,9 @@ MAN= accept_filter.9 \ vnode.9 \ VOP_ACCESS.9 \ VOP_ACLCHECK.9 \ + VOP_ADVISE.9 \ VOP_ADVLOCK.9 \ + VOP_ALLOCATE.9 \ VOP_ATTRIB.9 \ VOP_BWRITE.9 \ VOP_CREATE.9 \ diff --git a/share/man/man9/VOP_ADVISE.9 b/share/man/man9/VOP_ADVISE.9 new file mode 100644 index 00000000000..250be5209ae --- /dev/null +++ b/share/man/man9/VOP_ADVISE.9 @@ -0,0 +1,88 @@ +.\" -*- nroff -*- +.\" +.\" Copyright (c) 2013 Advanced Computing Technologies LLC +.\" Written by: John H. Baldwin +.\" 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$ +.\" +.Dd October 3, 2013 +.Dt VOP_ADVISE 9 +.Os +.Sh NAME +.Nm VOP_ADVISE +.Nd apply advice about use of file data +.Sh SYNOPSIS +.In sys/param.h +.In sys/vnode.h +.Ft int +.Fn VOP_ADVISE "struct vnode *vp" "off_t start" "off_t end" "int advice" +.Sh DESCRIPTION +This call applies advice for a range of a file's data. +It is used to implement the +.Xr posix_fadvise +system call. +.Pp +Its arguments are: +.Bl -tag -width offset +.It Fa vp +The vnode of the file. +.It Fa start +The start of the range of file data. +.It Fa end +The end of the range of file data. +.It Fa advice +The type of operation to apply to the file data. +Possible values are: +.Bl -tag -width POSIX_FADV_WILLNEED +.It Dv POSIX_FADV_WILLNEED +Initiate an asynchronous read of the file data if it is not already resident. +.It Dv POSIX_FADV_DONTNEED +Decrease the in-memory priority of clean file data or discard clean file data. +.El +.El +.Pp +If the +.Fa start +and +.Fa end +offsets are both zero, +then the operation should be applied to the entire file. +Note that this call is advisory only and may perform the requested +operation on a subset of the requested range +.Pq including not performing it at all +and still return success. +.Sh LOCKS +The file should be unlocked on entry. +.Sh RETURN VALUES +Zero is returned if the call is successful, otherwise an appropriate +error code is returned. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EINVAL +An invalid value was given for +.Fa advice . +.El +.Sh SEE ALSO +.Xr vnode 9 diff --git a/share/man/man9/VOP_ALLOCATE.9 b/share/man/man9/VOP_ALLOCATE.9 new file mode 100644 index 00000000000..314410d3e68 --- /dev/null +++ b/share/man/man9/VOP_ALLOCATE.9 @@ -0,0 +1,84 @@ +.\" -*- nroff -*- +.\" +.\" Copyright (c) 2013 Advanced Computing Technologies LLC +.\" Written by: John H. Baldwin +.\" 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$ +.\" +.Dd October 3, 2013 +.Dt VOP_ALLOCATE 9 +.Os +.Sh NAME +.Nm VOP_ALLOCATE +.Nd allocate storage for a file +.Sh SYNOPSIS +.In sys/param.h +.In sys/vnode.h +.Ft int +.Fn VOP_ALLOCATE "struct vnode *vp" "off_t *offset" "off_t *len" +.Sh DESCRIPTION +This call allocates storage for a range of offsets in a file. +It is used to implement the +.Xr posix_fallocate +system call. +.Pp +Its arguments are: +.Bl -tag -width offset +.It Fa vp +The vnode of the file. +.It Fa offset +The start of the range to allocate storage for in the file. +.It Fa len +The length of the range to allocate storage for in the file. +.El +.Pp +The +.Fa offset +and +.Fa len +arguments are updated to reflect the portion of the range that +still needs to be allocated on return. +A partial allocation is considered a successful operation. +The file's contents are not changed. +.Sh LOCKS +The file should be exclusively locked on entry and will still be locked on exit. +.Sh RETURN VALUES +Zero is returned if the call is successful, otherwise an appropriate +error code is returned. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EFBIG +An attempt was made to write a file that exceeds the process's file size +limit or the maximum file size. +.It Bq Er ENOSPC +The file system is full. +.It Bq Er EPERM +An append-only flag is set on the file, but the caller is attempting to +write before the current end of file. +.El +.Sh SEE ALSO +.Xr vnode 9 , +.Xr VOP_READ 9 , +.Xr VOP_WRITE 9 diff --git a/share/man/man9/vnode.9 b/share/man/man9/vnode.9 index eba208f0638..652d9728ac5 100644 --- a/share/man/man9/vnode.9 +++ b/share/man/man9/vnode.9 @@ -163,7 +163,9 @@ intertwining of VM Objects and Vnodes. .Xr malloc 9 , .Xr VOP_ACCESS 9 , .Xr VOP_ACLCHECK 9 , +.Xr VOP_ADVISE 9 , .Xr VOP_ADVLOCK 9 , +.Xr VOP_ALLOCATE 9 , .Xr VOP_ATTRIB 9 , .Xr VOP_BWRITE 9 , .Xr VOP_CREATE 9 , From 50fbc8e7e8cd1be3607504c404ed6630ab03dd80 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Mon, 7 Oct 2013 20:48:24 +0000 Subject: [PATCH 21/26] Make isci(4) loadable. Reviewed by: jimharris Sponsored by: The FreeBSD Foundation MFC after: 1 week Approved by: re (gjb) --- sys/dev/isci/isci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/dev/isci/isci.c b/sys/dev/isci/isci.c index cd20ba1df60..2f0727d088c 100644 --- a/sys/dev/isci/isci.c +++ b/sys/dev/isci/isci.c @@ -84,6 +84,7 @@ static driver_t isci_pci_driver = { }; DRIVER_MODULE(isci, pci, isci_pci_driver, isci_devclass, 0, 0); +MODULE_DEPEND(isci, cam, 1, 1, 1); static struct _pcsid { From 8be2d25e2c8866b93e5ae02e8ca5128e960563ca Mon Sep 17 00:00:00 2001 From: Xin LI Date: Mon, 7 Oct 2013 21:39:42 +0000 Subject: [PATCH 22/26] Reduce priority of host key exists message in sshd startup script to info. Approved by: re (gjb) --- etc/rc.d/sshd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/rc.d/sshd b/etc/rc.d/sshd index 01677894b7e..5ad1b100aff 100755 --- a/etc/rc.d/sshd +++ b/etc/rc.d/sshd @@ -53,7 +53,7 @@ sshd_keygen_alg() fi if [ -f "${keyfile}" ] ; then - echo "$ALG host key exists." + info "$ALG host key exists." else echo "Generating $ALG host key." /usr/bin/ssh-keygen -q -t $alg -f "$keyfile" -N "" From 44f01c419d1e84684fa53b3814459419ded71a6b Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Mon, 7 Oct 2013 22:22:57 +0000 Subject: [PATCH 23/26] don't assert on bad args, instead return an error.. Since so many programs don't check return value, always NUL terminate the buf... fix rounding when using base 1024 (the bug that started it all)... add a set of test cases so we can make sure that things don't break in the future... Thanks to Clifton Royston for testing and the test program... Approved by: re (hrs, glebius) MFC after: 1 week --- lib/libutil/humanize_number.3 | 17 +- lib/libutil/humanize_number.c | 74 ++- tools/regression/lib/libutil/Makefile | 3 +- .../lib/libutil/test-humanize_number.c | 592 ++++++++++++++++++ .../lib/libutil/test-humanize_number.t | 10 + 5 files changed, 658 insertions(+), 38 deletions(-) create mode 100644 tools/regression/lib/libutil/test-humanize_number.c create mode 100755 tools/regression/lib/libutil/test-humanize_number.t diff --git a/lib/libutil/humanize_number.3 b/lib/libutil/humanize_number.3 index 32df6f83853..3a883caf2e9 100644 --- a/lib/libutil/humanize_number.3 +++ b/lib/libutil/humanize_number.3 @@ -28,7 +28,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd Apr 12, 2011 +.Dd October 7, 2013 .Dt HUMANIZE_NUMBER 3 .Os .Sh NAME @@ -140,7 +140,7 @@ The following flags may be passed in .Fa flags : .Bl -tag -width ".Dv HN_DIVISOR_1000" -offset indent .It Dv HN_DECIMAL -If the final result is less than 10, display it using one digit. +If the final result is less than 10, display it using one decimal place. .It Dv HN_NOSPACE Do not put a space between .Fa number @@ -160,13 +160,18 @@ This flag has no effect when is also specified. .El .Sh RETURN VALUES -The -.Fn humanize_number -function returns the number of characters stored in +Upon success, the +.Nm +function returns the number of characters that would have been stored in .Fa buf (excluding the terminating .Dv NUL ) -upon success, or \-1 upon failure. +if +.Fa buf +was large enough, or \-1 upon failure. +Even upon failure, the contents of +.Fa buf +may be modified. If .Dv HN_GETSCALE is specified, the prefix index number will be returned instead. diff --git a/lib/libutil/humanize_number.c b/lib/libutil/humanize_number.c index 1cad1cf7a21..b773422475b 100644 --- a/lib/libutil/humanize_number.c +++ b/lib/libutil/humanize_number.c @@ -2,6 +2,7 @@ /* * Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc. + * Copyright 2013 John-Mark Gurney * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -50,15 +51,26 @@ humanize_number(char *buf, size_t len, int64_t quotient, { const char *prefixes, *sep; int i, r, remainder, s1, s2, sign; + int divisordeccut; int64_t divisor, max; size_t baselen; - assert(buf != NULL); - assert(suffix != NULL); - assert(scale >= 0); - assert(scale < maxscale || (((scale & (HN_AUTOSCALE | HN_GETSCALE)) != 0))); - assert(!((flags & HN_DIVISOR_1000) && (flags & HN_IEC_PREFIXES))); + /* Since so many callers don't check -1, NUL terminate the buffer */ + if (len > 0) + buf[0] = '\0'; + /* validate args */ + if (buf == NULL || suffix == NULL) + return (-1); + if (scale < 0) + return (-1); + else if (scale >= maxscale && + ((scale & ~(HN_AUTOSCALE|HN_GETSCALE)) != 0)) + return (-1); + if ((flags & HN_DIVISOR_1000) && (flags & HN_IEC_PREFIXES)) + return (-1); + + /* setup parameters */ remainder = 0; if (flags & HN_IEC_PREFIXES) { @@ -73,34 +85,32 @@ humanize_number(char *buf, size_t len, int64_t quotient, * an assertion earlier). */ divisor = 1024; + divisordeccut = 973; /* ceil(.95 * 1024) */ if (flags & HN_B) prefixes = "B\0\0Ki\0Mi\0Gi\0Ti\0Pi\0Ei"; else prefixes = "\0\0\0Ki\0Mi\0Gi\0Ti\0Pi\0Ei"; } else { baselen = 1; - if (flags & HN_DIVISOR_1000) + if (flags & HN_DIVISOR_1000) { divisor = 1000; - else + divisordeccut = 950; + if (flags & HN_B) + prefixes = "B\0\0k\0\0M\0\0G\0\0T\0\0P\0\0E"; + else + prefixes = "\0\0\0k\0\0M\0\0G\0\0T\0\0P\0\0E"; + } else { divisor = 1024; - - if (flags & HN_B) - prefixes = "B\0\0k\0\0M\0\0G\0\0T\0\0P\0\0E"; - else - prefixes = "\0\0\0k\0\0M\0\0G\0\0T\0\0P\0\0E"; + divisordeccut = 973; /* ceil(.95 * 1024) */ + if (flags & HN_B) + prefixes = "B\0\0K\0\0M\0\0G\0\0T\0\0P\0\0E"; + else + prefixes = "\0\0\0K\0\0M\0\0G\0\0T\0\0P\0\0E"; + } } #define SCALE2PREFIX(scale) (&prefixes[(scale) * 3]) - if (scale < 0 || (scale >= maxscale && - (scale & (HN_AUTOSCALE | HN_GETSCALE)) == 0)) - return (-1); - - if (buf == NULL || suffix == NULL) - return (-1); - - if (len > 0) - buf[0] = '\0'; if (quotient < 0) { sign = -1; quotient = -quotient; @@ -132,8 +142,8 @@ humanize_number(char *buf, size_t len, int64_t quotient, * divide once more. */ for (i = 0; - (quotient >= max || (quotient == max - 1 && remainder >= 950)) && - i < maxscale; i++) { + (quotient >= max || (quotient == max - 1 && + remainder >= divisordeccut)) && i < maxscale; i++) { remainder = quotient % divisor; quotient /= divisor; } @@ -148,20 +158,22 @@ humanize_number(char *buf, size_t len, int64_t quotient, } /* If a value <= 9.9 after rounding and ... */ - if (quotient <= 9 && remainder < 950 && i > 0 && flags & HN_DECIMAL) { - /* baselen + \0 + .N */ - if (len < baselen + 1 + 2) - return (-1); - s1 = (int)quotient + ((remainder + 50) / 1000); - s2 = ((remainder + 50) / 100) % 10; + /* + * XXX - should we make sure there is enough space for the decimal + * place and if not, don't do HN_DECIMAL? + */ + if (((quotient == 9 && remainder < divisordeccut) || quotient < 9) && + i > 0 && flags & HN_DECIMAL) { + s1 = (int)quotient + ((remainder * 10 + divisor / 2) / + divisor / 10); + s2 = ((remainder * 10 + divisor / 2) / divisor) % 10; r = snprintf(buf, len, "%d%s%d%s%s%s", sign * s1, localeconv()->decimal_point, s2, sep, SCALE2PREFIX(i), suffix); } else r = snprintf(buf, len, "%" PRId64 "%s%s%s", - sign * (quotient + (remainder + 50) / 1000), + sign * (quotient + (remainder + divisor / 2) / divisor), sep, SCALE2PREFIX(i), suffix); return (r); } - diff --git a/tools/regression/lib/libutil/Makefile b/tools/regression/lib/libutil/Makefile index 6fc97aaa425..229b4d264eb 100644 --- a/tools/regression/lib/libutil/Makefile +++ b/tools/regression/lib/libutil/Makefile @@ -1,6 +1,7 @@ # $FreeBSD$ -TESTS= test-trimdomain test-trimdomain-nodomain test-flopen test-grp test-pidfile +TESTS= test-trimdomain test-trimdomain-nodomain test-flopen test-grp \ + test-pidfile test-humanize_number CFLAGS+= -g -Wall -Wextra -Werror -lutil .PHONY: tests diff --git a/tools/regression/lib/libutil/test-humanize_number.c b/tools/regression/lib/libutil/test-humanize_number.c new file mode 100644 index 00000000000..24f197dac1e --- /dev/null +++ b/tools/regression/lib/libutil/test-humanize_number.c @@ -0,0 +1,592 @@ +/*- + * Copyright 2012 Clifton Royston + * Copyright 2013 John-Mark Gurney + * 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$ + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern char * optarg; + +#define MAX_STR_FLAGS_RESULT 80 +#define MAX_INT_STR_DIGITS 12 + +static const int64_t halfExabyte = (int64_t)500*1000*1000*1000*1000*1000L; + +static struct { + int retval; + const char *res; + int64_t num; + int flags; + int scale; +} test_args[] = { + /* tests 0-13 test 1000 suffixes */ + { 2, "0 ", (int64_t)0L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "1 k", (int64_t)500L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "1 M", (int64_t)500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "1 G", (int64_t)500*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "1 T", (int64_t)500*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "1 P", (int64_t)500*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "1 E", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 2, "1 ", (int64_t)1L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "2 k", (int64_t)1500L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "2 M", (int64_t)1500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "2 G", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "2 T", (int64_t)1500*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "2 P", (int64_t)1500*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "2 E", (int64_t)1500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + + /* tests 14-27 test 1024 suffixes */ + { 2, "0 ", (int64_t)0L, 0, HN_AUTOSCALE }, + { 3, "1 K", (int64_t)512L, 0, HN_AUTOSCALE }, + { 3, "1 M", (int64_t)512*1024L, 0, HN_AUTOSCALE }, + { 3, "1 G", (int64_t)512*1024*1024L, 0, HN_AUTOSCALE }, + { 3, "1 T", (int64_t)512*1024*1024*1024L, 0, HN_AUTOSCALE }, + { 3, "1 P", (int64_t)512*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, + { 3, "1 E", (int64_t)512*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, + { 2, "1 ", (int64_t)1L, 0, HN_AUTOSCALE }, + { 3, "2 K", (int64_t)1536L, 0, HN_AUTOSCALE }, + { 3, "2 M", (int64_t)1536*1024L, 0, HN_AUTOSCALE }, + { 3, "2 G", (int64_t)1536*1024*1024L, 0, HN_AUTOSCALE }, + { 3, "2 T", (int64_t)1536*1024*1024*1024L, 0, HN_AUTOSCALE }, + { 3, "2 P", (int64_t)1536*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, + { 3, "2 E", (int64_t)1536*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, + + /* tests 28-37 test rounding */ + { 3, "0 M", (int64_t)500*1000L-1, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "1 M", (int64_t)500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "1 M", (int64_t)1000*1000L + 500*1000L-1, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "2 M", (int64_t)1000*1000L + 500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "0 K", (int64_t)512L-1, 0, HN_AUTOSCALE }, + { 3, "1 K", (int64_t)512L, 0, HN_AUTOSCALE }, + { 3, "0 M", (int64_t)512*1024L-1, 0, HN_AUTOSCALE }, + { 3, "1 M", (int64_t)512*1024L, 0, HN_AUTOSCALE }, + { 3, "1 M", (int64_t)1024*1024L + 512*1024L-1, 0, HN_AUTOSCALE }, + { 3, "2 M", (int64_t)1024*1024L + 512*1024L, 0, HN_AUTOSCALE }, + + /* tests 38-61 test specific scale factors with 1000 divisor */ + { 3, "0 k", (int64_t)0L, HN_DIVISOR_1000, 1 }, + { 3, "1 k", (int64_t)500L, HN_DIVISOR_1000, 1 }, + { 3, "0 M", (int64_t)500L, HN_DIVISOR_1000, 2 }, + { 3, "1 M", (int64_t)500*1000L, HN_DIVISOR_1000, 2 }, + { 3, "0 G", (int64_t)500*1000L, HN_DIVISOR_1000, 3 }, + { 3, "1 G", (int64_t)500*1000*1000L, HN_DIVISOR_1000, 3 }, + { 3, "0 T", (int64_t)500*1000*1000L, HN_DIVISOR_1000, 4 }, + { 3, "1 T", (int64_t)500*1000*1000*1000L, HN_DIVISOR_1000, 4 }, + { 3, "0 P", (int64_t)500*1000*1000*1000L, HN_DIVISOR_1000, 5 }, + { 3, "1 P", (int64_t)500*1000*1000*1000*1000L, HN_DIVISOR_1000, 5 }, + { 3, "0 E", (int64_t)500*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, + { 3, "1 E", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, + { 3, "0 k", (int64_t)1L, HN_DIVISOR_1000, 1 }, + { 3, "2 k", (int64_t)1500L, HN_DIVISOR_1000, 1 }, + { 3, "0 M", (int64_t)1500L, HN_DIVISOR_1000, 2 }, + { 3, "2 M", (int64_t)1500*1000L, HN_DIVISOR_1000, 2 }, + { 3, "0 G", (int64_t)1500*1000L, HN_DIVISOR_1000, 3 }, + { 3, "2 G", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, 3 }, + { 3, "0 T", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, 4 }, + { 3, "2 T", (int64_t)1500*1000*1000*1000L, HN_DIVISOR_1000, 4 }, + { 3, "0 P", (int64_t)1500*1000*1000*1000L, HN_DIVISOR_1000, 5 }, + { 3, "2 P", (int64_t)1500*1000*1000*1000*1000L, HN_DIVISOR_1000, 5 }, + { 3, "0 E", (int64_t)1500*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, + { 3, "2 E", (int64_t)1500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, + + /* tests 62-85 test specific scale factors with 1024 divisor */ + { 3, "0 K", (int64_t)0L, 0, 1 }, + { 3, "1 K", (int64_t)512L, 0, 1 }, + { 3, "0 M", (int64_t)512L, 0, 2 }, + { 3, "1 M", (int64_t)512*1024L, 0, 2 }, + { 3, "0 G", (int64_t)512*1024L, 0, 3 }, + { 3, "1 G", (int64_t)512*1024*1024L, 0, 3 }, + { 3, "0 T", (int64_t)512*1024*1024L, 0, 4 }, + { 3, "1 T", (int64_t)512*1024*1024*1024L, 0, 4 }, + { 3, "0 P", (int64_t)512*1024*1024*1024L, 0, 5 }, + { 3, "1 P", (int64_t)512*1024*1024*1024*1024L, 0, 5 }, + { 3, "0 E", (int64_t)512*1024*1024*1024*1024L, 0, 6 }, + { 3, "1 E", (int64_t)512*1024*1024*1024*1024*1024L, 0, 6 }, + { 3, "0 K", (int64_t)1L, 0, 1 }, + { 3, "2 K", (int64_t)1536L, 0, 1 }, + { 3, "0 M", (int64_t)1536L, 0, 2 }, + { 3, "2 M", (int64_t)1536*1024L, 0, 2 }, + { 3, "0 G", (int64_t)1536*1024L, 0, 3 }, + { 3, "2 G", (int64_t)1536*1024*1024L, 0, 3 }, + { 3, "0 T", (int64_t)1536*1024*1024L, 0, 4 }, + { 3, "2 T", (int64_t)1536*1024*1024*1024L, 0, 4 }, + { 3, "0 P", (int64_t)1536*1024*1024*1024L, 0, 5 }, + { 3, "2 P", (int64_t)1536*1024*1024*1024*1024L, 0, 5 }, + { 3, "0 E", (int64_t)1536*1024*1024*1024*1024L, 0, 6 }, + { 3, "2 E", (int64_t)1536*1024*1024*1024*1024*1024L, 0, 6 }, + + /* tests 86-99 test invalid specific scale values of < 0 or >= 7 with + and without HN_DIVISOR_1000 set */ + /* all should return errors with new code; with old, the latter 3 + are instead processed as if having AUTOSCALE and/or GETSCALE set */ + { -1, "", (int64_t)1L, 0, 7 }, + { -1, "", (int64_t)1L, HN_DIVISOR_1000, 7 }, + { -1, "", (int64_t)1L, 0, 1000 }, + { -1, "", (int64_t)1L, HN_DIVISOR_1000, 1000 }, + { -1, "", (int64_t)0L, 0, 1000*1000 }, + { -1, "", (int64_t)0L, HN_DIVISOR_1000, 1000*1000 }, + { -1, "", (int64_t)0L, 0, INT_MAX }, + { -1, "", (int64_t)0L, HN_DIVISOR_1000, INT_MAX }, + + /* Negative scale values are not handled well + by the existing library routine - should report as error */ + /* all should return errors with new code, fail assertion with old */ + + { -1, "", (int64_t)1L, 0, -1 }, + { -1, "", (int64_t)1L, HN_DIVISOR_1000, -1 }, + { -1, "", (int64_t)1L, 0, -1000 }, + { -1, "", (int64_t)1L, HN_DIVISOR_1000, -1000 }, + + /* __INT_MIN doesn't print properly, skipped. */ + + { -1, "", (int64_t)1L, 0, -__INT_MAX }, + { -1, "", (int64_t)1L, HN_DIVISOR_1000, -__INT_MAX }, + + + /* tests for scale == 0, without autoscale */ + /* tests 100-114 test scale 0 with 1000 divisor - print first N digits */ + { 2, "0 ", (int64_t)0L, HN_DIVISOR_1000, 0 }, + { 2, "1 ", (int64_t)1L, HN_DIVISOR_1000, 0 }, + { 3, "10 ", (int64_t)10L, HN_DIVISOR_1000, 0 }, + { 3, "0 M", (int64_t)150L, HN_DIVISOR_1000, HN_NOSPACE }, + { 3, "0 M", (int64_t)500L, HN_DIVISOR_1000, HN_NOSPACE }, + { 3, "0 M", (int64_t)999L, HN_DIVISOR_1000, HN_NOSPACE }, + { 4, "150", (int64_t)150L, HN_DIVISOR_1000, 0 }, + { 4, "500", (int64_t)500L, HN_DIVISOR_1000, 0 }, + { 4, "999", (int64_t)999L, HN_DIVISOR_1000, 0 }, + { 5, "100", (int64_t)1000L, HN_DIVISOR_1000, 0 }, + { 5, "150", (int64_t)1500L, HN_DIVISOR_1000, 0 }, + { 7, "500", (int64_t)500*1000L, HN_DIVISOR_1000, 0 }, + { 8, "150", (int64_t)1500*1000L, HN_DIVISOR_1000, 0 }, + { 10, "500", (int64_t)500*1000*1000L, HN_DIVISOR_1000, 0 }, + { 11, "150", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, 0 }, + + /* tests 115-126 test scale 0 with 1024 divisor - print first N digits */ + { 2, "0 ", (int64_t)0L, 0, 0 }, + { 2, "1 ", (int64_t)1L, 0, 0 }, + { 3, "10 ", (int64_t)10L, 0, 0 }, + { 4, "150", (int64_t)150L, 0, 0 }, + { 4, "500", (int64_t)500L, 0, 0 }, + { 4, "999", (int64_t)999L, 0, 0 }, + { 5, "100", (int64_t)1000L, 0, 0 }, + { 5, "150", (int64_t)1500L, 0, 0 }, + { 7, "500", (int64_t)500*1000L, 0, 0 }, + { 8, "150", (int64_t)1500*1000L, 0, 0 }, + { 10, "500", (int64_t)500*1000*1000L, 0, 0 }, + { 11, "150", (int64_t)1500*1000*1000L, 0, 0 }, + + /* Test boundary cases for very large positive/negative number formatting */ + /* Explicit scale, divisor 1024 */ + + /* XXX = requires length 5 (buflen 6) for some cases*/ + /* KLUDGE - test loop below will bump length 5 up to 5 */ + { 3, "8 E", INT64_MAX, 0, 6 }, + { 4, "-8 E", -INT64_MAX, 0, 6 }, + { 3, "0 E", (int64_t)92*1024*1024*1024*1024*1024L, 0, 6 }, + { 3, "0 E", -(int64_t)92*1024*1024*1024*1024*1024L, 0, 6 }, + { 3, "0 E", (int64_t)82*1024*1024*1024*1024*1024L, 0, 6 }, + { 3, "0 E", -(int64_t)82*1024*1024*1024*1024*1024L, 0, 6 }, + { 3, "0 E", (int64_t)81*1024*1024*1024*1024*1024L, 0, 6 }, + { 3, "0 E", -(int64_t)81*1024*1024*1024*1024*1024L, 0, 6 }, + { 4, "92 P", (int64_t)92*1024*1024*1024*1024*1024L, 0, 5 }, + { 5, "-92 P", -(int64_t)92*1024*1024*1024*1024*1024L, 0, 5 }, + { 4, "82 P", (int64_t)82*1024*1024*1024*1024*1024L, 0, 5 }, + { 5, "-82 P", -(int64_t)82*1024*1024*1024*1024*1024L, 0, 5 }, + { 4, "81 P", (int64_t)81*1024*1024*1024*1024*1024L, 0, 5 }, + { 5, "-81 P", -(int64_t)81*1024*1024*1024*1024*1024L, 0, 5 }, + + /* Explicit scale, divisor 1000 */ + { 3, "9 E", INT64_MAX, HN_DIVISOR_1000, 6 }, + { 4, "-9 E", -INT64_MAX, HN_DIVISOR_1000, 6 }, + { 3, "0 E", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6 }, + { 3, "0 E", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6 }, + { 3, "0 E", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6 }, + { 3, "0 E", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6 }, + { 4, "92 P", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5 }, + { 5, "-92 P", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5 }, + { 4, "91 P", (int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5 }, + { 5, "-91 P", -(int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5 }, + + /* Autoscale, divisor 1024 */ + { 3, "8 E", INT64_MAX, 0, HN_AUTOSCALE }, + { 4, "-8 E", -INT64_MAX, 0, HN_AUTOSCALE }, + { 4, "92 P", (int64_t)92*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, + { 5, "-92 P", -(int64_t)92*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, + { 4, "82 P", (int64_t)82*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, + { 5, "-82 P", -(int64_t)82*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, + { 4, "81 P", (int64_t)81*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, + { 5, "-81 P", -(int64_t)81*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, + /* Autoscale, divisor 1000 */ + { 3, "9 E", INT64_MAX, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 4, "-9 E", -INT64_MAX, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 4, "92 P", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "-92 P", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 4, "91 P", (int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "-91 P", -(int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE }, + + /* 0 scale, divisor 1024 */ + { 12, "skdj", INT64_MAX, 0, 0 }, + { 21, "-9223", -INT64_MAX, 0, 0 }, + { 19, "10358", (int64_t)92*1024*1024*1024*1024*1024L, 0, 0 }, + { 20, "-1035", -(int64_t)92*1024*1024*1024*1024*1024L, 0, 0 }, + { 18, "92323", (int64_t)82*1024*1024*1024*1024*1024L, 0, 0 }, + { 19, "-9232", -(int64_t)82*1024*1024*1024*1024*1024L, 0, 0 }, + { 18, "91197", (int64_t)81*1024*1024*1024*1024*1024L, 0, 0 }, + { 19, "-9119", -(int64_t)81*1024*1024*1024*1024*1024L, 0, 0 }, + + /* 0 scale, divisor 1000 */ + /* XXX - why does this fail? */ + { -1, "", INT64_MAX, HN_DIVISOR_1000, 0 }, + { 21, "-9223", -INT64_MAX, HN_DIVISOR_1000, 0 }, + { 19, "10358", (int64_t)92*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, + { 20, "-1035", -(int64_t)92*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, + { 18, "92323", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, + { 19, "-9232", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, + /* Expected to pass */ + { 18, "91197", (int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, + { 19, "-9119", -(int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, + + + + /* Need to implement tests for GETSCALE */ +/* { ?, "", (int64_t)0L, HN_DIVISOR_1000, HN_GETSCALE }, + ... +*/ + /* Tests for HN_DECIMAL */ + /* Positive, Autoscale */ + { 5, "500 k", (int64_t)500*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "994 k", (int64_t)994*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "995 k", (int64_t)995*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "999 k", (int64_t)999*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "1.0 M", (int64_t)1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "1.5 M", (int64_t)1500*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "1.9 M", (int64_t)1949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "2.0 M", (int64_t)1950*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "9.9 M", (int64_t)9949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 4, "10 M", (int64_t)9950*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "500 M", (int64_t)500*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "994 M", (int64_t)994*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "995 M", (int64_t)995*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "999 M", (int64_t)999*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + + { 5, "500 K", (int64_t)500*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "994 K", (int64_t)994*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "995 K", (int64_t)995*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "999 K", (int64_t)999*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "1.0 M", (int64_t)1000*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "1.0 M", (int64_t)1018*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "1.0 M", (int64_t)1019*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "1.5 M", (int64_t)1536*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "1.9 M", (int64_t)1996*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "2.0 M", (int64_t)1997*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "2.0 M", (int64_t)2047*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "2.0 M", (int64_t)2048*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "2.0 M", (int64_t)2099*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "2.1 M", (int64_t)2100*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "9.9 M", (int64_t)10188*1024L, HN_DECIMAL, HN_AUTOSCALE }, + /* XXX - shouldn't the following two be "10. M"? */ + { 4, "10 M", (int64_t)10189*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 4, "10 M", (int64_t)10240*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "500 M", (int64_t)500*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "994 M", (int64_t)994*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "995 M", (int64_t)995*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "999 M", (int64_t)999*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "1.0 G", (int64_t)1000*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "1.0 G", (int64_t)1023*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, + + /* Negative, Autoscale - should pass */ + { 6, "-1.5 ", -(int64_t)1500*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 6, "-1.9 ", -(int64_t)1949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 6, "-9.9 ", -(int64_t)9949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + + { 6, "-1.5 ", -(int64_t)1536*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 6, "-1.9 ", -(int64_t)1949*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 6, "-9.7 ", -(int64_t)9949*1024L, HN_DECIMAL, HN_AUTOSCALE }, + + /* Positive/negative, at maximum scale */ + { 5, "500 P", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "1.9 E", (int64_t)1949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "8.9 E", (int64_t)8949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "9.2 E", INT64_MAX, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + /* Negatives work with latest rev only: */ + { 6, "-9.2 ", -INT64_MAX, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 6, "-8.9 ", -(int64_t)8949*1000*1000*1000*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + + { 5, "8.0 E", INT64_MAX, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "7.9 E", INT64_MAX-(int64_t)100*1024*1024*1024*1024*1024LL, HN_DECIMAL, HN_AUTOSCALE }, + { 6, "-8.0 ", -INT64_MAX, HN_DECIMAL, HN_AUTOSCALE }, + { 6, "-7.9 ", -INT64_MAX+(int64_t)100*1024*1024*1024*1024*1024LL, HN_DECIMAL, HN_AUTOSCALE }, + + /* Positive, Fixed scales */ + { 5, "500 k", (int64_t)500*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1 }, + { 5, "0.5 M", (int64_t)500*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, + { 5, "949 k", (int64_t)949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1 }, + { 5, "0.9 M", (int64_t)949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, + { 5, "950 k", (int64_t)950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1 }, + { 5, "1.0 M", (int64_t)950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, + { 5, "999 k", (int64_t)999*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1 }, + { 5, "1.0 M", (int64_t)999*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, + { 5, "1.5 M", (int64_t)1500*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, + { 5, "1.9 M", (int64_t)1949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, + { 5, "2.0 M", (int64_t)1950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, + { 5, "9.9 M", (int64_t)9949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, + { 4, "10 M", (int64_t)9950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, + { 5, "500 M", (int64_t)500*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, + { 5, "0.5 G", (int64_t)500*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 3 }, + { 5, "999 M", (int64_t)999*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, + { 5, "1.0 G", (int64_t)999*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 3 }, + /* Positive/negative, at maximum scale */ + { 5, "500 P", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 5 }, + { 5, "1.0 E", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, + { 5, "1.9 E", (int64_t)1949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, + { 5, "8.9 E", (int64_t)8949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, + { 5, "9.2 E", INT64_MAX, HN_DECIMAL|HN_DIVISOR_1000, 6 }, + + /* HN_DECIMAL + binary + fixed scale cases not completed */ + { 5, "512 K", (int64_t)512*1024L, HN_DECIMAL, 1 }, + { 5, "0.5 M", (int64_t)512*1024L, HN_DECIMAL, 2 }, + + /* Negative, Fixed scales */ + /* Not yet added, but should work with latest rev */ + +}; + + +/* Command line options usage */ +static void +usage(char * progname) { + printf("%s: tests libutil humanize_number function\n", progname); + printf("Usage: %s [-nE] [-l num] [-v]\n\n", progname); + printf("Options:\n"); + printf("\t-l num\tSet max length for result; buflen = num + 1\n"); + printf("\t\t (NOTE: does not change expected result strings.)\n"); + printf("\t-n\tInclude negative scale tests, which cause older libutil\n"); + printf("\t\t version of function to coredump with assertion failure\n"); + printf("\t-E\tInclude numbers > 1/2 Exa[byte] which currently fail\n"); + printf("\t-v\tVerbose - always print summary results\n"); + printf("\t-h, -?\tShow options\n"); +} + +/* Parse command line options */ +static void +read_options(int argc, char * const argv[], size_t *bufLength, + int *includeNegativeScale, int *includeExabytes, int *verbose) { + int ch; + size_t temp; + + while ((ch = getopt(argc, argv, "nEh?vl:")) != -1) { + switch (ch) { + default: + usage(argv[0]); + exit(1); + break; /* UNREACHABLE */ + case 'h' : + case '?' : + usage(argv[0]); + exit(0); + break; /* UNREACHABLE */ + case 'l' : + sscanf(optarg, "%zu", &temp); + *bufLength = temp + 1; + break; + case 'n' : + *includeNegativeScale = 1; + break; + case 'E' : + *includeExabytes = 1; + break; + case 'v' : + *verbose = 1; + break; + } + } +} + +static struct { + int value; + const char *name; + } flags[] = { + { HN_AUTOSCALE, "HN_AUTOSCALE" }, + { HN_GETSCALE, "HN_GETSCALE" }, + { HN_DIVISOR_1000, "HN_DIVISOR_1000"}, + { HN_B, "HN_B"}, + { HN_DECIMAL, "HN_DECIMAL"}, +}; + +static const char *separator = "|"; + +/* Format flags parameter for meaningful display */ +static char * +str_flags(int hn_flags, char *noFlags) { + size_t i; + char * result; + + result = malloc(MAX_STR_FLAGS_RESULT); + result[0] = '\0'; + + for (i = 0; i < sizeof flags / sizeof *flags; i++) { + if (hn_flags & flags[i].value) { + if (*result != 0) + strlcat(result, separator, + MAX_STR_FLAGS_RESULT); + strlcat(result, flags[i].name, MAX_STR_FLAGS_RESULT); + } + } + + if (strlen(result) == 0) + strlcat(result, noFlags, MAX_STR_FLAGS_RESULT); + return result; +} + + +/* Format scale parameter for meaningful display */ +static char * +str_scale(int scale) { + char *result; + + if (scale == HN_AUTOSCALE || scale == HN_GETSCALE) + return str_flags(scale, ""); + + result = malloc(MAX_INT_STR_DIGITS); + result[0] = '\0'; + snprintf(result, MAX_INT_STR_DIGITS, "%d", scale); + return result; +} + +static void +testskipped(size_t i) +{ + + printf("ok %lu # skip - not turned on\n", i); +} + +int +main(int argc, char * const argv[]) +{ + char *buf; + char *flag_str, *scale_str; + size_t i; + size_t errcnt, tested, skipped; + int r; + size_t buflen; + int includeNegScale; + int includeExabyteTests; + int verbose; + + buflen = 4; + includeNegScale = 0; + includeExabyteTests = 0; + verbose = 0; + + read_options(argc, argv, &buflen, &includeNegScale, + &includeExabyteTests, &verbose); + + buf = malloc(buflen); + errcnt = 0; + tested = 0; + skipped = 0; + + if (buflen != 4) + printf("Warning: buffer size %zu != 4, expect some results to differ.\n", buflen); + + printf("1..%lu\n", sizeof test_args / sizeof *test_args); + for (i = 0; i < sizeof test_args / sizeof *test_args; i++) { + /* KLUDGE */ + if (test_args[i].num == INT64_MAX && buflen == 4) { + /* Start final tests which require buffer of 6 */ + free(buf); + buflen = 6; + buf = malloc(buflen); + if (verbose) + printf("Buffer length increased to %zu\n", + buflen); + } + + if (test_args[i].scale < 0 && ! includeNegScale) { + skipped++; + testskipped(i); + continue; + } + if (test_args[i].num >= halfExabyte && ! includeExabyteTests) { + skipped++; + testskipped(i); + continue; + } + + r = humanize_number(buf, buflen, test_args[i].num, "", + test_args[i].scale, test_args[i].flags); + flag_str = str_flags(test_args[i].flags, "[no flags]"); + scale_str = str_scale(test_args[i].scale); + + if (r != test_args[i].retval) { + if (verbose) + printf("wrong return value on index %lu, buflen: %zu, got: %d + \"%s\", expected %d + \"%s\"; num = %" PRId64 ", scale = %s, flags= %s.\n", + i, buflen, r, buf, test_args[i].retval, + test_args[i].res, test_args[i].num, + scale_str, flag_str); + else + printf("not ok %lu # return %d != %d\n", i, r, + test_args[i].retval); + errcnt++; + } else if (strcmp(buf, test_args[i].res) != 0) { + if (verbose) + printf("result mismatch on index %lu, got: \"%s\", expected \"%s\"; num = %" PRId64 ", scale = %s, flags= %s.\n", + i, buf, test_args[i].res, test_args[i].num, + scale_str, flag_str); + else + printf("not ok %lu # buf \"%s\" != \"%s\"\n", i, + buf, test_args[i].res); + errcnt++; + } else { + if (verbose) + printf("successful result on index %lu, returned %d, got: \"%s\"; num = %" PRId64 ", scale = %s, flags= %s.\n", + i, r, buf, test_args[i].num, scale_str, + flag_str); + else + printf("ok %lu\n", i); + } + tested++; + } + + if (verbose) + printf("total errors: %lu/%lu tests, %lu skipped\n", errcnt, + tested, skipped); + + if (errcnt) + return 1; + + return 0; +} diff --git a/tools/regression/lib/libutil/test-humanize_number.t b/tools/regression/lib/libutil/test-humanize_number.t new file mode 100755 index 00000000000..516bc4c2575 --- /dev/null +++ b/tools/regression/lib/libutil/test-humanize_number.t @@ -0,0 +1,10 @@ +#!/bin/sh +# $FreeBSD$ + +cd `dirname $0` + +executable=`basename $0 .t` + +make $executable 2>&1 > /dev/null + +exec ./$executable && echo humanize_numbers ok From 64db8966177a7eb138f7a1ade88441b988326ff9 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 7 Oct 2013 22:30:03 +0000 Subject: [PATCH 24/26] Fix kernel build on amd64 after r256118, since the machine/md_var.h header is not implicitly included there. So include it explicitly. Approved by: re (delphij) Pointy hat to: dim MFC after: 3 days X-MFC-With: r256118 --- sys/dev/cxgbe/t4_sge.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/dev/cxgbe/t4_sge.c b/sys/dev/cxgbe/t4_sge.c index 417843c61ae..cbb37b35c34 100644 --- a/sys/dev/cxgbe/t4_sge.c +++ b/sys/dev/cxgbe/t4_sge.c @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include "common/common.h" #include "common/t4_regs.h" From 6eb151f212180889f9a785175da6e67442b2530e Mon Sep 17 00:00:00 2001 From: Xin LI Date: Tue, 8 Oct 2013 01:38:24 +0000 Subject: [PATCH 25/26] Improve lzjb decompress performance by reorganizing the code to tighten the copy loop. Submitted by: Denis Ahrens MFC after: 2 weeks Approved by: re (gjb) --- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lzjb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lzjb.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lzjb.c index f8d3061bed8..699373ad4d4 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lzjb.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lzjb.c @@ -117,7 +117,9 @@ lzjb_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n) src += 2; if ((cpy = dst - offset) < (uchar_t *)d_start) return (-1); - while (--mlen >= 0 && dst < d_end) + if (mlen > (d_end - dst)) + mlen = d_end - dst; + while (--mlen >= 0) *dst++ = *cpy++; } else { *dst++ = *src++; From e590690fad2b243bb68ee101d6a4857130053e5e Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Tue, 8 Oct 2013 04:16:22 +0000 Subject: [PATCH 26/26] Fix an inverted check for the master user in "camcontrol security -U". PR: bin/182703 Submitted by: Scott Burns Approved by: re (gjb) MFC after: 3 days --- sbin/camcontrol/camcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c index e80c549cf96..68c6d799a8c 100644 --- a/sbin/camcontrol/camcontrol.c +++ b/sbin/camcontrol/camcontrol.c @@ -2748,7 +2748,7 @@ atasecurity(struct cam_device *device, int retry_count, int timeout, if (strcasecmp(optarg, "user") == 0) { pwd.ctrl |= ATA_SECURITY_PASSWORD_USER; pwd.ctrl &= ~ATA_SECURITY_PASSWORD_MASTER; - } else if (strcasecmp(optarg, "master") != 0) { + } else if (strcasecmp(optarg, "master") == 0) { pwd.ctrl |= ATA_SECURITY_PASSWORD_MASTER; pwd.ctrl &= ~ATA_SECURITY_PASSWORD_USER; } else {