|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include "fastfetch.h" |
| 4 | + |
| 5 | +/* |
| 6 | + * CDDL HEADER START |
| 7 | + * |
| 8 | + * The contents of this file are subject to the terms of the |
| 9 | + * Common Development and Distribution License (the "License"). |
| 10 | + * You may not use this file except in compliance with the License. |
| 11 | + * |
| 12 | + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
| 13 | + * or https://opensource.org/licenses/CDDL-1.0. |
| 14 | + * See the License for the specific language governing permissions |
| 15 | + * and limitations under the License. |
| 16 | + * |
| 17 | + * When distributing Covered Code, include this CDDL HEADER in each |
| 18 | + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
| 19 | + * If applicable, add the following below this CDDL HEADER, with the |
| 20 | + * fields enclosed by brackets "[]" replaced with your own identifying |
| 21 | + * information: Portions Copyright [yyyy] [name of copyright owner] |
| 22 | + * |
| 23 | + * CDDL HEADER END |
| 24 | + */ |
| 25 | + |
| 26 | +// From https://github.com/NetBSD/src/blob/trunk/external/cddl/osnet/sys/sys/opentypes.h |
| 27 | + |
| 28 | +typedef longlong_t hrtime_t; |
| 29 | +typedef unsigned int uint_t; |
| 30 | +typedef bool boolean_t; |
| 31 | + |
| 32 | +// From https://github.com/NetBSD/src/blob/trunk/external/cddl/osnet/dist/uts/common/sys/fs/zfs.h |
| 33 | + |
| 34 | +typedef enum { |
| 35 | + ZPOOL_PROP_NAME, |
| 36 | + ZPOOL_PROP_SIZE, |
| 37 | + ZPOOL_PROP_CAPACITY, |
| 38 | + ZPOOL_PROP_ALTROOT, |
| 39 | + ZPOOL_PROP_HEALTH, |
| 40 | + ZPOOL_PROP_GUID, |
| 41 | + ZPOOL_PROP_VERSION, |
| 42 | + ZPOOL_PROP_BOOTFS, |
| 43 | + ZPOOL_PROP_DELEGATION, |
| 44 | + ZPOOL_PROP_AUTOREPLACE, |
| 45 | + ZPOOL_PROP_CACHEFILE, |
| 46 | + ZPOOL_PROP_FAILUREMODE, |
| 47 | + ZPOOL_PROP_LISTSNAPS, |
| 48 | + ZPOOL_PROP_AUTOEXPAND, |
| 49 | + ZPOOL_PROP_DEDUPDITTO, |
| 50 | + ZPOOL_PROP_DEDUPRATIO, |
| 51 | + ZPOOL_PROP_FREE, |
| 52 | + ZPOOL_PROP_ALLOCATED, |
| 53 | + ZPOOL_PROP_READONLY, |
| 54 | + ZPOOL_PROP_COMMENT, |
| 55 | + ZPOOL_PROP_EXPANDSZ, |
| 56 | + ZPOOL_PROP_FREEING, |
| 57 | + ZPOOL_PROP_FRAGMENTATION, |
| 58 | + ZPOOL_PROP_LEAKED, |
| 59 | + ZPOOL_PROP_MAXBLOCKSIZE, |
| 60 | + ZPOOL_NUM_PROPS |
| 61 | +} zpool_prop_t; |
| 62 | + |
| 63 | +typedef enum { |
| 64 | + ZPROP_SRC_NONE = 0x1, |
| 65 | + ZPROP_SRC_DEFAULT = 0x2, |
| 66 | + ZPROP_SRC_TEMPORARY = 0x4, |
| 67 | + ZPROP_SRC_LOCAL = 0x8, |
| 68 | + ZPROP_SRC_INHERITED = 0x10, |
| 69 | + ZPROP_SRC_RECEIVED = 0x20 |
| 70 | +} zprop_source_t; |
| 71 | + |
| 72 | +#define ZPOOL_CONFIG_VDEV_TREE "vdev_tree" |
| 73 | +#define ZPOOL_CONFIG_VDEV_STATS "vdev_stats" |
| 74 | + |
| 75 | +typedef enum vdev_state { |
| 76 | + VDEV_STATE_UNKNOWN = 0, |
| 77 | + VDEV_STATE_CLOSED, |
| 78 | + VDEV_STATE_OFFLINE, |
| 79 | + VDEV_STATE_REMOVED, |
| 80 | + VDEV_STATE_CANT_OPEN, |
| 81 | + VDEV_STATE_FAULTED, |
| 82 | + VDEV_STATE_DEGRADED, |
| 83 | + VDEV_STATE_HEALTHY |
| 84 | +} vdev_state_t; |
| 85 | + |
| 86 | +typedef enum vdev_aux { |
| 87 | + VDEV_AUX_NONE, |
| 88 | + VDEV_AUX_OPEN_FAILED, |
| 89 | + VDEV_AUX_CORRUPT_DATA, |
| 90 | + VDEV_AUX_NO_REPLICAS, |
| 91 | + VDEV_AUX_BAD_GUID_SUM, |
| 92 | + VDEV_AUX_TOO_SMALL, |
| 93 | + VDEV_AUX_BAD_LABEL, |
| 94 | + VDEV_AUX_VERSION_NEWER, |
| 95 | + VDEV_AUX_VERSION_OLDER, |
| 96 | + VDEV_AUX_UNSUP_FEAT, |
| 97 | + VDEV_AUX_SPARED, |
| 98 | + VDEV_AUX_ERR_EXCEEDED, |
| 99 | + VDEV_AUX_IO_FAILURE, |
| 100 | + VDEV_AUX_BAD_LOG, |
| 101 | + VDEV_AUX_EXTERNAL, |
| 102 | + VDEV_AUX_SPLIT_POOL, |
| 103 | + VDEV_AUX_ASHIFT_TOO_BIG |
| 104 | +} vdev_aux_t; |
| 105 | + |
| 106 | +typedef enum pool_state { |
| 107 | + POOL_STATE_ACTIVE = 0, |
| 108 | + POOL_STATE_EXPORTED, |
| 109 | + POOL_STATE_DESTROYED, |
| 110 | + POOL_STATE_SPARE, |
| 111 | + POOL_STATE_L2CACHE, |
| 112 | + POOL_STATE_UNINITIALIZED, |
| 113 | + POOL_STATE_UNAVAIL, |
| 114 | + POOL_STATE_POTENTIALLY_ACTIVE |
| 115 | +} pool_state_t; |
| 116 | + |
| 117 | +typedef enum zio_type { |
| 118 | + ZIO_TYPE_NULL = 0, |
| 119 | + ZIO_TYPE_READ, |
| 120 | + ZIO_TYPE_WRITE, |
| 121 | + ZIO_TYPE_FREE, |
| 122 | + ZIO_TYPE_CLAIM, |
| 123 | + ZIO_TYPE_IOCTL, |
| 124 | + ZIO_TYPES |
| 125 | +} zio_type_t; |
| 126 | + |
| 127 | + |
| 128 | +typedef struct vdev_stat { |
| 129 | + hrtime_t vs_timestamp; |
| 130 | + uint64_t vs_state; |
| 131 | + uint64_t vs_aux; |
| 132 | + uint64_t vs_alloc; |
| 133 | + uint64_t vs_space; |
| 134 | + uint64_t vs_dspace; |
| 135 | + uint64_t vs_rsize; |
| 136 | + uint64_t vs_esize; |
| 137 | + uint64_t vs_ops[ZIO_TYPES]; |
| 138 | + uint64_t vs_bytes[ZIO_TYPES]; |
| 139 | + uint64_t vs_read_errors; |
| 140 | + uint64_t vs_write_errors; |
| 141 | + uint64_t vs_checksum_errors; |
| 142 | + uint64_t vs_self_healed; |
| 143 | + uint64_t vs_scan_removing; |
| 144 | + uint64_t vs_scan_processed; |
| 145 | + uint64_t vs_configured_ashift; |
| 146 | + uint64_t vs_logical_ashift; |
| 147 | + uint64_t vs_physical_ashift; |
| 148 | + uint64_t vs_fragmentation; |
| 149 | +} vdev_stat_t; |
| 150 | + |
| 151 | +// From https://github.com/NetBSD/src/blob/trunk/external/cddl/osnet/uts/common/sys/nvpair.h |
| 152 | + |
| 153 | +typedef struct nvlist { |
| 154 | + int32_t nvl_version; |
| 155 | + uint32_t nvl_nvflag; |
| 156 | + uint64_t nvl_priv; |
| 157 | + uint32_t nvl_flag; |
| 158 | + int32_t nvl_pad; |
| 159 | +} nvlist_t; |
| 160 | + |
| 161 | +// From https://github.com/NetBSD/src/blob/trunk/external/cddl/osnet/dist/lib/libzfs/common/libzfs.h |
| 162 | + |
| 163 | +typedef enum { |
| 164 | + ZPOOL_STATUS_CORRUPT_CACHE, |
| 165 | + ZPOOL_STATUS_MISSING_DEV_R, |
| 166 | + ZPOOL_STATUS_MISSING_DEV_NR, |
| 167 | + ZPOOL_STATUS_CORRUPT_LABEL_R, |
| 168 | + ZPOOL_STATUS_CORRUPT_LABEL_NR, |
| 169 | + ZPOOL_STATUS_BAD_GUID_SUM, |
| 170 | + ZPOOL_STATUS_CORRUPT_POOL, |
| 171 | + ZPOOL_STATUS_CORRUPT_DATA, |
| 172 | + ZPOOL_STATUS_FAILING_DEV, |
| 173 | + ZPOOL_STATUS_VERSION_NEWER, |
| 174 | + ZPOOL_STATUS_HOSTID_MISMATCH, |
| 175 | + ZPOOL_STATUS_IO_FAILURE_WAIT, |
| 176 | + ZPOOL_STATUS_IO_FAILURE_CONTINUE, |
| 177 | + ZPOOL_STATUS_BAD_LOG, |
| 178 | + ZPOOL_STATUS_UNSUP_FEAT_READ, |
| 179 | + ZPOOL_STATUS_UNSUP_FEAT_WRITE, |
| 180 | + ZPOOL_STATUS_FAULTED_DEV_R, |
| 181 | + ZPOOL_STATUS_FAULTED_DEV_NR, |
| 182 | + ZPOOL_STATUS_VERSION_OLDER, |
| 183 | + ZPOOL_STATUS_FEAT_DISABLED, |
| 184 | + ZPOOL_STATUS_RESILVERING, |
| 185 | + ZPOOL_STATUS_OFFLINE_DEV, |
| 186 | + ZPOOL_STATUS_REMOVED_DEV, |
| 187 | + ZPOOL_STATUS_NON_NATIVE_ASHIFT, |
| 188 | + ZPOOL_STATUS_OK |
| 189 | +} zpool_status_t; |
| 190 | + |
| 191 | +typedef struct zpool_handle zpool_handle_t; |
| 192 | +typedef struct libzfs_handle libzfs_handle_t; |
| 193 | +typedef int (*zpool_iter_f)(zpool_handle_t *, void *); |
| 194 | + |
| 195 | +extern libzfs_handle_t *libzfs_init(void); |
| 196 | +extern void libzfs_fini(libzfs_handle_t *); |
| 197 | +extern const char *zpool_get_name(zpool_handle_t *); |
| 198 | +extern int zpool_get_state(zpool_handle_t *); |
| 199 | +extern const char *zpool_state_to_name(vdev_state_t, vdev_aux_t); |
| 200 | +extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *); |
| 201 | +extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t, zprop_source_t *); |
| 202 | +extern zpool_status_t zpool_get_status(zpool_handle_t *, char **); |
| 203 | +extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **); |
| 204 | + |
| 205 | +const char *zpool_get_state_str(zpool_handle_t *); |
| 206 | + |
| 207 | +// From https://github.com/NetBSD/src/blob/trunk/external/cddl/osnet/dist/uts/common/sys/nvpair.h |
| 208 | + |
| 209 | +extern nvlist_t *opensolaris_fnvlist_lookup_nvlist(nvlist_t *, const char *); |
| 210 | +extern int opensolaris_nvlist_lookup_uint64_array(nvlist_t *, const char *, uint64_t **, uint_t *); |
| 211 | +extern int opensolaris_nvlist_lookup_uint32_array(nvlist_t *, const char *, uint32_t **, uint_t *); |
0 commit comments