[Midnightbsd-cvs] src [10643] trunk/lib/libstand: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jun 9 12:51:44 EDT 2018


Revision: 10643
          http://svnweb.midnightbsd.org/src/?rev=10643
Author:   laffer1
Date:     2018-06-09 12:51:43 -0400 (Sat, 09 Jun 2018)
Log Message:
-----------
sync with freebsd

Modified Paths:
--------------
    trunk/lib/libstand/Makefile
    trunk/lib/libstand/__main.c
    trunk/lib/libstand/arp.c
    trunk/lib/libstand/assert.c
    trunk/lib/libstand/bcd.c
    trunk/lib/libstand/bootp.c
    trunk/lib/libstand/bootp.h
    trunk/lib/libstand/bootparam.c
    trunk/lib/libstand/bootparam.h
    trunk/lib/libstand/bzipfs.c
    trunk/lib/libstand/cd9660.c
    trunk/lib/libstand/close.c
    trunk/lib/libstand/closeall.c
    trunk/lib/libstand/dev.c
    trunk/lib/libstand/dosfs.c
    trunk/lib/libstand/dosfs.h
    trunk/lib/libstand/environment.c
    trunk/lib/libstand/ether.c
    trunk/lib/libstand/ext2fs.c
    trunk/lib/libstand/fstat.c
    trunk/lib/libstand/getopt.c
    trunk/lib/libstand/gets.c
    trunk/lib/libstand/globals.c
    trunk/lib/libstand/gzipfs.c
    trunk/lib/libstand/i386/_setjmp.S
    trunk/lib/libstand/in_cksum.c
    trunk/lib/libstand/inet_ntoa.c
    trunk/lib/libstand/ioctl.c
    trunk/lib/libstand/iodesc.h
    trunk/lib/libstand/libstand.3
    trunk/lib/libstand/lseek.c
    trunk/lib/libstand/net.c
    trunk/lib/libstand/net.h
    trunk/lib/libstand/netif.c
    trunk/lib/libstand/netif.h
    trunk/lib/libstand/nfs.c
    trunk/lib/libstand/nfsv2.h
    trunk/lib/libstand/nullfs.c
    trunk/lib/libstand/open.c
    trunk/lib/libstand/pager.c
    trunk/lib/libstand/printf.c
    trunk/lib/libstand/qdivrem.c
    trunk/lib/libstand/quad.h
    trunk/lib/libstand/random.c
    trunk/lib/libstand/rarp.c
    trunk/lib/libstand/read.c
    trunk/lib/libstand/readdir.c
    trunk/lib/libstand/rpc.c
    trunk/lib/libstand/rpc.h
    trunk/lib/libstand/rpcv2.h
    trunk/lib/libstand/saioctl.h
    trunk/lib/libstand/sbrk.c
    trunk/lib/libstand/sparc64/_setjmp.S
    trunk/lib/libstand/splitfs.c
    trunk/lib/libstand/stand.h
    trunk/lib/libstand/stat.c
    trunk/lib/libstand/strcasecmp.c
    trunk/lib/libstand/strdup.c
    trunk/lib/libstand/strerror.c
    trunk/lib/libstand/strtol.c
    trunk/lib/libstand/tftp.c
    trunk/lib/libstand/tftp.h
    trunk/lib/libstand/twiddle.c
    trunk/lib/libstand/udp.c
    trunk/lib/libstand/ufs.c
    trunk/lib/libstand/write.c
    trunk/lib/libstand/zalloc.c
    trunk/lib/libstand/zalloc_defs.h
    trunk/lib/libstand/zalloc_malloc.c
    trunk/lib/libstand/zalloc_mem.h

Added Paths:
-----------
    trunk/lib/libstand/amd64/
    trunk/lib/libstand/amd64/_setjmp.S
    trunk/lib/libstand/mips/
    trunk/lib/libstand/mips/_setjmp.S
    trunk/lib/libstand/nandfs.c
    trunk/lib/libstand/powerpc/
    trunk/lib/libstand/powerpc/_setjmp.S
    trunk/lib/libstand/strtoul.c

Property Changed:
----------------
    trunk/lib/libstand/i386/_setjmp.S
    trunk/lib/libstand/libstand.3
    trunk/lib/libstand/sparc64/_setjmp.S

Modified: trunk/lib/libstand/Makefile
===================================================================
--- trunk/lib/libstand/Makefile	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/Makefile	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,4 +1,5 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/lib/libstand/Makefile 312403 2017-01-19 07:29:52Z delphij $
 # Originally from	$NetBSD: Makefile,v 1.21 1997/10/26 22:08:38 lukem Exp $
 #
 # Notes:
@@ -9,16 +10,20 @@
 .include <bsd.own.mk>
 MK_SSP=		no
 
+LIBSTAND_SRC?=	${.CURDIR}
+LIBSTAND_CPUARCH?=${MACHINE_CPUARCH}
+LIBC_SRC=	${LIBSTAND_SRC}/../libc
+
 LIB=		stand
 NO_PROFILE=
 NO_PIC=
-INCS=		stand.h
-MAN=		libstand.3
+INCS?=		stand.h
+MAN?=		libstand.3
 
 WARNS?=		0
 
 CFLAGS+= -ffreestanding -Wformat
-CFLAGS+= -I${.CURDIR}
+CFLAGS+= -I${LIBSTAND_SRC}
 
 .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
 CFLAGS+=	-mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -msoft-float
@@ -29,7 +34,6 @@
 .if ${MACHINE_CPUARCH} == "amd64"
 CFLAGS+=	-fPIC -mno-red-zone
 .endif
-
 .if ${MACHINE} == "pc98"
 CFLAGS+=	-Os
 .endif
@@ -36,69 +40,81 @@
 .if ${MACHINE_CPUARCH} == "powerpc"
 CFLAGS+=	-msoft-float -D_STANDALONE -DNETIF_DEBUG
 .endif
-.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "powerpc64"
-CFLAGS+=	-m32 -I.
-.endif
 .if ${MACHINE_CPUARCH} == "arm"
 CFLAGS+=	-msoft-float -D_STANDALONE
 .endif
+.if ${MACHINE_CPUARCH} == "mips"
+CFLAGS+=	-G0 -fno-pic -mno-abicalls
+.endif
 
 # standalone components and stuff we have modified locally
-SRCS+=	gzguts.h zutil.h __main.c assert.c bcd.c bswap.c environment.c getopt.c gets.c \
-	globals.c pager.c printf.c strdup.c strerror.c strtol.c random.c \
+SRCS+=	gzguts.h zutil.h __main.c assert.c bcd.c environment.c getopt.c gets.c \
+	globals.c pager.c printf.c strdup.c strerror.c strtol.c strtoul.c random.c \
 	sbrk.c twiddle.c zalloc.c zalloc_malloc.c
 
 # private (pruned) versions of libc string functions
 SRCS+=	strcasecmp.c
 
-.PATH: ${.CURDIR}/../libc/net
+.PATH: ${LIBC_SRC}/net
 
 SRCS+= ntoh.c
 
 # string functions from libc
-.PATH: ${.CURDIR}/../libc/string
-.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "powerpc" || \
-	${MACHINE_CPUARCH} == "sparc64" || ${MACHINE_CPUARCH} == "amd64" || \
-	${MACHINE_CPUARCH} == "arm"
-SRCS+=	bcmp.c bcopy.c bzero.c ffs.c index.c memccpy.c memchr.c memcmp.c \
-        memcpy.c memmove.c memset.c qdivrem.c rindex.c strcat.c strchr.c \
-        strcmp.c strcpy.c strcspn.c strlen.c strncat.c strncmp.c strncpy.c \
+.PATH: ${LIBC_SRC}/string
+.if ${MACHINE_CPUARCH} != "ia64"
+SRCS+=	bcmp.c bcopy.c bzero.c ffs.c memccpy.c memchr.c memcmp.c memcpy.c \
+	memmove.c memset.c qdivrem.c strcat.c strchr.c strcmp.c strcpy.c \
+	strcspn.c strlcat.c strlcpy.c strlen.c strncat.c strncmp.c strncpy.c \
 	strpbrk.c strrchr.c strsep.c strspn.c strstr.c strtok.c swab.c
 .endif
 .if ${MACHINE_CPUARCH} == "arm"
-.PATH: ${.CURDIR}/../libc/arm/gen
+.PATH: ${LIBC_SRC}/arm/gen
+
+.if ${MK_ARM_EABI} == "no"
 SRCS+= divsi3.S
+.else
+# Compiler support functions
+.PATH: ${LIBSTAND_SRC}/../../contrib/compiler-rt/lib/
+# __clzsi2 and ctzsi2 for various builtin functions
+SRCS+=	clzsi2.c ctzsi2.c
+# Divide and modulus functions called by the compiler
+SRCS+=	 divmoddi4.c  divmodsi4.c  divdi3.c  divsi3.c  moddi3.c  modsi3.c
+SRCS+=	udivmoddi4.c udivmodsi4.c udivdi3.c udivsi3.c umoddi3.c umodsi3.c
+
+.PATH: ${LIBSTAND_SRC}/../../contrib/compiler-rt/lib/arm/
+SRCS+=	aeabi_idivmod.S aeabi_ldivmod.S aeabi_uidivmod.S aeabi_uldivmod.S
+SRCS+=	aeabi_memcmp.S aeabi_memcpy.S aeabi_memmove.S aeabi_memset.S
 .endif
+
+.endif
 .if ${MACHINE_CPUARCH} == "ia64"
-.PATH: ${.CURDIR}/../libc/ia64/string
-SRCS+=	bcmp.c bcopy.S bzero.S ffs.S index.c memccpy.c memchr.c memcmp.c \
-	memcpy.S memmove.S memset.c rindex.c strcat.c strchr.c \
-	strcmp.c strcpy.c strcspn.c strlen.c \
-	strncat.c strncmp.c strncpy.c strpbrk.c strrchr.c strsep.c \
+.PATH: ${LIBC_SRC}/ia64/string
+SRCS+=	bcmp.c bcopy.S bzero.S ffs.S memccpy.c memchr.c memcmp.c memcpy.S \
+	memmove.S memset.c strcat.c strchr.c strcmp.c strcpy.c strcspn.c \
+	strlcat.c strlcpy.c \
+	strlen.c strncat.c strncmp.c strncpy.c strpbrk.c strrchr.c strsep.c \
 	strspn.c strstr.c strtok.c swab.c
 
-.PATH: ${.CURDIR}/../libc/ia64/gen
+.PATH: ${LIBC_SRC}/ia64/gen
 SRCS+= __divdi3.S __divsi3.S __moddi3.S __modsi3.S
 SRCS+= __udivdi3.S __udivsi3.S __umoddi3.S __umodsi3.S
 .endif
 .if ${MACHINE_CPUARCH} == "powerpc"
-.PATH: ${.CURDIR}/../libc/quad
+.PATH: ${LIBC_SRC}/quad
 SRCS+=	ashldi3.c ashrdi3.c
-.PATH: ${.CURDIR}/../libc/powerpc/gen
+.PATH: ${LIBC_SRC}/powerpc/gen
 SRCS+=	syncicache.c
 .endif
 
 # uuid functions from libc
-.PATH: ${.CURDIR}/../libc/uuid
+.PATH: ${LIBC_SRC}/uuid
 SRCS+= uuid_equal.c uuid_is_nil.c
 
 # _setjmp/_longjmp
-.if ${MACHINE_CPUARCH} == "amd64"
-.PATH: ${.CURDIR}/i386
-.elif ${MACHINE_ARCH} == "powerpc64"
-.PATH: ${.CURDIR}/powerpc
+.if ${MACHINE_ARCH} == "powerpc64"
+.PATH: ${LIBSTAND_SRC}/powerpc
 .else
-.PATH: ${.CURDIR}/${MACHINE_CPUARCH}
+.PATH: ${LIBSTAND_SRC}/${LIBSTAND_CPUARCH}
 .endif
 SRCS+=	_setjmp.S
 
@@ -105,7 +121,7 @@
 # decompression functionality from libbz2
 # NOTE: to actually test this functionality after libbz2 upgrade compile
 # loader(8) with LOADER_BZIP2_SUPPORT defined
-.PATH: ${.CURDIR}/../../contrib/bzip2
+.PATH: ${LIBSTAND_SRC}/../../contrib/bzip2
 CFLAGS+= -DBZ_NO_STDIO -DBZ_NO_COMPRESS
 SRCS+=	libstand_bzlib_private.h
 
@@ -123,8 +139,8 @@
 		${.ALLSRC} > ${.TARGET}
 
 # decompression functionality from libz
-.PATH: ${.CURDIR}/../../contrib/zlib
-CFLAGS+=-DHAVE_MEMCPY -I${.CURDIR}/../../contrib/zlib
+.PATH: ${LIBSTAND_SRC}/../../contrib/zlib
+CFLAGS+=-DHAVE_MEMCPY -I${LIBSTAND_SRC}/../../contrib/zlib
 SRCS+=	adler32.c crc32.c libstand_zutil.h libstand_gzguts.h
 
 .for file in infback.c inffast.c inflate.c inftrees.c zutil.c
@@ -163,15 +179,9 @@
 SRCS+=	ufs.c nfs.c cd9660.c tftp.c gzipfs.c bzipfs.c
 SRCS+=	dosfs.c ext2fs.c
 SRCS+=	splitfs.c
+.if ${MK_NAND} != "no"
+SRCS+=	nandfs.c
+.endif
 
 .include <bsd.lib.mk>
 
-.if ${MACHINE_CPUARCH} == "amd64"
-beforedepend ${OBJS}: machine
-cleandepend: cleanmachine
-cleanmachine:
-	rm -f machine
-
-machine:
-	ln -s ${.CURDIR}/../../sys/i386/include machine
-.endif

