From: Theodore Ts'o Date: Fri, 21 Oct 2016 14:21:54 +0000 (-0400) Subject: libext2fs: unix_io: reflect error from read/write calls to caller X-Git-Tag: 1.43.4~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=025b828c9c43dac660902bf3a874c37fc3e1e450;p=thirdparty%2Fe2fsprogs.git libext2fs: unix_io: reflect error from read/write calls to caller If the read(2) or write(2) system calls fail, return the error to the caller instead of returning "short read" or "short write", which is just misleading. Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c index 85ad4e39f..429ea2411 100644 --- a/lib/ext2fs/unix_io.c +++ b/lib/ext2fs/unix_io.c @@ -208,9 +208,11 @@ static errcode_t raw_read_blk(io_channel channel, actual = read(data->dev, buf, size); if (actual != size) { short_read: - if (actual < 0) + if (actual < 0) { + retval = errno; actual = 0; - retval = EXT2_ET_SHORT_READ; + } else + retval = EXT2_ET_SHORT_READ; goto error_out; } return 0; @@ -313,6 +315,10 @@ static errcode_t raw_write_blk(io_channel channel, (IS_ALIGNED(buf, channel->align) && IS_ALIGNED(size, channel->align))) { actual = write(data->dev, buf, size); + if (actual < 0) { + retval = errno; + goto error_out; + } if (actual != size) { short_write: retval = EXT2_ET_SHORT_WRITE; @@ -336,7 +342,7 @@ bounce_write: channel->block_size); if (actual != channel->block_size) { if (actual < 0) { - retval = EXT2_ET_SHORT_READ; + retval = errno; goto error_out; } memset(data->bounce + actual, 0, @@ -352,6 +358,10 @@ bounce_write: goto error_out; } actual = write(data->dev, data->bounce, channel->block_size); + if (actual < 0) { + retval = errno; + goto error_out; + } if (actual != channel->block_size) goto short_write; size -= actual; @@ -997,6 +1007,8 @@ static errcode_t unix_write_byte(io_channel channel, unsigned long offset, return errno; actual = write(data->dev, buf, size); + if (actual < 0) + return errno; if (actual != size) return EXT2_ET_SHORT_WRITE;