mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-21 22:45:18 +00:00
btrfs-convert: Iterate correctly using libext2fs functions
This patch corrects open-coded inode_map iteration, which happens to be illegal in new libext2fs due to inode_map being private, causing warning, which becomes a compile error.
This commit is contained in:
parent
e9fa78e2ec
commit
33d7977a95
43
convert.c
43
convert.c
@ -955,29 +955,24 @@ static int copy_inode_item(struct btrfs_inode_item *dst,
|
|||||||
static int copy_single_inode(struct btrfs_trans_handle *trans,
|
static int copy_single_inode(struct btrfs_trans_handle *trans,
|
||||||
struct btrfs_root *root, u64 objectid,
|
struct btrfs_root *root, u64 objectid,
|
||||||
ext2_filsys ext2_fs, ext2_ino_t ext2_ino,
|
ext2_filsys ext2_fs, ext2_ino_t ext2_ino,
|
||||||
|
struct ext2_inode *ext2_inode,
|
||||||
int datacsum, int packing, int noxattr)
|
int datacsum, int packing, int noxattr)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
errcode_t err;
|
|
||||||
struct ext2_inode ext2_inode;
|
|
||||||
struct btrfs_key inode_key;
|
struct btrfs_key inode_key;
|
||||||
struct btrfs_inode_item btrfs_inode;
|
struct btrfs_inode_item btrfs_inode;
|
||||||
|
|
||||||
if (ext2_inode->i_links_count == 0)
|
if (ext2_inode->i_links_count == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err = ext2fs_read_inode(ext2_fs, ext2_ino, &ext2_inode);
|
copy_inode_item(&btrfs_inode, ext2_inode);
|
||||||
if (err)
|
if (!datacsum && S_ISREG(ext2_inode->i_mode)) {
|
||||||
goto error;
|
|
||||||
|
|
||||||
copy_inode_item(&btrfs_inode, &ext2_inode);
|
|
||||||
if (!datacsum && S_ISREG(ext2_inode.i_mode)) {
|
|
||||||
u32 flags = btrfs_stack_inode_flags(&btrfs_inode) |
|
u32 flags = btrfs_stack_inode_flags(&btrfs_inode) |
|
||||||
BTRFS_INODE_NODATASUM;
|
BTRFS_INODE_NODATASUM;
|
||||||
btrfs_set_stack_inode_flags(&btrfs_inode, flags);
|
btrfs_set_stack_inode_flags(&btrfs_inode, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ext2_inode.i_mode & S_IFMT) {
|
switch (ext2_inode->i_mode & S_IFMT) {
|
||||||
case S_IFREG:
|
case S_IFREG:
|
||||||
ret = create_file_extents(trans, root, objectid, &btrfs_inode,
|
ret = create_file_extents(trans, root, objectid, &btrfs_inode,
|
||||||
ext2_fs, ext2_ino, datacsum, packing);
|
ext2_fs, ext2_ino, datacsum, packing);
|
||||||
@ -988,7 +983,7 @@ static int copy_single_inode(struct btrfs_trans_handle *trans,
|
|||||||
break;
|
break;
|
||||||
case S_IFLNK:
|
case S_IFLNK:
|
||||||
ret = create_symbol_link(trans, root, objectid, &btrfs_inode,
|
ret = create_symbol_link(trans, root, objectid, &btrfs_inode,
|
||||||
ext2_fs, ext2_ino, &ext2_inode);
|
ext2_fs, ext2_ino, ext2_inode);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -1008,9 +1003,6 @@ static int copy_single_inode(struct btrfs_trans_handle *trans,
|
|||||||
btrfs_set_key_type(&inode_key, BTRFS_INODE_ITEM_KEY);
|
btrfs_set_key_type(&inode_key, BTRFS_INODE_ITEM_KEY);
|
||||||
ret = btrfs_insert_inode(trans, root, objectid, &btrfs_inode);
|
ret = btrfs_insert_inode(trans, root, objectid, &btrfs_inode);
|
||||||
return ret;
|
return ret;
|
||||||
error:
|
|
||||||
fprintf(stderr, "ext2fs_read_inode: %s\n", error_message(err));
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int copy_disk_extent(struct btrfs_root *root, u64 dst_bytenr,
|
static int copy_disk_extent(struct btrfs_root *root, u64 dst_bytenr,
|
||||||
@ -1043,6 +1035,9 @@ static int copy_inodes(struct btrfs_root *root, ext2_filsys ext2_fs,
|
|||||||
int datacsum, int packing, int noxattr)
|
int datacsum, int packing, int noxattr)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
errcode_t err;
|
||||||
|
ext2_inode_scan ext2_scan;
|
||||||
|
struct ext2_inode ext2_inode;
|
||||||
ext2_ino_t ext2_ino;
|
ext2_ino_t ext2_ino;
|
||||||
u64 objectid;
|
u64 objectid;
|
||||||
struct btrfs_trans_handle *trans;
|
struct btrfs_trans_handle *trans;
|
||||||
@ -1050,10 +1045,16 @@ static int copy_inodes(struct btrfs_root *root, ext2_filsys ext2_fs,
|
|||||||
trans = btrfs_start_transaction(root, 1);
|
trans = btrfs_start_transaction(root, 1);
|
||||||
if (!trans)
|
if (!trans)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
ext2_ino = ext2_fs->inode_map->start;
|
err = ext2fs_open_inode_scan(ext2_fs, 0, &ext2_scan);
|
||||||
for (; ext2_ino <= ext2_fs->inode_map->end; ext2_ino++) {
|
if (err) {
|
||||||
if (ext2fs_fast_test_inode_bitmap(ext2_fs->inode_map,
|
fprintf(stderr, "ext2fs_open_inode_scan: %s\n", error_message(err));
|
||||||
ext2_ino)) {
|
return -1;
|
||||||
|
}
|
||||||
|
while (!(err = ext2fs_get_next_inode(ext2_scan, &ext2_ino,
|
||||||
|
&ext2_inode))) {
|
||||||
|
/* no more inodes */
|
||||||
|
if (ext2_ino == 0)
|
||||||
|
break;
|
||||||
/* skip special inode in ext2fs */
|
/* skip special inode in ext2fs */
|
||||||
if (ext2_ino < EXT2_GOOD_OLD_FIRST_INO &&
|
if (ext2_ino < EXT2_GOOD_OLD_FIRST_INO &&
|
||||||
ext2_ino != EXT2_ROOT_INO)
|
ext2_ino != EXT2_ROOT_INO)
|
||||||
@ -1061,10 +1062,10 @@ static int copy_inodes(struct btrfs_root *root, ext2_filsys ext2_fs,
|
|||||||
objectid = ext2_ino + INO_OFFSET;
|
objectid = ext2_ino + INO_OFFSET;
|
||||||
ret = copy_single_inode(trans, root,
|
ret = copy_single_inode(trans, root,
|
||||||
objectid, ext2_fs, ext2_ino,
|
objectid, ext2_fs, ext2_ino,
|
||||||
datacsum, packing, noxattr);
|
&ext2_inode, datacsum, packing,
|
||||||
|
noxattr);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
if (trans->blocks_used >= 4096) {
|
if (trans->blocks_used >= 4096) {
|
||||||
ret = btrfs_commit_transaction(trans, root);
|
ret = btrfs_commit_transaction(trans, root);
|
||||||
BUG_ON(ret);
|
BUG_ON(ret);
|
||||||
@ -1072,6 +1073,10 @@ static int copy_inodes(struct btrfs_root *root, ext2_filsys ext2_fs,
|
|||||||
BUG_ON(!trans);
|
BUG_ON(!trans);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (err) {
|
||||||
|
fprintf(stderr, "ext2fs_get_next_inode: %s\n", error_message(err));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
ret = btrfs_commit_transaction(trans, root);
|
ret = btrfs_commit_transaction(trans, root);
|
||||||
BUG_ON(ret);
|
BUG_ON(ret);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user