From 942e52f776e6bbe016a3e920c96a1cd4dbddf7e3 Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Wed, 1 Jun 2022 10:28:43 +0300 Subject: [PATCH] test_diskread(): detect end of the disk Detect the end of the disk condition. This may happpen when disk image is truncated and the reads are addressing blocks past image end. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D35432 --- stand/userboot/test/test.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stand/userboot/test/test.c b/stand/userboot/test/test.c index baf1b6243c1..4ad18176ba6 100644 --- a/stand/userboot/test/test.c +++ b/stand/userboot/test/test.c @@ -254,6 +254,11 @@ test_diskread(void *arg, int unit, uint64_t offset, void *dst, size_t size, if (unit > disk_index || disk_fd[unit] == -1) return (EIO); n = pread(disk_fd[unit], dst, size, offset); + if (n == 0) { + printf("%s: end of disk (%ju)\n", __func__, (intmax_t)offset); + return (EIO); + } + if (n < 0) return (errno); *resid_return = size - n;