From eu@grosbein.pp.ru  Sat Nov 11 20:55:01 2006
Return-Path: <eu@grosbein.pp.ru>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 4674D16A412
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 11 Nov 2006 20:55:01 +0000 (UTC)
	(envelope-from eu@grosbein.pp.ru)
Received: from grosbein.pp.ru (grgw.svzserv.kemerovo.su [213.184.64.166])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 8FD0A43D66
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 11 Nov 2006 20:54:57 +0000 (GMT)
	(envelope-from eu@grosbein.pp.ru)
Received: from grosbein.pp.ru (localhost [127.0.0.1])
	by grosbein.pp.ru (8.13.8/8.13.8) with ESMTP id kABKsrEH002903
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 12 Nov 2006 03:54:53 +0700 (KRAT)
	(envelope-from eu@grosbein.pp.ru)
Received: (from root@localhost)
	by grosbein.pp.ru (8.13.8/8.13.8/Submit) id kABKsqnM002902;
	Sun, 12 Nov 2006 03:54:52 +0700 (KRAT)
	(envelope-from eu)
Message-Id: <200611112054.kABKsqnM002902@grosbein.pp.ru>
Date: Sun, 12 Nov 2006 03:54:52 +0700 (KRAT)
From: Eugene Grosbein <eugen@grosbein.pp.ru>
Reply-To: Eugene Grosbein <eugen@grosbein.pp.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [msdosfs] msdosfs mounted as r/o cannot be remounted to r/w
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         105412
>Category:       bin
>Synopsis:       [patch] mount(8): msdosfs mounted as r/o cannot be remounted to r/w
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    rodrigc
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Nov 11 21:00:41 GMT 2006
>Closed-Date:    Wed Jan 17 04:20:20 GMT 2007
>Last-Modified:  Wed Jan 17 04:20:20 GMT 2007
>Originator:     Eugene Grosbein
>Release:        FreeBSD 6.2-PRERELEASE i386
>Organization:
Svyaz Service JSC
>Environment:
System: FreeBSD grosbein.pp.ru 6.2-PRERELEASE FreeBSD 6.2-PRERELEASE #20: Fri Nov 10 20:05:19 KRAT 2006 eu@grosbein.pp.ru:/mnt/home/obj/usr/local/src/sys/DADV i386

>Description:

	It must be possible to remount msdosfs from r/o to r/w

>How-To-Repeat:

	Let's make an image for file system to play with:

# dd if=/dev/zero bs=1k count=1440 of=image

	Then make it device /dev/md0:

# mdconfig -a -t vnode -f image

	Then make new filesystem to mount:

# newfs_msdos -f 1440 /dev/md0

	Then mount it read-only:

# mount_msdosfs -o ro /dev/md0 /mnt/tmp

	Now look at this:

# mount | grep md0
/dev/md0 on /mnt/tmp (msdosfs, local, read-only)

	Still good. Now try to remount it r/w:

# mount -u -o rw /dev/md0; echo $?
0

	It pretends to finish with success. But it has failed:

# echo test > /mnt/tmp/test; mount | grep md0
bash: /mnt/tmp/test: Read-only file system
/dev/md0 on /mnt/tmp (msdosfs, local, read-only)

>Fix:

	Unknown. There are two problems really.
	First, mount(8) does not treat msdosfs as remountable.
	This should be fixed with the following patch:

--- sbin/mount/mount.c.orig	Sun Nov 12 01:16:13 2006
+++ sbin/mount/mount.c	Sun Nov 12 01:16:23 2006
@@ -116,7 +116,7 @@
  */
 static const char *
 remountable_fs_names[] = {
-	"ufs", "ffs", "ext2fs",
+	"ufs", "ffs", "ext2fs","msdosfs",
 	0
 };
 

	Second, "mount -o update,noro /dev/md0" results in
	a call to msdosfs_mount() that for some reason finds "export"
	option in its arguments and just returns 0 effectively ignoring
	the request for upgrade to r/w.

Eugene Grosbein
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: rodrigc 
State-Changed-When: Thu Dec 14 04:48:52 UTC 2006 
State-Changed-Why:  
Very nice testcase.  I made a shell script for it: 

#!/bin/sh 
dd if=/dev/zero bs=1k count=1440 of=image.msdos 
mdconfig -a -t vnode -f image.msdos 
newfs_msdos -f 1440 /dev/md0 
mount_msdosfs -o ro /dev/md0 /mnt 
mount | grep md0 
mount -u -o rw /dev/md0; echo $? 
mount | grep md0 

