ext4 extent support
PATCH 1/1 ext4 extent support
Hi,
This patch add support for extents in ext4.
Signature · 1 line
Bean
fs/ext2.c +104 -0
@@ -86,6 +86,8 @@#define EXT3_JOURNAL_FLAG_DELETED 4#define EXT3_JOURNAL_FLAG_LAST_TAG 8 +#define EXT4_EXTENTS_FLAG 0x80000 +/* The ext2 superblock. */ struct grub_ext2_sblock {
@@ -226,6 +228,33 @@ struct grub_ext3_journal_sblockgrub_uint32_t start; }; +#define EXT4_EXT_MAGIC 0xf30a + +struct grub_ext4_extent_header +{ +grub_uint16_t magic; +grub_uint16_t entries; +grub_uint16_t max; +grub_uint16_t depth; +grub_uint32_t generation; +}; + +struct grub_ext4_extent +{ +grub_uint32_t block; +grub_uint16_t len; +grub_uint16_t start_hi; +grub_uint32_t start; +}; + +struct grub_ext4_extent_idx +{ +grub_uint32_t block; +grub_uint32_t leaf; +grub_uint16_t leaf_hi; +grub_uint16_t unused; +}; +struct grub_fshelp_node {struct grub_ext2_data *data;
@@ -262,6 +291,46 @@ grub_ext2_blockgroup (struct grub_ext2_data *data, int group, sizeof (struct grub_ext2_block_group), (char *) blkgrp); } +static struct grub_ext4_extent_header * +grub_ext4_find_leaf (struct grub_ext2_data *data, +struct grub_ext4_extent_header *ext_block, +grub_uint32_t fileblock) +{ +char buf[EXT2_BLOCK_SIZE (data)]; +struct grub_ext4_extent_idx *index; + +while (1 ) + { +int i; +grub_disk_addr_t block; + + index = (struct grub_ext4_extent_idx *) (ext_block +1 ); + +if (grub_le_to_cpu16 (ext_block->magic) !=EXT4_EXT_MAGIC ) +return 0 ; + +if (ext_block->depth ==0 ) +return ext_block; + +for (i =0 ; i <grub_le_to_cpu16 (ext_block->entries); i++) + { +if (fileblock <grub_le_to_cpu32 (index[i].block)) +break ; + } + +if (i ==0 ) +return 0 ; + + block =grub_le_to_cpu16 (index[i].leaf_hi); + block = (block <<32 ) +grub_le_to_cpu32 (index[i].leaf); +if (grub_disk_read (data->disk, + block <<LOG2_EXT2_BLOCK_SIZE (data), +0 ,sizeof (buf), buf)) +return 0 ; + + ext_block = (struct grub_ext4_extent_header *) buf; + } +}static grub_disk_addr_t grub_ext2_read_block (grub_fshelp_node_t node,grub_disk_addr_t fileblock)
@@ -272,6 +341,41 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)unsigned int blksz =EXT2_BLOCK_SIZE (data);int log2_blksz =LOG2_EXT2_BLOCK_SIZE (data); +if (inode->flags &EXT4_EXTENTS_FLAG ) + { +struct grub_ext4_extent_header *leaf; +struct grub_ext4_extent *ext; +int i; + + leaf =grub_ext4_find_leaf (data, + (struct grub_ext4_extent_header *) inode->blocks.dir_blocks, + fileblock); +if (! leaf) + { +grub_error (GRUB_ERR_BAD_FS ,"invalid extent" ); +return -1 ; + } + + ext = (struct grub_ext4_extent *) (leaf +1 ); +for (i =0 ; i <grub_le_to_cpu16 (leaf->entries); i++) +if ((fileblock >=grub_le_to_cpu32 (ext[i].block)) && + (fileblock <grub_le_to_cpu32 (ext[i].block) + +grub_le_to_cpu16 (ext[i].len)) && + ((grub_le_to_cpu16 (ext[i].len) >>15 ) ==0 )) + { +grub_disk_addr_t start; + + start =grub_le_to_cpu16 (ext[i].start_hi); + start = (start <<32 ) +grub_le_to_cpu32 (ext[i].start); +return fileblock -grub_le_to_cpu32 (ext[i].block) + start; + } + + + +grub_printf ("HH\n" ); +return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET , +"ext2fs doesn't support extents" ); + }/* Direct blocks. */ if (fileblock <INDIRECT_BLOCKS ) blknr =grub_le_to_cpu32 (inode->blocks.dir_blocks[fileblock]);
Quoted 3 lines · Bean
Hi,
This patch add support for extents in ext4.
Nice.. how big is the size increase? I wonder if it would make sense to to split it in a separate module using a hook or a build system hack.
Or maybe this is overkill..
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What good is a phone call… if you are unable to speak? (as seen on /.)
Quoted 9 lines · Robert Millan
Quoted 3 lines · Bean
Hi,
This patch add support for extents in ext4.
Nice.. how big is the size increase? I wonder if it would make sense to to split it in a separate module using a hook or a build system hack.
Or maybe this is overkill..
Hi,
There is not much code, I think it's not necessary to split it.
Signature · 1 line
Bean
From: "Bean" <[email protected]>
Sent: Friday, July 04, 2008 7:59 PM
To: "The development of GRUB 2" <[email protected]>
Subject: [PATCH] ext4 extent support
Quoted 4 lines
Hi,
This patch add support for extents in ext4.
Thanks for the patch.I just tested it
GRUB now works fine with 31 MB /boot ext4 with extent and flex_bg, though flex_bg shouldn't make a difference on that small partiton With uninit_bg enabled, which isn't by default enabled by e2fsprogs 1.41WIP, GRUB loaded but failed to load my Linux kernel with "can't read linux header" Once I had GRUB failing with file not found and then going to rescue mode but I think I did something wrong.
Quoted 1 line · Felix Zielcke
GRUB now works fine with 31 MB /boot ext4 with extent
Wonderful!! Bean, you're awesome!
Quoted 2 lines
and
flex_bg, thoughflex_bgshouldn't make a difference on that small partiton
I think flex_bg support is unimplemented right now (at least I didn't see it anywhere), but it "worked" because it's not being used? Just a guess
From: "JavierMartín" <[email protected]>
Sent: Saturday, July 05, 2008 3:25 PM
To: "The development of GRUB 2" <[email protected]>
Subject: Re: [PATCH] ext4 extent support
Quoted 3 lines
I think
flex_bgsupport is unimplemented right now (at least I didn't see it anywhere), but it "worked" because it's not being used? Just a guess
I just checked.
Kernel 2.6.26-rc8 has a bit code with flex_bg
e2fsprogs 1.41WIP from Debian experimantel has a bit more code with flex (not much with flex_bg more flexbg or just _flex)
But I don't know much C so I don't understand the code :)
Anyway I think the most important ext4 support are extents, because you can enable them by just remounting to ext4 as long as you don't use noextents mount option flex_bg can only be enabled by mkfs.ext4(dev) not afterwards with tune2fs but it's default enabled in mke2fs.conf for ext4(dev) uninit_bg isn't enabled by default and can be enabled afterwards with tune2fs but resize2fs isn't currently working with it
Quoted 9 lines · Felix Zielcke
From: "JavierMartín" <[email protected]>
Sent: Saturday, July 05, 2008 3:25 PM
To: "The development of GRUB 2" <[email protected]>
Subject: Re: [PATCH] ext4 extent supportQuoted 3 lines
I think
flex_bgsupport is unimplemented right now (at least I didn't see it anywhere), but it "worked" because it's not being used? Just a guess
Quoted 12 lines
I just checked.
Kernel 2.6.26-rc8 has a bit code withflex_bg
e2fsprogs 1.41WIP from Debian experimantel has a bit more code with flex (not much withflex_bgmore flexbg or just_flex)
But I don't know much C so I don't understand the code :) Anyway I think the most important ext4 support are extents, because you can enable them by just remounting to ext4 as long as you don't use noextents mount optionflex_bgcan only be enabled bymkfs.ext4(dev)not afterwards with tune2fs but it's default enabled in mke2fs.conf for ext4(dev)uninit_bgisn't enabled by default and can be enabled afterwards with tune2fs but resize2fs isn't currently working with it
I mean unimplemented in GRUB right now. IIrc, flex_bg relaxes some of the rules governing the location of the metadata block groups or something like that, so that they can be placed in "arbitrary" locations.Uninit_bg allows yet-unused block groups and inode tables to be initalized on first use, and saves a lot of time in mkfs (because it doesn't have to write all the inode tables) and fsck (because there's no need to check unused block groups at all).
Quoted 22 lines · Javier Martín
Quoted 9 lines · Felix Zielcke
From: "JavierMartín" <[email protected]>
Sent: Saturday, July 05, 2008 3:25 PM
To: "The development of GRUB 2" <[email protected]>
Subject: Re: [PATCH] ext4 extent supportQuoted 3 lines
I think
flex_bgsupport is unimplemented right now (at least I didn't see it anywhere), but it "worked" because it's not being used? Just a guessQuoted 12 lines
I just checked.
Kernel 2.6.26-rc8 has a bit code withflex_bg
e2fsprogs 1.41WIP from Debian experimantel has a bit more code with flex (not much withflex_bgmore flexbg or just_flex)
But I don't know much C so I don't understand the code :) Anyway I think the most important ext4 support are extents, because you can enable them by just remounting to ext4 as long as you don't use noextents mount optionflex_bgcan only be enabled bymkfs.ext4(dev)not afterwards with tune2fs but it's default enabled in mke2fs.conf for ext4(dev)uninit_bgisn't enabled by default and can be enabled afterwards with tune2fs but resize2fs isn't currently working with it
Quoted 4 lines
I mean unimplemented in GRUB right now. IIrc,
flex_bgrelaxes some of the rules governing the location of the metadata block groups or something like that, so that they can be placed in "arbitrary" locations.
Hi,
I found the description of flex_bg:
This feature relaxes check restrictions on where each block groups meta data is located within the storage media. This allows for the allocation of bitmaps or inode tables outside the block group boundaries in cases where bad blocks forces us to look for new blocks which the owning block group can not satisfy. This will also allow for new meta-data allocation schemes to improve performance and scalability.
The reallocation only occurs when bad blocks force us to use another block group, which is quite rare. So we should silently ignore this flag.
Signature · 1 line
Bean
From: "Bean" <[email protected]>
Sent: Sunday, July 06, 2008 6:51 AM
To: "The development of GRUB 2" <[email protected]>
Subject: Re: [PATCH] ext4 extent support
Quoted 9 lines
I found the description of
flex_bg:This feature relaxes check restrictions on where each block groups meta data is located within the storage media. This allows for the allocation of bitmaps or inode tables outside the block group boundaries in cases where bad blocks forces us to look for new blocks which the owning block group can not satisfy. This will also allow for new meta-data allocation schemes to improve performance and scalability.
Quoted 4 lines
The reallocation only occurs when bad blocks force us to use another block group, which is quite rare. So we should silently ignore this flag.
Hm, I just saw that there's a next branch in Tytso's ext4 git tree [1]
I always looked at the normal HEAD tree or whatever it's called on git, I don't know much about git slang :) There in Documentation/filesystems/ext4.txt it says:
* ability to pack bitmaps and inode tables into larger virtual groups via the flex_bg feature
* Inode allocation using large virtual block groups via flex_bg
mke2fs man page [2] says:
Allow bitmaps and inode tables for a block group to be placed anywhere on the storage media (use with -G option to group meta-data in order to create a large virtual block group).
But because I don't know what that exactly means I'm not sure if GRUB code needs to be a bit changed for it or not :)
[1] http://git.kernel.org/?p=linux/kernel/git/tytso/ext4.git;a=tree;h=next;hb=next
[2] http://git.kernel.org/?p=fs/ext2/e2fsprogs.git;a=blob;f=misc/mke2fs.8.in;hb=HEAD
--------------------------------------------------
From: "JavierMartín" <[email protected]>
Sent: Saturday, July 05, 2008 8:09 PM
To: "The development of GRUB 2" <[email protected]>
Subject: Re: [PATCH] ext4 extent support
Quoted 1 line
I mean unimplemented in GRUB right now.
Ah yeah of course :)
Quoted 9 lines
IIrc,
flex_bgrelaxes some of
the rules governing the location of the metadata block groups or something like that, so that they can be placed in "arbitrary" locations.Uninit_bgallows yet-unused block groups and inode tables to be initalized on first use, and saves a lot of time in mkfs (because it doesn't have to write all the inode tables) and fsck (because there's no
need to check unused block groups at all).
Yeah I read sth. about these ext4 features before I started to try it out.
But I thought extN on a small new created filesystem with no deleted files works like inode/block 0 to x is used and x+1 to end is unused so it shouldn't make a difference with uninit_bg enabled or not GRUB wouldn't get to these unused inodes/blocks
Seems like there's still much I could learn :)
Oh and by the way
http://tytso.livejournal.com/57492.html
The ext4 developer is now using ext4 as primary fs on his notebook
and he says it should be in a few weeks ready to be used for production data
So seems like not a bad Idea to think about ext4 support in GRUB :)
I only had problems with 2.6.25 Kernel. Since I switched from that one to 2.6.26-rc7 ext4 worked fine But I only use it in a VMware test system which isn't used much
Hi Bean,
Quoted 1 line · Bean
This patch add support for extents in ext4.
This is really great! :D
Can you also provide a changelog entry?
Quoted 120 lines
fs/ext2.c +91
-0@@ -86,6 +86,8 @@#define EXT3_JOURNAL_FLAG_DELETED 4#define EXT3_JOURNAL_FLAG_LAST_TAG 8 +#define EXT4_EXTENTS_FLAG 0x80000 +/* The ext2 superblock. */ struct grub_ext2_sblock {@@ -226,6 +228,33 @@ struct grub_ext3_journal_sblockgrub_uint32_t start; }; +#define EXT4_EXT_MAGIC 0xf30a + +struct grub_ext4_extent_header +{ +grub_uint16_t magic; +grub_uint16_t entries; +grub_uint16_t max; +grub_uint16_t depth; +grub_uint32_t generation; +}; + +struct grub_ext4_extent +{ +grub_uint32_t block; +grub_uint16_t len; +grub_uint16_t start_hi; +grub_uint32_t start; +}; + +struct grub_ext4_extent_idx +{ +grub_uint32_t block; +grub_uint32_t leaf; +grub_uint16_t leaf_hi; +grub_uint16_t unused; +}; +struct grub_fshelp_node {struct grub_ext2_data *data;@@ -262,6 +291,46 @@ grub_ext2_blockgroup (struct grub_ext2_data *data, int group, sizeof (struct grub_ext2_block_group), (char *) blkgrp); } +static struct grub_ext4_extent_header * +grub_ext4_find_leaf (struct grub_ext2_data *data, +struct grub_ext4_extent_header *ext_block, +grub_uint32_t fileblock) +{ +char buf[EXT2_BLOCK_SIZE (data)]; +struct grub_ext4_extent_idx *index; + +while (1 ) + { +int i; +grub_disk_addr_t block; + + index = (struct grub_ext4_extent_idx *) (ext_block +1 ); + +if (grub_le_to_cpu16 (ext_block->magic) !=EXT4_EXT_MAGIC ) +return 0 ; + +if (ext_block->depth ==0 ) +return ext_block; + +for (i =0 ; i <grub_le_to_cpu16 (ext_block->entries); i++) + { +if (fileblock <grub_le_to_cpu32 (index[i].block)) +break ; + } + +if (i ==0 ) +return 0 ; + + block =grub_le_to_cpu16 (index[i].leaf_hi); + block = (block <<32 ) +grub_le_to_cpu32 (index[i].leaf); +if (grub_disk_read (data->disk, + block <<LOG2_EXT2_BLOCK_SIZE (data), +0 ,sizeof (buf), buf)) +return 0 ; + + ext_block = (struct grub_ext4_extent_header *) buf; + } +}static grub_disk_addr_t grub_ext2_read_block (grub_fshelp_node_t node,grub_disk_addr_t fileblock)@@ -272,6 +341,41 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)unsigned int blksz =EXT2_BLOCK_SIZE (data);int log2_blksz =LOG2_EXT2_BLOCK_SIZE (data); +if (inode->flags &EXT4_EXTENTS_FLAG ) + { +struct grub_ext4_extent_header *leaf; +struct grub_ext4_extent *ext; +int i; + + leaf =grub_ext4_find_leaf (data, + (struct grub_ext4_extent_header *) inode->blocks.dir_blocks, + fileblock); +if (! leaf) + { +grub_error (GRUB_ERR_BAD_FS ,"invalid extent" ); +return -1 ; + } + + ext = (struct grub_ext4_extent *) (leaf +1 ); +for (i =0 ; i <grub_le_to_cpu16 (leaf->entries); i++) +if ((fileblock >=grub_le_to_cpu32 (ext[i].block)) && + (fileblock <grub_le_to_cpu32 (ext[i].block) + +grub_le_to_cpu16 (ext[i].len)) && + ((grub_le_to_cpu16 (ext[i].len) >>15 ) ==0 )) + {
fs/ext2.c grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) · line 375
Quoted 10 lines
fs/ext2.c +10
-0+grub_disk_addr_t start; + + start =grub_le_to_cpu16 (ext[i].start_hi); + start = (start <<32 ) +grub_le_to_cpu32 (ext[i].start); +return fileblock -grub_le_to_cpu32 (ext[i].block) + start; + } + + + +grub_printf ("HH\n" );
Whoops? ;-)
fs/ext2.c grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) · line 377
Quoted 2 lines
fs/ext2.c +2
-0+return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET , +"ext2fs doesn't support extents" );
Why the error? I thought you have added extent support? Doesn't this mean the extent has another error of some kind?
--
Marco
Quoted 9 lines · Marco Gerards
Quoted 1 line
+
grub_printf("HH\n");Whoops? ;-)
Review
Quoted 2 lines
(quoted diff) +2
-0+ return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "ext2fs doesn't support extents");Why the error? I thought you have added extent support? Doesn't this mean the extent has another error of some kind?
Hi,
Oh, I forget to cleanup the code, here is the new patch.
2008-07-06 Bean <[email protected]>
* fs/ext2.c (EXT4_EXTENTS_FLAG): New macro. (grub_ext4_extent_header): New structure. (grub_ext4_extent): Likewise. (grub_ext4_extent_idx): Likewise. (grub_ext4_find_leaf): New function. (grub_ext2_read_block): Handle extents.
Signature · 1 line
Bean
fs/ext2.c +101 -0
@@ -86,6 +86,8 @@#define EXT3_JOURNAL_FLAG_DELETED 4#define EXT3_JOURNAL_FLAG_LAST_TAG 8 +#define EXT4_EXTENTS_FLAG 0x80000 +/* The ext2 superblock. */ struct grub_ext2_sblock {
@@ -226,6 +228,33 @@ struct grub_ext3_journal_sblockgrub_uint32_t start; }; +#define EXT4_EXT_MAGIC 0xf30a + +struct grub_ext4_extent_header +{ +grub_uint16_t magic; +grub_uint16_t entries; +grub_uint16_t max; +grub_uint16_t depth; +grub_uint32_t generation; +}; + +struct grub_ext4_extent +{ +grub_uint32_t block; +grub_uint16_t len; +grub_uint16_t start_hi; +grub_uint32_t start; +}; + +struct grub_ext4_extent_idx +{ +grub_uint32_t block; +grub_uint32_t leaf; +grub_uint16_t leaf_hi; +grub_uint16_t unused; +}; +struct grub_fshelp_node {struct grub_ext2_data *data;
@@ -262,6 +291,46 @@ grub_ext2_blockgroup (struct grub_ext2_data *data, int group, sizeof (struct grub_ext2_block_group), (char *) blkgrp); } +static struct grub_ext4_extent_header * +grub_ext4_find_leaf (struct grub_ext2_data *data, +struct grub_ext4_extent_header *ext_block, +grub_uint32_t fileblock) +{ +char buf[EXT2_BLOCK_SIZE (data)]; +struct grub_ext4_extent_idx *index; + +while (1 ) + { +int i; +grub_disk_addr_t block; + + index = (struct grub_ext4_extent_idx *) (ext_block +1 ); + +if (grub_le_to_cpu16 (ext_block->magic) !=EXT4_EXT_MAGIC ) +return 0 ; + +if (ext_block->depth ==0 ) +return ext_block; + +for (i =0 ; i <grub_le_to_cpu16 (ext_block->entries); i++) + { +if (fileblock <grub_le_to_cpu32 (index[i].block)) +break ; + } + +if (i ==0 ) +return 0 ; + + block =grub_le_to_cpu16 (index[i].leaf_hi); + block = (block <<32 ) +grub_le_to_cpu32 (index[i].leaf); +if (grub_disk_read (data->disk, + block <<LOG2_EXT2_BLOCK_SIZE (data), +0 ,sizeof (buf), buf)) +return 0 ; + + ext_block = (struct grub_ext4_extent_header *) buf; + } +}static grub_disk_addr_t grub_ext2_read_block (grub_fshelp_node_t node,grub_disk_addr_t fileblock)
@@ -272,6 +341,38 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)unsigned int blksz =EXT2_BLOCK_SIZE (data);int log2_blksz =LOG2_EXT2_BLOCK_SIZE (data); +if (inode->flags &EXT4_EXTENTS_FLAG ) + { +struct grub_ext4_extent_header *leaf; +struct grub_ext4_extent *ext; +int i; + + leaf =grub_ext4_find_leaf (data, + (struct grub_ext4_extent_header *) inode->blocks.dir_blocks, + fileblock); +if (! leaf) + { +grub_error (GRUB_ERR_BAD_FS ,"invalid extent" ); +return -1 ; + } + + ext = (struct grub_ext4_extent *) (leaf +1 ); +for (i =0 ; i <grub_le_to_cpu16 (leaf->entries); i++) +if ((fileblock >=grub_le_to_cpu32 (ext[i].block)) && + (fileblock <grub_le_to_cpu32 (ext[i].block) + +grub_le_to_cpu16 (ext[i].len)) && + ((grub_le_to_cpu16 (ext[i].len) >>15 ) ==0 )) + { +grub_disk_addr_t start; + + start =grub_le_to_cpu16 (ext[i].start_hi); + start = (start <<32 ) +grub_le_to_cpu32 (ext[i].start); +return fileblock -grub_le_to_cpu32 (ext[i].block) + start; + } + +grub_error (GRUB_ERR_BAD_FS ,"something wrong with extent" ); +return -1 ; + }/* Direct blocks. */ if (fileblock <INDIRECT_BLOCKS ) blknr =grub_le_to_cpu32 (inode->blocks.dir_blocks[fileblock]);
From: "Bean" <[email protected]>
Sent: Friday, July 04, 2008 7:59 PM
To: "The development of GRUB 2" <[email protected]>
Subject: [PATCH] ext4 extent support
Quoted 7 lines
Hi,
This patch add support for extents in ext4.
Signature · 1 line
Bean
Any news? Will it be committed soon?
Just saw that there's a commit on e2fsprogs 1.41 wich enables uninit_bg enables for ext4 by default. It would be very nice if grub would support that, too :)
huge_file,dir_nlink,extra_isize are enabled now, too but these are ROCOMPAT features so no need to worry
Tytso wants to get e2fsprogs 1.41 into lenny [1] Woudn' be that bad if grub would support ext4 on lenny
[1] http://lists.debian.org/debian-release/2008/07/msg00120.html
Quoted 18 lines · Felix Zielcke
From: "Bean" <[email protected]>
Sent: Friday, July 04, 2008 7:59 PM
To: "The development of GRUB 2" <[email protected]>
Subject: [PATCH] ext4 extent supportQuoted 7 lines
Hi,
This patch add support for extents in ext4.
--
BeanAny news? Will it be committed soon?
Just saw that there's a commit on e2fsprogs 1.41 wich enablesuninit_bgenables for ext4 by default.
It would be very nice if grub would support that, too :)
Quoted 7 lines
huge_file,dir_nlink,extra_isize are enabled now, too but these are ROCOMPAT features so no need to worry
Tytso wants to get e2fsprogs 1.41 into lenny [1] Woudn' be that bad if grub would support ext4 on lenny
[1] http://lists.debian.org/debian-release/2008/07/msg00120.html
Hi,
Can you make a small test image with uninit_bg flag enabled ?
Signature · 1 line
Bean
From: "Bean" <[email protected]>
Sent: Friday, July 11, 2008 9:25 AM
To: "The development of GRUB 2" <[email protected]>
Subject: Re: [PATCH] ext4 extent support
Quoted 6 lines
Hi,
Can you make a small test image with
uninit_bgflag enabled ?Signature · 1 line
Bean
Attached, i made it 30 MB big, because that's the size of the /boot I tested with but that shouldn't matter Thanks for working on it, very nice :)
Quoted 7 lines · Felix Zielcke
From: "Bean" <[email protected]>
Sent: Friday, July 11, 2008 9:25 AM
To: "The development of GRUB 2" <[email protected]>
Subject: Re: [PATCH] ext4 extent supportQuoted 2 lines
Hi,
Quoted 8 lines
Quoted 4 lines
Can you make a small test image with
uninit_bgflag enabled ?--
BeanAttached, i made it 30 MB big, because that's the size of the /boot I tested with but that shouldn't matter
Thanks for working on it, very nice :)
Hi,
Is the image empty ? Perhaps you can add a few files to it. Also, you can use grub-fstest to check if grub can access it, For example:
grub-fstest ext4.img ls /
grub-fstest ext4.img ls /boot
grub-fstest ext4.img hex /boot/grub.cfg
Signature · 1 line
Bean
From: "Bean" <[email protected]>
Sent: Friday, July 11, 2008 10:17 AM
To: "The development of GRUB 2" <[email protected]>
Subject: Re: [PATCH] ext4 extent support
Quoted 5 lines
Hi,
Is the image empty ? Perhaps you can add a few files to it. Also, you can use grub-fstest to check if grub can access it, For example:
Urm, yeah sorry, didn't think that it could be more helpful with files on it I copied now my /boot to it
Seems like 1,9 MB is too big for the mailing list, message returned So i just uploaded to rapidshare
http://rapidshare.com/files/128833892/ext4.img.bz2.html
But if you like i'll send it to you offlist
Quoted 3 lines
grub-fstest ext4.img ls /
grub-fstest ext4.img ls /boot
grub-fstest ext4.img hex/boot/grub.cfg
just with ext4.img it didn't worked, it complained about not using an absolute path
# grub2/grub-fstest /root/ext4.img ls / lost+found/ grub/ System.map-2.6.26-rc9 config-2.6.26-rc9 vmlinuz-2.6.26-rc9 # grub2/grub-fstest /root/ext4.img ls /grub/ _linux.mod amiga.mod ascii.pff biosdisk.mod bitmap.mod cdboot.img [...] vbeinfo.mod video.mod # grub2/grub-fstest /root/ext4.img hex /grub/grub.cfg 00000000 23 0a 23 20 44 4f 20 4e 4f 54 20 45 44 49 54 20 |#.# DO NOT EDIT | 00000010 54 48 49 53 20 46 49 4c 45 0a 23 0a 23 20 49 74 |THIS FILE.#.# It| 00000020 20 69 73 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c | is automaticall| [...] 00000470 44 20 2f 65 74 63 2f 67 72 75 62 2e 64 2f 33 30 |D /etc/grub.d/30| 00000480 5f 6f 73 2d 70 72 6f 62 65 72 20 23 23 23 0a |_os-prober ###.| # grub2/grub-fstest /root/ext4.img hex /vmlinuz-2.6.26-rc9 grub-fstest: error: read error at offset 0. # grub2/grub-fstest /root/ext4.img ls /vmlinuz-2.6.26-rc9 vmlinuz-2.6.26-rc9
Quoted 40 lines · Felix Zielcke
From: "Bean" <[email protected]>
Sent: Friday, July 11, 2008 10:17 AM
To: "The development of GRUB 2" <[email protected]>
Subject: Re: [PATCH] ext4 extent supportQuoted 5 lines
Hi,
Is the image empty ? Perhaps you can add a few files to it. Also, you can use grub-fstest to check if grub can access it, For example:
Urm, yeah sorry, didn't think that it could be more helpful with files on it I copied now my /boot to it
Seems like 1,9 MB is too big for the mailing list, message returned So i just uploaded to rapidsharehttp://rapidshare.com/files/128833892/ext4.img.bz2.html
But if you like i'll send it to you offlist
Quoted 3 lines
grub-fstest ext4.img ls /
grub-fstest ext4.img ls /boot
grub-fstest ext4.img hex/boot/grub.cfgjust with ext4.img it didn't worked, it complained about not using an absolute path
# grub2/grub-fstest /root/ext4.img ls / lost+found/ grub/ System.map-2.6.26-rc9 config-2.6.26-rc9 vmlinuz-2.6.26-rc9 # grub2/grub-fstest /root/ext4.img ls /grub/ _linux.mod amiga.mod ascii.pff biosdisk.mod bitmap.mod cdboot.img [...] vbeinfo.mod video.mod # grub2/grub-fstest /root/ext4.img hex /grub/grub.cfg 00000000 23 0a 23 20 44 4f 20 4e 4f 54 20 45 44 49 54 20 |#.# DO NOT EDIT | 00000010 54 48 49 53 20 46 49 4c 45 0a 23 0a 23 20 49 74 |THIS FILE.#.# It| 00000020 20 69 73 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c | is automaticall| [...]
Quoted 8 lines
00000470 44 20 2f 65 74 63 2f 67 72 75 62 2e 64 2f 33 30 |D /etc/grub.d/30| 00000480 5f 6f 73 2d 70 72 6f 62 65 72 20 23 23 23 0a |_os-prober ###.| # grub2/grub-fstest /root/ext4.img hex /vmlinuz-2.6.26-rc9 grub-fstest: error: read error at offset 0. # grub2/grub-fstest /root/ext4.img ls /vmlinuz-2.6.26-rc9 vmlinuz-2.6.26-rc9
Hi,
This patch should fix the problem.
Signature · 1 line
Bean
fs/ext2.c +112 -0
@@ -86,6 +86,8 @@#define EXT3_JOURNAL_FLAG_DELETED 4#define EXT3_JOURNAL_FLAG_LAST_TAG 8 +#define EXT4_EXTENTS_FLAG 0x80000 +/* The ext2 superblock. */ struct grub_ext2_sblock {
@@ -226,6 +228,33 @@ struct grub_ext3_journal_sblockgrub_uint32_t start; }; +#define EXT4_EXT_MAGIC 0xf30a + +struct grub_ext4_extent_header +{ +grub_uint16_t magic; +grub_uint16_t entries; +grub_uint16_t max; +grub_uint16_t depth; +grub_uint32_t generation; +}; + +struct grub_ext4_extent +{ +grub_uint32_t block; +grub_uint16_t len; +grub_uint16_t start_hi; +grub_uint32_t start; +}; + +struct grub_ext4_extent_idx +{ +grub_uint32_t block; +grub_uint32_t leaf; +grub_uint16_t leaf_hi; +grub_uint16_t unused; +}; +struct grub_fshelp_node {struct grub_ext2_data *data;
@@ -262,6 +291,45 @@ grub_ext2_blockgroup (struct grub_ext2_data *data, int group, sizeof (struct grub_ext2_block_group), (char *) blkgrp); } +static struct grub_ext4_extent_header * +grub_ext4_find_leaf (struct grub_ext2_data *data,char *buf, +struct grub_ext4_extent_header *ext_block, +grub_uint32_t fileblock) +{ +struct grub_ext4_extent_idx *index; + +while (1 ) + { +int i; +grub_disk_addr_t block; + + index = (struct grub_ext4_extent_idx *) (ext_block +1 ); + +if (grub_le_to_cpu16 (ext_block->magic) !=EXT4_EXT_MAGIC ) +return 0 ; + +if (ext_block->depth ==0 ) +return ext_block; + +for (i =0 ; i <grub_le_to_cpu16 (ext_block->entries); i++) + { +if (fileblock <grub_le_to_cpu32 (index[i].block)) +break ; + } + +if (--i <0 ) +return 0 ; + + block =grub_le_to_cpu16 (index[i].leaf_hi); + block = (block <<32 ) +grub_le_to_cpu32 (index[i].leaf); +if (grub_disk_read (data->disk, + block <<LOG2_EXT2_BLOCK_SIZE (data), +0 ,EXT2_BLOCK_SIZE (data), buf)) +return 0 ; + + ext_block = (struct grub_ext4_extent_header *) buf; + } +}static grub_disk_addr_t grub_ext2_read_block (grub_fshelp_node_t node,grub_disk_addr_t fileblock)
@@ -272,6 +340,50 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)unsigned int blksz =EXT2_BLOCK_SIZE (data);int log2_blksz =LOG2_EXT2_BLOCK_SIZE (data); +if (inode->flags &EXT4_EXTENTS_FLAG ) + { +char buf[EXT2_BLOCK_SIZE (data)]; +struct grub_ext4_extent_header *leaf; +struct grub_ext4_extent *ext; +int i; + + leaf =grub_ext4_find_leaf (data, buf, + (struct grub_ext4_extent_header *) inode->blocks.dir_blocks, + fileblock); +if (! leaf) + { +grub_error (GRUB_ERR_BAD_FS ,"invalid extent" ); +return -1 ; + } + + ext = (struct grub_ext4_extent *) (leaf +1 ); +for (i =0 ; i <grub_le_to_cpu16 (leaf->entries); i++) + { +if (fileblock <grub_le_to_cpu32 (ext[i].block)) +break ; + } + +if (--i >=0 ) + { + fileblock -=grub_le_to_cpu32 (ext[i].block); +if (fileblock >=grub_le_to_cpu16 (ext[i].len)) +return 0 ; +else + { +grub_disk_addr_t start; + + start =grub_le_to_cpu16 (ext[i].start_hi); + start = (start <<32 ) +grub_le_to_cpu32 (ext[i].start); + +return fileblock + start; + } + } +else + { +grub_error (GRUB_ERR_BAD_FS ,"something wrong with extent" ); +return -1 ; + } + }/* Direct blocks. */ if (fileblock <INDIRECT_BLOCKS ) blknr =grub_le_to_cpu32 (inode->blocks.dir_blocks[fileblock]);
From: "Bean" <[email protected]>
Sent: Friday, July 11, 2008 5:34 PM
Quoted 7 lines
Hi,
This patch should fix the problem.
Signature · 1 line
Bean
Hello,
yeah, it works fine now.
Thanks very much
Quoted 12 lines · Felix Zielcke
From: "Bean" <[email protected]>
Sent: Friday, July 11, 2008 5:34 PMQuoted 8 lines
Hi,
This patch should fix the problem.
--
Bean
Quoted 4 lines
Hello,
yeah, it works fine now.
Thanks very much
Hi,
Thanks for your testing, if there is no objection, I'd commit it soon.
Signature · 1 line
Bean
Quoted 13 lines · Bean
Quoted 12 lines · Felix Zielcke
From: "Bean" <[email protected]>
Sent: Friday, July 11, 2008 5:34 PMQuoted 8 lines
Hi,
This patch should fix the problem.
--
Bean
Quoted 8 lines
Quoted 4 lines
Hello,
yeah, it works fine now.
Thanks very muchHi,
Thanks for your testing, if there is no objection, I'd commit it soon.
Committed.
Signature · 1 line
Bean