3 # convert ext2/3/4 images to btrfs images, and make sure the results are
10 SCRIPT_DIR=$(dirname $(readlink -f $0))
11 TOP=$(readlink -f $SCRIPT_DIR/../)
12 RESULTS="$TOP/tests/convert-tests-results.txt"
13 # how many files to create.
16 source $TOP/tests/common
23 CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX)
28 dirpath=$TEST_MNT/$dataset_type
29 run_check $SUDO_HELPER mkdir -p $dirpath
33 for num in $(seq 1 $DATASET_SIZE); do
34 run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \
35 count=1 >/dev/null 2>&1
40 for num in $(seq 1 $DATASET_SIZE); do
41 run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
42 run_check $SUDO_HELPER ln $dirpath/$dataset_type.$num $dirpath/hlink.$num
47 for num in $(seq 1 $DATASET_SIZE); do
48 run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
49 run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/slink.$num
54 for num in $(seq 1 $DATASET_SIZE); do
55 run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/blink.$num
60 for modes in $(seq 1 7777); do
61 if [[ "$modes" == *9* ]] || [[ "$modes" == *8* ]]
65 run_check $SUDO_HELPER touch $dirpath/$dataset_type.$modes
66 run_check $SUDO_HELPER chmod $modes $dirpath/$dataset_type.$modes
72 for num in $(seq 1 $DATASET_SIZE); do
73 run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \
74 count=1 >/dev/null 2>&1
75 run_check $SUDO_HELPER truncate -s 500K $dirpath/$dataset_type.$num
76 run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \
77 oflag=append conv=notrunc count=1 >/dev/null 2>&1
78 run_check $SUDO_HELPER truncate -s 800K $dirpath/$dataset_type.$num
83 for num in $(seq 1 $DATASET_SIZE); do
84 run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
85 run_check $SUDO_HELPER setfacl -m "u:root:x" $dirpath/$dataset_type.$num
86 run_check $SUDO_HELPER setfattr -n user.foo -v bar$num $dirpath/$dataset_type.$num
94 for dataset_type in 'small' 'hardlink' 'symlink' 'brokenlink' 'perm' 'sparse' 'acls'; do
95 generate_dataset "$dataset_type"
106 if [ -z "$features" ]; then
107 echo " [TEST/conv] $1, btrfs defaults"
109 echo " [TEST/conv] $1, btrfs $features"
113 echo "creating ext image with: $*" >> $RESULTS
114 # TEST_DEV not removed as the file might have special permissions, eg.
115 # when test image is on NFS and would not be writable for root
116 run_check truncate -s 0 $TEST_DEV
117 # 256MB is the smallest acceptable btrfs image.
118 run_check truncate -s 512M $TEST_DEV
119 run_check $* -F $TEST_DEV
121 # create a file to check btrfs-convert can convert regular file
123 run_check_mount_test_dev
125 run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \
126 count=1 >/dev/null 2>&1
127 run_check_stdout find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > $CHECKSUMTMP
128 run_check_umount_test_dev
130 run_check $TOP/btrfs-convert ${features:+-O "$features"} -N "$nodesize" $TEST_DEV
131 run_check $TOP/btrfs check $TEST_DEV
132 run_check $TOP/btrfs-show-super $TEST_DEV
134 run_check_mount_test_dev
135 run_check_stdout md5sum -c $CHECKSUMTMP |
136 grep -q 'FAILED' && _fail "file validation failed."
137 run_check_umount_test_dev
140 if ! [ -z "$TEST" ]; then
141 echo " [TEST/conv] skipped all convert tests, TEST=$TEST"
145 for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do
146 convert_test "$feature" "ext2 4k nodesize" 4096 mke2fs -b 4096
147 convert_test "$feature" "ext3 4k nodesize" 4096 mke2fs -j -b 4096
148 convert_test "$feature" "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096
149 convert_test "$feature" "ext2 8k nodesize" 8192 mke2fs -b 4096
150 convert_test "$feature" "ext3 8k nodesize" 8192 mke2fs -j -b 4096
151 convert_test "$feature" "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096
152 convert_test "$feature" "ext2 16k nodesize" 16384 mke2fs -b 4096
153 convert_test "$feature" "ext3 16k nodesize" 16384 mke2fs -j -b 4096
154 convert_test "$feature" "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096
155 convert_test "$feature" "ext2 32k nodesize" 32768 mke2fs -b 4096
156 convert_test "$feature" "ext3 32k nodesize" 32768 mke2fs -j -b 4096
157 convert_test "$feature" "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096
158 convert_test "$feature" "ext2 64k nodesize" 65536 mke2fs -b 4096
159 convert_test "$feature" "ext3 64k nodesize" 65536 mke2fs -j -b 4096
160 convert_test "$feature" "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096