Take a look at src/sys/fs/msdosfs/msdosfs_vfsops.c version 1.144.2.7. 
For me, that makes your testcase pass on RELENG_6. 

The patch that you posted for mount(8) is only used for 
"mount -a", so doesn't handle your testcase. 


Responsible-Changed-From-To: freebsd-bugs->rodrigc 
Responsible-Changed-By: rodrigc 
Responsible-Changed-When: Thu Dec 14 04:48:52 UTC 2006 
Responsible-Changed-Why:  
Very nice testcase.  I made a shell script for it: 

#!/bin/sh 
dd if=/dev/zero bs=1k count=1440 of=image.msdos 
mdconfig -a -t vnode -f image.msdos 
newfs_msdos -f 1440 /dev/md0 
mount_msdosfs -o ro /dev/md0 /mnt 
mount | grep md0 
mount -u -o rw /dev/md0; echo $? 
mount | grep md0 

Take a look at src/sys/fs/msdosfs/msdosfs_vfsops.c version 1.144.2.7. 
For me, that makes your testcase pass on RELENG_6. 

The patch that you posted for mount(8) is only used for 
"mount -a", so doesn't handle your testcase. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=105412 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/105412: commit references a PR
Date: Thu, 14 Dec 2006 04:48:50 +0000 (UTC)

 rodrigc     2006-12-14 04:48:17 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     sys/fs/msdosfs       msdosfs_vfsops.c 
   Log:
   MFC: 1.155 (without vfs_mount_error()):
   - Fix MNT_UPDATE for msdosfs, do not allow "export" requests if
     MSDOSFS_LARGEFS flag is set.
   
   PR:     kern/105412
   
   Revision   Changes    Path
   1.144.2.7  +4 -3      src/sys/fs/msdosfs/msdosfs_vfsops.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"
 

From: Eugene Grosbein <eugen@kuzbass.ru>
To: rodrigc@freebsd.org
Cc: bug-followup@freebsd.org
Subject: Re: bin/105412: [patch] mount(8): msdosfs mounted as r/o cannot be remounted to r/w
Date: Thu, 14 Dec 2006 23:45:54 +0700

 Hi!
 
 I've just updated to latest RELENG_6 and tested it.
 Yes, now it works for FAT12. And no, it still does not work for FAT16:
 
 #!/bin/sh 
 dd if=/dev/zero bs=1m count=1 oseek=119 of=image.msdos 
 mdconfig -a -t vnode -f image.msdos 
 newfs_msdos -F 16 /dev/md0 fd120m
 mount_msdosfs -o ro /dev/md0 /mnt/tmp
 mount | grep md0 
 mount -u -o rw /dev/md0; echo $? 
 mount | grep md0
 
 It complains: mount_msdosfs: /dev/md0: Read-only file system
 for 'mount -u ...'. That's because markvoldirty() is called while
 MSDOSFSMNT_RONLY flag is not cleaned.
 
 Eugene Grosbein

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/105412: commit references a PR
Date: Wed, 20 Dec 2006 01:33:13 +0000 (UTC)

 rodrigc     2006-12-20 01:32:59 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6_2)
     sys/fs/msdosfs       msdosfs_vfsops.c 
   Log:
   MFC: 1.155 (without vfs_mount_error()):
   - Fix MNT_UPDATE for msdosfs, do not allow "export" requests if
     MSDOSFS_LARGEFS flag is set.
   
   PR:             105412
   Approved by:    re (bmah)
   
   Revision       Changes    Path
   1.144.2.6.2.1  +8 -4      src/sys/fs/msdosfs/msdosfs_vfsops.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"
 

