From 856340754c1309f3731e885b93baa2b7283c11c5 Mon Sep 17 00:00:00 2001 From: avg Date: Tue, 1 Aug 2017 11:09:18 +0000 Subject: [PATCH] zfsboottest: catch up with r316585 and provide ldi_get_size method This method is required for querying file / disk sizes which is needed at least for finding all copies of ZFS VDEV labels. Reported by: ngie MFC after: 1 week --- tools/tools/zfsboottest/zfsboottest.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/tools/zfsboottest/zfsboottest.c b/tools/tools/zfsboottest/zfsboottest.c index a072671f44d8..875657f55b7b 100644 --- a/tools/tools/zfsboottest/zfsboottest.c +++ b/tools/tools/zfsboottest/zfsboottest.c @@ -28,7 +28,9 @@ /* $FreeBSD$ */ #include +#include #include +#include #include #include #include @@ -51,6 +53,20 @@ pager_output(const char *line) return (0); } +uint64_t +ldi_get_size(void *priv) +{ + struct stat sb; + int fd; + + fd = *(int *)priv; + if (fstat(fd, &sb) != 0) + return (0); + if (S_ISCHR(sb.st_mode) && ioctl(fd, DIOCGMEDIASIZE, &sb.st_size) != 0) + return (0); + return (sb.st_size); +} + #define ZFS_TEST #define printf(...) fprintf(stderr, __VA_ARGS__) #include "libzfs.h"