From nobody@FreeBSD.org  Tue Sep 27 23:34:35 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id CA34416A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 27 Sep 2005 23:34:35 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 7D0F843D48
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 27 Sep 2005 23:34:35 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j8RNYZPL057325
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 27 Sep 2005 23:34:35 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id j8RNYZvK057324;
	Tue, 27 Sep 2005 23:34:35 GMT
	(envelope-from nobody)
Message-Id: <200509272334.j8RNYZvK057324@www.freebsd.org>
Date: Tue, 27 Sep 2005 23:34:35 GMT
From: Micah Lieske <micahjon@ywave.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] msdosfs incorrectly handles NT 8.3 capitalization
X-Send-Pr-Version: www-2.3

>Number:         86655
>Category:       kern
>Synopsis:       [msdosfs] [patch] msdosfs incorrectly handles NT 8.3 capitalization
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 27 23:40:16 GMT 2005
>Closed-Date:    Tue Dec 19 19:16:22 GMT 2006
>Last-Modified:  Tue Dec 19 19:16:22 GMT 2006
>Originator:     Micah Lieske
>Release:        5.4-RELEASE-p7
>Organization:
>Environment:
FreeBSD trisha.eidolonworld 5.4-RELEASE-p7 FreeBSD 5.4-RELEASE-p7 #0: Fri Sep  9 19:10:20 PDT 2005     root@trisha.eidolonworld:/usr/obj/usr/src/sys/TRISHA  i386

>Description:
If I create the files a.txt, B.txt, C.TXT and d.TXT in Win2K or XP (and probably any NT based windows) on a FAT partition or floppy an ls in FreeBSD will display the names as a.txt, b.txt, C.TXT, and d.txt.  This only applies to files that fit the 8.3 limitations and doesn't apply to long file names.
>How-To-Repeat:
Create the files named above in an NT based windows and save to a FAT partion or floppy disk.  Mount the partition/disk in FreeBSD and do an ls.

>Fix:
The functions dos2unixfn calls dos2unixchr seperately for the base name and the extension but passes dos2unixchr the capitalization flags for both base and extension.  The following patch passes only LCASE_BASE when converting the base, and LCASE_EXT when converting the extension.  Contact me if this form mangled the patch too much (sorry, not sure how I should attach it using the web form).