From: Craig Rodrigues <rodrigc@crodrigues.org>
To: Eugene Grosbein <eugen@kuzbass.ru>
Cc: bug-followup@freebsd.org
Subject: Re: bin/105412: [patch] mount(8): msdosfs mounted as r/o cannot be remounted to r/w
Date: Fri, 5 Jan 2007 01:05:54 -0500

 --a8Wt8u1KmwUX3Y2C
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 On Thu, Dec 14, 2006 at 04:50:07PM +0000, Eugene Grosbein wrote:
 >  
 >  #!/bin/sh 
 >  dd if=/dev/zero bs=1m count=1 oseek=119 of=image.msdos 
 >  mdconfig -a -t vnode -f image.msdos 
 >  newfs_msdos -F 16 /dev/md0 fd120m
 >  mount_msdosfs -o ro /dev/md0 /mnt/tmp
 >  mount | grep md0 
 >  mount -u -o rw /dev/md0; echo $? 
 >  mount | grep md0
 >  
 >  It complains: mount_msdosfs: /dev/md0: Read-only file system
 >  for 'mount -u ...'. That's because markvoldirty() is called while
 >  MSDOSFSMNT_RONLY flag is not cleaned.
 >  
 >  Eugene Grosbein
 
 Hi,
 
 Can you try the attached patch?
 
 -- 
 Craig Rodrigues        
 rodrigc@crodrigues.org
 
 --a8Wt8u1KmwUX3Y2C
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="msdosfs_vfsops.c.txt"
 
 --- msdosfs_vfsops.c.orig	Fri Jan  5 00:10:01 2007
 +++ msdosfs_vfsops.c	Fri Jan  5 00:13:53 2007
 @@ -310,15 +310,19 @@
  			if (error)
  				return (error);
  
 -			/* Now that the volume is modifiable, mark it dirty. */
 -			error = markvoldirty(pmp, 1);
 -			if (error)
 -				return (error);
  		}
  		vfs_flagopt(mp->mnt_optnew, "ro",
  		    &pmp->pm_flags, MSDOSFSMNT_RONLY);
  		vfs_flagopt(mp->mnt_optnew, "ro",
  		    &mp->mnt_flag, MNT_RDONLY);
 +
 +		if (!(pmp->pm_flags & MSDOSFSMNT_RONLY)) {
 +			/* Now that the volume is modifiable, mark it dirty. */
 +			error = markvoldirty(pmp, 1);
 +			if (error)
 +				return (error);
 +		}
 +
  		if (vfs_getopt(mp->mnt_optnew, "from", NULL, NULL)) {
  #ifdef	__notyet__	/* doesn't work correctly with current mountd	XXX */
  			if (args.flags & MSDOSFSMNT_MNTOPT) {
 
 --a8Wt8u1KmwUX3Y2C--

From: Eugene Grosbein <eugen@kuzbass.ru>
To: Craig Rodrigues <rodrigc@crodrigues.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/105412: [patch] mount(8): msdosfs mounted as r/o cannot be remounted to r/w
Date: Fri, 5 Jan 2007 19:42:07 +0700

 On Fri, Jan 05, 2007 at 01:05:54AM -0500, Craig Rodrigues wrote:
 
 > Can you try the attached patch?
 
 Thank you, it works just right.
 
 Eugene

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/105412: commit references a PR
Date: Sat,  6 Jan 2007 20:46:10 +0000 (UTC)

 rodrigc     2007-01-06 20:46:02 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/fs/msdosfs       msdosfs_vfsops.c 
   Log:
   When performing a mount update to change a mount from read-only to read-write,
   do not call markvoldirty() until the mount has been flagged as read-write.
   Due to the nature of the msdosfs code, this bug only seemed to appear for
   FAT-16 and FAT-32.
   
   This fixes the testcase:
   #!/bin/sh
   dd if=/dev/zero bs=1m count=1 oseek=119 of=image.msdos
   mdconfig -a -t vnode -f image.msdos
   newfs_msdos -F 16 /dev/md0 fd120m
   mount_msdosfs -o ro /dev/md0 /mnt
   mount | grep md0
   mount -u -o rw /dev/md0; echo $?
   mount | grep md0
   umount /mnt
   mdconfig -d -u 0
   
   PR:             105412
   Tested by:      Eugene Grosbein <eugen grosbein pp ru>
   
   Revision  Changes    Path
   1.156     +10 -4     src/sys/fs/msdosfs/msdosfs_vfsops.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"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/105412: commit references a PR
Date: Sat,  6 Jan 2007 22:17:32 +0000 (UTC)

 rodrigc     2007-01-06 22:17:15 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     sys/fs/msdosfs       msdosfs_vfsops.c 
   Log:
   MFC 1.56:
     Fix mount update from read-only to read-write for FAT-16 and FAT-32.
   
   PR:             105412
   Tested by:      Eugene Grosbein <eugen grosbein pp ru>
   
   Revision   Changes    Path
   1.144.2.8  +10 -4     src/sys/fs/msdosfs/msdosfs_vfsops.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: patched->closed 
State-Changed-By: rodrigc 
State-Changed-When: Wed Jan 17 04:19:40 UTC 2007 
State-Changed-Why:  
Merged to RELENG_6. 

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