diff --git a/libisofs/filesrc.c b/libisofs/filesrc.c index 52564af..c007224 100644 --- a/libisofs/filesrc.c +++ b/libisofs/filesrc.c @@ -243,6 +243,7 @@ int filesrc_writer_write_data(IsoImageWriter *writer) Ecma119Image *t; IsoFileSrc *file; IsoFileSrc **filelist; + char *name; char buffer[BLOCK_SIZE]; if (writer == NULL) { @@ -265,12 +266,12 @@ int filesrc_writer_write_data(IsoImageWriter *writer) uint32_t nblocks = DIV_UP(iso_file_src_get_size(file), BLOCK_SIZE); res = filesrc_open(file); + name = iso_stream_get_name(file->stream); if (res < 0) { /* * UPS, very ugly error, the best we can do is just to write * 0's to image */ - char *name = iso_stream_get_name(file->stream); res = iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, res, "File \"%s\" can't be opened. Filling with 0s.", name); free(name); @@ -287,7 +288,6 @@ int filesrc_writer_write_data(IsoImageWriter *writer) } continue; } else if (res > 1) { - char *name = iso_stream_get_name(file->stream); res = iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, 0, "Size of file \"%s\" has changed. It will be %s", name, (res == 2 ? "truncated" : "padded with 0's")); @@ -297,12 +297,14 @@ int filesrc_writer_write_data(IsoImageWriter *writer) return res; /* aborted due to error severity */ } } + iso_msg_debug(t->image->id, "Writing file %s", name); + free(name); /* write file contents to image */ for (b = 0; b < nblocks; ++b) { int wres; res = filesrc_read(file, buffer, BLOCK_SIZE); - if (res <= 0) { + if (res < 0) { /* read error */ break; } diff --git a/libisofs/fs_image.c b/libisofs/fs_image.c index 72cff22..ccb7935 100644 --- a/libisofs/fs_image.c +++ b/libisofs/fs_image.c @@ -620,7 +620,7 @@ int ifs_read(IsoFileSource *src, void *buf, size_t count) /* how much can I read */ bytes = MIN(BLOCK_SIZE - (data->data.offset % BLOCK_SIZE), count - read); - if (data->data.offset + (off_t)bytes > data->info.st_size) { + if (data->data.offset + (off_t)bytes > data->info.st_size) { bytes = data->info.st_size - data->data.offset; } orig = data->data.content;