X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=send-stream.c;h=78f2571ae40be82cbce1b7eb40e80c5293acd6c8;hb=faaf70f1cc7ade1d6d5a41a900a3b58cc4bd5f58;hp=d2de9d39d2962939580b980116f64e6ca9e30902;hpb=028476f19c0b6fd8cd5069837fcb3f0faf9d0173;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/send-stream.c b/send-stream.c index d2de9d3..78f2571 100644 --- a/send-stream.c +++ b/send-stream.c @@ -33,6 +33,12 @@ struct btrfs_send_stream { struct btrfs_tlv_header *cmd_attrs[BTRFS_SEND_A_MAX + 1]; u32 version; + /* + * end of last successful read, equivalent to start of current + * malformated part of block + */ + size_t stream_pos; + struct btrfs_send_ops *ops; void *user; }; @@ -61,13 +67,20 @@ static int read_buf(struct btrfs_send_stream *sctx, char *buf, size_t len) } if (rbytes == 0) { ret = 1; - goto out; + goto out_eof; } pos += rbytes; } - ret = 0; +out_eof: + if (0 < pos && pos < len) { + error("short read from stream: expected %zu read %zu", len, pos); + ret = -EIO; + } else { + sctx->stream_pos += pos; + } + out: return ret; } @@ -473,12 +486,13 @@ int btrfs_read_and_process_send_stream(int fd, sctx.fd = fd; sctx.ops = ops; sctx.user = user; + sctx.stream_pos = 0; ret = read_buf(&sctx, (char*)&hdr, sizeof(hdr)); if (ret < 0) goto out; if (ret) { - ret = 1; + ret = -ENODATA; goto out; }