From owner-freebsd-arch@FreeBSD.ORG Sun Mar 6 07:42:21 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7B33116A4CE for ; Sun, 6 Mar 2005 07:42:21 +0000 (GMT) Received: from ylpvm01.prodigy.net (ylpvm01-ext.prodigy.net [207.115.57.32]) by mx1.FreeBSD.org (Postfix) with ESMTP id 03FE343D2F for ; Sun, 6 Mar 2005 07:42:21 +0000 (GMT) (envelope-from nate@root.org) Received: from [10.0.5.51] (adsl-64-171-186-189.dsl.snfc21.pacbell.net [64.171.186.189])j267gJ0i023492 for ; Sun, 6 Mar 2005 02:42:19 -0500 Message-ID: <422AB45A.9040809@root.org> Date: Sat, 05 Mar 2005 23:42:18 -0800 From: Nate Lawson User-Agent: Mozilla Thunderbird 1.0RC1 (X11/20041205) X-Accept-Language: en-us, en MIME-Version: 1.0 To: arch@freebsd.org Content-Type: multipart/mixed; boundary="------------010002050708010508050009" Subject: patch: clean up msdosfs conversion routine X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Mar 2005 07:42:21 -0000 This is a multi-part message in MIME format. --------------010002050708010508050009 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit The attached patch optimizes the unix2win conversion routine. It uses 16 bit accesses instead of 8 bit and jumps to "out" once it hits the trailing NUL rather than drop through each loop. I'd like to make sure my use of the endian routines is correct, if someone can check this. Thanks, -- Nate --------------010002050708010508050009 Content-Type: text/plain; name="msd1.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="msd1.diff" Index: msdosfs_conv.c =================================================================== RCS file: /home/ncvs/src/sys/fs/msdosfs/msdosfs_conv.c,v retrieving revision 1.39 diff -u -r1.39 msdosfs_conv.c --- msdosfs_conv.c 8 Feb 2005 07:51:14 -0000 1.39 +++ msdosfs_conv.c 2 Mar 2005 17:48:52 -0000 @@ -52,6 +52,7 @@ * System include files. */ #include +#include #include #include /* defines tz */ #include @@ -708,9 +711,8 @@ int chksum; struct msdosfsmount *pmp; { - u_int8_t *wcp; - int i, end; - u_int16_t code; + u_int16_t *wcp; + int end, i; /* * Drop trailing blanks and dots @@ -726,7 +728,7 @@ /* * Initialize winentry to some useful default */ - for (wcp = (u_int8_t *)wep, i = sizeof(*wep); --i >= 0; *wcp++ = 0xff); + memset(wep, 0xff, sizeof(*wep)); wep->weCnt = cnt; wep->weAttributes = ATTR_WIN95; wep->weReserved1 = 0; @@ -737,29 +739,34 @@ * Now convert the filename parts */ end = 0; - for (wcp = wep->wePart1, i = sizeof(wep->wePart1)/2; --i >= 0 && !end;) { - code = unix2winchr(&un, &unlen, 0, pmp); - *wcp++ = code; - *wcp++ = code >> 8; - if (!code) + wcp = (uint16_t *)wep->wePart1; + for (i = sizeof(wep->wePart1)/2; --i >= 0;) { + *wcp = htole16(unix2winchr(&un, &unlen, 0, pmp)); + if (*wcp++ == 0) { end = WIN_LAST; + goto out; + } } - for (wcp = wep->wePart2, i = sizeof(wep->wePart2)/2; --i >= 0 && !end;) { - code = unix2winchr(&un, &unlen, 0, pmp); - *wcp++ = code; - *wcp++ = code >> 8; - if (!code) + wcp = (uint16_t *)wep->wePart2; + for (i = sizeof(wep->wePart2)/2; --i >= 0;) { + *wcp = htole16(unix2winchr(&un, &unlen, 0, pmp)); + if (*wcp++ == 0) { end = WIN_LAST; + goto out; + } } - for (wcp = wep->wePart3, i = sizeof(wep->wePart3)/2; --i >= 0 && !end;) { - code = unix2winchr(&un, &unlen, 0, pmp); - *wcp++ = code; - *wcp++ = code >> 8; - if (!code) + wcp = (uint16_t *)wep->wePart3; + for (i = sizeof(wep->wePart3)/2; --i >= 0;) { + *wcp = htole16(unix2winchr(&un, &unlen, 0, pmp)); + if (*wcp++ == 0) { end = WIN_LAST; + goto out; + } } if (*un == '\0') end = WIN_LAST; + +out: wep->weCnt |= end; return !end; } --------------010002050708010508050009--