Modified: trunk/lib/libstand/__main.c
===================================================================
--- trunk/lib/libstand/__main.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/__main.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: __main.c,v 1.4 1996/03/14 18:52:03 christos Exp $	*/
 
 /*
@@ -31,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/__main.c 221358 2011-05-03 04:44:50Z rodrigc $");
 
 #include <sys/types.h>
 

Added: trunk/lib/libstand/amd64/_setjmp.S
===================================================================
--- trunk/lib/libstand/amd64/_setjmp.S	                        (rev 0)
+++ trunk/lib/libstand/amd64/_setjmp.S	2018-06-09 16:51:43 UTC (rev 10643)
@@ -0,0 +1,94 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+	.asciz "@(#)_setjmp.s	5.1 (Berkeley) 4/23/90"
+#endif /* LIBC_SCCS and not lint */
+#include <machine/asm.h>
+__FBSDID("$FreeBSD: stable/10/lib/libstand/amd64/_setjmp.S 223695 2011-06-30 16:08:56Z dfr $");
+
+/*
+ * C library -- _setjmp, _longjmp
+ *
+ *	_longjmp(a,v)
+ * will generate a "return(v)" from the last call to
+ *	_setjmp(a)
+ * by restoring registers from the environment 'a'.
+ * The previous signal state is NOT restored.
+ */
+
+ENTRY(_setjmp)
+	movq	%rdi,%rax
+	movq	0(%rsp),%rdx		/* retval */
+	movq	%rdx, 0(%rax)		/* 0; retval */
+	movq	%rbx, 8(%rax)		/* 1; rbx */
+	movq	%rsp,16(%rax)		/* 2; rsp */
+	movq	%rbp,24(%rax)		/* 3; rbp */
+	movq	%r12,32(%rax)		/* 4; r12 */
+	movq	%r13,40(%rax)		/* 5; r13 */
+	movq	%r14,48(%rax)		/* 6; r14 */
+	movq	%r15,56(%rax)		/* 7; r15 */
+	fnstcw	64(%rax)		/* 8; fpu cw */
+	stmxcsr	68(%rax)		/*    and mxcsr */
+	xorq	%rax,%rax
+	ret
+END(_setjmp)
+
+	.weak	CNAME(_longjmp)
+ENTRY(_longjmp)
+	movq	%rdi,%rdx
+	/* Restore the mxcsr, but leave exception flags intact. */
+	stmxcsr	-4(%rsp)
+	movl	68(%rdx),%eax
+	andl	$0xffffffc0,%eax
+	movl	-4(%rsp),%edi
+	andl	$0x3f,%edi
+	xorl	%eax,%edi
+	movl	%edi,-4(%rsp)
+	ldmxcsr -4(%rsp)
+	movq	%rsi,%rax		/* retval */
+	movq	0(%rdx),%rcx
+	movq	8(%rdx),%rbx
+	movq	16(%rdx),%rsp
+	movq	24(%rdx),%rbp
+	movq	32(%rdx),%r12
+	movq	40(%rdx),%r13
+	movq	48(%rdx),%r14
+	movq	56(%rdx),%r15
+	fldcw	64(%rdx)
+	testq	%rax,%rax
+	jnz	1f
+	incq	%rax
+1:	movq	%rcx,0(%rsp)
+	ret
+END(_longjmp)


Property changes on: trunk/lib/libstand/amd64/_setjmp.S
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/lib/libstand/arp.c
===================================================================
--- trunk/lib/libstand/arp.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/arp.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: arp.c,v 1.18 1997/07/07 15:52:49 drochner Exp $	*/
 
 /*
@@ -36,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/arp.c 165906 2007-01-09 01:02:06Z imp $");
 
 #include <sys/types.h>
 #include <sys/socket.h>

Modified: trunk/lib/libstand/assert.c
===================================================================
--- trunk/lib/libstand/assert.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/assert.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1998 Michael Smith.
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/assert.c 205900 2010-03-30 19:07:41Z jhb $");
 
 #include <assert.h>
 

Modified: trunk/lib/libstand/bcd.c
===================================================================
--- trunk/lib/libstand/bcd.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/bcd.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Some data-tables that are often used.
  * Cannot be copyrighted.
@@ -4,7 +5,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/bcd.c 84221 2001-09-30 22:28:01Z dillon $");
 
 #include <sys/types.h>
 

Modified: trunk/lib/libstand/bootp.c
===================================================================
--- trunk/lib/libstand/bootp.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/bootp.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: bootp.c,v 1.14 1998/02/16 11:10:54 drochner Exp $	*/
 
 /*
@@ -36,9 +37,10 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/bootp.c 301056 2016-05-31 17:01:54Z ian $");
 
 #include <sys/types.h>
+#include <sys/endian.h>
 #include <netinet/in.h>
 #include <netinet/in_systm.h>
 
@@ -354,6 +356,7 @@
 	u_char *ep;
 	int size;
 	u_char tag;
+	const char *val;
 
 #ifdef BOOTP_DEBUG
 	if (debug)
@@ -380,16 +383,25 @@
 		}
 		if (tag == TAG_SWAPSERVER) {
 			/* let it override bp_siaddr */
-			bcopy(cp, &rootip.s_addr, sizeof(swapip.s_addr));
+			bcopy(cp, &rootip.s_addr, sizeof(rootip.s_addr));
 		}
 		if (tag == TAG_ROOTPATH) {
-			strncpy(rootpath, (char *)cp, sizeof(rootpath));
-			rootpath[size] = '\0';
+			if ((val = getenv("dhcp.root-path")) == NULL)
+				val = (const char *)cp;
+			strlcpy(rootpath, val, sizeof(rootpath));
 		}
 		if (tag == TAG_HOSTNAME) {
-			strncpy(hostname, (char *)cp, sizeof(hostname));
-			hostname[size] = '\0';
+			if ((val = getenv("dhcp.host-name")) == NULL)
+				val = (const char *)cp;
+			strlcpy(hostname, val, sizeof(hostname));
 		}
+		if (tag == TAG_INTF_MTU) {
+			if ((val = getenv("dhcp.interface-mtu")) != NULL) {
+				intf_mtu = (u_int)strtoul(val, NULL, 0);
+			} else {
+				intf_mtu = be16dec(cp);
+			}
+		}
 #ifdef SUPPORT_DHCP
 		if (tag == TAG_DHCP_MSGTYPE) {
 			if(*cp != expected_dhcpmsgtype)
@@ -703,13 +715,13 @@
 		u_char *s = NULL;	/* semicolon ? */
 
 		/* skip leading whitespace */
-		while (*endv && index(" \t\n\r", *endv))
+		while (*endv && strchr(" \t\n\r", *endv))
 		    endv++;
-		vp = index(endv, '=');	/* find name=value separator */
+		vp = strchr(endv, '=');	/* find name=value separator */
 		if (!vp)
 		    break;
 		*vp++ = 0;
-		if (op->fmt == __ILIST && (s = index(vp, ';')))
+		if (op->fmt == __ILIST && (s = strchr(vp, ';')))
 		    *s++ = '\0';
 		setenv(endv, vp, 1);
 		vp = s;	/* prepare for next round */
@@ -730,7 +742,11 @@
 		sprintf(env, op->desc, opts[0].desc, tag);
 	    else
 		sprintf(env, "%s%s", opts[0].desc, op->desc);
-	    setenv(env, buf, 1);
+	    /*
+	     * Do not replace existing values in the environment, so that
+	     * locally-obtained values can override server-provided values.
+	     */
+	    setenv(env, buf, 0);
 	}
     }
     if (tp != tags) {

Modified: trunk/lib/libstand/bootp.h
===================================================================
--- trunk/lib/libstand/bootp.h	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/bootp.h	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: bootp.h,v 1.4 1997/09/06 13:55:57 drochner Exp $	*/
 
 /*
@@ -19,7 +20,7 @@
  * suitability of this software for any purpose.  It is provided "as is"
  * without express or implied warranty.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/lib/libstand/bootp.h 301056 2016-05-31 17:01:54Z ian $
  */
 
 
@@ -91,6 +92,7 @@
 #define TAG_DOMAINNAME		((unsigned char)  15)
 #define TAG_SWAPSERVER		((unsigned char)  16)
 #define TAG_ROOTPATH		((unsigned char)  17)
+#define TAG_INTF_MTU		((unsigned char)  26)
 
 #ifdef SUPPORT_DHCP
 #define TAG_REQ_ADDR		((unsigned char)  50)

Modified: trunk/lib/libstand/bootparam.c
===================================================================
--- trunk/lib/libstand/bootparam.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/bootparam.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: bootparam.c,v 1.11 1997/06/26 19:11:32 drochner Exp $	*/
 
 /*
@@ -31,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/bootparam.c 84221 2001-09-30 22:28:01Z dillon $");
 
 /*
  * RPC/bootparams

Modified: trunk/lib/libstand/bootparam.h
===================================================================
--- trunk/lib/libstand/bootparam.h	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/bootparam.h	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: bootparam.h,v 1.3 1998/01/05 19:19:41 perry Exp $	*/
 
 int bp_whoami(int sock);

Modified: trunk/lib/libstand/bzipfs.c
===================================================================
--- trunk/lib/libstand/bzipfs.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/bzipfs.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* 
  * Copyright (c) 1998 Michael Smith.
  * Copyright (c) 2000 Maxim Sobolev
@@ -26,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/bzipfs.c 321071 2017-07-17 06:46:57Z delphij $");
 
 #ifndef REGRESSION
 #include "stand.h"
@@ -320,8 +321,6 @@
     case SEEK_CUR:
 	target = offset + bzf->bzf_bzstream.total_out_lo32;
 	break;
-    case SEEK_END:
-	target = -1;
     default:
 	errno = EINVAL;
 	return(-1);

Modified: trunk/lib/libstand/cd9660.c
===================================================================
--- trunk/lib/libstand/cd9660.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/cd9660.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: cd9660.c,v 1.5 1997/06/26 19:11:33 drochner Exp $	*/
 
 /*
@@ -32,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/cd9660.c 278602 2015-02-11 22:55:24Z ian $");
 
 /*
  * Stand-alone ISO9660 file reading package.
@@ -151,9 +152,14 @@
 				return (NULL);
 			p = susp_buffer + isonum_733(shc->offset);
 			end = p + isonum_733(shc->length);
-		} else
+		} else {
 			/* Ignore this record and skip to the next. */
 			p += isonum_711(sh->length);
+
+			/* Avoid infinite loops with corrupted file systems */
+			if (isonum_711(sh->length) == 0)
+				return (NULL);
+		}
 	}
 	return (NULL);
 }
@@ -281,7 +287,7 @@
 	buf = malloc(buf_size = ISO_DEFAULT_BLOCK_SIZE);
 	vd = buf;
 	for (bno = 16;; bno++) {
-		twiddle();
+		twiddle(1);
 		rc = f->f_dev->dv_strategy(f->f_devdata, F_READ, cdb2devb(bno),
 					   ISO_DEFAULT_BLOCK_SIZE, buf, &read);
 		if (rc)
@@ -314,7 +320,7 @@
 
 		while (off < dsize) {
 			if ((off % ISO_DEFAULT_BLOCK_SIZE) == 0) {
-				twiddle();
+				twiddle(1);
 				rc = f->f_dev->dv_strategy
 					(f->f_devdata, F_READ,
 					 cdb2devb(bno + boff),
@@ -374,7 +380,7 @@
 
 		/* Check for Rock Ridge since we didn't in the loop above. */
 		bno = isonum_733(rec.extent) + isonum_711(rec.ext_attr_length);
-		twiddle();
+		twiddle(1);
 		rc = f->f_dev->dv_strategy(f->f_devdata, F_READ, cdb2devb(bno),
 		    ISO_DEFAULT_BLOCK_SIZE, buf, &read);
 		if (rc)
@@ -431,7 +437,7 @@
 		if (fp->f_buf == (char *)0)
 			fp->f_buf = malloc(ISO_DEFAULT_BLOCK_SIZE);
 
-		twiddle();
+		twiddle(16);
 		rc = f->f_dev->dv_strategy(f->f_devdata, F_READ,
 		    cdb2devb(blkno), ISO_DEFAULT_BLOCK_SIZE, fp->f_buf, &read);
 		if (rc)

Modified: trunk/lib/libstand/close.c
===================================================================
--- trunk/lib/libstand/close.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/close.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: close.c,v 1.7 1997/01/22 00:38:09 cgd Exp $	*/
 
 /*-
@@ -61,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/close.c 165906 2007-01-09 01:02:06Z imp $");
 
 #include "stand.h"
 

Modified: trunk/lib/libstand/closeall.c
===================================================================
--- trunk/lib/libstand/closeall.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/closeall.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: closeall.c,v 1.1 1996/01/13 22:25:36 leo Exp $	*/
 
 /*-
@@ -61,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/closeall.c 165906 2007-01-09 01:02:06Z imp $");
 
 #include "stand.h"
 

Modified: trunk/lib/libstand/dev.c
===================================================================
--- trunk/lib/libstand/dev.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/dev.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: dev.c,v 1.4 1994/10/30 21:48:23 cgd Exp $	*/
 
 /*-
@@ -32,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/dev.c 165906 2007-01-09 01:02:06Z imp $");
 
 #include <sys/param.h>
 #include <sys/reboot.h>

Modified: trunk/lib/libstand/dosfs.c
===================================================================
--- trunk/lib/libstand/dosfs.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/dosfs.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1996, 1998 Robert Nordier
  * All rights reserved.
@@ -26,8 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-/* $FreeBSD: stable/9/lib/libstand/dosfs.c 281317 2015-04-09 18:45:03Z jhb $ */
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/dosfs.c 281317 2015-04-09 18:45:03Z jhb $");
 
 /*
  * Readonly filesystem for Microsoft FAT12/FAT16/FAT32 filesystems,
@@ -769,7 +769,7 @@
 {
     int	err;
 
-    twiddle();
+    twiddle(1);
     if ((err = (fd->f_dev->dv_strategy)(fd->f_devdata, F_READ, lsec, 
 					secbyt(nsec), buf, NULL)))
 	return(err);

Modified: trunk/lib/libstand/dosfs.h
===================================================================
--- trunk/lib/libstand/dosfs.h	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/dosfs.h	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1996, 1998 Robert Nordier
  * All rights reserved.

Modified: trunk/lib/libstand/environment.c
===================================================================
--- trunk/lib/libstand/environment.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/environment.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* 
  * Copyright (c) 1998 Michael Smith.
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/environment.c 221358 2011-05-03 04:44:50Z rodrigc $");
 
 /*
  * Manage an environment-like space in which string variables may be stored.

Modified: trunk/lib/libstand/ether.c
===================================================================
--- trunk/lib/libstand/ether.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/ether.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: ether.c,v 1.11 1997/07/07 15:52:50 drochner Exp $	*/
 
 /*
@@ -36,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/ether.c 165906 2007-01-09 01:02:06Z imp $");
 
 #include <sys/param.h>
 #include <sys/socket.h>

Modified: trunk/lib/libstand/ext2fs.c
===================================================================
--- trunk/lib/libstand/ext2fs.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/ext2fs.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1999,2000 Jonathan Lemon <jlemon at freebsd.org>
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/ext2fs.c 278602 2015-02-11 22:55:24Z ian $");
 
 /*-
  * Copyright (c) 1993
@@ -353,7 +354,7 @@
 	/* allocate space and read super block */
 	fs = (struct ext2fs *)malloc(sizeof(*fs));
 	fp->f_fs = fs;
-	twiddle();
+	twiddle(1);
 	error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
 	    EXT2_SBLOCK, EXT2_SBSIZE, (char *)fs, &buf_size);
 	if (error)
@@ -395,7 +396,7 @@
 	len = blkgrps * fs->fs_bsize;
 
 	fp->f_bg = malloc(len);
-	twiddle();
+	twiddle(1);
 	error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
 	    EXT2_SBLOCK + EXT2_SBSIZE / DEV_BSIZE, len,
 	    (char *)fp->f_bg, &buf_size);
@@ -507,7 +508,7 @@
 				if (error)
 					goto out;
 				
-				twiddle();
+				twiddle(1);
 				error = (f->f_dev->dv_strategy)(f->f_devdata,
 				    F_READ, fsb_to_db(fs, disk_block),
 				    fs->fs_bsize, buf, &buf_size);
@@ -568,7 +569,7 @@
 	 * Read inode and save it.
 	 */
 	buf = malloc(fs->fs_bsize);
-	twiddle();
+	twiddle(1);
 	error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
 	    ino_to_db(fs, fp->f_bg, inumber), fs->fs_bsize, buf, &rsize);
 	if (error)
@@ -665,7 +666,7 @@
 			if (fp->f_blk[level] == (char *)0)
 				fp->f_blk[level] =
 					malloc(fs->fs_bsize);
-			twiddle();
+			twiddle(1);
 			error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
 			    fsb_to_db(fp->f_fs, ind_block_num), fs->fs_bsize,
 			    fp->f_blk[level], &fp->f_blksize[level]);
