* limitations under the License.
*/
+#include "ext4_utils.h"
+#include "extent.h"
+
+#include <sparse/sparse.h>
+
+#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
-#include "ext4_utils.h"
-#include "ext4.h"
-#include "ext4_extents.h"
-#include "backed_block.h"
-
-#include "extent.h"
/* Creates data buffers for the first backing_len bytes of a block allocation
and queues them to be written */
len = min(region_len * info.block_size, backing_len);
- queue_data_block(ptr, len, region_block);
+ sparse_file_add_data(ext4_sparse_file, ptr, len, region_block);
ptr += len;
backing_len -= len;
}
static void extent_create_backing_file(struct block_allocation *alloc,
u64 backing_len, const char *filename)
{
- off_t offset = 0;
+ off64_t offset = 0;
for (; alloc != NULL && backing_len > 0; get_next_region(alloc)) {
u32 region_block;
u32 region_len;
len = min(region_len * info.block_size, backing_len);
- queue_data_file(filename, offset, len, region_block);
+ sparse_file_add_file(ext4_sparse_file, filename, offset, len,
+ region_block);
offset += len;
backing_len -= len;
}
if (!data)
critical_error_errno("calloc");
- queue_data_block(data, info.block_size, extent_block);
+ sparse_file_add_data(ext4_sparse_file, data, info.block_size,
+ extent_block);
if (((int)(info.block_size - sizeof(struct ext4_extent_header) /
sizeof(struct ext4_extent))) < allocation_len) {
- error("File size %llu is too big to fit in a single extent block\n",
+ error("File size %"PRIu64" is too big to fit in a single extent block\n",
len);
return NULL;
}
alloc = do_inode_allocate_extents(inode, len);
if (alloc == NULL) {
- error("failed to allocate extents for %llu bytes", len);
+ error("failed to allocate extents for %"PRIu64" bytes", len);
return NULL;
}
if (backing_len) {
data = extent_create_backing(alloc, backing_len);
if (!data)
- error("failed to create backing for %llu bytes", backing_len);
+ error("failed to create backing for %"PRIu64" bytes", backing_len);
}
free_alloc(alloc);
/* Allocates enough blocks to hold len bytes, queues them to be written
from a file, and connects them to an inode. */
-void inode_allocate_file_extents(struct ext4_inode *inode, u64 len,
+struct block_allocation* inode_allocate_file_extents(struct ext4_inode *inode, u64 len,
const char *filename)
{
struct block_allocation *alloc;
alloc = do_inode_allocate_extents(inode, len);
if (alloc == NULL) {
- error("failed to allocate extents for %llu bytes", len);
- return;
+ error("failed to allocate extents for %"PRIu64" bytes", len);
+ return NULL;
}
extent_create_backing_file(alloc, len, filename);
-
- free_alloc(alloc);
+ return alloc;
}
/* Allocates enough blocks to hold len bytes and connects them to an inode */
alloc = do_inode_allocate_extents(inode, len);
if (alloc == NULL) {
- error("failed to allocate extents for %llu bytes", len);
+ error("failed to allocate extents for %"PRIu64" bytes", len);
return;
}