diff --git a/include/erasurecode.h b/include/erasurecode.h new file mode 100644 index 0000000..4ddae7e --- /dev/null +++ b/include/erasurecode.h @@ -0,0 +1,112 @@ +/* + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY + * THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _ERASURECODE_H_ +#define _ERASURECODE_H_ + +#include "erasurecode_version.h" +#include "erasurecode_stdinc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined (__GNUC__) && __GNUC__ > 3 +#define dl_restrict __restrict +#else +#define dl_restrict +#endif + +/* liberasurecode API header */ + +typedef enum { + EC_BACKEND_NULL = 0, + EC_BACKEND_RS_VAND = 1, + EC_BACKEND_RS_CAUCHY_ORIG = 2, + EC_BACKEND_FLAT_XOR_3 = 3, + EC_BACKEND_FLAT_XOR_4 = 4, + EC_BACKENDS_MAX, +} ec_backend_id_t; + +typedef void * ec_backend_handle_t; + +struct ec_backend_ops { + int (*init)(TBD); + int (*exit)(TBD); + + ec_backend_handle_t (*open)(TBD); + void (*close)(ec_backend_handle_t handle); + + int (*encode)(TBD); + int (*decode)(TBD); + int (*reconstruct)(TBD); + int (*get_fragments_needed)(TBD); + int (*get_fragment_metadata)(TBD); + int (*verify_fragment_metadata)(TBD); + int (*verify_stripe_metadata)(TBD); +}; +typedef struct ec_backend_ops ec_backend_ops_t; + +struct ec_backend_private { + uint32_t flags; + /* other common/private EC backend members go here */ +}; +typedef struct ec_backend_private ec_backend_private_t; + + +#define MAX_BASENAMELEN 64 +#define MAX_LIBNAMELEN 64 +#define MAX_LIBVERLEN 64 +struct ec_backend { + ec_backend_id_t id; /* EC backend id */ + char name[MAX_BASENAMELEN]; /* EC backend common name */ + char soname[MAX_LIBNAMELEN]; /* EC backend shared library path */ + char soversion[MAX_LIBVERLEN]; /* EC backend shared library version */ + ec_backend_handle_t handle; /* EC backend shared library handle */ + uint8_t users; /* EC backend number of active references */ + + ec_backend_ops_t ops; /* EC backend ops table */ + ec_backend_private_t private; /* EC backend private data */ + + SLIST_ENTRY(ec_backend) link; +}; +typedef struct ec_backend ec_backend_t; + +/* Error codes */ +typedef enum { + EBACKENDNOTSUPP = 200, + EECMETHODNOTIMPL = 201, +} LIBERASURECODE_ERROR_CODES; + +/* Backend registration interface */ +int liberasurecode_backend_register(ec_backend_t *backend); +int liberasurecode_backend_unregister(ec_backend_t *backend); + +/* + +#ifdef __cplusplus +} +#endif + +#endif // _ERASURECODE_H_ diff --git a/include/erasurecode_internal.h b/include/erasurecode_internal.h new file mode 100644 index 0000000..c433bd3 --- /dev/null +++ b/include/erasurecode_internal.h @@ -0,0 +1,42 @@ +/* + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY + * THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _ERASURECODE_INTERNAL_H_ +#define _ERASURECODE_INTERNAL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "erasurecode.h" + +/* Init/exit routines */ +int liberasurecode_backend_init(ec_backend_t *backend); +int liberasurecode_backend_exit(ec_backend_t *backend); + +/* Backend query interface */ +ec_backend_t liberasurecode_backend_get_by_name(const char *name); +ec_backend_t liberasurecode_backend_get_by_soname(const char *soname); + +#endif // _ERASURECODE_INTERNAL_H_ diff --git a/include/erasurecode_stdinc.h b/include/erasurecode_stdinc.h new file mode 100644 index 0000000..007abc5 --- /dev/null +++ b/include/erasurecode_stdinc.h @@ -0,0 +1,131 @@ +/* + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY + * THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _ERASURECODE_STDINC_H +#define _ERASURECODE_STDINC_H + +#include "config.h" + +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_STDIO_H +#include +#endif +#if defined(STDC_HEADERS) +# include +# include +# include +#else +# if defined(HAVE_STDLIB_H) +# include +# elif defined(HAVE_MALLOC_H) +# include +# endif +# if defined(HAVE_STDDEF_H) +# include +# endif +# if defined(HAVE_STDARG_H) +# include +# endif +#endif +#ifdef HAVE_STRING_H +# if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H) +# include +# endif +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif +#if defined(HAVE_INTTYPES_H) +# include +#elif defined(HAVE_STDINT_H) +# include +#endif +#ifdef HAVE_CTYPE_H +# include +#endif +#if defined(HAVE_ICONV) && defined(HAVE_ICONV_H) +# include +#endif + +#if defined(__GNUC__) && __GNUC__ >= 4 +# define DECLSPEC __attribute__ ((visibility("default"))) +#else +# define DECLSPEC +#endif + +// FIXME - need to move these to the main liberasurecode header +#ifdef HAVE_MALLOC +#define ERASURECODE_malloc malloc +#else +extern DECLSPEC void * ERASURECODE_malloc(size_t size); +#endif + +#ifdef HAVE_CALLOC +#define ERASURECODE_calloc calloc +#else +extern DECLSPEC void * ERASURECODE_calloc(size_t nmemb, size_t size); +#endif + +#ifdef HAVE_REALLOC +#define ERASURECODE_realloc realloc +#else +extern DECLSPEC void * ERASURECODE_realloc(void *mem, size_t size); +#endif + +#ifdef HAVE_FREE +#define ERASURECODE_free free +#else +extern DECLSPEC void ERASURECODE_free(void *mem); +#endif + +/* Redefine main() on MacOS */ + +#if defined(__MACOS__) || defined(__MACOSX__) + +#ifdef __cplusplus +#define C_LINKAGE "C" +#else +#define C_LINKAGE +#endif /* __cplusplus */ + +/** The application's main() function must be called with C linkage, + * and should be declared like this: + * @code + * #ifdef __cplusplus + * extern "C" + * #endif + * int main(int argc, char *argv[]) + * { + * } + * @endcode + */ +#define main EC_main + +/** The prototype for the application's main() function */ +extern C_LINKAGE int EC_main(int argc, char *argv[]); + +#endif // _ERASURECODE_STDINC_H diff --git a/include/erasurecode_version.h b/include/erasurecode_version.h new file mode 100644 index 0000000..bf18edd --- /dev/null +++ b/include/erasurecode_version.h @@ -0,0 +1,37 @@ +/* + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY + * THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _ERASURECODE_VERSION_H_ +#define _ERASURECODE_VERSION_H_ + +#define MAJOR = 0 +#define MINOR = 9 +#define REV = 4 +#define VERSION(x, y, z) ((x << 16) | (y << 8) | (z)) + +#define LIBERASURECODE_VERSION VERSION(MAJOR, MINOR, REV) + +#endif // _ERASURECODE_VERSION_H_ + +