From nobody Mon May 15 19:57:27 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QKqsN0SPTz4B1xb; Mon, 15 May 2023 19:57:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QKqsN00Lwz4CMM; Mon, 15 May 2023 19:57:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684180648; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sCUUn2QJDjwHpywKuoMXQ0ncveRw4+i2oyxAO9VbjeU=; b=rzm4W7LBj3HDiAO0kEamihDi5a2QEPNLkezV/Y28mn0aj4Xlllo4WR9tfKMmeVg7axrHXt Lwo78kl7QeSIalrpyzG0HmXSlYp7GPfwlIPLkNighPuRIAFoYMAt3Xt6h9IhvvDcdPesan qZp3tVWQdPeZlgOqCZGZW3sR4NUwkeKjPxHYa/zexT/ChAE9UVIM/kAshBCTTljavoTHSB vTVukWgYXHQh9gI0dhEWOq0OgNsphW0U/BON9cu5oB3BIvUCMlh3qtmztWoSTha5rB4DdQ 4WvL7Yu4/Q8EBH3PMxR6lsOJKk92A1GdmgNg13a+N3wBBf3ucepjMZrIvoQSnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684180648; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sCUUn2QJDjwHpywKuoMXQ0ncveRw4+i2oyxAO9VbjeU=; b=adFtpGXp38qZLquBn2d6KNjbhv8RmhEf8LmqxbuTxpXKFrYH9yNQDpmGSoLg8HMuQnjwqF pGa6CEt5m+sVnGiP62PsMLWPJZB1BQmjJlUN8TXF8qaNs9Jb+CC7HQkOdYI/SkNVZt5r3k uBk3PcxyYw0/t8ASR+O1PgsuK1/RW//EQIW+5JF17cuzRujlgiyLK+odYTiMgUUKU7vDo0 e8qzph1y4UHwjobCLz/XfqY3OS17M0KytXomEd2Ximahta7WBUjXtPhMocotR+1a0lU622 DftamzsXWpYnTVy5A/VOuEkNUNafCIJ5dMUeJTE+MX+L9kOfmFdYaTU31yeD3w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684180648; a=rsa-sha256; cv=none; b=r6x55WU2J1bIi95Gh1qVW5ioIGrtZPf4kuBgNd3uxclBIfWe++8nW/0OL8Fjg89HfymC9U em6S0oMEKbbtqHObUUx7jmXbA8XOunUsmJ3w7MlZp+/FfzYnklflqfySuNFckevCrJxNAA ntPC1SS55/RBBjnimeyF7k53XuxTQ+lQuMy7si9Xbe/H+PyhOHJItzFmYI1WrrxyBt0DOa 5iHSVkcA6lRijAOaSqfOjl7DMv0xvetfO3ah/yGktF0MtIHguVEeIux4jgLE2RtTHhVNQx 4xe+gM/nFuSljXW9HewFedK5ndaCxQoZIObRXGlVSwQIbxKHI2vUU9d/TVyPZQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QKqsM68hkzshY; Mon, 15 May 2023 19:57:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 34FJvRTH085500; Mon, 15 May 2023 19:57:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34FJvR0v085499; Mon, 15 May 2023 19:57:27 GMT (envelope-from git) Date: Mon, 15 May 2023 19:57:27 GMT Message-Id: <202305151957.34FJvR0v085499@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kirk McKusick Subject: git: 0a6e34e950cd - main - Fix size differences between architectures of the UFS/FFS CGSIZE macro value. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mckusick X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0a6e34e950cd5889122a199c34519b67569be9cc Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=0a6e34e950cd5889122a199c34519b67569be9cc commit 0a6e34e950cd5889122a199c34519b67569be9cc Author: Kirk McKusick AuthorDate: 2023-05-15 19:56:27 +0000 Commit: Kirk McKusick CommitDate: 2023-05-15 19:57:15 +0000 Fix size differences between architectures of the UFS/FFS CGSIZE macro value. The cylinder group header structure ended with `u_int8_t cg_space[1]' representing the beginning of the inode bitmap array. Some architectures like the i386 rounded this up to a 4-byte boundry while other architectures like the amd64 rounded it up to an 8-byte boundry. Thus sizeof(struct cg) was four bytes bigger on an amd64 machine than on an i386 machine. If a filesystem created on an i386 machine was moved to an amd64 machine, the size of the cylinder group calculated by the CGSIZE macro would appear to grow by four bytes. Filesystems whose cylinder groups were exactly equal to the block size on an i386 machine would appear to have a cylinder group that was four bytes too big when moved to an amd64 machine. Note that although the structure appears to be too big, it in fact is fine. It is just the calaculation of its size that is in error. The fix is to remove the cg_space element from the cylinder-group structure so that the calculated size of the structure is the same size on all architectures. Reported by: Tijl Coosemans Tested by: Tijl Coosemans and Peter Holm MFC after: 1 week Sponsored by: The FreeBSD Foundation --- sbin/fsck_ffs/fsutil.c | 4 ++-- sbin/fsck_ffs/pass5.c | 4 ++-- sbin/growfs/growfs.c | 2 +- sbin/newfs/mkfs.c | 5 +++-- sys/ufs/ffs/fs.h | 7 +++---- usr.sbin/makefs/ffs/mkfs.c | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sbin/fsck_ffs/fsutil.c b/sbin/fsck_ffs/fsutil.c index 48810954ba94..5e60aecf1826 100644 --- a/sbin/fsck_ffs/fsutil.c +++ b/sbin/fsck_ffs/fsutil.c @@ -1038,7 +1038,7 @@ check_cgmagic(int cg, struct bufarea *cgbp) CHK(cgp->cg_ndblk, !=, sblock.fs_size - cgbase(&sblock, cg), "%jd"); } - start = &cgp->cg_space[0] - (u_char *)(&cgp->cg_firstfield); + start = sizeof(*cgp); if (sblock.fs_magic == FS_UFS2_MAGIC) { CHK(cgp->cg_iusedoff, !=, start, "%jd"); } else if (sblock.fs_magic == FS_UFS1_MAGIC) { @@ -1098,7 +1098,7 @@ rebuild_cg(int cg, struct bufarea *cgbp) cgp->cg_ndblk = sblock.fs_fpg; else cgp->cg_ndblk = sblock.fs_size - cgbase(&sblock, cg); - start = &cgp->cg_space[0] - (u_char *)(&cgp->cg_firstfield); + start = sizeof(*cgp); if (sblock.fs_magic == FS_UFS2_MAGIC) { cgp->cg_iusedoff = start; } else if (sblock.fs_magic == FS_UFS1_MAGIC) { diff --git a/sbin/fsck_ffs/pass5.c b/sbin/fsck_ffs/pass5.c index 61be54ed54ed..58143a0e8211 100644 --- a/sbin/fsck_ffs/pass5.c +++ b/sbin/fsck_ffs/pass5.c @@ -116,7 +116,7 @@ pass5(void) } } } - basesize = &newcg->cg_space[0] - (u_char *)(&newcg->cg_firstfield); + basesize = sizeof(*newcg); if (sblock.fs_magic == FS_UFS2_MAGIC) { newcg->cg_iusedoff = basesize; } else { @@ -131,7 +131,7 @@ pass5(void) fs->fs_old_cpg * sizeof(int32_t); newcg->cg_iusedoff = newcg->cg_old_boff + fs->fs_old_cpg * fs->fs_old_nrpos * sizeof(u_int16_t); - memset(&newcg->cg_space[0], 0, newcg->cg_iusedoff - basesize); + memset(&newcg[1], 0, newcg->cg_iusedoff - basesize); } inomapsize = howmany(fs->fs_ipg, CHAR_BIT); newcg->cg_freeoff = newcg->cg_iusedoff + inomapsize; diff --git a/sbin/growfs/growfs.c b/sbin/growfs/growfs.c index 93a51d03b18d..51bf997406d0 100644 --- a/sbin/growfs/growfs.c +++ b/sbin/growfs/growfs.c @@ -338,7 +338,7 @@ initcg(int cylno, time_t modtime, int fso, unsigned int Nflag) acg.cg_ndblk = dmax - cbase; if (sblock.fs_contigsumsize > 0) acg.cg_nclusterblks = acg.cg_ndblk / sblock.fs_frag; - start = &acg.cg_space[0] - (u_char *)(&acg.cg_firstfield); + start = sizeof(acg); if (sblock.fs_magic == FS_UFS2_MAGIC) { acg.cg_iusedoff = start; } else { diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index d8580a789b1d..adc64f47cac6 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -721,7 +721,7 @@ initcg(int cylno, time_t utime) acg.cg_ndblk = dmax - cbase; if (sblock.fs_contigsumsize > 0) acg.cg_nclusterblks = acg.cg_ndblk / sblock.fs_frag; - start = &acg.cg_space[0] - (u_char *)(&acg.cg_firstfield); + start = sizeof(acg); if (Oflag == 2) { acg.cg_iusedoff = start; } else { @@ -749,7 +749,8 @@ initcg(int cylno, time_t utime) howmany(fragstoblks(&sblock, sblock.fs_fpg), CHAR_BIT); } if (acg.cg_nextfreeoff > (unsigned)sblock.fs_cgsize) { - printf("Panic: cylinder group too big\n"); + printf("Panic: cylinder group too big by %d bytes\n", + acg.cg_nextfreeoff - (unsigned)sblock.fs_cgsize); exit(37); } acg.cg_cs.cs_nifree += sblock.fs_ipg; diff --git a/sys/ufs/ffs/fs.h b/sys/ufs/ffs/fs.h index c2279c183fc5..7b7a1f9f2ef6 100644 --- a/sys/ufs/ffs/fs.h +++ b/sys/ufs/ffs/fs.h @@ -573,11 +573,11 @@ CTASSERT(sizeof(struct fs) == 1376); * cylinder group and the (struct cg) size. */ #define CGSIZE(fs) \ - /* base cg */ (sizeof(struct cg) + sizeof(int32_t) + \ + /* base cg */ (sizeof(struct cg) + \ /* old btotoff */ (fs)->fs_old_cpg * sizeof(int32_t) + \ /* old boff */ (fs)->fs_old_cpg * sizeof(u_int16_t) + \ /* inode map */ howmany((fs)->fs_ipg, NBBY) + \ - /* block map */ howmany((fs)->fs_fpg, NBBY) +\ + /* block map */ howmany((fs)->fs_fpg, NBBY) + sizeof(int32_t) + \ /* if present */ ((fs)->fs_contigsumsize <= 0 ? 0 : \ /* cluster sum */ (fs)->fs_contigsumsize * sizeof(int32_t) + \ /* cluster map */ howmany(fragstoblks(fs, (fs)->fs_fpg), NBBY))) @@ -624,8 +624,7 @@ struct cg { u_int32_t cg_ckhash; /* check-hash of this cg */ ufs_time_t cg_time; /* time last written */ int64_t cg_sparecon64[3]; /* reserved for future use */ - u_int8_t cg_space[1]; /* space for cylinder group maps */ -/* actually longer */ + /* actually longer - space used for cylinder group maps */ }; /* diff --git a/usr.sbin/makefs/ffs/mkfs.c b/usr.sbin/makefs/ffs/mkfs.c index ef745fe3c196..d48dc65aac68 100644 --- a/usr.sbin/makefs/ffs/mkfs.c +++ b/usr.sbin/makefs/ffs/mkfs.c @@ -634,7 +634,7 @@ initcg(uint32_t cylno, time_t utime, const fsinfo_t *fsopts) acg.cg_ndblk = dmax - cbase; if (sblock.fs_contigsumsize > 0) acg.cg_nclusterblks = acg.cg_ndblk >> sblock.fs_fragshift; - start = &acg.cg_space[0] - (u_char *)(&acg.cg_firstfield); + start = sizeof(acg); if (Oflag == 2) { acg.cg_iusedoff = start; } else {