@@ -723,7 +724,7 @@
 			bzero(fp->f_buf, block_size);
 			fp->f_buf_size = block_size;
 		} else {
-			twiddle();
+			twiddle(4);
 			error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
 			    fsb_to_db(fs, disk_block), block_size,
 			    fp->f_buf, &fp->f_buf_size);

Modified: trunk/lib/libstand/fstat.c
===================================================================
--- trunk/lib/libstand/fstat.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/fstat.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: fstat.c,v 1.1 1996/01/13 22:25:38 leo Exp $	*/
 
 /*-
@@ -32,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/fstat.c 165906 2007-01-09 01:02:06Z imp $");
 
 #include "stand.h"
 

Modified: trunk/lib/libstand/getopt.c
===================================================================
--- trunk/lib/libstand/getopt.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/getopt.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1987, 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/getopt.c 221358 2011-05-03 04:44:50Z rodrigc $");
 
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)getopt.c	8.3 (Berkeley) 4/27/95";

Modified: trunk/lib/libstand/gets.c
===================================================================
--- trunk/lib/libstand/gets.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/gets.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: gets.c,v 1.6 1995/10/11 21:16:57 pk Exp $	*/
 
 /*-
@@ -32,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/gets.c 190593 2009-03-31 14:30:46Z jhb $");
 
 #include "stand.h"
 

Modified: trunk/lib/libstand/globals.c
===================================================================
--- trunk/lib/libstand/globals.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/globals.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: globals.c,v 1.3 1995/09/18 21:19:27 pk Exp $	*/
 
 /*
@@ -8,7 +9,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/globals.c 301056 2016-05-31 17:01:54Z ian $");
 
 #include <sys/param.h>
 #include <netinet/in.h>
@@ -32,5 +33,6 @@
 struct	in_addr swapip;			/* swap ip address */
 struct	in_addr gateip;			/* swap ip address */
 n_long	netmask = 0xffffff00;		/* subnet or net mask */
+u_int	intf_mtu;			/* interface mtu from bootp/dhcp */
 int	errno;				/* our old friend */
 

Modified: trunk/lib/libstand/gzipfs.c
===================================================================
--- trunk/lib/libstand/gzipfs.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/gzipfs.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* 
  * Copyright (c) 1998 Michael Smith.
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/gzipfs.c 321071 2017-07-17 06:46:57Z delphij $");
 
 #include "stand.h"
 
@@ -300,8 +301,6 @@
     case SEEK_CUR:
 	target = offset + zf->zf_zstream.total_out;
 	break;
-    case SEEK_END:
-	target = -1;
     default:
 	errno = EINVAL;
 	return(-1);

Modified: trunk/lib/libstand/i386/_setjmp.S
===================================================================
--- trunk/lib/libstand/i386/_setjmp.S	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/i386/_setjmp.S	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
  * All rights reserved.
@@ -32,7 +33,7 @@
 
 #if defined(LIBC_RCS) && !defined(lint)
 	.text
-	.asciz "$FreeBSD$"
+	.asciz "$FreeBSD: stable/10/lib/libstand/i386/_setjmp.S 192760 2009-05-25 14:37:10Z attilio $"
 #endif /* LIBC_RCS and not lint */
 
 /*


Property changes on: trunk/lib/libstand/i386/_setjmp.S
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libstand/in_cksum.c
===================================================================
--- trunk/lib/libstand/in_cksum.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/in_cksum.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: in_cksum.c,v 1.6 2000/03/31 19:55:09 castor Exp $	*/
 
 /*
@@ -36,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/in_cksum.c 165906 2007-01-09 01:02:06Z imp $");
 
 #include <sys/types.h>
 #include <machine/endian.h>

Modified: trunk/lib/libstand/inet_ntoa.c
===================================================================
--- trunk/lib/libstand/inet_ntoa.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/inet_ntoa.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1983, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/inet_ntoa.c 165906 2007-01-09 01:02:06Z imp $");
 
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)inet_ntoa.c	8.1 (Berkeley) 6/4/93";

Modified: trunk/lib/libstand/ioctl.c
===================================================================
--- trunk/lib/libstand/ioctl.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/ioctl.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: ioctl.c,v 1.4 1994/10/30 21:48:24 cgd Exp $	*/
 
 /*-
@@ -61,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/ioctl.c 165906 2007-01-09 01:02:06Z imp $");
 
 #include "stand.h"
 

Modified: trunk/lib/libstand/iodesc.h
===================================================================
--- trunk/lib/libstand/iodesc.h	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/iodesc.h	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: iodesc.h,v 1.4 1995/09/23 03:31:50 gwr Exp $	*/
 
 /*
@@ -33,7 +34,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/lib/libstand/iodesc.h 165906 2007-01-09 01:02:06Z imp $
  */
 
 #ifndef __SYS_LIBNETBOOT_IODESC_H

Modified: trunk/lib/libstand/libstand.3
===================================================================
--- trunk/lib/libstand/libstand.3	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/libstand.3	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\" Copyright (c) Michael Smith
 .\" All rights reserved.
 .\"
@@ -22,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/lib/libstand/libstand.3 213573 2010-10-08 12:40:16Z uqs $
 .\"
 .Dd August 6, 2004
 .Dt LIBSTAND 3


Property changes on: trunk/lib/libstand/libstand.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libstand/lseek.c
===================================================================
--- trunk/lib/libstand/lseek.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/lseek.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: lseek.c,v 1.4 1997/01/22 00:38:10 cgd Exp $	*/
 
 /*-
@@ -61,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/lseek.c 321071 2017-07-17 06:46:57Z delphij $");
 
 #include "stand.h"
 
@@ -87,7 +88,6 @@
 	case SEEK_CUR:
 	    f->f_offset += offset;
 	    break;
-	case SEEK_END:
 	default:
 	    errno = EOFFSET;
 	    return (-1);

Added: trunk/lib/libstand/mips/_setjmp.S
===================================================================
--- trunk/lib/libstand/mips/_setjmp.S	                        (rev 0)
+++ trunk/lib/libstand/mips/_setjmp.S	2018-06-09 16:51:43 UTC (rev 10643)
@@ -0,0 +1,109 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 1991, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Ralph Campbell.
+ *
+ * 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 the University of
+ *	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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: stable/10/lib/libstand/mips/_setjmp.S 250020 2013-04-28 14:40:29Z rwatson $
+ */
+
+#include <machine/regnum.h>
+#include <machine/asm.h>
+
+#if 0
+#if defined(LIBC_SCCS)
+	.text
+	.asciz "$OpenBSD: _setjmp.S,v 1.6 1996/09/23 21:27:53 imp Exp $"
+#endif /* LIBC_SCCS */
+#endif
+
+/*
+ * C library -- _setjmp, _longjmp
+ *
+ *	_longjmp(a,v)
+ * will generate a "return(v)" from
+ * the last call to
+ *	_setjmp(a)
+ * by restoring registers from the stack,
+ * The previous signal state is NOT restored.
+ */
+
+LEAF(_setjmp)
+	.set	noreorder
+	REG_LI	v0, 0xACEDBADE			# sigcontext magic number
+	REG_S	ra, (2 * SZREG)(a0)		# sc_pc = return address
+	REG_S	v0, (3 * SZREG)(a0)		#   saved in sc_regs[0]
+	REG_S	s0, ((S0 + 3) * SZREG)(a0)
+	REG_S	s1, ((S1 + 3) * SZREG)(a0)
+	REG_S	s2, ((S2 + 3) * SZREG)(a0)
+	REG_S	s3, ((S3 + 3) * SZREG)(a0)
+	REG_S	s4, ((S4 + 3) * SZREG)(a0)
+	REG_S	s5, ((S5 + 3) * SZREG)(a0)
+	REG_S	s6, ((S6 + 3) * SZREG)(a0)
+	REG_S	s7, ((S7 + 3) * SZREG)(a0)
+	REG_S	sp, ((SP + 3) * SZREG)(a0)
+	REG_S	s8, ((S8 + 3) * SZREG)(a0)
+	j	ra
+	move	v0, zero
+END(_setjmp)
+
+LEAF(_longjmp)
+#ifdef ABICALLS 
+	subu	sp, sp, 32
+	.cprestore 16
+#endif  
+	.set    noreorder
+	REG_L	v0, (3 * SZREG)(a0)		# get magic number
+	REG_L	ra, (2 * SZREG)(a0)
+	bne	v0, 0xACEDBADE, botch		# jump if error
+
+	addu	sp, sp, 32			# does not matter, sanity
+	REG_L	s0, ((S0 + 3) * SZREG)(a0)
+	REG_L	s1, ((S1 + 3) * SZREG)(a0)
+	REG_L	s2, ((S2 + 3) * SZREG)(a0)
+	REG_L	s3, ((S3 + 3) * SZREG)(a0)
+	REG_L	s4, ((S4 + 3) * SZREG)(a0)
+	REG_L	s5, ((S5 + 3) * SZREG)(a0)
+	REG_L	s6, ((S6 + 3) * SZREG)(a0)
+	REG_L	s7, ((S7 + 3) * SZREG)(a0)
+	REG_L	sp, ((SP + 3) * SZREG)(a0)
+	REG_L	s8, ((S8 + 3) * SZREG)(a0)
+
+	j	ra
+	move	v0, a1
+botch:
+	jal	_C_LABEL(longjmperror)
+	nop
+	jal	_C_LABEL(abort)
+	nop
+END(_longjmp)


