Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/cddl/osnet/dist/lib/libzpool/common Hacks to get zd...



details:   https://anonhg.NetBSD.org/src/rev/8c84f77e993a
branches:  trunk
changeset: 1024529:8c84f77e993a
user:      simonb <simonb%NetBSD.org@localhost>
date:      Wed Oct 27 11:35:23 2021 +0000

description:
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@.

diffstat:

 external/cddl/osnet/dist/lib/libzpool/common/kernel.c |  32 +++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diffs (63 lines):

diff -r 53f07d23fe80 -r 8c84f77e993a external/cddl/osnet/dist/lib/libzpool/common/kernel.c
--- a/external/cddl/osnet/dist/lib/libzpool/common/kernel.c     Wed Oct 27 11:27:25 2021 +0000
+++ b/external/cddl/osnet/dist/lib/libzpool/common/kernel.c     Wed Oct 27 11:35:23 2021 +0000
@@ -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 @@
         */
        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 @@
                        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 @@
                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);



Home | Main Index | Thread Index | Old Index