xref: /freebsd/sys/contrib/openzfs/include/zfs_valstr.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright (c) 2024, Klara Inc.
25  */
26 
27 #ifndef	_ZFS_VALSTR_H
28 #define	_ZFS_VALSTR_H extern __attribute__((visibility("default")))
29 
30 #include <sys/fs/zfs.h>
31 #include <sys/types.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 /*
38  * These macros create function prototypes for pretty-printing or stringifying
39  * certain kinds of numeric types.
40  *
41  * _ZFS_VALSTR_DECLARE_BITFIELD(name) creates:
42  *
43  *   size_t zfs_valstr_<name>_bits(uint64_t bits, char *out, size_t outlen);
44  *     expands single char for each set bit, and space for each clear bit
45  *
46  *   size_t zfs_valstr_<name>_pairs(uint64_t bits, char *out, size_t outlen);
47  *     expands two-char mnemonic for each bit set in `bits`, separated by `|`
48  *
49  *   size_t zfs_valstr_<name>(uint64_t bits, char *out, size_t outlen);
50  *     expands full name of each bit set in `bits`, separated by spaces
51  *
52  * _ZFS_VALSTR_DECLARE_ENUM(name) creates:
53  *
54  *   size_t zfs_valstr_<name>(int v, char *out, size_t outlen);
55  *     expands full name of enum value
56  *
57  * Each _ZFS_VALSTR_DECLARE_xxx needs a corresponding _VALSTR_xxx_IMPL string
58  * table in vfs_valstr.c.
59  */
60 
61 #define	_ZFS_VALSTR_DECLARE_BITFIELD(name)			\
62 	_ZFS_VALSTR_H size_t zfs_valstr_ ## name ## _bits(	\
63 	    uint64_t bits, char *out, size_t outlen);		\
64 	_ZFS_VALSTR_H size_t zfs_valstr_ ## name ## _pairs(	\
65 	    uint64_t bits, char *out, size_t outlen);		\
66 	_ZFS_VALSTR_H size_t zfs_valstr_ ## name(		\
67 	    uint64_t bits, char *out, size_t outlen);		\
68 
69 #define	_ZFS_VALSTR_DECLARE_ENUM(name)				\
70 	_ZFS_VALSTR_H size_t zfs_valstr_ ## name(		\
71 	    int v, char *out, size_t outlen);			\
72 
73 _ZFS_VALSTR_DECLARE_BITFIELD(zio_flag)
74 _ZFS_VALSTR_DECLARE_BITFIELD(zio_stage)
75 
76 _ZFS_VALSTR_DECLARE_ENUM(zio_priority)
77 
78 #undef _ZFS_VALSTR_DECLARE_BITFIELD
79 #undef _ZFS_VALSTR_DECLARE_ENUM
80 
81 #ifdef	__cplusplus
82 }
83 #endif
84 
85 #endif	/* _ZFS_VALSTR_H */
86