Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 Jun 2022 08:50:58 GMT
From:      Toomas Soome <tsoome@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 39510c65e376 - stable/13 - test_diskread(): detect end of the disk
Message-ID:  <202206260850.25Q8owKe013021@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by tsoome:

URL: https://cgit.FreeBSD.org/src/commit/?id=39510c65e376dad3948061d658d8290e25b504de

commit 39510c65e376dad3948061d658d8290e25b504de
Author:     Toomas Soome <tsoome@FreeBSD.org>
AuthorDate: 2022-06-01 07:28:43 +0000
Commit:     Toomas Soome <tsoome@FreeBSD.org>
CommitDate: 2022-06-26 05:28:07 +0000

    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.
    
    Differential Revision:  https://reviews.freebsd.org/D35432
    
    (cherry picked from commit 942e52f776e6bbe016a3e920c96a1cd4dbddf7e3)
---
 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 baf1b6243c1f..4ad18176ba6e 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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202206260850.25Q8owKe013021>