[Parted-commits] GNU Parted Official Repository: Changes to 'master'

Debarshi Ray rishi-guest at alioth.debian.org
Thu Jan 8 09:53:12 UTC 2009


 libparted/fs/ext2/ext2_fs.h   |    6 +++
 libparted/fs/ext2/interface.c |   65 ++++++++++++++++++++++++++++++++++++------
 tests/Makefile.am             |    1 
 tests/t1700-ext-probe.sh      |   42 +++++++++++++++++++++++++++
 4 files changed, 105 insertions(+), 9 deletions(-)

New commits:
commit 91937d42c36ff29b55468f28e24673a2ab37d7c4
Author: Debarshi Ray <rishi at gnu.org>
Date:   Wed Jan 7 12:35:10 2009 +0530

    Differentiate between Ext4 and Ext3 file systems.
    
    Fixes http://parted.alioth.debian.org/cgi-bin/trac.cgi/ticket/188
    
    * libparted/fs/ext2/ext2_fs.h (EXT4_FEATURE_RO_COMPAT_HUGE_FILE,
    EXT4_FEATURE_RO_COMPAT_DIR_NLINK, 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_* bits set, 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.

diff --git a/libparted/fs/ext2/ext2_fs.h b/libparted/fs/ext2/ext2_fs.h
index 713cc21..d642518 100644
--- a/libparted/fs/ext2/ext2_fs.h
+++ b/libparted/fs/ext2/ext2_fs.h
@@ -15,7 +15,7 @@
 
 /*
  * EXT2_*_*() convienience macros added by Andrew Clausen <clausen at gnu.org>
- * Copyright (C) 2000 Free Software Foundation, Inc.
+ * Copyright (C) 2000, 2009 Free Software Foundation, Inc.
  */
 
 #ifndef _EXT2_FS_H
@@ -56,9 +56,13 @@
 
 #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER	0x0001
 #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE	0x0002
+#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE	0x0008
+#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK	0x0020
 
 #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..907f349 100644
--- a/libparted/fs/ext2/interface.c
+++ b/libparted/fs/ext2/interface.c
@@ -1,6 +1,6 @@
 /*
     interface.c -- parted binding glue to libext2resize
-    Copyright (C) 1998-2000, 2007 Free Software Foundation, Inc.
+    Copyright (C) 1998-2000, 2007, 2009 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
@@ -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,29 @@ _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;
+		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 = ((EXT2_SUPER_FEATURE_RO_COMPAT (sb)
+				    & EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
+				   || (EXT2_SUPER_FEATURE_RO_COMPAT (sb)
+				       & EXT4_FEATURE_RO_COMPAT_DIR_NLINK)
+				   || (EXT2_SUPER_FEATURE_INCOMPAT (sb)
+				       & EXT4_FEATURE_INCOMPAT_EXTENTS)
+				   || (EXT2_SUPER_FEATURE_INCOMPAT (sb)
+				       & EXT4_FEATURE_INCOMPAT_64BIT));
+			if (is_ext4)
+				is_ext3 = 0;
+		}
 
-		if (expect_ext3 != is_ext3)
+		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 +83,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 +96,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 +349,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 +379,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..5a0744d
--- /dev/null
+++ b/tests/t1700-ext-probe.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+# Copyright (C) 2008-2009 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
+
+for type in ext2 ext3 ext4; do
+
+( mkfs.$type -V ) >/dev/null 2>&1 ||
+  { echo "no $type support; skipping that test"; continue; }
+
+test_expect_success \
+    "create an $type file system" '
+    dd if=/dev/zero of=$dev bs=1024 count=4096 >/dev/null &&
+    mkfs -F -t $type $dev >/dev/null'
+
+test_expect_success \
+    "probe the $type file system" '
+    parted -s $dev print >out 2>1
+    grep -w $type out'
+
+done
+
+test_done



More information about the Parted-commits mailing list