Re: newfs for UFS2 problems

From: Alex Popa <razor_at_ldc.ro>
Date: Wed, 30 Apr 2003 01:24:50 +0300
Hello, sorry for the delay in testing and answering.

The patch seems to work with a little modification, deduced from this:
lib/libufs/block.c, line 80:

bwrite(struct uufsd *disk, ufs2_daddr_t blockno, const void *data, size_t size)
...
cnt = pwrite(disk->d_fd, data, size, (off_t)(blockno * disk->d_bsize));
...

It look that it multiplies by a block size.  However, in
sys/ufs/ffs/fs.h, lines 68-69 mention the superblock offset is defined
in bytes, not blocks.

So it seems we need to change your "SBLOCK_UFS1" to
"SBLOCK_UFS1 / disk.d_bsize", to get the expected result (overwriting
the old ufs1 superblock).  This is all I have changed in your patch
(the modified patch is below).  I have tested it, and dumpfs and mount
from 4.8 now complain about a missing magic number / incorrect
superblock.

Thanks for your help

Alex

---8<---
Index: sbin/newfs/mkfs.c
===================================================================
RCS file: /home/ncvs/src/sbin/newfs/mkfs.c,v
retrieving revision 1.74
diff -u -r1.74 mkfs.c
--- sbin/newfs/mkfs.c	22 Feb 2003 23:26:11 -0000	1.74
+++ sbin/newfs/mkfs.c	29 Apr 2003 21:57:33 -0000
_at__at_ -113,6 +113,7 _at__at_
 	quad_t sizepb;
 	int width;
 	char tmpbuf[100];	/* XXX this will break in about 2,500 years */
+	char dummy[SBLOCKSIZE];
 
 	/*
 	 * Our blocks == sector size, and the version of UFS we are using is
_at__at_ -479,8 +480,13 _at__at_
 		sblock.fs_old_cstotal.cs_nifree = sblock.fs_cstotal.cs_nifree;
 		sblock.fs_old_cstotal.cs_nffree = sblock.fs_cstotal.cs_nffree;
 	}
-	if (!Nflag)
+	if (!Nflag) {
+		if (Oflag != 1) {
+			memset(dummy, '\0', SBLOCKSIZE);
+			bwrite(&disk, SBLOCK_UFS1 / disk.d_bsize, dummy, SBLOCKSIZE);
+		}
 		sbwrite(&disk, 0);
+	}
 	for (i = 0; i < sblock.fs_cssize; i += sblock.fs_bsize)
 		wtfs(fsbtodb(&sblock, sblock.fs_csaddr + numfrags(&sblock, i)),
 			sblock.fs_cssize - i < sblock.fs_bsize ?
---8<---


On Sat, Apr 26, 2003 at 11:01:41PM +0200, Lukas Ertl wrote:
> Alex Popa wrote:
> 
> > It seems the problem is partly caused by newfs on -current, which does
> > not remove the old UFS1 magic when creating an UFS2 superblock at a
> > different location.  This leftover magic is seen by the -stable kernel
> > and therefore used.
> 
> Hi Alex,
> 
> could you try this patch to newfs(8)? It wipes the old UFS1 superblock
> at location SBLOCK_UFS1 before writing the new superblock at location
> SBLOCK_UFS2.
> 
> 
> best regards,
> le
> 
> -- 
> Lukas Ertl                             eMail: l.ertl_at_univie.ac.at
> UNIX-Systemadministrator               Tel.:  (+43 1) 4277-14073
> Zentraler Informatikdienst (ZID)       Fax.:  (+43 1) 4277-9140
> der Universit?t Wien                   http://mailbox.univie.ac.at/~le/
------------+-------------------------------------------------------
Alex Popa,  |  "Computer science is no more about computers than
razor_at_ldc.ro|     astronomy is about telescopes" -- E. W. Dijkstra
------------+------------------------------------------------------
Received on Tue Apr 29 2003 - 13:24:54 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:05 UTC