server: Fix -U option so it copies trailing ASCII NUL character.
[nbdkit/ericb.git] / include / nbdkit-plugin.h
blob0fcb1cf3d40acad08c2d03938fcc305d4a4a0f59
1 /* nbdkit
2 * Copyright (C) 2013 Red Hat Inc.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of Red Hat nor the names of its contributors may be
17 * used to endorse or promote products derived from this software without
18 * specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 /* See nbdkit-plugin(3) for documentation and how to write a plugin. */
36 #ifndef NBDKIT_PLUGIN_H
37 #define NBDKIT_PLUGIN_H
39 #include <stdarg.h>
40 #include <stdint.h>
42 #define NBDKIT_THREAD_MODEL_SERIALIZE_CONNECTIONS 0
43 #define NBDKIT_THREAD_MODEL_SERIALIZE_ALL_REQUESTS 1
44 #define NBDKIT_THREAD_MODEL_SERIALIZE_REQUESTS 2
45 #define NBDKIT_THREAD_MODEL_PARALLEL 3
47 struct nbdkit_plugin {
48 uint64_t _struct_size;
49 int _api_version;
50 int _thread_model;
52 const char *name;
53 const char *longname;
54 const char *version;
55 const char *description;
57 void (*load) (void);
58 void (*unload) (void);
60 int (*config) (const char *key, const char *value);
61 int (*config_complete) (void);
62 const char *config_help;
64 void * (*open) (int readonly);
65 void (*close) (void *handle);
67 int64_t (*get_size) (void *handle);
69 int (*can_write) (void *handle);
70 int (*can_flush) (void *handle);
71 int (*is_rotational) (void *handle);
72 int (*can_trim) (void *handle);
74 int (*pread) (void *handle, void *buf, uint32_t count, uint64_t offset);
75 int (*pwrite) (void *handle, const void *buf, uint32_t count, uint64_t offset);
76 int (*flush) (void *handle);
77 int (*trim) (void *handle, uint32_t count, uint64_t offset);
79 /* int (*set_exportname) (void *handle, const char *exportname); */
82 extern void nbdkit_error (const char *msg, ...)
83 __attribute__((format (printf, 1, 2)));
84 extern void nbdkit_verror (const char *msg, va_list args);
85 extern void nbdkit_debug (const char *msg, ...)
86 __attribute__((format (printf, 1, 2)));
87 extern void nbdkit_vdebug (const char *msg, va_list args);
89 extern char *nbdkit_absolute_path (const char *path);
90 extern int64_t nbdkit_parse_size (const char *str);
92 #define NBDKIT_REGISTER_PLUGIN(plugin) \
93 struct nbdkit_plugin * \
94 plugin_init (void) \
95 { \
96 (plugin)._struct_size = sizeof (plugin); \
97 (plugin)._api_version = 1; \
98 (plugin)._thread_model = THREAD_MODEL; \
99 return &(plugin); \
102 #endif /* NBDKIT_PLUGIN_H */