[PATCH] Differentiate between Ext4 and Ext3 file systems. Fixes http://parted.alioth.debian.org/cgi-bin/trac.cgi/ticket/188

Debarshi Ray rishi at gnu.org
Mon Jan 5 19:32:38 UTC 2009


* libparted/fs/ext2/ext2_fs.h (EXT4_FEATURE_INCOMPAT_EXTENTS,
EXT4_FEATURE_INCOMPAT_64BIT): New constants.
* libparted/fs/ext2/interface.c (_ext2_generic_probe): Ext4 file systems
will have EXT4_FEATURE_INCOMPAT_EXTENTS, while Ext3 will not.
(_ext2_probe, _ext3_probe): Pass 2 and 3 respectively, instead of 0 and 1,
to _ext2_generic_probe.
(_ext4_probe): New function.
(_ext4_ops, _ext4_type): New structures.
(ped_file_system_ext2_init): Register Ext4 file system type.
(ped_file_system_ext2_done): Likewise.
* tests/Makefile.am (TESTS): Add t1700-ext-probe.sh.
* tests/t1700-ext-probe.sh: New file.
---
 libparted/fs/ext2/ext2_fs.h   |    2 +
 libparted/fs/ext2/interface.c |   61 +++++++++++++++++++++++++++++++++++-----
 tests/Makefile.am             |    1 +
 tests/t1700-ext-probe.sh      |   54 ++++++++++++++++++++++++++++++++++++
 4 files changed, 110 insertions(+), 8 deletions(-)
 create mode 100755 tests/t1700-ext-probe.sh

diff --git a/libparted/fs/ext2/ext2_fs.h b/libparted/fs/ext2/ext2_fs.h
index 713cc21..08d0c38 100644
--- a/libparted/fs/ext2/ext2_fs.h
+++ b/libparted/fs/ext2/ext2_fs.h
@@ -59,6 +59,8 @@

 #define EXT2_FEATURE_INCOMPAT_FILETYPE		0x0002
 #define EXT3_FEATURE_INCOMPAT_RECOVER		0x0004
+#define EXT4_FEATURE_INCOMPAT_EXTENTS           0x0040
+#define EXT4_FEATURE_INCOMPAT_64BIT             0x0080

 /*
  * Special inodes numbers
diff --git a/libparted/fs/ext2/interface.c b/libparted/fs/ext2/interface.c
index 8935840..80ae9bd 100644
--- a/libparted/fs/ext2/interface.c
+++ b/libparted/fs/ext2/interface.c
@@ -32,7 +32,7 @@ static PedFileSystemType _ext3_type;
 struct ext2_dev_handle*
ext2_make_dev_handle_from_parted_geometry(PedGeometry* geom);

 static PedGeometry*
-_ext2_generic_probe (PedGeometry* geom, int expect_ext3)
+_ext2_generic_probe (PedGeometry* geom, int expect_ext_ver)
 {
 	struct ext2_super_block sb;

@@ -46,10 +46,25 @@ _ext2_generic_probe (PedGeometry* geom, int expect_ext3)
 		PedSector group_nr = EXT2_SUPER_BLOCK_GROUP_NR(sb);
 		PedSector first_data_block = EXT2_SUPER_FIRST_DATA_BLOCK(sb);
 		int version = EXT2_SUPER_REV_LEVEL(sb);
-		int is_ext3 = (EXT2_SUPER_FEATURE_COMPAT(sb)
-				& EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0;
-
-		if (expect_ext3 != is_ext3)
+		int is_ext3 = 0;
+		int is_ext4 = 0;
+
+                is_ext3 = (EXT2_SUPER_FEATURE_COMPAT (sb)
+			   & EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0;
+                if (is_ext3) {
+                        is_ext4
+                            = is_ext3
+                                  && ((EXT2_SUPER_FEATURE_INCOMPAT (sb)
+                                      & EXT4_FEATURE_INCOMPAT_EXTENTS) != 0);
+                        if (is_ext4)
+                                is_ext3 = 0;
+                }
+
+		if (expect_ext_ver == 2 && (is_ext3 || is_ext4))
+			return NULL;
+		if (expect_ext_ver == 3 && !is_ext3)
+			return NULL;
+		else if (expect_ext_ver == 4 && !is_ext4)
 			return NULL;

 		if (version > 0 && group_nr > 0) {
@@ -64,7 +79,8 @@ _ext2_generic_probe (PedGeometry* geom, int expect_ext3)
 				return NULL;
 			ped_geometry_init (&probe_geom, geom->dev,
 					   start, block_count * block_size);
-			return _ext2_generic_probe (&probe_geom, expect_ext3);
+			return _ext2_generic_probe (&probe_geom,
+                                                    expect_ext_ver);
 		} else {
 			return ped_geometry_new (geom->dev, geom->start,
 						 block_count * block_size);
@@ -76,13 +92,19 @@ _ext2_generic_probe (PedGeometry* geom, int expect_ext3)
 static PedGeometry*
 _ext2_probe (PedGeometry* geom)
 {
-	return _ext2_generic_probe (geom, 0);
+	return _ext2_generic_probe (geom, 2);
 }

 static PedGeometry*
 _ext3_probe (PedGeometry* geom)
 {
-	return _ext2_generic_probe (geom, 1);
+	return _ext2_generic_probe (geom, 3);
+}
+
+static PedGeometry*
+_ext4_probe (PedGeometry* geom)
+{
+	return _ext2_generic_probe (geom, 4);
 }

 #ifndef DISCOVER_ONLY
@@ -323,6 +345,20 @@ static PedFileSystemOps _ext3_ops = {
 #endif /* !DISCOVER_ONLY */
 };

