PERFORCE change 166249 for review

Aditya Sarawgi truncs at FreeBSD.org
Sun Jul 19 06:11:13 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=166249

Change 166249 by truncs at aditya on 2009/07/19 06:10:20

	Implementing ext2fs group descriptors in a new way because the old implementation uses some GPL'd 
	functions.

Affected files ...

.. //depot/projects/soc2009/soc_ext2fs/src/sys/gnu/fs/ext2fs/ext2_fs.h#25 edit
.. //depot/projects/soc2009/soc_ext2fs/src/sys/gnu/fs/ext2fs/ext2_vfsops.c#13 edit
.. //depot/projects/soc2009/soc_ext2fs/src/sys/gnu/fs/ext2fs/fs.h#9 edit

Differences ...

==== //depot/projects/soc2009/soc_ext2fs/src/sys/gnu/fs/ext2fs/ext2_fs.h#25 (text+ko) ====

@@ -58,6 +58,8 @@
 #define MAXMNTLEN 512
 #define EXT2_MAX_GROUP_LOADED 8
 #define buffer_head buf
+#define e2fs_cgload(old, new, size) memcpy((new), (old), (size));
+#define e2fs_cgsave(old, new, size) memcpy((new), (old), (size));
 /*
  * The second extended filesystem constants/structures
  */
@@ -360,6 +362,7 @@
 	uint32_t e2fs_blocksize_bits;
 	char e2fs_wasvalid;       /* valid at mount time */
 	off_t e2fs_maxfilesize;
+	struct ext2_gd *e2fs_gd; /* Group Descriptors */
 };
 
 

==== //depot/projects/soc2009/soc_ext2fs/src/sys/gnu/fs/ext2fs/ext2_vfsops.c#13 (text+ko) ====

@@ -84,7 +84,7 @@
 static int	ext2_mountfs(struct vnode *, struct mount *);
 static int	ext2_reload(struct mount *mp, struct thread *td);
 static int	ext2_sbupdate(struct ext2mount *, int);
-
+static int	ext2_cgupdate(struct ext2mount *, int);
 static vfs_unmount_t		ext2_unmount;
 static vfs_root_t		ext2_root;
 static vfs_statfs_t		ext2_statfs;
@@ -157,7 +157,7 @@
 	 */
 	if (mp->mnt_flag & MNT_UPDATE) {
 		ump = VFSTOEXT2(mp);
-		fs = ump->um_e2fs;
+		fs = ump->um_e2fs; 
 		error = 0;
 		if (fs->e2fs_ronly == 0 &&
 		    vfs_flagopt(opts, "ro", NULL, 0)) {
@@ -171,7 +171,7 @@
 				return (EBUSY);
 			error = ext2_flushfiles(mp, flags, td);
 			vfs_unbusy(mp);
-			if (!error && fs->e2fs_wasvalid) {
+			if ( error == 0 && fs->e2fs_wasvalid && ext2_cgupdate(ump, MNT_WAIT) == 0) {
 				fs->e2fs->e2fs_state |= E2FS_ISCLEAN;
 				ext2_sbupdate(ump, MNT_WAIT);
 			}
@@ -227,7 +227,7 @@
 				}
 			}
 			fs->e2fs->e2fs_state &= ~E2FS_ISCLEAN;
-			ext2_sbupdate(ump, MNT_WAIT);
+			(void)ext2_cgupdate(ump, MNT_WAIT);
 			fs->e2fs_ronly = 0;
 			MNT_ILOCK(mp);
 			mp->mnt_flag &= ~MNT_RDONLY;
@@ -303,6 +303,7 @@
  * Checks that the data in the descriptor blocks make sense
  * this is taken from ext2/super.c.
  */
+/*
 static int
 ext2_check_descriptors(struct m_ext2fs *sb)
 {
@@ -312,7 +313,7 @@
 	int i;
 
 	for (i = 0; i < sb->e2fs_gcount; i++) {
-		/* examine next descriptor block */
+		examine next descriptor block */  /*
 		if ((i % EXT2_DESC_PER_BLOCK(sb)) == 0)
 			gdp = (struct ext2_gd *)
 			    sb->e2fs_group_desc[desc_block++]->b_data;
@@ -346,7 +347,7 @@
 	}
 	return (1);
 }
-
+*/
 static int
 ext2_check_sb_compat(struct ext2fs *es, struct cdev *dev, int ronly)
 {
@@ -382,8 +383,9 @@
     struct m_ext2fs *fs)
 {
 	int db_count, error;
-	int i, j;
+	int i;
 	int logic_sb_block = 1;	/* XXX for now */
+	struct buf *bp;
 
 	fs->e2fs_bsize = EXT2_MIN_BLOCK_SIZE << es->e2fs_log_bsize;
 	fs->e2fs_bshift = EXT2_MIN_BLOCK_LOG_SIZE + es->e2fs_log_bsize;
@@ -425,6 +427,8 @@
 	fs->e2fs_gdbcount = db_count;
 	fs->e2fs_group_desc = malloc(db_count * sizeof (struct buf *),
 	    M_EXT2MNT, M_WAITOK);
+	fs->e2fs_gd = malloc(db_count * fs->e2fs_bsize,
+	    M_EXT2MNT, M_WAITOK);
 
 	/*
 	 * Adjust logic_sb_block.
@@ -433,27 +437,21 @@
 	 */
 	if(fs->e2fs_bsize > SBSIZE)
 		logic_sb_block = 0;
-
 	for (i = 0; i < db_count; i++) {
-		error = bread(devvp , fsbtodb(fs, logic_sb_block + i + 1),
-		    fs->e2fs_bsize, NOCRED, &fs->e2fs_group_desc[i]);
-		if(error) {
-			for (j = 0; j < i; j++)
-				brelse(fs->e2fs_group_desc[j]);
-			free(fs->e2fs_group_desc, M_EXT2MNT);
-			printf("EXT2-fs: unable to read group descriptors"
-			    " (%d)\n", error);
-			return (EIO);
+		error = bread(devvp ,
+			 fsbtodb(fs, logic_sb_block + i + 1 ),
+			fs->e2fs_bsize, NOCRED, &bp);
+		if (error) {
+			free(fs->e2fs_gd, M_EXT2MNT);
+			brelse(bp);
+			return (error);
 		}
-		LCK_BUF(fs->e2fs_group_desc[i])
-	}
-	if(!ext2_check_descriptors(fs)) {
-		for (j = 0; j < db_count; j++)
-			ULCK_BUF(fs->e2fs_group_desc[j])
-		free(fs->e2fs_group_desc, M_EXT2MNT);
-		printf("EXT2-fs: (ext2_check_descriptors failure) "
-		    "unable to read group descriptors\n");
-		return (EIO);
+		e2fs_cgload((struct ext2_gd *)bp->b_data,
+		    &fs->e2fs_gd[
+			i * fs->e2fs_bsize / sizeof(struct ext2_gd)],
+		    fs->e2fs_bsize);
+		brelse(bp);
+		bp = NULL;
 	}
 	for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++) {
 		fs->e2fs_ibn[i] = 0;
@@ -706,6 +704,7 @@
 		PICKUP_GIANT();
 	}
 	if (ump) {
+		free(ump->um_e2fs->e2fs_gd, M_EXT2MNT);
 		free(ump->um_e2fs->e2fs, M_EXT2MNT);
 		free(ump->um_e2fs, M_EXT2MNT);
 		free(ump, M_EXT2MNT);
@@ -735,17 +734,17 @@
 	ump = VFSTOEXT2(mp);
 	fs = ump->um_e2fs;
 	ronly = fs->e2fs_ronly;
-	if (ronly == 0) {
+	if (ronly == 0 && ext2_cgupdate(ump, MNT_WAIT) == 0) {
 		if (fs->e2fs_wasvalid)
-			fs->e2fs->e2fs_state |= E2FS_ISCLEAN;
-		ext2_sbupdate(ump, MNT_WAIT);
+ 			fs->e2fs->e2fs_state |= E2FS_ISCLEAN;
+ 		ext2_sbupdate(ump, MNT_WAIT);
 	}
 
 	/* release buffers containing group descriptors */
-	for(i = 0; i < fs->e2fs_gdbcount; i++)
+/*	for(i = 0; i < fs->e2fs_gdbcount; i++)
 		ULCK_BUF(fs->e2fs_group_desc[i])
 	free(fs->e2fs_group_desc, M_EXT2MNT);
-
+*/
 	/* release cached inode/block bitmaps */
 	for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++)
 		if (fs->e2fs_ib[i])
@@ -760,6 +759,7 @@
 	g_topology_unlock();
 	PICKUP_GIANT();
 	vrele(ump->um_devvp);
+	free(fs->e2fs_gd, M_EXT2MNT);
 	free(fs->e2fs, M_EXT2MNT);
 	free(fs, M_EXT2MNT);
 	free(ump, M_EXT2MNT);
@@ -909,7 +909,7 @@
 	if (fs->e2fs_fmod != 0) {
 		fs->e2fs_fmod = 0;
 		fs->e2fs->e2fs_wtime = time_second;
-		if ((error = ext2_sbupdate(ump, waitfor)) != 0)
+		if ((error = ext2_cgupdate(ump, waitfor)) != 0)
 			allerror = error;
 	}
 	return (allerror);
@@ -1106,7 +1106,31 @@
 	 */
 	return (error);
 }
+int
+ext2_cgupdate(struct ext2mount *mp, int waitfor)
+{
+	struct m_ext2fs *fs = mp->um_e2fs;
+	struct buf *bp;
+	int i, error = 0, allerror = 0;
+
+	allerror = ext2_sbupdate(mp, waitfor);
+	for (i = 0; i < fs->e2fs_gdbcount; i++) {
+		bp = getblk(mp->um_devvp, fsbtodb(fs,
+		    fs->e2fs->e2fs_first_dblock +
+		    1 /* superblock */ + i), fs->e2fs_bsize, 0, 0, 0);
+		e2fs_cgsave(&fs->e2fs_gd[
+		    i * fs->e2fs_bsize / sizeof(struct ext2_gd)],
+		    (struct ext2_gd *)bp->b_data, fs->e2fs_bsize);
+		if (waitfor == MNT_WAIT)
+			error = bwrite(bp);
+		else
+			bawrite(bp);
+	}
 
+	if (!allerror && error)
+		allerror = error;
+	return (allerror);
+}
 /*
  * Return the root of a filesystem.
  */

==== //depot/projects/soc2009/soc_ext2fs/src/sys/gnu/fs/ext2fs/fs.h#9 (text+ko) ====

@@ -83,8 +83,9 @@
 #define ino_to_cg(fs, x)	(((x) - 1) / (fs->e2fs_ipg))
 
 /* get block containing inode from its number x */
-#define	ino_to_fsba(fs, x)	fs_cs(fs, ino_to_cg(fs, x)).ext2bgd_i_tables + \
-	(((x)-1) % (fs->e2fs_ipg))/(fs->e2fs_ipb)
+#define ino_to_fsba(fs, x)                                              \
+        ((fs)->e2fs_gd[ino_to_cg((fs), (x))].ext2bgd_i_tables +         \
+        (((x) - 1) % (fs)->e2fs->e2fs_ipg) / (fs)->e2fs_ipb)
 
 /* get offset for inode in block */
 #define	ino_to_fsbo(fs, x)	((x-1) % (fs->e2fs_ipb))


More information about the p4-projects mailing list