Property changes on: trunk/lib/libstand/mips/_setjmp.S
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libstand/nandfs.c
===================================================================
--- trunk/lib/libstand/nandfs.c	                        (rev 0)
+++ trunk/lib/libstand/nandfs.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -0,0 +1,1062 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2010-2012 Semihalf.
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libstand/nandfs.c 278602 2015-02-11 22:55:24Z ian $");
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/stdint.h>
+#include <ufs/ufs/dinode.h>
+#include <fs/nandfs/nandfs_fs.h>
+#include "stand.h"
+#include "string.h"
+#include "zlib.h"
+
+#define DEBUG
+#undef DEBUG
+#ifdef DEBUG
+#define NANDFS_DEBUG(fmt, args...) do { \
+    printf("NANDFS_DEBUG:" fmt "\n", ##args); } while (0)
+#else
+#define NANDFS_DEBUG(fmt, args...)
+#endif
+
+struct nandfs_mdt {
+	uint32_t	entries_per_block;
+	uint32_t	entries_per_group;
+	uint32_t	blocks_per_group;
+	uint32_t	groups_per_desc_block;	/* desc is super group */
+	uint32_t	blocks_per_desc_block;	/* desc is super group */
+};
+
+struct bmap_buf {
+	LIST_ENTRY(bmap_buf)	list;
+	nandfs_daddr_t		blknr;
+	uint64_t		*map;
+};
+
+struct nandfs_node {
+	struct nandfs_inode	*inode;
+	LIST_HEAD(, bmap_buf)	bmap_bufs;
+};
+struct nandfs {
+	int	nf_blocksize;
+	int	nf_sectorsize;
+	int	nf_cpno;
+
+	struct open_file	*nf_file;
+	struct nandfs_node	*nf_opened_node;
+	u_int			nf_offset;
+	uint8_t			*nf_buf;
+	int64_t			nf_buf_blknr;
+
+	struct nandfs_fsdata		*nf_fsdata;
+	struct nandfs_super_block	*nf_sb;
+	struct nandfs_segment_summary	nf_segsum;
+	struct nandfs_checkpoint	nf_checkpoint;
+	struct nandfs_super_root	nf_sroot;
+	struct nandfs_node		nf_ifile;
+	struct nandfs_node		nf_datfile;
+	struct nandfs_node		nf_cpfile;
+	struct nandfs_mdt		nf_datfile_mdt;
+	struct nandfs_mdt		nf_ifile_mdt;
+
+	int nf_nindir[NIADDR];
+};
+
+static int nandfs_open(const char *, struct open_file *);
+static int nandfs_close(struct open_file *);
+static int nandfs_read(struct open_file *, void *, size_t, size_t *);
+static off_t nandfs_seek(struct open_file *, off_t, int);
+static int nandfs_stat(struct open_file *, struct stat *);
+static int nandfs_readdir(struct open_file *, struct dirent *);
+
+static int nandfs_buf_read(struct nandfs *, void **, size_t *);
+static struct nandfs_node *nandfs_lookup_path(struct nandfs *, const char *);
+static int nandfs_read_inode(struct nandfs *, struct nandfs_node *,
+    nandfs_lbn_t, u_int, void *, int);
+static int nandfs_read_blk(struct nandfs *, nandfs_daddr_t, void *, int);
+static int nandfs_bmap_lookup(struct nandfs *, struct nandfs_node *,
+    nandfs_lbn_t, nandfs_daddr_t *, int);
+static int nandfs_get_checkpoint(struct nandfs *, uint64_t,
+    struct nandfs_checkpoint *);
+static nandfs_daddr_t nandfs_vtop(struct nandfs *, nandfs_daddr_t);
+static void nandfs_calc_mdt_consts(int, struct nandfs_mdt *, int);
+static void nandfs_mdt_trans(struct nandfs_mdt *, uint64_t,
+    nandfs_daddr_t *, uint32_t *);
+static int ioread(struct open_file *, off_t, void *, u_int);
+static int nandfs_probe_sectorsize(struct open_file *);
+
+struct fs_ops nandfs_fsops = {
+	"nandfs",
+	nandfs_open,
+	nandfs_close,
+	nandfs_read,
+	null_write,
+	nandfs_seek,
+	nandfs_stat,
+	nandfs_readdir
+};
+
+#define	NINDIR(fs)	((fs)->nf_blocksize / sizeof(nandfs_daddr_t))
+
+/* from NetBSD's src/sys/net/if_ethersubr.c */
+static uint32_t
+nandfs_crc32(uint32_t crc, const uint8_t *buf, size_t len)
+{
+	static const uint32_t crctab[] = {
+		0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
+		0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
+		0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
+		0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
+	};
+	size_t i;
+
+	crc = crc ^ ~0U;
+	for (i = 0; i < len; i++) {
+		crc ^= buf[i];
+		crc = (crc >> 4) ^ crctab[crc & 0xf];
+		crc = (crc >> 4) ^ crctab[crc & 0xf];
+	}
+	return (crc ^ ~0U);
+}
+
+static int
+nandfs_check_fsdata_crc(struct nandfs_fsdata *fsdata)
+{
+	uint32_t fsdata_crc, comp_crc;
+
+	if (fsdata->f_magic != NANDFS_FSDATA_MAGIC)
+		return (0);
+
+	/* Preserve crc */
+	fsdata_crc = fsdata->f_sum;
+
+	/* Calculate */
+	fsdata->f_sum = (0);
+	comp_crc = nandfs_crc32(0, (uint8_t *)fsdata, fsdata->f_bytes);
+
+	/* Restore */
+	fsdata->f_sum = fsdata_crc;
+
+	/* Check CRC */
+	return (fsdata_crc == comp_crc);
+}
+
+static int
+nandfs_check_superblock_crc(struct nandfs_fsdata *fsdata,
+    struct nandfs_super_block *super)
+{
+	uint32_t super_crc, comp_crc;
+
+	/* Check super block magic */
+	if (super->s_magic != NANDFS_SUPER_MAGIC)
+		return (0);
+
+	/* Preserve CRC */
+	super_crc = super->s_sum;
+
+	/* Calculate */
+	super->s_sum = (0);
+	comp_crc = nandfs_crc32(0, (uint8_t *)super, fsdata->f_sbbytes);
+
+	/* Restore */
+	super->s_sum = super_crc;
+
+	/* Check CRC */
+	return (super_crc == comp_crc);
+}
+
+static int
+nandfs_find_super_block(struct nandfs *fs, struct open_file *f)
+{
+	struct nandfs_super_block *sb;
+	int i, j, n, s;
+	int sectors_to_read, error;
+
+	sb = malloc(fs->nf_sectorsize);
+	if (sb == NULL)
+		return (ENOMEM);
+
+	memset(fs->nf_sb, 0, sizeof(*fs->nf_sb));
+
+	sectors_to_read = (NANDFS_NFSAREAS * fs->nf_fsdata->f_erasesize) /
+	    fs->nf_sectorsize;
+	for (i = 0; i < sectors_to_read; i++) {
+		NANDFS_DEBUG("reading i %d offset %d\n", i,
+		    i * fs->nf_sectorsize);
+		error = ioread(f, i * fs->nf_sectorsize, (char *)sb,
+		    fs->nf_sectorsize);
+		if (error) {
+			NANDFS_DEBUG("error %d\n", error);
+			continue;
+		}
+		n = fs->nf_sectorsize / sizeof(struct nandfs_super_block);
+		s = 0;
+		if ((i * fs->nf_sectorsize) % fs->nf_fsdata->f_erasesize == 0) {
+			if (fs->nf_sectorsize == sizeof(struct nandfs_fsdata))
+				continue;
+			else {
+				s += (sizeof(struct nandfs_fsdata) /
+				    sizeof(struct nandfs_super_block));
+			}
+		}
+
+		for (j = s; j < n; j++) {
+			if (!nandfs_check_superblock_crc(fs->nf_fsdata, &sb[j]))
+				continue;
+			NANDFS_DEBUG("magic %x wtime %jd, lastcp 0x%jx\n",
+			    sb[j].s_magic, sb[j].s_wtime, sb[j].s_last_cno);
+			if (sb[j].s_last_cno > fs->nf_sb->s_last_cno)
+				memcpy(fs->nf_sb, &sb[j], sizeof(*fs->nf_sb));
+		}
+	}
+
+	free(sb);
+
+	return (fs->nf_sb->s_magic != 0 ? 0 : EINVAL);
+}
+
+static int
+nandfs_find_fsdata(struct nandfs *fs, struct open_file *f)
+{
+	int offset, error, i;
+
+	NANDFS_DEBUG("starting\n");
+
+	offset = 0;
+	for (i = 0; i < 64 * NANDFS_NFSAREAS; i++) {
+		error = ioread(f, offset, (char *)fs->nf_fsdata,
+		    sizeof(struct nandfs_fsdata));
+		if (error)
+			return (error);
+		if (fs->nf_fsdata->f_magic == NANDFS_FSDATA_MAGIC) {
+			NANDFS_DEBUG("found at %x, volume %s\n", offset,
+			    fs->nf_fsdata->f_volume_name);
+			if (nandfs_check_fsdata_crc(fs->nf_fsdata))
+				break;
+		}
+		offset += fs->nf_sectorsize;
+	}
+
+	return (error);
+}
+
+static int
+nandfs_read_structures(struct nandfs *fs, struct open_file *f)
+{
+	int error;
+
+	error = nandfs_find_fsdata(fs, f);
+	if (error)
+		return (error);
+
+	error = nandfs_find_super_block(fs, f);
+
+	if (error == 0)
+		NANDFS_DEBUG("selected sb with w_time %jd last_pseg %jx\n",
+		    fs->nf_sb->s_wtime, fs->nf_sb->s_last_pseg);
+
+	return (error);
+}
+
+static int
+nandfs_mount(struct nandfs *fs, struct open_file *f)
+{
+	int err = 0, level;
+	uint64_t last_pseg;
+
+	fs->nf_fsdata = malloc(sizeof(struct nandfs_fsdata));
+	fs->nf_sb = malloc(sizeof(struct nandfs_super_block));
+
+	err = nandfs_read_structures(fs, f);
+	if (err) {
+		free(fs->nf_fsdata);
+		free(fs->nf_sb);
+		return (err);
+	}
+
+	fs->nf_blocksize = 1 << (fs->nf_fsdata->f_log_block_size + 10);
+
+	NANDFS_DEBUG("using superblock with wtime %jd\n", fs->nf_sb->s_wtime);
+
+	fs->nf_cpno = fs->nf_sb->s_last_cno;
+	last_pseg = fs->nf_sb->s_last_pseg;
+
+	/*
+	 * Calculate indirect block levels.
+	 */
+	nandfs_daddr_t mult;
+
+	mult = 1;
+	for (level = 0; level < NIADDR; level++) {
+		mult *= NINDIR(fs);
+		fs->nf_nindir[level] = mult;
+	}
+
+	nandfs_calc_mdt_consts(fs->nf_blocksize, &fs->nf_datfile_mdt,
+	    fs->nf_fsdata->f_dat_entry_size);
+
+	nandfs_calc_mdt_consts(fs->nf_blocksize, &fs->nf_ifile_mdt,
+	    fs->nf_fsdata->f_inode_size);
+
+	err = ioread(f, last_pseg * fs->nf_blocksize, &fs->nf_segsum,
+	    sizeof(struct nandfs_segment_summary));
+	if (err) {
+		free(fs->nf_sb);
+		free(fs->nf_fsdata);
+		return (err);
+	}
+
+	err = ioread(f, (last_pseg + fs->nf_segsum.ss_nblocks - 1) *
+	    fs->nf_blocksize, &fs->nf_sroot, sizeof(struct nandfs_super_root));
+	if (err) {
+		free(fs->nf_sb);
+		free(fs->nf_fsdata);
+		return (err);
+	}
+
+	fs->nf_datfile.inode = &fs->nf_sroot.sr_dat;
+	LIST_INIT(&fs->nf_datfile.bmap_bufs);
+	fs->nf_cpfile.inode = &fs->nf_sroot.sr_cpfile;
+	LIST_INIT(&fs->nf_cpfile.bmap_bufs);
+
+	err = nandfs_get_checkpoint(fs, fs->nf_cpno, &fs->nf_checkpoint);
+	if (err) {
+		free(fs->nf_sb);
+		free(fs->nf_fsdata);
+		return (err);
+	}
+
+	NANDFS_DEBUG("checkpoint cp_cno=%lld\n", fs->nf_checkpoint.cp_cno);
+	NANDFS_DEBUG("checkpoint cp_inodes_count=%lld\n",
+	    fs->nf_checkpoint.cp_inodes_count);
+	NANDFS_DEBUG("checkpoint cp_ifile_inode.i_blocks=%lld\n",
+	    fs->nf_checkpoint.cp_ifile_inode.i_blocks);
+
+	fs->nf_ifile.inode = &fs->nf_checkpoint.cp_ifile_inode;
+	LIST_INIT(&fs->nf_ifile.bmap_bufs);
+	return (0);
+}
+
+#define NINDIR(fs)	((fs)->nf_blocksize / sizeof(nandfs_daddr_t))
+
+static int
+nandfs_open(const char *path, struct open_file *f)
+{
+	struct nandfs *fs;
+	struct nandfs_node *node;
+	int err, bsize, level;
+
+	NANDFS_DEBUG("nandfs_open('%s', %p)\n", path, f);
+
+	fs = malloc(sizeof(struct nandfs));
+	f->f_fsdata = fs;
+	fs->nf_file = f;
+
+	bsize = nandfs_probe_sectorsize(f);
+	if (bsize < 0) {
+		printf("Cannot probe medium sector size\n");
+		return (EINVAL);
+	}
+
+	fs->nf_sectorsize = bsize;
+
+	/*
+	 * Calculate indirect block levels.
+	 */
+	nandfs_daddr_t mult;
+
+	mult = 1;
+	for (level = 0; level < NIADDR; level++) {
+		mult *= NINDIR(fs);
+		fs->nf_nindir[level] = mult;
+	}
+
+	NANDFS_DEBUG("fs %p nf_sectorsize=%x\n", fs, fs->nf_sectorsize);
+
+	err = nandfs_mount(fs, f);
+	if (err) {
+		NANDFS_DEBUG("Cannot mount nandfs: %s\n", strerror(err));
+		return (err);
+	}
+
+	node = nandfs_lookup_path(fs, path);
+	if (node == NULL)
+		return (EINVAL);
+
+	fs->nf_offset = 0;
+	fs->nf_buf = NULL;
+	fs->nf_buf_blknr = -1;
+	fs->nf_opened_node = node;
+	LIST_INIT(&fs->nf_opened_node->bmap_bufs);
+	return (0);
+}
+
+static void
+nandfs_free_node(struct nandfs_node *node)
+{
+	struct bmap_buf *bmap, *tmp;
+
+	free(node->inode);
+	LIST_FOREACH_SAFE(bmap, &node->bmap_bufs, list, tmp) {
+		LIST_REMOVE(bmap, list);
+		free(bmap->map);
+		free(bmap);
+	}
+	free(node);
+}
+
+static int
+nandfs_close(struct open_file *f)
+{
+	struct nandfs *fs = f->f_fsdata;
+
+	NANDFS_DEBUG("nandfs_close(%p)\n", f);
+
+	if (fs->nf_buf != NULL)
+		free(fs->nf_buf);
+
+	nandfs_free_node(fs->nf_opened_node);
+	free(fs->nf_sb);
+	free(fs);
+	return (0);
+}
+
+static int
+nandfs_read(struct open_file *f, void *addr, size_t size, size_t *resid)
+{
+	struct nandfs *fs = (struct nandfs *)f->f_fsdata;
+	size_t csize, buf_size;
+	void *buf;
+	int error = 0;
+
+	NANDFS_DEBUG("nandfs_read(file=%p, addr=%p, size=%d)\n", f, addr, size);
+
+	while (size != 0) {
+		if (fs->nf_offset >= fs->nf_opened_node->inode->i_size)
+			break;
+
+		error = nandfs_buf_read(fs, &buf, &buf_size);
+		if (error)
+			break;
+
+		csize = size;
+		if (csize > buf_size)
+			csize = buf_size;
+
+		bcopy(buf, addr, csize);
+
+		fs->nf_offset += csize;
+		addr = (char *)addr + csize;
+		size -= csize;
+	}
+
+	if (resid)
+		*resid = size;
+	return (error);
+}
+
+static off_t
+nandfs_seek(struct open_file *f, off_t offset, int where)
+{
+	struct nandfs *fs = f->f_fsdata;
+	off_t off;
+	u_int size;
+
+	NANDFS_DEBUG("nandfs_seek(file=%p, offset=%lld, where=%d)\n", f,
+	    offset, where);
+
+	size = fs->nf_opened_node->inode->i_size;
+
+	switch (where) {
+	case SEEK_SET:
+		off = 0;
+		break;
+	case SEEK_CUR:
+		off = fs->nf_offset;
+		break;
+	case SEEK_END:
+		off = size;
+		break;
+	default:
+		errno = EINVAL;
+		return (-1);
+	}
+
+	off += offset;
+	if (off < 0 || off > size) {
+		errno = EINVAL;
+		return(-1);
+	}
+
+	fs->nf_offset = (u_int)off;
+
+	return (off);
+}
+
+static int
+nandfs_stat(struct open_file *f, struct stat *sb)
+{
+	struct nandfs *fs = f->f_fsdata;
+
+	NANDFS_DEBUG("nandfs_stat(file=%p, stat=%p)\n", f, sb);
+
+	sb->st_size = fs->nf_opened_node->inode->i_size;
+	sb->st_mode = fs->nf_opened_node->inode->i_mode;
+	sb->st_uid = fs->nf_opened_node->inode->i_uid;
+	sb->st_gid = fs->nf_opened_node->inode->i_gid;
+	return (0);
+}
+
+static int
+nandfs_readdir(struct open_file *f, struct dirent *d)
+{
+	struct nandfs *fs = f->f_fsdata;
+	struct nandfs_dir_entry *dirent;
+	void *buf;
+	size_t buf_size;
+
+	NANDFS_DEBUG("nandfs_readdir(file=%p, dirent=%p)\n", f, d);
+
+	if (fs->nf_offset >= fs->nf_opened_node->inode->i_size) {
+		NANDFS_DEBUG("nandfs_readdir(file=%p, dirent=%p) ENOENT\n",
+		    f, d);
+		return (ENOENT);
+	}
+
+	if (nandfs_buf_read(fs, &buf, &buf_size)) {
+		NANDFS_DEBUG("nandfs_readdir(file=%p, dirent=%p)"
+		    "buf_read failed\n", f, d);
+		return (EIO);
+	}
+
+	NANDFS_DEBUG("nandfs_readdir(file=%p, dirent=%p) moving forward\n",
+	    f, d);
+
+	dirent = (struct nandfs_dir_entry *)buf;
+	fs->nf_offset += dirent->rec_len;
+	strncpy(d->d_name, dirent->name, dirent->name_len);
+	d->d_name[dirent->name_len] = '\0';
+	d->d_type = dirent->file_type;
+	return (0);
+}
+
+static int
+nandfs_buf_read(struct nandfs *fs, void **buf_p, size_t *size_p)
+{
+	nandfs_daddr_t blknr, blkoff;
+
+	blknr = fs->nf_offset / fs->nf_blocksize;
+	blkoff = fs->nf_offset % fs->nf_blocksize;
+
+	if (blknr != fs->nf_buf_blknr) {
+		if (fs->nf_buf == NULL)
+			fs->nf_buf = malloc(fs->nf_blocksize);
+
+		if (nandfs_read_inode(fs, fs->nf_opened_node, blknr, 1,
+		    fs->nf_buf, 0))
+			return (EIO);
+
+		fs->nf_buf_blknr = blknr;
+	}
+
+	*buf_p = fs->nf_buf + blkoff;
+	*size_p = fs->nf_blocksize - blkoff;
+
+	NANDFS_DEBUG("nandfs_buf_read buf_p=%p size_p=%d\n", *buf_p, *size_p);
+
+	if (*size_p > fs->nf_opened_node->inode->i_size - fs->nf_offset)
+		*size_p = fs->nf_opened_node->inode->i_size - fs->nf_offset;
+
+	return (0);
+}
+
+static struct nandfs_node *
+nandfs_lookup_node(struct nandfs *fs, uint64_t ino)
+{
+	uint64_t blocknr;
+	int entrynr;
+	struct nandfs_inode *buffer;
+	struct nandfs_node *node;
+	struct nandfs_inode *inode;
+
+	NANDFS_DEBUG("nandfs_lookup_node ino=%lld\n", ino);
+
+	if (ino == 0) {
+		printf("nandfs_lookup_node: invalid inode requested\n");
+		return (NULL);
+	}
+
+	buffer = malloc(fs->nf_blocksize);
+	inode = malloc(sizeof(struct nandfs_inode));
+	node = malloc(sizeof(struct nandfs_node));
+
+	nandfs_mdt_trans(&fs->nf_ifile_mdt, ino, &blocknr, &entrynr);
+
+	if (nandfs_read_inode(fs, &fs->nf_ifile, blocknr, 1, buffer, 0))
+		return (NULL);
+
+	memcpy(inode, &buffer[entrynr], sizeof(struct nandfs_inode));
+	node->inode = inode;
+	free(buffer);
+	return (node);
+}
+
+static struct nandfs_node *
+nandfs_lookup_path(struct nandfs *fs, const char *path)
+{
+	struct nandfs_node *node;
+	struct nandfs_dir_entry *dirent;
+	char *namebuf;
+	uint64_t i, done, pinode, inode;
+	int nlinks = 0, counter, len, link_len, nameidx;
+	uint8_t *buffer, *orig;
+	char *strp, *lpath;
+
+	buffer = malloc(fs->nf_blocksize);
+	orig = buffer;
+
+	namebuf = malloc(2 * MAXPATHLEN + 2);
+	strncpy(namebuf, path, MAXPATHLEN);
+	namebuf[MAXPATHLEN] = '\0';
+	done = nameidx = 0;
+	lpath = namebuf;
+
+	/* Get the root inode */
+	node = nandfs_lookup_node(fs, NANDFS_ROOT_INO);
+	inode = NANDFS_ROOT_INO;
+
+	while ((strp = strsep(&lpath, "/")) != NULL) {
+		if (*strp == '\0')
+			continue;
+		if ((node->inode->i_mode & IFMT) != IFDIR) {
+			nandfs_free_node(node);
+			node = NULL;
+			goto out;
+		}
+
+		len = strlen(strp);
+		NANDFS_DEBUG("%s: looking for %s\n", __func__, strp);
+		for (i = 0; i < node->inode->i_blocks; i++) {
+			if (nandfs_read_inode(fs, node, i, 1, orig, 0)) {
+				node = NULL;
+				goto out;
+			}
+
+			buffer = orig;
+			done = counter = 0;
+			while (1) {
+				dirent = 
+				    (struct nandfs_dir_entry *)(void *)buffer;
+				NANDFS_DEBUG("%s: dirent.name = %s\n",
+				    __func__, dirent->name);
+				NANDFS_DEBUG("%s: dirent.rec_len = %d\n",
+				    __func__, dirent->rec_len);
+				NANDFS_DEBUG("%s: dirent.inode = %lld\n",
+				    __func__, dirent->inode);
+				if (len == dirent->name_len &&
+				    (strncmp(strp, dirent->name, len) == 0) &&
+				    dirent->inode != 0) {
+					nandfs_free_node(node);
+					node = nandfs_lookup_node(fs,
+					    dirent->inode);
+					pinode = inode;
+					inode = dirent->inode;
+					done = 1;
+					break;
+				}
+
+				counter += dirent->rec_len;
+				buffer += dirent->rec_len;
+
+				if (counter == fs->nf_blocksize)
+					break;
+			}
+
+			if (done)
+				break;
+		}
+
+		if (!done) {
+			node = NULL;
+			goto out;
+		}
+
+		NANDFS_DEBUG("%s: %.*s has mode %o\n", __func__,
+		    dirent->name_len, dirent->name, node->inode->i_mode);
+
+		if ((node->inode->i_mode & IFMT) == IFLNK) {
+			NANDFS_DEBUG("%s: %.*s is symlink\n",
+			    __func__, dirent->name_len, dirent->name);
+			link_len = node->inode->i_size;
+
+			if (++nlinks > MAXSYMLINKS) {
+				nandfs_free_node(node);
+				node = NULL;
+				goto out;
+			}
+
+			if (nandfs_read_inode(fs, node, 0, 1, orig, 0)) {
+				nandfs_free_node(node);
+				node = NULL;
+				goto out;
+			}
+
+			NANDFS_DEBUG("%s: symlink is  %.*s\n",
+			    __func__, link_len, (char *)orig);
+
+			nameidx = (nameidx == 0) ? MAXPATHLEN + 1 : 0;
+			bcopy((char *)orig, namebuf + nameidx,
+			    (unsigned)link_len);
+			if (lpath != NULL) {
+				namebuf[nameidx + link_len++] = '/';
+				strncpy(namebuf + nameidx + link_len, lpath,
+				    MAXPATHLEN - link_len);
+				namebuf[nameidx + MAXPATHLEN] = '\0';
+			} else
+				namebuf[nameidx + link_len] = '\0';
+
+			NANDFS_DEBUG("%s: strp=%s, lpath=%s, namebuf0=%s, "
+			    "namebuf1=%s, idx=%d\n", __func__, strp, lpath,
+			    namebuf + 0, namebuf + MAXPATHLEN + 1, nameidx);
+
+			lpath = namebuf + nameidx;
+
+			nandfs_free_node(node);
+
+			/*
+			 * If absolute pathname, restart at root. Otherwise
+			 * continue with out parent inode.
+			 */
+			inode = (orig[0] == '/') ? NANDFS_ROOT_INO : pinode;
+			node = nandfs_lookup_node(fs, inode);
+		}
+	}
+
+out:
+	free(namebuf);
+	free(orig);
+	return (node);
+}
+
+static int
+nandfs_read_inode(struct nandfs *fs, struct nandfs_node *node,
+    nandfs_daddr_t blknr, u_int nblks, void *buf, int raw)
+{
+	uint64_t *pblks;
+	uint64_t *vblks;
+	u_int i;
+	int error;
+
+	pblks = malloc(nblks * sizeof(uint64_t));
+	vblks = malloc(nblks * sizeof(uint64_t));
+
+	NANDFS_DEBUG("nandfs_read_inode fs=%p node=%p blknr=%lld nblks=%d\n",
+	    fs, node, blknr, nblks);
+	for (i = 0; i < nblks; i++) {
+		error = nandfs_bmap_lookup(fs, node, blknr + i, &vblks[i], raw);
+		if (error) {
+			free(pblks);
+			free(vblks);
+			return (error);
+		}
+		if (raw == 0)
+			pblks[i] = nandfs_vtop(fs, vblks[i]);
+		else
+			pblks[i] = vblks[i];
+	}
+
+	for (i = 0; i < nblks; i++) {
+		if (ioread(fs->nf_file, pblks[i] * fs->nf_blocksize, buf,
+		    fs->nf_blocksize)) {
+			free(pblks);
+			free(vblks);
+			return (EIO);
+		}
+
+		buf = (void *)((uintptr_t)buf + fs->nf_blocksize);
+	}
+
+	free(pblks);
+	free(vblks);
+	return (0);
+}
+
+static int
+nandfs_read_blk(struct nandfs *fs, nandfs_daddr_t blknr, void *buf, int phys)
+{
+	uint64_t pblknr;
+
+	pblknr = (phys ? blknr : nandfs_vtop(fs, blknr));
+
+	return (ioread(fs->nf_file, pblknr * fs->nf_blocksize, buf,
+	    fs->nf_blocksize));
+}
+
+static int
+nandfs_get_checkpoint(struct nandfs *fs, uint64_t cpno,
+    struct nandfs_checkpoint *cp)
+{
+	uint64_t blocknr;
+	int blockoff, cp_per_block, dlen;
+	uint8_t *buf;
+
+	NANDFS_DEBUG("nandfs_get_checkpoint(fs=%p cpno=%lld)\n", fs, cpno);
+
+	buf = malloc(fs->nf_blocksize);
+
+	cpno += NANDFS_CPFILE_FIRST_CHECKPOINT_OFFSET - 1;
+	dlen = fs->nf_fsdata->f_checkpoint_size;
+	cp_per_block = fs->nf_blocksize / dlen;
+	blocknr = cpno / cp_per_block;
+	blockoff = (cpno % cp_per_block) * dlen;
+
+	if (nandfs_read_inode(fs, &fs->nf_cpfile, blocknr, 1, buf, 0)) {
+		free(buf);
+		return (EINVAL);
+	}
+
+	memcpy(cp, buf + blockoff, sizeof(struct nandfs_checkpoint));
+	free(buf);
+
+	return (0);
+}
+
+static uint64_t *
+nandfs_get_map(struct nandfs *fs, struct nandfs_node *node, nandfs_daddr_t blknr,
+    int phys)
+{
+	struct bmap_buf *bmap;
+	uint64_t *map;
+
+	LIST_FOREACH(bmap, &node->bmap_bufs, list) {
+		if (bmap->blknr == blknr)
+			return (bmap->map);
+	}
+
+	map = malloc(fs->nf_blocksize);
+	if (nandfs_read_blk(fs, blknr, map, phys)) {
+		free(map);
+		return (NULL);
+	}
+
+	bmap = malloc(sizeof(struct bmap_buf));
+	bmap->blknr = blknr;
+	bmap->map = map;
+
+	LIST_INSERT_HEAD(&node->bmap_bufs, bmap, list);
+
+	NANDFS_DEBUG("%s:(node=%p, map=%p)\n", __func__, node, map);
+	return (map);
+}
+
+static int
+nandfs_bmap_lookup(struct nandfs *fs, struct nandfs_node *node,
+    nandfs_lbn_t lblknr, nandfs_daddr_t *vblknr, int phys)
+{
+	struct nandfs_inode *ino;
+	nandfs_daddr_t ind_block_num;
+	uint64_t *map;
+	int idx;
+	int level;
+
+	ino = node->inode;
+
+	if (lblknr < NDADDR) {
+		*vblknr = ino->i_db[lblknr];
+		return (0);
+	}
+
+	lblknr -= NDADDR;
+
+	/*
+	 * nindir[0] = NINDIR
+	 * nindir[1] = NINDIR**2
+	 * nindir[2] = NINDIR**3
+	 *	etc
+	 */
+	for (level = 0; level < NIADDR; level++) {
+		NANDFS_DEBUG("lblknr=%jx fs->nf_nindir[%d]=%d\n", lblknr, level, fs->nf_nindir[level]);
+		if (lblknr < fs->nf_nindir[level])
+			break;
+		lblknr -= fs->nf_nindir[level];
+	}
+
+	if (level == NIADDR) {
+		/* Block number too high */
+		NANDFS_DEBUG("lblknr %jx too high\n", lblknr);
+		return (EFBIG);
+	}
+
+	ind_block_num = ino->i_ib[level];
+
+	for (; level >= 0; level--) {
+		if (ind_block_num == 0) {
+			*vblknr = 0;	/* missing */
+			return (0);
+		}
+
+		twiddle(1);
+		NANDFS_DEBUG("calling get_map with %jx\n", ind_block_num);
+		map = nandfs_get_map(fs, node, ind_block_num, phys);
+		if (map == NULL)
+			return (EIO);
+
+		if (level > 0) {
+			idx = lblknr / fs->nf_nindir[level - 1];
+			lblknr %= fs->nf_nindir[level - 1];
+		} else
+			idx = lblknr;
+
+		ind_block_num = ((nandfs_daddr_t *)map)[idx];
+	}
+
+	*vblknr = ind_block_num;
+
+	return (0);
+}
+
+static nandfs_daddr_t
+nandfs_vtop(struct nandfs *fs, nandfs_daddr_t vblocknr)
+{
+	nandfs_lbn_t blocknr;
+	nandfs_daddr_t pblocknr;
+	int entrynr;
+	struct nandfs_dat_entry *dat;
+
+	dat = malloc(fs->nf_blocksize);
+	nandfs_mdt_trans(&fs->nf_datfile_mdt, vblocknr, &blocknr, &entrynr);
+
+	if (nandfs_read_inode(fs, &fs->nf_datfile, blocknr, 1, dat, 1)) {
+		free(dat);
+		return (0);
+	}
+
+	NANDFS_DEBUG("nandfs_vtop entrynr=%d vblocknr=%lld pblocknr=%lld\n",
+	    entrynr, vblocknr, dat[entrynr].de_blocknr);
+
+	pblocknr = dat[entrynr].de_blocknr;
+	free(dat);
+	return (pblocknr);
+}
+
+static void
+nandfs_calc_mdt_consts(int blocksize, struct nandfs_mdt *mdt, int entry_size)
+{
+
+	mdt->entries_per_group = blocksize * 8;	   /* bits in sector */
+	mdt->entries_per_block = blocksize / entry_size;
+	mdt->blocks_per_group  =
+	    (mdt->entries_per_group -1) / mdt->entries_per_block + 1 + 1;
+	mdt->groups_per_desc_block =
+	    blocksize / sizeof(struct nandfs_block_group_desc);
+	mdt->blocks_per_desc_block =
+	    mdt->groups_per_desc_block * mdt->blocks_per_group + 1;
+}
+
+static void
+nandfs_mdt_trans(struct nandfs_mdt *mdt, uint64_t index,
+    nandfs_daddr_t *blocknr, uint32_t *entry_in_block)
+{
+	nandfs_daddr_t blknr;
+	uint64_t group, group_offset, blocknr_in_group;
+	uint64_t desc_block, desc_offset;
+
+	/* Calculate our offset in the file */
+	group = index / mdt->entries_per_group;
+	group_offset = index % mdt->entries_per_group;
+	desc_block = group / mdt->groups_per_desc_block;
+	desc_offset = group % mdt->groups_per_desc_block;
+	blocknr_in_group = group_offset / mdt->entries_per_block;
+
+	/* To descgroup offset */
+	blknr = 1 + desc_block * mdt->blocks_per_desc_block;
+
+	/* To group offset */
+	blknr += desc_offset * mdt->blocks_per_group;
+
+	/* To actual file block */
+	blknr += 1 + blocknr_in_group;
+
+	*blocknr        = blknr;
+	*entry_in_block = group_offset % mdt->entries_per_block;
+}
+
+static int
+ioread(struct open_file *f, off_t pos, void *buf, u_int length)
+{
+	void *buffer;
+	int err;
+	int bsize = ((struct nandfs *)f->f_fsdata)->nf_sectorsize;
+	u_int off, nsec;
+
+	off = pos % bsize;
+	pos /= bsize;
+	nsec = (length + (bsize - 1)) / bsize;
+
+	NANDFS_DEBUG("pos=%lld length=%d off=%d nsec=%d\n", pos, length,
+	    off, nsec);
+
+	buffer = malloc(nsec * bsize);
+
+	err = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, pos,
+	    nsec * bsize, buffer, NULL);
+
+	memcpy(buf, (void *)((uintptr_t)buffer + off), length);
+	free(buffer);
+
+	return (err);
+}
+
+static int
+nandfs_probe_sectorsize(struct open_file *f)
+{
+	void *buffer;
+	int i, err;
+
+	buffer = malloc(16 * 1024);
+
+	NANDFS_DEBUG("probing for sector size: ");
+
+	for (i = 512; i < (16 * 1024); i <<= 1) {
+		NANDFS_DEBUG("%d ", i);
+		err = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, 0, i,
+		    buffer, NULL);
+
+		if (err == 0) {
+			NANDFS_DEBUG("found");
+			free(buffer);
+			return (i);
+		}
+	}
+
+	free(buffer);
+	NANDFS_DEBUG("not found\n");
+	return (-1);
+}