--- msdosfs_conv.c      Tue Sep 27 14:41:06 2005
+++ msdosfs_conv.patch.c        Tue Sep 27 16:29:54 2005
@@ -436,7 +436,7 @@
         * Copy the name portion into the unix filename string.
         */
        for (i = 8; i > 0 && *dn != ' ';) {
-               c = dos2unixchr((const u_char **)&dn, &i, lower, pmp);
+               c = dos2unixchr((const u_char **)&dn, &i, lower & LCASE_BASE, pmp);
                if (c & 0xff00) {
                        *un++ = c >> 8;
                        thislong++;
@@ -454,7 +454,7 @@
                *un++ = '.';
                thislong++;
                for (i = 3; i > 0 && *dn != ' ';) {
-                       c = dos2unixchr((const u_char **)&dn, &i, lower, pmp);
+                       c = dos2unixchr((const u_char **)&dn, &i, lower & LCASE_EXT, pmp);
                        if (c & 0xff00) {
                                *un++ = c >> 8;
                                thislong++;

>Release-Note:
>Audit-Trail:

From: Maxim Konovalov <maxim@macomnet.ru>
To: Micah Lieske <micahjon@ywave.com>
Cc: bug-followup@freebsd.org
Subject: kern/86655
Date: Sun, 26 Nov 2006 20:20:29 +0300 (MSK)

 Hi Micah,
 
 I failed to see how your patch changes dos2unixchr() code path.  It
 seems it does the same things for any combinations of LCASE_* flags.
 Perhaps I'm just blind.  Could you explain your patch further?
 
 --
 Maxim Konovalov

From: Micah <micahjon@ywave.com>
To: Maxim Konovalov <maxim@macomnet.ru>
Cc: bug-followup@freebsd.org
Subject: Re: kern/86655
Date: Sun, 26 Nov 2006 10:25:50 -0800

 Maxim Konovalov wrote:
 > Hi Micah,
 > 
 > I failed to see how your patch changes dos2unixchr() code path.  It
 > seems it does the same things for any combinations of LCASE_* flags.
 > Perhaps I'm just blind.  Could you explain your patch further?
 > 
 > --
 > Maxim Konovalov
 
 Oh, it's been a while, let me examine it...
 
 In dos2unixfn, lower comes from direntry.deLowerCase. deLowerCase is 
 byte 0x0c in the FAT dir entry that has two flags. One flag (bit  3) 
 determines the "case" of the 8 character filename, the other flag (bit 
 4) determines the "case" of the 3 character extension. Wikipedia has a 
 good summary of this: 
 http://en.wikipedia.org/wiki/File_Allocation_Table#Directory_table
 
 Now for the code path:
 dos2unixchr will convert to lower case if LCASE_BASE or LCASE_EXT or 
 both are set. But dos2unixfn uses dos2unixchr separately for the 
 basename and the extension. So if either LCASE_BASE or LCASE_EXT is set, 
 dos2unixfn will convert both the basename and extension to lowercase 
 because it is blindly passing in the state of both flags to dos2unixchr. 
 The bit masks I used ensure that only the state of LCASE_BASE gets 
 passed to dos2unixchr when the basename is converted, and only the state 
 of LCASE_EXT is passed in when the extension is converted.
 
 Here's an example run:
 
 In the original:
 dosfn=TEST.TXT
 lower=LCASE_EXT (meaning the filename should be TEST.txt)
 unixfn=""
 When dos2unixfn executes the first call to dos2unixchr, dos2unixchr will 
 see that LCASE_EXT is set and convert the basename to lowercase:
 unixfn="test"
 When dos2unixfn executes the second call to dos2unixchr, dos2unixchr 
 will see that LCASE_EXT is set and convert the extension to lowercase:
 unixfn="test.txt" != "TEST.txt"
 
 In the patch:
 dosfn=TEST.TXT
 lower=LCASE_EXT (meaning the filename should be TEST.txt)
 unixfn=""
 When dos2unixfn executes the first call to dos2unixchr, dos2unixfn will 
 mask out all bits of lower but LCASE_BASE, dos2unixchr will see that no 
 bits are set and leave the basename as uppercase:
 unixfn="TEST"
 When dos2unixfn executes the second call to dos2unixchr, dos2unixfn will 
 mask out all bits of lower but LCASE_EXT, dos2unixchr will see that 
 LCASE_EXT is set and convert the extension to lowercase:
 unixfn="TEST.txt" == "TEST.txt"
 
 Does that help, or did I miss something completely when I wrote the patch?
 
 - Micah

From: Maxim Konovalov <maxim@macomnet.ru>
To: Micah <micahjon@ywave.com>
Cc: bug-followup@freebsd.org, mato <gamato@users.sourceforge.net>
Subject: Re: kern/86655
Date: Sun, 26 Nov 2006 21:36:57 +0300 (MSK)

 On Sun, 26 Nov 2006, 10:25-0800, Micah wrote:
 
 > Maxim Konovalov wrote:
 > > Hi Micah,
 > >
 > > I failed to see how your patch changes dos2unixchr() code path.  It
 > > seems it does the same things for any combinations of LCASE_* flags.
 > > Perhaps I'm just blind.  Could you explain your patch further?
 > >
 > > --
 > > Maxim Konovalov
 >
 > Oh, it's been a while, let me examine it...
 >
 > In dos2unixfn, lower comes from direntry.deLowerCase. deLowerCase is
 > byte 0x0c in the FAT dir entry that has two flags. One flag (bit 3)
 > determines the "case" of the 8 character filename, the other flag
 > (bit 4) determines the "case" of the 3 character extension.
 > Wikipedia has a good summary of this:
 > http://en.wikipedia.org/wiki/File_Allocation_Table#Directory_table
 >
 > Now for the code path: dos2unixchr will convert to lower case if
 > LCASE_BASE or LCASE_EXT or both are set. But dos2unixfn uses
 > dos2unixchr separately for the basename and the extension. So if
 > either LCASE_BASE or LCASE_EXT is set, dos2unixfn will convert both
 > the basename and extension to lowercase because it is blindly
 > passing in the state of both flags to dos2unixchr. The bit masks I
 > used ensure that only the state of LCASE_BASE gets passed to
 > dos2unixchr when the basename is converted, and only the state of
 > LCASE_EXT is passed in when the extension is converted.
 >
 > Here's an example run:
 >
 > In the original:
 > dosfn=TEST.TXT
 > lower=LCASE_EXT (meaning the filename should be TEST.txt)
 > unixfn=""
 > When dos2unixfn executes the first call to dos2unixchr, dos2unixchr will see
 > that LCASE_EXT is set and convert the basename to lowercase:
 > unixfn="test"
 > When dos2unixfn executes the second call to dos2unixchr, dos2unixchr will see
 > that LCASE_EXT is set and convert the extension to lowercase:
 > unixfn="test.txt" != "TEST.txt"
 >
 > In the patch:
 > dosfn=TEST.TXT
 > lower=LCASE_EXT (meaning the filename should be TEST.txt)
 > unixfn=""
 > When dos2unixfn executes the first call to dos2unixchr, dos2unixfn will mask
 > out all bits of lower but LCASE_BASE, dos2unixchr will see that no bits are
 > set and leave the basename as uppercase:
 > unixfn="TEST"
 > When dos2unixfn executes the second call to dos2unixchr, dos2unixfn will mask
 > out all bits of lower but LCASE_EXT, dos2unixchr will see that LCASE_EXT is
 > set and convert the extension to lowercase:
 > unixfn="TEST.txt" == "TEST.txt"
 >
 > Does that help, or did I miss something completely when I wrote the
 > patch?
 
 Yes, everything is clear now.  Thanks, Micah!
 
 -- 
 Maxim Konovalov

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/86655: commit references a PR
Date: Sun, 26 Nov 2006 18:49:50 +0000 (UTC)

 maxim       2006-11-26 18:49:44 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/fs/msdosfs       msdosfs_conv.c 
   Log:
   o From the submitter: dos2unixchr will convert to lower case if
   LCASE_BASE or LCASE_EXT or both are set.  But dos2unixfn uses
   dos2unixchr separately for the basename and the extension.  So if
   either LCASE_BASE or LCASE_EXT is set, dos2unixfn will convert both
   the basename and extension to lowercase because it is blindly
   passing in the state of both flags to dos2unixchr.  The bit masks I
   used ensure that only the state of LCASE_BASE gets passed to
   dos2unixchr when the basename is converted, and only the state of
   LCASE_EXT is passed in when the extension is converted.
   
   PR:             kern/86655
   Submitted by:   Micah Lieske
   MFC after:      3 weeks
   
   Revision  Changes    Path
   1.50      +4 -2      src/sys/fs/msdosfs/msdosfs_conv.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: maxim 
State-Changed-When: Sun Nov 26 18:57:32 UTC 2006 
State-Changed-Why:  
Fixed in HEAD.  Thanks for the submission! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=86655 
State-Changed-From-To: patched->closed 
State-Changed-By: maxim 
State-Changed-When: Tue Dec 19 19:15:59 UTC 2006 
State-Changed-Why:  
Merged to RELENG_6. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=86655 
>Unformatted:
