Module Name:    src
Committed By:   christos
Date:           Sun Aug 27 16:35:51 UTC 2023

Modified Files:
        src/sys/ufs/ext2fs: ext2fs.h ext2fs_vfsops.c

Log Message:
- fix cgload/cgsave inconsistencies
- add a constant for the rev 0 group descriptor size


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/ufs/ext2fs/ext2fs.h
cvs rdiff -u -r1.224 -r1.225 src/sys/ufs/ext2fs/ext2fs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ext2fs/ext2fs.h
diff -u src/sys/ufs/ext2fs/ext2fs.h:1.51 src/sys/ufs/ext2fs/ext2fs.h:1.52
--- src/sys/ufs/ext2fs/ext2fs.h:1.51	Sat Aug 26 01:22:50 2023
+++ src/sys/ufs/ext2fs/ext2fs.h	Sun Aug 27 12:35:51 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs.h,v 1.51 2023/08/26 05:22:50 riastradh Exp $	*/
+/*	$NetBSD: ext2fs.h,v 1.52 2023/08/27 16:35:51 christos Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -444,6 +444,7 @@ struct ext2_gd {
 	uint32_t reserved2_hi[3];
 };
 
+#define	E2FS_REV0_GD_SIZE	(sizeof(struct ext2_gd) / 2)	/* 32 */
 #define E2FS_BG_INODE_UNINIT	0x0001	/* Inode bitmap not used/initialized */
 #define E2FS_BG_BLOCK_UNINIT	0x0002	/* Block bitmap not used/initialized */
 #define E2FS_BG_INODE_ZEROED	0x0004	/* On-disk inode table initialized */

Index: src/sys/ufs/ext2fs/ext2fs_vfsops.c
diff -u src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.224 src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.225
--- src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.224	Sat Aug 26 17:56:23 2023
+++ src/sys/ufs/ext2fs/ext2fs_vfsops.c	Sun Aug 27 12:35:51 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_vfsops.c,v 1.224 2023/08/26 21:56:23 christos Exp $	*/
+/*	$NetBSD: ext2fs_vfsops.c,v 1.225 2023/08/27 16:35:51 christos Exp $	*/
 
 /*
  * Copyright (c) 1989, 1991, 1993, 1994
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.224 2023/08/26 21:56:23 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.225 2023/08/27 16:35:51 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -179,8 +179,9 @@ e2fs_cgload(const char *ondisk, struct e
 		}
 	} else {
 		for (int i = 0; i < lim; i++, optr++, iptr += sh) {
-			memcpy(optr, iptr, 32);
-			memset((char *)optr + 32, 0, sizeof(*optr) - 32);
+			memcpy(optr, iptr, E2FS_REV0_GD_SIZE);
+			memset((char *)optr + E2FS_REV0_GD_SIZE, 0,
+			    sizeof(*optr) - E2FS_REV0_GD_SIZE);
 		}
 	}
 }
@@ -202,11 +203,11 @@ e2fs_cgsave(const struct ext2_gd *inmemo
 	if (shift_cg_entry_size > 6) {
 		for (int i = 0; i < lim; i++, iptr++, optr += sh) {
 			memcpy(optr, iptr, sizeof(*iptr));
-			memset(optr + sizeof(*optr), 0, sh - sizeof(*iptr));
+			memset(optr + sizeof(*iptr), 0, sh - sizeof(*iptr));
 		}
 	} else {
 		for (int i = 0; i < lim; i++, iptr++, optr += sh) {
-			memcpy(optr, iptr, 32);
+			memcpy(optr, iptr, E2FS_REV0_GD_SIZE);
 		}
 	}
 }
@@ -653,7 +654,7 @@ ext2fs_reload(struct mount *mp, kauth_cr
 		}
 		e2fs_cgload(bp->b_data,
 		    &fs->e2fs_gd[i * fs->e2fs_bsize / sizeof(struct ext2_gd)],
-		    fs->e2fs_bsize, 1 << fs->e2fs_group_desc_shift);
+		    fs->e2fs_bsize, fs->e2fs_group_desc_shift);
 		brelse(bp, 0);
 	}
 
@@ -769,7 +770,8 @@ ext2fs_mountfs(struct vnode *devvp, stru
 		    m_fs->e2fs_bsize, 0, &bp);
 		if (error)
 			goto out1;
-		e2fs_cgload(bp->b_data, &m_fs->e2fs_gd[i * sh],
+		e2fs_cgload(bp->b_data, &m_fs->e2fs_gd[i * m_fs->e2fs_bsize
+		    / sizeof(struct ext2_gd)],
 		    m_fs->e2fs_bsize, m_fs->e2fs_group_desc_shift);
 		brelse(bp, 0);
 		bp = NULL;

Reply via email to