1
2Patch from Red Hat. See #463236, #463123.
3
4Index: grub/stage2/fsys_ext2fs.c
5===================================================================
6--- grub.orig/stage2/fsys_ext2fs.c	2008-05-27 18:47:19.045183000 +0100
7+++ grub/stage2/fsys_ext2fs.c	2008-05-27 19:09:21.293187000 +0100
8@@ -79,7 +79,52 @@
9     __u32 s_rev_level;		/* Revision level */
10     __u16 s_def_resuid;		/* Default uid for reserved blocks */
11     __u16 s_def_resgid;		/* Default gid for reserved blocks */
12-    __u32 s_reserved[235];	/* Padding to the end of the block */
13+    /*
14+     * These fields are for EXT2_DYNAMIC_REV superblocks only.
15+     *
16+     * Note: the difference between the compatible feature set and
17+     * the incompatible feature set is that if there is a bit set
18+     * in the incompatible feature set that the kernel doesn't
19+     * know about, it should refuse to mount the filesystem.
20+     *
21+     * e2fsck's requirements are more strict; if it doesn't know
22+     * about a feature in either the compatible or incompatible
23+     * feature set, it must abort and not try to meddle with
24+     * things it doesn't understand...
25+     */
26+    __u32 s_first_ino;		/* First non-reserved inode */
27+    __u16 s_inode_size;		/* size of inode structure */
28+    __u16 s_block_group_nr;	/* block group # of this superblock */
29+    __u32 s_feature_compat;	/* compatible feature set */
30+    __u32 s_feature_incompat;	/* incompatible feature set */
31+    __u32 s_feature_ro_compat;	/* readonly-compatible feature set */
32+    __u8  s_uuid[16];		/* 128-bit uuid for volume */
33+    char  s_volume_name[16];	/* volume name */
34+    char  s_last_mounted[64];	/* directory where last mounted */
35+    __u32 s_algorithm_usage_bitmap; /* For compression */
36+    /*
37+     * Performance hints.  Directory preallocation should only
38+     * happen if the EXT2_FEATURE_COMPAT_DIR_PREALLOC flag is on.
39+     */
40+    __u8  s_prealloc_blocks;	/* Nr of blocks to try to preallocate*/
41+    __u8  s_prealloc_dir_blocks;	/* Nr to preallocate for dirs */
42+    __u16 s_reserved_gdt_blocks;/* Per group table for online growth */
43+    /*
44+     * Journaling support valid if EXT2_FEATURE_COMPAT_HAS_JOURNAL set.
45+     */
46+    __u8 s_journal_uuid[16];	/* uuid of journal superblock */
47+    __u32 s_journal_inum;	/* inode number of journal file */
48+    __u32 s_journal_dev;	/* device number of journal file */
49+    __u32 s_last_orphan;	/* start of list of inodes to delete */
50+    __u32 s_hash_seed[4];	/* HTREE hash seed */
51+    __u8  s_def_hash_version;	/* Default hash version to use */
52+    __u8  s_jnl_backup_type; 	/* Default type of journal backup */
53+    __u16 s_reserved_word_pad;
54+    __u32 s_default_mount_opts;
55+    __u32 s_first_meta_bg;	/* First metablock group */
56+    __u32 s_mkfs_time;		/* When the filesystem was created */
57+    __u32 s_jnl_blocks[17]; 	/* Backup of the journal inode */
58+    __u32 s_reserved[172];	/* Padding to the end of the block */
59   };
60
61 struct ext2_group_desc
62@@ -218,6 +263,9 @@
63 #define EXT2_ADDR_PER_BLOCK(s)          (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
64 #define EXT2_ADDR_PER_BLOCK_BITS(s)		(log2(EXT2_ADDR_PER_BLOCK(s)))
65
66+#define EXT2_INODE_SIZE(s)		(SUPERBLOCK->s_inode_size)
67+#define EXT2_INODES_PER_BLOCK(s)	(EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s))
68+
69 /* linux/ext2_fs.h */
70 #define EXT2_BLOCK_SIZE_BITS(s)        ((s)->s_log_block_size + 10)
71 /* kind of from ext2/super.c */
72@@ -242,7 +290,14 @@
73 static __inline__ unsigned long
74 ffz (unsigned long word)
75 {
76-  __asm__ ("bsfl %1,%0"
77+  __asm__ ("bsf"
78+#ifdef __i386__
79+		  "l"
80+#endif
81+#ifdef __x86_64__
82+		  "q"
83+#endif
84+		  " %1,%0"
85 :	   "=r" (word)
86 :	   "r" (~word));
87   return word;
88@@ -553,7 +608,7 @@
89       gdp = GROUP_DESC;
90       ino_blk = gdp[desc].bg_inode_table +
91 	(((current_ino - 1) % (SUPERBLOCK->s_inodes_per_group))
92-	 >> log2 (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode)));
93+	 >> log2 (EXT2_INODES_PER_BLOCK (SUPERBLOCK)));
94 #ifdef E2DEBUG
95       printf ("inode table fsblock=%d\n", ino_blk);
96 #endif /* E2DEBUG */
97@@ -565,13 +620,12 @@
98       /* reset indirect blocks! */
99       mapblock2 = mapblock1 = -1;
100
101-      raw_inode = INODE +
102-	((current_ino - 1)
103-	 & (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode) - 1));
104+      raw_inode = (struct ext2_inode *)((char *)INODE +
105+	((current_ino - 1) & (EXT2_INODES_PER_BLOCK (SUPERBLOCK) - 1)) *
106+	EXT2_INODE_SIZE (SUPERBLOCK));
107 #ifdef E2DEBUG
108       printf ("ipb=%d, sizeof(inode)=%d\n",
109-	      (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode)),
110-	      sizeof (struct ext2_inode));
111+	      EXT2_INODES_PER_BLOCK (SUPERBLOCK), EXT2_INODE_SIZE (SUPERBLOCK));
112       printf ("inode=%x, raw_inode=%x\n", INODE, raw_inode);
113       printf ("offset into inode table block=%d\n", (int) raw_inode - (int) INODE);
114       for (i = (unsigned char *) INODE; i <= (unsigned char *) raw_inode;
115