Property changes on: trunk/lib/libstand/nandfs.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/lib/libstand/net.c
===================================================================
--- trunk/lib/libstand/net.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/net.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: net.c,v 1.20 1997/12/26 22:41:30 scottr Exp $	*/
 
 /*
@@ -36,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/net.c 223121 2011-06-15 21:58:01Z rodrigc $");
 
 #include <sys/param.h>
 #include <sys/socket.h>

Modified: trunk/lib/libstand/net.h
===================================================================
--- trunk/lib/libstand/net.h	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/net.h	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: net.h,v 1.10 1995/10/20 00:46:30 cgd Exp $	*/
 
 /*
@@ -33,7 +34,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/lib/libstand/net.h 301056 2016-05-31 17:01:54Z ian $
  */
 
 #ifndef _KERNEL	/* XXX - see <netinet/in.h> */
@@ -83,6 +84,7 @@
 extern	struct in_addr gateip;
 extern	struct in_addr nameip;
 extern	n_long netmask;
+extern	u_int intf_mtu;
 
 extern	int debug;			/* defined in the machdep sources */
 

Modified: trunk/lib/libstand/netif.c
===================================================================
--- trunk/lib/libstand/netif.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/netif.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: netif.c,v 1.10 1997/09/06 13:57:14 drochner Exp $	*/
 
 /*
@@ -32,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/netif.c 92913 2002-03-21 23:39:28Z obrien $");
 
 #include <sys/param.h>
 #include <sys/types.h>

Modified: trunk/lib/libstand/netif.h
===================================================================
--- trunk/lib/libstand/netif.h	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/netif.h	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,6 +1,7 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: netif.h,v 1.4 1995/09/14 23:45:30 pk Exp $	*/
 
