Move zfs_version_kernel to platform code
Linux uses sysfs to determine the module version, FreeBSD uses a different method. Reviewed-by: Igor Kozhukhov <igor@dilos.org> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ryan Moeller <ryan@iXsystems.com> Closes #9978
This commit is contained in:
parent
1bbeb6d755
commit
e7be5c47bd
|
@ -54,7 +54,6 @@
|
|||
#include "zfeature_common.h"
|
||||
#include <zfs_fletcher.h>
|
||||
#include <libzutil.h>
|
||||
#include <sys/zfs_sysfs.h>
|
||||
|
||||
|
||||
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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue