]> git.proxmox.com Git - mirror_zfs.git/blame - include/libzutil.h
zed: Ignore false 'atari' partitions in autoreplace
[mirror_zfs.git] / include / libzutil.h
CommitLineData
e89f1295
DB
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2018 by Delphix. All rights reserved.
24 */
25
26#ifndef _LIBZUTIL_H
739cfb96 27#define _LIBZUTIL_H extern __attribute__((visibility("default")))
e89f1295
DB
28
29#include <sys/nvpair.h>
30#include <sys/fs/zfs.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/*
37 * Default wait time for a device name to be created.
38 */
39#define DISK_LABEL_WAIT (30 * 1000) /* 30 seconds */
40
41
42/*
43 * Pool Config Operations
44 *
45 * These are specific to the library libzfs or libzpool instance.
46 */
47typedef nvlist_t *refresh_config_func_t(void *, nvlist_t *);
48
49typedef int pool_active_func_t(void *, const char *, uint64_t, boolean_t *);
50
51typedef const struct pool_config_ops {
52 refresh_config_func_t *pco_refresh_config;
53 pool_active_func_t *pco_pool_active;
54} pool_config_ops_t;
55
56/*
57 * An instance of pool_config_ops_t is expected in the caller's binary.
58 */
739cfb96
AZ
59_LIBZUTIL_H const pool_config_ops_t libzfs_config_ops;
60_LIBZUTIL_H const pool_config_ops_t libzpool_config_ops;
e89f1295
DB
61
62typedef struct importargs {
63 char **path; /* a list of paths to search */
64 int paths; /* number of paths to search */
65 const char *poolname; /* name of a pool to find */
66 uint64_t guid; /* guid of a pool to find */
67 const char *cachefile; /* cachefile to use for import */
68 boolean_t can_be_active; /* can the pool be active? */
69 boolean_t scan; /* prefer scanning to libblkid cache */
70 nvlist_t *policy; /* load policy (max txg, rewind, etc.) */
71} importargs_t;
72
739cfb96 73_LIBZUTIL_H nvlist_t *zpool_search_import(void *, importargs_t *,
e89f1295 74 const pool_config_ops_t *);
739cfb96
AZ
75_LIBZUTIL_H int zpool_find_config(void *, const char *, nvlist_t **,
76 importargs_t *, const pool_config_ops_t *);
e89f1295 77
739cfb96
AZ
78_LIBZUTIL_H const char * const * zpool_default_search_paths(size_t *count);
79_LIBZUTIL_H int zpool_read_label(int, nvlist_t **, int *);
80_LIBZUTIL_H int zpool_label_disk_wait(const char *, int);
e89f1295
DB
81
82struct udev_device;
83
739cfb96
AZ
84_LIBZUTIL_H int zfs_device_get_devid(struct udev_device *, char *, size_t);
85_LIBZUTIL_H int zfs_device_get_physical(struct udev_device *, char *, size_t);
95692927 86
739cfb96 87_LIBZUTIL_H void update_vdev_config_dev_strs(nvlist_t *);
e89f1295
DB
88
89/*
90 * Default device paths
91 */
92#define DISK_ROOT "/dev"
93#define UDISK_ROOT "/dev/disk"
94#define ZVOL_ROOT "/dev/zvol"
95
739cfb96
AZ
96_LIBZUTIL_H int zfs_append_partition(char *path, size_t max_len);
97_LIBZUTIL_H int zfs_resolve_shortname(const char *name, char *path,
98 size_t pathlen);
e89f1295 99
5ac80603
AZ
100_LIBZUTIL_H char *zfs_strip_partition(const char *);
101_LIBZUTIL_H const char *zfs_strip_path(const char *);
e89f1295 102
739cfb96 103_LIBZUTIL_H int zfs_strcmp_pathname(const char *, const char *, int);
e89f1295 104
739cfb96
AZ
105_LIBZUTIL_H boolean_t zfs_dev_is_dm(const char *);
106_LIBZUTIL_H boolean_t zfs_dev_is_whole_disk(const char *);
107_LIBZUTIL_H int zfs_dev_flush(int);
108_LIBZUTIL_H char *zfs_get_underlying_path(const char *);
109_LIBZUTIL_H char *zfs_get_enclosure_sysfs_path(const char *);
e89f1295 110
739cfb96 111_LIBZUTIL_H boolean_t is_mpath_whole_disk(const char *);
e89f1295 112
739cfb96 113_LIBZUTIL_H boolean_t zfs_isnumber(const char *);
3283f137 114
e89f1295
DB
115/*
116 * Formats for iostat numbers. Examples: "12K", "30ms", "4B", "2321234", "-".
117 *
118 * ZFS_NICENUM_1024: Print kilo, mega, tera, peta, exa..
119 * ZFS_NICENUM_BYTES: Print single bytes ("13B"), kilo, mega, tera...
120 * ZFS_NICENUM_TIME: Print nanosecs, microsecs, millisecs, seconds...
121 * ZFS_NICENUM_RAW: Print the raw number without any formatting
122 * ZFS_NICENUM_RAWTIME: Same as RAW, but print dashes ('-') for zero.
123 */
124enum zfs_nicenum_format {
125 ZFS_NICENUM_1024 = 0,
126 ZFS_NICENUM_BYTES = 1,
127 ZFS_NICENUM_TIME = 2,
128 ZFS_NICENUM_RAW = 3,
129 ZFS_NICENUM_RAWTIME = 4
130};
131
132/*
133 * Convert a number to a human-readable form.
134 */
739cfb96
AZ
135_LIBZUTIL_H void zfs_nicebytes(uint64_t, char *, size_t);
136_LIBZUTIL_H void zfs_nicenum(uint64_t, char *, size_t);
137_LIBZUTIL_H void zfs_nicenum_format(uint64_t, char *, size_t,
e89f1295 138 enum zfs_nicenum_format);
739cfb96
AZ
139_LIBZUTIL_H void zfs_nicetime(uint64_t, char *, size_t);
140_LIBZUTIL_H void zfs_niceraw(uint64_t, char *, size_t);
e89f1295
DB
141
142#define nicenum(num, buf, size) zfs_nicenum(num, buf, size)
143
739cfb96
AZ
144_LIBZUTIL_H void zpool_dump_ddt(const ddt_stat_t *, const ddt_histogram_t *);
145_LIBZUTIL_H int zpool_history_unpack(char *, uint64_t, uint64_t *, nvlist_t ***,
e89f1295
DB
146 uint_t *);
147
1f2f46be 148struct zfs_cmd;
1f2f46be 149
9fb2771a
TH
150/*
151 * List of colors to use
152 */
153#define ANSI_RED "\033[0;31m"
154#define ANSI_YELLOW "\033[0;33m"
155#define ANSI_RESET "\033[0m"
156#define ANSI_BOLD "\033[1m"
157
a926aab9 158_LIBZUTIL_H void color_start(const char *color);
739cfb96 159_LIBZUTIL_H void color_end(void);
a926aab9 160_LIBZUTIL_H int printf_color(const char *color, const char *format, ...);
9fb2771a 161
0854d4c1
AZ
162_LIBZUTIL_H const char *zfs_basename(const char *path);
163_LIBZUTIL_H ssize_t zfs_dirnamelen(const char *path);
164
2a8430a2
TH
165/*
166 * These functions are used by the ZFS libraries and cmd/zpool code, but are
167 * not exported in the ABI.
168 */
169typedef int (*pool_vdev_iter_f)(void *, nvlist_t *, void *);
170int for_each_vdev_cb(void *zhp, nvlist_t *nv, pool_vdev_iter_f func,
171 void *data);
172int for_each_vdev_in_nvlist(nvlist_t *nvroot, pool_vdev_iter_f func,
173 void *data);
174void update_vdevs_config_dev_sysfs_path(nvlist_t *config);
e89f1295
DB
175#ifdef __cplusplus
176}
177#endif
178
179#endif /* _LIBZUTIL_H */