-/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/lib/libstand/netif.h 64185 2000-08-03 09:08:29Z jhb $ */
 
 #ifndef __SYS_LIBNETBOOT_NETIF_H
 #define __SYS_LIBNETBOOT_NETIF_H

Modified: trunk/lib/libstand/nfs.c
===================================================================
--- trunk/lib/libstand/nfs.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/nfs.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: nfs.c,v 1.2 1998/01/24 12:43:09 drochner Exp $	*/
 
 /*-
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/nfs.c 307203 2016-10-13 08:09:40Z sephe $");
 
 #include <sys/param.h>
 #include <sys/time.h>
@@ -36,6 +37,7 @@
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <string.h>
+#include <stddef.h>
 
 #include <netinet/in.h>
 #include <netinet/in_systm.h>
@@ -50,7 +52,8 @@
 
 #define NFS_DEBUGxx
 
-#define NFSREAD_SIZE 1024
+#define NFSREAD_MIN_SIZE 1024
+#define NFSREAD_MAX_SIZE 4096
 
 /* Define our own NFS attributes without NQNFS stuff. */
 #ifdef OLD_NFSV2
@@ -83,7 +86,7 @@
 	n_long	errno;
 	struct	nfsv2_fattrs fa;
 	n_long	count;
-	u_char	data[NFSREAD_SIZE];
+	u_char	data[NFSREAD_MAX_SIZE];
 };
 
 #ifndef NFS_NOSYMLINK
@@ -210,6 +213,8 @@
 	nfs_readdir
 };
 
+static int nfs_read_size = NFSREAD_MIN_SIZE;
+
 #ifdef	OLD_NFSV2
 /*
  * Fetch the root file handle (call mount daemon)
@@ -264,6 +269,17 @@
 	if (repl->errno)
 		return (ntohl(repl->errno));
 	bcopy(repl->fh, fhp, sizeof(repl->fh));
+
+	/*
+	 * Improve boot performance over NFS
+	 */
+	if (getenv("nfs.read_size") != NULL)
+		nfs_read_size = strtol(getenv("nfs.read_size"), NULL, 0);
+	if (nfs_read_size < NFSREAD_MIN_SIZE)
+		nfs_read_size = NFSREAD_MIN_SIZE;
+	if (nfs_read_size > NFSREAD_MAX_SIZE)
+		nfs_read_size = NFSREAD_MAX_SIZE;
+
 	return (0);
 }
 
@@ -401,11 +417,11 @@
 
 	bcopy(d->fh, args->fh, NFS_FHSIZE);
 	args->off = htonl((n_long)off);
-	if (len > NFSREAD_SIZE)
-		len = NFSREAD_SIZE;
+	if (len > nfs_read_size)
+		len = nfs_read_size;
 	args->len = htonl((n_long)len);
 	args->xxx = htonl((n_long)0);
-	hlen = sizeof(*repl) - NFSREAD_SIZE;
+	hlen = offsetof(struct nfs_read_rpl, data[0]);
 
 	cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_READ,
 	    args, sizeof(*args),
@@ -606,10 +622,8 @@
 	error = 0;
 
 out:
-	if (newfd)
-		free(newfd);
-	if (path)
-		free(path);
+	free(newfd);
+	free(path);
 #else
         currfd->iodesc = desc;
 
