Index: head/etc/rc.d/hostid =================================================================== --- head/etc/rc.d/hostid (revision 333448) +++ head/etc/rc.d/hostid (revision 333449) @@ -1,152 +1,151 @@ #!/bin/sh # # Copyright (c) 2007 Pawel Jakub Dawidek # Copyright (c) 2015 Xin LI -# 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 AUTHORS 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 AUTHORS 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$ # # PROVIDE: hostid # REQUIRE: sysctl # KEYWORD: nojail . /etc/rc.subr name="hostid" desc="Generate a unique host ID" start_cmd="hostid_start" stop_cmd=":" reset_cmd="hostid_reset" extra_commands="reset" rcvar="hostid_enable" hostid_set() { uuid=$1 # Generate hostid based on hostuuid - take first four bytes from md5(uuid). id=`echo -n $uuid | /sbin/md5` id="0x${id%????????????????????????}" # Set both kern.hostuuid and kern.hostid. # check_startmsgs && echo "Setting hostuuid: ${uuid}." ${SYSCTL} kern.hostuuid="${uuid}" >/dev/null check_startmsgs && echo "Setting hostid: ${id}." ${SYSCTL} kern.hostid=${id} >/dev/null } valid_hostid() { uuid=$1 x="[0-9a-f]" y=$x$x$x$x # Check against a blacklist before # accepting the UUID. case "${uuid}" in 00000000-0000-0000-0000-000000000000) ;; 00020003-0004-0005-0006-000700080009) ;; 03000200-0400-0500-0006-000700080009) ;; 07090201-0103-0301-0807-060504030201) ;; 11111111-1111-1111-1111-111111111111) ;; 11111111-2222-3333-4444-555555555555) ;; 4c4c4544-0000-2010-8020-80c04f202020) ;; 58585858-5858-5858-5858-585858585858) ;; 890e2d14-cacd-45d1-ae66-bc80e8bfeb0f) ;; 8e275844-178f-44a8-aceb-a7d7e5178c63) ;; dc698397-fa54-4cf2-82c8-b1b5307a6a7f) ;; fefefefe-fefe-fefe-fefe-fefefefefefe) ;; *-ffff-ffff-ffff-ffffffffffff) ;; $y$y-$y-$y-$y-$y$y$y) return 0 ;; esac return 1 } hostid_hardware() { uuid=`kenv -q smbios.system.uuid` if valid_hostid $uuid; then echo "${uuid}" fi } hostid_generate() { # First look for UUID in hardware. uuid=`hostid_hardware` if [ -z "${uuid}" ]; then warn "hostid: unable to figure out a UUID from DMI data, generating a new one" sleep 2 # If not found, fall back to software-generated UUID. uuid=`uuidgen` fi hostid_set $uuid } hostid_reset() { hostid_generate # Store newly generated UUID in ${hostid_file}. echo $uuid > ${hostid_file} if [ $? -ne 0 ]; then warn "could not store hostuuid in ${hostid_file}." fi } hostid_start() { # If ${hostid_file} already exists, we take UUID from there. if [ -r ${hostid_file} ]; then read saved_hostid < ${hostid_file} if valid_hostid ${saved_hostid}; then hostid_set `cat ${hostid_file}` exit 0 fi fi # No hostid file, generate UUID. hostid_generate } load_rc_config $name run_rc_command "$1" Index: head/etc/rc.d/static_arp =================================================================== --- head/etc/rc.d/static_arp (revision 333448) +++ head/etc/rc.d/static_arp (revision 333449) @@ -1,75 +1,74 @@ #!/bin/sh # # Copyright (c) 2009 Xin LI -# 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. # # Configure static ARP table # # $FreeBSD$ # # PROVIDE: static_arp # REQUIRE: netif # KEYWORD: nojailvnet . /etc/rc.subr . /etc/network.subr name="static_arp" desc="Static ARP Configuration" start_cmd="static_arp_start" stop_cmd="static_arp_stop" static_arp_start() { local e arp_args if [ -n "${static_arp_pairs}" ]; then echo -n 'Binding static ARP pair(s):' for e in ${static_arp_pairs}; do echo -n " ${e}" eval arp_args=\$static_arp_${e} arp -S ${arp_args} >/dev/null 2>&1 done echo '.' fi } static_arp_stop() { local e arp_args if [ -n "${static_arp_pairs}" ]; then echo -n 'Unbinding static ARP pair(s):' for e in ${static_arp_pairs}; do echo -n " ${e}" eval arp_args=\$static_arp_${e} arp -d ${arp_args%%[ ]*} > /dev/null 2>&1 done echo '.' fi } load_rc_config $name run_rc_command "$1" Index: head/etc/rc.d/static_ndp =================================================================== --- head/etc/rc.d/static_ndp (revision 333448) +++ head/etc/rc.d/static_ndp (revision 333449) @@ -1,74 +1,73 @@ #!/bin/sh # -# Copyright (c) 2011 Xin Li -# All rights reserved. +# Copyright (c) 2011 Xin LI # # 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. # # Configure static NDP table # # $FreeBSD$ # # PROVIDE: static_ndp # REQUIRE: netif # KEYWORD: nojailvnet . /etc/rc.subr . /etc/network.subr name="static_ndp" start_cmd="static_ndp_start" stop_cmd="static_ndp_stop" static_ndp_start() { local e ndp_args if [ -n "${static_ndp_pairs}" ]; then echo -n 'Binding static NDP pair(s):' for e in ${static_ndp_pairs}; do echo -n " ${e}" eval ndp_args=\$static_ndp_${e} ndp -s ${ndp_args} >/dev/null 2>&1 done echo '.' fi } static_ndp_stop() { local e ndp_args if [ -n "${static_ndp_pairs}" ]; then echo -n 'Unbinding static NDP pair(s):' for e in ${static_ndp_pairs}; do echo -n " ${e}" eval ndp_args=\$static_ndp_${e} ndp -d ${ndp_args%%[ ]*} > /dev/null 2>&1 done echo '.' fi } load_rc_config $name run_rc_command "$1" Index: head/lib/libc/db/mpool/mpool-compat.c =================================================================== --- head/lib/libc/db/mpool/mpool-compat.c (revision 333448) +++ head/lib/libc/db/mpool/mpool-compat.c (revision 333449) @@ -1,45 +1,44 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2009 Xin LI - * 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. * */ #include __FBSDID("$FreeBSD$"); #include #include void *__mpool_new__44bsd(MPOOL *, pgno_t *); void * __mpool_new__44bsd(MPOOL *mp, pgno_t *pgnoaddr) { return (mpool_new(mp, pgnoaddr, MPOOL_PAGE_NEXT)); } __sym_compat(mpool_new, __mpool_new_44bsd, FBSD_1.0); Index: head/lib/libc/gen/libc_dlopen.c =================================================================== --- head/lib/libc/gen/libc_dlopen.c (revision 333448) +++ head/lib/libc/gen/libc_dlopen.c (revision 333449) @@ -1,63 +1,62 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * - * Copyright (c) 2011 Xin Li - * All rights reserved. + * Copyright (c) 2011 Xin LI * * 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 __FBSDID("$FreeBSD$"); #include #include #include #include "libc_private.h" /* * Whether we want to restrict dlopen()s. */ static int __libc_restricted_mode = 0; void * libc_dlopen(const char *path, int mode) { if (__libc_restricted_mode) { _rtld_error("Service unavailable -- libc in restricted mode"); return (NULL); } else return (dlopen(path, mode)); } void __FreeBSD_libc_enter_restricted_mode(void) { __libc_restricted_mode = 1; return; } Index: head/lib/libc/string/strlen.c =================================================================== --- head/lib/libc/string/strlen.c (revision 333448) +++ head/lib/libc/string/strlen.c (revision 333449) @@ -1,132 +1,131 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2009, 2010 Xin LI - * 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include /* * Portable strlen() for 32-bit and 64-bit systems. * * Rationale: it is generally much more efficient to do word length * operations and avoid branches on modern computer systems, as * compared to byte-length operations with a lot of branches. * * The expression: * * ((x - 0x01....01) & ~x & 0x80....80) * * would evaluate to a non-zero value iff any of the bytes in the * original word is zero. * * On multi-issue processors, we can divide the above expression into: * a) (x - 0x01....01) * b) (~x & 0x80....80) * c) a & b * * Where, a) and b) can be partially computed in parallel. * * The algorithm above is found on "Hacker's Delight" by * Henry S. Warren, Jr. */ /* Magic numbers for the algorithm */ #if LONG_BIT == 32 static const unsigned long mask01 = 0x01010101; static const unsigned long mask80 = 0x80808080; #elif LONG_BIT == 64 static const unsigned long mask01 = 0x0101010101010101; static const unsigned long mask80 = 0x8080808080808080; #else #error Unsupported word size #endif #define LONGPTR_MASK (sizeof(long) - 1) /* * Helper macro to return string length if we caught the zero * byte. */ #define testbyte(x) \ do { \ if (p[x] == '\0') \ return (p - str + x); \ } while (0) size_t strlen(const char *str) { const char *p; const unsigned long *lp; long va, vb; /* * Before trying the hard (unaligned byte-by-byte access) way * to figure out whether there is a nul character, try to see * if there is a nul character is within this accessible word * first. * * p and (p & ~LONGPTR_MASK) must be equally accessible since * they always fall in the same memory page, as long as page * boundaries is integral multiple of word size. */ lp = (const unsigned long *)((uintptr_t)str & ~LONGPTR_MASK); va = (*lp - mask01); vb = ((~*lp) & mask80); lp++; if (va & vb) /* Check if we have \0 in the first part */ for (p = str; p < (const char *)lp; p++) if (*p == '\0') return (p - str); /* Scan the rest of the string using word sized operation */ for (; ; lp++) { va = (*lp - mask01); vb = ((~*lp) & mask80); if (va & vb) { p = (const char *)(lp); testbyte(0); testbyte(1); testbyte(2); testbyte(3); #if (LONG_BIT >= 64) testbyte(4); testbyte(5); testbyte(6); testbyte(7); #endif } } /* NOTREACHED */ return (0); } Index: head/lib/libc/sys/rtprio.2 =================================================================== --- head/lib/libc/sys/rtprio.2 (revision 333448) +++ head/lib/libc/sys/rtprio.2 (revision 333449) @@ -1,199 +1,198 @@ .\"- .\" Copyright (c) 1994, Henrik Vestergaard Draboel .\" 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 Henrik Vestergaard Draboel. .\" 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 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. .\"- .\" Copyright (c) 2011 Xin LI -.\" 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 December 27, 2011 .Dt RTPRIO 2 .Os .Sh NAME .Nm rtprio , .Nm rtprio_thread .Nd examine or modify realtime or idle priority .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/types.h .In sys/rtprio.h .Ft int .Fn rtprio "int function" "pid_t pid" "struct rtprio *rtp" .Ft int .Fn rtprio_thread "int function" "lwpid_t lwpid" "struct rtprio *rtp" .Sh DESCRIPTION The .Fn rtprio system call is used to lookup or change the realtime or idle priority of a process, or the calling thread. The .Fn rtprio_thread system call is used to lookup or change the realtime or idle priority of a thread. .Pp The .Fa function argument specifies the operation to be performed. RTP_LOOKUP to lookup the current priority, and RTP_SET to set the priority. .Pp For the .Fn rtprio system call, the .Fa pid argument specifies the process to operate on, 0 for the calling thread. When .Fa pid is non-zero, the system call reports the highest priority in the process, or sets all threads' priority in the process, depending on value of the .Fa function argument. .Pp For the .Fn rtprio_thread system call, the .Fa lwpid specifies the thread to operate on, 0 for the calling thread. .Pp The .Fa *rtp argument is a pointer to a struct rtprio which is used to specify the priority and priority type. This structure has the following form: .Bd -literal struct rtprio { u_short type; u_short prio; }; .Ed .Pp The value of the .Va type field may be RTP_PRIO_REALTIME for realtime priorities, RTP_PRIO_NORMAL for normal priorities, and RTP_PRIO_IDLE for idle priorities. The priority specified by the .Va prio field ranges between 0 and .Dv RTP_PRIO_MAX .Pq usually 31 . 0 is the highest possible priority. .Pp Realtime and idle priority is inherited through fork() and exec(). .Pp A realtime thread can only be preempted by a thread of equal or higher priority, or by an interrupt; idle priority threads will run only when no other real/normal priority thread is runnable. Higher real/idle priority threads preempt lower real/idle priority threads. Threads of equal real/idle priority are run round-robin. .Sh RETURN VALUES .Rv -std rtprio rtprio_thread .Sh ERRORS The .Fn rtprio and .Fn rtprio_thread system calls will fail if: .Bl -tag -width Er .It Bq Er EFAULT The rtp pointer passed to .Fn rtprio or .Fn rtprio_thread was invalid. .It Bq Er EINVAL The specified .Fa prio was out of range. .It Bq Er EPERM The calling thread is not allowed to set the realtime priority. Only root is allowed to change the realtime priority of any thread, and non-root may only change the idle priority of threads the user owns, when the .Xr sysctl 8 variable .Va security.bsd.unprivileged_idprio is set to non-zero. .It Bq Er ESRCH The specified process or thread was not found or visible. .El .Sh SEE ALSO .Xr nice 1 , .Xr ps 1 , .Xr rtprio 1 , .Xr setpriority 2 , .Xr nice 3 , .Xr renice 8 , .Xr p_cansee 9 .Sh AUTHORS .An -nosplit The original author was .An Henrik Vestergaard Draboel Aq Mt hvd@terry.ping.dk . This implementation in .Fx was substantially rewritten by .An David Greenman . The .Fn rtprio_thread system call was implemented by .An David Xu . Index: head/lib/libz/zopen.3 =================================================================== --- head/lib/libz/zopen.3 (revision 333448) +++ head/lib/libz/zopen.3 (revision 333449) @@ -1,96 +1,95 @@ -.\" Copyright (c) 2014 Xin Li -.\" All rights reserved. +.\" Copyright (c) 2014 Xin LI .\" .\" 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 March 5, 2014 .Dt ZOPEN 3 .Os .Sh NAME .Nm zopen .Nd open a gzip compressed stream .Sh LIBRARY .Lb libz .Sh SYNOPSIS .Ft FILE * .Fn zopen "const char *path" "const char *mode" .Sh DESCRIPTION The .Fn zopen opens a gzip file whose name is the string pointed to by .Fa path and associates a stream with it. It is a wrapper around .Xr zlib 3 and standard stream I/O APIs. .Pp The argument .Fa mode have the same meaning as it does in .Xr fopen 3 . .Pp The .Nm function will associate read, write, seek and close functions of .Xr zlib 3 after successfully opened a file with .Xr funopen 3 so that they will be used to read or write the new stream. .Sh RETURN VALUES Upon successful completion .Nm returns a .Tn FILE pointer. Otherwise, .Dv NULL is returned and the global variable .Va errno is set to indicate the error. .Sh ERRORS In addition to the errors documented for .Xr fopen 3 , the .Nm function may also fail for: .Bl -tag -width Er .It Bq Er ENOMEM Insufficient memory is available. .El .Sh COMPATIBILITY This implementation of .Nm function first appeared in .Nx 1.6 and .Fx 4.5 . The .Nm function may not be portable to systems other than .Fx . .Sh SEE ALSO .Xr fopen 3 , .Xr funopen 3 , .Xr zlib 3 Index: head/share/man/man3/pthread_affinity_np.3 =================================================================== --- head/share/man/man3/pthread_affinity_np.3 (revision 333448) +++ head/share/man/man3/pthread_affinity_np.3 (revision 333449) @@ -1,153 +1,152 @@ .\"- .\" Copyright (c) 2010 Xin LI -.\" 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 March 23, 2010 .Dt PTHREAD_AFFINITY_NP 3 .Os .Sh NAME .Nm pthread_getaffinity_np , .Nm pthread_setaffinity_np .Nd manage CPU affinity .Sh LIBRARY .Lb libpthread .Sh SYNOPSIS .In pthread_np.h .Ft int .Fn pthread_getaffinity_np "pthread_t td" "size_t cpusetsize" "cpuset_t *cpusetp" .Ft int .Fn pthread_setaffinity_np "pthread_t td" "size_t cpusetsize" "const cpuset_t *cpusetp" .Sh DESCRIPTION .Fn pthread_getaffinity_np and .Fn pthread_setaffinity_np allow the manipulation of sets of CPUs available to the specified thread. .Pp Masks of type .Ft cpuset_t are composed using the .Dv CPU_SET macros. The kernel tolerates large sets as long as all CPUs specified in the set exist. Sets smaller than the kernel uses generate an error on calls to .Fn pthread_getaffinity_np even if the result set would fit within the user supplied set. Calls to .Fn pthread_setaffinity_np tolerate small sets with no restrictions. .Pp The supplied mask should have a size of .Fa cpusetsize bytes. This size is usually provided by calling .Li sizeof(cpuset_t) which is ultimately determined by the value of .Dv CPU_SETSIZE as defined in .In sys/cpuset.h . .Pp .Fn pthread_getaffinity_np retrieves the mask from the thread specified by .Fa td , and stores it in the space provided by .Fa cpusetp . .Pp .Fn pthread_setaffinity_np attempts to set the mask for the thread specified by .Fa td to the value in .Fa cpusetp . .Sh RETURN VALUES If successful, the .Fn pthread_getaffinity_np and .Fn pthread_setaffinity_np functions will return zero. Otherwise an error number will be returned to indicate the error. .Sh ERRORS The .Fn pthread_getaffinity_np and .Fn pthread_setaffinity_np functions may fail if: .Bl -tag -width Er .It Bq Er EDEADLK The .Fn pthread_setaffinity_np call would leave a thread without a valid CPU to run on because the set does not overlap with the thread's anonymous mask. .It Bq Er EFAULT The .Fa cpusetp pointer passed was invalid. .It Bq Er ESRCH The thread specified by the .Fa td argument could not be found. .It Bq Er ERANGE The .Fa cpusetsize was either preposterously large or smaller than the kernel set size. .It Bq Er EPERM The calling thread did not have the credentials required to complete the operation. .El .Sh SEE ALSO .Xr cpuset 1 , .Xr cpuset 2 , .Xr cpuset_getid 2 , .Xr cpuset_setid 2 , .Xr pthread 3 , .Xr pthread_attr_getaffinity_np 3 , .Xr pthread_attr_setaffinity_np 3 .Sh STANDARDS The .Nm pthread_getaffinity_np and .Nm pthread_setaffinity_np functions are non-standard .Fx extensions and may be not available on other operating systems. .Sh HISTORY The .Nm pthread_getaffinity_np and .Nm pthread_setaffinity_np function first appeared in .Fx 7.2 . .Sh AUTHORS .An -nosplit The .Nm pthread_getaffinity_np and .Nm pthread_setaffinity_np functions were written by .An David Xu Aq Mt davidxu@FreeBSD.org , and this manpage was written by .An Xin LI Aq Mt delphij@FreeBSD.org . Index: head/share/man/man3/pthread_attr_affinity_np.3 =================================================================== --- head/share/man/man3/pthread_attr_affinity_np.3 (revision 333448) +++ head/share/man/man3/pthread_attr_affinity_np.3 (revision 333449) @@ -1,161 +1,160 @@ .\"- .\" Copyright (c) 2010 Xin LI -.\" 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 June 2, 2016 .Dt PTHREAD_ATTR_AFFINITY_NP 3 .Os .Sh NAME .Nm pthread_attr_getaffinity_np , .Nm pthread_attr_setaffinity_np .Nd manage CPU affinity in thread attribute objects .Sh LIBRARY .Lb libpthread .Sh SYNOPSIS .In pthread_np.h .Ft int .Fn pthread_attr_getaffinity_np "const pthread_attr_t *pattr" "size_t cpusetsize" "cpuset_t *cpusetp" .Ft int .Fn pthread_attr_setaffinity_np "pthread_attr_t *pattr" "size_t cpusetsize" "const cpuset_t *cpusetp" .Sh DESCRIPTION The .Fn pthread_attr_getaffinity_np and .Fn pthread_attr_setaffinity_np functions allow the manipulation of sets of CPUs available to the specified thread attribute object. .Pp Masks of type .Ft cpuset_t are composed using the .Dv CPU_SET macros. The kernel tolerates large sets as long as all CPUs specified in the set exist. Sets smaller than the kernel uses generate an error on calls to .Fn pthread_attr_getaffinity_np even if the result set would fit within the user supplied set. Calls to .Fn pthread_attr_setaffinity_np tolerate small sets with no restrictions. .Pp The supplied mask should have a size of .Fa cpusetsize bytes. This size is usually provided by calling .Li sizeof(cpuset_t) which is ultimately determined by the value of .Dv CPU_SETSIZE as defined in .In sys/cpuset.h . .Pp .Fn pthread_attr_getaffinity_np retrieves the mask from the thread attribute object specified by .Fa pattr , and stores it in the space provided by .Fa cpusetp . .Pp .Fn pthread_attr_setaffinity_np sets the mask for the thread attribute object specified by .Fa pattr to the value in .Fa cpusetp . .Sh RETURN VALUES If successful, the .Fn pthread_attr_getaffinity_np and .Fn pthread_attr_setaffinity_np functions will return zero. Otherwise an error number will be returned to indicate the error. .Sh ERRORS The .Fn pthread_attr_getaffinity_np functions will fail if: .Bl -tag -width Er .It Bq Er EINVAL The .Fa pattr or the attribute specified by it is .Dv NULL . .It Bq Er ERANGE The .Fa cpusetsize is too small. .El .Pp The .Fn pthread_attr_setaffinity_np function will fail if: .Bl -tag -width Er .It Bq Er EINVAL The .Fa pattr or the attribute specified by it is .Dv NULL . .It Bq Er EINVAL The .Fa cpusetp specified a CPU that was outside the set supported by the kernel. .It Bq Er ERANGE The .Fa cpusetsize is too small. .It Bq Er ENOMEM Insufficient memory exists to store the cpuset mask. .El .Sh SEE ALSO .Xr cpuset 1 , .Xr cpuset 2 , .Xr cpuset_getid 2 , .Xr cpuset_setid 2 , .Xr pthread_getaffinity_np 3 , .Xr pthread_setaffinity_np 3 .Sh STANDARDS The .Nm pthread_attr_getaffinity_np and .Nm pthread_attr_setaffinity_np functions are non-standard .Fx extensions and may be not available on other operating systems. .Sh HISTORY The .Nm pthread_attr_getaffinity_np and .Nm pthread_attr_setaffinity_np functions first appeared in .Fx 7.2 . .Sh AUTHORS .An -nosplit The .Nm pthread_attr_getaffinity_np and .Nm pthread_attr_setaffinity_np functions were written by .An David Xu Aq Mt davidxu@FreeBSD.org , and this manpage was written by .An Xin LI Aq Mt delphij@FreeBSD.org . Index: head/share/man/man5/tmpfs.5 =================================================================== --- head/share/man/man5/tmpfs.5 (revision 333448) +++ head/share/man/man5/tmpfs.5 (revision 333449) @@ -1,180 +1,179 @@ .\"- .\" Copyright (c) 2007 Xin LI .\" Copyright (c) 2017 The FreeBSD Foundation, Inc. -.\" All rights reserved. .\" .\" Part of this documentation was written by .\" Konstantin Belousov under sponsorship .\" from the FreeBSD Foundation. .\" .\" 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 DOCUMENTATION 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. .\" .\"- .\" Copyright (c) 2005, 2006 The NetBSD Foundation, Inc. .\" 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 September 8, 2017 .Dt TMPFS 5 .Os .Sh NAME .Nm tmpfs .Nd "in-memory file system" .Sh SYNOPSIS To compile this driver into the kernel, place the following line in your kernel configuration file: .Bd -ragged -offset indent .Cd "options TMPFS" .Ed .Pp Alternatively, to load the driver as a module at boot time, place the following line in .Xr loader.conf 5 : .Bd -literal -offset indent tmpfs_load="YES" .Ed .Sh DESCRIPTION The .Nm driver implements an in-memory, or .Tn tmpfs file system. The filesystem stores both file metadata and data in main memory. This allows very fast and low latency accesses to the data. The data is volatile. An umount or system reboot invalidates it. These properties make the filesystem's mounts suitable for fast scratch storage, like .Pa /tmp . .Pp If the system becomes low on memory and swap is configured (see .Xr swapon 8 ), the system can transfer file data to swap space, freeing memory for other needs. Metadata, including the directory content, is never swapped out by the current implementation. Keep this in mind when planning the mount limits, especially when expecting to place many small files on a tmpfs mount. .Pp When .Xr mmap 2 is used on a file from a tmpfs mount, the swap VM object managing the file pages is used to implement mapping and avoid double-copying of the file data. This quirk causes process inspection tools, like .Xr procstat 1 , to report anonymous memory mappings instead of file mappings. .Sh OPTIONS The following options are available when mounting .Nm file systems: .Bl -tag -width "It Cm maxfilesize" .It Cm gid Specifies the group ID of the root inode of the file system. Defaults to the mount point's GID. .It Cm uid Specifies the user ID of the root inode of the file system. Defaults to the mount point's UID. .It Cm mode Specifies the mode (in octal notation) of the root inode of the file system. Defaults to the mount point's mode. .It Cm nonc Do not use namecache to resolve names to files for the created mount. This saves memory, but currently might impair scalability for highly used mounts on large machines. .It Cm inodes Specifies the maximum number of nodes available to the file system. If not specified, the file system chooses a reasonable maximum based on the file system size, which can be limited with the .Cm size option. .It Cm size Specifies the total file system size in bytes, unless suffixed with one of k, m, g, t, or p, which denote byte, kilobyte, megabyte, gigabyte, terabyte and petabyte respectively. If zero (the default) or a value larger than SIZE_MAX - PAGE_SIZE is given, the available amount of memory (including main memory and swap space) will be used. .It Cm maxfilesize Specifies the maximum file size in bytes. Defaults to the maximum possible value. .El .Sh EXAMPLES To mount a .Nm memory file system: .Pp .Dl "mount -t tmpfs tmpfs /tmp" .Sh SEE ALSO .Xr procstat 1 , .Xr mmap 2 , .Xr nmount 2 , .Xr unmount 2 , .Xr fstab 5 , .Xr mdmfs 8 , .Xr mount 8 , .Xr swapinfo 8 , .Xr swapon 8 .Sh HISTORY The .Nm driver first appeared in .Fx 7.0 . .Sh AUTHORS .An -nosplit The .Nm kernel implementation was written by .An Julio M. Merino Vidal Aq Mt jmmv@NetBSD.org as a Google Summer of Code project. .Pp .An Rohit Jalan and others ported it from .Nx to .Fx . .Pp This manual page was written by .An Xin LI Aq Mt delphij@FreeBSD.org . Index: head/sys/libkern/strlen.c =================================================================== --- head/sys/libkern/strlen.c (revision 333448) +++ head/sys/libkern/strlen.c (revision 333449) @@ -1,131 +1,130 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2009, 2010 Xin LI - * 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. */ #include __FBSDID("$FreeBSD$"); #include #include /* * Portable strlen() for 32-bit and 64-bit systems. * * Rationale: it is generally much more efficient to do word length * operations and avoid branches on modern computer systems, as * compared to byte-length operations with a lot of branches. * * The expression: * * ((x - 0x01....01) & ~x & 0x80....80) * * would evaluate to a non-zero value iff any of the bytes in the * original word is zero. * * On multi-issue processors, we can divide the above expression into: * a) (x - 0x01....01) * b) (~x & 0x80....80) * c) a & b * * Where, a) and b) can be partially computed in parallel. * * The algorithm above is found on "Hacker's Delight" by * Henry S. Warren, Jr. */ /* Magic numbers for the algorithm */ #if LONG_BIT == 32 static const unsigned long mask01 = 0x01010101; static const unsigned long mask80 = 0x80808080; #elif LONG_BIT == 64 static const unsigned long mask01 = 0x0101010101010101; static const unsigned long mask80 = 0x8080808080808080; #else #error Unsupported word size #endif #define LONGPTR_MASK (sizeof(long) - 1) /* * Helper macro to return string length if we caught the zero * byte. */ #define testbyte(x) \ do { \ if (p[x] == '\0') \ return (p - str + x); \ } while (0) size_t strlen(const char *str) { const char *p; const unsigned long *lp; long va, vb; /* * Before trying the hard (unaligned byte-by-byte access) way * to figure out whether there is a nul character, try to see * if there is a nul character is within this accessible word * first. * * p and (p & ~LONGPTR_MASK) must be equally accessible since * they always fall in the same memory page, as long as page * boundaries is integral multiple of word size. */ lp = (const unsigned long *)((uintptr_t)str & ~LONGPTR_MASK); va = (*lp - mask01); vb = ((~*lp) & mask80); lp++; if (va & vb) /* Check if we have \0 in the first part */ for (p = str; p < (const char *)lp; p++) if (*p == '\0') return (p - str); /* Scan the rest of the string using word sized operation */ for (; ; lp++) { va = (*lp - mask01); vb = ((~*lp) & mask80); if (va & vb) { p = (const char *)(lp); testbyte(0); testbyte(1); testbyte(2); testbyte(3); #if (LONG_BIT >= 64) testbyte(4); testbyte(5); testbyte(6); testbyte(7); #endif } } /* NOTREACHED */ return (0); } Index: head/usr.bin/gzip/unpack.c =================================================================== --- head/usr.bin/gzip/unpack.c (revision 333448) +++ head/usr.bin/gzip/unpack.c (revision 333449) @@ -1,341 +1,340 @@ /* $FreeBSD$ */ /* $NetBSD: unpack.c,v 1.3 2017/08/04 07:27:08 mrg Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2009 Xin LI - * 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$ */ /* This file is #included by gzip.c */ /* * pack(1) file format: * * The first 7 bytes is the header: * 00, 01 - Signature (US, RS), we already validated it earlier. * 02..05 - Uncompressed size * 06 - Level for the huffman tree (<=24) * * pack(1) will then store symbols (leaf) nodes count in each huffman * tree levels, each level would consume 1 byte (See [1]). * * After the symbol count table, there is the symbol table, storing * symbols represented by corresponding leaf node. EOB is not being * explicitly transmitted (not necessary anyway) in the symbol table. * * Compressed data goes after the symbol table. * * NOTES * * [1] If we count EOB into the symbols, that would mean that we will * have at most 256 symbols in the huffman tree. pack(1) rejects empty * file and files that just repeats one character, which means that we * will have at least 2 symbols. Therefore, pack(1) would reduce the * last level symbol count by 2 which makes it a number in * range [0..254], so all levels' symbol count would fit into 1 byte. */ #define PACK_HEADER_LENGTH 7 #define HTREE_MAXLEVEL 24 /* * unpack descriptor * * Represent the huffman tree in a similar way that pack(1) would * store in a packed file. We store all symbols in a linear table, * and store pointers to each level's first symbol. In addition to * that, maintain two counts for each level: inner nodes count and * leaf nodes count. */ typedef struct { int symbol_size; /* Size of the symbol table */ int treelevels; /* Levels for the huffman tree */ int *symbolsin; /* Table of leaf symbols count in each * level */ int *inodesin; /* Table of internal nodes count in * each level */ char *symbol; /* The symbol table */ char *symbol_eob; /* Pointer to the EOB symbol */ char **tree; /* Decoding huffman tree (pointers to * first symbol of each tree level */ off_t uncompressed_size; /* Uncompressed size */ FILE *fpIn; /* Input stream */ FILE *fpOut; /* Output stream */ } unpack_descriptor_t; /* * Release resource allocated to an unpack descriptor. * * Caller is responsible to make sure that all of these pointers are * initialized (in our case, they all point to valid memory block). * We don't zero out pointers here because nobody else would ever * reference the memory block without scrubbing them. */ static void unpack_descriptor_fini(unpack_descriptor_t *unpackd) { free(unpackd->symbolsin); free(unpackd->inodesin); free(unpackd->symbol); free(unpackd->tree); fclose(unpackd->fpIn); fclose(unpackd->fpOut); } /* * Recursively fill the internal node count table */ static void unpackd_fill_inodesin(const unpack_descriptor_t *unpackd, int level) { /* * The internal nodes would be 1/2 of total internal nodes and * leaf nodes in the next level. For the last level there * would be no internal node by definition. */ if (level < unpackd->treelevels) { unpackd_fill_inodesin(unpackd, level + 1); unpackd->inodesin[level] = (unpackd->inodesin[level + 1] + unpackd->symbolsin[level + 1]) / 2; } else unpackd->inodesin[level] = 0; } /* * Update counter for accepted bytes */ static void accepted_bytes(off_t *bytes_in, off_t newbytes) { if (bytes_in != NULL) (*bytes_in) += newbytes; } /* * Read file header and construct the tree. Also, prepare the buffered I/O * for decode routine. * * Return value is uncompressed size. */ static void unpack_parse_header(int in, int out, char *pre, size_t prelen, off_t *bytes_in, unpack_descriptor_t *unpackd) { unsigned char hdr[PACK_HEADER_LENGTH]; /* buffer for header */ ssize_t bytesread; /* Bytes read from the file */ int i, j, thisbyte; if (prelen > sizeof hdr) maybe_err("prelen too long"); /* Prepend the header buffer if we already read some data */ if (prelen != 0) memcpy(hdr, pre, prelen); /* Read in and fill the rest bytes of header */ bytesread = read(in, hdr + prelen, PACK_HEADER_LENGTH - prelen); if (bytesread < 0) maybe_err("Error reading pack header"); infile_newdata(bytesread); accepted_bytes(bytes_in, PACK_HEADER_LENGTH); /* Obtain uncompressed length (bytes 2,3,4,5) */ unpackd->uncompressed_size = 0; for (i = 2; i <= 5; i++) { unpackd->uncompressed_size <<= 8; unpackd->uncompressed_size |= hdr[i]; } /* Get the levels of the tree */ unpackd->treelevels = hdr[6]; if (unpackd->treelevels > HTREE_MAXLEVEL || unpackd->treelevels < 1) maybe_errx("Huffman tree has insane levels"); /* Let libc take care for buffering from now on */ if ((unpackd->fpIn = fdopen(in, "r")) == NULL) maybe_err("Can not fdopen() input stream"); if ((unpackd->fpOut = fdopen(out, "w")) == NULL) maybe_err("Can not fdopen() output stream"); /* Allocate for the tables of bounds and the tree itself */ unpackd->inodesin = calloc(unpackd->treelevels, sizeof(*(unpackd->inodesin))); unpackd->symbolsin = calloc(unpackd->treelevels, sizeof(*(unpackd->symbolsin))); unpackd->tree = calloc(unpackd->treelevels, (sizeof(*(unpackd->tree)))); if (unpackd->inodesin == NULL || unpackd->symbolsin == NULL || unpackd->tree == NULL) maybe_err("calloc"); /* We count from 0 so adjust to match array upper bound */ unpackd->treelevels--; /* Read the levels symbol count table and calculate total */ unpackd->symbol_size = 1; /* EOB */ for (i = 0; i <= unpackd->treelevels; i++) { if ((thisbyte = fgetc(unpackd->fpIn)) == EOF) maybe_err("File appears to be truncated"); unpackd->symbolsin[i] = (unsigned char)thisbyte; unpackd->symbol_size += unpackd->symbolsin[i]; } accepted_bytes(bytes_in, unpackd->treelevels); if (unpackd->symbol_size > 256) maybe_errx("Bad symbol table"); infile_newdata(unpackd->treelevels); /* Allocate for the symbol table, point symbol_eob at the beginning */ unpackd->symbol_eob = unpackd->symbol = calloc(1, unpackd->symbol_size); if (unpackd->symbol == NULL) maybe_err("calloc"); /* * Read in the symbol table, which contain [2, 256] symbols. * In order to fit the count in one byte, pack(1) would offset * it by reducing 2 from the actual number from the last level. * * We adjust the last level's symbol count by 1 here, because * the EOB symbol is not being transmitted explicitly. Another * adjustment would be done later afterward. */ unpackd->symbolsin[unpackd->treelevels]++; for (i = 0; i <= unpackd->treelevels; i++) { unpackd->tree[i] = unpackd->symbol_eob; for (j = 0; j < unpackd->symbolsin[i]; j++) { if ((thisbyte = fgetc(unpackd->fpIn)) == EOF) maybe_errx("Symbol table truncated"); *unpackd->symbol_eob++ = (char)thisbyte; } infile_newdata(unpackd->symbolsin[i]); accepted_bytes(bytes_in, unpackd->symbolsin[i]); } /* Now, take account for the EOB symbol as well */ unpackd->symbolsin[unpackd->treelevels]++; /* * The symbolsin table has been constructed now. * Calculate the internal nodes count table based on it. */ unpackd_fill_inodesin(unpackd, 0); } /* * Decode huffman stream, based on the huffman tree. */ static void unpack_decode(const unpack_descriptor_t *unpackd, off_t *bytes_in) { int thislevel, thiscode, thisbyte, inlevelindex; int i; off_t bytes_out = 0; const char *thissymbol; /* The symbol pointer decoded from stream */ /* * Decode huffman. Fetch every bytes from the file, get it * into 'thiscode' bit-by-bit, then output the symbol we got * when one has been found. * * Assumption: sizeof(int) > ((max tree levels + 1) / 8). * bad things could happen if not. */ thislevel = 0; thiscode = thisbyte = 0; while ((thisbyte = fgetc(unpackd->fpIn)) != EOF) { accepted_bytes(bytes_in, 1); infile_newdata(1); check_siginfo(); /* * Split one bit from thisbyte, from highest to lowest, * feed the bit into thiscode, until we got a symbol from * the tree. */ for (i = 7; i >= 0; i--) { thiscode = (thiscode << 1) | ((thisbyte >> i) & 1); /* Did we got a symbol? (referencing leaf node) */ if (thiscode >= unpackd->inodesin[thislevel]) { inlevelindex = thiscode - unpackd->inodesin[thislevel]; if (inlevelindex > unpackd->symbolsin[thislevel]) maybe_errx("File corrupt"); thissymbol = &(unpackd->tree[thislevel][inlevelindex]); if ((thissymbol == unpackd->symbol_eob) && (bytes_out == unpackd->uncompressed_size)) goto finished; fputc((*thissymbol), unpackd->fpOut); bytes_out++; /* Prepare for next input */ thislevel = 0; thiscode = 0; } else { thislevel++; if (thislevel > unpackd->treelevels) maybe_errx("File corrupt"); } } } finished: if (bytes_out != unpackd->uncompressed_size) maybe_errx("Premature EOF"); } /* Handler for pack(1)'ed file */ static off_t unpack(int in, int out, char *pre, size_t prelen, off_t *bytes_in) { unpack_descriptor_t unpackd; in = dup(in); if (in == -1) maybe_err("dup"); out = dup(out); if (out == -1) maybe_err("dup"); unpack_parse_header(in, out, pre, prelen, bytes_in, &unpackd); unpack_decode(&unpackd, bytes_in); unpack_descriptor_fini(&unpackd); /* If we reached here, the unpack was successful */ return (unpackd.uncompressed_size); } Index: head/usr.bin/ident/ident.c =================================================================== --- head/usr.bin/ident/ident.c (revision 333448) +++ head/usr.bin/ident/ident.c (revision 333449) @@ -1,279 +1,278 @@ /*- * Copyright (c) 2015 Baptiste Daroussin * Copyright (c) 2015 Xin LI - * 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 * in this position and unchanged. * 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(S) ``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(S) 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include typedef enum { /* state condition to transit to next state */ INIT, /* '$' */ DELIM_SEEN, /* letter */ KEYWORD, /* punctuation mark */ PUNC_SEEN, /* ':' -> _SVN; space -> TEXT */ PUNC_SEEN_SVN, /* space */ TEXT } analyzer_states; static int scan(FILE *fp, const char *name, bool quiet) { int c; bool hasid = false; bool subversion = false; analyzer_states state = INIT; struct sbuf *id = sbuf_new_auto(); locale_t l; l = newlocale(LC_ALL_MASK, "C", NULL); if (name != NULL) printf("%s:\n", name); while ((c = fgetc(fp)) != EOF) { switch (state) { case INIT: if (c == '$') { /* Transit to DELIM_SEEN if we see $ */ state = DELIM_SEEN; } else { /* Otherwise, stay in INIT state */ continue; } break; case DELIM_SEEN: if (isalpha_l(c, l)) { /* Transit to KEYWORD if we see letter */ sbuf_clear(id); sbuf_putc(id, '$'); sbuf_putc(id, c); state = KEYWORD; continue; } else if (c == '$') { /* Or, stay in DELIM_SEEN if more $ */ continue; } else { /* Otherwise, transit back to INIT */ state = INIT; } break; case KEYWORD: sbuf_putc(id, c); if (isalpha_l(c, l)) { /* * Stay in KEYWORD if additional letter is seen */ continue; } else if (c == ':') { /* * See ':' for the first time, transit to * PUNC_SEEN. */ state = PUNC_SEEN; subversion = false; } else if (c == '$') { /* * Incomplete ident. Go back to DELIM_SEEN * state because we see a '$' which could be * the beginning of a keyword. */ state = DELIM_SEEN; } else { /* * Go back to INIT state otherwise. */ state = INIT; } break; case PUNC_SEEN: case PUNC_SEEN_SVN: sbuf_putc(id, c); switch (c) { case ':': /* * If we see '::' (seen : in PUNC_SEEN), * activate subversion treatment and transit * to PUNC_SEEN_SVN state. * * If more than two :'s were seen, the ident * is invalid and we would therefore go back * to INIT state. */ if (state == PUNC_SEEN) { state = PUNC_SEEN_SVN; subversion = true; } else { state = INIT; } break; case ' ': /* * A space after ':' or '::' indicates we are at the * last component of potential ident. */ state = TEXT; break; default: /* All other characters are invalid */ state = INIT; break; } break; case TEXT: sbuf_putc(id, c); if (iscntrl_l(c, l)) { /* Control characters are not allowed in this state */ state = INIT; } else if (c == '$') { sbuf_finish(id); /* * valid ident should end with a space. * * subversion extension uses '#' to indicate that * the keyword expansion have exceeded the fixed * width, so it is also permitted if we are in * subversion mode. No length check is enforced * because GNU RCS ident(1) does not do it either. */ c = sbuf_data(id)[sbuf_len(id) - 2]; if (c == ' ' || (subversion && c == '#')) { printf(" %s\n", sbuf_data(id)); hasid = true; } state = INIT; } /* Other characters: stay in the state */ break; } } sbuf_delete(id); freelocale(l); if (!hasid) { if (!quiet) fprintf(stderr, "%s warning: no id keywords in %s\n", getprogname(), name ? name : "standard input"); return (EXIT_FAILURE); } return (EXIT_SUCCESS); } int main(int argc, char **argv) { bool quiet = false; int ch, i, *fds, fd; int ret = EXIT_SUCCESS; size_t nfds; FILE *fp; while ((ch = getopt(argc, argv, "qV")) != -1) { switch (ch) { case 'q': quiet = true; break; case 'V': /* Do nothing, compat with GNU rcs's ident */ return (EXIT_SUCCESS); default: errx(EXIT_FAILURE, "usage: %s [-q] [-V] [file...]", getprogname()); } } argc -= optind; argv += optind; if (caph_limit_stdio() < 0) err(EXIT_FAILURE, "unable to limit stdio"); if (argc == 0) { nfds = 1; fds = malloc(sizeof(*fds)); if (fds == NULL) err(EXIT_FAILURE, "unable to allocate fds array"); fds[0] = STDIN_FILENO; } else { nfds = argc; fds = malloc(sizeof(*fds) * nfds); if (fds == NULL) err(EXIT_FAILURE, "unable to allocate fds array"); for (i = 0; i < argc; i++) { fds[i] = fd = open(argv[i], O_RDONLY); if (fd < 0) { warn("%s", argv[i]); ret = EXIT_FAILURE; continue; } if (caph_limit_stream(fd, CAPH_READ) < 0) err(EXIT_FAILURE, "unable to limit fcntls/rights for %s", argv[i]); } } /* Enter Capsicum sandbox. */ if (cap_enter() < 0 && errno != ENOSYS) err(EXIT_FAILURE, "unable to enter capability mode"); for (i = 0; i < (int)nfds; i++) { if (fds[i] < 0) continue; fp = fdopen(fds[i], "r"); if (fp == NULL) { warn("%s", argv[i]); ret = EXIT_FAILURE; continue; } if (scan(fp, argc == 0 ? NULL : argv[i], quiet) != EXIT_SUCCESS) ret = EXIT_FAILURE; fclose(fp); } return (ret); } Index: head/usr.sbin/fstyp/zfs.c =================================================================== --- head/usr.sbin/fstyp/zfs.c (revision 333448) +++ head/usr.sbin/fstyp/zfs.c (revision 333449) @@ -1,78 +1,77 @@ /*- * Copyright (c) 2015 Allan Jude * Copyright (c) 2015 Xin LI - * 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 AUTHORS 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 AUTHORS 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include "fstyp.h" int fstyp_zfs(FILE *fp, char *label, size_t labelsize) { vdev_label_t *vdev_label = NULL; vdev_phys_t *vdev_phys; char *zpool_name = NULL; nvlist_t *config = NULL; int err = 0; /* * Read in the first ZFS vdev label ("L0"), located at the beginning * of the vdev and extract the pool name from it. * * TODO: the checksum of label should be validated. */ vdev_label = (vdev_label_t *)read_buf(fp, 0, sizeof(*vdev_label)); if (vdev_label == NULL) return (1); vdev_phys = &(vdev_label->vl_vdev_phys); if ((nvlist_unpack(vdev_phys->vp_nvlist, sizeof(vdev_phys->vp_nvlist), &config, 0)) == 0 && (nvlist_lookup_string(config, "name", &zpool_name) == 0)) { strlcpy(label, zpool_name, labelsize); } else err = 1; nvlist_free(config); free(vdev_label); return (err); } Index: head/usr.sbin/portsnap/phttpget/phttpget.8 =================================================================== --- head/usr.sbin/portsnap/phttpget/phttpget.8 (revision 333448) +++ head/usr.sbin/portsnap/phttpget/phttpget.8 (revision 333449) @@ -1,88 +1,87 @@ .\"- -.\" Copyright (c) 2015 Xin Li -.\" All rights reserved. +.\" Copyright (c) 2015 Xin LI .\" .\" 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 January 3, 2015 .Dt PHTTPGET 8 .Os .Sh NAME .Nm phttpget .Nd retrieve multiple files via pipelined HTTP .Sh SYNOPSIS .Nm .Ar server .Ar file ... .Sh DESCRIPTION The .Nm utility is a minimalist pipelined HTTP client, which is used to retrieve multiple .Ar file Ns s from one .Ar server , and saves the downloaded files in the current working directory, using the last portion of their download path as file names. .Pp By making several "in flight" HTTP requests, it can dramatically increase performance when a large number of small files need to be downloaded. .Pp The .Xr freebsd-update 8 and .Xr portsnap 8 tools use .Nm to download binary patch files. .Sh ENVIRONMENT .Bl -tag -width HTTP_PROXY_AUTH .It Ev HTTP_PROXY URL of the proxy to use for HTTP requests. .It Ev HTTP_PROXY_AUTH Authorization parameters for the HTTP proxy. .It Ev HTTP_USER_AGENT The User-Agent string to use for HTTP requests. The default is .Dq phttpget/0.1 . .It Ev HTTP_TIMEOUT Timeout for HTTP request in seconds. .El .Sh SEE ALSO .Xr fetch 1 , .Xr freebsd-update 8 , .Xr portsnap 8 .Sh AUTHORS .An -nosplit The .Nm utility was written by .An Colin Percival Aq Mt cperciva@FreeBSD.org for use with .Xr portsnap 8 and later with .Xr freebsd-update 8 . This manual page was written by .An Xin LI Aq Mt delphij@FreeBSD.org .