From owner-freebsd-current Sun Oct 22 1:22:18 2000 Delivered-To: freebsd-current@freebsd.org Received: from midten.fast.no (midten.fast.no [213.188.8.11]) by hub.freebsd.org (Postfix) with ESMTP id C873437B479; Sun, 22 Oct 2000 01:22:13 -0700 (PDT) Received: from fast.no (IDENT:tegge@midten.fast.no [213.188.8.11]) by midten.fast.no (8.9.3/8.9.3) with ESMTP id KAA59278; Sun, 22 Oct 2000 10:22:07 +0200 (CEST) Message-Id: <200010220822.KAA59278@midten.fast.no> To: jwd@FreeBSD.ORG Cc: freebsd-current@FreeBSD.ORG, peter@FreeBSD.ORG Subject: Re: newfs/fsck problem (bad superblocks) From: Tor.Egge@fast.no In-Reply-To: Your message of "Sun, 22 Oct 2000 00:36:41 -0400" References: <20001022003609.A33732@bsdwins.com> X-Mailer: Mew version 1.70 on Emacs 19.34.1 Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Sun_Oct_22_10:21:10_2000)--" Content-Transfer-Encoding: 7bit Date: Sun, 22 Oct 2000 10:22:07 +0200 Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG ----Next_Part(Sun_Oct_22_10:21:10_2000)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit > Reverting src/sbin/newfs/mkfs.c to revision 1.29 fixes > the problem. > > With just a quick review of the patch, I'm not sure I > understand what forces the last dirty buffer to be > written. > > revert the patch? try to fix it? comments? Try the enclosed patch. It flushes the dirty buffer before program exit and before reading blocks. - Tor Egge ----Next_Part(Sun_Oct_22_10:21:10_2000)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Index: sbin/newfs/mkfs.c =================================================================== RCS file: /home/ncvs/src/sbin/newfs/mkfs.c,v retrieving revision 1.30 diff -u -r1.30 mkfs.c --- sbin/newfs/mkfs.c 2000/10/17 00:41:36 1.30 +++ sbin/newfs/mkfs.c 2000/10/22 08:17:05 @@ -153,6 +153,7 @@ void rdfs __P((daddr_t, int, char *)); void setblock __P((struct fs *, unsigned char *, int)); void wtfs __P((daddr_t, int, char *)); +void wtfsflush __P((void)); #ifndef STANDALONE void get_memleft __P((void)); @@ -719,6 +720,7 @@ for (cylno = 0; cylno < sblock.fs_ncg; cylno++) wtfs(fsbtodb(&sblock, cgsblock(&sblock, cylno)), sbsize, (char *)&sblock); + wtfsflush(); /* * Update information about this partion in pack * label, to that it may be updated on disk. @@ -1309,6 +1311,7 @@ { int n; + wtfsflush(); if (mfs) { memmove(bf, membase + bno * sectorsize, size); return; @@ -1330,6 +1333,27 @@ static char wc[WCSIZE]; /* bytes */ /* + * Flush dirty write behind buffer. + */ +void +wtfsflush() +{ + int n; + if (wc_end) { + if (lseek(fso, (off_t)wc_sect * sectorsize, SEEK_SET) < 0) { + printf("seek error: %ld\n", (long)wc_sect); + err(35, "wtfs - writecombine"); + } + n = write(fso, wc, wc_end); + if (n != wc_end) { + printf("write error: %ld\n", (long)wc_sect); + err(36, "wtfs - writecombine"); + } + wc_end = 0; + } +} + +/* * write a block to the file system */ void @@ -1363,19 +1387,8 @@ if (wc_end < WCSIZE) return; done = 1; - } - if (wc_end) { - if (lseek(fso, (off_t)wc_sect * sectorsize, SEEK_SET) < 0) { - printf("seek error: %ld\n", (long)wc_sect); - err(35, "wtfs - writecombine"); - } - n = write(fso, wc, wc_end); - if (n != wc_end) { - printf("write error: %ld\n", (long)wc_sect); - err(36, "wtfs - writecombine"); - } - wc_end = 0; } + wtfsflush(); if (done) return; if (lseek(fso, (off_t)bno * sectorsize, SEEK_SET) < 0) { ----Next_Part(Sun_Oct_22_10:21:10_2000)---- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message