dovecot-2.2: lib-fs: Added support for giving a hash of the writ...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Sep 10 04:11:30 EEST 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/7e0ebc2faf3c
changeset: 16721:7e0ebc2faf3c
user: Timo Sirainen <tss at iki.fi>
date: Tue Sep 10 00:27:12 2013 +0300
description:
lib-fs: Added support for giving a hash of the written data to be verified by storage.
diffstat:
src/lib-fs/fs-api-private.h | 3 +++
src/lib-fs/fs-api.c | 17 +++++++++++++++++
src/lib-fs/fs-api.h | 13 ++++++++++++-
3 files changed, 32 insertions(+), 1 deletions(-)
diffs (105 lines):
diff -r f73c388ad360 -r 7e0ebc2faf3c src/lib-fs/fs-api-private.h
--- a/src/lib-fs/fs-api-private.h Mon Sep 09 04:34:58 2013 +0300
+++ b/src/lib-fs/fs-api-private.h Tue Sep 10 00:27:12 2013 +0300
@@ -75,6 +75,9 @@
struct istream *pending_read_input;
bool write_pending;
+ const struct hash_method *write_digest_method;
+ void *write_digest;
+
pool_t metadata_pool;
ARRAY_TYPE(fs_metadata) metadata;
diff -r f73c388ad360 -r 7e0ebc2faf3c src/lib-fs/fs-api.c
--- a/src/lib-fs/fs-api.c Mon Sep 09 04:34:58 2013 +0300
+++ b/src/lib-fs/fs-api.c Tue Sep 10 00:27:12 2013 +0300
@@ -4,6 +4,7 @@
#include "array.h"
#include "module-dir.h"
#include "str.h"
+#include "hash-method.h"
#include "istream.h"
#include "istream-seekable.h"
#include "ostream.h"
@@ -199,6 +200,7 @@
i_stream_unref(&file->copy_input);
(void)fs_write_stream_abort(file, &file->copy_output);
}
+ i_free_and_null(file->write_digest);
if (file->fs->v.file_close != NULL) T_BEGIN {
file->fs->v.file_close(file);
} T_END;
@@ -251,6 +253,11 @@
file->fs->v.get_path(file);
}
+struct fs *fs_file_fs(struct fs_file *file)
+{
+ return file->fs;
+}
+
static void ATTR_FORMAT(2, 0)
fs_set_verror(struct fs *fs, const char *fmt, va_list args)
{
@@ -475,6 +482,16 @@
} T_END;
}
+void fs_write_set_hash(struct fs_file *file, const struct hash_method *method,
+ const void *digest)
+{
+ file->write_digest_method = method;
+
+ i_free(file->write_digest);
+ file->write_digest = i_malloc(method->digest_size);
+ memcpy(file->write_digest, digest, method->digest_size);
+}
+
void fs_file_set_async_callback(struct fs_file *file,
fs_file_async_callback_t *callback,
void *context)
diff -r f73c388ad360 -r 7e0ebc2faf3c src/lib-fs/fs-api.h
--- a/src/lib-fs/fs-api.h Mon Sep 09 04:34:58 2013 +0300
+++ b/src/lib-fs/fs-api.h Tue Sep 10 00:27:12 2013 +0300
@@ -5,6 +5,7 @@
struct fs;
struct fs_file;
struct fs_lock;
+struct hash_method;
enum fs_properties {
FS_PROPERTY_METADATA = 0x01,
@@ -19,7 +20,9 @@
FS_PROPERTY_RELIABLEITER= 0x40,
/* Backend uses directories, which aren't automatically deleted
when its children are deleted. */
- FS_PROPERTY_DIRECTORIES = 0x80
+ FS_PROPERTY_DIRECTORIES = 0x80,
+ FS_PROPERTY_WRITE_HASH_MD5 = 0x100,
+ FS_PROPERTY_WRITE_HASH_SHA256 = 0x200
};
enum fs_open_mode {
@@ -115,6 +118,8 @@
FS_OPEN_MODE_CREATE_UNIQUE_128 and the write has already finished,
return the path including the generated filename. */
const char *fs_file_path(struct fs_file *file);
+/* Returns the file's fs. */
+struct fs *fs_file_fs(struct fs_file *file);
/* Return the error message for the last failed operation. */
const char *fs_last_error(struct fs *fs);
@@ -151,6 +156,12 @@
/* Abort writing via stream. Anything written to the stream is discarded. */
void fs_write_stream_abort(struct fs_file *file, struct ostream **output);
+/* Set a hash to the following write. The storage can then verify that the
+ input data matches the specified hash, or fail if it doesn't. Typically
+ implemented by Content-MD5 header. */
+void fs_write_set_hash(struct fs_file *file, const struct hash_method *method,
+ const void *digest);
+
/* Call the specified callback whenever the file can be read/written to.
May call the callback immediately. */
void fs_file_set_async_callback(struct fs_file *file,
More information about the dovecot-cvs
mailing list