Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Oct 2011 23:04:40 +0000 (UTC)
From:      Attilio Rao <attilio@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r226675 - in user/attilio/vmcontention: contrib/top etc etc/defaults etc/rc.d share/man/man4/man4.powerpc share/man/man5 share/mk sys/conf sys/contrib/pf/net sys/geom/part sys/kern tool...
Message-ID:  <201110232304.p9NN4erT060588@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: attilio
Date: Sun Oct 23 23:04:39 2011
New Revision: 226675
URL: http://svn.freebsd.org/changeset/base/226675

Log:
  MFC

Added:
  user/attilio/vmcontention/etc/rc.d/static_ndp
     - copied unchanged from r226674, head/etc/rc.d/static_ndp
Modified:
  user/attilio/vmcontention/etc/defaults/rc.conf
  user/attilio/vmcontention/etc/network.subr
  user/attilio/vmcontention/etc/rc.d/Makefile
  user/attilio/vmcontention/etc/rc.d/NETWORKING
  user/attilio/vmcontention/share/man/man4/man4.powerpc/abtn.4
  user/attilio/vmcontention/share/man/man5/rc.conf.5
  user/attilio/vmcontention/sys/conf/kern.mk
  user/attilio/vmcontention/sys/contrib/pf/net/if_pfsync.c
  user/attilio/vmcontention/sys/contrib/pf/net/pfvar.h
  user/attilio/vmcontention/sys/geom/part/g_part_gpt.c
  user/attilio/vmcontention/sys/kern/vfs_mountroot.c
  user/attilio/vmcontention/tools/tools/sysbuild/sysbuild.sh
  user/attilio/vmcontention/usr.bin/grep/Makefile
  user/attilio/vmcontention/usr.sbin/bsdinstall/partedit/gpart_ops.c
  user/attilio/vmcontention/usr.sbin/freebsd-update/freebsd-update.sh
Directory Properties:
  user/attilio/vmcontention/   (props changed)
  user/attilio/vmcontention/cddl/contrib/opensolaris/   (props changed)
  user/attilio/vmcontention/contrib/bind9/   (props changed)
  user/attilio/vmcontention/contrib/binutils/   (props changed)
  user/attilio/vmcontention/contrib/bzip2/   (props changed)
  user/attilio/vmcontention/contrib/com_err/   (props changed)
  user/attilio/vmcontention/contrib/compiler-rt/   (props changed)
  user/attilio/vmcontention/contrib/dialog/   (props changed)
  user/attilio/vmcontention/contrib/ee/   (props changed)
  user/attilio/vmcontention/contrib/expat/   (props changed)
  user/attilio/vmcontention/contrib/file/   (props changed)
  user/attilio/vmcontention/contrib/gcc/   (props changed)
  user/attilio/vmcontention/contrib/gdb/   (props changed)
  user/attilio/vmcontention/contrib/gdtoa/   (props changed)
  user/attilio/vmcontention/contrib/gnu-sort/   (props changed)
  user/attilio/vmcontention/contrib/groff/   (props changed)
  user/attilio/vmcontention/contrib/less/   (props changed)
  user/attilio/vmcontention/contrib/libpcap/   (props changed)
  user/attilio/vmcontention/contrib/libstdc++/   (props changed)
  user/attilio/vmcontention/contrib/llvm/   (props changed)
  user/attilio/vmcontention/contrib/llvm/tools/clang/   (props changed)
  user/attilio/vmcontention/contrib/ncurses/   (props changed)
  user/attilio/vmcontention/contrib/netcat/   (props changed)
  user/attilio/vmcontention/contrib/ntp/   (props changed)
  user/attilio/vmcontention/contrib/one-true-awk/   (props changed)
  user/attilio/vmcontention/contrib/openbsm/   (props changed)
  user/attilio/vmcontention/contrib/openpam/   (props changed)
  user/attilio/vmcontention/contrib/openresolv/   (props changed)
  user/attilio/vmcontention/contrib/pf/   (props changed)
  user/attilio/vmcontention/contrib/sendmail/   (props changed)
  user/attilio/vmcontention/contrib/tcpdump/   (props changed)
  user/attilio/vmcontention/contrib/tcsh/   (props changed)
  user/attilio/vmcontention/contrib/tnftp/   (props changed)
  user/attilio/vmcontention/contrib/top/   (props changed)
  user/attilio/vmcontention/contrib/top/install-sh   (props changed)
  user/attilio/vmcontention/contrib/tzcode/stdtime/   (props changed)
  user/attilio/vmcontention/contrib/tzcode/zic/   (props changed)
  user/attilio/vmcontention/contrib/tzdata/   (props changed)
  user/attilio/vmcontention/contrib/wpa/   (props changed)
  user/attilio/vmcontention/contrib/xz/   (props changed)
  user/attilio/vmcontention/crypto/heimdal/   (props changed)
  user/attilio/vmcontention/crypto/openssh/   (props changed)
  user/attilio/vmcontention/crypto/openssl/   (props changed)
  user/attilio/vmcontention/gnu/lib/   (props changed)
  user/attilio/vmcontention/gnu/usr.bin/binutils/   (props changed)
  user/attilio/vmcontention/gnu/usr.bin/cc/cc_tools/   (props changed)
  user/attilio/vmcontention/gnu/usr.bin/gdb/   (props changed)
  user/attilio/vmcontention/lib/libc/   (props changed)
  user/attilio/vmcontention/lib/libc/stdtime/   (props changed)
  user/attilio/vmcontention/lib/libutil/   (props changed)
  user/attilio/vmcontention/lib/libz/   (props changed)
  user/attilio/vmcontention/sbin/   (props changed)
  user/attilio/vmcontention/sbin/ipfw/   (props changed)
  user/attilio/vmcontention/share/mk/bsd.arch.inc.mk   (props changed)
  user/attilio/vmcontention/share/zoneinfo/   (props changed)
  user/attilio/vmcontention/sys/   (props changed)
  user/attilio/vmcontention/sys/amd64/include/xen/   (props changed)
  user/attilio/vmcontention/sys/boot/   (props changed)
  user/attilio/vmcontention/sys/boot/i386/efi/   (props changed)
  user/attilio/vmcontention/sys/boot/ia64/efi/   (props changed)
  user/attilio/vmcontention/sys/boot/ia64/ski/   (props changed)
  user/attilio/vmcontention/sys/boot/powerpc/boot1.chrp/   (props changed)
  user/attilio/vmcontention/sys/boot/powerpc/ofw/   (props changed)
  user/attilio/vmcontention/sys/cddl/contrib/opensolaris/   (props changed)
  user/attilio/vmcontention/sys/conf/   (props changed)
  user/attilio/vmcontention/sys/contrib/dev/acpica/   (props changed)
  user/attilio/vmcontention/sys/contrib/octeon-sdk/   (props changed)
  user/attilio/vmcontention/sys/contrib/pf/   (props changed)
  user/attilio/vmcontention/sys/contrib/x86emu/   (props changed)
  user/attilio/vmcontention/usr.bin/calendar/   (props changed)
  user/attilio/vmcontention/usr.bin/csup/   (props changed)
  user/attilio/vmcontention/usr.bin/procstat/   (props changed)
  user/attilio/vmcontention/usr.sbin/ndiscvt/   (props changed)
  user/attilio/vmcontention/usr.sbin/rtadvctl/   (props changed)
  user/attilio/vmcontention/usr.sbin/rtadvd/   (props changed)
  user/attilio/vmcontention/usr.sbin/rtsold/   (props changed)
  user/attilio/vmcontention/usr.sbin/zic/   (props changed)

