/* relay_file_read_subbuf_avail - return bytes available in sub-buffer @read_pos: file read position @buf: relay channel buffer  */
static size_t relay_file_read_subbuf_avail(size_t read_pos, struct rchan_buf *buf)
/* relay_file_read_subbuf_avail - return bytes available in sub-buffer @read_pos: file read position @buf: relay channel buffer  */
static size_t relay_file_read_subbuf_avail(size_t read_pos, struct rchan_buf *buf)
{
	size_t padding, avail = 0;
	size_t read_subbuf, read_offset, write_subbuf, write_offset;
	size_t subbuf_size = buf->chan->subbuf_size;
	write_subbuf = (buf->data - buf->start) / subbuf_size;
	write_offset = buf->offset > subbuf_size ? subbuf_size : buf->offset;
	read_subbuf = read_pos / subbuf_size;
	read_offset = read_pos % subbuf_size;
	padding = buf->padding[read_subbuf];
	if (read_subbuf == write_subbuf) {
		if (read_offset + padding < write_offset)
			avail = write_offset - (read_offset + padding);
	} else
		avail = (subbuf_size - padding) - read_offset;
	return avail;
}