aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libzfs/os/linux
diff options
context:
space:
mode:
authorRyan Moeller <[email protected]>2020-02-12 16:00:19 -0500
committerGitHub <[email protected]>2020-02-12 13:00:19 -0800
commite7be5c47bd8f824c79631b2747731ae169d6ae7a (patch)
tree092a00cad58f0482c578822d7647b15cb028d457 /lib/libzfs/os/linux
parent1bbeb6d755ba2aa72578faceb44183987c51b8d8 (diff)
Move zfs_version_kernel to platform code
Linux uses sysfs to determine the module version, FreeBSD uses a different method. Reviewed-by: Igor Kozhukhov <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ryan Moeller <[email protected]> Closes #9978
Diffstat (limited to 'lib/libzfs/os/linux')
-rw-r--r--lib/libzfs/os/linux/libzfs_util_os.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/libzfs/os/linux/libzfs_util_os.c b/lib/libzfs/os/linux/libzfs_util_os.c
index c27dc91bc..918a43f7d 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 <libzutil.h>
+#include <sys/zfs_sysfs.h>
#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);
+}