ext4_utils: move sparse file pointer out of fs_info
Move the sparse file pointer out of the fs_info struct in
preparation for exporting fs_info without sparse file support.
Change-Id: I5a72147fe4fb24296e615cb82dbba91c6dc6f7f0
diff --git a/ext4_utils/allocate.c b/ext4_utils/allocate.c
index 09ffa1b..64924c7 100644
--- a/ext4_utils/allocate.c
+++ b/ext4_utils/allocate.c
@@ -180,7 +180,7 @@
if (bg->inode_table == NULL)
critical_error_errno("calloc");
- sparse_file_add_data(info.sparse_file, bg->inode_table,
+ sparse_file_add_data(ext4_sparse_file, bg->inode_table,
aux_info.inode_table_blocks * info.block_size, block);
bg->flags &= ~EXT4_BG_INODE_UNINIT;
@@ -298,7 +298,7 @@
u32 block = bg->first_block;
if (bg->has_superblock)
block += 1 + aux_info.bg_desc_blocks + info.bg_desc_reserve_blocks;
- sparse_file_add_data(info.sparse_file, bg->bitmaps, 2 * info.block_size,
+ sparse_file_add_data(ext4_sparse_file, bg->bitmaps, 2 * info.block_size,
block);
bg->data_blocks_used = 0;
@@ -717,7 +717,7 @@
inode->i_blocks_lo = cpu_to_le32(le32_to_cpu(inode->i_blocks_lo) + (info.block_size / 512));
inode->i_file_acl_lo = cpu_to_le32(block_num);
- int result = sparse_file_add_data(info.sparse_file, block, info.block_size, block_num);
+ int result = sparse_file_add_data(ext4_sparse_file, block, info.block_size, block_num);
if (result != 0) {
error("get_xattr: sparse_file_add_data failure %d", result);
free(block);
diff --git a/ext4_utils/ext2simg.c b/ext4_utils/ext2simg.c
index 7b63836..f75b6c2 100644
--- a/ext4_utils/ext2simg.c
+++ b/ext4_utils/ext2simg.c
@@ -126,7 +126,7 @@
critical_error("failed to allocate block bitmap");
if (aux_info.first_data_block > 0)
- sparse_file_add_file(info.sparse_file, filename, 0,
+ sparse_file_add_file(ext4_sparse_file, filename, 0,
info.block_size * aux_info.first_data_block, 0);
for (i = 0; i < aux_info.groups; i++) {
@@ -151,7 +151,7 @@
u32 start_block = first_block + start_contiguous_block;
u32 len_blocks = block - start_contiguous_block;
- sparse_file_add_file(info.sparse_file, filename,
+ sparse_file_add_file(ext4_sparse_file, filename,
(u64)info.block_size * start_block,
info.block_size * len_blocks, start_block);
start_contiguous_block = -1;
@@ -165,7 +165,7 @@
if (start_contiguous_block >= 0) {
u32 start_block = first_block + start_contiguous_block;
u32 len_blocks = last_block - start_contiguous_block;
- sparse_file_add_file(info.sparse_file, filename,
+ sparse_file_add_file(ext4_sparse_file, filename,
(u64)info.block_size * start_block,
info.block_size * len_blocks, start_block);
}
@@ -230,7 +230,7 @@
read_ext(infd);
- info.sparse_file = sparse_file_new(info.block_size, info.len);
+ ext4_sparse_file = sparse_file_new(info.block_size, info.len);
build_sparse_ext(infd, in);
@@ -249,7 +249,7 @@
write_ext4_image(outfd, gzip, sparse, crc);
close(outfd);
- sparse_file_destroy(info.sparse_file);
+ sparse_file_destroy(ext4_sparse_file);
return 0;
}
diff --git a/ext4_utils/ext4_utils.c b/ext4_utils/ext4_utils.c
index 3547545..8c9d931 100644
--- a/ext4_utils/ext4_utils.c
+++ b/ext4_utils/ext4_utils.c
@@ -44,6 +44,7 @@
int force = 0;
struct fs_info info;
struct fs_aux_info aux_info;
+struct sparse_file *ext4_sparse_file;
jmp_buf setjmp_env;
@@ -81,7 +82,7 @@
/* Write the filesystem image to a file */
void write_ext4_image(int fd, int gz, int sparse, int crc)
{
- sparse_file_write(info.sparse_file, fd, gz, sparse, crc);
+ sparse_file_write(ext4_sparse_file, fd, gz, sparse, crc);
}
/* Compute the rest of the parameters of the filesystem from the basic info */
@@ -225,10 +226,10 @@
memcpy(aux_info.backup_sb[i], sb, info.block_size);
/* Update the block group nr of this backup superblock */
aux_info.backup_sb[i]->s_block_group_nr = i;
- sparse_file_add_data(info.sparse_file, aux_info.backup_sb[i],
+ sparse_file_add_data(ext4_sparse_file, aux_info.backup_sb[i],
info.block_size, group_start_block);
}
- sparse_file_add_data(info.sparse_file, aux_info.bg_desc,
+ sparse_file_add_data(ext4_sparse_file, aux_info.bg_desc,
aux_info.bg_desc_blocks * info.block_size,
group_start_block + 1);
header_size = 1 + aux_info.bg_desc_blocks + info.bg_desc_reserve_blocks;
@@ -254,9 +255,9 @@
if (info.block_size > 1024) {
u8 *buf = calloc(info.block_size, 1);
memcpy(buf + 1024, (u8*)aux_info.sb, 1024);
- sparse_file_add_data(info.sparse_file, buf, info.block_size, 0);
+ sparse_file_add_data(ext4_sparse_file, buf, info.block_size, 0);
} else {
- sparse_file_add_data(info.sparse_file, aux_info.sb, 1024, 1);
+ sparse_file_add_data(ext4_sparse_file, aux_info.sb, 1024, 1);
}
}
diff --git a/ext4_utils/ext4_utils.h b/ext4_utils/ext4_utils.h
index 07f9363..298fc35 100644
--- a/ext4_utils/ext4_utils.h
+++ b/ext4_utils/ext4_utils.h
@@ -109,8 +109,6 @@
u32 bg_desc_reserve_blocks;
const char *label;
u8 no_journal;
-
- struct sparse_file *sparse_file;
};
struct fs_aux_info {
@@ -132,6 +130,7 @@
extern struct fs_info info;
extern struct fs_aux_info aux_info;
+extern struct sparse_file *ext4_sparse_file;
extern jmp_buf setjmp_env;
diff --git a/ext4_utils/extent.c b/ext4_utils/extent.c
index ce58142..aeff0f6 100644
--- a/ext4_utils/extent.c
+++ b/ext4_utils/extent.c
@@ -41,7 +41,7 @@
len = min(region_len * info.block_size, backing_len);
- sparse_file_add_data(info.sparse_file, ptr, len, region_block);
+ sparse_file_add_data(ext4_sparse_file, ptr, len, region_block);
ptr += len;
backing_len -= len;
}
@@ -63,7 +63,7 @@
len = min(region_len * info.block_size, backing_len);
- sparse_file_add_file(info.sparse_file, filename, offset, len,
+ sparse_file_add_file(ext4_sparse_file, filename, offset, len,
region_block);
offset += len;
backing_len -= len;
@@ -123,7 +123,7 @@
if (!data)
critical_error_errno("calloc");
- sparse_file_add_data(info.sparse_file, data, info.block_size,
+ sparse_file_add_data(ext4_sparse_file, data, info.block_size,
extent_block);
if (((int)(info.block_size - sizeof(struct ext4_extent_header) /
diff --git a/ext4_utils/indirect.c b/ext4_utils/indirect.c
index b516a8a..cd85a43 100644
--- a/ext4_utils/indirect.c
+++ b/ext4_utils/indirect.c
@@ -44,7 +44,7 @@
len = min(region_len * info.block_size, backing_len);
- sparse_file_add_data(info.sparse_file, ptr, len, region_block);
+ sparse_file_add_data(ext4_sparse_file, ptr, len, region_block);
ptr += len;
backing_len -= len;
}
@@ -121,7 +121,7 @@
dind_block[i] = ind_block;
u32 *ind_block_data = calloc(info.block_size, 1);
- sparse_file_add_data(info.sparse_file, ind_block_data, info.block_size,
+ sparse_file_add_data(ext4_sparse_file, ind_block_data, info.block_size,
ind_block);
int ind_block_len = min((int)aux_info.blocks_per_ind, len);
@@ -151,7 +151,7 @@
tind_block[i] = dind_block;
u32 *dind_block_data = calloc(info.block_size, 1);
- sparse_file_add_data(info.sparse_file, dind_block_data, info.block_size,
+ sparse_file_add_data(ext4_sparse_file, dind_block_data, info.block_size,
dind_block);
int dind_block_len = min((int)aux_info.blocks_per_dind, len);
@@ -200,7 +200,7 @@
}
u32 *ind_block_data = calloc(info.block_size, 1);
- sparse_file_add_data(info.sparse_file, ind_block_data, info.block_size,
+ sparse_file_add_data(ext4_sparse_file, ind_block_data, info.block_size,
ind_block);
fill_indirect_block(ind_block_data, len, alloc);
@@ -232,7 +232,7 @@
}
u32 *dind_block_data = calloc(info.block_size, 1);
- sparse_file_add_data(info.sparse_file, dind_block_data, info.block_size,
+ sparse_file_add_data(ext4_sparse_file, dind_block_data, info.block_size,
dind_block);
fill_dindirect_block(dind_block_data, len, alloc);
@@ -264,7 +264,7 @@
}
u32 *tind_block_data = calloc(info.block_size, 1);
- sparse_file_add_data(info.sparse_file, tind_block_data, info.block_size,
+ sparse_file_add_data(ext4_sparse_file, tind_block_data, info.block_size,
tind_block);
fill_tindirect_block(tind_block_data, len, alloc);
@@ -444,13 +444,13 @@
u32 *dind_block_data = calloc(info.block_size, 1);
if (!dind_block_data)
critical_error_errno("calloc");
- sparse_file_add_data(info.sparse_file, dind_block_data, info.block_size,
+ sparse_file_add_data(ext4_sparse_file, dind_block_data, info.block_size,
dind_block);
u32 *ind_block_data = calloc(info.block_size, info.bg_desc_reserve_blocks);
if (!ind_block_data)
critical_error_errno("calloc");
- sparse_file_add_data(info.sparse_file, ind_block_data,
+ sparse_file_add_data(ext4_sparse_file, ind_block_data,
info.block_size * info.bg_desc_reserve_blocks,
get_block(alloc, 0));
diff --git a/ext4_utils/make_ext4fs.c b/ext4_utils/make_ext4fs.c
index c2a2665..2250241 100644
--- a/ext4_utils/make_ext4fs.c
+++ b/ext4_utils/make_ext4fs.c
@@ -362,9 +362,9 @@
memset(&info, 0, sizeof(info));
memset(&aux_info, 0, sizeof(aux_info));
- if (info.sparse_file) {
- sparse_file_destroy(info.sparse_file);
- info.sparse_file = NULL;
+ if (ext4_sparse_file) {
+ sparse_file_destroy(ext4_sparse_file);
+ ext4_sparse_file = NULL;
}
}
@@ -545,7 +545,7 @@
printf(" Block groups: %d\n", aux_info.groups);
printf(" Reserved block group size: %d\n", info.bg_desc_reserve_blocks);
- info.sparse_file = sparse_file_new(info.block_size, info.len);
+ ext4_sparse_file = sparse_file_new(info.block_size, info.len);
block_allocator_init();
@@ -607,8 +607,8 @@
write_ext4_image(fd, gzip, sparse, crc);
- sparse_file_destroy(info.sparse_file);
- info.sparse_file = NULL;
+ sparse_file_destroy(ext4_sparse_file);
+ ext4_sparse_file = NULL;
free(mountpoint);
free(directory);