File: test.sh

package info (click to toggle)
btrfs-progs 6.17.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,612 kB
  • sloc: ansic: 127,282; sh: 7,915; python: 1,384; makefile: 900; asm: 296
file content (53 lines) | stat: -rwxr-xr-x 1,798 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# Make sure btrfs is handling the ext4 uninit (preallocated) extent correctly

source "$TEST_TOP/common" || exit
source "$TEST_TOP/common.convert" || exit

setup_root_helper
prepare_test_dev 1G

check_global_prereq mkfs.ext4
check_global_prereq fallocate
check_global_prereq filefrag
check_global_prereq awk
check_global_prereq md5sum
check_prereq btrfs-convert
check_prereq btrfs

convert_test_prep_fs ext4 mke2fs -t ext4 -b 4096

# Create a preallocated extent first.
run_check $SUDO_HELPER fallocate -l 32K "$TEST_MNT/file"
sync
# Get the real on-disk location and write some data into it.
physical=$(run_check_stdout $SUDO_HELPER filefrag -v "$TEST_MNT/file" | grep unwritten | awk '{print $4}' | grep -o "[[:digit:]]*")

if [ -z "$physical" ]; then
	_fail "unable to get the physical address of the file"
fi

# Now fill the underlying range with non-zeros.
# For properly converted fs, we should not read the contents anyway
run_check $SUDO_HELPER dd if=/dev/urandom of="$TEST_DEV" bs=4096 seek="$physical" conv=notrunc count=8

# Write some thing into the file range.
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file" bs=4096 count=1 conv=notrunc
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file" bs=4096 count=1 seek=3 conv=notrunc
sync
md5_before=$(md5sum "$TEST_MNT/file" | cut -f1 -d' ')
_log "md5sum before convert: $md5_before"
run_check_umount_test_dev

# Btrfs-convert should handle the unwritten part correctly, either punching a hole
# or a proper preallocated extent, so that we won't read the on-disk data.
convert_test_do_convert

run_check_mount_test_dev
md5_after=$(md5sum "$TEST_MNT/file" | cut -f1 -d' ')
_log "md5sum after convert: $md5_after"
run_check_umount_test_dev

if [ "$md5_before" != "$md5_after" ]; then
	_fail "contents mismatch"
fi