2 * Copyright (C) 2013 Red Hat Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
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
34 /* See nbdkit-plugin(3) for documentation and how to write a plugin. */
36 #ifndef NBDKIT_PLUGIN_H
37 #define NBDKIT_PLUGIN_H
41 struct nbdkit_plugin
{
45 void (*unload
) (void);
47 void * (*open
) (void);
48 void (*close
) (void *handle
);
50 off_t (*get_size
) (void *handle
);
52 int (*can_write
) (void *handle
);
53 int (*can_flush
) (void *handle
);
54 int (*is_rotational
) (void *handle
);
55 int (*can_trim
) (void *handle
);
57 int (*pread
) (void *handle
, void *buf
, size_t count
, off_t offset
);
58 int (*pwrite
) (void *handle
, const void *buf
, size_t count
, off_t offset
);
59 int (*flush
) (void *handle
);
60 int (*trim
) (void *handle
, size_t count
, off_t offset
);
62 /* int (*set_exportname) (void *handle, const char *exportname); */
65 extern void nbdkit_error (char *msg
, ...);
67 #define NBDKIT_REGISTER_PLUGIN(plugin) \
68 static struct nbdkit_plugin *plugin_init (size_t *struct_size, int *version) \
69 __attribute__((constructor)); \
70 static struct nbdkit_plugin * \
71 plugin_init (size_t *struct_size, int *version) \
73 *struct_size = sizeof (plugin); \
78 #endif /* NBDKIT_PLUGIN_H */