+static PedFileSystemOps _ext4_ops = {
+	probe:		_ext4_probe,
+	clobber:	NULL,
+	open:		NULL,
+	create:         NULL,
+	close:		NULL,
+	check:          NULL,
+	resize:		NULL,
+	copy:           NULL,
+	get_create_constraint:	NULL,
+	get_copy_constraint:	NULL,
+	get_resize_constraint:	NULL
+};
+
 #define EXT23_BLOCK_SIZES ((int[6]){512, 1024, 2048, 4096, 8192, 0})

 static PedFileSystemType _ext2_type = {
@@ -339,14 +375,23 @@ static PedFileSystemType _ext3_type = {
        block_sizes:      EXT23_BLOCK_SIZES
 };

+static PedFileSystemType _ext4_type = {
+       next:		 NULL,
+       ops:		 &_ext4_ops,
+       name:		 "ext4",
+       block_sizes:      EXT23_BLOCK_SIZES
+};
+
 void ped_file_system_ext2_init ()
 {
 	ped_file_system_type_register (&_ext2_type);
 	ped_file_system_type_register (&_ext3_type);
+	ped_file_system_type_register (&_ext4_type);
 }

 void ped_file_system_ext2_done ()
 {
 	ped_file_system_type_unregister (&_ext2_type);
 	ped_file_system_type_unregister (&_ext3_type);
+	ped_file_system_type_unregister (&_ext4_type);
 }
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ab3b7cb..1214f9c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -4,6 +4,7 @@ TESTS = \
   t1000-mkpartfs.sh \
   t1100-busy-label.sh \
   t1500-small-ext2.sh \
+  t1700-ext-probe.sh \
   t2000-mkfs.sh \
   t2100-mkswap.sh \
   t2200-dos-label-recog.sh \
diff --git a/tests/t1700-ext-probe.sh b/tests/t1700-ext-probe.sh
new file mode 100755
index 0000000..035753c
--- /dev/null
+++ b/tests/t1700-ext-probe.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+# Copyright (C) 2008 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+test_description='Probe Ext2, Ext3 and Ext4 file systems.'
+
+: ${srcdir=.}
+. $srcdir/test-lib.sh
+
+dev=loop-file
+test_expect_success \
+    'setup' '
+    dd if=/dev/zero of=$dev bs=1024 count=4096> /dev/null &&
+    mkfs -F -t ext2 $dev >/dev/null'
+
+test_expect_success \
+    'probe the ext2 file system' '
+    parted -s $dev print >out 2>&1
+    grep -w "ext2" out'
+
+test_expect_success \
+    'setup' '
+    dd if=/dev/zero of=$dev bs=1024 count=4096> /dev/null &&
+    mkfs -F -t ext3 $dev >/dev/null'
+
+test_expect_success \
+    'probe the ext3 file system' '
+    parted -s $dev print >out 2>&1
+    grep -w "ext3" out'
+
+test_expect_success \
+    'setup' '
+    dd if=/dev/zero of=$dev bs=1024 count=4096> /dev/null &&
+    mkfs -F -t ext4 $dev >/dev/null'
+
+test_expect_success \
+    'probe the ext4 file system' '
+    parted -s $dev print >out 2>&1
+    grep -w "ext4" out'
+
+test_done
-- 
1.6.0.6

Comments?

Happy hacking,
Debarshi

[1] http://rishi.fedorapeople.org/gnu/0001-Differentiate-between-Ext4-and-Ext3-file-systems.-Fi.patch



More information about the parted-devel mailing list