Module Name: src Committed By: simonb Date: Wed Oct 27 11:35:23 UTC 2021
Modified Files: src/external/cddl/osnet/dist/lib/libzpool/common: kernel.c Log Message: Hacks to get zdb working on NetBSD: - Force accessing raw device but we're passed the block device. - Deal with wedges not returning their size on a stat(2) and use the DIOCGMEDIASIZE ioctl instead. Ok chs@. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 \ src/external/cddl/osnet/dist/lib/libzpool/common/kernel.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/cddl/osnet/dist/lib/libzpool/common/kernel.c diff -u src/external/cddl/osnet/dist/lib/libzpool/common/kernel.c:1.2 src/external/cddl/osnet/dist/lib/libzpool/common/kernel.c:1.3 --- src/external/cddl/osnet/dist/lib/libzpool/common/kernel.c:1.2 Mon May 28 21:05:06 2018 +++ src/external/cddl/osnet/dist/lib/libzpool/common/kernel.c Wed Oct 27 11:35:23 2021 @@ -41,6 +41,11 @@ #include <sys/utsname.h> #include <sys/systeminfo.h> +#ifdef __NetBSD__ +#include <sys/dkio.h> +#include <sys/ioctl.h> +#endif + /* * Emulation of kernel services in userland. */ @@ -447,6 +452,17 @@ vn_open(char *path, int x1, int flags, i */ if (strncmp(path, "/dev/", 5) == 0) { char *dsk; +#ifdef __NetBSD__ + /* + * For NetBSD, we've been passed in a block device name + * but need to convert to the character device name. + * XXX a bit ugly... + */ + char rawpath[MAXPATHLEN]; + + snprintf(rawpath, sizeof(rawpath), "/dev/r%s", path + 5); + path = rawpath; /* gets strdup()'d below */ +#endif /* __NetBSD__ */ fd = open64(path, O_RDONLY); if (fd == -1) return (errno); @@ -454,6 +470,14 @@ vn_open(char *path, int x1, int flags, i close(fd); return (errno); } +#ifdef __NetBSD__ + if (st.st_size == 0) { + off_t dsize; + + if (ioctl(fd, DIOCGMEDIASIZE, &dsize) == 0) + st.st_size = dsize; + } +#endif /* __NetBSD__ */ close(fd); (void) sprintf(realpath, "%s", path); dsk = strstr(path, "/dsk/"); @@ -587,6 +611,14 @@ fop_getattr(vnode_t *vp, vattr_t *vap) close(vp->v_fd); return (errno); } +#ifdef __NetBSD__ + if (st.st_size == 0) { + off_t dsize; + + if (ioctl(vp->v_fd, DIOCGMEDIASIZE, &dsize) == 0) + st.st_size = dsize; + } +#endif /* __NetBSD__ */ vap->va_size = st.st_size; return (0);