ufs: more signed/unsigned fixes

Fix the previous signed/unsigned fixes to build on 32-bit,
including applying this commit from FreeBSD:

  commit 2d34afcd04207cf3fa3d5b7f467a890eae75da41
  Author: Kirk McKusick <mckusick@FreeBSD.org>
  Date:   Sun Oct 25 21:04:07 2020 +0000

    Use proper type (ino_t) for inode numbers to avoid improper sign extention
    in the Pass 5 checks. The manifestation was fsck_ffs exiting with this error:

      ** Phase 5 - Check Cyl groups
      fsck_ffs: inoinfo: inumber 18446744071562087424 out of range

    The error only manifests itself for filesystems bigger than about 100Tb.

    Reported by:  Nikita Grechikhin <ngrechikhin at yandex.ru>
    MFC after:    2 weeks
    Sponsored by: Netflix
This commit is contained in:
chs 2023-01-08 05:25:24 +00:00
parent 4ea49518ea
commit 908deb24fa
2 changed files with 20 additions and 16 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass5.c,v 1.56 2023/01/07 19:41:29 chs Exp $ */
/* $NetBSD: pass5.c,v 1.57 2023/01/08 05:25:24 chs Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)pass5.c 8.9 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: pass5.c,v 1.56 2023/01/07 19:41:29 chs Exp $");
__RCSID("$NetBSD: pass5.c,v 1.57 2023/01/08 05:25:24 chs Exp $");
#endif
#endif /* not lint */
@ -60,12 +60,15 @@ void
pass5(void)
{
int blk, frags, basesize, sumsize, mapsize, cssize;
int inomapsize, blkmapsize;
uint32_t inomapsize, blkmapsize;
uint32_t c;
struct fs *fs = sblock;
daddr_t dbase, dmax;
daddr_t d;
long i, j, k;
uint32_t i;
int32_t j;
int k;
ino_t inum;
struct csum *cs;
struct csum_total cstotal;
struct inodesc idesc[4];
@ -317,9 +320,9 @@ pass5(void)
if (!is_ufs2 && ((fs->fs_old_flags & FS_FLAGS_UPDATED) == 0) &&
fs->fs_old_postblformat == FS_42POSTBLFMT)
ocg->cg_magic = CG_MAGIC;
j = fs->fs_ipg * c;
for (i = 0; i < fs->fs_ipg; j++, i++) {
info = inoinfo(j);
inum = fs->fs_ipg * c;
for (i = 0; i < fs->fs_ipg; inum++, i++) {
info = inoinfo(inum);
switch (info->ino_state) {
case USTATE:
@ -338,14 +341,14 @@ pass5(void)
break;
default:
if ((ino_t)j < UFS_ROOTINO)
if (inum < UFS_ROOTINO)
break;
errexit("BAD STATE %d FOR INODE I=%ld",
info->ino_state, (long)j);
errexit("BAD STATE %d FOR INODE I=%ju",
info->ino_state, (uintmax_t)inum);
}
}
if (c == 0)
for (i = 0; i < (long)UFS_ROOTINO; i++) {
for (i = 0; i < UFS_ROOTINO; i++) {
setbit(cg_inosused(newcg, 0), i);
newcg->cg_cs.cs_nifree--;
}
@ -450,7 +453,7 @@ pass5(void)
continue;
if (cg_inosused(cg, 0)[i] & (1 << k))
continue;
pwarn("ALLOCATED INODE %ld "
pwarn("ALLOCATED INODE %u "
"MARKED FREE\n",
c * fs->fs_ipg + i * 8 + k);
}
@ -464,7 +467,7 @@ pass5(void)
continue;
if (cg_inosused(cg, 0)[i] & (1 << k))
continue;
pwarn("ALLOCATED FRAG %ld "
pwarn("ALLOCATED FRAG %u "
"MARKED FREE\n",
c * fs->fs_fpg + i * 8 + k);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: setup.c,v 1.105 2023/01/07 19:41:29 chs Exp $ */
/* $NetBSD: setup.c,v 1.106 2023/01/08 05:25:24 chs Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)setup.c 8.10 (Berkeley) 5/9/95";
#else
__RCSID("$NetBSD: setup.c,v 1.105 2023/01/07 19:41:29 chs Exp $");
__RCSID("$NetBSD: setup.c,v 1.106 2023/01/08 05:25:24 chs Exp $");
#endif
#endif /* not lint */
@ -85,7 +85,8 @@ int16_t sblkpostbl[256];
int
setup(const char *dev, const char *origdev)
{
long cg, size, asked, i, j;
uint32_t cg;
long size, asked, i, j;
long bmapsize;
struct disk_geom geo;
struct dkwedge_info dkw;