aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2023-02-02 20:06:24 +0000
committerWarner Losh <imp@FreeBSD.org>2023-02-02 20:06:31 +0000
commit2e1edd04eb01bac15628185686cbf615d80de7de (patch)
tree2d4392038cf6e7ac38e39ea4860af356622922e5
parent81d71f94cabcef8f88637f426bcd8379f9448fd9 (diff)
downloadsrc-2e1edd04eb01bac15628185686cbf615d80de7de.tar.gz
src-2e1edd04eb01bac15628185686cbf615d80de7de.zip
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
-rw-r--r--stand/kboot/host_syscall.h10
-rw-r--r--stand/kboot/hostfs.c5
2 files changed, 12 insertions, 3 deletions
diff --git a/stand/kboot/host_syscall.h b/stand/kboot/host_syscall.h
index 38f0fb04aa95..75394afcde6c 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 08f532999abe..02afa885d833 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);