@@ -664,7 +678,7 @@
 		       (int)fp->off);
 #endif
 	while ((int)size > 0) {
-		twiddle();
+		twiddle(16);
 		cc = nfs_readdata(fp, fp->off, (void *)addr, size);
 		/* XXX maybe should retry on certain errors */
 		if (cc == -1) {
@@ -1024,7 +1038,7 @@
 		uint32_t count;
 		uint32_t eof;
 		uint32_t len;
-		u_char data[NFSREAD_SIZE];
+		u_char data[NFSREAD_MAX_SIZE];
 	} *repl;
 	struct {
 		uint32_t h[RPC_HEADER_WORDS];
@@ -1047,10 +1061,10 @@
 	pos = roundup(d->fhsize, sizeof(uint32_t)) / sizeof(uint32_t);
 	args->fhoffcnt[pos++] = 0;
 	args->fhoffcnt[pos++] = htonl((uint32_t)off);
-	if (len > NFSREAD_SIZE)
-		len = NFSREAD_SIZE;
+	if (len > nfs_read_size)
+		len = nfs_read_size;
 	args->fhoffcnt[pos] = htonl((uint32_t)len);
-	hlen = sizeof(*repl) - NFSREAD_SIZE;
+	hlen = offsetof(struct repl, data[0]);
 
 	cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER3, NFSPROCV3_READ,
 	    args, 4 * sizeof(uint32_t) + roundup(d->fhsize, sizeof(uint32_t)),
@@ -1313,7 +1327,7 @@
 		       (int)fp->off);
 #endif
 	while ((int)size > 0) {
-		twiddle();
+		twiddle(16);
 		cc = nfs_readdata(fp, fp->off, (void *)addr, size);
 		/* XXX maybe should retry on certain errors */
 		if (cc == -1) {

Modified: trunk/lib/libstand/nfsv2.h
===================================================================
--- trunk/lib/libstand/nfsv2.h	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/nfsv2.h	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,4 +1,5 @@
 /* $MidnightBSD$ */
+/* $FreeBSD: stable/10/lib/libstand/nfsv2.h 165906 2007-01-09 01:02:06Z imp $ */
 /*	$NetBSD: nfsv2.h,v 1.2 1996/02/26 23:05:23 gwr Exp $	*/
 
 /*

Modified: trunk/lib/libstand/nullfs.c
===================================================================
--- trunk/lib/libstand/nullfs.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/nullfs.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: nullfs.c,v 1.1 1996/01/13 22:25:39 leo Exp $	*/
 
 /*-
@@ -61,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/nullfs.c 165906 2007-01-09 01:02:06Z imp $");
 
 #include "stand.h"
 

Modified: trunk/lib/libstand/open.c
===================================================================
--- trunk/lib/libstand/open.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/open.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: open.c,v 1.16 1997/01/28 09:41:03 pk Exp $	*/
 
 /*-
@@ -61,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/open.c 198542 2009-10-28 14:13:45Z brueffer $");
 
 #include "stand.h"
 

Modified: trunk/lib/libstand/pager.c
===================================================================
--- trunk/lib/libstand/pager.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/pager.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1998 Michael Smith <msmith at freebsd.org>
  * All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/pager.c 84221 2001-09-30 22:28:01Z dillon $");
 
 #include "stand.h"
 #include <string.h>

Added: trunk/lib/libstand/powerpc/_setjmp.S
===================================================================
--- trunk/lib/libstand/powerpc/_setjmp.S	                        (rev 0)
+++ trunk/lib/libstand/powerpc/_setjmp.S	2018-06-09 16:51:43 UTC (rev 10643)
@@ -0,0 +1,116 @@
+/* $MidnightBSD$ */
+/*	$FreeBSD: stable/10/lib/libstand/powerpc/_setjmp.S 271129 2014-09-04 20:21:30Z emaste $  */
+/*	from:	NetBSD: setjmp.S,v 1.1 1998/01/27 15:13:12 sakamoto Exp $  */
+/*	from:	OpenBSD: setjmp.S,v 1.2 1996/12/28 06:22:18 rahnds Exp 	*/
+/* kernel version of this file, does not have signal goop */
+/* int setjmp(jmp_buf env) */
+
+#include <machine/asm.h>
+
+#ifdef __powerpc64__
+#define LD_REG	ld
+#define	ST_REG	std
+#define	REGWIDTH 8
+#else
+#define	LD_REG	lwz
+#define	ST_REG	stw
+#define	REGWIDTH 4
+#endif
+
+#define JMP_r1	1*REGWIDTH
+#define JMP_r2	2*REGWIDTH
+#define JMP_r14	3*REGWIDTH
+#define JMP_r15 4*REGWIDTH
+#define JMP_r16 5*REGWIDTH
+#define JMP_r17 6*REGWIDTH
+#define JMP_r18 7*REGWIDTH
+#define JMP_r19 8*REGWIDTH
+#define JMP_r20 9*REGWIDTH
+#define JMP_r21 10*REGWIDTH
+#define JMP_r22 11*REGWIDTH
+#define JMP_r23 12*REGWIDTH
+#define JMP_r24 13*REGWIDTH
+#define JMP_r25 14*REGWIDTH
+#define JMP_r26 15*REGWIDTH
+#define JMP_r27 16*REGWIDTH
+#define JMP_r28 17*REGWIDTH
+#define JMP_r29 18*REGWIDTH
+#define JMP_r30 19*REGWIDTH
+#define JMP_r31 20*REGWIDTH
+#define JMP_lr 	21*REGWIDTH
+#define JMP_cr	22*REGWIDTH
+#define JMP_ctr	23*REGWIDTH
+#define JMP_xer	24*REGWIDTH
+#define JMP_sig	25*REGWIDTH
+
+ASENTRY_NOPROF(setjmp)
+	ST_REG 31, JMP_r31(3)
+	/* r1, r2, r14-r30 */
+	ST_REG 1,  JMP_r1 (3)
+	ST_REG 2,  JMP_r2 (3)
+	ST_REG 14, JMP_r14(3)
+	ST_REG 15, JMP_r15(3)
+	ST_REG 16, JMP_r16(3)
+	ST_REG 17, JMP_r17(3)
+	ST_REG 18, JMP_r18(3)
+	ST_REG 19, JMP_r19(3)
+	ST_REG 20, JMP_r20(3)
+	ST_REG 21, JMP_r21(3)
+	ST_REG 22, JMP_r22(3)
+	ST_REG 23, JMP_r23(3)
+	ST_REG 24, JMP_r24(3)
+	ST_REG 25, JMP_r25(3)
+	ST_REG 26, JMP_r26(3)
+	ST_REG 27, JMP_r27(3)
+	ST_REG 28, JMP_r28(3)
+	ST_REG 29, JMP_r29(3)
+	ST_REG 30, JMP_r30(3)
+	/* cr, lr, ctr, xer */
+	mfcr 0
+	ST_REG 0, JMP_cr(3)
+	mflr 0
+	ST_REG 0, JMP_lr(3)
+	mfctr 0
+	ST_REG 0, JMP_ctr(3)
+	mfxer 0
+	ST_REG 0, JMP_xer(3)
+	/* f14-f31, fpscr */
+	li 3, 0
+	blr
+
+
+.extern sigsetmask
+ASENTRY_NOPROF(longjmp)
+	LD_REG 31, JMP_r31(3)
+	/* r1, r2, r14-r30 */
+	LD_REG 1,  JMP_r1 (3)
+	LD_REG 2,  JMP_r2 (3)
+	LD_REG 14, JMP_r14(3)
+	LD_REG 15, JMP_r15(3)
+	LD_REG 16, JMP_r16(3)
+	LD_REG 17, JMP_r17(3)
+	LD_REG 18, JMP_r18(3)
+	LD_REG 19, JMP_r19(3)
+	LD_REG 20, JMP_r20(3)
+	LD_REG 21, JMP_r21(3)
+	LD_REG 22, JMP_r22(3)
+	LD_REG 23, JMP_r23(3)
+	LD_REG 24, JMP_r24(3)
+	LD_REG 25, JMP_r25(3)
+	LD_REG 26, JMP_r26(3)
+	LD_REG 27, JMP_r27(3)
+	LD_REG 28, JMP_r28(3)
+	LD_REG 29, JMP_r29(3)
+	LD_REG 30, JMP_r30(3)
+	/* cr, lr, ctr, xer */
+	LD_REG 0, JMP_cr(3)
+	mtcr 0
+	LD_REG 0, JMP_lr(3)
+	mtlr 0
+	LD_REG 0, JMP_ctr(3)
+	mtctr 0
+	LD_REG 0, JMP_xer(3)
+	mtxer 0
+	/* f14-f31, fpscr */
+	mr 3, 4
+	blr


Property changes on: trunk/lib/libstand/powerpc/_setjmp.S
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/lib/libstand/printf.c
===================================================================
--- trunk/lib/libstand/printf.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/printf.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1986, 1988, 1991, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -35,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/printf.c 273664 2014-10-26 02:51:56Z ian $");
 
 /*
  * Standaloneified version of the FreeBSD kernel printf family.
@@ -56,9 +57,18 @@
 
 #define MAXNBUF (sizeof(intmax_t) * CHAR_BIT + 1)
 
+typedef void (kvprintf_fn_t)(int, void *);
+
 static char	*ksprintn (char *buf, uintmax_t num, int base, int *len, int upper);
-static int	kvprintf(char const *fmt, void (*func)(int), void *arg, int radix, va_list ap);
+static int	kvprintf(char const *fmt, kvprintf_fn_t *func, void *arg, int radix, va_list ap);
 
+static void
+putchar_wrapper(int cc, void *arg)
+{
+
+	putchar(cc);
+}
+
 int
 printf(const char *fmt, ...)
 {
@@ -66,7 +76,7 @@
 	int retval;
 
 	va_start(ap, fmt);
-	retval = kvprintf(fmt, putchar, NULL, 10, ap);
+	retval = kvprintf(fmt, putchar_wrapper, NULL, 10, ap);
 	va_end(ap);
 	return retval;
 }
@@ -75,7 +85,7 @@
 vprintf(const char *fmt, va_list ap)
 {
 
-	kvprintf(fmt, putchar, NULL, 10, ap);
+	kvprintf(fmt, putchar_wrapper, NULL, 10, ap);
 }
 
 int
@@ -91,6 +101,46 @@
 	return retval;
 }
 
+struct print_buf {
+	char *buf;
+	size_t size;
+};
+
+static void
+snprint_func(int ch, void *arg)
+{
+	struct print_buf *pbuf = arg;
+
+	if (pbuf->size < 2) {
+		/*
+		 * Reserve last buffer position for the terminating
+		 * character:
+		 */
+		return;
+	}
+	*(pbuf->buf)++ = ch;
+	pbuf->size--;
+}
+
+int
+snprintf(char *buf, size_t size, const char *cfmt, ...)
+{
+	int retval;
+	va_list ap;
+	struct print_buf arg;
+
+	arg.buf = buf;
+	arg.size = size;
+
+	va_start(ap, cfmt);
+	retval = kvprintf(cfmt, &snprint_func, &arg, 10, ap);
+	va_end(ap);
+
+	if (arg.size >= 1)
+		*(arg.buf)++ = 0;
+	return retval;
+}
+
 void
 vsprintf(char *buf, const char *cfmt, va_list ap)
 {
@@ -149,9 +199,9 @@
  *		("%*D", len, ptr, " " -> XX XX XX XX ...
  */
 static int
-kvprintf(char const *fmt, void (*func)(int), void *arg, int radix, va_list ap)
+kvprintf(char const *fmt, kvprintf_fn_t *func, void *arg, int radix, va_list ap)
 {
-#define PCHAR(c) {int cc=(c); if (func) (*func)(cc); else *d++ = cc; retval++; }
+#define PCHAR(c) {int cc=(c); if (func) (*func)(cc, arg); else *d++ = cc; retval++; }
 	char nbuf[MAXNBUF];
 	char *d;
 	const char *p, *percent, *q;

Modified: trunk/lib/libstand/qdivrem.c
===================================================================
--- trunk/lib/libstand/qdivrem.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/qdivrem.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1992, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -34,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/qdivrem.c 271134 2014-09-04 20:49:11Z emaste $");
 
 /*
  * Multiprecision divide.  This algorithm is from Knuth vol. 2 (2nd ed),
@@ -46,14 +47,13 @@
 #define	B	(1 << HALF_BITS)	/* digit base */
 
 /* Combine two `digits' to make a single two-digit number. */
-#define	COMBINE(a, b) (((u_long)(a) << HALF_BITS) | (b))
+#define	COMBINE(a, b) (((u_int)(a) << HALF_BITS) | (b))
 
+_Static_assert(sizeof(int) / 2 == sizeof(short),
+	"Bitwise functions in libstand are broken on this architecture\n");
+
 /* select a type for digits in base B: use unsigned short if they fit */
-#if ULONG_MAX == 0xffffffff && USHRT_MAX >= 0xffff
 typedef unsigned short digit;
-#else
-typedef u_long digit;
-#endif
 
 /*
  * Shift p[0]..p[len] left `sh' bits, ignoring any bits that
@@ -74,7 +74,7 @@
  * __qdivrem(u, v, rem) returns u/v and, optionally, sets *rem to u%v.
  *
  * We do this in base 2-sup-HALF_BITS, so that all intermediate products
- * fit within u_long.  As a consequence, the maximum length dividend and
+ * fit within u_int.  As a consequence, the maximum length dividend and
  * divisor are 4 `digits' in this base (they are shorter if they have
  * leading zeros).
  */
@@ -85,7 +85,7 @@
 	union uu tmp;
 	digit *u, *v, *q;
 	digit v1, v2;
-	u_long qhat, rhat, t;
+	u_int qhat, rhat, t;
 	int m, n, d, j, i;
 	digit uspace[5], vspace[5], qspace[5];
 
@@ -136,7 +136,7 @@
 	v[4] = LHALF(tmp.ul[L]);
 	for (n = 4; v[1] == 0; v++) {
 		if (--n == 1) {
-			u_long rbj;	/* r*B+u[j] (not root boy jim) */
+			u_int rbj;	/* r*B+u[j] (not root boy jim) */
 			digit q1, q2, q3, q4;
 
 			/*
@@ -212,7 +212,7 @@
 			rhat = uj1;
 			goto qhat_too_big;
 		} else {
-			u_long nn = COMBINE(uj0, uj1);
+			u_int nn = COMBINE(uj0, uj1);
 			qhat = nn / v1;
 			rhat = nn % v1;
 		}

Modified: trunk/lib/libstand/quad.h
===================================================================
--- trunk/lib/libstand/quad.h	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/quad.h	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1992, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -31,7 +32,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)quad.h	8.1 (Berkeley) 6/4/93
- * $MidnightBSD$
+ * $FreeBSD: stable/10/lib/libstand/quad.h 271134 2014-09-04 20:49:11Z emaste $
  */
 
 /*
@@ -54,6 +55,9 @@
 #include <sys/types.h>
 #include <limits.h>
 
+_Static_assert(sizeof(quad_t) == sizeof(int) * 2,
+	"Bitwise function in libstand are broken on this architecture\n");
+
 /*
  * Depending on the desired operation, we view a `long long' (aka quad_t) in
  * one or more of the following formats.
@@ -61,8 +65,8 @@
 union uu {
 	quad_t	q;		/* as a (signed) quad */
 	quad_t	uq;		/* as an unsigned quad */
-	long	sl[2];		/* as two signed longs */
-	u_long	ul[2];		/* as two unsigned longs */
+	int	sl[2];		/* as two signed ints */
+	u_int	ul[2];		/* as two unsigned ints */
 };
 
 /*
@@ -77,8 +81,7 @@
  * and assembly.
  */
 #define	QUAD_BITS	(sizeof(quad_t) * CHAR_BIT)
-#define	LONG_BITS	(sizeof(long) * CHAR_BIT)
-#define	HALF_BITS	(sizeof(long) * CHAR_BIT / 2)
+#define	HALF_BITS	(sizeof(int) * CHAR_BIT / 2)
 
 /*
  * Extract high and low shortwords from longword, and move low shortword of

Modified: trunk/lib/libstand/random.c
===================================================================
--- trunk/lib/libstand/random.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/random.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1992, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/random.c 165906 2007-01-09 01:02:06Z imp $");
 
 #include <sys/types.h>
 

Modified: trunk/lib/libstand/rarp.c
===================================================================
--- trunk/lib/libstand/rarp.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/rarp.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: rarp.c,v 1.16 1997/07/07 15:52:52 drochner Exp $	*/
 
 /*
@@ -36,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/rarp.c 165906 2007-01-09 01:02:06Z imp $");
 
 #include <sys/param.h>
 #include <sys/socket.h>

Modified: trunk/lib/libstand/read.c
===================================================================
--- trunk/lib/libstand/read.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/read.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: read.c,v 1.8 1997/01/22 00:38:12 cgd Exp $	*/
 
 /*-
@@ -61,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/read.c 278602 2015-02-11 22:55:24Z ian $");
 
 #include <sys/param.h>
 #include "stand.h"
@@ -77,7 +78,7 @@
 	return (-1);
     }
     if (f->f_flags & F_RAW) {
-	twiddle();
+	twiddle(4);
 	errno = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
 					btodb(f->f_offset), bcount, dest, &resid);
 	if (errno)

Modified: trunk/lib/libstand/readdir.c
===================================================================
--- trunk/lib/libstand/readdir.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/readdir.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1999,2000 Jonathan Lemon <jlemon at freebsd.org>
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/readdir.c 84221 2001-09-30 22:28:01Z dillon $");
 
 #include <sys/param.h>
 #include "stand.h"

Modified: trunk/lib/libstand/rpc.c
===================================================================
--- trunk/lib/libstand/rpc.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/rpc.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: rpc.c,v 1.18 1998/01/23 19:27:45 thorpej Exp $	*/
 
 /*
@@ -36,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/rpc.c 197178 2009-09-13 21:51:01Z emaste $");
 
 /*
  * RPC functions used by NFS and bootparams.

Modified: trunk/lib/libstand/rpc.h
===================================================================
--- trunk/lib/libstand/rpc.h	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/rpc.h	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: rpc.h,v 1.8 1996/09/26 23:22:03 cgd Exp $	*/
 
 /*
@@ -32,7 +33,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/lib/libstand/rpc.h 165906 2007-01-09 01:02:06Z imp $
  */
 
 /* XXX defines we can't easily get from system includes */

Modified: trunk/lib/libstand/rpcv2.h
===================================================================
--- trunk/lib/libstand/rpcv2.h	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/rpcv2.h	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: rpcv2.h,v 1.1 1996/02/26 23:05:32 gwr Exp $	*/
 
 /*
@@ -33,7 +34,7 @@
  *
  *	@(#)rpcv2.h	8.1 (Berkeley) 6/10/93
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/lib/libstand/rpcv2.h 165906 2007-01-09 01:02:06Z imp $
  */
 
 /*

Modified: trunk/lib/libstand/saioctl.h
===================================================================
--- trunk/lib/libstand/saioctl.h	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/saioctl.h	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: saioctl.h,v 1.2 1994/10/26 05:45:04 cgd Exp $	*/
 
 /*-
@@ -30,7 +31,7 @@
  *
  *	@(#)saioctl.h	8.1 (Berkeley) 6/11/93
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/lib/libstand/saioctl.h 165906 2007-01-09 01:02:06Z imp $
  */
 
 /* ioctl's -- for disks just now */

Modified: trunk/lib/libstand/sbrk.c
===================================================================
--- trunk/lib/libstand/sbrk.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/sbrk.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1998 Michael Smith
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/sbrk.c 269101 2014-07-25 23:12:22Z ian $");
 
 /*
  * Minimal sbrk() emulation required for malloc support.
@@ -33,6 +34,7 @@
 
 #include <string.h>
 #include "stand.h"
+#include "zalloc_defs.h"
 
 static size_t	maxheap, heapsize = 0;
 static void	*heapbase;
@@ -40,8 +42,9 @@
 void
 setheap(void *base, void *top)
 {
-    /* Align start address to 16 bytes for the malloc code. Sigh. */
-    heapbase = (void *)(((uintptr_t)base + 15) & ~15);
+    /* Align start address for the malloc code.  Sigh. */
+    heapbase = (void *)(((uintptr_t)base + MALLOCALIGN_MASK) & 
+        ~MALLOCALIGN_MASK);
     maxheap = (char *)top - (char *)heapbase;
 }
 

Modified: trunk/lib/libstand/sparc64/_setjmp.S
===================================================================
--- trunk/lib/libstand/sparc64/_setjmp.S	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/sparc64/_setjmp.S	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1992, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -42,7 +43,7 @@
 #endif /* LIBC_SCCS and not lint */
 
 #include <machine/asm.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/sparc64/_setjmp.S 165906 2007-01-09 01:02:06Z imp $");
 
 #define	_JB_FP		0x0
 #define	_JB_PC		0x8


Property changes on: trunk/lib/libstand/sparc64/_setjmp.S
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libstand/splitfs.c
===================================================================
--- trunk/lib/libstand/splitfs.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/splitfs.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* 
  * Copyright (c) 2002 Maxim Sobolev
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/splitfs.c 146443 2005-05-20 12:55:38Z charnier $");
 
 #include "stand.h"
 

Modified: trunk/lib/libstand/stand.h
===================================================================
--- trunk/lib/libstand/stand.h	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/stand.h	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1998 Michael Smith.
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/lib/libstand/stand.h 301056 2016-05-31 17:01:54Z ian $
  * From	$NetBSD: stand.h,v 1.22 1997/06/26 19:17:40 drochner Exp $	
  */
 
@@ -118,6 +119,7 @@
 extern struct fs_ops tftp_fsops;
 extern struct fs_ops nfs_fsops;
 extern struct fs_ops cd9660_fsops;
+extern struct fs_ops nandfs_fsops;
 extern struct fs_ops gzipfs_fsops;
 extern struct fs_ops bzipfs_fsops;
 extern struct fs_ops dosfs_fsops;
@@ -237,9 +239,11 @@
 extern int	printf(const char *fmt, ...) __printflike(1, 2);
 extern void	vprintf(const char *fmt, __va_list);
 extern int	sprintf(char *buf, const char *cfmt, ...) __printflike(2, 3);
+extern int	snprintf(char *buf, size_t size, const char *cfmt, ...) __printflike(3, 4);
 extern void	vsprintf(char *buf, const char *cfmt, __va_list);
 
-extern void	twiddle(void);
+extern void	twiddle(u_int callerdiv);
+extern void	twiddle_divisor(u_int globaldiv);
 
 extern void	ngets(char *, int);
 #define gets(x)	ngets((x), 0)
@@ -260,6 +264,7 @@
     
 /* imports from stdlib, locally modified */
 extern long	strtol(const char *, char **, int);
+extern unsigned long	strtoul(const char *, char **, int);
 extern char	*optarg;			/* getopt(3) external variables */
 extern int	optind, opterr, optopt, optreset;
 extern int	getopt(int, char * const [], const char *);
@@ -330,11 +335,6 @@
 static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); }
 static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); }
 
