Skip to content

Commit bdcd210

Browse files
perseantperseant
authored andcommitted
Check the existing inode address against LFS_UNUSED_DADDR before checking
whether it is in the same segment, to prevent a byte undercount in segment 0 during roll forward. This was most often expressed in the fs/lfs/t_rfw rfw64 test case, though it affected both 32- and 64-bit LFSs equally.
1 parent b584eb5 commit bdcd210

1 file changed

Lines changed: 11 additions & 18 deletions

File tree

sys/ufs/lfs/lfs_rfw.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: lfs_rfw.c,v 1.38 2025/10/06 20:58:48 perseant Exp $ */
1+
/* $NetBSD: lfs_rfw.c,v 1.39 2025/10/14 00:13:31 perseant Exp $ */
22

33
/*-
44
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
3030
*/
3131

3232
#include <sys/cdefs.h>
33-
__KERNEL_RCSID(0, "$NetBSD: lfs_rfw.c,v 1.38 2025/10/06 20:58:48 perseant Exp $");
33+
__KERNEL_RCSID(0, "$NetBSD: lfs_rfw.c,v 1.39 2025/10/14 00:13:31 perseant Exp $");
3434

3535
#if defined(_KERNEL_OPT)
3636
#include "opt_quota.h"
@@ -399,7 +399,7 @@ update_inoblk(struct lfs *fs, daddr_t offset, kauth_cred_t cred,
399399
IFILE *ifp;
400400
SEGUSE *sup;
401401
unsigned i, num;
402-
uint32_t gen;
402+
uint32_t gen, osn, nsn;
403403
char *buf;
404404

405405
devvp = VTOI(fs->lfs_ivnode)->i_devvp;
@@ -473,27 +473,20 @@ update_inoblk(struct lfs *fs, daddr_t offset, kauth_cred_t cred,
473473
/* Record change in location */
474474
LFS_IENTRY(ifp, fs, lfs_dino_getinumber(fs, dip), ibp);
475475
daddr = lfs_if_getdaddr(fs, ifp);
476-
lfs_if_setdaddr(fs, ifp, LFS_DBTOFSB(fs, dbp->b_blkno));
476+
lfs_if_setdaddr(fs, ifp, offset);
477477
error = LFS_BWRITE_LOG(ibp); /* Ifile */
478478
/* And do segment accounting */
479-
if (lfs_dtosn(fs, daddr)
480-
!= lfs_dtosn(fs, LFS_DBTOFSB(fs, dbp->b_blkno))) {
479+
osn = lfs_dtosn(fs, daddr);
480+
nsn = lfs_dtosn(fs, offset);
481+
if (DADDR_IS_BAD(daddr) || osn != nsn) {
481482
if (!DADDR_IS_BAD(daddr)) {
482-
LFS_SEGENTRY(sup, fs,
483-
lfs_dtosn(fs, daddr), ibp);
483+
LFS_SEGENTRY(sup, fs, osn, ibp);
484484
sup->su_nbytes -= DINOSIZE(fs);
485-
LFS_WRITESEGENTRY(sup, fs,
486-
lfs_dtosn(fs, daddr),
487-
ibp);
485+
LFS_WRITESEGENTRY(sup, fs, osn, ibp);
488486
}
489-
LFS_SEGENTRY(sup, fs, lfs_dtosn(fs,
490-
LFS_DBTOFSB(fs, dbp->b_blkno)),
491-
ibp);
487+
LFS_SEGENTRY(sup, fs, nsn, ibp);
492488
sup->su_nbytes += DINOSIZE(fs);
493-
LFS_WRITESEGENTRY(sup, fs,
494-
lfs_dtosn(fs, LFS_DBTOFSB(fs,
495-
dbp->b_blkno)),
496-
ibp);
489+
LFS_WRITESEGENTRY(sup, fs, nsn, ibp);
497490
}
498491
vput(vp);
499492
}

0 commit comments

Comments
 (0)