Subject: kern/22232: ffs_dinode2_swap() contains a cut/paste/forget to update bug
To: None <gnats-bugs@gnats.netbsd.org>
From: None <kre@munnari.OZ.AU>
List: netbsd-bugs
Date: 07/23/2003 15:28:51
>Number:         22232
>Category:       kern
>Synopsis:       ffs_dinode2_swap() contains a cut/paste/forget to update bug
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 23 08:31:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Robert Elz
>Release:        NetBSD 1.6U  (-- -current as of right now)
>Organization:
Prince of Songkla University
>Environment:
	
	
	nb: this stuff comes from the system used for send-pr which has
	very little relationship with anything else involved in this PR
	(the bug has existed since before 1.6Q though I suspect).
System: NetBSD jade.coe.psu.ac.th 1.6Q NetBSD 1.6Q (JADE-HP) #0: Sun Mar 23 02:27:44 ICT 2003 kre@fuchsia.cs.mu.OZ.AU:/usr/obj/sys/JADE-HP i386
Architecture: i386
Machine: i386

>Description:
	If a ufs2 filesystem is mounted on a "wrong"-endian host, the
	birthtime value (for what use that is, which isn't much, which
	is why this PR is non-critical/low) will appear to be the same as
	the ctime value (and might get set to that). (I believe, I don't
	have a ufs2 filesystem, nor easy access to an other endian host
	that the filesystem I don't have could be connected to...)

>How-To-Repeat:
	You could set up the environment described, but a much easier way
	is to inspect the code:

   sys/ufs/ffs/ffs_bswap.c:

void
ffs_dinode2_swap(struct ufs2_dinode *o, struct ufs2_dinode *n)
{
    [...]
	n->di_ctime = bswap64(o->di_ctime);
	n->di_ctimensec = bswap32(o->di_ctimensec);
	n->di_birthtime = bswap64(o->di_ctime);
	n->di_birthnsec = bswap32(o->di_ctimensec);
    [...]
}

	which looks like 2 lines were copied, and only partially
	updated for their new use (BTDT).

>Fix:
	The best fix would be to expunge st_birthtime (and everything
	related to it) from NetBSD completely, it is a useless idea.

	However, given that we're probably stuck with it for compatability
	with other UFS2 implementations, then apply the following patch:

--- ffs_bswap.c	Wed Apr 16 23:18:34 2003
+++ ffs_bswap.c.NEW	Wed Jul 23 15:25:37 2003
@@ -143,10 +143,10 @@
 	n->di_mtime = bswap64(o->di_mtime);
 	n->di_mtimensec = bswap32(o->di_mtimensec);
 	n->di_ctime = bswap64(o->di_ctime);
 	n->di_ctimensec = bswap32(o->di_ctimensec);
-	n->di_birthtime = bswap64(o->di_ctime);
-	n->di_birthnsec = bswap32(o->di_ctimensec);
+	n->di_birthtime = bswap64(o->di_birthtime);
+	n->di_birthnsec = bswap32(o->di_birthnsec);
 	n->di_gen = bswap32(o->di_gen);
 	n->di_kernflags = bswap32(o->di_kernflags);
 	n->di_flags = bswap32(o->di_flags);
 	n->di_extsize = bswap32(o->di_extsize);
>Release-Note:
>Audit-Trail:
>Unformatted: