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
This commit is contained in:
Toomas Soome 2022-06-01 10:28:43 +03:00
parent a2e02d9d8e
commit 942e52f776

View file

@ -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;