NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: kern/59563: Use of FS_UFS2_MAGIC is problematic
The following reply was made to PR kern/59563; it has been noted by GNATS.
From: Christos Zoulas <christos%zoulas.com@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: kern-bug-people%netbsd.org@localhost,
gnats-admin%netbsd.org@localhost,
netbsd-bugs%netbsd.org@localhost,
thorpej%me.com@localhost
Subject: Re: kern/59563: Use of FS_UFS2_MAGIC is problematic
Date: Tue, 29 Jul 2025 15:14:37 -0400
--Apple-Mail=_51C24F3A-4923-441F-A01B-8A48DF44B2B2
Content-Type: multipart/mixed;
boundary="Apple-Mail=_3D71D1DA-3C68-41C0-A60C-A8B9EFB2BD8F"
--Apple-Mail=_3D71D1DA-3C68-41C0-A60C-A8B9EFB2BD8F
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=us-ascii
Here is a patch that does the first. But we can't avoid comparisons with =
FS_UFS2_MAGIC completely...
christos
--Apple-Mail=_3D71D1DA-3C68-41C0-A60C-A8B9EFB2BD8F
Content-Disposition: attachment;
filename=ufs.patch
Content-Type: application/octet-stream;
name=ufs.patch;
x-unix-mode=0664
Content-Transfer-Encoding: 7bit
? o
Index: ffs/ffs_alloc.c
===================================================================
RCS file: /cvsroot/src/sys/ufs/ffs/ffs_alloc.c,v
retrieving revision 1.174
diff -u -p -u -r1.174 ffs_alloc.c
--- ffs/ffs_alloc.c 27 Jun 2025 19:55:38 -0000 1.174
+++ ffs/ffs_alloc.c 29 Jul 2025 19:12:13 -0000
@@ -1280,7 +1280,7 @@ ffs_nodealloccg(struct inode *ip, u_int
return (0);
mutex_exit(&ump->um_lock);
ibp = NULL;
- if (fs->fs_magic == FS_UFS2_MAGIC) {
+ if (fs->fs_magic != FS_UFS1_MAGIC) {
initediblk = -1;
} else {
initediblk = fs->fs_ipg;
@@ -1305,7 +1305,7 @@ retry:
/*
* Check to see if we need to initialize more inodes.
*/
- if (fs->fs_magic == FS_UFS2_MAGIC && ibp == NULL) {
+ if (fs->fs_magic != FS_UFS1_MAGIC && ibp == NULL) {
initediblk = ufs_rw32(cgp->cg_initediblk, needswap);
maxiblk = initediblk;
nalloc = fs->fs_ipg - ufs_rw32(cgp->cg_cs.cs_nifree, needswap);
Index: ffs/ffs_balloc.c
===================================================================
RCS file: /cvsroot/src/sys/ufs/ffs/ffs_balloc.c,v
retrieving revision 1.66
diff -u -p -u -r1.66 ffs_balloc.c
--- ffs/ffs_balloc.c 17 Nov 2022 06:40:40 -0000 1.66
+++ ffs/ffs_balloc.c 29 Jul 2025 19:12:13 -0000
@@ -95,7 +95,7 @@ ffs_balloc(struct vnode *vp, off_t off,
{
int error;
- if (VTOI(vp)->i_fs->fs_magic == FS_UFS2_MAGIC)
+ if (VTOI(vp)->i_fs->fs_magic != FS_UFS1_MAGIC)
error = ffs_balloc_ufs2(vp, off, size, cred, flags, bpp);
else
error = ffs_balloc_ufs1(vp, off, size, cred, flags, bpp);
Index: ffs/ffs_bswap.c
===================================================================
RCS file: /cvsroot/src/sys/ufs/ffs/ffs_bswap.c,v
retrieving revision 1.40
diff -u -p -u -r1.40 ffs_bswap.c
--- ffs/ffs_bswap.c 9 Feb 2017 04:37:35 -0000 1.40
+++ ffs/ffs_bswap.c 29 Jul 2025 19:12:13 -0000
@@ -215,7 +215,7 @@ ffs_cg_swap(struct cg *o, struct cg *n,
for (i = 0; i < MAXFRAG; i++)
n->cg_frsum[i] = bswap32(o->cg_frsum[i]);
- if ((fs->fs_magic != FS_UFS2_MAGIC) &&
+ if ((fs->fs_magic == FS_UFS1_MAGIC) &&
(fs->fs_old_postblformat == FS_42POSTBLFMT)) { /* old format */
struct ocg *on, *oo;
int j;
@@ -258,7 +258,7 @@ ffs_cg_swap(struct cg *o, struct cg *n,
for (i = 1; i < fs->fs_contigsumsize + 1; i++)
n32[i] = bswap32(o32[i]);
- if (fs->fs_magic == FS_UFS2_MAGIC)
+ if (fs->fs_magic != FS_UFS1_MAGIC)
return;
n32 = (u_int32_t *)((u_int8_t *)n + btotoff);
Index: ffs/ffs_inode.c
===================================================================
RCS file: /cvsroot/src/sys/ufs/ffs/ffs_inode.c,v
retrieving revision 1.131
diff -u -p -u -r1.131 ffs_inode.c
--- ffs/ffs_inode.c 31 Jul 2020 04:07:30 -0000 1.131
+++ ffs/ffs_inode.c 29 Jul 2025 19:12:13 -0000
@@ -247,7 +247,7 @@ ffs_truncate(struct vnode *ovp, off_t le
#define i_din2 i_din.ffs2_din
extblocks = 0;
datablocks = DIP(oip, blocks);
- if (fs->fs_magic == FS_UFS2_MAGIC && oip->i_din2->di_extsize > 0) {
+ if (fs->fs_magic != FS_UFS1_MAGIC && oip->i_din2->di_extsize > 0) {
extblocks = btodb(ffs_fragroundup(fs, oip->i_din2->di_extsize));
datablocks -= extblocks;
}
Index: ffs/ffs_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/ufs/ffs/ffs_vfsops.c,v
retrieving revision 1.384
diff -u -p -u -r1.384 ffs_vfsops.c
--- ffs/ffs_vfsops.c 30 Dec 2024 09:03:07 -0000 1.384
+++ ffs/ffs_vfsops.c 29 Jul 2025 19:12:13 -0000
@@ -203,7 +203,7 @@ ffs_checkrange(struct mount *mp, ino_t i
* Need to check if inode is initialized because ffsv2 does
* lazy initialization and we can get here from nfs_fhtovp
*/
- if (fs->fs_magic != FS_UFS2_MAGIC)
+ if (fs->fs_magic == FS_UFS1_MAGIC)
return 0;
struct buf *bp;
@@ -2309,7 +2309,7 @@ ffs_newvnode(struct mount *mp, struct vn
/* Set up a new generation number for this inode. */
ip->i_gen++;
DIP_ASSIGN(ip, gen, ip->i_gen);
- if (fs->fs_magic == FS_UFS2_MAGIC) {
+ if (fs->fs_magic != FS_UFS1_MAGIC) {
vfs_timestamp(&ts);
ip->i_ffs2_birthtime = ts.tv_sec;
ip->i_ffs2_birthnsec = ts.tv_nsec;
Index: ffs/fs.h
===================================================================
RCS file: /cvsroot/src/sys/ufs/ffs/fs.h,v
retrieving revision 1.73
diff -u -p -u -r1.73 fs.h
--- ffs/fs.h 13 Dec 2024 22:32:45 -0000 1.73
+++ ffs/fs.h 29 Jul 2025 19:12:13 -0000
@@ -634,8 +634,8 @@ struct ocg {
#define cgstart_ufs1(fs, c) \
(cgbase(fs, c) + (fs)->fs_old_cgoffset * ((c) & ~((fs)->fs_old_cgmask)))
#define cgstart_ufs2(fs, c) cgbase((fs), (c))
-#define cgstart(fs, c) ((fs)->fs_magic == FS_UFS2_MAGIC \
- ? cgstart_ufs2((fs), (c)) : cgstart_ufs1((fs), (c)))
+#define cgstart(fs, c) ((fs)->fs_magic == FS_UFS1_MAGIC \
+ ? cgstart_ufs1((fs), (c)) : cgstart_ufs2((fs), (c)))
#define cgdmin(fs, c) (cgstart(fs, c) + (fs)->fs_dblkno) /* 1st data */
#define cgimin(fs, c) (cgstart(fs, c) + (fs)->fs_iblkno) /* inode blk */
#define cgsblock(fs, c) (cgstart(fs, c) + (fs)->fs_sblkno) /* super blk */
@@ -704,13 +704,13 @@ struct ocg {
#define ffs_blknum(fs, fsb) /* calculates rounddown(fsb, fs->fs_frag) */ \
((fsb) &~ ((fs)->fs_frag - 1))
#define ffs_getdb(fs, ip, lb) \
- ((fs)->fs_magic == FS_UFS2_MAGIC ? \
- (daddr_t)ufs_rw64((ip)->i_ffs2_db[lb], UFS_FSNEEDSWAP(fs)) : \
- (daddr_t)ufs_rw32((ip)->i_ffs1_db[lb], UFS_FSNEEDSWAP(fs)))
+ ((fs)->fs_magic == FS_UFS1_MAGIC ? \
+ (daddr_t)ufs_rw32((ip)->i_ffs1_db[lb], UFS_FSNEEDSWAP(fs)) : \
+ (daddr_t)ufs_rw64((ip)->i_ffs2_db[lb], UFS_FSNEEDSWAP(fs)))
#define ffs_getib(fs, ip, lb) \
- ((fs)->fs_magic == FS_UFS2_MAGIC ? \
- (daddr_t)ufs_rw64((ip)->i_ffs2_ib[lb], UFS_FSNEEDSWAP(fs)) : \
- (daddr_t)ufs_rw32((ip)->i_ffs1_ib[lb], UFS_FSNEEDSWAP(fs)))
+ ((fs)->fs_magic == FS_UFS1_MAGIC ? \
+ (daddr_t)ufs_rw32((ip)->i_ffs1_ib[lb], UFS_FSNEEDSWAP(fs)) : \
+ (daddr_t)ufs_rw64((ip)->i_ffs2_ib[lb], UFS_FSNEEDSWAP(fs))
/*
* Determine the number of available frags given a
--Apple-Mail=_3D71D1DA-3C68-41C0-A60C-A8B9EFB2BD8F
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=us-ascii
--Apple-Mail=_3D71D1DA-3C68-41C0-A60C-A8B9EFB2BD8F--
--Apple-Mail=_51C24F3A-4923-441F-A01B-8A48DF44B2B2
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename=signature.asc
Content-Type: application/pgp-signature;
name=signature.asc
Content-Description: Message signed with OpenPGP
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
iF0EARECAB0WIQS+BJlbqPkO0MDBdsRxESqxbLM7OgUCaIkdnQAKCRBxESqxbLM7
OuPyAKCiKyEdE8fzEpxmWzH+asrifsJMKgCfby+6au4fc44EDo1KuR/4mrZLhgM=
=bnwu
-----END PGP SIGNATURE-----
--Apple-Mail=_51C24F3A-4923-441F-A01B-8A48DF44B2B2--
Home |
Main Index |
Thread Index |
Old Index