Skip to content

Commit

Permalink
Merge pull request gerard#51 from cernekee/local
Browse files Browse the repository at this point in the history
Fix assertion when sparse files don't end on a block boundary
  • Loading branch information
gerard authored Nov 10, 2018
2 parents 325bf27 + 73af629 commit ab9ae62
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion op_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ int op_read(const char *path, char *buf, size_t size, off_t offset,
disk_ctx_create(&read_ctx, BLOCKS2BYTES(pblock), BLOCK_SIZE, extent_len);
bytes = disk_ctx_read(&read_ctx, size - ret, buf);
} else {
bytes = BLOCK_SIZE;
bytes = size - ret;
if (bytes > BLOCK_SIZE) {
bytes = BLOCK_SIZE;
}
memset(buf,0,bytes);
DEBUG("sparse file, skipping %d bytes",bytes);
}
Expand Down
15 changes: 12 additions & 3 deletions test/0014-file-integrity-sparse.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/bin/bash

UNEVEN_BYTES=1048577

function t0014 {
FUSE_MD5=$(md5sum $MOUNTPOINT/`basename $TMP_FILE` | cut -d\ -f1)
FUSE_BYTES=$(cat $MOUNTPOINT/`basename $TMP_FILE.uneven` | wc -c)
}

function t0014-check {
[ "$FUSE_MD5" = "$FILE_MD5" ]
[ "$FUSE_MD5" = "$FILE_MD5" -a "$FUSE_BYTES" = "$UNEVEN_BYTES" ]
}

set -e
Expand All @@ -21,14 +25,19 @@ e4test_make_LOGFILE
e4test_make_FS 2
e4test_make_MOUNTPOINT

# Recreate the same sparse file on the target fs
e4test_mount

# Test A: recreate the same sparse file on the target fs
NEWTMP=$MOUNTPOINT/`basename $TMP_FILE`
dd if=/dev/zero of=$NEWTMP bs=1024 seek=1024 count=0 &> /dev/null
dd if=$TMP_FILE.rnd of=$NEWTMP bs=1024 seek=512 conv=notrunc &> /dev/null

# Test B: create a fully sparse file whose length is not block-aligned
truncate -s $UNEVEN_BYTES $MOUNTPOINT/`basename $TMP_FILE`.uneven

e4test_umount

# Check the md5 after mount using fuse
# Check the md5 (test A) and byte count (test B) after mount using fuse
e4test_fuse_mount
e4test_run t0014
e4test_fuse_umount
Expand Down
1 change: 1 addition & 0 deletions test/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function e4test_make_FS {
function e4test_mount {
mkdir $MOUNTPOINT
sudo mount -o loop -t ext4 $FS $MOUNTPOINT
sudo chown $USER $MOUNTPOINT
}

function __e4test_debugfs_precheck {
Expand Down

0 comments on commit ab9ae62

Please sign in to comment.