Modified: user/attilio/vmcontention/etc/defaults/rc.conf
==============================================================================
--- user/attilio/vmcontention/etc/defaults/rc.conf	Sun Oct 23 21:37:01 2011	(r226674)
+++ user/attilio/vmcontention/etc/defaults/rc.conf	Sun Oct 23 23:04:39 2011	(r226675)
@@ -383,6 +383,7 @@ bsnmpd_flags=""			# Flags for bsnmpd.
 ### Network routing options: ###
 defaultrouter="NO"		# Set to default gateway (or NO).
 static_arp_pairs=""		# Set to static ARP list (or leave empty).
+static_ndp_pairs=""		# Set to static NDP list (or leave empty).
 static_routes=""		# Set to static route list (or leave empty).
 natm_static_routes=""		# Set to static route list for NATM (or leave empty).
 gateway_enable="NO"		# Set to YES if this host will be a gateway.

Modified: user/attilio/vmcontention/etc/network.subr
==============================================================================
--- user/attilio/vmcontention/etc/network.subr	Sun Oct 23 21:37:01 2011	(r226674)
+++ user/attilio/vmcontention/etc/network.subr	Sun Oct 23 23:04:39 2011	(r226675)
@@ -532,7 +532,7 @@ ipv4_up()
 
 	# Add 127.0.0.1/8 to lo0 unless otherwise specified.
 	if [ "${_if}" = "lo0" ]; then
-		ifconfig_args=`ifconfig_getargs ${_if}`
+		ifconfig_args=`get_if_var ${_if} ifconfig_IF`
 		if [ -z "${ifconfig_args}" ]; then
 			ifconfig ${_if} inet 127.0.0.1/8 alias
 		fi
@@ -556,7 +556,7 @@ ipv6_up()
 	fi
 
 	ifalias_up ${_if} inet6 && _ret=0
-	ipv6_prefix_hostid_addr_up ${_if} && _ret=0
+	ipv6_prefix_hostid_addr_common ${_if} alias && _ret=0
 	ipv6_accept_rtadv_up ${_if} && _ret=0
 
 	# wait for DAD
@@ -612,6 +612,7 @@ ipv6_down()
 	fi
 
 	ipv6_accept_rtadv_down ${_if} && _ret=0
+	ipv6_prefix_hostid_addr_common ${_if} -alias && _ret=0
 	ifalias_down ${_if} inet6 && _ret=0
 
 	inetList="`ifconfig ${_if} | grep 'inet6 ' | tr "\n" "$_ifs"`"
@@ -859,12 +860,14 @@ ifalias_ipv6_down()
 	return $_ret
 }
 
