#include "ext2_fs.h"
#include "ext2fs.h"
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
#if !defined(ENABLE_LIBSPARSE)
static errcode_t sparse_open(const char *name EXT2FS_ATTR((unused)),
int flags EXT2FS_ATTR((unused)),
sm->blocks = NULL;
}
-static int sparse_import_segment(void *priv, const void *data, int len,
+static int sparse_import_segment(void *priv, const void *data, size_t len,
unsigned int block, unsigned int nr_blocks)
{
struct sparse_map *sm = priv;
goto err_alloc;
}
if (params->fd < 0) {
- sm->fd = open(params->file, O_CREAT | O_RDWR | O_TRUNC,
+ sm->fd = open(params->file, O_CREAT | O_RDWR | O_TRUNC | O_BINARY,
0644);
if (sm->fd < 0) {
retval = errno;
static errcode_t sparse_open_channel(struct sparse_io_params *sparse_params,
int flags, io_channel *channel)
{
+ errcode_t retval;
io_channel io;
io = calloc(1, sizeof(struct struct_io_channel));
io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
io->block_size = 0;
io->refcount = 1;
+
+ retval = io_manager_configure(sparse_params, flags, io);
+ if (retval) {
+ free(io);
+ return retval;
+ }
+
*channel = io;
- return io_manager_configure(sparse_params, flags, io);
+ return 0;
}
static errcode_t read_sparse_argv(const char *name, bool is_fd,
}
if (is_fd) {
- ret = sscanf(name, "%d:%llu:%u", &sparse_params->fd,
+ ret = sscanf(name, "(%d):%llu:%u", &sparse_params->fd,
(unsigned long long *)&sparse_params->blocks_count,
&sparse_params->block_size);
} else {
- ret = sscanf(name, "%[^:]%*[:]%llu%*[:]%u", sparse_params->file,
+ ret = sscanf(name, "(%[^)])%*[:]%llu%*[:]%u", sparse_params->file,
(unsigned long long *)&sparse_params->blocks_count,
&sparse_params->block_size);
}
buf = calloc(num, block_size);
if (!buf) {
- fprintf(stderr, "failed to alloc %lu\n", num * block_size);
+ fprintf(stderr, "failed to alloc %llu\n",
+ (unsigned long long)num * block_size);
return EXT2_ET_NO_MEMORY;
}