From nobody@FreeBSD.org  Tue Jan 16 12:16:13 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 770CA37B699
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 16 Jan 2001 12:16:13 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.1/8.11.1) id f0GKGCU11053;
	Tue, 16 Jan 2001 12:16:12 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200101162016.f0GKGCU11053@freefall.freebsd.org>
Date: Tue, 16 Jan 2001 12:16:12 -0800 (PST)
From: semenu@FreeBSD.org
To: freebsd-gnats-submit@FreeBSD.org
Subject: Patch to msdosfs to handle a kind of incorrect filesystems
X-Send-Pr-Version: www-1.0

>Number:         24393
>Category:       kern
>Synopsis:       Patch to msdosfs to handle a kind of incorrect filesystems
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    trhodes
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jan 16 12:20:04 PST 2001
>Closed-Date:    Thu Aug 22 09:21:01 PDT 2002
>Last-Modified:  Thu Aug 22 09:21:01 PDT 2002
>Originator:     Semen A. Ustimenko
>Release:        4.2-RELEASE
>Organization:
>Environment:
FreeBSD dev.the.net 4.2-RELEASE FreeBSD 4.2-RELEASE #3: Tue Dec 12 15:23:17 GMT+6 2000     root@default.the.net:/usr/src/sys/compile/DEFAULT  i386

>Description:
There are sometimes a FAT filesystems not handled correctly by msdosfs 
driver, but handled by mtools and other OSes. The problem is that 
msdosfs assume . entry in directory have cluster number set to real 
directory cluster number. But sometimes cluster number for . entry is 
set to 0, and msdosfs behaves wrong with such filesystems.

>How-To-Repeat:
Take a FAT12 formatted diskette image from vmware2 distribution 
(vmware-distrib/lib/floppies/windows.flp): 
without patch:

# ls -lR /floppy
ls: win2k: directory causes a cycle
ls: win9x: directory causes a cycle
ls: winnt: directory causes a cycle
total 850
-rwxr-xr-x  1 root  wheel  870002 Nov  1 17:36 VMwareTools.exe
drwxr-xr-x  1 root  wheel       0 Nov  1 17:36 win2k
drwxr-xr-x  1 root  wheel       0 Nov  1 17:36 win9x
drwxr-xr-x  1 root  wheel       0 Nov  1 17:36 winnt

with patch:
# ls -lR /floppy
total 852
-rwxr-xr-x  1 root  wheel  870002 Nov  1 17:36 VMwareTools.exe
drwxr-xr-x  1 root  wheel     512 Nov  1 17:36 win2k
drwxr-xr-x  1 root  wheel     512 Nov  1 17:36 win9x
drwxr-xr-x  1 root  wheel     512 Nov  1 17:36 winnt

/floppy/win2k:
total 28
-rwxr-xr-x  1 root  wheel  18432 Nov  1 17:36 vmx_fb.dll
-rwxr-xr-x  1 root  wheel   2274 Nov  1 17:36 vmx_svga.inf
-rwxr-xr-x  1 root  wheel   7440 Nov  1 17:36 vmx_svga.sys

/floppy/win9x:
total 25
-rwxr-xr-x  1 root  wheel  17136 Nov  1 17:36 VMX_SVGA.DRV
-rwxr-xr-x  1 root  wheel   5991 Nov  1 17:36 VMX_SVGA.vxd
-rwxr-xr-x  1 root  wheel   1669 Nov  1 17:36 vmx_svga.inf

/floppy/winnt:
total 38
-rwxr-xr-x  1 root  wheel  17408 Nov  1 17:36 vmx_fb.dll
-rwxr-xr-x  1 root  wheel  13637 Nov  1 17:36 vmx_svga.inf
-rwxr-xr-x  1 root  wheel   7440 Nov  1 17:36 vmx_svga.sys

>Fix:
Use following patch:

Index: src/sys/msdosfs/msdosfs_denode.c
===================================================================
RCS file: /usr/home/ncvs/src/sys/msdosfs/msdosfs_denode.c,v
retrieving revision 1.47.2.1
diff -c -r1.47.2.1 msdosfs_denode.c
*** src/sys/msdosfs/msdosfs_denode.c	2000/07/08 14:34:27	1.47.2.1
--- src/sys/msdosfs/msdosfs_denode.c	2001/01/16 19:30:13
***************
*** 356,361 ****
--- 356,371 ----
  		 */
  		u_long size;
  
+ 		/*
+ 		 * XXX Sometimes, there arrives that . entry have cluster
+ 		 * number 0, when it shouldn't. Use real cluster number
+ 		 * instead of what is written in directory entry.
+ 		 */
+ 		if ((diroffset == 0) && (ldep->de_StartCluster != dirclust)) {
+ 			printf("deget(): . entry at clust %ld != %ld\n", dirclust, ldep->de_StartCluster);
+ 			ldep->de_StartCluster = dirclust;
+ 		}
+ 
  		nvp->v_type = VDIR;
  		if (ldep->de_StartCluster != MSDOSFSROOT) {
  			error = pcbmap(ldep, 0xffff, 0, &size, 0);


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: trhodes 
State-Changed-When: Thu Aug 15 22:15:06 PDT 2002 
State-Changed-Why:  
Hello.  I have just applied this patch, thank you. 


Responsible-Changed-From-To: freebsd-bugs->trhodes 
Responsible-Changed-By: trhodes 
Responsible-Changed-When: Thu Aug 15 22:15:06 PDT 2002 
Responsible-Changed-Why:  
Hello.  I have just applied this patch, thank you. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=24393 
State-Changed-From-To: patched->closed 
State-Changed-By: trhodes 
State-Changed-When: Thu Aug 22 09:20:29 PDT 2002 
State-Changed-Why:  
Patch applied to stable!  Thanks for your submission. 

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