1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-13 10:02:38 +00:00

kboot: For hostfs, return better errors from read, where possible.

Translate the Linux error return from read to a FreeBSD errno. We use a
simplified translation: 1-34 are the same between the systems, so any of
those will be returned directly. All other errno map to EINVAL. This
will suffice for some code that reads /dev/mem in producing the right
diagnostic.

A fully generalized version is much harder. Linux has a number of errno
that don't translate well and has architecture dependent
encodings. Avoid this mess with a simple macro for now. Add comment
explaining why we use the simple method we do.

Sponsored by:		Netflix
Reviewed by:		kevans, andrew
Differential Revision:	https://reviews.freebsd.org/D38265
This commit is contained in:
Warner Losh 2023-02-02 13:06:24 -07:00
parent 81d71f94ca
commit 2e1edd04eb
2 changed files with 12 additions and 3 deletions

View File

@ -206,4 +206,14 @@ ssize_t host_write(int fd, const void *buf, size_t nbyte);
host_mmap(0, size, HOST_PROT_READ | HOST_PROT_WRITE, \
HOST_MAP_PRIVATE | HOST_MAP_ANONYMOUS, -1, 0);
/*
* Translate Linux errno to FreeBSD errno. The two system have idenitcal errors
* for 1-34. After that, they differ. Linux also has errno that don't map
* exactly to FreeBSD's errno, plus the Linux errno are arch dependent >
* 34. Since we just need to do this for simple cases, use the simple mapping
* function where -1 to -34 are translated to 1 to 34 and all others are EINVAL.
* Pass the linux return value, which will be the -errno.
*/
#define host_to_stand_errno(e) ((-e) > 34 ? EINVAL : (-e))
#endif

View File

@ -112,9 +112,8 @@ hostfs_read(struct open_file *f, void *start, size_t size, size_t *resid)
ssize_t sz;
sz = host_read(hf->hf_fd, start, size);
if (sz < 0) {
return (EINVAL);
}
if (sz < 0)
return (host_to_stand_errno(sz));
*resid = size - sz;
return (0);