From olli@lurza.secnetix.de  Wed Nov 29 15:31:14 2006
Return-Path: <olli@lurza.secnetix.de>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id BDC7716A523
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 29 Nov 2006 15:31:14 +0000 (UTC)
	(envelope-from olli@lurza.secnetix.de)
Received: from lurza.secnetix.de (lurza.secnetix.de [83.120.8.8])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 3289143CB3
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 29 Nov 2006 15:31:00 +0000 (GMT)
	(envelope-from olli@lurza.secnetix.de)
Received: from lurza.secnetix.de (dsdybk@localhost [127.0.0.1])
	by lurza.secnetix.de (8.13.4/8.13.4) with ESMTP id kATFUrGv077560;
	Wed, 29 Nov 2006 16:30:59 +0100 (CET)
	(envelope-from oliver.fromme@secnetix.de)
Received: (from olli@localhost)
	by lurza.secnetix.de (8.13.4/8.13.1/Submit) id kATFUrhW077559;
	Wed, 29 Nov 2006 16:30:53 +0100 (CET)
	(envelope-from olli)
Message-Id: <200611291530.kATFUrhW077559@lurza.secnetix.de>
Date: Wed, 29 Nov 2006 16:30:53 +0100 (CET)
From: Oliver Fromme <olli@secnetix.de>
Reply-To: Oliver Fromme <olli@secnetix.de>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Oliver Fromme <olli@secnetix.de>
Subject: [PATCH] msdosfs: fix handling of mtime, ctime and birthtime
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         106018
>Category:       kern
>Synopsis:       [msdosfs] [patch] fix handling of mtime, ctime and birthtime
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 29 15:40:14 GMT 2006
>Closed-Date:    Sun Dec 31 07:35:34 GMT 2006
>Last-Modified:  Sun Dec 31 07:35:34 GMT 2006
>Originator:     Oliver Fromme
>Release:        RELENG_6 + HEAD
>Organization:
secnetix GmbH & Co. KG
		http://www.secnetix.de/bsd
>Environment:
	This PR provides patches for RELENG_6 and HEAD
	(as of 2006-11-29).  However, the problem seems
	to exist for as long as FreeBSD has msdosfs.

>Description:

	A recent thread in the freebsd-fs mailing list
	reveals that src/sys/fs/msdosfs/msdosfs_vnops.c
	has a bug handling ctime, mtime and birthtime
	time stamps.  The cause of the bug is probably
	the confusing fact that the FAT world calls the
	birthtime "CTime" (creation time), while it does
	not support at all what UNIX calls the ctime.

	As a result from that confusion, the function
	msdosfs_getattr() sets ctime field to the "CTime"
	of the FAT entry (which is really the birthtime),
	and doesn't set the birthtime in the struct vattr
	at all, returning garbage.

	The patch below fixes the problem as follows:
	First, the ctime (which FAT doesn't support) is
	always set equal to the mtime.
	Second, in the MSDOSFSMNT_LONGNAME case, the
	birthtime is taken from the FAT's "CTime", and
	in the other case (unsupported) it is set to -1
	which should be a reasonable value.

	Bruce Evans asked me to record the whole thing
	via send-pr, so here it is.

>How-To-Repeat:

	Mount an msdosfs (you can easily create one with
	mdconfig + newfs_msdos, or use a USB stick with
	a FAT on it if you have one handy), touch a file
	in it, and check the birthtime with "ls -lU".

>Fix:

Patch for RELENG_6:

--- src/sys/fs/msdosfs/msdosfs_vnops.c.orig	Mon Mar 13 04:05:13 2006
+++ src/sys/fs/msdosfs/msdosfs_vnops.c	Wed Nov 29 15:51:20 2006
@@ -341,12 +341,15 @@
 	vap->va_rdev = 0;
 	vap->va_size = dep->de_FileSize;
 	dos2unixtime(dep->de_MDate, dep->de_MTime, 0, &vap->va_mtime);
+	vap->va_ctime = vap->va_mtime;
 	if (pmp->pm_flags & MSDOSFSMNT_LONGNAME) {
 		dos2unixtime(dep->de_ADate, 0, 0, &vap->va_atime);
-		dos2unixtime(dep->de_CDate, dep->de_CTime, dep->de_CHun, &vap->va_ctime);
+		dos2unixtime(dep->de_CDate, dep->de_CTime, dep->de_CHun,
+		    &vap->va_birthtime);
 	} else {
 		vap->va_atime = vap->va_mtime;
-		vap->va_ctime = vap->va_mtime;
+		vap->va_birthtime.tv_sec = -1;
+		vap->va_birthtime.tv_nsec = 0;
 	}
 	vap->va_flags = 0;
 	if ((dep->de_Attributes & ATTR_ARCHIVE) == 0)

Patch for HEAD (untested!):

--- src/sys/fs/msdosfs/msdosfs_vnops.c.orig	Mon Nov  6 14:41:57 2006
+++ src/sys/fs/msdosfs/msdosfs_vnops.c	Wed Nov 29 16:13:19 2006
@@ -343,13 +343,15 @@
 	vap->va_rdev = 0;
 	vap->va_size = dep->de_FileSize;
 	fattime2timespec(dep->de_MDate, dep->de_MTime, 0, 0, &vap->va_mtime);
+	vap->va_ctime = vap->va_mtime;
 	if (pmp->pm_flags & MSDOSFSMNT_LONGNAME) {
 		fattime2timespec(dep->de_ADate, 0, 0, 0, &vap->va_atime);
 		fattime2timespec(dep->de_CDate, dep->de_CTime, dep->de_CHun,
-		    0, &vap->va_ctime);
+		    0, &vap->va_birthtime);
 	} else {
 		vap->va_atime = vap->va_mtime;
-		vap->va_ctime = vap->va_mtime;
+		vap->va_birthtime.tv_sec = -1;
+		vap->va_birthtime.tv_nsec = 0;
 	}
 	vap->va_flags = 0;
 	if ((dep->de_Attributes & ATTR_ARCHIVE) == 0)

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: maxim 
State-Changed-When: Sun Dec 3 19:04:46 UTC 2006 
State-Changed-Why:  
Committed to HEAD.  Thanks for the submission! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/106018: commit references a PR
Date: Sun,  3 Dec 2006 19:04:42 +0000 (UTC)

 maxim       2006-12-03 19:04:27 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/fs/msdosfs       msdosfs_vnops.c 
   Log:
   o Do not leave uninitialized birthtime: in MSDOSFSMNT_LONGNAME
   set birthtime to FAT CTime (creation time) and in the other cases
   set birthtime to -1.
   
   o Set ctime to mtime instead of FAT CTime which has completely
   different meaning.
   
   PR:             kern/106018
   Submitted by:   Oliver Fromme
   MFC after:      1 month
   
   Revision  Changes    Path
   1.166     +4 -2      src/sys/fs/msdosfs/msdosfs_vnops.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: maxim 
State-Changed-When: Sun Dec 31 07:35:14 UTC 2006 
State-Changed-Why:  
Merged to RELENG_6. 

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