uint64_t rados_get_last_version(rados_ioctx_t io);
/**
- * Write data to an object
+ * Write *len* bytes from *buf* into the *oid* object, starting at
+ * offset *off*. The value of *len* must be <= UINT_MAX/2.
*
* @note This will never return a positive value not equal to len.
* @param io the io context in which the write will occur
int rados_write(rados_ioctx_t io, const char *oid, const char *buf, size_t len, uint64_t off);
/**
- * Write an entire object
+ * Write *len* bytes from *buf* into the *oid* object. The value of
+ * *len* must be <= UINT_MAX/2.
*
* The object is filled with the provided data. If the object exists,
* it is atomically truncated and then written.
const char *src, uint64_t src_off, size_t len);
/**
- * Append data to an object
+ * Append *len* bytes from *buf* into the *oid* object. The value of
+ * *len* must be <= UINT_MAX/2.
*
* @param io the context to operate in
* @param oid the name of the object
extern "C" int rados_write(rados_ioctx_t io, const char *o, const char *buf, size_t len, uint64_t off)
{
tracepoint(librados, rados_write_enter, io, o, buf, len, off);
+ if (len > UINT_MAX/2)
+ return -E2BIG;
librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
object_t oid(o);
bufferlist bl;
extern "C" int rados_append(rados_ioctx_t io, const char *o, const char *buf, size_t len)
{
tracepoint(librados, rados_append_enter, io, o, buf, len);
+ if (len > UINT_MAX/2)
+ return -E2BIG;
librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
object_t oid(o);
bufferlist bl;
extern "C" int rados_write_full(rados_ioctx_t io, const char *o, const char *buf, size_t len)
{
tracepoint(librados, rados_write_full_enter, io, o, buf, len);
+ if (len > UINT_MAX/2)
+ return -E2BIG;
librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
object_t oid(o);
bufferlist bl;
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*
// vim: ts=8 sw=2 smarttab
+#include <climits>
+
#include "include/rados/librados.h"
#include "include/rados/librados.hpp"
#include "test/librados/test.h"
ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
}
+TEST_F(LibRadosIo, E2BIG) {
+ char buf[1];
+ ASSERT_EQ(-E2BIG, rados_write(ioctx, "A", buf, UINT_MAX, 0));
+ ASSERT_EQ(-E2BIG, rados_append(ioctx, "A", buf, UINT_MAX));
+ ASSERT_EQ(-E2BIG, rados_write_full(ioctx, "A", buf, UINT_MAX));
+}
+
TEST_F(LibRadosIo, ReadTimeout) {
char buf[128];
memset(buf, 'a', sizeof(buf));