Skip to content

Commit 47d66c3

Browse files
committed
Add option and test for reading without read_buf
1 parent 365d3a3 commit 47d66c3

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

src/sparsebundlefs.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct sparsebundle_t {
9393
struct {
9494
bool allow_other = false;
9595
bool allow_root = false;
96+
bool noreadbuf = false;
9697
} options;
9798
};
9899

@@ -495,13 +496,15 @@ static int sparsebundle_show_usage(char *program_name)
495496

496497
enum {
497498
SPARSEBUNDLE_OPT_HANDLED = 0, SPARSEBUNDLE_OPT_IGNORED = 1,
498-
SPARSEBUNDLE_OPT_DEBUG, SPARSEBUNDLE_OPT_ALLOW_OTHER, SPARSEBUNDLE_OPT_ALLOW_ROOT
499+
SPARSEBUNDLE_OPT_DEBUG, SPARSEBUNDLE_OPT_ALLOW_OTHER, SPARSEBUNDLE_OPT_ALLOW_ROOT,
500+
SPARSEBUNDLE_OPT_NOREADBUF
499501
};
500502

501503
struct fuse_opt sparsebundle_options[] = {
502504
FUSE_OPT_KEY("-D", SPARSEBUNDLE_OPT_DEBUG),
503505
FUSE_OPT_KEY("allow_other", SPARSEBUNDLE_OPT_ALLOW_OTHER),
504506
FUSE_OPT_KEY("allow_root", SPARSEBUNDLE_OPT_ALLOW_ROOT),
507+
FUSE_OPT_KEY("noreadbuf", SPARSEBUNDLE_OPT_NOREADBUF),
505508
FUSE_OPT_END
506509
};
507510

@@ -522,6 +525,10 @@ static int sparsebundle_opt_proc(void *data, const char *arg, int key, struct fu
522525
sparsebundle->options.allow_root = true;
523526
return SPARSEBUNDLE_OPT_IGNORED;
524527

528+
case SPARSEBUNDLE_OPT_NOREADBUF:
529+
sparsebundle->options.noreadbuf = true;
530+
return SPARSEBUNDLE_OPT_HANDLED;
531+
525532
case FUSE_OPT_KEY_NONOPT:
526533
if (!sparsebundle->path) {
527534
sparsebundle->path = realpath(arg, 0);
@@ -612,7 +619,11 @@ int main(int argc, char **argv)
612619
sparsebundle_filesystem_operations.readdir = sparsebundle_readdir;
613620
sparsebundle_filesystem_operations.release = sparsebundle_release;
614621
#if FUSE_SUPPORTS_ZERO_COPY
615-
sparsebundle_filesystem_operations.read_buf = sparsebundle_read_buf;
622+
syslog(LOG_DEBUG, "fuse supports zero-copy");
623+
if (sparsebundle.options.noreadbuf)
624+
syslog(LOG_DEBUG, "disabling zero-copy");
625+
else
626+
sparsebundle_filesystem_operations.read_buf = sparsebundle_read_buf;
616627
#endif
617628

618629
int ret = fuse_main(args.argc, args.argv, &sparsebundle_filesystem_operations, &sparsebundle);

tests/30_noreadbuf.tst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env testrunner.sh
2+
3+
source "$(dirname "$0")/testhelpers.sh"
4+
5+
function setup() {
6+
mount_sparsebundle -o noreadbuf
7+
}
8+
9+
function test_dmg_has_correct_number_of_blocks() {
10+
hfsdump $dmg_file | grep "total_blocks: 268435456"
11+
}
12+
13+
function test_dmg_contents_is_same_as_testdata() {
14+
for f in $(ls $HFSFUSE_DIR/src); do
15+
echo "Diffing $HFSFUSE_DIR/src/$f"
16+
diff $HFSFUSE_DIR/src/$f <(hfsdump $dmg_file read "/src/$f")
17+
done
18+
}
19+
20+
function teardown() {
21+
umount $mount_dir
22+
rm -Rf $mount_dir
23+
}

0 commit comments

Comments
 (0)