mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
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:
parent
a2e02d9d8e
commit
942e52f776
1 changed files with 5 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue