summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQu Wenruo <wqu@suse.com>2018-03-30 15:35:26 +0800
committerDavid Sterba <dsterba@suse.com>2018-03-30 22:15:55 +0200
commit64f3dc013676544d3f6142a80cfef99644e4e49a (patch)
tree786288d9607738369f100275a42710e79a0fce5c
parent3f42d56fcbc6420cf47bed601542a776b1bc7ca2 (diff)
downloadbtrfs-progs-64f3dc013676544d3f6142a80cfef99644e4e49a.tar.gz
btrfs-progs-64f3dc013676544d3f6142a80cfef99644e4e49a.tar.bz2
btrfs-progs-64f3dc013676544d3f6142a80cfef99644e4e49a.zip
btrfs-progs: disk-io: Fix read_extent_data() error handler for missing device
When device is missing, read_extent_data() (function exported from old btrfs check code) has the following problems: 1) Modifies @len parameter if device is missing If device returned in @multi is missing, @len can be larger than @max_len (originl length). This could confuse caller and underflow in the read loop. 2) Still returns 0 for missing device It only handles read error, missing device is not handled and 0 is returned. 3) Wrong check for device->fd In fact, 0 is also a valid fd. Although not possible under most cases, but still needs fix. Fix them all. Fixes: 1bad2f2f2dfe ("Btrfs-progs: fsck: add an option to check data csums") Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--disk-io.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/disk-io.c b/disk-io.c
index 76958aef..58eae709 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -396,10 +396,12 @@ int read_extent_data(struct btrfs_fs_info *fs_info, char *data, u64 logical,
}
device = multi->stripes[0].dev;
- if (device->fd <= 0)
- goto err;
if (*len > max_len)
*len = max_len;
+ if (device->fd < 0) {
+ ret = -EIO;
+ goto err;
+ }
ret = pread64(device->fd, data, *len, multi->stripes[0].physical);
if (ret != *len)