patch: clean up msdosfs conversion routine
From: Nate Lawson (nate_at_root.org)
Date: 03/06/05
- Previous message: Sam Cole: "Re: FreeBSD for Macs?"
- Next in thread: Ryan Sommers: "Re: patch: clean up msdosfs conversion routine"
- Reply: Ryan Sommers: "Re: patch: clean up msdosfs conversion routine"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 05 Mar 2005 23:42:18 -0800 To: arch@freebsd.org
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
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 <sys/param.h>
+#include <sys/endian.h>
#include <sys/time.h>
#include <sys/kernel.h> /* defines tz */
#include <sys/systm.h>
@@ -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;
}
_______________________________________________
freebsd-arch@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
- Previous message: Sam Cole: "Re: FreeBSD for Macs?"
- Next in thread: Ryan Sommers: "Re: patch: clean up msdosfs conversion routine"
- Reply: Ryan Sommers: "Re: patch: clean up msdosfs conversion routine"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]