diff --git a/stand/kboot/host_syscall.h b/stand/kboot/host_syscall.h index 38f0fb04aa9..75394afcde6 100644 --- a/stand/kboot/host_syscall.h +++ b/stand/kboot/host_syscall.h @@ -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 diff --git a/stand/kboot/hostfs.c b/stand/kboot/hostfs.c index 08f532999ab..02afa885d83 100644 --- a/stand/kboot/hostfs.c +++ b/stand/kboot/hostfs.c @@ -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);