diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index 2ce3ad1062..a8e9ac9cbb 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -54,7 +54,6 @@ #include "zfeature_common.h" #include #include -#include int @@ -1833,36 +1832,6 @@ zfs_version_userland(char *version, int len) (void) strlcpy(version, ZFS_META_ALIAS, len); } -/* - * Fill given version buffer with zfs kernel version read from ZFS_SYSFS_DIR - * Returns 0 on success, and -1 on error (with errno set) - */ -int -zfs_version_kernel(char *version, int len) -{ - int _errno; - int fd; - int rlen; - - if ((fd = open(ZFS_SYSFS_DIR "/version", O_RDONLY)) == -1) - return (-1); - - if ((rlen = read(fd, version, len)) == -1) { - version[0] = '\0'; - _errno = errno; - (void) close(fd); - errno = _errno; - return (-1); - } - - version[rlen-1] = '\0'; /* discard '\n' */ - - if (close(fd) == -1) - return (-1); - - return (0); -} - /* * Prints both zfs userland and kernel versions * Returns 0 on success, and -1 on error (with errno set) diff --git a/lib/libzfs/os/linux/libzfs_util_os.c b/lib/libzfs/os/linux/libzfs_util_os.c index c27dc91bc6..918a43f7d0 100644 --- a/lib/libzfs/os/linux/libzfs_util_os.c +++ b/lib/libzfs/os/linux/libzfs_util_os.c @@ -41,6 +41,7 @@ #include "libzfs_impl.h" #include "zfs_prop.h" #include +#include #define ZDIFF_SHARESDIR "/.zfs/shares/" @@ -182,3 +183,33 @@ find_shares_object(differ_info_t *di) di->shares = (uint64_t)sb.st_ino; return (0); } + +/* + * Fill given version buffer with zfs kernel version read from ZFS_SYSFS_DIR + * Returns 0 on success, and -1 on error (with errno set) + */ +int +zfs_version_kernel(char *version, int len) +{ + int _errno; + int fd; + int rlen; + + if ((fd = open(ZFS_SYSFS_DIR "/version", O_RDONLY)) == -1) + return (-1); + + if ((rlen = read(fd, version, len)) == -1) { + version[0] = '\0'; + _errno = errno; + (void) close(fd); + errno = _errno; + return (-1); + } + + version[rlen-1] = '\0'; /* discard '\n' */ + + if (close(fd) == -1) + return (-1); + + return (0); +}