+
+static size_t
+full_write_with_fake_enospc(
+ int fd,
+ const void *buf,
+ size_t count)
+{
+ size_t rc;
+
+ //g_debug("HERE %zd %zd", count, (size_t)fake_enospc_at_byte);
+
+ if (count <= (size_t)fake_enospc_at_byte) {
+ fake_enospc_at_byte -= count;
+ return full_write(fd, buf, count);
+ }
+
+ /* if we get here, the caller has requested a size that is less
+ * than fake_enospc_at_byte. */
+ count = fake_enospc_at_byte;
+ g_debug("returning fake ENOSPC");
+
+ if (fake_enospc_at_byte) {
+ rc = full_write(fd, buf, fake_enospc_at_byte);
+ if (rc == (size_t)fake_enospc_at_byte) {
+ /* full_write succeeded, so fake a failure */
+ errno = ENOSPC;
+ }
+ } else {
+ /* no bytes to write; just fake an error */
+ errno = ENOSPC;
+ rc = 0;
+ }
+
+ /* switch back to calling full_write directly */
+ fake_enospc_at_byte = -1;
+ db_full_write = full_write;
+ return rc;
+}