-/* swaps (undocumented, useful?) */
-#ifdef __i386__
-extern u_int32_t	bswap32(u_int32_t x);
-extern u_int64_t	bswap64(u_int64_t x);
-#endif
 
 /* null functions for device/filesystem switches (undocumented) */
 extern int	nodev(void);

Modified: trunk/lib/libstand/stat.c
===================================================================
--- trunk/lib/libstand/stat.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/stat.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: stat.c,v 1.4 1996/01/13 22:25:43 leo Exp $	*/
 
 /*-
@@ -32,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/stat.c 165906 2007-01-09 01:02:06Z imp $");
 
 #include "stand.h"
 

Modified: trunk/lib/libstand/strcasecmp.c
===================================================================
--- trunk/lib/libstand/strcasecmp.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/strcasecmp.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1987, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/strcasecmp.c 165906 2007-01-09 01:02:06Z imp $");
 
 #include <sys/cdefs.h>
 #include <string.h>

Modified: trunk/lib/libstand/strdup.c
===================================================================
--- trunk/lib/libstand/strdup.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/strdup.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1988, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/strdup.c 165906 2007-01-09 01:02:06Z imp $");
 
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)strdup.c	8.1 (Berkeley) 6/4/93";

Modified: trunk/lib/libstand/strerror.c
===================================================================
--- trunk/lib/libstand/strerror.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/strerror.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: strerror.c,v 1.12 1997/01/25 00:37:50 cgd Exp $	*/
 
 /*-
@@ -30,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/strerror.c 165906 2007-01-09 01:02:06Z imp $");
 
 #include "stand.h"
 

Modified: trunk/lib/libstand/strtol.c
===================================================================
--- trunk/lib/libstand/strtol.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/strtol.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/strtol.c 165906 2007-01-09 01:02:06Z imp $");
 
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)strtol.c	8.1 (Berkeley) 6/4/93";

Added: trunk/lib/libstand/strtoul.c
===================================================================
--- trunk/lib/libstand/strtoul.c	                        (rev 0)
+++ trunk/lib/libstand/strtoul.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -0,0 +1,122 @@
+/* $MidnightBSD$ */
+/*
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Copyright (c) 2011 The FreeBSD Foundation
+ * All rights reserved.
+ * Portions of this software were developed by David Chisnall
+ * 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.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)strtoul.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libstand/strtoul.c 247001 2013-02-19 17:09:23Z kientzle $");
+
+#include "stand.h"
+#include <limits.h>
+
+/*
+ * Convert a string to an unsigned long integer.
+ *
+ * Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+unsigned long
+strtoul(const char * __restrict nptr, char ** __restrict endptr, int base)
+{
+	const char *s;
+	unsigned long acc;
+	char c;
+	unsigned long cutoff;
+	int neg, any, cutlim;
+
+	/*
+	 * See strtol for comments as to the logic used.
+	 */
+	s = nptr;
+	do {
+		c = *s++;
+	} while (isspace((unsigned char)c));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X') &&
+	    ((s[1] >= '0' && s[1] <= '9') ||
+	    (s[1] >= 'A' && s[1] <= 'F') ||
+	    (s[1] >= 'a' && s[1] <= 'f'))) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+	acc = any = 0;
+	if (base < 2 || base > 36)
+		goto noconv;
+
+	cutoff = ULONG_MAX / base;
+	cutlim = ULONG_MAX % base;
+	for ( ; ; c = *s++) {
+		if (c >= '0' && c <= '9')
+			c -= '0';
+		else if (c >= 'A' && c <= 'Z')
+			c -= 'A' - 10;
+		else if (c >= 'a' && c <= 'z')
+			c -= 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = ULONG_MAX;
+		errno = ERANGE;
+	} else if (!any) {
+noconv:
+		errno = EINVAL;
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (char *)(any ? s - 1 : nptr);
+	return (acc);
+}


Property changes on: trunk/lib/libstand/strtoul.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/lib/libstand/tftp.c
===================================================================
--- trunk/lib/libstand/tftp.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/tftp.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: tftp.c,v 1.4 1997/09/17 16:57:07 drochner Exp $	 */
 
 /*
@@ -32,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/tftp.c 278602 2015-02-11 22:55:24Z ian $");
 
 /*
  * Simple TFTP implementation for libsa.
@@ -292,8 +293,15 @@
 	wbuf.t.th_opcode = htons((u_short) RRQ);
 	wtail = wbuf.t.th_stuff;
 	l = strlen(h->path);
+#ifdef TFTP_PREPEND_PATH
+	if (l > FNAME_SIZE - (sizeof(TFTP_PREPEND_PATH) - 1))
+		return (ENAMETOOLONG);
+	bcopy(TFTP_PREPEND_PATH, wtail, sizeof(TFTP_PREPEND_PATH) - 1);
+	wtail += sizeof(TFTP_PREPEND_PATH) - 1;
+#else
 	if (l > FNAME_SIZE)
 		return (ENAMETOOLONG);
+#endif
 	bcopy(h->path, wtail, l + 1);
 	wtail += l + 1;
 	bcopy("octet", wtail, 6);
@@ -393,10 +401,14 @@
 	struct iodesc  *io;
 	int             res;
 
-#ifndef __i386__
-	if (strcmp(f->f_dev->dv_name, "net") != 0)
+	if (strcmp(f->f_dev->dv_name, "net") != 0) {
+#ifdef __i386__
+		if (strcmp(f->f_dev->dv_name, "pxe") != 0)
+			return (EINVAL);
+#else
 		return (EINVAL);
 #endif
+	}
 
 	if (is_open)
 		return (EBUSY);
@@ -436,14 +448,12 @@
     size_t *resid /* out */)
 {
 	struct tftp_handle *tftpfile;
-	static int      tc = 0;
 	tftpfile = (struct tftp_handle *) f->f_fsdata;
 
 	while (size > 0) {
 		int needblock, count;
 
-		if (!(tc++ % 16))
-			twiddle();
+		twiddle(32);
 
 		needblock = tftpfile->off / tftpfile->tftp_blksize + 1;
 

Modified: trunk/lib/libstand/tftp.h
===================================================================
--- trunk/lib/libstand/tftp.h	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/tftp.h	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: tftp.h,v 1.1.1.1 1997/03/14 02:40:31 perry Exp $	*/
 
 /*

Modified: trunk/lib/libstand/twiddle.c
===================================================================
--- trunk/lib/libstand/twiddle.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/twiddle.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1986, 1988, 1991, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -35,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/twiddle.c 278602 2015-02-11 22:55:24Z ian $");
 
 #include <sys/types.h>
 #include "stand.h"
@@ -42,11 +43,28 @@
 
 /* Extra functions from NetBSD standalone printf.c */
 
+static u_int globaldiv;
+
 void
-twiddle()
+twiddle(u_int callerdiv)
 {
-	static int pos;
+	static u_int callercnt, globalcnt, pos;
 
+	callercnt++;
+	if (callerdiv > 1 && (callercnt % callerdiv) != 0)
+		return;
+
+	globalcnt++;
+	if (globaldiv > 1 && (globalcnt % globaldiv) != 0)
+		return;
+
 	putchar("|/-\\"[pos++ & 3]);
 	putchar('\b');
 }
+
+void
+twiddle_divisor(u_int gdiv)
+{
+
+	globaldiv = gdiv;
+}

Modified: trunk/lib/libstand/udp.c
===================================================================
--- trunk/lib/libstand/udp.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/udp.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* Taken from $NetBSD: net.c,v 1.20 1997/12/26 22:41:30 scottr Exp $	*/
 
 /*
@@ -36,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/udp.c 221364 2011-05-03 07:39:54Z rodrigc $");
 
 #include <sys/param.h>
 #include <sys/socket.h>

Modified: trunk/lib/libstand/ufs.c
===================================================================
--- trunk/lib/libstand/ufs.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/ufs.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: ufs.c,v 1.20 1998/03/01 07:15:39 ross Exp $	*/
 
 /*-
@@ -68,7 +69,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/ufs.c 278602 2015-02-11 22:55:24Z ian $");
 
 /*
  *	Stand-alone file reading package.
@@ -155,7 +156,7 @@
 	 * Read inode and save it.
 	 */
 	buf = malloc(fs->fs_bsize);
-	twiddle();
+	twiddle(1);
 	rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
 		fsbtodb(fs, ino_to_fsba(fs, inumber)), fs->fs_bsize,
 		buf, &rsize);
@@ -265,7 +266,7 @@
 			if (fp->f_blk[level] == (char *)0)
 				fp->f_blk[level] =
 					malloc(fs->fs_bsize);
-			twiddle();
+			twiddle(1);
 			rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
 				fsbtodb(fp->f_fs, ind_block_num),
 				fs->fs_bsize,
@@ -346,7 +347,7 @@
 		if (fp->f_buf == (char *)0)
 			fp->f_buf = malloc(fs->fs_bsize);
 
-		twiddle();
+		twiddle(4);
 		rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
 			fsbtodb(fs, disk_block),
 			block_size, fp->f_buf, &fp->f_buf_size);
@@ -365,7 +366,7 @@
 	 *	Write the block out to storage.
 	 */
 
-	twiddle();
+	twiddle(4);
 	rc = (f->f_dev->dv_strategy)(f->f_devdata, F_WRITE,
 		fsbtodb(fs, disk_block),
 		block_size, fp->f_buf, &fp->f_buf_size);
@@ -406,7 +407,7 @@
 			bzero(fp->f_buf, block_size);
 			fp->f_buf_size = block_size;
 		} else {
-			twiddle();
+			twiddle(4);
 			rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
 				fsbtodb(fs, disk_block),
 				block_size, fp->f_buf, &fp->f_buf_size);
@@ -515,7 +516,7 @@
 	/* allocate space and read super block */
 	fs = malloc(SBLOCKSIZE);
 	fp->f_fs = fs;
-	twiddle();
+	twiddle(1);
 	/*
 	 * Try reading the superblock in each of its possible locations.
 	 */
@@ -649,7 +650,7 @@
 				if (rc)
 					goto out;
 				
-				twiddle();
+				twiddle(1);
 				rc = (f->f_dev->dv_strategy)(f->f_devdata,
 					F_READ, fsbtodb(fs, disk_block),
 					fs->fs_bsize, buf, &buf_size);

Modified: trunk/lib/libstand/write.c
===================================================================
--- trunk/lib/libstand/write.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/write.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: write.c,v 1.7 1996/06/21 20:29:30 pk Exp $	*/
 
 /*-
@@ -61,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/write.c 278602 2015-02-11 22:55:24Z ian $");
 
 #include <sys/param.h>
 #include "stand.h"
@@ -80,7 +81,7 @@
 		return (-1);
 	}
 	if (f->f_flags & F_RAW) {
-		twiddle();
+		twiddle(4);
 		errno = (f->f_dev->dv_strategy)(f->f_devdata, F_WRITE,
 			btodb(f->f_offset), bcount, dest, &resid);
 		if (errno)

Modified: trunk/lib/libstand/zalloc.c
===================================================================
--- trunk/lib/libstand/zalloc.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/zalloc.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * This module derived from code donated to the FreeBSD Project by 
  * Matthew Dillon <dillon at backplane.com>
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/zalloc.c 269101 2014-07-25 23:12:22Z ian $");
 
 /*
  * LIB/MEMORY/ZALLOC.C	- self contained low-overhead memory pool/allocation 
@@ -71,6 +72,15 @@
 #include "zalloc_defs.h"
 
 /*
+ * Objects in the pool must be aligned to at least the size of struct MemNode.
+ * They must also be aligned to MALLOCALIGN, which should normally be larger
+ * than the struct, so assert that to be so at compile time.
+ */
+typedef char assert_align[(sizeof(struct MemNode) <= MALLOCALIGN) ? 1 : -1];
+
+#define	MEMNODE_SIZE_MASK	MALLOCALIGN_MASK
+
+/*
  * znalloc() -	allocate memory (without zeroing) from pool.  Call reclaim
  *		and retry if appropriate, return NULL if unable to allocate
  *		memory.

Modified: trunk/lib/libstand/zalloc_defs.h
===================================================================
--- trunk/lib/libstand/zalloc_defs.h	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/zalloc_defs.h	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * This module derived from code donated to the FreeBSD Project by 
  * Matthew Dillon <dillon at backplane.com>
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/lib/libstand/zalloc_defs.h 269101 2014-07-25 23:12:22Z ian $
  */
 
 /*
@@ -52,18 +53,26 @@
 #define BLKEXTENDMASK	(BLKEXTEND - 1)
 
 /*
- * required malloc alignment.  Just hardwire to 16.
+ * Required malloc alignment.
  *
- * Note: if we implement a more sophisticated realloc, we should ensure that
- * MALLOCALIGN is at least as large as MemNode.
+ * Embedded platforms using the u-boot API drivers require that all I/O buffers
+ * be on a cache line sized boundary.  The worst case size for that is 64 bytes.
+ * For other platforms, 16 bytes works fine.  The alignment also must be at
+ * least sizeof(struct MemNode); this is asserted in zalloc.c.
  */
 
+#if defined(__arm__) || defined(__mips__) || defined(__powerpc__)
+#define	MALLOCALIGN		64
+#else
+#define	MALLOCALIGN		16
+#endif
+#define	MALLOCALIGN_MASK	(MALLOCALIGN - 1)
+
 typedef struct Guard {
     size_t	ga_Bytes;
     size_t	ga_Magic;	/* must be at least 32 bits */
 } Guard;
 
-#define MALLOCALIGN	16
 #define GAMAGIC		0x55FF44FD
 #define GAFREE		0x5F54F4DF
 

Modified: trunk/lib/libstand/zalloc_malloc.c
===================================================================
--- trunk/lib/libstand/zalloc_malloc.c	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/zalloc_malloc.c	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * This module derived from code donated to the FreeBSD Project by 
  * Matthew Dillon <dillon at backplane.com>
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libstand/zalloc_malloc.c 223905 2011-07-10 07:25:34Z avatar $");
 
 /*
  * MALLOC.C - malloc equivalent, runs on top of zalloc and uses sbrk

Modified: trunk/lib/libstand/zalloc_mem.h
===================================================================
--- trunk/lib/libstand/zalloc_mem.h	2018-06-09 16:50:13 UTC (rev 10642)
+++ trunk/lib/libstand/zalloc_mem.h	2018-06-09 16:51:43 UTC (rev 10643)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * This module derived from code donated to the FreeBSD Project by 
  * Matthew Dillon <dillon at backplane.com>
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/lib/libstand/zalloc_mem.h 269101 2014-07-25 23:12:22Z ian $
  */
 
 /*
@@ -48,8 +49,6 @@
     uintptr_t		mp_Used;
 } MemPool;
 
-#define MEMNODE_SIZE_MASK       ((sizeof(MemNode) <= 8) ? 7 : 15)
-
 #define ZNOTE_FREE	0
 #define ZNOTE_REUSE	1
 



More information about the Midnightbsd-cvs mailing list