From 4e41db28f67de0ee34d7eba53682aedf23292178 Mon Sep 17 00:00:00 2001
From: Alessandro Rubini <rubini@gnudd.com>
Date: Tue, 8 Jan 2013 09:44:17 +0100
Subject: [PATCH] zio-dump: accept zero-size data for zero-size blocks

Now we can have zero-size input blocks, as TDC is real. zio-dump
should not complain when reading zero bytes, if zero were expected.

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Acked-by: Federico Vaga <federico.vaga@gmail.com>
---
 tools/zio-dump.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/zio-dump.c b/tools/zio-dump.c
index 9087d14..a7866b8 100644
--- a/tools/zio-dump.c
+++ b/tools/zio-dump.c
@@ -54,10 +54,15 @@ void print_attributes(struct zio_control *ctrl)
 		       ctrl->attr_trigger.ext_val);
 }
 
-static void ziodump_dataeof(int cfd, int dfd)
+static void ziodump_dataeof(int cfd, int dfd, int expected_size)
 {
 	struct stat stbuf;
 
+	if (!expected_size) {
+		/* We got a zero-size block, so report end-of-data */
+		printf("\n");
+		return;
+	}
 	/*
 	 * If ctrl == data and this is a regular file, EOF is expected
 	 * (it is likely the current-ctrl in sysfs). If not a regular file
@@ -159,7 +164,7 @@ void read_channel(int cfd, int dfd, FILE *log)
 		return; /* next ctrl, let's see... */
 	}
 	if (!i) { /* EOF: handle the various cases */
-		ziodump_dataeof(cfd, dfd);
+		ziodump_dataeof(cfd, dfd, ctrl.nsamples * ctrl.ssize);
 		return;
 	}
 	if (i != ctrl.nsamples * ctrl.ssize) {
-- 
GitLab