-# ipv6_prefix_hostid_addr_up if
-#	add IPv6 prefix + hostid addr to the interface $if
-ipv6_prefix_hostid_addr_up()
+# ipv6_prefix_hostid_addr_common if action
+#	Add or remove IPv6 prefix + hostid addr on the interface $if
+#
+ipv6_prefix_hostid_addr_common()
 {
-	local _if prefix laddr hostid j address
+	local _if _action prefix laddr hostid j address
 	_if=$1
+	_action=$2
 	prefix=`get_if_var ${_if} ipv6_prefix_IF`
 
 	if [ -n "${prefix}" ]; then
@@ -874,13 +877,13 @@ ipv6_prefix_hostid_addr_up()
 
 		for j in ${prefix}; do
 			address=$j\:${hostid}
-			ifconfig ${_if} inet6 ${address} prefixlen 64 alias
+			ifconfig ${_if} inet6 ${address} prefixlen 64 ${_action}
 
 			# if I am a router, add subnet router
 			# anycast address (RFC 2373).
 			if checkyesno ipv6_gateway_enable; then
 				ifconfig ${_if} inet6 $j:: prefixlen 64 \
-					alias anycast
+					${_action} anycast
 			fi
 		done
 	fi

Modified: user/attilio/vmcontention/etc/rc.d/Makefile
==============================================================================
--- user/attilio/vmcontention/etc/rc.d/Makefile	Sun Oct 23 21:37:01 2011	(r226674)
+++ user/attilio/vmcontention/etc/rc.d/Makefile	Sun Oct 23 23:04:39 2011	(r226675)
@@ -32,7 +32,7 @@ FILES=	DAEMON FILESYSTEMS LOGIN NETWORKI
 	random rarpd rctl resolv rfcomm_pppd_server root \
 	route6d routed routing rpcbind rtadvd rtsold rwho \
 	savecore sdpd securelevel sendmail \
-	serial sppp statd static_arp stf swap1 \
+	serial sppp statd static_arp static_ndp stf swap1 \
 	syscons sysctl syslogd \
 	timed tmp \
 	ugidfw \

Modified: user/attilio/vmcontention/etc/rc.d/NETWORKING
==============================================================================
--- user/attilio/vmcontention/etc/rc.d/NETWORKING	Sun Oct 23 21:37:01 2011	(r226674)
+++ user/attilio/vmcontention/etc/rc.d/NETWORKING	Sun Oct 23 23:04:39 2011	(r226675)
@@ -6,6 +6,7 @@
 # PROVIDE: NETWORKING NETWORK
 # REQUIRE: netif netoptions routing ppp ipfw stf faith
 # REQUIRE: defaultroute routed mrouted route6d mroute6d resolv bridge
+# REQUIRE: static_arp static_ndp
 
 #	This is a dummy dependency, for services which require networking
 #	to be operational before starting.

Copied: user/attilio/vmcontention/etc/rc.d/static_ndp (from r226674, head/etc/rc.d/static_ndp)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/attilio/vmcontention/etc/rc.d/static_ndp	Sun Oct 23 23:04:39 2011	(r226675, copy of r226674, head/etc/rc.d/static_ndp)
@@ -0,0 +1,74 @@
+#!/bin/sh
+#
+# Copyright (c) 2011  Xin Li <delphij@FreeBSD.org>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# Configure static NDP table
+#
+# $FreeBSD$
+#
+
+# PROVIDE: static_ndp
+# REQUIRE: netif
+# KEYWORD: nojail
+
+. /etc/rc.subr
+. /etc/network.subr
+
+name="static_ndp"
+start_cmd="static_ndp_start"
+stop_cmd="static_ndp_stop"
+
+static_ndp_start()
+{
+	local e ndp_args
+
+	if [ -n "${static_ndp_pairs}" ]; then
+		echo -n 'Binding static NDP pair(s):'
+		for e in ${static_ndp_pairs}; do
+			echo -n " ${e}"
+			eval ndp_args=\$static_ndp_${e}
+			ndp -s ${ndp_args} >/dev/null 2>&1
+		done
+		echo '.'
+	fi
+}
+
+static_ndp_stop()
+{
+	local e ndp_args
+
+	if [ -n "${static_ndp_pairs}" ]; then
+		echo -n 'Unbinding static NDP pair(s):'
+		for e in ${static_ndp_pairs}; do
+			echo -n " ${e}"
+			eval ndp_args=\$static_ndp_${e}
+			ndp -d ${ndp_args%%[ 	]*} > /dev/null 2>&1
+		done
+		echo '.'
+	fi
+}
+
+load_rc_config $name
+run_rc_command "$1"

Modified: user/attilio/vmcontention/share/man/man4/man4.powerpc/abtn.4
==============================================================================
--- user/attilio/vmcontention/share/man/man4/man4.powerpc/abtn.4	Sun Oct 23 21:37:01 2011	(r226674)
+++ user/attilio/vmcontention/share/man/man4/man4.powerpc/abtn.4	Sun Oct 23 23:04:39 2011	(r226675)
@@ -92,7 +92,7 @@ Examples are included in /etc/devd/apple
 .Xr adb 4 ,
 .Xr akbd 4 ,
 .Xr cuda 4 ,
-.Xr pmu 4,
+.Xr pmu 4 ,
 .Xr devd 8
 .Sh HISTORY
 The

Modified: user/attilio/vmcontention/share/man/man5/rc.conf.5
==============================================================================
--- user/attilio/vmcontention/share/man/man5/rc.conf.5	Sun Oct 23 21:37:01 2011	(r226674)
+++ user/attilio/vmcontention/share/man/man5/rc.conf.5	Sun Oct 23 23:04:39 2011	(r226675)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd September 13, 2011
+.Dd October 23, 2011
 .Dt RC.CONF 5
 .Os
 .Sh NAME
@@ -1423,6 +1423,11 @@ IPv6 functionality on an interface shoul
 .Va ifconfig_ Ns Ao Ar interface Ac Ns _ipv6 ,
 instead of setting ifconfig parameters in
 .Va ifconfig_ Ns Aq Ar interface .
+If this variable is empty, all of IPv6 configurations on the
+specified interface by other variables such as
+.Va ipv6_prefix_ Ns Ao Ar interface Ac
+will be ignored.
+.Pp
 Aliases should be set by
 .Va ifconfig_ Ns Ao Ar interface Ac Ns Va _alias Ns Aq Ar n
 with
@@ -1433,6 +1438,17 @@ ifconfig_ed0_ipv6="inet6 2001:db8:1::1 p
 ifconfig_ed0_alias0="inet6 2001:db8:2::1 prefixlen 64"
 .Ed
 .Pp
+Interfaces that have an
+.Dq Li inet6 accept_rtadv
+keyword in
+.Va ifconfig_ Ns Ao Ar interface Ac Ns _ipv6
+setting will be automatically configured by SLAAC
+.Pq StateLess Address AutoConfiguration
+described in
+.Rs
+.%T "RFC 4862"
+.Re
+.Pp
 Note that a link-local address will be automatically configured in
 addition to the configured global-scope addresses because the IPv6
 specifications require it on each link.
@@ -1457,19 +1473,32 @@ For example:
 .Bd -literal
 ifconfig_ed0_ipv6="inet6 fe80::1 prefixlen 64"
 .Ed
-.Pp
-Interfaces that have an
-.Dq Li inet6 accept_rtadv
-keyword in
-.Va ifconfig_ Ns Ao Ar interface Ac Ns _ipv6
-setting will be automatically configured by
-.Xr rtsol 8 .
 .It Va ipv6_prefix_ Ns Aq Ar interface
 .Pq Vt str
 If one or more prefixes are defined in
 .Va ipv6_prefix_ Ns Aq Ar interface
 addresses based on each prefix and the EUI-64 interface index will be
 configured on that interface.
+Note that this variable will be ignored when
+.Va ifconfig_ Ns Ao Ar interface Ac Ns _ipv6
+is empty.
+.Pp
+For example, the following configuration
+.Bd -literal
+ipv6_prefix_ed0="2001:db8:1:0 2001:db8:2:0"
+.Ed
+.Pp
+is equivalent to the following:
+.Bd -literal
+ifconfig_ed0_alias0="inet6 2001:db8:1:: eui64 prefixlen 64"
+ifconfig_ed0_alias1="inet6 2001:db8:1:: prefixlen 64 anycast"
+ifconfig_ed0_alias2="inet6 2001:db8:2:: eui64 prefixlen 64"
+ifconfig_ed0_alias3="inet6 2001:db8:2:: prefixlen 64 anycast"
+.Ed
+.Pp
+These Subnet-Router anycast addresses will be added only when
+.Va ipv6_gateway_enable
+is YES.
 .It Va ipv6_default_interface
 .Pq Vt str
 If not set to
@@ -2568,6 +2597,22 @@ For example
 static_arp_pairs="gw"
 static_arp_gw="192.168.1.1 00:01:02:03:04:05"
 .Ed
+.It Va static_ndp_pairs
+.Pq Vt str
+Set to the list of static NDP pairs that are to be added at system
+boot time.
+For each whitespace separated
+.Ar element
+in the value, a
+.Va static_ndp_ Ns Aq Ar element
+variable is assumed to exist whose contents will later be passed to a
+.Dq Nm ndp Cm -s
+operation.
+For example
+.Bd -literal
+static_ndp_pairs="gw"
+static_ndp_gw="2001:db8:3::1 00:01:02:03:04:05"
+.Ed
 .It Va static_routes
 .Pq Vt str
 Set to the list of static routes that are to be added at system

Modified: user/attilio/vmcontention/sys/conf/kern.mk
==============================================================================
--- user/attilio/vmcontention/sys/conf/kern.mk	Sun Oct 23 21:37:01 2011	(r226674)
+++ user/attilio/vmcontention/sys/conf/kern.mk	Sun Oct 23 23:04:39 2011	(r226675)
@@ -1,11 +1,21 @@
 # $FreeBSD$
 
+.if ${CC:T:Mclang} != "clang"
+FREEBSD_GCC!=	${CC} --version | grep FreeBSD || true
+.endif
+
 #
 # Warning flags for compiling the kernel and components of the kernel:
 #
+.if ${FREEBSD_GCC}
+# FreeBSD extensions, not available in upstream GCC
+format_extensions=	-fformat-extensions
+no_align_long_strings=	-mno-align-long-strings
+.endif
+
 CWARNFLAGS?=	-Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes \
 		-Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual \
-		-Wundef -Wno-pointer-sign -fformat-extensions \
+		-Wundef -Wno-pointer-sign ${format_extensions} \
 		-Wmissing-include-dirs -fdiagnostics-show-option
 #
 # The following flags are next up for working on:
@@ -32,7 +42,7 @@ CWARNFLAGS?=	-Wall -Wredundant-decls -Wn
 #
 .if ${MACHINE_CPUARCH} == "i386"
 .if ${CC:T:Mclang} != "clang"
-CFLAGS+=	-mno-align-long-strings -mpreferred-stack-boundary=2 -mno-sse
+CFLAGS+=	${no_align_long_strings} -mpreferred-stack-boundary=2 -mno-sse
 .else
 CFLAGS+=	-mno-aes -mno-avx
 .endif

Modified: user/attilio/vmcontention/sys/contrib/pf/net/if_pfsync.c
==============================================================================
--- user/attilio/vmcontention/sys/contrib/pf/net/if_pfsync.c	Sun Oct 23 21:37:01 2011	(r226674)
+++ user/attilio/vmcontention/sys/contrib/pf/net/if_pfsync.c	Sun Oct 23 23:04:39 2011	(r226675)
@@ -493,7 +493,7 @@ pfsync_clone_create(struct if_clone *ifc
 	ifp->if_mtu = 1500; /* XXX */
 #ifdef __FreeBSD__
 	callout_init(&sc->sc_tmo, CALLOUT_MPSAFE);
-	callout_init(&sc->sc_bulk_tmo, CALLOUT_MPSAFE);
+	callout_init_mtx(&sc->sc_bulk_tmo, &pf_task_mtx, 0);
 	callout_init(&sc->sc_bulkfail_tmo, CALLOUT_MPSAFE);
 #else
 	ifp->if_hardmtu = MCLBYTES; /* XXX */
@@ -540,7 +540,7 @@ pfsync_clone_destroy(struct ifnet *ifp)
 #ifdef __FreeBSD__
 	EVENTHANDLER_DEREGISTER(ifnet_departure_event, sc->sc_detachtag);
 #endif
-	timeout_del(&sc->sc_bulk_tmo);
+	timeout_del(&sc->sc_bulk_tmo);	/* XXX: need PF_LOCK() before */
 	timeout_del(&sc->sc_tmo);
 #if NCARP > 0
 #ifdef notyet
@@ -762,7 +762,7 @@ pfsync_state_import(struct pfsync_state 
 	if (flags & PFSYNC_SI_IOCTL)
 		pool_flags = PR_WAITOK | PR_ZERO;
 	else
-		pool_flags = PR_ZERO;
+		pool_flags = PR_NOWAIT | PR_ZERO;
 
 	if ((st = pool_get(&V_pf_state_pl, pool_flags)) == NULL)
 		goto cleanup;
@@ -856,7 +856,11 @@ pfsync_state_import(struct pfsync_state 
 		CLR(st->state_flags, PFSTATE_NOSYNC);
 		if (ISSET(st->state_flags, PFSTATE_ACK)) {
 			pfsync_q_ins(st, PFSYNC_S_IACK);
+#ifdef __FreeBSD__
+			pfsync_sendout();
+#else
 			schednetisr(NETISR_PFSYNC);
+#endif
 		}
 	}
 	CLR(st->state_flags, PFSTATE_ACK);
@@ -1312,7 +1316,11 @@ pfsync_in_upd(struct pfsync_pkt *pkt, st
 			V_pfsyncstats.pfsyncs_stale++;
 
 			pfsync_update_state(st);
+#ifdef __FreeBSD__
+			pfsync_sendout();
+#else
 			schednetisr(NETISR_PFSYNC);
+#endif
 			continue;
 		}
 		pfsync_alloc_scrub_memory(&sp->dst, &st->dst);
@@ -1418,7 +1426,11 @@ pfsync_in_upd_c(struct pfsync_pkt *pkt, 
 			V_pfsyncstats.pfsyncs_stale++;
 
 			pfsync_update_state(st);
+#ifdef __FreeBSD__
+			pfsync_sendout();
+#else
 			schednetisr(NETISR_PFSYNC);
+#endif
 			continue;
 		}
 		pfsync_alloc_scrub_memory(&up->dst, &st->dst);
@@ -1994,8 +2006,8 @@ pfsyncioctl(struct ifnet *ifp, u_long cm
 #endif
 				printf("pfsync: requesting bulk update\n");
 #ifdef __FreeBSD__
-				callout_reset(&sc->sc_bulkfail_tmo, 5 * hz,
-				    pfsync_bulk_fail, V_pfsyncif);
+			callout_reset(&sc->sc_bulkfail_tmo, 5 * hz,
+			    pfsync_bulk_fail, V_pfsyncif);
 #else
 			timeout_add_sec(&sc->sc_bulkfail_tmo, 5);
 #endif
@@ -2146,6 +2158,7 @@ pfsync_sendout(void)
 #endif
 #ifdef __FreeBSD__
 	size_t pktlen;
+	int dummy_error;
 #endif
 	int offset;
 	int q, count = 0;
@@ -2349,32 +2362,21 @@ pfsync_sendout(void)
 #ifdef __FreeBSD__
 	sc->sc_ifp->if_opackets++;
 	sc->sc_ifp->if_obytes += m->m_pkthdr.len;
+	sc->sc_len = PFSYNC_MINPKT;
+
+	IFQ_ENQUEUE(&sc->sc_ifp->if_snd, m, dummy_error);
+	schednetisr(NETISR_PFSYNC);
 #else
 	sc->sc_if.if_opackets++;
 	sc->sc_if.if_obytes += m->m_pkthdr.len;
-#endif
 
-	sc->sc_len = PFSYNC_MINPKT;
-#ifdef __FreeBSD__
-	PF_UNLOCK();
-#endif
 	if (ip_output(m, NULL, NULL, IP_RAWOUTPUT, &sc->sc_imo, NULL) == 0)
-#ifdef __FreeBSD__
-	{
-		PF_LOCK();
-#endif
-		V_pfsyncstats.pfsyncs_opackets++;
-#ifdef __FreeBSD__
-	}
-#endif
+		pfsyncstats.pfsyncs_opackets++;
 	else
-#ifdef __FreeBSD__
-	{
-		PF_LOCK();
-#endif
-		V_pfsyncstats.pfsyncs_oerrors++;
-#ifdef __FreeBSD__
-	}
+		pfsyncstats.pfsyncs_oerrors++;
+
+	/* start again */
+	sc->sc_len = PFSYNC_MINPKT;
 #endif
 }
 
@@ -2422,7 +2424,11 @@ pfsync_insert_state(struct pf_state *st)
 	pfsync_q_ins(st, PFSYNC_S_INS);
 
 	if (ISSET(st->state_flags, PFSTATE_ACK))
+#ifdef __FreeBSD__
+		pfsync_sendout();
+#else
 		schednetisr(NETISR_PFSYNC);
+#endif
 	else
 		st->sync_updates = 0;
 }
@@ -2619,7 +2625,11 @@ pfsync_update_state(struct pf_state *st)
 
 	if (sync || (time_second - st->pfsync_time) < 2) {
 		pfsync_upds++;
+#ifdef __FreeBSD__
+		pfsync_sendout();
+#else
 		schednetisr(NETISR_PFSYNC);
+#endif
 	}
 }
 
@@ -2670,7 +2680,11 @@ pfsync_request_update(u_int32_t creatori
 	TAILQ_INSERT_TAIL(&sc->sc_upd_req_list, item, ur_entry);
 	sc->sc_len += nlen;
 
+#ifdef __FreeBSD__
+	pfsync_sendout();
+#else
 	schednetisr(NETISR_PFSYNC);
+#endif
 }
 
 void
@@ -2699,7 +2713,11 @@ pfsync_update_state_req(struct pf_state 
 		pfsync_q_del(st);
 	case PFSYNC_S_NONE:
 		pfsync_q_ins(st, PFSYNC_S_UPD);
+#ifdef __FreeBSD__
+		pfsync_sendout();
+#else
 		schednetisr(NETISR_PFSYNC);
+#endif
 		return;
 
 	case PFSYNC_S_INS:
@@ -2986,16 +3004,6 @@ pfsync_bulk_start(void)
 	struct pfsync_softc *sc = pfsyncif;
 #endif
 
-	sc->sc_ureq_received = time_uptime;
-
-	if (sc->sc_bulk_next == NULL)
-#ifdef __FreeBSD__
-		sc->sc_bulk_next = TAILQ_FIRST(&V_state_list);
-#else
-		sc->sc_bulk_next = TAILQ_FIRST(&state_list);
-#endif
-	sc->sc_bulk_last = sc->sc_bulk_next;
-
 #ifdef __FreeBSD__
 	if (V_pf_status.debug >= PF_DEBUG_MISC)
 #else
@@ -3003,10 +3011,30 @@ pfsync_bulk_start(void)
 #endif
 		printf("pfsync: received bulk update request\n");
 
+#ifdef __FreeBSD__
 	PF_LOCK();
-	pfsync_bulk_status(PFSYNC_BUS_START);
-	pfsync_bulk_update(sc);
+	if (TAILQ_EMPTY(&V_state_list))
+#else
+	if (TAILQ_EMPTY(&state_list))
+#endif
+		pfsync_bulk_status(PFSYNC_BUS_END);
+	else {
+		sc->sc_ureq_received = time_uptime;
+		if (sc->sc_bulk_next == NULL)
+#ifdef __FreeBSD__
+			sc->sc_bulk_next = TAILQ_FIRST(&V_state_list);
+#else
+			sc->sc_bulk_next = TAILQ_FIRST(&state_list);
+#endif
+			sc->sc_bulk_last = sc->sc_bulk_next;
+
+			pfsync_bulk_status(PFSYNC_BUS_START);
+			callout_reset(&sc->sc_bulk_tmo, 1,
+			    pfsync_bulk_update, sc);
+	}
+#ifdef __FreeBSD__
 	PF_UNLOCK();
+#endif
 }
 
 void
@@ -3023,7 +3051,7 @@ pfsync_bulk_update(void *arg)
 #ifdef __FreeBSD__
 	CURVNET_SET(sc->sc_ifp->if_vnet);
 #endif
-	do {
+	for (;;) {
 		if (st->sync_state == PFSYNC_S_NONE &&
 		    st->timeout < PFTM_MAX &&
 		    st->pfsync_time <= sc->sc_ureq_received) {
@@ -3039,24 +3067,32 @@ pfsync_bulk_update(void *arg)
 			st = TAILQ_FIRST(&state_list);
 #endif
 
-		if (i > 0 && TAILQ_EMPTY(&sc->sc_qs[PFSYNC_S_UPD])) {
+		if (st == sc->sc_bulk_last) {
+			/* we're done */
+			sc->sc_bulk_next = NULL;
+			sc->sc_bulk_last = NULL;
+			pfsync_bulk_status(PFSYNC_BUS_END);
+			break;
+		}
+
+#ifdef __FreeBSD__
+		if (i > 1 && (sc->sc_ifp->if_mtu - sc->sc_len) <
+#else
+		if (i > 1 && (sc->sc_if.if_mtu - sc->sc_len) <
+#endif
+		    sizeof(struct pfsync_state)) {
+			/* we've filled a packet */
 			sc->sc_bulk_next = st;
 #ifdef __FreeBSD__
 			callout_reset(&sc->sc_bulk_tmo, 1,
-			    pfsync_bulk_fail, sc);
+			    pfsync_bulk_update, sc);
 #else
 			timeout_add(&sc->sc_bulk_tmo, 1);
 #endif
-			goto out;
+			break;
 		}
-	} while (st != sc->sc_bulk_last);
-
-	/* we're done */
-	sc->sc_bulk_next = NULL;
-	sc->sc_bulk_last = NULL;
-	pfsync_bulk_status(PFSYNC_BUS_END);
+	}
 
-out:
 #ifdef __FreeBSD__
 	CURVNET_RESTORE();
 #endif
@@ -3208,13 +3244,12 @@ pfsync_state_in_use(struct pf_state *st)
 	if (sc == NULL)
 		return (0);
 
-	if (st->sync_state != PFSYNC_S_NONE)
+	if (st->sync_state != PFSYNC_S_NONE ||
+	    st == sc->sc_bulk_next ||
+	    st == sc->sc_bulk_last)
 		return (1);
 
-	if (sc->sc_bulk_next == NULL && sc->sc_bulk_last == NULL)
-		return (0);
-
-	return (1);
+	return (0);
 }
 
 u_int pfsync_ints;
@@ -3253,37 +3288,38 @@ pfsync_timeout(void *arg)
 void
 #ifdef __FreeBSD__
 pfsyncintr(void *arg)
+{
+	struct pfsync_softc *sc = arg;
+	struct mbuf *m;
+
+	CURVNET_SET(sc->sc_ifp->if_vnet);
+	pfsync_ints++;
+
+	for (;;) {
+		IF_DEQUEUE(&sc->sc_ifp->if_snd, m);
+		if (m == 0)
+			break;
+
+		if (ip_output(m, NULL, NULL, IP_RAWOUTPUT, &sc->sc_imo, NULL)
+		    == 0)
+			V_pfsyncstats.pfsyncs_opackets++;
+		else
+			V_pfsyncstats.pfsyncs_oerrors++;
+	}
+	CURVNET_RESTORE();
+}
 #else
 pfsyncintr(void)
-#endif
 {
-#ifdef __FreeBSD__
-	struct pfsync_softc *sc = arg;
-#endif
 	int s;
 
-#ifdef __FreeBSD__
-	if (sc == NULL)
-		return;
-
-	CURVNET_SET(sc->sc_ifp->if_vnet);
-#endif
 	pfsync_ints++;
 
 	s = splnet();
-#ifdef __FreeBSD__
-	PF_LOCK();
-#endif
 	pfsync_sendout();
-#ifdef __FreeBSD__
-	PF_UNLOCK();
-#endif
 	splx(s);
-
-#ifdef __FreeBSD__
-	CURVNET_RESTORE();
-#endif
 }
+#endif
 
 int
 pfsync_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,

Modified: user/attilio/vmcontention/sys/contrib/pf/net/pfvar.h
==============================================================================
--- user/attilio/vmcontention/sys/contrib/pf/net/pfvar.h	Sun Oct 23 21:37:01 2011	(r226674)
+++ user/attilio/vmcontention/sys/contrib/pf/net/pfvar.h	Sun Oct 23 23:04:39 2011	(r226675)
@@ -222,7 +222,7 @@ struct pfi_dynaddr {
 #define	PF_NAME		"pf"
 
 #define	PR_NOWAIT	M_NOWAIT
-#define	PR_WAITOK	M_WAIT
+#define	PR_WAITOK	M_WAITOK
 #define	PR_ZERO		M_ZERO
 #define	pool_get(p, f)	uma_zalloc(*(p), (f))
 #define	pool_put(p, o)	uma_zfree(*(p), (o))

Modified: user/attilio/vmcontention/sys/geom/part/g_part_gpt.c
==============================================================================
--- user/attilio/vmcontention/sys/geom/part/g_part_gpt.c	Sun Oct 23 21:37:01 2011	(r226674)
+++ user/attilio/vmcontention/sys/geom/part/g_part_gpt.c	Sun Oct 23 23:04:39 2011	(r226675)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2002, 2005, 2006, 2007 Marcel Moolenaar
+ * Copyright (c) 2002, 2005-2007, 2011 Marcel Moolenaar
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -79,6 +79,7 @@ struct g_part_gpt_table {
 	struct gpt_hdr		*hdr;
 	quad_t			lba[GPT_ELT_COUNT];
 	enum gpt_state		state[GPT_ELT_COUNT];
+	int			bootcamp;
 };
 
 struct g_part_gpt_entry {
@@ -178,41 +179,165 @@ static struct uuid gpt_uuid_unused = GPT
 static struct g_part_uuid_alias {
 	struct uuid *uuid;
 	int alias;
+	int mbrtype;
 } gpt_uuid_alias_match[] = {
-	{ &gpt_uuid_apple_boot,		G_PART_ALIAS_APPLE_BOOT },
-	{ &gpt_uuid_apple_hfs,		G_PART_ALIAS_APPLE_HFS },
-	{ &gpt_uuid_apple_label,	G_PART_ALIAS_APPLE_LABEL },
-	{ &gpt_uuid_apple_raid,		G_PART_ALIAS_APPLE_RAID },
-	{ &gpt_uuid_apple_raid_offline,	G_PART_ALIAS_APPLE_RAID_OFFLINE },
-	{ &gpt_uuid_apple_tv_recovery,	G_PART_ALIAS_APPLE_TV_RECOVERY },
-	{ &gpt_uuid_apple_ufs,		G_PART_ALIAS_APPLE_UFS },
-	{ &gpt_uuid_bios_boot,		G_PART_ALIAS_BIOS_BOOT },
-	{ &gpt_uuid_efi, 		G_PART_ALIAS_EFI },
-	{ &gpt_uuid_freebsd,		G_PART_ALIAS_FREEBSD },
-	{ &gpt_uuid_freebsd_boot, 	G_PART_ALIAS_FREEBSD_BOOT },
-	{ &gpt_uuid_freebsd_swap,	G_PART_ALIAS_FREEBSD_SWAP },
-	{ &gpt_uuid_freebsd_ufs,	G_PART_ALIAS_FREEBSD_UFS },
-	{ &gpt_uuid_freebsd_vinum,	G_PART_ALIAS_FREEBSD_VINUM },
-	{ &gpt_uuid_freebsd_zfs,	G_PART_ALIAS_FREEBSD_ZFS },
-	{ &gpt_uuid_linux_data,		G_PART_ALIAS_LINUX_DATA },
-	{ &gpt_uuid_linux_lvm,		G_PART_ALIAS_LINUX_LVM },
-	{ &gpt_uuid_linux_raid,		G_PART_ALIAS_LINUX_RAID },
-	{ &gpt_uuid_linux_swap,		G_PART_ALIAS_LINUX_SWAP },
-	{ &gpt_uuid_mbr,		G_PART_ALIAS_MBR },
-	{ &gpt_uuid_ms_basic_data,	G_PART_ALIAS_MS_BASIC_DATA },
-	{ &gpt_uuid_ms_ldm_data,	G_PART_ALIAS_MS_LDM_DATA },
-	{ &gpt_uuid_ms_ldm_metadata,	G_PART_ALIAS_MS_LDM_METADATA },
-	{ &gpt_uuid_ms_reserved,	G_PART_ALIAS_MS_RESERVED },
-	{ &gpt_uuid_netbsd_ccd,		G_PART_ALIAS_NETBSD_CCD },
-	{ &gpt_uuid_netbsd_cgd,		G_PART_ALIAS_NETBSD_CGD },
-	{ &gpt_uuid_netbsd_ffs,		G_PART_ALIAS_NETBSD_FFS },
-	{ &gpt_uuid_netbsd_lfs,		G_PART_ALIAS_NETBSD_LFS },
-	{ &gpt_uuid_netbsd_raid,	G_PART_ALIAS_NETBSD_RAID },
-	{ &gpt_uuid_netbsd_swap,	G_PART_ALIAS_NETBSD_SWAP },
-
-	{ NULL, 0 }
+	{ &gpt_uuid_apple_boot,		G_PART_ALIAS_APPLE_BOOT,	 0xab },
+	{ &gpt_uuid_apple_hfs,		G_PART_ALIAS_APPLE_HFS,		 0xaf },
+	{ &gpt_uuid_apple_label,	G_PART_ALIAS_APPLE_LABEL,	 0 },
+	{ &gpt_uuid_apple_raid,		G_PART_ALIAS_APPLE_RAID,	 0 },
+	{ &gpt_uuid_apple_raid_offline,	G_PART_ALIAS_APPLE_RAID_OFFLINE, 0 },
+	{ &gpt_uuid_apple_tv_recovery,	G_PART_ALIAS_APPLE_TV_RECOVERY,	 0 },
+	{ &gpt_uuid_apple_ufs,		G_PART_ALIAS_APPLE_UFS,		 0 },
+	{ &gpt_uuid_bios_boot,		G_PART_ALIAS_BIOS_BOOT,		 0 },
+	{ &gpt_uuid_efi, 		G_PART_ALIAS_EFI,		 0xee },
+	{ &gpt_uuid_freebsd,		G_PART_ALIAS_FREEBSD,		 0xa5 },
+	{ &gpt_uuid_freebsd_boot, 	G_PART_ALIAS_FREEBSD_BOOT,	 0 },
+	{ &gpt_uuid_freebsd_swap,	G_PART_ALIAS_FREEBSD_SWAP,	 0 },
+	{ &gpt_uuid_freebsd_ufs,	G_PART_ALIAS_FREEBSD_UFS,	 0 },
+	{ &gpt_uuid_freebsd_vinum,	G_PART_ALIAS_FREEBSD_VINUM,	 0 },
+	{ &gpt_uuid_freebsd_zfs,	G_PART_ALIAS_FREEBSD_ZFS,	 0 },
+	{ &gpt_uuid_linux_data,		G_PART_ALIAS_LINUX_DATA,	 0x0b },
+	{ &gpt_uuid_linux_lvm,		G_PART_ALIAS_LINUX_LVM,		 0 },
+	{ &gpt_uuid_linux_raid,		G_PART_ALIAS_LINUX_RAID,	 0 },
+	{ &gpt_uuid_linux_swap,		G_PART_ALIAS_LINUX_SWAP,	 0 },
+	{ &gpt_uuid_mbr,		G_PART_ALIAS_MBR,		 0 },
+	{ &gpt_uuid_ms_basic_data,	G_PART_ALIAS_MS_BASIC_DATA,	 0x0b },
+	{ &gpt_uuid_ms_ldm_data,	G_PART_ALIAS_MS_LDM_DATA,	 0 },
+	{ &gpt_uuid_ms_ldm_metadata,	G_PART_ALIAS_MS_LDM_METADATA,	 0 },
+	{ &gpt_uuid_ms_reserved,	G_PART_ALIAS_MS_RESERVED,	 0 },
+	{ &gpt_uuid_netbsd_ccd,		G_PART_ALIAS_NETBSD_CCD,	 0 },
+	{ &gpt_uuid_netbsd_cgd,		G_PART_ALIAS_NETBSD_CGD,	 0 },
+	{ &gpt_uuid_netbsd_ffs,		G_PART_ALIAS_NETBSD_FFS,	 0 },
+	{ &gpt_uuid_netbsd_lfs,		G_PART_ALIAS_NETBSD_LFS,	 0 },
+	{ &gpt_uuid_netbsd_raid,	G_PART_ALIAS_NETBSD_RAID,	 0 },
+	{ &gpt_uuid_netbsd_swap,	G_PART_ALIAS_NETBSD_SWAP,	 0 },
+	{ NULL, 0, 0 }
 };
 
+static int
+gpt_write_mbr_entry(u_char *mbr, int idx, int typ, quad_t start,
+    quad_t end)
+{
+
+	if (typ == 0 || start > UINT32_MAX || end > UINT32_MAX)
+		return (EINVAL);
+
+	mbr += DOSPARTOFF + idx * DOSPARTSIZE;
+	mbr[0] = 0;
+	if (start == 1) {
+		/*
+		 * Treat the PMBR partition specially to maximize
+		 * interoperability with BIOSes.
+		 */
+		mbr[1] = mbr[3] = 0;
+		mbr[2] = 2;
+	} else
+		mbr[1] = mbr[2] = mbr[3] = 0xff;
+	mbr[4] = typ;
+	mbr[5] = mbr[6] = mbr[7] = 0xff;
+	le32enc(mbr + 8, (uint32_t)start);
+	le32enc(mbr + 12, (uint32_t)(end - start + 1));
+	return (0);
+}
+
+static int
+gpt_map_type(struct uuid *t)
+{
+	struct g_part_uuid_alias *uap;
+
+	for (uap = &gpt_uuid_alias_match[0]; uap->uuid; uap++) {
+		if (EQUUID(t, uap->uuid))
+			return (uap->mbrtype);
+	}
+	return (0);
+}
+
+/*
+ * Under Boot Camp the PMBR partition (type 0xEE) doesn't cover the
+ * whole disk anymore. Rather, it covers the GPT table and the EFI
+ * system partition only. This way the HFS+ partition and any FAT
+ * partitions can be added to the MBR without creating an overlap.
+ */
+static int
+gpt_is_bootcamp(struct g_part_gpt_table *table, const char *provname)
+{
+	uint8_t *p;
+
+	p = table->mbr + DOSPARTOFF;
+	if (p[4] != 0xee || le32dec(p + 8) != 1)
+		return (0);
+
+	p += DOSPARTSIZE;
+	if (p[4] != 0xaf)
+		return (0);
+
+	printf("GEOM: %s: enabling Boot Camp\n", provname);
+	return (1);
+}
+
+static void
+gpt_update_bootcamp(struct g_part_table *basetable)
+{
+	struct g_part_entry *baseentry;
+	struct g_part_gpt_entry *entry;
+	struct g_part_gpt_table *table;
+	int bootable, error, index, slices, typ;
+
+	table = (struct g_part_gpt_table *)basetable;
+
+	bootable = -1;
+	for (index = 0; index < NDOSPART; index++) {
+		if (table->mbr[DOSPARTOFF + DOSPARTSIZE * index])
+			bootable = index;
+	}
+
+	bzero(table->mbr + DOSPARTOFF, DOSPARTSIZE * NDOSPART);
+	slices = 0;
+	LIST_FOREACH(baseentry, &basetable->gpt_entry, gpe_entry) {
+		if (baseentry->gpe_deleted)
+			continue;
+		index = baseentry->gpe_index - 1;
+		if (index >= NDOSPART)
+			continue;
+
+		entry = (struct g_part_gpt_entry *)baseentry;
+
+		switch (index) {
+		case 0:	/* This must be the EFI system partition. */
+			if (!EQUUID(&entry->ent.ent_type, &gpt_uuid_efi))
+				goto disable;
+			error = gpt_write_mbr_entry(table->mbr, index, 0xee,
+			    1ull, entry->ent.ent_lba_end);
+			break;
+		case 1:	/* This must be the HFS+ partition. */
+			if (!EQUUID(&entry->ent.ent_type, &gpt_uuid_apple_hfs))
+				goto disable;
+			error = gpt_write_mbr_entry(table->mbr, index, 0xaf,
+			    entry->ent.ent_lba_start, entry->ent.ent_lba_end);
+			break;
+		default:
+			typ = gpt_map_type(&entry->ent.ent_type);
+			error = gpt_write_mbr_entry(table->mbr, index, typ,
+			    entry->ent.ent_lba_start, entry->ent.ent_lba_end);
+			break;
+		}
+		if (error)
+			continue;
+
+		if (index == bootable)
+			table->mbr[DOSPARTOFF + DOSPARTSIZE * index] = 0x80;
+		slices |= 1 << index;
+	}
+	if ((slices & 3) == 3)
+		return;
+
+ disable:
+	table->bootcamp = 0;
+	bzero(table->mbr + DOSPARTOFF, DOSPARTSIZE * NDOSPART);
+	gpt_write_mbr_entry(table->mbr, 0, 0xee, 1ull,
+	    MIN(table->lba[GPT_ELT_SECHDR], UINT32_MAX));
+}
+
 static struct gpt_hdr *
 gpt_read_hdr(struct g_part_gpt_table *table, struct g_consumer *cp,
     enum gpt_elt elt)
@@ -457,8 +582,9 @@ g_part_gpt_bootcode(struct g_part_table 
 	if (codesz > 0)
 		bcopy(gpp->gpp_codeptr, table->mbr, codesz);
 
-	/* Mark the PMBR active since some BIOS require it */
-	table->mbr[DOSPARTOFF] = 0x80;		/* status */
+	/* Mark the PMBR active since some BIOS require it. */
+	if (!table->bootcamp)
+		table->mbr[DOSPARTOFF] = 0x80;		/* status */
 	return (0);
 }
 
@@ -486,15 +612,7 @@ g_part_gpt_create(struct g_part_table *b
 	last = (pp->mediasize / pp->sectorsize) - 1;
 
 	le16enc(table->mbr + DOSMAGICOFFSET, DOSMAGIC);
-	table->mbr[DOSPARTOFF + 1] = 0x01;		/* shd */
-	table->mbr[DOSPARTOFF + 2] = 0x01;		/* ssect */
-	table->mbr[DOSPARTOFF + 3] = 0x00;		/* scyl */
-	table->mbr[DOSPARTOFF + 4] = 0xee;		/* typ */
-	table->mbr[DOSPARTOFF + 5] = 0xff;		/* ehd */
-	table->mbr[DOSPARTOFF + 6] = 0xff;		/* esect */
-	table->mbr[DOSPARTOFF + 7] = 0xff;		/* ecyl */
-	le32enc(table->mbr + DOSPARTOFF + 8, 1);	/* start */
-	le32enc(table->mbr + DOSPARTOFF + 12, MIN(last, UINT32_MAX));
+	gpt_write_mbr_entry(table->mbr, 0, 0xee, 1, MIN(last, UINT32_MAX));
 
 	/* Allocate space for the header */
 	table->hdr = g_malloc(sizeof(struct gpt_hdr), M_WAITOK | M_ZERO);
@@ -802,6 +920,21 @@ g_part_gpt_read(struct g_part_table *bas
 	}
 
 	g_free(tbl);
+
+	/*
+	 * Under Mac OS X, the MBR mirrors the first 4 GPT partitions
+	 * if (and only if) any FAT32 or FAT16 partitions have been
+	 * created. This happens irrespective of whether Boot Camp is
+	 * used/enabled, though it's generally understood to be done
+	 * to support legacy Windows under Boot Camp. We refer to this
+	 * mirroring simply as Boot Camp. We try to detect Boot Camp
+	 * so that we can update the MBR if and when GPT changes have
+	 * been made. Note that we do not enable Boot Camp if not
+	 * previously enabled because we can't assume that we're on a
+	 * Mac alongside Mac OS X.
+	 */
+	table->bootcamp = gpt_is_bootcamp(table, pp->name);
+
 	return (0);
 }
 
@@ -816,73 +949,52 @@ g_part_gpt_recover(struct g_part_table *
 }
 
 static int
-g_part_gpt_setunset(struct g_part_table *table, struct g_part_entry *baseentry,
-    const char *attrib, unsigned int set)
+g_part_gpt_setunset(struct g_part_table *basetable,
+    struct g_part_entry *baseentry, const char *attrib, unsigned int set)
 {
-	struct g_part_entry *iter;
 	struct g_part_gpt_entry *entry;
-	int changed, bootme, bootonce, bootfailed;
+	struct g_part_gpt_table *table;
+	uint64_t attr;
+	int i;
 
-	bootme = bootonce = bootfailed = 0;
+	table = (struct g_part_gpt_table *)basetable;
+	entry = (struct g_part_gpt_entry *)baseentry;
+
+	if (strcasecmp(attrib, "active") == 0) {
+		if (!table->bootcamp || baseentry->gpe_index > NDOSPART)
+			return (EINVAL);
+		for (i = 0; i < NDOSPART; i++) {
+			table->mbr[DOSPARTOFF + i * DOSPARTSIZE] =
+			    (i == baseentry->gpe_index - 1) ? 0x80 : 0;
+		}
+		return (0);
+	}
+
+	attr = 0;
 	if (strcasecmp(attrib, "bootme") == 0) {
-		bootme = 1;
+		attr |= GPT_ENT_ATTR_BOOTME;
 	} else if (strcasecmp(attrib, "bootonce") == 0) {
-		/* BOOTME is set automatically with BOOTONCE, but not unset. */
-		bootonce = 1;
+		attr |= GPT_ENT_ATTR_BOOTONCE;
 		if (set)
-			bootme = 1;
+			attr |= GPT_ENT_ATTR_BOOTME;
 	} else if (strcasecmp(attrib, "bootfailed") == 0) {
 		/*
 		 * It should only be possible to unset BOOTFAILED, but it might
 		 * be useful for test purposes to also be able to set it.
 		 */
-		bootfailed = 1;
+		attr |= GPT_ENT_ATTR_BOOTFAILED;
 	}
-	if (!bootme && !bootonce && !bootfailed)

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201110232304.p9NN4erT060588>