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;
};
+/*
+ * Read len bytes to buf.
+ * Return:
+ * 0 - success
+ * < 0 - negative errno in case of error
+ * > 0 - no data read, EOF
+ */
static int read_buf(struct btrfs_send_stream *sctx, char *buf, size_t len)
{
int ret;
}
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;
}
/*
* Reads a single command from kernel space and decodes the TLV's into
* sctx->cmd_attrs
+ *
+ * Returns:
+ * 0 - success
+ * < 0 - an error in the command
*/
static int read_cmd(struct btrfs_send_stream *sctx)
{
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;
}