git: 4a3834e31fdf - stable/13 - Fix size differences between architectures of the UFS/FFS CGSIZE macro value.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 26 May 2023 21:26:14 UTC
The branch stable/13 has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=4a3834e31fdf3a3bcd9413fa4d5d1c66cfbe02a2 commit 4a3834e31fdf3a3bcd9413fa4d5d1c66cfbe02a2 Author: Kirk McKusick <mckusick@FreeBSD.org> AuthorDate: 2023-05-15 19:56:27 +0000 Commit: Kirk McKusick <mckusick@FreeBSD.org> CommitDate: 2023-05-26 21:25:50 +0000 Fix size differences between architectures of the UFS/FFS CGSIZE macro value. Reported-by: Tijl Coosemans Tested-by: Tijl Coosemans and Peter Holm Sponsored-by: The FreeBSD Foundation (cherry picked from commit 0a6e34e950cd5889122a199c34519b67569be9cc) --- 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 b5ca478fbc46..bed87299a3cf 100644 --- a/sbin/fsck_ffs/fsutil.c +++ b/sbin/fsck_ffs/fsutil.c @@ -1037,7 +1037,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) { @@ -1097,7 +1097,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 c7ef0ced4ed6..281eec32836c 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 1efada0dad17..42866f9b1426 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -718,7 +718,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 { @@ -746,7 +746,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 8069b2db54bd..b2ed2051471c 100644 --- a/sys/ufs/ffs/fs.h +++ b/sys/ufs/ffs/fs.h @@ -534,11 +534,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))) @@ -585,8 +585,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 {