diff --git a/include/libnvpair.h b/include/libnvpair.h index 5277f9574ddf..bc50c3b7e1f8 100644 --- a/include/libnvpair.h +++ b/include/libnvpair.h @@ -1,196 +1,197 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, Joyent, Inc. All rights reserved. */ #ifndef _LIBNVPAIR_H -#define _LIBNVPAIR_H +#define _LIBNVPAIR_H extern __attribute__((visibility("default"))) #include #include #include #include #ifdef __cplusplus extern "C" { #endif /* * All interfaces described in this file are private to Solaris, and * are subject to change at any time and without notice. The public * nvlist/nvpair interfaces, as documented in manpage sections 3NVPAIR, * are all imported from included above. */ -extern int nvpair_value_match(nvpair_t *, int, char *, char **); -extern int nvpair_value_match_regex(nvpair_t *, int, char *, regex_t *, +_LIBNVPAIR_H int nvpair_value_match(nvpair_t *, int, char *, char **); +_LIBNVPAIR_H int nvpair_value_match_regex(nvpair_t *, int, char *, regex_t *, char **); -extern void nvlist_print(FILE *, nvlist_t *); -int nvlist_print_json(FILE *, nvlist_t *); -extern void dump_nvlist(nvlist_t *, int); +_LIBNVPAIR_H void nvlist_print(FILE *, nvlist_t *); +_LIBNVPAIR_H int nvlist_print_json(FILE *, nvlist_t *); +_LIBNVPAIR_H void dump_nvlist(nvlist_t *, int); /* * Private nvlist printing interface that allows the caller some control * over output rendering (as opposed to nvlist_print and dump_nvlist). * * Obtain an opaque nvlist_prtctl_t cookie using nvlist_prtctl_alloc * (NULL on failure); on return the cookie is set up for default formatting * and rendering. Quote the cookie in subsequent customisation functions and * then pass the cookie to nvlist_prt to render the nvlist. Finally, * use nvlist_prtctl_free to release the cookie. * * For all nvlist_lookup_xxx and nvlist_lookup_xxx_array functions * we have a corresponding brace of functions that appoint replacement * rendering functions: * * extern void nvlist_prtctl_xxx(nvlist_prtctl_t, * void (*)(nvlist_prtctl_t ctl, void *private, const char *name, * xxxtype value)) * * and * * extern void nvlist_prtctl_xxx_array(nvlist_prtctl_t, * void (*)(nvlist_prtctl_t ctl, void *private, const char *name, * xxxtype value, uint_t count)) * * where xxxtype is the C datatype corresponding to xxx, eg int8_t for "int8" * and char * for "string". The function that is appointed to render the * specified datatype receives as arguments the cookie, the nvlist * member name, the value of that member (or a pointer for array function), * and (for array rendering functions) a count of the number of elements. */ typedef struct nvlist_prtctl *nvlist_prtctl_t; /* opaque */ enum nvlist_indent_mode { NVLIST_INDENT_ABS, /* Absolute indentation */ NVLIST_INDENT_TABBED /* Indent with tabstops */ }; -extern nvlist_prtctl_t nvlist_prtctl_alloc(void); -extern void nvlist_prtctl_free(nvlist_prtctl_t); -extern void nvlist_prt(nvlist_t *, nvlist_prtctl_t); +_LIBNVPAIR_H nvlist_prtctl_t nvlist_prtctl_alloc(void); +_LIBNVPAIR_H void nvlist_prtctl_free(nvlist_prtctl_t); +_LIBNVPAIR_H void nvlist_prt(nvlist_t *, nvlist_prtctl_t); /* Output stream */ -extern void nvlist_prtctl_setdest(nvlist_prtctl_t, FILE *); -extern FILE *nvlist_prtctl_getdest(nvlist_prtctl_t); +_LIBNVPAIR_H void nvlist_prtctl_setdest(nvlist_prtctl_t, FILE *); +_LIBNVPAIR_H FILE *nvlist_prtctl_getdest(nvlist_prtctl_t); /* Indentation mode, start indent, indent increment; default tabbed/0/1 */ -extern void nvlist_prtctl_setindent(nvlist_prtctl_t, enum nvlist_indent_mode, - int, int); -extern void nvlist_prtctl_doindent(nvlist_prtctl_t, int); +_LIBNVPAIR_H void nvlist_prtctl_setindent(nvlist_prtctl_t, + enum nvlist_indent_mode, int, int); +_LIBNVPAIR_H void nvlist_prtctl_doindent(nvlist_prtctl_t, int); enum nvlist_prtctl_fmt { NVLIST_FMT_MEMBER_NAME, /* name fmt; default "%s = " */ NVLIST_FMT_MEMBER_POSTAMBLE, /* after nvlist member; default "\n" */ NVLIST_FMT_BTWN_ARRAY /* between array members; default " " */ }; -extern void nvlist_prtctl_setfmt(nvlist_prtctl_t, enum nvlist_prtctl_fmt, +_LIBNVPAIR_H void nvlist_prtctl_setfmt(nvlist_prtctl_t, enum nvlist_prtctl_fmt, const char *); -extern void nvlist_prtctl_dofmt(nvlist_prtctl_t, enum nvlist_prtctl_fmt, ...); +_LIBNVPAIR_H void nvlist_prtctl_dofmt(nvlist_prtctl_t, enum nvlist_prtctl_fmt, + ...); /* * Function prototypes for interfaces that appoint a new rendering function * for single-valued nvlist members. * * A replacement function receives arguments as follows: * * nvlist_prtctl_t Print control structure; do not change preferences * for this object from a print callback function. * * void * The function-private cookie argument registered * when the replacement function was appointed. * * nvlist_t * The full nvlist that is being processed. The * rendering function is called to render a single * member (name and value passed as below) but it may * want to reference or incorporate other aspects of * the full nvlist. * * const char * Member name to render * * valtype Value of the member to render * * The function must return non-zero if it has rendered output for this * member, or 0 if it wants to default to standard rendering for this * one member. */ #define NVLIST_PRINTCTL_SVDECL(funcname, valtype) \ - extern void funcname(nvlist_prtctl_t, \ + _LIBNVPAIR_H void funcname(nvlist_prtctl_t, \ int (*)(nvlist_prtctl_t, void *, nvlist_t *, const char *, valtype), \ void *) NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_boolean, int); NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_boolean_value, boolean_t); NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_byte, uchar_t); NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int8, int8_t); NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint8, uint8_t); NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int16, int16_t); NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint16, uint16_t); NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int32, int32_t); NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint32, uint32_t); NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int64, int64_t); NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint64, uint64_t); NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_double, double); NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_string, char *); NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_hrtime, hrtime_t); NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_nvlist, nvlist_t *); #undef NVLIST_PRINTCTL_SVDECL /* was just for "clarity" above */ /* * Function prototypes for interfaces that appoint a new rendering function * for array-valued nvlist members. * * One additional argument is taken: uint_t for the number of array elements * * Return values as above. */ #define NVLIST_PRINTCTL_AVDECL(funcname, vtype) \ - extern void funcname(nvlist_prtctl_t, \ + _LIBNVPAIR_H void funcname(nvlist_prtctl_t, \ int (*)(nvlist_prtctl_t, void *, nvlist_t *, const char *, vtype, uint_t), \ void *) NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_boolean_array, boolean_t *); NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_byte_array, uchar_t *); NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int8_array, int8_t *); NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint8_array, uint8_t *); NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int16_array, int16_t *); NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint16_array, uint16_t *); NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int32_array, int32_t *); NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint32_array, uint32_t *); NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int64_array, int64_t *); NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint64_array, uint64_t *); NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_string_array, char **); NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_nvlist_array, nvlist_t **); #undef NVLIST_PRINTCTL_AVDECL /* was just for "clarity" above */ #ifdef __cplusplus } #endif #endif /* _LIBNVPAIR_H */ diff --git a/include/libzfs_core.h b/include/libzfs_core.h index 34161a06fb45..83d8211ab615 100644 --- a/include/libzfs_core.h +++ b/include/libzfs_core.h @@ -1,144 +1,150 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2012, 2020 by Delphix. All rights reserved. * Copyright (c) 2017 Datto Inc. * Copyright 2017 RackTop Systems. * Copyright (c) 2017 Open-E, Inc. All Rights Reserved. */ #ifndef _LIBZFS_CORE_H -#define _LIBZFS_CORE_H +#define _LIBZFS_CORE_H extern __attribute__((visibility("default"))) #include #include #include #include #ifdef __cplusplus extern "C" { #endif -int libzfs_core_init(void); -void libzfs_core_fini(void); +_LIBZFS_CORE_H int libzfs_core_init(void); +_LIBZFS_CORE_H void libzfs_core_fini(void); /* - * NB: this type should be kept binary compatible with dmu_objset_type_t. + * NB: this type should be kept binary-compatible with dmu_objset_type_t. */ enum lzc_dataset_type { LZC_DATSET_TYPE_ZFS = 2, LZC_DATSET_TYPE_ZVOL }; -int lzc_snapshot(nvlist_t *, nvlist_t *, nvlist_t **); -int lzc_create(const char *, enum lzc_dataset_type, nvlist_t *, uint8_t *, +_LIBZFS_CORE_H int lzc_snapshot(nvlist_t *, nvlist_t *, nvlist_t **); +_LIBZFS_CORE_H int lzc_create(const char *, enum lzc_dataset_type, nvlist_t *, + uint8_t *, uint_t); +_LIBZFS_CORE_H int lzc_clone(const char *, const char *, nvlist_t *); +_LIBZFS_CORE_H int lzc_promote(const char *, char *, int); +_LIBZFS_CORE_H int lzc_destroy_snaps(nvlist_t *, boolean_t, nvlist_t **); +_LIBZFS_CORE_H int lzc_bookmark(nvlist_t *, nvlist_t **); +_LIBZFS_CORE_H int lzc_get_bookmarks(const char *, nvlist_t *, nvlist_t **); +_LIBZFS_CORE_H int lzc_get_bookmark_props(const char *, nvlist_t **); +_LIBZFS_CORE_H int lzc_destroy_bookmarks(nvlist_t *, nvlist_t **); +_LIBZFS_CORE_H int lzc_load_key(const char *, boolean_t, uint8_t *, uint_t); +_LIBZFS_CORE_H int lzc_unload_key(const char *); +_LIBZFS_CORE_H int lzc_change_key(const char *, uint64_t, nvlist_t *, uint8_t *, uint_t); -int lzc_clone(const char *, const char *, nvlist_t *); -int lzc_promote(const char *, char *, int); -int lzc_destroy_snaps(nvlist_t *, boolean_t, nvlist_t **); -int lzc_bookmark(nvlist_t *, nvlist_t **); -int lzc_get_bookmarks(const char *, nvlist_t *, nvlist_t **); -int lzc_get_bookmark_props(const char *, nvlist_t **); -int lzc_destroy_bookmarks(nvlist_t *, nvlist_t **); -int lzc_load_key(const char *, boolean_t, uint8_t *, uint_t); -int lzc_unload_key(const char *); -int lzc_change_key(const char *, uint64_t, nvlist_t *, uint8_t *, uint_t); -int lzc_initialize(const char *, pool_initialize_func_t, nvlist_t *, - nvlist_t **); -int lzc_trim(const char *, pool_trim_func_t, uint64_t, boolean_t, +_LIBZFS_CORE_H int lzc_initialize(const char *, pool_initialize_func_t, nvlist_t *, nvlist_t **); -int lzc_redact(const char *, const char *, nvlist_t *); +_LIBZFS_CORE_H int lzc_trim(const char *, pool_trim_func_t, uint64_t, boolean_t, + nvlist_t *, nvlist_t **); +_LIBZFS_CORE_H int lzc_redact(const char *, const char *, nvlist_t *); -int lzc_snaprange_space(const char *, const char *, uint64_t *); +_LIBZFS_CORE_H int lzc_snaprange_space(const char *, const char *, uint64_t *); -int lzc_hold(nvlist_t *, int, nvlist_t **); -int lzc_release(nvlist_t *, nvlist_t **); -int lzc_get_holds(const char *, nvlist_t **); +_LIBZFS_CORE_H int lzc_hold(nvlist_t *, int, nvlist_t **); +_LIBZFS_CORE_H int lzc_release(nvlist_t *, nvlist_t **); +_LIBZFS_CORE_H int lzc_get_holds(const char *, nvlist_t **); enum lzc_send_flags { LZC_SEND_FLAG_EMBED_DATA = 1 << 0, LZC_SEND_FLAG_LARGE_BLOCK = 1 << 1, LZC_SEND_FLAG_COMPRESS = 1 << 2, LZC_SEND_FLAG_RAW = 1 << 3, LZC_SEND_FLAG_SAVED = 1 << 4, }; -int lzc_send(const char *, const char *, int, enum lzc_send_flags); -int lzc_send_resume(const char *, const char *, int, +_LIBZFS_CORE_H int lzc_send(const char *, const char *, int, + enum lzc_send_flags); +_LIBZFS_CORE_H int lzc_send_resume(const char *, const char *, int, enum lzc_send_flags, uint64_t, uint64_t); -int lzc_send_space(const char *, const char *, enum lzc_send_flags, uint64_t *); +_LIBZFS_CORE_H int lzc_send_space(const char *, const char *, + enum lzc_send_flags, uint64_t *); struct dmu_replay_record; -int lzc_send_redacted(const char *, const char *, int, enum lzc_send_flags, - const char *); -int lzc_send_resume_redacted(const char *, const char *, int, +_LIBZFS_CORE_H int lzc_send_redacted(const char *, const char *, int, + enum lzc_send_flags, const char *); +_LIBZFS_CORE_H int lzc_send_resume_redacted(const char *, const char *, int, enum lzc_send_flags, uint64_t, uint64_t, const char *); -int lzc_receive(const char *, nvlist_t *, const char *, boolean_t, boolean_t, - int); -int lzc_receive_resumable(const char *, nvlist_t *, const char *, boolean_t, - boolean_t, int); -int lzc_receive_with_header(const char *, nvlist_t *, const char *, boolean_t, - boolean_t, boolean_t, int, const struct dmu_replay_record *); -int lzc_receive_one(const char *, nvlist_t *, const char *, boolean_t, - boolean_t, boolean_t, int, const struct dmu_replay_record *, int, +_LIBZFS_CORE_H int lzc_receive(const char *, nvlist_t *, const char *, + boolean_t, boolean_t, int); +_LIBZFS_CORE_H int lzc_receive_resumable(const char *, nvlist_t *, const char *, + boolean_t, boolean_t, int); +_LIBZFS_CORE_H int lzc_receive_with_header(const char *, nvlist_t *, + const char *, boolean_t, boolean_t, boolean_t, int, + const struct dmu_replay_record *); +_LIBZFS_CORE_H int lzc_receive_one(const char *, nvlist_t *, const char *, + boolean_t, boolean_t, boolean_t, int, const struct dmu_replay_record *, int, uint64_t *, uint64_t *, uint64_t *, nvlist_t **); -int lzc_receive_with_cmdprops(const char *, nvlist_t *, nvlist_t *, - uint8_t *, uint_t, const char *, boolean_t, boolean_t, boolean_t, int, - const struct dmu_replay_record *, int, uint64_t *, uint64_t *, - uint64_t *, nvlist_t **); -int lzc_send_space(const char *, const char *, enum lzc_send_flags, uint64_t *); -int lzc_send_space_resume_redacted(const char *, const char *, +_LIBZFS_CORE_H int lzc_receive_with_cmdprops(const char *, nvlist_t *, + nvlist_t *, uint8_t *, uint_t, const char *, boolean_t, boolean_t, + boolean_t, int, const struct dmu_replay_record *, int, uint64_t *, + uint64_t *, uint64_t *, nvlist_t **); +_LIBZFS_CORE_H int lzc_send_space(const char *, const char *, + enum lzc_send_flags, uint64_t *); +_LIBZFS_CORE_H int lzc_send_space_resume_redacted(const char *, const char *, enum lzc_send_flags, uint64_t, uint64_t, uint64_t, const char *, int, uint64_t *); -uint64_t lzc_send_progress(int); +_LIBZFS_CORE_H uint64_t lzc_send_progress(int); -boolean_t lzc_exists(const char *); +_LIBZFS_CORE_H boolean_t lzc_exists(const char *); -int lzc_rollback(const char *, char *, int); -int lzc_rollback_to(const char *, const char *); +_LIBZFS_CORE_H int lzc_rollback(const char *, char *, int); +_LIBZFS_CORE_H int lzc_rollback_to(const char *, const char *); -int lzc_rename(const char *, const char *); -int lzc_destroy(const char *); +_LIBZFS_CORE_H int lzc_rename(const char *, const char *); +_LIBZFS_CORE_H int lzc_destroy(const char *); -int lzc_channel_program(const char *, const char *, uint64_t, - uint64_t, nvlist_t *, nvlist_t **); -int lzc_channel_program_nosync(const char *, const char *, uint64_t, +_LIBZFS_CORE_H int lzc_channel_program(const char *, const char *, uint64_t, uint64_t, nvlist_t *, nvlist_t **); +_LIBZFS_CORE_H int lzc_channel_program_nosync(const char *, const char *, + uint64_t, uint64_t, nvlist_t *, nvlist_t **); -int lzc_sync(const char *, nvlist_t *, nvlist_t **); -int lzc_reopen(const char *, boolean_t); +_LIBZFS_CORE_H int lzc_sync(const char *, nvlist_t *, nvlist_t **); +_LIBZFS_CORE_H int lzc_reopen(const char *, boolean_t); -int lzc_pool_checkpoint(const char *); -int lzc_pool_checkpoint_discard(const char *); +_LIBZFS_CORE_H int lzc_pool_checkpoint(const char *); +_LIBZFS_CORE_H int lzc_pool_checkpoint_discard(const char *); -int lzc_wait(const char *, zpool_wait_activity_t, boolean_t *); -int lzc_wait_tag(const char *, zpool_wait_activity_t, uint64_t, boolean_t *); -int lzc_wait_fs(const char *, zfs_wait_activity_t, boolean_t *); +_LIBZFS_CORE_H int lzc_wait(const char *, zpool_wait_activity_t, boolean_t *); +_LIBZFS_CORE_H int lzc_wait_tag(const char *, zpool_wait_activity_t, uint64_t, + boolean_t *); +_LIBZFS_CORE_H int lzc_wait_fs(const char *, zfs_wait_activity_t, boolean_t *); -int lzc_set_bootenv(const char *, const nvlist_t *); -int lzc_get_bootenv(const char *, nvlist_t **); +_LIBZFS_CORE_H int lzc_set_bootenv(const char *, const nvlist_t *); +_LIBZFS_CORE_H int lzc_get_bootenv(const char *, nvlist_t **); #ifdef __cplusplus } #endif #endif /* _LIBZFS_CORE_H */ diff --git a/include/libzfsbootenv.h b/include/libzfsbootenv.h index b078b605db7f..cbc8751dc51b 100644 --- a/include/libzfsbootenv.h +++ b/include/libzfsbootenv.h @@ -1,41 +1,43 @@ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2020 Toomas Soome */ #ifndef _LIBZFSBOOTENV_H -#define _LIBZFSBOOTENV_H +#define _LIBZFSBOOTENV_H extern __attribute__((visibility("default"))) #ifdef __cplusplus extern "C" { #endif typedef enum lzbe_flags { lzbe_add, /* add data to existing nvlist */ lzbe_replace /* replace current nvlist */ } lzbe_flags_t; -extern int lzbe_nvlist_get(const char *, const char *, void **); -extern int lzbe_nvlist_set(const char *, const char *, void *); -extern void lzbe_nvlist_free(void *); -extern int lzbe_add_pair(void *, const char *, const char *, void *, size_t); -extern int lzbe_remove_pair(void *, const char *); -extern int lzbe_set_boot_device(const char *, lzbe_flags_t, const char *); -extern int lzbe_get_boot_device(const char *, char **); -extern int lzbe_bootenv_print(const char *, const char *, FILE *); +_LIBZFSBOOTENV_H int lzbe_nvlist_get(const char *, const char *, void **); +_LIBZFSBOOTENV_H int lzbe_nvlist_set(const char *, const char *, void *); +_LIBZFSBOOTENV_H void lzbe_nvlist_free(void *); +_LIBZFSBOOTENV_H int lzbe_add_pair(void *, const char *, const char *, void *, + size_t); +_LIBZFSBOOTENV_H int lzbe_remove_pair(void *, const char *); +_LIBZFSBOOTENV_H int lzbe_set_boot_device(const char *, lzbe_flags_t, + const char *); +_LIBZFSBOOTENV_H int lzbe_get_boot_device(const char *, char **); +_LIBZFSBOOTENV_H int lzbe_bootenv_print(const char *, const char *, FILE *); #ifdef __cplusplus } #endif #endif /* _LIBZFSBOOTENV_H */ diff --git a/include/sys/avl.h b/include/sys/avl.h index ed3c6f86a568..20e88f2a6b06 100644 --- a/include/sys/avl.h +++ b/include/sys/avl.h @@ -1,325 +1,325 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* * Copyright (c) 2014 by Delphix. All rights reserved. */ #ifndef _AVL_H -#define _AVL_H +#define _AVL_H extern __attribute__((visibility("default"))) /* * This is a private header file. Applications should not directly include * this file. */ #ifdef __cplusplus extern "C" { #endif #include #include /* * This is a generic implementation of AVL trees for use in the Solaris kernel. * The interfaces provide an efficient way of implementing an ordered set of * data structures. * * AVL trees provide an alternative to using an ordered linked list. Using AVL * trees will usually be faster, however they requires more storage. An ordered * linked list in general requires 2 pointers in each data structure. The * AVL tree implementation uses 3 pointers. The following chart gives the * approximate performance of operations with the different approaches: * * Operation Link List AVL tree * --------- -------- -------- * lookup O(n) O(log(n)) * * insert 1 node constant constant * * delete 1 node constant between constant and O(log(n)) * * delete all nodes O(n) O(n) * * visit the next * or prev node constant between constant and O(log(n)) * * * The data structure nodes are anchored at an "avl_tree_t" (the equivalent * of a list header) and the individual nodes will have a field of * type "avl_node_t" (corresponding to list pointers). * * The type "avl_index_t" is used to indicate a position in the list for * certain calls. * * The usage scenario is generally: * * 1. Create the list/tree with: avl_create() * * followed by any mixture of: * * 2a. Insert nodes with: avl_add(), or avl_find() and avl_insert() * * 2b. Visited elements with: * avl_first() - returns the lowest valued node * avl_last() - returns the highest valued node * AVL_NEXT() - given a node go to next higher one * AVL_PREV() - given a node go to previous lower one * * 2c. Find the node with the closest value either less than or greater * than a given value with avl_nearest(). * * 2d. Remove individual nodes from the list/tree with avl_remove(). * * and finally when the list is being destroyed * * 3. Use avl_destroy_nodes() to quickly process/free up any remaining nodes. * Note that once you use avl_destroy_nodes(), you can no longer * use any routine except avl_destroy_nodes() and avl_destroy(). * * 4. Use avl_destroy() to destroy the AVL tree itself. * * Any locking for multiple thread access is up to the user to provide, just * as is needed for any linked list implementation. */ /* * AVL comparator helpers */ #define TREE_ISIGN(a) (((a) > 0) - ((a) < 0)) #define TREE_CMP(a, b) (((a) > (b)) - ((a) < (b))) #define TREE_PCMP(a, b) \ (((uintptr_t)(a) > (uintptr_t)(b)) - ((uintptr_t)(a) < (uintptr_t)(b))) /* * Type used for the root of the AVL tree. */ typedef struct avl_tree avl_tree_t; /* * The data nodes in the AVL tree must have a field of this type. */ typedef struct avl_node avl_node_t; /* * An opaque type used to locate a position in the tree where a node * would be inserted. */ typedef uintptr_t avl_index_t; /* * Direction constants used for avl_nearest(). */ #define AVL_BEFORE (0) #define AVL_AFTER (1) /* * Prototypes * * Where not otherwise mentioned, "void *" arguments are a pointer to the * user data structure which must contain a field of type avl_node_t. * * Also assume the user data structures looks like: * struct my_type { * ... * avl_node_t my_link; * ... * }; */ /* * Initialize an AVL tree. Arguments are: * * tree - the tree to be initialized * compar - function to compare two nodes, it must return exactly: -1, 0, or +1 * -1 for <, 0 for ==, and +1 for > * size - the value of sizeof(struct my_type) * offset - the value of OFFSETOF(struct my_type, my_link) */ -extern void avl_create(avl_tree_t *tree, +_AVL_H void avl_create(avl_tree_t *tree, int (*compar) (const void *, const void *), size_t size, size_t offset); /* * Find a node with a matching value in the tree. Returns the matching node * found. If not found, it returns NULL and then if "where" is not NULL it sets * "where" for use with avl_insert() or avl_nearest(). * * node - node that has the value being looked for * where - position for use with avl_nearest() or avl_insert(), may be NULL */ -extern void *avl_find(avl_tree_t *tree, const void *node, avl_index_t *where); +_AVL_H void *avl_find(avl_tree_t *tree, const void *node, avl_index_t *where); /* * Insert a node into the tree. * * node - the node to insert * where - position as returned from avl_find() */ -extern void avl_insert(avl_tree_t *tree, void *node, avl_index_t where); +_AVL_H void avl_insert(avl_tree_t *tree, void *node, avl_index_t where); /* * Insert "new_data" in "tree" in the given "direction" either after * or before the data "here". * * This might be useful for avl clients caching recently accessed * data to avoid doing avl_find() again for insertion. * * new_data - new data to insert * here - existing node in "tree" * direction - either AVL_AFTER or AVL_BEFORE the data "here". */ -extern void avl_insert_here(avl_tree_t *tree, void *new_data, void *here, +_AVL_H void avl_insert_here(avl_tree_t *tree, void *new_data, void *here, int direction); /* * Return the first or last valued node in the tree. Will return NULL * if the tree is empty. * */ -extern void *avl_first(avl_tree_t *tree); -extern void *avl_last(avl_tree_t *tree); +_AVL_H void *avl_first(avl_tree_t *tree); +_AVL_H void *avl_last(avl_tree_t *tree); /* * Return the next or previous valued node in the tree. * AVL_NEXT() will return NULL if at the last node. * AVL_PREV() will return NULL if at the first node. * * node - the node from which the next or previous node is found */ #define AVL_NEXT(tree, node) avl_walk(tree, node, AVL_AFTER) #define AVL_PREV(tree, node) avl_walk(tree, node, AVL_BEFORE) /* * Find the node with the nearest value either greater or less than * the value from a previous avl_find(). Returns the node or NULL if * there isn't a matching one. * * where - position as returned from avl_find() * direction - either AVL_BEFORE or AVL_AFTER * * EXAMPLE get the greatest node that is less than a given value: * * avl_tree_t *tree; * struct my_data look_for_value = {....}; * struct my_data *node; * struct my_data *less; * avl_index_t where; * * node = avl_find(tree, &look_for_value, &where); * if (node != NULL) * less = AVL_PREV(tree, node); * else * less = avl_nearest(tree, where, AVL_BEFORE); */ -extern void *avl_nearest(avl_tree_t *tree, avl_index_t where, int direction); +_AVL_H void *avl_nearest(avl_tree_t *tree, avl_index_t where, int direction); /* * Add a single node to the tree. * The node must not be in the tree, and it must not * compare equal to any other node already in the tree. * * node - the node to add */ -extern void avl_add(avl_tree_t *tree, void *node); +_AVL_H void avl_add(avl_tree_t *tree, void *node); /* * Remove a single node from the tree. The node must be in the tree. * * node - the node to remove */ -extern void avl_remove(avl_tree_t *tree, void *node); +_AVL_H void avl_remove(avl_tree_t *tree, void *node); /* * Reinsert a node only if its order has changed relative to its nearest * neighbors. To optimize performance avl_update_lt() checks only the previous * node and avl_update_gt() checks only the next node. Use avl_update_lt() and * avl_update_gt() only if you know the direction in which the order of the * node may change. */ -extern boolean_t avl_update(avl_tree_t *, void *); -extern boolean_t avl_update_lt(avl_tree_t *, void *); -extern boolean_t avl_update_gt(avl_tree_t *, void *); +_AVL_H boolean_t avl_update(avl_tree_t *, void *); +_AVL_H boolean_t avl_update_lt(avl_tree_t *, void *); +_AVL_H boolean_t avl_update_gt(avl_tree_t *, void *); /* * Swaps the contents of the two trees. */ -extern void avl_swap(avl_tree_t *tree1, avl_tree_t *tree2); +_AVL_H void avl_swap(avl_tree_t *tree1, avl_tree_t *tree2); /* * Return the number of nodes in the tree */ -extern ulong_t avl_numnodes(avl_tree_t *tree); +_AVL_H ulong_t avl_numnodes(avl_tree_t *tree); /* * Return B_TRUE if there are zero nodes in the tree, B_FALSE otherwise. */ -extern boolean_t avl_is_empty(avl_tree_t *tree); +_AVL_H boolean_t avl_is_empty(avl_tree_t *tree); /* * Used to destroy any remaining nodes in a tree. The cookie argument should * be initialized to NULL before the first call. Returns a node that has been * removed from the tree and may be free()'d. Returns NULL when the tree is * empty. * * Once you call avl_destroy_nodes(), you can only continuing calling it and * finally avl_destroy(). No other AVL routines will be valid. * * cookie - a "void *" used to save state between calls to avl_destroy_nodes() * * EXAMPLE: * avl_tree_t *tree; * struct my_data *node; * void *cookie; * * cookie = NULL; * while ((node = avl_destroy_nodes(tree, &cookie)) != NULL) * free(node); * avl_destroy(tree); */ -extern void *avl_destroy_nodes(avl_tree_t *tree, void **cookie); +_AVL_H void *avl_destroy_nodes(avl_tree_t *tree, void **cookie); /* * Final destroy of an AVL tree. Arguments are: * * tree - the empty tree to destroy */ -extern void avl_destroy(avl_tree_t *tree); +_AVL_H void avl_destroy(avl_tree_t *tree); #ifdef __cplusplus } #endif #endif /* _AVL_H */ diff --git a/include/sys/avl_impl.h b/include/sys/avl_impl.h index fddf76906dee..f577ecd42f7c 100644 --- a/include/sys/avl_impl.h +++ b/include/sys/avl_impl.h @@ -1,164 +1,163 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _AVL_IMPL_H -#define _AVL_IMPL_H - +#define _AVL_IMPL_H extern __attribute__((visibility("default"))) /* * This is a private header file. Applications should not directly include * this file. */ #include #ifdef __cplusplus extern "C" { #endif /* * generic AVL tree implementation for kernel use * * There are 5 pieces of information stored for each node in an AVL tree * * pointer to less than child * pointer to greater than child * a pointer to the parent of this node * an indication [0/1] of which child I am of my parent * a "balance" (-1, 0, +1) indicating which child tree is taller * * Since they only need 3 bits, the last two fields are packed into the * bottom bits of the parent pointer on 64 bit machines to save on space. */ #ifndef _LP64 struct avl_node { struct avl_node *avl_child[2]; /* left/right children */ struct avl_node *avl_parent; /* this node's parent */ unsigned short avl_child_index; /* my index in parent's avl_child[] */ short avl_balance; /* balance value: -1, 0, +1 */ }; #define AVL_XPARENT(n) ((n)->avl_parent) #define AVL_SETPARENT(n, p) ((n)->avl_parent = (p)) #define AVL_XCHILD(n) ((n)->avl_child_index) #define AVL_SETCHILD(n, c) ((n)->avl_child_index = (unsigned short)(c)) #define AVL_XBALANCE(n) ((n)->avl_balance) #define AVL_SETBALANCE(n, b) ((n)->avl_balance = (short)(b)) #else /* _LP64 */ /* * for 64 bit machines, avl_pcb contains parent pointer, balance and child_index * values packed in the following manner: * * |63 3| 2 |1 0 | * |-------------------------------------|-----------------|-------------| * | avl_parent hi order bits | avl_child_index | avl_balance | * | | | + 1 | * |-------------------------------------|-----------------|-------------| * */ struct avl_node { struct avl_node *avl_child[2]; /* left/right children nodes */ uintptr_t avl_pcb; /* parent, child_index, balance */ }; /* * macros to extract/set fields in avl_pcb * * pointer to the parent of the current node is the high order bits */ #define AVL_XPARENT(n) ((struct avl_node *)((n)->avl_pcb & ~7)) #define AVL_SETPARENT(n, p) \ ((n)->avl_pcb = (((n)->avl_pcb & 7) | (uintptr_t)(p))) /* * index of this node in its parent's avl_child[]: bit #2 */ #define AVL_XCHILD(n) (((n)->avl_pcb >> 2) & 1) #define AVL_SETCHILD(n, c) \ ((n)->avl_pcb = (uintptr_t)(((n)->avl_pcb & ~4) | ((c) << 2))) /* * balance indication for a node, lowest 2 bits. A valid balance is * -1, 0, or +1, and is encoded by adding 1 to the value to get the * unsigned values of 0, 1, 2. */ #define AVL_XBALANCE(n) ((int)(((n)->avl_pcb & 3) - 1)) #define AVL_SETBALANCE(n, b) \ ((n)->avl_pcb = (uintptr_t)((((n)->avl_pcb & ~3) | ((b) + 1)))) #endif /* _LP64 */ /* * switch between a node and data pointer for a given tree * the value of "o" is tree->avl_offset */ #define AVL_NODE2DATA(n, o) ((void *)((uintptr_t)(n) - (o))) #define AVL_DATA2NODE(d, o) ((struct avl_node *)((uintptr_t)(d) + (o))) /* * macros used to create/access an avl_index_t */ #define AVL_INDEX2NODE(x) ((avl_node_t *)((x) & ~1)) #define AVL_INDEX2CHILD(x) ((x) & 1) #define AVL_MKINDEX(n, c) ((avl_index_t)(n) | (c)) /* * The tree structure. The fields avl_root, avl_compar, and avl_offset come * first since they are needed for avl_find(). We want them to fit into * a single 64 byte cache line to make avl_find() as fast as possible. */ struct avl_tree { struct avl_node *avl_root; /* root node in tree */ int (*avl_compar)(const void *, const void *); size_t avl_offset; /* offsetof(type, avl_link_t field) */ ulong_t avl_numnodes; /* number of nodes in the tree */ size_t avl_size; /* sizeof user type struct */ }; /* * This will only by used via AVL_NEXT() or AVL_PREV() */ -extern void *avl_walk(struct avl_tree *, void *, int); +_AVL_IMPL_H void *avl_walk(struct avl_tree *, void *, int); #ifdef __cplusplus } #endif #endif /* _AVL_IMPL_H */ diff --git a/include/sys/efi_partition.h b/include/sys/efi_partition.h index fbb58013e22a..cda2c98e5d53 100644 --- a/include/sys/efi_partition.h +++ b/include/sys/efi_partition.h @@ -1,380 +1,381 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2012 Nexenta Systems, Inc. All rights reserved. */ #ifndef _SYS_EFI_PARTITION_H -#define _SYS_EFI_PARTITION_H +#define _SYS_EFI_PARTITION_H extern __attribute__((visibility("default"))) #include #ifdef __cplusplus extern "C" { #endif /* * GUID Partition Table Header */ #define EFI_MIN_LABEL_SIZE 92 #define EFI_LABEL_SIZE 512 #define LEN_EFI_PAD (EFI_LABEL_SIZE - \ ((5 * sizeof (diskaddr_t)) + \ (7 * sizeof (uint_t)) + \ (8 * sizeof (char)) + \ (1 * (sizeof (struct uuid))))) #define EFI_SIGNATURE 0x5452415020494645ULL /* EFI Guid Partition Table Header -- little endian on-disk format */ typedef struct efi_gpt { uint64_t efi_gpt_Signature; uint_t efi_gpt_Revision; uint_t efi_gpt_HeaderSize; uint_t efi_gpt_HeaderCRC32; uint_t efi_gpt_Reserved1; diskaddr_t efi_gpt_MyLBA; diskaddr_t efi_gpt_AlternateLBA; diskaddr_t efi_gpt_FirstUsableLBA; diskaddr_t efi_gpt_LastUsableLBA; struct uuid efi_gpt_DiskGUID; diskaddr_t efi_gpt_PartitionEntryLBA; uint_t efi_gpt_NumberOfPartitionEntries; uint_t efi_gpt_SizeOfPartitionEntry; uint_t efi_gpt_PartitionEntryArrayCRC32; char efi_gpt_Reserved2[LEN_EFI_PAD]; } efi_gpt_t; /* EFI Guid Partition Entry Attributes -- little endian format */ typedef struct efi_gpe_Attrs { uint32_t PartitionAttrs :16, Reserved2 :16; uint32_t Reserved1 :31, RequiredPartition :1; } efi_gpe_Attrs_t; /* * 6a96237f-1dd2-11b2-99a6-080020736631 V_UNASSIGNED (not used as such) * 6a82cb45-1dd2-11b2-99a6-080020736631 V_BOOT * 6a85cf4d-1dd2-11b2-99a6-080020736631 V_ROOT * 6a87c46f-1dd2-11b2-99a6-080020736631 V_SWAP * 6a898cc3-1dd2-11b2-99a6-080020736631 V_USR * 6a8b642b-1dd2-11b2-99a6-080020736631 V_BACKUP * 6a8d2ac7-1dd2-11b2-99a6-080020736631 V_STAND (not used) * 6a8ef2e9-1dd2-11b2-99a6-080020736631 V_VAR * 6a90ba39-1dd2-11b2-99a6-080020736631 V_HOME * 6a9283a5-1dd2-11b2-99a6-080020736631 V_ALTSCTR * 6a945a3b-1dd2-11b2-99a6-080020736631 V_CACHE */ #define EFI_UNUSED { 0x00000000, 0x0000, 0x0000, 0x00, 0x00, \ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } #define EFI_RESV1 { 0x6a96237f, 0x1dd2, 0x11b2, 0x99, 0xa6, \ { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } } #define EFI_BOOT { 0x6a82cb45, 0x1dd2, 0x11b2, 0x99, 0xa6, \ { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } } #define EFI_ROOT { 0x6a85cf4d, 0x1dd2, 0x11b2, 0x99, 0xa6, \ { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } } #define EFI_SWAP { 0x6a87c46f, 0x1dd2, 0x11b2, 0x99, 0xa6, \ { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } } #define EFI_USR { 0x6a898cc3, 0x1dd2, 0x11b2, 0x99, 0xa6, \ { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } } #define EFI_BACKUP { 0x6a8b642b, 0x1dd2, 0x11b2, 0x99, 0xa6, \ { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } } #define EFI_RESV2 { 0x6a8d2ac7, 0x1dd2, 0x11b2, 0x99, 0xa6, \ { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } } #define EFI_VAR { 0x6a8ef2e9, 0x1dd2, 0x11b2, 0x99, 0xa6, \ { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } } #define EFI_HOME { 0x6a90ba39, 0x1dd2, 0x11b2, 0x99, 0xa6, \ { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } } #define EFI_ALTSCTR { 0x6a9283a5, 0x1dd2, 0x11b2, 0x99, 0xa6, \ { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } } #define EFI_RESERVED { 0x6a945a3b, 0x1dd2, 0x11b2, 0x99, 0xa6, \ { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } } #define EFI_SYSTEM { 0xC12A7328, 0xF81F, 0x11d2, 0xBA, 0x4B, \ { 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B } } #define EFI_LEGACY_MBR { 0x024DEE41, 0x33E7, 0x11d3, 0x9D, 0x69, \ { 0x00, 0x08, 0xC7, 0x81, 0xF3, 0x9F } } #define EFI_SYMC_PUB { 0x6a9630d1, 0x1dd2, 0x11b2, 0x99, 0xa6, \ { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } } #define EFI_SYMC_CDS { 0x6a980767, 0x1dd2, 0x11b2, 0x99, 0xa6, \ { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } } #define EFI_MSFT_RESV { 0xE3C9E316, 0x0B5C, 0x4DB8, 0x81, 0x7D, \ { 0xF9, 0x2D, 0xF0, 0x02, 0x15, 0xAE } } #define EFI_DELL_BASIC { 0xebd0a0a2, 0xb9e5, 0x4433, 0x87, 0xc0, \ { 0x68, 0xb6, 0xb7, 0x26, 0x99, 0xc7 } } #define EFI_DELL_RAID { 0xa19d880f, 0x05fc, 0x4d3b, 0xa0, 0x06, \ { 0x74, 0x3f, 0x0f, 0x84, 0x91, 0x1e } } #define EFI_DELL_SWAP { 0x0657fd6d, 0xa4ab, 0x43c4, 0x84, 0xe5, \ { 0x09, 0x33, 0xc8, 0x4b, 0x4f, 0x4f } } #define EFI_DELL_LVM { 0xe6d6d379, 0xf507, 0x44c2, 0xa2, 0x3c, \ { 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28 } } #define EFI_DELL_RESV { 0x8da63339, 0x0007, 0x60c0, 0xc4, 0x36, \ { 0x08, 0x3a, 0xc8, 0x23, 0x09, 0x08 } } #define EFI_AAPL_HFS { 0x48465300, 0x0000, 0x11aa, 0xaa, 0x11, \ { 0x00, 0x30, 0x65, 0x43, 0xec, 0xac } } #define EFI_AAPL_UFS { 0x55465300, 0x0000, 0x11aa, 0xaa, 0x11, \ { 0x00, 0x30, 0x65, 0x43, 0xec, 0xac } } #define EFI_FREEBSD_BOOT { 0x83bd6b9d, 0x7f41, 0x11dc, 0xbe, 0x0b, \ { 0x00, 0x15, 0x60, 0xb8, 0x4f, 0x0f } } #define EFI_FREEBSD_SWAP { 0x516e7cb5, 0x6ecf, 0x11d6, 0x8f, 0xf8, \ { 0x00, 0x02, 0x2d, 0x09, 0x71, 0x2b } } #define EFI_FREEBSD_UFS { 0x516e7cb6, 0x6ecf, 0x11d6, 0x8f, 0xf8, \ { 0x00, 0x02, 0x2d, 0x09, 0x71, 0x2b } } #define EFI_FREEBSD_VINUM { 0x516e7cb8, 0x6ecf, 0x11d6, 0x8f, 0xf8, \ { 0x00, 0x02, 0x2d, 0x09, 0x71, 0x2b } } #define EFI_FREEBSD_ZFS { 0x516e7cba, 0x6ecf, 0x11d6, 0x8f, 0xf8, \ { 0x00, 0x02, 0x2d, 0x09, 0x71, 0x2b } } /* From Wikipedia */ #define EFI_BIOS_BOOT { 0x21686148, 0x6449, 0x6e6f, 0x74, 0x4e, \ { 0x65, 0x65, 0x64, 0x45, 0x46, 0x49 } } #define EFI_INTC_RS { 0xd3bfe2de, 0x3daf, 0x11df, 0xba, 0x40, \ { 0xe3, 0xa5, 0x56, 0xd8, 0x95, 0x93 } } #define EFI_SNE_BOOT { 0xf4019732, 0x066e, 0x4e12, 0x82, 0x73, \ { 0x34, 0x6c, 0x56, 0x41, 0x49, 0x4f } } #define EFI_LENOVO_BOOT { 0xbfbfafe7, 0xa34f, 0x448a, 0x9a, 0x5b, \ { 0x62, 0x13, 0xeb, 0x73, 0x6c, 0x22 } } #define EFI_MSFT_LDMM { 0x5808c8aa, 0x7e8f, 0x42e0, 0x85, 0xd2, \ { 0xe1, 0xe9, 0x04, 0x34, 0xcf, 0xb3 } } #define EFI_MSFT_LDMD { 0xaf9b60a0, 0x1431, 0x4f62, 0xbc, 0x68, \ { 0x33, 0x11, 0x71, 0x4a, 0x69, 0xad } } #define EFI_MSFT_RE { 0xde94bba4, 0x06d1, 0x4d40, 0xa1, 0x6a, \ { 0xbf, 0xd5, 0x01, 0x79, 0xd6, 0xac } } #define EFI_IBM_GPFS { 0x37affc90, 0xef7d, 0x4e96, 0x91, 0xc3, \ { 0x2d, 0x7a, 0xe0, 0x55, 0xb1, 0x74 } } #define EFI_MSFT_STORAGESPACES { 0xe75caf8f, 0xf680, 0x4cee, 0xaf, 0xa3, \ { 0xb0, 0x01, 0xe5, 0x6e, 0xfc, 0x2d } } #define EFI_HPQ_DATA { 0x75894c1e, 0x3aeb, 0x11d3, 0xb7, 0xc1, \ { 0x7b, 0x03, 0xa0, 0x00, 0x00, 0x00 } } #define EFI_HPQ_SVC { 0xe2a1e728, 0x32e3, 0x11d6, 0xa6, 0x82, \ { 0x7b, 0x03, 0xa0, 0x00, 0x00, 0x00 } } #define EFI_RHT_DATA { 0x0fc63daf, 0x8483, 0x4772, 0x8e, 0x79, \ { 0x3d, 0x69, 0xd8, 0x47, 0x7d, 0xe4 } } #define EFI_RHT_HOME { 0x933ac7e1, 0x2eb4, 0x4f13, 0xb8, 0x44, \ { 0x0e, 0x14, 0xe2, 0xae, 0xf9, 0x15 } } #define EFI_RHT_SRV { 0x3b8f8425, 0x20e0, 0x4f3b, 0x90, 0x7f, \ { 0x1a, 0x25, 0xa7, 0x6f, 0x98, 0xe8 } } #define EFI_RHT_DMCRYPT { 0x7ffec5c9, 0x2d00, 0x49b7, 0x89, 0x41, \ { 0x3e, 0xa1, 0x0a, 0x55, 0x86, 0xb7 } } #define EFI_RHT_LUKS { 0xca7d7ccb, 0x63ed, 0x4c53, 0x86, 0x1c, \ { 0x17, 0x42, 0x53, 0x60, 0x59, 0xcc } } #define EFI_FREEBSD_DISKLABEL { 0x516e7cb4, 0x6ecf, 0x11d6, 0x8f, 0xf8, \ { 0x00, 0x02, 0x2d, 0x09, 0x71, 0x2b } } #define EFI_AAPL_RAID { 0x52414944, 0x0000, 0x11aa, 0xaa, 0x11, \ { 0x00, 0x30, 0x65, 0x43, 0xec, 0xac } } #define EFI_AAPL_RAIDOFFLINE { 0x52414944, 0x5f4f, 0x11aa, 0xaa, 0x11, \ { 0x00, 0x30, 0x65, 0x43, 0xec, 0xac } } #define EFI_AAPL_BOOT { 0x426f6f74, 0x0000, 0x11aa, 0xaa, 0x11, \ { 0x00, 0x30, 0x65, 0x43, 0xec, 0xac } } #define EFI_AAPL_LABEL { 0x4c616265, 0x6c00, 0x11aa, 0xaa, 0x11, \ { 0x00, 0x30, 0x65, 0x43, 0xec, 0xac } } #define EFI_AAPL_TVRECOVERY { 0x5265636f, 0x7665, 0x11aa, 0xaa, 0x11, \ { 0x00, 0x30, 0x65, 0x43, 0xec, 0xac } } #define EFI_AAPL_CORESTORAGE { 0x53746f72, 0x6167, 0x11aa, 0xaa, 0x11, \ { 0x00, 0x30, 0x65, 0x43, 0xec, 0xac } } #define EFI_NETBSD_SWAP { 0x49f48d32, 0xb10e, 0x11dc, 0xb9, 0x9b, \ { 0x00, 0x19, 0xd1, 0x87, 0x96, 0x48 } } #define EFI_NETBSD_FFS { 0x49f48d5a, 0xb10e, 0x11dc, 0xb9, 0x9b, \ { 0x00, 0x19, 0xd1, 0x87, 0x96, 0x48 } } #define EFI_NETBSD_LFS { 0x49f48d82, 0xb10e, 0x11dc, 0xb9, 0x9b, \ { 0x00, 0x19, 0xd1, 0x87, 0x96, 0x48 } } #define EFI_NETBSD_RAID { 0x49f48daa, 0xb10e, 0x11dc, 0xb9, 0x9b, \ { 0x00, 0x19, 0xd1, 0x87, 0x96, 0x48 } } #define EFI_NETBSD_CAT { 0x2db519c4, 0xb10f, 0x11dc, 0xb9, 0x9b, \ { 0x00, 0x19, 0xd1, 0x87, 0x96, 0x48 } } #define EFI_NETBSD_CRYPT { 0x2db519ec, 0xb10f, 0x11dc, 0xb9, 0x9b, \ { 0x00, 0x19, 0xd1, 0x87, 0x96, 0x48 } } #define EFI_GOOG_KERN { 0xfe3a2a5d, 0x4f32, 0x41a7, 0xb7, 0x25, \ { 0xac, 0xcc, 0x32, 0x85, 0xa3, 0x09 } } #define EFI_GOOG_ROOT { 0x3cb8e202, 0x3b7e, 0x47dd, 0x8a, 0x3c, \ { 0x7f, 0xf2, 0xa1, 0x3c, 0xfc, 0xec } } #define EFI_GOOG_RESV { 0x2e0a753d, 0x9e48, 0x43b0, 0x83, 0x37, \ { 0xb1, 0x51, 0x92, 0xcb, 0x1b, 0x5e } } #define EFI_HAIKU_BFS { 0x42465331, 0x3ba3, 0x10f1, 0x80, 0x2a, \ { 0x48, 0x61, 0x69, 0x6b, 0x75, 0x21 } } #define EFI_MIDNIGHTBSD_BOOT { 0x85d5e45e, 0x237c, 0x11e1, 0xb4, 0xb3, \ { 0xe8, 0x9a, 0x8f, 0x7f, 0xc3, 0xa7 } } #define EFI_MIDNIGHTBSD_DATA { 0x85d5e45a, 0x237c, 0x11e1, 0xb4, 0xb3, \ { 0xe8, 0x9a, 0x8f, 0x7f, 0xc3, 0xa7 } } #define EFI_MIDNIGHTBSD_SWAP { 0x85d5e45b, 0x237c, 0x11e1, 0xb4, 0xb3, \ { 0xe8, 0x9a, 0x8f, 0x7f, 0xc3, 0xa7 } } #define EFI_MIDNIGHTBSD_UFS { 0x0394ef8b, 0x237e, 0x11e1, 0xb4, 0xb3, \ { 0xe8, 0x9a, 0x8f, 0x7f, 0xc3, 0xa7 } } #define EFI_MIDNIGHTBSD_VINUM { 0x85d5e45c, 0x237c, 0x11e1, 0xb4, 0xb3, \ { 0xe8, 0x9a, 0x8f, 0x7f, 0xc3, 0xa7 } } #define EFI_MIDNIGHTBSD_ZFS { 0x85d5e45d, 0x237c, 0x11e1, 0xb4, 0xb3, \ { 0xe8, 0x9a, 0x8f, 0x7f, 0xc3, 0xa7 } } #define EFI_CEPH_JOURNAL { 0x45b0969e, 0x9b03, 0x4f30, 0xb4, 0xc6, \ { 0xb4, 0xb8, 0x0c, 0xef, 0xf1, 0x06 } } #define EFI_CEPH_DMCRYPTJOURNAL { 0x45b0969e, 0x9b03, 0x4f30, 0xb4, 0xc6, \ { 0x5e, 0xc0, 0x0c, 0xef, 0xf1, 0x06 } } #define EFI_CEPH_OSD { 0x4fbd7e29, 0x9d25, 0x41b8, 0xaf, 0xd0, \ { 0x06, 0x2c, 0x0c, 0xef, 0xf0, 0x5d } } #define EFI_CEPH_DMCRYPTOSD { 0x4fbd7e29, 0x9d25, 0x41b8, 0xaf, 0xd0, \ { 0x5e, 0xc0, 0x0c, 0xef, 0xf0, 0x5d } } #define EFI_CEPH_CREATE { 0x89c57f98, 0x2fe5, 0x4dc0, 0x89, 0xc1, \ { 0xf3, 0xad, 0x0c, 0xef, 0xf2, 0xbe } } #define EFI_CEPH_DMCRYPTCREATE { 0x89c57f98, 0x2fe5, 0x4dc0, 0x89, 0xc1, \ { 0x5e, 0xc0, 0x0c, 0xef, 0xf2, 0xbe } } #define EFI_OPENBSD_DISKLABEL { 0x824cc7a0, 0x36a8, 0x11e3, 0x89, 0x0a, \ { 0x95, 0x25, 0x19, 0xad, 0x3f, 0x61 } } #define EFI_BBRY_QNX { 0xcef5a9ad, 0x73bc, 0x4601, 0x89, 0xf3, \ { 0xcd, 0xee, 0xee, 0xe3, 0x21, 0xa1 } } #define EFI_BELL_PLAN9 { 0xc91818f9, 0x8025, 0x47af, 0x89, 0xd2, \ { 0xf0, 0x30, 0xd7, 0x00, 0x0c, 0x2c } } #define EFI_VMW_KCORE { 0x9d275380, 0x40ad, 0x11db, 0xbf, 0x97, \ { 0x00, 0x0c, 0x29, 0x11, 0xd1, 0xb8 } } #define EFI_VMW_VMFS { 0xaa31e02a, 0x400f, 0x11db, 0x95, 0x90, \ { 0x00, 0x0c, 0x29, 0x11, 0xd1, 0xb8 } } #define EFI_VMW_RESV { 0x9198effc, 0x31c0, 0x11db, 0x8f, 0x78, \ { 0x00, 0x0c, 0x29, 0x11, 0xd1, 0xb8 } } /* From GPT fdisk */ #define EFI_RHT_ROOTX86 { 0x44479540, 0xf297, 0x41b2, 0x9a, 0xf7, \ { 0xd1, 0x31, 0xd5, 0xf0, 0x45, 0x8a } } #define EFI_RHT_ROOTAMD64 { 0x4f68bce3, 0xe8cd, 0x4db1, 0x96, 0xe7, \ { 0xfb, 0xca, 0xf9, 0x84, 0xb7, 0x09 } } #define EFI_RHT_ROOTARM { 0x69dad710, 0x2ce4, 0x4e3c, 0xb1, 0x6c, \ { 0x21, 0xa1, 0xd4, 0x9a, 0xbe, 0xd3 } } #define EFI_RHT_ROOTARM64 { 0xb921b045, 0x1df0, 0x41c3, 0xaf, 0x44, \ { 0x4c, 0x6f, 0x28, 0x0d, 0x3f, 0xae } } #define EFI_ACRONIS_SECUREZONE { 0x0311fc50, 0x01ca, 0x4725, 0xad, 0x77, \ { 0x9a, 0xdb, 0xb2, 0x0a, 0xce, 0x98 } } #define EFI_ONIE_BOOT { 0x7412f7d5, 0xa156, 0x4b13, 0x81, 0xdc, \ { 0x86, 0x71, 0x74, 0x92, 0x93, 0x25 } } #define EFI_ONIE_CONFIG { 0xd4e6e2cd, 0x4469, 0x46f3, 0xb5, 0xcb, \ { 0x1b, 0xff, 0x57, 0xaf, 0xc1, 0x49 } } #define EFI_IBM_PPRPBOOT { 0x9e1a2d38, 0xc612, 0x4316, 0xaa, 0x26, \ { 0x8b, 0x49, 0x52, 0x1e, 0x5a, 0x8b } } #define EFI_FREEDESKTOP_BOOT { 0xbc13c2ff, 0x59e6, 0x4262, 0xa3, 0x52, \ { 0xb2, 0x75, 0xfd, 0x6f, 0x71, 0x72 } } /* minimum # of bytes for partition table entries, per EFI spec */ #define EFI_MIN_ARRAY_SIZE (16 * 1024) #define EFI_PART_NAME_LEN 36 /* size of the "reserved" partition, in blocks */ #define EFI_MIN_RESV_SIZE (16 * 1024) /* EFI Guid Partition Entry */ typedef struct efi_gpe { struct uuid efi_gpe_PartitionTypeGUID; struct uuid efi_gpe_UniquePartitionGUID; diskaddr_t efi_gpe_StartingLBA; diskaddr_t efi_gpe_EndingLBA; efi_gpe_Attrs_t efi_gpe_Attributes; ushort_t efi_gpe_PartitionName[EFI_PART_NAME_LEN]; } efi_gpe_t; /* * passed to the useful (we hope) routines (efi_alloc_and_read and * efi_write) that take this VTOC-like struct. These routines handle * converting this struct into the EFI struct, generate UUIDs and * checksums, and perform any necessary byte-swapping to the on-disk * format. */ /* Solaris library abstraction for EFI partitions */ typedef struct dk_part { diskaddr_t p_start; /* starting LBA */ diskaddr_t p_size; /* size in blocks */ struct uuid p_guid; /* partition type GUID */ ushort_t p_tag; /* converted to part'n type GUID */ ushort_t p_flag; /* attributes */ char p_name[EFI_PART_NAME_LEN]; /* partition name */ struct uuid p_uguid; /* unique partition GUID */ uint_t p_resv[8]; /* future use - set to zero */ } dk_part_t; /* Solaris library abstraction for an EFI GPT */ #define EFI_VERSION102 0x00010002 #define EFI_VERSION100 0x00010000 #define EFI_VERSION_CURRENT EFI_VERSION100 typedef struct dk_gpt { uint_t efi_version; /* set to EFI_VERSION_CURRENT */ uint_t efi_nparts; /* number of partitions below */ uint_t efi_part_size; /* size of each partition entry */ /* efi_part_size is unused */ uint_t efi_lbasize; /* size of block in bytes */ diskaddr_t efi_last_lba; /* last block on the disk */ diskaddr_t efi_first_u_lba; /* first block after labels */ diskaddr_t efi_last_u_lba; /* last block before backup labels */ struct uuid efi_disk_uguid; /* unique disk GUID */ uint_t efi_flags; uint_t efi_reserved1; /* future use - set to zero */ diskaddr_t efi_altern_lba; /* lba of alternate GPT header */ uint_t efi_reserved[12]; /* future use - set to zero */ struct dk_part efi_parts[1]; /* array of partitions */ } dk_gpt_t; /* possible values for "efi_flags" */ #define EFI_GPT_PRIMARY_CORRUPT 0x1 /* primary label corrupt */ /* the private ioctl between libefi and the driver */ typedef struct dk_efi { diskaddr_t dki_lba; /* starting block */ len_t dki_length; /* length in bytes */ union { efi_gpt_t *_dki_data; uint64_t _dki_data_64; } dki_un; #define dki_data dki_un._dki_data #define dki_data_64 dki_un._dki_data_64 } dk_efi_t; struct partition64 { struct uuid p_type; uint_t p_partno; uint_t p_resv1; diskaddr_t p_start; diskaddr_t p_size; }; /* * Number of EFI partitions */ #if defined(__linux__) #define EFI_NUMPAR 128 /* Expected by parted-1.8.1 */ #else #define EFI_NUMPAR 9 #endif #ifndef _KERNEL -extern int efi_alloc_and_init(int, uint32_t, struct dk_gpt **); -extern int efi_alloc_and_read(int, struct dk_gpt **); -extern int efi_write(int, struct dk_gpt *); -extern int efi_rescan(int); -extern void efi_free(struct dk_gpt *); -extern int efi_type(int); -extern void efi_err_check(struct dk_gpt *); -extern int efi_use_whole_disk(int fd); +_SYS_EFI_PARTITION_H int efi_debug; +_SYS_EFI_PARTITION_H int efi_alloc_and_init(int, uint32_t, struct dk_gpt **); +_SYS_EFI_PARTITION_H int efi_alloc_and_read(int, struct dk_gpt **); +_SYS_EFI_PARTITION_H int efi_write(int, struct dk_gpt *); +_SYS_EFI_PARTITION_H int efi_rescan(int); +_SYS_EFI_PARTITION_H void efi_free(struct dk_gpt *); +_SYS_EFI_PARTITION_H int efi_type(int); +_SYS_EFI_PARTITION_H void efi_err_check(struct dk_gpt *); +_SYS_EFI_PARTITION_H int efi_use_whole_disk(int fd); #endif #ifdef __cplusplus } #endif #endif /* _SYS_EFI_PARTITION_H */ diff --git a/include/sys/nvpair.h b/include/sys/nvpair.h index b0be8bd7ada1..76d383a3c681 100644 --- a/include/sys/nvpair.h +++ b/include/sys/nvpair.h @@ -1,358 +1,407 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2018 by Delphix. All rights reserved. */ #ifndef _SYS_NVPAIR_H -#define _SYS_NVPAIR_H +#define _SYS_NVPAIR_H extern __attribute__((visibility("default"))) #include #include #include #ifdef __cplusplus extern "C" { #endif typedef enum { DATA_TYPE_DONTCARE = -1, DATA_TYPE_UNKNOWN = 0, DATA_TYPE_BOOLEAN, DATA_TYPE_BYTE, DATA_TYPE_INT16, DATA_TYPE_UINT16, DATA_TYPE_INT32, DATA_TYPE_UINT32, DATA_TYPE_INT64, DATA_TYPE_UINT64, DATA_TYPE_STRING, DATA_TYPE_BYTE_ARRAY, DATA_TYPE_INT16_ARRAY, DATA_TYPE_UINT16_ARRAY, DATA_TYPE_INT32_ARRAY, DATA_TYPE_UINT32_ARRAY, DATA_TYPE_INT64_ARRAY, DATA_TYPE_UINT64_ARRAY, DATA_TYPE_STRING_ARRAY, DATA_TYPE_HRTIME, DATA_TYPE_NVLIST, DATA_TYPE_NVLIST_ARRAY, DATA_TYPE_BOOLEAN_VALUE, DATA_TYPE_INT8, DATA_TYPE_UINT8, DATA_TYPE_BOOLEAN_ARRAY, DATA_TYPE_INT8_ARRAY, #if !defined(_KERNEL) && !defined(_STANDALONE) DATA_TYPE_UINT8_ARRAY, DATA_TYPE_DOUBLE #else DATA_TYPE_UINT8_ARRAY #endif } data_type_t; typedef struct nvpair { int32_t nvp_size; /* size of this nvpair */ int16_t nvp_name_sz; /* length of name string */ int16_t nvp_reserve; /* not used */ int32_t nvp_value_elem; /* number of elements for array types */ data_type_t nvp_type; /* type of value */ /* name string */ /* aligned ptr array for string arrays */ /* aligned array of data for value */ } nvpair_t; /* nvlist header */ typedef struct nvlist { int32_t nvl_version; uint32_t nvl_nvflag; /* persistent flags */ uint64_t nvl_priv; /* ptr to private data if not packed */ uint32_t nvl_flag; int32_t nvl_pad; /* currently not used, for alignment */ } nvlist_t; /* nvp implementation version */ #define NV_VERSION 0 /* nvlist pack encoding */ #define NV_ENCODE_NATIVE 0 #define NV_ENCODE_XDR 1 /* nvlist persistent unique name flags, stored in nvl_nvflags */ #define NV_UNIQUE_NAME 0x1 #define NV_UNIQUE_NAME_TYPE 0x2 /* nvlist lookup pairs related flags */ #define NV_FLAG_NOENTOK 0x1 /* convenience macros */ #define NV_ALIGN(x) (((ulong_t)(x) + 7ul) & ~7ul) #define NV_ALIGN4(x) (((x) + 3) & ~3) #define NVP_SIZE(nvp) ((nvp)->nvp_size) #define NVP_NAME(nvp) ((char *)(nvp) + sizeof (nvpair_t)) #define NVP_TYPE(nvp) ((nvp)->nvp_type) #define NVP_NELEM(nvp) ((nvp)->nvp_value_elem) #define NVP_VALUE(nvp) ((char *)(nvp) + NV_ALIGN(sizeof (nvpair_t) \ + (nvp)->nvp_name_sz)) #define NVL_VERSION(nvl) ((nvl)->nvl_version) #define NVL_SIZE(nvl) ((nvl)->nvl_size) #define NVL_FLAG(nvl) ((nvl)->nvl_flag) /* NV allocator framework */ typedef struct nv_alloc_ops nv_alloc_ops_t; typedef struct nv_alloc { const nv_alloc_ops_t *nva_ops; void *nva_arg; } nv_alloc_t; struct nv_alloc_ops { int (*nv_ao_init)(nv_alloc_t *, va_list); void (*nv_ao_fini)(nv_alloc_t *); void *(*nv_ao_alloc)(nv_alloc_t *, size_t); void (*nv_ao_free)(nv_alloc_t *, void *, size_t); void (*nv_ao_reset)(nv_alloc_t *); }; -extern const nv_alloc_ops_t *nv_fixed_ops; -extern nv_alloc_t *nv_alloc_nosleep; +_SYS_NVPAIR_H const nv_alloc_ops_t *nv_fixed_ops; +_SYS_NVPAIR_H nv_alloc_t *nv_alloc_nosleep; #if defined(_KERNEL) -extern nv_alloc_t *nv_alloc_sleep; -extern nv_alloc_t *nv_alloc_pushpage; +_SYS_NVPAIR_H nv_alloc_t *nv_alloc_sleep; +_SYS_NVPAIR_H nv_alloc_t *nv_alloc_pushpage; #endif -int nv_alloc_init(nv_alloc_t *, const nv_alloc_ops_t *, /* args */ ...); -void nv_alloc_reset(nv_alloc_t *); -void nv_alloc_fini(nv_alloc_t *); +_SYS_NVPAIR_H int nv_alloc_init(nv_alloc_t *, const nv_alloc_ops_t *, + /* args */ ...); +_SYS_NVPAIR_H void nv_alloc_reset(nv_alloc_t *); +_SYS_NVPAIR_H void nv_alloc_fini(nv_alloc_t *); /* list management */ -int nvlist_alloc(nvlist_t **, uint_t, int); -void nvlist_free(nvlist_t *); -int nvlist_size(nvlist_t *, size_t *, int); -int nvlist_pack(nvlist_t *, char **, size_t *, int, int); -int nvlist_unpack(char *, size_t, nvlist_t **, int); -int nvlist_dup(nvlist_t *, nvlist_t **, int); -int nvlist_merge(nvlist_t *, nvlist_t *, int); - -uint_t nvlist_nvflag(nvlist_t *); - -int nvlist_xalloc(nvlist_t **, uint_t, nv_alloc_t *); -int nvlist_xpack(nvlist_t *, char **, size_t *, int, nv_alloc_t *); -int nvlist_xunpack(char *, size_t, nvlist_t **, nv_alloc_t *); -int nvlist_xdup(nvlist_t *, nvlist_t **, nv_alloc_t *); -nv_alloc_t *nvlist_lookup_nv_alloc(nvlist_t *); - -int nvlist_add_nvpair(nvlist_t *, nvpair_t *); -int nvlist_add_boolean(nvlist_t *, const char *); -int nvlist_add_boolean_value(nvlist_t *, const char *, boolean_t); -int nvlist_add_byte(nvlist_t *, const char *, uchar_t); -int nvlist_add_int8(nvlist_t *, const char *, int8_t); -int nvlist_add_uint8(nvlist_t *, const char *, uint8_t); -int nvlist_add_int16(nvlist_t *, const char *, int16_t); -int nvlist_add_uint16(nvlist_t *, const char *, uint16_t); -int nvlist_add_int32(nvlist_t *, const char *, int32_t); -int nvlist_add_uint32(nvlist_t *, const char *, uint32_t); -int nvlist_add_int64(nvlist_t *, const char *, int64_t); -int nvlist_add_uint64(nvlist_t *, const char *, uint64_t); -int nvlist_add_string(nvlist_t *, const char *, const char *); -int nvlist_add_nvlist(nvlist_t *, const char *, nvlist_t *); -int nvlist_add_boolean_array(nvlist_t *, const char *, boolean_t *, uint_t); -int nvlist_add_byte_array(nvlist_t *, const char *, uchar_t *, uint_t); -int nvlist_add_int8_array(nvlist_t *, const char *, int8_t *, uint_t); -int nvlist_add_uint8_array(nvlist_t *, const char *, uint8_t *, uint_t); -int nvlist_add_int16_array(nvlist_t *, const char *, int16_t *, uint_t); -int nvlist_add_uint16_array(nvlist_t *, const char *, uint16_t *, uint_t); -int nvlist_add_int32_array(nvlist_t *, const char *, int32_t *, uint_t); -int nvlist_add_uint32_array(nvlist_t *, const char *, uint32_t *, uint_t); -int nvlist_add_int64_array(nvlist_t *, const char *, int64_t *, uint_t); -int nvlist_add_uint64_array(nvlist_t *, const char *, uint64_t *, uint_t); -int nvlist_add_string_array(nvlist_t *, const char *, char *const *, uint_t); -int nvlist_add_nvlist_array(nvlist_t *, const char *, nvlist_t **, uint_t); -int nvlist_add_hrtime(nvlist_t *, const char *, hrtime_t); +_SYS_NVPAIR_H int nvlist_alloc(nvlist_t **, uint_t, int); +_SYS_NVPAIR_H void nvlist_free(nvlist_t *); +_SYS_NVPAIR_H int nvlist_size(nvlist_t *, size_t *, int); +_SYS_NVPAIR_H int nvlist_pack(nvlist_t *, char **, size_t *, int, int); +_SYS_NVPAIR_H int nvlist_unpack(char *, size_t, nvlist_t **, int); +_SYS_NVPAIR_H int nvlist_dup(nvlist_t *, nvlist_t **, int); +_SYS_NVPAIR_H int nvlist_merge(nvlist_t *, nvlist_t *, int); + +_SYS_NVPAIR_H uint_t nvlist_nvflag(nvlist_t *); + +_SYS_NVPAIR_H int nvlist_xalloc(nvlist_t **, uint_t, nv_alloc_t *); +_SYS_NVPAIR_H int nvlist_xpack(nvlist_t *, char **, size_t *, int, + nv_alloc_t *); +_SYS_NVPAIR_H int nvlist_xunpack(char *, size_t, nvlist_t **, nv_alloc_t *); +_SYS_NVPAIR_H int nvlist_xdup(nvlist_t *, nvlist_t **, nv_alloc_t *); +_SYS_NVPAIR_H nv_alloc_t *nvlist_lookup_nv_alloc(nvlist_t *); + +_SYS_NVPAIR_H int nvlist_add_nvpair(nvlist_t *, nvpair_t *); +_SYS_NVPAIR_H int nvlist_add_boolean(nvlist_t *, const char *); +_SYS_NVPAIR_H int nvlist_add_boolean_value(nvlist_t *, const char *, boolean_t); +_SYS_NVPAIR_H int nvlist_add_byte(nvlist_t *, const char *, uchar_t); +_SYS_NVPAIR_H int nvlist_add_int8(nvlist_t *, const char *, int8_t); +_SYS_NVPAIR_H int nvlist_add_uint8(nvlist_t *, const char *, uint8_t); +_SYS_NVPAIR_H int nvlist_add_int16(nvlist_t *, const char *, int16_t); +_SYS_NVPAIR_H int nvlist_add_uint16(nvlist_t *, const char *, uint16_t); +_SYS_NVPAIR_H int nvlist_add_int32(nvlist_t *, const char *, int32_t); +_SYS_NVPAIR_H int nvlist_add_uint32(nvlist_t *, const char *, uint32_t); +_SYS_NVPAIR_H int nvlist_add_int64(nvlist_t *, const char *, int64_t); +_SYS_NVPAIR_H int nvlist_add_uint64(nvlist_t *, const char *, uint64_t); +_SYS_NVPAIR_H int nvlist_add_string(nvlist_t *, const char *, const char *); +_SYS_NVPAIR_H int nvlist_add_nvlist(nvlist_t *, const char *, nvlist_t *); +_SYS_NVPAIR_H int nvlist_add_boolean_array(nvlist_t *, const char *, + boolean_t *, uint_t); +_SYS_NVPAIR_H int nvlist_add_byte_array(nvlist_t *, const char *, uchar_t *, + uint_t); +_SYS_NVPAIR_H int nvlist_add_int8_array(nvlist_t *, const char *, int8_t *, + uint_t); +_SYS_NVPAIR_H int nvlist_add_uint8_array(nvlist_t *, const char *, uint8_t *, + uint_t); +_SYS_NVPAIR_H int nvlist_add_int16_array(nvlist_t *, const char *, int16_t *, + uint_t); +_SYS_NVPAIR_H int nvlist_add_uint16_array(nvlist_t *, const char *, uint16_t *, + uint_t); +_SYS_NVPAIR_H int nvlist_add_int32_array(nvlist_t *, const char *, int32_t *, + uint_t); +_SYS_NVPAIR_H int nvlist_add_uint32_array(nvlist_t *, const char *, uint32_t *, + uint_t); +_SYS_NVPAIR_H int nvlist_add_int64_array(nvlist_t *, const char *, int64_t *, + uint_t); +_SYS_NVPAIR_H int nvlist_add_uint64_array(nvlist_t *, const char *, uint64_t *, + uint_t); +_SYS_NVPAIR_H int nvlist_add_string_array(nvlist_t *, const char *, + char * const *, uint_t); +_SYS_NVPAIR_H int nvlist_add_nvlist_array(nvlist_t *, const char *, + nvlist_t **, uint_t); +_SYS_NVPAIR_H int nvlist_add_hrtime(nvlist_t *, const char *, hrtime_t); #if !defined(_KERNEL) && !defined(_STANDALONE) -int nvlist_add_double(nvlist_t *, const char *, double); +_SYS_NVPAIR_H int nvlist_add_double(nvlist_t *, const char *, double); #endif -int nvlist_remove(nvlist_t *, const char *, data_type_t); -int nvlist_remove_all(nvlist_t *, const char *); -int nvlist_remove_nvpair(nvlist_t *, nvpair_t *); - -int nvlist_lookup_boolean(nvlist_t *, const char *); -int nvlist_lookup_boolean_value(nvlist_t *, const char *, boolean_t *); -int nvlist_lookup_byte(nvlist_t *, const char *, uchar_t *); -int nvlist_lookup_int8(nvlist_t *, const char *, int8_t *); -int nvlist_lookup_uint8(nvlist_t *, const char *, uint8_t *); -int nvlist_lookup_int16(nvlist_t *, const char *, int16_t *); -int nvlist_lookup_uint16(nvlist_t *, const char *, uint16_t *); -int nvlist_lookup_int32(nvlist_t *, const char *, int32_t *); -int nvlist_lookup_uint32(nvlist_t *, const char *, uint32_t *); -int nvlist_lookup_int64(nvlist_t *, const char *, int64_t *); -int nvlist_lookup_uint64(nvlist_t *, const char *, uint64_t *); -int nvlist_lookup_string(nvlist_t *, const char *, char **); -int nvlist_lookup_nvlist(nvlist_t *, const char *, nvlist_t **); -int nvlist_lookup_boolean_array(nvlist_t *, const char *, +_SYS_NVPAIR_H int nvlist_remove(nvlist_t *, const char *, data_type_t); +_SYS_NVPAIR_H int nvlist_remove_all(nvlist_t *, const char *); +_SYS_NVPAIR_H int nvlist_remove_nvpair(nvlist_t *, nvpair_t *); + +_SYS_NVPAIR_H int nvlist_lookup_boolean(nvlist_t *, const char *); +_SYS_NVPAIR_H int nvlist_lookup_boolean_value(nvlist_t *, const char *, + boolean_t *); +_SYS_NVPAIR_H int nvlist_lookup_byte(nvlist_t *, const char *, uchar_t *); +_SYS_NVPAIR_H int nvlist_lookup_int8(nvlist_t *, const char *, int8_t *); +_SYS_NVPAIR_H int nvlist_lookup_uint8(nvlist_t *, const char *, uint8_t *); +_SYS_NVPAIR_H int nvlist_lookup_int16(nvlist_t *, const char *, int16_t *); +_SYS_NVPAIR_H int nvlist_lookup_uint16(nvlist_t *, const char *, uint16_t *); +_SYS_NVPAIR_H int nvlist_lookup_int32(nvlist_t *, const char *, int32_t *); +_SYS_NVPAIR_H int nvlist_lookup_uint32(nvlist_t *, const char *, uint32_t *); +_SYS_NVPAIR_H int nvlist_lookup_int64(nvlist_t *, const char *, int64_t *); +_SYS_NVPAIR_H int nvlist_lookup_uint64(nvlist_t *, const char *, uint64_t *); +_SYS_NVPAIR_H int nvlist_lookup_string(nvlist_t *, const char *, char **); +_SYS_NVPAIR_H int nvlist_lookup_nvlist(nvlist_t *, const char *, nvlist_t **); +_SYS_NVPAIR_H int nvlist_lookup_boolean_array(nvlist_t *, const char *, boolean_t **, uint_t *); -int nvlist_lookup_byte_array(nvlist_t *, const char *, uchar_t **, uint_t *); -int nvlist_lookup_int8_array(nvlist_t *, const char *, int8_t **, uint_t *); -int nvlist_lookup_uint8_array(nvlist_t *, const char *, uint8_t **, uint_t *); -int nvlist_lookup_int16_array(nvlist_t *, const char *, int16_t **, uint_t *); -int nvlist_lookup_uint16_array(nvlist_t *, const char *, uint16_t **, uint_t *); -int nvlist_lookup_int32_array(nvlist_t *, const char *, int32_t **, uint_t *); -int nvlist_lookup_uint32_array(nvlist_t *, const char *, uint32_t **, uint_t *); -int nvlist_lookup_int64_array(nvlist_t *, const char *, int64_t **, uint_t *); -int nvlist_lookup_uint64_array(nvlist_t *, const char *, uint64_t **, uint_t *); -int nvlist_lookup_string_array(nvlist_t *, const char *, char ***, uint_t *); -int nvlist_lookup_nvlist_array(nvlist_t *, const char *, +_SYS_NVPAIR_H int nvlist_lookup_byte_array(nvlist_t *, const char *, uchar_t **, + uint_t *); +_SYS_NVPAIR_H int nvlist_lookup_int8_array(nvlist_t *, const char *, int8_t **, + uint_t *); +_SYS_NVPAIR_H int nvlist_lookup_uint8_array(nvlist_t *, const char *, + uint8_t **, uint_t *); +_SYS_NVPAIR_H int nvlist_lookup_int16_array(nvlist_t *, const char *, + int16_t **, uint_t *); +_SYS_NVPAIR_H int nvlist_lookup_uint16_array(nvlist_t *, const char *, + uint16_t **, uint_t *); +_SYS_NVPAIR_H int nvlist_lookup_int32_array(nvlist_t *, const char *, + int32_t **, uint_t *); +_SYS_NVPAIR_H int nvlist_lookup_uint32_array(nvlist_t *, const char *, + uint32_t **, uint_t *); +_SYS_NVPAIR_H int nvlist_lookup_int64_array(nvlist_t *, const char *, + int64_t **, uint_t *); +_SYS_NVPAIR_H int nvlist_lookup_uint64_array(nvlist_t *, const char *, + uint64_t **, uint_t *); +_SYS_NVPAIR_H int nvlist_lookup_string_array(nvlist_t *, const char *, + char ***, uint_t *); +_SYS_NVPAIR_H int nvlist_lookup_nvlist_array(nvlist_t *, const char *, nvlist_t ***, uint_t *); -int nvlist_lookup_hrtime(nvlist_t *, const char *, hrtime_t *); -int nvlist_lookup_pairs(nvlist_t *, int, ...); +_SYS_NVPAIR_H int nvlist_lookup_hrtime(nvlist_t *, const char *, hrtime_t *); +_SYS_NVPAIR_H int nvlist_lookup_pairs(nvlist_t *, int, ...); #if !defined(_KERNEL) && !defined(_STANDALONE) -int nvlist_lookup_double(nvlist_t *, const char *, double *); +_SYS_NVPAIR_H int nvlist_lookup_double(nvlist_t *, const char *, double *); #endif -int nvlist_lookup_nvpair(nvlist_t *, const char *, nvpair_t **); -int nvlist_lookup_nvpair_embedded_index(nvlist_t *, const char *, nvpair_t **, - int *, char **); -boolean_t nvlist_exists(nvlist_t *, const char *); -boolean_t nvlist_empty(nvlist_t *); +_SYS_NVPAIR_H int nvlist_lookup_nvpair(nvlist_t *, const char *, nvpair_t **); +_SYS_NVPAIR_H int nvlist_lookup_nvpair_embedded_index(nvlist_t *, const char *, + nvpair_t **, int *, char **); +_SYS_NVPAIR_H boolean_t nvlist_exists(nvlist_t *, const char *); +_SYS_NVPAIR_H boolean_t nvlist_empty(nvlist_t *); /* processing nvpair */ -nvpair_t *nvlist_next_nvpair(nvlist_t *, nvpair_t *); -nvpair_t *nvlist_prev_nvpair(nvlist_t *, nvpair_t *); -char *nvpair_name(nvpair_t *); -data_type_t nvpair_type(nvpair_t *); -int nvpair_type_is_array(nvpair_t *); -int nvpair_value_boolean_value(nvpair_t *, boolean_t *); -int nvpair_value_byte(nvpair_t *, uchar_t *); -int nvpair_value_int8(nvpair_t *, int8_t *); -int nvpair_value_uint8(nvpair_t *, uint8_t *); -int nvpair_value_int16(nvpair_t *, int16_t *); -int nvpair_value_uint16(nvpair_t *, uint16_t *); -int nvpair_value_int32(nvpair_t *, int32_t *); -int nvpair_value_uint32(nvpair_t *, uint32_t *); -int nvpair_value_int64(nvpair_t *, int64_t *); -int nvpair_value_uint64(nvpair_t *, uint64_t *); -int nvpair_value_string(nvpair_t *, char **); -int nvpair_value_nvlist(nvpair_t *, nvlist_t **); -int nvpair_value_boolean_array(nvpair_t *, boolean_t **, uint_t *); -int nvpair_value_byte_array(nvpair_t *, uchar_t **, uint_t *); -int nvpair_value_int8_array(nvpair_t *, int8_t **, uint_t *); -int nvpair_value_uint8_array(nvpair_t *, uint8_t **, uint_t *); -int nvpair_value_int16_array(nvpair_t *, int16_t **, uint_t *); -int nvpair_value_uint16_array(nvpair_t *, uint16_t **, uint_t *); -int nvpair_value_int32_array(nvpair_t *, int32_t **, uint_t *); -int nvpair_value_uint32_array(nvpair_t *, uint32_t **, uint_t *); -int nvpair_value_int64_array(nvpair_t *, int64_t **, uint_t *); -int nvpair_value_uint64_array(nvpair_t *, uint64_t **, uint_t *); -int nvpair_value_string_array(nvpair_t *, char ***, uint_t *); -int nvpair_value_nvlist_array(nvpair_t *, nvlist_t ***, uint_t *); -int nvpair_value_hrtime(nvpair_t *, hrtime_t *); +_SYS_NVPAIR_H nvpair_t *nvlist_next_nvpair(nvlist_t *, nvpair_t *); +_SYS_NVPAIR_H nvpair_t *nvlist_prev_nvpair(nvlist_t *, nvpair_t *); +_SYS_NVPAIR_H char *nvpair_name(nvpair_t *); +_SYS_NVPAIR_H data_type_t nvpair_type(nvpair_t *); +_SYS_NVPAIR_H int nvpair_type_is_array(nvpair_t *); +_SYS_NVPAIR_H int nvpair_value_boolean_value(nvpair_t *, boolean_t *); +_SYS_NVPAIR_H int nvpair_value_byte(nvpair_t *, uchar_t *); +_SYS_NVPAIR_H int nvpair_value_int8(nvpair_t *, int8_t *); +_SYS_NVPAIR_H int nvpair_value_uint8(nvpair_t *, uint8_t *); +_SYS_NVPAIR_H int nvpair_value_int16(nvpair_t *, int16_t *); +_SYS_NVPAIR_H int nvpair_value_uint16(nvpair_t *, uint16_t *); +_SYS_NVPAIR_H int nvpair_value_int32(nvpair_t *, int32_t *); +_SYS_NVPAIR_H int nvpair_value_uint32(nvpair_t *, uint32_t *); +_SYS_NVPAIR_H int nvpair_value_int64(nvpair_t *, int64_t *); +_SYS_NVPAIR_H int nvpair_value_uint64(nvpair_t *, uint64_t *); +_SYS_NVPAIR_H int nvpair_value_string(nvpair_t *, char **); +_SYS_NVPAIR_H int nvpair_value_nvlist(nvpair_t *, nvlist_t **); +_SYS_NVPAIR_H int nvpair_value_boolean_array(nvpair_t *, boolean_t **, + uint_t *); +_SYS_NVPAIR_H int nvpair_value_byte_array(nvpair_t *, uchar_t **, uint_t *); +_SYS_NVPAIR_H int nvpair_value_int8_array(nvpair_t *, int8_t **, uint_t *); +_SYS_NVPAIR_H int nvpair_value_uint8_array(nvpair_t *, uint8_t **, uint_t *); +_SYS_NVPAIR_H int nvpair_value_int16_array(nvpair_t *, int16_t **, uint_t *); +_SYS_NVPAIR_H int nvpair_value_uint16_array(nvpair_t *, uint16_t **, uint_t *); +_SYS_NVPAIR_H int nvpair_value_int32_array(nvpair_t *, int32_t **, uint_t *); +_SYS_NVPAIR_H int nvpair_value_uint32_array(nvpair_t *, uint32_t **, uint_t *); +_SYS_NVPAIR_H int nvpair_value_int64_array(nvpair_t *, int64_t **, uint_t *); +_SYS_NVPAIR_H int nvpair_value_uint64_array(nvpair_t *, uint64_t **, uint_t *); +_SYS_NVPAIR_H int nvpair_value_string_array(nvpair_t *, char ***, uint_t *); +_SYS_NVPAIR_H int nvpair_value_nvlist_array(nvpair_t *, nvlist_t ***, uint_t *); +_SYS_NVPAIR_H int nvpair_value_hrtime(nvpair_t *, hrtime_t *); #if !defined(_KERNEL) && !defined(_STANDALONE) -int nvpair_value_double(nvpair_t *, double *); +_SYS_NVPAIR_H int nvpair_value_double(nvpair_t *, double *); #endif -nvlist_t *fnvlist_alloc(void); -void fnvlist_free(nvlist_t *); -size_t fnvlist_size(nvlist_t *); -char *fnvlist_pack(nvlist_t *, size_t *); -void fnvlist_pack_free(char *, size_t); -nvlist_t *fnvlist_unpack(char *, size_t); -nvlist_t *fnvlist_dup(nvlist_t *); -void fnvlist_merge(nvlist_t *, nvlist_t *); -size_t fnvlist_num_pairs(nvlist_t *); - -void fnvlist_add_boolean(nvlist_t *, const char *); -void fnvlist_add_boolean_value(nvlist_t *, const char *, boolean_t); -void fnvlist_add_byte(nvlist_t *, const char *, uchar_t); -void fnvlist_add_int8(nvlist_t *, const char *, int8_t); -void fnvlist_add_uint8(nvlist_t *, const char *, uint8_t); -void fnvlist_add_int16(nvlist_t *, const char *, int16_t); -void fnvlist_add_uint16(nvlist_t *, const char *, uint16_t); -void fnvlist_add_int32(nvlist_t *, const char *, int32_t); -void fnvlist_add_uint32(nvlist_t *, const char *, uint32_t); -void fnvlist_add_int64(nvlist_t *, const char *, int64_t); -void fnvlist_add_uint64(nvlist_t *, const char *, uint64_t); -void fnvlist_add_string(nvlist_t *, const char *, const char *); -void fnvlist_add_nvlist(nvlist_t *, const char *, nvlist_t *); -void fnvlist_add_nvpair(nvlist_t *, nvpair_t *); -void fnvlist_add_boolean_array(nvlist_t *, const char *, boolean_t *, uint_t); -void fnvlist_add_byte_array(nvlist_t *, const char *, uchar_t *, uint_t); -void fnvlist_add_int8_array(nvlist_t *, const char *, int8_t *, uint_t); -void fnvlist_add_uint8_array(nvlist_t *, const char *, uint8_t *, uint_t); -void fnvlist_add_int16_array(nvlist_t *, const char *, int16_t *, uint_t); -void fnvlist_add_uint16_array(nvlist_t *, const char *, uint16_t *, uint_t); -void fnvlist_add_int32_array(nvlist_t *, const char *, int32_t *, uint_t); -void fnvlist_add_uint32_array(nvlist_t *, const char *, uint32_t *, uint_t); -void fnvlist_add_int64_array(nvlist_t *, const char *, int64_t *, uint_t); -void fnvlist_add_uint64_array(nvlist_t *, const char *, uint64_t *, uint_t); -void fnvlist_add_string_array(nvlist_t *, const char *, char * const *, uint_t); -void fnvlist_add_nvlist_array(nvlist_t *, const char *, nvlist_t **, uint_t); - -void fnvlist_remove(nvlist_t *, const char *); -void fnvlist_remove_nvpair(nvlist_t *, nvpair_t *); - -nvpair_t *fnvlist_lookup_nvpair(nvlist_t *, const char *); -boolean_t fnvlist_lookup_boolean(nvlist_t *, const char *); -boolean_t fnvlist_lookup_boolean_value(nvlist_t *, const char *); -uchar_t fnvlist_lookup_byte(nvlist_t *, const char *); -int8_t fnvlist_lookup_int8(nvlist_t *, const char *); -int16_t fnvlist_lookup_int16(nvlist_t *, const char *); -int32_t fnvlist_lookup_int32(nvlist_t *, const char *); -int64_t fnvlist_lookup_int64(nvlist_t *, const char *); -uint8_t fnvlist_lookup_uint8(nvlist_t *, const char *); -uint16_t fnvlist_lookup_uint16(nvlist_t *, const char *); -uint32_t fnvlist_lookup_uint32(nvlist_t *, const char *); -uint64_t fnvlist_lookup_uint64(nvlist_t *, const char *); -char *fnvlist_lookup_string(nvlist_t *, const char *); -nvlist_t *fnvlist_lookup_nvlist(nvlist_t *, const char *); -boolean_t *fnvlist_lookup_boolean_array(nvlist_t *, const char *, uint_t *); -uchar_t *fnvlist_lookup_byte_array(nvlist_t *, const char *, uint_t *); -int8_t *fnvlist_lookup_int8_array(nvlist_t *, const char *, uint_t *); -uint8_t *fnvlist_lookup_uint8_array(nvlist_t *, const char *, uint_t *); -int16_t *fnvlist_lookup_int16_array(nvlist_t *, const char *, uint_t *); -uint16_t *fnvlist_lookup_uint16_array(nvlist_t *, const char *, uint_t *); -int32_t *fnvlist_lookup_int32_array(nvlist_t *, const char *, uint_t *); -uint32_t *fnvlist_lookup_uint32_array(nvlist_t *, const char *, uint_t *); -int64_t *fnvlist_lookup_int64_array(nvlist_t *, const char *, uint_t *); -uint64_t *fnvlist_lookup_uint64_array(nvlist_t *, const char *, uint_t *); - -boolean_t fnvpair_value_boolean_value(nvpair_t *nvp); -uchar_t fnvpair_value_byte(nvpair_t *nvp); -int8_t fnvpair_value_int8(nvpair_t *nvp); -int16_t fnvpair_value_int16(nvpair_t *nvp); -int32_t fnvpair_value_int32(nvpair_t *nvp); -int64_t fnvpair_value_int64(nvpair_t *nvp); -uint8_t fnvpair_value_uint8(nvpair_t *nvp); -uint16_t fnvpair_value_uint16(nvpair_t *nvp); -uint32_t fnvpair_value_uint32(nvpair_t *nvp); -uint64_t fnvpair_value_uint64(nvpair_t *nvp); -char *fnvpair_value_string(nvpair_t *nvp); -nvlist_t *fnvpair_value_nvlist(nvpair_t *nvp); +_SYS_NVPAIR_H nvlist_t *fnvlist_alloc(void); +_SYS_NVPAIR_H void fnvlist_free(nvlist_t *); +_SYS_NVPAIR_H size_t fnvlist_size(nvlist_t *); +_SYS_NVPAIR_H char *fnvlist_pack(nvlist_t *, size_t *); +_SYS_NVPAIR_H void fnvlist_pack_free(char *, size_t); +_SYS_NVPAIR_H nvlist_t *fnvlist_unpack(char *, size_t); +_SYS_NVPAIR_H nvlist_t *fnvlist_dup(nvlist_t *); +_SYS_NVPAIR_H void fnvlist_merge(nvlist_t *, nvlist_t *); +_SYS_NVPAIR_H size_t fnvlist_num_pairs(nvlist_t *); + +_SYS_NVPAIR_H void fnvlist_add_boolean(nvlist_t *, const char *); +_SYS_NVPAIR_H void fnvlist_add_boolean_value(nvlist_t *, const char *, + boolean_t); +_SYS_NVPAIR_H void fnvlist_add_byte(nvlist_t *, const char *, uchar_t); +_SYS_NVPAIR_H void fnvlist_add_int8(nvlist_t *, const char *, int8_t); +_SYS_NVPAIR_H void fnvlist_add_uint8(nvlist_t *, const char *, uint8_t); +_SYS_NVPAIR_H void fnvlist_add_int16(nvlist_t *, const char *, int16_t); +_SYS_NVPAIR_H void fnvlist_add_uint16(nvlist_t *, const char *, uint16_t); +_SYS_NVPAIR_H void fnvlist_add_int32(nvlist_t *, const char *, int32_t); +_SYS_NVPAIR_H void fnvlist_add_uint32(nvlist_t *, const char *, uint32_t); +_SYS_NVPAIR_H void fnvlist_add_int64(nvlist_t *, const char *, int64_t); +_SYS_NVPAIR_H void fnvlist_add_uint64(nvlist_t *, const char *, uint64_t); +_SYS_NVPAIR_H void fnvlist_add_string(nvlist_t *, const char *, const char *); +_SYS_NVPAIR_H void fnvlist_add_nvlist(nvlist_t *, const char *, nvlist_t *); +_SYS_NVPAIR_H void fnvlist_add_nvpair(nvlist_t *, nvpair_t *); +_SYS_NVPAIR_H void fnvlist_add_boolean_array(nvlist_t *, const char *, + boolean_t *, uint_t); +_SYS_NVPAIR_H void fnvlist_add_byte_array(nvlist_t *, const char *, uchar_t *, + uint_t); +_SYS_NVPAIR_H void fnvlist_add_int8_array(nvlist_t *, const char *, int8_t *, + uint_t); +_SYS_NVPAIR_H void fnvlist_add_uint8_array(nvlist_t *, const char *, uint8_t *, + uint_t); +_SYS_NVPAIR_H void fnvlist_add_int16_array(nvlist_t *, const char *, int16_t *, + uint_t); +_SYS_NVPAIR_H void fnvlist_add_uint16_array(nvlist_t *, const char *, + uint16_t *, uint_t); +_SYS_NVPAIR_H void fnvlist_add_int32_array(nvlist_t *, const char *, int32_t *, + uint_t); +_SYS_NVPAIR_H void fnvlist_add_uint32_array(nvlist_t *, const char *, + uint32_t *, uint_t); +_SYS_NVPAIR_H void fnvlist_add_int64_array(nvlist_t *, const char *, int64_t *, + uint_t); +_SYS_NVPAIR_H void fnvlist_add_uint64_array(nvlist_t *, const char *, + uint64_t *, uint_t); +_SYS_NVPAIR_H void fnvlist_add_string_array(nvlist_t *, const char *, + char * const *, uint_t); +_SYS_NVPAIR_H void fnvlist_add_nvlist_array(nvlist_t *, const char *, + nvlist_t **, uint_t); + +_SYS_NVPAIR_H void fnvlist_remove(nvlist_t *, const char *); +_SYS_NVPAIR_H void fnvlist_remove_nvpair(nvlist_t *, nvpair_t *); + +_SYS_NVPAIR_H nvpair_t *fnvlist_lookup_nvpair(nvlist_t *, const char *); +_SYS_NVPAIR_H boolean_t fnvlist_lookup_boolean(nvlist_t *, const char *); +_SYS_NVPAIR_H boolean_t fnvlist_lookup_boolean_value(nvlist_t *, const char *); +_SYS_NVPAIR_H uchar_t fnvlist_lookup_byte(nvlist_t *, const char *); +_SYS_NVPAIR_H int8_t fnvlist_lookup_int8(nvlist_t *, const char *); +_SYS_NVPAIR_H int16_t fnvlist_lookup_int16(nvlist_t *, const char *); +_SYS_NVPAIR_H int32_t fnvlist_lookup_int32(nvlist_t *, const char *); +_SYS_NVPAIR_H int64_t fnvlist_lookup_int64(nvlist_t *, const char *); +_SYS_NVPAIR_H uint8_t fnvlist_lookup_uint8(nvlist_t *, const char *); +_SYS_NVPAIR_H uint16_t fnvlist_lookup_uint16(nvlist_t *, const char *); +_SYS_NVPAIR_H uint32_t fnvlist_lookup_uint32(nvlist_t *, const char *); +_SYS_NVPAIR_H uint64_t fnvlist_lookup_uint64(nvlist_t *, const char *); +_SYS_NVPAIR_H char *fnvlist_lookup_string(nvlist_t *, const char *); +_SYS_NVPAIR_H nvlist_t *fnvlist_lookup_nvlist(nvlist_t *, const char *); +_SYS_NVPAIR_H boolean_t *fnvlist_lookup_boolean_array(nvlist_t *, const char *, + uint_t *); +_SYS_NVPAIR_H uchar_t *fnvlist_lookup_byte_array(nvlist_t *, const char *, + uint_t *); +_SYS_NVPAIR_H int8_t *fnvlist_lookup_int8_array(nvlist_t *, const char *, + uint_t *); +_SYS_NVPAIR_H uint8_t *fnvlist_lookup_uint8_array(nvlist_t *, const char *, + uint_t *); +_SYS_NVPAIR_H int16_t *fnvlist_lookup_int16_array(nvlist_t *, const char *, + uint_t *); +_SYS_NVPAIR_H uint16_t *fnvlist_lookup_uint16_array(nvlist_t *, const char *, + uint_t *); +_SYS_NVPAIR_H int32_t *fnvlist_lookup_int32_array(nvlist_t *, const char *, + uint_t *); +_SYS_NVPAIR_H uint32_t *fnvlist_lookup_uint32_array(nvlist_t *, const char *, + uint_t *); +_SYS_NVPAIR_H int64_t *fnvlist_lookup_int64_array(nvlist_t *, const char *, + uint_t *); +_SYS_NVPAIR_H uint64_t *fnvlist_lookup_uint64_array(nvlist_t *, const char *, + uint_t *); + +_SYS_NVPAIR_H boolean_t fnvpair_value_boolean_value(nvpair_t *nvp); +_SYS_NVPAIR_H uchar_t fnvpair_value_byte(nvpair_t *nvp); +_SYS_NVPAIR_H int8_t fnvpair_value_int8(nvpair_t *nvp); +_SYS_NVPAIR_H int16_t fnvpair_value_int16(nvpair_t *nvp); +_SYS_NVPAIR_H int32_t fnvpair_value_int32(nvpair_t *nvp); +_SYS_NVPAIR_H int64_t fnvpair_value_int64(nvpair_t *nvp); +_SYS_NVPAIR_H uint8_t fnvpair_value_uint8(nvpair_t *nvp); +_SYS_NVPAIR_H uint16_t fnvpair_value_uint16(nvpair_t *nvp); +_SYS_NVPAIR_H uint32_t fnvpair_value_uint32(nvpair_t *nvp); +_SYS_NVPAIR_H uint64_t fnvpair_value_uint64(nvpair_t *nvp); +_SYS_NVPAIR_H char *fnvpair_value_string(nvpair_t *nvp); +_SYS_NVPAIR_H nvlist_t *fnvpair_value_nvlist(nvpair_t *nvp); #ifdef __cplusplus } #endif #endif /* _SYS_NVPAIR_H */ diff --git a/include/thread_pool.h b/include/thread_pool.h index 57266f11c5a6..43090c3c6644 100644 --- a/include/thread_pool.h +++ b/include/thread_pool.h @@ -1,72 +1,56 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _THREAD_POOL_H_ -#define _THREAD_POOL_H_ +#define _THREAD_POOL_H_ extern __attribute__((visibility("default"))) #include #include #include #ifdef __cplusplus extern "C" { #endif typedef struct tpool tpool_t; /* opaque thread pool descriptor */ -#if defined(__STDC__) - -extern tpool_t *tpool_create(uint_t min_threads, uint_t max_threads, +_THREAD_POOL_H_ tpool_t *tpool_create(uint_t min_threads, uint_t max_threads, uint_t linger, pthread_attr_t *attr); -extern int tpool_dispatch(tpool_t *tpool, +_THREAD_POOL_H_ int tpool_dispatch(tpool_t *tpool, void (*func)(void *), void *arg); -extern void tpool_destroy(tpool_t *tpool); -extern void tpool_abandon(tpool_t *tpool); -extern void tpool_wait(tpool_t *tpool); -extern void tpool_suspend(tpool_t *tpool); -extern int tpool_suspended(tpool_t *tpool); -extern void tpool_resume(tpool_t *tpool); -extern int tpool_member(tpool_t *tpool); - -#else /* Non ANSI */ - -extern tpool_t *tpool_create(); -extern int tpool_dispatch(); -extern void tpool_destroy(); -extern void tpool_abandon(); -extern void tpool_wait(); -extern void tpool_suspend(); -extern int tpool_suspended(); -extern void tpool_resume(); -extern int tpool_member(); - -#endif /* __STDC__ */ +_THREAD_POOL_H_ void tpool_destroy(tpool_t *tpool); +_THREAD_POOL_H_ void tpool_abandon(tpool_t *tpool); +_THREAD_POOL_H_ void tpool_wait(tpool_t *tpool); +_THREAD_POOL_H_ void tpool_suspend(tpool_t *tpool); +_THREAD_POOL_H_ int tpool_suspended(tpool_t *tpool); +_THREAD_POOL_H_ void tpool_resume(tpool_t *tpool); +_THREAD_POOL_H_ int tpool_member(tpool_t *tpool); #ifdef __cplusplus } #endif #endif /* _THREAD_POOL_H_ */ diff --git a/lib/libavl/Makefile.am b/lib/libavl/Makefile.am index 2e0a431c77fb..3166febd02c5 100644 --- a/lib/libavl/Makefile.am +++ b/lib/libavl/Makefile.am @@ -1,16 +1,17 @@ include $(top_srcdir)/config/Rules.am VPATH = $(top_srcdir)/module/avl/ # Includes kernel code, generate warnings for large stack frames AM_CFLAGS += $(FRAME_LARGER_THAN) +AM_CFLAGS += -fvisibility=hidden noinst_LTLIBRARIES = libavl.la KERNEL_C = \ avl.c nodist_libavl_la_SOURCES = \ $(KERNEL_C) include $(top_srcdir)/config/CppCheck.am diff --git a/lib/libefi/Makefile.am b/lib/libefi/Makefile.am index b26f7a6dcd5b..580319a31495 100644 --- a/lib/libefi/Makefile.am +++ b/lib/libefi/Makefile.am @@ -1,14 +1,15 @@ include $(top_srcdir)/config/Rules.am AM_CFLAGS += $(LIBUUID_CFLAGS) $(ZLIB_CFLAGS) +AM_CFLAGS += -fvisibility=hidden noinst_LTLIBRARIES = libefi.la USER_C = \ rdwr_efi.c libefi_la_SOURCES = $(USER_C) libefi_la_LIBADD = $(LIBUUID_LIBS) $(ZLIB_LIBS) include $(top_srcdir)/config/CppCheck.am diff --git a/lib/libefi/rdwr_efi.c b/lib/libefi/rdwr_efi.c index 39b3509a5c4b..fd243e230e7d 100644 --- a/lib/libefi/rdwr_efi.c +++ b/lib/libefi/rdwr_efi.c @@ -1,1694 +1,1660 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2012 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 2018 by Delphix. All rights reserved. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static struct uuid_to_ptag { struct uuid uuid; } conversion_array[] = { { EFI_UNUSED }, { EFI_BOOT }, { EFI_ROOT }, { EFI_SWAP }, { EFI_USR }, { EFI_BACKUP }, { EFI_UNUSED }, /* STAND is never used */ { EFI_VAR }, { EFI_HOME }, { EFI_ALTSCTR }, { EFI_UNUSED }, /* CACHE (cachefs) is never used */ { EFI_RESERVED }, { EFI_SYSTEM }, { EFI_LEGACY_MBR }, { EFI_SYMC_PUB }, { EFI_SYMC_CDS }, { EFI_MSFT_RESV }, { EFI_DELL_BASIC }, { EFI_DELL_RAID }, { EFI_DELL_SWAP }, { EFI_DELL_LVM }, { EFI_DELL_RESV }, { EFI_AAPL_HFS }, { EFI_AAPL_UFS }, { EFI_FREEBSD_BOOT }, { EFI_FREEBSD_SWAP }, { EFI_FREEBSD_UFS }, { EFI_FREEBSD_VINUM }, { EFI_FREEBSD_ZFS }, { EFI_BIOS_BOOT }, { EFI_INTC_RS }, { EFI_SNE_BOOT }, { EFI_LENOVO_BOOT }, { EFI_MSFT_LDMM }, { EFI_MSFT_LDMD }, { EFI_MSFT_RE }, { EFI_IBM_GPFS }, { EFI_MSFT_STORAGESPACES }, { EFI_HPQ_DATA }, { EFI_HPQ_SVC }, { EFI_RHT_DATA }, { EFI_RHT_HOME }, { EFI_RHT_SRV }, { EFI_RHT_DMCRYPT }, { EFI_RHT_LUKS }, { EFI_FREEBSD_DISKLABEL }, { EFI_AAPL_RAID }, { EFI_AAPL_RAIDOFFLINE }, { EFI_AAPL_BOOT }, { EFI_AAPL_LABEL }, { EFI_AAPL_TVRECOVERY }, { EFI_AAPL_CORESTORAGE }, { EFI_NETBSD_SWAP }, { EFI_NETBSD_FFS }, { EFI_NETBSD_LFS }, { EFI_NETBSD_RAID }, { EFI_NETBSD_CAT }, { EFI_NETBSD_CRYPT }, { EFI_GOOG_KERN }, { EFI_GOOG_ROOT }, { EFI_GOOG_RESV }, { EFI_HAIKU_BFS }, { EFI_MIDNIGHTBSD_BOOT }, { EFI_MIDNIGHTBSD_DATA }, { EFI_MIDNIGHTBSD_SWAP }, { EFI_MIDNIGHTBSD_UFS }, { EFI_MIDNIGHTBSD_VINUM }, { EFI_MIDNIGHTBSD_ZFS }, { EFI_CEPH_JOURNAL }, { EFI_CEPH_DMCRYPTJOURNAL }, { EFI_CEPH_OSD }, { EFI_CEPH_DMCRYPTOSD }, { EFI_CEPH_CREATE }, { EFI_CEPH_DMCRYPTCREATE }, { EFI_OPENBSD_DISKLABEL }, { EFI_BBRY_QNX }, { EFI_BELL_PLAN9 }, { EFI_VMW_KCORE }, { EFI_VMW_VMFS }, { EFI_VMW_RESV }, { EFI_RHT_ROOTX86 }, { EFI_RHT_ROOTAMD64 }, { EFI_RHT_ROOTARM }, { EFI_RHT_ROOTARM64 }, { EFI_ACRONIS_SECUREZONE }, { EFI_ONIE_BOOT }, { EFI_ONIE_CONFIG }, { EFI_IBM_PPRPBOOT }, { EFI_FREEDESKTOP_BOOT } }; -/* - * Default vtoc information for non-SVr4 partitions - */ -struct dk_map2 default_vtoc_map[NDKMAP] = { - { V_ROOT, 0 }, /* a - 0 */ - { V_SWAP, V_UNMNT }, /* b - 1 */ - { V_BACKUP, V_UNMNT }, /* c - 2 */ - { V_UNASSIGNED, 0 }, /* d - 3 */ - { V_UNASSIGNED, 0 }, /* e - 4 */ - { V_UNASSIGNED, 0 }, /* f - 5 */ - { V_USR, 0 }, /* g - 6 */ - { V_UNASSIGNED, 0 }, /* h - 7 */ - -#if defined(_SUNOS_VTOC_16) - -#if defined(i386) || defined(__amd64) || defined(__arm) || \ - defined(__powerpc) || defined(__sparc) || defined(__s390__) || \ - defined(__mips__) || defined(__rv64g__) - { V_BOOT, V_UNMNT }, /* i - 8 */ - { V_ALTSCTR, 0 }, /* j - 9 */ - -#else -#error No VTOC format defined. -#endif /* defined(i386) */ - - { V_UNASSIGNED, 0 }, /* k - 10 */ - { V_UNASSIGNED, 0 }, /* l - 11 */ - { V_UNASSIGNED, 0 }, /* m - 12 */ - { V_UNASSIGNED, 0 }, /* n - 13 */ - { V_UNASSIGNED, 0 }, /* o - 14 */ - { V_UNASSIGNED, 0 }, /* p - 15 */ -#endif /* defined(_SUNOS_VTOC_16) */ -}; - int efi_debug = 0; static int efi_read(int, struct dk_gpt *); /* * Return a 32-bit CRC of the contents of the buffer. Pre-and-post * one's conditioning will be handled by crc32() internally. */ static uint32_t efi_crc32(const unsigned char *buf, unsigned int size) { uint32_t crc = crc32(0, Z_NULL, 0); crc = crc32(crc, buf, size); return (crc); } static int read_disk_info(int fd, diskaddr_t *capacity, uint_t *lbsize) { int sector_size; unsigned long long capacity_size; if (ioctl(fd, BLKSSZGET, §or_size) < 0) return (-1); if (ioctl(fd, BLKGETSIZE64, &capacity_size) < 0) return (-1); *lbsize = (uint_t)sector_size; *capacity = (diskaddr_t)(capacity_size / sector_size); return (0); } /* * Return back the device name associated with the file descriptor. The * caller is responsible for freeing the memory associated with the * returned string. */ static char * efi_get_devname(int fd) { char path[32]; /* * The libefi API only provides the open fd and not the file path. * To handle this realpath(3) is used to resolve the block device * name from /proc/self/fd/. */ (void) snprintf(path, sizeof (path), "/proc/self/fd/%d", fd); return (realpath(path, NULL)); } static int efi_get_info(int fd, struct dk_cinfo *dki_info) { char *dev_path; int rval = 0; memset(dki_info, 0, sizeof (*dki_info)); /* * The simplest way to get the partition number under linux is * to parse it out of the /dev/ block device name. * The kernel creates this using the partition number when it * populates /dev/ so it may be trusted. The tricky bit here is * that the naming convention is based on the block device type. * So we need to take this in to account when parsing out the * partition information. Aside from the partition number we collect * some additional device info. */ dev_path = efi_get_devname(fd); if (dev_path == NULL) goto error; if ((strncmp(dev_path, "/dev/sd", 7) == 0)) { strcpy(dki_info->dki_cname, "sd"); dki_info->dki_ctype = DKC_SCSI_CCS; rval = sscanf(dev_path, "/dev/%[a-zA-Z]%hu", dki_info->dki_dname, &dki_info->dki_partition); } else if ((strncmp(dev_path, "/dev/hd", 7) == 0)) { strcpy(dki_info->dki_cname, "hd"); dki_info->dki_ctype = DKC_DIRECT; rval = sscanf(dev_path, "/dev/%[a-zA-Z]%hu", dki_info->dki_dname, &dki_info->dki_partition); } else if ((strncmp(dev_path, "/dev/md", 7) == 0)) { strcpy(dki_info->dki_cname, "pseudo"); dki_info->dki_ctype = DKC_MD; strcpy(dki_info->dki_dname, "md"); rval = sscanf(dev_path, "/dev/md%[0-9]p%hu", dki_info->dki_dname + 2, &dki_info->dki_partition); } else if ((strncmp(dev_path, "/dev/vd", 7) == 0)) { strcpy(dki_info->dki_cname, "vd"); dki_info->dki_ctype = DKC_MD; rval = sscanf(dev_path, "/dev/%[a-zA-Z]%hu", dki_info->dki_dname, &dki_info->dki_partition); } else if ((strncmp(dev_path, "/dev/xvd", 8) == 0)) { strcpy(dki_info->dki_cname, "xvd"); dki_info->dki_ctype = DKC_MD; rval = sscanf(dev_path, "/dev/%[a-zA-Z]%hu", dki_info->dki_dname, &dki_info->dki_partition); } else if ((strncmp(dev_path, "/dev/zd", 7) == 0)) { strcpy(dki_info->dki_cname, "zd"); dki_info->dki_ctype = DKC_MD; strcpy(dki_info->dki_dname, "zd"); rval = sscanf(dev_path, "/dev/zd%[0-9]p%hu", dki_info->dki_dname + 2, &dki_info->dki_partition); } else if ((strncmp(dev_path, "/dev/dm-", 8) == 0)) { strcpy(dki_info->dki_cname, "pseudo"); dki_info->dki_ctype = DKC_VBD; strcpy(dki_info->dki_dname, "dm-"); rval = sscanf(dev_path, "/dev/dm-%[0-9]p%hu", dki_info->dki_dname + 3, &dki_info->dki_partition); } else if ((strncmp(dev_path, "/dev/ram", 8) == 0)) { strcpy(dki_info->dki_cname, "pseudo"); dki_info->dki_ctype = DKC_PCMCIA_MEM; strcpy(dki_info->dki_dname, "ram"); rval = sscanf(dev_path, "/dev/ram%[0-9]p%hu", dki_info->dki_dname + 3, &dki_info->dki_partition); } else if ((strncmp(dev_path, "/dev/loop", 9) == 0)) { strcpy(dki_info->dki_cname, "pseudo"); dki_info->dki_ctype = DKC_VBD; strcpy(dki_info->dki_dname, "loop"); rval = sscanf(dev_path, "/dev/loop%[0-9]p%hu", dki_info->dki_dname + 4, &dki_info->dki_partition); } else if ((strncmp(dev_path, "/dev/nvme", 9) == 0)) { strcpy(dki_info->dki_cname, "nvme"); dki_info->dki_ctype = DKC_SCSI_CCS; strcpy(dki_info->dki_dname, "nvme"); (void) sscanf(dev_path, "/dev/nvme%[0-9]", dki_info->dki_dname + 4); size_t controller_length = strlen( dki_info->dki_dname); strcpy(dki_info->dki_dname + controller_length, "n"); rval = sscanf(dev_path, "/dev/nvme%*[0-9]n%[0-9]p%hu", dki_info->dki_dname + controller_length + 1, &dki_info->dki_partition); } else { strcpy(dki_info->dki_dname, "unknown"); strcpy(dki_info->dki_cname, "unknown"); dki_info->dki_ctype = DKC_UNKNOWN; } switch (rval) { case 0: errno = EINVAL; goto error; case 1: dki_info->dki_partition = 0; } free(dev_path); return (0); error: if (efi_debug) (void) fprintf(stderr, "DKIOCINFO errno 0x%x\n", errno); switch (errno) { case EIO: return (VT_EIO); case EINVAL: return (VT_EINVAL); default: return (VT_ERROR); } } /* * the number of blocks the EFI label takes up (round up to nearest * block) */ #define NBLOCKS(p, l) (1 + ((((p) * (int)sizeof (efi_gpe_t)) + \ ((l) - 1)) / (l))) /* number of partitions -- limited by what we can malloc */ #define MAX_PARTS ((4294967295UL - sizeof (struct dk_gpt)) / \ sizeof (struct dk_part)) int efi_alloc_and_init(int fd, uint32_t nparts, struct dk_gpt **vtoc) { diskaddr_t capacity = 0; uint_t lbsize = 0; uint_t nblocks; size_t length; struct dk_gpt *vptr; struct uuid uuid; struct dk_cinfo dki_info; if (read_disk_info(fd, &capacity, &lbsize) != 0) return (-1); if (efi_get_info(fd, &dki_info) != 0) return (-1); if (dki_info.dki_partition != 0) return (-1); if ((dki_info.dki_ctype == DKC_PCMCIA_MEM) || (dki_info.dki_ctype == DKC_VBD) || (dki_info.dki_ctype == DKC_UNKNOWN)) return (-1); nblocks = NBLOCKS(nparts, lbsize); if ((nblocks * lbsize) < EFI_MIN_ARRAY_SIZE + lbsize) { /* 16K plus one block for the GPT */ nblocks = EFI_MIN_ARRAY_SIZE / lbsize + 1; } if (nparts > MAX_PARTS) { if (efi_debug) { (void) fprintf(stderr, "the maximum number of partitions supported is %lu\n", MAX_PARTS); } return (-1); } length = sizeof (struct dk_gpt) + sizeof (struct dk_part) * (nparts - 1); vptr = calloc(1, length); if (vptr == NULL) return (-1); *vtoc = vptr; vptr->efi_version = EFI_VERSION_CURRENT; vptr->efi_lbasize = lbsize; vptr->efi_nparts = nparts; /* * add one block here for the PMBR; on disks with a 512 byte * block size and 128 or fewer partitions, efi_first_u_lba * should work out to "34" */ vptr->efi_first_u_lba = nblocks + 1; vptr->efi_last_lba = capacity - 1; vptr->efi_altern_lba = capacity -1; vptr->efi_last_u_lba = vptr->efi_last_lba - nblocks; (void) uuid_generate((uchar_t *)&uuid); UUID_LE_CONVERT(vptr->efi_disk_uguid, uuid); return (0); } /* * Read EFI - return partition number upon success. */ int efi_alloc_and_read(int fd, struct dk_gpt **vtoc) { int rval; uint32_t nparts; int length; struct dk_gpt *vptr; /* figure out the number of entries that would fit into 16K */ nparts = EFI_MIN_ARRAY_SIZE / sizeof (efi_gpe_t); length = (int) sizeof (struct dk_gpt) + (int) sizeof (struct dk_part) * (nparts - 1); vptr = calloc(1, length); if (vptr == NULL) return (VT_ERROR); vptr->efi_nparts = nparts; rval = efi_read(fd, vptr); if ((rval == VT_EINVAL) && vptr->efi_nparts > nparts) { void *tmp; length = (int) sizeof (struct dk_gpt) + (int) sizeof (struct dk_part) * (vptr->efi_nparts - 1); nparts = vptr->efi_nparts; if ((tmp = realloc(vptr, length)) == NULL) { /* cppcheck-suppress doubleFree */ free(vptr); *vtoc = NULL; return (VT_ERROR); } else { vptr = tmp; rval = efi_read(fd, vptr); } } if (rval < 0) { if (efi_debug) { (void) fprintf(stderr, "read of EFI table failed, rval=%d\n", rval); } free(vptr); *vtoc = NULL; } else { *vtoc = vptr; } return (rval); } static int efi_ioctl(int fd, int cmd, dk_efi_t *dk_ioc) { void *data = dk_ioc->dki_data; int error; diskaddr_t capacity; uint_t lbsize; /* * When the IO is not being performed in kernel as an ioctl we need * to know the sector size so we can seek to the proper byte offset. */ if (read_disk_info(fd, &capacity, &lbsize) == -1) { if (efi_debug) fprintf(stderr, "unable to read disk info: %d", errno); errno = EIO; return (-1); } switch (cmd) { case DKIOCGETEFI: if (lbsize == 0) { if (efi_debug) (void) fprintf(stderr, "DKIOCGETEFI assuming " "LBA %d bytes\n", DEV_BSIZE); lbsize = DEV_BSIZE; } error = lseek(fd, dk_ioc->dki_lba * lbsize, SEEK_SET); if (error == -1) { if (efi_debug) (void) fprintf(stderr, "DKIOCGETEFI lseek " "error: %d\n", errno); return (error); } error = read(fd, data, dk_ioc->dki_length); if (error == -1) { if (efi_debug) (void) fprintf(stderr, "DKIOCGETEFI read " "error: %d\n", errno); return (error); } if (error != dk_ioc->dki_length) { if (efi_debug) (void) fprintf(stderr, "DKIOCGETEFI short " "read of %d bytes\n", error); errno = EIO; return (-1); } error = 0; break; case DKIOCSETEFI: if (lbsize == 0) { if (efi_debug) (void) fprintf(stderr, "DKIOCSETEFI unknown " "LBA size\n"); errno = EIO; return (-1); } error = lseek(fd, dk_ioc->dki_lba * lbsize, SEEK_SET); if (error == -1) { if (efi_debug) (void) fprintf(stderr, "DKIOCSETEFI lseek " "error: %d\n", errno); return (error); } error = write(fd, data, dk_ioc->dki_length); if (error == -1) { if (efi_debug) (void) fprintf(stderr, "DKIOCSETEFI write " "error: %d\n", errno); return (error); } if (error != dk_ioc->dki_length) { if (efi_debug) (void) fprintf(stderr, "DKIOCSETEFI short " "write of %d bytes\n", error); errno = EIO; return (-1); } /* Sync the new EFI table to disk */ error = fsync(fd); if (error == -1) return (error); /* Ensure any local disk cache is also flushed */ if (ioctl(fd, BLKFLSBUF, 0) == -1) return (error); error = 0; break; default: if (efi_debug) (void) fprintf(stderr, "unsupported ioctl()\n"); errno = EIO; return (-1); } return (error); } int efi_rescan(int fd) { int retry = 10; int error; /* Notify the kernel a devices partition table has been updated */ while ((error = ioctl(fd, BLKRRPART)) != 0) { if ((--retry == 0) || (errno != EBUSY)) { (void) fprintf(stderr, "the kernel failed to rescan " "the partition table: %d\n", errno); return (-1); } usleep(50000); } return (0); } static int check_label(int fd, dk_efi_t *dk_ioc) { efi_gpt_t *efi; uint_t crc; if (efi_ioctl(fd, DKIOCGETEFI, dk_ioc) == -1) { switch (errno) { case EIO: return (VT_EIO); default: return (VT_ERROR); } } efi = dk_ioc->dki_data; if (efi->efi_gpt_Signature != LE_64(EFI_SIGNATURE)) { if (efi_debug) (void) fprintf(stderr, "Bad EFI signature: 0x%llx != 0x%llx\n", (long long)efi->efi_gpt_Signature, (long long)LE_64(EFI_SIGNATURE)); return (VT_EINVAL); } /* * check CRC of the header; the size of the header should * never be larger than one block */ crc = efi->efi_gpt_HeaderCRC32; efi->efi_gpt_HeaderCRC32 = 0; len_t headerSize = (len_t)LE_32(efi->efi_gpt_HeaderSize); if (headerSize < EFI_MIN_LABEL_SIZE || headerSize > EFI_LABEL_SIZE) { if (efi_debug) (void) fprintf(stderr, "Invalid EFI HeaderSize %llu. Assuming %d.\n", headerSize, EFI_MIN_LABEL_SIZE); } if ((headerSize > dk_ioc->dki_length) || crc != LE_32(efi_crc32((unsigned char *)efi, headerSize))) { if (efi_debug) (void) fprintf(stderr, "Bad EFI CRC: 0x%x != 0x%x\n", crc, LE_32(efi_crc32((unsigned char *)efi, headerSize))); return (VT_EINVAL); } return (0); } static int efi_read(int fd, struct dk_gpt *vtoc) { int i, j; int label_len; int rval = 0; int md_flag = 0; int vdc_flag = 0; diskaddr_t capacity = 0; uint_t lbsize = 0; struct dk_minfo disk_info; dk_efi_t dk_ioc; efi_gpt_t *efi; efi_gpe_t *efi_parts; struct dk_cinfo dki_info; uint32_t user_length; boolean_t legacy_label = B_FALSE; /* * get the partition number for this file descriptor. */ if ((rval = efi_get_info(fd, &dki_info)) != 0) return (rval); if ((strncmp(dki_info.dki_cname, "pseudo", 7) == 0) && (strncmp(dki_info.dki_dname, "md", 3) == 0)) { md_flag++; } else if ((strncmp(dki_info.dki_cname, "vdc", 4) == 0) && (strncmp(dki_info.dki_dname, "vdc", 4) == 0)) { /* * The controller and drive name "vdc" (virtual disk client) * indicates a LDoms virtual disk. */ vdc_flag++; } /* get the LBA size */ if (read_disk_info(fd, &capacity, &lbsize) == -1) { if (efi_debug) { (void) fprintf(stderr, "unable to read disk info: %d", errno); } return (VT_EINVAL); } disk_info.dki_lbsize = lbsize; disk_info.dki_capacity = capacity; if (disk_info.dki_lbsize == 0) { if (efi_debug) { (void) fprintf(stderr, "efi_read: assuming LBA 512 bytes\n"); } disk_info.dki_lbsize = DEV_BSIZE; } /* * Read the EFI GPT to figure out how many partitions we need * to deal with. */ dk_ioc.dki_lba = 1; if (NBLOCKS(vtoc->efi_nparts, disk_info.dki_lbsize) < 34) { label_len = EFI_MIN_ARRAY_SIZE + disk_info.dki_lbsize; } else { label_len = vtoc->efi_nparts * (int) sizeof (efi_gpe_t) + disk_info.dki_lbsize; if (label_len % disk_info.dki_lbsize) { /* pad to physical sector size */ label_len += disk_info.dki_lbsize; label_len &= ~(disk_info.dki_lbsize - 1); } } if (posix_memalign((void **)&dk_ioc.dki_data, disk_info.dki_lbsize, label_len)) return (VT_ERROR); memset(dk_ioc.dki_data, 0, label_len); dk_ioc.dki_length = disk_info.dki_lbsize; user_length = vtoc->efi_nparts; efi = dk_ioc.dki_data; if (md_flag) { dk_ioc.dki_length = label_len; if (efi_ioctl(fd, DKIOCGETEFI, &dk_ioc) == -1) { switch (errno) { case EIO: return (VT_EIO); default: return (VT_ERROR); } } } else if ((rval = check_label(fd, &dk_ioc)) == VT_EINVAL) { /* * No valid label here; try the alternate. Note that here * we just read GPT header and save it into dk_ioc.data, * Later, we will read GUID partition entry array if we * can get valid GPT header. */ /* * This is a workaround for legacy systems. In the past, the * last sector of SCSI disk was invisible on x86 platform. At * that time, backup label was saved on the next to the last * sector. It is possible for users to move a disk from previous * solaris system to present system. Here, we attempt to search * legacy backup EFI label first. */ dk_ioc.dki_lba = disk_info.dki_capacity - 2; dk_ioc.dki_length = disk_info.dki_lbsize; rval = check_label(fd, &dk_ioc); if (rval == VT_EINVAL) { /* * we didn't find legacy backup EFI label, try to * search backup EFI label in the last block. */ dk_ioc.dki_lba = disk_info.dki_capacity - 1; dk_ioc.dki_length = disk_info.dki_lbsize; rval = check_label(fd, &dk_ioc); if (rval == 0) { legacy_label = B_TRUE; if (efi_debug) (void) fprintf(stderr, "efi_read: primary label corrupt; " "using EFI backup label located on" " the last block\n"); } } else { if ((efi_debug) && (rval == 0)) (void) fprintf(stderr, "efi_read: primary label" " corrupt; using legacy EFI backup label " " located on the next to last block\n"); } if (rval == 0) { dk_ioc.dki_lba = LE_64(efi->efi_gpt_PartitionEntryLBA); vtoc->efi_flags |= EFI_GPT_PRIMARY_CORRUPT; vtoc->efi_nparts = LE_32(efi->efi_gpt_NumberOfPartitionEntries); /* * Partition tables are between backup GPT header * table and ParitionEntryLBA (the starting LBA of * the GUID partition entries array). Now that we * already got valid GPT header and saved it in * dk_ioc.dki_data, we try to get GUID partition * entry array here. */ /* LINTED */ dk_ioc.dki_data = (efi_gpt_t *)((char *)dk_ioc.dki_data + disk_info.dki_lbsize); if (legacy_label) dk_ioc.dki_length = disk_info.dki_capacity - 1 - dk_ioc.dki_lba; else dk_ioc.dki_length = disk_info.dki_capacity - 2 - dk_ioc.dki_lba; dk_ioc.dki_length *= disk_info.dki_lbsize; if (dk_ioc.dki_length > ((len_t)label_len - sizeof (*dk_ioc.dki_data))) { rval = VT_EINVAL; } else { /* * read GUID partition entry array */ rval = efi_ioctl(fd, DKIOCGETEFI, &dk_ioc); } } } else if (rval == 0) { dk_ioc.dki_lba = LE_64(efi->efi_gpt_PartitionEntryLBA); /* LINTED */ dk_ioc.dki_data = (efi_gpt_t *)((char *)dk_ioc.dki_data + disk_info.dki_lbsize); dk_ioc.dki_length = label_len - disk_info.dki_lbsize; rval = efi_ioctl(fd, DKIOCGETEFI, &dk_ioc); } else if (vdc_flag && rval == VT_ERROR && errno == EINVAL) { /* * When the device is a LDoms virtual disk, the DKIOCGETEFI * ioctl can fail with EINVAL if the virtual disk backend * is a ZFS volume serviced by a domain running an old version * of Solaris. This is because the DKIOCGETEFI ioctl was * initially incorrectly implemented for a ZFS volume and it * expected the GPT and GPE to be retrieved with a single ioctl. * So we try to read the GPT and the GPE using that old style * ioctl. */ dk_ioc.dki_lba = 1; dk_ioc.dki_length = label_len; rval = check_label(fd, &dk_ioc); } if (rval < 0) { free(efi); return (rval); } /* LINTED -- always longlong aligned */ efi_parts = (efi_gpe_t *)(((char *)efi) + disk_info.dki_lbsize); /* * Assemble this into a "dk_gpt" struct for easier * digestibility by applications. */ vtoc->efi_version = LE_32(efi->efi_gpt_Revision); vtoc->efi_nparts = LE_32(efi->efi_gpt_NumberOfPartitionEntries); vtoc->efi_part_size = LE_32(efi->efi_gpt_SizeOfPartitionEntry); vtoc->efi_lbasize = disk_info.dki_lbsize; vtoc->efi_last_lba = disk_info.dki_capacity - 1; vtoc->efi_first_u_lba = LE_64(efi->efi_gpt_FirstUsableLBA); vtoc->efi_last_u_lba = LE_64(efi->efi_gpt_LastUsableLBA); vtoc->efi_altern_lba = LE_64(efi->efi_gpt_AlternateLBA); UUID_LE_CONVERT(vtoc->efi_disk_uguid, efi->efi_gpt_DiskGUID); /* * If the array the user passed in is too small, set the length * to what it needs to be and return */ if (user_length < vtoc->efi_nparts) { return (VT_EINVAL); } for (i = 0; i < vtoc->efi_nparts; i++) { UUID_LE_CONVERT(vtoc->efi_parts[i].p_guid, efi_parts[i].efi_gpe_PartitionTypeGUID); for (j = 0; j < sizeof (conversion_array) / sizeof (struct uuid_to_ptag); j++) { if (bcmp(&vtoc->efi_parts[i].p_guid, &conversion_array[j].uuid, sizeof (struct uuid)) == 0) { vtoc->efi_parts[i].p_tag = j; break; } } if (vtoc->efi_parts[i].p_tag == V_UNASSIGNED) continue; vtoc->efi_parts[i].p_flag = LE_16(efi_parts[i].efi_gpe_Attributes.PartitionAttrs); vtoc->efi_parts[i].p_start = LE_64(efi_parts[i].efi_gpe_StartingLBA); vtoc->efi_parts[i].p_size = LE_64(efi_parts[i].efi_gpe_EndingLBA) - vtoc->efi_parts[i].p_start + 1; for (j = 0; j < EFI_PART_NAME_LEN; j++) { vtoc->efi_parts[i].p_name[j] = (uchar_t)LE_16( efi_parts[i].efi_gpe_PartitionName[j]); } UUID_LE_CONVERT(vtoc->efi_parts[i].p_uguid, efi_parts[i].efi_gpe_UniquePartitionGUID); } free(efi); return (dki_info.dki_partition); } /* writes a "protective" MBR */ static int write_pmbr(int fd, struct dk_gpt *vtoc) { dk_efi_t dk_ioc; struct mboot mb; uchar_t *cp; diskaddr_t size_in_lba; uchar_t *buf; int len; len = (vtoc->efi_lbasize == 0) ? sizeof (mb) : vtoc->efi_lbasize; if (posix_memalign((void **)&buf, len, len)) return (VT_ERROR); /* * Preserve any boot code and disk signature if the first block is * already an MBR. */ memset(buf, 0, len); dk_ioc.dki_lba = 0; dk_ioc.dki_length = len; /* LINTED -- always longlong aligned */ dk_ioc.dki_data = (efi_gpt_t *)buf; if (efi_ioctl(fd, DKIOCGETEFI, &dk_ioc) == -1) { (void) memcpy(&mb, buf, sizeof (mb)); bzero(&mb, sizeof (mb)); mb.signature = LE_16(MBB_MAGIC); } else { (void) memcpy(&mb, buf, sizeof (mb)); if (mb.signature != LE_16(MBB_MAGIC)) { bzero(&mb, sizeof (mb)); mb.signature = LE_16(MBB_MAGIC); } } bzero(&mb.parts, sizeof (mb.parts)); cp = (uchar_t *)&mb.parts[0]; /* bootable or not */ *cp++ = 0; /* beginning CHS; 0xffffff if not representable */ *cp++ = 0xff; *cp++ = 0xff; *cp++ = 0xff; /* OS type */ *cp++ = EFI_PMBR; /* ending CHS; 0xffffff if not representable */ *cp++ = 0xff; *cp++ = 0xff; *cp++ = 0xff; /* starting LBA: 1 (little endian format) by EFI definition */ *cp++ = 0x01; *cp++ = 0x00; *cp++ = 0x00; *cp++ = 0x00; /* ending LBA: last block on the disk (little endian format) */ size_in_lba = vtoc->efi_last_lba; if (size_in_lba < 0xffffffff) { *cp++ = (size_in_lba & 0x000000ff); *cp++ = (size_in_lba & 0x0000ff00) >> 8; *cp++ = (size_in_lba & 0x00ff0000) >> 16; *cp++ = (size_in_lba & 0xff000000) >> 24; } else { *cp++ = 0xff; *cp++ = 0xff; *cp++ = 0xff; *cp++ = 0xff; } (void) memcpy(buf, &mb, sizeof (mb)); /* LINTED -- always longlong aligned */ dk_ioc.dki_data = (efi_gpt_t *)buf; dk_ioc.dki_lba = 0; dk_ioc.dki_length = len; if (efi_ioctl(fd, DKIOCSETEFI, &dk_ioc) == -1) { free(buf); switch (errno) { case EIO: return (VT_EIO); case EINVAL: return (VT_EINVAL); default: return (VT_ERROR); } } free(buf); return (0); } /* make sure the user specified something reasonable */ static int check_input(struct dk_gpt *vtoc) { int resv_part = -1; int i, j; diskaddr_t istart, jstart, isize, jsize, endsect; /* * Sanity-check the input (make sure no partitions overlap) */ for (i = 0; i < vtoc->efi_nparts; i++) { /* It can't be unassigned and have an actual size */ if ((vtoc->efi_parts[i].p_tag == V_UNASSIGNED) && (vtoc->efi_parts[i].p_size != 0)) { if (efi_debug) { (void) fprintf(stderr, "partition %d is " "\"unassigned\" but has a size of %llu", i, vtoc->efi_parts[i].p_size); } return (VT_EINVAL); } if (vtoc->efi_parts[i].p_tag == V_UNASSIGNED) { if (uuid_is_null((uchar_t *)&vtoc->efi_parts[i].p_guid)) continue; /* we have encountered an unknown uuid */ vtoc->efi_parts[i].p_tag = 0xff; } if (vtoc->efi_parts[i].p_tag == V_RESERVED) { if (resv_part != -1) { if (efi_debug) { (void) fprintf(stderr, "found " "duplicate reserved partition " "at %d\n", i); } return (VT_EINVAL); } resv_part = i; } if ((vtoc->efi_parts[i].p_start < vtoc->efi_first_u_lba) || (vtoc->efi_parts[i].p_start > vtoc->efi_last_u_lba)) { if (efi_debug) { (void) fprintf(stderr, "Partition %d starts at %llu. ", i, vtoc->efi_parts[i].p_start); (void) fprintf(stderr, "It must be between %llu and %llu.\n", vtoc->efi_first_u_lba, vtoc->efi_last_u_lba); } return (VT_EINVAL); } if ((vtoc->efi_parts[i].p_start + vtoc->efi_parts[i].p_size < vtoc->efi_first_u_lba) || (vtoc->efi_parts[i].p_start + vtoc->efi_parts[i].p_size > vtoc->efi_last_u_lba + 1)) { if (efi_debug) { (void) fprintf(stderr, "Partition %d ends at %llu. ", i, vtoc->efi_parts[i].p_start + vtoc->efi_parts[i].p_size); (void) fprintf(stderr, "It must be between %llu and %llu.\n", vtoc->efi_first_u_lba, vtoc->efi_last_u_lba); } return (VT_EINVAL); } for (j = 0; j < vtoc->efi_nparts; j++) { isize = vtoc->efi_parts[i].p_size; jsize = vtoc->efi_parts[j].p_size; istart = vtoc->efi_parts[i].p_start; jstart = vtoc->efi_parts[j].p_start; if ((i != j) && (isize != 0) && (jsize != 0)) { endsect = jstart + jsize -1; if ((jstart <= istart) && (istart <= endsect)) { if (efi_debug) { (void) fprintf(stderr, "Partition %d overlaps " "partition %d.", i, j); } return (VT_EINVAL); } } } } /* just a warning for now */ if ((resv_part == -1) && efi_debug) { (void) fprintf(stderr, "no reserved partition found\n"); } return (0); } static int call_blkpg_ioctl(int fd, int command, diskaddr_t start, diskaddr_t size, uint_t pno) { struct blkpg_ioctl_arg ioctl_arg; struct blkpg_partition linux_part; memset(&linux_part, 0, sizeof (linux_part)); char *path = efi_get_devname(fd); if (path == NULL) { (void) fprintf(stderr, "failed to retrieve device name\n"); return (VT_EINVAL); } linux_part.start = start; linux_part.length = size; linux_part.pno = pno; snprintf(linux_part.devname, BLKPG_DEVNAMELTH - 1, "%s%u", path, pno); linux_part.devname[BLKPG_DEVNAMELTH - 1] = '\0'; free(path); ioctl_arg.op = command; ioctl_arg.flags = 0; ioctl_arg.datalen = sizeof (struct blkpg_partition); ioctl_arg.data = &linux_part; return (ioctl(fd, BLKPG, &ioctl_arg)); } /* * add all the unallocated space to the current label */ int efi_use_whole_disk(int fd) { struct dk_gpt *efi_label = NULL; int rval; int i; uint_t resv_index = 0, data_index = 0; diskaddr_t resv_start = 0, data_start = 0; diskaddr_t data_size, limit, difference; boolean_t sync_needed = B_FALSE; uint_t nblocks; rval = efi_alloc_and_read(fd, &efi_label); if (rval < 0) { if (efi_label != NULL) efi_free(efi_label); return (rval); } /* * Find the last physically non-zero partition. * This should be the reserved partition. */ for (i = 0; i < efi_label->efi_nparts; i ++) { if (resv_start < efi_label->efi_parts[i].p_start) { resv_start = efi_label->efi_parts[i].p_start; resv_index = i; } } /* * Find the last physically non-zero partition before that. * This is the data partition. */ for (i = 0; i < resv_index; i ++) { if (data_start < efi_label->efi_parts[i].p_start) { data_start = efi_label->efi_parts[i].p_start; data_index = i; } } data_size = efi_label->efi_parts[data_index].p_size; /* * See the "efi_alloc_and_init" function for more information * about where this "nblocks" value comes from. */ nblocks = efi_label->efi_first_u_lba - 1; /* * Determine if the EFI label is out of sync. We check that: * * 1. the data partition ends at the limit we set, and * 2. the reserved partition starts at the limit we set. * * If either of these conditions is not met, then we need to * resync the EFI label. * * The limit is the last usable LBA, determined by the last LBA * and the first usable LBA fields on the EFI label of the disk * (see the lines directly above). Additionally, we factor in * EFI_MIN_RESV_SIZE (per its use in "zpool_label_disk") and * P2ALIGN it to ensure the partition boundaries are aligned * (for performance reasons). The alignment should match the * alignment used by the "zpool_label_disk" function. */ limit = P2ALIGN(efi_label->efi_last_lba - nblocks - EFI_MIN_RESV_SIZE, PARTITION_END_ALIGNMENT); if (data_start + data_size != limit || resv_start != limit) sync_needed = B_TRUE; if (efi_debug && sync_needed) (void) fprintf(stderr, "efi_use_whole_disk: sync needed\n"); /* * If alter_lba is 1, we are using the backup label. * Since we can locate the backup label by disk capacity, * there must be no unallocated space. */ if ((efi_label->efi_altern_lba == 1) || (efi_label->efi_altern_lba >= efi_label->efi_last_lba && !sync_needed)) { if (efi_debug) { (void) fprintf(stderr, "efi_use_whole_disk: requested space not found\n"); } efi_free(efi_label); return (VT_ENOSPC); } /* * Verify that we've found the reserved partition by checking * that it looks the way it did when we created it in zpool_label_disk. * If we've found the incorrect partition, then we know that this * device was reformatted and no longer is solely used by ZFS. */ if ((efi_label->efi_parts[resv_index].p_size != EFI_MIN_RESV_SIZE) || (efi_label->efi_parts[resv_index].p_tag != V_RESERVED) || (resv_index != 8)) { if (efi_debug) { (void) fprintf(stderr, "efi_use_whole_disk: wholedisk not available\n"); } efi_free(efi_label); return (VT_ENOSPC); } if (data_start + data_size != resv_start) { if (efi_debug) { (void) fprintf(stderr, "efi_use_whole_disk: " "data_start (%lli) + " "data_size (%lli) != " "resv_start (%lli)\n", data_start, data_size, resv_start); } return (VT_EINVAL); } if (limit < resv_start) { if (efi_debug) { (void) fprintf(stderr, "efi_use_whole_disk: " "limit (%lli) < resv_start (%lli)\n", limit, resv_start); } return (VT_EINVAL); } difference = limit - resv_start; if (efi_debug) (void) fprintf(stderr, "efi_use_whole_disk: difference is %lli\n", difference); /* * Move the reserved partition. There is currently no data in * here except fabricated devids (which get generated via * efi_write()). So there is no need to copy data. */ efi_label->efi_parts[data_index].p_size += difference; efi_label->efi_parts[resv_index].p_start += difference; efi_label->efi_last_u_lba = efi_label->efi_last_lba - nblocks; /* * Rescanning the partition table in the kernel can result * in the device links to be removed (see comment in vdev_disk_open). * If BLKPG_RESIZE_PARTITION is available, then we can resize * the partition table online and avoid having to remove the device * links used by the pool. This provides a very deterministic * approach to resizing devices and does not require any * loops waiting for devices to reappear. */ #ifdef BLKPG_RESIZE_PARTITION /* * Delete the reserved partition since we're about to expand * the data partition and it would overlap with the reserved * partition. * NOTE: The starting index for the ioctl is 1 while for the * EFI partitions it's 0. For that reason we have to add one * whenever we make an ioctl call. */ rval = call_blkpg_ioctl(fd, BLKPG_DEL_PARTITION, 0, 0, resv_index + 1); if (rval != 0) goto out; /* * Expand the data partition */ rval = call_blkpg_ioctl(fd, BLKPG_RESIZE_PARTITION, efi_label->efi_parts[data_index].p_start * efi_label->efi_lbasize, efi_label->efi_parts[data_index].p_size * efi_label->efi_lbasize, data_index + 1); if (rval != 0) { (void) fprintf(stderr, "Unable to resize data " "partition: %d\n", rval); /* * Since we failed to resize, we need to reset the start * of the reserve partition and re-create it. */ efi_label->efi_parts[resv_index].p_start -= difference; } /* * Re-add the reserved partition. If we've expanded the data partition * then we'll move the reserve partition to the end of the data * partition. Otherwise, we'll recreate the partition in its original * location. Note that we do this as best-effort and ignore any * errors that may arise here. This will ensure that we finish writing * the EFI label. */ (void) call_blkpg_ioctl(fd, BLKPG_ADD_PARTITION, efi_label->efi_parts[resv_index].p_start * efi_label->efi_lbasize, efi_label->efi_parts[resv_index].p_size * efi_label->efi_lbasize, resv_index + 1); #endif /* * We're now ready to write the EFI label. */ if (rval == 0) { rval = efi_write(fd, efi_label); if (rval < 0 && efi_debug) { (void) fprintf(stderr, "efi_use_whole_disk:fail " "to write label, rval=%d\n", rval); } } out: efi_free(efi_label); return (rval); } /* * write EFI label and backup label */ int efi_write(int fd, struct dk_gpt *vtoc) { dk_efi_t dk_ioc; efi_gpt_t *efi; efi_gpe_t *efi_parts; int i, j; struct dk_cinfo dki_info; int rval; int md_flag = 0; int nblocks; diskaddr_t lba_backup_gpt_hdr; if ((rval = efi_get_info(fd, &dki_info)) != 0) return (rval); /* check if we are dealing with a metadevice */ if ((strncmp(dki_info.dki_cname, "pseudo", 7) == 0) && (strncmp(dki_info.dki_dname, "md", 3) == 0)) { md_flag = 1; } if (check_input(vtoc)) { /* * not valid; if it's a metadevice just pass it down * because SVM will do its own checking */ if (md_flag == 0) { return (VT_EINVAL); } } dk_ioc.dki_lba = 1; if (NBLOCKS(vtoc->efi_nparts, vtoc->efi_lbasize) < 34) { dk_ioc.dki_length = EFI_MIN_ARRAY_SIZE + vtoc->efi_lbasize; } else { dk_ioc.dki_length = NBLOCKS(vtoc->efi_nparts, vtoc->efi_lbasize) * vtoc->efi_lbasize; } /* * the number of blocks occupied by GUID partition entry array */ nblocks = dk_ioc.dki_length / vtoc->efi_lbasize - 1; /* * Backup GPT header is located on the block after GUID * partition entry array. Here, we calculate the address * for backup GPT header. */ lba_backup_gpt_hdr = vtoc->efi_last_u_lba + 1 + nblocks; if (posix_memalign((void **)&dk_ioc.dki_data, vtoc->efi_lbasize, dk_ioc.dki_length)) return (VT_ERROR); memset(dk_ioc.dki_data, 0, dk_ioc.dki_length); efi = dk_ioc.dki_data; /* stuff user's input into EFI struct */ efi->efi_gpt_Signature = LE_64(EFI_SIGNATURE); efi->efi_gpt_Revision = LE_32(vtoc->efi_version); /* 0x02000100 */ efi->efi_gpt_HeaderSize = LE_32(sizeof (struct efi_gpt) - LEN_EFI_PAD); efi->efi_gpt_Reserved1 = 0; efi->efi_gpt_MyLBA = LE_64(1ULL); efi->efi_gpt_AlternateLBA = LE_64(lba_backup_gpt_hdr); efi->efi_gpt_FirstUsableLBA = LE_64(vtoc->efi_first_u_lba); efi->efi_gpt_LastUsableLBA = LE_64(vtoc->efi_last_u_lba); efi->efi_gpt_PartitionEntryLBA = LE_64(2ULL); efi->efi_gpt_NumberOfPartitionEntries = LE_32(vtoc->efi_nparts); efi->efi_gpt_SizeOfPartitionEntry = LE_32(sizeof (struct efi_gpe)); UUID_LE_CONVERT(efi->efi_gpt_DiskGUID, vtoc->efi_disk_uguid); /* LINTED -- always longlong aligned */ efi_parts = (efi_gpe_t *)((char *)dk_ioc.dki_data + vtoc->efi_lbasize); for (i = 0; i < vtoc->efi_nparts; i++) { for (j = 0; j < sizeof (conversion_array) / sizeof (struct uuid_to_ptag); j++) { if (vtoc->efi_parts[i].p_tag == j) { UUID_LE_CONVERT( efi_parts[i].efi_gpe_PartitionTypeGUID, conversion_array[j].uuid); break; } } if (j == sizeof (conversion_array) / sizeof (struct uuid_to_ptag)) { /* * If we didn't have a matching uuid match, bail here. * Don't write a label with unknown uuid. */ if (efi_debug) { (void) fprintf(stderr, "Unknown uuid for p_tag %d\n", vtoc->efi_parts[i].p_tag); } return (VT_EINVAL); } /* Zero's should be written for empty partitions */ if (vtoc->efi_parts[i].p_tag == V_UNASSIGNED) continue; efi_parts[i].efi_gpe_StartingLBA = LE_64(vtoc->efi_parts[i].p_start); efi_parts[i].efi_gpe_EndingLBA = LE_64(vtoc->efi_parts[i].p_start + vtoc->efi_parts[i].p_size - 1); efi_parts[i].efi_gpe_Attributes.PartitionAttrs = LE_16(vtoc->efi_parts[i].p_flag); for (j = 0; j < EFI_PART_NAME_LEN; j++) { efi_parts[i].efi_gpe_PartitionName[j] = LE_16((ushort_t)vtoc->efi_parts[i].p_name[j]); } if ((vtoc->efi_parts[i].p_tag != V_UNASSIGNED) && uuid_is_null((uchar_t *)&vtoc->efi_parts[i].p_uguid)) { (void) uuid_generate((uchar_t *) &vtoc->efi_parts[i].p_uguid); } bcopy(&vtoc->efi_parts[i].p_uguid, &efi_parts[i].efi_gpe_UniquePartitionGUID, sizeof (uuid_t)); } efi->efi_gpt_PartitionEntryArrayCRC32 = LE_32(efi_crc32((unsigned char *)efi_parts, vtoc->efi_nparts * (int)sizeof (struct efi_gpe))); efi->efi_gpt_HeaderCRC32 = LE_32(efi_crc32((unsigned char *)efi, LE_32(efi->efi_gpt_HeaderSize))); if (efi_ioctl(fd, DKIOCSETEFI, &dk_ioc) == -1) { free(dk_ioc.dki_data); switch (errno) { case EIO: return (VT_EIO); case EINVAL: return (VT_EINVAL); default: return (VT_ERROR); } } /* if it's a metadevice we're done */ if (md_flag) { free(dk_ioc.dki_data); return (0); } /* write backup partition array */ dk_ioc.dki_lba = vtoc->efi_last_u_lba + 1; dk_ioc.dki_length -= vtoc->efi_lbasize; /* LINTED */ dk_ioc.dki_data = (efi_gpt_t *)((char *)dk_ioc.dki_data + vtoc->efi_lbasize); if (efi_ioctl(fd, DKIOCSETEFI, &dk_ioc) == -1) { /* * we wrote the primary label okay, so don't fail */ if (efi_debug) { (void) fprintf(stderr, "write of backup partitions to block %llu " "failed, errno %d\n", vtoc->efi_last_u_lba + 1, errno); } } /* * now swap MyLBA and AlternateLBA fields and write backup * partition table header */ dk_ioc.dki_lba = lba_backup_gpt_hdr; dk_ioc.dki_length = vtoc->efi_lbasize; /* LINTED */ dk_ioc.dki_data = (efi_gpt_t *)((char *)dk_ioc.dki_data - vtoc->efi_lbasize); efi->efi_gpt_AlternateLBA = LE_64(1ULL); efi->efi_gpt_MyLBA = LE_64(lba_backup_gpt_hdr); efi->efi_gpt_PartitionEntryLBA = LE_64(vtoc->efi_last_u_lba + 1); efi->efi_gpt_HeaderCRC32 = 0; efi->efi_gpt_HeaderCRC32 = LE_32(efi_crc32((unsigned char *)dk_ioc.dki_data, LE_32(efi->efi_gpt_HeaderSize))); if (efi_ioctl(fd, DKIOCSETEFI, &dk_ioc) == -1) { if (efi_debug) { (void) fprintf(stderr, "write of backup header to block %llu failed, " "errno %d\n", lba_backup_gpt_hdr, errno); } } /* write the PMBR */ (void) write_pmbr(fd, vtoc); free(dk_ioc.dki_data); return (0); } void efi_free(struct dk_gpt *ptr) { free(ptr); } /* * Input: File descriptor * Output: 1 if disk has an EFI label, or > 2TB with no VTOC or legacy MBR. * Otherwise 0. */ int efi_type(int fd) { #if 0 struct vtoc vtoc; struct extvtoc extvtoc; if (ioctl(fd, DKIOCGEXTVTOC, &extvtoc) == -1) { if (errno == ENOTSUP) return (1); else if (errno == ENOTTY) { if (ioctl(fd, DKIOCGVTOC, &vtoc) == -1) if (errno == ENOTSUP) return (1); } } return (0); #else return (ENOSYS); #endif } void efi_err_check(struct dk_gpt *vtoc) { int resv_part = -1; int i, j; diskaddr_t istart, jstart, isize, jsize, endsect; int overlap = 0; /* * make sure no partitions overlap */ for (i = 0; i < vtoc->efi_nparts; i++) { /* It can't be unassigned and have an actual size */ if ((vtoc->efi_parts[i].p_tag == V_UNASSIGNED) && (vtoc->efi_parts[i].p_size != 0)) { (void) fprintf(stderr, "partition %d is \"unassigned\" but has a size " "of %llu\n", i, vtoc->efi_parts[i].p_size); } if (vtoc->efi_parts[i].p_tag == V_UNASSIGNED) { continue; } if (vtoc->efi_parts[i].p_tag == V_RESERVED) { if (resv_part != -1) { (void) fprintf(stderr, "found duplicate reserved partition at " "%d\n", i); } resv_part = i; if (vtoc->efi_parts[i].p_size != EFI_MIN_RESV_SIZE) (void) fprintf(stderr, "Warning: reserved partition size must " "be %d sectors\n", EFI_MIN_RESV_SIZE); } if ((vtoc->efi_parts[i].p_start < vtoc->efi_first_u_lba) || (vtoc->efi_parts[i].p_start > vtoc->efi_last_u_lba)) { (void) fprintf(stderr, "Partition %d starts at %llu\n", i, vtoc->efi_parts[i].p_start); (void) fprintf(stderr, "It must be between %llu and %llu.\n", vtoc->efi_first_u_lba, vtoc->efi_last_u_lba); } if ((vtoc->efi_parts[i].p_start + vtoc->efi_parts[i].p_size < vtoc->efi_first_u_lba) || (vtoc->efi_parts[i].p_start + vtoc->efi_parts[i].p_size > vtoc->efi_last_u_lba + 1)) { (void) fprintf(stderr, "Partition %d ends at %llu\n", i, vtoc->efi_parts[i].p_start + vtoc->efi_parts[i].p_size); (void) fprintf(stderr, "It must be between %llu and %llu.\n", vtoc->efi_first_u_lba, vtoc->efi_last_u_lba); } for (j = 0; j < vtoc->efi_nparts; j++) { isize = vtoc->efi_parts[i].p_size; jsize = vtoc->efi_parts[j].p_size; istart = vtoc->efi_parts[i].p_start; jstart = vtoc->efi_parts[j].p_start; if ((i != j) && (isize != 0) && (jsize != 0)) { endsect = jstart + jsize -1; if ((jstart <= istart) && (istart <= endsect)) { if (!overlap) { (void) fprintf(stderr, "label error: EFI Labels do not " "support overlapping partitions\n"); } (void) fprintf(stderr, "Partition %d overlaps partition " "%d.\n", i, j); overlap = 1; } } } } /* make sure there is a reserved partition */ if (resv_part == -1) { (void) fprintf(stderr, "no reserved partition found\n"); } } diff --git a/lib/libnvpair/Makefile.am b/lib/libnvpair/Makefile.am index a3e1fa307f7c..7b9ebebe7906 100644 --- a/lib/libnvpair/Makefile.am +++ b/lib/libnvpair/Makefile.am @@ -1,47 +1,48 @@ include $(top_srcdir)/config/Rules.am VPATH = \ $(top_srcdir)/module/nvpair \ $(top_srcdir)/lib/libnvpair # Includes kernel code, generate warnings for large stack frames # and required CFLAGS for libtirpc AM_CFLAGS += $(FRAME_LARGER_THAN) $(LIBTIRPC_CFLAGS) +AM_CFLAGS += -fvisibility=hidden lib_LTLIBRARIES = libnvpair.la include $(top_srcdir)/config/Abigail.am USER_C = \ libnvpair.c \ libnvpair_json.c \ nvpair_alloc_system.c KERNEL_C = \ nvpair_alloc_fixed.c \ nvpair.c \ fnvpair.c dist_libnvpair_la_SOURCES = \ $(USER_C) nodist_libnvpair_la_SOURCES = \ $(KERNEL_C) libnvpair_la_LIBADD = \ $(abs_top_builddir)/lib/libspl/libspl_assert.la libnvpair_la_LIBADD += $(LIBTIRPC_LIBS) $(LTLIBINTL) libnvpair_la_LDFLAGS = if !ASAN_ENABLED libnvpair_la_LDFLAGS += -Wl,-z,defs endif libnvpair_la_LDFLAGS += -version-info 3:0:0 include $(top_srcdir)/config/CppCheck.am # Library ABI EXTRA_DIST = libnvpair.abi libnvpair.suppr diff --git a/lib/libnvpair/libnvpair.abi b/lib/libnvpair/libnvpair.abi index 697a67b7fc61..8c503fecd152 100644 --- a/lib/libnvpair/libnvpair.abi +++ b/lib/libnvpair/libnvpair.abi @@ -1,3648 +1,3636 @@ - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - - - - - + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + + + + - - + + - - - - - + + + + + - - - + + + - + - - - - + + + + - - - + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - + - - + + - - - + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - + + + - - - + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - + + + - - - - - - + + + + + + - + - + - + - + - + - + - - - - - + + + + + - - - - + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + - - - + + - - - - - - + + + + - - + + - - + + - - + + - - + + - - - - + + + + - - - - + + + + - - + + - - - - + + + + - - - - + + + + - - - + + + - - - + + + - - - - + + + + - - - + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - + + + + - - - - + + + + - - - - - + + + + + - - - + + + - - - + + + - - + + - - + + - - + + - - + + - - - + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - + + + + - - - + + + - - - - + + + + - - - - - - + + + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - + + + - - - + + + - - - - + + + + - - - - + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - - - - + + + + - + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - + + + + + - - - - - + + + + + - + - + - + - + - + - + + + + + + + + + + + - + - + - + - - - - - - - - - - - + - - + + - + - - + + - + - - + + - + - - - + + + - + - - - + + + - - - + + + - + - - + + - + - - - + + + - + - - + + - - - + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - - - + + + + + - + - - - + + + - + - - - + + + - + - - - + + + - + - - - + + + - + - - - + + + - + - - - + + + - + - - - + + + - + - - - + + + - + - - - + + + - + - - - + + + - + - - - + + + - + - - - + + + - + - - - + + + - + - - - + + + - + - - - + + + - + - - - + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + diff --git a/lib/libshare/Makefile.am b/lib/libshare/Makefile.am index e42609c6496d..dff3e5382d6e 100644 --- a/lib/libshare/Makefile.am +++ b/lib/libshare/Makefile.am @@ -1,28 +1,30 @@ include $(top_srcdir)/config/Rules.am DEFAULT_INCLUDES += -I$(srcdir) +AM_CFLAGS += -fvisibility=hidden + noinst_LTLIBRARIES = libshare.la USER_C = \ libshare_impl.h \ libshare.c \ nfs.c \ nfs.h \ smb.h if BUILD_LINUX USER_C += \ os/linux/nfs.c \ os/linux/smb.c endif if BUILD_FREEBSD USER_C += \ os/freebsd/nfs.c \ os/freebsd/smb.c endif libshare_la_SOURCES = $(USER_C) include $(top_srcdir)/config/CppCheck.am diff --git a/lib/libshare/nfs.c b/lib/libshare/nfs.c index 44d3e93d42f0..e339ebc81f1b 100644 --- a/lib/libshare/nfs.c +++ b/lib/libshare/nfs.c @@ -1,157 +1,157 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ #include #include #include #include #include #include #include #include "nfs.h" static int nfs_lock_fd = -1; /* * nfs_exports_[lock|unlock] are used to guard against conconcurrent * updates to the exports file. Each protocol is responsible for * providing the necessary locking to ensure consistency. */ static int nfs_exports_lock(const char *name) { int err; nfs_lock_fd = open(name, O_RDWR | O_CREAT | O_CLOEXEC, 0600); if (nfs_lock_fd == -1) { err = errno; fprintf(stderr, "failed to lock %s: %s\n", name, strerror(err)); return (err); } if (flock(nfs_lock_fd, LOCK_EX) != 0) { err = errno; fprintf(stderr, "failed to lock %s: %s\n", name, strerror(err)); (void) close(nfs_lock_fd); nfs_lock_fd = -1; return (err); } return (0); } static void nfs_exports_unlock(const char *name) { verify(nfs_lock_fd > 0); if (flock(nfs_lock_fd, LOCK_UN) != 0) { fprintf(stderr, "failed to unlock %s: %s\n", name, strerror(errno)); } (void) close(nfs_lock_fd); nfs_lock_fd = -1; } static char * nfs_init_tmpfile(const char *prefix, const char *mdir) { char *tmpfile = NULL; struct stat sb; if (mdir != NULL && stat(mdir, &sb) < 0 && mkdir(mdir, 0755) < 0) { fprintf(stderr, "failed to create %s: %s\n", mdir, strerror(errno)); return (NULL); } if (asprintf(&tmpfile, "%s.XXXXXXXX", prefix) == -1) { fprintf(stderr, "Unable to allocate temporary file\n"); return (NULL); } int fd = mkostemp(tmpfile, O_CLOEXEC); if (fd == -1) { fprintf(stderr, "Unable to create temporary file: %s", strerror(errno)); free(tmpfile); return (NULL); } close(fd); return (tmpfile); } static int nfs_fini_tmpfile(const char *exports, char *tmpfile) { if (rename(tmpfile, exports) == -1) { fprintf(stderr, "Unable to rename %s: %s\n", tmpfile, strerror(errno)); unlink(tmpfile); free(tmpfile); return (SA_SYSTEM_ERR); } free(tmpfile); return (SA_OK); } -__attribute__((visibility("hidden"))) int +int nfs_toggle_share(const char *lockfile, const char *exports, const char *expdir, sa_share_impl_t impl_share, int(*cbk)(sa_share_impl_t impl_share, char *filename)) { int error; char *filename; if ((filename = nfs_init_tmpfile(exports, expdir)) == NULL) return (SA_SYSTEM_ERR); error = nfs_exports_lock(lockfile); if (error != 0) { unlink(filename); free(filename); return (error); } error = nfs_copy_entries(filename, impl_share->sa_mountpoint); if (error != SA_OK) goto fullerr; error = cbk(impl_share, filename); if (error != SA_OK) goto fullerr; error = nfs_fini_tmpfile(exports, filename); nfs_exports_unlock(lockfile); return (error); fullerr: unlink(filename); free(filename); nfs_exports_unlock(lockfile); return (error); } diff --git a/lib/libshare/os/freebsd/nfs.c b/lib/libshare/os/freebsd/nfs.c index b82491f2ebe8..0041bc228bb5 100644 --- a/lib/libshare/os/freebsd/nfs.c +++ b/lib/libshare/os/freebsd/nfs.c @@ -1,342 +1,342 @@ /* * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * Copyright (c) 2020 by Delphix. All rights reserved. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include "libshare_impl.h" #include "nfs.h" #define _PATH_MOUNTDPID "/var/run/mountd.pid" #define OPTSSIZE 1024 #define MAXLINESIZE (PATH_MAX + OPTSSIZE) #define ZFS_EXPORTS_FILE "/etc/zfs/exports" #define ZFS_EXPORTS_LOCK ZFS_EXPORTS_FILE".lock" static sa_fstype_t *nfs_fstype; /* * Read one line from a file. Skip comments, empty lines and a line with a * mountpoint specified in the 'skip' argument. * * NOTE: This function returns a static buffer and thus is not thread-safe. */ static char * zgetline(FILE *fd, const char *skip) { static char line[MAXLINESIZE]; size_t len, skiplen = 0; char *s, last; if (skip != NULL) skiplen = strlen(skip); for (;;) { s = fgets(line, sizeof (line), fd); if (s == NULL) return (NULL); /* Skip empty lines and comments. */ if (line[0] == '\n' || line[0] == '#') continue; len = strlen(line); if (line[len - 1] == '\n') line[len - 1] = '\0'; last = line[skiplen]; /* Skip the given mountpoint. */ if (skip != NULL && strncmp(skip, line, skiplen) == 0 && (last == '\t' || last == ' ' || last == '\0')) { continue; } break; } return (line); } /* * This function translate options to a format acceptable by exports(5), eg. * * -ro -network=192.168.0.0 -mask=255.255.255.0 -maproot=0 \ * zfs.freebsd.org 69.147.83.54 * * Accepted input formats: * * ro,network=192.168.0.0,mask=255.255.255.0,maproot=0,zfs.freebsd.org * ro network=192.168.0.0 mask=255.255.255.0 maproot=0 zfs.freebsd.org * -ro,-network=192.168.0.0,-mask=255.255.255.0,-maproot=0,zfs.freebsd.org * -ro -network=192.168.0.0 -mask=255.255.255.0 -maproot=0 \ * zfs.freebsd.org * * Recognized keywords: * * ro, maproot, mapall, mask, network, sec, alldirs, public, webnfs, * index, quiet * * NOTE: This function returns a static buffer and thus is not thread-safe. */ static char * translate_opts(const char *shareopts) { static const char *known_opts[] = { "ro", "maproot", "mapall", "mask", "network", "sec", "alldirs", "public", "webnfs", "index", "quiet", NULL }; static char newopts[OPTSSIZE]; char oldopts[OPTSSIZE]; char *o, *s = NULL; unsigned int i; size_t len; strlcpy(oldopts, shareopts, sizeof (oldopts)); newopts[0] = '\0'; s = oldopts; while ((o = strsep(&s, "-, ")) != NULL) { if (o[0] == '\0') continue; for (i = 0; known_opts[i] != NULL; i++) { len = strlen(known_opts[i]); if (strncmp(known_opts[i], o, len) == 0 && (o[len] == '\0' || o[len] == '=')) { strlcat(newopts, "-", sizeof (newopts)); break; } } strlcat(newopts, o, sizeof (newopts)); strlcat(newopts, " ", sizeof (newopts)); } return (newopts); } /* * This function copies all entries from the exports file to "filename", * omitting any entries for the specified mountpoint. */ -__attribute__((visibility("hidden"))) int +int nfs_copy_entries(char *filename, const char *mountpoint) { int error = SA_OK; char *line; FILE *oldfp = fopen(ZFS_EXPORTS_FILE, "re"); FILE *newfp = fopen(filename, "w+e"); if (newfp == NULL) { fprintf(stderr, "failed to open %s file: %s", filename, strerror(errno)); fclose(oldfp); return (SA_SYSTEM_ERR); } fputs(FILE_HEADER, newfp); /* * The ZFS_EXPORTS_FILE may not exist yet. If that's the * case then just write out the new file. */ if (oldfp != NULL) { while ((line = zgetline(oldfp, mountpoint)) != NULL) fprintf(newfp, "%s\n", line); if (ferror(oldfp) != 0) { error = ferror(oldfp); } if (fclose(oldfp) != 0) { fprintf(stderr, "Unable to close file %s: %s\n", filename, strerror(errno)); error = error != 0 ? error : SA_SYSTEM_ERR; } } if (error == 0 && ferror(newfp) != 0) { error = ferror(newfp); } if (fclose(newfp) != 0) { fprintf(stderr, "Unable to close file %s: %s\n", filename, strerror(errno)); error = error != 0 ? error : SA_SYSTEM_ERR; } return (error); } static int nfs_enable_share_impl(sa_share_impl_t impl_share, char *filename) { FILE *fp = fopen(filename, "a+e"); if (fp == NULL) { fprintf(stderr, "failed to open %s file: %s", filename, strerror(errno)); return (SA_SYSTEM_ERR); } char *shareopts = FSINFO(impl_share, nfs_fstype)->shareopts; if (strcmp(shareopts, "on") == 0) shareopts = ""; if (fprintf(fp, "%s\t%s\n", impl_share->sa_mountpoint, translate_opts(shareopts)) < 0) { fprintf(stderr, "failed to write to %s\n", filename); fclose(fp); return (SA_SYSTEM_ERR); } if (fclose(fp) != 0) { fprintf(stderr, "Unable to close file %s: %s\n", filename, strerror(errno)); return (SA_SYSTEM_ERR); } return (SA_OK); } static int nfs_enable_share(sa_share_impl_t impl_share) { return (nfs_toggle_share( ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE, NULL, impl_share, nfs_enable_share_impl)); } static int nfs_disable_share_impl(sa_share_impl_t impl_share, char *filename) { return (SA_OK); } static int nfs_disable_share(sa_share_impl_t impl_share) { return (nfs_toggle_share( ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE, NULL, impl_share, nfs_disable_share_impl)); } static boolean_t nfs_is_shared(sa_share_impl_t impl_share) { char *s, last, line[MAXLINESIZE]; size_t len; char *mntpoint = impl_share->sa_mountpoint; size_t mntlen = strlen(mntpoint); FILE *fp = fopen(ZFS_EXPORTS_FILE, "re"); if (fp == NULL) return (B_FALSE); for (;;) { s = fgets(line, sizeof (line), fp); if (s == NULL) return (B_FALSE); /* Skip empty lines and comments. */ if (line[0] == '\n' || line[0] == '#') continue; len = strlen(line); if (line[len - 1] == '\n') line[len - 1] = '\0'; last = line[mntlen]; /* Skip the given mountpoint. */ if (strncmp(mntpoint, line, mntlen) == 0 && (last == '\t' || last == ' ' || last == '\0')) { fclose(fp); return (B_TRUE); } } fclose(fp); return (B_FALSE); } static int nfs_validate_shareopts(const char *shareopts) { return (SA_OK); } static int nfs_update_shareopts(sa_share_impl_t impl_share, const char *shareopts) { FSINFO(impl_share, nfs_fstype)->shareopts = (char *)shareopts; return (SA_OK); } static void nfs_clear_shareopts(sa_share_impl_t impl_share) { FSINFO(impl_share, nfs_fstype)->shareopts = NULL; } /* * Commit the shares by restarting mountd. */ static int nfs_commit_shares(void) { struct pidfh *pfh; pid_t mountdpid; pfh = pidfile_open(_PATH_MOUNTDPID, 0600, &mountdpid); if (pfh != NULL) { /* Mountd is not running. */ pidfile_remove(pfh); return (SA_OK); } if (errno != EEXIST) { /* Cannot open pidfile for some reason. */ return (SA_SYSTEM_ERR); } /* We have mountd(8) PID in mountdpid variable. */ kill(mountdpid, SIGHUP); return (SA_OK); } static const sa_share_ops_t nfs_shareops = { .enable_share = nfs_enable_share, .disable_share = nfs_disable_share, .is_shared = nfs_is_shared, .validate_shareopts = nfs_validate_shareopts, .update_shareopts = nfs_update_shareopts, .clear_shareopts = nfs_clear_shareopts, .commit_shares = nfs_commit_shares, }; /* * Initializes the NFS functionality of libshare. */ void libshare_nfs_init(void) { nfs_fstype = register_fstype("nfs", &nfs_shareops); } diff --git a/lib/libshare/os/linux/nfs.c b/lib/libshare/os/linux/nfs.c index c236f25698f2..bd578adeec5d 100644 --- a/lib/libshare/os/linux/nfs.c +++ b/lib/libshare/os/linux/nfs.c @@ -1,606 +1,606 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011 Gunnar Beutner * Copyright (c) 2012 Cyril Plisko. All rights reserved. * Copyright (c) 2019, 2020 by Delphix. All rights reserved. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "libshare_impl.h" #include "nfs.h" #define ZFS_EXPORTS_DIR "/etc/exports.d" #define ZFS_EXPORTS_FILE ZFS_EXPORTS_DIR"/zfs.exports" #define ZFS_EXPORTS_LOCK ZFS_EXPORTS_FILE".lock" static sa_fstype_t *nfs_fstype; typedef int (*nfs_shareopt_callback_t)(const char *opt, const char *value, void *cookie); typedef int (*nfs_host_callback_t)(const char *sharepath, const char *filename, const char *host, const char *security, const char *access, void *cookie); /* * Invokes the specified callback function for each Solaris share option * listed in the specified string. */ static int foreach_nfs_shareopt(const char *shareopts, nfs_shareopt_callback_t callback, void *cookie) { char *shareopts_dup, *opt, *cur, *value; int was_nul, error; if (shareopts == NULL) return (SA_OK); if (strcmp(shareopts, "on") == 0) shareopts = "rw,crossmnt"; shareopts_dup = strdup(shareopts); if (shareopts_dup == NULL) return (SA_NO_MEMORY); opt = shareopts_dup; was_nul = 0; while (1) { cur = opt; while (*cur != ',' && *cur != '\0') cur++; if (*cur == '\0') was_nul = 1; *cur = '\0'; if (cur > opt) { value = strchr(opt, '='); if (value != NULL) { *value = '\0'; value++; } error = callback(opt, value, cookie); if (error != SA_OK) { free(shareopts_dup); return (error); } } opt = cur + 1; if (was_nul) break; } free(shareopts_dup); return (SA_OK); } typedef struct nfs_host_cookie_s { nfs_host_callback_t callback; const char *sharepath; void *cookie; const char *filename; const char *security; } nfs_host_cookie_t; /* * Helper function for foreach_nfs_host. This function checks whether the * current share option is a host specification and invokes a callback * function with information about the host. */ static int foreach_nfs_host_cb(const char *opt, const char *value, void *pcookie) { int error; const char *access; char *host_dup, *host, *next; nfs_host_cookie_t *udata = (nfs_host_cookie_t *)pcookie; #ifdef DEBUG fprintf(stderr, "foreach_nfs_host_cb: key=%s, value=%s\n", opt, value); #endif if (strcmp(opt, "sec") == 0) udata->security = value; if (strcmp(opt, "rw") == 0 || strcmp(opt, "ro") == 0) { if (value == NULL) value = "*"; access = opt; host_dup = strdup(value); if (host_dup == NULL) return (SA_NO_MEMORY); host = host_dup; do { next = strchr(host, ':'); if (next != NULL) { *next = '\0'; next++; } error = udata->callback(udata->filename, udata->sharepath, host, udata->security, access, udata->cookie); if (error != SA_OK) { free(host_dup); return (error); } host = next; } while (host != NULL); free(host_dup); } return (SA_OK); } /* * Invokes a callback function for all NFS hosts that are set for a share. */ static int foreach_nfs_host(sa_share_impl_t impl_share, char *filename, nfs_host_callback_t callback, void *cookie) { nfs_host_cookie_t udata; char *shareopts; udata.callback = callback; udata.sharepath = impl_share->sa_mountpoint; udata.cookie = cookie; udata.filename = filename; udata.security = "sys"; shareopts = FSINFO(impl_share, nfs_fstype)->shareopts; return (foreach_nfs_shareopt(shareopts, foreach_nfs_host_cb, &udata)); } /* * Converts a Solaris NFS host specification to its Linux equivalent. */ static int get_linux_hostspec(const char *solaris_hostspec, char **plinux_hostspec) { /* * For now we just support CIDR masks (e.g. @192.168.0.0/16) and host * wildcards (e.g. *.example.org). */ if (solaris_hostspec[0] == '@') { /* * Solaris host specifier, e.g. @192.168.0.0/16; we just need * to skip the @ in this case */ *plinux_hostspec = strdup(solaris_hostspec + 1); } else { *plinux_hostspec = strdup(solaris_hostspec); } if (*plinux_hostspec == NULL) { return (SA_NO_MEMORY); } return (SA_OK); } /* * Adds a Linux share option to an array of NFS options. */ static int add_linux_shareopt(char **plinux_opts, const char *key, const char *value) { size_t len = 0; char *new_linux_opts; if (*plinux_opts != NULL) len = strlen(*plinux_opts); new_linux_opts = realloc(*plinux_opts, len + 1 + strlen(key) + (value ? 1 + strlen(value) : 0) + 1); if (new_linux_opts == NULL) return (SA_NO_MEMORY); new_linux_opts[len] = '\0'; if (len > 0) strcat(new_linux_opts, ","); strcat(new_linux_opts, key); if (value != NULL) { strcat(new_linux_opts, "="); strcat(new_linux_opts, value); } *plinux_opts = new_linux_opts; return (SA_OK); } /* * Validates and converts a single Solaris share option to its Linux * equivalent. */ static int get_linux_shareopts_cb(const char *key, const char *value, void *cookie) { char **plinux_opts = (char **)cookie; /* host-specific options, these are taken care of elsewhere */ if (strcmp(key, "ro") == 0 || strcmp(key, "rw") == 0 || strcmp(key, "sec") == 0) return (SA_OK); if (strcmp(key, "anon") == 0) key = "anonuid"; if (strcmp(key, "root_mapping") == 0) { (void) add_linux_shareopt(plinux_opts, "root_squash", NULL); key = "anonuid"; } if (strcmp(key, "nosub") == 0) key = "subtree_check"; if (strcmp(key, "insecure") != 0 && strcmp(key, "secure") != 0 && strcmp(key, "async") != 0 && strcmp(key, "sync") != 0 && strcmp(key, "no_wdelay") != 0 && strcmp(key, "wdelay") != 0 && strcmp(key, "nohide") != 0 && strcmp(key, "hide") != 0 && strcmp(key, "crossmnt") != 0 && strcmp(key, "no_subtree_check") != 0 && strcmp(key, "subtree_check") != 0 && strcmp(key, "insecure_locks") != 0 && strcmp(key, "secure_locks") != 0 && strcmp(key, "no_auth_nlm") != 0 && strcmp(key, "auth_nlm") != 0 && strcmp(key, "no_acl") != 0 && strcmp(key, "mountpoint") != 0 && strcmp(key, "mp") != 0 && strcmp(key, "fsuid") != 0 && strcmp(key, "refer") != 0 && strcmp(key, "replicas") != 0 && strcmp(key, "root_squash") != 0 && strcmp(key, "no_root_squash") != 0 && strcmp(key, "all_squash") != 0 && strcmp(key, "no_all_squash") != 0 && strcmp(key, "fsid") != 0 && strcmp(key, "anonuid") != 0 && strcmp(key, "anongid") != 0) { return (SA_SYNTAX_ERR); } (void) add_linux_shareopt(plinux_opts, key, value); return (SA_OK); } /* * Takes a string containing Solaris share options (e.g. "sync,no_acl") and * converts them to a NULL-terminated array of Linux NFS options. */ static int get_linux_shareopts(const char *shareopts, char **plinux_opts) { int error; assert(plinux_opts != NULL); *plinux_opts = NULL; /* no_subtree_check - Default as of nfs-utils v1.1.0 */ (void) add_linux_shareopt(plinux_opts, "no_subtree_check", NULL); /* mountpoint - Restrict exports to ZFS mountpoints */ (void) add_linux_shareopt(plinux_opts, "mountpoint", NULL); error = foreach_nfs_shareopt(shareopts, get_linux_shareopts_cb, plinux_opts); if (error != SA_OK) { free(*plinux_opts); *plinux_opts = NULL; } return (error); } /* * This function populates an entry into /etc/exports.d/zfs.exports. * This file is consumed by the linux nfs server so that zfs shares are * automatically exported upon boot or whenever the nfs server restarts. */ static int nfs_add_entry(const char *filename, const char *sharepath, const char *host, const char *security, const char *access_opts, void *pcookie) { int error; char *linuxhost; const char *linux_opts = (const char *)pcookie; error = get_linux_hostspec(host, &linuxhost); if (error != SA_OK) return (error); if (linux_opts == NULL) linux_opts = ""; FILE *fp = fopen(filename, "a+e"); if (fp == NULL) { fprintf(stderr, "failed to open %s file: %s", filename, strerror(errno)); free(linuxhost); return (SA_SYSTEM_ERR); } if (fprintf(fp, "%s %s(sec=%s,%s,%s)\n", sharepath, linuxhost, security, access_opts, linux_opts) < 0) { fprintf(stderr, "failed to write to %s\n", filename); free(linuxhost); fclose(fp); return (SA_SYSTEM_ERR); } free(linuxhost); if (fclose(fp) != 0) { fprintf(stderr, "Unable to close file %s: %s\n", filename, strerror(errno)); return (SA_SYSTEM_ERR); } return (SA_OK); } /* * This function copies all entries from the exports file to "filename", * omitting any entries for the specified mountpoint. */ -__attribute__((visibility("hidden"))) int +int nfs_copy_entries(char *filename, const char *mountpoint) { char *buf = NULL; size_t buflen = 0; int error = SA_OK; FILE *oldfp = fopen(ZFS_EXPORTS_FILE, "re"); FILE *newfp = fopen(filename, "w+e"); if (newfp == NULL) { fprintf(stderr, "failed to open %s file: %s", filename, strerror(errno)); fclose(oldfp); return (SA_SYSTEM_ERR); } fputs(FILE_HEADER, newfp); /* * The ZFS_EXPORTS_FILE may not exist yet. If that's the * case then just write out the new file. */ if (oldfp != NULL) { while (getline(&buf, &buflen, oldfp) != -1) { char *space = NULL; if (buf[0] == '\n' || buf[0] == '#') continue; if ((space = strchr(buf, ' ')) != NULL) { int mountpoint_len = strlen(mountpoint); if (space - buf == mountpoint_len && strncmp(mountpoint, buf, mountpoint_len) == 0) { continue; } } fputs(buf, newfp); } if (ferror(oldfp) != 0) { error = ferror(oldfp); } if (fclose(oldfp) != 0) { fprintf(stderr, "Unable to close file %s: %s\n", filename, strerror(errno)); error = error != 0 ? error : SA_SYSTEM_ERR; } } if (error == 0 && ferror(newfp) != 0) { error = ferror(newfp); } free(buf); if (fclose(newfp) != 0) { fprintf(stderr, "Unable to close file %s: %s\n", filename, strerror(errno)); error = error != 0 ? error : SA_SYSTEM_ERR; } return (error); } /* * Enables NFS sharing for the specified share. */ static int nfs_enable_share_impl(sa_share_impl_t impl_share, char *filename) { char *shareopts, *linux_opts; int error; shareopts = FSINFO(impl_share, nfs_fstype)->shareopts; error = get_linux_shareopts(shareopts, &linux_opts); if (error != SA_OK) return (error); error = foreach_nfs_host(impl_share, filename, nfs_add_entry, linux_opts); free(linux_opts); return (error); } static int nfs_enable_share(sa_share_impl_t impl_share) { return (nfs_toggle_share( ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE, ZFS_EXPORTS_DIR, impl_share, nfs_enable_share_impl)); } /* * Disables NFS sharing for the specified share. */ static int nfs_disable_share_impl(sa_share_impl_t impl_share, char *filename) { return (SA_OK); } static int nfs_disable_share(sa_share_impl_t impl_share) { return (nfs_toggle_share( ZFS_EXPORTS_LOCK, ZFS_EXPORTS_FILE, ZFS_EXPORTS_DIR, impl_share, nfs_disable_share_impl)); } static boolean_t nfs_is_shared(sa_share_impl_t impl_share) { size_t buflen = 0; char *buf = NULL; FILE *fp = fopen(ZFS_EXPORTS_FILE, "re"); if (fp == NULL) { return (B_FALSE); } while ((getline(&buf, &buflen, fp)) != -1) { char *space = NULL; if ((space = strchr(buf, ' ')) != NULL) { int mountpoint_len = strlen(impl_share->sa_mountpoint); if (space - buf == mountpoint_len && strncmp(impl_share->sa_mountpoint, buf, mountpoint_len) == 0) { fclose(fp); free(buf); return (B_TRUE); } } } free(buf); fclose(fp); return (B_FALSE); } /* * Checks whether the specified NFS share options are syntactically correct. */ static int nfs_validate_shareopts(const char *shareopts) { char *linux_opts; int error; error = get_linux_shareopts(shareopts, &linux_opts); if (error != SA_OK) return (error); free(linux_opts); return (SA_OK); } static int nfs_update_shareopts(sa_share_impl_t impl_share, const char *shareopts) { FSINFO(impl_share, nfs_fstype)->shareopts = (char *)shareopts; return (SA_OK); } /* * Clears a share's NFS options. Used by libshare to * clean up shares that are about to be free()'d. */ static void nfs_clear_shareopts(sa_share_impl_t impl_share) { FSINFO(impl_share, nfs_fstype)->shareopts = NULL; } static int nfs_commit_shares(void) { char *argv[] = { "/usr/sbin/exportfs", "-ra", NULL }; return (libzfs_run_process(argv[0], argv, 0)); } static const sa_share_ops_t nfs_shareops = { .enable_share = nfs_enable_share, .disable_share = nfs_disable_share, .is_shared = nfs_is_shared, .validate_shareopts = nfs_validate_shareopts, .update_shareopts = nfs_update_shareopts, .clear_shareopts = nfs_clear_shareopts, .commit_shares = nfs_commit_shares, }; /* * Initializes the NFS functionality of libshare. */ void libshare_nfs_init(void) { nfs_fstype = register_fstype("nfs", &nfs_shareops); } diff --git a/lib/libspl/include/libshare.h b/lib/libspl/include/libshare.h index ea53f8c15089..5d06b163a3ba 100644 --- a/lib/libspl/include/libshare.h +++ b/lib/libspl/include/libshare.h @@ -1,86 +1,86 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * Copyright (c) 2019, 2020 by Delphix. All rights reserved. */ #ifndef _LIBSPL_LIBSHARE_H -#define _LIBSPL_LIBSHARE_H +#define _LIBSPL_LIBSHARE_H extern __attribute__((visibility("default"))) /* API Initialization */ #define SA_INIT_SHARE_API 0x0001 /* init share specific interface */ #define SA_INIT_CONTROL_API 0x0002 /* init control specific interface */ /* * defined error values */ #define SA_OK 0 #define SA_NO_SUCH_PATH 1 /* provided path doesn't exist */ #define SA_NO_MEMORY 2 /* no memory for data structures */ #define SA_DUPLICATE_NAME 3 /* object name is already in use */ #define SA_BAD_PATH 4 /* not a full path */ #define SA_NO_SUCH_GROUP 5 /* group is not defined */ #define SA_CONFIG_ERR 6 /* system configuration error */ #define SA_SYSTEM_ERR 7 /* system error, use errno */ #define SA_SYNTAX_ERR 8 /* syntax error on command line */ #define SA_NO_PERMISSION 9 /* no permission for operation */ #define SA_BUSY 10 /* resource is busy */ #define SA_NO_SUCH_PROP 11 /* property doesn't exist */ #define SA_INVALID_NAME 12 /* name of object is invalid */ #define SA_INVALID_PROTOCOL 13 /* specified protocol not valid */ #define SA_NOT_ALLOWED 14 /* operation not allowed */ #define SA_BAD_VALUE 15 /* bad value for property */ #define SA_INVALID_SECURITY 16 /* invalid security type */ #define SA_NO_SUCH_SECURITY 17 /* security set not found */ #define SA_VALUE_CONFLICT 18 /* property value conflict */ #define SA_NOT_IMPLEMENTED 19 /* plugin interface not implemented */ #define SA_INVALID_PATH 20 /* path is sub-dir of existing share */ #define SA_NOT_SUPPORTED 21 /* operation not supported for proto */ #define SA_PROP_SHARE_ONLY 22 /* property valid on share only */ #define SA_NOT_SHARED 23 /* path is not shared */ #define SA_NO_SUCH_RESOURCE 24 /* resource not found */ #define SA_RESOURCE_REQUIRED 25 /* resource name is required */ #define SA_MULTIPLE_ERROR 26 /* multiple protocols reported error */ #define SA_PATH_IS_SUBDIR 27 /* check_path found path is subdir */ #define SA_PATH_IS_PARENTDIR 28 /* check_path found path is parent */ #define SA_NO_SECTION 29 /* protocol requires section info */ #define SA_NO_SUCH_SECTION 30 /* no section found */ #define SA_NO_PROPERTIES 31 /* no properties found */ #define SA_PASSWORD_ENC 32 /* passwords must be encrypted */ #define SA_SHARE_EXISTS 33 /* path or file is already shared */ /* initialization */ -extern char *sa_errorstr(int); +_LIBSPL_LIBSHARE_H char *sa_errorstr(int); /* share control */ -extern int sa_enable_share(const char *, const char *, const char *, +_LIBSPL_LIBSHARE_H int sa_enable_share(const char *, const char *, const char *, char *); -extern int sa_disable_share(const char *, char *); -extern boolean_t sa_is_shared(const char *, char *); -extern void sa_commit_shares(const char *); +_LIBSPL_LIBSHARE_H int sa_disable_share(const char *, char *); +_LIBSPL_LIBSHARE_H boolean_t sa_is_shared(const char *, char *); +_LIBSPL_LIBSHARE_H void sa_commit_shares(const char *); /* protocol specific interfaces */ -extern int sa_validate_shareopts(char *, char *); +_LIBSPL_LIBSHARE_H int sa_validate_shareopts(char *, char *); #endif /* _LIBSPL_LIBSHARE_H */ diff --git a/lib/libtpool/Makefile.am b/lib/libtpool/Makefile.am index aa8bde32f963..40fd137b4335 100644 --- a/lib/libtpool/Makefile.am +++ b/lib/libtpool/Makefile.am @@ -1,11 +1,13 @@ include $(top_srcdir)/config/Rules.am +AM_CFLAGS += -fvisibility=hidden + noinst_LTLIBRARIES = libtpool.la USER_C = \ thread_pool.c \ thread_pool_impl.h libtpool_la_SOURCES = $(USER_C) include $(top_srcdir)/config/CppCheck.am diff --git a/lib/libzfs/libzfs.abi b/lib/libzfs/libzfs.abi index 3dd8b2b14510..9a1d95d96ce9 100644 --- a/lib/libzfs/libzfs.abi +++ b/lib/libzfs/libzfs.abi @@ -1,7804 +1,7767 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - + + + + - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + diff --git a/lib/libzfs_core/Makefile.am b/lib/libzfs_core/Makefile.am index 67e554dc8706..b2101e21144d 100644 --- a/lib/libzfs_core/Makefile.am +++ b/lib/libzfs_core/Makefile.am @@ -1,35 +1,37 @@ include $(top_srcdir)/config/Rules.am pkgconfig_DATA = libzfs_core.pc +AM_CFLAGS += -fvisibility=hidden + lib_LTLIBRARIES = libzfs_core.la include $(top_srcdir)/config/Abigail.am USER_C = \ libzfs_core.c libzfs_core_la_SOURCES = $(USER_C) libzfs_core_la_LIBADD = \ $(abs_top_builddir)/lib/libzutil/libzutil.la \ $(abs_top_builddir)/lib/libnvpair/libnvpair.la libzfs_core_la_LIBADD += $(LTLIBINTL) libzfs_core_la_LDFLAGS = -pthread if !ASAN_ENABLED libzfs_core_la_LDFLAGS += -Wl,-z,defs endif if BUILD_FREEBSD libzfs_core_la_LIBADD += -lutil -lgeom endif libzfs_core_la_LDFLAGS += -version-info 3:0:0 include $(top_srcdir)/config/CppCheck.am # Library ABI EXTRA_DIST = libzfs_core.abi libzfs_core.suppr diff --git a/lib/libzfs_core/libzfs_core.abi b/lib/libzfs_core/libzfs_core.abi index 79567d1504db..f397929e1afe 100644 --- a/lib/libzfs_core/libzfs_core.abi +++ b/lib/libzfs_core/libzfs_core.abi @@ -1,4569 +1,4512 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - - - + + + - + - + - + - - + + - + - + - + - + - - + + - + - + - - + + - + - - + + - - - - - + + + + + - - + + - - - + + + - + - + - - + + - + - + - - - - - - - - - - - - - - + + - - + + - + - - + + + + + + + + + + + + + + + + + - - + + - + - + - + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - - - - - + + + + + - + - + - - + + - - + + - - + + - - + + - - + + - + - + + - - + - + - + - + - + - - + + - - + + - + - + - + - + - + - - - + + + - - + + - + - + - + - + - + - + - - + + - + - + - + - + - - - - + + + + - + - - + + - - - + + + - - + + - - + + - - + + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - - - - + + + + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - - + + - - + + - + - + - - + + - + - - + + - + - + - + - - + + - - - - - + - + - + - + - + - + - + - - - + + + - + - - + + - - + + - + - - + + - - + + - + - + - - - - - - - - - - - - - - + + + - + - + - - + + - - + + - + - + - - - + + + - - + + - + - + - + - + - + - + - - + + - + + + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - - + + - - + + - + - - + + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - - - + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - - + + - - + + - + - + - - - - + + + + - + - + - - + + - - + + - - + + - - + + - + - - + + - + - + - + - + - + - + - + - + - + - - + + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - - + + - - + + - - + + - + - - + + - + - + - + - - + + - + - + - + - + - - + + - - + + - + - - + + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - - + + - + - - - + + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - + - + - + - + - + - + - + - + - - - + + + - - + + - - + + - + - + - + - + - + - - + + - - + + - + - - + + - - + + - - + + - + - + - + - + - + - - + + - - + + - + - - + + - - + + - - + + - + - + - - + + - + - + - - + + - - + + - - + + - + - + - - + + - + - + - - + + - - + + - - + + - + - + - - + + - + - + - - + + - - + + - - + + - + - + - - + + - + - - + + - - - + + + - + - + - + - + - + - + - + - + - - + + - - + + - - + + - - - + + + - + - + - + - + - + - + - + - + - - + + - - + + - + - - - + + + - - - + + + - - - + + + - + - + - - - + + + - + - + - - - + + + - - - + + + - - - + + + - + - + - - - + + + - + - + - - - - + + + + - - - - + + + + - - - - + + + + - + - + - - - - + + + + - + - + - + - - - + + + - - - + + + - - - + + + - + - + - - - + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + + + + - - + + - - - - + + + + - - + + - + - - - + + + - + - - - + + + - + - + - - + + - + - + - - + + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - + + + + + + + - + - + - - + + - + - + - + - + - + - - - + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - - + + - - + + - + - + - + - + - + - + - - + + - + - + - + - + - - - + + + - - + + - - + + - + - + - + - - - - - - - - - - - - - - - + - + - + - - + + - + - + - + diff --git a/lib/libzfsbootenv/Makefile.am b/lib/libzfsbootenv/Makefile.am index 984df0b8a353..0c454a5e031b 100644 --- a/lib/libzfsbootenv/Makefile.am +++ b/lib/libzfsbootenv/Makefile.am @@ -1,39 +1,41 @@ include $(top_srcdir)/config/Rules.am pkgconfig_DATA = libzfsbootenv.pc +AM_CFLAGS += -fvisibility=hidden + lib_LTLIBRARIES = libzfsbootenv.la include $(top_srcdir)/config/Abigail.am if BUILD_FREEBSD DEFAULT_INCLUDES += -I$(top_srcdir)/include/os/freebsd/zfs endif if BUILD_LINUX DEFAULT_INCLUDES += -I$(top_srcdir)/include/os/linux/zfs endif USER_C = \ lzbe_device.c \ lzbe_pair.c \ lzbe_util.c dist_libzfsbootenv_la_SOURCES = \ $(USER_C) libzfsbootenv_la_LIBADD = \ $(abs_top_builddir)/lib/libzfs/libzfs.la \ $(abs_top_builddir)/lib/libnvpair/libnvpair.la libzfsbootenv_la_LDFLAGS = if !ASAN_ENABLED libzfsbootenv_la_LDFLAGS += -Wl,-z,defs endif libzfsbootenv_la_LDFLAGS += -version-info 1:0:0 include $(top_srcdir)/config/CppCheck.am # Library ABI EXTRA_DIST = libzfsbootenv.abi libzfsbootenv.suppr diff --git a/lib/libzutil/Makefile.am b/lib/libzutil/Makefile.am index 2f0357e9f900..0bc29f05e0fb 100644 --- a/lib/libzutil/Makefile.am +++ b/lib/libzutil/Makefile.am @@ -1,54 +1,55 @@ include $(top_srcdir)/config/Rules.am # Suppress unused but set variable warnings often due to ASSERTs AM_CFLAGS += $(NO_UNUSED_BUT_SET_VARIABLE) AM_CFLAGS += $(LIBBLKID_CFLAGS) $(LIBUDEV_CFLAGS) +AM_CFLAGS += -fvisibility=hidden DEFAULT_INCLUDES += -I$(srcdir) noinst_LTLIBRARIES = libzutil.la USER_C = \ zutil_device_path.c \ zutil_import.c \ zutil_import.h \ zutil_nicenum.c \ zutil_pool.c if BUILD_LINUX USER_C += \ os/linux/zutil_device_path_os.c \ os/linux/zutil_import_os.c \ os/linux/zutil_compat.c endif if BUILD_FREEBSD DEFAULT_INCLUDES += -I$(top_srcdir)/include/os/freebsd/zfs USER_C += \ os/freebsd/zutil_device_path_os.c \ os/freebsd/zutil_import_os.c \ os/freebsd/zutil_compat.c VPATH += $(top_srcdir)/module/os/freebsd/zfs nodist_libzutil_la_SOURCES = zfs_ioctl_compat.c endif libzutil_la_SOURCES = $(USER_C) libzutil_la_LIBADD = \ $(abs_top_builddir)/lib/libavl/libavl.la \ $(abs_top_builddir)/lib/libtpool/libtpool.la \ $(abs_top_builddir)/lib/libnvpair/libnvpair.la \ $(abs_top_builddir)/lib/libspl/libspl.la if BUILD_LINUX libzutil_la_LIBADD += \ $(abs_top_builddir)/lib/libefi/libefi.la \ -lrt endif libzutil_la_LIBADD += -lm $(LIBBLKID_LIBS) $(LIBUDEV_LIBS) include $(top_srcdir)/config/CppCheck.am