From kwhite@uottawa.ca  Wed May  7 11:30:03 2014
Return-Path: <kwhite@uottawa.ca>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id 1F4E4141
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  7 May 2014 11:30:03 +0000 (UTC)
Received: from smtp2.vianet.ca (smtp2.vianet.ca [209.91.128.19])
	by mx1.freebsd.org (Postfix) with ESMTP id ED4D4BB5
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  7 May 2014 11:30:02 +0000 (UTC)
Received: from localhost.my.domain (unused-69-60-246-88.vianet.ca [69.60.246.88])
	by smtp2.vianet.ca (Postfix) with ESMTPS id 779C315BE7B
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  7 May 2014 07:20:36 -0400 (EDT)
Received: from localhost.my.domain (localhost [127.0.0.1])
	by localhost.my.domain (8.14.8/8.14.8) with ESMTP id s47BC2Rj012682
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO)
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 7 May 2014 07:12:02 -0400 (EDT)
	(envelope-from kwhite@localhost.my.domain)
Received: (from root@localhost)
	by localhost.my.domain (8.14.8/8.14.8/Submit) id s47BC2t6012681;
	Wed, 7 May 2014 07:12:02 -0400 (EDT)
	(envelope-from kwhite)
Message-Id: <201405071112.s47BC2t6012681@localhost.my.domain>
Date: Wed, 7 May 2014 07:12:02 -0400 (EDT)
From: Keith White <kwhite@uottawa.ca>
Reply-To: Keith White <kwhite@uottawa.ca>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Keith White <kwhite@uottawa.ca>
Subject: [patch] mount_smbfs missing from arm
X-Send-Pr-Version: 3.114
X-GNATS-Notify:

>Number:         189415
>Category:       arm
>Synopsis:       [patch] mount_smbfs missing from arm
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-arm
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed May 07 11:40:00 UTC 2014
>Closed-Date:
>Last-Modified:
>Originator:     Keith White
>Release:        FreeBSD 11.0-CURRENT arm
>Organization:
Faculty of Engineering, University of Ottawa
>Environment:
System: FreeBSD beaglebone 11.0-CURRENT FreeBSD 11.0-CURRENT #46 r265404M: Mon May 5 19:27:21 EDT 2014 root@beaglebone:/usr/obj/usr/src/sys/BEAGLEBONE arm

>Description:

mount_smbfs is not included with base arm builds since libsmb uses
casts to u_short that result in unaligned access to memory.

Patch attached.

>How-To-Repeat:

>Fix:

The following patch replaces potential unaligned access in libsmb
with a function call to the internal function memsetw(), and adds
libsmb and mount_smbfs to the base build.


Index: contrib/smbfs/lib/smb/nb_name.c
===================================================================
--- contrib/smbfs/lib/smb/nb_name.c	(revision 265468)
+++ contrib/smbfs/lib/smb/nb_name.c	(working copy)
@@ -146,14 +146,26 @@
 #define	NBENCODE(c)	(htole16((u_short)(((u_char)(c) >> 4) | \
 			 (((u_char)(c) & 0xf) << 8)) + 0x4141))
 
+#ifdef __arm__
 static void
 memsetw(char *dst, int n, u_short word)
 {
 	while (n--) {
+		((u_char*)dst)[0] = word & 0xff;
+		((u_char*)dst)[1] = word >> 8;
+		dst += 2;
+	}
+}
+#else
+static void
+memsetw(char *dst, int n, u_short word)
+{
+	while (n--) {
 		*(u_short*)dst = word;
 		dst += 2;
 	}
 }
+#endif
 
 int
 nb_name_encode(struct nb_name *np, u_char *dst)
@@ -165,18 +177,30 @@
 	*cp++ = NB_ENCNAMELEN;
 	name = np->nn_name;
 	if (name[0] == '*' && name[1] == 0) {
+#ifdef __arm__
+		memsetw(cp, 1, NBENCODE('*'));
+#else
 		*(u_short*)cp = NBENCODE('*');
+#endif
 		memsetw(cp + 2, NB_NAMELEN - 1, NBENCODE(' '));
 		cp += NB_ENCNAMELEN;
 	} else {
 		for (i = 0; *name && i < NB_NAMELEN - 1; i++, cp += 2, name++)
+#ifdef __arm__
+			memsetw(cp, 1, NBENCODE(toupper(*name)));
+#else
 			*(u_short*)cp = NBENCODE(toupper(*name));
+#endif
 		i = NB_NAMELEN - i - 1;
 		if (i > 0) {
 			memsetw(cp, i, NBENCODE(' '));
 			cp += i * 2;
 		}
+#ifdef __arm__
+		memsetw(cp, 1, NBENCODE(np->nn_type));
+#else
 		*(u_short*)cp = NBENCODE(np->nn_type);
+#endif
 		cp += 2;
 	}
 	*cp = 0;
Index: lib/Makefile
===================================================================
--- lib/Makefile	(revision 265468)
+++ lib/Makefile	(working copy)
@@ -217,6 +217,10 @@
 _libvmmapi=	libvmmapi
 .endif
 
+.if ${MACHINE_CPUARCH} == "arm"
+_libsmb=	libsmb
+.endif
+
 .if ${MACHINE_CPUARCH} == "ia64"
 _libefi=	libefi
 _libsmb=	libsmb
Index: usr.sbin/Makefile.arm
===================================================================
--- usr.sbin/Makefile.arm	(revision 265468)
+++ usr.sbin/Makefile.arm	(working copy)
@@ -2,3 +2,4 @@
 
 SUBDIR+=	ofwdump
 SUBDIR+=	kgmon
+SUBDIR+=	mount_smbfs

>Release-Note:
>Audit-Trail:
>Unformatted:
