From 47d66c39bb391b97f178fd47e7c809e28f6f7f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sun, 27 Jun 2021 23:46:16 +0200 Subject: [PATCH] Add option and test for reading without read_buf --- src/sparsebundlefs.cpp | 15 +++++++++++++-- tests/30_noreadbuf.tst | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/30_noreadbuf.tst diff --git a/src/sparsebundlefs.cpp b/src/sparsebundlefs.cpp index 92bdcea..4cf6f7e 100644 --- a/src/sparsebundlefs.cpp +++ b/src/sparsebundlefs.cpp @@ -93,6 +93,7 @@ struct sparsebundle_t { struct { bool allow_other = false; bool allow_root = false; + bool noreadbuf = false; } options; }; @@ -495,13 +496,15 @@ static int sparsebundle_show_usage(char *program_name) enum { SPARSEBUNDLE_OPT_HANDLED = 0, SPARSEBUNDLE_OPT_IGNORED = 1, - SPARSEBUNDLE_OPT_DEBUG, SPARSEBUNDLE_OPT_ALLOW_OTHER, SPARSEBUNDLE_OPT_ALLOW_ROOT + SPARSEBUNDLE_OPT_DEBUG, SPARSEBUNDLE_OPT_ALLOW_OTHER, SPARSEBUNDLE_OPT_ALLOW_ROOT, + SPARSEBUNDLE_OPT_NOREADBUF }; struct fuse_opt sparsebundle_options[] = { FUSE_OPT_KEY("-D", SPARSEBUNDLE_OPT_DEBUG), FUSE_OPT_KEY("allow_other", SPARSEBUNDLE_OPT_ALLOW_OTHER), FUSE_OPT_KEY("allow_root", SPARSEBUNDLE_OPT_ALLOW_ROOT), + FUSE_OPT_KEY("noreadbuf", SPARSEBUNDLE_OPT_NOREADBUF), FUSE_OPT_END }; @@ -522,6 +525,10 @@ static int sparsebundle_opt_proc(void *data, const char *arg, int key, struct fu sparsebundle->options.allow_root = true; return SPARSEBUNDLE_OPT_IGNORED; + case SPARSEBUNDLE_OPT_NOREADBUF: + sparsebundle->options.noreadbuf = true; + return SPARSEBUNDLE_OPT_HANDLED; + case FUSE_OPT_KEY_NONOPT: if (!sparsebundle->path) { sparsebundle->path = realpath(arg, 0); @@ -612,7 +619,11 @@ int main(int argc, char **argv) sparsebundle_filesystem_operations.readdir = sparsebundle_readdir; sparsebundle_filesystem_operations.release = sparsebundle_release; #if FUSE_SUPPORTS_ZERO_COPY - sparsebundle_filesystem_operations.read_buf = sparsebundle_read_buf; + syslog(LOG_DEBUG, "fuse supports zero-copy"); + if (sparsebundle.options.noreadbuf) + syslog(LOG_DEBUG, "disabling zero-copy"); + else + sparsebundle_filesystem_operations.read_buf = sparsebundle_read_buf; #endif int ret = fuse_main(args.argc, args.argv, &sparsebundle_filesystem_operations, &sparsebundle); diff --git a/tests/30_noreadbuf.tst b/tests/30_noreadbuf.tst new file mode 100644 index 0000000..c5a7e50 --- /dev/null +++ b/tests/30_noreadbuf.tst @@ -0,0 +1,23 @@ +#!/usr/bin/env testrunner.sh + +source "$(dirname "$0")/testhelpers.sh" + +function setup() { + mount_sparsebundle -o noreadbuf +} + +function test_dmg_has_correct_number_of_blocks() { + hfsdump $dmg_file | grep "total_blocks: 268435456" +} + +function test_dmg_contents_is_same_as_testdata() { + for f in $(ls $HFSFUSE_DIR/src); do + echo "Diffing $HFSFUSE_DIR/src/$f" + diff $HFSFUSE_DIR/src/$f <(hfsdump $dmg_file read "/src/$f") + done +} + +function teardown() { + umount $mount_dir + rm -Rf $mount_dir +} \ No newline at end of file