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