David Sterba
2013-Mar-15 16:10 UTC
[PATCH] btrfs-progs: convert: access name_len and file_type the old way
We can''t use ext2_dir_entry_2 typecast on big endian machines directly. The bytes do not get converted during extX block read due to missing flag EXT2_DIRBLOCK_V2_STRUCT passed down to ext2fs_read_dir_block4 from ext2fs_process_dir_block. Fixing on the ext2 side needs updating callers and (maybe) the library interfaces. We''ll fix it on the convert side for now. CC: Jan Kara <jack@suse.cz> Signed-off-by: David Sterba <dsterba@suse.cz> --- convert.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/convert.c b/convert.c index 400488e..7766c09 100644 --- a/convert.c +++ b/convert.c @@ -264,10 +264,13 @@ static int dir_iterate_proc(ext2_ino_t dir, int entry, struct btrfs_key location; struct ext2_dir_entry_2 *dirent = (struct ext2_dir_entry_2 *)old; struct dir_iterate_data *idata = (struct dir_iterate_data *)priv_data; + int name_len; + + name_len = old->name_len & 0xFF; objectid = dirent->inode + INO_OFFSET; - if (!strncmp(dirent->name, dotdot, dirent->name_len)) { - if (dirent->name_len == 2) { + if (!strncmp(dirent->name, dotdot, name_len)) { + if (name_len == 2) { BUG_ON(idata->parent != 0); idata->parent = objectid; } @@ -280,7 +283,7 @@ static int dir_iterate_proc(ext2_ino_t dir, int entry, location.offset = 0; btrfs_set_key_type(&location, BTRFS_INODE_ITEM_KEY); - file_type = dirent->file_type; + file_type = old->name_len >> 8; BUG_ON(file_type > EXT2_FT_SYMLINK); ret = btrfs_insert_dir_item(idata->trans, idata->root, dirent->name, dirent->name_len, -- 1.8.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Jan Kara
2013-Mar-18 15:21 UTC
Re: [PATCH] btrfs-progs: convert: access name_len and file_type the old way
On Fri 15-03-13 17:10:45, David Sterba wrote:> We can''t use ext2_dir_entry_2 typecast on big endian machines directly. > The bytes do not get converted during extX block read due to missing > flag EXT2_DIRBLOCK_V2_STRUCT passed down to ext2fs_read_dir_block4 from > ext2fs_process_dir_block. Fixing on the ext2 side needs updating callers > and (maybe) the library interfaces. We''ll fix it on the convert side for > now. > > CC: Jan Kara <jack@suse.cz> > Signed-off-by: David Sterba <dsterba@suse.cz> > --- > convert.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/convert.c b/convert.c > index 400488e..7766c09 100644 > --- a/convert.c > +++ b/convert.c > @@ -264,10 +264,13 @@ static int dir_iterate_proc(ext2_ino_t dir, int entry, > struct btrfs_key location; > struct ext2_dir_entry_2 *dirent = (struct ext2_dir_entry_2 *)old;You may as well remove this and use ''old'' everywhere. But technically the patch is OK. Honza> struct dir_iterate_data *idata = (struct dir_iterate_data *)priv_data; > + int name_len; > + > + name_len = old->name_len & 0xFF; > > objectid = dirent->inode + INO_OFFSET; > - if (!strncmp(dirent->name, dotdot, dirent->name_len)) { > - if (dirent->name_len == 2) { > + if (!strncmp(dirent->name, dotdot, name_len)) { > + if (name_len == 2) { > BUG_ON(idata->parent != 0); > idata->parent = objectid; > } > @@ -280,7 +283,7 @@ static int dir_iterate_proc(ext2_ino_t dir, int entry, > location.offset = 0; > btrfs_set_key_type(&location, BTRFS_INODE_ITEM_KEY); > > - file_type = dirent->file_type; > + file_type = old->name_len >> 8; > BUG_ON(file_type > EXT2_FT_SYMLINK); > ret = btrfs_insert_dir_item(idata->trans, idata->root, > dirent->name, dirent->name_len, > -- > 1.8.1.4 >-- Jan Kara <jack@suse.cz> SUSE Labs, CR -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
David Sterba
2013-Mar-18 18:39 UTC
[PATCH v2] btrfs-progs: convert: access name_len and file_type the old way
We can''t use ext2_dir_entry_2 typecast on big endian machines directly. The bytes do not get converted during extX block read due to missing flag EXT2_DIRBLOCK_V2_STRUCT passed down to ext2fs_read_dir_block4 from ext2fs_process_dir_block. Fixing on the ext2 side needs updating callers and (maybe) the library interfaces. We''ll fix it on the convert side for now. CC: Jan Kara <jack@suse.cz> Signed-off-by: David Sterba <dsterba@suse.cz> --- v2: - use v1 ext2_dir_entry everywhere - fix remaining incorrect uses of dirent->name_len convert.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/convert.c b/convert.c index f462597..399856f 100644 --- a/convert.c +++ b/convert.c @@ -252,7 +252,7 @@ static u8 filetype_conversion_table[EXT2_FT_MAX] = { }; static int dir_iterate_proc(ext2_ino_t dir, int entry, - struct ext2_dir_entry *old, + struct ext2_dir_entry *dirent, int offset, int blocksize, char *buf,void *priv_data) { @@ -262,12 +262,14 @@ static int dir_iterate_proc(ext2_ino_t dir, int entry, u64 inode_size; char dotdot[] = ".."; struct btrfs_key location; - struct ext2_dir_entry_2 *dirent = (struct ext2_dir_entry_2 *)old; struct dir_iterate_data *idata = (struct dir_iterate_data *)priv_data; + int name_len; + + name_len = dirent->name_len & 0xFF; objectid = dirent->inode + INO_OFFSET; - if (!strncmp(dirent->name, dotdot, dirent->name_len)) { - if (dirent->name_len == 2) { + if (!strncmp(dirent->name, dotdot, name_len)) { + if (name_len == 2) { BUG_ON(idata->parent != 0); idata->parent = objectid; } @@ -280,24 +282,24 @@ static int dir_iterate_proc(ext2_ino_t dir, int entry, location.offset = 0; btrfs_set_key_type(&location, BTRFS_INODE_ITEM_KEY); - file_type = dirent->file_type; + file_type = dirent->name_len >> 8; BUG_ON(file_type > EXT2_FT_SYMLINK); ret = btrfs_insert_dir_item(idata->trans, idata->root, - dirent->name, dirent->name_len, + dirent->name, name_len, idata->objectid, &location, filetype_conversion_table[file_type], idata->index_cnt); if (ret) goto fail; ret = btrfs_insert_inode_ref(idata->trans, idata->root, - dirent->name, dirent->name_len, + dirent->name, name_len, objectid, idata->objectid, idata->index_cnt); if (ret) goto fail; idata->index_cnt++; inode_size = btrfs_stack_inode_size(idata->inode) + - dirent->name_len * 2; + name_len * 2; btrfs_set_stack_inode_size(idata->inode, inode_size); return 0; fail: -- 1.8.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Jan Kara
2013-Mar-18 21:35 UTC
Re: [PATCH v2] btrfs-progs: convert: access name_len and file_type the old way
On Mon 18-03-13 19:39:31, David Sterba wrote:> We can''t use ext2_dir_entry_2 typecast on big endian machines directly. > The bytes do not get converted during extX block read due to missing > flag EXT2_DIRBLOCK_V2_STRUCT passed down to ext2fs_read_dir_block4 from > ext2fs_process_dir_block. Fixing on the ext2 side needs updating callers > and (maybe) the library interfaces. We''ll fix it on the convert side for > now. > > CC: Jan Kara <jack@suse.cz> > Signed-off-by: David Sterba <dsterba@suse.cz>Yes, now the patch looks OK to me. Honza> --- > > v2: > - use v1 ext2_dir_entry everywhere > - fix remaining incorrect uses of dirent->name_len > > convert.c | 18 ++++++++++-------- > 1 file changed, 10 insertions(+), 8 deletions(-) > > diff --git a/convert.c b/convert.c > index f462597..399856f 100644 > --- a/convert.c > +++ b/convert.c > @@ -252,7 +252,7 @@ static u8 filetype_conversion_table[EXT2_FT_MAX] = { > }; > > static int dir_iterate_proc(ext2_ino_t dir, int entry, > - struct ext2_dir_entry *old, > + struct ext2_dir_entry *dirent, > int offset, int blocksize, > char *buf,void *priv_data) > { > @@ -262,12 +262,14 @@ static int dir_iterate_proc(ext2_ino_t dir, int entry, > u64 inode_size; > char dotdot[] = ".."; > struct btrfs_key location; > - struct ext2_dir_entry_2 *dirent = (struct ext2_dir_entry_2 *)old; > struct dir_iterate_data *idata = (struct dir_iterate_data *)priv_data; > + int name_len; > + > + name_len = dirent->name_len & 0xFF; > > objectid = dirent->inode + INO_OFFSET; > - if (!strncmp(dirent->name, dotdot, dirent->name_len)) { > - if (dirent->name_len == 2) { > + if (!strncmp(dirent->name, dotdot, name_len)) { > + if (name_len == 2) { > BUG_ON(idata->parent != 0); > idata->parent = objectid; > } > @@ -280,24 +282,24 @@ static int dir_iterate_proc(ext2_ino_t dir, int entry, > location.offset = 0; > btrfs_set_key_type(&location, BTRFS_INODE_ITEM_KEY); > > - file_type = dirent->file_type; > + file_type = dirent->name_len >> 8; > BUG_ON(file_type > EXT2_FT_SYMLINK); > ret = btrfs_insert_dir_item(idata->trans, idata->root, > - dirent->name, dirent->name_len, > + dirent->name, name_len, > idata->objectid, &location, > filetype_conversion_table[file_type], > idata->index_cnt); > if (ret) > goto fail; > ret = btrfs_insert_inode_ref(idata->trans, idata->root, > - dirent->name, dirent->name_len, > + dirent->name, name_len, > objectid, idata->objectid, > idata->index_cnt); > if (ret) > goto fail; > idata->index_cnt++; > inode_size = btrfs_stack_inode_size(idata->inode) + > - dirent->name_len * 2; > + name_len * 2; > btrfs_set_stack_inode_size(idata->inode, inode_size); > return 0; > fail: > -- > 1.8.1.4 >-- Jan Kara <jack@suse.cz> SUSE Labs, CR -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html