X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lib%2Fext2fs%2Fsparse_io.c;h=5e0e2cd9a2105629461a31314be2bcffd19ad905;hb=ea4d53b7b9079fd6e2cc34cf569a993a183bfbd2;hp=a307859f88602846b32d9d4e10bf553d689da56d;hpb=a5d3c5ba686cfeb21d1d679f7ca2dc8f09748b75;p=tools%2Fe2fsprogs.git diff --git a/lib/ext2fs/sparse_io.c b/lib/ext2fs/sparse_io.c index a307859..5e0e2cd 100644 --- a/lib/ext2fs/sparse_io.c +++ b/lib/ext2fs/sparse_io.c @@ -7,6 +7,10 @@ #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)), @@ -63,7 +67,7 @@ static void free_sparse_blocks(struct sparse_map *sm) 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; @@ -155,7 +159,7 @@ static errcode_t io_manager_configure(struct sparse_io_params *params, 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; @@ -181,14 +185,22 @@ err_params: 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, @@ -206,11 +218,11 @@ 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); } @@ -266,7 +278,8 @@ static errcode_t sparse_merge_blocks(struct sparse_map *sm, uint64_t start, 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; }