Update Red Hat Copyright Notices
[nbdkit.git] / include / nbdkit-common.h
blobe070245b8c6c28789d28b5cb87cd18d4fde29295
1 /* nbdkit
2 * Copyright Red Hat
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of Red Hat nor the names of its contributors may be
16 * used to endorse or promote products derived from this software without
17 * specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
33 #ifndef NBDKIT_COMMON_H
34 #define NBDKIT_COMMON_H
36 #if !defined (NBDKIT_PLUGIN_H) && !defined (NBDKIT_FILTER_H)
37 #error this header file should not be directly included
38 #endif
40 #include <stdarg.h>
41 #include <stdint.h>
42 #include <errno.h>
44 #if !defined (_WIN32) && !defined (__MINGW32__) && \
45 !defined (__CYGWIN__) && !defined (_MSC_VER)
46 #include <sys/socket.h>
47 #else
48 #include <ws2tcpip.h>
49 #endif
51 #include <nbdkit-version.h>
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
57 #if (defined (__GNUC__) || defined (__clang__)) && \
58 defined (HAVE_VFPRINTF_PERCENT_M)
59 #define ATTRIBUTE_FORMAT_PRINTF(fmtpos, argpos) \
60 __attribute__ ((__format__ (__printf__, fmtpos, argpos)))
61 #else
62 #define ATTRIBUTE_FORMAT_PRINTF(fmtpos, argpos)
63 #endif
65 #define NBDKIT_THREAD_MODEL_SERIALIZE_CONNECTIONS 0
66 #define NBDKIT_THREAD_MODEL_SERIALIZE_ALL_REQUESTS 1
67 #define NBDKIT_THREAD_MODEL_SERIALIZE_REQUESTS 2
68 #define NBDKIT_THREAD_MODEL_PARALLEL 3
70 #define NBDKIT_FLAG_MAY_TRIM (1<<0) /* Maps to !NBD_CMD_FLAG_NO_HOLE */
71 #define NBDKIT_FLAG_FUA (1<<1) /* Maps to NBD_CMD_FLAG_FUA */
72 #define NBDKIT_FLAG_REQ_ONE (1<<2) /* Maps to NBD_CMD_FLAG_REQ_ONE */
73 #define NBDKIT_FLAG_FAST_ZERO (1<<3) /* Maps to NBD_CMD_FLAG_FAST_ZERO */
75 #define NBDKIT_FUA_NONE 0
76 #define NBDKIT_FUA_EMULATE 1
77 #define NBDKIT_FUA_NATIVE 2
79 #define NBDKIT_CACHE_NONE 0
80 #define NBDKIT_CACHE_EMULATE 1
81 #define NBDKIT_CACHE_NATIVE 2
83 #define NBDKIT_EXTENT_HOLE (1<<0) /* Same as NBD_STATE_HOLE */
84 #define NBDKIT_EXTENT_ZERO (1<<1) /* Same as NBD_STATE_ZERO */
86 #ifndef WIN32
87 #define NBDKIT_EXTERN_DECL(ret, fn, args) extern ret fn args
88 #define NBDKIT_DLL_PUBLIC __attribute__ ((__visibility__ ("default")))
89 #else
90 #define NBDKIT_EXTERN_DECL(ret, fn, args) \
91 extern __declspec (dllexport) ret fn args
92 #define NBDKIT_DLL_PUBLIC __declspec (dllexport)
93 #endif
95 NBDKIT_EXTERN_DECL (void, nbdkit_error,
96 (const char *msg, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2));
97 NBDKIT_EXTERN_DECL (void, nbdkit_verror,
98 (const char *msg, va_list args)
99 ATTRIBUTE_FORMAT_PRINTF (1, 0));
100 NBDKIT_EXTERN_DECL (void, nbdkit_debug,
101 (const char *msg, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2));
102 NBDKIT_EXTERN_DECL (void, nbdkit_vdebug,
103 (const char *msg, va_list args)
104 ATTRIBUTE_FORMAT_PRINTF (1, 0));
106 NBDKIT_EXTERN_DECL (char *, nbdkit_absolute_path, (const char *path));
107 NBDKIT_EXTERN_DECL (int64_t, nbdkit_parse_size, (const char *str));
108 NBDKIT_EXTERN_DECL (int, nbdkit_parse_bool, (const char *str));
109 NBDKIT_EXTERN_DECL (int, nbdkit_parse_int,
110 (const char *what, const char *str, int *r));
111 NBDKIT_EXTERN_DECL (int, nbdkit_parse_unsigned,
112 (const char *what, const char *str, unsigned *r));
113 NBDKIT_EXTERN_DECL (int, nbdkit_parse_int8_t,
114 (const char *what, const char *str, int8_t *r));
115 NBDKIT_EXTERN_DECL (int, nbdkit_parse_uint8_t,
116 (const char *what, const char *str, uint8_t *r));
117 NBDKIT_EXTERN_DECL (int, nbdkit_parse_int16_t,
118 (const char *what, const char *str, int16_t *r));
119 NBDKIT_EXTERN_DECL (int, nbdkit_parse_uint16_t,
120 (const char *what, const char *str, uint16_t *r));
121 NBDKIT_EXTERN_DECL (int, nbdkit_parse_int32_t,
122 (const char *what, const char *str, int32_t *r));
123 NBDKIT_EXTERN_DECL (int, nbdkit_parse_uint32_t,
124 (const char *what, const char *str, uint32_t *r));
125 NBDKIT_EXTERN_DECL (int, nbdkit_parse_int64_t,
126 (const char *what, const char *str, int64_t *r));
127 NBDKIT_EXTERN_DECL (int, nbdkit_parse_uint64_t,
128 (const char *what, const char *str, uint64_t *r));
129 NBDKIT_EXTERN_DECL (int, nbdkit_stdio_safe, (void));
130 NBDKIT_EXTERN_DECL (int, nbdkit_read_password,
131 (const char *value, char **password));
132 NBDKIT_EXTERN_DECL (char *, nbdkit_realpath, (const char *path));
133 NBDKIT_EXTERN_DECL (int, nbdkit_nanosleep, (unsigned sec, unsigned nsec));
134 NBDKIT_EXTERN_DECL (int, nbdkit_peer_name,
135 (struct sockaddr *addr, socklen_t *addrlen));
136 NBDKIT_EXTERN_DECL (int64_t, nbdkit_peer_pid, (void));
137 NBDKIT_EXTERN_DECL (int64_t, nbdkit_peer_uid, (void));
138 NBDKIT_EXTERN_DECL (int64_t, nbdkit_peer_gid, (void));
139 NBDKIT_EXTERN_DECL (void, nbdkit_shutdown, (void));
140 NBDKIT_EXTERN_DECL (void, nbdkit_disconnect, (int force));
142 NBDKIT_EXTERN_DECL (const char *, nbdkit_strdup_intern,
143 (const char *str));
144 NBDKIT_EXTERN_DECL (const char *, nbdkit_strndup_intern,
145 (const char *str, size_t n));
146 NBDKIT_EXTERN_DECL (const char *, nbdkit_printf_intern,
147 (const char *msg, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2));
148 NBDKIT_EXTERN_DECL (const char *, nbdkit_vprintf_intern,
149 (const char *msg, va_list args)
150 ATTRIBUTE_FORMAT_PRINTF (1, 0));
152 struct nbdkit_extents;
153 NBDKIT_EXTERN_DECL (int, nbdkit_add_extent,
154 (struct nbdkit_extents *,
155 uint64_t offset, uint64_t length, uint32_t type));
157 struct nbdkit_exports;
158 NBDKIT_EXTERN_DECL (int, nbdkit_add_export,
159 (struct nbdkit_exports *,
160 const char *name, const char *description));
161 NBDKIT_EXTERN_DECL (int, nbdkit_use_default_export,
162 (struct nbdkit_exports *));
164 /* A static non-NULL pointer which can be used when you don't need a
165 * per-connection handle.
167 #define NBDKIT_HANDLE_NOT_NEEDED (&errno)
169 #ifdef __cplusplus
171 #endif
173 #ifdef __cplusplus
174 #define NBDKIT_CXX_LANG_C extern "C"
175 #else
176 #define NBDKIT_CXX_LANG_C /* nothing */
177 #endif
179 #endif /* NBDKIT_COMMON_H */